@ggraphic/editor 0.0.0 → 0.1.0-alpha.1

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 (136) hide show
  1. package/README.md +16 -3
  2. package/THIRD_PARTY_NOTICES +25 -1
  3. package/dist/brand/brandRegistry.d.ts +11 -3
  4. package/dist/brand/brandRegistry.js +18 -3
  5. package/dist/brand/documentBrand.d.ts +16 -0
  6. package/dist/brand/documentBrand.js +6 -0
  7. package/dist/components/CanvasContextMenu/CanvasActionSheet.js +2 -1
  8. package/dist/components/CanvasContextMenu/CanvasContextMenu.js +3 -2
  9. package/dist/components/CanvasEditor/CanvasEditorShell.js +43 -34
  10. package/dist/components/CanvasTextOverlay.js +14 -5
  11. package/dist/components/CustomColorSwatch.js +3 -2
  12. package/dist/components/GenericCanvas.js +21 -5
  13. package/dist/components/RichTextField.js +6 -1
  14. package/dist/components/SelectionPill.js +2 -1
  15. package/dist/components/TextFormatButtons.js +12 -23
  16. package/dist/components/TopBar/ContextControls.js +4 -2
  17. package/dist/components/TopBar/modules/FloatingColorPicker.js +3 -1
  18. package/dist/components/TopBar/modules/FloatingFontRoleControl.js +2 -2
  19. package/dist/components/kindRenderers.d.ts +1 -1
  20. package/dist/components/markerMark.d.ts +6 -1
  21. package/dist/components/markerMark.js +7 -11
  22. package/dist/configs/factory/actionFactories.d.ts +38 -9
  23. package/dist/configs/factory/actionFactories.js +53 -36
  24. package/dist/configs/types.d.ts +13 -2
  25. package/dist/export/pptx/buildPptxModel.d.ts +3 -0
  26. package/dist/export/pptx/buildPptxModel.js +5 -5
  27. package/dist/export/pptx/exportPptxDeck.d.ts +4 -1
  28. package/dist/export/pptx/exportPptxDeck.js +5 -2
  29. package/dist/export/pptx/textModel.d.ts +6 -2
  30. package/dist/export/pptx/textModel.js +14 -11
  31. package/dist/hooks/useFloatingModuleHandlers.js +2 -2
  32. package/dist/hooks/useMultiPageExport.js +1 -1
  33. package/dist/i18n/de.d.ts +14 -0
  34. package/dist/i18n/de.js +14 -0
  35. package/dist/i18n/en.js +12 -0
  36. package/dist/page/actions.d.ts +66 -0
  37. package/dist/page/actions.js +353 -0
  38. package/dist/page/config.d.ts +15 -0
  39. package/dist/page/config.js +91 -0
  40. package/dist/page/fitting.d.ts +6 -0
  41. package/dist/page/fitting.js +26 -0
  42. package/dist/page/hug.d.ts +10 -0
  43. package/dist/page/hug.js +18 -0
  44. package/dist/page/instantiate.d.ts +8 -0
  45. package/dist/page/instantiate.js +30 -0
  46. package/dist/page/logoSize.d.ts +8 -0
  47. package/dist/page/logoSize.js +29 -0
  48. package/dist/page/pageState.d.ts +41 -0
  49. package/dist/page/pageState.js +59 -0
  50. package/dist/page/seeds.d.ts +14 -0
  51. package/dist/page/seeds.js +40 -0
  52. package/dist/page/slotBudgets.d.ts +22 -0
  53. package/dist/page/slotBudgets.js +18 -0
  54. package/dist/page/templatePack.d.ts +31 -0
  55. package/dist/page/templatePack.js +55 -0
  56. package/dist/page/typography.d.ts +11 -0
  57. package/dist/page/typography.js +13 -0
  58. package/dist/primitives/CanvasRichText.js +7 -4
  59. package/dist/primitives/CanvasStage.js +3 -2
  60. package/dist/primitives/UserImagePrimitive.js +3 -1
  61. package/dist/sidebar/sections/ChartSettingsSection.d.ts +1 -1
  62. package/dist/sidebar/sections/ChartSettingsSection.js +5 -2
  63. package/dist/sidebar/sections/CombinedTextSection.js +4 -3
  64. package/dist/sidebar/sections/DiagrammeSection.js +10 -11
  65. package/dist/sidebar/sections/FormenSection.d.ts +3 -1
  66. package/dist/sidebar/sections/FormenSection.js +25 -13
  67. package/dist/sidebar/sections/GenericShareSection.js +3 -2
  68. package/dist/sidebar/sections/IllustrationSettings.js +4 -3
  69. package/dist/sidebar/sections/ImageAdjustSection.js +6 -5
  70. package/dist/sidebar/sections/assets/ElementThumb.js +3 -1
  71. package/dist/sidebar/sections/assets/useElementCatalog.d.ts +2 -1
  72. package/dist/sidebar/sections/assets/useElementCatalog.js +30 -15
  73. package/dist/sidebar/sections/effects/GradientSettings.js +4 -2
  74. package/dist/sidebar/sections/effects/OutlineSettings.js +4 -3
  75. package/dist/sidebar/sections/effects/ShadowSettings.js +4 -3
  76. package/dist/sidebar/sections/tools/BlobCreatorTool.js +11 -6
  77. package/dist/sidebar/sections/tools/GradientTextTool.js +14 -12
  78. package/dist/sidebar/sections/tools/TextPathCreatorTool.js +15 -13
  79. package/dist/sidebar/sections/tools/ToolsSection.js +5 -3
  80. package/dist/styles/compiled.css +2 -0
  81. package/dist/testing/documentBrandConfig.d.ts +14 -0
  82. package/dist/testing/documentBrandConfig.js +60 -0
  83. package/dist/testing/documentBrandPacks.d.ts +10 -0
  84. package/dist/testing/documentBrandPacks.js +45 -0
  85. package/dist/ui/alert-dialog.js +3 -2
  86. package/dist/ui/button.d.ts +2 -2
  87. package/dist/ui/dialog.js +3 -2
  88. package/dist/ui/editorScope.d.ts +10 -0
  89. package/dist/ui/editorScope.js +9 -0
  90. package/dist/ui/popover.js +2 -1
  91. package/dist/ui/select.js +2 -1
  92. package/dist/utils/canvasAssets.d.ts +7 -1
  93. package/dist/utils/canvasLayerManager.d.ts +14 -0
  94. package/dist/utils/canvasLayerManager.js +24 -0
  95. package/dist/utils/circleBadgeUtils.d.ts +3 -1
  96. package/dist/utils/circleBadgeUtils.js +5 -5
  97. package/dist/utils/colorNames.d.ts +7 -2
  98. package/dist/utils/colorNames.js +14 -5
  99. package/dist/utils/fontMarkSupport.d.ts +11 -0
  100. package/dist/utils/fontMarkSupport.js +27 -5
  101. package/dist/utils/frameUtils.d.ts +3 -2
  102. package/dist/utils/frameUtils.js +3 -2
  103. package/dist/utils/illustrations/registry.d.ts +4 -1
  104. package/dist/utils/illustrations/registry.js +5 -3
  105. package/dist/utils/illustrations/svgCache.js +13 -6
  106. package/dist/utils/illustrations/types.d.ts +1 -1
  107. package/dist/utils/imageFilters.d.ts +4 -2
  108. package/dist/utils/imageFilters.js +3 -2
  109. package/dist/utils/imageLook.d.ts +4 -2
  110. package/dist/utils/imageLook.js +4 -2
  111. package/dist/utils/layerLabels.js +3 -6
  112. package/dist/utils/markerBoxes.d.ts +16 -1
  113. package/dist/utils/markerBoxes.js +2 -15
  114. package/dist/utils/markerColors.d.ts +12 -5
  115. package/dist/utils/markerColors.js +8 -15
  116. package/dist/utils/photoPlaceholder.d.ts +4 -1
  117. package/dist/utils/photoPlaceholder.js +5 -3
  118. package/dist/utils/pillBadgeUtils.d.ts +3 -2
  119. package/dist/utils/pillBadgeUtils.js +5 -5
  120. package/dist/utils/shapes.d.ts +4 -2
  121. package/dist/utils/shapes.js +4 -2
  122. package/dist/utils/textUtils.js +2 -10
  123. package/dist/utils/zipPageImages.d.ts +2 -1
  124. package/dist/utils/zipPageImages.js +3 -2
  125. package/package.json +14 -7
  126. package/skills/ggraphic-embed/SKILL.md +145 -0
  127. package/dist/components/MobileSelectionPill.d.ts +0 -40
  128. package/dist/components/MobileSelectionPill.js +0 -85
  129. package/dist/components/TopBar/modules/FloatingGradientControl.d.ts +0 -9
  130. package/dist/components/TopBar/modules/FloatingGradientControl.js +0 -35
  131. package/dist/components/TopBar/modules/FloatingOutlineControl.d.ts +0 -11
  132. package/dist/components/TopBar/modules/FloatingOutlineControl.js +0 -31
  133. package/dist/components/TopBar/modules/FloatingShadowControl.d.ts +0 -12
  134. package/dist/components/TopBar/modules/FloatingShadowControl.js +0 -40
  135. package/dist/utils/balkenUtils.d.ts +0 -22
  136. package/dist/utils/balkenUtils.js +0 -8
