@r2digisolutions/components 0.24.4 → 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.
@@ -3,6 +3,8 @@
3
3
  import MediaAssetBrowser from '../../molecules/MediaAssetBrowser/MediaAssetBrowser.svelte';
4
4
  import MediaLayerList from '../../molecules/MediaLayerList/MediaLayerList.svelte';
5
5
  import MediaStage from '../../molecules/MediaStage/MediaStage.svelte';
6
+ import CanvasPageStrip from './CanvasPageStrip.svelte';
7
+ import CanvasQuickDock from './CanvasQuickDock.svelte';
6
8
  import CanvasInspector from '../../molecules/CanvasInspector/CanvasInspector.svelte';
7
9
  import CanvasElementsPanel, {
8
10
  type CanvasElementDef
@@ -25,18 +27,25 @@
25
27
  INSTAGRAM_GRID_PRESET_ID,
26
28
  alignLayerRect,
27
29
  applyTextAutoSize,
30
+ blankCanvasPage,
31
+ cloneCanvasLayers,
28
32
  createCanvasGuide,
29
33
  createCanvasLayer,
30
34
  createPathFromDocPoints,
31
35
  defaultSlotFromRect,
36
+ documentWithPages,
32
37
  emptyCanvasDocument,
33
38
  instagramGridGuides,
34
39
  migrateCanvasDocument,
40
+ pagesOf,
35
41
  presetIdForSize,
42
+ projectPage,
43
+ writePage,
36
44
  type CanvasAlign,
37
45
  type CanvasDocument,
38
46
  type CanvasLayer,
39
- type CanvasLayerKind
47
+ type CanvasLayerKind,
48
+ type CanvasPage
40
49
  } from '../../../utils/canvasDocument.js';
41
50
  import {
42
51
  deleteSubtree,
@@ -173,11 +182,14 @@
173
182
  onexport
174
183
  }: CanvasEditorProps = $props();
175
184
 
176
- // Ensure v2 document shape
185
+ // Ensure v2 document shape and a page list (older files are one sheet).
177
186
  $effect.pre(() => {
178
187
  if (value.version !== 2 || !value.widgets) {
179
188
  value = migrateCanvasDocument(value);
180
189
  }
190
+ if (!value.pages?.length) {
191
+ value = documentWithPages(value);
192
+ }
181
193
  });
182
194
 
183
195
  let selectedIds = $state<string[]>([]);
@@ -195,7 +207,12 @@
195
207
  let editingWidgetId = $state<string | null>(null);
196
208
  let history = $state<CanvasHistoryState>(createCanvasHistory(value));
197
209
  let applyingHistory = false;
210
+ let activePageId = $state('');
211
+ type PageSnap = { width: number; height: number; page: CanvasPage };
212
+ type PageHist = { past: string[]; future: string[]; last: string };
213
+ let pageHistory = $state<Record<string, PageHist>>({});
198
214
  let syncInstanceSizes = $state(true);
215
+ const toolOn = 'bg-neutral-200 text-neutral-950 dark:bg-neutral-700 dark:text-neutral-50';
199
216
 
200
217
  const gridSizeOptions = [
201
218
  { value: '4', label: '4px' },
@@ -210,8 +227,22 @@
210
227
  editingWidgetId ? ((value.widgets ?? []).find((w) => w.id === editingWidgetId) ?? null) : null
211
228
  );
212
229
 
