@sealpixel/ui 1.0.0-rc.20 → 1.0.0-rc.22
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/dist/components/editor/empty-state.d.ts +14 -0
- package/dist/components/editor/empty-state.js +38 -0
- package/dist/components/editor/empty-state.js.map +1 -0
- package/dist/components/editor/json-attribute.d.ts +5 -0
- package/dist/components/editor/json-attribute.js +18 -0
- package/dist/components/editor/json-attribute.js.map +1 -0
- package/dist/components/editor/panel-fit.d.ts +20 -0
- package/dist/components/editor/panel-fit.js +60 -0
- package/dist/components/editor/panel-fit.js.map +1 -0
- package/dist/components/editor/styles.d.ts +2 -0
- package/dist/components/editor/styles.js +697 -0
- package/dist/components/editor/styles.js.map +1 -0
- package/dist/components/editor/toast.d.ts +8 -0
- package/dist/components/editor/toast.js +21 -0
- package/dist/components/editor/toast.js.map +1 -0
- package/dist/components/sealpixel-editor.d.ts +9 -44
- package/dist/components/sealpixel-editor.js +45 -888
- package/dist/components/sealpixel-editor.js.map +1 -1
- package/dist/components/sealpixel-stage.js +11 -2
- package/dist/components/sealpixel-stage.js.map +1 -1
- package/dist/controllers/history-shortcuts-controller.d.ts +18 -0
- package/dist/controllers/history-shortcuts-controller.js +68 -0
- package/dist/controllers/history-shortcuts-controller.js.map +1 -0
- package/dist/locales/de.js +16 -0
- package/dist/locales/de.js.map +1 -1
- package/dist/locales/en.js +16 -0
- package/dist/locales/en.js.map +1 -1
- package/dist/locales/es.js +16 -0
- package/dist/locales/es.js.map +1 -1
- package/dist/locales/fr.js +16 -0
- package/dist/locales/fr.js.map +1 -1
- package/dist/locales/ja.js +16 -0
- package/dist/locales/ja.js.map +1 -1
- package/dist/locales/pt.js +16 -0
- package/dist/locales/pt.js.map +1 -1
- package/dist/tools/annotate.d.ts +58 -0
- package/dist/tools/annotate.js +136 -12
- package/dist/tools/annotate.js.map +1 -1
- package/dist/tools/assist.d.ts +3 -0
- package/dist/tools/assist.js +44 -9
- package/dist/tools/assist.js.map +1 -1
- package/dist/tools/crop-mask.d.ts +2 -0
- package/dist/tools/crop-mask.js +11 -0
- package/dist/tools/crop-mask.js.map +1 -1
- package/dist/tools/crop.d.ts +9 -0
- package/dist/tools/crop.js +117 -48
- package/dist/tools/crop.js.map +1 -1
- package/dist/tools/filter.js +41 -19
- package/dist/tools/filter.js.map +1 -1
- package/dist/tools/finetune.js +10 -7
- package/dist/tools/finetune.js.map +1 -1
- package/dist/tools/frame.js +10 -10
- package/dist/tools/frame.js.map +1 -1
- package/dist/tools/instance-state.d.ts +8 -0
- package/dist/tools/instance-state.js +32 -0
- package/dist/tools/instance-state.js.map +1 -0
- package/dist/tools/keys.d.ts +95 -3
- package/dist/tools/keys.js +135 -2
- package/dist/tools/keys.js.map +1 -1
- package/dist/tools/redact.d.ts +18 -10
- package/dist/tools/redact.js +233 -35
- package/dist/tools/redact.js.map +1 -1
- package/dist/tools/region-transform.d.ts +23 -14
- package/dist/tools/region-transform.js +45 -32
- package/dist/tools/region-transform.js.map +1 -1
- package/dist/tools/resize.js +11 -9
- package/dist/tools/resize.js.map +1 -1
- package/dist/tools/sticker.js +7 -3
- package/dist/tools/sticker.js.map +1 -1
- package/package.json +4 -4
package/dist/tools/resize.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resize.js","sourceRoot":"","sources":["../../src/tools/resize.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAsB,MAAM,oBAAoB,CAAC;AAChF,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,KAAK,CAAC;AACpC,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAEpC,OAAO,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AAErC;;;;;GAKG;AACH,SAAS,WAAW,CAAC,GAAkB;IACrC,MAAM,QAAQ,GAAG,GAAG,CAAC,KAAK,CAAC,QAAQ,CAAC;IACpC,IAAI,QAAQ,EAAE,CAAC;QAC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CACrQ;mBACI;YACT,CAAC,CAAC,OACN;KACD,CAAC;IACJ,CAAC;CACF,CAAC","sourcesContent":["import { RESIZE_DEFAULT_OPTIONS, type ResizeOptions } from '@sealpixel/plugins';\nimport { html, nothing } from 'lit';\nimport { icons } from '../icons.js';\nimport type { UiTool, UiToolContext } from '../tool.js';\nimport { opId } from './finetune.js';\n\n/**\n * The size the resize stage receives: the image after crop, turn and every\n * other stage before it, in logical pixels. A linked resize keeps this aspect,\n * not the source's, because a crop or a quarter turn changes it. The source\n * size stands in until the first preview has a geometry.\n */\nfunction resizeInput(ctx: UiToolContext): { width: number; height: number } | null {\n const geometry = ctx.stage.geometry;\n if (geometry) {\n return geometry.stages.find((s) => s.name === 'resize')?.logicalIn ?? geometry.logicalOut;\n }\n return ctx.state.source;\n}\n\n/** Whether the two dimensions move together. Kept across panel renders. */\nlet linked = true;\n\nexport const resizeTool: UiTool = {\n id: 'resize',\n icon: icons.resize,\n label: 'tool.resize',\n panel: (ctx: UiToolContext) => {\n const target = (\n ctx.document as unknown as {\n resize: {\n target: {\n width: number | null;\n height: number | null;\n fit: string;\n upscale: boolean;\n } | null;\n };\n }\n ).resize.target;\n const options = ctx.options<ResizeOptions>('resize') ?? RESIZE_DEFAULT_OPTIONS;\n const commit = (patch: Record<string, unknown>) =>\n ctx.dispatch({\n type: 'resize.set',\n id: opId(),\n ...(target === null ? { fit: options.defaultFit } : {}),\n ...patch,\n });\n const num = (e: Event) => {\n const v = (e.target as HTMLInputElement).value.trim();\n return v === '' ? null : Math.max(1, Math.round(Number(v)));\n };\n const input = resizeInput(ctx);\n const ratio = input && input.width > 0 ? input.height / input.width : 1;\n /**\n * With the link closed the two fields are one measurement: typing either\n * side writes both, so the log carries the size that will be rendered\n * rather than one number and a rule for finding the other.\n */\n const setWidth = (w: number | null) =>\n commit(\n linked && w !== null\n ? { width: w, height: Math.max(1, Math.round(w * ratio)) }\n : { width: w },\n );\n const setHeight = (h: number | null) =>\n commit(\n linked && h !== null\n ? { width: Math.max(1, Math.round(h / ratio)), height: h }\n : { height: h },\n );\n // The resting value is the size that comes out without a resize, so a\n // field never sits empty saying nothing about what will come out.\n const shownWidth = target?.width ?? input?.width ?? null;\n const shownHeight = target?.height ?? input?.height ?? null;\n const derived = (own: number | null | undefined) => (own == null ? 'derived' : '');\n return html`\n <div class=\"rows\">\n <div class=\"field\">\n <span>${ctx.t('resize.size')}</span>\n <div class=\"dims\">\n <input class=${derived(target?.width)} data-field=\"width\" type=\"number\" min=\"1\" max=${options.max?.width ?? nothing} inputmode=\"numeric\" aria-label=${ctx.t('resize.width')} .value=${shownWidth?.toString() ?? ''} @change=${(e: Event) => setWidth(num(e))} />\n <sealpixel-button\n variant=\"ghost\"\n data-action=\"link\"\n ?pressed=${linked}\n .label=${ctx.t(linked ? 'resize.linked' : 'resize.unlinked')}\n @click=${() => {\n linked = !linked;\n ctx.refresh();\n }}\n >${linked ? icons.link : icons.linkOff}</sealpixel-button\n >\n <input class=${derived(target?.height)} data-field=\"height\" type=\"number\" min=\"1\" max=${options.max?.height ?? nothing} inputmode=\"numeric\" aria-label=${ctx.t('resize.height')} .value=${shownHeight?.toString() ?? ''} @change=${(e: Event) => setHeight(num(e))} />\n </div>\n </div>\n ${\n // A closed link never squeezes the image, so there is nothing for a\n // fit mode to decide.\n linked\n ? nothing\n : html`<label class=\"field\">\n <span>${ctx.t('resize.fit')}</span>\n <select data-field=\"fit\" .value=${target?.fit ?? options.defaultFit} @change=${(e: Event) => commit({ fit: (e.target as HTMLSelectElement).value })}>\n ${options.fits.map((f) => html`<option value=${f} ?selected=${(target?.fit ?? options.defaultFit) === f}>${ctx.t(`resize.fit.${f}`)}</option>`)}\n </select>\n </label>`\n }\n ${\n options.upscale\n ? html`<label class=\"field check\">\n <input data-field=\"upscale\" type=\"checkbox\" .checked=${target?.upscale ?? false} @change=${(e: Event) => commit({ upscale: (e.target as HTMLInputElement).checked })} />\n <span>${ctx.t('resize.upscale')}</span>\n </label>`\n : nothing\n }\n <sealpixel-button variant=\"ghost\" data-action=\"reset\" ?disabled=${target === null} .label=${ctx.t('resize.clear')} @click=${() => ctx.dispatch({ type: 'resize.clear', id: opId() })}>\n ${ctx.t('resize.clear')}\n </sealpixel-button>\n </div>\n ${\n options.presets.length > 0\n ? html`<div class=\"strip choice\" role=\"group\" aria-label=${ctx.t('resize.presets')}>\n ${options.presets.map(\n (p) =>\n html`<sealpixel-button data-preset=${p.label} variant=\"ghost\" ?pressed=${target?.width === (p.width ?? null) && target?.height === (p.height ?? null)} @click=${() => commit({ width: p.width ?? null, height: p.height ?? null })}>${p.label}</sealpixel-button>`,\n )}\n </div>`\n : nothing\n }\n `;\n },\n};\n"]}
|
|
1
|
+
{"version":3,"file":"resize.js","sourceRoot":"","sources":["../../src/tools/resize.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAsB,MAAM,oBAAoB,CAAC;AAChF,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,KAAK,CAAC;AACpC,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAEpC,OAAO,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AACrC,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAEhD;;;;;GAKG;AACH,SAAS,WAAW,CAAC,GAAkB;IACrC,MAAM,QAAQ,GAAG,GAAG,CAAC,KAAK,CAAC,QAAQ,CAAC;IACpC,IAAI,QAAQ,EAAE,CAAC;QACb,OAAO,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,QAAQ,CAAC,EAAE,SAAS,IAAI,QAAQ,CAAC,UAAU,CAAC;IAC5F,CAAC;IACD,OAAO,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC;AAC1B,CAAC;AAED,uFAAuF;AACvF,MAAM,iBAAiB,GAAG,GAAwB,EAAE,CAAC,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,CAA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ResizeOptions } from '@sealpixel/plugins';\nimport { html, nothing } from 'lit';\nimport { icons } from '../icons.js';\nimport type { UiTool, UiToolContext } from '../tool.js';\nimport { opId } from './finetune.js';\nimport { toolState } from './instance-state.js';\n\n/**\n * The size the resize stage receives: the image after crop, turn and every\n * other stage before it, in logical pixels. A linked resize keeps this aspect,\n * not the source's, because a crop or a quarter turn changes it. The source\n * size stands in until the first preview has a geometry.\n */\nfunction resizeInput(ctx: UiToolContext): { width: number; height: number } | null {\n const geometry = ctx.stage.geometry;\n if (geometry) {\n return geometry.stages.find((s) => s.name === 'resize')?.logicalIn ?? geometry.logicalOut;\n }\n return ctx.state.source;\n}\n\n/** Whether the two dimensions move together. Kept across panel renders, per editor. */\nconst createResizeState = (): { linked: boolean } => ({ linked: true });\n\nexport const resizeTool: UiTool = {\n id: 'resize',\n icon: icons.resize,\n label: 'tool.resize',\n panel: (ctx: UiToolContext) => {\n const target = (\n ctx.document as unknown as {\n resize: {\n target: {\n width: number | null;\n height: number | null;\n fit: string;\n upscale: boolean;\n } | null;\n };\n }\n ).resize.target;\n const options = ctx.options<ResizeOptions>('resize') ?? RESIZE_DEFAULT_OPTIONS;\n const state = toolState(ctx, createResizeState);\n const commit = (patch: Record<string, unknown>) =>\n ctx.dispatch({\n type: 'resize.set',\n id: opId(),\n ...(target === null ? { fit: options.defaultFit } : {}),\n ...patch,\n });\n const num = (e: Event) => {\n const v = (e.target as HTMLInputElement).value.trim();\n return v === '' ? null : Math.max(1, Math.round(Number(v)));\n };\n const input = resizeInput(ctx);\n const ratio = input && input.width > 0 ? input.height / input.width : 1;\n /**\n * With the link closed the two fields are one measurement: typing either\n * side writes both, so the log carries the size that will be rendered\n * rather than one number and a rule for finding the other.\n */\n const setWidth = (w: number | null) =>\n commit(\n state.linked && w !== null\n ? { width: w, height: Math.max(1, Math.round(w * ratio)) }\n : { width: w },\n );\n const setHeight = (h: number | null) =>\n commit(\n state.linked && h !== null\n ? { width: Math.max(1, Math.round(h / ratio)), height: h }\n : { height: h },\n );\n // The resting value is the size that comes out without a resize, so a\n // field never sits empty saying nothing about what will come out.\n const shownWidth = target?.width ?? input?.width ?? null;\n const shownHeight = target?.height ?? input?.height ?? null;\n const derived = (own: number | null | undefined) => (own == null ? 'derived' : '');\n return html`\n <div class=\"rows\">\n <div class=\"field\">\n <span>${ctx.t('resize.size')}</span>\n <div class=\"dims\">\n <input class=${derived(target?.width)} data-field=\"width\" type=\"number\" min=\"1\" max=${options.max?.width ?? nothing} inputmode=\"numeric\" aria-label=${ctx.t('resize.width')} .value=${shownWidth?.toString() ?? ''} @change=${(e: Event) => setWidth(num(e))} />\n <sealpixel-button\n variant=\"ghost\"\n data-action=\"link\"\n ?pressed=${state.linked}\n .label=${ctx.t(state.linked ? 'resize.linked' : 'resize.unlinked')}\n @click=${() => {\n state.linked = !state.linked;\n ctx.refresh();\n }}\n >${state.linked ? icons.link : icons.linkOff}</sealpixel-button\n >\n <input class=${derived(target?.height)} data-field=\"height\" type=\"number\" min=\"1\" max=${options.max?.height ?? nothing} inputmode=\"numeric\" aria-label=${ctx.t('resize.height')} .value=${shownHeight?.toString() ?? ''} @change=${(e: Event) => setHeight(num(e))} />\n </div>\n </div>\n ${\n // A closed link never squeezes the image, so there is nothing for a\n // fit mode to decide.\n state.linked\n ? nothing\n : html`<label class=\"field\">\n <span>${ctx.t('resize.fit')}</span>\n <select data-field=\"fit\" .value=${target?.fit ?? options.defaultFit} @change=${(e: Event) => commit({ fit: (e.target as HTMLSelectElement).value })}>\n ${options.fits.map((f) => html`<option value=${f} ?selected=${(target?.fit ?? options.defaultFit) === f}>${ctx.t(`resize.fit.${f}`)}</option>`)}\n </select>\n </label>`\n }\n ${\n options.upscale\n ? html`<label class=\"field check\">\n <input data-field=\"upscale\" type=\"checkbox\" .checked=${target?.upscale ?? false} @change=${(e: Event) => commit({ upscale: (e.target as HTMLInputElement).checked })} />\n <span>${ctx.t('resize.upscale')}</span>\n </label>`\n : nothing\n }\n <sealpixel-button variant=\"ghost\" data-action=\"reset\" ?disabled=${target === null} .label=${ctx.t('resize.clear')} @click=${() => ctx.dispatch({ type: 'resize.clear', id: opId() })}>\n ${ctx.t('resize.clear')}\n </sealpixel-button>\n </div>\n ${\n options.presets.length > 0\n ? html`<div class=\"strip choice\" role=\"group\" aria-label=${ctx.t('resize.presets')}>\n ${options.presets.map(\n (p) =>\n html`<sealpixel-button data-preset=${p.label} variant=\"ghost\" ?pressed=${target?.width === (p.width ?? null) && target?.height === (p.height ?? null)} @click=${() => commit({ width: p.width ?? null, height: p.height ?? null })}>${p.label}</sealpixel-button>`,\n )}\n </div>`\n : nothing\n }\n `;\n },\n};\n"]}
|
package/dist/tools/sticker.js
CHANGED
|
@@ -3,12 +3,13 @@ import { html, nothing, svg } from 'lit';
|
|
|
3
3
|
import { icons } from '../icons.js';
|
|
4
4
|
import { deleteHandle, toPx } from './delete-handle.js';
|
|
5
5
|
import { opId } from './finetune.js';
|
|
6
|
+
import { toolState } from './instance-state.js';
|
|
6
7
|
import { elementKeys, focusEditor, focusWhen } from './keys.js';
|
|
7
|
-
const
|
|
8
|
+
const createStickerState = () => ({
|
|
8
9
|
selected: null,
|
|
9
10
|
drag: null,
|
|
10
11
|
focusPending: null,
|
|
11
|
-
};
|
|
12
|
+
});
|
|
12
13
|
/**
|
|
13
14
|
* Stickers live in crop space, so the normal (cropped) preview is the right
|
|
14
15
|
* stage. Assets come from the plugin's declarations or from an upload, which
|
|
@@ -18,12 +19,14 @@ export const stickerTool = {
|
|
|
18
19
|
id: 'sticker',
|
|
19
20
|
icon: icons.sticker,
|
|
20
21
|
label: 'tool.sticker',
|
|
21
|
-
deactivate: () => {
|
|
22
|
+
deactivate: (ctx) => {
|
|
23
|
+
const state = toolState(ctx, createStickerState);
|
|
22
24
|
state.selected = null;
|
|
23
25
|
state.drag = null;
|
|
24
26
|
state.focusPending = null;
|
|
25
27
|
},
|
|
26
28
|
panel: (ctx) => {
|
|
29
|
+
const state = toolState(ctx, createStickerState);
|
|
27
30
|
const doc = ctx.document.sticker;
|
|
28
31
|
const options = ctx.options('sticker') ?? STICKER_DEFAULT_OPTIONS;
|
|
29
32
|
const declared = options.library.length > 0
|
|
@@ -83,6 +86,7 @@ export const stickerTool = {
|
|
|
83
86
|
`;
|
|
84
87
|
},
|
|
85
88
|
overlay: (ctx) => {
|
|
89
|
+
const state = toolState(ctx, createStickerState);
|
|
86
90
|
const doc = ctx.document.sticker;
|
|
87
91
|
const { width: W, height: H, zoom } = ctx.stage;
|
|
88
92
|
if (!W || !H)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sticker.js","sourceRoot":"","sources":["../../src/tools/sticker.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,uBAAuB,EAAuB,MAAM,oBAAoB,CAAC;AAClF,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,KAAK,CAAC;AACzC,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAEpC,OAAO,EAAE,YAAY,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AACrC,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAehE,MAAM,KAAK,GAYP;IACF,QAAQ,EAAE,IAAI;IACd,IAAI,EAAE,IAAI;IACV,YAAY,EAAE,IAAI;CACnB,CAAC;AAEF;;;;GAIG;AACH,MAAM,CAAC,MAAM,WAAW,GAAW;IACjC,EAAE,EAAE,SAAS;IACb,IAAI,EAAE,KAAK,CAAC,OAAO;IACnB,KAAK,EAAE,cAAc;IACrB,UAAU,EAAE,GAAG,EAAE;QACf,KAAK,CAAC,QAAQ,GAAG,IAAI,CAAC;QACtB,KAAK,CAAC,IAAI,GAAG,IAAI,CAAC;QAClB,KAAK,CAAC,YAAY,GAAG,IAAI,CAAC;IAC5B,CAAC;IACD,KAAK,EAAE,CAAC,GAAkB,EAAE,EAA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C,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,IAAI,IAAI,CAAC,GAAG,IAAI,EAAE,qCAAqC,KAAK,CAAC,IAAI,EAAE,MAAM,CAAC;YACrlB,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAA,mDAAmD,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,MAAM,EAAE,qEAAqE,EAAE,4CAA4C,KAAK,CAAC,IAAI,EAAE,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI;aACzQ,CAAC;QACR,CAAC,CAAC;QAEA,YAAY;YACV,CAAC,CAAC,YAAY,CACV,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,EAAE,KAAK,YAAY,CAAC,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,YAAY,CAAC,IAAI,EAAE,CAAC,EAAE,CAAC,CAAC,EACpF,GAAG,CAAC,KAAK,EACT,GAAG,CAAC,CAAC,CAAC,gBAAgB,CAAC,EACvB,GAAG,EAAE;gBACH,KAAK,CAAC,QAAQ,GAAG,IAAI,CAAC;gBACtB,GAAG,CAAC,QAAQ,CAAC,EAAE,IAAI,EAAE,gBAAgB,EAAE,EAAE,EAAE,IAAI,EAAE,EAAE,MAAM,EAAE,YAAY,CAAC,EAAE,EAAE,CAAC,CAAC;YAChF,CAAC,CACF;YACH,CAAC,CAAC,OACN;KACD,CAAC;IACJ,CAAC;CACF,CAAC","sourcesContent":["import type { Rect } from '@sealpixel/core';\nimport { STICKER_DEFAULT_OPTIONS, type StickerOptions } from '@sealpixel/plugins';\nimport { html, nothing, svg } from 'lit';\nimport { icons } from '../icons.js';\nimport type { UiTool, UiToolContext } from '../tool.js';\nimport { deleteHandle, toPx } from './delete-handle.js';\nimport { opId } from './finetune.js';\nimport { elementKeys, focusEditor, focusWhen } from './keys.js';\n\ninterface StickerItem {\n id: string;\n asset: string;\n rect: Rect;\n rotation: number;\n opacity: number;\n flipX: boolean;\n flipY: boolean;\n}\ninterface StickerDoc {\n items: StickerItem[];\n}\n\nconst state: {\n selected: string | null;\n /** A move or scale in progress; `keys` when the arrow keys drive it, so a pointer drag is told apart. */\n drag: {\n id: string;\n rect: Rect;\n mode: 'move' | 'scale';\n start: [number, number];\n keys?: true;\n } | null;\n /** The sticker that takes keyboard focus on the next render: just added, or next after a deletion. */\n focusPending: string | null;\n} = {\n selected: null,\n drag: null,\n focusPending: null,\n};\n\n/**\n * Stickers live in crop space, so the normal (cropped) preview is the right\n * stage. Assets come from the plugin's declarations or from an upload, which\n * is registered on the session and recorded in the log.\n */\nexport const stickerTool: UiTool = {\n id: 'sticker',\n icon: icons.sticker,\n label: 'tool.sticker',\n deactivate: () => {\n state.selected = null;\n state.drag = null;\n state.focusPending = null;\n },\n panel: (ctx: UiToolContext) => {\n const doc = (ctx.document as unknown as { sticker: StickerDoc }).sticker;\n const options = ctx.options<StickerOptions>('sticker') ?? STICKER_DEFAULT_OPTIONS;\n const declared =\n options.library.length > 0\n ? options.library\n : (ctx.session.registry.byId.get('sticker')?.assets ?? []);\n const uploaded = options.upload ? (ctx.state.history.log.assets ?? []) : [];\n const full = options.max !== null && doc.items.length >= options.max;\n const labelOf = (a: { id: string; label?: string | undefined }) =>\n a.label ?? a.id.replace(/^sticker\\./, '');\n const sel = doc.items.find((i) => i.id === state.selected) ?? null;\n const add = (asset: string) => {\n const id = opId();\n ctx.dispatch({\n type: 'sticker.add',\n id,\n asset,\n rect: { x: 0.35, y: 0.35, width: 0.3, height: 0.3 },\n });\n state.selected = id;\n state.focusPending = id;\n };\n const update = (patch: Partial<StickerItem>) =>\n sel && ctx.dispatch({ type: 'sticker.update', id: opId(), itemId: sel.id, ...patch });\n const upload = async (e: Event) => {\n const file = (e.target as HTMLInputElement).files?.[0];\n if (!file) return;\n const bytes = new Uint8Array(await file.arrayBuffer());\n const decl = await ctx.session.addAsset(bytes, {\n id: `sticker.${file.name\n .replace(/\\.[^.]+$/, '')\n .replace(/[^a-z0-9-]/gi, '-')\n .toLowerCase()}`,\n });\n add(decl.id);\n };\n return html`\n ${\n options.upload\n ? html`<label class=\"field\">\n <span>${ctx.t('sticker.upload')}</span>\n <input data-field=\"upload\" type=\"file\" accept=\"image/png,image/jpeg,image/webp\" ?disabled=${full} @change=${upload} />\n </label>`\n : nothing\n }\n ${\n declared.length + uploaded.length > 0\n ? html`<div class=\"grid choice\" role=\"list\" aria-label=${ctx.t('sticker.library')}>\n ${[...declared, ...uploaded].map((a) => html`<sealpixel-button role=\"listitem\" data-asset=${a.id} ?disabled=${full} @click=${() => add(a.id)}>${labelOf(a)}</sealpixel-button>`)}\n </div>`\n : html`<p class=\"hint\">${ctx.t('sticker.hint.empty')}</p>`\n }\n ${\n sel\n ? html`\n <sealpixel-slider data-param=\"rotation\" .label=${ctx.t('sticker.rotation')} .value=${Number(((sel.rotation * 180) / Math.PI).toFixed(1))} .min=${-180} .max=${180} .step=${1} .format=${(v: number) => `${v.toFixed(0)}°`} @commit=${(e: CustomEvent<number>) => update({ rotation: (e.detail * Math.PI) / 180 })}></sealpixel-slider>\n <sealpixel-slider data-param=\"opacity\" .label=${ctx.t('sticker.opacity')} .value=${sel.opacity} .min=${0} .max=${1} .step=${0.01} @commit=${(e: CustomEvent<number>) => update({ opacity: e.detail })}></sealpixel-slider>\n <div class=\"row\">\n <sealpixel-button data-action=\"flip-x\" ?pressed=${sel.flipX} @click=${() => update({ flipX: !sel.flipX })}>⇋</sealpixel-button>\n <sealpixel-button data-action=\"flip-y\" ?pressed=${sel.flipY} @click=${() => update({ flipY: !sel.flipY })}>⇅</sealpixel-button>\n </div>\n`\n : null\n }\n `;\n },\n overlay: (ctx: UiToolContext) => {\n const doc = (ctx.document as unknown as { sticker: StickerDoc }).sticker;\n const { width: W, height: H, zoom } = ctx.stage;\n if (!W || !H) return svg``;\n const sw = 1.5 / zoom;\n const hr = 7 / zoom;\n const toN = (e: PointerEvent): [number, number] => {\n const p = ctx.stage.toImage(e.clientX, e.clientY);\n return [p.x / W, p.y / H];\n };\n const begin = (item: StickerItem, mode: 'move' | 'scale') => (e: PointerEvent) => {\n e.stopPropagation();\n e.preventDefault();\n state.selected = item.id;\n // preventDefault above keeps the browser from focusing the sticker.\n if (mode === 'move') (e.currentTarget as SVGElement).focus({ preventScroll: true });\n const start = toN(e);\n state.drag = { id: item.id, rect: item.rect, mode, start };\n const move = (ev: PointerEvent) => {\n if (!state.drag) return;\n const q = toN(ev);\n const dx = q[0] - start[0];\n const dy = q[1] - start[1];\n state.drag.rect =\n mode === 'move'\n ? { ...item.rect, x: item.rect.x + dx, y: item.rect.y + dy }\n : {\n ...item.rect,\n width: Math.max(0.02, item.rect.width + dx),\n height: Math.max(0.02, item.rect.height + dy),\n };\n ctx.refresh();\n };\n const up = () => {\n window.removeEventListener('pointermove', move);\n window.removeEventListener('pointerup', up);\n window.removeEventListener('pointercancel', up);\n const d = state.drag;\n state.drag = null;\n if (d && JSON.stringify(d.rect) !== JSON.stringify(item.rect)) {\n ctx.dispatch({ type: 'sticker.update', id: opId(), itemId: item.id, rect: d.rect });\n }\n ctx.refresh();\n };\n window.addEventListener('pointermove', move);\n window.addEventListener('pointerup', up);\n window.addEventListener('pointercancel', up);\n };\n const selectedItem = doc.items.find((i) => i.id === state.selected) ?? null;\n return svg`\n <rect data-interactive x=\"0\" y=\"0\" width=${W} height=${H} fill=\"transparent\" @pointerdown=${(\n e: PointerEvent,\n ) => {\n e.stopPropagation();\n state.selected = null;\n ctx.refresh();\n }} />\n ${doc.items.map((item, i) => {\n const r = state.drag?.id === item.id ? state.drag.rect : item.rect;\n const selected = state.selected === item.id;\n // The keyboard moves the sticker through the same transient drag as the\n // pointer and commits one update when the key is released.\n const commit = () => {\n const d = state.drag;\n if (!d?.keys || d.id !== item.id) return;\n state.drag = null;\n if (JSON.stringify(d.rect) !== JSON.stringify(item.rect)) {\n ctx.dispatch({ type: 'sticker.update', id: opId(), itemId: item.id, rect: d.rect });\n }\n ctx.refresh();\n };\n const keys = elementKeys(ctx.stage, {\n select: () => {\n if (state.selected === item.id) return;\n state.selected = item.id;\n ctx.refresh();\n },\n move: (dx, dy) => {\n if (state.drag && !state.drag.keys) return;\n const base = state.drag?.id === item.id ? state.drag.rect : item.rect;\n // Unclamped, like the pointer move: a sticker may hang over the edge.\n const rect = { ...base, x: base.x + dx, y: base.y + dy };\n state.drag = { id: item.id, rect, mode: 'move', start: [0, 0], keys: true };\n ctx.refresh();\n },\n commit,\n remove: (el) => {\n commit();\n // Focus moves on before the sticker goes, so Tab stays in the editor.\n const next = doc.items[i + 1] ?? doc.items[i - 1] ?? null;\n state.selected = next?.id ?? null;\n state.focusPending = next?.id ?? null;\n if (!next) focusEditor(el);\n ctx.dispatch({ type: 'sticker.remove', id: opId(), itemId: item.id });\n },\n escape: () => {\n const open = state.selected !== null || !!state.drag?.keys;\n if (state.drag?.keys) state.drag = null;\n state.selected = null;\n ctx.refresh();\n return open;\n },\n });\n const cx = (r.x + r.width / 2) * W;\n const cy = (r.y + r.height / 2) * H;\n const deg = (item.rotation * 180) / Math.PI;\n return svg`<g transform=${`rotate(${deg} ${cx} ${cy})`}>\n <rect data-interactive data-item=${item.id} tabindex=\"0\" role=\"button\" aria-pressed=${selected ? 'true' : 'false'} aria-label=${ctx.t('sticker.item', { n: i + 1 })} ${focusWhen(state, item.id)} @focus=${keys.focus} @blur=${keys.blur} @keydown=${keys.keydown} @keyup=${keys.keyup} x=${r.x * W} y=${r.y * H} width=${r.width * W} height=${r.height * H} fill=\"rgba(255,255,255,0.001)\" stroke=${selected ? 'var(--sealpixel-color-accent)' : 'rgba(255,255,255,0.6)'} stroke-width=${sw} stroke-dasharray=${selected ? 'none' : `${4 / zoom} ${3 / zoom}`} style=\"cursor:move\" @pointerdown=${begin(item, 'move')} />\n ${selected ? svg`<circle data-interactive data-handle=\"scale\" cx=${(r.x + r.width) * W} cy=${(r.y + r.height) * H} r=${hr} fill=\"white\" stroke=\"var(--sealpixel-color-accent)\" stroke-width=${sw} style=\"cursor:nwse-resize\" @pointerdown=${begin(item, 'scale')} />` : null}\n </g>`;\n })}\n ${\n selectedItem\n ? deleteHandle(\n toPx(state.drag?.id === selectedItem.id ? state.drag.rect : selectedItem.rect, W, H),\n ctx.stage,\n ctx.t('sticker.delete'),\n () => {\n state.selected = null;\n ctx.dispatch({ type: 'sticker.remove', id: opId(), itemId: selectedItem.id });\n },\n )\n : nothing\n }\n `;\n },\n};\n"]}
|
|
1
|
+
{"version":3,"file":"sticker.js","sourceRoot":"","sources":["../../src/tools/sticker.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,uBAAuB,EAAuB,MAAM,oBAAoB,CAAC;AAClF,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,KAAK,CAAC;AACzC,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAEpC,OAAO,EAAE,YAAY,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AACrC,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAChD,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AA4BhE,MAAM,kBAAkB,GAAG,GAAiB,EAAE,CAAC,CAAC;IAC9C,QAAQ,EAAE,IAAI;IACd,IAAI,EAAE,IAAI;IACV,YAAY,EAAE,IAAI;CACnB,CAAC,CAAC;AAEH;;;;GAIG;AACH,MAAM,CAAC,MAAM,WAAW,GAAW;IACjC,EAAE,EAAE,SAAS;IACb,IAAI,EAAE,KAAK,CAAC,OAAO;IACnB,KAAK,EAAE,cAAc;IACrB,UAAU,EAAE,CAAC,GAAG,EAAE,EAAE;QAClB,MAAM,KAAK,GAAG,SAAS,CAAC,GAAG,EAAE,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AE,EAAE,MAAM,EAAE,YAAY,CAAC,EAAE,EAAE,CAAC,CAAC;YAChF,CAAC,CACF;YACH,CAAC,CAAC,OACN;KACD,CAAC;IACJ,CAAC;CACF,CAAC","sourcesContent":["import type { Rect } from '@sealpixel/core';\nimport { STICKER_DEFAULT_OPTIONS, type StickerOptions } from '@sealpixel/plugins';\nimport { html, nothing, svg } from 'lit';\nimport { icons } from '../icons.js';\nimport type { UiTool, UiToolContext } from '../tool.js';\nimport { deleteHandle, toPx } from './delete-handle.js';\nimport { opId } from './finetune.js';\nimport { toolState } from './instance-state.js';\nimport { elementKeys, focusEditor, focusWhen } from './keys.js';\n\ninterface StickerItem {\n id: string;\n asset: string;\n rect: Rect;\n rotation: number;\n opacity: number;\n flipX: boolean;\n flipY: boolean;\n}\ninterface StickerDoc {\n items: StickerItem[];\n}\n\ninterface StickerState {\n selected: string | null;\n /** A move or scale in progress; `keys` when the arrow keys drive it, so a pointer drag is told apart. */\n drag: {\n id: string;\n rect: Rect;\n mode: 'move' | 'scale';\n start: [number, number];\n keys?: true;\n } | null;\n /** The sticker that takes keyboard focus on the next render: just added, or next after a deletion. */\n focusPending: string | null;\n}\nconst createStickerState = (): StickerState => ({\n selected: null,\n drag: null,\n focusPending: null,\n});\n\n/**\n * Stickers live in crop space, so the normal (cropped) preview is the right\n * stage. Assets come from the plugin's declarations or from an upload, which\n * is registered on the session and recorded in the log.\n */\nexport const stickerTool: UiTool = {\n id: 'sticker',\n icon: icons.sticker,\n label: 'tool.sticker',\n deactivate: (ctx) => {\n const state = toolState(ctx, createStickerState);\n state.selected = null;\n state.drag = null;\n state.focusPending = null;\n },\n panel: (ctx: UiToolContext) => {\n const state = toolState(ctx, createStickerState);\n const doc = (ctx.document as unknown as { sticker: StickerDoc }).sticker;\n const options = ctx.options<StickerOptions>('sticker') ?? STICKER_DEFAULT_OPTIONS;\n const declared =\n options.library.length > 0\n ? options.library\n : (ctx.session.registry.byId.get('sticker')?.assets ?? []);\n const uploaded = options.upload ? (ctx.state.history.log.assets ?? []) : [];\n const full = options.max !== null && doc.items.length >= options.max;\n const labelOf = (a: { id: string; label?: string | undefined }) =>\n a.label ?? a.id.replace(/^sticker\\./, '');\n const sel = doc.items.find((i) => i.id === state.selected) ?? null;\n const add = (asset: string) => {\n const id = opId();\n ctx.dispatch({\n type: 'sticker.add',\n id,\n asset,\n rect: { x: 0.35, y: 0.35, width: 0.3, height: 0.3 },\n });\n state.selected = id;\n state.focusPending = id;\n };\n const update = (patch: Partial<StickerItem>) =>\n sel && ctx.dispatch({ type: 'sticker.update', id: opId(), itemId: sel.id, ...patch });\n const upload = async (e: Event) => {\n const file = (e.target as HTMLInputElement).files?.[0];\n if (!file) return;\n const bytes = new Uint8Array(await file.arrayBuffer());\n const decl = await ctx.session.addAsset(bytes, {\n id: `sticker.${file.name\n .replace(/\\.[^.]+$/, '')\n .replace(/[^a-z0-9-]/gi, '-')\n .toLowerCase()}`,\n });\n add(decl.id);\n };\n return html`\n ${\n options.upload\n ? html`<label class=\"field\">\n <span>${ctx.t('sticker.upload')}</span>\n <input data-field=\"upload\" type=\"file\" accept=\"image/png,image/jpeg,image/webp\" ?disabled=${full} @change=${upload} />\n </label>`\n : nothing\n }\n ${\n declared.length + uploaded.length > 0\n ? html`<div class=\"grid choice\" role=\"list\" aria-label=${ctx.t('sticker.library')}>\n ${[...declared, ...uploaded].map((a) => html`<sealpixel-button role=\"listitem\" data-asset=${a.id} ?disabled=${full} @click=${() => add(a.id)}>${labelOf(a)}</sealpixel-button>`)}\n </div>`\n : html`<p class=\"hint\">${ctx.t('sticker.hint.empty')}</p>`\n }\n ${\n sel\n ? html`\n <sealpixel-slider data-param=\"rotation\" .label=${ctx.t('sticker.rotation')} .value=${Number(((sel.rotation * 180) / Math.PI).toFixed(1))} .min=${-180} .max=${180} .step=${1} .format=${(v: number) => `${v.toFixed(0)}°`} @commit=${(e: CustomEvent<number>) => update({ rotation: (e.detail * Math.PI) / 180 })}></sealpixel-slider>\n <sealpixel-slider data-param=\"opacity\" .label=${ctx.t('sticker.opacity')} .value=${sel.opacity} .min=${0} .max=${1} .step=${0.01} @commit=${(e: CustomEvent<number>) => update({ opacity: e.detail })}></sealpixel-slider>\n <div class=\"row\">\n <sealpixel-button data-action=\"flip-x\" ?pressed=${sel.flipX} @click=${() => update({ flipX: !sel.flipX })}>⇋</sealpixel-button>\n <sealpixel-button data-action=\"flip-y\" ?pressed=${sel.flipY} @click=${() => update({ flipY: !sel.flipY })}>⇅</sealpixel-button>\n </div>\n`\n : null\n }\n `;\n },\n overlay: (ctx: UiToolContext) => {\n const state = toolState(ctx, createStickerState);\n const doc = (ctx.document as unknown as { sticker: StickerDoc }).sticker;\n const { width: W, height: H, zoom } = ctx.stage;\n if (!W || !H) return svg``;\n const sw = 1.5 / zoom;\n const hr = 7 / zoom;\n const toN = (e: PointerEvent): [number, number] => {\n const p = ctx.stage.toImage(e.clientX, e.clientY);\n return [p.x / W, p.y / H];\n };\n const begin = (item: StickerItem, mode: 'move' | 'scale') => (e: PointerEvent) => {\n e.stopPropagation();\n e.preventDefault();\n state.selected = item.id;\n // preventDefault above keeps the browser from focusing the sticker.\n if (mode === 'move') (e.currentTarget as SVGElement).focus({ preventScroll: true });\n const start = toN(e);\n state.drag = { id: item.id, rect: item.rect, mode, start };\n const move = (ev: PointerEvent) => {\n if (!state.drag) return;\n const q = toN(ev);\n const dx = q[0] - start[0];\n const dy = q[1] - start[1];\n state.drag.rect =\n mode === 'move'\n ? { ...item.rect, x: item.rect.x + dx, y: item.rect.y + dy }\n : {\n ...item.rect,\n width: Math.max(0.02, item.rect.width + dx),\n height: Math.max(0.02, item.rect.height + dy),\n };\n ctx.refresh();\n };\n const up = () => {\n window.removeEventListener('pointermove', move);\n window.removeEventListener('pointerup', up);\n window.removeEventListener('pointercancel', up);\n const d = state.drag;\n state.drag = null;\n if (d && JSON.stringify(d.rect) !== JSON.stringify(item.rect)) {\n ctx.dispatch({ type: 'sticker.update', id: opId(), itemId: item.id, rect: d.rect });\n }\n ctx.refresh();\n };\n window.addEventListener('pointermove', move);\n window.addEventListener('pointerup', up);\n window.addEventListener('pointercancel', up);\n };\n const selectedItem = doc.items.find((i) => i.id === state.selected) ?? null;\n return svg`\n <rect data-interactive x=\"0\" y=\"0\" width=${W} height=${H} fill=\"transparent\" @pointerdown=${(\n e: PointerEvent,\n ) => {\n e.stopPropagation();\n state.selected = null;\n ctx.refresh();\n }} />\n ${doc.items.map((item, i) => {\n const r = state.drag?.id === item.id ? state.drag.rect : item.rect;\n const selected = state.selected === item.id;\n // The keyboard moves the sticker through the same transient drag as the\n // pointer and commits one update when the key is released.\n const commit = () => {\n const d = state.drag;\n if (!d?.keys || d.id !== item.id) return;\n state.drag = null;\n if (JSON.stringify(d.rect) !== JSON.stringify(item.rect)) {\n ctx.dispatch({ type: 'sticker.update', id: opId(), itemId: item.id, rect: d.rect });\n }\n ctx.refresh();\n };\n const keys = elementKeys(ctx.stage, {\n select: () => {\n if (state.selected === item.id) return;\n state.selected = item.id;\n ctx.refresh();\n },\n move: (dx, dy) => {\n if (state.drag && !state.drag.keys) return;\n const base = state.drag?.id === item.id ? state.drag.rect : item.rect;\n // Unclamped, like the pointer move: a sticker may hang over the edge.\n const rect = { ...base, x: base.x + dx, y: base.y + dy };\n state.drag = { id: item.id, rect, mode: 'move', start: [0, 0], keys: true };\n ctx.refresh();\n },\n commit,\n remove: (el) => {\n commit();\n // Focus moves on before the sticker goes, so Tab stays in the editor.\n const next = doc.items[i + 1] ?? doc.items[i - 1] ?? null;\n state.selected = next?.id ?? null;\n state.focusPending = next?.id ?? null;\n if (!next) focusEditor(el);\n ctx.dispatch({ type: 'sticker.remove', id: opId(), itemId: item.id });\n },\n escape: () => {\n const open = state.selected !== null || !!state.drag?.keys;\n if (state.drag?.keys) state.drag = null;\n state.selected = null;\n ctx.refresh();\n return open;\n },\n });\n const cx = (r.x + r.width / 2) * W;\n const cy = (r.y + r.height / 2) * H;\n const deg = (item.rotation * 180) / Math.PI;\n return svg`<g transform=${`rotate(${deg} ${cx} ${cy})`}>\n <rect data-interactive data-item=${item.id} tabindex=\"0\" role=\"button\" aria-pressed=${selected ? 'true' : 'false'} aria-label=${ctx.t('sticker.item', { n: i + 1 })} ${focusWhen(state, item.id)} @focus=${keys.focus} @blur=${keys.blur} @keydown=${keys.keydown} @keyup=${keys.keyup} x=${r.x * W} y=${r.y * H} width=${r.width * W} height=${r.height * H} fill=\"rgba(255,255,255,0.001)\" stroke=${selected ? 'var(--sealpixel-color-accent)' : 'rgba(255,255,255,0.6)'} stroke-width=${sw} stroke-dasharray=${selected ? 'none' : `${4 / zoom} ${3 / zoom}`} style=\"cursor:move\" @pointerdown=${begin(item, 'move')} />\n ${selected ? svg`<circle data-interactive data-handle=\"scale\" cx=${(r.x + r.width) * W} cy=${(r.y + r.height) * H} r=${hr} fill=\"white\" stroke=\"var(--sealpixel-color-accent)\" stroke-width=${sw} style=\"cursor:nwse-resize\" @pointerdown=${begin(item, 'scale')} />` : null}\n </g>`;\n })}\n ${\n selectedItem\n ? deleteHandle(\n toPx(state.drag?.id === selectedItem.id ? state.drag.rect : selectedItem.rect, W, H),\n ctx.stage,\n ctx.t('sticker.delete'),\n () => {\n state.selected = null;\n ctx.dispatch({ type: 'sticker.remove', id: opId(), itemId: selectedItem.id });\n },\n )\n : nothing\n }\n `;\n },\n};\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sealpixel/ui",
|
|
3
|
-
"version": "1.0.0-rc.
|
|
3
|
+
"version": "1.0.0-rc.22",
|
|
4
4
|
"description": "Default, themeable Sealpixel editor UI as Web Components (Lit). Optional: the core is headless.",
|
|
5
5
|
"license": "BUSL-1.1",
|
|
6
6
|
"repository": {
|
|
@@ -36,13 +36,13 @@
|
|
|
36
36
|
"./themes/*": "./themes/*"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@sealpixel/core": "1.0.0-rc.
|
|
40
|
-
"@sealpixel/plugins": "1.0.0-rc.
|
|
39
|
+
"@sealpixel/core": "1.0.0-rc.22",
|
|
40
|
+
"@sealpixel/plugins": "1.0.0-rc.22",
|
|
41
41
|
"lit": "^3.3.0"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
44
|
"@sealpixel/config": "0.0.0",
|
|
45
|
-
"@sealpixel/wasm": "1.0.0-rc.
|
|
45
|
+
"@sealpixel/wasm": "1.0.0-rc.22",
|
|
46
46
|
"@types/node": "^24.0.0",
|
|
47
47
|
"typescript": "^6.0.0",
|
|
48
48
|
"vitest": "^5.0.0"
|