@@ -0,0 +1,15 @@
1
+ import { type FullCanvasConfig } from '@ggraphic/editor/configs/types';
2
+ import { type PageActions } from './actions.js';
3
+ import { type PageSeed, type PageState } from './pageState.js';
4
+ import { type TemplateLookup } from './slotBudgets.js';
5
+ export interface PageConfigOptions {
6
+ /** The config id the pages document stores. */
7
+ id: string;
8
+ /** The canvas format; the default format when unknown. */
9
+ formatId: string | undefined;
10
+ /** What a page that has never been saved starts with, on a `width` × `height` sheet. */
11
+ seedFor: (width: number, height: number) => PageSeed;
12
+ /** The host's catalogue, for the line limits of template slots. */
13
+ templateOf?: TemplateLookup;
14
+ }
15
+ export declare function createPageConfig({ id, formatId, seedFor, templateOf, }: PageConfigOptions): FullCanvasConfig<PageState, PageActions>;
@@ -0,0 +1,91 @@
1
+ // SPDX-License-Identifier: MPL-2.0
2
+ /**
3
+ * The one page config for templates as data: a colour ground and the editor's free elements, with
4
+ * the Text, Elements, Uploads and Tools tabs. Templates differ only in what a fresh page starts
5
+ * with (`seedFor`). The config lays out on the document's format, so one template serves every
6
+ * format.
7
+ */
8
+ import { activeBrand } from '@ggraphic/editor/brand/brandRegistry';
9
+ import { makeSectionDefiner } from '@ggraphic/editor/configs/factory/defineSection';
10
+ import { injectFeatureProps } from '@ggraphic/editor/configs/featureInjector';
11
+ import { getCanvasFormatOrDefault } from '@ggraphic/editor/formats/index';
12
+ import { messages } from '@ggraphic/editor/i18n/messages';
13
+ import { AssetsSection, CombinedTextSection, ToolsSection, UploadsSection, } from '@ggraphic/editor/sidebar/sections/index';
14
+ import { PiSquaresFour, PiTextAa, PiToolbox, PiUploadSimple } from 'react-icons/pi';
15
+ import { createPageActions } from './actions.js';
16
+ import { pageStateFrom } from './pageState.js';
17
+ import { noTemplates } from './slotBudgets.js';
18
+ const section = makeSectionDefiner();
19
+ // Read when the picker renders, so a project of another organisation offers its colours.
20
+ const backgroundColors = () => activeBrand().palette.map(({ id, label, color, ref }) => ({
21
+ id,
22
+ label,
23
+ color,
24
+ ...(ref && { ref }),
25
+ }));
26
+ export function createPageConfig({ id, formatId, seedFor, templateOf = noTemplates, }) {
27
+ const { width, height } = getCanvasFormatOrDefault(formatId);
28
+ const t = messages().pageTabs;
29
+ return {
30
+ id,
31
+ canvas: { width, height },
32
+ features: { icons: true, shapes: true, illustrations: true },
33
+ multiPage: { enabled: true, maxPages: 10, heterogeneous: true },
34
+ backgroundType: 'color',
35
+ fonts: { primary: activeBrand().fonts.headline, fontSize: 60, requireFontLoad: true },
36
+ tabs: [
37
+ { id: 'text', icon: PiTextAa, label: t.text, ariaLabel: t.textAriaLabel },
38
+ { id: 'elements', icon: PiSquaresFour, label: t.elements, ariaLabel: t.elementsAriaLabel },
39
+ { id: 'uploads', icon: PiUploadSimple, label: t.uploads, ariaLabel: t.uploadsAriaLabel },
40
+ { id: 'tools', icon: PiToolbox, label: t.tools, ariaLabel: t.toolsAriaLabel },
41
+ ],
42
+ sections: {
43
+ text: section({
44
+ component: CombinedTextSection,
45
+ propsFactory: (state, actions) => ({
46
+ additionalTexts: state.additionalTexts,
47
+ onAddHeader: actions.addHeader,
48
+ onAddSubheader: actions.addSubheader,
49
+ onAddText: actions.addText,
50
+ onUpdateText: actions.updateAdditionalText,
51
+ onRemoveText: actions.removeAdditionalText,
52
+ }),
53
+ }),
54
+ elements: section({
55
+ component: AssetsSection,
56
+ propsFactory: (state, actions, context) => ({
57
+ onAddAsset: actions.addAsset,
58
+ ...injectFeatureProps(state, actions, context),
59
+ }),
60
+ }),
61
+ uploads: section({
62
+ component: UploadsSection,
63
+ propsFactory: (_state, actions) => ({ onPlaceFromUrl: actions.addUserImageFromUrl }),
64
+ }),
65
+ tools: section({
66
+ component: ToolsSection,
67
+ propsFactory: (_state, actions) => ({ onPlaceImageUrl: actions.addUserImageFromUrl }),
68
+ }),
69
+ },
70
+ background: (state, actions) => ({
71
+ colors: backgroundColors(),
72
+ currentColor: state.backgroundColor,
73
+ onColorChange: actions.setBackgroundColor,
74
+ }),
75
+ elements: [
76
+ {
77
+ id: 'background',
78
+ type: 'background',
79
+ x: 0,
80
+ y: 0,
81
+ order: -1,
82
+ width,
83
+ height,
84
+ fillStateKey: 'backgroundColor',
85
+ },
86
+ ],
87
+ calculateLayout: () => ({}),
88
+ createInitialState: (props) => pageStateFrom(props, seedFor(width, height)),
89
+ createActions: (getState, setState, saveToHistory, debouncedSaveToHistory) => createPageActions(getState, setState, saveToHistory, debouncedSaveToHistory, width, height, templateOf),
90
+ };
91
+ }
@@ -0,0 +1,6 @@
1
+ import { type TemplateLookup } from './slotBudgets.js';
2
+ /**
3
+ * The size a text with a numeric `maxFontSize` fits at on `page` (a page of a template of `templateOf`
4
+ * takes its line limit from the slot of that name); null for a text without one, or one that cannot be fitted.
5
+ */
6
+ export declare function fittedFontSize(el: Readonly<Record<string, unknown>>, page: Readonly<Record<string, unknown>>, canvasHeight: number, templateOf: TemplateLookup): number | null;
@@ -0,0 +1,26 @@
1
+ // SPDX-License-Identifier: MPL-2.0
2
+ /**
3
+ * Text sizes fitted to the brand's fonts, up to the prototype's size (`maxFontSize`). The fit
4
+ * itself is the gate adapter's (`TEMPLATE_GATE_ADAPTER.fitText`, the width tables the gate
5
+ * measures with); this adds what a page knows beyond the element: the line limit of its
6
+ * template slot and the room down to the element below it.
7
+ */
8
+ import { roomBelow } from '@ggraphic/core';
9
+ import { TEMPLATE_GATE_ADAPTER } from '@ggraphic/editor/templates/templateGeometry';
10
+ import { slotBudgetFor } from './slotBudgets.js';
11
+ /**
12
+ * The size a text with a numeric `maxFontSize` fits at on `page` (a page of a template of `templateOf`
13
+ * takes its line limit from the slot of that name); null for a text without one, or one that cannot be fitted.
14
+ */
15
+ export function fittedFontSize(el, page, canvasHeight, templateOf) {
16
+ if (typeof el['maxFontSize'] !== 'number')
17
+ return null;
18
+ const maxLines = slotBudgetFor(page, String(el['id']), templateOf)?.budget.maxLines;
19
+ const maxHeight = roomBelow(page, 'additionalTexts', el, (k, e) => TEMPLATE_GATE_ADAPTER.box(k, e, 1));
20
+ const fit = TEMPLATE_GATE_ADAPTER.fitText?.(el, {
21
+ ...(maxLines === undefined ? {} : { maxLines }),
22
+ ...(maxHeight === undefined ? {} : { maxHeight }),
23
+ canvasHeight,
24
+ });
25
+ return fit ? fit.fontSize : null;
26
+ }
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Plates that hug their text (`hug` on a shape), kept in step with the text wherever a page
3
+ * changes a text's geometry after placing: a committed edit, a brand rebind, an AI fill.
4
+ * Placing and the gate hug through core; this is the page-level door for the rest.
5
+ */
6
+ import { type HugAdapter } from '@ggraphic/core';
7
+ /** The editor's measures for hugging; null parts of the gate adapter never occur in the editor. */
8
+ export declare const HUG_ADAPTER: HugAdapter;
9
+ /** `page` with every hugging plate brought to its text; the same object when none moves. */
10
+ export declare function withHuggedPlates<P extends Readonly<Record<string, unknown>>>(page: P): P;
@@ -0,0 +1,18 @@
1
+ // SPDX-License-Identifier: MPL-2.0
2
+ /**
3
+ * Plates that hug their text (`hug` on a shape), kept in step with the text wherever a page
4
+ * changes a text's geometry after placing: a committed edit, a brand rebind, an AI fill.
5
+ * Placing and the gate hug through core; this is the page-level door for the rest.
6
+ */
7
+ import { hugPlates } from '@ggraphic/core';
8
+ import { TEMPLATE_GATE_ADAPTER } from '@ggraphic/editor/templates/templateGeometry';
9
+ /** The editor's measures for hugging; null parts of the gate adapter never occur in the editor. */
10
+ export const HUG_ADAPTER = {
11
+ box: TEMPLATE_GATE_ADAPTER.box,
12
+ textExtent: TEMPLATE_GATE_ADAPTER.textExtent,
13
+ placeBox: TEMPLATE_GATE_ADAPTER.placeBox,
14
+ };
15
+ /** `page` with every hugging plate brought to its text; the same object when none moves. */
16
+ export function withHuggedPlates(page) {
17
+ return hugPlates(page, HUG_ADAPTER);
18
+ }
@@ -0,0 +1,8 @@
1
+ /** Places a template on a page: the one door from template data to page state. */
2
+ import { type BrandPack, type SchemeId } from '@ggraphic/core';
3
+ import { type TemplateFile, type TemplateFormat } from '@ggraphic/schema';
4
+ /** `template` placed on a `width` × `height` sheet of the given aspect; null when it cannot be placed. */
5
+ export declare function placeTemplate(template: TemplateFile, canvas: {
6
+ width: number;
7
+ height: number;
8
+ }, format: TemplateFormat | null, schemeId?: SchemeId | null, brand?: BrandPack): Record<string, unknown> | null;
@@ -0,0 +1,30 @@
1
+ // SPDX-License-Identifier: MPL-2.0
2
+ /** Places a template on a page: the one door from template data to page state. */
3
+ import { instantiateTemplatePage, } from '@ggraphic/core';
4
+ import { activeBrand } from '@ggraphic/editor/brand/brandRegistry';
5
+ import { TEMPLATE_GATE_ADAPTER, TEMPLATE_GEOMETRY, } from '@ggraphic/editor/templates/templateGeometry';
6
+ import { HUG_ADAPTER } from './hug.js';
7
+ import { logoSizeOf } from './logoSize.js';
8
+ import { fontFallbackFor } from './typography.js';
9
+ // A parsed template file is what placing takes; if the schema drifts from core's input, this stops compiling.
10
+ const _assert = {};
11
+ void _assert;
12
+ /** `template` placed on a `width` × `height` sheet of the given aspect; null when it cannot be placed. */
13
+ export function placeTemplate(template, canvas, format, schemeId = null, brand = activeBrand()) {
14
+ if (!format)
15
+ return null;
16
+ const result = instantiateTemplatePage(template, {
17
+ brand,
18
+ canvas,
19
+ format,
20
+ geometry: TEMPLATE_GEOMETRY,
21
+ locale: 'en',
22
+ fontFallback: fontFallbackFor,
23
+ fitText: TEMPLATE_GATE_ADAPTER.fitText,
24
+ boxOf: (key, el) => TEMPLATE_GATE_ADAPTER.box(key, el, 1),
25
+ hug: HUG_ADAPTER,
26
+ schemeId,
27
+ logoSizeOf,
28
+ });
29
+ return result.ok ? result.state : null;
30
+ }
@@ -0,0 +1,8 @@
1
+ export declare function rememberLogoSize(src: string, width: number, height: number): void;
2
+ /** The measured size, or null while unknown or when the image has no area. */
3
+ export declare function logoSizeOf(src: string): {
4
+ width: number;
5
+ height: number;
6
+ } | null;
7
+ /** Loads the image to learn its size; a logo that does not load stays unmeasured. */
8
+ export declare function measureLogo(src: string): Promise<void>;
@@ -0,0 +1,29 @@
1
+ // SPDX-License-Identifier: MPL-2.0
2
+ /**
3
+ * Natural sizes of brand logos. A template seed is built synchronously but needs the
4
+ * logo's proportions, so the host measures the image first (`measureLogo`, when it applies a
5
+ * brand) and placing reads it here.
6
+ */
7
+ const sizes = new Map();
8
+ export function rememberLogoSize(src, width, height) {
9
+ sizes.set(src, { width, height });
10
+ }
11
+ /** The measured size, or null while unknown or when the image has no area. */
12
+ export function logoSizeOf(src) {
13
+ const size = sizes.get(src);
14
+ return size && size.width > 0 && size.height > 0 ? size : null;
15
+ }
16
+ /** Loads the image to learn its size; a logo that does not load stays unmeasured. */
17
+ export function measureLogo(src) {
18
+ if (logoSizeOf(src) || typeof Image === 'undefined')
19
+ return Promise.resolve();
20
+ return new Promise((resolve) => {
21
+ const img = new Image();
22
+ img.onload = () => {
23
+ rememberLogoSize(src, img.naturalWidth, img.naturalHeight);
24
+ resolve();
25
+ };
26
+ img.onerror = () => resolve();
27
+ img.src = src;
28
+ });
29
+ }
@@ -0,0 +1,41 @@
1
+ /**
2
+ * The state of a free page: what a template seeds, what the editor stores and reads back. Every
3
+ * page of a host that offers templates as data (`createPageConfig`) has this shape.
4
+ */
5
+ import { type Bindings } from '@ggraphic/core';
6
+ import { type BaseCanvasState } from '@ggraphic/editor/configs/factory/baseTypes';
7
+ /** An element group on a page; the full semantics come with the groups feature. */
8
+ export interface PageGroup {
9
+ id: string;
10
+ blockRef?: {
11
+ id: string;
12
+ version: number;
13
+ };
14
+ elementIds: string[];
15
+ }
16
+ /**
17
+ * A free page: the editor's element collections plus a colour ground. Only
18
+ * keys the editor writes back into the pages document persist
19
+ * (`PAGE_PERSISTED_STATE_KEYS`): the collections, `backgroundColor` and the
20
+ * brand binding keys, `templateRef` and `groups`.
21
+ */
22
+ export interface PageState extends BaseCanvasState {
23
+ backgroundColor: string;
24
+ layerOrder: string[];
25
+ bind?: Bindings;
26
+ brandScheme?: string;
27
+ brandStamp?: string;
28
+ templateRef?: {
29
+ id: string;
30
+ version: number;
31
+ };
32
+ groups?: PageGroup[];
33
+ }
34
+ /** What a template puts on a fresh page. */
35
+ export type PageSeed = Partial<Pick<PageState, 'backgroundColor' | 'additionalTexts' | 'shapeInstances' | 'userImageInstances' | 'bind' | 'brandScheme' | 'brandStamp'>>;
36
+ /**
37
+ * The page state from what is stored (`props`). A page that has never been
38
+ * saved has no collections yet and gets the template's seed; a saved one keeps
39
+ * exactly what it holds, also when the user emptied it.
40
+ */
41
+ export declare function pageStateFrom(props: Record<string, unknown>, seed: PageSeed): PageState;
@@ -0,0 +1,59 @@
1
+ import { activeBrand } from '@ggraphic/editor/brand/brandRegistry';
2
+ import { carryInstanceState } from '@ggraphic/editor/configs/factory/carryInstanceState';
3
+ const isRef = (v) => typeof v === 'object' &&
4
+ v !== null &&
5
+ typeof v.id === 'string' &&
6
+ Number.isInteger(v.version) &&
7
+ v.version >= 1;
8
+ const isGroup = (v) => {
9
+ if (typeof v !== 'object' || v === null)
10
+ return false;
11
+ const g = v;
12
+ return (typeof g['id'] === 'string' &&
13
+ Array.isArray(g['elementIds']) &&
14
+ g['elementIds'].every((id) => typeof id === 'string') &&
15
+ (g['blockRef'] === undefined || isRef(g['blockRef'])));
16
+ };
17
+ /** The brand binding and template keys a page keeps across a re-seed (read back, never invented). */
18
+ function brandKeysFrom(props) {
19
+ const out = {};
20
+ const bind = props['bind'];
21
+ if (typeof bind === 'object' && bind !== null && !Array.isArray(bind)) {
22
+ out.bind = bind;
23
+ }
24
+ if (typeof props['brandScheme'] === 'string')
25
+ out.brandScheme = props['brandScheme'];
26
+ if (typeof props['brandStamp'] === 'string')
27
+ out.brandStamp = props['brandStamp'];
28
+ if (isRef(props['templateRef'])) {
29
+ out.templateRef = { id: props['templateRef'].id, version: props['templateRef'].version };
30
+ }
31
+ if (Array.isArray(props['groups']))
32
+ out.groups = props['groups'].filter(isGroup);
33
+ return out;
34
+ }
35
+ /**
36
+ * The page state from what is stored (`props`). A page that has never been
37
+ * saved has no collections yet and gets the template's seed; a saved one keeps
38
+ * exactly what it holds, also when the user emptied it.
39
+ */
40
+ export function pageStateFrom(props, seed) {
41
+ const stored = Array.isArray(props['additionalTexts']) || Array.isArray(props['shapeInstances']);
42
+ const seeded = stored ? props : { ...props, ...seed, layerOrder: seedLayerOrder(seed) };
43
+ const background = seeded['backgroundColor'];
44
+ return {
45
+ isDesktop: typeof window !== 'undefined' && window.innerWidth >= 900,
46
+ ...carryInstanceState(seeded),
47
+ backgroundColor: typeof background === 'string'
48
+ ? background
49
+ : (seed.backgroundColor ?? activeBrand().defaultBackground),
50
+ ...brandKeysFrom(seeded),
51
+ };
52
+ }
53
+ function seedLayerOrder(seed) {
54
+ return [
55
+ ...(seed.shapeInstances ?? []),
56
+ ...(seed.userImageInstances ?? []),
57
+ ...(seed.additionalTexts ?? []),
58
+ ].map((e) => e.id);
59
+ }
@@ -0,0 +1,14 @@
1
+ /** What a fresh page starts with: a template placed on the sheet, and that seed as stored state. */
2
+ import { type TemplateFile, type TemplateFormat } from '@ggraphic/schema';
3
+ import { type PageSeed } from './pageState.js';
4
+ /** The declared aspect closest to the sheet's. */
5
+ export declare function aspectOfSize(width: number, height: number): TemplateFormat;
6
+ /** The fresh page of `template` on a `width` × `height` sheet; empty without a template. */
7
+ export declare function seedFromTemplate(template: TemplateFile | null, width: number, height: number): PageSeed;
8
+ /**
9
+ * The seed as stored page state. A page the editor opens with (`initialPages`)
10
+ * goes into the pages document as given, and the editor writes back only what
11
+ * changes later: a document must therefore start with the seed spelled out,
12
+ * or the AI draft and the autosave would see an empty page.
13
+ */
14
+ export declare function storedPageSeed(seed: PageSeed): Record<string, unknown>;
@@ -0,0 +1,40 @@
1
+ import { placeTemplate } from './instantiate.js';
2
+ const ASPECTS = [
3
+ { format: '1:1', ratio: 1 },
4
+ { format: '4:5', ratio: 4 / 5 },
5
+ { format: '16:9', ratio: 16 / 9 },
6
+ ];
7
+ /** The declared aspect closest to the sheet's. */
8
+ export function aspectOfSize(width, height) {
9
+ const ratio = width / height;
10
+ return ASPECTS.reduce((best, a) => Math.abs(a.ratio - ratio) < Math.abs(best.ratio - ratio) ? a : best).format;
11
+ }
12
+ /** The fresh page of `template` on a `width` × `height` sheet; empty without a template. */
13
+ export function seedFromTemplate(template, width, height) {
14
+ if (!template)
15
+ return {};
16
+ // The nearest aspect is picked from all three, not from the template's: say so here instead of
17
+ // leaving it to the placer, so a template never lands on a sheet it did not declare.
18
+ const aspect = aspectOfSize(width, height);
19
+ if (!template.formats.includes(aspect))
20
+ return {};
21
+ return (placeTemplate(template, { width, height }, aspect) ?? {});
22
+ }
23
+ /**
24
+ * The seed as stored page state. A page the editor opens with (`initialPages`)
25
+ * goes into the pages document as given, and the editor writes back only what
26
+ * changes later: a document must therefore start with the seed spelled out,
27
+ * or the AI draft and the autosave would see an empty page.
28
+ */
29
+ export function storedPageSeed(seed) {
30
+ const shapes = seed.shapeInstances ?? [];
31
+ const texts = seed.additionalTexts ?? [];
32
+ const images = seed.userImageInstances ?? [];
33
+ return {
34
+ ...seed,
35
+ shapeInstances: shapes,
36
+ ...(images.length ? { userImageInstances: images } : {}),
37
+ additionalTexts: texts,
38
+ layerOrder: [...shapes, ...images, ...texts].map((e) => e.id),
39
+ };
40
+ }
@@ -0,0 +1,22 @@
1
+ /**
2
+ * The text budget of a template element, for the editor's status line
3
+ * (`CanvasEditorServices.slotBudgets`) and for fitting. A page made from a catalogue template
4
+ * carries `templateRef`; its elements keep the template's element ids, which
5
+ * are the keys of the template's `slots`.
6
+ */
7
+ import { type SlotBudget } from '@ggraphic/core';
8
+ import { type TemplateFile } from '@ggraphic/schema';
9
+ /** The host's catalogue: the template file of id `id`, or null when it has none of that id. */
10
+ export type TemplateLookup = (id: string) => TemplateFile | null;
11
+ /** A catalogue with no templates: pages that carry no `templateRef` need nothing more. */
12
+ export declare const noTemplates: TemplateLookup;
13
+ /**
14
+ * The budget and role of element `elementId` on a page in state `pageState`, or
15
+ * null for a page that is not from a template of `templateOf` and for an element that
16
+ * is not a slot. The template's current version applies, whatever version the
17
+ * page was made from.
18
+ */
19
+ export declare function slotBudgetFor(pageState: Readonly<Record<string, unknown>>, elementId: string, templateOf: TemplateLookup): {
20
+ budget: SlotBudget;
21
+ role: string;
22
+ } | null;
@@ -0,0 +1,18 @@
1
+ /** A catalogue with no templates: pages that carry no `templateRef` need nothing more. */
2
+ export const noTemplates = () => null;
3
+ /**
4
+ * The budget and role of element `elementId` on a page in state `pageState`, or
5
+ * null for a page that is not from a template of `templateOf` and for an element that
6
+ * is not a slot. The template's current version applies, whatever version the
7
+ * page was made from.
8
+ */
9
+ export function slotBudgetFor(pageState, elementId, templateOf) {
10
+ const ref = pageState['templateRef'];
11
+ if (typeof ref !== 'object' || ref === null)
12
+ return null;
13
+ const id = ref.id;
14
+ if (typeof id !== 'string')
15
+ return null;
16
+ const slot = templateOf(id)?.slots[elementId];
17
+ return slot ? { budget: slot.budget, role: slot.role } : null;
18
+ }
@@ -0,0 +1,31 @@
1
+ /**
2
+ * Templates as data: template files (the `@ggraphic/schema` format) become editor templates.
3
+ * Every template is a free page (`createPageConfig`) seeded with its file, so a host registers its
4
+ * pack with `registerTemplates(...pack.definitions)` and writes no config of its own.
5
+ */
6
+ import { type TemplateFile } from '@ggraphic/schema';
7
+ import { type FullCanvasConfig } from '../configs/types.js';
8
+ import { type TemplateDefinition } from '../templates/registry.js';
9
+ import { type PageActions } from './actions.js';
10
+ import { type PageState } from './pageState.js';
11
+ import { type TemplateLookup } from './slotBudgets.js';
12
+ /** A file of the pack that was not loaded, and why. */
13
+ export interface TemplatePackProblem {
14
+ id: string | null;
15
+ reason: string;
16
+ }
17
+ export interface TemplatePack {
18
+ /** The pack's templates, in file order; blocks are not pages and are left out. */
19
+ templates: TemplateFile[];
20
+ /** One editor template per entry of `templates`, under the template's id. */
21
+ definitions: TemplateDefinition<string, FullCanvasConfig<PageState, PageActions>>[];
22
+ /** The pack as a lookup, for slot budgets (`CanvasEditorServices.slotBudgets`). */
23
+ templateOf: TemplateLookup;
24
+ /** Files that do not read, are newer than this editor, or repeat an id. */
25
+ problems: TemplatePackProblem[];
26
+ }
27
+ /**
28
+ * The template files in `json` (an array of files, or one file) as a pack. A file that does not
29
+ * read is reported and skipped, never half-loaded; the first of a duplicate id wins.
30
+ */
31
+ export declare function templatePackFromJson(json: unknown): TemplatePack;
@@ -0,0 +1,55 @@
1
+ // SPDX-License-Identifier: MPL-2.0
2
+ /**
3
+ * Templates as data: template files (the `@ggraphic/schema` format) become editor templates.
4
+ * Every template is a free page (`createPageConfig`) seeded with its file, so a host registers its
5
+ * pack with `registerTemplates(...pack.definitions)` and writes no config of its own.
6
+ */
7
+ import { readTemplateFile } from '@ggraphic/schema';
8
+ import { defineTemplate } from '../templates/registry.js';
9
+ import { createPageConfig } from './config.js';
10
+ import { seedFromTemplate } from './seeds.js';
11
+ const idOf = (raw) => typeof raw === 'object' && raw !== null && typeof raw.id === 'string'
12
+ ? raw.id
13
+ : null;
14
+ /**
15
+ * The template files in `json` (an array of files, or one file) as a pack. A file that does not
16
+ * read is reported and skipped, never half-loaded; the first of a duplicate id wins.
17
+ */
18
+ export function templatePackFromJson(json) {
19
+ const files = Array.isArray(json) ? json : [json];
20
+ const templates = [];
21
+ const problems = [];
22
+ const byId = new Map();
23
+ const seen = new Set();
24
+ for (const raw of files) {
25
+ const read = readTemplateFile(raw);
26
+ if (read.status !== 'ok') {
27
+ const reason = read.status === 'invalid'
28
+ ? read.reason
29
+ : `written by a newer version (${read.scope} ${read.version})`;
30
+ problems.push({ id: idOf(raw), reason });
31
+ continue;
32
+ }
33
+ const template = read.template;
34
+ if (seen.has(template.id)) {
35
+ problems.push({ id: template.id, reason: 'duplicate id: the first one is kept' });
36
+ continue;
37
+ }
38
+ seen.add(template.id);
39
+ if (template.kind !== 'template')
40
+ continue;
41
+ byId.set(template.id, template);
42
+ templates.push(template);
43
+ }
44
+ const templateOf = (id) => byId.get(id) ?? null;
45
+ const definitions = templates.map((template) => defineTemplate({
46
+ id: template.id,
47
+ load: (formatId) => Promise.resolve(createPageConfig({
48
+ id: template.id,
49
+ formatId,
50
+ seedFor: (width, height) => seedFromTemplate(template, width, height),
51
+ templateOf,
52
+ })),
53
+ }));
54
+ return { templates, definitions, templateOf, problems };
55
+ }
@@ -0,0 +1,11 @@
1
+ import { type BrandFontRole } from '@ggraphic/core';
2
+ /** Font stacks of the active brand's headline, body and quote families. */
3
+ export declare const headlineFont: () => string;
4
+ export declare const bodyFont: () => string;
5
+ export declare const quoteFont: () => string;
6
+ /** The fallbacks behind a bound font role's family, the same as above. */
7
+ export declare const fontFallbackFor: (role: string) => "Georgia, serif" | "Arial, sans-serif";
8
+ /** The stack for a bound font role: the brand's family, then the same fallbacks as above. */
9
+ export declare const fontStackFor: (role: BrandFontRole, family: string) => string;
10
+ /** Type sizes are set for a 1080 px short side and follow the format from there. */
11
+ export declare const scaleFor: (width: number, height: number) => number;
@@ -0,0 +1,13 @@
1
+ import { activeBrand } from '@ggraphic/editor/brand/brandRegistry';
2
+ /** Font stacks of the active brand's headline, body and quote families. */
3
+ export const headlineFont = () => `${activeBrand().fonts.headline}, Arial, sans-serif`;
4
+ export const bodyFont = () => `${activeBrand().fonts.body}, Arial, sans-serif`;
5
+ export const quoteFont = () => `${activeBrand().fonts.quoteEmphasis}, Georgia, serif`;
6
+ /** The fallbacks behind a bound font role's family, the same as above. */
7
+ export const fontFallbackFor = (role) => role === 'quoteShort' || role === 'quoteEmphasis' || role === 'serif'
8
+ ? 'Georgia, serif'
9
+ : 'Arial, sans-serif';
10
+ /** The stack for a bound font role: the brand's family, then the same fallbacks as above. */
11
+ export const fontStackFor = (role, family) => `${family}, ${fontFallbackFor(role)}`;
12
+ /** Type sizes are set for a 1080 px short side and follow the format from there. */
13
+ export const scaleFor = (width, height) => Math.min(width, height) / 1080;
@@ -26,6 +26,7 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
26
26
  import { layoutRichTextBlock } from '@ggraphic/schema';
