@trismegisto/charts 3.3.13 → 3.4.0
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/README.md +36 -25
- package/dist/core/bar-chart.d.ts +12 -0
- package/dist/core/bar-chart.js +30 -0
- package/dist/core/bar-chart.js.map +1 -0
- package/dist/core/boxplot-chart.d.ts +15 -0
- package/dist/core/boxplot-chart.js +45 -0
- package/dist/core/boxplot-chart.js.map +1 -0
- package/dist/core/bullet-chart.d.ts +29 -0
- package/dist/core/bullet-chart.js +95 -0
- package/dist/core/bullet-chart.js.map +1 -0
- package/dist/core/calendar-heatmap.d.ts +18 -0
- package/dist/core/calendar-heatmap.js +79 -0
- package/dist/core/calendar-heatmap.js.map +1 -0
- package/dist/core/chart-host.d.ts +19 -0
- package/dist/core/chart-host.js +109 -0
- package/dist/core/chart-host.js.map +1 -0
- package/dist/core/charts-i18n.d.ts +25 -0
- package/dist/core/charts-i18n.js +33 -0
- package/dist/core/charts-i18n.js.map +1 -0
- package/dist/core/charts-messages.d.ts +88 -0
- package/dist/core/charts-messages.en.d.ts +2 -0
- package/dist/core/charts-messages.en.js +106 -0
- package/dist/core/charts-messages.en.js.map +1 -0
- package/dist/core/charts-messages.es.d.ts +2 -0
- package/dist/core/charts-messages.es.js +106 -0
- package/dist/core/charts-messages.es.js.map +1 -0
- package/dist/core/charts-messages.js +106 -0
- package/dist/core/charts-messages.js.map +1 -0
- package/dist/core/context.d.ts +22 -0
- package/dist/core/context.js +13 -0
- package/dist/core/context.js.map +1 -0
- package/dist/core/engine-locale.d.ts +3 -0
- package/dist/core/engine-locale.js +59 -0
- package/dist/core/engine-locale.js.map +1 -0
- package/dist/core/format.d.ts +13 -0
- package/dist/core/format.js +64 -0
- package/dist/core/format.js.map +1 -0
- package/dist/core/frame.d.ts +19 -0
- package/dist/core/frame.js +28 -0
- package/dist/core/frame.js.map +1 -0
- package/dist/core/funnel-chart.d.ts +8 -0
- package/dist/core/funnel-chart.js +33 -0
- package/dist/core/funnel-chart.js.map +1 -0
- package/dist/core/gauge-chart.d.ts +44 -0
- package/dist/core/gauge-chart.js +218 -0
- package/dist/core/gauge-chart.js.map +1 -0
- package/dist/core/gauge-layout.d.ts +67 -0
- package/dist/core/gauge-layout.js +140 -0
- package/dist/core/gauge-layout.js.map +1 -0
- package/dist/core/heatmap-chart.d.ts +17 -0
- package/dist/core/heatmap-chart.js +55 -0
- package/dist/core/heatmap-chart.js.map +1 -0
- package/dist/core/index.d.ts +32 -0
- package/dist/core/index.js +38 -0
- package/dist/core/index.js.map +1 -0
- package/dist/core/line-chart.d.ts +12 -0
- package/dist/core/line-chart.js +29 -0
- package/dist/core/line-chart.js.map +1 -0
- package/dist/core/navigation.d.ts +25 -0
- package/dist/core/navigation.js +57 -0
- package/dist/core/navigation.js.map +1 -0
- package/dist/core/observe.d.ts +28 -0
- package/dist/core/observe.js +115 -0
- package/dist/core/observe.js.map +1 -0
- package/dist/core/options.d.ts +27 -0
- package/dist/core/options.js +64 -0
- package/dist/core/options.js.map +1 -0
- package/dist/core/pie-chart.d.ts +9 -0
- package/dist/core/pie-chart.js +34 -0
- package/dist/core/pie-chart.js.map +1 -0
- package/dist/core/radar-chart.d.ts +18 -0
- package/dist/core/radar-chart.js +34 -0
- package/dist/core/radar-chart.js.map +1 -0
- package/dist/core/sankey-chart.d.ts +15 -0
- package/dist/core/sankey-chart.js +32 -0
- package/dist/core/sankey-chart.js.map +1 -0
- package/dist/core/scatter-chart.d.ts +33 -0
- package/dist/core/scatter-chart.js +62 -0
- package/dist/core/scatter-chart.js.map +1 -0
- package/dist/core/sparkline-chart.d.ts +20 -0
- package/dist/core/sparkline-chart.js +60 -0
- package/dist/core/sparkline-chart.js.map +1 -0
- package/dist/core/stats.d.ts +12 -0
- package/dist/core/stats.js +23 -0
- package/dist/core/stats.js.map +1 -0
- package/dist/core/theme.d.ts +8 -0
- package/dist/core/theme.js +171 -0
- package/dist/core/theme.js.map +1 -0
- package/dist/core/treemap-chart.d.ts +21 -0
- package/dist/core/treemap-chart.js +45 -0
- package/dist/core/treemap-chart.js.map +1 -0
- package/dist/core/types.d.ts +10 -0
- package/dist/core/types.js +2 -0
- package/dist/core/types.js.map +1 -0
- package/dist/core/view.d.ts +24 -0
- package/dist/core/view.js +2 -0
- package/dist/core/view.js.map +1 -0
- package/dist/core/waterfall-chart.d.ts +32 -0
- package/dist/core/waterfall-chart.js +115 -0
- package/dist/core/waterfall-chart.js.map +1 -0
- package/dist/engine/aria.d.ts +8 -0
- package/dist/engine/aria.js +70 -0
- package/dist/engine/aria.js.map +1 -0
- package/dist/engine/component/legend.d.ts +11 -0
- package/dist/engine/component/legend.js +349 -0
- package/dist/engine/component/legend.js.map +1 -0
- package/dist/engine/component/text-style.d.ts +6 -0
- package/dist/engine/component/text-style.js +26 -0
- package/dist/engine/component/text-style.js.map +1 -0
- package/dist/engine/component/title.d.ts +2 -0
- package/dist/engine/component/title.js +90 -0
- package/dist/engine/component/title.js.map +1 -0
- package/dist/engine/component/tooltip.d.ts +40 -0
- package/dist/engine/component/tooltip.js +418 -0
- package/dist/engine/component/tooltip.js.map +1 -0
- package/dist/engine/component/visual-map.d.ts +9 -0
- package/dist/engine/component/visual-map.js +381 -0
- package/dist/engine/component/visual-map.js.map +1 -0
- package/dist/engine/contract.d.ts +504 -0
- package/dist/engine/contract.js +10 -0
- package/dist/engine/contract.js.map +1 -0
- package/dist/engine/coord/axis.d.ts +55 -0
- package/dist/engine/coord/axis.js +349 -0
- package/dist/engine/coord/axis.js.map +1 -0
- package/dist/engine/coord/calendar.d.ts +44 -0
- package/dist/engine/coord/calendar.js +282 -0
- package/dist/engine/coord/calendar.js.map +1 -0
- package/dist/engine/coord/cartesian.d.ts +22 -0
- package/dist/engine/coord/cartesian.js +449 -0
- package/dist/engine/coord/cartesian.js.map +1 -0
- package/dist/engine/coord/polar.d.ts +24 -0
- package/dist/engine/coord/polar.js +232 -0
- package/dist/engine/coord/polar.js.map +1 -0
- package/dist/engine/coord/radar.d.ts +90 -0
- package/dist/engine/coord/radar.js +288 -0
- package/dist/engine/coord/radar.js.map +1 -0
- package/dist/engine/index.d.ts +27 -0
- package/dist/engine/index.js +16 -0
- package/dist/engine/index.js.map +1 -0
- package/dist/engine/instance.d.ts +79 -0
- package/dist/engine/instance.js +773 -0
- package/dist/engine/instance.js.map +1 -0
- package/dist/engine/label-layout.d.ts +3 -0
- package/dist/engine/label-layout.js +35 -0
- package/dist/engine/label-layout.js.map +1 -0
- package/dist/engine/locale.d.ts +9 -0
- package/dist/engine/locale.js +154 -0
- package/dist/engine/locale.js.map +1 -0
- package/dist/engine/model.d.ts +26 -0
- package/dist/engine/model.js +307 -0
- package/dist/engine/model.js.map +1 -0
- package/dist/engine/option/axis.d.ts +167 -0
- package/dist/engine/option/axis.js +2 -0
- package/dist/engine/option/axis.js.map +1 -0
- package/dist/engine/option/components.d.ts +424 -0
- package/dist/engine/option/components.js +2 -0
- package/dist/engine/option/components.js.map +1 -0
- package/dist/engine/option.d.ts +59 -0
- package/dist/engine/option.js +2 -0
- package/dist/engine/option.js.map +1 -0
- package/dist/engine/registry.d.ts +9 -0
- package/dist/engine/registry.js +42 -0
- package/dist/engine/registry.js.map +1 -0
- package/dist/engine/render/path.d.ts +26 -0
- package/dist/engine/render/path.js +387 -0
- package/dist/engine/render/path.js.map +1 -0
- package/dist/engine/render/svg.d.ts +60 -0
- package/dist/engine/render/svg.js +624 -0
- package/dist/engine/render/svg.js.map +1 -0
- package/dist/engine/render/text.d.ts +13 -0
- package/dist/engine/render/text.js +144 -0
- package/dist/engine/render/text.js.map +1 -0
- package/dist/engine/scale.d.ts +38 -0
- package/dist/engine/scale.js +170 -0
- package/dist/engine/scale.js.map +1 -0
- package/dist/engine/series/bar.d.ts +65 -0
- package/dist/engine/series/bar.js +417 -0
- package/dist/engine/series/bar.js.map +1 -0
- package/dist/engine/series/boxplot.d.ts +31 -0
- package/dist/engine/series/boxplot.js +125 -0
- package/dist/engine/series/boxplot.js.map +1 -0
- package/dist/engine/series/cartesian-data.d.ts +38 -0
- package/dist/engine/series/cartesian-data.js +159 -0
- package/dist/engine/series/cartesian-data.js.map +1 -0
- package/dist/engine/series/circular-common.d.ts +51 -0
- package/dist/engine/series/circular-common.js +196 -0
- package/dist/engine/series/circular-common.js.map +1 -0
- package/dist/engine/series/circular-options.d.ts +151 -0
- package/dist/engine/series/circular-options.js +2 -0
- package/dist/engine/series/circular-options.js.map +1 -0
- package/dist/engine/series/common.d.ts +51 -0
- package/dist/engine/series/common.js +210 -0
- package/dist/engine/series/common.js.map +1 -0
- package/dist/engine/series/funnel.d.ts +37 -0
- package/dist/engine/series/funnel.js +204 -0
- package/dist/engine/series/funnel.js.map +1 -0
- package/dist/engine/series/gauge.d.ts +106 -0
- package/dist/engine/series/gauge.js +349 -0
- package/dist/engine/series/gauge.js.map +1 -0
- package/dist/engine/series/heatmap.d.ts +31 -0
- package/dist/engine/series/heatmap.js +222 -0
- package/dist/engine/series/heatmap.js.map +1 -0
- package/dist/engine/series/label-fit.d.ts +7 -0
- package/dist/engine/series/label-fit.js +56 -0
- package/dist/engine/series/label-fit.js.map +1 -0
- package/dist/engine/series/line.d.ts +63 -0
- package/dist/engine/series/line.js +347 -0
- package/dist/engine/series/line.js.map +1 -0
- package/dist/engine/series/pie.d.ts +59 -0
- package/dist/engine/series/pie.js +396 -0
- package/dist/engine/series/pie.js.map +1 -0
- package/dist/engine/series/radar.d.ts +34 -0
- package/dist/engine/series/radar.js +168 -0
- package/dist/engine/series/radar.js.map +1 -0
- package/dist/engine/series/sankey.d.ts +64 -0
- package/dist/engine/series/sankey.js +486 -0
- package/dist/engine/series/sankey.js.map +1 -0
- package/dist/engine/series/scatter.d.ts +38 -0
- package/dist/engine/series/scatter.js +167 -0
- package/dist/engine/series/scatter.js.map +1 -0
- package/dist/engine/series/treemap.d.ts +77 -0
- package/dist/engine/series/treemap.js +493 -0
- package/dist/engine/series/treemap.js.map +1 -0
- package/dist/engine/theme.d.ts +9 -0
- package/dist/engine/theme.js +84 -0
- package/dist/engine/theme.js.map +1 -0
- package/dist/engine/util.d.ts +68 -0
- package/dist/engine/util.js +269 -0
- package/dist/engine/util.js.map +1 -0
- package/package.json +35 -24
- package/fesm2022/trismegisto-charts.mjs +0 -12428
- package/fesm2022/trismegisto-charts.mjs.map +0 -1
- package/types/trismegisto-charts.d.ts +0 -1970
- package/types/trismegisto-charts.d.ts.map +0 -1
|
@@ -0,0 +1,624 @@
|
|
|
1
|
+
import { interpolateShape, shapeToPath } from './path';
|
|
2
|
+
import { DEFAULT_FONT_FAMILY, DEFAULT_FONT_SIZE, lineHeightOf, measureText } from './text';
|
|
3
|
+
const SVG_NS = 'http://www.w3.org/2000/svg';
|
|
4
|
+
let instanceCounter = 0;
|
|
5
|
+
const EASINGS = {
|
|
6
|
+
linear: (t) => t,
|
|
7
|
+
cubicOut: (t) => 1 - (1 - t) ** 3,
|
|
8
|
+
cubicInOut: (t) => (t < 0.5 ? 4 * t ** 3 : 1 - (-2 * t + 2) ** 3 / 2),
|
|
9
|
+
quadraticOut: (t) => 1 - (1 - t) ** 2,
|
|
10
|
+
exponentialOut: (t) => (t >= 1 ? 1 : 1 - 2 ** (-10 * t)),
|
|
11
|
+
backOut: (t) => 1 + 2.70158 * (t - 1) ** 3 + 1.70158 * (t - 1) ** 2,
|
|
12
|
+
elasticOut: (t) => (t === 0 || t === 1 ? t : 2 ** (-10 * t) * Math.sin(((t * 10 - 0.75) * 2 * Math.PI) / 3) + 1),
|
|
13
|
+
};
|
|
14
|
+
export class SvgRenderer {
|
|
15
|
+
host;
|
|
16
|
+
svg;
|
|
17
|
+
defs;
|
|
18
|
+
root;
|
|
19
|
+
doc;
|
|
20
|
+
entries = new Map();
|
|
21
|
+
nodeOf = new WeakMap();
|
|
22
|
+
defsUsed = new Set();
|
|
23
|
+
defsMade = new Map();
|
|
24
|
+
prefix = `hmc${++instanceCounter}-`;
|
|
25
|
+
frame = 0;
|
|
26
|
+
settings = { animate: false, duration: 0, durationUpdate: 0, easing: 'cubicOut', easingUpdate: 'cubicInOut' };
|
|
27
|
+
keyCounts = new Map();
|
|
28
|
+
listeners = [];
|
|
29
|
+
animating = new Set();
|
|
30
|
+
/** Chamado quando as animações terminam (evento `finished`). */
|
|
31
|
+
onFinished = () => { };
|
|
32
|
+
constructor(host, callbacks) {
|
|
33
|
+
this.host = host;
|
|
34
|
+
this.doc = host.ownerDocument;
|
|
35
|
+
this.svg = this.doc.createElementNS(SVG_NS, 'svg');
|
|
36
|
+
this.svg.setAttribute('xmlns', SVG_NS);
|
|
37
|
+
this.svg.setAttribute('version', '1.1');
|
|
38
|
+
this.svg.style.display = 'block';
|
|
39
|
+
this.svg.style.userSelect = 'none';
|
|
40
|
+
this.svg.style.overflow = 'hidden';
|
|
41
|
+
this.defs = this.doc.createElementNS(SVG_NS, 'defs');
|
|
42
|
+
this.root = this.doc.createElementNS(SVG_NS, 'g');
|
|
43
|
+
this.svg.append(this.defs, this.root);
|
|
44
|
+
host.appendChild(this.svg);
|
|
45
|
+
const point = (e) => {
|
|
46
|
+
const r = this.svg.getBoundingClientRect();
|
|
47
|
+
return [e.clientX - r.left, e.clientY - r.top];
|
|
48
|
+
};
|
|
49
|
+
const on = (type, fn) => {
|
|
50
|
+
const listener = fn;
|
|
51
|
+
this.svg.addEventListener(type, listener);
|
|
52
|
+
this.listeners.push([type, listener]);
|
|
53
|
+
};
|
|
54
|
+
on('mousemove', (e) => callbacks.onPointer(this.itemAt(e.target), ...point(e), e));
|
|
55
|
+
on('click', (e) => callbacks.onClick(this.itemAt(e.target), ...point(e), e));
|
|
56
|
+
on('mouseleave', (e) => callbacks.onLeave(e));
|
|
57
|
+
}
|
|
58
|
+
setSize(width, height) {
|
|
59
|
+
this.svg.setAttribute('width', String(width));
|
|
60
|
+
this.svg.setAttribute('height', String(height));
|
|
61
|
+
this.svg.setAttribute('viewBox', `0 0 ${width} ${height}`);
|
|
62
|
+
}
|
|
63
|
+
/** Rótulo acessível do SVG (descrição do gráfico) ou `null` para tirá-lo da árvore de acessibilidade. */
|
|
64
|
+
setLabel(label) {
|
|
65
|
+
if (label) {
|
|
66
|
+
this.svg.setAttribute('role', 'img');
|
|
67
|
+
this.svg.setAttribute('aria-label', label);
|
|
68
|
+
this.svg.removeAttribute('aria-hidden');
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
this.svg.removeAttribute('role');
|
|
72
|
+
this.svg.removeAttribute('aria-label');
|
|
73
|
+
this.svg.setAttribute('aria-hidden', 'true');
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
setBackground(color) {
|
|
77
|
+
this.svg.style.backgroundColor = color && color !== 'transparent' ? color : '';
|
|
78
|
+
}
|
|
79
|
+
/** Item de série (ou componente) sob um elemento: sobe até achar um nó com `item` que não seja `silent`. */
|
|
80
|
+
itemAt(target) {
|
|
81
|
+
let el = target;
|
|
82
|
+
while (el && el !== this.svg) {
|
|
83
|
+
const entry = this.nodeOf.get(el);
|
|
84
|
+
if (entry && entry.node.item && !entry.node.silent)
|
|
85
|
+
return entry.node.item;
|
|
86
|
+
el = el.parentElement;
|
|
87
|
+
}
|
|
88
|
+
return null;
|
|
89
|
+
}
|
|
90
|
+
render(nodes, settings) {
|
|
91
|
+
this.settings = settings;
|
|
92
|
+
for (const entry of this.entries.values())
|
|
93
|
+
entry.seen = false;
|
|
94
|
+
this.defsUsed.clear();
|
|
95
|
+
this.keyCounts.clear();
|
|
96
|
+
this.reconcile(this.root, nodes);
|
|
97
|
+
for (const [key, entry] of this.entries) {
|
|
98
|
+
if (entry.seen)
|
|
99
|
+
continue;
|
|
100
|
+
entry.el.remove();
|
|
101
|
+
entry.decalEl?.remove();
|
|
102
|
+
this.animating.delete(entry);
|
|
103
|
+
this.entries.delete(key);
|
|
104
|
+
}
|
|
105
|
+
for (const [id, el] of this.defsMade) {
|
|
106
|
+
if (!this.defsUsed.has(id)) {
|
|
107
|
+
el.remove();
|
|
108
|
+
this.defsMade.delete(id);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
if (this.animating.size)
|
|
112
|
+
this.schedule();
|
|
113
|
+
else
|
|
114
|
+
this.onFinished();
|
|
115
|
+
}
|
|
116
|
+
toString() {
|
|
117
|
+
return new XMLSerializer().serializeToString(this.svg);
|
|
118
|
+
}
|
|
119
|
+
dispose() {
|
|
120
|
+
if (this.frame)
|
|
121
|
+
cancelAnimationFrame(this.frame);
|
|
122
|
+
for (const [type, l] of this.listeners)
|
|
123
|
+
this.svg.removeEventListener(type, l);
|
|
124
|
+
this.svg.remove();
|
|
125
|
+
this.entries.clear();
|
|
126
|
+
}
|
|
127
|
+
// ---------------------------------------------------------------- árvore
|
|
128
|
+
uniqueKey(key) {
|
|
129
|
+
const count = this.keyCounts.get(key) ?? 0;
|
|
130
|
+
this.keyCounts.set(key, count + 1);
|
|
131
|
+
return count ? `${key}#${count}` : key;
|
|
132
|
+
}
|
|
133
|
+
reconcile(parent, nodes) {
|
|
134
|
+
// Ordem por z (estável): o que tem z maior fica por cima.
|
|
135
|
+
const ordered = nodes.map((node, i) => ({ node, i })).sort((a, b) => (a.node.z ?? 0) - (b.node.z ?? 0) || a.i - b.i);
|
|
136
|
+
let cursor = parent.firstChild;
|
|
137
|
+
for (const { node } of ordered) {
|
|
138
|
+
const key = this.uniqueKey(node.key);
|
|
139
|
+
let entry = this.entries.get(key);
|
|
140
|
+
const boxed = node.kind === 'text' && hasTextBox(node.style);
|
|
141
|
+
if (entry && (entry.kind !== node.kind || (node.kind === 'text' && entry.boxed !== boxed))) {
|
|
142
|
+
entry.el.remove();
|
|
143
|
+
entry.decalEl?.remove();
|
|
144
|
+
this.entries.delete(key);
|
|
145
|
+
entry = undefined;
|
|
146
|
+
}
|
|
147
|
+
const isNew = !entry;
|
|
148
|
+
if (!entry) {
|
|
149
|
+
const tag = node.kind === 'group' || boxed ? 'g' : node.kind === 'path' ? 'path' : 'text';
|
|
150
|
+
const el = this.doc.createElementNS(SVG_NS, tag);
|
|
151
|
+
entry = { key, kind: node.kind, el, node, opacity: 1, seen: true, boxed };
|
|
152
|
+
this.entries.set(key, entry);
|
|
153
|
+
this.nodeOf.set(el, entry);
|
|
154
|
+
}
|
|
155
|
+
entry.seen = true;
|
|
156
|
+
const previous = entry.node;
|
|
157
|
+
entry.node = node;
|
|
158
|
+
// Posição na ordem certa (sem mexer em quem já está no lugar).
|
|
159
|
+
if (cursor !== entry.el)
|
|
160
|
+
parent.insertBefore(entry.el, cursor);
|
|
161
|
+
cursor = entry.el.nextSibling;
|
|
162
|
+
if (node.kind === 'path') {
|
|
163
|
+
this.updatePath(entry, node, isNew, previous);
|
|
164
|
+
if (entry.decalEl) {
|
|
165
|
+
if (cursor !== entry.decalEl)
|
|
166
|
+
parent.insertBefore(entry.decalEl, cursor);
|
|
167
|
+
cursor = entry.decalEl.nextSibling;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
else if (node.kind === 'text')
|
|
171
|
+
this.updateText(entry, node, isNew);
|
|
172
|
+
else
|
|
173
|
+
this.updateGroup(entry, node);
|
|
174
|
+
this.applyCommon(entry.el, node);
|
|
175
|
+
}
|
|
176
|
+
// O que sobrou depois do cursor não está mais na cena deste pai: sai no fim (entradas não vistas).
|
|
177
|
+
}
|
|
178
|
+
applyCommon(el, node) {
|
|
179
|
+
const t = node.transform;
|
|
180
|
+
// Símbolo com `rotate` (graus, sentido anti-horário, como `symbolRotate`) gira em torno do próprio centro.
|
|
181
|
+
const symbolRotate = node.kind === 'path' && node.shape.type === 'symbol' && node.shape.rotate ? node.shape : null;
|
|
182
|
+
if ((t || symbolRotate) && node.kind !== 'text') {
|
|
183
|
+
const parts = [];
|
|
184
|
+
if (symbolRotate && symbolRotate.type === 'symbol')
|
|
185
|
+
parts.push(`rotate(${num(-(symbolRotate.rotate ?? 0))} ${num(symbolRotate.x)} ${num(symbolRotate.y)})`);
|
|
186
|
+
if (!t) {
|
|
187
|
+
setAttr(el, 'transform', parts.join(' '));
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
if (t && node.kind !== 'text') {
|
|
191
|
+
const parts = symbolRotate && symbolRotate.type === 'symbol' ? [`rotate(${num(-(symbolRotate.rotate ?? 0))} ${num(symbolRotate.x)} ${num(symbolRotate.y)})`] : [];
|
|
192
|
+
if (t.x || t.y)
|
|
193
|
+
parts.push(`translate(${num(t.x ?? 0)} ${num(t.y ?? 0)})`);
|
|
194
|
+
if (t.rotation || (t.scaleX ?? 1) !== 1 || (t.scaleY ?? 1) !== 1) {
|
|
195
|
+
const ox = t.originX ?? 0;
|
|
196
|
+
const oy = t.originY ?? 0;
|
|
197
|
+
if (ox || oy)
|
|
198
|
+
parts.push(`translate(${num(ox)} ${num(oy)})`);
|
|
199
|
+
if (t.rotation)
|
|
200
|
+
parts.push(`rotate(${num((t.rotation * 180) / Math.PI)})`);
|
|
201
|
+
if ((t.scaleX ?? 1) !== 1 || (t.scaleY ?? 1) !== 1)
|
|
202
|
+
parts.push(`scale(${num(t.scaleX ?? 1)} ${num(t.scaleY ?? 1)})`);
|
|
203
|
+
if (ox || oy)
|
|
204
|
+
parts.push(`translate(${num(-ox)} ${num(-oy)})`);
|
|
205
|
+
}
|
|
206
|
+
// A rotação do símbolo vem por último (aplicada primeiro, no espaço do próprio nó). Só ela muda de lugar:
|
|
207
|
+
// sem rotação de símbolo, a ordem translate(origem) → rotate → translate(-origem) fica como está.
|
|
208
|
+
if (symbolRotate) {
|
|
209
|
+
const own = parts.shift();
|
|
210
|
+
if (own)
|
|
211
|
+
parts.push(own);
|
|
212
|
+
}
|
|
213
|
+
setAttr(el, 'transform', parts.join(' ') || null);
|
|
214
|
+
}
|
|
215
|
+
else if (node.kind !== 'text' && !symbolRotate)
|
|
216
|
+
setAttr(el, 'transform', null);
|
|
217
|
+
setAttr(el, 'aria-hidden', node.ariaHidden ? 'true' : null);
|
|
218
|
+
setAttr(el, 'class', node.className ?? null);
|
|
219
|
+
if (node.silent)
|
|
220
|
+
el.style.pointerEvents = 'none';
|
|
221
|
+
else {
|
|
222
|
+
el.style.pointerEvents = '';
|
|
223
|
+
el.style.cursor = node.cursor ?? (node.item && node.item.componentType !== 'title' ? 'pointer' : '');
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
updateGroup(entry, node) {
|
|
227
|
+
if (node.clip) {
|
|
228
|
+
const id = this.clipPath(node.key, node.clip);
|
|
229
|
+
setAttr(entry.el, 'clip-path', `url(#${id})`);
|
|
230
|
+
}
|
|
231
|
+
else
|
|
232
|
+
setAttr(entry.el, 'clip-path', null);
|
|
233
|
+
this.reconcile(entry.el, node.children);
|
|
234
|
+
}
|
|
235
|
+
// ---------------------------------------------------------------- caminhos
|
|
236
|
+
updatePath(entry, node, isNew, previous) {
|
|
237
|
+
const el = entry.el;
|
|
238
|
+
const style = node.style;
|
|
239
|
+
this.applyFillStyle(el, style, node.key);
|
|
240
|
+
const targetOpacity = style.opacity ?? 1;
|
|
241
|
+
const anim = node.animation;
|
|
242
|
+
const s = this.settings;
|
|
243
|
+
const lineWidth = style.stroke ? (style.lineWidth ?? 1) : 0;
|
|
244
|
+
let tween;
|
|
245
|
+
if (s.animate && anim !== false) {
|
|
246
|
+
if (isNew && anim?.from) {
|
|
247
|
+
const fromShape = anim.from.shape ? { ...node.shape, ...anim.from.shape } : undefined;
|
|
248
|
+
tween = {
|
|
249
|
+
start: now(),
|
|
250
|
+
delay: anim.delay ?? 0,
|
|
251
|
+
duration: anim.duration ?? s.duration,
|
|
252
|
+
easing: anim.easing ?? s.easing,
|
|
253
|
+
fromShape,
|
|
254
|
+
toShape: fromShape ? node.shape : undefined,
|
|
255
|
+
fromOpacity: anim.from.style?.opacity,
|
|
256
|
+
toOpacity: anim.from.style?.opacity !== undefined ? targetOpacity : undefined,
|
|
257
|
+
};
|
|
258
|
+
}
|
|
259
|
+
else if (!isNew && entry.shape && !sameShape(entry.shape, node.shape) && previous.kind === 'path') {
|
|
260
|
+
tween = { start: now(), delay: 0, duration: anim?.duration ?? s.durationUpdate, easing: s.easingUpdate, fromShape: entry.shape, toShape: node.shape };
|
|
261
|
+
}
|
|
262
|
+
if (!isNew && entry.opacity !== targetOpacity) {
|
|
263
|
+
tween = tween ?? { start: now(), delay: 0, duration: s.durationUpdate, easing: s.easingUpdate };
|
|
264
|
+
tween.fromOpacity = entry.opacity;
|
|
265
|
+
tween.toOpacity = targetOpacity;
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
if (tween && tween.duration > 0) {
|
|
269
|
+
entry.tween = tween;
|
|
270
|
+
this.animating.add(entry);
|
|
271
|
+
this.applyFrame(entry, 0);
|
|
272
|
+
}
|
|
273
|
+
else {
|
|
274
|
+
entry.tween = undefined;
|
|
275
|
+
this.animating.delete(entry);
|
|
276
|
+
entry.shape = node.shape;
|
|
277
|
+
entry.opacity = targetOpacity;
|
|
278
|
+
setAttr(el, 'd', shapeToPath(node.shape, lineWidth) || 'M0 0');
|
|
279
|
+
setAttr(el, 'opacity', targetOpacity === 1 ? null : num(targetOpacity));
|
|
280
|
+
}
|
|
281
|
+
// Padrão de acessibilidade (decal): um segundo caminho por cima, com o padrão.
|
|
282
|
+
if (style.decal) {
|
|
283
|
+
if (!entry.decalEl) {
|
|
284
|
+
entry.decalEl = this.doc.createElementNS(SVG_NS, 'path');
|
|
285
|
+
entry.decalEl.setAttribute('aria-hidden', 'true');
|
|
286
|
+
entry.decalEl.style.pointerEvents = 'none';
|
|
287
|
+
this.nodeOf.set(entry.decalEl, entry);
|
|
288
|
+
}
|
|
289
|
+
setAttr(entry.decalEl, 'fill', `url(#${this.pattern(style.decal)})`);
|
|
290
|
+
setAttr(entry.decalEl, 'd', el.getAttribute('d'));
|
|
291
|
+
}
|
|
292
|
+
else if (entry.decalEl) {
|
|
293
|
+
entry.decalEl.remove();
|
|
294
|
+
entry.decalEl = undefined;
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
applyFillStyle(el, style, key) {
|
|
298
|
+
setAttr(el, 'fill', style.fill === undefined || style.fill === 'none' ? 'none' : this.paint(style.fill, key, 'fill'));
|
|
299
|
+
setAttr(el, 'stroke', style.stroke === undefined || style.stroke === 'none' ? null : this.paint(style.stroke, key, 'stroke'));
|
|
300
|
+
const hasStroke = style.stroke !== undefined && style.stroke !== 'none';
|
|
301
|
+
setAttr(el, 'stroke-width', hasStroke ? num(style.lineWidth ?? 1) : null);
|
|
302
|
+
setAttr(el, 'fill-opacity', style.fillOpacity === undefined || style.fillOpacity === 1 ? null : num(style.fillOpacity));
|
|
303
|
+
setAttr(el, 'stroke-opacity', style.strokeOpacity === undefined || style.strokeOpacity === 1 ? null : num(style.strokeOpacity));
|
|
304
|
+
setAttr(el, 'stroke-dasharray', hasStroke && style.lineDash?.length ? style.lineDash.map(num).join(' ') : null);
|
|
305
|
+
setAttr(el, 'stroke-dashoffset', hasStroke && style.lineDashOffset ? num(style.lineDashOffset) : null);
|
|
306
|
+
setAttr(el, 'stroke-linecap', hasStroke && style.lineCap && style.lineCap !== 'butt' ? style.lineCap : null);
|
|
307
|
+
setAttr(el, 'stroke-linejoin', hasStroke && style.lineJoin && style.lineJoin !== 'miter' ? style.lineJoin : null);
|
|
308
|
+
setAttr(el, 'filter', style.shadowBlur || style.shadowOffsetX || style.shadowOffsetY ? `url(#${this.shadow(style)})` : null);
|
|
309
|
+
}
|
|
310
|
+
// ---------------------------------------------------------------- texto
|
|
311
|
+
updateText(entry, node, isNew) {
|
|
312
|
+
const s = this.settings;
|
|
313
|
+
const target = [node.x, node.y];
|
|
314
|
+
const anim = node.animation;
|
|
315
|
+
if (s.animate && anim !== false && !isNew && entry.xy && (entry.xy[0] !== target[0] || entry.xy[1] !== target[1])) {
|
|
316
|
+
entry.tween = { start: now(), delay: 0, duration: s.durationUpdate, easing: s.easingUpdate, fromXY: entry.xy, toXY: target };
|
|
317
|
+
this.animating.add(entry);
|
|
318
|
+
}
|
|
319
|
+
else if (s.animate && anim && isNew && anim.from?.style?.opacity !== undefined) {
|
|
320
|
+
entry.tween = { start: now(), delay: anim.delay ?? 0, duration: anim.duration ?? s.duration, easing: anim.easing ?? s.easing, fromOpacity: anim.from.style.opacity, toOpacity: node.style.opacity ?? 1 };
|
|
321
|
+
this.animating.add(entry);
|
|
322
|
+
}
|
|
323
|
+
else {
|
|
324
|
+
entry.tween = undefined;
|
|
325
|
+
this.animating.delete(entry);
|
|
326
|
+
}
|
|
327
|
+
this.drawText(entry, node, entry.tween?.fromXY ?? target);
|
|
328
|
+
entry.xy = entry.tween?.fromXY ?? target;
|
|
329
|
+
if (!entry.tween)
|
|
330
|
+
entry.xy = target;
|
|
331
|
+
entry.opacity = node.style.opacity ?? 1;
|
|
332
|
+
if (entry.tween?.fromOpacity !== undefined)
|
|
333
|
+
setAttr(entry.el, 'opacity', num(entry.tween.fromOpacity));
|
|
334
|
+
}
|
|
335
|
+
drawText(entry, node, [x, y]) {
|
|
336
|
+
const style = node.style;
|
|
337
|
+
const fontSize = style.fontSize ?? DEFAULT_FONT_SIZE;
|
|
338
|
+
const measured = measureText(node.text, style);
|
|
339
|
+
const lh = lineHeightOf(style);
|
|
340
|
+
const [pt, pr, pb, pl] = padding(style.padding);
|
|
341
|
+
const align = style.align ?? 'left';
|
|
342
|
+
const valign = style.verticalAlign ?? 'top';
|
|
343
|
+
const blockH = measured.height;
|
|
344
|
+
const top = (valign === 'middle' ? y - blockH / 2 : valign === 'bottom' ? y - blockH : y) + (valign === 'top' ? pt : valign === 'bottom' ? -pb : (pt - pb) / 2);
|
|
345
|
+
const anchorX = x + (align === 'left' ? pl : align === 'right' ? -pr : (pl - pr) / 2);
|
|
346
|
+
const text = (entry.boxed ? entry.el.lastChild : entry.el);
|
|
347
|
+
let textEl = text;
|
|
348
|
+
if (entry.boxed) {
|
|
349
|
+
let rect = entry.el.firstChild;
|
|
350
|
+
if (!rect || rect.tagName !== 'rect') {
|
|
351
|
+
entry.el.textContent = '';
|
|
352
|
+
rect = this.doc.createElementNS(SVG_NS, 'rect');
|
|
353
|
+
textEl = this.doc.createElementNS(SVG_NS, 'text');
|
|
354
|
+
entry.el.append(rect, textEl);
|
|
355
|
+
}
|
|
356
|
+
const boxW = measured.width + pl + pr;
|
|
357
|
+
const boxH = blockH + pt + pb;
|
|
358
|
+
const left = (align === 'left' ? x : align === 'right' ? x - boxW : x - boxW / 2);
|
|
359
|
+
const boxTop = top - pt;
|
|
360
|
+
setAttr(rect, 'x', num(left));
|
|
361
|
+
setAttr(rect, 'y', num(boxTop));
|
|
362
|
+
setAttr(rect, 'width', num(boxW));
|
|
363
|
+
setAttr(rect, 'height', num(boxH));
|
|
364
|
+
setAttr(rect, 'rx', style.borderRadius ? num(style.borderRadius) : null);
|
|
365
|
+
setAttr(rect, 'fill', style.backgroundColor ?? 'none');
|
|
366
|
+
setAttr(rect, 'stroke', style.borderColor ?? null);
|
|
367
|
+
setAttr(rect, 'stroke-width', style.borderColor ? num(style.borderWidth ?? 1) : null);
|
|
368
|
+
}
|
|
369
|
+
const el = textEl;
|
|
370
|
+
setAttr(el, 'text-anchor', align === 'center' ? 'middle' : align === 'right' ? 'end' : null);
|
|
371
|
+
setAttr(el, 'font-size', num(fontSize));
|
|
372
|
+
setAttr(el, 'font-family', style.fontFamily ?? DEFAULT_FONT_FAMILY);
|
|
373
|
+
setAttr(el, 'font-weight', style.fontWeight !== undefined && style.fontWeight !== 'normal' ? String(style.fontWeight) : null);
|
|
374
|
+
setAttr(el, 'font-style', style.fontStyle && style.fontStyle !== 'normal' ? style.fontStyle : null);
|
|
375
|
+
setAttr(el, 'fill', style.color ?? '#333');
|
|
376
|
+
setAttr(el, 'opacity', style.opacity !== undefined && style.opacity !== 1 ? num(style.opacity) : null);
|
|
377
|
+
if (style.textBorderColor && (style.textBorderWidth ?? 0) > 0) {
|
|
378
|
+
setAttr(el, 'stroke', style.textBorderColor);
|
|
379
|
+
setAttr(el, 'stroke-width', num((style.textBorderWidth ?? 0) * 2));
|
|
380
|
+
setAttr(el, 'paint-order', 'stroke');
|
|
381
|
+
setAttr(el, 'stroke-linejoin', 'round');
|
|
382
|
+
}
|
|
383
|
+
else {
|
|
384
|
+
setAttr(el, 'stroke', null);
|
|
385
|
+
setAttr(el, 'stroke-width', null);
|
|
386
|
+
setAttr(el, 'paint-order', null);
|
|
387
|
+
}
|
|
388
|
+
const holder = entry.boxed ? entry.el : el;
|
|
389
|
+
setAttr(holder, 'transform', node.rotate ? `rotate(${num(-node.rotate)} ${num(x)} ${num(y)})` : null);
|
|
390
|
+
// Linha de base calculada (sem `dominant-baseline`, que varia entre navegadores).
|
|
391
|
+
const baseline = (i) => top + i * lh + (lh - fontSize) / 2 + fontSize * 0.82;
|
|
392
|
+
const lines = measured.lines;
|
|
393
|
+
if (lines.length === 1) {
|
|
394
|
+
if (el.childNodes.length !== 1 || el.firstChild?.nodeType !== 3)
|
|
395
|
+
el.textContent = lines[0];
|
|
396
|
+
else if (el.textContent !== lines[0])
|
|
397
|
+
el.textContent = lines[0];
|
|
398
|
+
setAttr(el, 'x', num(anchorX));
|
|
399
|
+
setAttr(el, 'y', num(baseline(0)));
|
|
400
|
+
}
|
|
401
|
+
else {
|
|
402
|
+
el.textContent = '';
|
|
403
|
+
el.removeAttribute('x');
|
|
404
|
+
el.removeAttribute('y');
|
|
405
|
+
lines.forEach((line, i) => {
|
|
406
|
+
const tspan = this.doc.createElementNS(SVG_NS, 'tspan');
|
|
407
|
+
tspan.setAttribute('x', num(anchorX));
|
|
408
|
+
tspan.setAttribute('y', num(baseline(i)));
|
|
409
|
+
tspan.textContent = line;
|
|
410
|
+
el.appendChild(tspan);
|
|
411
|
+
});
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
// ---------------------------------------------------------------- animação
|
|
415
|
+
schedule() {
|
|
416
|
+
if (this.frame)
|
|
417
|
+
return;
|
|
418
|
+
const raf = typeof requestAnimationFrame === 'function' ? requestAnimationFrame : null;
|
|
419
|
+
if (!raf) {
|
|
420
|
+
for (const entry of this.animating)
|
|
421
|
+
this.applyFrame(entry, Number.POSITIVE_INFINITY);
|
|
422
|
+
this.animating.clear();
|
|
423
|
+
this.onFinished();
|
|
424
|
+
return;
|
|
425
|
+
}
|
|
426
|
+
this.frame = raf(() => {
|
|
427
|
+
this.frame = 0;
|
|
428
|
+
const t = now();
|
|
429
|
+
for (const entry of [...this.animating]) {
|
|
430
|
+
if (this.applyFrame(entry, t))
|
|
431
|
+
this.animating.delete(entry);
|
|
432
|
+
}
|
|
433
|
+
if (this.animating.size)
|
|
434
|
+
this.schedule();
|
|
435
|
+
else
|
|
436
|
+
this.onFinished();
|
|
437
|
+
});
|
|
438
|
+
}
|
|
439
|
+
/** Desenha o quadro `time` da animação do nó; `true` quando acabou. */
|
|
440
|
+
applyFrame(entry, time) {
|
|
441
|
+
const tw = entry.tween;
|
|
442
|
+
if (!tw)
|
|
443
|
+
return true;
|
|
444
|
+
const elapsed = time - tw.start - tw.delay;
|
|
445
|
+
const raw = tw.duration > 0 ? Math.max(0, Math.min(1, elapsed / tw.duration)) : 1;
|
|
446
|
+
const k = EASINGS[tw.easing]?.(raw) ?? raw;
|
|
447
|
+
const node = entry.node;
|
|
448
|
+
if (node.kind === 'path') {
|
|
449
|
+
const lineWidth = node.style.stroke ? (node.style.lineWidth ?? 1) : 0;
|
|
450
|
+
if (tw.fromShape && tw.toShape) {
|
|
451
|
+
const shape = interpolateShape(tw.fromShape, tw.toShape, k);
|
|
452
|
+
entry.shape = shape;
|
|
453
|
+
setAttr(entry.el, 'd', shapeToPath(shape, lineWidth) || 'M0 0');
|
|
454
|
+
if (entry.decalEl)
|
|
455
|
+
setAttr(entry.decalEl, 'd', entry.el.getAttribute('d'));
|
|
456
|
+
}
|
|
457
|
+
else {
|
|
458
|
+
entry.shape = node.shape;
|
|
459
|
+
setAttr(entry.el, 'd', shapeToPath(node.shape, lineWidth) || 'M0 0');
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
else if (node.kind === 'text' && tw.fromXY && tw.toXY) {
|
|
463
|
+
const xy = [tw.fromXY[0] + (tw.toXY[0] - tw.fromXY[0]) * k, tw.fromXY[1] + (tw.toXY[1] - tw.fromXY[1]) * k];
|
|
464
|
+
entry.xy = xy;
|
|
465
|
+
this.drawText(entry, node, xy);
|
|
466
|
+
}
|
|
467
|
+
if (tw.fromOpacity !== undefined && tw.toOpacity !== undefined) {
|
|
468
|
+
const o = tw.fromOpacity + (tw.toOpacity - tw.fromOpacity) * k;
|
|
469
|
+
entry.opacity = o;
|
|
470
|
+
setAttr(entry.el, 'opacity', o >= 1 ? null : num(o));
|
|
471
|
+
}
|
|
472
|
+
if (raw >= 1) {
|
|
473
|
+
entry.tween = undefined;
|
|
474
|
+
return true;
|
|
475
|
+
}
|
|
476
|
+
return false;
|
|
477
|
+
}
|
|
478
|
+
// ---------------------------------------------------------------- defs
|
|
479
|
+
def(id, make) {
|
|
480
|
+
const full = this.prefix + id;
|
|
481
|
+
this.defsUsed.add(full);
|
|
482
|
+
if (!this.defsMade.has(full)) {
|
|
483
|
+
const el = make();
|
|
484
|
+
el.setAttribute('id', full);
|
|
485
|
+
this.defs.appendChild(el);
|
|
486
|
+
this.defsMade.set(full, el);
|
|
487
|
+
}
|
|
488
|
+
return full;
|
|
489
|
+
}
|
|
490
|
+
paint(paint, key, role) {
|
|
491
|
+
if (typeof paint === 'string')
|
|
492
|
+
return paint;
|
|
493
|
+
const id = `g${hash(JSON.stringify(paint))}`;
|
|
494
|
+
void key;
|
|
495
|
+
void role;
|
|
496
|
+
return `url(#${this.def(id, () => this.gradient(paint))})`;
|
|
497
|
+
}
|
|
498
|
+
gradient(g) {
|
|
499
|
+
const el = this.doc.createElementNS(SVG_NS, g.type === 'radial' ? 'radialGradient' : 'linearGradient');
|
|
500
|
+
if (g.global)
|
|
501
|
+
el.setAttribute('gradientUnits', 'userSpaceOnUse');
|
|
502
|
+
if (g.type === 'radial') {
|
|
503
|
+
el.setAttribute('cx', num(g.x ?? 0.5));
|
|
504
|
+
el.setAttribute('cy', num(g.y ?? 0.5));
|
|
505
|
+
el.setAttribute('r', num(g.r ?? 0.5));
|
|
506
|
+
}
|
|
507
|
+
else {
|
|
508
|
+
el.setAttribute('x1', num(g.x ?? 0));
|
|
509
|
+
el.setAttribute('y1', num(g.y ?? 0));
|
|
510
|
+
el.setAttribute('x2', num(g.x2 ?? 1));
|
|
511
|
+
el.setAttribute('y2', num(g.y2 ?? 0));
|
|
512
|
+
}
|
|
513
|
+
for (const stop of g.colorStops) {
|
|
514
|
+
const s = this.doc.createElementNS(SVG_NS, 'stop');
|
|
515
|
+
s.setAttribute('offset', num(stop.offset));
|
|
516
|
+
s.setAttribute('stop-color', stop.color);
|
|
517
|
+
el.appendChild(s);
|
|
518
|
+
}
|
|
519
|
+
return el;
|
|
520
|
+
}
|
|
521
|
+
pattern(decal) {
|
|
522
|
+
const id = `p${hash(JSON.stringify(decal))}`;
|
|
523
|
+
return this.def(id, () => {
|
|
524
|
+
const size = Math.max(4, decal.size);
|
|
525
|
+
const p = this.doc.createElementNS(SVG_NS, 'pattern');
|
|
526
|
+
p.setAttribute('patternUnits', 'userSpaceOnUse');
|
|
527
|
+
p.setAttribute('width', num(size));
|
|
528
|
+
p.setAttribute('height', num(size));
|
|
529
|
+
if (decal.rotation)
|
|
530
|
+
p.setAttribute('patternTransform', `rotate(${num((decal.rotation * 180) / Math.PI)})`);
|
|
531
|
+
const shape = this.doc.createElementNS(SVG_NS, 'path');
|
|
532
|
+
const c = size / 2;
|
|
533
|
+
const r = size / 4;
|
|
534
|
+
const d = {
|
|
535
|
+
rect: `M${c - r} ${c - r}h${2 * r}v${2 * r}h${-2 * r}Z`,
|
|
536
|
+
circle: `M${c - r} ${c}a${r} ${r} 0 1 0 ${2 * r} 0a${r} ${r} 0 1 0 ${-2 * r} 0Z`,
|
|
537
|
+
triangle: `M${c} ${c - r}L${c + r} ${c + r}L${c - r} ${c + r}Z`,
|
|
538
|
+
diamond: `M${c} ${c - r}L${c + r} ${c}L${c} ${c + r}L${c - r} ${c}Z`,
|
|
539
|
+
line: `M0 ${c - 1}h${size}v2H0Z`,
|
|
540
|
+
cross: `M${c - 1} 0h2v${size}h-2ZM0 ${c - 1}h${size}v2H0Z`,
|
|
541
|
+
};
|
|
542
|
+
shape.setAttribute('d', d[decal.symbol]);
|
|
543
|
+
shape.setAttribute('fill', decal.color);
|
|
544
|
+
p.appendChild(shape);
|
|
545
|
+
return p;
|
|
546
|
+
});
|
|
547
|
+
}
|
|
548
|
+
shadow(style) {
|
|
549
|
+
const key = `${style.shadowBlur ?? 0}|${style.shadowColor ?? ''}|${style.shadowOffsetX ?? 0}|${style.shadowOffsetY ?? 0}`;
|
|
550
|
+
return this.def(`s${hash(key)}`, () => {
|
|
551
|
+
const f = this.doc.createElementNS(SVG_NS, 'filter');
|
|
552
|
+
f.setAttribute('x', '-50%');
|
|
553
|
+
f.setAttribute('y', '-50%');
|
|
554
|
+
f.setAttribute('width', '200%');
|
|
555
|
+
f.setAttribute('height', '200%');
|
|
556
|
+
const drop = this.doc.createElementNS(SVG_NS, 'feDropShadow');
|
|
557
|
+
drop.setAttribute('dx', num(style.shadowOffsetX ?? 0));
|
|
558
|
+
drop.setAttribute('dy', num(style.shadowOffsetY ?? 0));
|
|
559
|
+
drop.setAttribute('stdDeviation', num((style.shadowBlur ?? 0) / 2));
|
|
560
|
+
drop.setAttribute('flood-color', style.shadowColor ?? 'rgba(0,0,0,0.3)');
|
|
561
|
+
f.appendChild(drop);
|
|
562
|
+
return f;
|
|
563
|
+
});
|
|
564
|
+
}
|
|
565
|
+
clipPath(key, rect) {
|
|
566
|
+
const id = `c${hash(`${key}|${rect.x}|${rect.y}|${rect.width}|${rect.height}`)}`;
|
|
567
|
+
return this.def(id, () => {
|
|
568
|
+
const c = this.doc.createElementNS(SVG_NS, 'clipPath');
|
|
569
|
+
const r = this.doc.createElementNS(SVG_NS, 'rect');
|
|
570
|
+
r.setAttribute('x', num(rect.x));
|
|
571
|
+
r.setAttribute('y', num(rect.y));
|
|
572
|
+
r.setAttribute('width', num(Math.max(0, rect.width)));
|
|
573
|
+
r.setAttribute('height', num(Math.max(0, rect.height)));
|
|
574
|
+
c.appendChild(r);
|
|
575
|
+
return c;
|
|
576
|
+
});
|
|
577
|
+
}
|
|
578
|
+
}
|
|
579
|
+
// ---------------------------------------------------------------- auxiliares
|
|
580
|
+
function now() {
|
|
581
|
+
return typeof performance !== 'undefined' ? performance.now() : Date.now();
|
|
582
|
+
}
|
|
583
|
+
function num(v) {
|
|
584
|
+
if (!Number.isFinite(v))
|
|
585
|
+
return '0';
|
|
586
|
+
const r = Math.round(v * 1000) / 1000;
|
|
587
|
+
return Object.is(r, -0) ? '0' : String(r);
|
|
588
|
+
}
|
|
589
|
+
function setAttr(el, name, value) {
|
|
590
|
+
if (value === null || value === undefined) {
|
|
591
|
+
if (el.hasAttribute(name))
|
|
592
|
+
el.removeAttribute(name);
|
|
593
|
+
}
|
|
594
|
+
else if (el.getAttribute(name) !== value)
|
|
595
|
+
el.setAttribute(name, value);
|
|
596
|
+
}
|
|
597
|
+
function hasTextBox(style) {
|
|
598
|
+
return !!(style.backgroundColor || style.borderColor);
|
|
599
|
+
}
|
|
600
|
+
function padding(p) {
|
|
601
|
+
if (Array.isArray(p)) {
|
|
602
|
+
if (p.length === 2)
|
|
603
|
+
return [p[0], p[1], p[0], p[1]];
|
|
604
|
+
if (p.length === 4)
|
|
605
|
+
return [p[0], p[1], p[2], p[3]];
|
|
606
|
+
const v = p[0] ?? 0;
|
|
607
|
+
return [v, v, v, v];
|
|
608
|
+
}
|
|
609
|
+
const v = p ?? 0;
|
|
610
|
+
return [v, v, v, v];
|
|
611
|
+
}
|
|
612
|
+
function sameShape(a, b) {
|
|
613
|
+
return JSON.stringify(a) === JSON.stringify(b);
|
|
614
|
+
}
|
|
615
|
+
/** Hash curto e estável (FNV-1a) para ids de defs. */
|
|
616
|
+
function hash(text) {
|
|
617
|
+
let h = 0x811c9dc5;
|
|
618
|
+
for (let i = 0; i < text.length; i++) {
|
|
619
|
+
h ^= text.charCodeAt(i);
|
|
620
|
+
h = Math.imul(h, 0x01000193);
|
|
621
|
+
}
|
|
622
|
+
return (h >>> 0).toString(36);
|
|
623
|
+
}
|
|
624
|
+
//# sourceMappingURL=svg.js.map
|