@ggraphic/editor 0.1.0-alpha.4 → 0.1.0-alpha.6

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.
Files changed (131) hide show
  1. package/dist/CanvasEditorProvider.d.ts +6 -1
  2. package/dist/collab/useYjsPageStateSync.d.ts +1 -1
  3. package/dist/collab/useYjsPageStateSync.js +5 -2
  4. package/dist/components/CanvasEditor/CanvasEditorShell.js +139 -36
  5. package/dist/components/CanvasEditor/editorShell.d.ts +6 -0
  6. package/dist/components/CanvasEditor/types.d.ts +28 -0
  7. package/dist/components/GenericCanvas.d.ts +19 -2
  8. package/dist/components/GenericCanvas.js +30 -5
  9. package/dist/components/PagePreview.d.ts +8 -1
  10. package/dist/components/PagePreview.js +4 -1
  11. package/dist/components/TopBar/DownloadSection.d.ts +24 -3
  12. package/dist/components/TopBar/DownloadSection.js +45 -7
  13. package/dist/components/TopBar/ShareDropdown.d.ts +4 -2
  14. package/dist/components/TopBar/ShareDropdown.js +2 -2
  15. package/dist/entries/export.d.ts +14 -1
  16. package/dist/entries/export.js +14 -1
  17. package/dist/entries/services.d.ts +1 -1
  18. package/dist/export/fonts/fontFiles.d.ts +100 -0
  19. package/dist/export/fonts/fontFiles.js +333 -0
  20. package/dist/export/fonts/glyphs.d.ts +113 -0
  21. package/dist/export/fonts/glyphs.js +120 -0
  22. package/dist/export/fonts/variation.d.ts +23 -0
  23. package/dist/export/fonts/variation.js +43 -0
  24. package/dist/export/pdf/pdfContent.d.ts +108 -0
  25. package/dist/export/pdf/pdfContent.js +566 -0
  26. package/dist/export/pdf/pdfFontkit.d.ts +54 -0
  27. package/dist/export/pdf/pdfFontkit.js +159 -0
  28. package/dist/export/pdf/pdfGeometry.d.ts +54 -0
  29. package/dist/export/pdf/pdfGeometry.js +228 -0
  30. package/dist/export/pdf/pdfResources.d.ts +109 -0
  31. package/dist/export/pdf/pdfResources.js +314 -0
  32. package/dist/export/pdf/writePdf.d.ts +34 -0
  33. package/dist/export/pdf/writePdf.js +165 -0
  34. package/dist/export/pptx/exportPptxDeck.d.ts +10 -2
  35. package/dist/export/pptx/exportPptxDeck.js +5 -2
  36. package/dist/export/pptx/svgPicture.d.ts +19 -0
  37. package/dist/export/pptx/svgPicture.js +64 -0
  38. package/dist/export/pptx/vectorizeElement.d.ts +9 -0
  39. package/dist/export/pptx/vectorizeElement.js +118 -0
  40. package/dist/export/pptx/writePptx.d.ts +13 -0
  41. package/dist/export/pptx/writePptx.js +17 -0
  42. package/dist/export/printPdf.d.ts +1 -0
  43. package/dist/export/printPdf.js +1 -1
  44. package/dist/export/scene/browserDeps.d.ts +32 -0
  45. package/dist/export/scene/browserDeps.js +174 -0
  46. package/dist/export/scene/imageBytes.d.ts +79 -0
  47. package/dist/export/scene/imageBytes.js +330 -0
  48. package/dist/export/scene/itemBounds.d.ts +9 -0
  49. package/dist/export/scene/itemBounds.js +40 -0
  50. package/dist/export/scene/matrix.d.ts +13 -0
  51. package/dist/export/scene/matrix.js +32 -0
  52. package/dist/export/scene/rasterLimit.d.ts +13 -0
  53. package/dist/export/scene/rasterLimit.js +24 -0
  54. package/dist/export/scene/rebaseOps.d.ts +8 -0
  55. package/dist/export/scene/rebaseOps.js +51 -0
  56. package/dist/export/scene/recordPageScene.d.ts +28 -0
  57. package/dist/export/scene/recordPageScene.js +224 -0
  58. package/dist/export/scene/recordingCanvas.d.ts +55 -0
  59. package/dist/export/scene/recordingCanvas.js +71 -0
  60. package/dist/export/scene/recordingContext.d.ts +162 -0
  61. package/dist/export/scene/recordingContext.js +1031 -0
  62. package/dist/export/scene/replayScene.d.ts +31 -0
  63. package/dist/export/scene/replayScene.js +213 -0
  64. package/dist/export/scene/resolveScene.d.ts +48 -0
  65. package/dist/export/scene/resolveScene.js +236 -0
  66. package/dist/export/scene/trustedSvgImages.d.ts +3 -0
  67. package/dist/export/scene/trustedSvgImages.js +21 -0
  68. package/dist/export/scene/types.d.ts +241 -0
  69. package/dist/export/scene/types.js +38 -0
  70. package/dist/export/slidesPdf.d.ts +10 -2
  71. package/dist/export/slidesPdf.js +8 -4
  72. package/dist/export/svg/__fixtures__/barChart.svg +1 -0
  73. package/dist/export/svg/__golden__/fixture-editable.svg +87 -0
  74. package/dist/export/svg/__golden__/fixture-outlines.svg +88 -0
  75. package/dist/export/svg/inlineSvg.d.ts +10 -0
  76. package/dist/export/svg/inlineSvg.js +119 -0
  77. package/dist/export/svg/scopeCss.d.ts +45 -0
  78. package/dist/export/svg/scopeCss.js +214 -0
  79. package/dist/export/svg/svgColor.d.ts +8 -0
  80. package/dist/export/svg/svgColor.js +46 -0
  81. package/dist/export/svg/svgImageScene.d.ts +41 -0
  82. package/dist/export/svg/svgImageScene.js +128 -0
  83. package/dist/export/svg/svgPathData.d.ts +31 -0
  84. package/dist/export/svg/svgPathData.js +466 -0
  85. package/dist/export/svg/svgToScene.d.ts +19 -0
  86. package/dist/export/svg/svgToScene.js +1183 -0
  87. package/dist/export/svg/writeSvg.d.ts +33 -0
  88. package/dist/export/svg/writeSvg.js +594 -0
  89. package/dist/export/svg/xml.d.ts +23 -0
  90. package/dist/export/svg/xml.js +49 -0
  91. package/dist/export/vectorDeps.d.ts +27 -0
  92. package/dist/export/vectorDeps.js +37 -0
  93. package/dist/export/vectorExport.d.ts +85 -0
  94. package/dist/export/vectorExport.js +287 -0
  95. package/dist/hostServices.d.ts +15 -0
  96. package/dist/i18n/de.d.ts +26 -9
  97. package/dist/i18n/de.js +26 -10
  98. package/dist/i18n/en.js +24 -0
  99. package/dist/primitives/AssetPrimitive.js +7 -2
  100. package/dist/primitives/CanvasIcons.js +6 -0
  101. package/dist/primitives/CanvasStage.js +2 -2
  102. package/dist/primitives/ChartPrimitive.d.ts +11 -1
  103. package/dist/primitives/ChartPrimitive.js +73 -19
  104. package/dist/primitives/IconPrimitive.js +3 -0
  105. package/dist/primitives/IllustrationPrimitive.js +14 -1
  106. package/dist/primitives/chartFont.d.ts +30 -0
  107. package/dist/primitives/chartFont.js +127 -0
  108. package/dist/sidebar/sections/ImageAdjustSection.js +5 -4
  109. package/dist/sidebar/sections/assets/ElementsPanel.js +4 -2
  110. package/dist/sidebar/sections/assets/assetAudience.d.ts +12 -0
  111. package/dist/sidebar/sections/assets/assetAudience.js +18 -0
  112. package/dist/sidebar/sections/assets/useElementCatalog.js +3 -2
  113. package/dist/stores/createCanvasEditorStore.d.ts +5 -2
  114. package/dist/stores/createCanvasEditorStore.js +9 -5
  115. package/dist/styles/compiled.css +1 -1
  116. package/dist/utils/canvasAssets.d.ts +11 -1
  117. package/dist/utils/canvasAssets.js +8 -0
  118. package/dist/utils/canvasIcons.js +5 -3
  119. package/dist/utils/captureStage.d.ts +19 -0
  120. package/dist/utils/captureStage.js +14 -1
  121. package/dist/utils/externalIcons.d.ts +7 -0
  122. package/dist/utils/externalIcons.js +70 -3
  123. package/dist/utils/illustrations/svgCache.js +6 -1
  124. package/dist/utils/imageFilters.d.ts +13 -0
  125. package/dist/utils/imageFilters.js +11 -0
  126. package/dist/utils/rebaseHistoryState.d.ts +9 -0
  127. package/dist/utils/rebaseHistoryState.js +26 -0
  128. package/dist/utils/zipPageImages.d.ts +8 -0
  129. package/dist/utils/zipPageImages.js +16 -4
  130. package/package.json +6 -2
  131. package/skills/ggraphic-embed/SKILL.md +33 -1
