rendx-shape 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 +574 -0
- package/dist/main.d.cts +229 -0
- package/dist/main.d.ts +229 -0
- package/dist/main.js +511 -0
- package/package.json +48 -0
package/dist/main.js
ADDED
|
@@ -0,0 +1,511 @@
|
|
|
1
|
+
// src/primitives/circle.ts
|
|
2
|
+
var createCircle = (path, { cx, cy, r }) => {
|
|
3
|
+
path.M(cx, cy - r);
|
|
4
|
+
path.A(r, r, 0, 1, 0, cx, cy + r);
|
|
5
|
+
path.A(r, r, 0, 1, 0, cx, cy - r);
|
|
6
|
+
path.Z();
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
// src/primitives/rect.ts
|
|
10
|
+
import { isNum, isUndef } from "rendx-core";
|
|
11
|
+
var createRectNormal = (path, { x, y, width, height }) => {
|
|
12
|
+
path.M(x, y);
|
|
13
|
+
path.L(x + width, y);
|
|
14
|
+
path.L(x + width, y + height);
|
|
15
|
+
path.L(x, y + height);
|
|
16
|
+
path.Z();
|
|
17
|
+
};
|
|
18
|
+
var createRectRounded = (path, { x, y, width, height, rx, ry }) => {
|
|
19
|
+
if (isNum(rx)) rx = [rx, rx, rx, rx];
|
|
20
|
+
if (isNum(ry)) ry = [ry, ry, ry, ry];
|
|
21
|
+
const [rx1, rx2, rx3 = rx1, rx4 = rx2] = rx.map(Number).map((r) => Math.min(r, width / 2));
|
|
22
|
+
const [ry1, ry2, ry3 = ry1, ry4 = ry2] = ry.map(Number).map((r) => Math.min(r, height / 2));
|
|
23
|
+
path.M(x + rx1, y);
|
|
24
|
+
path.L(x + width - rx2, y);
|
|
25
|
+
path.A(rx2, ry2, 0, 0, 1, x + width, y + ry2);
|
|
26
|
+
path.L(x + width, y + height - ry3);
|
|
27
|
+
path.A(rx3, ry3, 0, 0, 1, x + width - rx3, y + height);
|
|
28
|
+
path.L(x + rx4, y + height);
|
|
29
|
+
path.A(rx4, ry4, 0, 0, 1, x, y + height - ry4);
|
|
30
|
+
path.L(x, y + ry1);
|
|
31
|
+
path.A(rx1, ry1, 0, 0, 1, x + rx1, y);
|
|
32
|
+
path.Z();
|
|
33
|
+
};
|
|
34
|
+
var createRect = (path, options) => {
|
|
35
|
+
const { rx, ry } = options;
|
|
36
|
+
if (!isUndef(rx) && rx !== 0 && !isUndef(ry) && ry !== 0) createRectRounded(path, options);
|
|
37
|
+
else createRectNormal(path, options);
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
// src/polar/arc.ts
|
|
41
|
+
var createArc = (path, options) => {
|
|
42
|
+
const { cx, cy, r, startAngle, endAngle, radius } = options;
|
|
43
|
+
const r1 = r * radius;
|
|
44
|
+
const t0 = startAngle;
|
|
45
|
+
const t1 = endAngle;
|
|
46
|
+
if (Math.abs(t1 - t0) >= 2 * Math.PI) return createCircle(path, { cx, cy, r: r1 });
|
|
47
|
+
const largeArcFlag = Math.abs(t1 - t0) % (2 * Math.PI) > Math.PI ? 1 : 0;
|
|
48
|
+
path.M(cx + r1 * Math.cos(t0), cy + r1 * Math.sin(t0));
|
|
49
|
+
path.A(r1, r1, 0, largeArcFlag, 1, cx + r1 * Math.cos(t1), cy + r1 * Math.sin(t1));
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
// src/polar/ring.ts
|
|
53
|
+
var createRing = (path, options) => {
|
|
54
|
+
const { cx, cy, r, innerRadius, outerRadius } = options;
|
|
55
|
+
const r0 = innerRadius * r;
|
|
56
|
+
const r1 = outerRadius * r;
|
|
57
|
+
path.M(cx, cy - r1);
|
|
58
|
+
path.A(r1, r1, 0, 1, 0, cx, cy + r1);
|
|
59
|
+
path.L(cx, cy + r0);
|
|
60
|
+
path.A(r0, r0, 0, 1, 1, cx, cy - r0);
|
|
61
|
+
path.Z();
|
|
62
|
+
path.M(cx, cy - r0);
|
|
63
|
+
path.A(r0, r0, 0, 1, 1, cx, cy + r0);
|
|
64
|
+
path.L(cx, cy + r1);
|
|
65
|
+
path.A(r1, r1, 0, 1, 0, cx, cy - r1);
|
|
66
|
+
path.Z();
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
// src/polar/sector.ts
|
|
70
|
+
import { isNum as isNum2, isUndef as isUndef2 } from "rendx-core";
|
|
71
|
+
var createSectorNormal = (path, options) => {
|
|
72
|
+
const { cx, cy, r, startAngle, endAngle, innerRadius, outerRadius } = options;
|
|
73
|
+
const r0 = innerRadius * r;
|
|
74
|
+
const r1 = outerRadius * r;
|
|
75
|
+
const t0 = startAngle;
|
|
76
|
+
const t1 = endAngle;
|
|
77
|
+
if (Math.abs(t1 - t0) >= 2 * Math.PI) return createRing(path, { cx, cy, r, innerRadius, outerRadius });
|
|
78
|
+
const largeArcFlag = (t1 - t0) % (2 * Math.PI) > Math.PI ? 1 : 0;
|
|
79
|
+
path.M(cx + r1 * Math.cos(t0), cy + r1 * Math.sin(t0));
|
|
80
|
+
path.A(r1, r1, 0, largeArcFlag, 1, cx + r1 * Math.cos(t1), cy + r1 * Math.sin(t1));
|
|
81
|
+
if (r0 === 0) {
|
|
82
|
+
path.L(cx, cy);
|
|
83
|
+
} else {
|
|
84
|
+
path.L(cx + r0 * Math.cos(t1), cy + r0 * Math.sin(t1));
|
|
85
|
+
path.A(r0, r0, 0, largeArcFlag, 0, cx + r0 * Math.cos(t0), cy + r0 * Math.sin(t0));
|
|
86
|
+
}
|
|
87
|
+
path.Z();
|
|
88
|
+
};
|
|
89
|
+
var tangent = (t, t0, r, rc, outer, left) => {
|
|
90
|
+
const rc0 = outer ? r * Math.sin(t / 2) / (1 + Math.sin(t / 2)) : r * Math.sin(t / 2) / (1 - Math.sin(t / 2));
|
|
91
|
+
if (rc > rc0) rc = rc0;
|
|
92
|
+
const sign = outer ? 1 : -1;
|
|
93
|
+
const ot = Math.asin(rc / (r + sign * rc));
|
|
94
|
+
const t1 = left ? (t0 + ot) % (2 * Math.PI) : (t0 - ot) % (2 * Math.PI);
|
|
95
|
+
const r0 = (r + sign * rc) * Math.cos(ot);
|
|
96
|
+
return {
|
|
97
|
+
ot,
|
|
98
|
+
cx: (r + sign * rc) * Math.cos(t1),
|
|
99
|
+
cy: (r + sign * rc) * Math.sin(t1),
|
|
100
|
+
x0: r0 * Math.cos(t0),
|
|
101
|
+
y0: r0 * Math.sin(t0),
|
|
102
|
+
x1: r * Math.cos(t1),
|
|
103
|
+
y1: r * Math.sin(t1),
|
|
104
|
+
rc
|
|
105
|
+
};
|
|
106
|
+
};
|
|
107
|
+
var epsilon = 1e-6;
|
|
108
|
+
var createSectorRounded = (path, options) => {
|
|
109
|
+
const { cx, cy, r, startAngle, endAngle, innerRadius, outerRadius } = options;
|
|
110
|
+
let { rc } = options;
|
|
111
|
+
if (isNum2(rc)) rc = [rc, rc, rc, rc];
|
|
112
|
+
const r0 = innerRadius * r;
|
|
113
|
+
const r1 = outerRadius * r;
|
|
114
|
+
const t0 = startAngle;
|
|
115
|
+
const t1 = endAngle;
|
|
116
|
+
const dt = Math.abs(t1 - t0);
|
|
117
|
+
const dr = Math.abs(r1 - r0);
|
|
118
|
+
if (Math.abs(t1 - t0) >= 2 * Math.PI) return createRing(path, { cx, cy, r, innerRadius, outerRadius });
|
|
119
|
+
const [rc01, rc00, rc11 = rc01, rc10 = rc00] = rc.map((x) => Math.max(0, Math.min(x, dr / 2)));
|
|
120
|
+
if (dt < 1e-6) return;
|
|
121
|
+
const c01 = tangent(dt, t0, r1, rc01, true, true);
|
|
122
|
+
const c11 = tangent(dt, t1, r1, rc11, true, false);
|
|
123
|
+
let largeArcFlag = dt - c01.ot - c11.ot > Math.PI - epsilon ? 1 : 0;
|
|
124
|
+
path.M(cx + c01.x0, cy + c01.y0);
|
|
125
|
+
path.A(c01.rc, c01.rc, 0, 0, 1, cx + c01.x1, cy + c01.y1);
|
|
126
|
+
path.A(r1, r1, 0, largeArcFlag, 1, cx + c11.x1, cy + c11.y1);
|
|
127
|
+
path.A(c11.rc, c11.rc, 0, 0, 1, cx + c11.x0, cy + c11.y0);
|
|
128
|
+
if (r0 === 0) {
|
|
129
|
+
path.L(cx, cy);
|
|
130
|
+
} else {
|
|
131
|
+
const c00 = tangent(dt, t0, r0, rc00, false, true);
|
|
132
|
+
const c10 = tangent(dt, t1, r0, rc10, false, false);
|
|
133
|
+
largeArcFlag = dt - c00.ot - c10.ot > Math.PI - epsilon ? 1 : 0;
|
|
134
|
+
path.L(cx + c10.x0, cy + c10.y0);
|
|
135
|
+
path.A(c10.rc, c10.rc, 0, 0, 1, cx + c10.x1, cy + c10.y1);
|
|
136
|
+
path.A(r0, r0, 0, largeArcFlag, 0, cx + c00.x1, cy + c00.y1);
|
|
137
|
+
path.A(c00.rc, c00.rc, 0, 0, 1, cx + c00.x0, cy + c00.y0);
|
|
138
|
+
}
|
|
139
|
+
path.Z();
|
|
140
|
+
};
|
|
141
|
+
var createSector = (path, options) => {
|
|
142
|
+
const { rc, startAngle, endAngle, padAngle = 0 } = options;
|
|
143
|
+
const da = Math.abs(endAngle - startAngle) - padAngle;
|
|
144
|
+
if (da <= 1e-4) return;
|
|
145
|
+
const hp = padAngle / 2;
|
|
146
|
+
options.startAngle = startAngle + hp;
|
|
147
|
+
options.endAngle = endAngle - hp;
|
|
148
|
+
if (!isUndef2(rc) && rc !== 0) createSectorRounded(path, options);
|
|
149
|
+
else createSectorNormal(path, options);
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
// src/data/line.ts
|
|
153
|
+
import { curveMap } from "rendx-curve";
|
|
154
|
+
var createLine = (path, options) => {
|
|
155
|
+
const { curve = "linear", closed = false, points } = options;
|
|
156
|
+
if (Reflect.has(curveMap, curve)) curveMap[curve](path, points);
|
|
157
|
+
if (points.length === 1) path.Z();
|
|
158
|
+
if (closed) path.Z();
|
|
159
|
+
};
|
|
160
|
+
var createSegmentLine = (path, options) => {
|
|
161
|
+
const { curve, closed = false, segments } = options;
|
|
162
|
+
const len = segments.length;
|
|
163
|
+
for (let i = 0; i < len; i++) createLine(path, { curve, points: segments[i] });
|
|
164
|
+
if (closed) path.Z();
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
// src/data/area.ts
|
|
168
|
+
import { curveMap as curveMap2 } from "rendx-curve";
|
|
169
|
+
var createArea = (path, options) => {
|
|
170
|
+
const { upperPoints, lowerPoints, curve = "linear", upperCurve = curve, lowerCurve = curve } = options;
|
|
171
|
+
if (Reflect.has(curveMap2, upperCurve)) curveMap2[upperCurve](path, upperPoints);
|
|
172
|
+
const [x, y] = lowerPoints.at(-1);
|
|
173
|
+
path.L(x, y);
|
|
174
|
+
if (Reflect.has(curveMap2, lowerCurve)) curveMap2[lowerCurve](path, lowerPoints.reverse(), false);
|
|
175
|
+
path.Z();
|
|
176
|
+
};
|
|
177
|
+
var createSegmentArea = (path, options) => {
|
|
178
|
+
const { upperSegments, lowerSegments, curve = "linear", upperCurve = curve, lowerCurve = curve } = options;
|
|
179
|
+
const length = Math.min(upperSegments.length, lowerSegments.length);
|
|
180
|
+
for (let i = 0; i < length; i++) {
|
|
181
|
+
createArea(path, { upperPoints: upperSegments[i], lowerPoints: lowerSegments[i], curve, upperCurve, lowerCurve });
|
|
182
|
+
}
|
|
183
|
+
};
|
|
184
|
+
|
|
185
|
+
// src/data/box.ts
|
|
186
|
+
var createBoxX = (path, options) => {
|
|
187
|
+
const { cx, minY, maxY, q1Y, q2Y, q3Y, x, y, width, height } = options;
|
|
188
|
+
path.clear();
|
|
189
|
+
path.M(x, y).H(x + width).V(y + height).H(x).Z();
|
|
190
|
+
path.M(cx, maxY).V(q3Y);
|
|
191
|
+
path.M(cx, minY).V(q1Y);
|
|
192
|
+
path.M(x, maxY).H(x + width);
|
|
193
|
+
path.M(x, q2Y).H(x + width);
|
|
194
|
+
path.M(x, minY).H(x + width);
|
|
195
|
+
};
|
|
196
|
+
var createBoxY = (path, options) => {
|
|
197
|
+
const { cy, minX, maxX, q1X, q2X, q3X, x, y, width, height } = options;
|
|
198
|
+
path.clear();
|
|
199
|
+
path.M(x, y).H(x + width).V(y + height).H(x).Z();
|
|
200
|
+
path.M(maxX, cy).H(q3X);
|
|
201
|
+
path.M(minX, cy).H(q1X);
|
|
202
|
+
path.M(maxX, y).V(y + height);
|
|
203
|
+
path.M(q2X, y).V(y + height);
|
|
204
|
+
path.M(minX, y).V(y + height);
|
|
205
|
+
};
|
|
206
|
+
|
|
207
|
+
// src/factory.ts
|
|
208
|
+
var shapeCreators = /* @__PURE__ */ new Map([
|
|
209
|
+
["circle", createCircle],
|
|
210
|
+
["rect", createRect],
|
|
211
|
+
["arc", createArc],
|
|
212
|
+
["sector", createSector],
|
|
213
|
+
["line", createLine],
|
|
214
|
+
["segmentLine", createSegmentLine],
|
|
215
|
+
["area", createArea],
|
|
216
|
+
["segmentArea", createSegmentArea],
|
|
217
|
+
["boxX", createBoxX],
|
|
218
|
+
["boxY", createBoxY]
|
|
219
|
+
]);
|
|
220
|
+
var createShape = (path, type, options) => {
|
|
221
|
+
const creator = shapeCreators.get(type);
|
|
222
|
+
if (!creator) throw new Error(`Unknown shape type: ${type}`);
|
|
223
|
+
creator(path, options);
|
|
224
|
+
};
|
|
225
|
+
|
|
226
|
+
// src/symbols/circle.ts
|
|
227
|
+
var createCircleSymbol = createCircle;
|
|
228
|
+
|
|
229
|
+
// src/symbols/cross.ts
|
|
230
|
+
var createCrossSymbol = (path, { cx, cy, r }) => {
|
|
231
|
+
const lw = r * 0.382;
|
|
232
|
+
path.M(cx - r, cy - lw);
|
|
233
|
+
path.L(cx - lw, cy - lw);
|
|
234
|
+
path.L(cx - lw, cy - r);
|
|
235
|
+
path.L(cx + lw, cy - r);
|
|
236
|
+
path.L(cx + lw, cy - lw);
|
|
237
|
+
path.L(cx + r, cy - lw);
|
|
238
|
+
path.L(cx + r, cy + lw);
|
|
239
|
+
path.L(cx + lw, cy + lw);
|
|
240
|
+
path.L(cx + lw, cy + r);
|
|
241
|
+
path.L(cx - lw, cy + r);
|
|
242
|
+
path.L(cx - lw, cy + lw);
|
|
243
|
+
path.L(cx - r, cy + lw);
|
|
244
|
+
path.Z();
|
|
245
|
+
};
|
|
246
|
+
|
|
247
|
+
// src/symbols/diamond.ts
|
|
248
|
+
var createDiamondSymbol = (path, { cx, cy, r }) => {
|
|
249
|
+
path.M(cx - r, cy);
|
|
250
|
+
path.L(cx, cy - r);
|
|
251
|
+
path.L(cx + r, cy);
|
|
252
|
+
path.L(cx, cy + r);
|
|
253
|
+
path.Z();
|
|
254
|
+
};
|
|
255
|
+
|
|
256
|
+
// src/symbols/square.ts
|
|
257
|
+
var createSquareSymbol = (path, { cx, cy, r }) => {
|
|
258
|
+
path.M(cx - r, cy - r);
|
|
259
|
+
path.L(cx + r, cy - r);
|
|
260
|
+
path.L(cx + r, cy + r);
|
|
261
|
+
path.L(cx - r, cy + r);
|
|
262
|
+
path.Z();
|
|
263
|
+
};
|
|
264
|
+
|
|
265
|
+
// src/symbols/triangle.ts
|
|
266
|
+
var createTriangle = (path, cx, cy, r, points) => {
|
|
267
|
+
path.M(cx + points[0][0] * r, cy + points[0][1] * r);
|
|
268
|
+
for (let i = 1; i < points.length; i++) path.L(cx + points[i][0] * r, cy + points[i][1] * r);
|
|
269
|
+
path.Z();
|
|
270
|
+
};
|
|
271
|
+
var createUpTriangleSymbol = (path, { cx, cy, r }) => {
|
|
272
|
+
createTriangle(path, +cx, +cy, +r, [
|
|
273
|
+
[0, -1],
|
|
274
|
+
[-1, 1],
|
|
275
|
+
[1, 1]
|
|
276
|
+
]);
|
|
277
|
+
};
|
|
278
|
+
var createDownTriangleSymbol = (path, { cx, cy, r }) => {
|
|
279
|
+
createTriangle(path, +cx, +cy, +r, [
|
|
280
|
+
[0, 1],
|
|
281
|
+
[-1, -1],
|
|
282
|
+
[1, -1]
|
|
283
|
+
]);
|
|
284
|
+
};
|
|
285
|
+
var createLeftTriangleSymbol = (path, { cx, cy, r }) => {
|
|
286
|
+
createTriangle(path, +cx, +cy, +r, [
|
|
287
|
+
[-1, 0],
|
|
288
|
+
[1, -1],
|
|
289
|
+
[1, 1]
|
|
290
|
+
]);
|
|
291
|
+
};
|
|
292
|
+
var createRightTriangleSymbol = (path, { cx, cy, r }) => {
|
|
293
|
+
createTriangle(path, +cx, +cy, +r, [
|
|
294
|
+
[1, 0],
|
|
295
|
+
[-1, -1],
|
|
296
|
+
[-1, 1]
|
|
297
|
+
]);
|
|
298
|
+
};
|
|
299
|
+
var createTriangleSymbol = createUpTriangleSymbol;
|
|
300
|
+
var createInvertedTriangleSymbol = createDownTriangleSymbol;
|
|
301
|
+
|
|
302
|
+
// src/symbols/line.ts
|
|
303
|
+
var createHLineSymbol = (path, { cx, cy, r }) => {
|
|
304
|
+
path.M(cx - r, cy);
|
|
305
|
+
path.L(cx + r, cy);
|
|
306
|
+
path.Z();
|
|
307
|
+
};
|
|
308
|
+
var createVLineSymbol = (path, { cx, cy, r }) => {
|
|
309
|
+
path.M(cx, cy - r);
|
|
310
|
+
path.L(cx, cy + r);
|
|
311
|
+
path.Z();
|
|
312
|
+
};
|
|
313
|
+
|
|
314
|
+
// src/symbols/eye.ts
|
|
315
|
+
var createEyeSymbol = (path, { cx, cy, r }) => {
|
|
316
|
+
path.M(cx, cy - r);
|
|
317
|
+
path.A(r, r, 0, 1, 0, cx, cy + r);
|
|
318
|
+
path.A(r, r, 0, 1, 0, cx, cy - r);
|
|
319
|
+
path.Z();
|
|
320
|
+
};
|
|
321
|
+
var createClosedEyeSymbol = (path, { cx, cy, r }) => {
|
|
322
|
+
const rx = r * 2 / 3;
|
|
323
|
+
const ry = r / 2;
|
|
324
|
+
const r2 = r / 5;
|
|
325
|
+
const dx = r * 2 / 3 + 2;
|
|
326
|
+
const dy = r / 5 + 2;
|
|
327
|
+
path.M(cx - rx, cy);
|
|
328
|
+
path.A(rx, ry, 0, 1, 0, cx + rx, cy);
|
|
329
|
+
path.A(rx, ry, 0, 1, 0, cx - rx, cy);
|
|
330
|
+
path.M(cx - r2, cy);
|
|
331
|
+
path.A(r2, r2, 0, 1, 1, cx + r2, cy);
|
|
332
|
+
path.A(r2, r2, 0, 1, 1, cx - r2, cy);
|
|
333
|
+
path.M(cx - dx, cy + dy);
|
|
334
|
+
path.L(cx + dx, cy - dy);
|
|
335
|
+
};
|
|
336
|
+
|
|
337
|
+
// src/symbols/reset.ts
|
|
338
|
+
var createResetSymbol = (path, { cx, cy, r }) => {
|
|
339
|
+
path.M(cx - 0.5 * r, cy + 0.2 * r);
|
|
340
|
+
path.L(cx - 0.5 * r, cy + r);
|
|
341
|
+
path.L(cx + r, cy + r);
|
|
342
|
+
path.L(cx + r, cy - 0.5 * r);
|
|
343
|
+
path.L(cx - 0.8 * r, cy - 0.5 * r);
|
|
344
|
+
path.M(cx - 0.2 * r, cy - 0.8 * r);
|
|
345
|
+
path.L(cx - 0.8 * r, cy - 0.5 * r);
|
|
346
|
+
path.L(cx - 0.2 * r, cy - 0.2 * r);
|
|
347
|
+
};
|
|
348
|
+
|
|
349
|
+
// src/symbols/select.ts
|
|
350
|
+
var createSelectSymbol = (path, { cx, cy, r }) => {
|
|
351
|
+
path.M(cx - 0.5 * r, cy + 0.2 * r);
|
|
352
|
+
path.L(cx - 0.5 * r, cy + r);
|
|
353
|
+
path.L(cx + r, cy + r);
|
|
354
|
+
path.L(cx + r, cy - 0.5 * r);
|
|
355
|
+
path.L(cx + 0.2 * r, cy - 0.5 * r);
|
|
356
|
+
path.M(cx - r, cy - 0.5 * r);
|
|
357
|
+
path.L(cx, cy - 0.5 * r);
|
|
358
|
+
path.M(cx - 0.5 * r, cy - r);
|
|
359
|
+
path.L(cx - 0.5 * r, cy);
|
|
360
|
+
};
|
|
361
|
+
|
|
362
|
+
// src/symbols/star.ts
|
|
363
|
+
var STAR_COS = [];
|
|
364
|
+
var STAR_SIN = [];
|
|
365
|
+
for (let i = 0; i < 5; i++) {
|
|
366
|
+
const a0 = (i * 72 - 18) * Math.PI / 180;
|
|
367
|
+
const a1 = a0 + 36 * Math.PI / 180;
|
|
368
|
+
STAR_COS.push(Math.cos(a0), 0.5 * Math.cos(a1));
|
|
369
|
+
STAR_SIN.push(Math.sin(a0), 0.5 * Math.sin(a1));
|
|
370
|
+
}
|
|
371
|
+
var createStarSymbol = (path, { cx, cy, r }) => {
|
|
372
|
+
path.M(cx + r * STAR_COS[0], cy + r * STAR_SIN[0]);
|
|
373
|
+
for (let i = 1; i < 10; i++) {
|
|
374
|
+
path.L(cx + r * STAR_COS[i], cy + r * STAR_SIN[i]);
|
|
375
|
+
}
|
|
376
|
+
path.Z();
|
|
377
|
+
};
|
|
378
|
+
|
|
379
|
+
// src/symbols/wye.ts
|
|
380
|
+
var sin = 0.5;
|
|
381
|
+
var cos = Math.sqrt(3) / 2;
|
|
382
|
+
var createWyeSymbol = (path, { cx, cy, r }) => {
|
|
383
|
+
const lineWidth = r * (1 - 0.618);
|
|
384
|
+
const r1 = r;
|
|
385
|
+
const r2 = 1 / cos * lineWidth;
|
|
386
|
+
const r3 = r - r2 * sin;
|
|
387
|
+
const r4 = r - lineWidth * (cos / sin);
|
|
388
|
+
path.M(cx - r2 * cos, cy + r2 * sin);
|
|
389
|
+
path.L(cx - r2 * cos, cy + r1);
|
|
390
|
+
path.L(cx + r2 * cos, cy + r1);
|
|
391
|
+
path.L(cx + r2 * cos, cy + r2 * sin);
|
|
392
|
+
path.L(cx + 2 * lineWidth + r4 * cos, cy - r4 * sin);
|
|
393
|
+
path.L(cx + r3 * cos, cy - r2 - r3 * sin);
|
|
394
|
+
path.L(cx, cy - r2);
|
|
395
|
+
path.L(cx - r3 * cos, cy - r2 - r3 * sin);
|
|
396
|
+
path.L(cx - 2 * lineWidth - r4 * cos, cy - r4 * sin);
|
|
397
|
+
path.Z();
|
|
398
|
+
};
|
|
399
|
+
|
|
400
|
+
// src/symbols/index.ts
|
|
401
|
+
var fillSymbolMap = {
|
|
402
|
+
circle: createCircleSymbol,
|
|
403
|
+
cross: createCrossSymbol,
|
|
404
|
+
diamond: createDiamondSymbol,
|
|
405
|
+
square: createSquareSymbol,
|
|
406
|
+
triangle: createUpTriangleSymbol,
|
|
407
|
+
iTriangle: createDownTriangleSymbol,
|
|
408
|
+
upTriangle: createUpTriangleSymbol,
|
|
409
|
+
downTriangle: createDownTriangleSymbol,
|
|
410
|
+
leftTriangle: createLeftTriangleSymbol,
|
|
411
|
+
rightTriangle: createRightTriangleSymbol
|
|
412
|
+
};
|
|
413
|
+
var featureSymbolMap = {
|
|
414
|
+
line: createHLineSymbol,
|
|
415
|
+
hLine: createHLineSymbol,
|
|
416
|
+
vLine: createVLineSymbol,
|
|
417
|
+
eye: createEyeSymbol,
|
|
418
|
+
closedEye: createClosedEyeSymbol,
|
|
419
|
+
reset: createResetSymbol,
|
|
420
|
+
select: createSelectSymbol
|
|
421
|
+
};
|
|
422
|
+
var fillSymbols = Object.keys(fillSymbolMap);
|
|
423
|
+
var createSymbol = (path, symbol, options) => {
|
|
424
|
+
if (fillSymbolMap[symbol]) fillSymbolMap[symbol](path, options);
|
|
425
|
+
else if (featureSymbolMap[symbol]) featureSymbolMap[symbol](path, options);
|
|
426
|
+
else fillSymbolMap.circle(path, options);
|
|
427
|
+
};
|
|
428
|
+
|
|
429
|
+
// src/general/indicator-box.ts
|
|
430
|
+
var createIndicatorBox = (path, options) => {
|
|
431
|
+
const { anchor, anchorSize: s, width: w, height: h } = options;
|
|
432
|
+
const s2 = s / 2;
|
|
433
|
+
const w2 = w / 2;
|
|
434
|
+
const h2 = h / 2;
|
|
435
|
+
if (anchor === "top") {
|
|
436
|
+
path.M(-w2, s);
|
|
437
|
+
path.L(-s2, s);
|
|
438
|
+
path.L(0, 0);
|
|
439
|
+
path.L(s2, s);
|
|
440
|
+
path.L(w2, s);
|
|
441
|
+
path.L(w2, h + s);
|
|
442
|
+
path.L(-w2, h + s);
|
|
443
|
+
path.Z();
|
|
444
|
+
} else if (anchor === "bottom") {
|
|
445
|
+
path.M(-w2, -h - s);
|
|
446
|
+
path.L(w2, -h - s);
|
|
447
|
+
path.L(w2, -s);
|
|
448
|
+
path.L(s2, -s);
|
|
449
|
+
path.L(0, 0);
|
|
450
|
+
path.L(-s2, -s);
|
|
451
|
+
path.L(-w2, -s);
|
|
452
|
+
path.Z();
|
|
453
|
+
} else if (anchor === "left") {
|
|
454
|
+
path.M(s, -h2);
|
|
455
|
+
path.L(s, -s2);
|
|
456
|
+
path.L(0, 0);
|
|
457
|
+
path.L(s, s2);
|
|
458
|
+
path.L(s, h2);
|
|
459
|
+
path.L(w + s, h2);
|
|
460
|
+
path.L(w + s, -h2);
|
|
461
|
+
path.Z();
|
|
462
|
+
} else if (anchor === "right") {
|
|
463
|
+
path.M(-w - s, -h2);
|
|
464
|
+
path.L(-w - s, h2);
|
|
465
|
+
path.L(-s, h2);
|
|
466
|
+
path.L(-s, s2);
|
|
467
|
+
path.L(0, 0);
|
|
468
|
+
path.L(-s, -s2);
|
|
469
|
+
path.L(-s, -h2);
|
|
470
|
+
path.Z();
|
|
471
|
+
}
|
|
472
|
+
};
|
|
473
|
+
export {
|
|
474
|
+
createArc,
|
|
475
|
+
createArea,
|
|
476
|
+
createBoxX,
|
|
477
|
+
createBoxY,
|
|
478
|
+
createCircle,
|
|
479
|
+
createCircleSymbol,
|
|
480
|
+
createClosedEyeSymbol,
|
|
481
|
+
createCrossSymbol,
|
|
482
|
+
createDiamondSymbol,
|
|
483
|
+
createDownTriangleSymbol,
|
|
484
|
+
createEyeSymbol,
|
|
485
|
+
createHLineSymbol,
|
|
486
|
+
createIndicatorBox,
|
|
487
|
+
createInvertedTriangleSymbol,
|
|
488
|
+
createLeftTriangleSymbol,
|
|
489
|
+
createLine,
|
|
490
|
+
createRect,
|
|
491
|
+
createRectNormal,
|
|
492
|
+
createRectRounded,
|
|
493
|
+
createResetSymbol,
|
|
494
|
+
createRightTriangleSymbol,
|
|
495
|
+
createRing,
|
|
496
|
+
createSector,
|
|
497
|
+
createSectorNormal,
|
|
498
|
+
createSectorRounded,
|
|
499
|
+
createSegmentArea,
|
|
500
|
+
createSegmentLine,
|
|
501
|
+
createSelectSymbol,
|
|
502
|
+
createShape,
|
|
503
|
+
createSquareSymbol,
|
|
504
|
+
createStarSymbol,
|
|
505
|
+
createSymbol,
|
|
506
|
+
createTriangleSymbol,
|
|
507
|
+
createUpTriangleSymbol,
|
|
508
|
+
createVLineSymbol,
|
|
509
|
+
createWyeSymbol,
|
|
510
|
+
fillSymbols
|
|
511
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "rendx-shape",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Shape generators (circle, rect, arc, sector, area, polygon, symbol)",
|
|
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/shape"
|
|
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-curve": "^0.1.0",
|
|
34
|
+
"rendx-path": "^0.1.0",
|
|
35
|
+
"rendx-core": "^0.1.0"
|
|
36
|
+
},
|
|
37
|
+
"sideEffects": false,
|
|
38
|
+
"files": [
|
|
39
|
+
"dist"
|
|
40
|
+
],
|
|
41
|
+
"publishConfig": {
|
|
42
|
+
"access": "public"
|
|
43
|
+
},
|
|
44
|
+
"scripts": {
|
|
45
|
+
"build": "tsup",
|
|
46
|
+
"dev": "tsup --watch"
|
|
47
|
+
}
|
|
48
|
+
}
|