@printine/pod-editor 0.0.0-stage → 0.1.14
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 +242 -2
- package/dist/DesignerRuntimeContext.d.ts +3 -0
- package/dist/PrintineDesigner.d.ts +9 -0
- package/dist/api/asset-client.d.ts +8 -0
- package/dist/api/asset-client.js +40 -0
- package/dist/api/asset-endpoints.d.ts +36 -0
- package/dist/api/client.d.ts +8 -0
- package/dist/api/client.js +82 -0
- package/dist/api/common-endpoints.d.ts +12 -0
- package/dist/api/design-endpoints.d.ts +4 -0
- package/dist/api/endpoints.d.ts +23 -0
- package/dist/api/endpoints.js +33 -0
- package/dist/api/files-endpoints.d.ts +1 -0
- package/dist/assets/icons/aspect_ratio.d.ts +3 -0
- package/dist/assets/icons/delete.d.ts +3 -0
- package/dist/assets/icons/fit_screen.d.ts +3 -0
- package/dist/assets/icons/index.d.ts +11 -0
- package/dist/assets/icons/loading_1.d.ts +3 -0
- package/dist/assets/icons/loading_2.d.ts +3 -0
- package/dist/assets/icons/loading_3.d.ts +3 -0
- package/dist/assets/icons/pan.d.ts +3 -0
- package/dist/assets/icons/setting.d.ts +3 -0
- package/dist/assets/icons/text_color.d.ts +3 -0
- package/dist/assets/icons/text_h.d.ts +3 -0
- package/dist/assets/icons/text_v.d.ts +3 -0
- package/dist/bundled-assets.d.ts +4 -0
- package/dist/components/add-design.d.ts +8 -0
- package/dist/components/assets-dialog.d.ts +24 -0
- package/dist/components/canvas-context-menu.d.ts +6 -0
- package/dist/components/color-picker/index.d.ts +11 -0
- package/dist/components/context.d.ts +24 -0
- package/dist/components/design.d.ts +9 -0
- package/dist/components/fonts.d.ts +26 -0
- package/dist/components/image-crop.d.ts +5 -0
- package/dist/components/image-edit.d.ts +1 -0
- package/dist/components/layout/aside.d.ts +4 -0
- package/dist/components/layout/bottom-nav/element-menu-sheet.d.ts +11 -0
- package/dist/components/layout/bottom-nav/element-sheet.d.ts +11 -0
- package/dist/components/layout/bottom-nav/index.d.ts +1 -0
- package/dist/components/layout/header.d.ts +1 -0
- package/dist/components/loading.d.ts +3 -0
- package/dist/components/menus/ai.d.ts +5 -0
- package/dist/components/menus/background.d.ts +6 -0
- package/dist/components/menus/clipart.d.ts +6 -0
- package/dist/components/menus/files.d.ts +7 -0
- package/dist/components/menus/image.d.ts +8 -0
- package/dist/components/menus/index.d.ts +13 -0
- package/dist/components/menus/layer.d.ts +5 -0
- package/dist/components/menus/product.d.ts +3 -0
- package/dist/components/menus/sca.d.ts +5 -0
- package/dist/components/menus/shapes.d.ts +6 -0
- package/dist/components/menus/templates.d.ts +6 -0
- package/dist/components/menus/text-effects.d.ts +5 -0
- package/dist/components/menus/text.d.ts +6 -0
- package/dist/components/placement-tab.d.ts +7 -0
- package/dist/components/preview/3d.d.ts +8 -0
- package/dist/components/preview/graphic.d.ts +15 -0
- package/dist/components/preview/index.d.ts +20 -0
- package/dist/components/preview/open.d.ts +7 -0
- package/dist/components/preview/real-time/3d.d.ts +12 -0
- package/dist/components/preview/real-time/graphic.d.ts +31 -0
- package/dist/components/preview/real-time/index.d.ts +12 -0
- package/dist/components/scale-tools.d.ts +7 -0
- package/dist/components/semi-deisgn-config.d.ts +13 -0
- package/dist/components/semi-design-link.d.ts +9 -0
- package/dist/components/semi-interact-editor.d.ts +27 -0
- package/dist/components/semi-renderer.d.ts +74 -0
- package/dist/components/store.d.ts +1 -0
- package/dist/components/toolbar.d.ts +2 -0
- package/dist/config-D2qm60gf.js +16 -0
- package/dist/contracts/api-design.d.ts +180 -0
- package/dist/contracts/design.d.ts +86 -0
- package/dist/design-C_TmcalT.js +21449 -0
- package/dist/designer-store-Da9fICz8.js +153 -0
- package/dist/engine/canvas-designer.d.ts +101 -0
- package/dist/engine/canvas-designer.js +313 -0
- package/dist/engine/constants.d.ts +26 -0
- package/dist/engine/constants.js +147 -0
- package/dist/engine/editor.d.ts +199 -0
- package/dist/engine/editor.js +801 -0
- package/dist/engine/events.d.ts +35 -0
- package/dist/engine/events.js +7 -0
- package/dist/engine/extensions/curved-text.d.ts +59 -0
- package/dist/engine/fabric.d.ts +4 -0
- package/dist/engine/fabric.js +187 -0
- package/dist/engine/history.d.ts +27 -0
- package/dist/engine/history.js +56 -0
- package/dist/engine/managers/event.d.ts +101 -0
- package/dist/engine/managers/event.js +410 -0
- package/dist/engine/managers/resize.d.ts +26 -0
- package/dist/engine/managers/resize.js +64 -0
- package/dist/engine/managers/snapline.d.ts +70 -0
- package/dist/engine/managers/snapline.js +124 -0
- package/dist/engine/managers/workspace.d.ts +29 -0
- package/dist/engine/managers/workspace.js +75 -0
- package/dist/engine/processors/image.d.ts +88 -0
- package/dist/engine/processors/image.js +473 -0
- package/dist/engine/processors/template.d.ts +45 -0
- package/dist/engine/processors/template.js +314 -0
- package/dist/engine/processors/text.d.ts +74 -0
- package/dist/engine/processors/text.js +215 -0
- package/dist/engine/semi-export-editor.d.ts +215 -0
- package/dist/engine/types.d.ts +28 -0
- package/dist/engine/utils/common.d.ts +25 -0
- package/dist/engine/utils/common.js +68 -0
- package/dist/engine/utils/dialog.d.ts +25 -0
- package/dist/engine/utils/font.d.ts +5 -0
- package/dist/engine/utils/font.js +39 -0
- package/dist/engine/utils/image.d.ts +8 -0
- package/dist/engine/utils/image.js +50 -0
- package/dist/engine/utils/loading.d.ts +17 -0
- package/dist/engine/utils/loading.js +71 -0
- package/dist/engine/utils/measure.d.ts +6 -0
- package/dist/engine/utils/measure.js +6 -0
- package/dist/engine/utils/mockup.d.ts +59 -0
- package/dist/engine/utils/setting.d.ts +4 -0
- package/dist/engine/utils/setting.js +73 -0
- package/dist/fabric-types.d.ts +59 -0
- package/dist/full-designer.js +14 -0
- package/dist/hooks/pagination.d.ts +19 -0
- package/dist/hooks/use-adobe-express.d.ts +50 -0
- package/dist/hooks/use-before-unload.d.ts +1 -0
- package/dist/hooks/use-image-drop.d.ts +18 -0
- package/dist/hooks/use-oss-upload.d.ts +36 -0
- package/dist/hooks/use-preview-assets.d.ts +2 -0
- package/dist/hooks/use-screen.d.ts +1 -0
- package/dist/i18n/index.d.ts +12 -0
- package/dist/images/design/asset_empty.png +0 -0
- package/dist/images/design/design/background.svg +3 -0
- package/dist/images/design/design/color-picker.svg +15 -0
- package/dist/images/design/design/computer.svg +1 -0
- package/dist/images/design/design/copy.svg +1 -0
- package/dist/images/design/design/image.svg +10 -0
- package/dist/images/design/design/line.svg +1 -0
- package/dist/images/design/design/text.svg +1 -0
- package/dist/images/design/design/title.svg +1 -0
- package/dist/images/design/empty.png +0 -0
- package/dist/images/design/layer_empty.png +0 -0
- package/dist/images/design/menu/ai.svg +1 -0
- package/dist/images/design/menu/back.svg +4 -0
- package/dist/images/design/menu/background.svg +6 -0
- package/dist/images/design/menu/clipart.svg +6 -0
- package/dist/images/design/menu/file.svg +4 -0
- package/dist/images/design/menu/fill.svg +1 -0
- package/dist/images/design/menu/image.svg +7 -0
- package/dist/images/design/menu/layer.svg +6 -0
- package/dist/images/design/menu/product.svg +3 -0
- package/dist/images/design/menu/sca.svg +5 -0
- package/dist/images/design/menu/shapes.svg +5 -0
- package/dist/images/design/menu/templates.svg +6 -0
- package/dist/images/design/menu/text.svg +6 -0
- package/dist/images/design/menu/uploads.svg +7 -0
- package/dist/images/design/spinner.svg +3 -0
- package/dist/images/design/spinners.svg +17 -0
- package/dist/images/design/transparent_pattern.svg +5 -0
- package/dist/index.d.ts +51 -0
- package/dist/index.js +168 -0
- package/dist/lib/analytics.d.ts +17 -0
- package/dist/lib/cn.d.ts +3 -0
- package/dist/lib/common.d.ts +16 -0
- package/dist/lib/config.d.ts +14 -0
- package/dist/lib/navigation.d.ts +2 -0
- package/dist/pixel-map-dSys7UAx.js +137 -0
- package/dist/renderer/ThreeDPreview.d.ts +14 -0
- package/dist/renderer/latest-task-queue.d.ts +17 -0
- package/dist/renderer/pixel-map.d.ts +37 -0
- package/dist/renderer/preview-asset-cache.d.ts +4 -0
- package/dist/renderer/render-layer-output.d.ts +5 -0
- package/dist/renderer/semi-resource-cache.d.ts +28 -0
- package/dist/renderer/sticker.d.ts +34 -0
- package/dist/renderer/sticker.js +1837 -0
- package/dist/renderer/three-d-preview.js +32 -0
- package/dist/semi-interact-editor-DfzphWy3.js +1409 -0
- package/dist/semi-renderer.d.ts +7 -0
- package/dist/semi-renderer.js +5 -0
- package/dist/state/designer-store.d.ts +43 -0
- package/dist/state/designer-store.js +8 -0
- package/dist/style.css +1 -0
- package/dist/types.d.ts +305 -0
- package/dist/ui/accordion.d.ts +7 -0
- package/dist/ui/button-group.d.ts +11 -0
- package/dist/ui/button.d.ts +10 -0
- package/dist/ui/checkbox.d.ts +4 -0
- package/dist/ui/command.d.ts +18 -0
- package/dist/ui/confirm-dialog.d.ts +15 -0
- package/dist/ui/context-menu.d.ts +25 -0
- package/dist/ui/dialog.d.ts +15 -0
- package/dist/ui/drawer.d.ts +15 -0
- package/dist/ui/editable-combobox.d.ts +11 -0
- package/dist/ui/hint.d.ts +8 -0
- package/dist/ui/image.d.ts +24 -0
- package/dist/ui/input-group.d.ts +16 -0
- package/dist/ui/input-with-addon.d.ts +17 -0
- package/dist/ui/input.d.ts +3 -0
- package/dist/ui/label.d.ts +4 -0
- package/dist/ui/loading-button.d.ts +15 -0
- package/dist/ui/popover.d.ts +9 -0
- package/dist/ui/scroll-area.d.ts +5 -0
- package/dist/ui/select.d.ts +22 -0
- package/dist/ui/separator.d.ts +4 -0
- package/dist/ui/shared-loading-button.d.ts +20 -0
- package/dist/ui/simple-dialog.d.ts +19 -0
- package/dist/ui/simple-popover.d.ts +13 -0
- package/dist/ui/simple-select.d.ts +20 -0
- package/dist/ui/skeleton.d.ts +2 -0
- package/dist/ui/slider.d.ts +4 -0
- package/dist/ui/spinner-box.d.ts +12 -0
- package/dist/ui/spinner.d.ts +2 -0
- package/dist/ui/switch.d.ts +6 -0
- package/dist/ui/tab/index.d.ts +15 -0
- package/dist/ui/textarea.d.ts +3 -0
- package/dist/ui/tooltip.d.ts +7 -0
- package/dist/workers/image-resize.worker.d.ts +1 -0
- package/dist/workers/mockup.worker.d.ts +5 -0
- package/dist/workers/pixel-map.worker.d.ts +1 -0
- package/dist/workers/render-asset-cache.d.ts +18 -0
- package/dist/workers/render.worker.d.ts +1 -0
- package/docs/HOST_DATA_CONTRACT.md +426 -0
- package/docs/INTEGRATION_API.md +549 -0
- package/docs/SEMI_RENDERER.md +141 -0
- package/docs/auth-api.md +3 -0
- package/package.json +208 -4
package/dist/index.js
ADDED
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import { AdvancedIText as q } from "./engine/fabric.js";
|
|
2
|
+
import { s as d, D as R, a as U, b, C as B } from "./design-C_TmcalT.js";
|
|
3
|
+
import { F as Q, S as ee, u as re } from "./design-C_TmcalT.js";
|
|
4
|
+
import { jsx as r, jsxs as N } from "react/jsx-runtime";
|
|
5
|
+
import { useMemo as c, useEffect as a } from "react";
|
|
6
|
+
import { DEFAULT_PRINTINE_API_BASE_URL as y, createDesignerApiClient as M } from "./api/client.js";
|
|
7
|
+
import { setDesignerApiClient as u } from "./api/endpoints.js";
|
|
8
|
+
import { CommonApi as te, DesignApi as ae } from "./api/endpoints.js";
|
|
9
|
+
import { DEFAULT_PRINTINE_ASSET_BASE_URL as h, createAssetCenterApiClient as O } from "./api/asset-client.js";
|
|
10
|
+
import { s as x } from "./designer-store-Da9fICz8.js";
|
|
11
|
+
import { A as se, u as ie } from "./designer-store-Da9fICz8.js";
|
|
12
|
+
import { d as z, s as H } from "./config-D2qm60gf.js";
|
|
13
|
+
import { P as me, a as pe } from "./semi-interact-editor-DfzphWy3.js";
|
|
14
|
+
import { P as ge } from "./pixel-map-dSys7UAx.js";
|
|
15
|
+
import { CanvasDesigner as ce, renderPlacementPreviews as ue } from "./engine/canvas-designer.js";
|
|
16
|
+
import { Editor as Ee } from "./engine/editor.js";
|
|
17
|
+
import { HistoryManager as Te } from "./engine/history.js";
|
|
18
|
+
import { ALIGN_TYPES as Ie, DEFAULT_FILL_COLOR_LIST as Pe, DEFAULT_FONT_SIZE as ve, ELEMENT_TITLE_MAP as _e, FONT_WEIGHT as Le, LAYER_BLACK_LIST as Se } from "./engine/constants.js";
|
|
19
|
+
import { createEventBus as Fe, default as Re } from "./engine/events.js";
|
|
20
|
+
import { SnaplineManager as be } from "./engine/managers/snapline.js";
|
|
21
|
+
import { ResizeManager as Ne } from "./engine/managers/resize.js";
|
|
22
|
+
import { WorkspaceManager as Me } from "./engine/managers/workspace.js";
|
|
23
|
+
import { EventManager as Oe } from "./engine/managers/event.js";
|
|
24
|
+
import { ImageProcessor as He } from "./engine/processors/image.js";
|
|
25
|
+
import { TextProcessor as we } from "./engine/processors/text.js";
|
|
26
|
+
import { TemplateProcessor as Ye } from "./engine/processors/template.js";
|
|
27
|
+
import { blobToDataURL as We, blobUrlToFile as Ke, cloneObject as Ve, dataUrlToFile as Xe, directionOffsetToXY as Ze, generateThumbImage as $e, getCanvasSize as qe, resizeBase64Image as Je, toHorizontalRaw as Qe, toVerticalStack as er, urlToBlob as rr, urlToDataURL as or, xyToDirectionOffset as tr } from "./engine/utils/common.js";
|
|
28
|
+
import { loadImage as nr, loadOverlaySvgImage as sr, loadSvgImage as ir } from "./engine/utils/image.js";
|
|
29
|
+
import { fontCache as mr, loadFontFile as pr, loadFontface as fr } from "./engine/utils/font.js";
|
|
30
|
+
import { DEFAULT_DPI as dr, inchToPixel as cr, isSvg as ur } from "./engine/utils/measure.js";
|
|
31
|
+
import { Loading as Er } from "./engine/utils/loading.js";
|
|
32
|
+
import { getImageControls as Tr, setDefaultControls as Dr } from "./engine/utils/setting.js";
|
|
33
|
+
import { fabric as Pr } from "fabric";
|
|
34
|
+
function X(e) {
|
|
35
|
+
const {
|
|
36
|
+
productId: o,
|
|
37
|
+
apiBaseUrl: i = y,
|
|
38
|
+
assetBaseUrl: l = h,
|
|
39
|
+
locale: n,
|
|
40
|
+
imageBaseUrl: m,
|
|
41
|
+
threeDEnvironmentUrl: E,
|
|
42
|
+
basePlateId: A,
|
|
43
|
+
basePlate: T,
|
|
44
|
+
loading: D = !1,
|
|
45
|
+
initialDesignData: I,
|
|
46
|
+
initialBackgroundCustomized: P,
|
|
47
|
+
productInfo: v,
|
|
48
|
+
adapters: t,
|
|
49
|
+
// Legacy top-level prop (kept for reference; uploads now come from adapters):
|
|
50
|
+
// uploadImage,
|
|
51
|
+
semiDesignPermission: _,
|
|
52
|
+
messages: L,
|
|
53
|
+
className: S,
|
|
54
|
+
children: C,
|
|
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]);
|
|
59
|
+
return a(() => {
|
|
60
|
+
p?.({ name: "ready", productId: o });
|
|
61
|
+
}, [p, o]), a(() => (u(s), () => u(null)), [s]), a(() => (x(g), () => x(null)), [g]), a(() => (d(f ?? null), () => d(null)), [f]), H({
|
|
62
|
+
...m !== void 0 ? { imageBaseUrl: m } : {}
|
|
63
|
+
}), /* @__PURE__ */ r(
|
|
64
|
+
R,
|
|
65
|
+
{
|
|
66
|
+
value: {
|
|
67
|
+
productId: o,
|
|
68
|
+
basePlateId: A,
|
|
69
|
+
initialDesignData: I,
|
|
70
|
+
initialBackgroundCustomized: P,
|
|
71
|
+
productInfo: v,
|
|
72
|
+
uploadImage: t?.uploadImage,
|
|
73
|
+
assets: t?.assets,
|
|
74
|
+
templates: t?.templates,
|
|
75
|
+
library: t?.library,
|
|
76
|
+
locale: n,
|
|
77
|
+
threeDEnvironmentUrl: E,
|
|
78
|
+
messages: L,
|
|
79
|
+
onClose: F,
|
|
80
|
+
onSave: e.onSave,
|
|
81
|
+
onRenderPreview: e.onRenderPreview,
|
|
82
|
+
onError: e.onError,
|
|
83
|
+
onEvent: e.onEvent,
|
|
84
|
+
api: s
|
|
85
|
+
},
|
|
86
|
+
children: /* @__PURE__ */ N(
|
|
87
|
+
"section",
|
|
88
|
+
{
|
|
89
|
+
className: ["printine-designer", S].filter(Boolean).join(" "),
|
|
90
|
+
"data-product-id": o,
|
|
91
|
+
style: {
|
|
92
|
+
"--printine-designer-transparent-pattern": `url("${z("/images/design/transparent_pattern.svg")}")`
|
|
93
|
+
},
|
|
94
|
+
children: [
|
|
95
|
+
/* @__PURE__ */ r("main", { className: "printine-designer__content", children: C ?? (D ? /* @__PURE__ */ r(U, {}) : /* @__PURE__ */ r(b, { basePlate: T, semiDesignPermission: _ })) }),
|
|
96
|
+
/* @__PURE__ */ r(B, {})
|
|
97
|
+
]
|
|
98
|
+
}
|
|
99
|
+
)
|
|
100
|
+
}
|
|
101
|
+
);
|
|
102
|
+
}
|
|
103
|
+
export {
|
|
104
|
+
Ie as ALIGN_TYPES,
|
|
105
|
+
q as AdvancedIText,
|
|
106
|
+
se as AssetCenterApi,
|
|
107
|
+
ce as CanvasDesigner,
|
|
108
|
+
te as CommonApi,
|
|
109
|
+
dr as DEFAULT_DPI,
|
|
110
|
+
Pe as DEFAULT_FILL_COLOR_LIST,
|
|
111
|
+
ve as DEFAULT_FONT_SIZE,
|
|
112
|
+
h as DEFAULT_PRINTINE_ASSET_BASE_URL,
|
|
113
|
+
ae as DesignApi,
|
|
114
|
+
R as DesignerRuntimeProvider,
|
|
115
|
+
_e as ELEMENT_TITLE_MAP,
|
|
116
|
+
Ee as Editor,
|
|
117
|
+
Oe as EventManager,
|
|
118
|
+
Le as FONT_WEIGHT,
|
|
119
|
+
Q as FontList,
|
|
120
|
+
b as FullDesigner,
|
|
121
|
+
Te as HistoryManager,
|
|
122
|
+
He as ImageProcessor,
|
|
123
|
+
Se as LAYER_BLACK_LIST,
|
|
124
|
+
Er as Loading,
|
|
125
|
+
ge as PixelMapRenderer,
|
|
126
|
+
X as PrintineDesigner,
|
|
127
|
+
me as PrintineSemiInteractEditor,
|
|
128
|
+
pe as PrintineSemiRenderer,
|
|
129
|
+
Ne as ResizeManager,
|
|
130
|
+
ee as SimpleSelect,
|
|
131
|
+
be as SnaplineManager,
|
|
132
|
+
Ye as TemplateProcessor,
|
|
133
|
+
we as TextProcessor,
|
|
134
|
+
Me as WorkspaceManager,
|
|
135
|
+
We as blobToDataURL,
|
|
136
|
+
Ke as blobUrlToFile,
|
|
137
|
+
Ve as cloneObject,
|
|
138
|
+
O as createAssetCenterApiClient,
|
|
139
|
+
M as createDesignerApiClient,
|
|
140
|
+
Fe as createEventBus,
|
|
141
|
+
Xe as dataUrlToFile,
|
|
142
|
+
Re as designerEventBus,
|
|
143
|
+
Ze as directionOffsetToXY,
|
|
144
|
+
Pr as fabric,
|
|
145
|
+
mr as fontCache,
|
|
146
|
+
$e as generateThumbImage,
|
|
147
|
+
qe as getCanvasSize,
|
|
148
|
+
Tr as getImageControls,
|
|
149
|
+
cr as inchToPixel,
|
|
150
|
+
ur as isSvg,
|
|
151
|
+
pr as loadFontFile,
|
|
152
|
+
fr as loadFontface,
|
|
153
|
+
nr as loadImage,
|
|
154
|
+
sr as loadOverlaySvgImage,
|
|
155
|
+
ir as loadSvgImage,
|
|
156
|
+
ue as renderPlacementPreviews,
|
|
157
|
+
Je as resizeBase64Image,
|
|
158
|
+
x as setAssetCenterApiClient,
|
|
159
|
+
Dr as setDefaultControls,
|
|
160
|
+
u as setDesignerApiClient,
|
|
161
|
+
Qe as toHorizontalRaw,
|
|
162
|
+
er as toVerticalStack,
|
|
163
|
+
rr as urlToBlob,
|
|
164
|
+
or as urlToDataURL,
|
|
165
|
+
re as useDesignerRuntime,
|
|
166
|
+
ie as useDesignerStore,
|
|
167
|
+
tr as xyToDirectionOffset
|
|
168
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Analytics indirection.
|
|
3
|
+
*
|
|
4
|
+
* The package never talks to gtag, Meta or Reddit pixels directly. It emits
|
|
5
|
+
* named editor events and the host decides whether to forward them anywhere.
|
|
6
|
+
*/
|
|
7
|
+
export type DesignerAnalyticsEvent = 'preview_design';
|
|
8
|
+
export type DesignerAnalyticsHandler = (event: DesignerAnalyticsEvent, payload: Record<string, unknown>) => void;
|
|
9
|
+
/** Registered by `PrintineDesigner`; unset on unmount. */
|
|
10
|
+
export declare function setAnalyticsHandler(next: DesignerAnalyticsHandler | null): void;
|
|
11
|
+
export declare const DesignerAnalytics: {
|
|
12
|
+
previewDesign: (productId?: string | number, modelId?: string | number) => void;
|
|
13
|
+
};
|
|
14
|
+
/** Compatibility alias for the migrated components. */
|
|
15
|
+
export declare const GtagEvents: {
|
|
16
|
+
previewDesign: (productId?: string | number, modelId?: string | number) => void;
|
|
17
|
+
};
|
package/dist/lib/cn.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/** Converts a `#rgb`/`#rrggbb` string to its RGB channels. */
|
|
2
|
+
export declare const hexToRgb: (hex: string) => {
|
|
3
|
+
r: number;
|
|
4
|
+
g: number;
|
|
5
|
+
b: number;
|
|
6
|
+
};
|
|
7
|
+
export declare const roundToDecimals: (num: number, decimals?: number) => number;
|
|
8
|
+
/**
|
|
9
|
+
* Appends the OSS resize query used for thumbnails. SVG and video assets are
|
|
10
|
+
* returned untouched because the OSS pipeline cannot resize them.
|
|
11
|
+
*/
|
|
12
|
+
export declare const getScaleImage: (url: string, params: string) => string;
|
|
13
|
+
/** Prefixes an OSS object key with the configured image base URL. */
|
|
14
|
+
export declare const getFullImageUrl: (path: string) => string;
|
|
15
|
+
/** True when a hex colour resolves to pure white. */
|
|
16
|
+
export declare const isWhite: (code: string) => boolean;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Runtime configuration shared by non-React modules.
|
|
3
|
+
*
|
|
4
|
+
* The host app previously read build-time environment variables. The package
|
|
5
|
+
* takes configuration as props instead, so it carries no host-environment coupling.
|
|
6
|
+
*/
|
|
7
|
+
export interface DesignerConfig {
|
|
8
|
+
/** Prefix prepended to OSS object keys returned by the upload endpoints. */
|
|
9
|
+
imageBaseUrl: string;
|
|
10
|
+
}
|
|
11
|
+
export declare const designerConfig: DesignerConfig;
|
|
12
|
+
export declare function setDesignerConfig(next: Partial<DesignerConfig>): void;
|
|
13
|
+
/** Resolves an editor asset embedded in the package output. */
|
|
14
|
+
export declare function designerAssetUrl(path: string): string;
|
|
@@ -0,0 +1,137 @@
|
|
|
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
|
|
2
|
+
in vec2 a_position; in vec2 a_uv; uniform vec2 u_resolution;
|
|
3
|
+
out vec2 v_uv; out vec2 v_position;
|
|
4
|
+
void main() {
|
|
5
|
+
vec2 clip = (a_position / u_resolution) * 2.0 - 1.0;
|
|
6
|
+
gl_Position = vec4(clip * vec2(1.0, -1.0), 0.0, 1.0);
|
|
7
|
+
v_uv = a_uv; v_position = a_position;
|
|
8
|
+
}\`,ie=\`#version 300 es
|
|
9
|
+
precision highp float;
|
|
10
|
+
uniform sampler2D u_image; uniform sampler2D u_mask;
|
|
11
|
+
uniform int u_mode; uniform float u_opacity; uniform vec4 u_tint; uniform vec4 u_mask_rect;
|
|
12
|
+
in vec2 v_uv; in vec2 v_position; out vec4 out_color;
|
|
13
|
+
void main() {
|
|
14
|
+
vec4 source = texture(u_image, v_uv);
|
|
15
|
+
if (u_mode == 1) {
|
|
16
|
+
vec2 maskUv = (v_position - u_mask_rect.xy) / u_mask_rect.zw;
|
|
17
|
+
if (maskUv.x < 0.0 || maskUv.y < 0.0 || maskUv.x > 1.0 || maskUv.y > 1.0) discard;
|
|
18
|
+
vec4 mask = texture(u_mask, maskUv);
|
|
19
|
+
source *= mask.a;
|
|
20
|
+
} else if (u_mode == 2) {
|
|
21
|
+
float tintAlpha = source.a * u_tint.a;
|
|
22
|
+
source = vec4(u_tint.rgb * tintAlpha, tintAlpha);
|
|
23
|
+
} else if (u_mode == 3) {
|
|
24
|
+
vec2 maskUv = (v_position - u_mask_rect.xy) / u_mask_rect.zw;
|
|
25
|
+
if (maskUv.x < 0.0 || maskUv.y < 0.0 || maskUv.x > 1.0 || maskUv.y > 1.0) discard;
|
|
26
|
+
vec4 mask = texture(u_mask, maskUv);
|
|
27
|
+
float maskAlpha = mask.a;
|
|
28
|
+
float designMask = mask.a;
|
|
29
|
+
float designAlpha = source.a * designMask;
|
|
30
|
+
float combinedAlpha = designAlpha + maskAlpha * (1.0 - designAlpha);
|
|
31
|
+
vec3 designColor = source.rgb * designMask;
|
|
32
|
+
vec3 fillColor = u_tint.rgb * maskAlpha;
|
|
33
|
+
source = vec4(designColor + fillColor * (1.0 - designAlpha), combinedAlpha);
|
|
34
|
+
}
|
|
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)})}}})();
|
|
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
|
+
function b(i) {
|
|
39
|
+
let e;
|
|
40
|
+
try {
|
|
41
|
+
if (e = m && (self.URL || self.webkitURL).createObjectURL(m), !e) throw "";
|
|
42
|
+
const t = new Worker(e, {
|
|
43
|
+
name: i?.name
|
|
44
|
+
});
|
|
45
|
+
return t.addEventListener("error", () => {
|
|
46
|
+
(self.URL || self.webkitURL).revokeObjectURL(e);
|
|
47
|
+
}), t;
|
|
48
|
+
} catch {
|
|
49
|
+
return new Worker(
|
|
50
|
+
"data:text/javascript;charset=utf-8," + encodeURIComponent(h),
|
|
51
|
+
{
|
|
52
|
+
name: i?.name
|
|
53
|
+
}
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
function x(i, e, t = !!i.texture) {
|
|
58
|
+
return !i.design || t || !!e;
|
|
59
|
+
}
|
|
60
|
+
function f(i) {
|
|
61
|
+
if (!i) return i;
|
|
62
|
+
const e = typeof document < "u" ? document.baseURI : typeof location < "u" ? location.href : void 0;
|
|
63
|
+
if (!e) return i;
|
|
64
|
+
try {
|
|
65
|
+
return new URL(i, e).href;
|
|
66
|
+
} catch {
|
|
67
|
+
return i;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
class g {
|
|
71
|
+
constructor() {
|
|
72
|
+
this.worker = null, this.nextRequestId = 0, this.pending = /* @__PURE__ */ new Map(), this.renderQueue = Promise.resolve();
|
|
73
|
+
}
|
|
74
|
+
static isSupported() {
|
|
75
|
+
return typeof Worker < "u" && typeof OffscreenCanvas < "u" && typeof createImageBitmap < "u";
|
|
76
|
+
}
|
|
77
|
+
ensureWorker() {
|
|
78
|
+
if (this.worker) return this.worker;
|
|
79
|
+
if (!g.isSupported()) throw new Error("Pixel-map rendering requires Worker, OffscreenCanvas, and ImageBitmap support");
|
|
80
|
+
const e = new b();
|
|
81
|
+
return e.onmessage = (t) => {
|
|
82
|
+
const r = t.data, s = this.pending.get(r.id);
|
|
83
|
+
s && (this.pending.delete(r.id), r.type === "result" ? s.resolve(r.blob) : r.type === "preloaded" ? s.resolve(null) : s.reject(new Error(r.message)));
|
|
84
|
+
}, e.onerror = (t) => {
|
|
85
|
+
const r = t.filename ? ` (${t.filename}:${t.lineno}:${t.colno})` : "", s = t.error instanceof Error ? t.error : new Error(`${t.message || "Pixel-map worker failed"}${r}`);
|
|
86
|
+
this.pending.forEach(({ reject: a }) => a(s)), this.pending.clear(), this.worker === e && (e.terminate(), this.worker = null);
|
|
87
|
+
}, e.onmessageerror = () => {
|
|
88
|
+
const t = new Error("Pixel-map worker could not deserialize its render payload");
|
|
89
|
+
this.pending.forEach(({ reject: r }) => r(t)), this.pending.clear(), this.worker === e && (e.terminate(), this.worker = null);
|
|
90
|
+
}, this.worker = e, e;
|
|
91
|
+
}
|
|
92
|
+
/** Warm compressed resources without exporting Fabric or entering the GPU queue. */
|
|
93
|
+
async preloadAssets(e, t = !1) {
|
|
94
|
+
const r = [...new Set(e.filter(Boolean).map(f))];
|
|
95
|
+
if (!r.length) return;
|
|
96
|
+
const s = this.ensureWorker(), a = ++this.nextRequestId;
|
|
97
|
+
await new Promise((u, o) => {
|
|
98
|
+
this.pending.set(a, { resolve: u, reject: o });
|
|
99
|
+
try {
|
|
100
|
+
s.postMessage({ type: "preload", id: a, sources: r, priority: t });
|
|
101
|
+
} catch (c) {
|
|
102
|
+
this.pending.delete(a), o(c instanceof Error ? c : new Error(String(c)));
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
async onOffscreenRender(e, t = {}) {
|
|
107
|
+
const r = e.flatMap((o) => t.composition === "design-layer" && !o.design ? [] : x(o, t.color) ? [o.image, typeof o.texture == "string" ? o.texture : ""] : []), s = this.preloadAssets(r, !0);
|
|
108
|
+
s.catch(() => {
|
|
109
|
+
});
|
|
110
|
+
const a = async () => {
|
|
111
|
+
await s;
|
|
112
|
+
const o = this.ensureWorker(), c = ++this.nextRequestId, d = await Promise.all(e.map(async (n) => {
|
|
113
|
+
const l = n.texture instanceof ImageBitmap ? await createImageBitmap(n.texture) : typeof n.texture == "string" ? f(n.texture) : n.texture;
|
|
114
|
+
return {
|
|
115
|
+
...n,
|
|
116
|
+
image: f(n.image),
|
|
117
|
+
texture: l
|
|
118
|
+
};
|
|
119
|
+
})), p = d.map((n) => n.texture).filter((n) => n instanceof ImageBitmap);
|
|
120
|
+
return new Promise((n, l) => {
|
|
121
|
+
this.pending.set(c, { resolve: n, reject: l });
|
|
122
|
+
const y = { type: "render", id: c, areas: d, options: t };
|
|
123
|
+
o.postMessage(y, p);
|
|
124
|
+
});
|
|
125
|
+
}, u = this.renderQueue.then(a, a);
|
|
126
|
+
return this.renderQueue = u.then(() => {
|
|
127
|
+
}, () => {
|
|
128
|
+
}), u;
|
|
129
|
+
}
|
|
130
|
+
destroy() {
|
|
131
|
+
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();
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
export {
|
|
135
|
+
g as P,
|
|
136
|
+
x as r
|
|
137
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { TDRender } from '../contracts/api-design';
|
|
2
|
+
export interface ThreeDPreviewProps {
|
|
3
|
+
model: TDRender;
|
|
4
|
+
/** Preview images keyed by placement name and/or base plate area id. */
|
|
5
|
+
textures: Record<string, string | ImageBitmap>;
|
|
6
|
+
environmentUrl?: string;
|
|
7
|
+
className?: string;
|
|
8
|
+
onError?: (error: unknown) => void;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Lazy 3D renderer. It stays out of the main designer entry until a host opens
|
|
12
|
+
* a 3D preview, keeping Pixi/Babylon out of the canvas editor's initial load.
|
|
13
|
+
*/
|
|
14
|
+
export declare function ThreeDPreview({ model, textures, environmentUrl, className, onError }: ThreeDPreviewProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export type LatestTask = () => Promise<void>;
|
|
2
|
+
/**
|
|
3
|
+
* Runs one task at a time while retaining only the newest task submitted
|
|
4
|
+
* during an active run. This prevents rapid editor input from building an
|
|
5
|
+
* unbounded queue of obsolete preview renders.
|
|
6
|
+
*/
|
|
7
|
+
export declare class LatestTaskQueue {
|
|
8
|
+
private readonly onBusy;
|
|
9
|
+
private readonly onIdle;
|
|
10
|
+
private pending;
|
|
11
|
+
private running;
|
|
12
|
+
constructor(onBusy: () => void, onIdle: () => void);
|
|
13
|
+
get active(): boolean;
|
|
14
|
+
enqueue(task: LatestTask): void;
|
|
15
|
+
clear(): void;
|
|
16
|
+
private drain;
|
|
17
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { RenderArea } from '../contracts/api-design';
|
|
2
|
+
/**
|
|
3
|
+
* OffscreenCanvas/WebGL2 Worker implementation of the 2D product-preview
|
|
4
|
+
* pipeline. It shares the existing RenderArea contract with StickerPlugin.
|
|
5
|
+
*/
|
|
6
|
+
export type PixelMapArea = Omit<RenderArea, 'texture'> & {
|
|
7
|
+
texture?: string | ImageBitmap;
|
|
8
|
+
config?: Record<string, unknown>;
|
|
9
|
+
};
|
|
10
|
+
export interface PixelMapRenderOptions {
|
|
11
|
+
color?: string;
|
|
12
|
+
scale?: number;
|
|
13
|
+
/** Longest output edge in CSS-independent pixels. */
|
|
14
|
+
targetSize?: number;
|
|
15
|
+
/** Render only the mapped design pixels so static product assets can stay in the DOM. */
|
|
16
|
+
composition?: 'full' | 'design-layer';
|
|
17
|
+
quality?: number;
|
|
18
|
+
format?: 'image/png' | 'image/webp';
|
|
19
|
+
/** Stable per-view key reserved for renderer-side caching. */
|
|
20
|
+
cacheKey?: string | number;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* A small client for the pixel-mapping Worker. It owns neither textures nor
|
|
24
|
+
* object URLs, so callers can keep their current Fabric/Pixi lifecycle rules.
|
|
25
|
+
*/
|
|
26
|
+
export declare class PixelMapRenderer {
|
|
27
|
+
private worker;
|
|
28
|
+
private nextRequestId;
|
|
29
|
+
private pending;
|
|
30
|
+
private renderQueue;
|
|
31
|
+
static isSupported(): boolean;
|
|
32
|
+
private ensureWorker;
|
|
33
|
+
/** Warm compressed resources without exporting Fabric or entering the GPU queue. */
|
|
34
|
+
preloadAssets(sources: string[], priority?: boolean): Promise<void>;
|
|
35
|
+
onOffscreenRender(areas: PixelMapArea[], options?: PixelMapRenderOptions): Promise<Blob | null>;
|
|
36
|
+
destroy(): void;
|
|
37
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/** Keep these resource URLs alive until the consumer closes its editing session. */
|
|
2
|
+
export interface SemiResourceLease {
|
|
3
|
+
urls: Record<string, string>;
|
|
4
|
+
release: () => void;
|
|
5
|
+
}
|
|
6
|
+
/** One encoded-resource session shared by Fabric, the Worker, and host loading UI. */
|
|
7
|
+
export declare class SemiResourceCache {
|
|
8
|
+
private urls;
|
|
9
|
+
private disposed;
|
|
10
|
+
private current;
|
|
11
|
+
private holds;
|
|
12
|
+
private cache;
|
|
13
|
+
private key;
|
|
14
|
+
private sources;
|
|
15
|
+
private updatePins;
|
|
16
|
+
pin(sources: string[]): void;
|
|
17
|
+
hold(sources: string[]): () => void;
|
|
18
|
+
preload(sources: string[], priority?: boolean): Promise<void>;
|
|
19
|
+
url(source: string): Promise<string>;
|
|
20
|
+
acquire(sources: string[]): Promise<SemiResourceLease>;
|
|
21
|
+
dispose(): void;
|
|
22
|
+
}
|
|
23
|
+
/** Include nested/group/clip-path images and SVG-image sources, not just top-level objects. */
|
|
24
|
+
export declare function documentImageSources(document: Record<string, unknown>): string[];
|
|
25
|
+
/** Rewrite a private Fabric snapshot only; never mutate the host's persisted design URLs. */
|
|
26
|
+
export declare function cachedFabricDocument(document: Record<string, unknown>, resources: Pick<SemiResourceCache, 'url'>): Promise<Record<string, unknown>>;
|
|
27
|
+
/** Interaction snapshots must never persist temporary session URLs. */
|
|
28
|
+
export declare function originalFabricDocument(document: Record<string, unknown>, lease: SemiResourceLease, original: Record<string, unknown>): Record<string, unknown>;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { RenderArea } from '../contracts/api-design';
|
|
2
|
+
|
|
3
|
+
export class StickerPlugin {
|
|
4
|
+
constructor(
|
|
5
|
+
canvasOrSize: { width: number; height: number } | HTMLCanvasElement,
|
|
6
|
+
headless?: boolean,
|
|
7
|
+
options?: { subdiv?: number; stagePadding?: number },
|
|
8
|
+
);
|
|
9
|
+
onOffscreenRender(
|
|
10
|
+
areas: Array<Omit<RenderArea, 'texture'> & { texture?: string | ImageBitmap }>,
|
|
11
|
+
options?: {
|
|
12
|
+
color?: string;
|
|
13
|
+
scale?: number;
|
|
14
|
+
cleanCache?: boolean;
|
|
15
|
+
quality?: number;
|
|
16
|
+
format?: string;
|
|
17
|
+
removeBg?: boolean;
|
|
18
|
+
},
|
|
19
|
+
): Promise<Blob | undefined>;
|
|
20
|
+
destroy(): void;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export class Sticker3DPlugin {
|
|
24
|
+
constructor(container: HTMLCanvasElement);
|
|
25
|
+
init(options?: { envUrl?: string }): Promise<unknown> | unknown;
|
|
26
|
+
loadModel(url: string): Promise<unknown>;
|
|
27
|
+
replaceTexture(
|
|
28
|
+
url: string | ImageBitmap,
|
|
29
|
+
name: string,
|
|
30
|
+
transform: Record<string, unknown>,
|
|
31
|
+
visible: boolean,
|
|
32
|
+
): Promise<unknown> | undefined;
|
|
33
|
+
dispose(): void;
|
|
34
|
+
}
|