@@ -1,4 +1,4 @@
1
- import type { CanvasCarouselService, CanvasIconSearchService, CanvasFeedbackService, CanvasFileDeliveryService, CanvasImageShareService, CanvasImageUrlService, CanvasMediaLibraryService, CanvasPrintService, UseCanvasAssetLibrary, UseCanvasUnsplashSearch } from './hostServices.js';
1
+ import type { CanvasCarouselService, CanvasExportFontService, CanvasIconSearchService, CanvasFeedbackService, CanvasFileDeliveryService, CanvasImageShareService, CanvasImageUrlService, CanvasMediaLibraryService, CanvasPrintService, UseCanvasAssetLibrary, UseCanvasUnsplashSearch } from './hostServices.js';
2
2
  import type { ApplyResult, HostCanvasAiOperation, HostCanvasAiSnapshot } from './ai/types.js';
3
3
  import type { StockImage } from './common/imageSourceTypes.js';
4
4
  import type { AltTextPage, CanvasSpecEditBridge } from './editorSeamTypes.js';
@@ -184,6 +184,11 @@ export interface CanvasEditorServices extends CanvasEditorHostServices {
184
184
  * omitted, no format carries an impressum; the PDF export still works.
185
185
  */
186
186
  print?: CanvasPrintService;
187
+ /**
188
+ * The font files of the vector export (`CanvasExportFontService` in `hostServices.ts`). When
189
+ * omitted, the export reads the brand pack's font faces and the page's `@font-face` rules.
190
+ */
191
+ exportFonts?: CanvasExportFontService;
187
192
  /**
188
193
  * Where the host's feedback form opens from. When omitted, or while
189
194
  * `canRequest()` is false, the share menu offers no „Feedback" entry.
@@ -2,5 +2,5 @@ import * as Y from 'yjs';
2
2
  export declare function useYjsPageStateSync(options: {
3
3
  pageYMap: Y.Map<unknown> | null;
4
4
  isSynced: boolean;
5
- onRemoteState: (partial: Record<string, unknown>, base: Record<string, unknown>) => void;
5
+ onRemoteState: (partial: Record<string, unknown>, base: Record<string, unknown>, own: boolean) => void;
6
6
  }): void;
@@ -28,7 +28,10 @@ import { PAGES_STATE_ORIGIN } from './useYjsPages.js';
28
28
  *
29
29
  * Own writes with another origin (a deck op, a deck undo's restore, a version
30
30
  * lift) reach the canvas like remote ones: another stack owns them or they
31
- * are not undoable, so the canvas history takes them in.
31
+ * are not undoable, so the canvas history takes them in. They are reported
32
+ * with `own: true` (a local Yjs transaction): the history takes them in only
33
+ * where it still holds the value they replaced, so undoing a deck op leaves
34
+ * the steps before it undoable.
32
35
  */
33
36
  /** Own values kept per key, to name the one a remote write started from. */
34
37
  const OWN_VALUES_PER_KEY = 32;
@@ -109,7 +112,7 @@ export function useYjsPageStateSync(options) {
109
112
  }
110
113
  }