230
+ const designPages = $derived(pagesOf(value));
231
+ const resolvedPageId = $derived(
232
+ designPages.some((page) => page.id === activePageId)
233
+ ? activePageId
234
+ : (designPages[0]?.id ?? '')
235
+ );
236
+ const activePageHist = $derived(pageHistory[resolvedPageId]);
237
+ const canUndo = $derived(
238
+ editingWidgetId ? history.past.length > 0 : (activePageHist?.past.length ?? 0) > 0
239
+ );
240
+ const canRedo = $derived(
241
+ editingWidgetId ? history.future.length > 0 : (activePageHist?.future.length ?? 0) > 0
242
+ );
243
+
213
244
  const stageDoc = $derived.by((): CanvasDocument => {
214
- if (!editingWidget) return value;
245
+ if (!editingWidget) return projectPage(value, resolvedPageId);
215
246
  return {
216
247
  ...value,
217
248
  width: editingWidget.width,
@@ -247,8 +278,8 @@
247
278
  id: 'edit',
248
279
  label: 'Edición',
249
280
  items: [
250
- { id: 'undo', label: 'Deshacer', shortcut: '⌘Z', disabled: history.past.length === 0 },
251
- { id: 'redo', label: 'Rehacer', shortcut: '⇧⌘Z', disabled: history.future.length === 0 },
281
+ { id: 'undo', label: 'Deshacer', shortcut: '⌘Z', disabled: !canUndo },
282
+ { id: 'redo', label: 'Rehacer', shortcut: '⇧⌘Z', disabled: !canRedo },
252
283
  {
253
284
  id: 'delete',
254
285
  label: 'Borrar selección',
@@ -471,37 +502,187 @@
471
502
  ];
472
503
  });
473
504
 
505
+ function pageSnap(doc: CanvasDocument, pageId: string): string {
506
+ const page = pagesOf(doc).find((item) => item.id === pageId) ?? pagesOf(doc)[0];
507
+ const snap: PageSnap = { width: doc.width, height: doc.height, page };
508
+ return JSON.stringify(snap);
509
+ }
510
+
511
+ function seedPageHistory(doc: CanvasDocument, pageId: string) {
512
+ if (!pageId || pageHistory[pageId]) return;
513
+ pageHistory = {
514
+ ...pageHistory,
515
+ [pageId]: { past: [], future: [], last: pageSnap(doc, pageId) }
516
+ };
517
+ }
518
+
519
+ function applyPageSnap(doc: CanvasDocument, raw: string): CanvasDocument {
520
+ const snap = JSON.parse(raw) as PageSnap;
521
+ return {
522
+ ...writePage(doc, snap.page.id, snap.page),
523
+ width: snap.width,
524
+ height: snap.height
525
+ };
526
+ }
527
+
474
528
  function emit(next: CanvasDocument) {
475
529
  const migrated = migrateCanvasDocument(next);
476
- if (!applyingHistory) {
477
- history = pushCanvasHistory(history, migrated);
478
- } else {
479
- history = { ...history, last: JSON.stringify(migrated) };
530
+ if (editingWidgetId) {
531
+ if (!applyingHistory) {
532
+ history = pushCanvasHistory(history, migrated);
533
+ } else {
534
+ history = { ...history, last: JSON.stringify(migrated) };
535
+ }
536
+ value = migrated;
537
+ onchange?.(value);
538
+ return;
480
539
  }
481
- value = migrated;
540
+ const pageId = resolvedPageId;
541
+ seedPageHistory(value, pageId);
542
+ const stored = {
543
+ ...writePage(migrated, pageId, {
544
+ background: migrated.background,
545
+ layers: migrated.layers,
546
+ guides: migrated.guides,
547
+ guidesLocked: migrated.guidesLocked
548
+ }),
549
+ width: migrated.width,
550
+ height: migrated.height,
551
+ widgets: migrated.widgets ?? []
552
+ };
553
+ const snap = pageSnap(stored, pageId);
554
+ const hist = pageHistory[pageId] ?? { past: [], future: [], last: snap };
555
+ if (!applyingHistory && snap !== hist.last) {
556
+ pageHistory = {
557
+ ...pageHistory,
558
+ [pageId]: {
559
+ past: [...hist.past, hist.last].slice(-80),
560
+ future: [],
561
+ last: snap
562
+ }
563
+ };
564
+ } else if (applyingHistory) {
565
+ pageHistory = {
566
+ ...pageHistory,
567
+ [pageId]: { ...hist, last: snap }
568
+ };
569
+ }
570
+ value = stored;
482
571
  onchange?.(value);
483
572
  }
484
573
 
485
574
  function undo() {
486
- const result = undoCanvasHistory(history);
487
- if (!result) return;
575
+ if (editingWidgetId) {
576
+ const result = undoCanvasHistory(history);
577
+ if (!result) return;
578
+ applyingHistory = true;
579
+ history = result.state;
580
+ value = migrateCanvasDocument(result.doc);
581
+ applyingHistory = false;
582
+ onchange?.(value);
583
+ selectedIds = selectedIds.filter((id) => stageDoc.layers.some((l) => l.id === id));
584
+ return;
585
+ }
586
+ const pageId = resolvedPageId;
587
+ const hist = pageHistory[pageId];
588
+ if (!hist?.past.length) return;
589
+ const prev = hist.past[hist.past.length - 1];
488
590
  applyingHistory = true;
489
- history = result.state;
490
- value = migrateCanvasDocument(result.doc);
591
+ pageHistory = {
592
+ ...pageHistory,
593
+ [pageId]: {
594
+ past: hist.past.slice(0, -1),
595
+ future: [hist.last, ...hist.future].slice(0, 80),
596
+ last: prev
597
+ }
598
+ };
599
+ value = applyPageSnap(value, prev);
491
600
  applyingHistory = false;
492
601
  onchange?.(value);
493
- selectedIds = selectedIds.filter((id) => stageDoc.layers.some((l) => l.id === id));
602
+ selectedIds = selectedIds.filter((id) => value.layers.some((l) => l.id === id));
494
603
  }
495
604
 
496
605
  function redo() {
497
- const result = redoCanvasHistory(history);
498
- if (!result) return;
606
+ if (editingWidgetId) {
607
+ const result = redoCanvasHistory(history);
608
+ if (!result) return;
609
+ applyingHistory = true;
610
+ history = result.state;
611
+ value = migrateCanvasDocument(result.doc);
612
+ applyingHistory = false;
613
+ onchange?.(value);
614
+ selectedIds = selectedIds.filter((id) => stageDoc.layers.some((l) => l.id === id));
615
+ return;
616
+ }
617
+ const pageId = resolvedPageId;
618
+ const hist = pageHistory[pageId];
619
+ if (!hist?.future.length) return;
620
+ const next = hist.future[0];
499
621
  applyingHistory = true;
500
- history = result.state;
501
- value = migrateCanvasDocument(result.doc);
622
+ pageHistory = {
623
+ ...pageHistory,
624
+ [pageId]: {
625
+ past: [...hist.past, hist.last].slice(-80),
626
+ future: hist.future.slice(1),
627
+ last: next
628
+ }
629
+ };
630
+ value = applyPageSnap(value, next);
502
631
  applyingHistory = false;
503
632
  onchange?.(value);
504
- selectedIds = selectedIds.filter((id) => stageDoc.layers.some((l) => l.id === id));
633
+ selectedIds = selectedIds.filter((id) => value.layers.some((l) => l.id === id));
634
+ }
635
+
636
+ function showPage(pageId: string, pages = pagesOf(value)) {
637
+ activePageId = pageId;
638
+ const next = projectPage({ ...value, pages }, pageId);
639
+ seedPageHistory(next, pageId);
640
+ value = next;
641
+ selectedIds = [];
642
+ editingTextId = null;
643
+ onchange?.(value);
644
+ }
645
+
646
+ function addPage() {
647
+ const page = blankCanvasPage({ name: `Hoja ${designPages.length + 1}` });
648
+ showPage(page.id, [...designPages, page]);
649
+ }
650
+
651
+ function duplicatePage(pageId: string) {
652
+ const source = designPages.find((page) => page.id === pageId);
653
+ if (!source) return;
654
+ const copy = blankCanvasPage({
655
+ name: `${source.name?.trim() || 'Hoja'} copia`,
656
+ background: source.background,
657
+ layers: cloneCanvasLayers(source.layers),
658
+ guides: (source.guides ?? []).map((guide) =>
659
+ createCanvasGuide(guide.orientation, guide.position, { locked: guide.locked })
660
+ ),
661
+ guidesLocked: source.guidesLocked
662
+ });
663
+ const index = designPages.findIndex((page) => page.id === pageId);
664
+ const pages = [...designPages];
665
+ pages.splice(index + 1, 0, copy);
666
+ showPage(copy.id, pages);
667
+ }
668
+
669
+ function deletePage(pageId: string) {
670
+ if (designPages.length < 2) return;
671
+ const index = designPages.findIndex((page) => page.id === pageId);
672
+ const pages = designPages.filter((page) => page.id !== pageId);
673
+ const neighbor = pages[Math.min(index, pages.length - 1)];
674
+ showPage(neighbor.id, pages);
675
+ }
676
+
677
+ function movePage(pageId: string, direction: -1 | 1) {
678
+ const pages = [...designPages];
679
+ const index = pages.findIndex((page) => page.id === pageId);
680
+ const target = index + direction;
681
+ if (index < 0 || target < 0 || target >= pages.length) return;
682
+ const [item] = pages.splice(index, 1);
683
+ pages.splice(target, 0, item);
684
+ value = projectPage({ ...value, pages }, resolvedPageId);
685
+ onchange?.(value);
505
686
  }
506
687
 
507
688
  function emitStageLayers(layers: CanvasLayer[], extra?: Partial<CanvasDocument>) {
@@ -1129,8 +1310,8 @@
1129
1310
  downloadBlob(blob, 'canvas-document.json');
1130
1311
  return;
1131
1312
  }
1132
- const blob = await exportCanvasBlob(value, format);
1133
- onexport?.({ format, document: value, blob });
1313
+ const blob = await exportCanvasBlob(projectPage(value, resolvedPageId), format);
1314
+ onexport?.({ format, document: projectPage(value, resolvedPageId), blob });
1134
1315
  downloadBlob(blob, format === 'jpeg' ? 'canvas.jpg' : 'canvas.png');
1135
1316
  } catch (err) {
1136
1317
  console.error('Canvas export failed', err);
@@ -1239,7 +1420,7 @@
1239
1420
  <Menubar items={menuItems} onselect={onMenu} />
1240
1421
  {/if}
1241
1422
  <header
1242
- class="gap-3 border-border bg-surface-elevated px-3 py-2 flex shrink-0 items-center border-b"
1423
+ class="gap-3 border-border bg-neutral-100 px-3 py-2 dark:bg-neutral-900 relative flex shrink-0 items-center border-b"
1243
1424
  >
1244
1425
  <div class="min-w-0 gap-2 flex items-center">
1245
1426
  {#if editingWidget}
@@ -1291,10 +1472,10 @@
1291
1472
  </div>
1292
1473
 
1293
1474
  <div class="rounded-lg border-border bg-surface p-0.5 flex items-center border">
1294
- <IconButton label="Undo" size="sm" disabled={!history.past.length} onclick={undo}>
1475
+ <IconButton label="Undo" size="sm" disabled={!canUndo} onclick={undo}>
1295
1476
  <Undo2 class="h-3.5 w-3.5" />
1296
1477
  </IconButton>
1297
- <IconButton label="Redo" size="sm" disabled={!history.future.length} onclick={redo}>
1478
+ <IconButton label="Redo" size="sm" disabled={!canRedo} onclick={redo}>
1298
1479
  <Redo2 class="h-3.5 w-3.5" />
1299
1480
  </IconButton>
1300
1481
  </div>
@@ -1309,7 +1490,7 @@
1309
1490
  showGrid = !showGrid;
1310
1491
  (e.currentTarget as HTMLButtonElement).blur();
1311
1492
  }}
1312
- class={showGrid ? 'bg-brand-500/10 text-brand-600' : undefined}
1493
+ class={showGrid ? toolOn : undefined}
1313
1494
  >
1314
1495
  <Grid3x3 class="h-3.5 w-3.5" />
1315
1496
  </IconButton>
@@ -1335,7 +1516,7 @@
1335
1516
  snap = !snap;
1336
1517
  (e.currentTarget as HTMLButtonElement).blur();
1337
1518
  }}
