@printine/pod-editor 0.1.14 → 0.1.16
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 +27 -45
- package/dist/api/asset-client.d.ts +1 -1
- package/dist/components/context.d.ts +2 -2
- package/dist/components/design.d.ts +2 -2
- package/dist/components/preview/index.d.ts +2 -2
- package/dist/components/semi-renderer.d.ts +3 -1
- package/dist/components/upload-types.d.ts +20 -0
- package/dist/{design-C_TmcalT.js → design-CpQzcaGG.js} +5589 -5595
- package/dist/full-designer.js +2 -3
- package/dist/index.d.ts +1 -3
- package/dist/index.js +134 -146
- package/dist/lib/base-plate.d.ts +3 -0
- package/dist/{pixel-map-dSys7UAx.js → pixel-map-BLlgu5Ix.js} +3 -3
- package/dist/renderer/pixel-map.d.ts +3 -0
- package/dist/renderer/render-layer-output.d.ts +1 -0
- package/dist/{semi-interact-editor-DfzphWy3.js → semi-interact-editor-BVPJX2-9.js} +358 -350
- package/dist/semi-renderer.js +1 -1
- package/dist/style.css +1 -1
- package/dist/types.d.ts +3 -29
- package/docs/HOST_DATA_CONTRACT.md +77 -69
- package/docs/INTEGRATION_API.md +25 -27
- package/docs/SEMI_RENDERER.md +7 -2
- package/package.json +2 -11
- package/dist/api/client.d.ts +0 -8
- package/dist/api/client.js +0 -82
- package/dist/api/common-endpoints.d.ts +0 -12
- package/dist/api/design-endpoints.d.ts +0 -4
- package/dist/api/endpoints.d.ts +0 -23
- package/dist/api/endpoints.js +0 -33
- package/dist/api/files-endpoints.d.ts +0 -1
- package/dist/components/menus/ai.d.ts +0 -5
- package/dist/hooks/use-oss-upload.d.ts +0 -36
package/dist/full-designer.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import "react/jsx-runtime";
|
|
2
2
|
import "react";
|
|
3
|
-
import "./
|
|
4
|
-
import { b as s } from "./design-C_TmcalT.js";
|
|
3
|
+
import { c as l } from "./design-CpQzcaGG.js";
|
|
5
4
|
import "./engine/events.js";
|
|
6
5
|
import "zustand/react/shallow";
|
|
7
6
|
import "./engine/history.js";
|
|
@@ -10,5 +9,5 @@ import "./engine/constants.js";
|
|
|
10
9
|
import "./engine/utils/common.js";
|
|
11
10
|
import "./designer-store-Da9fICz8.js";
|
|
12
11
|
export {
|
|
13
|
-
|
|
12
|
+
l as default
|
|
14
13
|
};
|
package/dist/index.d.ts
CHANGED
|
@@ -16,10 +16,8 @@ export type { FontListProps } from './components/fonts';
|
|
|
16
16
|
export { SimpleSelect } from './ui/simple-select';
|
|
17
17
|
export { CanvasDesigner, renderPlacementPreviews } from './engine/canvas-designer';
|
|
18
18
|
export { Editor } from './engine/editor';
|
|
19
|
-
export { createDesignerApiClient } from './api/client';
|
|
20
19
|
export { createAssetCenterApiClient, DEFAULT_PRINTINE_ASSET_BASE_URL } from './api/asset-client';
|
|
21
20
|
export { AssetCenterApi, setAssetCenterApiClient } from './api/asset-endpoints';
|
|
22
|
-
export { CommonApi, DesignApi, setDesignerApiClient } from './api/endpoints';
|
|
23
21
|
export { HistoryManager } from './engine/history';
|
|
24
22
|
export { ALIGN_TYPES, DEFAULT_FILL_COLOR_LIST, DEFAULT_FONT_SIZE, ELEMENT_TITLE_MAP, FONT_WEIGHT, LAYER_BLACK_LIST, } from './engine/constants';
|
|
25
23
|
export { createEventBus, designerEventBus } from './engine/events';
|
|
@@ -37,7 +35,7 @@ export * from './engine/utils/font';
|
|
|
37
35
|
export { DEFAULT_DPI, inchToPixel, isSvg } from './engine/utils/measure';
|
|
38
36
|
export { Loading } from './engine/utils/loading';
|
|
39
37
|
export { getImageControls, setDefaultControls } from './engine/utils/setting';
|
|
40
|
-
export type {
|
|
38
|
+
export type { AssetCenterApiClient, AssetCenterApiClientOptions, AssetCenterApiResponse, AssetCenterPagination, DesignerAdapters, DesignerAsset, DesignerAssetsAdapter, DesignerError, DesignerEvent, DesignerImageUploadInput, DesignerImageUploadPurpose, DesignerImageUploadResult, DesignerImageMetadata, DesignerLibraryAdapters, DesignerShape, DesignerClipart, DesignerClipartCategory, DesignerPage, DesignerProductInfo, DesignerRenderPreviewInput, DesignerSaveInput, DesignerTemplatesAdapter, DesignerUserTemplate, DesignerRuntime, DesignDocument, PrintineDesignerProps, } from './types';
|
|
41
39
|
export type { AppEvents, DesignerEventBus } from './engine/events';
|
|
42
40
|
export type { EditorOptions } from './engine/editor';
|
|
43
41
|
export type { DesignerState } from './state/designer-store';
|
package/dist/index.js
CHANGED
|
@@ -1,99 +1,91 @@
|
|
|
1
|
-
import { AdvancedIText as
|
|
2
|
-
import { s as
|
|
3
|
-
import { F as
|
|
4
|
-
import { jsx as r, jsxs as
|
|
5
|
-
import { useMemo as
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
18
|
-
import {
|
|
19
|
-
import {
|
|
20
|
-
import {
|
|
21
|
-
import {
|
|
22
|
-
import {
|
|
23
|
-
import {
|
|
24
|
-
import {
|
|
25
|
-
import {
|
|
26
|
-
import {
|
|
27
|
-
import {
|
|
28
|
-
import {
|
|
29
|
-
import {
|
|
30
|
-
import {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
import { fabric as Pr } from "fabric";
|
|
34
|
-
function X(e) {
|
|
1
|
+
import { AdvancedIText as G } from "./engine/fabric.js";
|
|
2
|
+
import { a as S, s as f, D as L, b as _, c as C, C as F } from "./design-CpQzcaGG.js";
|
|
3
|
+
import { F as K, S as V, u as X } from "./design-CpQzcaGG.js";
|
|
4
|
+
import { jsx as r, jsxs as R } from "react/jsx-runtime";
|
|
5
|
+
import { useMemo as b, useEffect as a } from "react";
|
|
6
|
+
import { DEFAULT_PRINTINE_ASSET_BASE_URL as U, createAssetCenterApiClient as B } from "./api/asset-client.js";
|
|
7
|
+
import { s as d } from "./designer-store-Da9fICz8.js";
|
|
8
|
+
import { A as $, u as q } from "./designer-store-Da9fICz8.js";
|
|
9
|
+
import { d as y, s as M } from "./config-D2qm60gf.js";
|
|
10
|
+
import { P as Q, a as ee } from "./semi-interact-editor-BVPJX2-9.js";
|
|
11
|
+
import { P as te } from "./pixel-map-BLlgu5Ix.js";
|
|
12
|
+
import { CanvasDesigner as ae, renderPlacementPreviews as ne } from "./engine/canvas-designer.js";
|
|
13
|
+
import { Editor as ie } from "./engine/editor.js";
|
|
14
|
+
import { HistoryManager as me } from "./engine/history.js";
|
|
15
|
+
import { ALIGN_TYPES as de, DEFAULT_FILL_COLOR_LIST as ge, DEFAULT_FONT_SIZE as pe, ELEMENT_TITLE_MAP as ce, FONT_WEIGHT as ue, LAYER_BLACK_LIST as xe } from "./engine/constants.js";
|
|
16
|
+
import { createEventBus as Te, default as ve } from "./engine/events.js";
|
|
17
|
+
import { SnaplineManager as Ie } from "./engine/managers/snapline.js";
|
|
18
|
+
import { ResizeManager as Ae } from "./engine/managers/resize.js";
|
|
19
|
+
import { WorkspaceManager as Le } from "./engine/managers/workspace.js";
|
|
20
|
+
import { EventManager as Ce } from "./engine/managers/event.js";
|
|
21
|
+
import { ImageProcessor as Re } from "./engine/processors/image.js";
|
|
22
|
+
import { TextProcessor as Ue } from "./engine/processors/text.js";
|
|
23
|
+
import { TemplateProcessor as ye } from "./engine/processors/template.js";
|
|
24
|
+
import { blobToDataURL as Ne, blobUrlToFile as he, cloneObject as Oe, dataUrlToFile as ze, directionOffsetToXY as He, generateThumbImage as je, getCanvasSize as we, resizeBase64Image as ke, toHorizontalRaw as Ye, toVerticalStack as Ge, urlToBlob as We, urlToDataURL as Ke, xyToDirectionOffset as Ve } from "./engine/utils/common.js";
|
|
25
|
+
import { loadImage as Ze, loadOverlaySvgImage as $e, loadSvgImage as qe } from "./engine/utils/image.js";
|
|
26
|
+
import { fontCache as Qe, loadFontFile as er, loadFontface as rr } from "./engine/utils/font.js";
|
|
27
|
+
import { DEFAULT_DPI as or, inchToPixel as ar, isSvg as nr } from "./engine/utils/measure.js";
|
|
28
|
+
import { Loading as ir } from "./engine/utils/loading.js";
|
|
29
|
+
import { getImageControls as mr, setDefaultControls as fr } from "./engine/utils/setting.js";
|
|
30
|
+
import { fabric as gr } from "fabric";
|
|
31
|
+
function w(e) {
|
|
32
|
+
S(e.basePlate);
|
|
35
33
|
const {
|
|
36
|
-
productId:
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
onClose: F,
|
|
56
|
-
onEvent: p,
|
|
57
|
-
onAnalytics: f
|
|
58
|
-
} = e, s = c(() => M({ apiBaseUrl: i, locale: n }), [i, n]), g = c(() => O({ assetBaseUrl: l }), [l]);
|
|
34
|
+
productId: t,
|
|
35
|
+
assetBaseUrl: n = U,
|
|
36
|
+
locale: g,
|
|
37
|
+
imageBaseUrl: s,
|
|
38
|
+
threeDEnvironmentUrl: p,
|
|
39
|
+
basePlate: c,
|
|
40
|
+
loading: u = !1,
|
|
41
|
+
initialDesignData: x,
|
|
42
|
+
initialBackgroundCustomized: E,
|
|
43
|
+
productInfo: T,
|
|
44
|
+
adapters: o,
|
|
45
|
+
semiDesignPermission: v,
|
|
46
|
+
messages: D,
|
|
47
|
+
className: I,
|
|
48
|
+
children: P,
|
|
49
|
+
onClose: A,
|
|
50
|
+
onEvent: i,
|
|
51
|
+
onAnalytics: l
|
|
52
|
+
} = e, m = b(() => B({ assetBaseUrl: n }), [n]);
|
|
59
53
|
return a(() => {
|
|
60
|
-
|
|
61
|
-
}, [
|
|
62
|
-
...
|
|
54
|
+
i?.({ name: "ready", productId: t });
|
|
55
|
+
}, [i, t]), a(() => (d(m), () => d(null)), [m]), a(() => (f(l ?? null), () => f(null)), [l]), M({
|
|
56
|
+
...s !== void 0 ? { imageBaseUrl: s } : {}
|
|
63
57
|
}), /* @__PURE__ */ r(
|
|
64
|
-
|
|
58
|
+
L,
|
|
65
59
|
{
|
|
66
60
|
value: {
|
|
67
|
-
productId:
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
onClose: F,
|
|
61
|
+
productId: t,
|
|
62
|
+
initialDesignData: x,
|
|
63
|
+
initialBackgroundCustomized: E,
|
|
64
|
+
productInfo: T,
|
|
65
|
+
uploadImage: o?.uploadImage,
|
|
66
|
+
assets: o?.assets,
|
|
67
|
+
templates: o?.templates,
|
|
68
|
+
library: o?.library,
|
|
69
|
+
locale: g,
|
|
70
|
+
threeDEnvironmentUrl: p,
|
|
71
|
+
messages: D,
|
|
72
|
+
onClose: A,
|
|
80
73
|
onSave: e.onSave,
|
|
81
74
|
onRenderPreview: e.onRenderPreview,
|
|
82
75
|
onError: e.onError,
|
|
83
|
-
onEvent: e.onEvent
|
|
84
|
-
api: s
|
|
76
|
+
onEvent: e.onEvent
|
|
85
77
|
},
|
|
86
|
-
children: /* @__PURE__ */
|
|
78
|
+
children: /* @__PURE__ */ R(
|
|
87
79
|
"section",
|
|
88
80
|
{
|
|
89
|
-
className: ["printine-designer",
|
|
90
|
-
"data-product-id":
|
|
81
|
+
className: ["printine-designer", I].filter(Boolean).join(" "),
|
|
82
|
+
"data-product-id": t,
|
|
91
83
|
style: {
|
|
92
|
-
"--printine-designer-transparent-pattern": `url("${
|
|
84
|
+
"--printine-designer-transparent-pattern": `url("${y("/images/design/transparent_pattern.svg")}")`
|
|
93
85
|
},
|
|
94
86
|
children: [
|
|
95
|
-
/* @__PURE__ */ r("main", { className: "printine-designer__content", children:
|
|
96
|
-
/* @__PURE__ */ r(
|
|
87
|
+
/* @__PURE__ */ r("main", { className: "printine-designer__content", children: P ?? (u ? /* @__PURE__ */ r(_, {}) : /* @__PURE__ */ r(C, { basePlate: c, semiDesignPermission: v })) }),
|
|
88
|
+
/* @__PURE__ */ r(F, {})
|
|
97
89
|
]
|
|
98
90
|
}
|
|
99
91
|
)
|
|
@@ -101,68 +93,64 @@ function X(e) {
|
|
|
101
93
|
);
|
|
102
94
|
}
|
|
103
95
|
export {
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
mr as
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
or as urlToDataURL,
|
|
165
|
-
re as useDesignerRuntime,
|
|
166
|
-
ie as useDesignerStore,
|
|
167
|
-
tr as xyToDirectionOffset
|
|
96
|
+
de as ALIGN_TYPES,
|
|
97
|
+
G as AdvancedIText,
|
|
98
|
+
$ as AssetCenterApi,
|
|
99
|
+
ae as CanvasDesigner,
|
|
100
|
+
or as DEFAULT_DPI,
|
|
101
|
+
ge as DEFAULT_FILL_COLOR_LIST,
|
|
102
|
+
pe as DEFAULT_FONT_SIZE,
|
|
103
|
+
U as DEFAULT_PRINTINE_ASSET_BASE_URL,
|
|
104
|
+
L as DesignerRuntimeProvider,
|
|
105
|
+
ce as ELEMENT_TITLE_MAP,
|
|
106
|
+
ie as Editor,
|
|
107
|
+
Ce as EventManager,
|
|
108
|
+
ue as FONT_WEIGHT,
|
|
109
|
+
K as FontList,
|
|
110
|
+
C as FullDesigner,
|
|
111
|
+
me as HistoryManager,
|
|
112
|
+
Re as ImageProcessor,
|
|
113
|
+
xe as LAYER_BLACK_LIST,
|
|
114
|
+
ir as Loading,
|
|
115
|
+
te as PixelMapRenderer,
|
|
116
|
+
w as PrintineDesigner,
|
|
117
|
+
Q as PrintineSemiInteractEditor,
|
|
118
|
+
ee as PrintineSemiRenderer,
|
|
119
|
+
Ae as ResizeManager,
|
|
120
|
+
V as SimpleSelect,
|
|
121
|
+
Ie as SnaplineManager,
|
|
122
|
+
ye as TemplateProcessor,
|
|
123
|
+
Ue as TextProcessor,
|
|
124
|
+
Le as WorkspaceManager,
|
|
125
|
+
Ne as blobToDataURL,
|
|
126
|
+
he as blobUrlToFile,
|
|
127
|
+
Oe as cloneObject,
|
|
128
|
+
B as createAssetCenterApiClient,
|
|
129
|
+
Te as createEventBus,
|
|
130
|
+
ze as dataUrlToFile,
|
|
131
|
+
ve as designerEventBus,
|
|
132
|
+
He as directionOffsetToXY,
|
|
133
|
+
gr as fabric,
|
|
134
|
+
Qe as fontCache,
|
|
135
|
+
je as generateThumbImage,
|
|
136
|
+
we as getCanvasSize,
|
|
137
|
+
mr as getImageControls,
|
|
138
|
+
ar as inchToPixel,
|
|
139
|
+
nr as isSvg,
|
|
140
|
+
er as loadFontFile,
|
|
141
|
+
rr as loadFontface,
|
|
142
|
+
Ze as loadImage,
|
|
143
|
+
$e as loadOverlaySvgImage,
|
|
144
|
+
qe as loadSvgImage,
|
|
145
|
+
ne as renderPlacementPreviews,
|
|
146
|
+
ke as resizeBase64Image,
|
|
147
|
+
d as setAssetCenterApiClient,
|
|
148
|
+
fr as setDefaultControls,
|
|
149
|
+
Ye as toHorizontalRaw,
|
|
150
|
+
Ge as toVerticalStack,
|
|
151
|
+
We as urlToBlob,
|
|
152
|
+
Ke as urlToDataURL,
|
|
153
|
+
X as useDesignerRuntime,
|
|
154
|
+
q as useDesignerStore,
|
|
155
|
+
Ve as xyToDirectionOffset
|
|
168
156
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const h = `(function(){"use strict";class W{constructor(e=32*1024*1024,t=4,r){this.budget=e,this.concurrency=t,this.onEvict=r,this.entries=new Map,this.bytes=0,this.active=0,this.waiting=[],this.pinned=new Set}setPinnedSources(e){this.pinned=new Set(e),this.waiting.forEach(t=>{t.foreground=this.pinned.has(t.source)}),this.waiting.sort((t,r)=>Number(r.foreground)-Number(t.foreground)),this.trim()}trim(){for(const[e,t]of this.entries){if(this.bytes<=this.budget)break;!t.bytes||this.pinned.has(e)||(this.entries.delete(e),this.bytes-=t.bytes,this.onEvict?.(e))}}clear(){for(const e of this.waiting.splice(0))e.cancel();for(const e of this.entries.keys())this.onEvict?.(e);this.entries.clear(),this.pinned.clear(),this.bytes=0}promote(e){const t=this.waiting.findIndex(s=>s.source===e&&!s.foreground);if(t<0)return;const[r]=this.waiting.splice(t,1);r.foreground=!0;const o=this.waiting.findIndex(s=>!s.foreground);this.waiting.splice(o<0?this.waiting.length:o,0,r)}async fetchBlob(e,t){await new Promise((r,o)=>{const s=()=>{this.active+=1,r()};this.active<this.concurrency?s():(this.waiting.push({source:e,foreground:!1,start:s,cancel:()=>o(new Error("Resource cache was released"))}),t&&this.promote(e))});try{const r=await fetch(e);if(!r.ok)throw new Error(\`Could not load render asset (\${r.status})\`);return await r.blob()}finally{this.active-=1,this.waiting.shift()?.start()}}load(e,t=!0){const r=this.entries.get(e);if(r)return this.entries.delete(e),this.entries.set(e,r),t&&this.promote(e),r.ready;const o={ready:this.fetchBlob(e,t),bytes:0};return this.entries.set(e,o),o.ready.then(s=>{this.entries.get(e)===o&&(o.bytes=s.size,this.bytes+=o.bytes,this.trim())}).catch(()=>{this.entries.get(e)===o&&this.entries.delete(e)}),o.ready}}function I(n,e,t=!!n.texture){return!n.design||t||!!e}const v=44,H=32*1024*1024,w=new Map;let U=0;const N=new W;function x(n,e=0){return typeof n=="number"&&Number.isFinite(n)?n:e}function k(n,e=1){const t=x(n,e);return Math.max(0,Math.min(1,t>1?t/255:t))}function z(n=new Set){for(const[e,t]of w){if(U<=H)break;n.has(e)||!t.bitmap||(w.delete(e),U-=t.bytes,t.bitmap.close())}}async function M(n,e){if(!n)return null;if(n instanceof ImageBitmap)return n;e.add(n);let t=w.get(n);return t?(w.delete(n),w.set(n,t)):(t={bytes:0,promise:N.load(n).then(createImageBitmap)},w.set(n,t),t.promise.then(r=>{t.bitmap=r,t.bytes=r.width*r.height*4,U+=t.bytes}).catch(()=>w.delete(n))),t.promise}function V(n){const e=n;return!!e&&Array.isArray(e.uLines)&&e.uLines.length>=2&&Array.isArray(e.vLines)&&e.vLines.length>=2&&Array.isArray(e.grid)&&e.grid.length===e.vLines.length&&e.grid.every(t=>Array.isArray(t)&&t.length===e.uLines.length)}function $(n){const e=n;if(!e||!Array.isArray(e.vertices)||!Array.isArray(e.uvs)||!Array.isArray(e.indices)||!e.vertices.length||e.vertices.length%2!==0||e.uvs.length!==e.vertices.length||!e.indices.length||e.indices.length%3!==0)return!1;const t=e.vertices.length/2;return e.vertices.every(Number.isFinite)&&e.uvs.every(Number.isFinite)&&e.indices.every(r=>Number.isInteger(r)&&r>=0&&r<t&&r<=65535)}function j(n){return n.some(e=>e.some(t=>["r","l","u","d"].some(r=>{const o=t[r];return typeof o=="object"&&!!o.moved})))}function K(n,e){const t=n[e];return t?.moved?{dx:x(t.dx)-x(t.baseDx),dy:x(t.dy)-x(t.baseDy)}:{dx:0,dy:0}}function S(n,e,t,r,o){const s=1-o;return{x:s**3*n.x+3*s*s*o*e.x+3*s*o*o*t.x+o**3*r.x,y:s**3*n.y+3*s*s*o*e.y+3*s*o*o*t.y+o**3*r.y}}function Q(n,e,t,r,o,s){const h=(l,b)=>({dx:(b.x-l.x)/3,dy:(b.y-l.y)/3}),c=(l,b,T)=>{const g=h(l,b),f=K(l,T);return{x:l.x+g.dx+f.dx,y:l.y+g.dy+f.dy}},a=S(n,c(n,e,"r"),c(e,n,"l"),e,o),u=S(t,c(t,r,"r"),c(r,t,"l"),r,o),d=S(n,c(n,t,"d"),c(t,n,"u"),t,s),y=S(e,c(e,r,"d"),c(r,e,"u"),r,s),m={x:n.x*(1-o)*(1-s)+e.x*o*(1-s)+t.x*(1-o)*s+r.x*o*s,y:n.y*(1-o)*(1-s)+e.y*o*(1-s)+t.y*(1-o)*s+r.y*o*s};return{x:a.x*(1-s)+u.x*s+d.x*(1-o)+y.x*o-m.x,y:a.y*(1-s)+u.y*s+d.y*(1-o)+y.y*o-m.y}}function P(n,e){if(n.length<=2)return 0;let t=0,r=n.length;const o=e-1e-9;for(;t<r;){const s=t+r>>1;n[s]<o?t=s+1:r=s}return Math.min(Math.max(t-1,0),n.length-2)}function J(n,e,t,r){const o=P(n.uLines,e),s=P(n.vLines,t),h=n.uLines[o+1]-n.uLines[o],c=n.vLines[s+1]-n.vLines[s],a=h>1e-9?(e-n.uLines[o])/h:0,u=c>1e-9?(t-n.vLines[s])/c:0,[d,y]=[n.grid[s][o],n.grid[s][o+1]],[m,l]=[n.grid[s+1][o],n.grid[s+1][o+1]];return r?Q(d,y,m,l,a,u):{x:d.x*(1-a)*(1-u)+y.x*a*(1-u)+m.x*(1-a)*u+l.x*a*u,y:d.y*(1-a)*(1-u)+y.y*a*(1-u)+m.y*(1-a)*u+l.y*a*u}}function C(n){let e=1/0,t=1/0,r=-1/0,o=-1/0;for(const s of n)e=Math.min(e,s.x),t=Math.min(t,s.y),r=Math.max(r,s.x),o=Math.max(o,s.y);return{minX:e,minY:t,maxX:r,maxY:o}}function Z(n,e){const t=n.config??n.texture_transform??{},r=t.transform??{},o=n.textureSize??t.textureSize,s=x(o?.[0]),h=x(o?.[1]),c=e.width,a=e.height;if(!(s>0&&h>0&&c>0&&a>0&&(s!==c||h!==a)))return{...r};const d=s/c,y=h/a,m=Math.sqrt(d*y);return{...r,...typeof r.baseScale=="number"?{baseScale:r.baseScale*m}:{},...typeof r.scale=="number"?{scale:r.scale*m}:{},...typeof r.scaleX=="number"?{scaleX:r.scaleX*d}:{},...typeof r.scaleY=="number"?{scaleY:r.scaleY*y}:{}}}function q(n,e,t,r){if(r||!n.length)return n;const o=C(n),s={x:(o.minX+o.maxX)/2,y:(o.minY+o.maxY)/2},h=typeof e.scaleX=="number"?e.scaleX:typeof e.scale=="number"?e.scale:t,c=typeof e.scaleY=="number"?e.scaleY:typeof e.scale=="number"?e.scale:t,a=h/(t||1)*x(e.flipX,1),u=c/(t||1)*x(e.flipY,1),d=x(e.rotation)*Math.PI/180,y=Math.cos(d),m=Math.sin(d),l=n.map(f=>{const _=(f.x-s.x)*a,A=(f.y-s.y)*u;return{x:_*y-A*m+s.x,y:_*m+A*y+s.y}}),b=C(l),T=typeof e.translateX=="number"?e.translateX-b.minX:0,g=typeof e.translateY=="number"?e.translateY-b.minY:0;return T||g?l.map(f=>({x:f.x+T,y:f.y+g})):l}function ee(n,e){if(!$(e))return null;const t=new Float32Array(e.vertices.length);for(let r=0;r<e.vertices.length;r+=2)t[r]=n.x+e.vertices[r],t[r+1]=n.y+e.vertices[r+1];return{vertices:t,uvs:new Float32Array(e.uvs),indices:new Uint16Array(e.indices)}}function te(n,e){const t=n.config??n.texture_transform??{},r=ee(n,t);if(r)return r;const o=Z(n,e),s=V(t.mesh)?t.mesh:null;let h,c=x(o.baseScale,1);if(s){const g=j(s.grid);h=(f,_)=>J(s,f,_,g)}else{const g=Math.max(n.width/e.width,n.height/e.height);c=typeof o.baseScale=="number"?o.baseScale:Math.min(1,g);const f=e.width*c,_=e.height*c,A=(n.width-f)/2,L=(n.height-_)/2;h=(B,me)=>({x:A+f*B,y:L+_*me})}const a=[],u=new Float32Array((v+1)**2*2);let d=0;for(let g=0;g<=v;g+=1){const f=g/v;for(let _=0;_<=v;_+=1){const A=_/v;a.push(h(A,f)),u[d++]=A,u[d++]=f}}const y=q(a,o,c,!!o.baked),m=new Float32Array(y.length*2);y.forEach((g,f)=>{m[f*2]=n.x+g.x,m[f*2+1]=n.y+g.y});const l=new Uint16Array(v*v*6);let b=0;const T=v+1;for(let g=0;g<v;g+=1)for(let f=0;f<v;f+=1){const _=g*T+f,A=_+1,L=_+T,B=L+1;l[b++]=_,l[b++]=A,l[b++]=L,l[b++]=A,l[b++]=B,l[b++]=L}return{vertices:m,uvs:u,indices:l}}const E=new OffscreenCanvas(1,1),F=E.getContext("webgl2",{alpha:!0,antialias:!0,depth:!1,stencil:!1,premultipliedAlpha:!1,preserveDrawingBuffer:!0});if(!F)throw new Error("WebGL2 is unavailable in the render worker");const i=F,ne=\`#version 300 es
|
|
1
|
+
const h = `(function(){"use strict";class W{constructor(e=32*1024*1024,t=4,r){this.budget=e,this.concurrency=t,this.onEvict=r,this.entries=new Map,this.bytes=0,this.active=0,this.waiting=[],this.pinned=new Set}setPinnedSources(e){this.pinned=new Set(e),this.waiting.forEach(t=>{t.foreground=this.pinned.has(t.source)}),this.waiting.sort((t,r)=>Number(r.foreground)-Number(t.foreground)),this.trim()}trim(){for(const[e,t]of this.entries){if(this.bytes<=this.budget)break;!t.bytes||this.pinned.has(e)||(this.entries.delete(e),this.bytes-=t.bytes,this.onEvict?.(e))}}clear(){for(const e of this.waiting.splice(0))e.cancel();for(const e of this.entries.keys())this.onEvict?.(e);this.entries.clear(),this.pinned.clear(),this.bytes=0}promote(e){const t=this.waiting.findIndex(s=>s.source===e&&!s.foreground);if(t<0)return;const[r]=this.waiting.splice(t,1);r.foreground=!0;const o=this.waiting.findIndex(s=>!s.foreground);this.waiting.splice(o<0?this.waiting.length:o,0,r)}async fetchBlob(e,t){await new Promise((r,o)=>{const s=()=>{this.active+=1,r()};this.active<this.concurrency?s():(this.waiting.push({source:e,foreground:!1,start:s,cancel:()=>o(new Error("Resource cache was released"))}),t&&this.promote(e))});try{const r=await fetch(e);if(!r.ok)throw new Error(\`Could not load render asset (\${r.status})\`);return await r.blob()}finally{this.active-=1,this.waiting.shift()?.start()}}load(e,t=!0){const r=this.entries.get(e);if(r)return this.entries.delete(e),this.entries.set(e,r),t&&this.promote(e),r.ready;const o={ready:this.fetchBlob(e,t),bytes:0};return this.entries.set(e,o),o.ready.then(s=>{this.entries.get(e)===o&&(o.bytes=s.size,this.bytes+=o.bytes,this.trim())}).catch(()=>{this.entries.get(e)===o&&this.entries.delete(e)}),o.ready}}function I(n,e,t=!!n.texture){return!n.design||t||!!(e??n.color)}const v=44,H=32*1024*1024,w=new Map;let U=0;const N=new W;function x(n,e=0){return typeof n=="number"&&Number.isFinite(n)?n:e}function k(n,e=1){const t=x(n,e);return Math.max(0,Math.min(1,t>1?t/255:t))}function z(n=new Set){for(const[e,t]of w){if(U<=H)break;n.has(e)||!t.bitmap||(w.delete(e),U-=t.bytes,t.bitmap.close())}}async function M(n,e){if(!n)return null;if(n instanceof ImageBitmap)return n;e.add(n);let t=w.get(n);return t?(w.delete(n),w.set(n,t)):(t={bytes:0,promise:N.load(n).then(createImageBitmap)},w.set(n,t),t.promise.then(r=>{t.bitmap=r,t.bytes=r.width*r.height*4,U+=t.bytes}).catch(()=>w.delete(n))),t.promise}function V(n){const e=n;return!!e&&Array.isArray(e.uLines)&&e.uLines.length>=2&&Array.isArray(e.vLines)&&e.vLines.length>=2&&Array.isArray(e.grid)&&e.grid.length===e.vLines.length&&e.grid.every(t=>Array.isArray(t)&&t.length===e.uLines.length)}function $(n){const e=n;if(!e||!Array.isArray(e.vertices)||!Array.isArray(e.uvs)||!Array.isArray(e.indices)||!e.vertices.length||e.vertices.length%2!==0||e.uvs.length!==e.vertices.length||!e.indices.length||e.indices.length%3!==0)return!1;const t=e.vertices.length/2;return e.vertices.every(Number.isFinite)&&e.uvs.every(Number.isFinite)&&e.indices.every(r=>Number.isInteger(r)&&r>=0&&r<t&&r<=65535)}function j(n){return n.some(e=>e.some(t=>["r","l","u","d"].some(r=>{const o=t[r];return typeof o=="object"&&!!o.moved})))}function K(n,e){const t=n[e];return t?.moved?{dx:x(t.dx)-x(t.baseDx),dy:x(t.dy)-x(t.baseDy)}:{dx:0,dy:0}}function S(n,e,t,r,o){const s=1-o;return{x:s**3*n.x+3*s*s*o*e.x+3*s*o*o*t.x+o**3*r.x,y:s**3*n.y+3*s*s*o*e.y+3*s*o*o*t.y+o**3*r.y}}function Q(n,e,t,r,o,s){const h=(l,b)=>({dx:(b.x-l.x)/3,dy:(b.y-l.y)/3}),c=(l,b,T)=>{const g=h(l,b),f=K(l,T);return{x:l.x+g.dx+f.dx,y:l.y+g.dy+f.dy}},a=S(n,c(n,e,"r"),c(e,n,"l"),e,o),u=S(t,c(t,r,"r"),c(r,t,"l"),r,o),d=S(n,c(n,t,"d"),c(t,n,"u"),t,s),y=S(e,c(e,r,"d"),c(r,e,"u"),r,s),m={x:n.x*(1-o)*(1-s)+e.x*o*(1-s)+t.x*(1-o)*s+r.x*o*s,y:n.y*(1-o)*(1-s)+e.y*o*(1-s)+t.y*(1-o)*s+r.y*o*s};return{x:a.x*(1-s)+u.x*s+d.x*(1-o)+y.x*o-m.x,y:a.y*(1-s)+u.y*s+d.y*(1-o)+y.y*o-m.y}}function P(n,e){if(n.length<=2)return 0;let t=0,r=n.length;const o=e-1e-9;for(;t<r;){const s=t+r>>1;n[s]<o?t=s+1:r=s}return Math.min(Math.max(t-1,0),n.length-2)}function J(n,e,t,r){const o=P(n.uLines,e),s=P(n.vLines,t),h=n.uLines[o+1]-n.uLines[o],c=n.vLines[s+1]-n.vLines[s],a=h>1e-9?(e-n.uLines[o])/h:0,u=c>1e-9?(t-n.vLines[s])/c:0,[d,y]=[n.grid[s][o],n.grid[s][o+1]],[m,l]=[n.grid[s+1][o],n.grid[s+1][o+1]];return r?Q(d,y,m,l,a,u):{x:d.x*(1-a)*(1-u)+y.x*a*(1-u)+m.x*(1-a)*u+l.x*a*u,y:d.y*(1-a)*(1-u)+y.y*a*(1-u)+m.y*(1-a)*u+l.y*a*u}}function C(n){let e=1/0,t=1/0,r=-1/0,o=-1/0;for(const s of n)e=Math.min(e,s.x),t=Math.min(t,s.y),r=Math.max(r,s.x),o=Math.max(o,s.y);return{minX:e,minY:t,maxX:r,maxY:o}}function Z(n,e){const t=n.config??n.texture_transform??{},r=t.transform??{},o=n.textureSize??t.textureSize,s=x(o?.[0]),h=x(o?.[1]),c=e.width,a=e.height;if(!(s>0&&h>0&&c>0&&a>0&&(s!==c||h!==a)))return{...r};const d=s/c,y=h/a,m=Math.sqrt(d*y);return{...r,...typeof r.baseScale=="number"?{baseScale:r.baseScale*m}:{},...typeof r.scale=="number"?{scale:r.scale*m}:{},...typeof r.scaleX=="number"?{scaleX:r.scaleX*d}:{},...typeof r.scaleY=="number"?{scaleY:r.scaleY*y}:{}}}function q(n,e,t,r){if(r||!n.length)return n;const o=C(n),s={x:(o.minX+o.maxX)/2,y:(o.minY+o.maxY)/2},h=typeof e.scaleX=="number"?e.scaleX:typeof e.scale=="number"?e.scale:t,c=typeof e.scaleY=="number"?e.scaleY:typeof e.scale=="number"?e.scale:t,a=h/(t||1)*x(e.flipX,1),u=c/(t||1)*x(e.flipY,1),d=x(e.rotation)*Math.PI/180,y=Math.cos(d),m=Math.sin(d),l=n.map(f=>{const _=(f.x-s.x)*a,A=(f.y-s.y)*u;return{x:_*y-A*m+s.x,y:_*m+A*y+s.y}}),b=C(l),T=typeof e.translateX=="number"?e.translateX-b.minX:0,g=typeof e.translateY=="number"?e.translateY-b.minY:0;return T||g?l.map(f=>({x:f.x+T,y:f.y+g})):l}function ee(n,e){if(!$(e))return null;const t=new Float32Array(e.vertices.length);for(let r=0;r<e.vertices.length;r+=2)t[r]=n.x+e.vertices[r],t[r+1]=n.y+e.vertices[r+1];return{vertices:t,uvs:new Float32Array(e.uvs),indices:new Uint16Array(e.indices)}}function te(n,e){const t=n.config??n.texture_transform??{},r=ee(n,t);if(r)return r;const o=Z(n,e),s=V(t.mesh)?t.mesh:null;let h,c=x(o.baseScale,1);if(s){const g=j(s.grid);h=(f,_)=>J(s,f,_,g)}else{const g=Math.max(n.width/e.width,n.height/e.height);c=typeof o.baseScale=="number"?o.baseScale:Math.min(1,g);const f=e.width*c,_=e.height*c,A=(n.width-f)/2,L=(n.height-_)/2;h=(B,me)=>({x:A+f*B,y:L+_*me})}const a=[],u=new Float32Array((v+1)**2*2);let d=0;for(let g=0;g<=v;g+=1){const f=g/v;for(let _=0;_<=v;_+=1){const A=_/v;a.push(h(A,f)),u[d++]=A,u[d++]=f}}const y=q(a,o,c,!!o.baked),m=new Float32Array(y.length*2);y.forEach((g,f)=>{m[f*2]=n.x+g.x,m[f*2+1]=n.y+g.y});const l=new Uint16Array(v*v*6);let b=0;const T=v+1;for(let g=0;g<v;g+=1)for(let f=0;f<v;f+=1){const _=g*T+f,A=_+1,L=_+T,B=L+1;l[b++]=_,l[b++]=A,l[b++]=L,l[b++]=A,l[b++]=B,l[b++]=L}return{vertices:m,uvs:u,indices:l}}const E=new OffscreenCanvas(1,1),F=E.getContext("webgl2",{alpha:!0,antialias:!0,depth:!1,stencil:!1,premultipliedAlpha:!1,preserveDrawingBuffer:!0});if(!F)throw new Error("WebGL2 is unavailable in the render worker");const i=F,ne=\`#version 300 es
|
|
2
2
|
in vec2 a_position; in vec2 a_uv; uniform vec2 u_resolution;
|
|
3
3
|
out vec2 v_uv; out vec2 v_position;
|
|
4
4
|
void main() {
|
|
@@ -33,7 +33,7 @@ void main() {
|
|
|
33
33
|
source = vec4(designColor + fillColor * (1.0 - designAlpha), combinedAlpha);
|
|
34
34
|
}
|
|
35
35
|
out_color = source * u_opacity;
|
|
36
|
-
}\`;function X(n,e){const t=i.createShader(n);if(!t)throw new Error("Could not create WebGL shader");if(i.shaderSource(t,e),i.compileShader(t),!i.getShaderParameter(t,i.COMPILE_STATUS))throw new Error(i.getShaderInfoLog(t)||"WebGL shader compilation failed");return t}const p=i.createProgram();if(!p)throw new Error("Could not create WebGL program");if(i.attachShader(p,X(i.VERTEX_SHADER,ne)),i.attachShader(p,X(i.FRAGMENT_SHADER,ie)),i.linkProgram(p),!i.getProgramParameter(p,i.LINK_STATUS))throw new Error(i.getProgramInfoLog(p)||"WebGL program link failed");const D=i.getAttribLocation(p,"a_position"),Y=i.getAttribLocation(p,"a_uv"),re=i.getUniformLocation(p,"u_resolution"),oe=i.getUniformLocation(p,"u_image"),se=i.getUniformLocation(p,"u_mask"),ae=i.getUniformLocation(p,"u_mode"),ce=i.getUniformLocation(p,"u_opacity"),le=i.getUniformLocation(p,"u_tint"),ue=i.getUniformLocation(p,"u_mask_rect");function O(n,e=!1){if(e)return n;const t=i.createTexture();if(!t)throw new Error("Could not create WebGL texture");return i.bindTexture(i.TEXTURE_2D,t),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_WRAP_S,i.CLAMP_TO_EDGE),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_WRAP_T,i.CLAMP_TO_EDGE),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_MIN_FILTER,i.LINEAR),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_MAG_FILTER,i.LINEAR),i.pixelStorei(i.UNPACK_PREMULTIPLY_ALPHA_WEBGL,!0),i.texImage2D(i.TEXTURE_2D,0,i.RGBA,i.RGBA,i.UNSIGNED_BYTE,n),t}function fe(n){const e=String(n??"normal").toLowerCase();i.enable(i.BLEND),e==="multiply"||e==="2"?i.blendFuncSeparate(i.DST_COLOR,i.ONE_MINUS_SRC_ALPHA,i.ONE,i.ONE_MINUS_SRC_ALPHA):i.blendFuncSeparate(i.ONE,i.ONE_MINUS_SRC_ALPHA,i.ONE,i.ONE_MINUS_SRC_ALPHA)}function G(n){if(!n)return[1,1,1,1];const e=/^#([\\da-f]{3})$/i.exec(n),t=/^#([\\da-f]{6})$/i.exec(n),r=/^rgba?\\(\\s*(\\d+)\\s*,\\s*(\\d+)\\s*,\\s*(\\d+)/i.exec(n);let o=null;return e&&(o=e[1].split("").map(s=>Number.parseInt(s+s,16))),t&&(o=[t[1].slice(0,2),t[1].slice(2,4),t[1].slice(4,6)].map(s=>Number.parseInt(s,16))),r&&(o=[Number(r[1]),Number(r[2]),Number(r[3])]),o?[o[0]/255,o[1]/255,o[2]/255,1]:[1,1,1,1]}function de(n,e,t,r){return{vertices:new Float32Array([n,e,n+t,e,n,e+r,n+t,e+r]),uvs:new Float32Array([0,0,1,0,0,1,1,1]),indices:new Uint16Array([0,1,2,1,3,2])}}function R(n,e,t={}){i.useProgram(p),fe(t.blend);const r=i.createBuffer(),o=i.createBuffer(),s=i.createBuffer();if(!r||!o||!s)throw new Error("Could not allocate WebGL geometry");i.bindBuffer(i.ARRAY_BUFFER,r),i.bufferData(i.ARRAY_BUFFER,n.vertices,i.STREAM_DRAW),i.enableVertexAttribArray(D),i.vertexAttribPointer(D,2,i.FLOAT,!1,0,0),i.bindBuffer(i.ARRAY_BUFFER,o),i.bufferData(i.ARRAY_BUFFER,n.uvs,i.STATIC_DRAW),i.enableVertexAttribArray(Y),i.vertexAttribPointer(Y,2,i.FLOAT,!1,0,0),i.bindBuffer(i.ELEMENT_ARRAY_BUFFER,s),i.bufferData(i.ELEMENT_ARRAY_BUFFER,n.indices,i.STATIC_DRAW),i.activeTexture(i.TEXTURE0);const h=O(e,t.imageIsTexture);i.bindTexture(i.TEXTURE_2D,h),i.uniform1i(oe,0);let c=null;t.mask&&(i.activeTexture(i.TEXTURE1),c=O(t.mask),i.bindTexture(i.TEXTURE_2D,c),i.uniform1i(se,1)),i.uniform2f(re,E.width,E.height),i.uniform1i(ae,t.mode??0),i.uniform1f(ce,t.opacity??1),i.uniform4fv(le,t.tint??[1,1,1,1]),i.uniform4fv(ue,t.maskRect??[0,0,1,1]),i.drawElements(i.TRIANGLES,n.indices.length,i.UNSIGNED_SHORT,0),i.deleteBuffer(r),i.deleteBuffer(o),i.deleteBuffer(s),t.imageIsTexture||i.deleteTexture(h),c&&i.deleteTexture(c)}async function he(n){const e=n.areas.find(a=>a.name==="bg");if(!e)throw new Error("WebGL worker rendering requires a bg render area");const t=x(n.options.targetSize),r=t>0?t/Math.max(e.width,e.height):Math.max(.1,x(n.options.scale,1)),o=n.options.composition==="design-layer";E.width=Math.max(1,Math.round(e.width*r)),E.height=Math.max(1,Math.round(e.height*r)),i.viewport(0,0,E.width,E.height),i.bindFramebuffer(i.FRAMEBUFFER,null),i.clearColor(0,0,0,0),i.clear(i.COLOR_BUFFER_BIT);const s=new Set,h=new Set;for(const a of n.areas)o&&!a.design||I(a,n.options.color)&&(a.image&&h.add(a.image),typeof a.texture=="string"&&h.add(a.texture));await Promise.all([...h].map(a=>M(a,s)));const c=a=>de(a.x*r,a.y*r,a.width*r,a.height*r);try{for(const a of n.areas){if(o&&!a.design||!I(a,n.options.color))continue;const u=await M(a.image,s);if(!u)continue;if(!a.design){R(c(a),u,{blend:a.export?.blend,opacity:k(a.export?.opacity)});continue}const d=await M(a.texture,s),y=n.options.color;if(d){const m=a.config??a.texture_transform??{},l=te(a,d);for(let b=0;b<l.vertices.length;b+=1)l.vertices[b]*=r;o?R(l,d,{mode:1,mask:u,maskRect:[a.x*r,a.y*r,a.width*r,a.height*r],blend:"normal",opacity:k(m.opacity)}):y?R(l,d,{mode:3,mask:u,tint:G(y),maskRect:[a.x*r,a.y*r,a.width*r,a.height*r],blend:"multiply",opacity:k(m.opacity)}):R(l,d,{mode:1,mask:u,maskRect:[a.x*r,a.y*r,a.width*r,a.height*r],blend:o?"normal":m.blendMode,opacity:k(m.opacity)}),a.texture instanceof ImageBitmap&&d.close()}else y&&R(c(a),u,{mode:2,tint:G(y),blend:"multiply"})}i.finish();try{return await E.convertToBlob({type:n.options.format??"image/png",quality:n.options.quality??.9})}catch{return E.convertToBlob({type:"image/png"})}}finally{z(s)}}self.onmessage=async n=>{const e=n.data;if(e.type==="preload"){try{await Promise.all([...new Set(e.sources)].map(t=>w.has(t)?Promise.resolve():N.load(t,e.priority===!0))),self.postMessage({type:"preloaded",id:e.id})}catch(t){self.postMessage({type:"error",id:e.id,message:t instanceof Error?t.message:String(t)})}return}if(e.type==="render")try{self.postMessage({type:"result",id:e.id,blob:await he(e)})}catch(t){self.postMessage({type:"error",id:e.id,message:t instanceof Error?t.message:String(t)})}}})();
|
|
36
|
+
}\`;function X(n,e){const t=i.createShader(n);if(!t)throw new Error("Could not create WebGL shader");if(i.shaderSource(t,e),i.compileShader(t),!i.getShaderParameter(t,i.COMPILE_STATUS))throw new Error(i.getShaderInfoLog(t)||"WebGL shader compilation failed");return t}const p=i.createProgram();if(!p)throw new Error("Could not create WebGL program");if(i.attachShader(p,X(i.VERTEX_SHADER,ne)),i.attachShader(p,X(i.FRAGMENT_SHADER,ie)),i.linkProgram(p),!i.getProgramParameter(p,i.LINK_STATUS))throw new Error(i.getProgramInfoLog(p)||"WebGL program link failed");const D=i.getAttribLocation(p,"a_position"),Y=i.getAttribLocation(p,"a_uv"),re=i.getUniformLocation(p,"u_resolution"),oe=i.getUniformLocation(p,"u_image"),se=i.getUniformLocation(p,"u_mask"),ae=i.getUniformLocation(p,"u_mode"),ce=i.getUniformLocation(p,"u_opacity"),le=i.getUniformLocation(p,"u_tint"),ue=i.getUniformLocation(p,"u_mask_rect");function O(n,e=!1){if(e)return n;const t=i.createTexture();if(!t)throw new Error("Could not create WebGL texture");return i.bindTexture(i.TEXTURE_2D,t),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_WRAP_S,i.CLAMP_TO_EDGE),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_WRAP_T,i.CLAMP_TO_EDGE),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_MIN_FILTER,i.LINEAR),i.texParameteri(i.TEXTURE_2D,i.TEXTURE_MAG_FILTER,i.LINEAR),i.pixelStorei(i.UNPACK_PREMULTIPLY_ALPHA_WEBGL,!0),i.texImage2D(i.TEXTURE_2D,0,i.RGBA,i.RGBA,i.UNSIGNED_BYTE,n),t}function fe(n){const e=String(n??"normal").toLowerCase();i.enable(i.BLEND),e==="multiply"||e==="2"?i.blendFuncSeparate(i.DST_COLOR,i.ONE_MINUS_SRC_ALPHA,i.ONE,i.ONE_MINUS_SRC_ALPHA):i.blendFuncSeparate(i.ONE,i.ONE_MINUS_SRC_ALPHA,i.ONE,i.ONE_MINUS_SRC_ALPHA)}function G(n){if(!n)return[1,1,1,1];const e=/^#([\\da-f]{3})$/i.exec(n),t=/^#([\\da-f]{6})$/i.exec(n),r=/^rgba?\\(\\s*(\\d+)\\s*,\\s*(\\d+)\\s*,\\s*(\\d+)/i.exec(n);let o=null;return e&&(o=e[1].split("").map(s=>Number.parseInt(s+s,16))),t&&(o=[t[1].slice(0,2),t[1].slice(2,4),t[1].slice(4,6)].map(s=>Number.parseInt(s,16))),r&&(o=[Number(r[1]),Number(r[2]),Number(r[3])]),o?[o[0]/255,o[1]/255,o[2]/255,1]:[1,1,1,1]}function de(n,e,t,r){return{vertices:new Float32Array([n,e,n+t,e,n,e+r,n+t,e+r]),uvs:new Float32Array([0,0,1,0,0,1,1,1]),indices:new Uint16Array([0,1,2,1,3,2])}}function R(n,e,t={}){i.useProgram(p),fe(t.blend);const r=i.createBuffer(),o=i.createBuffer(),s=i.createBuffer();if(!r||!o||!s)throw new Error("Could not allocate WebGL geometry");i.bindBuffer(i.ARRAY_BUFFER,r),i.bufferData(i.ARRAY_BUFFER,n.vertices,i.STREAM_DRAW),i.enableVertexAttribArray(D),i.vertexAttribPointer(D,2,i.FLOAT,!1,0,0),i.bindBuffer(i.ARRAY_BUFFER,o),i.bufferData(i.ARRAY_BUFFER,n.uvs,i.STATIC_DRAW),i.enableVertexAttribArray(Y),i.vertexAttribPointer(Y,2,i.FLOAT,!1,0,0),i.bindBuffer(i.ELEMENT_ARRAY_BUFFER,s),i.bufferData(i.ELEMENT_ARRAY_BUFFER,n.indices,i.STATIC_DRAW),i.activeTexture(i.TEXTURE0);const h=O(e,t.imageIsTexture);i.bindTexture(i.TEXTURE_2D,h),i.uniform1i(oe,0);let c=null;t.mask&&(i.activeTexture(i.TEXTURE1),c=O(t.mask),i.bindTexture(i.TEXTURE_2D,c),i.uniform1i(se,1)),i.uniform2f(re,E.width,E.height),i.uniform1i(ae,t.mode??0),i.uniform1f(ce,t.opacity??1),i.uniform4fv(le,t.tint??[1,1,1,1]),i.uniform4fv(ue,t.maskRect??[0,0,1,1]),i.drawElements(i.TRIANGLES,n.indices.length,i.UNSIGNED_SHORT,0),i.deleteBuffer(r),i.deleteBuffer(o),i.deleteBuffer(s),t.imageIsTexture||i.deleteTexture(h),c&&i.deleteTexture(c)}async function he(n){const e=n.areas.find(a=>a.name==="bg");if(!e)throw new Error("WebGL worker rendering requires a bg render area");const t=x(n.options.targetSize),r=t>0?t/Math.max(e.width,e.height):Math.max(.1,x(n.options.scale,1)),o=n.options.composition==="design-layer";E.width=Math.max(1,Math.round(e.width*r)),E.height=Math.max(1,Math.round(e.height*r)),i.viewport(0,0,E.width,E.height),i.bindFramebuffer(i.FRAMEBUFFER,null),i.clearColor(0,0,0,0),i.clear(i.COLOR_BUFFER_BIT);const s=new Set,h=new Set;for(const a of n.areas)o&&!a.design||I(a,n.options.color)&&(a.image&&h.add(a.image),typeof a.texture=="string"&&h.add(a.texture));await Promise.all([...h].map(a=>M(a,s)));const c=a=>de(a.x*r,a.y*r,a.width*r,a.height*r);try{for(const a of n.areas){if(o&&!a.design||!I(a,n.options.color))continue;const u=await M(a.image,s);if(!u)continue;if(!a.design){R(c(a),u,{blend:a.export?.blend,opacity:k(a.export?.opacity)});continue}const d=await M(a.texture,s),y=n.options.color??a.color;if(d){const m=a.config??a.texture_transform??{},l=te(a,d);for(let b=0;b<l.vertices.length;b+=1)l.vertices[b]*=r;o?R(l,d,{mode:1,mask:u,maskRect:[a.x*r,a.y*r,a.width*r,a.height*r],blend:"normal",opacity:k(m.opacity)}):y?R(l,d,{mode:3,mask:u,tint:G(y),maskRect:[a.x*r,a.y*r,a.width*r,a.height*r],blend:"multiply",opacity:k(m.opacity)}):R(l,d,{mode:1,mask:u,maskRect:[a.x*r,a.y*r,a.width*r,a.height*r],blend:o?"normal":m.blendMode,opacity:k(m.opacity)}),a.texture instanceof ImageBitmap&&d.close()}else y&&R(c(a),u,{mode:2,tint:G(y),blend:"multiply"})}i.finish();try{return await E.convertToBlob({type:n.options.format??"image/png",quality:n.options.quality??.9})}catch{return E.convertToBlob({type:"image/png"})}}finally{z(s)}}self.onmessage=async n=>{const e=n.data;if(e.type==="preload"){try{await Promise.all([...new Set(e.sources)].map(t=>w.has(t)?Promise.resolve():N.load(t,e.priority===!0))),self.postMessage({type:"preloaded",id:e.id})}catch(t){self.postMessage({type:"error",id:e.id,message:t instanceof Error?t.message:String(t)})}return}if(e.type==="render")try{self.postMessage({type:"result",id:e.id,blob:await he(e)})}catch(t){self.postMessage({type:"error",id:e.id,message:t instanceof Error?t.message:String(t)})}}})();
|
|
37
37
|
`, m = typeof self < "u" && self.Blob && new Blob(["(self.URL || self.webkitURL).revokeObjectURL(self.location.href);", h], { type: "text/javascript;charset=utf-8" });
|
|
38
38
|
function b(i) {
|
|
39
39
|
let e;
|
|
@@ -55,7 +55,7 @@ function b(i) {
|
|
|
55
55
|
}
|
|
56
56
|
}
|
|
57
57
|
function x(i, e, t = !!i.texture) {
|
|
58
|
-
return !i.design || t || !!e;
|
|
58
|
+
return !i.design || t || !!(e ?? i.color);
|
|
59
59
|
}
|
|
60
60
|
function f(i) {
|
|
61
61
|
if (!i) return i;
|
|
@@ -5,9 +5,12 @@ import type { RenderArea } from '../contracts/api-design';
|
|
|
5
5
|
*/
|
|
6
6
|
export type PixelMapArea = Omit<RenderArea, 'texture'> & {
|
|
7
7
|
texture?: string | ImageBitmap;
|
|
8
|
+
/** This printable placement's fill; never inferred from another placement. */
|
|
9
|
+
color?: string;
|
|
8
10
|
config?: Record<string, unknown>;
|
|
9
11
|
};
|
|
10
12
|
export interface PixelMapRenderOptions {
|
|
13
|
+
/** Explicit global override; omission preserves each area's own fill. */
|
|
11
14
|
color?: string;
|
|
12
15
|
scale?: number;
|
|
13
16
|
/** Longest output edge in CSS-independent pixels. */
|