Skip to content

PublisherInterface

seancrowe edited this page Oct 26, 2022 · 2 revisions

@chili-publish/publisher-interface / Exports / PublisherInterface

Class: PublisherInterface

Table of contents

Constructors

Properties

Accessors

Methods

Constructors

constructor

Private new PublisherInterface()

Defined in

PublisherInterface.ts:133

Properties

_editorObject

Private _editorObject: null | EditorObjectAlias = null

Defined in

PublisherInterface.ts:177


child

Private child: AsyncMethodReturns<ChiliWrapper>

Defined in

PublisherInterface.ts:127


chiliEventListenerCallbacks

Private chiliEventListenerCallbacks: Map<string, (targetId: string) => void>

Defined in

PublisherInterface.ts:128

Accessors

editorObject

get editorObject(): EditorObjectAlias

Returns an alias for editorObject with similarly named functions. This is to help with backwards compatibility, but these functions still return a Promise.

Returns

EditorObjectAlias

Defined in

PublisherInterface.ts:181

Methods

addListener

addListener(eventName, callbackFunction?): Promise<void>

Adds a listener to an editor event and a user defined callback function when event is fired. The function will receive the target id of the event and is executed when the event is triggered.

Example

publisherInterface.addListener("FrameMoved", (targetId)=>{console.log(targetId)}));

Parameters

Name Type Description
eventName string A case-sensitive string representing the editor event type to listen for.
callbackFunction? (targetId: string) => void A function that executes when the event is triggered. If callback is null, the listener will instead call window.OnEditorEvent

Returns

Promise<void>

Defined in

PublisherInterface.ts:337


alert

alert(message, title): Promise<void>

Displays a modal box within the editor UI containing a title with a message.

Parameters

Name Type Description
message string The message to be displayed.
title string The title/header of the modal.

Returns

Promise<void>

Defined in

PublisherInterface.ts:218


clearAssetSubjectInfo

clearAssetSubjectInfo(frameIdOrTag): Promise<void>

Resets the asset subject area of target to {height: "0", width: "0", x: "1", y: "1", poiX: "0.5", poiY: "0.5"}.

Parameters

Name Type Description
frameIdOrTag string The string id or tag of the frame to clear the asset subject area.

Returns

Promise<void>

Defined in

PublisherInterface.ts:602


clearFrameSubjectArea

clearFrameSubjectArea(idOrTag): Promise<void>

Resets the frame subject area to {height: "0", width: "0", x: "1", y: "1"}.

Parameters

Name Type Description
idOrTag string The string id or tag of the frame to clear the subject area.

Returns

Promise<void>

Defined in

PublisherInterface.ts:535


executeFunction

executeFunction(chiliPath, functionName, ...params): Promise<undefined | null | string | number | boolean | object>

Executes function of functionName found as a property or method on the object defined in the chiliPath.

Example

// Will add a new frame of type text on page of index 0 at coordinates X: 10 mm and Y: 15 mm with width: 100 mm and height: 50 mm

publisherInterface.ExecuteFunction('document.pages[0].frames', 'Add', 'text', '10 mm', '15 mm', '100 mm', '50 mm');

Parameters

Name Type Description
chiliPath string A case-sensitive string query path for selecting properties and objects in a CHILI document.
functionName string A case-sensitive string of the name of the function to execute.
...params (undefined | null | string | number | boolean)[] Parameters to be passed to function of functionName.

Returns

Promise<undefined | null | string | number | boolean | object>

Returns the return of executed function.

Defined in

PublisherInterface.ts:401


getAssetSubjectInfo

getAssetSubjectInfo(frameIdOrTag): Promise<{ height: string ; poiX: string ; poiY: string ; width: string ; x: string ; y: string }>

Gets the asset subject area for the target frame for image fit mode Smart Fit.

Parameters

Name Type Description
frameIdOrTag string The string id or tag of the frame.

Returns

Promise<{ height: string ; poiX: string ; poiY: string ; width: string ; x: string ; y: string }>

The asset subject area.

Defined in

PublisherInterface.ts:548


getDirtyState

getDirtyState(): Promise<boolean>

Returns value of document.isDirty which signifies if the document has been changed since previous save.

Returns

Promise<boolean>

Returns boolean to signify if the document has been changed since previous save.

Defined in

PublisherInterface.ts:230