111
114
  if (Object.keys(partial).length > 0)
112
- onRemoteStateRef.current(partial, base);
115
+ onRemoteStateRef.current(partial, base, events[0].transaction.local);
113
116
  };
114
117
  pageYMap.observeDeep(handler);
115
118
  return () => {
@@ -27,11 +27,13 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
27
27
  * - usePageUndoRedoShortcuts — Cmd/Ctrl+Z page-array history
28
28
  * - useToolbarHandlers — bundled toolbar actions for the active page
29
29
  */
30
+ import { activeBrand } from '../../brand/brandRegistry.js';
30
31
  import { DocumentBrandContext } from '../../brand/documentBrand.js';
31
32
  import { useCanvasEditorServices } from '../../CanvasEditorProvider.js';
32
33
  import { messages, useMessages } from '../../i18n/messages.js';
33
34
  import { provideCoreSidebar } from '../../sidebar/coreSidebar.js';
34
35
  import { CORE_SIDEBAR_PARTS } from '../../sidebar/coreSidebarParts.js';
36
+ import { DocumentAudienceContext } from '../../sidebar/sections/assets/assetAudience.js';
35
37
  import { usePreloadSections } from '../../sidebar/sections/usePreloadSections.js';
36
38
  import { pagePersistedStateKeys } from '../../collab/pageElementStateKeys.js';
37
39
  import { serializeDeck } from '../../collab/pagesDoc.js';
@@ -54,6 +56,8 @@ import { useCallback, useImperativeHandle, useRef, useMemo, useEffect, useState,
54
56
  import { shareImageText } from '../../configs/shareSection.js';
55
57
  import { exportPptxDeck } from '../../export/pptx/exportPptxDeck.js';
56
58
  import { exportPrintPdf, lowResolutionWarnings, PRINT_JPEG_QUALITY, printPdfFilename, } from '../../export/printExport.js';
59
+ import { createVectorDeps } from '../../export/vectorDeps.js';
60
+ import { exportPagesPdf, exportPagesSvg, } from '../../export/vectorExport.js';
57
61
  import { exportSlidesPdf } from '../../export/slidesPdf.js';
58
62
  import { EditorBoxProvider } from '../../hooks/editorBox.js';
59
63
  import { StageFitProvider, useMeasuredStageFit } from '../../hooks/stageFit.js';
@@ -142,7 +146,11 @@ function CanvasEditorInner({ initialConfigId, formatId, documentTitle, initialPr
142
146
  });
143
147
  // Store loaded configs for rendering
144
148
  const loadedConfigs = useLoadedConfigs({ pages, getConfigForPage });
145
- const { tabs: editorTabs = NO_EDITOR_TABS, Provider: ShellProvider = NoShellProvider, pagePicker, pageCallbackKeys = NO_CALLBACK_KEYS, deckLocale: deckLocaleOf = DEFAULT_DECK_LOCALE, } = registeredEditorShell();
149
+ const shellExtensions = registeredEditorShell();
150
+ const { tabs: editorTabs = NO_EDITOR_TABS, Provider: ShellProvider = NoShellProvider, pagePicker, pageCallbackKeys = NO_CALLBACK_KEYS, deckLocale: deckLocaleOf = DEFAULT_DECK_LOCALE, } = shellExtensions;
151
+ // Only a host that registered `documentAudience` names the document's audience;
152
+ // without one the Elemente tab keeps following the user's locale.
153
+ const documentAudience = shellExtensions.documentAudience?.(pages) ?? null;
146
154
  // Template-field callbacks dual-write into the page's `state` map so other
147
155
  // clients (useYjsPageStateSync), page duplication and reloads see the
148
156
  // edits. Wrappers are identity-stable per page id and resolve the host
@@ -408,6 +416,16 @@ function CanvasEditorInner({ initialConfigId, formatId, documentTitle, initialPr
408
416
  return null;
409
417
  return await ref.current.captureCanvas(options);
410
418
  }, [currentPageIndex, canvasRefsRef]);
419
+ // One brand per deck: its pages share a country. Without one, the active brand's.
420
+ const brandOfDeck = useCallback((deck) => (deck[0] ? loadedConfigs.get(deck[0].configId)?.brand : undefined) ?? activeBrand(), [loadedConfigs]);
421
+ // What the SVG and the PDF export need of the editor: every page needs its mounted stage, like
422
+ // the PPTX export.
423
+ const vectorDeps = useCallback((format, brand) => createVectorDeps({
424
+ canvasOf: (index) => canvasRefsRef.current[index]?.current,
425
+ exportFonts: services.exportFonts,
426
+ brand,
427
+ format,
428
+ }), [canvasRefsRef, services.exportFonts]);
411
429
  // Wie capturePages: jede Seite braucht ihr gemountetes Stage, sonst bricht der Export ab.
412
430
  const buildPptx = useCallback(async (onProgress) => {
413
431
  await ensureFontsReady();
@@ -418,15 +436,99 @@ function CanvasEditorInner({ initialConfigId, formatId, documentTitle, initialPr
418
436
  }
419
437
  // One brand per deck: its pages share a country.
420
438
  const brand = deck[0] ? loadedConfigs.get(deck[0].configId)?.brand : undefined;
439
+ const format = getCanvasFormatOrDefault(formatId);
421
440
  return exportPptxDeck({
422
441
  pages: deck.map((page) => page.state),
423
- format: getCanvasFormatOrDefault(formatId),
442
+ format,
424
443
  rasterizeElement: async (slideIndex, elementId) => (await refs[slideIndex]?.current?.rasterizeElement(elementId)) ?? null,
444
+ // What the PNG rasters of shapes, icons and frames can be as SVG instead.
445
+ vector: vectorDeps(format, brandOfDeck(deck)),
425
446
  ...(documentTitle ? { title: documentTitle } : {}),
426
447
  ...(brand ? { brand } : {}),
427
448
  ...(onProgress ? { onProgress } : {}),
428
449
  });
429
- }, [pagesDoc, canvasRefsRef, formatId, documentTitle, loadedConfigs]);
450
+ }, [pagesDoc, canvasRefsRef, formatId, documentTitle, loadedConfigs, brandOfDeck, vectorDeps]);
451
+ // SVG: the file is named after the document the way the PDF is; a digital document without a
452
+ // title is named after the host.
453
+ const exportSvg = useCallback(async ({ pages: which, text, transparent = false, }) => {
454
+ const refs = canvasRefsRef.current;
455
+ const deck = serializeDeck(pagesDoc);
456
+ const indexes = which === 'all' ? deck.map((_, i) => i) : [currentPageIndex];
457
+ if (indexes.some((i) => !refs[i]?.current)) {
458
+ throw new Error(messages().errors.exportPagesPartial);
459
+ }
460
+ const format = getCanvasFormatOrDefault(formatId);
461
+ const brand = brandOfDeck(deck);
462
+ const title = documentTitle ??
463
+ (isSlideFormat(format) ? messages().defaults.presentationTitle : filenamePrefix);
464
+ return exportPagesSvg(indexes, {
465
+ text,
466
+ transparent,
467
+ filenameBase: printPdfFilename(title, filenamePrefix).replace(/\.pdf$/, ''),
468
+ }, vectorDeps(format, brand));
469
+ }, [
470
+ canvasRefsRef,
471
+ currentPageIndex,
472
+ formatId,
473
+ pagesDoc,
474
+ brandOfDeck,
475
+ documentTitle,
476
+ filenamePrefix,
477
+ vectorDeps,
478
+ ]);
479
+ // Print: one PDF page per editor page, in page order.
480
+ const printPages = useCallback(() => {
481
+ const refs = canvasRefsRef.current;
482
+ return refs.map((ref) => ({
483
+ captureTile: async (tile, pixelRatio) => (await ref.current?.capturePrintTile(tile, pixelRatio, PRINT_JPEG_QUALITY)) ?? null,
484
+ getImages: () => ref.current?.getPrintImages() ?? [],
485
+ }));
486
+ }, [canvasRefsRef]);
487
+ const printFormat = useMemo(() => {
488
+ const f = getCanvasFormatOrDefault(formatId);
489
+ return isPrintFormat(f) ? f : null;
490
+ }, [formatId]);
491
+ // PDF: every page, vector, in the mode of the format. If that cannot be made, the PDF of page
492
+ // pictures this replaces is (print: JPEG tiles with crop marks; slides and digital: PNGs).
493
+ const exportPdf = useCallback(async () => {
494
+ const refs = canvasRefsRef.current;
495
+ const deck = serializeDeck(pagesDoc);
496
+ if (deck.some((_, i) => !refs[i]?.current)) {
497
+ throw new Error(messages().errors.exportPagesPartial);
498
+ }
499
+ await ensureFontsReady();
500
+ const format = getCanvasFormatOrDefault(formatId);
501
+ const mode = isPrintFormat(format) ? 'print' : isSlideFormat(format) ? 'slides' : 'digital';
502
+ const brand = brandOfDeck(deck);
503
+ // A print file without a title is named for print; the others as the SVG is.
504
+ const title = mode === 'print'
505
+ ? (documentTitle ?? null)
506
+ : (documentTitle ??
507
+ (mode === 'slides' ? messages().defaults.presentationTitle : filenamePrefix));
508
+ const rasterFallback = async () => {
509
+ if (isPrintFormat(format))
510
+ return exportPrintPdf({ format, pages: printPages() });
511
+ const images = await exportAllPages({ pixelRatio: SLIDES_PDF_PIXEL_RATIO });
512
+ return exportSlidesPdf(images, mode === 'slides' ? undefined : { width: format.width, height: format.height });
513
+ };
514
+ return exportPagesPdf({
515
+ mode,
516
+ format,
517
+ brand,
518
+ filenameBase: printPdfFilename(title, filenamePrefix).replace(/\.pdf$/, ''),
519
+ pageCount: deck.length,
520
+ }, { ...vectorDeps(format, brand), rasterFallback });
521
+ }, [
522
+ canvasRefsRef,
523
+ pagesDoc,
524
+ formatId,
525
+ brandOfDeck,
526
+ documentTitle,
527
+ filenamePrefix,
528
+ printPages,
529
+ exportAllPages,
530
+ vectorDeps,
531
+ ]);
430
532
  // The host's callback at call time: it may pass a new function every render.
431
533
  const onPagesChangeRef = useRef(onPagesChange);
432
534
  onPagesChangeRef.current = onPagesChange;
@@ -448,10 +550,20 @@ function CanvasEditorInner({ initialConfigId, formatId, documentTitle, initialPr
448
550
  return exportAllPages({ pixelRatio });
449
551
  },
450
552
  exportPptx: () => buildPptx(),
553
+ exportSvg,
554
+ exportPdf,
451
555
  getPages: () => serializeDeck(pagesDoc).map(({ configId, state }) => ({ configId, state })),
452
556
  undo: toolbarHandlers.undo,
453
557
  redo: toolbarHandlers.redo,
454
- }), [handleCaptureCanvas, exportAllPages, buildPptx, pagesDoc, toolbarHandlers]);
558
+ }), [
559
+ handleCaptureCanvas,
560
+ exportAllPages,
561
+ buildPptx,
562
+ exportSvg,
563
+ exportPdf,
564
+ pagesDoc,
565
+ toolbarHandlers,
566
+ ]);
455
567
  const handleCaptureCanvasForAi = useCallback(async () => {
456
568
  const ref = canvasRefsRef.current[currentPageIndex];
457
569
  if (!ref?.current)
@@ -662,42 +774,23 @@ function CanvasEditorInner({ initialConfigId, formatId, documentTitle, initialPr
662
774
  observedPagesRef.current = next;
663
775
  startTransition(() => setObservedPages(next));
664
776
  }, []);
665
- // Print: one PDF page per editor page, in page order.
666
- const printPages = useCallback(() => {
667
- const refs = canvasRefsRef.current;
668
- return refs.map((ref) => ({
669
- captureTile: async (tile, pixelRatio) => (await ref.current?.capturePrintTile(tile, pixelRatio, PRINT_JPEG_QUALITY)) ?? null,
670
- getImages: () => ref.current?.getPrintImages() ?? [],
671
- }));
672
- }, [canvasRefsRef]);
673
- const printFormat = useMemo(() => {
674
- const f = getCanvasFormatOrDefault(formatId);
675
- return isPrintFormat(f) ? f : null;
676
- }, [formatId]);
777
+ // The report tells the download view what is a picture in the PDF, and whether all of it is.
677
778
  const handleDownloadPdf = useCallback(async () => {
678
- if (!printFormat)
679
- return;
680
- const pages = printPages();
681
- if (pages.some((_, i) => !canvasRefsRef.current[i]?.current)) {
682
- throw new Error(messages().errors.exportPagesPartial);
683
- }
684
- const pdf = await exportPrintPdf({ format: printFormat, pages });
685
- const blob = new Blob([pdf], { type: 'application/pdf' });
686
- await fileDelivery.downloadBlob(blob, printPdfFilename(documentTitle ?? null, filenamePrefix));
687
- }, [printFormat, printPages, canvasRefsRef, documentTitle, fileDelivery, filenamePrefix]);
779
+ const { blob, filename, report } = await exportPdf();
780
+ await fileDelivery.downloadBlob(blob, filename);
781
+ return report;
782
+ }, [exportPdf, fileDelivery]);
688
783
  const isSlideDeck = useMemo(() => isSlideFormat(getCanvasFormatOrDefault(formatId)), [formatId]);
