rendx-svg 0.1.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/dist/main.cjs +166 -0
- package/dist/main.d.cts +28 -0
- package/dist/main.d.ts +28 -0
- package/dist/main.js +140 -0
- package/package.json +52 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025-present wei.liang (https://github.com/weiliang0121)
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/main.cjs
ADDED
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __typeError = (msg) => {
|
|
7
|
+
throw TypeError(msg);
|
|
8
|
+
};
|
|
9
|
+
var __export = (target, all) => {
|
|
10
|
+
for (var name in all)
|
|
11
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
12
|
+
};
|
|
13
|
+
var __copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
15
|
+
for (let key of __getOwnPropNames(from))
|
|
16
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
17
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
18
|
+
}
|
|
19
|
+
return to;
|
|
20
|
+
};
|
|
21
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
22
|
+
var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
|
|
23
|
+
var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
24
|
+
var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
25
|
+
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
|
|
26
|
+
var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
|
|
27
|
+
|
|
28
|
+
// src/main.ts
|
|
29
|
+
var main_exports = {};
|
|
30
|
+
__export(main_exports, {
|
|
31
|
+
SvgRenderer: () => SvgRenderer
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(main_exports);
|
|
34
|
+
|
|
35
|
+
// src/renderer.ts
|
|
36
|
+
var import_rendx_dom = require("rendx-dom");
|
|
37
|
+
var import_rendx_gradient = require("rendx-gradient");
|
|
38
|
+
var import_rendx_core = require("rendx-core");
|
|
39
|
+
var DEFAULT_SIZE = { width: 300, height: 150 };
|
|
40
|
+
var _size, _element, _group, _g, _defs, _stack, _attributes, _SvgRenderer_instances, initG_fn, transform_fn, addEl_fn;
|
|
41
|
+
var SvgRenderer = class {
|
|
42
|
+
constructor(size = DEFAULT_SIZE) {
|
|
43
|
+
__privateAdd(this, _SvgRenderer_instances);
|
|
44
|
+
__privateAdd(this, _size);
|
|
45
|
+
__privateAdd(this, _element);
|
|
46
|
+
__privateAdd(this, _group);
|
|
47
|
+
__privateAdd(this, _g);
|
|
48
|
+
__privateAdd(this, _defs);
|
|
49
|
+
__privateAdd(this, _stack, []);
|
|
50
|
+
__privateAdd(this, _attributes, {});
|
|
51
|
+
__privateSet(this, _size, size);
|
|
52
|
+
__privateSet(this, _element, (0, import_rendx_dom.createSvgEl)("svg"));
|
|
53
|
+
__privateSet(this, _defs, (0, import_rendx_dom.getSvgElByTag)(__privateGet(this, _element), "defs"));
|
|
54
|
+
__privateSet(this, _group, (0, import_rendx_dom.getSvgElByTag)(__privateGet(this, _element), "g"));
|
|
55
|
+
__privateSet(this, _g, (0, import_rendx_dom.createSvgEl)("g"));
|
|
56
|
+
(0, import_rendx_dom.setSVGAttrs)(__privateGet(this, _element), __privateGet(this, _size));
|
|
57
|
+
(0, import_rendx_dom.setStyles)(__privateGet(this, _element), { width: `${__privateGet(this, _size).width}px`, height: `${__privateGet(this, _size).height}px`, userSelect: "none" });
|
|
58
|
+
(0, import_rendx_dom.setStyles)(__privateGet(this, _group), { pointerEvents: "none" });
|
|
59
|
+
__privateMethod(this, _SvgRenderer_instances, initG_fn).call(this);
|
|
60
|
+
}
|
|
61
|
+
get el() {
|
|
62
|
+
return __privateGet(this, _element);
|
|
63
|
+
}
|
|
64
|
+
getSize() {
|
|
65
|
+
return __privateGet(this, _size);
|
|
66
|
+
}
|
|
67
|
+
resize(size) {
|
|
68
|
+
__privateSet(this, _size, size);
|
|
69
|
+
(0, import_rendx_dom.setSVGAttrs)(__privateGet(this, _element), __privateGet(this, _size));
|
|
70
|
+
(0, import_rendx_dom.setStyles)(__privateGet(this, _element), { width: `${__privateGet(this, _size).width}px`, height: `${__privateGet(this, _size).height}px` });
|
|
71
|
+
}
|
|
72
|
+
dispose() {
|
|
73
|
+
this.el.remove();
|
|
74
|
+
}
|
|
75
|
+
clear() {
|
|
76
|
+
__privateGet(this, _group).innerHTML = "";
|
|
77
|
+
__privateGet(this, _defs).innerHTML = "";
|
|
78
|
+
__privateSet(this, _g, (0, import_rendx_dom.createSvgEl)("g"));
|
|
79
|
+
__privateSet(this, _stack, []);
|
|
80
|
+
__privateMethod(this, _SvgRenderer_instances, initG_fn).call(this);
|
|
81
|
+
}
|
|
82
|
+
save(createChild) {
|
|
83
|
+
const last = __privateGet(this, _stack)[__privateGet(this, _stack).length - 1];
|
|
84
|
+
const g = (0, import_rendx_dom.createSvgEl)("g");
|
|
85
|
+
if (createChild) last.appendChild(g);
|
|
86
|
+
else last.parentNode?.appendChild(g);
|
|
87
|
+
__privateSet(this, _g, g);
|
|
88
|
+
__privateGet(this, _stack).push(g);
|
|
89
|
+
}
|
|
90
|
+
restore() {
|
|
91
|
+
if (__privateGet(this, _stack).length > 1) __privateGet(this, _stack).pop();
|
|
92
|
+
__privateSet(this, _g, __privateGet(this, _stack)[__privateGet(this, _stack).length - 1]);
|
|
93
|
+
}
|
|
94
|
+
translate(tx, ty) {
|
|
95
|
+
__privateMethod(this, _SvgRenderer_instances, transform_fn).call(this, `translate(${tx} ${ty})`);
|
|
96
|
+
}
|
|
97
|
+
rotate(radian) {
|
|
98
|
+
__privateMethod(this, _SvgRenderer_instances, transform_fn).call(this, `rotate(${radian * import_rendx_core.r2d})`);
|
|
99
|
+
}
|
|
100
|
+
scale(sx, sy) {
|
|
101
|
+
__privateMethod(this, _SvgRenderer_instances, transform_fn).call(this, `scale(${sx} ${sy})`);
|
|
102
|
+
}
|
|
103
|
+
setTransform(a, b, c, d, e, f) {
|
|
104
|
+
__privateGet(this, _g).setAttribute("transform", `matrix(${a} ${b} ${c} ${d} ${e} ${f})`);
|
|
105
|
+
}
|
|
106
|
+
setAttributes(attrs) {
|
|
107
|
+
__privateSet(this, _attributes, attrs);
|
|
108
|
+
}
|
|
109
|
+
rect(x, y, width, height) {
|
|
110
|
+
__privateGet(this, _g).appendChild(__privateMethod(this, _SvgRenderer_instances, addEl_fn).call(this, "rect", { x, y, width, height }));
|
|
111
|
+
}
|
|
112
|
+
line(x1, y1, x2, y2) {
|
|
113
|
+
__privateGet(this, _g).appendChild(__privateMethod(this, _SvgRenderer_instances, addEl_fn).call(this, "line", { x1, y1, x2, y2 }));
|
|
114
|
+
}
|
|
115
|
+
circle(x, y, radius) {
|
|
116
|
+
__privateGet(this, _g).appendChild(__privateMethod(this, _SvgRenderer_instances, addEl_fn).call(this, "circle", { cx: x, cy: y, r: radius }));
|
|
117
|
+
}
|
|
118
|
+
text(text, x, y) {
|
|
119
|
+
const textElement = __privateMethod(this, _SvgRenderer_instances, addEl_fn).call(this, "text", { x, y });
|
|
120
|
+
textElement.textContent = text;
|
|
121
|
+
__privateGet(this, _g).appendChild(textElement);
|
|
122
|
+
}
|
|
123
|
+
path(path) {
|
|
124
|
+
__privateGet(this, _g).appendChild(__privateMethod(this, _SvgRenderer_instances, addEl_fn).call(this, "path", { d: path }));
|
|
125
|
+
}
|
|
126
|
+
image(source, x, y, width, height) {
|
|
127
|
+
const href = typeof source === "string" ? source : source.src ?? "";
|
|
128
|
+
const el = __privateMethod(this, _SvgRenderer_instances, addEl_fn).call(this, "image", { href, x, y, width, height });
|
|
129
|
+
el.setAttribute("preserveAspectRatio", "none");
|
|
130
|
+
__privateGet(this, _g).appendChild(el);
|
|
131
|
+
}
|
|
132
|
+
clipPath(clipPath) {
|
|
133
|
+
const el = (0, import_rendx_dom.createSvgEl)("clipPath");
|
|
134
|
+
el.setAttribute("id", clipPath.id);
|
|
135
|
+
const pathEl = (0, import_rendx_dom.createSvgEl)("path");
|
|
136
|
+
pathEl.setAttribute("d", clipPath.path);
|
|
137
|
+
el.appendChild(pathEl);
|
|
138
|
+
__privateGet(this, _defs).appendChild(el);
|
|
139
|
+
}
|
|
140
|
+
gradient(options) {
|
|
141
|
+
const gradient = (0, import_rendx_gradient.createSVGGradient)(options);
|
|
142
|
+
if (gradient) __privateGet(this, _defs).appendChild(gradient);
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
_size = new WeakMap();
|
|
146
|
+
_element = new WeakMap();
|
|
147
|
+
_group = new WeakMap();
|
|
148
|
+
_g = new WeakMap();
|
|
149
|
+
_defs = new WeakMap();
|
|
150
|
+
_stack = new WeakMap();
|
|
151
|
+
_attributes = new WeakMap();
|
|
152
|
+
_SvgRenderer_instances = new WeakSet();
|
|
153
|
+
initG_fn = function() {
|
|
154
|
+
__privateGet(this, _group).appendChild(__privateGet(this, _g));
|
|
155
|
+
__privateGet(this, _stack).push(__privateGet(this, _g));
|
|
156
|
+
};
|
|
157
|
+
transform_fn = function(transform) {
|
|
158
|
+
__privateGet(this, _g).setAttribute("transform", `${__privateGet(this, _g).getAttribute("transform") || ""} ${transform}`);
|
|
159
|
+
};
|
|
160
|
+
addEl_fn = function(tag, attributes) {
|
|
161
|
+
return (0, import_rendx_dom.setSVGAttrs)((0, import_rendx_dom.createSvgEl)(tag), { ...__privateGet(this, _attributes), ...attributes });
|
|
162
|
+
};
|
|
163
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
164
|
+
0 && (module.exports = {
|
|
165
|
+
SvgRenderer
|
|
166
|
+
});
|
package/dist/main.d.cts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { IGraphicsRenderer, Size, AO, ClipPath, GradientOptions } from 'rendx-core';
|
|
2
|
+
|
|
3
|
+
declare class SvgRenderer implements IGraphicsRenderer {
|
|
4
|
+
#private;
|
|
5
|
+
constructor(size?: Size);
|
|
6
|
+
get el(): SVGSVGElement;
|
|
7
|
+
getSize(): Size;
|
|
8
|
+
resize(size: Size): void;
|
|
9
|
+
dispose(): void;
|
|
10
|
+
clear(): void;
|
|
11
|
+
save(createChild?: boolean): void;
|
|
12
|
+
restore(): void;
|
|
13
|
+
translate(tx: number, ty: number): void;
|
|
14
|
+
rotate(radian: number): void;
|
|
15
|
+
scale(sx: number, sy: number): void;
|
|
16
|
+
setTransform(a: number, b: number, c: number, d: number, e: number, f: number): void;
|
|
17
|
+
setAttributes(attrs: AO): void;
|
|
18
|
+
rect(x: number, y: number, width: number, height: number): void;
|
|
19
|
+
line(x1: number, y1: number, x2: number, y2: number): void;
|
|
20
|
+
circle(x: number, y: number, radius: number): void;
|
|
21
|
+
text(text: string, x: number, y: number): void;
|
|
22
|
+
path(path: string): void;
|
|
23
|
+
image(source: CanvasImageSource | string, x: number, y: number, width: number, height: number): void;
|
|
24
|
+
clipPath(clipPath: ClipPath): void;
|
|
25
|
+
gradient(options: GradientOptions): void;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export { SvgRenderer };
|
package/dist/main.d.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { IGraphicsRenderer, Size, AO, ClipPath, GradientOptions } from 'rendx-core';
|
|
2
|
+
|
|
3
|
+
declare class SvgRenderer implements IGraphicsRenderer {
|
|
4
|
+
#private;
|
|
5
|
+
constructor(size?: Size);
|
|
6
|
+
get el(): SVGSVGElement;
|
|
7
|
+
getSize(): Size;
|
|
8
|
+
resize(size: Size): void;
|
|
9
|
+
dispose(): void;
|
|
10
|
+
clear(): void;
|
|
11
|
+
save(createChild?: boolean): void;
|
|
12
|
+
restore(): void;
|
|
13
|
+
translate(tx: number, ty: number): void;
|
|
14
|
+
rotate(radian: number): void;
|
|
15
|
+
scale(sx: number, sy: number): void;
|
|
16
|
+
setTransform(a: number, b: number, c: number, d: number, e: number, f: number): void;
|
|
17
|
+
setAttributes(attrs: AO): void;
|
|
18
|
+
rect(x: number, y: number, width: number, height: number): void;
|
|
19
|
+
line(x1: number, y1: number, x2: number, y2: number): void;
|
|
20
|
+
circle(x: number, y: number, radius: number): void;
|
|
21
|
+
text(text: string, x: number, y: number): void;
|
|
22
|
+
path(path: string): void;
|
|
23
|
+
image(source: CanvasImageSource | string, x: number, y: number, width: number, height: number): void;
|
|
24
|
+
clipPath(clipPath: ClipPath): void;
|
|
25
|
+
gradient(options: GradientOptions): void;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export { SvgRenderer };
|
package/dist/main.js
ADDED
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
var __typeError = (msg) => {
|
|
2
|
+
throw TypeError(msg);
|
|
3
|
+
};
|
|
4
|
+
var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
|
|
5
|
+
var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
6
|
+
var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
7
|
+
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
|
|
8
|
+
var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
|
|
9
|
+
|
|
10
|
+
// src/renderer.ts
|
|
11
|
+
import { createSvgEl, getSvgElByTag, setSVGAttrs, setStyles } from "rendx-dom";
|
|
12
|
+
import { createSVGGradient } from "rendx-gradient";
|
|
13
|
+
import { r2d } from "rendx-core";
|
|
14
|
+
var DEFAULT_SIZE = { width: 300, height: 150 };
|
|
15
|
+
var _size, _element, _group, _g, _defs, _stack, _attributes, _SvgRenderer_instances, initG_fn, transform_fn, addEl_fn;
|
|
16
|
+
var SvgRenderer = class {
|
|
17
|
+
constructor(size = DEFAULT_SIZE) {
|
|
18
|
+
__privateAdd(this, _SvgRenderer_instances);
|
|
19
|
+
__privateAdd(this, _size);
|
|
20
|
+
__privateAdd(this, _element);
|
|
21
|
+
__privateAdd(this, _group);
|
|
22
|
+
__privateAdd(this, _g);
|
|
23
|
+
__privateAdd(this, _defs);
|
|
24
|
+
__privateAdd(this, _stack, []);
|
|
25
|
+
__privateAdd(this, _attributes, {});
|
|
26
|
+
__privateSet(this, _size, size);
|
|
27
|
+
__privateSet(this, _element, createSvgEl("svg"));
|
|
28
|
+
__privateSet(this, _defs, getSvgElByTag(__privateGet(this, _element), "defs"));
|
|
29
|
+
__privateSet(this, _group, getSvgElByTag(__privateGet(this, _element), "g"));
|
|
30
|
+
__privateSet(this, _g, createSvgEl("g"));
|
|
31
|
+
setSVGAttrs(__privateGet(this, _element), __privateGet(this, _size));
|
|
32
|
+
setStyles(__privateGet(this, _element), { width: `${__privateGet(this, _size).width}px`, height: `${__privateGet(this, _size).height}px`, userSelect: "none" });
|
|
33
|
+
setStyles(__privateGet(this, _group), { pointerEvents: "none" });
|
|
34
|
+
__privateMethod(this, _SvgRenderer_instances, initG_fn).call(this);
|
|
35
|
+
}
|
|
36
|
+
get el() {
|
|
37
|
+
return __privateGet(this, _element);
|
|
38
|
+
}
|
|
39
|
+
getSize() {
|
|
40
|
+
return __privateGet(this, _size);
|
|
41
|
+
}
|
|
42
|
+
resize(size) {
|
|
43
|
+
__privateSet(this, _size, size);
|
|
44
|
+
setSVGAttrs(__privateGet(this, _element), __privateGet(this, _size));
|
|
45
|
+
setStyles(__privateGet(this, _element), { width: `${__privateGet(this, _size).width}px`, height: `${__privateGet(this, _size).height}px` });
|
|
46
|
+
}
|
|
47
|
+
dispose() {
|
|
48
|
+
this.el.remove();
|
|
49
|
+
}
|
|
50
|
+
clear() {
|
|
51
|
+
__privateGet(this, _group).innerHTML = "";
|
|
52
|
+
__privateGet(this, _defs).innerHTML = "";
|
|
53
|
+
__privateSet(this, _g, createSvgEl("g"));
|
|
54
|
+
__privateSet(this, _stack, []);
|
|
55
|
+
__privateMethod(this, _SvgRenderer_instances, initG_fn).call(this);
|
|
56
|
+
}
|
|
57
|
+
save(createChild) {
|
|
58
|
+
const last = __privateGet(this, _stack)[__privateGet(this, _stack).length - 1];
|
|
59
|
+
const g = createSvgEl("g");
|
|
60
|
+
if (createChild) last.appendChild(g);
|
|
61
|
+
else last.parentNode?.appendChild(g);
|
|
62
|
+
__privateSet(this, _g, g);
|
|
63
|
+
__privateGet(this, _stack).push(g);
|
|
64
|
+
}
|
|
65
|
+
restore() {
|
|
66
|
+
if (__privateGet(this, _stack).length > 1) __privateGet(this, _stack).pop();
|
|
67
|
+
__privateSet(this, _g, __privateGet(this, _stack)[__privateGet(this, _stack).length - 1]);
|
|
68
|
+
}
|
|
69
|
+
translate(tx, ty) {
|
|
70
|
+
__privateMethod(this, _SvgRenderer_instances, transform_fn).call(this, `translate(${tx} ${ty})`);
|
|
71
|
+
}
|
|
72
|
+
rotate(radian) {
|
|
73
|
+
__privateMethod(this, _SvgRenderer_instances, transform_fn).call(this, `rotate(${radian * r2d})`);
|
|
74
|
+
}
|
|
75
|
+
scale(sx, sy) {
|
|
76
|
+
__privateMethod(this, _SvgRenderer_instances, transform_fn).call(this, `scale(${sx} ${sy})`);
|
|
77
|
+
}
|
|
78
|
+
setTransform(a, b, c, d, e, f) {
|
|
79
|
+
__privateGet(this, _g).setAttribute("transform", `matrix(${a} ${b} ${c} ${d} ${e} ${f})`);
|
|
80
|
+
}
|
|
81
|
+
setAttributes(attrs) {
|
|
82
|
+
__privateSet(this, _attributes, attrs);
|
|
83
|
+
}
|
|
84
|
+
rect(x, y, width, height) {
|
|
85
|
+
__privateGet(this, _g).appendChild(__privateMethod(this, _SvgRenderer_instances, addEl_fn).call(this, "rect", { x, y, width, height }));
|
|
86
|
+
}
|
|
87
|
+
line(x1, y1, x2, y2) {
|
|
88
|
+
__privateGet(this, _g).appendChild(__privateMethod(this, _SvgRenderer_instances, addEl_fn).call(this, "line", { x1, y1, x2, y2 }));
|
|
89
|
+
}
|
|
90
|
+
circle(x, y, radius) {
|
|
91
|
+
__privateGet(this, _g).appendChild(__privateMethod(this, _SvgRenderer_instances, addEl_fn).call(this, "circle", { cx: x, cy: y, r: radius }));
|
|
92
|
+
}
|
|
93
|
+
text(text, x, y) {
|
|
94
|
+
const textElement = __privateMethod(this, _SvgRenderer_instances, addEl_fn).call(this, "text", { x, y });
|
|
95
|
+
textElement.textContent = text;
|
|
96
|
+
__privateGet(this, _g).appendChild(textElement);
|
|
97
|
+
}
|
|
98
|
+
path(path) {
|
|
99
|
+
__privateGet(this, _g).appendChild(__privateMethod(this, _SvgRenderer_instances, addEl_fn).call(this, "path", { d: path }));
|
|
100
|
+
}
|
|
101
|
+
image(source, x, y, width, height) {
|
|
102
|
+
const href = typeof source === "string" ? source : source.src ?? "";
|
|
103
|
+
const el = __privateMethod(this, _SvgRenderer_instances, addEl_fn).call(this, "image", { href, x, y, width, height });
|
|
104
|
+
el.setAttribute("preserveAspectRatio", "none");
|
|
105
|
+
__privateGet(this, _g).appendChild(el);
|
|
106
|
+
}
|
|
107
|
+
clipPath(clipPath) {
|
|
108
|
+
const el = createSvgEl("clipPath");
|
|
109
|
+
el.setAttribute("id", clipPath.id);
|
|
110
|
+
const pathEl = createSvgEl("path");
|
|
111
|
+
pathEl.setAttribute("d", clipPath.path);
|
|
112
|
+
el.appendChild(pathEl);
|
|
113
|
+
__privateGet(this, _defs).appendChild(el);
|
|
114
|
+
}
|
|
115
|
+
gradient(options) {
|
|
116
|
+
const gradient = createSVGGradient(options);
|
|
117
|
+
if (gradient) __privateGet(this, _defs).appendChild(gradient);
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
_size = new WeakMap();
|
|
121
|
+
_element = new WeakMap();
|
|
122
|
+
_group = new WeakMap();
|
|
123
|
+
_g = new WeakMap();
|
|
124
|
+
_defs = new WeakMap();
|
|
125
|
+
_stack = new WeakMap();
|
|
126
|
+
_attributes = new WeakMap();
|
|
127
|
+
_SvgRenderer_instances = new WeakSet();
|
|
128
|
+
initG_fn = function() {
|
|
129
|
+
__privateGet(this, _group).appendChild(__privateGet(this, _g));
|
|
130
|
+
__privateGet(this, _stack).push(__privateGet(this, _g));
|
|
131
|
+
};
|
|
132
|
+
transform_fn = function(transform) {
|
|
133
|
+
__privateGet(this, _g).setAttribute("transform", `${__privateGet(this, _g).getAttribute("transform") || ""} ${transform}`);
|
|
134
|
+
};
|
|
135
|
+
addEl_fn = function(tag, attributes) {
|
|
136
|
+
return setSVGAttrs(createSvgEl(tag), { ...__privateGet(this, _attributes), ...attributes });
|
|
137
|
+
};
|
|
138
|
+
export {
|
|
139
|
+
SvgRenderer
|
|
140
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "rendx-svg",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "SVG renderer implementation for Rendx",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": "wei.liang (https://github.com/weiliang0121)",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"keywords": [
|
|
9
|
+
"rendx",
|
|
10
|
+
"2d",
|
|
11
|
+
"canvas",
|
|
12
|
+
"rendering",
|
|
13
|
+
"visualization",
|
|
14
|
+
"scene-graph"
|
|
15
|
+
],
|
|
16
|
+
"homepage": "https://weiliang0121.github.io/rendx/",
|
|
17
|
+
"repository": {
|
|
18
|
+
"type": "git",
|
|
19
|
+
"url": "https://github.com/weiliang0121/rendx.git",
|
|
20
|
+
"directory": "packages/svg"
|
|
21
|
+
},
|
|
22
|
+
"main": "dist/main.cjs",
|
|
23
|
+
"module": "dist/main.js",
|
|
24
|
+
"types": "dist/main.d.ts",
|
|
25
|
+
"exports": {
|
|
26
|
+
".": {
|
|
27
|
+
"types": "./dist/main.d.ts",
|
|
28
|
+
"import": "./dist/main.js",
|
|
29
|
+
"require": "./dist/main.cjs"
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
"dependencies": {
|
|
33
|
+
"rendx-gradient": "^0.1.0",
|
|
34
|
+
"rendx-dom": "^0.1.0",
|
|
35
|
+
"rendx-core": "^0.1.0"
|
|
36
|
+
},
|
|
37
|
+
"devDependencies": {
|
|
38
|
+
"rendx-shape": "^0.1.0",
|
|
39
|
+
"rendx-path": "^0.1.0"
|
|
40
|
+
},
|
|
41
|
+
"sideEffects": false,
|
|
42
|
+
"files": [
|
|
43
|
+
"dist"
|
|
44
|
+
],
|
|
45
|
+
"publishConfig": {
|
|
46
|
+
"access": "public"
|
|
47
|
+
},
|
|
48
|
+
"scripts": {
|
|
49
|
+
"build": "tsup",
|
|
50
|
+
"dev": "tsup --watch"
|
|
51
|
+
}
|
|
52
|
+
}
|