@merchi/product-editor 0.1.9

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 (123) hide show
  1. package/.turbo/turbo-build.log +1 -0
  2. package/README.md +174 -0
  3. package/dist/components/AlignMenu.d.ts +3 -0
  4. package/dist/components/AlignMenu.js +61 -0
  5. package/dist/components/FloatingToolbar.d.ts +4 -0
  6. package/dist/components/FloatingToolbar.js +97 -0
  7. package/dist/components/FormatButtons.d.ts +2 -0
  8. package/dist/components/FormatButtons.js +22 -0
  9. package/dist/components/ImageNavButton.d.ts +7 -0
  10. package/dist/components/ImageNavButton.js +14 -0
  11. package/dist/components/ImageZoomModal.d.ts +12 -0
  12. package/dist/components/ImageZoomModal.js +129 -0
  13. package/dist/components/LayerPanel.d.ts +4 -0
  14. package/dist/components/LayerPanel.js +223 -0
  15. package/dist/components/LoadingOverlay.d.ts +9 -0
  16. package/dist/components/LoadingOverlay.js +17 -0
  17. package/dist/components/ProductEditor.d.ts +4 -0
  18. package/dist/components/ProductEditor.js +67 -0
  19. package/dist/components/ProductImageGallery.d.ts +6 -0
  20. package/dist/components/ProductImageGallery.js +148 -0
  21. package/dist/components/ProductPreviews.d.ts +7 -0
  22. package/dist/components/ProductPreviews.js +281 -0
  23. package/dist/components/TextToolbar.d.ts +4 -0
  24. package/dist/components/TextToolbar.js +117 -0
  25. package/dist/components/Toolbar.d.ts +3 -0
  26. package/dist/components/Toolbar.js +47 -0
  27. package/dist/config/colorConfig.d.ts +1 -0
  28. package/dist/config/colorConfig.js +10 -0
  29. package/dist/config/fontConfig.d.ts +5 -0
  30. package/dist/config/fontConfig.js +21 -0
  31. package/dist/context/ProductEditorContext.d.ts +60 -0
  32. package/dist/context/ProductEditorContext.js +743 -0
  33. package/dist/hooks/useSwipeNavigate.d.ts +11 -0
  34. package/dist/hooks/useSwipeNavigate.js +35 -0
  35. package/dist/index.d.ts +6 -0
  36. package/dist/index.js +30 -0
  37. package/dist/styles/BottomPreviewDisplay.css +65 -0
  38. package/dist/styles/FloatingToolbar.css +41 -0
  39. package/dist/styles/ImageGallery.css +147 -0
  40. package/dist/styles/ImageNavButton.css +35 -0
  41. package/dist/styles/ImageZoomModal.css +101 -0
  42. package/dist/styles/LayerPanel.css +179 -0
  43. package/dist/styles/LoadingOverlay.css +48 -0
  44. package/dist/styles/ProductEditor.css +192 -0
  45. package/dist/styles/TextToolbar.css +327 -0
  46. package/dist/styles/Toolbar.css +125 -0
  47. package/dist/styles/index.css +5 -0
  48. package/dist/styles/textToolbarSelectStyles.d.ts +3 -0
  49. package/dist/styles/textToolbarSelectStyles.js +30 -0
  50. package/dist/types.d.ts +228 -0
  51. package/dist/types.js +17 -0
  52. package/dist/utils/canvasAddText.d.ts +11 -0
  53. package/dist/utils/canvasAddText.js +66 -0
  54. package/dist/utils/canvasUtils.d.ts +37 -0
  55. package/dist/utils/canvasUtils.js +342 -0
  56. package/dist/utils/deviceUtils.d.ts +5 -0
  57. package/dist/utils/deviceUtils.js +33 -0
  58. package/dist/utils/draftTemplateUtils.d.ts +23 -0
  59. package/dist/utils/draftTemplateUtils.js +66 -0
  60. package/dist/utils/grid.d.ts +32 -0
  61. package/dist/utils/grid.js +151 -0
  62. package/dist/utils/imageUtils.d.ts +12 -0
  63. package/dist/utils/imageUtils.js +178 -0
  64. package/dist/utils/job.d.ts +40 -0
  65. package/dist/utils/job.js +115 -0
  66. package/dist/utils/keyboard.d.ts +1 -0
  67. package/dist/utils/keyboard.js +26 -0
  68. package/dist/utils/previewUtils.d.ts +9 -0
  69. package/dist/utils/previewUtils.js +39 -0
  70. package/dist/utils/psdConverter.d.ts +40 -0
  71. package/dist/utils/psdConverter.js +516 -0
  72. package/dist/utils/psdRenderUtils.d.ts +12 -0
  73. package/dist/utils/psdRenderUtils.js +465 -0
  74. package/dist/utils/renderUtils.d.ts +2 -0
  75. package/dist/utils/renderUtils.js +85 -0
  76. package/package.json +66 -0
  77. package/src/components/AlignMenu.tsx +49 -0
  78. package/src/components/FloatingToolbar.tsx +83 -0
  79. package/src/components/FormatButtons.tsx +31 -0
  80. package/src/components/ImageNavButton.tsx +23 -0
  81. package/src/components/ImageZoomModal.tsx +163 -0
  82. package/src/components/LayerPanel.tsx +256 -0
  83. package/src/components/LoadingOverlay.tsx +27 -0
  84. package/src/components/ProductEditor.tsx +104 -0
  85. package/src/components/ProductImageGallery.tsx +181 -0
  86. package/src/components/ProductPreviews.tsx +243 -0
  87. package/src/components/TextToolbar.tsx +164 -0
  88. package/src/components/Toolbar.tsx +86 -0
  89. package/src/config/colorConfig.ts +7 -0
  90. package/src/config/fontConfig.ts +23 -0
  91. package/src/context/ProductEditorContext.tsx +829 -0
  92. package/src/hooks/useSwipeNavigate.ts +40 -0
  93. package/src/index.ts +6 -0
  94. package/src/styles/BottomPreviewDisplay.css +65 -0
  95. package/src/styles/FloatingToolbar.css +41 -0
  96. package/src/styles/ImageGallery.css +147 -0
  97. package/src/styles/ImageNavButton.css +35 -0
  98. package/src/styles/ImageZoomModal.css +101 -0
  99. package/src/styles/LayerPanel.css +179 -0
  100. package/src/styles/LoadingOverlay.css +48 -0
  101. package/src/styles/ProductEditor.css +192 -0
  102. package/src/styles/TextToolbar.css +327 -0
  103. package/src/styles/Toolbar.css +125 -0
  104. package/src/styles/index.css +5 -0
  105. package/src/styles/textToolbarSelectStyles.ts +60 -0
  106. package/src/types/ag-psd/index.d.ts +1 -0
  107. package/src/types/fabric.d.ts +14 -0
  108. package/src/types/lodash/index.d.ts +1 -0
  109. package/src/types/psd.d.ts +53 -0
  110. package/src/types.ts +247 -0
  111. package/src/utils/canvasAddText.ts +72 -0
  112. package/src/utils/canvasUtils.ts +406 -0
  113. package/src/utils/deviceUtils.ts +31 -0
  114. package/src/utils/draftTemplateUtils.ts +70 -0
  115. package/src/utils/grid.ts +154 -0
  116. package/src/utils/imageUtils.ts +218 -0
  117. package/src/utils/job.ts +128 -0
  118. package/src/utils/keyboard.ts +28 -0
  119. package/src/utils/previewUtils.ts +43 -0
  120. package/src/utils/psdConverter.ts +595 -0
  121. package/src/utils/psdRenderUtils.ts +453 -0
  122. package/src/utils/renderUtils.ts +44 -0
  123. package/tsconfig.json +17 -0
