@printine/designer 0.1.0

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.
Files changed (199) hide show
  1. package/README.md +146 -0
  2. package/dist/DesignerRuntimeContext.d.ts +3 -0
  3. package/dist/PrintineDesigner.d.ts +9 -0
  4. package/dist/api/client.d.ts +8 -0
  5. package/dist/api/client.js +82 -0
  6. package/dist/api/common-endpoints.d.ts +12 -0
  7. package/dist/api/design-endpoints.d.ts +18 -0
  8. package/dist/api/endpoints.d.ts +33 -0
  9. package/dist/api/endpoints.js +46 -0
  10. package/dist/api/files-endpoints.d.ts +1 -0
  11. package/dist/assets/icons/aspect_ratio.d.ts +3 -0
  12. package/dist/assets/icons/delete.d.ts +3 -0
  13. package/dist/assets/icons/fit_screen.d.ts +3 -0
  14. package/dist/assets/icons/index.d.ts +11 -0
  15. package/dist/assets/icons/loading_1.d.ts +3 -0
  16. package/dist/assets/icons/loading_2.d.ts +3 -0
  17. package/dist/assets/icons/loading_3.d.ts +3 -0
  18. package/dist/assets/icons/pan.d.ts +3 -0
  19. package/dist/assets/icons/setting.d.ts +3 -0
  20. package/dist/assets/icons/text_color.d.ts +3 -0
  21. package/dist/assets/icons/text_h.d.ts +3 -0
  22. package/dist/assets/icons/text_v.d.ts +3 -0
  23. package/dist/bundled-assets.d.ts +4 -0
  24. package/dist/components/add-design.d.ts +8 -0
  25. package/dist/components/assets-dialog.d.ts +21 -0
  26. package/dist/components/canvas-context-menu.d.ts +6 -0
  27. package/dist/components/color-picker/index.d.ts +10 -0
  28. package/dist/components/context.d.ts +24 -0
  29. package/dist/components/design.d.ts +9 -0
  30. package/dist/components/fonts.d.ts +26 -0
  31. package/dist/components/image-crop.d.ts +4 -0
  32. package/dist/components/image-edit.d.ts +1 -0
  33. package/dist/components/layout/aside.d.ts +3 -0
  34. package/dist/components/layout/bottom-nav/element-menu-sheet.d.ts +11 -0
  35. package/dist/components/layout/bottom-nav/element-sheet.d.ts +11 -0
  36. package/dist/components/layout/bottom-nav/index.d.ts +1 -0
  37. package/dist/components/layout/header.d.ts +5 -0
  38. package/dist/components/loading.d.ts +3 -0
  39. package/dist/components/menus/ai.d.ts +5 -0
  40. package/dist/components/menus/background.d.ts +6 -0
  41. package/dist/components/menus/clipart.d.ts +6 -0
  42. package/dist/components/menus/files.d.ts +7 -0
  43. package/dist/components/menus/image.d.ts +8 -0
  44. package/dist/components/menus/index.d.ts +13 -0
  45. package/dist/components/menus/layer.d.ts +5 -0
  46. package/dist/components/menus/product.d.ts +3 -0
  47. package/dist/components/menus/sca.d.ts +5 -0
  48. package/dist/components/menus/shapes.d.ts +6 -0
  49. package/dist/components/menus/templates.d.ts +6 -0
  50. package/dist/components/menus/text-effects.d.ts +5 -0
  51. package/dist/components/menus/text.d.ts +6 -0
  52. package/dist/components/placement-tab.d.ts +7 -0
  53. package/dist/components/preview/3d.d.ts +7 -0
  54. package/dist/components/preview/graphic.d.ts +7 -0
  55. package/dist/components/preview/index.d.ts +18 -0
  56. package/dist/components/preview/open.d.ts +7 -0
  57. package/dist/components/preview/real-time/3d.d.ts +12 -0
  58. package/dist/components/preview/real-time/graphic.d.ts +18 -0
  59. package/dist/components/preview/real-time/index.d.ts +11 -0
  60. package/dist/components/scale-tools.d.ts +7 -0
  61. package/dist/components/semi-deisgn-config.d.ts +13 -0
  62. package/dist/components/semi-design-link.d.ts +9 -0
  63. package/dist/components/store.d.ts +1 -0
  64. package/dist/components/toolbar.d.ts +2 -0
  65. package/dist/config-D2qm60gf.js +16 -0
  66. package/dist/contracts/api-design.d.ts +176 -0
  67. package/dist/contracts/design.d.ts +86 -0
  68. package/dist/design-7zRpRtv9.js +20331 -0
  69. package/dist/engine/canvas-designer.d.ts +101 -0
  70. package/dist/engine/canvas-designer.js +313 -0
  71. package/dist/engine/constants.d.ts +27 -0
  72. package/dist/engine/constants.js +148 -0
  73. package/dist/engine/editor.d.ts +186 -0
  74. package/dist/engine/editor.js +734 -0
  75. package/dist/engine/events.d.ts +34 -0
  76. package/dist/engine/events.js +7 -0
  77. package/dist/engine/extensions/curved-text.d.ts +59 -0
  78. package/dist/engine/fabric.d.ts +4 -0
  79. package/dist/engine/fabric.js +187 -0
  80. package/dist/engine/history.d.ts +27 -0
  81. package/dist/engine/history.js +56 -0
  82. package/dist/engine/managers/event.d.ts +101 -0
  83. package/dist/engine/managers/event.js +410 -0
  84. package/dist/engine/managers/resize.d.ts +24 -0
  85. package/dist/engine/managers/resize.js +63 -0
  86. package/dist/engine/managers/snapline.d.ts +70 -0
  87. package/dist/engine/managers/snapline.js +124 -0
  88. package/dist/engine/managers/workspace.d.ts +26 -0
  89. package/dist/engine/managers/workspace.js +53 -0
  90. package/dist/engine/processors/image.d.ts +88 -0
  91. package/dist/engine/processors/image.js +473 -0
  92. package/dist/engine/processors/template.d.ts +45 -0
  93. package/dist/engine/processors/template.js +314 -0
  94. package/dist/engine/processors/text.d.ts +74 -0
  95. package/dist/engine/processors/text.js +215 -0
  96. package/dist/engine/semi-export-editor.d.ts +199 -0
  97. package/dist/engine/types.d.ts +28 -0
  98. package/dist/engine/utils/common.d.ts +25 -0
  99. package/dist/engine/utils/common.js +68 -0
  100. package/dist/engine/utils/dialog.d.ts +25 -0
  101. package/dist/engine/utils/font.d.ts +5 -0
  102. package/dist/engine/utils/font.js +39 -0
  103. package/dist/engine/utils/image.d.ts +8 -0
  104. package/dist/engine/utils/image.js +50 -0
  105. package/dist/engine/utils/loading.d.ts +17 -0
  106. package/dist/engine/utils/loading.js +71 -0
  107. package/dist/engine/utils/measure.d.ts +6 -0
  108. package/dist/engine/utils/measure.js +6 -0
  109. package/dist/engine/utils/mockup.d.ts +59 -0
  110. package/dist/engine/utils/setting.d.ts +4 -0
  111. package/dist/engine/utils/setting.js +73 -0
  112. package/dist/fabric-types.d.ts +59 -0
  113. package/dist/full-designer.js +14 -0
  114. package/dist/hooks/pagination.d.ts +19 -0
  115. package/dist/hooks/use-adobe-express.d.ts +50 -0
  116. package/dist/hooks/use-before-unload.d.ts +1 -0
  117. package/dist/hooks/use-image-drop.d.ts +18 -0
  118. package/dist/hooks/use-oss-upload.d.ts +34 -0
  119. package/dist/hooks/use-screen.d.ts +1 -0
  120. package/dist/i18n/index.d.ts +12 -0
  121. package/dist/images/design/asset_empty.png +0 -0
  122. package/dist/images/design/design/background.svg +3 -0
  123. package/dist/images/design/design/color-picker.svg +15 -0
  124. package/dist/images/design/design/computer.svg +1 -0
  125. package/dist/images/design/design/copy.svg +1 -0
  126. package/dist/images/design/design/image.svg +10 -0
  127. package/dist/images/design/design/line.svg +1 -0
  128. package/dist/images/design/design/text.svg +1 -0
  129. package/dist/images/design/design/title.svg +1 -0
  130. package/dist/images/design/empty.png +0 -0
  131. package/dist/images/design/layer_empty.png +0 -0
  132. package/dist/images/design/menu/ai.svg +1 -0
  133. package/dist/images/design/menu/back.svg +4 -0
  134. package/dist/images/design/menu/background.svg +6 -0
  135. package/dist/images/design/menu/clipart.svg +6 -0
  136. package/dist/images/design/menu/file.svg +4 -0
  137. package/dist/images/design/menu/fill.svg +1 -0
  138. package/dist/images/design/menu/image.svg +7 -0
  139. package/dist/images/design/menu/layer.svg +6 -0
  140. package/dist/images/design/menu/product.svg +3 -0
  141. package/dist/images/design/menu/sca.svg +5 -0
  142. package/dist/images/design/menu/shapes.svg +5 -0
  143. package/dist/images/design/menu/templates.svg +6 -0
  144. package/dist/images/design/menu/text.svg +6 -0
  145. package/dist/images/design/menu/uploads.svg +7 -0
  146. package/dist/images/design/spinner.svg +3 -0
  147. package/dist/images/design/spinners.svg +17 -0
  148. package/dist/images/design/transparent_pattern.svg +5 -0
  149. package/dist/index.d.ts +39 -0
  150. package/dist/index.js +127 -0
  151. package/dist/lib/analytics.d.ts +17 -0
  152. package/dist/lib/cn.d.ts +3 -0
  153. package/dist/lib/common.d.ts +16 -0
  154. package/dist/lib/config.d.ts +14 -0
  155. package/dist/lib/navigation.d.ts +2 -0
  156. package/dist/renderer/ThreeDPreview.d.ts +14 -0
  157. package/dist/renderer/sticker.js +1731 -0
  158. package/dist/renderer/three-d-preview.js +32 -0
  159. package/dist/state/designer-store.d.ts +43 -0
  160. package/dist/state/designer-store.js +85 -0
  161. package/dist/style.css +1 -0
  162. package/dist/types.d.ts +184 -0
  163. package/dist/ui/accordion.d.ts +7 -0
  164. package/dist/ui/button-group.d.ts +11 -0
  165. package/dist/ui/button.d.ts +10 -0
  166. package/dist/ui/checkbox.d.ts +4 -0
  167. package/dist/ui/command.d.ts +18 -0
  168. package/dist/ui/confirm-dialog.d.ts +15 -0
  169. package/dist/ui/context-menu.d.ts +25 -0
  170. package/dist/ui/dialog.d.ts +15 -0
  171. package/dist/ui/drawer.d.ts +15 -0
  172. package/dist/ui/editable-combobox.d.ts +10 -0
  173. package/dist/ui/hint.d.ts +8 -0
  174. package/dist/ui/image.d.ts +24 -0
  175. package/dist/ui/input-group.d.ts +16 -0
  176. package/dist/ui/input-with-addon.d.ts +17 -0
  177. package/dist/ui/input.d.ts +3 -0
  178. package/dist/ui/label.d.ts +4 -0
  179. package/dist/ui/loading-button.d.ts +15 -0
  180. package/dist/ui/popover.d.ts +9 -0
  181. package/dist/ui/scroll-area.d.ts +5 -0
  182. package/dist/ui/select.d.ts +22 -0
  183. package/dist/ui/separator.d.ts +4 -0
  184. package/dist/ui/shared-loading-button.d.ts +20 -0
  185. package/dist/ui/simple-dialog.d.ts +19 -0
  186. package/dist/ui/simple-popover.d.ts +13 -0
  187. package/dist/ui/simple-select.d.ts +20 -0
  188. package/dist/ui/skeleton.d.ts +2 -0
  189. package/dist/ui/slider.d.ts +4 -0
  190. package/dist/ui/spinner-box.d.ts +12 -0
  191. package/dist/ui/spinner.d.ts +2 -0
  192. package/dist/ui/switch.d.ts +6 -0
  193. package/dist/ui/tab/index.d.ts +15 -0
  194. package/dist/ui/textarea.d.ts +3 -0
  195. package/dist/ui/tooltip.d.ts +7 -0
  196. package/dist/workers/image-resize.worker.d.ts +1 -0
  197. package/dist/workers/mockup.worker.d.ts +5 -0
  198. package/dist/workers/render.worker.d.ts +1 -0
  199. package/package.json +201 -0
