-
Notifications
You must be signed in to change notification settings - Fork 4
PublisherInterface
@chili-publish/publisher-interface / Exports / PublisherInterface
- addListener
- alert
- clearAssetSubjectInfo
- clearFrameSubjectArea
- executeFunction
- getAssetSubjectInfo
- getDirtyState
- getFrameSnapshot
- getFrameSubjectArea
- getNumPages
- getObject
- getPageSnapshot
- getSelectedPage
- getSelectedPageName
- handleEvents
- nextPage
- previousPage
- removeListener
- setAssetSubjectInfo
- setFrameSubjectArea
- setProperty
- setSelectedPage
- setVariableIsLocked
- build
• Private
new PublisherInterface()
• Private
_editorObject: null
| EditorObjectAlias
= null
• Private
child: AsyncMethodReturns
<ChiliWrapper
>
• Private
chiliEventListenerCallbacks: Map
<string
, (targetId
: string
) => void
>
• 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.
▸ 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)}));
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 |
Promise
<void
>
▸ alert(message
, title
): Promise
<void
>
Displays a modal box within the editor UI containing a title with a message.
Name | Type | Description |
---|---|---|
message |
string |
The message to be displayed. |
title |
string |
The title/header of the modal. |
Promise
<void
>
▸ 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"}.
Name | Type | Description |
---|---|---|
frameIdOrTag |
string |
The string id or tag of the frame to clear the asset subject area. |
Promise
<void
>
▸ clearFrameSubjectArea(idOrTag
): Promise
<void
>
Resets the frame subject area to {height: "0", width: "0", x: "1", y: "1"}.
Name | Type | Description |
---|---|---|
idOrTag |
string |
The string id or tag of the frame to clear the subject area. |
Promise
<void
>
▸ 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');
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. |
Promise
<undefined
| null
| string
| number
| boolean
| object
>
Returns the return of executed function.
▸ 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.
Name | Type | Description |
---|---|---|
frameIdOrTag |
string |
The string id or tag of the frame. |
Promise
<{ height
: string
; poiX
: string
; poiY
: string
; width
: string
; x
: string
; y
: string
}>
The asset subject area.
▸ getDirtyState(): Promise
<boolean
>
Returns value of document.isDirty which signifies if the document has been changed since previous save.
Promise
<boolean
>
Returns boolean to signify if the document has been changed since previous save.
▸ getFrameSnapshot(idOrTag
, size
, transparentBackground
): Promise
<string
>
Returns a base64 encoded PNG snapshot image of a specific frame
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. |
Promise
<string
>
A base64 encoded PNG image of the frame.
▸ getFrameSubjectArea(idOrTag
): Promise
<{ height
: string
; width
: string
; x
: string
; y
: string
}>
Gets the frame subject area for the image fit mode Smart Fit.
Name | Type | Description |
---|---|---|
idOrTag |
string |
The string id or tag of the frame. |
Promise
<{ height
: string
; width
: string
; x
: string
; y
: string
}>
- The subject area of the frame.
▸ getNumPages(): Promise
<number
>
Returns the total number of pages.
Promise
<number
>
The total number of pages.
▸ getObject(chiliPath
): Promise
<undefined
| null
| string
| number
| boolean
| object
>
Gets the value of the property or object found at given chiliPath.
Name | Type | Description |
---|---|---|
chiliPath |
string |
A case-sensitive string query path for selecting properties and objects in a CHILI document. |
Promise
<undefined
| null
| string
| number
| boolean
| object
>
Returns the value of the property or object found at given chiliPath.
▸ 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);
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. |
Promise
<string
>
A base64 encoded PNG image of the document.
▸ 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.
Promise
<number
>
Page index + 1 of the selected page.
▸ getSelectedPageName(): Promise
<string
>
Returns the name of the selected page.
Promise
<string
>
Name of the page.
▸ Private
handleEvents(eventName
, id
): string
Name | Type |
---|---|
eventName |
string |
id |
string |
string
▸ 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.
Promise
<void
>
▸ previousPage(): Promise
<void
>
Selects the previous page in the document.pages list. If the current selected page has the last index then nothing happens.
Promise
<void
>
▸ removeListener(eventName
): Promise
<void
>
Removes the listener for the specified editor event.
Name | Type | Description |
---|---|---|
eventName |
string |
A case-sensitive string representing the editor event type to stop listening to. |
Promise
<void
>
▸ 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.
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. |
Promise
<void
>
▸ setFrameSubjectArea(idOrTag
, x
, y
, width
, height
): Promise
<void
>
Sets the frame subject area for the image fit mode Smart Fit.
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. |
Promise
<void
>
▸ setProperty(chiliPath
, property
, value
): Promise
<void
>
Sets the value of the property defined by property on the object defined by the chiliPath
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. |
Promise
<void
>
▸ setSelectedPage(page
): Promise
<void
>
Selects page by common language page number causing the editor to visually jump to that page.
Name | Type | Description |
---|---|---|
page |
number |
Common language page number (page index + 1) to select. |
Promise
<void
>
▸ setVariableIsLocked(variableName
, isLocked
): Promise
<void
>
Sets the locked (editable) state of a variable.
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. |
Promise
<void
>
▸ 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.
Name | Type |
---|---|
iframe |
HTMLIFrameElement |
options |
buildOptions |
Promise
<PublisherInterface
>