1338
- class={snap ? 'bg-brand-500/10 text-brand-600' : undefined}
1519
+ class={snap ? toolOn : undefined}
1339
1520
  >
1340
1521
  <Magnet class="h-3.5 w-3.5" />
1341
1522
  </IconButton>
@@ -1350,7 +1531,7 @@
1350
1531
  label="Pen tool"
1351
1532
  size="sm"
1352
1533
  onclick={() => (drawMode = !drawMode)}
1353
- class={drawMode ? 'bg-brand-500/10 text-brand-600' : undefined}
1534
+ class={drawMode ? toolOn : undefined}
1354
1535
  >
1355
1536
  <Pencil class="h-3.5 w-3.5" />
1356
1537
  </IconButton>
@@ -1365,7 +1546,7 @@
1365
1546
  label="Toggle guides"
1366
1547
  size="sm"
1367
1548
  onclick={() => (showGuides = !showGuides)}
1368
- class={showGuides ? 'bg-brand-500/10 text-brand-600' : undefined}
1549
+ class={showGuides ? toolOn : undefined}
1369
1550
  >
1370
1551
  <Eye class="h-3.5 w-3.5" />
1371
1552
  </IconButton>
@@ -1385,7 +1566,7 @@
1385
1566
  label={value.guidesLocked ? 'Unlock guides' : 'Lock guides'}