27
27
  import { useRef, useEffect, useCallback, useMemo, useState, Fragment } from 'react';
28
28
  import { Group, Rect, Text as KonvaText, Transformer } from 'react-konva';
29
+ import { useDocumentBrand } from '@ggraphic/editor/brand/documentBrand';
29
30
  import { LOCKED_TRANSFORMER, useIsItemLocked } from '@ggraphic/editor/components/canvasItemLock';
30
31
  import { overlayBoxForNode, useCanvasTextEditor, } from '@ggraphic/editor/components/CanvasTextOverlay';
31
32
  import { useFontGeneration } from '@ggraphic/editor/hooks/useFontGeneration';
@@ -79,14 +80,16 @@ export function CanvasRichText({ id, text, x, y, width, fontSize = 24, fontFamil
79
80
  : align === 'right'
80
81
  ? innerBoxWidth - lineWidths[index]
81
82
  : 0)), [lines, lineWidths, align, padding, innerBoxWidth]);
82
- // Ohne Markerstil der Vorlage bekommt ein `++`-Lauf den Standardkasten.
83
- const marker = templateMarker ?? defaultTextMarker();
83
+ // Ohne Markerstil der Vorlage bekommt ein `++`-Lauf den Standardkasten des Dokuments.
84
+ const brand = useDocumentBrand();
85
+ const marker = templateMarker ?? defaultTextMarker(brand);
84
86
  const boxes = useMemo(() => markerBoxes(lines, measure, marker, {
85
87
  fontSize,
86
88
  lineHeightPx,
87
89
  top: padding,
88
90
  originX,
89
- }), [marker, lines, measure, fontSize, lineHeightPx, padding, originX]);
91
+ brand,
92
+ }), [marker, lines, measure, fontSize, lineHeightPx, padding, originX, brand]);
90
93
  useEffect(() => {
91
94
  if (selected && trRef.current && groupRef.current && !isEditing) {
92
95
  trRef.current.nodes([groupRef.current]);
@@ -250,7 +253,7 @@ export function CanvasRichText({ id, text, x, y, width, fontSize = 24, fontFamil
250
253
  ? // Ink chosen for the box: no halo or outline of the photo text.
251
254
  {
252
255
  fill: run.accentColor ??
253
- (run.markerColor ? markerInkOn(run.markerColor) : marker.color),
256
+ (run.markerColor ? markerInkOn(run.markerColor, brand) : marker.color),
254
257
  lineJoin: 'round',
255
258
  }
256
259
  : {
@@ -10,7 +10,7 @@ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-run
10
10
  import Konva from 'konva';
11
11
  import { useRef, useState, useEffect, forwardRef, useImperativeHandle, useCallback, } from 'react';
12
12
  import { Stage, Layer, Group, Rect } from 'react-konva';
13
- import { activeBrand } from '@ggraphic/editor/brand/brandRegistry';
13
+ import { useDocumentBrand } from '@ggraphic/editor/brand/documentBrand';
14
14
  import { CanvasTextEditorProvider } from '@ggraphic/editor/components/CanvasTextOverlay';
15
15
  import { TransformHud } from '@ggraphic/editor/components/TransformHud';
16
16
  import { useHoverOutline } from '@ggraphic/editor/hooks/useHoverOutline';
@@ -91,6 +91,7 @@ function cancelTransforms(before) {
91
91
  }
92
92
  const exportMimeType = (options) => `image/${options.format || 'png'}`;
93
93
  export const CanvasStage = forwardRef(({ width, height, logicalWidth, logicalHeight, responsive = true, maxContainerWidth = 600, maxContainerHeight, onStageClick, listening = true, ariaLabel, children, overlay, className, style, }, ref) => {
94
+ const surface = useDocumentBrand().colors.surface;
94
95
  const displayStageRef = useRef(null);
95
96
  const containerDivRef = useRef(null);
96
97
  const [containerSize, setContainerSize] = useState({ width: 400, height: 400 });
@@ -286,6 +287,6 @@ export const CanvasStage = forwardRef(({ width, height, logicalWidth, logicalHei
286
287
  ...style,
287
288
  }, children: [_jsx(Stage, { ref: displayStageRef, width: containerSize.width, height: containerSize.height, scale: { x: displayScale, y: displayScale }, listening: listening, onMouseDown: onStageClick, onTouchStart: onStageClick, children: _jsx(Layer, { listening: listening, children: logicalWidth &&
288
289
  logicalHeight &&
289
- (logicalWidth !== width || logicalHeight !== height) ? (_jsxs(_Fragment, { children: [_jsx(Rect, { x: 0, y: 0, width: width, height: height, fill: activeBrand().colors.surface }), _jsx(Group, { scaleX: width / logicalWidth, scaleY: height / logicalHeight, children: children })] })) : (children) }) }), overlay, _jsx(TransformHud, { stageRef: displayStageRef, enabled: listening })] }) }));
290
+ (logicalWidth !== width || logicalHeight !== height) ? (_jsxs(_Fragment, { children: [_jsx(Rect, { x: 0, y: 0, width: width, height: height, fill: surface }), _jsx(Group, { scaleX: width / logicalWidth, scaleY: height / logicalHeight, children: children })] })) : (children) }) }), overlay, _jsx(TransformHud, { stageRef: displayStageRef, enabled: listening })] }) }));
290
291
  });
291
292
  CanvasStage.displayName = 'CanvasStage';