@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.
- package/dist/CanvasEditorProvider.d.ts +6 -1
- package/dist/collab/useYjsPageStateSync.d.ts +1 -1
- package/dist/collab/useYjsPageStateSync.js +5 -2
- package/dist/components/CanvasEditor/CanvasEditorShell.js +139 -36
- package/dist/components/CanvasEditor/editorShell.d.ts +6 -0
- package/dist/components/CanvasEditor/types.d.ts +28 -0
- package/dist/components/GenericCanvas.d.ts +19 -2
- package/dist/components/GenericCanvas.js +30 -5
- package/dist/components/PagePreview.d.ts +8 -1
- package/dist/components/PagePreview.js +4 -1
- package/dist/components/TopBar/DownloadSection.d.ts +24 -3
- package/dist/components/TopBar/DownloadSection.js +45 -7
- package/dist/components/TopBar/ShareDropdown.d.ts +4 -2
- package/dist/components/TopBar/ShareDropdown.js +2 -2
- package/dist/entries/export.d.ts +14 -1
- package/dist/entries/export.js +14 -1
- package/dist/entries/services.d.ts +1 -1
- package/dist/export/fonts/fontFiles.d.ts +100 -0
- package/dist/export/fonts/fontFiles.js +333 -0
- package/dist/export/fonts/glyphs.d.ts +113 -0
- package/dist/export/fonts/glyphs.js +120 -0
- package/dist/export/fonts/variation.d.ts +23 -0
- package/dist/export/fonts/variation.js +43 -0
- package/dist/export/pdf/pdfContent.d.ts +108 -0
- package/dist/export/pdf/pdfContent.js +566 -0
- package/dist/export/pdf/pdfFontkit.d.ts +54 -0
- package/dist/export/pdf/pdfFontkit.js +159 -0
- package/dist/export/pdf/pdfGeometry.d.ts +54 -0
- package/dist/export/pdf/pdfGeometry.js +228 -0
- package/dist/export/pdf/pdfResources.d.ts +109 -0
- package/dist/export/pdf/pdfResources.js +314 -0
- package/dist/export/pdf/writePdf.d.ts +34 -0
- package/dist/export/pdf/writePdf.js +165 -0
- package/dist/export/pptx/exportPptxDeck.d.ts +10 -2
- package/dist/export/pptx/exportPptxDeck.js +5 -2
- package/dist/export/pptx/svgPicture.d.ts +19 -0
- package/dist/export/pptx/svgPicture.js +64 -0
- package/dist/export/pptx/vectorizeElement.d.ts +9 -0
- package/dist/export/pptx/vectorizeElement.js +118 -0
- package/dist/export/pptx/writePptx.d.ts +13 -0
- package/dist/export/pptx/writePptx.js +17 -0
- package/dist/export/printPdf.d.ts +1 -0
- package/dist/export/printPdf.js +1 -1
- package/dist/export/scene/browserDeps.d.ts +32 -0
- package/dist/export/scene/browserDeps.js +174 -0
- package/dist/export/scene/imageBytes.d.ts +79 -0
- package/dist/export/scene/imageBytes.js +330 -0
- package/dist/export/scene/itemBounds.d.ts +9 -0
- package/dist/export/scene/itemBounds.js +40 -0
- package/dist/export/scene/matrix.d.ts +13 -0
- package/dist/export/scene/matrix.js +32 -0
- package/dist/export/scene/rasterLimit.d.ts +13 -0
- package/dist/export/scene/rasterLimit.js +24 -0
- package/dist/export/scene/rebaseOps.d.ts +8 -0
- package/dist/export/scene/rebaseOps.js +51 -0
- package/dist/export/scene/recordPageScene.d.ts +28 -0
- package/dist/export/scene/recordPageScene.js +224 -0
- package/dist/export/scene/recordingCanvas.d.ts +55 -0
- package/dist/export/scene/recordingCanvas.js +71 -0
- package/dist/export/scene/recordingContext.d.ts +162 -0
- package/dist/export/scene/recordingContext.js +1031 -0
- package/dist/export/scene/replayScene.d.ts +31 -0
- package/dist/export/scene/replayScene.js +213 -0
- package/dist/export/scene/resolveScene.d.ts +48 -0
- package/dist/export/scene/resolveScene.js +236 -0
- package/dist/export/scene/trustedSvgImages.d.ts +3 -0
- package/dist/export/scene/trustedSvgImages.js +21 -0
- package/dist/export/scene/types.d.ts +241 -0
- package/dist/export/scene/types.js +38 -0
- package/dist/export/slidesPdf.d.ts +10 -2
- package/dist/export/slidesPdf.js +8 -4
- package/dist/export/svg/__fixtures__/barChart.svg +1 -0
- package/dist/export/svg/__golden__/fixture-editable.svg +87 -0
- package/dist/export/svg/__golden__/fixture-outlines.svg +88 -0
- package/dist/export/svg/inlineSvg.d.ts +10 -0
- package/dist/export/svg/inlineSvg.js +119 -0
- package/dist/export/svg/scopeCss.d.ts +45 -0
- package/dist/export/svg/scopeCss.js +214 -0
- package/dist/export/svg/svgColor.d.ts +8 -0
- package/dist/export/svg/svgColor.js +46 -0
- package/dist/export/svg/svgImageScene.d.ts +41 -0
- package/dist/export/svg/svgImageScene.js +128 -0
- package/dist/export/svg/svgPathData.d.ts +31 -0
- package/dist/export/svg/svgPathData.js +466 -0
- package/dist/export/svg/svgToScene.d.ts +19 -0
- package/dist/export/svg/svgToScene.js +1183 -0
- package/dist/export/svg/writeSvg.d.ts +33 -0
- package/dist/export/svg/writeSvg.js +594 -0
- package/dist/export/svg/xml.d.ts +23 -0
- package/dist/export/svg/xml.js +49 -0
- package/dist/export/vectorDeps.d.ts +27 -0
- package/dist/export/vectorDeps.js +37 -0
- package/dist/export/vectorExport.d.ts +85 -0
- package/dist/export/vectorExport.js +287 -0
- package/dist/hostServices.d.ts +15 -0
- package/dist/i18n/de.d.ts +26 -9
- package/dist/i18n/de.js +26 -10
- package/dist/i18n/en.js +24 -0
- package/dist/primitives/AssetPrimitive.js +7 -2
- package/dist/primitives/CanvasIcons.js +6 -0
- package/dist/primitives/CanvasStage.js +2 -2
- package/dist/primitives/ChartPrimitive.d.ts +11 -1
- package/dist/primitives/ChartPrimitive.js +73 -19
- package/dist/primitives/IconPrimitive.js +3 -0
- package/dist/primitives/IllustrationPrimitive.js +14 -1
- package/dist/primitives/chartFont.d.ts +30 -0
- package/dist/primitives/chartFont.js +127 -0
- package/dist/sidebar/sections/ImageAdjustSection.js +5 -4
- package/dist/sidebar/sections/assets/ElementsPanel.js +4 -2
- package/dist/sidebar/sections/assets/assetAudience.d.ts +12 -0
- package/dist/sidebar/sections/assets/assetAudience.js +18 -0
- package/dist/sidebar/sections/assets/useElementCatalog.js +3 -2
- package/dist/stores/createCanvasEditorStore.d.ts +5 -2
- package/dist/stores/createCanvasEditorStore.js +9 -5
- package/dist/styles/compiled.css +1 -1
- package/dist/utils/canvasAssets.d.ts +11 -1
- package/dist/utils/canvasAssets.js +8 -0
- package/dist/utils/canvasIcons.js +5 -3
- package/dist/utils/captureStage.d.ts +19 -0
- package/dist/utils/captureStage.js +14 -1
- package/dist/utils/externalIcons.d.ts +7 -0
- package/dist/utils/externalIcons.js +70 -3
- package/dist/utils/illustrations/svgCache.js +6 -1
- package/dist/utils/imageFilters.d.ts +13 -0
- package/dist/utils/imageFilters.js +11 -0
- package/dist/utils/rebaseHistoryState.d.ts +9 -0
- package/dist/utils/rebaseHistoryState.js +26 -0
- package/dist/utils/zipPageImages.d.ts +8 -0
- package/dist/utils/zipPageImages.js +16 -4
- package/package.json +6 -2
- package/skills/ggraphic-embed/SKILL.md +33 -1
|
@@ -4,6 +4,7 @@ import { useState, useEffect, useRef, useCallback, memo } from 'react';
|
|
|
4
4
|
import { Image, Group, Rect, Transformer } from 'react-konva';
|
|
5
5
|
import { activeBrand } from '../brand/brandRegistry.js';
|
|
6
6
|
import { LOCKED_TRANSFORMER, useIsItemLocked } from '../components/canvasItemLock.js';
|
|
7
|
+
import { markTrustedSvgImage } from '../export/scene/trustedSvgImages.js';
|
|
7
8
|
import { useGeometryReporter } from '../hooks/useGeometryReporter.js';
|
|
8
9
|
import { useSnapScheduler } from '../hooks/useSnapScheduler.js';
|
|
9
10
|
import { isGroupDrag } from '../utils/multiSelect.js';
|
|
@@ -11,7 +12,7 @@ import { ELEMENT_TRANSFORMER, signedScale } from '../utils/orientation.js';
|
|
|
11
12
|
import { useImageRetry, useTrackPendingImage } from '../utils/pendingImages.js';
|
|
12
13
|
import { applyPixelHitArea } from '../utils/pixelHitArea.js';
|
|
13
14
|
import { boxFrame, createBoxFrame, frameBounds, snapByBounds } from '../utils/snapping.js';
|
|
14
|
-
import { ASSET_TARGET_SIZE, isStickerLikeInstance, resolveAssetInstanceSrc, } from '../utils/canvasAssets.js';
|
|
15
|
+
import { ASSET_TARGET_SIZE, isCatalogueInstance, isStickerLikeInstance, resolveAssetInstanceSrc, } from '../utils/canvasAssets.js';
|
|
15
16
|
// Rahmen für Snap und Geometrie-Meldung, pro Aufruf neu beschrieben (synchron, ohne Allokation).
|
|
16
17
|
const dragFrame = createBoxFrame();
|
|
17
18
|
const EXPORT_PIXEL_RATIO = 2;
|
|
@@ -24,6 +25,7 @@ function AssetPrimitiveInner({ asset, isSelected, onSelect, onDragEnd, onTransfo
|
|
|
24
25
|
const [imageSize, setImageSize] = useState({ width: 100, height: 100 });
|
|
25
26
|
const src = resolveAssetInstanceSrc(asset);
|
|
26
27
|
const stickerLike = isStickerLikeInstance(asset);
|
|
28
|
+
const fromCatalogue = isCatalogueInstance(asset);
|
|
27
29
|
const [settled, setSettled] = useState(null);
|
|
28
30
|
// A retry (`retryFailedImages`) loads the same source again.
|
|
29
31
|
const retry = useImageRetry(asset.id);
|
|
@@ -32,6 +34,9 @@ function AssetPrimitiveInner({ asset, isSelected, onSelect, onDragEnd, onTransfo
|
|
|
32
34
|
return;
|
|
33
35
|
const img = new window.Image();
|
|
34
36
|
img.crossOrigin = 'anonymous';
|
|
37
|
+
// The host's catalogue is the host's own artwork; a file stored for one instance is not.
|
|
38
|
+
if (fromCatalogue)
|
|
39
|
+
markTrustedSvgImage(img);
|
|
35
40
|
img.src = src;
|
|
36
41
|
img.onload = () => {
|
|
37
42
|
setImage(img);
|
|
@@ -43,7 +48,7 @@ function AssetPrimitiveInner({ asset, isSelected, onSelect, onDragEnd, onTransfo
|
|
|
43
48
|
img.onload = null;
|
|
44
49
|
img.onerror = null;
|
|
45
50
|
};
|
|
46
|
-
}, [src, retry]);
|
|
51
|
+
}, [src, retry, fromCatalogue]);
|
|
47
52
|
// Logos and stickers are assets too: the chat preview must not capture
|
|
48
53
|
// before they have arrived (#4834).
|
|
49
54
|
useTrackPendingImage(asset.id, src ?? '', settled?.src !== src || settled.retry !== retry ? 'loading' : settled.ok ? 'loaded' : 'failed');
|
|
@@ -5,6 +5,7 @@ import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
|
|
|
5
5
|
*/
|
|
6
6
|
import { useEffect, useState, useCallback } from 'react';
|
|
7
7
|
import useImage from 'use-image';
|
|
8
|
+
import { markTrustedSvgImage } from '../export/scene/trustedSvgImages.js';
|
|
8
9
|
import { generateIconDataUrl } from '../utils/canvasIcons.js';
|
|
9
10
|
import { CanvasImage } from './CanvasImage.js';
|
|
10
11
|
// Single icon component that loads from data URL
|
|
@@ -21,6 +22,11 @@ function CanvasIcon({ iconId, position, onDragEnd, onTransformEnd, selected, onS
|
|
|
21
22
|
};
|
|
22
23
|
}, [iconId, position.size, color]);
|
|
23
24
|
const [image] = useImage(dataUrl || '', 'anonymous');
|
|
25
|
+
// `useImage` makes the element; its url is the icon set's SVG from `generateIconDataUrl`.
|
|
26
|
+
useEffect(() => {
|
|
27
|
+
if (image)
|
|
28
|
+
markTrustedSvgImage(image);
|
|
29
|
+
}, [image]);
|
|
24
30
|
if (!dataUrl || !image)
|
|
25
31
|
return null;
|
|
26
32
|
return (_jsx(CanvasImage, { id: `icon-${iconId}`, image: image, x: position.x, y: position.y, width: position.size, height: position.size, draggable: true, selected: selected, onSelect: onSelect, onDragEnd: onDragEnd, onTransformEnd: onTransformEnd, stageWidth: stageWidth, stageHeight: stageHeight, transformConfig: { keepRatio: true, bounds: { minWidth: 24, maxWidth: 200 } } }));
|
|
@@ -19,7 +19,7 @@ import { cn } from '../utils/cn.js';
|
|
|
19
19
|
import { MOUSE_DRAG_DISTANCE, TOUCH_DRAG_DISTANCE } from '../utils/touchInput.js';
|
|
20
20
|
import { USER_PHOTO_NODE_NAME } from '../utils/userImageUtils.js';
|
|
21
21
|
import { STAGE_VERTICAL_CHROME } from '../utils/viewport.js';
|
|
22
|
-
import { withSelectionChromeHidden } from '../utils/captureStage.js';
|
|
22
|
+
import { PAGE_ROOT_NAME, withSelectionChromeHidden } from '../utils/captureStage.js';
|
|
23
23
|
import { BACKGROUND_IMAGE_NODE_ID, printImageInfo } from '../utils/printImageInfo.js';
|
|
24
24
|
/**
|
|
25
25
|
* The stage region to hand Konva's `toDataURL` so the PNG is exactly the
|
|
@@ -300,6 +300,6 @@ export const CanvasStage = forwardRef(({ width, height, logicalWidth, logicalHei
|
|
|
300
300
|
...style,
|
|
301
301
|
}, 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 &&
|
|
302
302
|
logicalHeight &&
|
|
303
|
-
(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 })] }) }));
|
|
303
|
+
(logicalWidth !== width || logicalHeight !== height) ? (_jsxs(_Fragment, { children: [_jsx(Rect, { x: 0, y: 0, width: width, height: height, fill: surface }), _jsx(Group, { name: PAGE_ROOT_NAME, scaleX: width / logicalWidth, scaleY: height / logicalHeight, children: children })] })) : (children) }) }), overlay, _jsx(TransformHud, { stageRef: displayStageRef, enabled: listening })] }) }));
|
|
304
304
|
});
|
|
305
305
|
CanvasStage.displayName = 'CanvasStage';
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
*/
|
|
11
11
|
import { type SnapProps } from '../hooks/useBoxSnap.js';
|
|
12
12
|
import { type ChartInstance } from '../utils/chartUtils.js';
|
|
13
|
+
import { type ChartFont } from './chartFont.js';
|
|
13
14
|
export interface ChartPrimitiveProps extends SnapProps {
|
|
14
15
|
chart: ChartInstance;
|
|
15
16
|
isSelected: boolean;
|
|
@@ -18,7 +19,16 @@ export interface ChartPrimitiveProps extends SnapProps {
|
|
|
18
19
|
onTransformEnd: (x: number, y: number, scale: number, rotation: number) => void;
|
|
19
20
|
draggable?: boolean;
|
|
20
21
|
}
|
|
21
|
-
|
|
22
|
+
/**
|
|
23
|
+
* `family` is the font-family the SVG will declare (`chartFontFamily`): the legend and the
|
|
24
|
+
* category axis are sized by labels measured in it.
|
|
25
|
+
*/
|
|
26
|
+
export declare function buildChartElement(recharts: any, chart: ChartInstance, family?: string): import("react").JSX.Element;
|
|
27
|
+
/**
|
|
28
|
+
* The chart as an image. `font` is the brand body font as the SVG carries it: an SVG image cannot
|
|
29
|
+
* load web fonts, so the files are embedded in the SVG itself (see `chartFont.ts`).
|
|
30
|
+
*/
|
|
31
|
+
export declare function renderChartImage(chart: ChartInstance, font: ChartFont): Promise<HTMLImageElement | null>;
|
|
22
32
|
declare function ChartPrimitiveInner({ chart, isSelected, onSelect, onDragEnd, onTransformEnd, draggable, ...snapProps }: ChartPrimitiveProps): import("react").JSX.Element;
|
|
23
33
|
export declare const ChartPrimitive: import("react").MemoExoticComponent<typeof ChartPrimitiveInner>;
|
|
24
34
|
export {};
|
|
@@ -13,13 +13,19 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
|
|
|
13
13
|
import { memo, useEffect, useRef, useState } from 'react';
|
|
14
14
|
import { createRoot } from 'react-dom/client';
|
|
15
15
|
import { Image, Group, Rect, Transformer } from 'react-konva';
|
|
16
|
+
import { useDocumentBrand } from '../brand/documentBrand.js';
|
|
16
17
|
import { activeBrand } from '../brand/brandRegistry.js';
|
|
18
|
+
import { useCanvasEditorServices } from '../CanvasEditorProvider.js';
|
|
17
19
|
import { LOCKED_TRANSFORMER, useIsItemLocked } from '../components/canvasItemLock.js';
|
|
20
|
+
import { markTrustedSvgImage } from '../export/scene/trustedSvgImages.js';
|
|
18
21
|
import { useBoxSnap } from '../hooks/useBoxSnap.js';
|
|
19
|
-
import { CHART_INK_DARK, chartInk, chartLegendPosition, chartSeries, chartSeriesOutlines, } from '../utils/chartUtils.js';
|
|
22
|
+
import { CHART_INK_DARK, chartColors, chartInk, chartLegendPosition, chartSeries, chartSeriesOutlines, } from '../utils/chartUtils.js';
|
|
23
|
+
import { isSafeColor } from '../utils/externalIcons.js';
|
|
20
24
|
import { ELEMENT_TRANSFORMER } from '../utils/orientation.js';
|
|
25
|
+
import { ensureFontsReady } from '../utils/ensureFontsReady.js';
|
|
21
26
|
import { useTrackPendingImage } from '../utils/pendingImages.js';
|
|
22
27
|
import { chartBox } from '../utils/renderedBoxes.js';
|
|
28
|
+
import { SANS, chartFontCss, chartFontFamily } from './chartFont.js';
|
|
23
29
|
const AXIS_TICK = { fontSize: 13, fill: CHART_INK_DARK };
|
|
24
30
|
/** Value labels stay dark, because in a light series colour they would vanish on white. */
|
|
25
31
|
const VALUE_LABEL = { fill: AXIS_TICK.fill, fontSize: 14, fontWeight: 700 };
|
|
@@ -27,12 +33,12 @@ const VALUE_LABEL = { fill: AXIS_TICK.fill, fontSize: 14, fontWeight: 700 };
|
|
|
27
33
|
const OUTLINE_PX = 2;
|
|
28
34
|
let measureContext;
|
|
29
35
|
/**
|
|
30
|
-
* A label's width at tick size
|
|
31
|
-
*
|
|
32
|
-
* needs 95 px where 13 × 7.5 − 8
|
|
33
|
-
* canvas can measure.
|
|
36
|
+
* A label's width at tick size in `family`, the font-family the chart SVG declares
|
|
37
|
+
* (`chartFontFamily`), so a label is measured in the font it is drawn in. A per-character
|
|
38
|
+
* estimate clipped wide labels: „Wünschen mehr" needs 95 px in sans-serif where 13 × 7.5 − 8
|
|
39
|
+
* left 89.5. The estimate stays only where no canvas can measure.
|
|
34
40
|
*/
|
|
35
|
-
function tickTextWidth(text) {
|
|
41
|
+
function tickTextWidth(text, family) {
|
|
36
42
|
if (measureContext === undefined) {
|
|
37
43
|
try {
|
|
38
44
|
measureContext = document.createElement('canvas').getContext('2d');
|
|
@@ -43,7 +49,7 @@ function tickTextWidth(text) {
|
|
|
43
49
|
}
|
|
44
50
|
if (!measureContext)
|
|
45
51
|
return text.length * 7.5;
|
|
46
|
-
measureContext.font = `${AXIS_TICK.fontSize}px
|
|
52
|
+
measureContext.font = `${AXIS_TICK.fontSize}px ${family}`;
|
|
47
53
|
return measureContext.measureText(text).width;
|
|
48
54
|
}
|
|
49
55
|
const LEGEND_ROW = 24;
|
|
@@ -56,8 +62,8 @@ const LEGEND_GAP = 18;
|
|
|
56
62
|
* and never reaches the image, so the legend is drawn as SVG: a column right
|
|
57
63
|
* of the chart, or centred rows below it that wrap at the chart's width.
|
|
58
64
|
*/
|
|
59
|
-
function layoutLegend(entries, position, width, height) {
|
|
60
|
-
const widths = entries.map((e) => LEGEND_TEXT_X + Math.ceil(tickTextWidth(e.name)));
|
|
65
|
+
function layoutLegend(entries, position, width, height, family) {
|
|
66
|
+
const widths = entries.map((e) => LEGEND_TEXT_X + Math.ceil(tickTextWidth(e.name, family)));
|
|
61
67
|
if (position === 'right') {
|
|
62
68
|
// 8 px gap to the chart, 4 px slack at the edge.
|
|
63
69
|
const column = Math.max(...widths) + 12;
|
|
@@ -98,16 +104,33 @@ function layoutLegend(entries, position, width, height) {
|
|
|
98
104
|
},
|
|
99
105
|
};
|
|
100
106
|
}
|
|
107
|
+
/**
|
|
108
|
+
* A series colour that can be written into the chart SVG. The colours are document data and the
|
|
109
|
+
* SVG is inlined into exports as it is, so `url(https://…)` and the like must not get through: the
|
|
110
|
+
* brand's colour of the same slot stands in for a colour `isSafeColor` rejects.
|
|
111
|
+
*/
|
|
112
|
+
function safeSeriesColor(color, index) {
|
|
113
|
+
if (isSafeColor(color))
|
|
114
|
+
return color;
|
|
115
|
+
const brand = chartColors();
|
|
116
|
+
const fallback = brand[index % brand.length];
|
|
117
|
+
return fallback !== undefined && isSafeColor(fallback) ? fallback : CHART_INK_DARK;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* `family` is the font-family the SVG will declare (`chartFontFamily`): the legend and the
|
|
121
|
+
* category axis are sized by labels measured in it.
|
|
122
|
+
*/
|
|
101
123
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
102
|
-
export function buildChartElement(recharts, chart) {
|
|
124
|
+
export function buildChartElement(recharts, chart, family = SANS) {
|
|
103
125
|
const { BarChart, Bar, LineChart, Line, AreaChart, Area, PieChart, Pie, Cell, XAxis, YAxis, CartesianGrid, LabelList, } = recharts;
|
|
104
|
-
const { width, height, data,
|
|
126
|
+
const { width, height, data, chartType, showGrid, showLegend, showValues } = chart;
|
|
127
|
+
const colors = chart.colors.map(safeSeriesColor);
|
|
105
128
|
const color = (i) => colors[i % colors.length];
|
|
106
129
|
// Auf dunklem Grund (dunkle Folie) stehen Achsen, Legende und Werte weiß.
|
|
107
130
|
const ink = chartInk(chart);
|
|
108
131
|
const tick = { ...AXIS_TICK, fill: ink };
|
|
109
132
|
const valueLabel = { ...VALUE_LABEL, fill: ink };
|
|
110
|
-
const outlines = chartSeriesOutlines(chart);
|
|
133
|
+
const outlines = chartSeriesOutlines({ ...chart, colors });
|
|
111
134
|
const outline = (i) => {
|
|
112
135
|
const stroke = outlines[i % colors.length];
|
|
113
136
|
return stroke ? { stroke, strokeWidth: OUTLINE_PX / chart.scale } : {};
|
|
@@ -123,7 +146,7 @@ export function buildChartElement(recharts, chart) {
|
|
|
123
146
|
? data.map((d, index) => ({ name: d.name, index }))
|
|
124
147
|
: (series ?? []).map((s, index) => ({ name: s.name, index }));
|
|
125
148
|
const legendPosition = chartLegendPosition(chart);
|
|
126
|
-
const legend = entries.length > 0 ? layoutLegend(entries, legendPosition, width, height) : null;
|
|
149
|
+
const legend = entries.length > 0 ? layoutLegend(entries, legendPosition, width, height, family) : null;
|
|
127
150
|
const legendTop = height - (legend?.height ?? 0);
|
|
128
151
|
const legendSvg = legend ? (_jsx("g", { children: legend.at(legendTop).map((pos, i) => (_jsxs("g", { transform: `translate(${pos.x}, ${pos.y})`, children: [_jsx("rect", { width: 14, height: 14, y: 3, rx: 3, fill: color(entries[i].index), ...outline(entries[i].index) }), _jsx("text", { x: LEGEND_TEXT_X, y: 10, dominantBaseline: "central", ...tick, children: entries[i].name })] }, i))) })) : null;
|
|
129
152
|
// Several series: one row per category, one key per series.
|
|
@@ -171,7 +194,7 @@ export function buildChartElement(recharts, chart) {
|
|
|
171
194
|
const horizontal = chartType === 'bar-horizontal';
|
|
172
195
|
// Room for the longest category name on the left and the longest value label
|
|
173
196
|
// past the bar's end (~8.5 px a bold character).
|
|
174
|
-
const nameWidth = Math.min(width * 0.4, Math.max(64, Math.ceil(Math.max(...data.map((d) => tickTextWidth(d.name)))) + 12));
|
|
197
|
+
const nameWidth = Math.min(width * 0.4, Math.max(64, Math.ceil(Math.max(...data.map((d) => tickTextWidth(d.name, family)))) + 12));
|
|
175
198
|
const valueRoom = showValues
|
|
176
199
|
? Math.max(...allValues.map((v) => formatValue(v).length)) * 8.5 + 12
|
|
177
200
|
: 0;
|
|
@@ -181,13 +204,25 @@ export function buildChartElement(recharts, chart) {
|
|
|
181
204
|
// Recharts' default `preserveEnd` drops names it measures as colliding.
|
|
182
205
|
interval: 0 })] })) : (_jsxs(_Fragment, { children: [_jsx(XAxis, { dataKey: "name", tick: tick, tickLine: false, axisLine: { stroke: '#c8c8c7' } }), _jsx(YAxis, { tick: tick, tickLine: false, axisLine: { stroke: '#c8c8c7' }, width: 40 })] })), keys.map((key, si) => (_jsxs(Bar, { dataKey: key, isAnimationActive: false, radius: horizontal ? [0, 4, 4, 0] : [4, 4, 0, 0], ...(series ? { fill: color(si), ...outline(si) } : {}), children: [series ? null : data.map((_, i) => _jsx(Cell, { fill: color(i), ...outline(i) }, i)), showValues ? (_jsx(LabelList, { dataKey: key, formatter: formatValue, ...valueLabel, position: horizontal ? 'right' : 'top' })) : null] }, key))), legendSvg] }));
|
|
183
206
|
}
|
|
184
|
-
|
|
207
|
+
/** How long a chart waits for the page's fonts before it measures with what is there. */
|
|
208
|
+
const FONT_WAIT_MS = 2000;
|
|
209
|
+
/**
|
|
210
|
+
* The chart as an image. `font` is the brand body font as the SVG carries it: an SVG image cannot
|
|
211
|
+
* load web fonts, so the files are embedded in the SVG itself (see `chartFont.ts`).
|
|
212
|
+
*/
|
|
213
|
+
export async function renderChartImage(chart, font) {
|
|
185
214
|
const container = document.createElement('div');
|
|
186
215
|
container.style.cssText = `position:absolute;left:-99999px;top:0;width:${chart.width}px;height:${chart.height}px;font-family:sans-serif;`;
|
|
187
216
|
document.body.appendChild(container);
|
|
188
|
-
|
|
217
|
+
// One family for both: the labels are measured in the font the SVG then draws them in. The
|
|
218
|
+
// brand font is a web font of the page; until it is loaded the canvas measures the fallback.
|
|
219
|
+
const family = chartFontFamily(font);
|
|
220
|
+
const [recharts] = await Promise.all([
|
|
221
|
+
import('recharts'),
|
|
222
|
+
font.css ? ensureFontsReady({ timeoutMs: FONT_WAIT_MS }) : undefined,
|
|
223
|
+
]);
|
|
189
224
|
const root = createRoot(container);
|
|
190
|
-
root.render(buildChartElement(recharts, chart));
|
|
225
|
+
root.render(buildChartElement(recharts, chart, family));
|
|
191
226
|
// Recharts paints after a couple of frames; poll for a populated <svg>.
|
|
192
227
|
const raf = () => new Promise((r) => requestAnimationFrame(() => r()));
|
|
193
228
|
let svg = null;
|
|
@@ -202,11 +237,18 @@ async function renderChartImage(chart) {
|
|
|
202
237
|
if (svg) {
|
|
203
238
|
svg.setAttribute('width', String(chart.width));
|
|
204
239
|
svg.setAttribute('height', String(chart.height));
|
|
205
|
-
svg.setAttribute('font-family',
|
|
240
|
+
svg.setAttribute('font-family', family);
|
|
241
|
+
if (font.css) {
|
|
242
|
+
const style = document.createElementNS('http://www.w3.org/2000/svg', 'style');
|
|
243
|
+
style.textContent = font.css;
|
|
244
|
+
svg.insertBefore(style, svg.firstChild);
|
|
245
|
+
}
|
|
206
246
|
const xml = new XMLSerializer().serializeToString(svg);
|
|
207
247
|
const url = `data:image/svg+xml;charset=utf-8,${encodeURIComponent(xml)}`;
|
|
208
248
|
image = await new Promise((resolve) => {
|
|
209
249
|
const img = new window.Image();
|
|
250
|
+
// The SVG is Recharts' own output for this chart; exports inline it as it is.
|
|
251
|
+
markTrustedSvgImage(img);
|
|
210
252
|
img.onload = () => resolve(img);
|
|
211
253
|
img.onerror = () => resolve(null);
|
|
212
254
|
img.src = url;
|
|
@@ -216,8 +258,15 @@ async function renderChartImage(chart) {
|
|
|
216
258
|
container.remove();
|
|
217
259
|
return image;
|
|
218
260
|
}
|
|
261
|
+
/** The chart image in the brand body font, or in `sans-serif` where no file for it is found. */
|
|
262
|
+
async function renderChartInBrandFont(chart, family, fontDeps) {
|
|
263
|
+
return renderChartImage(chart, { family, css: await chartFontCss(family, fontDeps) });
|
|
264
|
+
}
|
|
219
265
|
function ChartPrimitiveInner({ chart, isSelected, onSelect, onDragEnd, onTransformEnd, draggable = true, ...snapProps }) {
|
|
220
266
|
const locked = useIsItemLocked();
|
|
267
|
+
const brand = useDocumentBrand();
|
|
268
|
+
const { exportFonts } = useCanvasEditorServices();
|
|
269
|
+
const bodyFamily = brand.fonts.body;
|
|
221
270
|
const snap = useBoxSnap({ id: chart.id, ...snapProps }, chartBox(chart));
|
|
222
271
|
const groupRef = useRef(null);
|
|
223
272
|
const transformerRef = useRef(null);
|
|
@@ -237,6 +286,7 @@ function ChartPrimitiveInner({ chart, isSelected, onSelect, onDragEnd, onTransfo
|
|
|
237
286
|
chart.unit ?? '',
|
|
238
287
|
chart.background ?? '',
|
|
239
288
|
chart.scale,
|
|
289
|
+
bodyFamily,
|
|
240
290
|
]);
|
|
241
291
|
const [rendered, setRendered] = useState({
|
|
242
292
|
image: null,
|
|
@@ -254,7 +304,11 @@ function ChartPrimitiveInner({ chart, isSelected, onSelect, onDragEnd, onTransfo
|
|
|
254
304
|
useEffect(() => {
|
|
255
305
|
let cancelled = false;
|
|
256
306
|
const timer = setTimeout(() => {
|
|
257
|
-
void
|
|
307
|
+
void renderChartInBrandFont(chart, bodyFamily, {
|
|
308
|
+
...(exportFonts ? { host: exportFonts } : {}),
|
|
309
|
+
brandFaces: brand.fontFaces,
|
|
310
|
+
...(brand.fonts.boldFamilies ? { boldFamilies: brand.fonts.boldFamilies } : {}),
|
|
311
|
+
})
|
|
258
312
|
.catch(() => null)
|
|
259
313
|
.then((img) => {
|
|
260
314
|
// A failed render keeps the last image but stops the wait.
|
|
@@ -3,6 +3,7 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
|
|
|
3
3
|
import { useState, useEffect, useRef, useCallback, memo } from 'react';
|
|
4
4
|
import { Image, Group, Rect, Transformer } from 'react-konva';
|
|
5
5
|
import { LOCKED_TRANSFORMER, useIsItemLocked } from '../components/canvasItemLock.js';
|
|
6
|
+
import { markTrustedSvgImage } from '../export/scene/trustedSvgImages.js';
|
|
6
7
|
import { useGeometryReporter } from '../hooks/useGeometryReporter.js';
|
|
7
8
|
import { useSnapScheduler } from '../hooks/useSnapScheduler.js';
|
|
8
9
|
import { generateIconDataUrl } from '../utils/canvasIcons.js';
|
|
@@ -26,6 +27,8 @@ function IconPrimitiveInner({ id, icon, x, y, scale, rotation, flipX = false, fl
|
|
|
26
27
|
if (cancelled || !dataUrl)
|
|
27
28
|
return;
|
|
28
29
|
const img = new window.Image();
|
|
30
|
+
// The data url is built from the icon set (or the sanitised external icon) and a colour.
|
|
31
|
+
markTrustedSvgImage(img);
|
|
29
32
|
img.src = dataUrl;
|
|
30
33
|
img.onload = () => {
|
|
31
34
|
if (!cancelled)
|
|
@@ -4,7 +4,9 @@ import { useState, useEffect, useRef, memo } from 'react';
|
|
|
4
4
|
import { Image, Group, Rect, Transformer } from 'react-konva';
|
|
5
5
|
import { activeBrand } from '../brand/brandRegistry.js';
|
|
6
6
|
import { LOCKED_TRANSFORMER, useIsItemLocked } from '../components/canvasItemLock.js';
|
|
7
|
+
import { markTrustedSvgImage } from '../export/scene/trustedSvgImages.js';
|
|
7
8
|
import { useBoxSnap } from '../hooks/useBoxSnap.js';
|
|
9
|
+
import { isSafeColor } from '../utils/externalIcons.js';
|
|
8
10
|
import { ILLUSTRATION_TARGET_SIZE, MOTIF_BASE_SIZE } from '../utils/motifSizes.js';
|
|
9
11
|
import { ELEMENT_TRANSFORMER, signedScale } from '../utils/orientation.js';
|
|
10
12
|
import { illustrationBox } from '../utils/renderedBoxes.js';
|
|
@@ -35,7 +37,11 @@ async function renderKawaiiSvg(instance, size) {
|
|
|
35
37
|
const Component = components[instance.illustrationId];
|
|
36
38
|
if (!Component)
|
|
37
39
|
return null;
|
|
38
|
-
|
|
40
|
+
// The colour is the document's and goes into the markup as it is; `export` inlines this SVG as
|
|
41
|
+
// trusted, so a value that is not a plain colour (`url(https://…)`) must not get that far. The
|
|
42
|
+
// library draws its own default colour without one.
|
|
43
|
+
const color = isSafeColor(instance.color) ? instance.color : undefined;
|
|
44
|
+
return renderToStaticMarkup(_jsx(Component, { size: size, mood: instance.mood, color: color }));
|
|
39
45
|
}
|
|
40
46
|
function IllustrationPrimitiveInner({ illustration, isSelected, onSelect, onDragEnd, onTransformEnd, draggable = true, ...snapProps }) {
|
|
41
47
|
const locked = useIsItemLocked();
|
|
@@ -55,6 +61,8 @@ function IllustrationPrimitiveInner({ illustration, isSelected, onSelect, onDrag
|
|
|
55
61
|
const encoded = encodeURIComponent(svgString);
|
|
56
62
|
const dataUrl = `data:image/svg+xml;charset=utf-8,${encoded}`;
|
|
57
63
|
const img = new window.Image();
|
|
64
|
+
// Rendered from the Kawaii components right here.
|
|
65
|
+
markTrustedSvgImage(img);
|
|
58
66
|
img.src = dataUrl;
|
|
59
67
|
img.onload = () => setImage(img);
|
|
60
68
|
});
|
|
@@ -70,6 +78,8 @@ function IllustrationPrimitiveInner({ illustration, isSelected, onSelect, onDrag
|
|
|
70
78
|
const cached = getCachedSVG(svgDef.id, illustration.color);
|
|
71
79
|
if (cached) {
|
|
72
80
|
const img = new window.Image();
|
|
81
|
+
// The catalogue's SVG, recoloured; the document only picks the entry and the colour.
|
|
82
|
+
markTrustedSvgImage(img);
|
|
73
83
|
img.src = cached;
|
|
74
84
|
img.onload = () => setImage(img);
|
|
75
85
|
return;
|
|
@@ -78,6 +88,7 @@ function IllustrationPrimitiveInner({ illustration, isSelected, onSelect, onDrag
|
|
|
78
88
|
try {
|
|
79
89
|
const dataUrl = await getSVG(svgDef.id, svgDef, illustration.color, assetBaseUrl);
|
|
80
90
|
const img = new window.Image();
|
|
91
|
+
markTrustedSvgImage(img);
|
|
81
92
|
img.src = dataUrl;
|
|
82
93
|
img.onload = () => setImage(img);
|
|
83
94
|
}
|
|
@@ -86,6 +97,8 @@ function IllustrationPrimitiveInner({ illustration, isSelected, onSelect, onDrag
|
|
|
86
97
|
// Final fallback: direct load without color manipulation
|
|
87
98
|
const path = getIllustrationPath(svgDef, assetBaseUrl);
|
|
88
99
|
const img = new window.Image();
|
|
100
|
+
// The catalogue entry's own file, by its path under the host's asset base.
|
|
101
|
+
markTrustedSvgImage(img);
|
|
89
102
|
img.src = path;
|
|
90
103
|
img.onload = () => setImage(img);
|
|
91
104
|
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The brand body font as CSS for a chart SVG.
|
|
3
|
+
*
|
|
4
|
+
* The chart is drawn as an image, and an SVG image cannot load web fonts: its labels fell back to
|
|
5
|
+
* the system sans. So the font files travel inside the SVG, as `@font-face` rules with `data:`
|
|
6
|
+
* URLs in a `<style>` element. The files come from the same resolver the vector export uses
|
|
7
|
+
* (`resolveFontFiles`), so the canvas and an exported SVG draw the same face.
|
|
8
|
+
*/
|
|
9
|
+
import type { FontFile, FontSourceDeps } from '../export/fonts/fontFiles.js';
|
|
10
|
+
/** The body font a chart is drawn in: the family, and the rules that make an SVG image draw it. */
|
|
11
|
+
export interface ChartFont {
|
|
12
|
+
family: string;
|
|
13
|
+
/** `@font-face` rules with the files as data URLs; null = no file found, the SVG stays `sans-serif`. */
|
|
14
|
+
css: string | null;
|
|
15
|
+
}
|
|
16
|
+
/** What a chart without a font of its own is drawn and measured in. */
|
|
17
|
+
export declare const SANS = "sans-serif";
|
|
18
|
+
/**
|
|
19
|
+
* The `font-family` the chart SVG declares, and the one its labels are measured in. A chart
|
|
20
|
+
* draws and measures through this one function, so the two cannot drift apart.
|
|
21
|
+
*/
|
|
22
|
+
export declare function chartFontFamily(font: ChartFont): string;
|
|
23
|
+
export declare function chartFontCss(family: string, deps: FontSourceDeps): Promise<string | null>;
|
|
24
|
+
/** `value` as a CSS string: quoted, with `"`, `\` and control characters escaped. */
|
|
25
|
+
export declare function cssString(value: string): string;
|
|
26
|
+
/** The `@font-face` rules for the files of `family`, or null if none may be written into an SVG. */
|
|
27
|
+
export declare function fontFaceCss(family: string, entries: readonly {
|
|
28
|
+
weight: number;
|
|
29
|
+
file: FontFile;
|
|
30
|
+
}[]): string | null;
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
/** What a chart without a font of its own is drawn and measured in. */
|
|
2
|
+
export const SANS = 'sans-serif';
|
|
3
|
+
/**
|
|
4
|
+
* The `font-family` the chart SVG declares, and the one its labels are measured in. A chart
|
|
5
|
+
* draws and measures through this one function, so the two cannot drift apart.
|
|
6
|
+
*/
|
|
7
|
+
export function chartFontFamily(font) {
|
|
8
|
+
return font.css ? `${cssString(font.family)}, ${SANS}` : SANS;
|
|
9
|
+
}
|
|
10
|
+
/** Tick and legend text is regular, value labels are bold. */
|
|
11
|
+
const WEIGHTS = [400, 700];
|
|
12
|
+
/**
|
|
13
|
+
* One build per family for the whole session: fonts do not change while the editor is open, and
|
|
14
|
+
* every chart re-render (a few a second while someone types in the data table) would otherwise
|
|
15
|
+
* read and encode the files again. A build that found nothing is dropped again, so a font that
|
|
16
|
+
* was only late (a failed download) is tried the next time instead of being missing until reload.
|
|
17
|
+
*/
|
|
18
|
+
const builds = new Map();
|
|
19
|
+
export function chartFontCss(family, deps) {
|
|
20
|
+
const key = `${family}|${WEIGHTS.join(',')}`;
|
|
21
|
+
let build = builds.get(key);
|
|
22
|
+
if (!build) {
|
|
23
|
+
const started = buildCss(family, deps);
|
|
24
|
+
build = started;
|
|
25
|
+
builds.set(key, started);
|
|
26
|
+
void started.then((css) => {
|
|
27
|
+
if (css === null && builds.get(key) === started)
|
|
28
|
+
builds.delete(key);
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
return build;
|
|
32
|
+
}
|
|
33
|
+
async function buildCss(family, deps) {
|
|
34
|
+
try {
|
|
35
|
+
// Loaded on the first chart, like recharts: the resolver is not part of the editor core chunk.
|
|
36
|
+
const { resolveFontFiles } = await import('../export/fonts/fontFiles.js');
|
|
37
|
+
const sets = await Promise.all(WEIGHTS.map((weight) => resolveFontFiles({ family, weight, style: 'normal', size: 13 }, deps)));
|
|
38
|
+
return fontFaceCss(family, sets.flatMap((set) => set.files.map((file) => ({ weight: set.face.weight, file }))));
|
|
39
|
+
}
|
|
40
|
+
catch {
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
/** `value` as a CSS string: quoted, with `"`, `\` and control characters escaped. */
|
|
45
|
+
export function cssString(value) {
|
|
46
|
+
const escaped = value.replace(
|
|
47
|
+
// eslint-disable-next-line no-control-regex -- control characters are exactly what is escaped
|
|
48
|
+
/["\\\u0000-\u001f\u007f]/g, (char) => char === '"' || char === '\\' ? `\\${char}` : `\\${char.charCodeAt(0).toString(16)} `);
|
|
49
|
+
return `"${escaped}"`;
|
|
50
|
+
}
|
|
51
|
+
/** The `@font-face` rules for the files of `family`, or null if none may be written into an SVG. */
|
|
52
|
+
export function fontFaceCss(family, entries) {
|
|
53
|
+
// The same file serves both weights when the font is variable, or has no bold of its own.
|
|
54
|
+
const faces = [];
|
|
55
|
+
for (const { weight, file } of entries) {
|
|
56
|
+
// A licence that keeps the font out of a file keeps it out of a data URL as well.
|
|
57
|
+
if (file.embeddable !== 'yes')
|
|
58
|
+
continue;
|
|
59
|
+
const same = faces.find((face) => sameFile(face.file, file));
|
|
60
|
+
if (same)
|
|
61
|
+
same.weights.push(weight);
|
|
62
|
+
else
|
|
63
|
+
faces.push({ file, weights: [weight] });
|
|
64
|
+
}
|
|
65
|
+
const rules = faces.flatMap(({ file, weights }) => {
|
|
66
|
+
const type = fontType(file.bytes);
|
|
67
|
+
if (!type)
|
|
68
|
+
return [];
|
|
69
|
+
const declarations = [
|
|
70
|
+
`font-family:${cssString(family)}`,
|
|
71
|
+
'font-style:normal',
|
|
72
|
+
`font-weight:${weightDescriptor(file, weights)}`,
|
|
73
|
+
`src:url(data:${type.mime};base64,${toBase64(file.bytes)}) format('${type.format}')`,
|
|
74
|
+
];
|
|
75
|
+
if (file.ranges)
|
|
76
|
+
declarations.push(`unicode-range:${file.ranges.map(unicodeRange).join(',')}`);
|
|
77
|
+
return [`@font-face{${declarations.join(';')}}`];
|
|
78
|
+
});
|
|
79
|
+
return rules.length > 0 ? rules.join('\n') : null;
|
|
80
|
+
}
|
|
81
|
+
function sameFile(a, b) {
|
|
82
|
+
if (a.bytes.length !== b.bytes.length)
|
|
83
|
+
return false;
|
|
84
|
+
if (JSON.stringify(a.ranges) !== JSON.stringify(b.ranges))
|
|
85
|
+
return false;
|
|
86
|
+
return a.bytes.every((byte, i) => byte === b.bytes[i]);
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* A variable font declares the range of its weight axis, so a bold label gets the real bold
|
|
90
|
+
* instead of a slanted-on one. A static file declares the lightest weight it was asked for: when
|
|
91
|
+
* it is the regular cut standing in for the bold, the browser thickens it itself.
|
|
92
|
+
*/
|
|
93
|
+
function weightDescriptor(file, weights) {
|
|
94
|
+
// Boundary cast: fontkit reads `variationAxes` on variable fonts; `FontkitFont` does not declare it.
|
|
95
|
+
const axes = file.font
|
|
96
|
+
.variationAxes;
|
|
97
|
+
const wght = axes?.['wght'];
|
|
98
|
+
return wght ? `${wght.min} ${wght.max}` : String(Math.min(...weights));
|
|
99
|
+
}
|
|
100
|
+
function unicodeRange([from, to]) {
|
|
101
|
+
const hex = (n) => n.toString(16).toUpperCase();
|
|
102
|
+
return from === to ? `U+${hex(from)}` : `U+${hex(from)}-${hex(to)}`;
|
|
103
|
+
}
|
|
104
|
+
/** What the first bytes say the file is; the stylesheet's `format()` hint can be wrong or missing. */
|
|
105
|
+
function fontType(bytes) {
|
|
106
|
+
const tag = String.fromCharCode(bytes[0] ?? 0, bytes[1] ?? 0, bytes[2] ?? 0, bytes[3] ?? 0);
|
|
107
|
+
switch (tag) {
|
|
108
|
+
case 'wOF2':
|
|
109
|
+
return { mime: 'font/woff2', format: 'woff2' };
|
|
110
|
+
case 'wOFF':
|
|
111
|
+
return { mime: 'font/woff', format: 'woff' };
|
|
112
|
+
case 'OTTO':
|
|
113
|
+
return { mime: 'font/otf', format: 'opentype' };
|
|
114
|
+
case 'true':
|
|
115
|
+
case '\u0000\u0001\u0000\u0000':
|
|
116
|
+
return { mime: 'font/ttf', format: 'truetype' };
|
|
117
|
+
default:
|
|
118
|
+
return null;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
function toBase64(bytes) {
|
|
122
|
+
let binary = '';
|
|
123
|
+
for (let i = 0; i < bytes.length; i += 0x8000) {
|
|
124
|
+
binary += String.fromCharCode(...bytes.subarray(i, i + 0x8000));
|
|
125
|
+
}
|
|
126
|
+
return btoa(binary);
|
|
127
|
+
}
|
|
@@ -4,7 +4,7 @@ import { useDocumentBrand } from '../../brand/documentBrand.js';
|
|
|
4
4
|
import { CustomColorSwatch } from '../../components/CustomColorSwatch.js';
|
|
5
5
|
import { useMessages } from '../../i18n/messages.js';
|
|
6
6
|
import { Switch } from '../../ui/switch.js';
|
|
7
|
-
import {
|
|
7
|
+
import { duotoneLook, EMPTY_ADJUSTMENTS, fallbackTintOf, IMAGE_PRESETS, withoutDuotone, } from '../../utils/imageFilters.js';
|
|
8
8
|
import { CROP_PRESETS, cropPresetUpdate, } from '../../utils/userImageUtils.js';
|
|
9
9
|
import { colorName } from '../../utils/colorNames.js';
|
|
10
10
|
import { SidebarSlider } from '../components/SidebarSlider.js';
|
|
@@ -21,6 +21,7 @@ const GROUP_LABEL = 'text-[11px] font-semibold uppercase tracking-wide text-fore
|
|
|
21
21
|
export function ImageAdjustSection({ selectedImage, onUpdateImage, backgroundPhoto = null, brandScheme = null, }) {
|
|
22
22
|
const brand = useDocumentBrand();
|
|
23
23
|
const { tints, shadows } = brand.effects;
|
|
24
|
+
const fallbackTint = fallbackTintOf(brand);
|
|
24
25
|
const t = useMessages();
|
|
25
26
|
const img = selectedImage;
|
|
26
27
|
const adj = img ?? backgroundPhoto?.adjustments ?? null;
|
|
@@ -67,13 +68,13 @@ export function ImageAdjustSection({ selectedImage, onUpdateImage, backgroundPho
|
|
|
67
68
|
return (_jsxs("div", { className: "flex flex-col gap-4 p-md w-full min-w-0", children: [_jsxs("div", { className: "flex items-center justify-between", children: [_jsx("span", { className: "text-sm font-semibold text-foreground", children: t.sidebar.imageAdjust.title }), _jsx("button", { type: "button", onClick: () => set({ ...EMPTY_ADJUSTMENTS, ...(img ? withoutDuotone(img) : {}) }), className: "rounded-md px-2 py-1 text-xs text-foreground-muted hover:text-foreground", children: t.sidebar.imageAdjust.reset })] }), _jsxs("div", { className: "flex flex-col gap-1.5", children: [_jsx("span", { className: GROUP_LABEL, children: "Presets" }), _jsx("div", { className: "grid grid-cols-3 gap-1.5", children: IMAGE_PRESETS.map((preset) => (_jsx("button", { type: "button", onClick: () => applyPreset(preset), className: "rounded-md border border-editor-border-strong px-2 py-1.5 text-xs text-foreground-muted transition-colors hover:border-primary-500 hover:text-foreground", children: preset.label }, preset.id))) })] }), img && (_jsxs("div", { className: "flex flex-col gap-1.5", children: [_jsx("span", { className: GROUP_LABEL, children: t.topBar.crop }), _jsx("div", { className: "grid grid-cols-4 gap-1.5", children: CROP_PRESETS.map((preset) => (_jsx("button", { type: "button", onClick: () => applyCrop(preset), className: "rounded-md border border-editor-border-strong px-2 py-1.5 text-xs text-foreground-muted transition-colors hover:border-primary-500 hover:text-foreground", children: preset.label }, preset.id))) })] })), _jsxs("div", { className: "flex flex-col gap-1.5", children: [_jsx("span", { className: GROUP_LABEL, children: t.sidebar.imageAdjust.flip }), _jsx("div", { className: "grid grid-cols-2 gap-1.5", children: [
|
|
68
69
|
['flipX', t.sidebar.imageAdjust.horizontal],
|
|
69
70
|
['flipY', t.sidebar.imageAdjust.vertical],
|
|
70
|
-
].map(([key, label]) => (_jsx("button", { type: "button", "aria-pressed": !!adj[key], onClick: () => set({ [key]: !adj[key] }), className: "rounded-md border border-editor-border-strong px-2 py-1.5 text-xs text-foreground-muted transition-colors hover:border-primary-500 hover:text-foreground aria-pressed:border-primary-500 aria-pressed:text-foreground", children: label }, key))) })] }), _jsxs("div", { className: "flex flex-col gap-2", children: [_jsx("span", { className: GROUP_LABEL, children: t.sidebar.imageAdjust.tint }), _jsxs("div", { className: "flex items-center gap-1.5", children: [tints.map((c) => (_jsx("button", { type: "button", onClick: () => setTint({ tint: c, tintStrength: adj.tintStrength || 1 }), title: colorName(c, brand), "aria-label": t.sidebar.imageAdjust.tintIn(colorName(c, brand)), "aria-pressed": (adj.tint ??
|
|
71
|
+
].map(([key, label]) => (_jsx("button", { type: "button", "aria-pressed": !!adj[key], onClick: () => set({ [key]: !adj[key] }), className: "rounded-md border border-editor-border-strong px-2 py-1.5 text-xs text-foreground-muted transition-colors hover:border-primary-500 hover:text-foreground aria-pressed:border-primary-500 aria-pressed:text-foreground", children: label }, key))) })] }), _jsxs("div", { className: "flex flex-col gap-2", children: [_jsx("span", { className: GROUP_LABEL, children: t.sidebar.imageAdjust.tint }), _jsxs("div", { className: "flex items-center gap-1.5", children: [tints.map((c) => (_jsx("button", { type: "button", onClick: () => setTint({ tint: c, tintStrength: adj.tintStrength || 1 }), title: colorName(c, brand), "aria-label": t.sidebar.imageAdjust.tintIn(colorName(c, brand)), "aria-pressed": (adj.tint ?? fallbackTint) === c && !!adj.tintStrength, className: "size-6 rounded-full border border-black/10 transition-transform hover:scale-110", style: {
|
|
71
72
|
backgroundColor: c,
|
|
72
|
-
outline: (adj.tint ??
|
|
73
|
+
outline: (adj.tint ?? fallbackTint) === c && adj.tintStrength
|
|
73
74
|
? '2px solid var(--editor-accent)'
|
|
74
75
|
: 'none',
|
|
75
76
|
outlineOffset: '2px',
|
|
76
|
-
} }, c))), _jsx(CustomColorSwatch, { value: adj.tintStrength ? adj.tint : null, presets: tints, onPick: (color) => setTint({ tint: color, tintStrength: adj.tintStrength || 1 }), className: "size-6" })] }), _jsx(SidebarSlider, { label: t.sidebar.imageAdjust.intensity, value: adj.tintStrength ?? 0, onValueChange: (v) => set({ tintStrength: v }), min: 0, max: 1, step: 0.05, unit: "%" })] }), _jsxs("div", { className: "flex flex-col gap-2", children: [_jsx("span", { className: GROUP_LABEL, children: t.sidebar.imageAdjust.whiteBalance }), _jsx(SidebarSlider, { label: t.sidebar.imageAdjust.colorTemperature, value: adj.temperature ?? 0, onValueChange: (v) => set({ temperature: v }), min: -100, max: 100, step: 1 }), _jsx(SidebarSlider, { label: t.sidebar.imageAdjust.hue, value: adj.hue ?? 0, onValueChange: (v) => set({ hue: v }), min: 0, max: 360, step: 1 })] }), _jsxs("div", { className: "flex flex-col gap-2", children: [_jsx("span", { className: GROUP_LABEL, children: t.sidebar.imageAdjust.light }), _jsx(SidebarSlider, { label: t.sidebar.imageAdjust.brightness, value: adj.brightness ?? 0, onValueChange: (v) => set({ brightness: v }), min: -1, max: 1, step: 0.05 }), _jsx(SidebarSlider, { label: t.sidebar.imageAdjust.contrast, value: adj.contrast ?? 0, onValueChange: (v) => set({ contrast: v }), min: -100, max: 100, step: 1 })] }), _jsxs("div", { className: "flex flex-col gap-2", children: [_jsx("span", { className: GROUP_LABEL, children: t.sidebar.imageAdjust.colorAndSharpness }), _jsx(SidebarSlider, { label: t.sidebar.imageAdjust.saturation, value: adj.saturation ?? 0, onValueChange: (v) => set({ saturation: v }), min: -2, max: 10, step: 0.1 }), _jsx(SidebarSlider, { label: t.sidebar.imageAdjust.blur, value: adj.blur ?? 0, onValueChange: (v) => set({ blur: v }), min: 0, max: 40, step: 1 }), _jsx(SidebarSlider, { label: t.sidebar.imageAdjust.vignette, value: adj.vignette ?? 0, onValueChange: (v) => set({ vignette: v }), min: 0, max: 1, step: 0.05, unit: "%" })] }), img && (_jsxs("div", { className: "flex flex-col gap-2", children: [_jsxs("div", { className: "flex items-center justify-between", children: [_jsx("span", { className: GROUP_LABEL, children: t.topBar.shadow }), _jsx("button", { type: "button", onClick: toggleShadow, className: "text-[11px] font-medium text-primary-600 hover:underline", children: shadowOn ? t.sidebar.imageAdjust.remove : t.sidebar.imageAdjust.enable })] }), shadowOn && (_jsxs(_Fragment, { children: [_jsxs("div", { className: "flex items-center gap-1.5", children: [shadows.map((c) => (_jsx("button", { type: "button", onClick: () => setShadow({ shadowColor: c }), title: colorName(c, brand), "aria-label": colorName(c, brand), "aria-pressed": img.shadowColor === c, className: "size-6 rounded-full border border-black/10 transition-transform hover:scale-110", style: {
|
|
77
|
+
} }, c))), _jsx(CustomColorSwatch, { value: adj.tintStrength ? adj.tint : null, presets: tints, onPick: (color) => setTint({ tint: color, tintStrength: adj.tintStrength || 1 }), className: "size-6" })] }), _jsx(SidebarSlider, { label: t.sidebar.imageAdjust.intensity, value: adj.tintStrength ?? 0, onValueChange: (v) => set({ tintStrength: v, ...(adj.tint ? {} : { tint: fallbackTint }) }), min: 0, max: 1, step: 0.05, unit: "%" })] }), _jsxs("div", { className: "flex flex-col gap-2", children: [_jsx("span", { className: GROUP_LABEL, children: t.sidebar.imageAdjust.whiteBalance }), _jsx(SidebarSlider, { label: t.sidebar.imageAdjust.colorTemperature, value: adj.temperature ?? 0, onValueChange: (v) => set({ temperature: v }), min: -100, max: 100, step: 1 }), _jsx(SidebarSlider, { label: t.sidebar.imageAdjust.hue, value: adj.hue ?? 0, onValueChange: (v) => set({ hue: v }), min: 0, max: 360, step: 1 })] }), _jsxs("div", { className: "flex flex-col gap-2", children: [_jsx("span", { className: GROUP_LABEL, children: t.sidebar.imageAdjust.light }), _jsx(SidebarSlider, { label: t.sidebar.imageAdjust.brightness, value: adj.brightness ?? 0, onValueChange: (v) => set({ brightness: v }), min: -1, max: 1, step: 0.05 }), _jsx(SidebarSlider, { label: t.sidebar.imageAdjust.contrast, value: adj.contrast ?? 0, onValueChange: (v) => set({ contrast: v }), min: -100, max: 100, step: 1 })] }), _jsxs("div", { className: "flex flex-col gap-2", children: [_jsx("span", { className: GROUP_LABEL, children: t.sidebar.imageAdjust.colorAndSharpness }), _jsx(SidebarSlider, { label: t.sidebar.imageAdjust.saturation, value: adj.saturation ?? 0, onValueChange: (v) => set({ saturation: v }), min: -2, max: 10, step: 0.1 }), _jsx(SidebarSlider, { label: t.sidebar.imageAdjust.blur, value: adj.blur ?? 0, onValueChange: (v) => set({ blur: v }), min: 0, max: 40, step: 1 }), _jsx(SidebarSlider, { label: t.sidebar.imageAdjust.vignette, value: adj.vignette ?? 0, onValueChange: (v) => set({ vignette: v }), min: 0, max: 1, step: 0.05, unit: "%" })] }), img && (_jsxs("div", { className: "flex flex-col gap-2", children: [_jsxs("div", { className: "flex items-center justify-between", children: [_jsx("span", { className: GROUP_LABEL, children: t.topBar.shadow }), _jsx("button", { type: "button", onClick: toggleShadow, className: "text-[11px] font-medium text-primary-600 hover:underline", children: shadowOn ? t.sidebar.imageAdjust.remove : t.sidebar.imageAdjust.enable })] }), shadowOn && (_jsxs(_Fragment, { children: [_jsxs("div", { className: "flex items-center gap-1.5", children: [shadows.map((c) => (_jsx("button", { type: "button", onClick: () => setShadow({ shadowColor: c }), title: colorName(c, brand), "aria-label": colorName(c, brand), "aria-pressed": img.shadowColor === c, className: "size-6 rounded-full border border-black/10 transition-transform hover:scale-110", style: {
|
|
77
78
|
backgroundColor: c,
|
|
78
79
|
outline: img.shadowColor === c ? '2px solid var(--editor-accent)' : 'none',
|
|
79
80
|
outlineOffset: '2px',
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
2
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
3
3
|
import { useCanvasEditorServices } from '../../../CanvasEditorProvider.js';
|
|
4
|
+
import { useAssetAudience } from './assetAudience.js';
|
|
4
5
|
import { useDebounce } from '../../../hooks/useDebounce.js';
|
|
5
6
|
import { messages, useMessages } from '../../../i18n/messages.js';
|
|
6
7
|
import { registeredAssetCatalog } from '../../../utils/canvasAssets.js';
|
|
@@ -67,7 +68,8 @@ function BlockGroups({ blocks, items, grid, }) {
|
|
|
67
68
|
export function ElementsPanel(props) {
|
|
68
69
|
const t = useMessages();
|
|
69
70
|
const isMobile = useIsCanvasMobile();
|
|
70
|
-
const {
|
|
71
|
+
const { searchUnsplashImages, iconSearch } = useCanvasEditorServices();
|
|
72
|
+
const audience = useAssetAudience();
|
|
71
73
|
// Opened for a selected frame or illustration ("Mehr" on the phone), it starts in that category.
|
|
72
74
|
const [cat, setCat] = useState(() => props.selectedFrameId ? 'rahmen' : props.selectedIllustrationId ? 'illustrationen' : null);
|
|
73
75
|
const [query, setQuery] = useState('');
|
|
@@ -202,7 +204,7 @@ export function ElementsPanel(props) {
|
|
|
202
204
|
const placeholder = category
|
|
203
205
|
? t.sidebar.elements.searchIn(category.label)
|
|
204
206
|
: t.sidebar.elements.searchElements;
|
|
205
|
-
const noResultsHint = panelHost?.noResultsHint?.(
|
|
207
|
+
const noResultsHint = panelHost?.noResultsHint?.(audience) ?? null;
|
|
206
208
|
const canDrag = !isMobile;
|
|
207
209
|
const selectedIllustration = cat === 'illustrationen' && props.selectedIllustrationId
|
|
208
210
|
? (props.illustrationInstances?.find((i) => i.id === props.selectedIllustrationId) ?? null)
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { AssetAudience } from '../../../utils/canvasAssets.js';
|
|
2
|
+
/**
|
|
3
|
+
* The document's own audience: the host's `deckLocale(pages)` (`registerEditorShell`),
|
|
4
|
+
* provided by the shell around the active sidebar section. `null` when the host
|
|
5
|
+
* registered none.
|
|
6
|
+
*/
|
|
7
|
+
export declare const DocumentAudienceContext: import("react").Context<AssetAudience | null>;
|
|
8
|
+
/**
|
|
9
|
+
* Whose assets the Elemente tab offers: the document's audience, else the user's
|
|
10
|
+
* locale — so a de-DE user editing a de-AT document gets the Austrian logos.
|
|
11
|
+
*/
|
|
12
|
+
export declare function useAssetAudience(): AssetAudience;
|