1386
1567
  size="sm"
1387
1568
  onclick={toggleGuidesLocked}
1388
- class={value.guidesLocked ? 'bg-brand-500/10 text-brand-600' : undefined}
1569
+ class={value.guidesLocked ? toolOn : undefined}
1389
1570
  >
1390
1571
  {#if value.guidesLocked}
1391
1572
  <Lock class="h-3.5 w-3.5" />
@@ -1430,6 +1611,68 @@
1430
1611
  </div>
1431
1612
  {/if}
1432
1613
 
1614
+ <div
1615
+ class="pointer-events-none absolute inset-y-0 left-1/2 flex -translate-x-1/2 items-center"
1616
+ >
1617
+ <div
1618
+ class="border-border bg-neutral-50 p-0.5 dark:bg-neutral-800 pointer-events-auto flex items-center rounded-lg border"
1619
+ >
1620
+ <button
1621
+ type="button"
1622
+ class={[
1623
+ 'rounded-md px-2.5 py-1 text-xs font-medium',
1624
+ stageFrame === 'edit' ? toolOn : 'text-neutral-600 hover:bg-neutral-200/70 dark:text-neutral-300 dark:hover:bg-neutral-700 dark:hover:text-neutral-50'
1625
+ ]}
1626
+ aria-pressed={stageFrame === 'edit'}
1627
+ onclick={() => (stageFrame = 'edit')}
1628
+ >
1629
+ Lienzo
1630
+ </button>
1631
+ <button
1632
+ type="button"
1633
+ class={[
1634
+ 'gap-1 rounded-md px-2.5 py-1 text-xs font-medium inline-flex items-center',
1635
+ stageFrame === 'desktop'
1636
+ ? toolOn
1637
+ : 'text-neutral-600 hover:bg-neutral-200/70 dark:text-neutral-300 dark:hover:bg-neutral-700 dark:hover:text-neutral-50'
1638
+ ]}
1639
+ aria-pressed={stageFrame === 'desktop'}
1640
+ onclick={() => (stageFrame = 'desktop')}
1641
+ >
1642
+ <Monitor class="h-3.5 w-3.5" />
1643
+ Escritorio
1644
+ </button>
1645
+ <button
1646
+ type="button"
1647
+ class={[
1648
+ 'gap-1 rounded-md px-2.5 py-1 text-xs font-medium inline-flex items-center',
1649
+ stageFrame === 'tablet'
1650
+ ? toolOn
1651
+ : 'text-neutral-600 hover:bg-neutral-200/70 dark:text-neutral-300 dark:hover:bg-neutral-700 dark:hover:text-neutral-50'
1652
+ ]}
1653
+ aria-pressed={stageFrame === 'tablet'}
1654
+ onclick={() => (stageFrame = 'tablet')}
1655
+ >
1656
+ <Tablet class="h-3.5 w-3.5" />
1657
+ Tablet
1658
+ </button>
1659
+ <button
1660
+ type="button"
1661
+ class={[
1662
+ 'gap-1 rounded-md px-2.5 py-1 text-xs font-medium inline-flex items-center',
1663
+ stageFrame === 'mobile'
1664
+ ? toolOn
1665
+ : 'text-neutral-600 hover:bg-neutral-200/70 dark:text-neutral-300 dark:hover:bg-neutral-700 dark:hover:text-neutral-50'
1666
+ ]}
1667
+ aria-pressed={stageFrame === 'mobile'}
1668
+ onclick={() => (stageFrame = 'mobile')}
1669
+ >
1670
+ <Smartphone class="h-3.5 w-3.5" />
1671
+ Móvil
1672
+ </button>
1673
+ </div>
1674
+ </div>
1675
+
1433
1676
  <div class="gap-1 ml-auto flex items-center">
1434
1677
  <IconButton
1435
1678
  label="Toggle sidebar"
@@ -1694,7 +1937,8 @@
1694
1937
  {/snippet}
1695
1938
 
1696
1939
  {#snippet workspace()}
1697
- <div class="min-h-0 relative h-full">
1940
+ <div class="flex h-full min-h-0 flex-col">
1941
+ <div class="relative min-h-0 flex-1">
1698
1942
  <MediaStage
1699
1943
  document={stageDoc}
1700
1944
  {selectedIds}
@@ -1746,46 +1990,31 @@
1746
1990
  {editingTextId}
1747
1991
  ontextcommit={commitText}
1748
1992
  />
1749
- <div class="inset-x-0 bottom-3 pointer-events-none absolute z-20 flex justify-center">
1750
- <div class="pointer-events-auto">
1751
- <Dock size="sm">
1752
- <DockItem
1753
- size="sm"
1754
- active={stageFrame === 'edit'}
1755
- ariaLabel="Lienzo"
1756
- onclick={() => (stageFrame = 'edit')}
1757
- >
1758
- Lienzo
1759
- </DockItem>
1760
- <DockItem
1761
- size="sm"
1762
- active={stageFrame === 'desktop'}
1763
- ariaLabel="Escritorio"
1764
- onclick={() => (stageFrame = 'desktop')}
1765
- >
1766
- <Monitor class="h-3.5 w-3.5" />
1767
- Escritorio
1768
- </DockItem>
1769
- <DockItem
1770
- size="sm"
1771
- active={stageFrame === 'tablet'}
1772
- ariaLabel="Tablet"
1773
- onclick={() => (stageFrame = 'tablet')}
1774
- >
1775
- <Tablet class="h-3.5 w-3.5" />
1776
- Tablet
1777
- </DockItem>
1778
- <DockItem
1779
- size="sm"
1780
- active={stageFrame === 'mobile'}
1781
- ariaLabel="Móvil"
1782
- onclick={() => (stageFrame = 'mobile')}
1783
- >
1784
- <Smartphone class="h-3.5 w-3.5" />
1785
- Móvil
1786
- </DockItem>
1787
- </Dock>
1993
+ {#if selectedLayer && mode !== 'frame'}
1994
+ <div class="inset-x-0 top-3 pointer-events-none absolute z-30 flex justify-center">
1995
+ <CanvasQuickDock
1996
+ layer={selectedLayer}
1997
+ onpatch={patchLayer}
1998
+ onduplicate={duplicateSelected}
1999
+ ondelete={deleteSelected}
2000
+ />
1788
2001
  </div>
2002
+ {/if}
2003
+ <div class="inset-x-0 bottom-3 pointer-events-none absolute z-20 flex justify-center">
2004
+ {#if mode !== 'frame' && !editingWidget}
2005
+ <div class="pointer-events-auto">
2006
+ <CanvasPageStrip
2007
+ pages={designPages}
2008
+ activeId={resolvedPageId}
2009
+ onselect={showPage}
2010
+ onduplicate={duplicatePage}
2011
+ ondelete={deletePage}
2012
+ onmove={movePage}
2013
+ onadd={addPage}
2014
+ />
2015
+ </div>
2016
+ {/if}
2017
+ </div>
1789
2018
  </div>
1790
2019
  </div>
1791
2020
  {/snippet}
@@ -0,0 +1,135 @@
1
+ <script lang="ts">
2
+ import IconButton from '../../atoms/IconButton/IconButton.svelte';
3
+ import type { CanvasPage } from '../../../utils/canvasDocument.js';
4
+ import Plus from '@lucide/svelte/icons/plus';
5
+ import Copy from '@lucide/svelte/icons/copy';
6
+ import Trash2 from '@lucide/svelte/icons/trash-2';
7
+ import ChevronDown from '@lucide/svelte/icons/chevron-down';
8
+ import ChevronLeft from '@lucide/svelte/icons/chevron-left';
9
+ import ChevronRight from '@lucide/svelte/icons/chevron-right';
10
+
11
+ interface CanvasPageStripProps {
12
+ pages: CanvasPage[];
13
+ activeId: string;
14
+ onselect: (id: string) => void;
15
+ onadd: () => void;
16
+ onduplicate: (id: string) => void;
17
+ ondelete: (id: string) => void;
18
+ onmove: (id: string, direction: -1 | 1) => void;
19
+ }
20
+
21
+ let { pages, activeId, onselect, onadd, onduplicate, ondelete, onmove }: CanvasPageStripProps =
22
+ $props();
23
+
24
+ let open = $state(false);
25
+
26
+ const activeIndex = $derived(Math.max(0, pages.findIndex((page) => page.id === activeId)));
27
+ const active = $derived(pages[activeIndex] ?? pages[0]);
28
+
29
+ function pick(id: string) {
30
+ onselect(id);
31
+ open = false;
32
+ }
33
+ </script>
34
+
35
+ <div class="relative">
36
+ <div
37
+ class="border-border bg-neutral-100 dark:bg-neutral-900 gap-0.5 rounded-xl p-1 shadow-lg flex items-center border"
38
+ aria-label="Hojas"
39
+ >
40
+ <button
41
+ type="button"
42
+ class="rounded-md relative h-11 w-9 overflow-hidden border border-border"
43
+ style:background-color={active?.background ?? '#ffffff'}
44
+ aria-current="true"
45
+ aria-label={`${active?.name?.trim() || `Hoja ${activeIndex + 1}`}, ${activeIndex + 1} de ${pages.length}`}
46
+ onclick={() => (open = !open)}
47
+ >
48
+ <span
49
+ class="bottom-0.5 left-0.5 rounded-sm bg-white/90 px-0.5 text-[10px] font-semibold leading-none text-neutral-900 absolute"
50
+ >
51
+ {activeIndex + 1}
52
+ </span>
53
+ </button>
54
+ <span class="text-neutral-700 dark:text-neutral-200 px-1 text-[11px] font-medium tabular-nums">
55
+ {activeIndex + 1} de {pages.length}
56
+ </span>
57
+ <IconButton label="Añadir hoja" size="sm" onclick={onadd}>
58
+ <Plus class="h-4 w-4" />
59
+ </IconButton>
60
+ <IconButton
61
+ label={open ? 'Cerrar hojas' : 'Ver hojas'}
62
+ size="sm"
63
+ onclick={() => (open = !open)}
64
+ >
65
+ <ChevronDown class={['h-4 w-4 transition-transform', open && 'rotate-180']} />
66
+ </IconButton>
67
+ </div>
68
+
69
+ {#if open}
70
+ <div
71
+ class="border-border bg-surface-elevated bottom-full rounded-xl p-2 shadow-lg absolute left-1/2 mb-2 w-72 -translate-x-1/2 border"
72
+ >
73
+ <div class="gap-2 flex overflow-x-auto pb-1">
74
+ {#each pages as page, index (page.id)}
75
+ {@const selected = page.id === activeId}
76
+ <button
77
+ type="button"
78
+ class={[
79
+ 'rounded-md relative h-16 w-12 shrink-0 overflow-hidden border',
80
+ selected ? 'border-neutral-950 ring-2 ring-neutral-950 dark:border-neutral-50 dark:ring-neutral-50' : 'border-border'
81
+ ]}
82
+ style:background-color={page.background}
83
+ aria-current={selected ? 'true' : undefined}
84
+ aria-label={page.name?.trim() || `Hoja ${index + 1}`}
85
+ onclick={() => pick(page.id)}
86
+ >
87
+ <span
88
+ class="bottom-0.5 left-0.5 rounded-sm bg-white/90 px-0.5 text-[10px] font-semibold leading-none text-neutral-900 absolute"
89
+ >
90
+ {index + 1}
91
+ </span>
92
+ </button>
93
+ {/each}
94
+ </div>
95
+ {#if active}
96
+ <div class="mt-1 flex items-center justify-between">
97
+ <span class="text-secondary min-w-0 truncate text-xs">
98
+ {active.name?.trim() || `Hoja ${activeIndex + 1}`}
99
+ <span class="text-muted">· {activeIndex + 1} de {pages.length}</span>
100
+ </span>
101
+ <div class="flex shrink-0">
102
+ <IconButton
103
+ label="Mover a la izquierda"
104
+ size="xs"
105
+ disabled={activeIndex === 0}
106
+ onclick={() => onmove(active.id, -1)}
107
+ >
108
+ <ChevronLeft class="h-3 w-3" />
109
+ </IconButton>
110
+ <IconButton
111
+ label="Mover a la derecha"
112
+ size="xs"
113
+ disabled={activeIndex >= pages.length - 1}
114
+ onclick={() => onmove(active.id, 1)}
115
+ >
116
+ <ChevronRight class="h-3 w-3" />
117
+ </IconButton>
118
+ <IconButton label="Duplicar hoja" size="xs" onclick={() => onduplicate(active.id)}>
119
+ <Copy class="h-3 w-3" />
120
+ </IconButton>
121
+ <IconButton
122
+ label="Eliminar hoja"
123
+ size="xs"
124
+ variant="destructive"
125
+ disabled={pages.length < 2}
126
+ onclick={() => ondelete(active.id)}
127
+ >
128
+ <Trash2 class="h-3 w-3" />
129
+ </IconButton>
130
+ </div>
131
+ </div>
132
+ {/if}
133
+ </div>
134
+ {/if}
135
+ </div>
@@ -0,0 +1,13 @@
1
+ import type { CanvasPage } from '../../../utils/canvasDocument.js';
2
+ interface CanvasPageStripProps {
3
+ pages: CanvasPage[];
4
+ activeId: string;
5
+ onselect: (id: string) => void;
6
+ onadd: () => void;
7
+ onduplicate: (id: string) => void;
8
+ ondelete: (id: string) => void;
9
+ onmove: (id: string, direction: -1 | 1) => void;
10
+ }
11
+ declare const CanvasPageStrip: import("svelte").Component<CanvasPageStripProps, {}, "">;
12
+ type CanvasPageStrip = ReturnType<typeof CanvasPageStrip>;
13
+ export default CanvasPageStrip;