@r2digisolutions/components 0.24.3 → 0.24.5
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.
- package/dist/components/molecules/CanvasInspector/CanvasInspector.svelte +25 -5
- package/dist/components/molecules/LocaleSwitcher/LocaleSwitcher.svelte +1 -1
- package/dist/components/molecules/MediaLayerItem/MediaLayerItem.svelte +1 -0
- package/dist/components/molecules/MediaStage/MediaStage.svelte +27 -30
- package/dist/components/molecules/PropertyField/PropertyField.svelte +14 -22
- package/dist/components/molecules/Stepper/Stepper.svelte +2 -0
- package/dist/components/molecules/WidgetFrame/WidgetFrame.svelte +25 -6
- package/dist/components/organisms/CanvasEditor/CanvasEditor.svelte +330 -78
- package/dist/components/organisms/CanvasEditor/CanvasEditor.svelte.d.ts +9 -1
- package/dist/components/organisms/CanvasEditor/CanvasPageStrip.svelte +135 -0
- package/dist/components/organisms/CanvasEditor/CanvasPageStrip.svelte.d.ts +13 -0
- package/dist/components/organisms/CanvasEditor/CanvasQuickDock.svelte +132 -0
- package/dist/components/organisms/CanvasEditor/CanvasQuickDock.svelte.d.ts +10 -0
- package/dist/components/organisms/DataListPage/DataListPage.svelte.d.ts +1 -1
- package/dist/components/organisms/ResourceStudio/ResourceStudio.svelte.d.ts +1 -1
- package/dist/components/organisms/SearchResults/SearchResults.svelte.d.ts +1 -1
- package/dist/components/templates/ListingTemplate/ListingTemplate.svelte.d.ts +1 -1
- package/dist/components/templates/ResourceStudioTemplate/ResourceStudioTemplate.svelte.d.ts +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/dist/styles.css +1 -1
- package/dist/utils/canvasDocument.d.ts +44 -0
- package/dist/utils/canvasDocument.js +139 -5
- package/package.json +1 -1
|
@@ -81,17 +81,106 @@ const LAYER_DEFAULTS = {
|
|
|
81
81
|
uniformGrid: { w: 320, h: 240, name: 'Uniform Grid', fill: 'transparent', gap: 8 }
|
|
82
82
|
};
|
|
83
83
|
export function emptyCanvasDocument(partial) {
|
|
84
|
+
const background = partial?.background ?? '#ffffff';
|
|
85
|
+
const layers = (partial?.layers ?? []).map(ensureLayerSlot);
|
|
86
|
+
const guides = partial?.guides ?? [];
|
|
87
|
+
const guidesLocked = partial?.guidesLocked ?? false;
|
|
88
|
+
const pages = partial?.pages && partial.pages.length > 0
|
|
89
|
+
? partial.pages
|
|
90
|
+
: [
|
|
91
|
+
blankCanvasPage({
|
|
92
|
+
name: 'Hoja 1',
|
|
93
|
+
background,
|
|
94
|
+
layers,
|
|
95
|
+
guides,
|
|
96
|
+
guidesLocked
|
|
97
|
+
})
|
|
98
|
+
];
|
|
99
|
+
const first = pages[0];
|
|
84
100
|
return {
|
|
85
101
|
version: 2,
|
|
86
102
|
width: partial?.width ?? 1280,
|
|
87
103
|
height: partial?.height ?? 720,
|
|
104
|
+
background: first.background,
|
|
105
|
+
layers: first.layers,
|
|
106
|
+
guides: first.guides ?? [],
|
|
107
|
+
guidesLocked: first.guidesLocked ?? false,
|
|
108
|
+
widgets: partial?.widgets ?? [],
|
|
109
|
+
pages
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
export function blankCanvasPage(partial) {
|
|
113
|
+
return {
|
|
114
|
+
id: uid('page'),
|
|
115
|
+
name: partial?.name,
|
|
88
116
|
background: partial?.background ?? '#ffffff',
|
|
89
|
-
layers:
|
|
117
|
+
layers: partial?.layers ?? [],
|
|
90
118
|
guides: partial?.guides ?? [],
|
|
91
|
-
guidesLocked: partial?.guidesLocked ?? false
|
|
92
|
-
|
|
119
|
+
guidesLocked: partial?.guidesLocked ?? false
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
/** Pages on a document. A document without `pages` is a single sheet. */
|
|
123
|
+
export function pagesOf(doc) {
|
|
124
|
+
if (doc.pages && doc.pages.length > 0)
|
|
125
|
+
return doc.pages;
|
|
126
|
+
return [
|
|
127
|
+
{
|
|
128
|
+
id: 'page-1',
|
|
129
|
+
name: 'Hoja 1',
|
|
130
|
+
background: doc.background,
|
|
131
|
+
layers: doc.layers,
|
|
132
|
+
guides: doc.guides ?? [],
|
|
133
|
+
guidesLocked: doc.guidesLocked ?? false
|
|
134
|
+
}
|
|
135
|
+
];
|
|
136
|
+
}
|
|
137
|
+
/** Persist `pages` without changing a document that already has them. */
|
|
138
|
+
export function documentWithPages(doc) {
|
|
139
|
+
if (doc.pages && doc.pages.length > 0)
|
|
140
|
+
return doc;
|
|
141
|
+
const page = pagesOf(doc)[0];
|
|
142
|
+
return { ...doc, pages: [page] };
|
|
143
|
+
}
|
|
144
|
+
/** View of the document as the given sheet. Top-level fields mirror that sheet. */
|
|
145
|
+
export function projectPage(doc, pageId) {
|
|
146
|
+
const pages = pagesOf(doc);
|
|
147
|
+
const page = pages.find((item) => item.id === pageId) ?? pages[0];
|
|
148
|
+
return {
|
|
149
|
+
...doc,
|
|
150
|
+
pages,
|
|
151
|
+
background: page.background,
|
|
152
|
+
layers: page.layers,
|
|
153
|
+
guides: page.guides ?? [],
|
|
154
|
+
guidesLocked: page.guidesLocked ?? false
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
/** Write one sheet and mirror it on the top-level fields (the active sheet). */
|
|
158
|
+
export function writePage(doc, pageId, patch) {
|
|
159
|
+
const pages = pagesOf(doc);
|
|
160
|
+
const index = Math.max(0, pages.findIndex((item) => item.id === pageId));
|
|
161
|
+
const current = pages[index] ?? pages[0];
|
|
162
|
+
const nextPage = { ...current, ...patch, id: current.id };
|
|
163
|
+
const nextPages = pages.map((item, i) => (i === index ? nextPage : item));
|
|
164
|
+
return {
|
|
165
|
+
...doc,
|
|
166
|
+
pages: nextPages,
|
|
167
|
+
background: nextPage.background,
|
|
168
|
+
layers: nextPage.layers,
|
|
169
|
+
guides: nextPage.guides ?? [],
|
|
170
|
+
guidesLocked: nextPage.guidesLocked ?? false
|
|
93
171
|
};
|
|
94
172
|
}
|
|
173
|
+
/** Clone layer ids so a duplicated sheet does not share identity with the source. */
|
|
174
|
+
export function cloneCanvasLayers(layers) {
|
|
175
|
+
const idMap = new Map(layers.map((layer) => [layer.id, uid('layer')]));
|
|
176
|
+
return layers.map((layer) => {
|
|
177
|
+
const copy = JSON.parse(JSON.stringify(layer));
|
|
178
|
+
copy.id = idMap.get(layer.id);
|
|
179
|
+
if (copy.parentId && idMap.has(copy.parentId))
|
|
180
|
+
copy.parentId = idMap.get(copy.parentId);
|
|
181
|
+
return copy;
|
|
182
|
+
});
|
|
183
|
+
}
|
|
95
184
|
/** Migrate v1 (flat absolute layers) → v2 (parentId + slot). */
|
|
96
185
|
export function migrateCanvasDocument(doc) {
|
|
97
186
|
const version = doc.version ?? 1;
|
|
@@ -198,6 +287,10 @@ export function createCanvasLayer(kind, partial) {
|
|
|
198
287
|
function canvasValuesEqual(a, b) {
|
|
199
288
|
if (a === b)
|
|
200
289
|
return true;
|
|
290
|
+
if (typeof a === 'number' && typeof b === 'string' && b !== '' && Number(b) === a)
|
|
291
|
+
return true;
|
|
292
|
+
if (typeof b === 'number' && typeof a === 'string' && a !== '' && Number(a) === b)
|
|
293
|
+
return true;
|
|
201
294
|
// Treat unset numeric effects as 0
|
|
202
295
|
if ((a == null || a === 0) && (b == null || b === 0))
|
|
203
296
|
return true;
|
|
@@ -243,9 +336,13 @@ export function canvasLayerFieldDefault(kind, field) {
|
|
|
243
336
|
case 'fontSize':
|
|
244
337
|
return d.fontSize;
|
|
245
338
|
case 'fontWeight':
|
|
339
|
+
return kind === 'text' || kind === 'sticky' ? 600 : undefined;
|
|
246
340
|
case 'fontFamily':
|
|
341
|
+
return undefined;
|
|
247
342
|
case 'fontStyle':
|
|
343
|
+
return kind === 'text' || kind === 'sticky' ? 'normal' : undefined;
|
|
248
344
|
case 'textDecoration':
|
|
345
|
+
return kind === 'text' || kind === 'sticky' ? 'none' : undefined;
|
|
249
346
|
case 'letterSpacing':
|
|
250
347
|
case 'lineHeight':
|
|
251
348
|
return undefined;
|
|
@@ -280,8 +377,8 @@ export function canvasLayerFieldDefault(kind, field) {
|
|
|
280
377
|
export function isCanvasFieldModified(layer, field) {
|
|
281
378
|
const def = canvasLayerFieldDefault(layer.kind, field);
|
|
282
379
|
const raw = layer[field];
|
|
283
|
-
//
|
|
284
|
-
const cur =
|
|
380
|
+
// Unset means the kind default (older docs and fields the UI fills in).
|
|
381
|
+
const cur = raw === undefined ? def : raw;
|
|
285
382
|
return !canvasValuesEqual(cur, def);
|
|
286
383
|
}
|
|
287
384
|
export function resetCanvasField(layer, field) {
|
|
@@ -498,17 +595,54 @@ export function canvasLayerFilter(layer) {
|
|
|
498
595
|
parts.push(`saturate(${layer.saturate}%)`);
|
|
499
596
|
return parts.length ? parts.join(' ') : undefined;
|
|
500
597
|
}
|
|
598
|
+
/** Instagram puzzle feed: 3 columns × 1080 and 3 rows × 1350 (4:5 tiles). */
|
|
599
|
+
export const INSTAGRAM_GRID_PRESET_ID = 'ig-grid-3x3';
|
|
600
|
+
export const INSTAGRAM_GRID = {
|
|
601
|
+
id: INSTAGRAM_GRID_PRESET_ID,
|
|
602
|
+
cols: 3,
|
|
603
|
+
rows: 3,
|
|
604
|
+
cellWidth: 1080,
|
|
605
|
+
cellHeight: 1350,
|
|
606
|
+
width: 3240,
|
|
607
|
+
height: 4050
|
|
608
|
+
};
|
|
501
609
|
export const CANVAS_PRESETS = [
|
|
502
610
|
{ id: 'cover', label: 'Cover · 1800×600', width: 1800, height: 600 },
|
|
503
611
|
{ id: 'hd', label: 'HD · 1280×720', width: 1280, height: 720 },
|
|
504
612
|
{ id: 'fhd', label: 'Full HD · 1920×1080', width: 1920, height: 1080 },
|
|
505
613
|
{ id: 'square', label: 'Instagram · 1080×1080', width: 1080, height: 1080 },
|
|
506
614
|
{ id: 'story', label: 'Story · 1080×1920', width: 1080, height: 1920 },
|
|
615
|
+
{
|
|
616
|
+
id: INSTAGRAM_GRID_PRESET_ID,
|
|
617
|
+
label: 'Instagram 3×3 · 3240×4050',
|
|
618
|
+
width: INSTAGRAM_GRID.width,
|
|
619
|
+
height: INSTAGRAM_GRID.height
|
|
620
|
+
},
|
|
507
621
|
{ id: 'landscape', label: 'Landscape · 1600×900', width: 1600, height: 900 },
|
|
508
622
|
{ id: 'presentation', label: 'Presentation · 1920×1080', width: 1920, height: 1080 },
|
|
509
623
|
{ id: 'a4', label: 'A4 · 794×1123', width: 794, height: 1123 },
|
|
510
624
|
{ id: 'twitter', label: 'X Post · 1600×900', width: 1600, height: 900 }
|
|
511
625
|
];
|
|
626
|
+
/** Locked cut lines between the nine Instagram tiles. */
|
|
627
|
+
export function instagramGridGuides() {
|
|
628
|
+
const guides = [];
|
|
629
|
+
for (let col = 1; col < INSTAGRAM_GRID.cols; col++) {
|
|
630
|
+
guides.push(createCanvasGuide('vertical', col * INSTAGRAM_GRID.cellWidth, { locked: true }));
|
|
631
|
+
}
|
|
632
|
+
for (let row = 1; row < INSTAGRAM_GRID.rows; row++) {
|
|
633
|
+
guides.push(createCanvasGuide('horizontal', row * INSTAGRAM_GRID.cellHeight, { locked: true }));
|
|
634
|
+
}
|
|
635
|
+
return guides;
|
|
636
|
+
}
|
|
637
|
+
export function emptyInstagramGridDocument() {
|
|
638
|
+
return emptyCanvasDocument({
|
|
639
|
+
width: INSTAGRAM_GRID.width,
|
|
640
|
+
height: INSTAGRAM_GRID.height,
|
|
641
|
+
background: '#0b1f3a',
|
|
642
|
+
guides: instagramGridGuides(),
|
|
643
|
+
guidesLocked: true
|
|
644
|
+
});
|
|
645
|
+
}
|
|
512
646
|
export function presetIdForSize(width, height) {
|
|
513
647
|
const match = CANVAS_PRESETS.find((p) => p.width === width && p.height === height);
|
|
514
648
|
return match?.id ?? 'custom';
|