@@ -0,0 +1,178 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.loadRegularImagePromise = void 0;
4
+ var fabric_1 = require("fabric");
5
+ /**
6
+ * Loads a template image onto a canvas with enhanced error handling and fallbacks
7
+ *
8
+ * @param fabricCanvas The Fabric.js canvas instance
9
+ * @param template The template containing image information
10
+ * @param width The canvas width
11
+ * @param height The canvas height
12
+ * @returns Promise that resolves when the image is loaded
13
+ */
14
+ var loadRegularImagePromise = function (fabricCanvas, template, width, height) {
15
+ // Get the canvas ID for tracking if it exists
16
+ var canvasId = fabricCanvas.loadingId;
17
+ var trackingEnabled = !!canvasId;
18
+ return new Promise(function (resolve) {
19
+ var _a, _b;
20
+ // Check if canvas is still valid when tracking is enabled
21
+ if (trackingEnabled && fabricCanvas.loadingId !== canvasId) {
22
+ resolve();
23
+ return;
24
+ }
25
+ // Make sure template has a file with a viewUrl
26
+ if (!template.file || !template.file.viewUrl) {
27
+ console.error('Template has no viewUrl:', template);
28
+ resolve();
29
+ return;
30
+ }
31
+ var imageUrl = template.file.viewUrl;
32
+ // Check if this might be a problematic file format
33
+ var isPossiblyUnsupported = !imageUrl.match(/\.(jpg|jpeg|png|gif|svg|webp)$/i);
34
+ // If we have a thumbnailUrl or previewUrl, use that instead for unsupported formats
35
+ var urlToUse = imageUrl;
36
+ if (isPossiblyUnsupported) {
37
+ // Try to use alternative URLs if available
38
+ if ((_a = template.file) === null || _a === void 0 ? void 0 : _a.thumbnailUrl) {
39
+ urlToUse = template.file.thumbnailUrl;
40
+ }
41
+ else if ((_b = template.file) === null || _b === void 0 ? void 0 : _b.previewUrl) {
42
+ urlToUse = template.file.previewUrl;
43
+ }
44
+ }
45
+ // Add error handling for image loading
46
+ fabric_1.fabric.Image.fromURL(urlToUse, function (img) {
47
+ // Check if canvas is still valid when tracking is enabled
48
+ if (trackingEnabled && fabricCanvas.loadingId !== canvasId) {
49
+ console.warn('Canvas changed after image loaded, aborting');
50
+ resolve();
51
+ return;
52
+ }
53
+ if (!img || !img.width || !img.height) {
54
+ console.error('Failed to load image or image has invalid dimensions:', img);
55
+ // Try loading the image with a different approach - create an HTML image first
56
+ var imgElement_1 = new Image();
57
+ imgElement_1.crossOrigin = 'anonymous';
58
+ imgElement_1.onload = function () {
59
+ // Check if canvas is still valid when tracking is enabled
60
+ if (trackingEnabled && fabricCanvas.loadingId !== canvasId) {
61
+ console.warn('Canvas changed after alternative image loaded, aborting');
62
+ resolve();
63
+ return;
64
+ }
65
+ var fabricImg = new fabric_1.fabric.Image(imgElement_1);
66
+ // Continue with the same scaling and positioning logic
67
+ var scale = Math.min(width / fabricImg.width, height / fabricImg.height);
68
+ fabricImg.scale(scale);
69
+ fabricImg.set({
70
+ left: (width - fabricImg.width * scale) / 2,
71
+ top: (height - fabricImg.height * scale) / 2,
72
+ selectable: false,
73
+ evented: false,
74
+ });
75
+ // Check again before adding to canvas when tracking is enabled
76
+ if (trackingEnabled && fabricCanvas.loadingId !== canvasId) {
77
+ console.warn('Canvas changed before adding alternative image, aborting');
78
+ resolve();
79
+ return;
80
+ }
81
+ fabricCanvas.add(fabricImg);
82
+ fabricCanvas.sendToBack(fabricImg);
83
+ // Final check before render when tracking is enabled
84
+ if (trackingEnabled && fabricCanvas.loadingId !== canvasId) {
85
+ console.warn('Canvas changed before rendering alternative image, aborting');
86
+ resolve();
87
+ return;
88
+ }
89
+ try {
90
+ fabricCanvas.renderAll();
91
+ }
92
+ catch (e) {
93
+ console.error('Error rendering canvas with alternative image:', e);
94
+ }
95
+ resolve();
96
+ };
97
+ imgElement_1.onerror = function () {
98
+ // Check if canvas is still valid when tracking is enabled
99
+ if (trackingEnabled && fabricCanvas.loadingId !== canvasId) {
100
+ console.warn('Canvas changed after image load error, aborting');
101
+ resolve();
102
+ return;
103
+ }
104
+ console.error('Alternative loading also failed. Using placeholder image.');
105
+ // Use a placeholder SVG as absolute fallback
106
+ var placeholderURL = 'data:image/svg+xml;charset=UTF-8,%3Csvg%20width%3D%22800%22%20height%3D%22600%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%20800%20600%22%20preserveAspectRatio%3D%22none%22%3E%3Cdefs%3E%3Cstyle%20type%3D%22text%2Fcss%22%3E%23holder_1891%20text%20%7Bfill%3A%23AAAAAA%3Bfont-weight%3Abold%3Bfont-family%3AArial%2C%20Helvetica%2C%20Open%20Sans%2C%20sans-serif%2C%20monospace%3Bfont-size%3A40pt%20%7D%3C%2Fstyle%3E%3C%2Fdefs%3E%3Cg%20id%3D%22holder%22%3E%3Crect%20width%3D%22800%22%20height%3D%22600%22%20fill%3D%22%23EEEEEE%22%3E%3C%2Frect%3E%3Cg%3E%3Ctext%20x%3D%22285%22%20y%3D%22300%22%3EThumbnail%20Unavailable%3C%2Ftext%3E%3Ctext%20x%3D%22205%22%20y%3D%22350%22%3ETemplate%3A%20' + template.name + '%3C%2Ftext%3E%3C%2Fg%3E%3C%2Fg%3E%3C%2Fsvg%3E';
107
+ fabric_1.fabric.Image.fromURL(placeholderURL, function (placeholderImg) {
108
+ // Check if canvas is still valid when tracking is enabled
109
+ if (trackingEnabled && fabricCanvas.loadingId !== canvasId) {
110
+ console.warn('Canvas changed before adding placeholder image, aborting');
111
+ resolve();
112
+ return;
113
+ }
114
+ placeholderImg.set({
115
+ left: 0,
116
+ top: 0,
117
+ width: width,
118
+ height: height,
119
+ selectable: false,
120
+ evented: false,
121
+ });
122
+ fabricCanvas.add(placeholderImg);
123
+ // Final check before render when tracking is enabled
124
+ if (trackingEnabled && fabricCanvas.loadingId !== canvasId) {
125
+ console.warn('Canvas changed before rendering placeholder image, aborting');
126
+ resolve();
127
+ return;
128
+ }
129
+ try {
130
+ fabricCanvas.renderAll();
131
+ }
132
+ catch (e) {
133
+ console.error('Error rendering canvas with placeholder image:', e);
134
+ }
135
+ resolve();
136
+ });
137
+ };
138
+ imgElement_1.src = urlToUse;
139
+ return;
140
+ }
141
+ // Scale image to fit canvas while maintaining aspect ratio
142
+ var scale = Math.min(width / img.width, height / img.height);
143
+ img.scale(scale);
144
+ // Center the image
145
+ img.set({
146
+ left: (width - img.width * scale) / 2,
147
+ top: (height - img.height * scale) / 2,
148
+ selectable: false,
149
+ evented: false,
150
+ crossOrigin: 'anonymous',
151
+ });
152
+ // Check if canvas is still valid when tracking is enabled
153
+ if (trackingEnabled && fabricCanvas.loadingId !== canvasId) {
154
+ console.warn('Canvas changed before adding image, aborting');
155
+ resolve();
156
+ return;
157
+ }
158
+ // Add the image to the canvas
159
+ fabricCanvas.add(img);
160
+ // Send the template image to the back
161
+ fabricCanvas.sendToBack(img);
162
+ // Final check before render when tracking is enabled
163
+ if (trackingEnabled && fabricCanvas.loadingId !== canvasId) {
164
+ console.warn('Canvas changed before rendering, aborting');
165
+ resolve();
166
+ return;
167
+ }
168
+ try {
169
+ fabricCanvas.renderAll();
170
+ }
171
+ catch (e) {
172
+ console.error('Error rendering canvas:', e);
173
+ }
174
+ resolve();
175
+ }, { crossOrigin: 'anonymous' });
176
+ });
177
+ };
178
+ exports.loadRegularImagePromise = loadRegularImagePromise;
@@ -0,0 +1,40 @@
1
+ import { MerchiFile, Product, Variation, DraftTemplate, DraftTemplateData } from '../types';
2
+ export declare const generateUniqueId: () => string;
3
+ export declare function findTemplatesSelectedByVarations(draftTemplates: DraftTemplate[], variations: Variation[]): DraftTemplate[];
4
+ export declare function filterVariationsByTemplate(variations: Variation[], template: DraftTemplate): Variation[];
5
+ export declare function buildVariationFieldCanvasObject(variation: Variation): {
6
+ canvasObjectType: string;
7
+ fieldId: number | undefined;
8
+ fileId: number | undefined;
9
+ value: string | null | undefined;
10
+ file: MerchiFile;
11
+ uniqueId: string;
12
+ }[] | {
13
+ fieldId: number | undefined;
14
+ value: null;
15
+ uniqueId: string;
16
+ } | {
17
+ canvasObjectType: string;
18
+ value: string;
19
+ fieldId: number | undefined;
20
+ text: string;
21
+ fontSize: number;
22
+ fontFamily: string;
23
+ uniqueId: string;
24
+ }[] | {
25
+ canvasObjectType: string;
26
+ fieldId: number | undefined;
27
+ value: string | null | undefined;
28
+ colour: string | null | undefined;
29
+ uniqueId: string;
30
+ }[] | {
31
+ fieldId: number | undefined;
32
+ value: string | null | undefined;
33
+ uniqueId: string;
34
+ }[];
35
+ export declare function canvasTemplateVariationObjects(variations: Variation[], template: DraftTemplate): {
36
+ fieldId: number | undefined;
37
+ value: string | null | undefined;
38
+ uniqueId: string;
39
+ }[];
40
+ export declare function initDraftTemplates(variations: Variation[], product: Product): DraftTemplateData[];
@@ -0,0 +1,115 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.initDraftTemplates = exports.canvasTemplateVariationObjects = exports.buildVariationFieldCanvasObject = exports.filterVariationsByTemplate = exports.findTemplatesSelectedByVarations = exports.generateUniqueId = void 0;
4
+ var types_1 = require("../types");
5
+ // Add a UUID generator for unique IDs
6
+ var generateUniqueId = function () {
7
+ return 'canvas-obj-' + Math.random().toString(36).substring(2, 11) + Date.now().toString(36);
8
+ };
9
+ exports.generateUniqueId = generateUniqueId;
10
+ function findTemplatesSelectedByVarations(draftTemplates, variations) {
11
+ // filter all the selected variation values
12
+ var selectedVarationValues = variations
13
+ .filter(function (v) { return v.value !== undefined && v.value !== null && v.value !== ''; })
14
+ .map(function (v) { return String(v.value); });
15
+ // return all the draft templates that have a selectedByVariationFieldOptions that includes
16
+ // any of the selected variation values
17
+ return draftTemplates.filter(function (template) {
18
+ var _a;
19
+ if (!(template === null || template === void 0 ? void 0 : template.selectedByVariationFieldOptions)) {
20
+ return false;
21
+ }
22
+ return !!((_a = template.selectedByVariationFieldOptions) === null || _a === void 0 ? void 0 : _a.find(function (o) { return selectedVarationValues.includes(String(o.id)); }));
23
+ });
24
+ }
25
+ exports.findTemplatesSelectedByVarations = findTemplatesSelectedByVarations;
26
+ function filterVariationsByTemplate(variations, template) {
27
+ var _a;
28
+ // filter the variations by the template and only return the variations which edit the template
29
+ // we will use these variations to add canvas objects to the canvas
30
+ var editFieldIds = (_a = template.editedByVariationFields) === null || _a === void 0 ? void 0 : _a.map(function (field) { return field.id; });
31
+ return variations.filter(function (v) { var _a; return editFieldIds === null || editFieldIds === void 0 ? void 0 : editFieldIds.includes((_a = v.variationField) === null || _a === void 0 ? void 0 : _a.id); });
32
+ }
33
+ exports.filterVariationsByTemplate = filterVariationsByTemplate;
34
+ function buildVariationFieldCanvasObject(variation) {
35
+ // takes a variation and returns an associated canvas object to redner
36
+ var value = variation.value, variationField = variation.variationField, _a = variation.variationFiles, variationFiles = _a === void 0 ? [] : _a;
37
+ var _b = variationField || {}, _c = _b.fieldType, fieldType = _c === void 0 ? types_1.FieldType.TEXT_INPUT : _c, id = _b.id;
38
+ if ([types_1.FieldType.TEXT_INPUT, types_1.FieldType.TEXT_AREA, types_1.FieldType.NUMBER_INPUT].includes(fieldType)) {
39
+ // if value is null or empty, do not create a text object
40
+ if (value === null || value === undefined || value === '') {
41
+ return {
42
+ fieldId: id,
43
+ value: null,
44
+ uniqueId: (0, exports.generateUniqueId)()
45
+ };
46
+ }
47
+ // Used to add a text to the canvas
48
+ return [{
49
+ canvasObjectType: 'text',
50
+ value: value,
51
+ fieldId: id,
52
+ text: value,
53
+ fontSize: 24,
54
+ fontFamily: 'Nunito',
55
+ uniqueId: (0, exports.generateUniqueId)(),
56
+ }];
57
+ }
58
+ if (fieldType === types_1.FieldType.FILE_UPLOAD) {
59
+ // Used to add an image to the canvas
60
+ return variationFiles.map(function (file) { return ({
61
+ canvasObjectType: 'image',
62
+ fieldId: id,
63
+ fileId: file.id,
64
+ value: value,
65
+ file: file,
66
+ uniqueId: (0, exports.generateUniqueId)(),
67
+ }); });
68
+ }
69
+ if ([types_1.FieldType.COLOUR_PICKER, types_1.FieldType.COLOUR_SELECT].includes(fieldType)) {
70
+ // Used to add a colour to the canvas
71
+ return [{
72
+ canvasObjectType: 'colour',
73
+ fieldId: id,
74
+ value: value,
75
+ colour: value,
76
+ uniqueId: (0, exports.generateUniqueId)(),
77
+ }];
78
+ }
79
+ return [{
80
+ fieldId: id,
81
+ value: value,
82
+ uniqueId: (0, exports.generateUniqueId)(),
83
+ }];
84
+ }
85
+ exports.buildVariationFieldCanvasObject = buildVariationFieldCanvasObject;
86
+ function canvasTemplateVariationObjects(variations, template) {
87
+ // takes a list of variations and a template and returns a list of canvas objects to render
88
+ var templateVariations = filterVariationsByTemplate(variations, template);
89
+ return templateVariations
90
+ .flatMap(function (v) { return buildVariationFieldCanvasObject(v); })
91
+ .filter(function (obj) { return obj.canvasObjectType; });
92
+ }
93
+ exports.canvasTemplateVariationObjects = canvasTemplateVariationObjects;
94
+ function initDraftTemplates(variations, product) {
95
+ var _a = product.draftTemplates, draftTemplates = _a === void 0 ? [] : _a;
96
+ // Check for any templates that are selected by the variation options
97
+ var templates = findTemplatesSelectedByVarations(draftTemplates, variations) || [];
98
+ // If there are no templates selected, return the draft templates
99
+ var useTemplates = templates.length ? templates : draftTemplates;
100
+ return useTemplates.map(function (template) {
101
+ // find the variations which edit the template
102
+ var templateVariations = filterVariationsByTemplate(variations, template);
103
+ // build the canvas objects for the template
104
+ var variationObjects = canvasTemplateVariationObjects(templateVariations, template);
105
+ return {
106
+ template: template,
107
+ variationFieldIds: templateVariations
108
+ .map(function (v) { var _a; return (_a = v.variationField) === null || _a === void 0 ? void 0 : _a.id; })
109
+ .filter(Boolean)
110
+ .map(function (id) { return Number(id); }),
111
+ variationObjects: variationObjects,
112
+ };
113
+ });
114
+ }
115
+ exports.initDraftTemplates = initDraftTemplates;
@@ -0,0 +1 @@
1
+ export declare const setupKeyboardEvents: (canvas: fabric.Canvas, onObjectRemoved?: ((dataUrl: string) => void) | undefined) => () => void;
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.setupKeyboardEvents = void 0;
4
+ var setupKeyboardEvents = function (canvas, onObjectRemoved) {
5
+ var handleKeyDown = function (e) {
6
+ if (e.key === 'Delete') {
7
+ var activeObject = canvas.getActiveObject();
8
+ if (activeObject) {
9
+ canvas.remove(activeObject);
10
+ canvas.renderAll();
11
+ if (onObjectRemoved) {
12
+ var dataUrl = canvas.toDataURL({
13
+ format: 'png',
14
+ quality: 1,
15
+ });
16
+ onObjectRemoved(dataUrl);
17
+ }
18
+ }
19
+ }
20
+ };
21
+ document.addEventListener('keydown', handleKeyDown);
22
+ return function () {
23
+ document.removeEventListener('keydown', handleKeyDown);
24
+ };
25
+ };
26
+ exports.setupKeyboardEvents = setupKeyboardEvents;
@@ -0,0 +1,9 @@
1
+ import { DraftTemplateData, DraftPreview } from '../types';
2
+ /**
3
+ * Gets all unique draft previews from the draft templates
4
+ * Loops through each template's draftPreviewLayers to collect associated previews
5
+ *
6
+ * @param draftTemplates Array of draft templates with their variation data
7
+ * @returns Array of unique draft previews
8
+ */
9
+ export declare function setNewDraftPreviews(draftTemplates: DraftTemplateData[]): DraftPreview[];
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.setNewDraftPreviews = void 0;
4
+ /**
5
+ * Gets all unique draft previews from the draft templates
6
+ * Loops through each template's draftPreviewLayers to collect associated previews
7
+ *
8
+ * @param draftTemplates Array of draft templates with their variation data
9
+ * @returns Array of unique draft previews
10
+ */
11
+ function setNewDraftPreviews(draftTemplates) {
12
+ // Create a map to track which previews we've already included by ID
13
+ var includedPreviewIds = new Set();
14
+ var draftPreviews = [];
15
+ // Loop through each draft template
16
+ draftTemplates.forEach(function (draftTemplateData) {
17
+ var template = draftTemplateData.template;
18
+ // Skip if the template doesn't have preview layers
19
+ if (!template.draftPreviewLayers || template.draftPreviewLayers.length === 0) {
20
+ return;
21
+ }
22
+ // Look through each preview layer to find associated previews
23
+ template.draftPreviewLayers.forEach(function (layer) {
24
+ // If the layer has a preview and we haven't already included it
25
+ if (layer.draftPreview && layer.draftPreview.id) {
26
+ var previewId = layer.draftPreview.id;
27
+ if (!includedPreviewIds.has(previewId)) {
28
+ // Add to our tracking set
29
+ includedPreviewIds.add(previewId);
30
+ // Add the preview to our result array
31
+ draftPreviews.push(layer.draftPreview);
32
+ }
33
+ }
34
+ });
35
+ });
36
+ // Return the unique list of previews
37
+ return draftPreviews;
38
+ }
39
+ exports.setNewDraftPreviews = setNewDraftPreviews;
@@ -0,0 +1,40 @@
1
+ import { fabric } from 'fabric';
2
+ import { SavedCanvasObject } from '../types';
3
+ interface ExtendedCanvas extends fabric.Canvas {
4
+ designBounds?: {
5
+ left: number;
6
+ top: number;
7
+ right: number;
8
+ bottom: number;
9
+ width: number;
10
+ height: number;
11
+ };
12
+ psdUrl?: string;
13
+ anythingABC?: string;
14
+ }
15
+ /**
16
+ * Extracts layers from a PSD file and renders them to a PNG
17
+ *
18
+ * @param psdUrl URL to the PSD file
19
+ * @returns Promise that resolves to a PNG data URL
20
+ */
21
+ export declare const extractPsdBaseLayer: (psdUrl: string) => Promise<{
22
+ dataUrl: string;
23
+ designBounds?: {
24
+ left: number;
25
+ top: number;
26
+ right: number;
27
+ bottom: number;
28
+ };
29
+ }>;
30
+ /**
31
+ * Loads a PSD file onto a fabric.js canvas
32
+ *
33
+ * @param canvas fabric.js Canvas instance
34
+ * @param psdUrl URL to the PSD file
35
+ * @param width Canvas width
36
+ * @param height Canvas height
37
+ * @returns Promise that resolves when the image is added to the canvas
38
+ */
39
+ export declare const loadPsdOntoCanvas: (canvas: ExtendedCanvas, psdUrl: string, variations: any[], savedObjects: SavedCanvasObject[], width: number, height: number) => Promise<void>;
40
+ export {};