ok-canvas-export 1.0.4 → 1.0.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.
@@ -1,23 +0,0 @@
1
- /**
2
- * Downloads are handled elsewhere.
3
- *
4
- * This file contains SVG serialization and preparation utilities.
5
- */
6
- /**
7
- * Serializes an SVG element to a string.
8
- *
9
- * CSS custom properties are resolved using the current document styles.
10
- */
11
- export declare const serializeSvg: (svg: SVGSVGElement) => string;
12
- /**
13
- * Creates a Blob URL from SVG markup.
14
- */
15
- export declare const createSvgUrl: (svgMarkup: string) => string;
16
- /**
17
- * Creates a clean SVG clone for export.
18
- *
19
- * sourceX/sourceY represent the origin of the exported
20
- * coordinate system.
21
- */
22
- export declare const prepareSvgForExport: (sourceSvg: SVGSVGElement, width: number, height: number, background: "white" | "transparent", margin?: number, sourceX?: number, sourceY?: number) => SVGSVGElement;
23
- //# sourceMappingURL=serializer.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"serializer.d.ts","sourceRoot":"","sources":["../../src/utils/serializer.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;;GAIG;AACH,eAAO,MAAM,YAAY,GACvB,KAAK,aAAa,KACjB,MAwDF,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,YAAY,GACvB,WAAW,MAAM,KAChB,MAUF,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,mBAAmB,GAC9B,WAAW,aAAa,EACxB,OAAO,MAAM,EACb,QAAQ,MAAM,EACd,YAAY,OAAO,GAAG,aAAa,EACnC,SAAQ,MAAU,EAClB,UAAS,MAAU,EACnB,UAAS,MAAU,KAClB,aAuIF,CAAC"}
@@ -1,115 +0,0 @@
1
- /**
2
- * Downloads are handled elsewhere.
3
- *
4
- * This file contains SVG serialization and preparation utilities.
5
- */
6
- /**
7
- * Serializes an SVG element to a string.
8
- *
9
- * CSS custom properties are resolved using the current document styles.
10
- */
11
- export const serializeSvg = (svg) => {
12
- const serializer = new XMLSerializer();
13
- const styles = typeof document !== 'undefined'
14
- ? getComputedStyle(document.documentElement)
15
- : null;
16
- let markup = serializer.serializeToString(svg);
17
- /*
18
- * Resolve CSS custom properties.
19
- */
20
- if (styles) {
21
- markup = markup.replace(/var\(--([^)]+)\)/g, (_match, name) => {
22
- const value = styles
23
- .getPropertyValue(`--${name}`)
24
- ?.trim();
25
- return (value ||
26
- `var(--${name})`);
27
- });
28
- }
29
- /*
30
- * Ensure SVG has the proper namespace.
31
- */
32
- if (!markup.includes('xmlns="http://www.w3.org/2000/svg"')) {
33
- markup = markup.replace('<svg', '<svg xmlns="http://www.w3.org/2000/svg"');
34
- }
35
- return markup;
36
- };
37
- /**
38
- * Creates a Blob URL from SVG markup.
39
- */
40
- export const createSvgUrl = (svgMarkup) => {
41
- return URL.createObjectURL(new Blob([svgMarkup], {
42
- type: 'image/svg+xml;charset=utf-8',
43
- }));
44
- };
45
- /**
46
- * Creates a clean SVG clone for export.
47
- *
48
- * sourceX/sourceY represent the origin of the exported
49
- * coordinate system.
50
- */
51
- export const prepareSvgForExport = (sourceSvg, width, height, background, margin = 0, sourceX = 0, sourceY = 0) => {
52
- const clone = sourceSvg.cloneNode(true);
53
- /*
54
- * Remove viewport/background elements.
55
- */
56
- const bgNodes = clone.querySelectorAll('[data-export-bg="canvas"]');
57
- bgNodes.forEach((node) => {
58
- node.remove();
59
- });
60
- /*
61
- * Set final dimensions.
62
- */
63
- clone.setAttribute('width', String(width));
64
- clone.setAttribute('height', String(height));
65
- /*
66
- * The viewBox is what allows us to export content
67
- * that exists outside the original viewport.
68
- */
69
- clone.setAttribute('viewBox', `${sourceX} ${sourceY} ${width} ${height}`);
70
- /*
71
- * Prevent unexpected aspect-ratio behavior.
72
- */
73
- clone.setAttribute('preserveAspectRatio', 'xMinYMin meet');
74
- /*
75
- * Add explicit background.
76
- */
77
- if (background === 'white') {
78
- const whiteRect = document.createElementNS('http://www.w3.org/2000/svg', 'rect');
79
- whiteRect.setAttribute('x', String(sourceX));
80
- whiteRect.setAttribute('y', String(sourceY));
81
- whiteRect.setAttribute('width', String(width));
82
- whiteRect.setAttribute('height', String(height));
83
- whiteRect.setAttribute('fill', '#ffffff');
84
- /*
85
- * Keep background behind the diagram.
86
- */
87
- clone.insertBefore(whiteRect, clone.firstChild);
88
- }
89
- /*
90
- * Backwards compatibility:
91
- *
92
- * Older consumers/tests may call this function without
93
- * sourceX/sourceY and expect the old margin behavior.
94
- *
95
- * In the real export flow sourceX/sourceY are provided,
96
- * so we do NOT modify existing transforms.
97
- */
98
- if (margin > 0 &&
99
- sourceX === 0 &&
100
- sourceY === 0) {
101
- const scaledGroup = clone.querySelector('g[transform*="scale"]');
102
- if (scaledGroup) {
103
- const existingTransform = scaledGroup.getAttribute('transform') || '';
104
- /*
105
- * Preserve the original scale/transform.
106
- *
107
- * We prepend translate instead of replacing
108
- * the transform entirely.
109
- */
110
- scaledGroup.setAttribute('transform', `translate(${margin / 2}, ${margin / 2}) ${existingTransform}`);
111
- }
112
- }
113
- return clone;
114
- };
115
- //# sourceMappingURL=serializer.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"serializer.js","sourceRoot":"","sources":["../../src/utils/serializer.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;;GAIG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,CAC1B,GAAkB,EACV,EAAE;IACV,MAAM,UAAU,GACd,IAAI,aAAa,EAAE,CAAC;IAEtB,MAAM,MAAM,GACV,OAAO,QAAQ,KAAK,WAAW;QAC7B,CAAC,CAAC,gBAAgB,CACd,QAAQ,CAAC,eAAe,CACzB;QACH,CAAC,CAAC,IAAI,CAAC;IAEX,IAAI,MAAM,GACR,UAAU,CAAC,iBAAiB,CAC1B,GAAG,CACJ,CAAC;IAEJ;;OAEG;IACH,IAAI,MAAM,EAAE,CAAC;QACX,MAAM,GAAG,MAAM,CAAC,OAAO,CACrB,mBAAmB,EACnB,CACE,MAAM,EACN,IAAY,EACZ,E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