@@ -0,0 +1,124 @@
1
+ const d = (u) => Math.floor(u) + 0.5;
2
+ class Y {
3
+ constructor() {
4
+ this.horizontalLine = null, this.verticalLine = null, this.objectsVerticalLines = [], this.objectsHorizontalLines = [], this.snapThreshold = 5, this.snapThresholdForObject = 2, this.isSnapping = !1, this.snappedLineTypes = {
5
+ left: !1,
6
+ top: !1,
7
+ bottom: !1,
8
+ right: !1,
9
+ centerX: !1,
10
+ centerY: !1
11
+ };
12
+ }
13
+ clearGuideLines() {
14
+ this.horizontalLine = null, this.verticalLine = null, this.objectsVerticalLines = [], this.objectsHorizontalLines = [];
15
+ }
16
+ drawGuideLines(e) {
17
+ this.horizontalLine && this.verticalLine && (Object.keys(this.horizontalLine).forEach((t) => {
18
+ this.drawAlignLine(e, t, this.horizontalLine[t]);
19
+ }), Object.keys(this.verticalLine).forEach((t) => {
20
+ this.drawAlignLine(e, t, this.verticalLine[t]);
21
+ })), this.objectsHorizontalLines.forEach((t) => this.drawObjectGuideLine(e, [t.start, t.pos, t.end, t.pos])), this.objectsVerticalLines.forEach((t) => this.drawObjectGuideLine(e, [t.pos, t.start, t.pos, t.end]));
22
+ }
23
+ drawAlignLine(e, t, h) {
24
+ e.save(), e.strokeStyle = "#C9CACC", this.snappedLineTypes[t] ? e.strokeStyle = "#F35B37" : e.setLineDash([5, 4]), e.lineWidth = 1.5, e.beginPath(), e.moveTo(h[0], h[1]), e.lineTo(h[2], h[3]), e.stroke(), e.restore();
25
+ }
26
+ drawObjectGuideLine(e, t) {
27
+ e.save(), e.strokeStyle = "rgb(255, 0, 119)", e.lineWidth = 1, e.beginPath(), e.moveTo(d(t[0]), d(t[1])), e.lineTo(d(t[2]), d(t[3])), e.stroke();
28
+ }
29
+ showGuideLines(e) {
30
+ if (this.horizontalLine || this.verticalLine) return;
31
+ const t = this.generateGuideLines(e);
32
+ this.horizontalLine = { top: t.top, centerX: t.centerX, bottom: t.bottom }, this.verticalLine = { left: t.left, centerY: t.centerY, right: t.right };
33
+ }
34
+ snapToGuidelines(e, t, h) {
35
+ const s = e.viewportTransform, a = this.calcGuidePositions(h, s);
36
+ this.showGuideLines(a);
37
+ const i = this.calcObjectDimensions(t, s);
38
+ if (this.checkSnapConditionsForAllObjects({ canvas: e, currentObject: t, currentObjectDimension: i }), this.isSnapping) return;
39
+ const { newLeft: l, newTop: r } = this.checkSnapConditions(i, a, s);
40
+ if (l !== i.left || r !== i.top) {
41
+ this.isSnapping = !0;
42
+ const f = (l - s[4]) / s[0], L = (r - s[5]) / s[3], o = t.getBoundingRect(!0, !0);
43
+ t.set({ left: t.left + f - o.left, top: t.top + L - o.top }), t.setCoords();
44
+ }
45
+ requestAnimationFrame(() => {
46
+ this.isSnapping = !1;
47
+ });
48
+ }
49
+ snapToObjectGuideLines(e, t) {
50
+ this.checkSnapConditionsForAllObjects({
51
+ canvas: e,
52
+ currentObject: t,
53
+ currentObjectDimension: this.calcObjectDimensions(t, e.viewportTransform),
54
+ snap: !1
55
+ });
56
+ }
57
+ calcGuidePositions(e, t) {
58
+ return {
59
+ left: e.left * t[0] + t[4],
60
+ right: e.right * t[0] + t[4],
61
+ top: e.top * t[3] + t[5],
62
+ bottom: e.bottom * t[3] + t[5],
63
+ centerX: e.center.x * t[0] + t[4],
64
+ centerY: e.center.y * t[3] + t[5]
65
+ };
66
+ }
67
+ calcObjectDimensions(e, t) {
68
+ const h = e.getBoundingRect(!0, !0), s = h.left * t[0] + t[4], a = h.top * t[3] + t[5], i = h.width * t[0], l = h.height * t[3];
69
+ return { width: h.width, height: h.height, left: s, top: a, right: s + i, bottom: a + l, centerX: s + i / 2, centerY: a + l / 2 };
70
+ }
71
+ generateGuideLines(e) {
72
+ return {
73
+ left: [e.left, e.top, e.left, e.bottom],
74
+ right: [e.right, e.top, e.right, e.bottom],
75
+ centerX: [e.centerX, e.top, e.centerX, e.bottom],
76
+ top: [e.left, e.top, e.right, e.top],
77
+ bottom: [e.left, e.bottom, e.right, e.bottom],
78
+ centerY: [e.left, e.centerY, e.right, e.centerY]
79
+ };
80
+ }
81
+ checkSnapConditions(e, t, h) {
82
+ let s = e.left, a = e.top;
83
+ const i = this.snapThreshold;
84
+ return Math.abs(e.left - t.left) < i ? (s = t.left, this.snappedLineTypes.left = !0) : this.snappedLineTypes.left = !1, Math.abs(e.right - t.right) < i ? (s = t.right - e.width * h[0], this.snappedLineTypes.right = !0) : this.snappedLineTypes.right = !1, Math.abs(e.centerX - t.centerX) < i ? (s = t.centerX - e.width * h[0] / 2, this.snappedLineTypes.centerX = !0) : this.snappedLineTypes.centerX = !1, Math.abs(e.top - t.top) < i ? (a = t.top, this.snappedLineTypes.top = !0) : this.snappedLineTypes.top = !1, Math.abs(e.bottom - t.bottom) < i ? (a = t.bottom - e.height * h[3], this.snappedLineTypes.bottom = !0) : this.snappedLineTypes.bottom = !1, Math.abs(e.centerY - t.centerY) < i ? (a = t.centerY - e.height * h[3] / 2, this.snappedLineTypes.centerY = !0) : this.snappedLineTypes.centerY = !1, t.left - e.right >= 0 && (s = t.left - e.width * h[0]), t.right - e.left <= 0 && (s = t.right), t.top - e.bottom >= 0 && (a = t.top - e.height * h[3]), t.bottom - e.top <= 0 && (a = t.bottom), { newLeft: s, newTop: a };
85
+ }
86
+ checkSnapConditionsForAllObjects({ canvas: e, currentObject: t, currentObjectDimension: h, snap: s = !0 }) {
87
+ this.objectsHorizontalLines = [], this.objectsVerticalLines = [];
88
+ const a = [], i = [], l = s ? this.snapThresholdForObject : 1;
89
+ let r = l + 1, f = l + 1, L = 0, o = 0, m = h.top, M = h.left;
90
+ const y = { left: h.left, center: h.centerX, right: h.right }, X = { top: h.top, center: h.centerY, bottom: h.bottom };
91
+ e._objects.forEach((b) => {
92
+ if (b === t || b.excludeHistory || !b.visible || !b.isOnScreen()) return;
93
+ const n = this.calcObjectDimensions(b, e.viewportTransform);
94
+ [n.left, n.centerX, n.right].forEach((g) => {
95
+ Object.values(y).forEach((p) => {
96
+ const c = p - g;
97
+ Math.abs(c) < r && (r = Math.abs(c), L = c, a.length = 0), Math.abs(c) === r && a.push({ pos: g, min: n.top, max: n.bottom });
98
+ });
99
+ }), [n.top, n.centerY, n.bottom].forEach((g) => {
100
+ Object.values(X).forEach((p) => {
101
+ const c = p - g;
102
+ Math.abs(c) < f && (f = Math.abs(c), o = c, i.length = 0), Math.abs(c) === f && i.push({ pos: g, min: n.left, max: n.right });
103
+ });
104
+ });
105
+ }), r <= l && s && (t.set({ left: t.left - L }), M -= L), f <= l && s && (t.set({ top: t.top - o }), m -= o), r <= l && this.addVerticalObjectLines(a, m, h.height), f <= l && this.addHorizontalObjectLines(i, M, h.width);
106
+ }
107
+ addVerticalObjectLines(e, t, h) {
108
+ const s = /* @__PURE__ */ new Map();
109
+ e.forEach((a) => {
110
+ const i = s.get(a.pos) ?? { min: t, max: t + h };
111
+ i.min = Math.min(i.min, a.min), i.max = Math.max(i.max, a.max), s.set(a.pos, i);
112
+ }), s.forEach((a, i) => this.objectsVerticalLines.push({ pos: i, start: a.min, end: a.max }));
113
+ }
114
+ addHorizontalObjectLines(e, t, h) {
115
+ const s = /* @__PURE__ */ new Map();
116
+ e.forEach((a) => {
117
+ const i = s.get(a.pos) ?? { min: t, max: t + h };
118
+ i.min = Math.min(i.min, a.min), i.max = Math.max(i.max, a.max), s.set(a.pos, i);
119
+ }), s.forEach((a, i) => this.objectsHorizontalLines.push({ pos: i, start: a.min, end: a.max }));
120
+ }
121
+ }
122
+ export {
123
+ Y as SnaplineManager
124
+ };
@@ -0,0 +1,26 @@
1
+ import { fabric } from 'fabric';
2
+ import type { PrintArea, RenderableBox, Size } from '../types';
3
+ export interface WorkspaceEditor {
4
+ canvas: fabric.Canvas;
5
+ }
6
+ export interface WorkspaceManagerOptions {
7
+ /** Public path or CDN URL for the transparent-background SVG asset. */
8
+ transparentPatternUrl?: string;
9
+ dpi?: number;
10
+ }
11
+ /** Owns the printable Fabric clip path and its physical print-area mapping. */
12
+ export declare class WorkspaceManager {
13
+ private readonly editor;
14
+ workspace: fabric.Object;
15
+ printAreaSize?: Size;
16
+ private readonly transparentPatternUrl;
17
+ private readonly dpi;
18
+ constructor(editor: WorkspaceEditor, options?: WorkspaceManagerOptions);
19
+ get dimension(): RenderableBox;
20
+ get scale(): number;
21
+ setPrintAreaSize(size: PrintArea): void;
22
+ setClipPath(clipPath: fabric.Object, size: Size): void;
23
+ setFillColor(color: string): void;
24
+ setFillImage(image: string, callback?: () => void): Promise<void>;
25
+ setTransparentPattern(): Promise<void>;
26
+ }
@@ -0,0 +1,53 @@
1
+ import { fabric as s } from "fabric";
2
+ import { loadImage as a } from "../utils/image.js";
3
+ import { d as n } from "../../config-D2qm60gf.js";
4
+ class d {
5
+ constructor(t, e = {}) {
6
+ this.editor = t, this.transparentPatternUrl = e.transparentPatternUrl ?? n("/images/design/transparent_pattern.svg"), this.dpi = e.dpi ?? 300;
7
+ }
8
+ get dimension() {
9
+ if (!this.workspace)
10
+ return { left: 0, top: 0, width: 0, height: 0, right: 0, bottom: 0, center: { x: 0, y: 0 } };
11
+ const t = this.workspace.left ?? 0, e = this.workspace.top ?? 0, i = (this.workspace.width ?? 0) * (this.workspace.scaleX || 1), r = (this.workspace.height ?? 0) * (this.workspace.scaleY || 1);
12
+ return { left: t, top: e, width: i, height: r, right: t + i, bottom: e + r, center: { x: t + i / 2, y: e + r / 2 } };
13
+ }
14
+ get scale() {
15
+ const { width: t, height: e } = this.dimension, i = this.printAreaSize?.width ?? t, r = this.printAreaSize?.height ?? e;
16
+ return i / r - t / e > 0.01 && console.warn("Canvas workspace and physical print area dimensions differ"), t / i;
17
+ }
18
+ setPrintAreaSize(t) {
19
+ this.printAreaSize = { width: t.widthInInch * this.dpi, height: t.heightInInch * this.dpi };
20
+ }
21
+ setClipPath(t, e) {
22
+ this.workspace = t, this.editor.canvas.clipPath = t, this.printAreaSize = { width: e.width, height: e.height };
23
+ }
24
+ setFillColor(t) {
25
+ this.editor.canvas.setBackgroundColor(t, this.editor.canvas.renderAll.bind(this.editor.canvas));
26
+ }
27
+ async setFillImage(t, e) {
28
+ const i = await a(t);
29
+ i.set({
30
+ left: this.workspace.left,
31
+ top: this.workspace.top,
32
+ scaleX: this.workspace.width / i.width,
33
+ scaleY: this.workspace.height / i.height,
34
+ originSrc: t
35
+ }), this.editor.canvas.setBackgroundImage(i, () => {
36
+ this.editor.canvas.renderAll(), e?.();
37
+ });
38
+ }
39
+ async setTransparentPattern() {
40
+ const t = new Image();
41
+ return t.crossOrigin = "anonymous", t.src = this.transparentPatternUrl, new Promise((e) => {
42
+ t.onload = () => {
43
+ const i = new s.Pattern({ source: t, repeat: "repeat" });
44
+ this.editor.canvas.setBackgroundColor(i, () => {
45
+ this.editor.canvas.renderAll(), e();
46
+ });
47
+ }, t.onerror = () => e();
48
+ });
49
+ }
50
+ }
51
+ export {
52
+ d as WorkspaceManager
53
+ };
@@ -0,0 +1,88 @@
1
+ import fabric from '../fabric';
2
+ import '../../fabric-types';
3
+ import type { RenderableBox } from '../types';
4
+ import type { ImageFile } from '../../contracts/design';
5
+ import type { TemplateElement } from '../../contracts/api-design';
6
+ import type { Editor } from '../editor';
7
+ /**
8
+ * 图片处理器
9
+ *
10
+ * Handles adding, replacing, mirroring, fitting and non-destructive cropping of
11
+ * bitmap and SVG layers. Crop results stay serializable as plain Fabric objects.
12
+ */
13
+ export declare class ImageProcessor {
14
+ private editor;
15
+ /** 裁剪框 */
16
+ private cropRect;
17
+ /** 遮罩层 */
18
+ private overlay;
19
+ constructor(editor: Editor);
20
+ /**
21
+ * 给图片添加 svg 形状图片蒙层
22
+ */
23
+ addShapeImage(file: ImageFile, shape: fabric.Object, config?: Record<string, any>): Promise<void>;
24
+ /**
25
+ * 添加图片(本地图片)
26
+ */
27
+ addImage(file: ImageFile, config?: Record<string, any>): Promise<void>;
28
+ /** 添加图片(远程图片),自动区分位图和 SVG */
29
+ addImageFromUrl(url: string, config?: Record<string, any>): Promise<void>;
30
+ /**
31
+ * 添加图片(远程图片),只支持位图
32
+ */
33
+ addBitmapImage(url: string, config?: Record<string, any>): Promise<void>;
34
+ /**
35
+ * 从模板中添加图片
36
+ */
37
+ addImageFromTemplate(el: TemplateElement, area: {
38
+ left: number;
39
+ top: number;
40
+ s: number;
41
+ zIndex: number;
42
+ }): Promise<fabric.Object | null>;
43
+ /**
44
+ * 添加 svg 图片
45
+ */
46
+ addSvgImage(url: string, config?: Record<string, any>): Promise<void>;
47
+ /**
48
+ * 替换图片对象
49
+ */
50
+ replaceImage(replaceObj: fabric.Image, file: ImageFile, config?: Record<string, any>): Promise<void>;
51
+ /**
52
+ * 修改图片对象配置
53
+ */
54
+ updateImageConfig(config: Record<string, any>): void;
55
+ /**
56
+ * 修改 svg 对象填充色
57
+ */
58
+ updateSvgColor(color: string): void;
59
+ /**
60
+ * 图片在可编辑区域内的适配
61
+ */
62
+ fitToEditableArea(type: string): void;
63
+ /**
64
+ * 图片镜像
65
+ */
66
+ flip(type: string): void;
67
+ /**
68
+ * 图片复制
69
+ */
70
+ copy(): void;
71
+ /**
72
+ * 监听裁剪框的 scaling、moving、deselected 事件
73
+ */
74
+ _startCropListener(activeObjBounds: RenderableBox): void;
75
+ /**
76
+ * 清除裁剪框
77
+ */
78
+ clearCropRect(activeObject: fabric.Object): void;
79
+ /**
80
+ * 显示裁剪框
81
+ */
82
+ showCropRect(): Promise<void>;
83
+ /** 对图片进行裁剪 */
84
+ onCrop(activeObject: fabric.Image): Promise<void>;
85
+ _calcOuterClipPath(imgBounds: RenderableBox): string;
86
+ _updateOverlayClipPath(imgBounds: RenderableBox): void;
87
+ }
88
+ export default ImageProcessor;