689
784
  const handleDownloadPptx = useCallback(async (onProgress) => {
690
785
  const blob = await buildPptx(onProgress);
691
786
  const filename = printPdfFilename(documentTitle ?? messages().defaults.presentationTitle, filenamePrefix).replace(/\.pdf$/, '.pptx');
692
787
  await fileDelivery.downloadBlob(blob, filename);
693
788
  }, [buildPptx, documentTitle, fileDelivery, filenamePrefix]);
694
- const handleDownloadSlidesPdf = useCallback(async () => {
695
- await ensureFontsReady();
696
- const images = await exportAllPages({ pixelRatio: SLIDES_PDF_PIXEL_RATIO });
697
- const pdf = await exportSlidesPdf(images);
698
- const blob = new Blob([pdf], { type: 'application/pdf' });
699
- await fileDelivery.downloadBlob(blob, printPdfFilename(documentTitle ?? messages().defaults.presentationTitle, filenamePrefix));
700
- }, [exportAllPages, documentTitle, fileDelivery, filenamePrefix]);
789
+ const handleDownloadSvg = useCallback(async (options) => {
790
+ const { blob, filename, report } = await exportSvg(options);
791
+ await fileDelivery.downloadBlob(blob, filename);
792
+ return report;
793
+ }, [exportSvg, fileDelivery]);
701
794
  // Every poster page should carry a filled-in V.i.S.d.P. / Impressum, whichever
