@rocketium/auto-adapt 2.0.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.
@@ -0,0 +1,696 @@
1
+ import { fabric } from 'fabric';
2
+ import { IObjectOptions, IPatternOptions, IGradientOptions } from 'fabric/fabric-impl';
3
+
4
+ type Prettify<T> = {
5
+ [P in keyof T]: T[P];
6
+ };
7
+ type Radius = {
8
+ tl?: number;
9
+ tr?: number;
10
+ bl?: number;
11
+ br?: number;
12
+ };
13
+ type AutoFitSizes = [number, number];
14
+ type Scale = {
15
+ scale: number;
16
+ scaleX?: never;
17
+ scaleY?: never;
18
+ } | {
19
+ scale?: never;
20
+ scaleX: number;
21
+ scaleY: number;
22
+ };
23
+ type ObjectFit = 'fill' | 'fit' | 'crop';
24
+ type TextCase = 'uppercase' | 'lowercase' | 'titlecase' | 'none';
25
+ type FontStyle = 'normal' | 'italic' | 'oblique';
26
+ type ORIGIN_X = 'left' | 'center' | 'right';
27
+ type ORIGIN_Y = 'top' | 'middle' | 'bottom';
28
+ type FontMetaData = {
29
+ fontId: string;
30
+ fontUrl: string;
31
+ };
32
+ type ObjectPosition = 'top-left' | 'top-center' | 'top-right' | 'center-left' | 'center' | 'center-right' | 'bottom-left' | 'bottom-center' | 'bottom-right' | 'custom';
33
+ type Padding = {
34
+ all?: number;
35
+ top?: number;
36
+ right?: number;
37
+ bottom?: number;
38
+ left?: number;
39
+ };
40
+ type BorderPosition = 'center' | 'inside' | 'outside';
41
+ type Border = {
42
+ color?: string;
43
+ style?: 'dashed' | 'solid';
44
+ top?: number;
45
+ right?: number;
46
+ bottom?: number;
47
+ left?: number;
48
+ position?: BorderPosition;
49
+ dashWidth?: number;
50
+ dashGap?: number;
51
+ dashCap?: string;
52
+ stroke?: string;
53
+ strokeWidth?: number;
54
+ strokeDashArray?: number[];
55
+ };
56
+ type FillOptions = IGradientOptions | IPatternOptions | string;
57
+ type SerializedFillType = string | IPatternOptions | IGradientOptions;
58
+ type SerializedFabricShadow = Pick<fabric.Shadow, 'color' | 'blur' | 'offsetX' | 'offsetY'>;
59
+ type SerializedImageFilter = {
60
+ brightness?: number;
61
+ saturation?: number;
62
+ contrast?: number;
63
+ invert?: boolean;
64
+ blur?: number;
65
+ };
66
+ type ColorMap = {
67
+ [key: string]: FillOptions;
68
+ };
69
+ declare const CANVAS_EDITOR_ELEMENT: {
70
+ readonly TEXT: "TEXT";
71
+ readonly SHAPE: "SHAPE";
72
+ readonly IMAGE: "IMAGE";
73
+ readonly GROUP: "GROUP";
74
+ readonly CREATIVE_BOX: "CREATIVE_BOX";
75
+ readonly VIDEO: "VIDEO";
76
+ readonly AUDIO: "AUDIO";
77
+ readonly CANVAS_MASK: "CANVAS_MASK";
78
+ };
79
+ type CANVAS_EDITOR_ELEMENT_TYPE = (typeof CANVAS_EDITOR_ELEMENT)[keyof typeof CANVAS_EDITOR_ELEMENT];
80
+ declare enum CreativeElementCategory {
81
+ HERO_IMAGE = "HERO_IMAGE",
82
+ PRODUCT_IMAGE = "PRODUCT_IMAGE",
83
+ BACKGROUND = "BACKGROUND",
84
+ LOGO = "LOGO",
85
+ ICON = "ICON",
86
+ HEADLINE = "HEADLINE",
87
+ SUBHEADLINE = "SUBHEADLINE",
88
+ BODY_COPY = "BODY_COPY",
89
+ PRICE = "PRICE",
90
+ CTA = "CTA",
91
+ TERMS_CONDITIONS = "TERMS_CONDITIONS",
92
+ REVIEWS_TESTIMONIALS = "REVIEWS_TESTIMONIALS",
93
+ WARRANTY_INFO = "WARRANTY_INFO",
94
+ BADGE = "BADGE",
95
+ NEW_PRODUCT_LABEL = "NEW_PRODUCT_LABEL",
96
+ OTHER = "OTHER"
97
+ }
98
+ type LayerRules = {
99
+ editingLocked?: boolean;
100
+ maxCharCount?: number;
101
+ };
102
+ type GroupPath = string | null;
103
+ declare enum WORD_STYLE_TYPE {
104
+ WORD_STYLE = "WORD_STYLE",
105
+ MISSING_GLYPH = "MISSING_GLYPH",
106
+ VARIABLES = "VARIABLES"
107
+ }
108
+ type WordStyleStyles = {
109
+ fontFamily?: string;
110
+ fontSize?: number;
111
+ fontSizeUnit?: 'px' | '%';
112
+ fontWeight?: string | number;
113
+ fontStyle?: FontStyle;
114
+ textDecoration?: string;
115
+ textAlign?: string;
116
+ textBackgroundColor?: string;
117
+ fill?: string;
118
+ stroke?: string;
119
+ strokeWidth?: number;
120
+ deltaY?: number;
121
+ linethrough?: boolean;
122
+ underline?: boolean;
123
+ subscript?: boolean;
124
+ superscript?: boolean;
125
+ linethroughOffset?: number;
126
+ underlineOffset?: number;
127
+ offsets?: {
128
+ linethrough?: number;
129
+ underline?: number;
130
+ overline?: number;
131
+ };
132
+ };
133
+ type WordStyle = {
134
+ id: string;
135
+ type?: WORD_STYLE_TYPE;
136
+ variableId?: string;
137
+ fontMetaDataWS?: {
138
+ fontId?: string;
139
+ fontUrl?: string;
140
+ name?: string;
141
+ } | null;
142
+ data: {
143
+ start: number;
144
+ end: number;
145
+ styles: WordStyleStyles;
146
+ };
147
+ };
148
+ type WordStyles = Array<WordStyle>;
149
+ type Point = {
150
+ x: number;
151
+ y: number;
152
+ };
153
+ type TranslateKeyframes = {
154
+ id: string;
155
+ offset: number;
156
+ x: number;
157
+ y: number;
158
+ P1?: Point;
159
+ P2?: Point;
160
+ };
161
+ type ScaleKeyframes = {
162
+ id: string;
163
+ offset: number;
164
+ scaleX: number;
165
+ scaleY: number;
166
+ };
167
+ type RotateKeyframes = {
168
+ id: string;
169
+ offset: number;
170
+ angle: number;
171
+ };
172
+ type OpacityKeyframes = {
173
+ id: string;
174
+ offset: number;
175
+ opacity: number;
176
+ };
177
+ type AnimationTrack = {
178
+ translate?: TranslateKeyframes[];
179
+ scale?: ScaleKeyframes[];
180
+ rotate?: RotateKeyframes[];
181
+ opacity?: OpacityKeyframes[];
182
+ };
183
+ type AnimationReference = Partial<{
184
+ coordinates: Point;
185
+ origin: Point;
186
+ scale: Point;
187
+ rotate: number;
188
+ opacity: number;
189
+ track: AnimationTrack;
190
+ originalReference: AnimationReference;
191
+ }>;
192
+ declare enum TextAnimationType {
193
+ CHARACTER = "character",
194
+ WORD = "word",
195
+ LINE = "line"
196
+ }
197
+ declare enum AnimationSpecialCase {
198
+ TYPING_EFFECT = "typing-effect",
199
+ NONE = "none"
200
+ }
201
+ type TextAnimationKeyframe = {
202
+ offset: number;
203
+ y?: number;
204
+ opacity?: number;
205
+ };
206
+ type TextAnimation = {
207
+ _id: string;
208
+ type: TextAnimationType;
209
+ clipped?: boolean;
210
+ reverse?: boolean;
211
+ specialCase?: AnimationSpecialCase | null;
212
+ name: string;
213
+ keyframes: TextAnimationKeyframe[];
214
+ start: number;
215
+ end: number;
216
+ loop?: number;
217
+ };
218
+ type SerializedRoundedRect = SerializedFabricBaseObject & {
219
+ properties?: {
220
+ layerStartTime?: number;
221
+ layerEndTime?: number;
222
+ visible?: boolean;
223
+ fill?: string;
224
+ outputFormat?: string;
225
+ layerRules?: LayerRules;
226
+ clipPathId?: string;
227
+ clipPathParentId?: string;
228
+ };
229
+ animatable?: boolean;
230
+ };
231
+ type SerializedFabricBaseObject = Pick<IObjectOptions, 'originX' | 'originY' | 'left' | 'top' | 'width' | 'height' | 'stroke' | 'strokeWidth' | 'strokeDashArray' | 'strokeLineCap' | 'strokeDashOffset' | 'strokeLineJoin' | 'strokeUniform' | 'strokeMiterLimit' | 'scaleX' | 'scaleY' | 'angle' | 'flipX' | 'flipY' | 'opacity' | 'visible' | 'backgroundColor' | 'fillRule' | 'paintFirst' | 'globalCompositeOperation' | 'skewX' | 'skewY' | 'data' | 'selectable' | 'hoverCursor' | 'moveCursor' | 'hasControls' | 'hasBorders' | 'lockRotation' | 'lockMovementY' | 'lockScalingX' | 'lockScalingY' | 'lockSkewingX' | 'lockSkewingY' | 'lockScalingFlip' | 'inverted' | 'absolutePositioned' | 'centeredScaling'> & {
232
+ version: '5.3.0';
233
+ type: 'rect' | 'circle' | 'triangle' | 'line' | 'polygon' | 'polyline' | 'path' | 'group' | 'image' | 'text' | 'rounded-rect' | 'text-container' | 'image-container' | 'custom-textbox' | 'shape-container' | 'video-container' | 'audio-container' | 'svg-container' | 'group-container';
234
+ fill?: SerializedFillType;
235
+ shadow?: SerializedFabricShadow;
236
+ globalCompositeOperation: GlobalCompositeOperation;
237
+ rx?: number;
238
+ ry?: number;
239
+ evented?: boolean;
240
+ clipPath?: SerializedRoundedRect;
241
+ };
242
+ type BaseElementJSON = {
243
+ id: string;
244
+ type: SerializedFabricBaseObject['type'];
245
+ displayText: string;
246
+ dataType: CANVAS_EDITOR_ELEMENT_TYPE;
247
+ left: number;
248
+ top: number;
249
+ width: number;
250
+ height: number;
251
+ angle: number;
252
+ opacity: number;
253
+ shadow: SerializedFabricShadow | null;
254
+ visible: boolean;
255
+ globalCompositeOperation: GlobalCompositeOperation;
256
+ selectable: boolean;
257
+ fill: SerializedFillType;
258
+ border: Border;
259
+ padding: Padding;
260
+ cornerRadius: Radius;
261
+ layerRules?: LayerRules;
262
+ groupPath: GroupPath;
263
+ animationTrack?: AnimationTrack;
264
+ animationReference?: AnimationReference;
265
+ scaleX?: number;
266
+ scaleY?: number;
267
+ category?: CreativeElementCategory;
268
+ };
269
+ type CreativeBoxJSON = Omit<BaseElementJSON, 'left' | 'top' | 'angle' | 'opacity' | 'shadow' | 'visible' | 'globalCompositeOperation' | 'selectable' | 'border' | 'padding' | 'cornerRadius' | 'layerRules'> & {
270
+ type: 'rect';
271
+ dataType: 'CREATIVE_BOX';
272
+ zIndex: number;
273
+ layerRules?: LayerRules;
274
+ };
275
+ type ImageContainerJSON = Omit<BaseElementJSON, 'type'> & {
276
+ type: 'image-container';
277
+ dataType: 'IMAGE';
278
+ objectPosition: ObjectPosition;
279
+ imageOriginX: ORIGIN_X;
280
+ imageOriginY: ORIGIN_Y;
281
+ imageScale: number;
282
+ imageRotation: number;
283
+ imageLeft: number;
284
+ imageTop: number;
285
+ imageWidth: number;
286
+ imageHeight: number;
287
+ objectFit: ObjectFit;
288
+ src: string;
289
+ layerStartTime?: number;
290
+ layerEndTime?: number;
291
+ propertiesVisible?: boolean;
292
+ exportSrc?: string;
293
+ originalSrc?: string;
294
+ displayText: string;
295
+ layerRules?: LayerRules;
296
+ flipX?: boolean;
297
+ flipY?: boolean;
298
+ filter?: Partial<SerializedImageFilter>;
299
+ animationTrack?: AnimationTrack;
300
+ animationReference?: AnimationReference;
301
+ };
302
+ type PathJSON = Omit<BaseElementJSON, 'border' | 'padding' | 'cornerRadius'> & {
303
+ type: 'shape-container';
304
+ dataType: 'SHAPE';
305
+ path: (string | number)[][];
306
+ layerStartTime?: number;
307
+ layerEndTime?: number;
308
+ propertiesVisible?: boolean;
309
+ propertiesFill?: string;
310
+ layerRules?: LayerRules;
311
+ } & Scale;
312
+ type RoundedRectJSON = Omit<BaseElementJSON, 'border' | 'padding'> & {
313
+ type: 'rounded-rect';
314
+ dataType: 'SHAPE';
315
+ scale: number;
316
+ layerStartTime?: number;
317
+ layerEndTime?: number;
318
+ propertiesVisible?: boolean;
319
+ propertiesFill?: string;
320
+ displayText: string;
321
+ layerRules?: LayerRules;
322
+ };
323
+ type TextContainerJSON = Omit<BaseElementJSON, 'type'> & {
324
+ type: 'text-container';
325
+ dataType: 'TEXT';
326
+ autoFit: boolean;
327
+ autoFitSizes: [number | null, number | null];
328
+ textCase: TextCase;
329
+ serializedText: string;
330
+ fontMetaData: FontMetaData;
331
+ objectPosition: ObjectPosition;
332
+ textleft: number;
333
+ textTop: number;
334
+ textHeight: number;
335
+ textFill: SerializedFillType;
336
+ fontFamily: string;
337
+ fontWeight: number | string;
338
+ fontSize: number;
339
+ text: string;
340
+ underline: boolean;
341
+ overline: boolean;
342
+ linethrough: boolean;
343
+ textAlign: string;
344
+ fontStyle: '' | 'normal' | 'italic' | 'oblique';
345
+ lineHeight: number;
346
+ charSpacing: number;
347
+ styles: unknown[];
348
+ wordStyle: WordStyles;
349
+ missingGlyphChars: [];
350
+ layerStartTime?: number;
351
+ layerEndTime?: number;
352
+ propertiesVisible?: boolean;
353
+ wordSpacing?: number;
354
+ offsets: {
355
+ linethrough?: number;
356
+ };
357
+ linethroughOffset: -0.315;
358
+ underlineOffset: 0.1;
359
+ displayText: string;
360
+ textAnimationTrack?: TextAnimation;
361
+ };
362
+ type VideoContainerJSON = Omit<BaseElementJSON, 'type'> & {
363
+ type: 'video-container';
364
+ dataType: 'VIDEO';
365
+ objectPosition: ObjectPosition;
366
+ imageScale: number;
367
+ imageLeft: number;
368
+ imageTop: number;
369
+ imageWidth: number;
370
+ imageHeight: number;
371
+ objectFit: ObjectFit;
372
+ src: string;
373
+ layerStartTime?: number;
374
+ layerEndTime?: number;
375
+ propertiesVisible?: boolean;
376
+ volume?: number;
377
+ trimmerStartTime?: number;
378
+ displayText: string;
379
+ layerRules?: LayerRules;
380
+ imageOriginX: ORIGIN_X;
381
+ imageOriginY: ORIGIN_Y;
382
+ flipX: boolean;
383
+ flipY: boolean;
384
+ filter: Partial<SerializedImageFilter>;
385
+ imageRotation: number;
386
+ originalSrc?: string;
387
+ exportSrc?: string;
388
+ animationTrack?: AnimationTrack;
389
+ animationReference?: AnimationReference;
390
+ };
391
+ type AudioContainerJSON = {
392
+ type: 'audio-container';
393
+ dataType: 'AUDIO';
394
+ src: string;
395
+ layerStartTime?: number;
396
+ layerEndTime?: number;
397
+ volume?: number;
398
+ id: string;
399
+ displayText: string;
400
+ selectable?: boolean;
401
+ trimmerStartTime?: number;
402
+ layerRules?: LayerRules;
403
+ };
404
+ type SvgJSON = Omit<BaseElementJSON, 'border' | 'padding' | 'cornerRadius' | 'fill'> & {
405
+ type: 'svg-container';
406
+ dataType: 'SHAPE';
407
+ src: string;
408
+ layerStartTime?: number;
409
+ layerEndTime?: number;
410
+ propertiesVisible?: boolean;
411
+ objectFit?: ObjectFit;
412
+ imageRotation?: number;
413
+ objectPosition?: ObjectPosition;
414
+ imageLeft?: number;
415
+ imageTop?: number;
416
+ imageWidth?: number;
417
+ imageHeight?: number;
418
+ flipX?: boolean;
419
+ flipY?: boolean;
420
+ imageScale: number;
421
+ animationTrack?: AnimationTrack;
422
+ animationReference?: AnimationReference;
423
+ colorMap?: ColorMap;
424
+ imageOriginX?: ORIGIN_X;
425
+ imageOriginY?: ORIGIN_Y;
426
+ } & Scale;
427
+ type GroupContainerJSON = Omit<BaseElementJSON, 'type' | 'fill' | 'border' | 'padding' | 'cornerRadius' | 'layerRules'> & {
428
+ type: 'group-container';
429
+ dataType: 'GROUP';
430
+ objects: string[];
431
+ isAlreadyGrouped: boolean;
432
+ isMaskedGroup: boolean;
433
+ propertiesVisible?: boolean;
434
+ layerRules?: LayerRules;
435
+ };
436
+ type CanvasElementJSON = CreativeBoxJSON | ImageContainerJSON | PathJSON | RoundedRectJSON | TextContainerJSON | VideoContainerJSON | AudioContainerJSON | SvgJSON | GroupContainerJSON;
437
+ type CanvasElementWithOverrides<T extends CanvasElementJSON> = Prettify<T & {
438
+ zIndex: number;
439
+ overrides: Record<string, Partial<T> & {
440
+ zIndex: number;
441
+ }>;
442
+ }>;
443
+
444
+ type DatabaseVariant = {
445
+ id: string;
446
+ sizes: Record<string, DatabaseSize>;
447
+ objects: Record<string, CanvasElementWithOverrides<CanvasElementJSON>>;
448
+ };
449
+ type DatabaseSize = {
450
+ width: number;
451
+ height: number;
452
+ id: string;
453
+ rulers: Record<string, RulerLine>;
454
+ showRulers?: boolean;
455
+ showGrid: boolean;
456
+ grid?: GridOption;
457
+ rulersLocked?: boolean;
458
+ displayName: string;
459
+ videoLength?: number;
460
+ };
461
+ declare const RULER_AXIS: {
462
+ readonly X: "x";
463
+ readonly Y: "y";
464
+ };
465
+ type RULER_AXIS_TYPE = (typeof RULER_AXIS)[keyof typeof RULER_AXIS];
466
+ type RulerLine = {
467
+ axis: RULER_AXIS_TYPE;
468
+ value: number;
469
+ id: string;
470
+ };
471
+ type GridOption = {
472
+ size: number;
473
+ unit: 'PIXEL';
474
+ color: string;
475
+ subdivisions: number;
476
+ };
477
+ type SavedCustomDimensions = {
478
+ active: boolean;
479
+ name: string;
480
+ creativeUrl: string;
481
+ thumbnail?: string;
482
+ width?: number;
483
+ height?: number;
484
+ fileName?: string;
485
+ fileNameSource?: 'formula' | 'manual';
486
+ };
487
+ type OutputFormat = 'image' | 'video';
488
+ interface ServerCapsule {
489
+ videoLength: number;
490
+ name: string;
491
+ image: string;
492
+ author: string;
493
+ timestamp: string;
494
+ version: number;
495
+ isDeleted: boolean;
496
+ collaborators: string[];
497
+ tags: string[];
498
+ orientation: string;
499
+ videoBackground: string;
500
+ branding: boolean;
501
+ outputFormat: OutputFormat;
502
+ brandPalettes: [];
503
+ capsuleErrors: [];
504
+ withCanvas: boolean;
505
+ creativesOrder: string[];
506
+ _id: string;
507
+ capsuleId: string;
508
+ audio: {
509
+ link: string;
510
+ };
511
+ authorId: string;
512
+ canvasData: {
513
+ metadata: {};
514
+ variant: DatabaseVariant;
515
+ };
516
+ cards: {
517
+ id: string;
518
+ tags: string[];
519
+ type: string;
520
+ groups: [];
521
+ image: string;
522
+ options: [];
523
+ autoTimeBasedOnElements: boolean;
524
+ }[];
525
+ createdAt: string;
526
+ createdUsingStylingPanel: null;
527
+ customDimensions: {
528
+ _id: string;
529
+ width: number;
530
+ height: number;
531
+ };
532
+ exportSettings: {
533
+ quality: string;
534
+ };
535
+ lastModified: string;
536
+ lastModifiedId: string;
537
+ listId: string;
538
+ logoImage: string;
539
+ logoLoop: boolean;
540
+ logoPosition: string;
541
+ logoSize: number;
542
+ metadata: {
543
+ platform: string;
544
+ shareString: string;
545
+ isSaved: boolean;
546
+ name: string;
547
+ assetGroup: string;
548
+ email: string;
549
+ };
550
+ savedCustomDimensions: Record<string, SavedCustomDimensions>;
551
+ shortId: string;
552
+ teamId: string;
553
+ themeId: string;
554
+ title: string;
555
+ updatedAt: string;
556
+ videoBackgroundExtraClasses: string;
557
+ videoIndex: number;
558
+ videoStyling: null;
559
+ videoTemplateRules: null;
560
+ visibility: string;
561
+ newAddedSizes?: Record<string, SavedCustomDimensions>;
562
+ sourceCapsuleId?: string | null;
563
+ }
564
+
565
+ declare const getAdaptedObjectsJSON: ({ adaptSize, objects, closestSize, }: {
566
+ adaptSize: string;
567
+ objects: Record<string, CanvasElementJSON>;
568
+ closestSize: string;
569
+ }) => Record<string, CanvasElementJSON>;
570
+ /**
571
+ * Resolve CanvasElementWithOverrides to flat CanvasElementJSON for a given sizeId.
572
+ * Applies overrides[sizeId] onto the base object.
573
+ */
574
+ declare const resolveObjectsForSize: (objects: Record<string, CanvasElementWithOverrides<CanvasElementJSON>>, sizeId: string) => Record<string, CanvasElementJSON>;
575
+ /**
576
+ * Convert adapted flat objects back to overrides on the original objects.
577
+ * For each layer, the adapted result is stored as overrides[newSizeId].
578
+ */
579
+ declare const applyAdaptedAsOverrides: (originalObjects: Record<string, CanvasElementWithOverrides<CanvasElementJSON>>, adaptedObjects: Record<string, CanvasElementJSON>, newSizeId: string) => Record<string, CanvasElementWithOverrides<CanvasElementJSON>>;
580
+ /**
581
+ * Builds a new ServerCapsule with an added size. Handles canvasData.variant.sizes,
582
+ * savedCustomDimensions, newAddedSizes, and creativesOrder.
583
+ */
584
+ declare const buildNewCapsule: ({ originalCapsule, updatedObjects, sizeId, referenceCreativeId, sizeToGenerate, sizeName, sizeCategory, videoLength, }: {
585
+ originalCapsule: ServerCapsule;
586
+ updatedObjects: Record<string, CanvasElementWithOverrides<CanvasElementJSON>>;
587
+ sizeId: string;
588
+ referenceCreativeId: string;
589
+ sizeToGenerate: string;
590
+ sizeName?: string;
591
+ sizeCategory?: string;
592
+ videoLength?: number;
593
+ }) => ServerCapsule;
594
+ /**
595
+ * Generate a base layout for a new size.
596
+ *
597
+ * Takes the original capsule and target size params, returns a new ServerCapsule
598
+ * with the adapted layout. Follows the frontend's getAdaptedObjectsJSON logic exactly.
599
+ */
600
+ declare const generateBaseLayoutForSize: ({ originalCapsule, capsuleId, creativeId, sizeId, sizeToGenerate, sizeName, sizeCategory, }: {
601
+ originalCapsule: ServerCapsule;
602
+ capsuleId: string;
603
+ creativeId: string | null;
604
+ sizeId: string;
605
+ sizeToGenerate: string;
606
+ sizeName?: string;
607
+ sizeCategory?: string;
608
+ }) => ServerCapsule;
609
+
610
+ declare const getNormalizedSizeValue: (sizeValue: string) => string;
611
+ declare const getEuclideanDistanceBetweenSizes: ({ size1, size2 }: {
612
+ size1: string;
613
+ size2: string;
614
+ }) => number;
615
+ /**
616
+ * Finds the closest match among string-based sizes (e.g. ['720x720', '1080x1920']).
617
+ * Returns the single best match and all sorted match percentages.
618
+ */
619
+ declare const findClosestSizeWithMatches: ({ availableSizes, adaptSize, }: {
620
+ availableSizes: string[];
621
+ adaptSize: string;
622
+ }) => {
623
+ closestSize: string;
624
+ sortedMatches: Record<string, number>;
625
+ };
626
+ /**
627
+ * Finds closest matches among size objects (Record<sizeId, DatabaseSize>).
628
+ * Returns enriched size objects with _id and matchPercentage, sorted descending.
629
+ */
630
+ declare const findClosestSizeObjectsWithMatches: ({ availableSizes, adaptSize, }: {
631
+ availableSizes: Record<string, DatabaseSize>;
632
+ adaptSize: string;
633
+ }) => (DatabaseSize & {
634
+ _id: string;
635
+ matchPercentage: number;
636
+ })[];
637
+ /**
638
+ * Find the best reference size from available size objects.
639
+ * Uses weighted scoring: 90% aspect-ratio similarity, 10% euclidean distance.
640
+ * Returns the sizeId (key) of the best match.
641
+ */
642
+ declare const findBestReferenceSize: (availableSizes: Record<string, DatabaseSize>, targetSize: string) => string;
643
+
644
+ declare const getAreaPercentageOfElementOnCanvasJSON: ({ element, canvasDimensions, }: {
645
+ element: CanvasElementJSON;
646
+ canvasDimensions: {
647
+ height: number;
648
+ width: number;
649
+ };
650
+ }) => number;
651
+ declare const checkIfElementShouldBeSkewed: ({ areaPercentage, referenceLengths, type, }: {
652
+ areaPercentage: number;
653
+ referenceLengths: {
654
+ left: number;
655
+ top: number;
656
+ width: number;
657
+ height: number;
658
+ canvasWidth: number;
659
+ canvasHeight: number;
660
+ };
661
+ type: string;
662
+ }) => boolean;
663
+ declare const scaleCornerRadius: (cornerRadius: Radius | undefined, scalingRatio: number) => Radius;
664
+ declare const scalePadding: (padding: Padding | undefined, scalingRatio: number) => Padding;
665
+ declare const getScaledBorderJSON: ({ object, scalingRatio, }: {
666
+ object: CanvasElementJSON;
667
+ scalingRatio: number;
668
+ }) => {
669
+ border?: Border;
670
+ };
671
+ declare const adaptWordStyleFontSizes: ({ wordStyle, scalingRatio, }: {
672
+ wordStyle: WordStyle[];
673
+ scalingRatio: number;
674
+ }) => WordStyle[];
675
+ declare const scaleAutoFitSizes: (autoFitSizes: [number | null, number | null] | undefined, scalingRatio: number, fallbackHeight: number) => AutoFitSizes;
676
+ declare const getValuesWithoutSkewingJSON: ({ closestSize, adaptSize, object, }: {
677
+ closestSize: string;
678
+ adaptSize: string;
679
+ object: CanvasElementJSON;
680
+ }) => {
681
+ left: number;
682
+ top: number;
683
+ width: number;
684
+ height: number;
685
+ };
686
+
687
+ declare const isTextJSON: (object: CanvasElementJSON) => object is TextContainerJSON;
688
+ declare const isImageJSON: (object: CanvasElementJSON) => object is ImageContainerJSON;
689
+ declare const isShapeJSON: (object: CanvasElementJSON) => object is PathJSON | RoundedRectJSON | SvgJSON;
690
+ declare const isSVGContainerJSON: (object: CanvasElementJSON) => object is SvgJSON;
691
+ declare const isRoundedRectJSON: (object: CanvasElementJSON) => object is RoundedRectJSON;
692
+ declare const isGroupJSON: (object: CanvasElementJSON | undefined) => object is GroupContainerJSON;
693
+ declare const isCreativeBoxJSON: (object: CanvasElementJSON) => boolean;
694
+ declare const isAudioJSON: (object: CanvasElementJSON) => boolean;
695
+
696
+ export { type AnimationReference, AnimationSpecialCase, type AnimationTrack, type AudioContainerJSON, type AutoFitSizes, type BaseElementJSON, type Border, type BorderPosition, CANVAS_EDITOR_ELEMENT, type CANVAS_EDITOR_ELEMENT_TYPE, type CanvasElementJSON, type CanvasElementWithOverrides, type ColorMap, type CreativeBoxJSON, CreativeElementCategory, type DatabaseSize, type DatabaseVariant, type FillOptions, type FontMetaData, type FontStyle, type GridOption, type GroupContainerJSON, type GroupPath, type ImageContainerJSON, type LayerRules, type ORIGIN_X, type ORIGIN_Y, type ObjectFit, type ObjectPosition, type OpacityKeyframes, type OutputFormat, type Padding, type PathJSON, type Point, type Prettify, RULER_AXIS, type RULER_AXIS_TYPE, type Radius, type RotateKeyframes, type RoundedRectJSON, type RulerLine, type SavedCustomDimensions, type Scale, type ScaleKeyframes, type SerializedFabricBaseObject, type SerializedFabricShadow, type SerializedFillType, type SerializedImageFilter, type SerializedRoundedRect, type ServerCapsule, type SvgJSON, type TextAnimation, type TextAnimationKeyframe, TextAnimationType, type TextCase, type TextContainerJSON, type TranslateKeyframes, type VideoContainerJSON, WORD_STYLE_TYPE, type WordStyle, type WordStyleStyles, type WordStyles, adaptWordStyleFontSizes, applyAdaptedAsOverrides, buildNewCapsule, checkIfElementShouldBeSkewed, findBestReferenceSize, findClosestSizeObjectsWithMatches, findClosestSizeWithMatches, generateBaseLayoutForSize, getAdaptedObjectsJSON, getAreaPercentageOfElementOnCanvasJSON, getEuclideanDistanceBetweenSizes, getNormalizedSizeValue, getScaledBorderJSON, getValuesWithoutSkewingJSON, isAudioJSON, isCreativeBoxJSON, isGroupJSON, isImageJSON, isRoundedRectJSON, isSVGContainerJSON, isShapeJSON, isTextJSON, resolveObjectsForSize, scaleAutoFitSizes, scaleCornerRadius, scalePadding };