getFrameSnapshot

getFrameSnapshot(idOrTag, size, transparentBackground): Promise<string>

Returns a base64 encoded PNG snapshot image of a specific frame

Parameters

Name Type Description
idOrTag string The id or tag of the frame to return as an image.
size string | number | { height: number ; width: number } The size of the returned png. This can be set as an image size in pixels by using a string width x height. For example "1000x1500". This can be set as a zoom level. For example "75" would be 75% zoom of the document. This can be set as an object of width and height. For example {width:1000 height:1000}. If the size is set in pixels and the ratio is different from the page ratio, the image is scaled to fit entirely in the png and placed at (0,0) top left. The extra space at the bottom or the right is filled with background color. If a zoom percentage is given, the output size is automatically calculated using the document dimensions, assuming the resolution is 72 dpi.
transparentBackground boolean A boolean that determines if the png document background should be transparent.

Returns

Promise<string>

A base64 encoded PNG image of the frame.

Defined in

PublisherInterface.ts:470


getFrameSubjectArea

getFrameSubjectArea(idOrTag): Promise<{ height: string ; width: string ; x: string ; y: string }>

Gets the frame subject area for the image fit mode Smart Fit.

Parameters

Name Type Description
idOrTag string The string id or tag of the frame.

Returns

Promise<{ height: string ; width: string ; x: string ; y: string }>

  • The subject area of the frame.

Defined in

PublisherInterface.ts:492


getNumPages

getNumPages(): Promise<number>

Returns the total number of pages.

Returns

Promise<number>

The total number of pages.

Defined in

PublisherInterface.ts:305


getObject

getObject(chiliPath): Promise<undefined | null | string | number | boolean | object>

Gets the value of the property or object found at given chiliPath.

Parameters

Name Type Description
chiliPath string A case-sensitive string query path for selecting properties and objects in a CHILI document.

Returns

Promise<undefined | null | string | number | boolean | object>

Returns the value of the property or object found at given chiliPath.

Defined in

PublisherInterface.ts:360


getPageSnapshot

getPageSnapshot(pageIndex, size, layers, frames, viewMode, transparentBackground): Promise<string>

Returns a base64 encoded PNG snapshot image of a specific page.

Example

\\ This will get a 1000 by 1000 image of the first page and open it in a popup.
let base64 = publisherInterface.GetPageSnapshot('0', '1000x1000', null, null, 'preview', true);

let newImage = new Image();
newImage.src = "data:image/png;base64," + base64;

let popup = open("", "Popup", "width=1000,height=1000,top="+(window.screen.height/2)+",left="+(window.screen.height/2));
popup.document.body.appendChild(newImage);

Parameters

Name Type Description
pageIndex number The page index to return as an image.
size string | number | { height: number ; width: number } The size of the returned png. This can be set as an image size in pixels by using a string width x height. For example "1000x1500". This can be set as a zoom level. For example "75" would be 75% zoom of the document. This can be set as an object of width and height. For example {width:1000 height:1000}. If the size is set in pixels and the ratio is different from the page ratio, the image is scaled to fit entirely in the png and placed at (0,0) top left. The extra space at the bottom or the right is filled with background color. If a zoom percentage is given, the output size is automatically calculated using the document dimensions, assuming the resolution is 72 dpi.
layers null | string[] An array of layers that are to be visible in the png. An array of visible layers can be provided using the layer "name" property or layer "id" property. If no list is passed, the layer visibility is the same as in the editor window.
frames null | string[] An array of frames that are visible in the png. An array of visible frame elements can be provided using the frame "tag" property or layer "id" property. If no list is passed, the frame visibility is the same as in the editor window.
viewMode "preview" | "edit" | "technical" A string that is either: preview, edit, or technical. "preview" shows the page in standard preview mode in the same way as the editor does. If there is an active selection, it should not be indicated in the resulting png. Annotations should be hidden. "edit" shows the page in standard edit mode in the same way as the editor does. The view can be identical to the editor view, with active selections and frame handles. "technical" shows the page in edit mode, but without the control handles and selections. Annotations should be hidden.
transparentBackground boolean A boolean that determines if the png document background should be transparent.

Returns

Promise<string>

A base64 encoded PNG image of the document.

Defined in

PublisherInterface.ts:440


getSelectedPage

getSelectedPage(): Promise<number>