702
795
  // page is active; the download warns (never blocks) once every page has reported.
703
796
  const impressumGate = usePrintImpressumGate(printFormat, pages, observedPages);
@@ -911,11 +1004,12 @@ function CanvasEditorInner({ initialConfigId, formatId, documentTitle, initialPr
911
1004
  background: source.config.background?.(source.state, source.actions) ?? null,
912
1005
  chartColors: source.config.chartColors ?? source.config.brand?.chart,
913
1006
  });
914
- return (_jsx(Suspense, { fallback: sidebarLoadingFallback, children: _jsx(SectionComponent, { ...sectionProps }) }));
1007
+ return (_jsx(Suspense, { fallback: sidebarLoadingFallback, children: _jsx(DocumentAudienceContext.Provider, { value: documentAudience, children: _jsx(SectionComponent, { ...sectionProps }) }) }));
915
1008
  }, [
916
1009
  activeTab,
917
1010
  sectionSource,
918
1011
  activeConfig,
1012
+ documentAudience,
919
1013
  shareProps,
920
1014
  specEdit,
921
1015
  activeEditorTab,
@@ -988,16 +1082,25 @@ function CanvasEditorInner({ initialConfigId, formatId, documentTitle, initialPr
988
1082
  : null,
989
1083
  slideDeck: isSlideDeck
990
1084
  ? {
991
- onDownloadPdf: handleDownloadSlidesPdf,
1085
+ onDownloadPdf: handleDownloadPdf,
992
1086
  onDownloadPptx: handleDownloadPptx,
993
1087
  locale: deckLocale,
994
1088
  }
995
1089
  : null,
1090
+ vectorExport: {
1091
+ category: printFormat
1092
+ ? 'print'
1093
+ : isSlideDeck
1094
+ ? 'slides'
1095
+ : 'digital',
1096
+ onDownloadSvg: handleDownloadSvg,
1097
+ onDownloadPdf: handleDownloadPdf,
1098
+ },
996
1099
  }), [
997
1100
  getPhotoCredit,
998
1101
  isSlideDeck,
999
- handleDownloadSlidesPdf,
1000
1102
  handleDownloadPptx,
1103
+ handleDownloadSvg,
1001
1104
  deckLocale,
1002
1105
  printFormat,
1003
1106
  impressumGate,
@@ -2,6 +2,7 @@ import type { CanvasEditorServices, CanvasSpecEditBridge } from '../../CanvasEdi
2
2
  import type { GenericCanvasRef } from '../GenericCanvas.js';
3
3
  import type { PageInheritance } from '../../configs/pageInheritance.js';
4
4
  import type { HeterogeneousPage } from '../../configs/types.js';
5
+ import type { AssetAudience } from '../../utils/canvasAssets.js';
5
6
  import type { SidebarTab, SidebarTabId } from '../../sidebar/types.js';
6
7
  import type React from 'react';
7
8
  /** Lets the editor hand a tile dropped on a page (`isTemplateDrag`) to the open tab. */
@@ -97,6 +98,11 @@ export interface EditorShellExtensions {
97
98
  pageCallbackKeys?: (configId: string) => readonly string[];
98
99
  /** Whose house fonts a slide deck carries (the PowerPoint font hint). Default `de-DE`. */
99
100
  deckLocale?: (pages: readonly HeterogeneousPage[]) => 'de-DE' | 'de-AT';
101
+ /**
102
+ * Whose assets (logos, marks) the Elemente tab offers for this document; `null` = the
103
+ * user's locale. Default: the user's locale.
104
+ */
105
+ documentAudience?: (pages: readonly HeterogeneousPage[]) => AssetAudience | null;
100
106
  }
101
107
  /** The host's document tabs and provider; replaces the ones before. */
102
108
  export declare function registerEditorShell(extensions: EditorShellExtensions): void;
@@ -1,3 +1,4 @@
1
+ import type { ExportReport } from '../../export/scene/types.js';
1
2
  import type { SidebarTabId } from '../../sidebar/types.js';
2
3
  import type { GenericCanvasRef, ToolbarStateReport } from '../GenericCanvas.js';
3
4
  import type { FullCanvasConfig } from '../../configs/types.js';
@@ -139,6 +140,33 @@ export interface CanvasEditorExportApi {
139
140
  }) => Promise<string[]>;
140
141
  /** The deck as an editable .pptx; throws when a page cannot be rendered. */
141
142
  exportPptx: () => Promise<Blob>;
143
+ /**
144
+ * The page, or every page, as SVG: one page is the SVG itself, several are a ZIP of SVGs. Throws
145
+ * when a page cannot be rendered. The report says what could not stay vector and what is missing.
146
+ */
147
+ exportSvg: (options: {
148
+ pages: 'current' | 'all';
149
+ /** `outlines`: glyph outlines. `editable`: live `<text>`, which needs the font where it is opened. */
150
+ text: 'outlines' | 'editable';
151
+ /** No page background. */
152
+ transparent?: boolean;
153
+ }) => Promise<{
154
+ blob: Blob;
155
+ filename: string;
156
+ report: ExportReport;
157
+ }>;
158
+ /**
159
+ * Every page as one PDF, vector, in the mode that fits the format: print pages with bleed, trim
160
+ * and crop marks, slides at slide size, other pages at 1 px to the pt. Throws when a page cannot
161
+ * be rendered. The report says what could not stay vector and what is missing; when the
162
+ * document could not be made as vector at all, the PDF is made of page pictures and
163
+ * `report.fallback` says so.
164
+ */
165
+ exportPdf: () => Promise<{
166
+ blob: Blob;
167
+ filename: string;
168
+ report: ExportReport;
169
+ }>;
142
170
  /** The deck as a Vorlage stores it: config and state per page. */
143
171
  getPages: () => {
144
172
  configId: string;
@@ -18,6 +18,7 @@ import { rasterizeStageElement } from '../utils/captureStage.js';
18
18
  import type { CanvasMenuSnapshot } from './CanvasContextMenu/canvasMenuModel.js';
19
19
  import type { BaseCanvasState } from '../configs/factory/baseTypes.js';
20
20
  import type { FullCanvasConfig } from '../configs/types.js';
21
+ import type { RecordedScene } from '../export/scene/types.js';
21
22
  import type { OptionalCanvasActions } from '../hooks/useCanvasElementHandlers.js';
22
23
  import type { ShadowPatch } from '../hooks/useFloatingModuleHandlers.js';
23
24
  import type { FloatingModuleState } from '../hooks/useFloatingModuleState.js';
@@ -223,8 +224,24 @@ export interface GenericCanvasRef {
223
224
  captureCanvasForAi: () => Promise<string | null>;
224
225
  /** The page's visible texts in reading order, for alt texts. */
225
226
  getVisibleTexts: () => string[];
226
- /** One element alone as PNG plus its box in page px (PPTX raster fallback); null when not on the stage. */
227
- rasterizeElement: (elementId: string) => Promise<ReturnType<typeof rasterizeStageElement>>;
227
+ /**
228
+ * One element alone as PNG plus its box in page px (PPTX raster fallback); null when not on the
229
+ * stage. `pixelRatio` is per page px; default 2.
230
+ */
231
+ rasterizeElement: (elementId: string, pixelRatio?: number) => Promise<ReturnType<typeof rasterizeStageElement>>;
232
+ /**
233
+ * A PNG of the stage node `recordScene` kept as the `nodeRef` of a raster island, for an island
234
+ * whose item has no element id to look the node up by; null when it cannot be drawn.
235
+ */
236
+ rasterizeNode: (nodeRef: unknown, pixelRatio: number) => Promise<Uint8Array | null>;
237
+ /**
238
+ * This page as a scene for the vector export: one item per element, ops in page px. Waits for
239
+ * the fonts; null when there is no stage.
240
+ */
241
+ recordScene: (options: {
242
+ page: number;
243
+ transparent?: boolean;
244
+ }) => Promise<RecordedScene | null>;
228
245
  /** Clears this page's element selection — the per-page store lives behind
229
246
  * CanvasStoreProvider, so the parent editor reaches it through this handle. */
230
247
  deselect: () => void;
@@ -14,6 +14,8 @@ import { DocumentBrandContext } from '../brand/documentBrand.js';
14
14
  import { useEmitHostStateChanges } from '../collab/useEmitHostStateChanges.js';
15
15
  import { useYjsCanvasBinding } from '../collab/useYjsCanvasBinding.js';
16
16
  import { stateKeyOfCallback } from '../collab/wrapCallbacksWithPageSync.js';
17
+ import { pngFromDataUrl } from '../export/scene/imageBytes.js';
18
+ import { recordPageScene } from '../export/scene/recordPageScene.js';
17
19
  import { CropGhostOverlay } from './CropGhostOverlay.js';
18
20
  import { PrintGuides } from './PrintGuides.js';
19
21
  import { SlotBudgetStatus } from './SlotBudgetStatus.js';
@@ -53,7 +55,7 @@ import { createCanvasCommands, } from '../utils/canvasCommands.js';
53
55
  import { canvasFontFamilies } from '../utils/canvasFontFamilies.js';
54
56
  import { buildCanvasItems, buildSortedRenderList, insertedItemIds, withInsertsOnTop, } from '../utils/canvasLayerManager.js';
55
57
  import { addHostElement, fromHostKinds } from '../utils/elementKinds.js';
56
- import { captureStageImage, captureStageImageAsync, rasterizeStageElement, visibleStageTexts, } from '../utils/captureStage.js';
58
+ import { captureStageImage, captureStageImageAsync, rasterizeStageElement, rasterizeStageNode, visibleStageTexts, } from '../utils/captureStage.js';
57
59
  import { MAX_ICON_SELECTIONS, selectedCatalogIconIds } from '../utils/iconInstances.js';
58
60
  import { layerLabel, pageLayerLabels, stageSummary } from '../utils/layerLabels.js';
59
61
  import { findTemplateEntry } from '../utils/templateElementInstance.js';
@@ -165,11 +167,11 @@ function GenericCanvasWithRef(props) {
165
167
  // is measured from the values its writer started from, not from this
166
168
  // canvas: an own value not yet written, or one the write overrode, is no
167
169
  // part of the other client's edit.
168
- const handleRemotePageState = useCallback((partial, base) => {
170
+ const handleRemotePageState = useCallback((partial, base, own) => {
169
171
  const committed = committedStateRef.current;
170
172
  store
171
173
  .getState()
172
- .rebaseHistory(config.createInitialState({ ...committed, ...base }), config.createInitialState({ ...committed, ...partial }));
174
+ .rebaseHistory(config.createInitialState({ ...committed, ...base }), config.createInitialState({ ...committed, ...partial }), own);
173
175
  setStateRaw((prev) => config.createInitialState({ ...prev, ...partial }));
174
176
  setRemoteStateCount((n) => n + 1);
175
177
  }, [store, config]);
@@ -585,9 +587,31 @@ function GenericCanvasWithRef(props) {
585
587
  },
586
588
  captureCanvasForAi: async () => captureStageImage(stageRef.current, { format: 'jpeg', pixelRatio: 1, quality: 0.85 }),
587
589
  getVisibleTexts: () => visibleStageTexts(stageRef.current?.getStage() ?? null),
588
- rasterizeElement: async (elementId) => {
590
+ rasterizeElement: async (elementId, pixelRatio) => {
589
591
  await ensureFontsReady();
590
- return rasterizeStageElement(stageRef.current?.getStage() ?? null, elementId);
592
+ return rasterizeStageElement(stageRef.current?.getStage() ?? null, elementId, pixelRatio);
593
+ },
594
+ rasterizeNode: async (nodeRef, pixelRatio) => {
595
+ if (!(nodeRef instanceof Konva.Node))
596
+ return null;
597
+ const drawn = rasterizeStageNode(stageRef.current?.getStage() ?? null, nodeRef, pixelRatio);
598
+ return drawn ? pngFromDataUrl(drawn.dataUrl) : null;
599
+ },
600
+ recordScene: async ({ page, transparent }) => {
601
+ await ensureFontsReady();
602
+ const stage = stageRef.current?.getStage();
603
+ if (!stage)
604
+ return null;
605
+ // Read at call time, like the doors above: the page as it is on screen now.
606
+ const { sortedRenderList } = commandInputsRef.current;
607
+ const labels = new Map(sortedRenderList.map((item) => [item.id, layerLabel(item, committedStateRef.current)]));
608
+ return recordPageScene(stage, {
609
+ page,
610
+ // The format: the stage's own size is rounded to whole display px.
611
+ size: { width: stageWidth, height: stageHeight },
612
+ labels,
613
+ ...(transparent === undefined ? {} : { transparent }),
614
+ });
591
615
  },
592
616
  deselect: () => setSelectedElement(null),
593
617
  selectLayers: (change) => applyLayerSelection(store, change),
@@ -821,6 +845,7 @@ function GenericCanvasWithRef(props) {
821
845
  store,
822
846
  actions,
823
847
  stageWidth,
848
+ stageHeight,
824
849
  referenceWidth,
825
850
  referenceHeight,
826
851
  commands,
@@ -1,3 +1,4 @@
1
+ import { type GenericCanvasRef } from './GenericCanvas.js';
1
2
  import type { FullCanvasConfig } from '../configs/types.js';
2
3
  export interface PagePreviewProps {
3
4
  config: FullCanvasConfig;
@@ -8,7 +9,13 @@ export interface PagePreviewProps {
8
9
  onRendered: (dataUrl: string) => void;
9
10
  /** Called once instead, when the page could not be drawn or produced no image. */
10
11
  onFailed?: () => void;
12
+ /**
13
+ * Called once with the page's canvas handle when it has settled, just before the image is
14
+ * encoded; the handle stays valid while the preview is mounted. For a host that reads more than
15
+ * the PNG off the same stage (the render gate exports it as SVG and PDF).
16
+ */
17
+ onCanvas?: (canvas: GenericCanvasRef) => void;
11
18
  /** The page's format; absent: the default format. */
12
19
  formatId?: string;
13
20
  }
14
- export declare function PagePreview({ config, state, width, onRendered, onFailed, formatId, }: PagePreviewProps): import("react").JSX.Element;
21
+ export declare function PagePreview({ config, state, width, onRendered, onFailed, onCanvas, formatId, }: PagePreviewProps): import("react").JSX.Element;
@@ -18,12 +18,14 @@ import { GenericCanvas } from './GenericCanvas.js';
18
18
  const POLL_MS = 50;
19
19
  const SETTLE_TIMEOUT_MS = 8000;
20
20
  const noop = () => { };
21
- export function PagePreview({ config, state, width, onRendered, onFailed, formatId, }) {
21
+ export function PagePreview({ config, state, width, onRendered, onFailed, onCanvas, formatId, }) {
22
22
  const canvasRef = useRef(null);
23
23
  const onRenderedRef = useRef(onRendered);
24
24
  onRenderedRef.current = onRendered;
25
25
  const onFailedRef = useRef(onFailed);
26
26
  onFailedRef.current = onFailed;
27
+ const onCanvasRef = useRef(onCanvas);
28
+ onCanvasRef.current = onCanvas;
27
29
  const stageWidth = getCanvasFormatOrDefault(formatId).width;
28
30
  useEffect(() => {
29
31
  let cancelled = false;
@@ -35,6 +37,7 @@ export function PagePreview({ config, state, width, onRendered, onFailed, format
35
37
  if (!ref && late)
36
38
  return onFailedRef.current?.();
37
39
  if (ref && (ref.imagesSettled() || late)) {
40
+ onCanvasRef.current?.(ref);
38
41
  // Waits for the fonts, then encodes off the main thread: a gallery keeps scrolling.
39
42
  const dataUrl = await ref.captureCanvas({
40
43
  format: 'png',
@@ -1,8 +1,10 @@
1
1
  import type { CanvasImprintLocale, CanvasImprintParts } from '../../hostServices.js';
2
+ import type { ExportReport } from '../../export/scene/types.js';
2
3
  export type CanvasDownloadChoice = 'png' | 'jpeg' | 'webp';
3
4
  /** Print formats: PDF with bleed and crop marks is the default download. */
4
5
  export interface PrintExportProps {
5
- onDownloadPdf: () => Promise<void>;
6
+ /** Resolves with what could not stay vector and whether a raster PDF was made instead, if it knows. */
7
+ onDownloadPdf: () => Promise<ExportReport | void>;
6
8
  /** Notices for photos too small to print well. */
7
9
  getWarnings: () => string[];
8
10
  /** Posters only: warns (without blocking) while this is missing or a placeholder. */
@@ -13,13 +15,31 @@ export interface PrintExportProps {
13
15
  * mit allen Seiten, ohne Druckmarken.
14
16
  */
15
17
  export interface SlideDeckExportProps {
16
- onDownloadPdf: () => Promise<void>;
18
+ /** As `PrintExportProps.onDownloadPdf`. */
19
+ onDownloadPdf: () => Promise<ExportReport | void>;
17
20
  /** Meldet nach jeder geschriebenen Folie den Fortschritt. */
18
21
  onDownloadPptx: (onProgress: (done: number, total: number) => void) => Promise<void>;
19
22
  /** Welche Hausschriften das Deck trägt: deutsche oder österreichische Marke. */
20
23
  locale: DeckLocale;
21
24
  }
22
25
  type DeckLocale = 'de-DE' | 'de-AT';
26
+ /**
27
+ * SVG for every format, and the PDF of a digital format (a print format and a slide deck have
28
+ * theirs in `PrintExportProps` and `SlideDeckExportProps`). `category` decides what the SVG choice
29
+ * offers: only a digital format has a page background to leave out (a print page or a slide
30
+ * always has one).
31
+ */
32
+ export interface VectorExportProps {
33
+ category: 'print' | 'slides' | 'digital';
34
+ /** The PDF with every page. Resolves with what could not stay vector or is missing. */
35
+ onDownloadPdf: () => Promise<ExportReport>;
36
+ /** Resolves with what could not stay vector or is missing, which the section tells the person. */
37
+ onDownloadSvg: (options: {
38
+ pages: 'current' | 'all';
39
+ text: 'outlines' | 'editable';
40
+ transparent: boolean;
41
+ }) => Promise<ExportReport>;
42
+ }
23
43
  export interface PrintImpressumGate {
24
44
  /** False until every poster page has reported its state; no warning until then. */
25
45
  ready: boolean;
@@ -42,6 +62,7 @@ export interface DownloadSectionProps {
42
62
  exportNotice?: string | null;
43
63
  printExport?: PrintExportProps | null;
44
64
  slideDeck?: SlideDeckExportProps | null;
65
+ vectorExport?: VectorExportProps | null;
45
66
  }
46
- export declare function DownloadSection({ onDownload, onDownloadAllZip, pageCount, isMultiExporting, exportProgress, exportError, exportNotice, printExport, slideDeck, }: DownloadSectionProps): import("react").JSX.Element;
67
+ export declare function DownloadSection({ onDownload, onDownloadAllZip, pageCount, isMultiExporting, exportProgress, exportError, exportNotice, printExport, slideDeck, vectorExport, }: DownloadSectionProps): import("react").JSX.Element;
47
68
  export {};