@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
|
@@ -0,0 +1,801 @@
|
|
|
1
|
+
import { AdvancedIText as A } from "./fabric.js";
|
|
2
|
+
import { v4 as M } from "uuid";
|
|
3
|
+
import { cloneObject as b, urlToDataURL as E } from "./utils/common.js";
|
|
4
|
+
import { loadOverlaySvgImage as T, loadImage as B } from "./utils/image.js";
|
|
5
|
+
import { Loading as Y } from "./utils/loading.js";
|
|
6
|
+
import { HistoryManager as X } from "./history.js";
|
|
7
|
+
import { LAYER_BLACK_LIST as R } from "./constants.js";
|
|
8
|
+
import U from "./events.js";
|
|
9
|
+
import { ImageProcessor as L } from "./processors/image.js";
|
|
10
|
+
import { TemplateProcessor as W } from "./processors/template.js";
|
|
11
|
+
import { TextProcessor as D } from "./processors/text.js";
|
|
12
|
+
import { ResizeManager as _ } from "./managers/resize.js";
|
|
13
|
+
import { WorkspaceManager as q } from "./managers/workspace.js";
|
|
14
|
+
import { fabric as p } from "fabric";
|
|
15
|
+
class se {
|
|
16
|
+
constructor(t, a, e, r = {}) {
|
|
17
|
+
this.previewExporting = !1, this.imageCache = /* @__PURE__ */ new Map(), this.overlayCache = /* @__PURE__ */ new Map(), this.destroyed = !1, this.deleteObject = (n) => {
|
|
18
|
+
if (n) {
|
|
19
|
+
const i = this.canvas._objects.find((c) => c.id === n);
|
|
20
|
+
i && (this.canvas.remove(i), this.revokeImgBlobLink(i));
|
|
21
|
+
} else {
|
|
22
|
+
const i = this.canvas.getActiveObjects();
|
|
23
|
+
i.length > 0 && (i.forEach((c) => {
|
|
24
|
+
this.canvas.remove(c), this.revokeImgBlobLink(c);
|
|
25
|
+
}), this.canvas.discardActiveObject());
|
|
26
|
+
}
|
|
27
|
+
this.canvas.requestRenderAll();
|
|
28
|
+
};
|
|
29
|
+
const s = typeof r == "number" ? { overlayScale: r } : r;
|
|
30
|
+
this.canvas = new p.Canvas(t, {
|
|
31
|
+
enableRetinaScaling: !0,
|
|
32
|
+
width: a.width,
|
|
33
|
+
height: a.height,
|
|
34
|
+
preserveObjectStacking: !0,
|
|
35
|
+
stopContextMenu: !1,
|
|
36
|
+
centeredRotation: !0,
|
|
37
|
+
hoverCursor: "grab",
|
|
38
|
+
moveCursor: "grabbing",
|
|
39
|
+
allowTouchScrolling: !0,
|
|
40
|
+
selection: !0,
|
|
41
|
+
interactive: !0,
|
|
42
|
+
controlsAboveOverlay: !0,
|
|
43
|
+
fireRightClick: !0
|
|
44
|
+
// 允许识别右键点击
|
|
45
|
+
}), this.overlayScale = s.overlayScale ?? 0.85, this.loadingOptions = s.loading ?? {}, this.events = s.events ?? U, this.imageProcessor = new L(this), this.templateProcessor = new W(this), this.textProcessor = new D(this), this.resizeManager = new _(this, e), this.workspaceManager = new q(this, s.workspace), this.setupImageCacheInterceptor();
|
|
46
|
+
}
|
|
47
|
+
get isPreviewExporting() {
|
|
48
|
+
return this.previewExporting;
|
|
49
|
+
}
|
|
50
|
+
/** Fabric callbacks can finish after React has unmounted the editor. */
|
|
51
|
+
isCanvasReady() {
|
|
52
|
+
const t = this.canvas;
|
|
53
|
+
return !this.destroyed && !!(t.contextContainer && t.contextTop);
|
|
54
|
+
}
|
|
55
|
+
/** Builds a loading indicator that already carries the package asset configuration. */
|
|
56
|
+
createLoading(t) {
|
|
57
|
+
return new Y(this.canvas, t, this.loadingOptions);
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* 统一拦截图片创建:优先从会话缓存复用已加载的 HTMLImageElement,避免视图切换或导出时重复请求远程图片
|
|
61
|
+
*/
|
|
62
|
+
setupImageCacheInterceptor() {
|
|
63
|
+
const t = this.imageCache, a = p.Image.fromURL, e = p.Image.fromObject;
|
|
64
|
+
if (p.Image._printineCacheHooked) return;
|
|
65
|
+
p.Image._printineCacheHooked = !0;
|
|
66
|
+
const r = (n) => {
|
|
67
|
+
if (!n) return null;
|
|
68
|
+
const i = t.get(n);
|
|
69
|
+
return i?.element && i.element.complete ? (t.set(n, { ...i, lastUsed: Date.now() }), i.element) : null;
|
|
70
|
+
};
|
|
71
|
+
p.Image.fromURL = function(n, i, c) {
|
|
72
|
+
const o = { ...c, crossOrigin: "anonymous" }, l = r(n);
|
|
73
|
+
if (l) {
|
|
74
|
+
const f = new p.Image(l, o);
|
|
75
|
+
f.originSrc = n, i && i(f);
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
return a.call(
|
|
79
|
+
this,
|
|
80
|
+
n,
|
|
81
|
+
(f) => {
|
|
82
|
+
f && (f.originSrc = n), i && i(f);
|
|
83
|
+
},
|
|
84
|
+
o
|
|
85
|
+
);
|
|
86
|
+
};
|
|
87
|
+
const s = (n) => !!n && typeof n == "object" && typeof n.set == "function" && typeof n.shouldCache == "function";
|
|
88
|
+
p.Image.fromObject = function(n, i) {
|
|
89
|
+
const c = n?.originSrc || n?.src, o = r(c);
|
|
90
|
+
if (o) {
|
|
91
|
+
const { clipPath: l, ...f } = n ?? {}, v = new p.Image(o, { ...f });
|
|
92
|
+
if (v.originSrc = c, !l || s(l)) {
|
|
93
|
+
l && (v.clipPath = l), i?.(v);
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
p.util.enlivenObjects(
|
|
97
|
+
[l],
|
|
98
|
+
(u) => {
|
|
99
|
+
const [C] = u || [];
|
|
100
|
+
C && (v.clipPath = C), i?.(v);
|
|
101
|
+
},
|
|
102
|
+
""
|
|
103
|
+
);
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
return e.call(this, { ...n, crossOrigin: "anonymous" }, i);
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* 渲染 overlayImage(SVG)
|
|
111
|
+
* @param mockup 模板信息
|
|
112
|
+
* @param changeView 是否切换视图,如果为 true,则需要重新设置画布和背景图
|
|
113
|
+
*/
|
|
114
|
+
async renderOverlayImage(t, a = !1) {
|
|
115
|
+
const { image: e, clipPath: r } = await this.getOverlayImage(t.image);
|
|
116
|
+
if (!this.isCanvasReady()) return;
|
|
117
|
+
const s = Math.min(this.canvas.width, this.canvas.height) * this.overlayScale, n = s / e.width, i = s / e.height, c = Math.min(n, i);
|
|
118
|
+
return e.set({
|
|
119
|
+
scaleX: c,
|
|
120
|
+
scaleY: c,
|
|
121
|
+
left: (this.canvas.width - e.width * c) / 2,
|
|
122
|
+
top: (this.canvas.height - e.height * c) / 2,
|
|
123
|
+
selectable: !1
|
|
124
|
+
}), r && r.set({
|
|
125
|
+
scaleX: c,
|
|
126
|
+
scaleY: c,
|
|
127
|
+
left: (this.canvas.width - r.width * c) / 2,
|
|
128
|
+
top: (this.canvas.height - r.height * c) / 2,
|
|
129
|
+
absolutePositioned: !0,
|
|
130
|
+
selectable: !1,
|
|
131
|
+
evented: !1
|
|
132
|
+
}), a && this.canvas.setViewportTransform([1, 0, 0, 1, 0, 0]), new Promise((o) => {
|
|
133
|
+
this.canvas.setOverlayImage(e, async () => {
|
|
134
|
+
if (!this.isCanvasReady()) {
|
|
135
|
+
o();
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
this.workspaceManager.setClipPath(r ?? e, {
|
|
139
|
+
width: e.width,
|
|
140
|
+
height: e.height
|
|
141
|
+
}), this.setupOverlayBorders(e, r), this.canvas.renderAll(), o();
|
|
142
|
+
});
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* 获取 overlay 图:优先使用会话级缓存,避免重复网络请求
|
|
147
|
+
* 会返回深拷贝,确保不同视图间互不影响
|
|
148
|
+
*/
|
|
149
|
+
async getOverlayImage(t) {
|
|
150
|
+
const a = this.overlayCache.get(t);
|
|
151
|
+
if (a) {
|
|
152
|
+
const n = await b(a.image), i = a.clipPath ? await b(a.clipPath) : void 0;
|
|
153
|
+
return { image: n, clipPath: i };
|
|
154
|
+
}
|
|
155
|
+
const e = await T(t);
|
|
156
|
+
this.overlayCache.set(t, e);
|
|
157
|
+
const r = await b(e.image), s = e.clipPath ? await b(e.clipPath) : void 0;
|
|
158
|
+
return { image: r, clipPath: s };
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* 绘制可设计区域边框,优先使用 clipPath 的真实形状
|
|
162
|
+
*/
|
|
163
|
+
setupOverlayBorders(t, a) {
|
|
164
|
+
this.overlayBorderHandler && this.canvas.off("after:render", this.overlayBorderHandler);
|
|
165
|
+
const e = a ?? t;
|
|
166
|
+
this.overlayBorderHandler = () => {
|
|
167
|
+
if (this.previewExporting) return;
|
|
168
|
+
const r = this.canvas.getContext(), s = this.canvas.viewportTransform || [1, 0, 0, 1, 0, 0];
|
|
169
|
+
r.save(), r.transform(s[0], s[1], s[2], s[3], s[4], s[5]);
|
|
170
|
+
const n = {
|
|
171
|
+
stroke: e.stroke,
|
|
172
|
+
strokeWidth: e.strokeWidth,
|
|
173
|
+
strokeDashArray: e.strokeDashArray,
|
|
174
|
+
fill: e.fill,
|
|
175
|
+
strokeUniform: e.strokeUniform
|
|
176
|
+
};
|
|
177
|
+
e.set({
|
|
178
|
+
stroke: "#C3C3CC",
|
|
179
|
+
strokeWidth: 1,
|
|
180
|
+
strokeDashArray: [],
|
|
181
|
+
fill: "transparent",
|
|
182
|
+
strokeUniform: !0,
|
|
183
|
+
objectCaching: !1
|
|
184
|
+
}), e.render(r);
|
|
185
|
+
const i = 6, c = (e.getScaledWidth() + i * 2) / e.getScaledWidth(), o = (e.getScaledHeight() + i * 2) / e.getScaledHeight(), l = e.left ?? 0, f = e.top ?? 0, v = e.scaleX ?? 1, u = e.scaleY ?? 1;
|
|
186
|
+
e.set({
|
|
187
|
+
strokeDashArray: [4, 4],
|
|
188
|
+
stroke: "#C3C3CC",
|
|
189
|
+
strokeWidth: 1,
|
|
190
|
+
strokeUniform: !0,
|
|
191
|
+
scaleX: v * c,
|
|
192
|
+
scaleY: u * o,
|
|
193
|
+
left: l - i,
|
|
194
|
+
top: f - i
|
|
195
|
+
}), e.render(r), e.set({
|
|
196
|
+
stroke: n.stroke,
|
|
197
|
+
strokeWidth: n.strokeWidth,
|
|
198
|
+
strokeDashArray: n.strokeDashArray,
|
|
199
|
+
fill: n.fill,
|
|
200
|
+
strokeUniform: n.strokeUniform,
|
|
201
|
+
scaleX: v,
|
|
202
|
+
scaleY: u,
|
|
203
|
+
left: l,
|
|
204
|
+
top: f
|
|
205
|
+
}), r.restore();
|
|
206
|
+
}, this.canvas.on("after:render", this.overlayBorderHandler);
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* 设置背景遮罩
|
|
210
|
+
*/
|
|
211
|
+
async setBackgroundMask(t) {
|
|
212
|
+
const a = document.querySelector(".lower-canvas");
|
|
213
|
+
if (a && !t)
|
|
214
|
+
return a.style.backgroundImage = "", Promise.resolve();
|
|
215
|
+
const e = await B(t);
|
|
216
|
+
if (e == null) return Promise.resolve();
|
|
217
|
+
e.set({
|
|
218
|
+
scaleX: this.canvas.width / e.width,
|
|
219
|
+
scaleY: this.canvas.height / e.height
|
|
220
|
+
});
|
|
221
|
+
const r = e.toDataURL({ format: "png" });
|
|
222
|
+
a && (a.style.backgroundImage = `url(${r})`, a.style.backgroundSize = "100% 100%");
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* 设置背景颜色、透明图案
|
|
226
|
+
*/
|
|
227
|
+
async setBackground(t) {
|
|
228
|
+
t ? await this.workspaceManager.setFillColor(t) : await this.workspaceManager.setTransparentPattern(), this.isCanvasReady() && this.canvas.requestRenderAll();
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* 获取当前选中的对象
|
|
232
|
+
*/
|
|
233
|
+
get activeObject() {
|
|
234
|
+
return this.canvas.getActiveObject();
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* 获取对象经过画布转换后的实际尺寸
|
|
238
|
+
*/
|
|
239
|
+
getObjectActualSize(t) {
|
|
240
|
+
const { left: a = 0, top: e = 0, width: r = 0, height: s = 0 } = t.getBoundingRect(), n = t.getCenterPoint(), i = this.canvas.viewportTransform;
|
|
241
|
+
return {
|
|
242
|
+
left: a * i[0] + i[4],
|
|
243
|
+
top: e * i[3] + i[5],
|
|
244
|
+
width: r * i[0],
|
|
245
|
+
height: s * i[3],
|
|
246
|
+
centerX: n.x * i[0] + i[4],
|
|
247
|
+
centerY: n.y * i[3] + i[5]
|
|
248
|
+
};
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* 添加对象
|
|
252
|
+
*/
|
|
253
|
+
addObject(t, a = !0) {
|
|
254
|
+
t.set({
|
|
255
|
+
id: M()
|
|
256
|
+
}), this.canvas.add(t), a && this.canvas.setActiveObject(t);
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* 恢复对象
|
|
260
|
+
*/
|
|
261
|
+
async restoreObject(t) {
|
|
262
|
+
return new Promise((a) => {
|
|
263
|
+
p.util.enlivenObjects([t], (e) => a(e), "");
|
|
264
|
+
});
|
|
265
|
+
}
|
|
266
|
+
/**
|
|
267
|
+
* 清理图片 blob URL(只清理不在缓存中的临时 blob)
|
|
268
|
+
*/
|
|
269
|
+
revokeImgBlobLink(t) {
|
|
270
|
+
if (t.type === "image" && t.getSrc) {
|
|
271
|
+
const a = t, e = a.getSrc(), r = a.originSrc || e;
|
|
272
|
+
if (e && e.startsWith("blob:")) {
|
|
273
|
+
const s = this.imageCache.get(r);
|
|
274
|
+
if (!s || s.blobUrl !== e)
|
|
275
|
+
try {
|
|
276
|
+
URL.revokeObjectURL(e);
|
|
277
|
+
} catch {
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
/**
|
|
283
|
+
* 修改对象的属性
|
|
284
|
+
*/
|
|
285
|
+
updateObject(t, a) {
|
|
286
|
+
const e = this.canvas._objects.find((r) => r.id === t);
|
|
287
|
+
if (e) {
|
|
288
|
+
if (Object.prototype.hasOwnProperty.call(a, "angle"))
|
|
289
|
+
e.rotate(a.angle);
|
|
290
|
+
else if (Object.prototype.hasOwnProperty.call(a, "align")) {
|
|
291
|
+
const { left: r, right: s, top: n, bottom: i, center: c } = this.workspaceManager.dimension, o = e.getBoundingRect(!0, !0);
|
|
292
|
+
switch (a.align) {
|
|
293
|
+
case "top":
|
|
294
|
+
e.set({
|
|
295
|
+
top: e.top + (n - o.top)
|
|
296
|
+
});
|
|
297
|
+
break;
|
|
298
|
+
case "left":
|
|
299
|
+
e.set({
|
|
300
|
+
left: e.left + (r - o.left)
|
|
301
|
+
});
|
|
302
|
+
break;
|
|
303
|
+
case "horizontal-center":
|
|
304
|
+
e.set({
|
|
305
|
+
left: e.left + (c.x - (o.left + o.width / 2))
|
|
306
|
+
});
|
|
307
|
+
break;
|
|
308
|
+
case "right":
|
|
309
|
+
e.set({
|
|
310
|
+
left: e.left + (s - (o.left + o.width))
|
|
311
|
+
});
|
|
312
|
+
break;
|
|
313
|
+
case "vertical-center":
|
|
314
|
+
e.set({
|
|
315
|
+
top: e.top + (c.y - (o.top + o.height / 2))
|
|
316
|
+
});
|
|
317
|
+
break;
|
|
318
|
+
case "bottom":
|
|
319
|
+
e.set({
|
|
320
|
+
top: e.top + (i - (o.top + o.height))
|
|
321
|
+
});
|
|
322
|
+
break;
|
|
323
|
+
}
|
|
324
|
+
} else if (Object.prototype.hasOwnProperty.call(a, "zIndex"))
|
|
325
|
+
this.canvas.moveTo(e, a.zIndex);
|
|
326
|
+
else if (Object.prototype.hasOwnProperty.call(a, "scale"))
|
|
327
|
+
this.updateObjectScale(e, a.scale);
|
|
328
|
+
else if (Object.prototype.hasOwnProperty.call(a, "width") || Object.prototype.hasOwnProperty.call(a, "height")) {
|
|
329
|
+
const r = Object.prototype.hasOwnProperty.call(a, "width") ? e.width : e.height, n = (a.width || a.height) / r * this.workspaceManager.scale;
|
|
330
|
+
this.updateObjectScale(e, n);
|
|
331
|
+
} else
|
|
332
|
+
e.set(a);
|
|
333
|
+
e.setCoords(), this.canvas.requestRenderAll(), Object.prototype.hasOwnProperty.call(a, "selectable") || this.canvas.fire("object:modified", {
|
|
334
|
+
target: e
|
|
335
|
+
});
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
/**
|
|
339
|
+
* 对象缩放
|
|
340
|
+
*/
|
|
341
|
+
updateObjectScale(t, a) {
|
|
342
|
+
const e = t.getCenterPoint(), r = this.workspaceManager.dimension.width * 0.01 / t.width;
|
|
343
|
+
t.scale(a < r ? r : a), t.setPositionByOrigin(e, "center", "center");
|
|
344
|
+
}
|
|
345
|
+
/**
|
|
346
|
+
* 修改画布上的对象的选中状态和事件状态
|
|
347
|
+
*/
|
|
348
|
+
updateObjectsEvents(t) {
|
|
349
|
+
this.canvas.forEachObject((a) => {
|
|
350
|
+
a.set({
|
|
351
|
+
selectable: t,
|
|
352
|
+
evented: t
|
|
353
|
+
});
|
|
354
|
+
});
|
|
355
|
+
}
|
|
356
|
+
/**
|
|
357
|
+
* 获取当前可选择的对象,不包括背景图、裁剪区域
|
|
358
|
+
*/
|
|
359
|
+
getLayerList() {
|
|
360
|
+
return this.canvas._objects.filter((t) => !R.includes(t.id || ""));
|
|
361
|
+
}
|
|
362
|
+
/**
|
|
363
|
+
* 设置当前选中的对象
|
|
364
|
+
*/
|
|
365
|
+
setActiveObject(t) {
|
|
366
|
+
const a = this.canvas.getActiveObjects(), e = a.some((s) => s.id === t), r = this.getLayerList().find((s) => s.id === t);
|
|
367
|
+
r && (this.canvas.discardActiveObject(), (!e || a.length > 1) && this.canvas.setActiveObject(r), this.canvas.requestRenderAll());
|
|
368
|
+
}
|
|
369
|
+
/**
|
|
370
|
+
* 同时选中多个对象
|
|
371
|
+
*/
|
|
372
|
+
setActiveObjects(t) {
|
|
373
|
+
const a = new p.ActiveSelection(t, { canvas: this.canvas });
|
|
374
|
+
this.canvas.setActiveObject(a), this.canvas.requestRenderAll();
|
|
375
|
+
}
|
|
376
|
+
/**
|
|
377
|
+
* 以画布中心点缩放画布
|
|
378
|
+
*/
|
|
379
|
+
zoomToCenter(t) {
|
|
380
|
+
if (t === 1)
|
|
381
|
+
this.canvas.setViewportTransform([1, 0, 0, 1, 0, 0]);
|
|
382
|
+
else {
|
|
383
|
+
const a = this.canvas.viewportTransform, e = a[0], r = a[4], s = a[5], n = this.canvas.width / 2, i = this.canvas.height / 2, c = t - e, o = r - n * c, l = s - i * c;
|
|
384
|
+
this.canvas.setViewportTransform([t, 0, 0, t, o, l]);
|
|
385
|
+
}
|
|
386
|
+
this.canvas.requestRenderAll();
|
|
387
|
+
}
|
|
388
|
+
/**
|
|
389
|
+
* 获取当前画布上渲染的对象
|
|
390
|
+
*/
|
|
391
|
+
getRenderedObjects() {
|
|
392
|
+
const { objects: t } = this.canvas.toJSON(X.DEFAULT_SAVE_PROPERTIES), a = this.workspaceManager.dimension;
|
|
393
|
+
return {
|
|
394
|
+
objects: t.filter((e) => !R.includes(e.id || "")),
|
|
395
|
+
workspaceMetadata: {
|
|
396
|
+
width: a.width,
|
|
397
|
+
height: a.height,
|
|
398
|
+
centerX: a.center.x,
|
|
399
|
+
centerY: a.center.y
|
|
400
|
+
}
|
|
401
|
+
};
|
|
402
|
+
}
|
|
403
|
+
/**
|
|
404
|
+
* 清空当前画布
|
|
405
|
+
*/
|
|
406
|
+
clearCanvas() {
|
|
407
|
+
this.isCanvasReady() && this.canvas._objects.length && (this.canvas.clear(), this.canvas.requestRenderAll());
|
|
408
|
+
}
|
|
409
|
+
/**
|
|
410
|
+
* 将图片对象的 clipPath 重新关联到画布上的对象
|
|
411
|
+
*/
|
|
412
|
+
relinkClipPaths() {
|
|
413
|
+
const t = /* @__PURE__ */ new Map(), a = this.canvas.getObjects(), e = (s) => {
|
|
414
|
+
const n = s.id;
|
|
415
|
+
n && t.set(String(n), s), s.type === "group" && s._objects?.forEach(e);
|
|
416
|
+
};
|
|
417
|
+
a.forEach(e);
|
|
418
|
+
const r = (s) => {
|
|
419
|
+
const i = s.clipPath?.id;
|
|
420
|
+
if (i && t.has(String(i))) {
|
|
421
|
+
const c = t.get(String(i));
|
|
422
|
+
c.set({ absolutePositioned: !0 }), s.set("clipPath", c), s.dirty = !0;
|
|
423
|
+
}
|
|
424
|
+
s.type === "group" && s._objects?.forEach(r);
|
|
425
|
+
};
|
|
426
|
+
a.forEach(r);
|
|
427
|
+
}
|
|
428
|
+
/**
|
|
429
|
+
* 切换视图,重新渲染画布
|
|
430
|
+
*/
|
|
431
|
+
async switchView(t, a, e) {
|
|
432
|
+
if (this.isCanvasReady()) {
|
|
433
|
+
if (this.canvas.clear(), e && e.objects && e.objects.length)
|
|
434
|
+
return p.AdvancedIText = A, await this.textProcessor.preloadFontsFromState(e), this.isCanvasReady() ? new Promise((r) => {
|
|
435
|
+
this.canvas.loadFromJSON(
|
|
436
|
+
e,
|
|
437
|
+
async () => {
|
|
438
|
+
if (!this.isCanvasReady()) {
|
|
439
|
+
r();
|
|
440
|
+
return;
|
|
441
|
+
}
|
|
442
|
+
if (this.relinkClipPaths(), await this.renderOverlayImage(t, !0), await this.setBackground(a), !this.isCanvasReady()) {
|
|
443
|
+
r();
|
|
444
|
+
return;
|
|
445
|
+
}
|
|
446
|
+
e.workspaceMetadata && this._scaleObjectsToWorkspace(e.workspaceMetadata);
|
|
447
|
+
const s = this.canvas.getObjects().filter((n) => n.type === "image");
|
|
448
|
+
if (s.length > 0 && await Promise.all(
|
|
449
|
+
s.map((n) => new Promise((i) => {
|
|
450
|
+
const c = n.getElement(), o = n.getSrc() || n.originSrc;
|
|
451
|
+
if (!o) {
|
|
452
|
+
i();
|
|
453
|
+
return;
|
|
454
|
+
}
|
|
455
|
+
c && c.complete && c.naturalWidth > 0 ? (this.registerImageCache(o, n), i()) : c ? (c.onload = () => {
|
|
456
|
+
this.registerImageCache(o, n), i();
|
|
457
|
+
}, c.onerror = () => {
|
|
458
|
+
i();
|
|
459
|
+
}) : i();
|
|
460
|
+
}))
|
|
461
|
+
), !this.isCanvasReady()) {
|
|
462
|
+
r();
|
|
463
|
+
return;
|
|
464
|
+
}
|
|
465
|
+
this.canvas.renderAll(), this.events.emit("design:layerChange"), r();
|
|
466
|
+
},
|
|
467
|
+
(s, n) => {
|
|
468
|
+
s.clipPath && !e.objects.some((i) => i.id === s.clipPath.id) && (delete n.clipPath, p.util.enlivenObjects(
|
|
469
|
+
[s.clipPath],
|
|
470
|
+
(i) => {
|
|
471
|
+
const c = i[0];
|
|
472
|
+
c && (n.set("clipPath", c), n.dirty = !0, this.isCanvasReady() && this.canvas.requestRenderAll());
|
|
473
|
+
},
|
|
474
|
+
""
|
|
475
|
+
));
|
|
476
|
+
}
|
|
477
|
+
);
|
|
478
|
+
}) : void 0;
|
|
479
|
+
await this.renderOverlayImage(t, !0), await this.setBackground(a), this.isCanvasReady() && e && e.object && await this.imageProcessor.addBitmapImage(e.object, {}, !1);
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
/**
|
|
483
|
+
* 根据 workspace 尺寸变化,按比例缩放所有对象
|
|
484
|
+
*/
|
|
485
|
+
_scaleObjectsToWorkspace(t) {
|
|
486
|
+
const a = this.workspaceManager.dimension, e = Math.min(
|
|
487
|
+
a.width / t.width,
|
|
488
|
+
a.height / t.height
|
|
489
|
+
), r = t.centerX, s = t.centerY, n = a.center.x, i = a.center.y, c = Math.abs(n - r), o = Math.abs(i - s), l = Math.abs(e - 1) >= 1e-3, f = c >= 0.1 || o >= 0.1;
|
|
490
|
+
if (!l && !f) return;
|
|
491
|
+
const v = this.canvas.getObjects(), u = new Set(v), C = /* @__PURE__ */ new Set(), P = (d) => {
|
|
492
|
+
const g = d.clipPath;
|
|
493
|
+
g && u.has(g) && C.add(g);
|
|
494
|
+
};
|
|
495
|
+
v.forEach(P);
|
|
496
|
+
const O = (d) => {
|
|
497
|
+
const g = (d.left || 0) - r, y = (d.top || 0) - s, w = n + g * e, m = i + y * e;
|
|
498
|
+
d.set({
|
|
499
|
+
left: w,
|
|
500
|
+
top: m,
|
|
501
|
+
scaleX: (d.scaleX || 1) * e,
|
|
502
|
+
scaleY: (d.scaleY || 1) * e
|
|
503
|
+
}), d.setCoords(), d.dirty = !0;
|
|
504
|
+
}, k = /* @__PURE__ */ new Set(), S = (d) => {
|
|
505
|
+
!d.selectable && !C.has(d) || (O(d), k.add(d));
|
|
506
|
+
};
|
|
507
|
+
v.forEach(S);
|
|
508
|
+
const h = (d) => {
|
|
509
|
+
const g = d.clipPath;
|
|
510
|
+
g && g.absolutePositioned && !u.has(g) && !k.has(g) && (O(g), k.add(g));
|
|
511
|
+
};
|
|
512
|
+
v.forEach(h);
|
|
513
|
+
}
|
|
514
|
+
/**
|
|
515
|
+
* 计算对象相对于画布的全局变换矩阵(包括父组的影响)
|
|
516
|
+
*/
|
|
517
|
+
getGlobalTransformMatrix(t) {
|
|
518
|
+
return t.calcTransformMatrix();
|
|
519
|
+
}
|
|
520
|
+
/**
|
|
521
|
+
* 判断对象是否位于 activeSelection 中
|
|
522
|
+
*/
|
|
523
|
+
isInActiveSelection(t) {
|
|
524
|
+
let a = t.group;
|
|
525
|
+
for (; a; ) {
|
|
526
|
+
if (a.type === "activeSelection") return !0;
|
|
527
|
+
a = a.group;
|
|
528
|
+
}
|
|
529
|
+
return !1;
|
|
530
|
+
}
|
|
531
|
+
/**
|
|
532
|
+
* 注册图片到缓存(会话级缓存,整个编辑期间保持)
|
|
533
|
+
*/
|
|
534
|
+
registerImageCache(t, a, e) {
|
|
535
|
+
if (!t || t.startsWith("data:")) return;
|
|
536
|
+
const r = a.getElement(), s = this.imageCache.get(t);
|
|
537
|
+
this.imageCache.set(t, {
|
|
538
|
+
element: r,
|
|
539
|
+
blobUrl: e || s?.blobUrl,
|
|
540
|
+
lastUsed: Date.now()
|
|
541
|
+
});
|
|
542
|
+
}
|
|
543
|
+
/**
|
|
544
|
+
* 清除整个图片缓存(在关闭编辑器时调用)
|
|
545
|
+
*/
|
|
546
|
+
clearImageCache() {
|
|
547
|
+
this.imageCache.forEach((t) => {
|
|
548
|
+
if (t.blobUrl)
|
|
549
|
+
try {
|
|
550
|
+
URL.revokeObjectURL(t.blobUrl);
|
|
551
|
+
} catch {
|
|
552
|
+
}
|
|
553
|
+
}), this.imageCache.clear();
|
|
554
|
+
}
|
|
555
|
+
/**
|
|
556
|
+
* 销毁编辑器,释放所有资源
|
|
557
|
+
*/
|
|
558
|
+
destroy() {
|
|
559
|
+
if (this.destroyed) return;
|
|
560
|
+
this.destroyed = !0, this.clearImageCache();
|
|
561
|
+
const t = this.canvas;
|
|
562
|
+
t.contextContainer && t.contextTop && (t.cancelRequestedRender?.(), t.dispose()), this.resizeManager.destroy();
|
|
563
|
+
}
|
|
564
|
+
/**
|
|
565
|
+
* 按需生成图片 dataURL(不缓存,减少内存占用)
|
|
566
|
+
*/
|
|
567
|
+
async getCachedDataURL(t) {
|
|
568
|
+
if (!t)
|
|
569
|
+
return "";
|
|
570
|
+
const a = this.imageCache.get(t);
|
|
571
|
+
if (a?.element && a.element.complete) {
|
|
572
|
+
const e = document.createElement("canvas");
|
|
573
|
+
e.width = a.element.naturalWidth || a.element.width, e.height = a.element.naturalHeight || a.element.height;
|
|
574
|
+
const r = e.getContext("2d");
|
|
575
|
+
if (r) {
|
|
576
|
+
r.drawImage(a.element, 0, 0);
|
|
577
|
+
const s = e.toDataURL("image/png");
|
|
578
|
+
return e.width = 0, e.height = 0, s;
|
|
579
|
+
}
|
|
580
|
+
return "";
|
|
581
|
+
}
|
|
582
|
+
return await E(t);
|
|
583
|
+
}
|
|
584
|
+
/**
|
|
585
|
+
* 从缓存克隆图片,避免重复下载
|
|
586
|
+
*/
|
|
587
|
+
async cloneImageFromCache(t, a) {
|
|
588
|
+
const e = t.getSrc() || "", r = t.originSrc || "", s = t.isCropped, n = r || e;
|
|
589
|
+
if (n.startsWith("data:"))
|
|
590
|
+
return new Promise((c) => {
|
|
591
|
+
t.clone((o) => {
|
|
592
|
+
o.set(a), c(o);
|
|
593
|
+
}, ["absolutePositioned"]);
|
|
594
|
+
});
|
|
595
|
+
const i = this.imageCache.get(n);
|
|
596
|
+
return i?.element && i.element.complete ? new Promise(async (c) => {
|
|
597
|
+
const o = new p.Image(i.element, {
|
|
598
|
+
width: t.width,
|
|
599
|
+
height: t.height,
|
|
600
|
+
...a
|
|
601
|
+
});
|
|
602
|
+
if (t.clipPath)
|
|
603
|
+
try {
|
|
604
|
+
const l = await b(t.clipPath, ["absolutePositioned"]);
|
|
605
|
+
o.set({ clipPath: l });
|
|
606
|
+
} catch {
|
|
607
|
+
}
|
|
608
|
+
s && (o.isCropped = !0, o.cropBlob = t.cropBlob), c(o);
|
|
609
|
+
}) : new Promise((c) => {
|
|
610
|
+
t.clone((o) => {
|
|
611
|
+
this.registerImageCache(n, o), o.set(a), s && (o.isCropped = !0, o.cropBlob = t.cropBlob), c(o);
|
|
612
|
+
}, ["absolutePositioned"]);
|
|
613
|
+
});
|
|
614
|
+
}
|
|
615
|
+
/**
|
|
616
|
+
* 导出 clipPath 区域内容(按打印区域原始尺寸)
|
|
617
|
+
* @param embedImages 是否将图片转为 dataURL 内嵌
|
|
618
|
+
* @param color 背景颜色
|
|
619
|
+
*/
|
|
620
|
+
async export(t = !1, a) {
|
|
621
|
+
const e = this.workspaceManager.dimension, r = this.workspaceManager.printAreaSize?.width ?? e.width, s = this.workspaceManager.printAreaSize?.height ?? e.height, n = window.devicePixelRatio || 1, i = Math.max(r / e.width, s / e.height), c = Math.max(4, Math.min(8, Math.ceil(i * n)));
|
|
622
|
+
let o = new p.Rect({
|
|
623
|
+
left: 0,
|
|
624
|
+
top: 0,
|
|
625
|
+
width: e.width,
|
|
626
|
+
height: e.height,
|
|
627
|
+
absolutePositioned: !0,
|
|
628
|
+
strokeWidth: 0
|
|
629
|
+
});
|
|
630
|
+
this.canvas.clipPath && (o = await b(this.canvas.clipPath, ["absolutePositioned"]), o.set({
|
|
631
|
+
left: this.canvas.clipPath.left - e.left,
|
|
632
|
+
top: this.canvas.clipPath.top - e.top,
|
|
633
|
+
absolutePositioned: !0
|
|
634
|
+
}));
|
|
635
|
+
const l = new p.StaticCanvas(null, {
|
|
636
|
+
width: e.width,
|
|
637
|
+
height: e.height,
|
|
638
|
+
enableRetinaScaling: !1,
|
|
639
|
+
backgroundColor: a || "transparent",
|
|
640
|
+
preserveObjectStacking: !0,
|
|
641
|
+
clipPath: o
|
|
642
|
+
}), f = this.getLayerList();
|
|
643
|
+
(await Promise.all(
|
|
644
|
+
f.map(
|
|
645
|
+
(h) => new Promise((d) => {
|
|
646
|
+
try {
|
|
647
|
+
if (h.type === "image") {
|
|
648
|
+
const g = h;
|
|
649
|
+
let y = {
|
|
650
|
+
selectable: !1,
|
|
651
|
+
evented: !1,
|
|
652
|
+
flipX: h.flipX || !1,
|
|
653
|
+
flipY: h.flipY || !1
|
|
654
|
+
};
|
|
655
|
+
if (this.isInActiveSelection(h)) {
|
|
656
|
+
const w = this.getGlobalTransformMatrix(h), m = p.util.qrDecompose(w);
|
|
657
|
+
y = {
|
|
658
|
+
...y,
|
|
659
|
+
left: (m.translateX || 0) - (e.left || 0),
|
|
660
|
+
top: (m.translateY || 0) - (e.top || 0),
|
|
661
|
+
angle: m.angle || 0,
|
|
662
|
+
scaleX: m.scaleX || 1,
|
|
663
|
+
scaleY: m.scaleY || 1,
|
|
664
|
+
originX: "center",
|
|
665
|
+
originY: "center"
|
|
666
|
+
};
|
|
667
|
+
} else
|
|
668
|
+
y = {
|
|
669
|
+
...y,
|
|
670
|
+
left: h.left - e.left,
|
|
671
|
+
top: h.top - e.top,
|
|
672
|
+
angle: h.angle || 0,
|
|
673
|
+
scaleX: h.scaleX || 1,
|
|
674
|
+
scaleY: h.scaleY || 1,
|
|
675
|
+
originX: "left",
|
|
676
|
+
originY: "top"
|
|
677
|
+
};
|
|
678
|
+
this.cloneImageFromCache(g, y).then(async (w) => {
|
|
679
|
+
if (w.clipPath) {
|
|
680
|
+
const m = w.clipPath;
|
|
681
|
+
m.absolutePositioned && m.set({
|
|
682
|
+
left: (m.left || 0) - e.left,
|
|
683
|
+
top: (m.top || 0) - e.top
|
|
684
|
+
});
|
|
685
|
+
}
|
|
686
|
+
if (t && w.type === "image")
|
|
687
|
+
try {
|
|
688
|
+
const m = w, I = m.getSrc() || m.originSrc || "";
|
|
689
|
+
if (I) {
|
|
690
|
+
const x = await this.getCachedDataURL(I);
|
|
691
|
+
m.setSrc(x, () => d(w));
|
|
692
|
+
return;
|
|
693
|
+
}
|
|
694
|
+
} catch {
|
|
695
|
+
}
|
|
696
|
+
d(w);
|
|
697
|
+
}).catch(() => {
|
|
698
|
+
d(h);
|
|
699
|
+
});
|
|
700
|
+
} else
|
|
701
|
+
h.cloneAsImage(
|
|
702
|
+
(g) => {
|
|
703
|
+
if (this.isInActiveSelection(h)) {
|
|
704
|
+
const y = this.getGlobalTransformMatrix(h), w = p.util.qrDecompose(y);
|
|
705
|
+
g.set({
|
|
706
|
+
left: (w.translateX || 0) - (e.left || 0),
|
|
707
|
+
top: (w.translateY || 0) - (e.top || 0),
|
|
708
|
+
angle: w.angle || 0,
|
|
709
|
+
scaleX: (w.scaleX || 1) / c,
|
|
710
|
+
scaleY: (w.scaleY || 1) / c,
|
|
711
|
+
selectable: !1,
|
|
712
|
+
hasControls: !1,
|
|
713
|
+
hasBorders: !1,
|
|
714
|
+
originX: "center",
|
|
715
|
+
originY: "center"
|
|
716
|
+
});
|
|
717
|
+
} else {
|
|
718
|
+
const y = h.getBoundingRect(!0, !0);
|
|
719
|
+
g.set({
|
|
720
|
+
left: y.left - e.left,
|
|
721
|
+
top: y.top - e.top,
|
|
722
|
+
scaleX: 1 / c,
|
|
723
|
+
scaleY: 1 / c,
|
|
724
|
+
angle: 0,
|
|
725
|
+
selectable: !1,
|
|
726
|
+
hasControls: !1,
|
|
727
|
+
hasBorders: !1,
|
|
728
|
+
originX: "left",
|
|
729
|
+
originY: "top"
|
|
730
|
+
});
|
|
731
|
+
}
|
|
732
|
+
d(g);
|
|
733
|
+
},
|
|
734
|
+
{ multiplier: c }
|
|
735
|
+
);
|
|
736
|
+
} catch {
|
|
737
|
+
d(h);
|
|
738
|
+
}
|
|
739
|
+
})
|
|
740
|
+
)
|
|
741
|
+
)).forEach((h) => l.add(h));
|
|
742
|
+
const u = r / e.width, C = s / e.height;
|
|
743
|
+
l.setViewportTransform([u, 0, 0, C, 0, 0]), l.renderAll();
|
|
744
|
+
const P = 1024;
|
|
745
|
+
let O = 1;
|
|
746
|
+
(r < P || s < P) && (O = Math.max(1, P / Math.max(r, s)));
|
|
747
|
+
let k = "";
|
|
748
|
+
const S = () => l.toDataURL({
|
|
749
|
+
format: "webp",
|
|
750
|
+
quality: 0.5,
|
|
751
|
+
width: r,
|
|
752
|
+
height: s,
|
|
753
|
+
multiplier: O
|
|
754
|
+
});
|
|
755
|
+
if (window.createImageBitmap && typeof l.toCanvasElement == "function") {
|
|
756
|
+
const h = l.toCanvasElement(O, { width: r, height: s });
|
|
757
|
+
k = await createImageBitmap(h);
|
|
758
|
+
} else
|
|
759
|
+
k = S();
|
|
760
|
+
return l.dispose(), k;
|
|
761
|
+
}
|
|
762
|
+
/**
|
|
763
|
+
* Rasterize the current design for real-time product previews without
|
|
764
|
+
* cloning objects, embedding source images or serializing a data URL.
|
|
765
|
+
*
|
|
766
|
+
* The returned bitmap is capped by `maxSize` on its longest edge while
|
|
767
|
+
* retaining the physical print-area aspect ratio expected by the mesh.
|
|
768
|
+
*/
|
|
769
|
+
async exportPreviewBitmap(t = 600, a) {
|
|
770
|
+
if (!this.isCanvasReady()) throw new Error("Canvas is not ready");
|
|
771
|
+
const e = this.workspaceManager.dimension, r = this.workspaceManager.printAreaSize?.width ?? e.width, s = this.workspaceManager.printAreaSize?.height ?? e.height;
|
|
772
|
+
if (!e.width || !e.height || !r || !s)
|
|
773
|
+
throw new Error("Printable workspace has no dimensions");
|
|
774
|
+
const n = Math.max(r, s), i = t / n, c = Math.max(1, Math.round(r * i)), o = Math.max(1, Math.round(s * i)), l = this.canvas.viewportTransform?.slice(), f = this.canvas.overlayImage?.visible, v = this.canvas.backgroundColor, u = this.canvas.getActiveObject(), C = u ? { hasBorders: u.hasBorders, hasControls: u.hasControls } : null;
|
|
775
|
+
try {
|
|
776
|
+
this.previewExporting = !0, this.canvas.overlayImage && (this.canvas.overlayImage.visible = !1), u?.set({ hasBorders: !1, hasControls: !1 }), this.canvas.backgroundColor = a || "transparent", this.canvas.viewportTransform = [1, 0, 0, 1, 0, 0], this.canvas.renderAll();
|
|
777
|
+
const P = document.createElement("canvas");
|
|
778
|
+
P.width = c, P.height = o;
|
|
779
|
+
const O = P.getContext("2d", { alpha: !0 });
|
|
780
|
+
if (!O) throw new Error("Could not create preview canvas context");
|
|
781
|
+
const k = this.canvas, S = k.getRetinaScaling?.() ?? window.devicePixelRatio ?? 1;
|
|
782
|
+
return O.drawImage(
|
|
783
|
+
k.lowerCanvasEl,
|
|
784
|
+
e.left * S,
|
|
785
|
+
e.top * S,
|
|
786
|
+
e.width * S,
|
|
787
|
+
e.height * S,
|
|
788
|
+
0,
|
|
789
|
+
0,
|
|
790
|
+
c,
|
|
791
|
+
o
|
|
792
|
+
), await createImageBitmap(P);
|
|
793
|
+
} finally {
|
|
794
|
+
this.canvas.backgroundColor = v, this.canvas.overlayImage && f !== void 0 && (this.canvas.overlayImage.visible = f), u && C && u.set(C), l && (this.canvas.viewportTransform = l), this.previewExporting = !1, this.isCanvasReady() && this.canvas.requestRenderAll();
|
|
795
|
+
}
|
|
796
|
+
}
|
|
797
|
+
}
|
|
798
|
+
export {
|
|
799
|
+
se as Editor,
|
|
800
|
+
se as default
|
|
801
|
+
};
|