Returns the common language page number, which is page index + 1. So if you have page with index 0 selected, this would return 1.

Returns

Promise<number>

Page index + 1 of the selected page.

Defined in

PublisherInterface.ts:279


getSelectedPageName

getSelectedPageName(): Promise<string>

Returns the name of the selected page.

Returns

Promise<string>

Name of the page.

Defined in

PublisherInterface.ts:292


handleEvents

Private handleEvents(eventName, id): string

Parameters

Name Type
eventName string
id string

Returns

string

Defined in

PublisherInterface.ts:171


nextPage

nextPage(): Promise<void>

Selects the next page in the document.pages list. If the current selected page has the beginning index 0 then nothing happens.

Returns

Promise<void>

Defined in

PublisherInterface.ts:243


previousPage

previousPage(): Promise<void>

Selects the previous page in the document.pages list. If the current selected page has the last index then nothing happens.

Returns

Promise<void>

Defined in

PublisherInterface.ts:254


removeListener

removeListener(eventName): Promise<void>

Removes the listener for the specified editor event.

Parameters

Name Type Description
eventName string A case-sensitive string representing the editor event type to stop listening to.

Returns

Promise<void>

Defined in

PublisherInterface.ts:318


setAssetSubjectInfo

setAssetSubjectInfo(frameIdOrTag, x, y, width, height, poiX, poiY): Promise<void>

Sets the asset subject area for the target frame for image fit mode Smart Fit.

Parameters

Name Type Description
frameIdOrTag string The string id or tag of the frame.
x number A number 0 to 1 representing the x coordinate. Setting the number outside that range will clip the result to 0 or 1.
y number A number 0 to 1 representing the y coordinate. Setting the number outside that range will clip the result to 0 or 1.
width number A number 0 to 1 representing width. Setting the number outside that range will clip the result to 0 or 1.
height number A number 0 to 1 representing height. Setting the number outside that range will clip the result to 0 or 1.
poiX number A number 0 to 1 representing x coordinate of teh point of interest. Setting the number outside that range will clip the result to 0 or 1.
poiY number A number 0 to 1 representing y coordinate of teh point of interest.

Returns

Promise<void>

Defined in

PublisherInterface.ts:574


setFrameSubjectArea

setFrameSubjectArea(idOrTag, x, y, width, height): Promise<void>

Sets the frame subject area for the image fit mode Smart Fit.

Parameters

Name Type Description
idOrTag string The string id or tag of the frame.
x number A number 0 to 1 representing the x coordinate. Setting the number outside that range will clip the result to 0 or 1.
y number A number 0 to 1 representing the y coordinate. Setting the number outside that range will clip the result to 0 or 1.
width number A number 0 to 1 representing width. Setting the number outside that range will clip the result to 0 or 1.
height number A number 0 to 1 representing height. Setting the number outside that range will clip the result to 0 or 1.

Returns

Promise<void>

Defined in

PublisherInterface.ts:511


setProperty

setProperty(chiliPath, property, value): Promise<void>

Sets the value of the property defined by property on the object defined by the chiliPath

Parameters

Name Type Description
chiliPath string A case-sensitive string query path for selecting properties and objects in a CHILI document.
property string The case-sensitive string name of the property found on the object of the chiliPath.
value null | string | number | boolean The value to set the property.

Returns

Promise<void>

Defined in

PublisherInterface.ts:377


setSelectedPage

setSelectedPage(page): Promise<void>

Selects page by common language page number causing the editor to visually jump to that page.

Parameters

Name Type Description
page number Common language page number (page index + 1) to select.

Returns

Promise<void>

Defined in

PublisherInterface.ts:266


setVariableIsLocked

setVariableIsLocked(variableName, isLocked): Promise<void>

Sets the locked (editable) state of a variable.

Parameters

Name Type Description
variableName string A case-sensitive string of the variable name to target.
isLocked boolean A boolean to set the variable as locked or unlocked.

Returns

Promise<void>

Defined in

PublisherInterface.ts:615


build

Static build(iframe, options?): Promise<PublisherInterface>

The build method will wait for a connection to the other side of iframe. Must be called before iframe onload event is fired.

Parameters

Name Type
iframe HTMLIFrameElement
options buildOptions

Returns

Promise<PublisherInterface>

Defined in

PublisherInterface.ts:142

Clone this wiki locally