@hussmartinez/image-sdk 0.3.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +48 -4
- package/dist/assets/image/render.worker.js +2 -1
- package/dist/element.d.ts +873 -338
- package/dist/element.js +5 -3
- package/dist/element.js.map +1 -1
- package/dist/index.d.ts +810 -178
- package/dist/index.js +76 -11
- package/dist/index.js.map +1 -1
- package/dist/lazy/inline-worker-DsBNkr8Q.js +30 -0
- package/dist/lazy/{inline-worker-l_ynDNuS.js.map → inline-worker-DsBNkr8Q.js.map} +1 -1
- package/dist/react.d.ts +970 -339
- package/dist/react.js +1 -1
- package/dist/shared/{core-BWNmXDlB.js → core-BlFeJWak.js} +1159 -159
- package/dist/shared/core-BlFeJWak.js.map +1 -0
- package/dist/shared/editor-Bjv32UmV.js +3817 -0
- package/dist/shared/editor-Bjv32UmV.js.map +1 -0
- package/dist/styles.css +252 -17
- package/formats/hm-image-command/v2.schema.json +266 -0
- package/formats/hm-image-plan/v2.schema.json +877 -0
- package/package.json +3 -3
- package/dist/lazy/inline-worker-l_ynDNuS.js +0 -30
- package/dist/shared/core-BWNmXDlB.js.map +0 -1
- package/dist/shared/editor-CJXEK6MY.js +0 -1804
- package/dist/shared/editor-CJXEK6MY.js.map +0 -1
package/dist/element.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { Nt as ImageError } from "./shared/core-BlFeJWak.js";
|
|
2
|
+
import { d as imageEditorMessages, p as ExportListenerContext, t as ImageEditor } from "./shared/editor-Bjv32UmV.js";
|
|
3
3
|
import { useEffect, useRef } from "react";
|
|
4
4
|
import { jsx } from "react/jsx-runtime";
|
|
5
5
|
import { createEditorElement } from "@hussmartinez/sdk-core/element";
|
|
@@ -77,6 +77,7 @@ function mountImageEditor(host, initial, context) {
|
|
|
77
77
|
},
|
|
78
78
|
handle: {
|
|
79
79
|
open: async (file) => (await ready).open(file),
|
|
80
|
+
insertImage: async (file) => (await ready).insertImage(file),
|
|
80
81
|
export: async (format) => (await ready).export(format),
|
|
81
82
|
execute: (commands) => {
|
|
82
83
|
const editor = now();
|
|
@@ -111,6 +112,7 @@ var defineImageEditorElement = /* @__PURE__ */ createEditorElement({
|
|
|
111
112
|
],
|
|
112
113
|
methods: [
|
|
113
114
|
"open",
|
|
115
|
+
"insertImage",
|
|
114
116
|
"execute",
|
|
115
117
|
"export",
|
|
116
118
|
"undo",
|
|
@@ -124,6 +126,6 @@ var defineImageEditorElement = /* @__PURE__ */ createEditorElement({
|
|
|
124
126
|
],
|
|
125
127
|
mount: mountImageEditor
|
|
126
128
|
});
|
|
127
|
-
export { defineImageEditorElement };
|
|
129
|
+
export { defineImageEditorElement, imageEditorMessages };
|
|
128
130
|
|
|
129
131
|
//# sourceMappingURL=element.js.map
|
package/dist/element.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"element.js","names":[],"sources":["../src/react/element/mount.tsx","../src/element.ts"],"sourcesContent":["import type { MessageOverrides } from \"@hussmartinez/sdk-core\";\nimport type { EditorElementContext, MountedEditor } from \"@hussmartinez/sdk-core/element\";\nimport { type ReactNode, type RefCallback, useEffect, useRef } from \"react\";\nimport { createRoot } from \"react-dom/client\";\nimport { ImageError } from \"../../core/errors/image-error.js\";\nimport type { ImageFilePolicyOverrides } from \"../../core/errors/image-limits.js\";\nimport type { ImagePlan } from \"../../core/model/plan.js\";\nimport type { ImageEngine } from \"../../core/ports/image-engine.js\";\nimport type { ImageProcessor } from \"../../core/ports/image-processor.js\";\nimport type { ImageMessageCatalogue } from \"../../messages/en.js\";\nimport { ImageEditor } from \"../editor/ImageEditor.js\";\nimport type { ImageEditorHandle } from \"../editor/types.js\";\nimport { ExportListenerContext, type ImageExportReport } from \"../export/export-listener.js\";\n\n/**\n * The `<hm-image-editor>` element's props: its attributes, `theme`, `locale`\n * and `tools`, and its properties (docs/adr/0007). They're writable, since a\n * host sets them on the element, such as `editor.file = file`.\n *\n * @public\n */\nexport interface ImageEditorElementProps {\n /** `light`, `dark` or `system`: ui's colour mode, on the element. Inherited when unset. */\n theme?: string;\n /** The locale for numbers and plurals. Defaults to `\"en\"`. */\n locale?: string;\n /** Which tools are present, by id, in order: the attribute is space-separated. */\n tools?: readonly string[];\n /** An image to open. Setting another opens it, replacing the current one. */\n file?: Blob;\n /** The plan, applied as one undoable step when it changes. */\n plan?: ImagePlan;\n filePolicy?: ImageFilePolicyOverrides;\n /** Where the application serves the package's `dist/assets/` directory. */\n assetsUrl?: string | URL;\n /** Text overrides, typed against the English catalogue. */\n messages?: MessageOverrides<ImageMessageCatalogue>;\n engine?: ImageEngine;\n processor?: ImageProcessor;\n}\n\n/**\n * The `<hm-image-editor>` element's methods: the React editor's ref handle.\n * They wait for the editor's first render; `export()` returns the file.\n *\n * @public\n */\nexport type ImageEditorElementMethods = Pick<\n ImageEditorHandle,\n \"open\" | \"execute\" | \"export\" | \"undo\" | \"redo\"\n>;\n\n/**\n * The element's events, fired as `hm-image-editor-<name>`. None carries a\n * file name or contents (sdk-core ADR 0012):\n *\n * - `change`: the plan, after each committed edit, open, undo or redo.\n * - `event`: the session's anonymous usage event.\n * - `export`: an {@link ImageExportReport} after the export dialog finishes.\n * - `error`: `{ code, details }` of a failure the editor shows.\n *\n * @public\n */\nexport type ImageEditorElementEvent = \"change\" | \"event\" | \"export\" | \"error\";\n\nconst MODES = new Set([\"light\", \"dark\", \"system\"]);\n\ninterface ElementEditorProps {\n readonly values: Partial<ImageEditorElementProps>;\n readonly setHandle: RefCallback<ImageEditorHandle>;\n readonly handle: { readonly current: ImageEditorHandle | null };\n readonly dispatch: EditorElementContext<ImageEditorElementEvent>[\"dispatch\"];\n readonly report: (report: ImageExportReport) => void;\n}\n\nfunction ElementEditor(props: ElementEditorProps): ReactNode {\n const { values, setHandle, handle, dispatch, report } = props;\n const { file, theme: _theme, ...editorProps } = values;\n\n // A file opens when it's set, and another replaces it.\n const opened = useRef<Blob | undefined>(undefined);\n useEffect(() => {\n if (!file || file === opened.current) return;\n opened.current = file;\n void handle.current?.open(file);\n }, [file, handle]);\n\n // A failure the editor shows is an `error` event, once per failure.\n useEffect(() => {\n const session = handle.current?.session;\n if (!session) return;\n let last = session.getSnapshot().error;\n return session.subscribe(() => {\n const error = session.getSnapshot().error;\n if (error && error !== last) {\n dispatch(\"error\", { code: error.code, details: error.details ?? {} });\n }\n last = error;\n });\n }, [handle, dispatch]);\n\n return (\n <ExportListenerContext.Provider value={report}>\n <ImageEditor\n ref={setHandle}\n {...editorProps}\n onChange={(plan) => dispatch(\"change\", plan)}\n onEvent={(event) => dispatch(\"event\", event)}\n />\n </ExportListenerContext.Provider>\n );\n}\n\n/**\n * Renders `<ImageEditor>` into the element's light DOM, for\n * `createEditorElement` (sdk-core ADR 0040). It renders without `flushSync`,\n * since the element may connect during a host's React commit; so `open()`\n * and `export()` wait for the first render, and `execute()`, `undo()` and\n * `redo()` act on the document there is.\n */\nexport function mountImageEditor(\n host: HTMLElement,\n initial: Partial<ImageEditorElementProps>,\n context: EditorElementContext<ImageEditorElementEvent>,\n): MountedEditor<Partial<ImageEditorElementProps>, ImageEditorElementMethods> {\n const root = createRoot(host);\n const handle: { current: ImageEditorHandle | null } = { current: null };\n let resolveReady: (editor: ImageEditorHandle) => void = () => {};\n const ready = new Promise<ImageEditorHandle>((resolve) => {\n resolveReady = resolve;\n });\n const setHandle: RefCallback<ImageEditorHandle> = (editor) => {\n handle.current = editor;\n if (editor) resolveReady(editor);\n };\n const dispatch = context.dispatch;\n const report = (exported: ImageExportReport) => dispatch(\"export\", exported);\n\n const render = (values: Partial<ImageEditorElementProps>) => {\n // The colour mode is ui's attribute on the element itself, so changing it\n // never re-renders the editor.\n const mode = values.theme;\n if (mode && MODES.has(mode)) host.setAttribute(\"data-hm-theme\", mode);\n else host.removeAttribute(\"data-hm-theme\");\n root.render(\n <ElementEditor\n values={values}\n setHandle={setHandle}\n handle={handle}\n dispatch={dispatch}\n report={report}\n />,\n );\n };\n render(initial);\n\n const now = (): ImageEditorHandle | null => handle.current;\n return {\n update: render,\n unmount: () => {\n root.unmount();\n host.removeAttribute(\"data-hm-theme\");\n },\n handle: {\n open: async (file) => (await ready).open(file),\n export: async (format) => (await ready).export(format),\n execute: (commands) => {\n const editor = now();\n if (!editor) {\n throw new ImageError(\"INVALID_COMMAND\", \"There's nothing to edit before a file is open.\");\n }\n editor.execute(commands);\n },\n undo: () => now()?.undo(),\n redo: () => now()?.redo(),\n },\n };\n}\n","/**\n * The `<hm-image-editor>` custom element of the image SDK.\n *\n * @remarks\n * Importing this entry registers nothing: applications call\n * `defineImageEditorElement()` themselves, and importing it on a server does\n * nothing (ADR 0004, ADR 0007). The element renders `<ImageEditor>` into its\n * light DOM, so React and React DOM, the package's optional peer\n * dependencies, are needed here. Hosts import `@hussmartinez/ui/styles.css`\n * once, then this package's `styles.css` (sdk-core ADR 0036).\n *\n * @packageDocumentation\n */\n\nimport { createEditorElement } from \"@hussmartinez/sdk-core/element\";\nimport {\n type ImageEditorElementEvent,\n type ImageEditorElementMethods,\n type ImageEditorElementProps,\n mountImageEditor,\n} from \"./react/element/mount.js\";\n\nexport type { ImageExportReport } from \"./react/export/export-listener.js\";\nexport type { ImageEditorElementEvent, ImageEditorElementMethods, ImageEditorElementProps };\n\n/** A space-separated list, as the `tools` attribute holds. */\nconst words = (value: string): readonly string[] => value.split(/\\s+/).filter(Boolean);\n\n/**\n * Registers `<hm-image-editor>`, or the tag you name, and returns its class\n * (docs/adr/0007, sdk-core ADR 0040): the attributes `theme`, `locale` and\n * `tools`; the properties `file`, `plan`, `filePolicy`, `assetsUrl`,\n * `messages`, `engine` and `processor`; the methods `open`, `execute`,\n * `export`, `undo` and `redo`; and the events `hm-image-editor-change`,\n * `-event`, `-export` and `-error`. Calling it again returns the same class.\n *\n * @example\n * ```ts\n * import { defineImageEditorElement } from \"@hussmartinez/image-sdk/element\";\n *\n * defineImageEditorElement();\n * const editor = document.querySelector(\"hm-image-editor\");\n * editor.file = file;\n * editor.addEventListener(\"hm-image-editor-change\", (event) => save(event.detail));\n * ```\n *\n * @public\n */\nexport const defineImageEditorElement = /* @__PURE__ */ createEditorElement<\n Partial<ImageEditorElementProps>,\n ImageEditorElementMethods,\n ImageEditorElementEvent\n>({\n kind: \"image\",\n attributes: {\n theme: \"theme\",\n locale: \"locale\",\n tools: { property: \"tools\", parse: words },\n },\n properties: [\"file\", \"plan\", \"filePolicy\", \"assetsUrl\", \"messages\", \"engine\", \"processor\"],\n methods: [\"open\", \"execute\", \"export\", \"undo\", \"redo\"],\n events: [\"change\", \"event\", \"export\", \"error\"],\n mount: mountImageEditor,\n});\n"],"mappings":";;;;;;;AAiEA,IAAM,wBAAQ,IAAI,IAAI;CAAC;CAAS;CAAQ;AAAQ,CAAC;AAUjD,SAAS,cAAc,OAAsC;CAC3D,MAAM,EAAE,QAAQ,WAAW,QAAQ,UAAU,WAAW;CACxD,MAAM,EAAE,MAAM,OAAO,QAAQ,GAAG,gBAAgB;CAGhD,MAAM,SAAS,OAAyB,KAAA,CAAS;CACjD,gBAAgB;EACd,IAAI,CAAC,QAAQ,SAAS,OAAO,SAAS;EACtC,OAAO,UAAU;EACjB,OAAY,SAAS,KAAK,IAAI;CAChC,GAAG,CAAC,MAAM,MAAM,CAAC;CAGjB,gBAAgB;EACd,MAAM,UAAU,OAAO,SAAS;EAChC,IAAI,CAAC,SAAS;EACd,IAAI,OAAO,QAAQ,YAAY,CAAC,CAAC;EACjC,OAAO,QAAQ,gBAAgB;GAC7B,MAAM,QAAQ,QAAQ,YAAY,CAAC,CAAC;GACpC,IAAI,SAAS,UAAU,MACrB,SAAS,SAAS;IAAE,MAAM,MAAM;IAAM,SAAS,MAAM,WAAW,CAAC;GAAE,CAAC;GAEtE,OAAO;EACT,CAAC;CACH,GAAG,CAAC,QAAQ,QAAQ,CAAC;CAErB,OACE,oBAAC,sBAAsB,UAAvB;EAAgC,OAAO;EACrC,UAAA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CAAC,OAAO,OAAO;AAsBrF,IAAa,2BAA2C,oCAItD;CACA,MAAM;CACN,YAAY;EACV,OAAO;EACP,QAAQ;EACR,OAAO;GAAE,UAAU;GAAS,OAAO;EAAM;CAC3C;CACA,YAAY;EAAC;EAAQ;EAAQ;EAAc;EAAa;EAAY;EAAU;CAAW;CACzF,SAAS;EAAC;EAAQ;EAAW;EAAU;EAAQ;CAAM;CACrD,QAAQ;EAAC;EAAU;EAAS;EAAU;CAAO;CAC7C,OAAO;AACT,CAAC"}
|
|
1
|
+
{"version":3,"file":"element.js","names":[],"sources":["../src/react/element/mount.tsx","../src/element.ts"],"sourcesContent":["import type { MessageOverrides } from \"@hussmartinez/sdk-core\";\nimport type { EditorElementContext, MountedEditor } from \"@hussmartinez/sdk-core/element\";\nimport { type ReactNode, type RefCallback, useEffect, useRef } from \"react\";\nimport { createRoot } from \"react-dom/client\";\nimport { ImageError } from \"../../core/errors/image-error.js\";\nimport type { ImageFilePolicyOverrides } from \"../../core/errors/image-limits.js\";\nimport type { ImagePlan } from \"../../core/model/plan.js\";\nimport type { ImageEngine } from \"../../core/ports/image-engine.js\";\nimport type { ImageProcessor } from \"../../core/ports/image-processor.js\";\nimport { ImageEditor } from \"../editor/ImageEditor.js\";\nimport type { ImageEditorHandle } from \"../editor/types.js\";\nimport type { ImageEditorMessageCatalogue } from \"../editor-messages.js\";\nimport { ExportListenerContext, type ImageExportReport } from \"../export/export-listener.js\";\n\n/**\n * The `<hm-image-editor>` element's props: its attributes, `theme`, `locale`\n * and `tools`, and its properties (docs/adr/0007). They're writable, since a\n * host sets them on the element, such as `editor.file = file`.\n *\n * @public\n */\nexport interface ImageEditorElementProps {\n /** `light`, `dark` or `system`: ui's colour mode, on the element. Inherited when unset. */\n theme?: string;\n /** The locale for numbers and plurals. Defaults to `\"en\"`. */\n locale?: string;\n /** Which tools are present, by id, in order: the attribute is space-separated. */\n tools?: readonly string[];\n /** An image to open. Setting another opens it, replacing the current one. */\n file?: Blob;\n /** The plan, applied as one undoable step when it changes. */\n plan?: ImagePlan;\n filePolicy?: ImageFilePolicyOverrides;\n /** Where the application serves the package's `dist/assets/` directory. */\n assetsUrl?: string | URL;\n /** Text overrides, typed against the English catalogue. */\n messages?: MessageOverrides<ImageEditorMessageCatalogue>;\n engine?: ImageEngine;\n processor?: ImageProcessor;\n}\n\n/**\n * The `<hm-image-editor>` element's methods: the React editor's ref handle.\n * They wait for the editor's first render; `export()` returns the file.\n *\n * @public\n */\nexport type ImageEditorElementMethods = Pick<\n ImageEditorHandle,\n \"open\" | \"insertImage\" | \"execute\" | \"export\" | \"undo\" | \"redo\"\n>;\n\n/**\n * The element's events, fired as `hm-image-editor-<name>`. None carries a\n * file name or contents (sdk-core ADR 0012):\n *\n * - `change`: the plan, after each committed edit, open, undo or redo.\n * - `event`: the session's anonymous usage event.\n * - `export`: an {@link ImageExportReport} after the export dialog finishes.\n * - `error`: `{ code, details }` of a failure the editor shows.\n *\n * @public\n */\nexport type ImageEditorElementEvent = \"change\" | \"event\" | \"export\" | \"error\";\n\nconst MODES = new Set([\"light\", \"dark\", \"system\"]);\n\ninterface ElementEditorProps {\n readonly values: Partial<ImageEditorElementProps>;\n readonly setHandle: RefCallback<ImageEditorHandle>;\n readonly handle: { readonly current: ImageEditorHandle | null };\n readonly dispatch: EditorElementContext<ImageEditorElementEvent>[\"dispatch\"];\n readonly report: (report: ImageExportReport) => void;\n}\n\nfunction ElementEditor(props: ElementEditorProps): ReactNode {\n const { values, setHandle, handle, dispatch, report } = props;\n const { file, theme: _theme, ...editorProps } = values;\n\n // A file opens when it's set, and another replaces it.\n const opened = useRef<Blob | undefined>(undefined);\n useEffect(() => {\n if (!file || file === opened.current) return;\n opened.current = file;\n void handle.current?.open(file);\n }, [file, handle]);\n\n // A failure the editor shows is an `error` event, once per failure.\n useEffect(() => {\n const session = handle.current?.session;\n if (!session) return;\n let last = session.getSnapshot().error;\n return session.subscribe(() => {\n const error = session.getSnapshot().error;\n if (error && error !== last) {\n dispatch(\"error\", { code: error.code, details: error.details ?? {} });\n }\n last = error;\n });\n }, [handle, dispatch]);\n\n return (\n <ExportListenerContext.Provider value={report}>\n <ImageEditor\n ref={setHandle}\n {...editorProps}\n onChange={(plan) => dispatch(\"change\", plan)}\n onEvent={(event) => dispatch(\"event\", event)}\n />\n </ExportListenerContext.Provider>\n );\n}\n\n/**\n * Renders `<ImageEditor>` into the element's light DOM, for\n * `createEditorElement` (sdk-core ADR 0040). It renders without `flushSync`,\n * since the element may connect during a host's React commit; so `open()`\n * and `export()` wait for the first render, and `execute()`, `undo()` and\n * `redo()` act on the document there is.\n */\nexport function mountImageEditor(\n host: HTMLElement,\n initial: Partial<ImageEditorElementProps>,\n context: EditorElementContext<ImageEditorElementEvent>,\n): MountedEditor<Partial<ImageEditorElementProps>, ImageEditorElementMethods> {\n const root = createRoot(host);\n const handle: { current: ImageEditorHandle | null } = { current: null };\n let resolveReady: (editor: ImageEditorHandle) => void = () => {};\n const ready = new Promise<ImageEditorHandle>((resolve) => {\n resolveReady = resolve;\n });\n const setHandle: RefCallback<ImageEditorHandle> = (editor) => {\n handle.current = editor;\n if (editor) resolveReady(editor);\n };\n const dispatch = context.dispatch;\n const report = (exported: ImageExportReport) => dispatch(\"export\", exported);\n\n const render = (values: Partial<ImageEditorElementProps>) => {\n // The colour mode is ui's attribute on the element itself, so changing it\n // never re-renders the editor.\n const mode = values.theme;\n if (mode && MODES.has(mode)) host.setAttribute(\"data-hm-theme\", mode);\n else host.removeAttribute(\"data-hm-theme\");\n root.render(\n <ElementEditor\n values={values}\n setHandle={setHandle}\n handle={handle}\n dispatch={dispatch}\n report={report}\n />,\n );\n };\n render(initial);\n\n const now = (): ImageEditorHandle | null => handle.current;\n return {\n update: render,\n unmount: () => {\n root.unmount();\n host.removeAttribute(\"data-hm-theme\");\n },\n handle: {\n open: async (file) => (await ready).open(file),\n insertImage: async (file) => (await ready).insertImage(file),\n export: async (format) => (await ready).export(format),\n execute: (commands) => {\n const editor = now();\n if (!editor) {\n throw new ImageError(\"INVALID_COMMAND\", \"There's nothing to edit before a file is open.\");\n }\n editor.execute(commands);\n },\n undo: () => now()?.undo(),\n redo: () => now()?.redo(),\n },\n };\n}\n","/**\n * The `<hm-image-editor>` custom element of the image SDK.\n *\n * @remarks\n * Importing this entry registers nothing: applications call\n * `defineImageEditorElement()` themselves, and importing it on a server does\n * nothing (ADR 0004, ADR 0007). The element renders `<ImageEditor>` into its\n * light DOM, so React and React DOM, the package's optional peer\n * dependencies, are needed here. Hosts import `@hussmartinez/ui/styles.css`\n * once, then this package's `styles.css` (sdk-core ADR 0036).\n *\n * @packageDocumentation\n */\n\nimport { createEditorElement } from \"@hussmartinez/sdk-core/element\";\nimport {\n type ImageEditorElementEvent,\n type ImageEditorElementMethods,\n type ImageEditorElementProps,\n mountImageEditor,\n} from \"./react/element/mount.js\";\n\nexport type { ImageEditorMessageCatalogue } from \"./react/editor-messages.js\";\nexport { imageEditorMessages } from \"./react/editor-messages.js\";\nexport type { ImageExportReport } from \"./react/export/export-listener.js\";\nexport type { ImageEditorElementEvent, ImageEditorElementMethods, ImageEditorElementProps };\n\n/** A space-separated list, as the `tools` attribute holds. */\nconst words = (value: string): readonly string[] => value.split(/\\s+/).filter(Boolean);\n\n/**\n * Registers `<hm-image-editor>`, or the tag you name, and returns its class\n * (docs/adr/0007, sdk-core ADR 0040): the attributes `theme`, `locale` and\n * `tools`; the properties `file`, `plan`, `filePolicy`, `assetsUrl`,\n * `messages`, `engine` and `processor`; the methods `open`, `insertImage`, `execute`,\n * `export`, `undo` and `redo`; and the events `hm-image-editor-change`,\n * `-event`, `-export` and `-error`. Calling it again returns the same class.\n *\n * @example\n * ```ts\n * import { defineImageEditorElement } from \"@hussmartinez/image-sdk/element\";\n *\n * defineImageEditorElement();\n * const editor = document.querySelector(\"hm-image-editor\");\n * editor.file = file;\n * editor.addEventListener(\"hm-image-editor-change\", (event) => save(event.detail));\n * ```\n *\n * @public\n */\nexport const defineImageEditorElement = /* @__PURE__ */ createEditorElement<\n Partial<ImageEditorElementProps>,\n ImageEditorElementMethods,\n ImageEditorElementEvent\n>({\n kind: \"image\",\n attributes: {\n theme: \"theme\",\n locale: \"locale\",\n tools: { property: \"tools\", parse: words },\n },\n properties: [\"file\", \"plan\", \"filePolicy\", \"assetsUrl\", \"messages\", \"engine\", \"processor\"],\n methods: [\"open\", \"insertImage\", \"execute\", \"export\", \"undo\", \"redo\"],\n events: [\"change\", \"event\", \"export\", \"error\"],\n mount: mountImageEditor,\n});\n"],"mappings":";;;;;;;AAiEA,IAAM,wBAAQ,IAAI,IAAI;CAAC;CAAS;CAAQ;AAAQ,CAAC;AAUjD,SAAS,cAAc,OAAsC;CAC3D,MAAM,EAAE,QAAQ,WAAW,QAAQ,UAAU,WAAW;CACxD,MAAM,EAAE,MAAM,OAAO,QAAQ,GAAG,gBAAgB;CAGhD,MAAM,SAAS,OAAyB,KAAA,CAAS;CACjD,gBAAgB;EACd,IAAI,CAAC,QAAQ,SAAS,OAAO,SAAS;EACtC,OAAO,UAAU;EACjB,OAAY,SAAS,KAAK,IAAI;CAChC,GAAG,CAAC,MAAM,MAAM,CAAC;CAGjB,gBAAgB;EACd,MAAM,UAAU,OAAO,SAAS;EAChC,IAAI,CAAC,SAAS;EACd,IAAI,OAAO,QAAQ,YAAY,CAAC,CAAC;EACjC,OAAO,QAAQ,gBAAgB;GAC7B,MAAM,QAAQ,QAAQ,YAAY,CAAC,CAAC;GACpC,IAAI,SAAS,UAAU,MACrB,SAAS,SAAS;IAAE,MAAM,MAAM;IAAM,SAAS,MAAM,WAAW,CAAC;GAAE,CAAC;GAEtE,OAAO;EACT,CAAC;CACH,GAAG,CAAC,QAAQ,QAAQ,CAAC;CAErB,OACE,oBAAC,sBAAsB,UAAvB;EAAgC,OAAO;EACrC,UAAA,oBAAC,aAAD;GACE,KAAK;GACL,GAAI;GACJ,WAAW,SAAS,SAAS,UAAU,IAAI;GAC3C,UAAU,UAAU,SAAS,SAAS,KAAK;EAC5C,CAA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