@macroui/echarts-vue 1.0.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/LICENSE +21 -0
- package/README.md +550 -0
- package/README.zh-Hans.md +518 -0
- package/dist/graphic.d.ts +2786 -0
- package/dist/graphic.js +673 -0
- package/dist/graphic.js.map +1 -0
- package/dist/index-CJnrqQei.d.ts +219 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +741 -0
- package/dist/index.js.map +1 -0
- package/dist/index.min.js +5 -0
- package/dist/index.min.js.map +1 -0
- package/dist/runtime-CcSlBnVC.js +55 -0
- package/dist/runtime-CcSlBnVC.js.map +1 -0
- package/dist/style.css +3 -0
- package/package.json +92 -0
package/dist/graphic.js
ADDED
|
@@ -0,0 +1,673 @@
|
|
|
1
|
+
import { c as parseOnEvent, l as warn$1, r as isBrowser, t as registerRuntime } from "./runtime-CcSlBnVC.js";
|
|
2
|
+
import { Teleport, defineComponent, getCurrentInstance, h, inject, onScopeDispose, onUnmounted, provide, shallowRef } from "vue";
|
|
3
|
+
import { use } from "echarts/core";
|
|
4
|
+
import { GraphicComponent } from "echarts/components";
|
|
5
|
+
//#region src/graphic/props-common.ts
|
|
6
|
+
const COMMON_PROP_KEYS = [
|
|
7
|
+
"id",
|
|
8
|
+
"x",
|
|
9
|
+
"y",
|
|
10
|
+
"rotation",
|
|
11
|
+
"scaleX",
|
|
12
|
+
"scaleY",
|
|
13
|
+
"originX",
|
|
14
|
+
"originY",
|
|
15
|
+
"left",
|
|
16
|
+
"right",
|
|
17
|
+
"top",
|
|
18
|
+
"bottom",
|
|
19
|
+
"width",
|
|
20
|
+
"height",
|
|
21
|
+
"bounding",
|
|
22
|
+
"z",
|
|
23
|
+
"zlevel",
|
|
24
|
+
"silent",
|
|
25
|
+
"draggable",
|
|
26
|
+
"cursor",
|
|
27
|
+
"ignore",
|
|
28
|
+
"invisible",
|
|
29
|
+
"progressive",
|
|
30
|
+
"info",
|
|
31
|
+
"focus",
|
|
32
|
+
"blurScope",
|
|
33
|
+
"textContent",
|
|
34
|
+
"textConfig",
|
|
35
|
+
"transition",
|
|
36
|
+
"enterFrom",
|
|
37
|
+
"leaveTo",
|
|
38
|
+
"enterAnimation",
|
|
39
|
+
"updateAnimation",
|
|
40
|
+
"leaveAnimation",
|
|
41
|
+
"keyframeAnimation"
|
|
42
|
+
];
|
|
43
|
+
const BASE_STYLE_KEYS = [
|
|
44
|
+
"fill",
|
|
45
|
+
"stroke",
|
|
46
|
+
"lineWidth",
|
|
47
|
+
"lineDash",
|
|
48
|
+
"lineDashOffset",
|
|
49
|
+
"lineCap",
|
|
50
|
+
"lineJoin",
|
|
51
|
+
"miterLimit",
|
|
52
|
+
"shadowBlur",
|
|
53
|
+
"shadowOffsetX",
|
|
54
|
+
"shadowOffsetY",
|
|
55
|
+
"shadowColor",
|
|
56
|
+
"opacity",
|
|
57
|
+
"blend"
|
|
58
|
+
];
|
|
59
|
+
const STYLE_KEYS_BY_TYPE = {
|
|
60
|
+
text: [
|
|
61
|
+
"text",
|
|
62
|
+
"font",
|
|
63
|
+
"textFill",
|
|
64
|
+
"textStroke",
|
|
65
|
+
"textStrokeWidth",
|
|
66
|
+
"textAlign",
|
|
67
|
+
"textVerticalAlign",
|
|
68
|
+
"textLineHeight",
|
|
69
|
+
"textShadowBlur",
|
|
70
|
+
"textShadowOffsetX",
|
|
71
|
+
"textShadowOffsetY",
|
|
72
|
+
"textShadowColor",
|
|
73
|
+
"width",
|
|
74
|
+
"overflow",
|
|
75
|
+
"ellipsis"
|
|
76
|
+
],
|
|
77
|
+
image: [
|
|
78
|
+
"image",
|
|
79
|
+
"x",
|
|
80
|
+
"y",
|
|
81
|
+
"width",
|
|
82
|
+
"height"
|
|
83
|
+
]
|
|
84
|
+
};
|
|
85
|
+
const ImageElement = typeof HTMLImageElement === "undefined" ? Object : HTMLImageElement;
|
|
86
|
+
const CanvasElement = typeof HTMLCanvasElement === "undefined" ? Object : HTMLCanvasElement;
|
|
87
|
+
const VideoElement = typeof HTMLVideoElement === "undefined" ? Object : HTMLVideoElement;
|
|
88
|
+
const graphicCommonOnlyProps = {
|
|
89
|
+
id: [String, Number],
|
|
90
|
+
x: Number,
|
|
91
|
+
y: Number,
|
|
92
|
+
rotation: Number,
|
|
93
|
+
scaleX: Number,
|
|
94
|
+
scaleY: Number,
|
|
95
|
+
originX: Number,
|
|
96
|
+
originY: Number,
|
|
97
|
+
left: [String, Number],
|
|
98
|
+
right: [String, Number],
|
|
99
|
+
top: [String, Number],
|
|
100
|
+
bottom: [String, Number],
|
|
101
|
+
width: [String, Number],
|
|
102
|
+
height: [String, Number],
|
|
103
|
+
bounding: String,
|
|
104
|
+
z: Number,
|
|
105
|
+
zlevel: Number,
|
|
106
|
+
silent: Boolean,
|
|
107
|
+
draggable: [Boolean, String],
|
|
108
|
+
cursor: String,
|
|
109
|
+
ignore: Boolean,
|
|
110
|
+
invisible: Boolean,
|
|
111
|
+
progressive: Number,
|
|
112
|
+
info: null,
|
|
113
|
+
focus: String,
|
|
114
|
+
blurScope: String,
|
|
115
|
+
textContent: Object,
|
|
116
|
+
textConfig: Object,
|
|
117
|
+
transition: [String, Array],
|
|
118
|
+
enterFrom: Object,
|
|
119
|
+
leaveTo: Object,
|
|
120
|
+
enterAnimation: Object,
|
|
121
|
+
updateAnimation: Object,
|
|
122
|
+
leaveAnimation: Object,
|
|
123
|
+
keyframeAnimation: Object
|
|
124
|
+
};
|
|
125
|
+
const baseStyleProps = {
|
|
126
|
+
fill: String,
|
|
127
|
+
stroke: String,
|
|
128
|
+
lineWidth: Number,
|
|
129
|
+
lineDash: [String, Array],
|
|
130
|
+
lineDashOffset: Number,
|
|
131
|
+
lineCap: String,
|
|
132
|
+
lineJoin: String,
|
|
133
|
+
miterLimit: Number,
|
|
134
|
+
shadowBlur: Number,
|
|
135
|
+
shadowOffsetX: Number,
|
|
136
|
+
shadowOffsetY: Number,
|
|
137
|
+
shadowColor: String,
|
|
138
|
+
opacity: Number,
|
|
139
|
+
blend: String
|
|
140
|
+
};
|
|
141
|
+
const textStyleProps = {
|
|
142
|
+
text: String,
|
|
143
|
+
font: String,
|
|
144
|
+
textFill: String,
|
|
145
|
+
textStroke: String,
|
|
146
|
+
textStrokeWidth: Number,
|
|
147
|
+
textAlign: String,
|
|
148
|
+
textVerticalAlign: String,
|
|
149
|
+
textLineHeight: Number,
|
|
150
|
+
textShadowBlur: Number,
|
|
151
|
+
textShadowOffsetX: Number,
|
|
152
|
+
textShadowOffsetY: Number,
|
|
153
|
+
textShadowColor: String,
|
|
154
|
+
overflow: String,
|
|
155
|
+
ellipsis: String
|
|
156
|
+
};
|
|
157
|
+
const imageStyleProps = { image: [
|
|
158
|
+
String,
|
|
159
|
+
ImageElement,
|
|
160
|
+
CanvasElement,
|
|
161
|
+
VideoElement
|
|
162
|
+
] };
|
|
163
|
+
const commonProps = {
|
|
164
|
+
...graphicCommonOnlyProps,
|
|
165
|
+
shape: Object,
|
|
166
|
+
style: Object,
|
|
167
|
+
shapeTransition: [String, Array],
|
|
168
|
+
styleTransition: [String, Array],
|
|
169
|
+
...baseStyleProps,
|
|
170
|
+
...textStyleProps,
|
|
171
|
+
...imageStyleProps
|
|
172
|
+
};
|
|
173
|
+
//#endregion
|
|
174
|
+
//#region src/graphic/props-shape.ts
|
|
175
|
+
const SHAPE_KEYS_BY_TYPE = {
|
|
176
|
+
rect: [
|
|
177
|
+
"x",
|
|
178
|
+
"y",
|
|
179
|
+
"width",
|
|
180
|
+
"height",
|
|
181
|
+
"r"
|
|
182
|
+
],
|
|
183
|
+
circle: [
|
|
184
|
+
"cx",
|
|
185
|
+
"cy",
|
|
186
|
+
"r"
|
|
187
|
+
],
|
|
188
|
+
sector: [
|
|
189
|
+
"cx",
|
|
190
|
+
"cy",
|
|
191
|
+
"r",
|
|
192
|
+
"r0",
|
|
193
|
+
"startAngle",
|
|
194
|
+
"endAngle",
|
|
195
|
+
"clockwise",
|
|
196
|
+
"cornerRadius"
|
|
197
|
+
],
|
|
198
|
+
ring: [
|
|
199
|
+
"cx",
|
|
200
|
+
"cy",
|
|
201
|
+
"r",
|
|
202
|
+
"r0"
|
|
203
|
+
],
|
|
204
|
+
arc: [
|
|
205
|
+
"cx",
|
|
206
|
+
"cy",
|
|
207
|
+
"r",
|
|
208
|
+
"r0",
|
|
209
|
+
"startAngle",
|
|
210
|
+
"endAngle",
|
|
211
|
+
"clockwise"
|
|
212
|
+
],
|
|
213
|
+
line: [
|
|
214
|
+
"x1",
|
|
215
|
+
"y1",
|
|
216
|
+
"x2",
|
|
217
|
+
"y2",
|
|
218
|
+
"percent"
|
|
219
|
+
],
|
|
220
|
+
polyline: [
|
|
221
|
+
"points",
|
|
222
|
+
"smooth",
|
|
223
|
+
"smoothConstraint"
|
|
224
|
+
],
|
|
225
|
+
polygon: [
|
|
226
|
+
"points",
|
|
227
|
+
"smooth",
|
|
228
|
+
"smoothConstraint"
|
|
229
|
+
],
|
|
230
|
+
bezierCurve: [
|
|
231
|
+
"x1",
|
|
232
|
+
"y1",
|
|
233
|
+
"x2",
|
|
234
|
+
"y2",
|
|
235
|
+
"cpx1",
|
|
236
|
+
"cpy1",
|
|
237
|
+
"cpx2",
|
|
238
|
+
"cpy2",
|
|
239
|
+
"percent"
|
|
240
|
+
],
|
|
241
|
+
compoundPath: ["paths"]
|
|
242
|
+
};
|
|
243
|
+
const shapeProps = {
|
|
244
|
+
x: Number,
|
|
245
|
+
y: Number,
|
|
246
|
+
cx: Number,
|
|
247
|
+
cy: Number,
|
|
248
|
+
r: [Number, Array],
|
|
249
|
+
r0: Number,
|
|
250
|
+
x1: Number,
|
|
251
|
+
y1: Number,
|
|
252
|
+
x2: Number,
|
|
253
|
+
y2: Number,
|
|
254
|
+
cpx1: Number,
|
|
255
|
+
cpy1: Number,
|
|
256
|
+
cpx2: Number,
|
|
257
|
+
cpy2: Number,
|
|
258
|
+
startAngle: Number,
|
|
259
|
+
endAngle: Number,
|
|
260
|
+
percent: Number,
|
|
261
|
+
points: Array,
|
|
262
|
+
smooth: [Boolean, Number],
|
|
263
|
+
smoothConstraint: Array,
|
|
264
|
+
paths: Array,
|
|
265
|
+
clockwise: Boolean,
|
|
266
|
+
cornerRadius: [Number, Array]
|
|
267
|
+
};
|
|
268
|
+
//#endregion
|
|
269
|
+
//#region src/graphic/build.ts
|
|
270
|
+
const EMPTY_PROP_KEYS = [];
|
|
271
|
+
function resolveShapeKeys(type) {
|
|
272
|
+
return SHAPE_KEYS_BY_TYPE[type] ?? EMPTY_PROP_KEYS;
|
|
273
|
+
}
|
|
274
|
+
function resolveStyleKeys(type) {
|
|
275
|
+
return STYLE_KEYS_BY_TYPE[type] ?? EMPTY_PROP_KEYS;
|
|
276
|
+
}
|
|
277
|
+
function mergeProps(target, keys, props) {
|
|
278
|
+
for (const key of keys) if (props[key] !== void 0) target[key] = props[key];
|
|
279
|
+
}
|
|
280
|
+
function buildStyle(props, extraKeys) {
|
|
281
|
+
const style = { ...props.style };
|
|
282
|
+
mergeProps(style, BASE_STYLE_KEYS, props);
|
|
283
|
+
mergeProps(style, extraKeys, props);
|
|
284
|
+
if (props.styleTransition !== void 0) style.transition = props.styleTransition;
|
|
285
|
+
return Object.keys(style).length > 0 ? style : void 0;
|
|
286
|
+
}
|
|
287
|
+
function buildShape(type, props) {
|
|
288
|
+
const shape = { ...props.shape };
|
|
289
|
+
mergeProps(shape, resolveShapeKeys(type), props);
|
|
290
|
+
if (props.shapeTransition !== void 0) shape.transition = props.shapeTransition;
|
|
291
|
+
return Object.keys(shape).length > 0 ? shape : void 0;
|
|
292
|
+
}
|
|
293
|
+
function buildCommon(type, props) {
|
|
294
|
+
const out = {};
|
|
295
|
+
const shapeKeys = resolveShapeKeys(type);
|
|
296
|
+
const styleKeys = resolveStyleKeys(type);
|
|
297
|
+
for (const key of COMMON_PROP_KEYS) {
|
|
298
|
+
if (shapeKeys.includes(key) || styleKeys.includes(key)) continue;
|
|
299
|
+
if (props[key] !== void 0) out[key] = props[key];
|
|
300
|
+
}
|
|
301
|
+
return out;
|
|
302
|
+
}
|
|
303
|
+
function toEventHandler(value, once) {
|
|
304
|
+
const handlers = [];
|
|
305
|
+
if (typeof value === "function") handlers.push(value);
|
|
306
|
+
else if (Array.isArray(value)) {
|
|
307
|
+
for (const item of value) if (typeof item === "function") handlers.push(item);
|
|
308
|
+
}
|
|
309
|
+
if (handlers.length === 0) return;
|
|
310
|
+
const invoke = (...args) => {
|
|
311
|
+
for (const handler of handlers) handler(...args);
|
|
312
|
+
};
|
|
313
|
+
if (!once) return invoke;
|
|
314
|
+
let called = false;
|
|
315
|
+
return (...args) => {
|
|
316
|
+
if (called) return;
|
|
317
|
+
called = true;
|
|
318
|
+
invoke(...args);
|
|
319
|
+
};
|
|
320
|
+
}
|
|
321
|
+
function buildHandlers(handlers) {
|
|
322
|
+
const out = {};
|
|
323
|
+
for (const [key, value] of Object.entries(handlers)) {
|
|
324
|
+
const descriptor = parseOnEvent(key);
|
|
325
|
+
if (!descriptor) continue;
|
|
326
|
+
const handler = toEventHandler(value, descriptor.once);
|
|
327
|
+
if (!handler) continue;
|
|
328
|
+
const eventKey = `on${descriptor.event}`;
|
|
329
|
+
const existing = out[eventKey];
|
|
330
|
+
if (!existing) {
|
|
331
|
+
out[eventKey] = handler;
|
|
332
|
+
continue;
|
|
333
|
+
}
|
|
334
|
+
out[eventKey] = (...args) => {
|
|
335
|
+
existing(...args);
|
|
336
|
+
handler(...args);
|
|
337
|
+
};
|
|
338
|
+
}
|
|
339
|
+
return Object.keys(out).length > 0 ? out : void 0;
|
|
340
|
+
}
|
|
341
|
+
function toElement(node, children) {
|
|
342
|
+
const { type, id, props } = node;
|
|
343
|
+
const styleKeys = resolveStyleKeys(type);
|
|
344
|
+
const out = {
|
|
345
|
+
type,
|
|
346
|
+
id
|
|
347
|
+
};
|
|
348
|
+
Object.assign(out, buildCommon(type, props));
|
|
349
|
+
const handlers = buildHandlers(node.handlers);
|
|
350
|
+
if (handlers) Object.assign(out, handlers);
|
|
351
|
+
if (props.info !== void 0) out.info = props.info;
|
|
352
|
+
if (type === "group") {
|
|
353
|
+
if (children?.length) out.children = children;
|
|
354
|
+
return out;
|
|
355
|
+
}
|
|
356
|
+
const shape = buildShape(type, props);
|
|
357
|
+
if (shape) out.shape = shape;
|
|
358
|
+
const style = buildStyle(props, styleKeys);
|
|
359
|
+
if (style) out.style = style;
|
|
360
|
+
return out;
|
|
361
|
+
}
|
|
362
|
+
function buildOption(nodes, rootId) {
|
|
363
|
+
const byParent = /* @__PURE__ */ new Map();
|
|
364
|
+
for (const node of nodes) {
|
|
365
|
+
const list = byParent.get(node.parentId);
|
|
366
|
+
if (list) {
|
|
367
|
+
list.push(node);
|
|
368
|
+
continue;
|
|
369
|
+
}
|
|
370
|
+
byParent.set(node.parentId, [node]);
|
|
371
|
+
}
|
|
372
|
+
for (const list of byParent.values()) list.sort((a, b) => a.order - b.order);
|
|
373
|
+
const childrenOf = (parentId) => {
|
|
374
|
+
return (byParent.get(parentId) ?? []).map((node) => {
|
|
375
|
+
if (node.type !== "group") return toElement(node);
|
|
376
|
+
return toElement(node, childrenOf(node.id));
|
|
377
|
+
});
|
|
378
|
+
};
|
|
379
|
+
return { graphic: { elements: [{
|
|
380
|
+
type: "group",
|
|
381
|
+
id: rootId,
|
|
382
|
+
$action: "replace",
|
|
383
|
+
children: childrenOf(null)
|
|
384
|
+
}] } };
|
|
385
|
+
}
|
|
386
|
+
//#endregion
|
|
387
|
+
//#region src/graphic/collector.ts
|
|
388
|
+
function createCollector(options) {
|
|
389
|
+
const { onFlush } = options;
|
|
390
|
+
const nodes = /* @__PURE__ */ new Map();
|
|
391
|
+
const warnedKeys = /* @__PURE__ */ new Set();
|
|
392
|
+
const seenInPass = /* @__PURE__ */ new Map();
|
|
393
|
+
let order = 0;
|
|
394
|
+
let pending = false;
|
|
395
|
+
let disposed = false;
|
|
396
|
+
function beginPass() {
|
|
397
|
+
order = 0;
|
|
398
|
+
seenInPass.clear();
|
|
399
|
+
}
|
|
400
|
+
function warn(message, options) {
|
|
401
|
+
warn$1(message, options ? {
|
|
402
|
+
...options,
|
|
403
|
+
onceStore: warnedKeys
|
|
404
|
+
} : void 0);
|
|
405
|
+
}
|
|
406
|
+
function register(node) {
|
|
407
|
+
if (disposed) return;
|
|
408
|
+
const seenSource = seenInPass.get(node.id);
|
|
409
|
+
if (seenSource != null && seenSource !== node.sourceId) warn(`Duplicate graphic id "${node.id}" detected. Updates may be unstable.`, { onceKey: `duplicate-id:${node.id}` });
|
|
410
|
+
const nextOrder = node.order ?? order;
|
|
411
|
+
order = Math.max(order, nextOrder + 1);
|
|
412
|
+
nodes.set(node.id, {
|
|
413
|
+
...node,
|
|
414
|
+
order: nextOrder
|
|
415
|
+
});
|
|
416
|
+
seenInPass.set(node.id, node.sourceId);
|
|
417
|
+
requestFlush();
|
|
418
|
+
}
|
|
419
|
+
function unregister(id, sourceId) {
|
|
420
|
+
if (disposed) return;
|
|
421
|
+
const existing = nodes.get(id);
|
|
422
|
+
if (!existing) return;
|
|
423
|
+
if (sourceId != null && existing.sourceId !== sourceId) return;
|
|
424
|
+
nodes.delete(id);
|
|
425
|
+
requestFlush();
|
|
426
|
+
}
|
|
427
|
+
function requestFlush() {
|
|
428
|
+
if (disposed || pending) return;
|
|
429
|
+
pending = true;
|
|
430
|
+
queueMicrotask(() => {
|
|
431
|
+
pending = false;
|
|
432
|
+
if (disposed) return;
|
|
433
|
+
onFlush();
|
|
434
|
+
});
|
|
435
|
+
}
|
|
436
|
+
function getNodes() {
|
|
437
|
+
return nodes.values();
|
|
438
|
+
}
|
|
439
|
+
function dispose() {
|
|
440
|
+
disposed = true;
|
|
441
|
+
pending = false;
|
|
442
|
+
nodes.clear();
|
|
443
|
+
seenInPass.clear();
|
|
444
|
+
warnedKeys.clear();
|
|
445
|
+
}
|
|
446
|
+
return {
|
|
447
|
+
beginPass,
|
|
448
|
+
register,
|
|
449
|
+
unregister,
|
|
450
|
+
warn,
|
|
451
|
+
getNodes,
|
|
452
|
+
dispose
|
|
453
|
+
};
|
|
454
|
+
}
|
|
455
|
+
//#endregion
|
|
456
|
+
//#region src/graphic/context.ts
|
|
457
|
+
const GRAPHIC_COLLECTOR_KEY = Symbol("@macroui/echarts-vue:graphic-collector");
|
|
458
|
+
const GRAPHIC_PARENT_ID_KEY = Symbol("@macroui/echarts-vue:graphic-parent-id");
|
|
459
|
+
const GRAPHIC_ORDER_KEY = Symbol("@macroui/echarts-vue:graphic-order");
|
|
460
|
+
//#endregion
|
|
461
|
+
//#region src/graphic/identity.ts
|
|
462
|
+
function resolveIdentity(propsId, vnodeKey, uid) {
|
|
463
|
+
if (propsId != null) {
|
|
464
|
+
const id = String(propsId);
|
|
465
|
+
return {
|
|
466
|
+
id,
|
|
467
|
+
orderKey: `id:${id}`,
|
|
468
|
+
missingIdentity: false
|
|
469
|
+
};
|
|
470
|
+
}
|
|
471
|
+
if (vnodeKey != null) {
|
|
472
|
+
const id = String(vnodeKey);
|
|
473
|
+
return {
|
|
474
|
+
id,
|
|
475
|
+
orderKey: `key:${id}`,
|
|
476
|
+
missingIdentity: false
|
|
477
|
+
};
|
|
478
|
+
}
|
|
479
|
+
return {
|
|
480
|
+
id: `__ve_graphic_${uid}`,
|
|
481
|
+
missingIdentity: true
|
|
482
|
+
};
|
|
483
|
+
}
|
|
484
|
+
function resolveOrderKey(propsId, vnodeKey) {
|
|
485
|
+
if (propsId != null) return `id:${String(propsId)}`;
|
|
486
|
+
if (vnodeKey != null) return `key:${String(vnodeKey)}`;
|
|
487
|
+
return null;
|
|
488
|
+
}
|
|
489
|
+
//#endregion
|
|
490
|
+
//#region src/graphic/marker.ts
|
|
491
|
+
const GRAPHIC_COMPONENT_MARKER = Symbol("@macroui/echarts-vue:graphic-component");
|
|
492
|
+
//#endregion
|
|
493
|
+
//#region src/graphic/order.ts
|
|
494
|
+
function getType(vnode) {
|
|
495
|
+
if (!vnode || typeof vnode !== "object") return null;
|
|
496
|
+
const type = vnode.type;
|
|
497
|
+
if (!type || typeof type !== "object") return null;
|
|
498
|
+
const mark = type[GRAPHIC_COMPONENT_MARKER];
|
|
499
|
+
return typeof mark === "string" ? mark : null;
|
|
500
|
+
}
|
|
501
|
+
function collectOrder(value, orderMap, order) {
|
|
502
|
+
if (Array.isArray(value)) {
|
|
503
|
+
for (const child of value) order = collectOrder(child, orderMap, order);
|
|
504
|
+
return order;
|
|
505
|
+
}
|
|
506
|
+
if (!value || typeof value !== "object") return order;
|
|
507
|
+
const vnode = value;
|
|
508
|
+
const type = getType(vnode);
|
|
509
|
+
if (type) {
|
|
510
|
+
const props = vnode.props;
|
|
511
|
+
const identity = resolveOrderKey(props?.id, vnode.key);
|
|
512
|
+
if (identity) orderMap.set(identity, order);
|
|
513
|
+
order += 1;
|
|
514
|
+
}
|
|
515
|
+
if (type === "group") {
|
|
516
|
+
const slot = vnode.children?.default;
|
|
517
|
+
if (slot) return collectOrder(slot(), orderMap, order);
|
|
518
|
+
}
|
|
519
|
+
const children = vnode.children;
|
|
520
|
+
if (Array.isArray(children)) for (const child of children) order = collectOrder(child, orderMap, order);
|
|
521
|
+
return order;
|
|
522
|
+
}
|
|
523
|
+
//#endregion
|
|
524
|
+
//#region src/graphic/mount.ts
|
|
525
|
+
const GraphicMount = defineComponent({
|
|
526
|
+
name: "GraphicMount",
|
|
527
|
+
props: { collector: {
|
|
528
|
+
type: Object,
|
|
529
|
+
required: true
|
|
530
|
+
} },
|
|
531
|
+
setup(props, { slots }) {
|
|
532
|
+
const { collector } = props;
|
|
533
|
+
const { beginPass } = collector;
|
|
534
|
+
const detachedRoot = isBrowser() ? document.createElement("div") : void 0;
|
|
535
|
+
const parentId = shallowRef(null);
|
|
536
|
+
const orderMapRef = shallowRef(/* @__PURE__ */ new Map());
|
|
537
|
+
provide(GRAPHIC_COLLECTOR_KEY, collector);
|
|
538
|
+
provide(GRAPHIC_PARENT_ID_KEY, parentId);
|
|
539
|
+
provide(GRAPHIC_ORDER_KEY, orderMapRef);
|
|
540
|
+
onUnmounted(() => {
|
|
541
|
+
detachedRoot?.remove();
|
|
542
|
+
});
|
|
543
|
+
return () => {
|
|
544
|
+
beginPass();
|
|
545
|
+
const content = slots.default?.();
|
|
546
|
+
const orderMap = /* @__PURE__ */ new Map();
|
|
547
|
+
collectOrder(content, orderMap, 0);
|
|
548
|
+
orderMapRef.value = orderMap;
|
|
549
|
+
return detachedRoot ? h(Teleport, { to: detachedRoot }, h("div", { style: { display: "contents" } }, content)) : null;
|
|
550
|
+
};
|
|
551
|
+
}
|
|
552
|
+
});
|
|
553
|
+
//#endregion
|
|
554
|
+
//#region src/graphic/extension.ts
|
|
555
|
+
const ROOT_ID = "__ve_graphic_root__";
|
|
556
|
+
const UPDATE_OPTIONS = { replaceMerge: ["graphic"] };
|
|
557
|
+
let componentRegistered = false;
|
|
558
|
+
function registerExtension() {
|
|
559
|
+
if (!componentRegistered) {
|
|
560
|
+
use([GraphicComponent]);
|
|
561
|
+
componentRegistered = true;
|
|
562
|
+
}
|
|
563
|
+
registerRuntime((ctx) => {
|
|
564
|
+
const { slots, manualUpdate, requestUpdate } = ctx;
|
|
565
|
+
let warnedOverride = false;
|
|
566
|
+
const collector = createCollector({ onFlush: handleFlush });
|
|
567
|
+
const { dispose, getNodes, warn } = collector;
|
|
568
|
+
function handleFlush() {
|
|
569
|
+
if (!requestUpdate(UPDATE_OPTIONS) && manualUpdate.value) warn("`#graphic` slot updates are ignored when `manual-update` is `true`.", { onceKey: "manual-update-graphic" });
|
|
570
|
+
}
|
|
571
|
+
onScopeDispose(dispose);
|
|
572
|
+
return {
|
|
573
|
+
patchOption(option) {
|
|
574
|
+
if (!slots.graphic) return option;
|
|
575
|
+
if (option.graphic && !warnedOverride) {
|
|
576
|
+
warn("`#graphic` slot is provided, so `option.graphic` is ignored. Remove one of them to avoid ambiguity.");
|
|
577
|
+
warnedOverride = true;
|
|
578
|
+
}
|
|
579
|
+
const nextOption = buildOption(getNodes(), ROOT_ID);
|
|
580
|
+
return {
|
|
581
|
+
...option,
|
|
582
|
+
graphic: nextOption.graphic
|
|
583
|
+
};
|
|
584
|
+
},
|
|
585
|
+
render() {
|
|
586
|
+
if (!slots.graphic) return null;
|
|
587
|
+
return h(GraphicMount, { collector }, { default: slots.graphic });
|
|
588
|
+
}
|
|
589
|
+
};
|
|
590
|
+
});
|
|
591
|
+
}
|
|
592
|
+
//#endregion
|
|
593
|
+
//#region src/graphic/component-factory.ts
|
|
594
|
+
const componentProps = {
|
|
595
|
+
...commonProps,
|
|
596
|
+
...shapeProps
|
|
597
|
+
};
|
|
598
|
+
function createComponent(name, type) {
|
|
599
|
+
const component = defineComponent({
|
|
600
|
+
name,
|
|
601
|
+
inheritAttrs: false,
|
|
602
|
+
props: componentProps,
|
|
603
|
+
emits: {},
|
|
604
|
+
setup(props, { attrs, slots }) {
|
|
605
|
+
const instance = getCurrentInstance();
|
|
606
|
+
const collector = inject(GRAPHIC_COLLECTOR_KEY, null);
|
|
607
|
+
const parentIdRef = inject(GRAPHIC_PARENT_ID_KEY, null);
|
|
608
|
+
const orderRef = inject(GRAPHIC_ORDER_KEY, null);
|
|
609
|
+
if (!collector) {
|
|
610
|
+
warn$1(`\`${name}\` must be used inside \`#graphic\` slot.`);
|
|
611
|
+
return () => null;
|
|
612
|
+
}
|
|
613
|
+
const { register: registerNode, unregister, warn: warnScoped } = collector;
|
|
614
|
+
let currentId = null;
|
|
615
|
+
function register() {
|
|
616
|
+
const identity = resolveIdentity(props.id, instance.vnode.key, instance.uid);
|
|
617
|
+
if (identity.missingIdentity) warnScoped(`\`${name}\` is missing \`id\` and \`key\`. Updates might be unstable in \`v-for\`.`, { onceKey: `missing-id:${instance.uid}` });
|
|
618
|
+
if (currentId && currentId !== identity.id) unregister(currentId, instance.uid);
|
|
619
|
+
currentId = identity.id;
|
|
620
|
+
const hintedOrder = identity.orderKey ? orderRef?.value.get(identity.orderKey) : void 0;
|
|
621
|
+
registerNode({
|
|
622
|
+
id: currentId,
|
|
623
|
+
type,
|
|
624
|
+
parentId: parentIdRef?.value ?? null,
|
|
625
|
+
order: hintedOrder,
|
|
626
|
+
props,
|
|
627
|
+
handlers: attrs,
|
|
628
|
+
sourceId: instance.uid
|
|
629
|
+
});
|
|
630
|
+
return currentId;
|
|
631
|
+
}
|
|
632
|
+
onUnmounted(() => {
|
|
633
|
+
if (currentId) unregister(currentId, instance.uid);
|
|
634
|
+
});
|
|
635
|
+
if (type === "group") {
|
|
636
|
+
const providedParent = shallowRef(null);
|
|
637
|
+
provide(GRAPHIC_PARENT_ID_KEY, providedParent);
|
|
638
|
+
return () => {
|
|
639
|
+
providedParent.value = register();
|
|
640
|
+
return slots.default?.() ?? null;
|
|
641
|
+
};
|
|
642
|
+
}
|
|
643
|
+
return () => {
|
|
644
|
+
register();
|
|
645
|
+
return null;
|
|
646
|
+
};
|
|
647
|
+
}
|
|
648
|
+
});
|
|
649
|
+
component[GRAPHIC_COMPONENT_MARKER] = type;
|
|
650
|
+
return component;
|
|
651
|
+
}
|
|
652
|
+
//#endregion
|
|
653
|
+
//#region src/graphic/components.ts
|
|
654
|
+
const GGroup = createComponent("GGroup", "group");
|
|
655
|
+
const GRect = createComponent("GRect", "rect");
|
|
656
|
+
const GCircle = createComponent("GCircle", "circle");
|
|
657
|
+
const GText = createComponent("GText", "text");
|
|
658
|
+
const GLine = createComponent("GLine", "line");
|
|
659
|
+
const GPolyline = createComponent("GPolyline", "polyline");
|
|
660
|
+
const GPolygon = createComponent("GPolygon", "polygon");
|
|
661
|
+
const GImage = createComponent("GImage", "image");
|
|
662
|
+
const GSector = createComponent("GSector", "sector");
|
|
663
|
+
const GRing = createComponent("GRing", "ring");
|
|
664
|
+
const GArc = createComponent("GArc", "arc");
|
|
665
|
+
const GBezierCurve = createComponent("GBezierCurve", "bezierCurve");
|
|
666
|
+
const GCompoundPath = createComponent("GCompoundPath", "compoundPath");
|
|
667
|
+
//#endregion
|
|
668
|
+
//#region src/graphic/index.ts
|
|
669
|
+
registerExtension();
|
|
670
|
+
//#endregion
|
|
671
|
+
export { GArc, GBezierCurve, GCircle, GCompoundPath, GGroup, GImage, GLine, GPolygon, GPolyline, GRect, GRing, GSector, GText };
|
|
672
|
+
|
|
673
|
+
//# sourceMappingURL=graphic.js.map
|