@overtone-art/canvas-editor-core 0.2.6 → 0.2.7

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.
@@ -0,0 +1,383 @@
1
+ import { FabricObject } from 'fabric';
2
+
3
+ type Unit = 'px' | 'mm' | 'in';
4
+ type LayerType = 'image' | 'text' | 'shape' | 'template' | 'group';
5
+ interface LayerData {
6
+ id: string;
7
+ type: LayerType;
8
+ name: string;
9
+ visible: boolean;
10
+ locked: boolean;
11
+ opacity: number;
12
+ /** Non-fabric metadata persisted with the layer (pattern config, etc). */
13
+ meta?: LayerMeta;
14
+ }
15
+ interface LayerMeta {
16
+ pattern?: PatternState;
17
+ [key: string]: unknown;
18
+ }
19
+ interface SerializedLayer extends LayerData {
20
+ fabricObject: Record<string, unknown>;
21
+ }
22
+ interface EditorState {
23
+ version: string;
24
+ canvas: {
25
+ width: number;
26
+ height: number;
27
+ unit?: Unit;
28
+ dpi?: number;
29
+ };
30
+ layers: SerializedLayer[];
31
+ background?: string;
32
+ backgroundImage?: Record<string, unknown> | null;
33
+ mockup?: MockupConfig | null;
34
+ }
35
+ interface EditorConfig {
36
+ width: number;
37
+ height: number;
38
+ backgroundColor?: string;
39
+ fileAdapter?: FileAdapter;
40
+ imageProvider?: ImageProvider;
41
+ preserveObjectStacking?: boolean;
42
+ unit?: Unit;
43
+ dpi?: number;
44
+ /** Resolve a non-CORS image through a trusted proxy or same-origin store for pattern rendering. */
45
+ patternSourceResolver?: PatternSourceResolver;
46
+ fonts?: FontDefinition[];
47
+ license?: LicenseConfig;
48
+ }
49
+ type ExportFormat = 'png' | 'jpeg' | 'webp' | 'svg' | 'json';
50
+ interface ResizeOptions {
51
+ /** Scale layer positions and dimensions with the canvas. Defaults to true. */
52
+ scaleContent?: boolean;
53
+ }
54
+ interface BackgroundImageOptions {
55
+ fit?: 'cover' | 'contain' | 'stretch';
56
+ opacity?: number;
57
+ }
58
+ interface DpiIssue {
59
+ layerId: string;
60
+ layerName: string;
61
+ effectiveDpi: number;
62
+ minimumDpi: number;
63
+ }
64
+ interface ImageAdjustments {
65
+ /** Range -1 to 1. */
66
+ brightness?: number;
67
+ /** Range -1 to 1. */
68
+ contrast?: number;
69
+ /** Range -1 to 1. */
70
+ saturation?: number;
71
+ /** Range 0 to 1. */
72
+ blur?: number;
73
+ }
74
+ type PatternSourceResolver = (source: string) => Promise<string>;
75
+ interface FontDefinition {
76
+ family: string;
77
+ /** URL, data URL, or a complete CSS FontFace source such as `local(...)`. */
78
+ source: string;
79
+ weight?: string;
80
+ style?: string;
81
+ display?: FontDisplay;
82
+ }
83
+ interface SvgExportOptions {
84
+ /** Embed registered URL/data fonts into the SVG. Defaults to true. */
85
+ embedFonts?: boolean;
86
+ }
87
+ interface LicensePayload {
88
+ id: string;
89
+ domains: string[];
90
+ expiresAt?: string;
91
+ features?: string[];
92
+ }
93
+ type LicenseStatus = {
94
+ state: 'community' | 'exempt' | 'checking';
95
+ payload: null;
96
+ } | {
97
+ state: 'valid';
98
+ payload: LicensePayload;
99
+ } | {
100
+ state: 'invalid' | 'expired' | 'domain-mismatch';
101
+ payload: LicensePayload | null;
102
+ };
103
+ interface LicenseConfig {
104
+ key?: string;
105
+ /** Offline signature decoder/verifier supplied by the commercial distribution. */
106
+ verifyOffline?: (key: string) => Promise<LicensePayload | null> | LicensePayload | null;
107
+ hostname?: string;
108
+ environment?: 'development' | 'test' | 'production';
109
+ onUsage?: (event: {
110
+ name: string;
111
+ at: string;
112
+ licenseId?: string;
113
+ }) => void;
114
+ }
115
+ interface CanvasSizePreset {
116
+ id: string;
117
+ name: string;
118
+ width: number;
119
+ height: number;
120
+ unit: Unit;
121
+ dpi: number;
122
+ }
123
+ interface FileAdapter {
124
+ save(data: Blob | string, filename: string, format: ExportFormat): Promise<string>;
125
+ }
126
+ interface ImageProviderResult {
127
+ id?: string;
128
+ url: string;
129
+ width: number;
130
+ height: number;
131
+ previewUrl?: string;
132
+ thumbnailUrl?: string;
133
+ alt?: string;
134
+ sourceUrl?: string;
135
+ attribution?: ImageAttribution;
136
+ /** Provider event endpoint retained for use tracking; never render this as an image. */
137
+ trackingUrl?: string;
138
+ }
139
+ interface ImageAttribution {
140
+ name: string;
141
+ url: string;
142
+ provider?: string;
143
+ }
144
+ interface ImageSearchOptions {
145
+ page?: number;
146
+ perPage?: number;
147
+ orientation?: 'landscape' | 'portrait' | 'squarish';
148
+ orderBy?: 'relevant' | 'latest';
149
+ contentFilter?: 'low' | 'high';
150
+ }
151
+ interface ImageSearchResult {
152
+ items: ImageProviderResult[];
153
+ page: number;
154
+ total: number;
155
+ totalPages: number;
156
+ }
157
+ interface ImageProvider {
158
+ upload?(file: File): Promise<ImageProviderResult>;
159
+ browse?(): Promise<ImageProviderResult | null>;
160
+ search?(query: string, options?: ImageSearchOptions): Promise<ImageSearchResult>;
161
+ /** Called immediately before a provider asset is inserted into the design. */
162
+ trackUse?(image: ImageProviderResult): Promise<void>;
163
+ }
164
+ interface ShapePlugin {
165
+ name: string;
166
+ icon: string;
167
+ category?: string;
168
+ create(options?: Record<string, unknown>): FabricObject;
169
+ }
170
+ interface TemplateParameter {
171
+ key: string;
172
+ label: string;
173
+ type: 'text' | 'color' | 'number' | 'font';
174
+ default?: string | number;
175
+ }
176
+ interface TemplateDefinition {
177
+ id: string;
178
+ name: string;
179
+ category: string;
180
+ svg: string;
181
+ parameters: TemplateParameter[];
182
+ preview?: string;
183
+ }
184
+ interface PrintifyPositioning {
185
+ x: number;
186
+ y: number;
187
+ scale: number;
188
+ angle: number;
189
+ }
190
+ interface NormalizedLayerPosition {
191
+ layerId: string;
192
+ name: string;
193
+ type: LayerType;
194
+ centerX: number;
195
+ centerY: number;
196
+ width: number;
197
+ height: number;
198
+ scaleX: number;
199
+ scaleY: number;
200
+ angle: number;
201
+ }
202
+ interface PositioningAdapter<T> {
203
+ readonly provider: string;
204
+ map(positions: NormalizedLayerPosition[], canvas: {
205
+ width: number;
206
+ height: number;
207
+ }): T;
208
+ }
209
+ interface ProjectPage {
210
+ id: string;
211
+ name: string;
212
+ state: EditorState;
213
+ }
214
+ interface ProjectState {
215
+ version: '1.0.0';
216
+ activePageId: string;
217
+ pages: ProjectPage[];
218
+ }
219
+ type TileMode = 'grid' | 'brick-horizontal' | 'brick-vertical';
220
+ interface PatternConfig {
221
+ mode: TileMode;
222
+ /**
223
+ * Tile size as a % of the source image's on-canvas size (100 = natural).
224
+ * Smaller values pack more repeats across the print area; larger values make
225
+ * fewer, bigger tiles. Independent of how the source layer was placed.
226
+ */
227
+ scale: number;
228
+ /** Extra horizontal gap between tiles, as % of tile width. */
229
+ horizontalSpacing: number;
230
+ /** Extra vertical gap between tiles, as % of tile height. */
231
+ verticalSpacing: number;
232
+ /** Rotation of the whole pattern, in degrees. */
233
+ angle: number;
234
+ /** Brick row/column shift, as % of tile size. */
235
+ horizontalOffset: number;
236
+ /**
237
+ * Phase shift of the whole tile grid inside the print area, as % of tile
238
+ * width. The pattern object itself is pinned to the print area (it can't be
239
+ * dragged — that would expose bare edges), so this is how the tiling is
240
+ * nudged into alignment. Clamped to ±100% so coverage is never broken.
241
+ */
242
+ offsetX: number;
243
+ /** Phase shift of the tile grid, as % of tile height. See {@link offsetX}. */
244
+ offsetY: number;
245
+ /** Added rotation per horizontal step, in degrees. */
246
+ rotationStepH: number;
247
+ /** Added rotation per vertical step, in degrees. */
248
+ rotationStepV: number;
249
+ }
250
+ /** Fabric interaction flags frozen while a layer is rendered as a pattern. */
251
+ interface PatternLocks {
252
+ lockMovementX: boolean;
253
+ lockMovementY: boolean;
254
+ lockScalingX: boolean;
255
+ lockScalingY: boolean;
256
+ lockRotation: boolean;
257
+ hasControls: boolean;
258
+ }
259
+ /** Persisted on a layer's meta while it is rendered as a repeating pattern. */
260
+ interface PatternState {
261
+ config: PatternConfig;
262
+ /** Original (pre-pattern) image source, as a durable data URL when possible. */
263
+ originalSrc: string;
264
+ /**
265
+ * Serialized `clipPath` the image carried before it became a pattern, or null
266
+ * if it had none. A pattern must fill the whole print area, so any pre-pattern
267
+ * clip (e.g. a template crop sized to the original box) is stripped while the
268
+ * pattern is on and re-applied when it is turned off. Persisted so it survives
269
+ * serialization / reload / undo.
270
+ */
271
+ originalClip?: Record<string, unknown> | null;
272
+ /**
273
+ * Interaction flags the object carried before it became a pattern. A pattern
274
+ * fills the whole print area, so while it is on the object is locked in place
275
+ * (a drag/resize would slide the tiled bitmap off the area and leave a bare
276
+ * band); the captured flags are restored when the pattern is turned off.
277
+ */
278
+ originalLocks?: PatternLocks;
279
+ /** Original fabric transform, restored when the pattern is turned off. */
280
+ original: {
281
+ left: number;
282
+ top: number;
283
+ scaleX: number;
284
+ scaleY: number;
285
+ width: number;
286
+ height: number;
287
+ angle: number;
288
+ cropX: number;
289
+ cropY: number;
290
+ };
291
+ }
292
+ declare const DEFAULT_PATTERN_CONFIG: PatternConfig;
293
+ interface MockupPrintArea {
294
+ left: number;
295
+ top: number;
296
+ width: number;
297
+ height: number;
298
+ }
299
+ type MockupBlendMode = 'normal' | 'multiply' | 'screen' | 'overlay' | 'soft-light' | 'hard-light';
300
+ interface MockupOverlay {
301
+ /** Lighting, texture, or shadow image drawn above the design. */
302
+ image: string;
303
+ blendMode?: MockupBlendMode;
304
+ opacity?: number;
305
+ }
306
+ interface MockupConfig {
307
+ /** Garment/product image rendered behind the design. */
308
+ image: string;
309
+ /** Print-area rectangle, in canvas pixels. Drawn as a guide. */
310
+ printArea?: MockupPrintArea;
311
+ /** Clip the design to printArea. Defaults to true when printArea exists. */
312
+ clipToPrintArea?: boolean;
313
+ designBlendMode?: MockupBlendMode;
314
+ designOpacity?: number;
315
+ /** Optional product lighting/shadow pass rendered after the design. */
316
+ overlay?: MockupOverlay;
317
+ }
318
+ interface EditorEvents {
319
+ 'layer:added': {
320
+ layer: LayerData;
321
+ };
322
+ 'layer:removed': {
323
+ layerId: string;
324
+ };
325
+ 'layer:selected': {
326
+ layerId: string | null;
327
+ };
328
+ 'layer:modified': {
329
+ layerId: string;
330
+ };
331
+ 'layer:reordered': {
332
+ layerIds: string[];
333
+ };
334
+ 'layers:changed': {
335
+ layers: LayerData[];
336
+ };
337
+ 'selection:changed': {
338
+ selected: string[];
339
+ };
340
+ 'history:changed': {
341
+ canUndo: boolean;
342
+ canRedo: boolean;
343
+ };
344
+ 'history:snapshot': {
345
+ bytes: number;
346
+ totalBytes: number;
347
+ entries: number;
348
+ };
349
+ 'zoom:changed': {
350
+ zoom: number;
351
+ };
352
+ 'snap:changed': {
353
+ enabled: boolean;
354
+ };
355
+ 'crop:changed': {
356
+ active: boolean;
357
+ layerId: string | null;
358
+ };
359
+ 'mockup:changed': {
360
+ mockup: MockupConfig | null;
361
+ };
362
+ 'canvas:modified': Record<string, never>;
363
+ 'project:changed': {
364
+ activePageId: string;
365
+ pages: Array<{
366
+ id: string;
367
+ name: string;
368
+ }>;
369
+ };
370
+ 'export:start': {
371
+ format: string;
372
+ };
373
+ 'export:complete': {
374
+ format: string;
375
+ url?: string;
376
+ };
377
+ error: {
378
+ message: string;
379
+ error?: unknown;
380
+ };
381
+ }
382
+
383
+ export { type SvgExportOptions as A, type BackgroundImageOptions as B, type CanvasSizePreset as C, DEFAULT_PATTERN_CONFIG as D, type EditorConfig as E, type FileAdapter as F, type TemplateParameter as G, type TileMode as H, type ImageAdjustments as I, type LayerData as L, type MockupBlendMode as M, type NormalizedLayerPosition as N, type PatternConfig as P, type ResizeOptions as R, type SerializedLayer as S, type TemplateDefinition as T, type Unit as U, type DpiIssue as a, type EditorEvents as b, type EditorState as c, type ExportFormat as d, type FontDefinition as e, type ImageAttribution as f, type ImageProvider as g, type ImageProviderResult as h, type ImageSearchOptions as i, type ImageSearchResult as j, type LayerMeta as k, type LayerType as l, type LicenseConfig as m, type LicensePayload as n, type LicenseStatus as o, type MockupConfig as p, type MockupOverlay as q, type MockupPrintArea as r, type PatternLocks as s, type PatternSourceResolver as t, type PatternState as u, type PositioningAdapter as v, type PrintifyPositioning as w, type ProjectPage as x, type ProjectState as y, type ShapePlugin as z };