svelte-product-mockup 1.0.11 → 1.0.12

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.
@@ -1,11 +1,11 @@
1
1
  <script lang="ts">
2
2
  import { onMount, onDestroy, tick, untrack } from 'svelte';
3
- import type { Mockup } from '../types';
3
+ import type { Mockup, MockupConfig } from '../types';
4
4
  import { renderMockupCanvasEditor, type RenderController } from '../renderMockupCanvasEditor';
5
5
  import { denormalizeMockup } from '../mockup-normalize';
6
6
 
7
7
  interface Props {
8
- mockup: Mockup;
8
+ mockup: Mockup | MockupConfig;
9
9
  imageOverrides?: Record<string, string>;
10
10
  objectFit?: 'contain' | 'cover';
11
11
  debounceMs?: number;
@@ -1,6 +1,6 @@
1
- import type { Mockup } from '../types';
1
+ import type { Mockup, MockupConfig } from '../types';
2
2
  interface Props {
3
- mockup: Mockup;
3
+ mockup: Mockup | MockupConfig;
4
4
  imageOverrides?: Record<string, string>;
5
5
  objectFit?: 'contain' | 'cover';
6
6
  debounceMs?: number;
@@ -1,11 +1,11 @@
1
1
  <script lang="ts">
2
2
  import { onMount } from 'svelte';
3
- import type { Mockup } from '../types';
3
+ import type { Mockup, MockupConfig } from '../types';
4
4
  import { renderMockupCanvas } from '../renderMockupCanvas';
5
5
  import { denormalizeMockup } from '../mockup-normalize';
6
6
 
7
7
  interface Props {
8
- mockup: Mockup;
8
+ mockup: Mockup | MockupConfig;
9
9
  imageOverrides?: Record<string, string>;
10
10
  objectFit?: 'contain' | 'cover';
11
11
  }
@@ -1,6 +1,6 @@
1
- import type { Mockup } from '../types';
1
+ import type { Mockup, MockupConfig } from '../types';
2
2
  interface Props {
3
- mockup: Mockup;
3
+ mockup: Mockup | MockupConfig;
4
4
  imageOverrides?: Record<string, string>;
5
5
  objectFit?: 'contain' | 'cover';
6
6
  }
@@ -1,3 +1,3 @@
1
- import type { Mockup } from './types';
2
- export declare function normalizeMockup(mockup: Mockup, clean?: boolean): Partial<Mockup>;
3
- export declare function denormalizeMockup(mockup: Partial<Mockup>): Mockup;
1
+ import type { Mockup, MockupConfig, DenormalizedMockup } from './types';
2
+ export declare function normalizeMockup(mockup: Mockup, clean?: boolean): Partial<MockupConfig>;
3
+ export declare function denormalizeMockup(mockup: Partial<MockupConfig>): DenormalizedMockup;
@@ -157,12 +157,13 @@ function normalizeView(view) {
157
157
  return omitDefaults(view, defaultView);
158
158
  }
159
159
  export function normalizeMockup(mockup, clean = false) {
160
+ const canvasSize = mockup.canvasSize || DEFAULT_CANVAS_SIZE;
160
161
  const normalized = {
161
162
  id: mockup.id,
162
163
  name: mockup.name,
163
164
  canvasSize: {
164
- width: mockup.canvasSize.width,
165
- height: mockup.canvasSize.height
165
+ width: canvasSize.width,
166
+ height: canvasSize.height
166
167
  }
167
168
  };
168
169
  if (mockup.composition) {
@@ -279,11 +280,17 @@ function denormalizeView(view) {
279
280
  return mergeDefaults(view, defaultView);
280
281
  }
281
282
  export function denormalizeMockup(mockup) {
282
- const composition = denormalizeComposition(mockup.composition || {});
283
+ const canvasSize = mockup.canvasSize || DEFAULT_CANVAS_SIZE;
284
+ const compositionInput = mockup.composition || {};
285
+ const composition = denormalizeComposition({
286
+ ...compositionInput,
287
+ width: compositionInput.width ?? canvasSize.width,
288
+ height: compositionInput.height ?? canvasSize.height
289
+ });
283
290
  return {
284
291
  id: mockup.id || crypto.randomUUID(),
285
292
  name: mockup.name || 'Untitled Mockup',
286
- canvasSize: mockup.canvasSize || DEFAULT_CANVAS_SIZE,
293
+ canvasSize: canvasSize,
287
294
  layers: composition.layers,
288
295
  composition: composition,
289
296
  view: denormalizeView(mockup.view || {}),
package/dist/types.d.ts CHANGED
@@ -14,6 +14,39 @@ export interface Layer {
14
14
  visible?: boolean;
15
15
  effects?: LayerEffect[];
16
16
  }
17
+ export type MockupLayerEffect = ({
18
+ type: 'restyle';
19
+ } & Partial<Extract<LayerEffect, {
20
+ type: 'restyle';
21
+ }>>) | ({
22
+ type: 'resize';
23
+ width: number;
24
+ height: number;
25
+ } & Partial<Extract<LayerEffect, {
26
+ type: 'resize';
27
+ }>>) | ({
28
+ type: 'position';
29
+ containerWidth: number;
30
+ containerHeight: number;
31
+ } & Partial<Extract<LayerEffect, {
32
+ type: 'position';
33
+ }>>) | ({
34
+ type: 'warp';
35
+ enabled: boolean;
36
+ } & Partial<Extract<LayerEffect, {
37
+ type: 'warp';
38
+ }>>) | Extract<LayerEffect, {
39
+ type: 'svg';
40
+ }>;
41
+ export interface MockupLayer {
42
+ id: string;
43
+ src: string;
44
+ name?: string;
45
+ transform?: LayerTransform;
46
+ opacity?: number;
47
+ visible?: boolean;
48
+ effects?: MockupLayerEffect[];
49
+ }
17
50
  export interface CanvasSize {
18
51
  width: number;
19
52
  height: number;
@@ -25,6 +58,12 @@ export interface Composition {
25
58
  layers: Layer[];
26
59
  effects: CanvasEffect[];
27
60
  }
61
+ export interface MockupComposition {
62
+ width: number;
63
+ height: number;
64
+ layers: MockupLayer[];
65
+ effects?: CanvasEffect[];
66
+ }
28
67
  export interface ViewSettings {
29
68
  zoom: number;
30
69
  panX: number;
@@ -40,6 +79,26 @@ export interface Mockup {
40
79
  createdAt: number;
41
80
  updatedAt: number;
42
81
  }
82
+ export interface MockupConfig {
83
+ id: string;
84
+ name: string;
85
+ canvasSize?: CanvasSize;
86
+ layers?: MockupLayer[];
87
+ composition?: MockupComposition;
88
+ view?: Partial<ViewSettings>;
89
+ createdAt?: number;
90
+ updatedAt?: number;
91
+ }
92
+ export interface DenormalizedMockup extends Mockup {
93
+ id: string;
94
+ name: string;
95
+ canvasSize: CanvasSize;
96
+ layers: Layer[];
97
+ composition: Composition;
98
+ view: ViewSettings;
99
+ createdAt: number;
100
+ updatedAt: number;
101
+ }
43
102
  export declare const defaultTransform: LayerTransform;
44
103
  export declare const defaultLayer: Omit<Layer, 'id' | 'src'>;
45
104
  export declare const defaultView: ViewSettings;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "svelte-product-mockup",
3
- "version": "1.0.11",
3
+ "version": "1.0.12",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",
@@ -30,7 +30,7 @@
30
30
  "check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
31
31
  "check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
32
32
  "prepublishOnly": "pnpm run build:package",
33
- "publish": "sh -c 'set -a && . ../.env && set +a && npm publish'"
33
+ "publish": "set -a && . ../.env && set +a && npm publish"
34
34
  },
35
35
  "peerDependencies": {
36
36
  "svelte": "^5.0.0"
@@ -1,11 +1,11 @@
1
1
  <script lang="ts">
2
2
  import { onMount, onDestroy, tick, untrack } from 'svelte';
3
- import type { Mockup } from '$lib/types';
3
+ import type { Mockup, MockupConfig } from '$lib/types';
4
4
  import { renderMockupCanvasEditor, type RenderController } from '$lib/renderMockupCanvasEditor';
5
5
  import { denormalizeMockup } from '$lib/mockup-normalize';
6
6
 
7
7
  interface Props {
8
- mockup: Mockup;
8
+ mockup: Mockup | MockupConfig;
9
9
  imageOverrides?: Record<string, string>;
10
10
  objectFit?: 'contain' | 'cover';
11
11
  debounceMs?: number;
@@ -1,11 +1,11 @@
1
1
  <script lang="ts">
2
2
  import { onMount } from 'svelte';
3
- import type { Mockup } from '$lib/types';
3
+ import type { Mockup, MockupConfig } from '$lib/types';
4
4
  import { renderMockupCanvas } from '$lib/renderMockupCanvas';
5
5
  import { denormalizeMockup } from '$lib/mockup-normalize';
6
6
 
7
7
  interface Props {
8
- mockup: Mockup;
8
+ mockup: Mockup | MockupConfig;
9
9
  imageOverrides?: Record<string, string>;
10
10
  objectFit?: 'contain' | 'cover';
11
11
  }
@@ -1,4 +1,14 @@
1
- import type { Mockup, Layer, Composition, LayerTransform, ViewSettings } from './types';
1
+ import type {
2
+ Mockup,
3
+ MockupConfig,
4
+ DenormalizedMockup,
5
+ Layer,
6
+ MockupLayer,
7
+ Composition,
8
+ MockupComposition,
9
+ LayerTransform,
10
+ ViewSettings
11
+ } from './types';
2
12
  import {
3
13
  defaultLayer,
4
14
  defaultTransform,
@@ -156,8 +166,8 @@ function normalizeLayerEffect(effect: LayerEffect): Partial<LayerEffect> | null
156
166
  }
157
167
  }
158
168
 
159
- function normalizeLayer(layer: Layer): Partial<Layer> {
160
- const normalized: Partial<Layer> = {
169
+ function normalizeLayer(layer: Layer): MockupLayer {
170
+ const normalized: MockupLayer = {
161
171
  id: layer.id,
162
172
  src: layer.src
163
173
  };
@@ -191,11 +201,11 @@ function normalizeLayer(layer: Layer): Partial<Layer> {
191
201
  return normalized;
192
202
  }
193
203
 
194
- function normalizeComposition(composition: Composition): Partial<Composition> & { width: number; height: number; layers: Layer[] } {
195
- const normalized: Partial<Composition> & { width: number; height: number; layers: Layer[] } = {
204
+ function normalizeComposition(composition: Composition): MockupComposition {
205
+ const normalized: MockupComposition = {
196
206
  width: composition.width,
197
207
  height: composition.height,
198
- layers: composition.layers.length > 0 ? composition.layers.map(normalizeLayer) as Layer[] : []
208
+ layers: composition.layers.length > 0 ? composition.layers.map(normalizeLayer) : []
199
209
  };
200
210
 
201
211
  if (composition.effects && composition.effects.length > 0) {
@@ -209,13 +219,14 @@ function normalizeView(view: ViewSettings): Partial<ViewSettings> {
209
219
  return omitDefaults(view, defaultView);
210
220
  }
211
221
 
212
- export function normalizeMockup(mockup: Mockup, clean: boolean = false): Partial<Mockup> {
213
- const normalized: Partial<Mockup> = {
222
+ export function normalizeMockup(mockup: Mockup, clean: boolean = false): Partial<MockupConfig> {
223
+ const canvasSize = mockup.canvasSize || DEFAULT_CANVAS_SIZE;
224
+ const normalized: Partial<MockupConfig> = {
214
225
  id: mockup.id,
215
226
  name: mockup.name,
216
227
  canvasSize: {
217
- width: mockup.canvasSize.width,
218
- height: mockup.canvasSize.height
228
+ width: canvasSize.width,
229
+ height: canvasSize.height
219
230
  }
220
231
  };
221
232
 
@@ -320,7 +331,7 @@ function denormalizeLayerEffect(effect: Partial<LayerEffect>): LayerEffect {
320
331
  }
321
332
  }
322
333
 
323
- function denormalizeLayer(layer: Partial<Layer>): Layer {
334
+ function denormalizeLayer(layer: Partial<MockupLayer>): Layer {
324
335
  const denormalized: Layer = {
325
336
  id: layer.id!,
326
337
  src: layer.src || '',
@@ -337,7 +348,7 @@ function denormalizeLayer(layer: Partial<Layer>): Layer {
337
348
  return denormalized;
338
349
  }
339
350
 
340
- function denormalizeComposition(composition: Partial<Composition>): Composition {
351
+ function denormalizeComposition(composition: Partial<MockupComposition>): Composition {
341
352
  return {
342
353
  width: composition.width ?? defaultComposition.width,
343
354
  height: composition.height ?? defaultComposition.height,
@@ -350,12 +361,18 @@ function denormalizeView(view: Partial<ViewSettings>): ViewSettings {
350
361
  return mergeDefaults(view, defaultView);
351
362
  }
352
363
 
353
- export function denormalizeMockup(mockup: Partial<Mockup>): Mockup {
354
- const composition = denormalizeComposition(mockup.composition || {});
364
+ export function denormalizeMockup(mockup: Partial<MockupConfig>): DenormalizedMockup {
365
+ const canvasSize = mockup.canvasSize || DEFAULT_CANVAS_SIZE;
366
+ const compositionInput = mockup.composition || {};
367
+ const composition = denormalizeComposition({
368
+ ...compositionInput,
369
+ width: compositionInput.width ?? canvasSize.width,
370
+ height: compositionInput.height ?? canvasSize.height
371
+ });
355
372
  return {
356
373
  id: mockup.id || crypto.randomUUID(),
357
374
  name: mockup.name || 'Untitled Mockup',
358
- canvasSize: mockup.canvasSize || DEFAULT_CANVAS_SIZE,
375
+ canvasSize: canvasSize,
359
376
  layers: composition.layers,
360
377
  composition: composition,
361
378
  view: denormalizeView(mockup.view || {}),
package/src/lib/types.ts CHANGED
@@ -17,6 +17,23 @@ export interface Layer {
17
17
  effects?: LayerEffect[];
18
18
  }
19
19
 
20
+ export type MockupLayerEffect =
21
+ | ({ type: 'restyle' } & Partial<Extract<LayerEffect, { type: 'restyle' }>>)
22
+ | ({ type: 'resize'; width: number; height: number } & Partial<Extract<LayerEffect, { type: 'resize' }>>)
23
+ | ({ type: 'position'; containerWidth: number; containerHeight: number } & Partial<Extract<LayerEffect, { type: 'position' }>>)
24
+ | ({ type: 'warp'; enabled: boolean } & Partial<Extract<LayerEffect, { type: 'warp' }>>)
25
+ | Extract<LayerEffect, { type: 'svg' }>;
26
+
27
+ export interface MockupLayer {
28
+ id: string;
29
+ src: string;
30
+ name?: string;
31
+ transform?: LayerTransform;
32
+ opacity?: number;
33
+ visible?: boolean;
34
+ effects?: MockupLayerEffect[];
35
+ }
36
+
20
37
  export interface CanvasSize {
21
38
  width: number;
22
39
  height: number;
@@ -34,6 +51,13 @@ export interface Composition {
34
51
  effects: CanvasEffect[];
35
52
  }
36
53
 
54
+ export interface MockupComposition {
55
+ width: number;
56
+ height: number;
57
+ layers: MockupLayer[];
58
+ effects?: CanvasEffect[];
59
+ }
60
+
37
61
  export interface ViewSettings {
38
62
  zoom: number;
39
63
  panX: number;
@@ -51,6 +75,28 @@ export interface Mockup {
51
75
  updatedAt: number;
52
76
  }
53
77
 
78
+ export interface MockupConfig {
79
+ id: string;
80
+ name: string;
81
+ canvasSize?: CanvasSize;
82
+ layers?: MockupLayer[];
83
+ composition?: MockupComposition;
84
+ view?: Partial<ViewSettings>;
85
+ createdAt?: number;
86
+ updatedAt?: number;
87
+ }
88
+
89
+ export interface DenormalizedMockup extends Mockup {
90
+ id: string;
91
+ name: string;
92
+ canvasSize: CanvasSize;
93
+ layers: Layer[];
94
+ composition: Composition;
95
+ view: ViewSettings;
96
+ createdAt: number;
97
+ updatedAt: number;
98
+ }
99
+
54
100
  export const defaultTransform: LayerTransform = {
55
101
  x: 0,
56
102
  y: 0,