@printine/pod-editor 0.1.19 → 0.1.21
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 +8 -0
- package/dist/components/context.d.ts +7 -0
- package/dist/components/menus/sca.d.ts +2 -4
- package/dist/components/personalization-background.d.ts +6 -0
- package/dist/components/personalization-controller.d.ts +2 -0
- package/dist/components/personalization-preview.d.ts +5 -0
- package/dist/components/personalization-shared.d.ts +3 -0
- package/dist/components/preview/real-time/index.d.ts +2 -1
- package/dist/components/semi-deisgn-config.d.ts +8 -2
- package/dist/{design-BXbmX1Tb.js → design-zuaYzDgn.js} +8687 -8449
- package/dist/designer-store-BZFMaojO.js +261 -0
- package/dist/engine/constants.js +1 -1
- package/dist/engine/editor.js +120 -116
- package/dist/engine/events.d.ts +6 -0
- package/dist/engine/managers/event.js +1 -1
- package/dist/full-designer.js +3 -3
- package/dist/i18n/personalization.d.ts +3 -0
- package/dist/index.js +6 -6
- package/dist/lib/personalization.d.ts +78 -0
- package/dist/personalization-preview-D9z7Ketn.js +352 -0
- package/dist/pixel-map-CSpWvUYE.js +315 -0
- package/dist/{pixi-print-base-CKs4lF7h.js → pixi-print-base-DIvtSF7v.js} +1 -1
- package/dist/renderer/pixel-map.d.ts +9 -2
- package/dist/{semi-interact-editor-nZVBXXQn.js → semi-interact-editor-DpzQN5ZB.js} +2 -2
- package/dist/semi-renderer.js +1 -1
- package/dist/state/designer-store.d.ts +2 -0
- package/dist/state/designer-store.js +1 -1
- package/dist/style.css +1 -1
- package/docs/BUYER_PERSONALIZATION.md +137 -0
- package/docs/HOST_DATA_CONTRACT.md +1 -1
- package/docs/SEMI_RENDERER.md +37 -1
- package/package.json +3 -1
- package/dist/designer-store-Da9fICz8.js +0 -153
- package/dist/pixel-map-BvQ0VU_i.js +0 -199
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
# Buyer personalization experience
|
|
2
|
+
|
|
3
|
+
This document describes the buyer personalization workflow included in
|
|
4
|
+
`@printine/pod-editor@0.1.21`. Existing saved customization formats and host
|
|
5
|
+
integration callbacks are preserved. Consuming applications can adopt the
|
|
6
|
+
workflow by upgrading the SDK.
|
|
7
|
+
|
|
8
|
+
## Merchant flow
|
|
9
|
+
|
|
10
|
+
For `semiDesignPermission={true}`, the former Custom menu is now
|
|
11
|
+
**Personalization**. It starts with a setup guide and a list grouped by print
|
|
12
|
+
placement. Cards display the layer name, thumbnail, fixed/editable state and a
|
|
13
|
+
permission switch. Background color is explicitly labeled as applying to all
|
|
14
|
+
print areas.
|
|
15
|
+
|
|
16
|
+
Select a supported canvas element to see its permission switch and settings
|
|
17
|
+
button beside the normal editing tools. Open settings from either that button
|
|
18
|
+
or its management card. Basic settings contain the buyer-facing label,
|
|
19
|
+
description, text hint and character limit. Advanced settings contain movement,
|
|
20
|
+
color, font and preset choices. Existing linked-element configuration remains
|
|
21
|
+
available, with explicit unlink actions and placement labels.
|
|
22
|
+
|
|
23
|
+
While **Personalization** is active, the floating **Product preview** is hidden;
|
|
24
|
+
its renderer stays mounted and returns when another menu is selected. On screens
|
|
25
|
+
at least 1100 CSS pixels wide, selecting a canvas element or its placement card
|
|
26
|
+
opens a right-hand settings inspector instead of a modal. Each placement also
|
|
27
|
+
has an explicit **Edit** action. The inspector shows the element name, print
|
|
28
|
+
area and permission status. Valid changes apply immediately; incomplete or
|
|
29
|
+
invalid rules display an inline message and keep the last valid rules. Narrower
|
|
30
|
+
screens retain the settings dialog and its explicit Save action. The separate
|
|
31
|
+
buyer preview remains available from either layout.
|
|
32
|
+
|
|
33
|
+
Background color uses the same settings location: its left-hand card only shows
|
|
34
|
+
the permission and status. Selecting it opens the right-hand inspector (or the
|
|
35
|
+
settings dialog on narrow screens), where the merchant manages allowed colors
|
|
36
|
+
and the any-color permission. Its scope remains **All print areas**. Background
|
|
37
|
+
selection clears the canvas element selection; selecting an element switches
|
|
38
|
+
the inspector back to that element. Dialog changes use Save/Cancel, while the
|
|
39
|
+
desktop inspector applies changes immediately. Disabling background
|
|
40
|
+
personalization preserves its color choices for re-enabling.
|
|
41
|
+
|
|
42
|
+
New text/image fields retain the template position, size and styling by default.
|
|
43
|
+
Restored configurations retain their existing permissions, including legacy
|
|
44
|
+
`moveable: true` values and unknown host fields. Switching a field off retains
|
|
45
|
+
its rules only in editor memory, so switching it on restores them. Unmounting
|
|
46
|
+
or switching products clears these temporary drafts. Disabled rules do not
|
|
47
|
+
appear in the saved-style preview document.
|
|
48
|
+
|
|
49
|
+
Ordinary products (`semiDesignPermission={false}`) do not display personalization
|
|
50
|
+
controls. Menu availability is instance-specific; enabling it no longer mutates
|
|
51
|
+
a module-level menu array shared with later products.
|
|
52
|
+
|
|
53
|
+
## Buyer preview
|
|
54
|
+
|
|
55
|
+
**Preview buyer experience** is a separate action from **Product preview** and
|
|
56
|
+
from the existing Next/Done save workflow. It uses an isolated JSON snapshot,
|
|
57
|
+
`PrintineSemiRenderer`, and `PrintineSemiInteractEditor` for real Fabric text
|
|
58
|
+
fitting, image composition and allowed position changes. Text, font, color,
|
|
59
|
+
image and placement changes do not update the merchant canvas or its history.
|
|
60
|
+
|
|
61
|
+
The preview provides desktop and phone layouts. The phone form includes a
|
|
62
|
+
sticky live thumbnail, so the current product effect remains visible while
|
|
63
|
+
editing lower fields. Print views can be selected explicitly and switch to the
|
|
64
|
+
relevant placement when its input receives focus. Linked fields use one input
|
|
65
|
+
with all affected placement labels and apply edits to all linked targets.
|
|
66
|
+
|
|
67
|
+
When a base plate has no 2D product renders, the preview composes a flat print
|
|
68
|
+
area with the same local Fabric/rendering path and labels it **Print area
|
|
69
|
+
preview**. This is not a 3D material or product mockup. Rendering failures show
|
|
70
|
+
a retry control and are reported through the host's existing `onError` callback
|
|
71
|
+
with code `BUYER_PREVIEW_RENDER_FAILED`.
|
|
72
|
+
|
|
73
|
+
Free image selection uses temporary object URLs in the browser. It never calls
|
|
74
|
+
`adapters.uploadImage`, `onSave`, a cart API or an order API. All preview object
|
|
75
|
+
URLs are revoked when the preview closes. Text updates are serialized, discard
|
|
76
|
+
stale requests and are invalidated on reset/unmount.
|
|
77
|
+
|
|
78
|
+
## Existing contract
|
|
79
|
+
|
|
80
|
+
The saved `customConfig` and `background_customized` formats are unchanged.
|
|
81
|
+
The implementation uses the existing fields:
|
|
82
|
+
|
|
83
|
+
- `name`, `description`, `hintText`, `maxCount`;
|
|
84
|
+
- `enableOption`, `options` and `syncKey`;
|
|
85
|
+
- `enableOptionalFont`, `optionalFontList` and `enableColor`;
|
|
86
|
+
- `moveable` for movement, resizing and rotation together;
|
|
87
|
+
- background `enable`, `colors` and `palette`.
|
|
88
|
+
|
|
89
|
+
The prototype's independent move/scale switches and required-field proposals
|
|
90
|
+
are not new persisted capabilities in this SDK change. Separate permissions or
|
|
91
|
+
required validation would also need support in the consuming buyer application.
|
|
92
|
+
This implementation presents the combined existing placement permission and
|
|
93
|
+
validates merchant labels, character limits, presets and font choices.
|
|
94
|
+
|
|
95
|
+
The new experience uses the SDK existing localization configuration: English
|
|
96
|
+
by default and its existing Spanish catalog. It adds no locales and does not
|
|
97
|
+
force a `locale` value. Host `locale` and `messages` overrides retain their
|
|
98
|
+
existing precedence. The validation page also omits `locale` by default; its
|
|
99
|
+
optional locale selector is derived from `DESIGNER_MESSAGES`.
|
|
100
|
+
|
|
101
|
+
## Local verification page
|
|
102
|
+
|
|
103
|
+
From the repository:
|
|
104
|
+
|
|
105
|
+
```sh
|
|
106
|
+
npm run dev:personalization
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
Open `http://127.0.0.1:18887/tests/personalization.html`.
|
|
110
|
+
|
|
111
|
+
The page mounts the real source SDK with synthetic, browser-local assets and
|
|
112
|
+
in-memory host adapters. Its LOCAL QA controls switch first-use/configured
|
|
113
|
+
scenarios, language, product mode, and presence of 2D mockups. The unmount button
|
|
114
|
+
releases the editor and its normal unsaved-change guard before reloading the
|
|
115
|
+
fixture during development. No store or credentials are needed.
|
|
116
|
+
|
|
117
|
+
Relevant checks:
|
|
118
|
+
|
|
119
|
+
```sh
|
|
120
|
+
npm run typecheck
|
|
121
|
+
npm run build
|
|
122
|
+
npm run test:personalization
|
|
123
|
+
npm run test:api
|
|
124
|
+
npm run test:semi-renderer
|
|
125
|
+
npm run test:preview-assets
|
|
126
|
+
npm run test:workspace-pattern
|
|
127
|
+
npm run test:render-preload
|
|
128
|
+
npm run test:print-base
|
|
129
|
+
npm run test:semi-bundle
|
|
130
|
+
npm run pack:check
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
The new regression checks cover conservative defaults, legacy rule preservation,
|
|
134
|
+
disabled draft reset, linked fields across placements, immutable preview
|
|
135
|
+
snapshots, fixed artwork, per-placement patches, and replacement image bounds.
|
|
136
|
+
The existing API test loader now loads the real personalization helper used by
|
|
137
|
+
the store; its endpoint and credential assertions are unchanged.
|
|
@@ -245,7 +245,7 @@ interface RenderArea {
|
|
|
245
245
|
}
|
|
246
246
|
```
|
|
247
247
|
|
|
248
|
-
对于实时 2D 合成,`image`、`texture`、坐标尺寸和 `area.name` 都应返回。`name === "bg"` 的 `image`
|
|
248
|
+
对于实时 2D 合成,`image`、`texture`、坐标尺寸和 `area.name` 都应返回。`name === "bg"` 的 `image` 也会在合成尚未完成时作为预览回退图。`render_areas[].image` 可以是 PNG、JPEG、WebP 或 SVG;SVG 图层会在主线程按合成像素尺寸栅格化后再参与合成,SVG 文件应声明 `width`/`height`(不能只有 `viewBox`),以便所有浏览器都能栅格化。
|
|
249
249
|
|
|
250
250
|
### 3D 渲染:`TDRender` 与 `TDRenderArea`
|
|
251
251
|
|
package/docs/SEMI_RENDERER.md
CHANGED
|
@@ -76,7 +76,7 @@ Worker 解码都使用这些本地 URL,不再各自请求远程图片。宿主
|
|
|
76
76
|
宿主只需切换 `render` 到当前视角,其他视角不必挂载渲染器。修改设计后,宿主按
|
|
77
77
|
版本标记旧结果失效;切换到已缓存的最新结果时保持 `enabled={false}`,直接展示缓存图。
|
|
78
78
|
暂停会清除旧待执行任务,并阻止正在执行的过期结果发布,但不会销毁会话资源缓存。
|
|
79
|
-
`
|
|
79
|
+
`enabled` 默认 `true`。设为 `false` 只暂停合成,不销毁文字适配用的 Fabric 编辑器,因此 `updateText()` 在暂停时仍可调用。
|
|
80
80
|
|
|
81
81
|
非当前视角压缩资源采用 32 MiB LRU 预算,当前视角与在执行任务的资源会保留,即使
|
|
82
82
|
单个视角超过预算,也不会因后台预加载完成而被淘汰。网络最多同时加载 4 个资源;当前图的请求优先于
|
|
@@ -128,6 +128,42 @@ Worker 解码都使用这些本地 URL,不再各自请求远程图片。宿主
|
|
|
128
128
|
- `getPreviewUrl()`:为当前结果新建 object URL。调用方负责 `URL.revokeObjectURL()`。
|
|
129
129
|
- `refresh()`:当图片 URL 的内容原地更新、但 `designData` 引用不变时,使 Fabric
|
|
130
130
|
纹理和 Worker 资源缓存失效并强制重新合成。
|
|
131
|
+
- `updateText(rawObject, changes)`:按半定制规则计算文字补丁。它不修改 `designData`,
|
|
132
|
+
也不触发渲染。宿主把返回值合并进对应 Fabric 对象后,再把新的 `designData` 交给渲染器。
|
|
133
|
+
|
|
134
|
+
### `updateText`
|
|
135
|
+
|
|
136
|
+
只接受 `type` 为 `text`,或 `type` 字符串中包含 `i-text` 的对象(含 `advanced-i-text`)。
|
|
137
|
+
其他类型、对象无法恢复,或内部画布尚未挂载时返回 `null`。`changes` 会先作用于恢复出的对象,
|
|
138
|
+
常见字段是 `text`、`fill`、`fontFamily`、`fontWeight`、`fontStyle`。`changes.fontPath`
|
|
139
|
+
有值时,会先按 `fontFamily`、`fontWeight`、`fontStyle` 加载字体。
|
|
140
|
+
|
|
141
|
+
不要只改对象里的 `text`。Fabric 会沿用原来的 `width` 和缩放,更长的字符串会被裁进旧宽度。
|
|
142
|
+
|
|
143
|
+
固定框由对象自己的 `customConfig` 决定:`originalWidth` 与 `originalHeight` 都是大于 0 的数,
|
|
144
|
+
且 `moveable` 不为真。此时把未缩放文字放进这个框里,取宽、高两个方向里更小的缩放(contain),
|
|
145
|
+
再放回框中心。翻转由原来的 `scaleX` / `scaleY` 符号保留。中心和翻转符号会写入返回的
|
|
146
|
+
`__semiTargetInfo`;宿主必须保留该字段,下次更新才会继续锁在这个中心。丢掉它时,中心改取对象当前的 `getCenterPoint()`。
|
|
147
|
+
|
|
148
|
+
不满足固定框条件时不做框内适配,只更新内容和字体并重新测量。普通文字保持原锚点;
|
|
149
|
+
带 `radius` 的 `advanced-i-text` 保持中心点。
|
|
150
|
+
|
|
151
|
+
返回值在 `changes` 之上覆盖这些几何字段,宿主应整份合并:
|
|
152
|
+
|
|
153
|
+
- `text`、`left`、`top`、`width`、`height`
|
|
154
|
+
- `scaleX`、`scaleY`、`angle`、`originX`、`originY`
|
|
155
|
+
- `selectable`:取调用时传入对象上的值
|
|
156
|
+
- 固定框时还有 `__semiTargetInfo`:`{ width, height, centerX, centerY, signX, signY }`
|
|
157
|
+
- 对象上已有的运行时字段会原样带回:`__baseWidth`、`__baseHeight`、`__basePadding`、
|
|
158
|
+
`__baseObjectCaching`、`__curvedCenterX`、`__curvedCenterY`、`__lastCurvedWidth`、
|
|
159
|
+
`__lastCurvedHeight`、`__lastCurvedCenterX`、`__lastCurvedCenterY`、`__rawText`、
|
|
160
|
+
`orientation`、`radius`、`spacing`
|
|
161
|
+
|
|
162
|
+
```ts
|
|
163
|
+
const patch = await rendererRef.current?.updateText(textObject, { text: nextText });
|
|
164
|
+
if (!patch) return;
|
|
165
|
+
const nextObject = { ...textObject, ...patch };
|
|
166
|
+
```
|
|
131
167
|
|
|
132
168
|
## Move 交互
|
|
133
169
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@printine/pod-editor",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.21",
|
|
4
4
|
"description": "React online product designer with Fabric canvas and host-owned commerce integrations.",
|
|
5
5
|
"private": false,
|
|
6
6
|
"keywords": [
|
|
@@ -138,6 +138,8 @@
|
|
|
138
138
|
"scripts": {
|
|
139
139
|
"build": "vite build && tsc -p tsconfig.build.json && node ./scripts/copy-declarations.mjs",
|
|
140
140
|
"typecheck": "tsc --noEmit -p tsconfig.json",
|
|
141
|
+
"test:personalization": "node ./tests/personalization.smoke.mjs",
|
|
142
|
+
"dev:personalization": "vite --host 127.0.0.1 --port 18887 --strictPort",
|
|
141
143
|
"test:api": "node ./tests/api-client.smoke.mjs && node --test ./tests/editor-assets.smoke.mjs && node ./tests/base-plate.smoke.mjs",
|
|
142
144
|
"test:preview-assets": "node ./tests/preview-assets.smoke.mjs",
|
|
143
145
|
"test:workspace-pattern": "node ./tests/workspace-pattern.smoke.mjs",
|
|
@@ -1,153 +0,0 @@
|
|
|
1
|
-
import { create as y } from "zustand";
|
|
2
|
-
import { HistoryManager as p } from "./engine/history.js";
|
|
3
|
-
import { loadFontFile as b } from "./engine/utils/font.js";
|
|
4
|
-
import { FONT_WEIGHT as h } from "./engine/constants.js";
|
|
5
|
-
let u = null;
|
|
6
|
-
function j(e) {
|
|
7
|
-
u = e;
|
|
8
|
-
}
|
|
9
|
-
function l() {
|
|
10
|
-
if (!u)
|
|
11
|
-
throw new Error(
|
|
12
|
-
"[printine-designer] Editor asset API client is not ready. Render <PrintineDesigner /> before calling the API."
|
|
13
|
-
);
|
|
14
|
-
return u;
|
|
15
|
-
}
|
|
16
|
-
function r(e) {
|
|
17
|
-
return typeof e == "string" ? e : "";
|
|
18
|
-
}
|
|
19
|
-
function d(e, o) {
|
|
20
|
-
return {
|
|
21
|
-
data: e,
|
|
22
|
-
meta: {
|
|
23
|
-
current_page: o?.page ?? 1,
|
|
24
|
-
last_page: o?.total_pages ?? 1,
|
|
25
|
-
total: o?.total ?? e.length
|
|
26
|
-
}
|
|
27
|
-
};
|
|
28
|
-
}
|
|
29
|
-
function w(e) {
|
|
30
|
-
const o = [];
|
|
31
|
-
for (const t of e) {
|
|
32
|
-
const n = [];
|
|
33
|
-
for (const s of t.variants ?? []) {
|
|
34
|
-
const a = typeof s.weight == "number" ? s.weight : 400, m = s.style === "italic" ? "italic" : "normal", f = `${a}${m === "normal" ? "" : "italic"}`, g = r(s.url);
|
|
35
|
-
g && n.push({
|
|
36
|
-
style: m,
|
|
37
|
-
variant: f,
|
|
38
|
-
weight: a,
|
|
39
|
-
label: h[f] || `${a}`,
|
|
40
|
-
url: g
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
const i = r(t.name);
|
|
44
|
-
!i || !n.length || o.push({
|
|
45
|
-
category: "",
|
|
46
|
-
family: i,
|
|
47
|
-
variants: [...new Set(n.map((s) => s.variant ?? `${s.weight}`))],
|
|
48
|
-
files: n
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
return o;
|
|
52
|
-
}
|
|
53
|
-
function C(e) {
|
|
54
|
-
const o = r(e.id), t = r(e.asset_url);
|
|
55
|
-
if (!o || !t) return null;
|
|
56
|
-
const n = r(e.thumbnail_url);
|
|
57
|
-
return { id: o, name: r(e.name), url: t, ...n ? { thumbnailUrl: n } : {} };
|
|
58
|
-
}
|
|
59
|
-
function S(e) {
|
|
60
|
-
return C(e);
|
|
61
|
-
}
|
|
62
|
-
const k = {
|
|
63
|
-
async getFontList() {
|
|
64
|
-
const e = await l().get("fonts");
|
|
65
|
-
return w(e.data);
|
|
66
|
-
},
|
|
67
|
-
async getShapeList(e) {
|
|
68
|
-
const { size: o, ...t } = e, n = await l().get("shapes", {
|
|
69
|
-
...t,
|
|
70
|
-
page: typeof e.page == "number" ? e.page : 1,
|
|
71
|
-
limit: typeof o == "number" ? o : 30
|
|
72
|
-
}), i = n.data.map(C).filter((s) => s !== null);
|
|
73
|
-
return d(i, n.pagination);
|
|
74
|
-
},
|
|
75
|
-
async getClipArtCategories() {
|
|
76
|
-
const o = (await l().get("clipart-categories")).data.map((t) => {
|
|
77
|
-
const n = r(t.id);
|
|
78
|
-
return n ? {
|
|
79
|
-
id: n,
|
|
80
|
-
name: r(t.name),
|
|
81
|
-
clip_arts: (t.cliparts ?? []).map(S).filter((i) => i !== null)
|
|
82
|
-
} : null;
|
|
83
|
-
}).filter((t) => t !== null);
|
|
84
|
-
return d(o);
|
|
85
|
-
}
|
|
86
|
-
};
|
|
87
|
-
let c = 0;
|
|
88
|
-
const A = y((e, o) => ({
|
|
89
|
-
currentSide: "",
|
|
90
|
-
historyManager: new p(""),
|
|
91
|
-
fontList: [],
|
|
92
|
-
backgroundColor: "",
|
|
93
|
-
colors: [],
|
|
94
|
-
activeObjects: [],
|
|
95
|
-
rendering: !1,
|
|
96
|
-
copiedObjects: null,
|
|
97
|
-
semiCustom: {},
|
|
98
|
-
semiCustomBackground: { colors: [], palette: !1, enable: !1 },
|
|
99
|
-
initData: (t, n) => {
|
|
100
|
-
const { getFontList: i, getColors: s } = o();
|
|
101
|
-
i(t), s(n);
|
|
102
|
-
},
|
|
103
|
-
getFontList: async (t) => {
|
|
104
|
-
try {
|
|
105
|
-
e({ fontList: await (t ? t() : k.getFontList()) });
|
|
106
|
-
} catch {
|
|
107
|
-
e({ fontList: [] });
|
|
108
|
-
}
|
|
109
|
-
},
|
|
110
|
-
loadMultipleFont: async (t) => {
|
|
111
|
-
const { fontList: n } = o(), i = t.map((s) => n.find((a) => a.family === s)).filter((s) => !!s);
|
|
112
|
-
await Promise.all(i.map((s) => b(s)));
|
|
113
|
-
},
|
|
114
|
-
getColors: async (t) => {
|
|
115
|
-
const n = ++c;
|
|
116
|
-
e({ colors: [] });
|
|
117
|
-
try {
|
|
118
|
-
const i = t ? await t() : [];
|
|
119
|
-
n === c && e({ colors: Array.isArray(i) ? i.filter((s) => typeof s == "string" && s.trim()) : [] });
|
|
120
|
-
} catch {
|
|
121
|
-
n === c && e({ colors: [] });
|
|
122
|
-
}
|
|
123
|
-
},
|
|
124
|
-
setActiveObjects: (t) => e({ activeObjects: t }),
|
|
125
|
-
setCurrentSide: (t) => e({ currentSide: t }),
|
|
126
|
-
setBackgroundColor: (t) => e({ backgroundColor: t }),
|
|
127
|
-
setHistoryManager: (t) => e({ historyManager: t }),
|
|
128
|
-
setRendering: (t) => e({ rendering: t }),
|
|
129
|
-
setCopiedObjects: (t) => e({ copiedObjects: t }),
|
|
130
|
-
setSemiCustom: (t) => e({ semiCustom: t }),
|
|
131
|
-
setSemiCustomItem: (t, n) => e({ semiCustom: { ...o().semiCustom, [t]: n } }),
|
|
132
|
-
delSemiCustomInfo: (t) => e({ semiCustom: { ...o().semiCustom, [t]: void 0 } }),
|
|
133
|
-
setSemiCustomBackground: (t) => e({ semiCustomBackground: t }),
|
|
134
|
-
setSemiCustomBackgroundItem: (t, n) => e({ semiCustomBackground: { ...o().semiCustomBackground, [t]: n } }),
|
|
135
|
-
reset: () => {
|
|
136
|
-
c += 1, e({
|
|
137
|
-
historyManager: new p(""),
|
|
138
|
-
activeObjects: [],
|
|
139
|
-
backgroundColor: "",
|
|
140
|
-
currentSide: "",
|
|
141
|
-
copiedObjects: null,
|
|
142
|
-
semiCustom: {},
|
|
143
|
-
semiCustomBackground: { colors: [], palette: !1, enable: !1 },
|
|
144
|
-
colors: []
|
|
145
|
-
});
|
|
146
|
-
}
|
|
147
|
-
})), B = A;
|
|
148
|
-
export {
|
|
149
|
-
k as A,
|
|
150
|
-
B as a,
|
|
151
|
-
j as s,
|
|
152
|
-
A as u
|
|
153
|
-
};
|
|
@@ -1,199 +0,0 @@
|
|
|
1
|
-
import { jsxs as p, jsx as f } from "react/jsx-runtime";
|
|
2
|
-
function A({ image: t, alt: e = "Product preview", loading: r, failed: n, onRetry: i }) {
|
|
3
|
-
return /* @__PURE__ */ p("div", { "data-print-material-preview": "true", style: { position: "relative", width: "100%", height: "100%", minHeight: 80 }, children: [
|
|
4
|
-
t && /* @__PURE__ */ f("img", { src: t, alt: e, style: { display: "block", width: "100%", height: "100%", objectFit: "contain" } }),
|
|
5
|
-
(!t || n) && /* @__PURE__ */ p("div", { role: n ? "alert" : "status", "aria-live": "polite", style: {
|
|
6
|
-
position: "absolute",
|
|
7
|
-
inset: 0,
|
|
8
|
-
minHeight: 80,
|
|
9
|
-
display: "flex",
|
|
10
|
-
flexDirection: "column",
|
|
11
|
-
alignItems: "center",
|
|
12
|
-
justifyContent: "center",
|
|
13
|
-
gap: 8,
|
|
14
|
-
padding: 12,
|
|
15
|
-
textAlign: "center",
|
|
16
|
-
background: "#f3f4f6",
|
|
17
|
-
color: "#374151",
|
|
18
|
-
fontSize: 12
|
|
19
|
-
}, children: [
|
|
20
|
-
/* @__PURE__ */ f("span", { children: n ? "Preview could not be generated." : "Generating preview…" }),
|
|
21
|
-
n && i && /* @__PURE__ */ f(
|
|
22
|
-
"button",
|
|
23
|
-
{
|
|
24
|
-
type: "button",
|
|
25
|
-
disabled: r,
|
|
26
|
-
onClick: (s) => {
|
|
27
|
-
s.stopPropagation(), i();
|
|
28
|
-
},
|
|
29
|
-
style: { border: "1px solid #9ca3af", borderRadius: 4, background: "#fff", padding: "5px 12px", cursor: "pointer" },
|
|
30
|
-
children: "Retry"
|
|
31
|
-
}
|
|
32
|
-
)
|
|
33
|
-
] })
|
|
34
|
-
] });
|
|
35
|
-
}
|
|
36
|
-
function h(t) {
|
|
37
|
-
return typeof t == "string" && /^#[\da-f]{6}$/i.test(t) ? t.toLowerCase() : void 0;
|
|
38
|
-
}
|
|
39
|
-
function w(t, e, r = !!t.texture) {
|
|
40
|
-
return !t.design || r || !!(e ?? t.color) || !!h(t.defaultPrintColor);
|
|
41
|
-
}
|
|
42
|
-
function m(...t) {
|
|
43
|
-
for (const e of t) if (e !== void 0) return e === null ? null : h(e) ?? null;
|
|
44
|
-
}
|
|
45
|
-
function v(t, e) {
|
|
46
|
-
const r = m(t.defaultPrintColor, e);
|
|
47
|
-
return { ...t, defaultPrintColor: r, render_areas: t.render_areas.map((n) => ({
|
|
48
|
-
...n,
|
|
49
|
-
defaultPrintColor: n.design ? m(n.defaultPrintColor, n.area?.defaultPrintColor, r) : void 0
|
|
50
|
-
})) };
|
|
51
|
-
}
|
|
52
|
-
function U(t) {
|
|
53
|
-
return { ...t, areas: t.areas.map((e) => ({
|
|
54
|
-
...e,
|
|
55
|
-
defaultPrintColor: m(e.defaultPrintColor, t.defaultPrintColor)
|
|
56
|
-
})), renders: (t.renders || []).map((e) => v(e, t.defaultPrintColor)) };
|
|
57
|
-
}
|
|
58
|
-
function L(t) {
|
|
59
|
-
return t.some((e) => e.design && !!h(e.defaultPrintColor));
|
|
60
|
-
}
|
|
61
|
-
const b = `(function(){"use strict";class V{constructor(t=32*1024*1024,n=4,r){this.budget=t,this.concurrency=n,this.onEvict=r,this.entries=new Map,this.bytes=0,this.active=0,this.waiting=[],this.pinned=new Set}setPinnedSources(t){this.pinned=new Set(t),this.waiting.forEach(n=>{n.foreground=this.pinned.has(n.source)}),this.waiting.sort((n,r)=>Number(r.foreground)-Number(n.foreground)),this.trim()}trim(){for(const[t,n]of this.entries){if(this.bytes<=this.budget)break;!n.bytes||this.pinned.has(t)||(this.entries.delete(t),this.bytes-=n.bytes,this.onEvict?.(t))}}clear(){for(const t of this.waiting.splice(0))t.cancel();for(const t of this.entries.keys())this.onEvict?.(t);this.entries.clear(),this.pinned.clear(),this.bytes=0}promote(t){const n=this.waiting.findIndex(s=>s.source===t&&!s.foreground);if(n<0)return;const[r]=this.waiting.splice(n,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(t,n){await new Promise((r,o)=>{const s=()=>{this.active+=1,r()};this.active<this.concurrency?s():(this.waiting.push({source:t,foreground:!1,start:s,cancel:()=>o(new Error("Resource cache was released"))}),n&&this.promote(t))});try{const r=await fetch(t);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(t,n=!0){const r=this.entries.get(t);if(r)return this.entries.delete(t),this.entries.set(t,r),n&&this.promote(t),r.ready;const o={ready:this.fetchBlob(t,n),bytes:0};return this.entries.set(t,o),o.ready.then(s=>{this.entries.get(t)===o&&(o.bytes=s.size,this.bytes+=o.bytes,this.trim())}).catch(()=>{this.entries.get(t)===o&&this.entries.delete(t)}),o.ready}}function I(i){return typeof i=="string"&&/^#[\\da-f]{6}$/i.test(i)?i.toLowerCase():void 0}function P(i,t,n=!!i.texture){return!i.design||n||!!(t??i.color)||!!I(i.defaultPrintColor)}const v=44,$=32*1024*1024,L=new Map;let M=0;const X=new V;function x(i,t=0){return typeof i=="number"&&Number.isFinite(i)?i:t}function U(i,t=1){const n=x(i,t);return Math.max(0,Math.min(1,n>1?n/255:n))}function j(i=new Set){for(const[t,n]of L){if(M<=$)break;i.has(t)||!n.bitmap||(L.delete(t),M-=n.bytes,n.bitmap.close())}}async function k(i,t){if(!i)return null;if(i instanceof ImageBitmap)return i;t.add(i);let n=L.get(i);return n?(L.delete(i),L.set(i,n)):(n={bytes:0,promise:X.load(i).then(createImageBitmap)},L.set(i,n),n.promise.then(r=>{n.bitmap=r,n.bytes=r.width*r.height*4,M+=n.bytes}).catch(()=>L.delete(i))),n.promise}function K(i){const t=i;return!!t&&Array.isArray(t.uLines)&&t.uLines.length>=2&&Array.isArray(t.vLines)&&t.vLines.length>=2&&Array.isArray(t.grid)&&t.grid.length===t.vLines.length&&t.grid.every(n=>Array.isArray(n)&&n.length===t.uLines.length)}function Q(i){const t=i;if(!t||!Array.isArray(t.vertices)||!Array.isArray(t.uvs)||!Array.isArray(t.indices)||!t.vertices.length||t.vertices.length%2!==0||t.uvs.length!==t.vertices.length||!t.indices.length||t.indices.length%3!==0)return!1;const n=t.vertices.length/2;return t.vertices.every(Number.isFinite)&&t.uvs.every(Number.isFinite)&&t.indices.every(r=>Number.isInteger(r)&&r>=0&&r<n&&r<=65535)}function J(i){return i.some(t=>t.some(n=>["r","l","u","d"].some(r=>{const o=n[r];return typeof o=="object"&&!!o.moved})))}function Z(i,t){const n=i[t];return n?.moved?{dx:x(n.dx)-x(n.baseDx),dy:x(n.dy)-x(n.baseDy)}:{dx:0,dy:0}}function S(i,t,n,r,o){const s=1-o;return{x:s**3*i.x+3*s*s*o*t.x+3*s*o*o*n.x+o**3*r.x,y:s**3*i.y+3*s*s*o*t.y+3*s*o*o*n.y+o**3*r.y}}function q(i,t,n,r,o,s){const m=(c,b)=>({dx:(b.x-c.x)/3,dy:(b.y-c.y)/3}),u=(c,b,R)=>{const f=m(c,b),l=Z(c,R);return{x:c.x+f.dx+l.dx,y:c.y+f.dy+l.dy}},d=S(i,u(i,t,"r"),u(t,i,"l"),t,o),a=S(n,u(n,r,"r"),u(r,n,"l"),r,o),g=S(i,u(i,n,"d"),u(n,i,"u"),n,s),h=S(t,u(t,r,"d"),u(r,t,"u"),r,s),y={x:i.x*(1-o)*(1-s)+t.x*o*(1-s)+n.x*(1-o)*s+r.x*o*s,y:i.y*(1-o)*(1-s)+t.y*o*(1-s)+n.y*(1-o)*s+r.y*o*s};return{x:d.x*(1-s)+a.x*s+g.x*(1-o)+h.x*o-y.x,y:d.y*(1-s)+a.y*s+g.y*(1-o)+h.y*o-y.y}}function C(i,t){if(i.length<=2)return 0;let n=0,r=i.length;const o=t-1e-9;for(;n<r;){const s=n+r>>1;i[s]<o?n=s+1:r=s}return Math.min(Math.max(n-1,0),i.length-2)}function ee(i,t,n,r){const o=C(i.uLines,t),s=C(i.vLines,n),m=i.uLines[o+1]-i.uLines[o],u=i.vLines[s+1]-i.vLines[s],d=m>1e-9?(t-i.uLines[o])/m:0,a=u>1e-9?(n-i.vLines[s])/u:0,[g,h]=[i.grid[s][o],i.grid[s][o+1]],[y,c]=[i.grid[s+1][o],i.grid[s+1][o+1]];return r?q(g,h,y,c,d,a):{x:g.x*(1-d)*(1-a)+h.x*d*(1-a)+y.x*(1-d)*a+c.x*d*a,y:g.y*(1-d)*(1-a)+h.y*d*(1-a)+y.y*(1-d)*a+c.y*d*a}}function D(i){let t=1/0,n=1/0,r=-1/0,o=-1/0;for(const s of i)t=Math.min(t,s.x),n=Math.min(n,s.y),r=Math.max(r,s.x),o=Math.max(o,s.y);return{minX:t,minY:n,maxX:r,maxY:o}}function te(i,t){const n=i.config??i.texture_transform??{},r=n.transform??{},o=i.textureSize??n.textureSize,s=x(o?.[0]),m=x(o?.[1]),u=t.width,d=t.height;if(!(s>0&&m>0&&u>0&&d>0&&(s!==u||m!==d)))return{...r};const g=s/u,h=m/d,y=Math.sqrt(g*h);return{...r,...typeof r.baseScale=="number"?{baseScale:r.baseScale*y}:{},...typeof r.scale=="number"?{scale:r.scale*y}:{},...typeof r.scaleX=="number"?{scaleX:r.scaleX*g}:{},...typeof r.scaleY=="number"?{scaleY:r.scaleY*h}:{}}}function ne(i,t,n,r){if(r||!i.length)return i;const o=D(i),s={x:(o.minX+o.maxX)/2,y:(o.minY+o.maxY)/2},m=typeof t.scaleX=="number"?t.scaleX:typeof t.scale=="number"?t.scale:n,u=typeof t.scaleY=="number"?t.scaleY:typeof t.scale=="number"?t.scale:n,d=m/(n||1)*x(t.flipX,1),a=u/(n||1)*x(t.flipY,1),g=x(t.rotation)*Math.PI/180,h=Math.cos(g),y=Math.sin(g),c=i.map(l=>{const _=(l.x-s.x)*d,T=(l.y-s.y)*a;return{x:_*h-T*y+s.x,y:_*y+T*h+s.y}}),b=D(c),R=typeof t.translateX=="number"?t.translateX-b.minX:0,f=typeof t.translateY=="number"?t.translateY-b.minY:0;return R||f?c.map(l=>({x:l.x+R,y:l.y+f})):c}function ie(i,t){if(!Q(t))return null;const n=new Float32Array(t.vertices.length);for(let r=0;r<t.vertices.length;r+=2)n[r]=i.x+t.vertices[r],n[r+1]=i.y+t.vertices[r+1];return{vertices:n,uvs:new Float32Array(t.uvs),indices:new Uint16Array(t.indices)}}function N(i,t){const n=i.config??i.texture_transform??{},r=ie(i,n);if(r)return r;const o=te(i,t),s=K(n.mesh)?n.mesh:null;let m,u=x(o.baseScale,1);if(s){const f=J(s.grid);m=(l,_)=>ee(s,l,_,f)}else{const f=Math.max(i.width/t.width,i.height/t.height);u=typeof o.baseScale=="number"?o.baseScale:Math.min(1,f);const l=t.width*u,_=t.height*u,T=(i.width-l)/2,A=(i.height-_)/2;m=(B,ge)=>({x:T+l*B,y:A+_*ge})}const d=[],a=new Float32Array((v+1)**2*2);let g=0;for(let f=0;f<=v;f+=1){const l=f/v;for(let _=0;_<=v;_+=1){const T=_/v;d.push(m(T,l)),a[g++]=T,a[g++]=l}}const h=ne(d,o,u,!!o.baked),y=new Float32Array(h.length*2);h.forEach((f,l)=>{y[l*2]=i.x+f.x,y[l*2+1]=i.y+f.y});const c=new Uint16Array(v*v*6);let b=0;const R=v+1;for(let f=0;f<v;f+=1)for(let l=0;l<v;l+=1){const _=f*R+l,T=_+1,A=_+R,B=A+1;c[b++]=_,c[b++]=T,c[b++]=A,c[b++]=T,c[b++]=B,c[b++]=A}return{vertices:y,uvs:a,indices:c}}const p=new OffscreenCanvas(1,1),O=p.getContext("webgl2",{alpha:!0,antialias:!0,depth:!1,stencil:!1,premultipliedAlpha:!1,preserveDrawingBuffer:!0});if(!O)throw new Error("WebGL2 is unavailable in the render worker");const e=O,re=\`#version 300 es
|
|
62
|
-
in vec2 a_position; in vec2 a_uv; uniform vec2 u_resolution;
|
|
63
|
-
out vec2 v_uv; out vec2 v_position;
|
|
64
|
-
void main() {
|
|
65
|
-
vec2 clip = (a_position / u_resolution) * 2.0 - 1.0;
|
|
66
|
-
gl_Position = vec4(clip * vec2(1.0, -1.0), 0.0, 1.0);
|
|
67
|
-
v_uv = a_uv; v_position = a_position;
|
|
68
|
-
}\`,oe=\`#version 300 es
|
|
69
|
-
precision highp float;
|
|
70
|
-
uniform sampler2D u_image; uniform sampler2D u_mask;
|
|
71
|
-
uniform int u_mode; uniform float u_opacity; uniform vec4 u_tint; uniform vec4 u_mask_rect;
|
|
72
|
-
in vec2 v_uv; in vec2 v_position; out vec4 out_color;
|
|
73
|
-
void main() {
|
|
74
|
-
vec4 source = texture(u_image, v_uv);
|
|
75
|
-
if (u_mode == 1) {
|
|
76
|
-
vec2 maskUv = (v_position - u_mask_rect.xy) / u_mask_rect.zw;
|
|
77
|
-
if (maskUv.x < 0.0 || maskUv.y < 0.0 || maskUv.x > 1.0 || maskUv.y > 1.0) discard;
|
|
78
|
-
vec4 mask = texture(u_mask, maskUv);
|
|
79
|
-
source *= mask.a;
|
|
80
|
-
} else if (u_mode == 2) {
|
|
81
|
-
float tintAlpha = source.a * u_tint.a;
|
|
82
|
-
source = vec4(u_tint.rgb * tintAlpha, tintAlpha);
|
|
83
|
-
} else if (u_mode == 3) {
|
|
84
|
-
vec2 maskUv = (v_position - u_mask_rect.xy) / u_mask_rect.zw;
|
|
85
|
-
if (maskUv.x < 0.0 || maskUv.y < 0.0 || maskUv.x > 1.0 || maskUv.y > 1.0) discard;
|
|
86
|
-
vec4 mask = texture(u_mask, maskUv);
|
|
87
|
-
// Compose the premultiplied artwork over its fill before clipping. Applying
|
|
88
|
-
// mask alpha to each term separately would count translucent edges twice.
|
|
89
|
-
vec4 fill = vec4(u_tint.rgb * u_tint.a, u_tint.a);
|
|
90
|
-
source = (source + fill * (1.0 - source.a)) * mask.a;
|
|
91
|
-
}
|
|
92
|
-
if (u_mode == 4) source = vec4(u_tint.rgb * u_tint.a, u_tint.a);
|
|
93
|
-
else if (u_mode == 5) source += vec4(u_tint.rgb * u_tint.a, u_tint.a) * (1.0 - source.a);
|
|
94
|
-
out_color = source * u_opacity;
|
|
95
|
-
}\`;function G(i,t){const n=e.createShader(i);if(!n)throw new Error("Could not create WebGL shader");if(e.shaderSource(n,t),e.compileShader(n),!e.getShaderParameter(n,e.COMPILE_STATUS))throw new Error(e.getShaderInfoLog(n)||"WebGL shader compilation failed");return n}const E=e.createProgram();if(!E)throw new Error("Could not create WebGL program");if(e.attachShader(E,G(e.VERTEX_SHADER,re)),e.attachShader(E,G(e.FRAGMENT_SHADER,oe)),e.linkProgram(E),!e.getProgramParameter(E,e.LINK_STATUS))throw new Error(e.getProgramInfoLog(E)||"WebGL program link failed");const Y=e.getAttribLocation(E,"a_position"),W=e.getAttribLocation(E,"a_uv"),se=e.getUniformLocation(E,"u_resolution"),ae=e.getUniformLocation(E,"u_image"),ce=e.getUniformLocation(E,"u_mask"),le=e.getUniformLocation(E,"u_mode"),ue=e.getUniformLocation(E,"u_opacity"),fe=e.getUniformLocation(E,"u_tint"),de=e.getUniformLocation(E,"u_mask_rect");function H(i,t=!1){if(t)return i;const n=e.createTexture();if(!n)throw new Error("Could not create WebGL texture");return e.bindTexture(e.TEXTURE_2D,n),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.LINEAR),e.pixelStorei(e.UNPACK_PREMULTIPLY_ALPHA_WEBGL,!0),e.texImage2D(e.TEXTURE_2D,0,e.RGBA,e.RGBA,e.UNSIGNED_BYTE,i),n}function me(i){const t=String(i??"normal").toLowerCase();e.enable(e.BLEND),t==="multiply"||t==="2"?e.blendFuncSeparate(e.DST_COLOR,e.ONE_MINUS_SRC_ALPHA,e.ONE,e.ONE_MINUS_SRC_ALPHA):e.blendFuncSeparate(e.ONE,e.ONE_MINUS_SRC_ALPHA,e.ONE,e.ONE_MINUS_SRC_ALPHA)}function F(i){if(!i)return[1,1,1,1];const t=/^#([\\da-f]{3})$/i.exec(i),n=/^#([\\da-f]{6})$/i.exec(i),r=/^rgba?\\(\\s*(\\d+)\\s*,\\s*(\\d+)\\s*,\\s*(\\d+)(?:\\s*,\\s*([+-]?(?:\\d*\\.)?\\d+))?/i.exec(i);let o=null;t&&(o=t[1].split("").map(m=>Number.parseInt(m+m,16))),n&&(o=[n[1].slice(0,2),n[1].slice(2,4),n[1].slice(4,6)].map(m=>Number.parseInt(m,16))),r&&(o=[Number(r[1]),Number(r[2]),Number(r[3])]);const s=r?.[4]===void 0?1:Math.max(0,Math.min(1,Number(r[4])));return o?[o[0]/255,o[1]/255,o[2]/255,s]:[1,1,1,1]}function z(i,t,n,r){return{vertices:new Float32Array([i,t,i+n,t,i,t+r,i+n,t+r]),uvs:new Float32Array([0,0,1,0,0,1,1,1]),indices:new Uint16Array([0,1,2,1,3,2])}}function w(i,t,n={}){e.useProgram(E),me(n.blend);const r=e.createBuffer(),o=e.createBuffer(),s=e.createBuffer();if(!r||!o||!s)throw new Error("Could not allocate WebGL geometry");e.bindBuffer(e.ARRAY_BUFFER,r),e.bufferData(e.ARRAY_BUFFER,i.vertices,e.STREAM_DRAW),e.enableVertexAttribArray(Y),e.vertexAttribPointer(Y,2,e.FLOAT,!1,0,0),e.bindBuffer(e.ARRAY_BUFFER,o),e.bufferData(e.ARRAY_BUFFER,i.uvs,e.STATIC_DRAW),e.enableVertexAttribArray(W),e.vertexAttribPointer(W,2,e.FLOAT,!1,0,0),e.bindBuffer(e.ELEMENT_ARRAY_BUFFER,s),e.bufferData(e.ELEMENT_ARRAY_BUFFER,i.indices,e.STATIC_DRAW),e.activeTexture(e.TEXTURE0);const m=H(t,n.imageIsTexture);e.bindTexture(e.TEXTURE_2D,m),e.uniform1i(ae,0);let u=null;n.mask&&(e.activeTexture(e.TEXTURE1),u=H(n.mask),e.bindTexture(e.TEXTURE_2D,u),e.uniform1i(ce,1)),e.uniform2f(se,p.width,p.height),e.uniform1i(le,n.mode??0),e.uniform1f(ue,n.opacity??1),e.uniform4fv(fe,n.tint??[1,1,1,1]),e.uniform4fv(de,n.maskRect??[0,0,1,1]),e.drawElements(e.TRIANGLES,i.indices.length,e.UNSIGNED_SHORT,0),e.deleteBuffer(r),e.deleteBuffer(o),e.deleteBuffer(s),n.imageIsTexture||e.deleteTexture(m),u&&e.deleteTexture(u)}function he(i,t){const n=e.createTexture(),r=e.createFramebuffer();if(!n||!r)throw new Error("Could not allocate WebGL layer target");if(e.bindTexture(e.TEXTURE_2D,n),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.LINEAR),e.texImage2D(e.TEXTURE_2D,0,e.RGBA,i,t,0,e.RGBA,e.UNSIGNED_BYTE,null),e.bindFramebuffer(e.FRAMEBUFFER,r),e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0,e.TEXTURE_2D,n,0),e.checkFramebufferStatus(e.FRAMEBUFFER)!==e.FRAMEBUFFER_COMPLETE)throw new Error("WebGL layer framebuffer is incomplete");return e.bindFramebuffer(e.FRAMEBUFFER,null),e.bindTexture(e.TEXTURE_2D,null),{texture:n,framebuffer:r}}async function ye(i){const t=i.areas.find(a=>a.name==="bg");if(!t)throw new Error("WebGL worker rendering requires a bg render area");const n=x(i.options.targetSize),r=n>0?n/Math.max(t.width,t.height):Math.max(.1,x(i.options.scale,1)),o=i.options.composition==="design-layer";p.width=Math.max(1,Math.round(t.width*r)),p.height=Math.max(1,Math.round(t.height*r)),e.viewport(0,0,p.width,p.height),e.bindFramebuffer(e.FRAMEBUFFER,null),e.clearColor(0,0,0,0),e.clear(e.COLOR_BUFFER_BIT);const s=new Set,m=new Set;for(const a of i.areas)o&&!a.design||P(a,i.options.color)&&(a.image&&m.add(a.image),typeof a.texture=="string"&&m.add(a.texture));await Promise.all([...m].map(a=>k(a,s)));const u=a=>z(a.x*r,a.y*r,a.width*r,a.height*r);let d;try{for(const a of i.areas){if(o&&!a.design||!P(a,i.options.color))continue;const g=await k(a.image,s);if(!g)continue;if(!a.design){w(u(a),g,{blend:a.export?.blend,opacity:U(a.export?.opacity)});continue}const h=await k(a.texture,s),y=i.options.color??a.color,c=a.config??a.texture_transform??{},b=o?"normal":c.blendMode??"multiply",R=I(a.defaultPrintColor);if(R){d??=he(p.width,p.height),e.bindFramebuffer(e.FRAMEBUFFER,d.framebuffer),e.clearColor(0,0,0,0),e.clear(e.COLOR_BUFFER_BIT);const f=c.textureSize??[a.width,a.height],l=N(a,h??{width:f[0],height:f[1]});for(let A=0;A<l.vertices.length;A++)l.vertices[A]*=r;w(l,g,{mode:4,tint:F(R),blend:"normal"});const _=c.blendMode??(y?"multiply":"normal");h?w(l,h,{mode:y?5:0,tint:F(y),blend:_}):y&&w(l,g,{mode:4,tint:F(y),blend:_}),e.bindFramebuffer(e.FRAMEBUFFER,null);const T=z(0,0,p.width,p.height);T.uvs=new Float32Array([0,1,1,1,0,0,1,0]),w(T,d.texture,{imageIsTexture:!0,mode:1,mask:g,maskRect:[a.x*r,a.y*r,a.width*r,a.height*r],blend:"normal",opacity:U(c.opacity)}),a.texture instanceof ImageBitmap&&h?.close();continue}if(h){const f=N(a,h);for(let l=0;l<f.vertices.length;l+=1)f.vertices[l]*=r;o?w(f,h,{mode:1,mask:g,maskRect:[a.x*r,a.y*r,a.width*r,a.height*r],blend:"normal",opacity:U(c.opacity)}):y?w(f,h,{mode:3,mask:g,tint:F(y),maskRect:[a.x*r,a.y*r,a.width*r,a.height*r],blend:b,opacity:U(c.opacity)}):w(f,h,{mode:1,mask:g,maskRect:[a.x*r,a.y*r,a.width*r,a.height*r],blend:o?"normal":c.blendMode,opacity:U(c.opacity)}),a.texture instanceof ImageBitmap&&h.close()}else y&&w(u(a),g,{mode:2,tint:F(y),blend:b,opacity:U(c.opacity)})}e.finish();try{return await p.convertToBlob({type:i.options.format??"image/png",quality:i.options.quality??.9})}catch{return p.convertToBlob({type:"image/png"})}}finally{d&&(e.deleteFramebuffer(d.framebuffer),e.deleteTexture(d.texture)),j(s)}}self.onmessage=async i=>{const t=i.data;if(t.type==="preload"){try{await Promise.all([...new Set(t.sources)].map(n=>L.has(n)?Promise.resolve():X.load(n,t.priority===!0))),self.postMessage({type:"preloaded",id:t.id})}catch(n){self.postMessage({type:"error",id:t.id,message:n instanceof Error?n.message:String(n)})}return}if(t.type==="render")try{self.postMessage({type:"result",id:t.id,blob:await ye(t)})}catch(n){self.postMessage({type:"error",id:t.id,message:n instanceof Error?n.message:String(n)})}}})();
|
|
96
|
-
`, y = typeof self < "u" && self.Blob && new Blob(["(self.URL || self.webkitURL).revokeObjectURL(self.location.href);", b], { type: "text/javascript;charset=utf-8" });
|
|
97
|
-
function R(t) {
|
|
98
|
-
let e;
|
|
99
|
-
try {
|
|
100
|
-
if (e = y && (self.URL || self.webkitURL).createObjectURL(y), !e) throw "";
|
|
101
|
-
const r = new Worker(e, {
|
|
102
|
-
name: t?.name
|
|
103
|
-
});
|
|
104
|
-
return r.addEventListener("error", () => {
|
|
105
|
-
(self.URL || self.webkitURL).revokeObjectURL(e);
|
|
106
|
-
}), r;
|
|
107
|
-
} catch {
|
|
108
|
-
return new Worker(
|
|
109
|
-
"data:text/javascript;charset=utf-8," + encodeURIComponent(b),
|
|
110
|
-
{
|
|
111
|
-
name: t?.name
|
|
112
|
-
}
|
|
113
|
-
);
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
function d(t) {
|
|
117
|
-
if (!t) return t;
|
|
118
|
-
const e = typeof document < "u" ? document.baseURI : typeof location < "u" ? location.href : void 0;
|
|
119
|
-
if (!e) return t;
|
|
120
|
-
try {
|
|
121
|
-
return new URL(t, e).href;
|
|
122
|
-
} catch {
|
|
123
|
-
return t;
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
class E {
|
|
127
|
-
constructor() {
|
|
128
|
-
this.worker = null, this.nextRequestId = 0, this.pending = /* @__PURE__ */ new Map(), this.renderQueue = Promise.resolve();
|
|
129
|
-
}
|
|
130
|
-
static isSupported() {
|
|
131
|
-
return typeof Worker < "u" && typeof OffscreenCanvas < "u" && typeof createImageBitmap < "u";
|
|
132
|
-
}
|
|
133
|
-
ensureWorker() {
|
|
134
|
-
if (this.worker) return this.worker;
|
|
135
|
-
if (!E.isSupported()) throw new Error("Pixel-map rendering requires Worker, OffscreenCanvas, and ImageBitmap support");
|
|
136
|
-
const e = new R();
|
|
137
|
-
return e.onmessage = (r) => {
|
|
138
|
-
const n = r.data, i = this.pending.get(n.id);
|
|
139
|
-
i && (this.pending.delete(n.id), n.type === "result" ? i.resolve(n.blob) : n.type === "preloaded" ? i.resolve(null) : i.reject(new Error(n.message)));
|
|
140
|
-
}, e.onerror = (r) => {
|
|
141
|
-
const n = r.filename ? ` (${r.filename}:${r.lineno}:${r.colno})` : "", i = r.error instanceof Error ? r.error : new Error(`${r.message || "Pixel-map worker failed"}${n}`);
|
|
142
|
-
this.pending.forEach(({ reject: s }) => s(i)), this.pending.clear(), this.worker === e && (e.terminate(), this.worker = null);
|
|
143
|
-
}, e.onmessageerror = () => {
|
|
144
|
-
const r = new Error("Pixel-map worker could not deserialize its render payload");
|
|
145
|
-
this.pending.forEach(({ reject: n }) => n(r)), this.pending.clear(), this.worker === e && (e.terminate(), this.worker = null);
|
|
146
|
-
}, this.worker = e, e;
|
|
147
|
-
}
|
|
148
|
-
/** Warm compressed resources without exporting Fabric or entering the GPU queue. */
|
|
149
|
-
async preloadAssets(e, r = !1) {
|
|
150
|
-
const n = [...new Set(e.filter(Boolean).map(d))];
|
|
151
|
-
if (!n.length) return;
|
|
152
|
-
const i = this.ensureWorker(), s = ++this.nextRequestId;
|
|
153
|
-
await new Promise((u, a) => {
|
|
154
|
-
this.pending.set(s, { resolve: u, reject: a });
|
|
155
|
-
try {
|
|
156
|
-
i.postMessage({ type: "preload", id: s, sources: n, priority: r });
|
|
157
|
-
} catch (c) {
|
|
158
|
-
this.pending.delete(s), a(c instanceof Error ? c : new Error(String(c)));
|
|
159
|
-
}
|
|
160
|
-
});
|
|
161
|
-
}
|
|
162
|
-
async onOffscreenRender(e, r = {}) {
|
|
163
|
-
const n = e.flatMap((a) => r.composition === "design-layer" && !a.design ? [] : w(a, r.color) ? [a.image, typeof a.texture == "string" ? a.texture : ""] : []), i = this.preloadAssets(n, !0);
|
|
164
|
-
i.catch(() => {
|
|
165
|
-
});
|
|
166
|
-
const s = async () => {
|
|
167
|
-
await i;
|
|
168
|
-
const a = this.ensureWorker(), c = ++this.nextRequestId, g = await Promise.all(e.map(async (o) => {
|
|
169
|
-
const l = o.texture instanceof ImageBitmap ? await createImageBitmap(o.texture) : typeof o.texture == "string" ? d(o.texture) : o.texture;
|
|
170
|
-
return {
|
|
171
|
-
...o,
|
|
172
|
-
image: d(o.image),
|
|
173
|
-
texture: l
|
|
174
|
-
};
|
|
175
|
-
})), x = g.map((o) => o.texture).filter((o) => o instanceof ImageBitmap);
|
|
176
|
-
return new Promise((o, l) => {
|
|
177
|
-
this.pending.set(c, { resolve: o, reject: l });
|
|
178
|
-
const _ = { type: "render", id: c, areas: g, options: r };
|
|
179
|
-
a.postMessage(_, x);
|
|
180
|
-
});
|
|
181
|
-
}, u = this.renderQueue.then(s, s);
|
|
182
|
-
return this.renderQueue = u.then(() => {
|
|
183
|
-
}, () => {
|
|
184
|
-
}), u;
|
|
185
|
-
}
|
|
186
|
-
destroy() {
|
|
187
|
-
this.worker?.terminate(), this.worker = null, this.pending.forEach(({ reject: e }) => e(new Error("Pixel-map renderer was destroyed"))), this.pending.clear(), this.renderQueue = Promise.resolve();
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
export {
|
|
191
|
-
A as M,
|
|
192
|
-
E as P,
|
|
193
|
-
w as a,
|
|
194
|
-
U as b,
|
|
195
|
-
L as h,
|
|
196
|
-
m as i,
|
|
197
|
-
h as n,
|
|
198
|
-
v as r
|
|
199
|
-
};
|