rendx-path 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 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,131 @@
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
+
27
+ // src/main.ts
28
+ var main_exports = {};
29
+ __export(main_exports, {
30
+ Path: () => Path
31
+ });
32
+ module.exports = __toCommonJS(main_exports);
33
+
34
+ // src/path.ts
35
+ var _d;
36
+ var Path = class {
37
+ constructor() {
38
+ __privateAdd(this, _d, "");
39
+ }
40
+ /** 返回完整路径字符串 */
41
+ toString() {
42
+ return __privateGet(this, _d);
43
+ }
44
+ /** 清空路径 */
45
+ clear() {
46
+ __privateSet(this, _d, "");
47
+ }
48
+ // 相对坐标命令
49
+ h(x) {
50
+ __privateSet(this, _d, __privateGet(this, _d) + `h${x} `);
51
+ return this;
52
+ }
53
+ v(y) {
54
+ __privateSet(this, _d, __privateGet(this, _d) + `v${y} `);
55
+ return this;
56
+ }
57
+ l(x, y) {
58
+ __privateSet(this, _d, __privateGet(this, _d) + `l${x} ${y} `);
59
+ return this;
60
+ }
61
+ q(x1, y1, x, y) {
62
+ __privateSet(this, _d, __privateGet(this, _d) + `q${x1} ${y1} ${x} ${y} `);
63
+ return this;
64
+ }
65
+ c(x1, y1, x2, y2, x, y) {
66
+ __privateSet(this, _d, __privateGet(this, _d) + `c${x1} ${y1} ${x2} ${y2} ${x} ${y} `);
67
+ return this;
68
+ }
69
+ a(rx, ry, angle, largeArcFlag, sweepFlag, x, y) {
70
+ __privateSet(this, _d, __privateGet(this, _d) + `a${rx} ${ry} ${angle} ${largeArcFlag} ${sweepFlag} ${x} ${y} `);
71
+ return this;
72
+ }
73
+ // 绝对坐标命令
74
+ M(x, y) {
75
+ __privateSet(this, _d, __privateGet(this, _d) + `M${x} ${y} `);
76
+ return this;
77
+ }
78
+ H(x) {
79
+ __privateSet(this, _d, __privateGet(this, _d) + `H${x} `);
80
+ return this;
81
+ }
82
+ V(y) {
83
+ __privateSet(this, _d, __privateGet(this, _d) + `V${y} `);
84
+ return this;
85
+ }
86
+ L(x, y) {
87
+ __privateSet(this, _d, __privateGet(this, _d) + `L${x} ${y} `);
88
+ return this;
89
+ }
90
+ Q(x1, y1, x, y) {
91
+ __privateSet(this, _d, __privateGet(this, _d) + `Q${x1} ${y1} ${x} ${y} `);
92
+ return this;
93
+ }
94
+ /**
95
+ * 绝对坐标三次贝塞尔曲线
96
+ * @param x1 - 控制点1 X
97
+ * @param y1 - 控制点1 Y
98
+ * @param x2 - 控制点2 X
99
+ * @param y2 - 控制点2 Y
100
+ * @param x - 终点 X
101
+ * @param y - 终点 Y
102
+ */
103
+ C(x1, y1, x2, y2, x, y) {
104
+ __privateSet(this, _d, __privateGet(this, _d) + `C${x1} ${y1} ${x2} ${y2} ${x} ${y} `);
105
+ return this;
106
+ }
107
+ /**
108
+ * 绝对坐标椭圆弧
109
+ * @param rx - X 轴半径
110
+ * @param ry - Y 轴半径
111
+ * @param angle - X 轴旋转角度
112
+ * @param largeArcFlag - 大弧标志 (0|1)
113
+ * @param sweepFlag - 顺时针标志 (0|1)
114
+ * @param x - 终点 X
115
+ * @param y - 终点 Y
116
+ */
117
+ A(rx, ry, angle, largeArcFlag, sweepFlag, x, y) {
118
+ __privateSet(this, _d, __privateGet(this, _d) + `A${rx} ${ry} ${angle} ${largeArcFlag} ${sweepFlag} ${x} ${y} `);
119
+ return this;
120
+ }
121
+ // 闭合路径
122
+ Z() {
123
+ __privateSet(this, _d, __privateGet(this, _d) + "Z ");
124
+ return this;
125
+ }
126
+ };
127
+ _d = new WeakMap();
128
+ // Annotate the CommonJS export names for ESM import in node:
129
+ 0 && (module.exports = {
130
+ Path
131
+ });
@@ -0,0 +1,60 @@
1
+ /**
2
+ * SVG 路径命令构建器
3
+ *
4
+ * 使用直接字符串拼接(+=)替代 string[] + join,
5
+ * V8 引擎对 += 使用 cons string(rope)优化,amortized O(1),
6
+ * 消除了数组分配、push 和 join 的开销。
7
+ */
8
+ /**
9
+ * SVG 路径命令构建器,链式 API 生成 SVG path d 属性。
10
+ * 内部使用字符串拼接(`+=`)优化性能。
11
+ *
12
+ * @example
13
+ * ```ts
14
+ * const p = new Path();
15
+ * p.M(0, 0).L(100, 0).L(100, 100).Z();
16
+ * p.toString(); // "M0 0 L100 0 L100 100 Z "
17
+ * ```
18
+ */
19
+ declare class Path {
20
+ #private;
21
+ /** 返回完整路径字符串 */
22
+ toString(): string;
23
+ /** 清空路径 */
24
+ clear(): void;
25
+ h(x: number): this;
26
+ v(y: number): this;
27
+ l(x: number, y: number): this;
28
+ q(x1: number, y1: number, x: number, y: number): this;
29
+ c(x1: number, y1: number, x2: number, y2: number, x: number, y: number): this;
30
+ a(rx: number, ry: number, angle: number, largeArcFlag: number, sweepFlag: number, x: number, y: number): this;
31
+ M(x: number, y: number): this;
32
+ H(x: number): this;
33
+ V(y: number): this;
34
+ L(x: number, y: number): this;
35
+ Q(x1: number, y1: number, x: number, y: number): this;
36
+ /**
37
+ * 绝对坐标三次贝塞尔曲线
38
+ * @param x1 - 控制点1 X
39
+ * @param y1 - 控制点1 Y
40
+ * @param x2 - 控制点2 X
41
+ * @param y2 - 控制点2 Y
42
+ * @param x - 终点 X
43
+ * @param y - 终点 Y
44
+ */
45
+ C(x1: number, y1: number, x2: number, y2: number, x: number, y: number): this;
46
+ /**
47
+ * 绝对坐标椭圆弧
48
+ * @param rx - X 轴半径
49
+ * @param ry - Y 轴半径
50
+ * @param angle - X 轴旋转角度
51
+ * @param largeArcFlag - 大弧标志 (0|1)
52
+ * @param sweepFlag - 顺时针标志 (0|1)
53
+ * @param x - 终点 X
54
+ * @param y - 终点 Y
55
+ */
56
+ A(rx: number, ry: number, angle: number, largeArcFlag: number, sweepFlag: number, x: number, y: number): this;
57
+ Z(): this;
58
+ }
59
+
60
+ export { Path };
package/dist/main.d.ts ADDED
@@ -0,0 +1,60 @@
1
+ /**
2
+ * SVG 路径命令构建器
3
+ *
4
+ * 使用直接字符串拼接(+=)替代 string[] + join,
5
+ * V8 引擎对 += 使用 cons string(rope)优化,amortized O(1),
6
+ * 消除了数组分配、push 和 join 的开销。
7
+ */
8
+ /**
9
+ * SVG 路径命令构建器,链式 API 生成 SVG path d 属性。
10
+ * 内部使用字符串拼接(`+=`)优化性能。
11
+ *
12
+ * @example
13
+ * ```ts
14
+ * const p = new Path();
15
+ * p.M(0, 0).L(100, 0).L(100, 100).Z();
16
+ * p.toString(); // "M0 0 L100 0 L100 100 Z "
17
+ * ```
18
+ */
19
+ declare class Path {
20
+ #private;
21
+ /** 返回完整路径字符串 */
22
+ toString(): string;
23
+ /** 清空路径 */
24
+ clear(): void;
25
+ h(x: number): this;
26
+ v(y: number): this;
27
+ l(x: number, y: number): this;
28
+ q(x1: number, y1: number, x: number, y: number): this;
29
+ c(x1: number, y1: number, x2: number, y2: number, x: number, y: number): this;
30
+ a(rx: number, ry: number, angle: number, largeArcFlag: number, sweepFlag: number, x: number, y: number): this;
31
+ M(x: number, y: number): this;
32
+ H(x: number): this;
33
+ V(y: number): this;
34
+ L(x: number, y: number): this;
35
+ Q(x1: number, y1: number, x: number, y: number): this;
36
+ /**
37
+ * 绝对坐标三次贝塞尔曲线
38
+ * @param x1 - 控制点1 X
39
+ * @param y1 - 控制点1 Y
40
+ * @param x2 - 控制点2 X
41
+ * @param y2 - 控制点2 Y
42
+ * @param x - 终点 X
43
+ * @param y - 终点 Y
44
+ */
45
+ C(x1: number, y1: number, x2: number, y2: number, x: number, y: number): this;
46
+ /**
47
+ * 绝对坐标椭圆弧
48
+ * @param rx - X 轴半径
49
+ * @param ry - Y 轴半径
50
+ * @param angle - X 轴旋转角度
51
+ * @param largeArcFlag - 大弧标志 (0|1)
52
+ * @param sweepFlag - 顺时针标志 (0|1)
53
+ * @param x - 终点 X
54
+ * @param y - 终点 Y
55
+ */
56
+ A(rx: number, ry: number, angle: number, largeArcFlag: number, sweepFlag: number, x: number, y: number): this;
57
+ Z(): this;
58
+ }
59
+
60
+ export { Path };
package/dist/main.js ADDED
@@ -0,0 +1,105 @@
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
+
9
+ // src/path.ts
10
+ var _d;
11
+ var Path = class {
12
+ constructor() {
13
+ __privateAdd(this, _d, "");
14
+ }
15
+ /** 返回完整路径字符串 */
16
+ toString() {
17
+ return __privateGet(this, _d);
18
+ }
19
+ /** 清空路径 */
20
+ clear() {
21
+ __privateSet(this, _d, "");
22
+ }
23
+ // 相对坐标命令
24
+ h(x) {
25
+ __privateSet(this, _d, __privateGet(this, _d) + `h${x} `);
26
+ return this;
27
+ }
28
+ v(y) {
29
+ __privateSet(this, _d, __privateGet(this, _d) + `v${y} `);
30
+ return this;
31
+ }
32
+ l(x, y) {
33
+ __privateSet(this, _d, __privateGet(this, _d) + `l${x} ${y} `);
34
+ return this;
35
+ }
36
+ q(x1, y1, x, y) {
37
+ __privateSet(this, _d, __privateGet(this, _d) + `q${x1} ${y1} ${x} ${y} `);
38
+ return this;
39
+ }
40
+ c(x1, y1, x2, y2, x, y) {
41
+ __privateSet(this, _d, __privateGet(this, _d) + `c${x1} ${y1} ${x2} ${y2} ${x} ${y} `);
42
+ return this;
43
+ }
44
+ a(rx, ry, angle, largeArcFlag, sweepFlag, x, y) {
45
+ __privateSet(this, _d, __privateGet(this, _d) + `a${rx} ${ry} ${angle} ${largeArcFlag} ${sweepFlag} ${x} ${y} `);
46
+ return this;
47
+ }
48
+ // 绝对坐标命令
49
+ M(x, y) {
50
+ __privateSet(this, _d, __privateGet(this, _d) + `M${x} ${y} `);
51
+ return this;
52
+ }
53
+ H(x) {
54
+ __privateSet(this, _d, __privateGet(this, _d) + `H${x} `);
55
+ return this;
56
+ }
57
+ V(y) {
58
+ __privateSet(this, _d, __privateGet(this, _d) + `V${y} `);
59
+ return this;
60
+ }
61
+ L(x, y) {
62
+ __privateSet(this, _d, __privateGet(this, _d) + `L${x} ${y} `);
63
+ return this;
64
+ }
65
+ Q(x1, y1, x, y) {
66
+ __privateSet(this, _d, __privateGet(this, _d) + `Q${x1} ${y1} ${x} ${y} `);
67
+ return this;
68
+ }
69
+ /**
70
+ * 绝对坐标三次贝塞尔曲线
71
+ * @param x1 - 控制点1 X
72
+ * @param y1 - 控制点1 Y
73
+ * @param x2 - 控制点2 X
74
+ * @param y2 - 控制点2 Y
75
+ * @param x - 终点 X
76
+ * @param y - 终点 Y
77
+ */
78
+ C(x1, y1, x2, y2, x, y) {
79
+ __privateSet(this, _d, __privateGet(this, _d) + `C${x1} ${y1} ${x2} ${y2} ${x} ${y} `);
80
+ return this;
81
+ }
82
+ /**
83
+ * 绝对坐标椭圆弧
84
+ * @param rx - X 轴半径
85
+ * @param ry - Y 轴半径
86
+ * @param angle - X 轴旋转角度
87
+ * @param largeArcFlag - 大弧标志 (0|1)
88
+ * @param sweepFlag - 顺时针标志 (0|1)
89
+ * @param x - 终点 X
90
+ * @param y - 终点 Y
91
+ */
92
+ A(rx, ry, angle, largeArcFlag, sweepFlag, x, y) {
93
+ __privateSet(this, _d, __privateGet(this, _d) + `A${rx} ${ry} ${angle} ${largeArcFlag} ${sweepFlag} ${x} ${y} `);
94
+ return this;
95
+ }
96
+ // 闭合路径
97
+ Z() {
98
+ __privateSet(this, _d, __privateGet(this, _d) + "Z ");
99
+ return this;
100
+ }
101
+ };
102
+ _d = new WeakMap();
103
+ export {
104
+ Path
105
+ };
package/package.json ADDED
@@ -0,0 +1,43 @@
1
+ {
2
+ "name": "rendx-path",
3
+ "version": "0.1.0",
4
+ "description": "SVG path builder and parser",
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/path"
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
+ "sideEffects": false,
33
+ "files": [
34
+ "dist"
35
+ ],
36
+ "publishConfig": {
37
+ "access": "public"
38
+ },
39
+ "scripts": {
40
+ "build": "tsup",
41
+ "dev": "tsup --watch"
42
+ }
43
+ }