@xom11/whiteboard 0.24.1 → 0.25.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.
Files changed (85) hide show
  1. package/README.md +85 -12
  2. package/dist/ai.d.mts +472 -0
  3. package/dist/ai.d.ts +472 -0
  4. package/dist/ai.js +2156 -0
  5. package/dist/ai.js.map +1 -0
  6. package/dist/ai.mjs +1495 -0
  7. package/dist/ai.mjs.map +1 -0
  8. package/dist/catalog.json +4 -4
  9. package/dist/chunk-73Q7ADVL.mjs +35 -0
  10. package/dist/chunk-73Q7ADVL.mjs.map +1 -0
  11. package/dist/{chunk-BKSXPNPQ.mjs → chunk-AYSFWUPK.mjs} +4 -3
  12. package/dist/chunk-AYSFWUPK.mjs.map +1 -0
  13. package/dist/chunk-B4NJJZFR.mjs +18 -0
  14. package/dist/chunk-B4NJJZFR.mjs.map +1 -0
  15. package/dist/{chunk-LVNCYP4J.mjs → chunk-CJBLJUWG.mjs} +5 -5
  16. package/dist/{chunk-LVNCYP4J.mjs.map → chunk-CJBLJUWG.mjs.map} +1 -1
  17. package/dist/{chunk-YIPI3WUL.mjs → chunk-ESVPQWHX.mjs} +5 -5
  18. package/dist/{chunk-YIPI3WUL.mjs.map → chunk-ESVPQWHX.mjs.map} +1 -1
  19. package/dist/{chunk-IBTRMWD6.mjs → chunk-I24QOHPU.mjs} +3 -3
  20. package/dist/{chunk-IBTRMWD6.mjs.map → chunk-I24QOHPU.mjs.map} +1 -1
  21. package/dist/{chunk-ZBJBQKJ2.mjs → chunk-IHUFOV7L.mjs} +4 -19
  22. package/dist/chunk-IHUFOV7L.mjs.map +1 -0
  23. package/dist/{chunk-AZIARTGX.mjs → chunk-M42TGYT6.mjs} +3 -3
  24. package/dist/{chunk-AZIARTGX.mjs.map → chunk-M42TGYT6.mjs.map} +1 -1
  25. package/dist/{chunk-WWMQ2VHZ.mjs → chunk-NDEZJKNY.mjs} +4 -4
  26. package/dist/{chunk-WWMQ2VHZ.mjs.map → chunk-NDEZJKNY.mjs.map} +1 -1
  27. package/dist/{chunk-CSCF3YFZ.mjs → chunk-ONBCUWVI.mjs} +6 -4
  28. package/dist/chunk-ONBCUWVI.mjs.map +1 -0
  29. package/dist/{chunk-6V4SH4JJ.mjs → chunk-REIJZDVZ.mjs} +6 -35
  30. package/dist/chunk-REIJZDVZ.mjs.map +1 -0
  31. package/dist/{chunk-4D5CSIJO.mjs → chunk-TB4CL25L.mjs} +10 -8
  32. package/dist/chunk-TB4CL25L.mjs.map +1 -0
  33. package/dist/chunk-VNCCIV6O.mjs +938 -0
  34. package/dist/chunk-VNCCIV6O.mjs.map +1 -0
  35. package/dist/{chunk-MFOGFFIL.mjs → chunk-VRHWDZ66.mjs} +6 -5
  36. package/dist/chunk-VRHWDZ66.mjs.map +1 -0
  37. package/dist/{chunk-CRAPWQKJ.mjs → chunk-YSJOVBCD.mjs} +4 -4
  38. package/dist/{chunk-CRAPWQKJ.mjs.map → chunk-YSJOVBCD.mjs.map} +1 -1
  39. package/dist/geometry-2d.d.mts +2 -1
  40. package/dist/geometry-2d.d.ts +2 -1
  41. package/dist/geometry-2d.js +1383 -23
  42. package/dist/geometry-2d.js.map +1 -1
  43. package/dist/geometry-2d.mjs +7 -5
  44. package/dist/geometry-3d.d.mts +2 -1
  45. package/dist/geometry-3d.d.ts +2 -1
  46. package/dist/geometry-3d.js +2 -2
  47. package/dist/geometry-3d.js.map +1 -1
  48. package/dist/geometry-3d.mjs +6 -4
  49. package/dist/graph-2d.d.mts +2 -1
  50. package/dist/graph-2d.d.ts +2 -1
  51. package/dist/graph-2d.js +2 -2
  52. package/dist/graph-2d.js.map +1 -1
  53. package/dist/graph-2d.mjs +9 -7
  54. package/dist/{host-TLIXN4CF.mjs → host-A64ITWVX.mjs} +8 -6
  55. package/dist/host-A64ITWVX.mjs.map +1 -0
  56. package/dist/{host-DOAYVL35.mjs → host-L7FMFZUW.mjs} +228 -30
  57. package/dist/host-L7FMFZUW.mjs.map +1 -0
  58. package/dist/{host-GKNQBBUE.mjs → host-QK53UYMD.mjs} +12 -10
  59. package/dist/host-QK53UYMD.mjs.map +1 -0
  60. package/dist/index.d.mts +4 -616
  61. package/dist/index.d.ts +4 -616
  62. package/dist/index.js +8889 -8529
  63. package/dist/index.js.map +1 -1
  64. package/dist/index.mjs +21 -1012
  65. package/dist/index.mjs.map +1 -1
  66. package/dist/latex.d.mts +2 -1
  67. package/dist/latex.d.ts +2 -1
  68. package/dist/render-3WTY7NZB.mjs +9 -0
  69. package/dist/{render-SA4JTOW3.mjs.map → render-3WTY7NZB.mjs.map} +1 -1
  70. package/dist/serialize-SRJVKYUG.mjs +8 -0
  71. package/dist/{serialize-3NZS6A6Q.mjs.map → serialize-SRJVKYUG.mjs.map} +1 -1
  72. package/dist/{types-rA4slL08.d.ts → types-DWRyCa2m.d.mts} +139 -1
  73. package/dist/{types-rA4slL08.d.mts → types-DWRyCa2m.d.ts} +139 -1
  74. package/package.json +6 -1
  75. package/dist/chunk-4D5CSIJO.mjs.map +0 -1
  76. package/dist/chunk-6V4SH4JJ.mjs.map +0 -1
  77. package/dist/chunk-BKSXPNPQ.mjs.map +0 -1
  78. package/dist/chunk-CSCF3YFZ.mjs.map +0 -1
  79. package/dist/chunk-MFOGFFIL.mjs.map +0 -1
  80. package/dist/chunk-ZBJBQKJ2.mjs.map +0 -1
  81. package/dist/host-DOAYVL35.mjs.map +0 -1
  82. package/dist/host-GKNQBBUE.mjs.map +0 -1
  83. package/dist/host-TLIXN4CF.mjs.map +0 -1
  84. package/dist/render-SA4JTOW3.mjs +0 -8
  85. package/dist/serialize-3NZS6A6Q.mjs +0 -6
@@ -0,0 +1,938 @@
1
+ "use client";
2
+ import { getKind } from './chunk-B4NJJZFR.mjs';
3
+ import { z } from 'zod';
4
+
5
+ var NameZ = z.string().regex(/^[A-Za-z][A-Za-z0-9_'₀-₉]{0,11}$/);
6
+
7
+ // src/stamps/geometry-2d/dsl/kinds/_types.ts
8
+ function defineModule(m) {
9
+ return m;
10
+ }
11
+
12
+ // src/stamps/geometry-2d/dsl/kinds/_shared.ts
13
+ var POINT_BASE_FIELDS = {
14
+ visible: true,
15
+ locked: false,
16
+ layer: "default",
17
+ schemaVersion: 1
18
+ };
19
+ function emitPointObject(id, name, constraint) {
20
+ return {
21
+ id,
22
+ kind: "point",
23
+ label: name,
24
+ ...POINT_BASE_FIELDS,
25
+ attrs: { constraint }
26
+ };
27
+ }
28
+ function resolveTriangleVertices(ctx, vertices) {
29
+ return [ctx.resolveId(vertices[0]), ctx.resolveId(vertices[1]), ctx.resolveId(vertices[2])];
30
+ }
31
+ var SHAPE_BASE_FIELDS = {
32
+ visible: true,
33
+ locked: false,
34
+ layer: "default",
35
+ schemaVersion: 1
36
+ };
37
+
38
+ // src/stamps/geometry-2d/dsl/kinds/points/free.ts
39
+ var freeModule = defineModule({
40
+ kind: "free",
41
+ role: "point",
42
+ category: "points",
43
+ prefix: "p",
44
+ schema: z.object({
45
+ name: NameZ,
46
+ kind: z.literal("free"),
47
+ x: z.number().finite(),
48
+ y: z.number().finite()
49
+ }),
50
+ collectRefs: () => [],
51
+ emit: (e, ctx) => [{
52
+ role: "primary",
53
+ object: emitPointObject(ctx.resolveId(e.name), e.name, { kind: "free", x: e.x, y: e.y })
54
+ }]
55
+ });
56
+ var midpointModule = defineModule({
57
+ kind: "midpoint",
58
+ role: "point",
59
+ category: "points",
60
+ prefix: "p",
61
+ schema: z.object({
62
+ name: NameZ,
63
+ kind: z.literal("midpoint"),
64
+ p1: NameZ,
65
+ p2: NameZ
66
+ }),
67
+ collectRefs: (e) => [e.p1, e.p2],
68
+ emit: (e, ctx) => [{
69
+ role: "primary",
70
+ object: emitPointObject(
71
+ ctx.resolveId(e.name),
72
+ e.name,
73
+ { kind: "midpoint", p1: ctx.resolveId(e.p1), p2: ctx.resolveId(e.p2) }
74
+ )
75
+ }]
76
+ });
77
+ var onSegmentModule = defineModule({
78
+ kind: "onSegment",
79
+ role: "point",
80
+ category: "points",
81
+ prefix: "p",
82
+ schema: z.object({
83
+ name: NameZ,
84
+ kind: z.literal("onSegment"),
85
+ segmentId: NameZ,
86
+ t: z.number().min(0).max(1)
87
+ }),
88
+ collectRefs: (e) => [e.segmentId],
89
+ emit: (e, ctx) => [{
90
+ role: "primary",
91
+ object: emitPointObject(
92
+ ctx.resolveId(e.name),
93
+ e.name,
94
+ { kind: "onSegment", segmentId: ctx.resolveId(e.segmentId), t: e.t }
95
+ )
96
+ }]
97
+ });
98
+ var onLineModule = defineModule({
99
+ kind: "onLine",
100
+ role: "point",
101
+ category: "points",
102
+ prefix: "p",
103
+ schema: z.object({
104
+ name: NameZ,
105
+ kind: z.literal("onLine"),
106
+ lineId: NameZ,
107
+ t: z.number().finite()
108
+ }),
109
+ collectRefs: (e) => [e.lineId],
110
+ emit: (e, ctx) => [{
111
+ role: "primary",
112
+ object: emitPointObject(
113
+ ctx.resolveId(e.name),
114
+ e.name,
115
+ { kind: "onLine", lineId: ctx.resolveId(e.lineId), t: e.t }
116
+ )
117
+ }]
118
+ });
119
+ var onCircleModule = defineModule({
120
+ kind: "onCircle",
121
+ role: "point",
122
+ category: "points",
123
+ prefix: "p",
124
+ schema: z.object({
125
+ name: NameZ,
126
+ kind: z.literal("onCircle"),
127
+ circleId: NameZ,
128
+ theta: z.number().finite()
129
+ }),
130
+ collectRefs: (e) => [e.circleId],
131
+ emit: (e, ctx) => [{
132
+ role: "primary",
133
+ object: emitPointObject(
134
+ ctx.resolveId(e.name),
135
+ e.name,
136
+ { kind: "onCircle", circleId: ctx.resolveId(e.circleId), theta: e.theta }
137
+ )
138
+ }]
139
+ });
140
+ var perpFootModule = defineModule({
141
+ kind: "perpFoot",
142
+ role: "point",
143
+ category: "points",
144
+ prefix: "p",
145
+ schema: z.object({
146
+ name: NameZ,
147
+ kind: z.literal("perpFoot"),
148
+ from: NameZ,
149
+ onLine: NameZ
150
+ }),
151
+ collectRefs: (e) => [e.from, e.onLine],
152
+ emit: (e, ctx) => [{
153
+ role: "primary",
154
+ object: emitPointObject(
155
+ ctx.resolveId(e.name),
156
+ e.name,
157
+ { kind: "perpFoot", from: ctx.resolveId(e.from), onLine: ctx.resolveId(e.onLine) }
158
+ )
159
+ }]
160
+ });
161
+ var circumcenterModule = defineModule({
162
+ kind: "circumcenter",
163
+ role: "point",
164
+ category: "points",
165
+ prefix: "p",
166
+ schema: z.object({
167
+ name: NameZ,
168
+ kind: z.literal("circumcenter"),
169
+ vertices: z.tuple([NameZ, NameZ, NameZ])
170
+ }),
171
+ collectRefs: (e) => [...e.vertices],
172
+ emit: (e, ctx) => [{
173
+ role: "primary",
174
+ object: emitPointObject(
175
+ ctx.resolveId(e.name),
176
+ e.name,
177
+ { kind: "circumcenter", vertices: resolveTriangleVertices(ctx, e.vertices) }
178
+ )
179
+ }]
180
+ });
181
+ var incenterModule = defineModule({
182
+ kind: "incenter",
183
+ role: "point",
184
+ category: "points",
185
+ prefix: "p",
186
+ schema: z.object({
187
+ name: NameZ,
188
+ kind: z.literal("incenter"),
189
+ vertices: z.tuple([NameZ, NameZ, NameZ])
190
+ }),
191
+ collectRefs: (e) => [...e.vertices],
192
+ emit: (e, ctx) => [{
193
+ role: "primary",
194
+ object: emitPointObject(
195
+ ctx.resolveId(e.name),
196
+ e.name,
197
+ { kind: "incenter", vertices: resolveTriangleVertices(ctx, e.vertices) }
198
+ )
199
+ }]
200
+ });
201
+ var centroidModule = defineModule({
202
+ kind: "centroid",
203
+ role: "point",
204
+ category: "points",
205
+ prefix: "p",
206
+ schema: z.object({
207
+ name: NameZ,
208
+ kind: z.literal("centroid"),
209
+ vertices: z.tuple([NameZ, NameZ, NameZ])
210
+ }),
211
+ collectRefs: (e) => [...e.vertices],
212
+ emit: (e, ctx) => [{
213
+ role: "primary",
214
+ object: emitPointObject(
215
+ ctx.resolveId(e.name),
216
+ e.name,
217
+ { kind: "centroid", vertices: resolveTriangleVertices(ctx, e.vertices) }
218
+ )
219
+ }]
220
+ });
221
+ var orthocenterModule = defineModule({
222
+ kind: "orthocenter",
223
+ role: "point",
224
+ category: "points",
225
+ prefix: "p",
226
+ schema: z.object({
227
+ name: NameZ,
228
+ kind: z.literal("orthocenter"),
229
+ vertices: z.tuple([NameZ, NameZ, NameZ])
230
+ }),
231
+ collectRefs: (e) => [...e.vertices],
232
+ emit: (e, ctx) => [{
233
+ role: "primary",
234
+ object: emitPointObject(
235
+ ctx.resolveId(e.name),
236
+ e.name,
237
+ { kind: "orthocenter", vertices: resolveTriangleVertices(ctx, e.vertices) }
238
+ )
239
+ }]
240
+ });
241
+ var intersectionModule = defineModule({
242
+ kind: "intersection",
243
+ role: "point",
244
+ category: "points",
245
+ prefix: "i",
246
+ schema: z.object({
247
+ name: NameZ,
248
+ kind: z.literal("intersection"),
249
+ ref1: NameZ,
250
+ ref2: NameZ,
251
+ branch: z.union([z.literal(0), z.literal(1)]).optional()
252
+ }),
253
+ collectRefs: (e) => [e.ref1, e.ref2],
254
+ emit: (e, ctx) => {
255
+ const r1IsCircle = ctx.hintOf(e.ref1) === "circle";
256
+ const r2IsCircle = ctx.hintOf(e.ref2) === "circle";
257
+ let intersectKind;
258
+ if (r1IsCircle && r2IsCircle) intersectKind = "circleCircle";
259
+ else if (r1IsCircle || r2IsCircle) intersectKind = "lineCircle";
260
+ else intersectKind = "lineLine";
261
+ const attrs = {
262
+ kind: intersectKind,
263
+ ref1: ctx.resolveId(e.ref1),
264
+ ref2: ctx.resolveId(e.ref2)
265
+ };
266
+ if (intersectKind !== "lineLine") {
267
+ attrs.branch = e.branch ?? 0;
268
+ }
269
+ return [{
270
+ role: "primary",
271
+ object: {
272
+ id: ctx.resolveId(e.name),
273
+ kind: "intersection",
274
+ label: e.name,
275
+ ...POINT_BASE_FIELDS,
276
+ attrs
277
+ }
278
+ }];
279
+ }
280
+ });
281
+ var segmentModule = defineModule({
282
+ kind: "segment",
283
+ role: "segment",
284
+ category: "lines",
285
+ prefix: "s",
286
+ schema: z.object({
287
+ name: NameZ,
288
+ kind: z.literal("segment"),
289
+ p1: NameZ,
290
+ p2: NameZ
291
+ }),
292
+ collectRefs: (e) => [e.p1, e.p2],
293
+ emit: (e, ctx) => [{
294
+ role: "primary",
295
+ object: {
296
+ id: ctx.resolveId(e.name),
297
+ kind: "segment",
298
+ label: e.name,
299
+ ...SHAPE_BASE_FIELDS,
300
+ attrs: { p1: ctx.resolveId(e.p1), p2: ctx.resolveId(e.p2) }
301
+ }
302
+ }]
303
+ });
304
+ var lineModule = defineModule({
305
+ kind: "line",
306
+ role: "line",
307
+ category: "lines",
308
+ prefix: "l",
309
+ schema: z.object({
310
+ name: NameZ,
311
+ kind: z.literal("line"),
312
+ p1: NameZ,
313
+ p2: NameZ
314
+ }),
315
+ collectRefs: (e) => [e.p1, e.p2],
316
+ emit: (e, ctx) => [{
317
+ role: "primary",
318
+ object: {
319
+ id: ctx.resolveId(e.name),
320
+ kind: "line",
321
+ label: e.name,
322
+ ...SHAPE_BASE_FIELDS,
323
+ attrs: { p1: ctx.resolveId(e.p1), p2: ctx.resolveId(e.p2) }
324
+ }
325
+ }]
326
+ });
327
+ var rayModule = defineModule({
328
+ kind: "ray",
329
+ role: "ray",
330
+ category: "lines",
331
+ prefix: "r",
332
+ schema: z.object({
333
+ name: NameZ,
334
+ kind: z.literal("ray"),
335
+ origin: NameZ,
336
+ through: NameZ
337
+ }),
338
+ collectRefs: (e) => [e.origin, e.through],
339
+ emit: (e, ctx) => [{
340
+ role: "primary",
341
+ object: {
342
+ id: ctx.resolveId(e.name),
343
+ kind: "ray",
344
+ label: e.name,
345
+ ...SHAPE_BASE_FIELDS,
346
+ attrs: { origin: ctx.resolveId(e.origin), through: ctx.resolveId(e.through) }
347
+ }
348
+ }]
349
+ });
350
+ var perpendicularModule = defineModule({
351
+ kind: "perpendicular",
352
+ role: "lineConstruction",
353
+ category: "lines",
354
+ prefix: "l",
355
+ schema: z.object({
356
+ name: NameZ,
357
+ kind: z.literal("perpendicular"),
358
+ throughPoint: NameZ,
359
+ toLine: NameZ
360
+ }),
361
+ collectRefs: (e) => [e.throughPoint, e.toLine],
362
+ emit: (e, ctx) => [{
363
+ role: "primary",
364
+ object: {
365
+ id: ctx.resolveId(e.name),
366
+ kind: "line",
367
+ label: e.name,
368
+ ...SHAPE_BASE_FIELDS,
369
+ attrs: {
370
+ construction: {
371
+ kind: "perpendicular",
372
+ throughPoint: ctx.resolveId(e.throughPoint),
373
+ toLine: ctx.resolveId(e.toLine)
374
+ }
375
+ }
376
+ }
377
+ }]
378
+ });
379
+ var parallelModule = defineModule({
380
+ kind: "parallel",
381
+ role: "lineConstruction",
382
+ category: "lines",
383
+ prefix: "l",
384
+ schema: z.object({
385
+ name: NameZ,
386
+ kind: z.literal("parallel"),
387
+ throughPoint: NameZ,
388
+ toLine: NameZ
389
+ }),
390
+ collectRefs: (e) => [e.throughPoint, e.toLine],
391
+ emit: (e, ctx) => [{
392
+ role: "primary",
393
+ object: {
394
+ id: ctx.resolveId(e.name),
395
+ kind: "line",
396
+ label: e.name,
397
+ ...SHAPE_BASE_FIELDS,
398
+ attrs: {
399
+ construction: {
400
+ kind: "parallel",
401
+ throughPoint: ctx.resolveId(e.throughPoint),
402
+ toLine: ctx.resolveId(e.toLine)
403
+ }
404
+ }
405
+ }
406
+ }]
407
+ });
408
+ var perpBisectorModule = defineModule({
409
+ kind: "perpBisector",
410
+ role: "lineConstruction",
411
+ category: "lines",
412
+ prefix: "l",
413
+ schema: z.object({
414
+ name: NameZ,
415
+ kind: z.literal("perpBisector"),
416
+ p1: NameZ,
417
+ p2: NameZ
418
+ }),
419
+ collectRefs: (e) => [e.p1, e.p2],
420
+ emit: (e, ctx) => [{
421
+ role: "primary",
422
+ object: {
423
+ id: ctx.resolveId(e.name),
424
+ kind: "line",
425
+ label: e.name,
426
+ ...SHAPE_BASE_FIELDS,
427
+ attrs: {
428
+ construction: {
429
+ kind: "perpBisector",
430
+ p1: ctx.resolveId(e.p1),
431
+ p2: ctx.resolveId(e.p2)
432
+ }
433
+ }
434
+ }
435
+ }]
436
+ });
437
+ var angleBisectorModule = defineModule({
438
+ kind: "angleBisector",
439
+ role: "lineConstruction",
440
+ category: "lines",
441
+ prefix: "l",
442
+ schema: z.object({
443
+ name: NameZ,
444
+ kind: z.literal("angleBisector"),
445
+ p1: NameZ,
446
+ vertex: NameZ,
447
+ p2: NameZ
448
+ }),
449
+ collectRefs: (e) => [e.p1, e.vertex, e.p2],
450
+ emit: (e, ctx) => [{
451
+ role: "primary",
452
+ object: {
453
+ id: ctx.resolveId(e.name),
454
+ kind: "line",
455
+ label: e.name,
456
+ ...SHAPE_BASE_FIELDS,
457
+ attrs: {
458
+ construction: {
459
+ kind: "angleBisector",
460
+ p1: ctx.resolveId(e.p1),
461
+ vertex: ctx.resolveId(e.vertex),
462
+ p2: ctx.resolveId(e.p2)
463
+ }
464
+ }
465
+ }
466
+ }]
467
+ });
468
+ var tangentModule = defineModule({
469
+ kind: "tangent",
470
+ role: "lineConstruction",
471
+ category: "lines",
472
+ prefix: "l",
473
+ schema: z.object({
474
+ name: NameZ,
475
+ kind: z.literal("tangent"),
476
+ throughPoint: NameZ,
477
+ toCircle: NameZ,
478
+ branch: z.union([z.literal(0), z.literal(1), z.literal("on")]).optional()
479
+ }),
480
+ collectRefs: (e) => [e.throughPoint, e.toCircle],
481
+ emit: (e, ctx) => {
482
+ const construction = {
483
+ kind: "tangent",
484
+ throughPoint: ctx.resolveId(e.throughPoint),
485
+ toCircle: ctx.resolveId(e.toCircle)
486
+ };
487
+ if (e.branch !== void 0) construction.branch = e.branch;
488
+ return [{
489
+ role: "primary",
490
+ object: {
491
+ id: ctx.resolveId(e.name),
492
+ kind: "line",
493
+ label: e.name,
494
+ ...SHAPE_BASE_FIELDS,
495
+ attrs: { construction }
496
+ }
497
+ }];
498
+ }
499
+ });
500
+ var polygonModule = defineModule({
501
+ kind: "polygon",
502
+ role: "polygon",
503
+ category: "polygons",
504
+ prefix: "poly",
505
+ schema: z.object({
506
+ name: NameZ,
507
+ kind: z.literal("polygon"),
508
+ vertices: z.array(NameZ).min(3)
509
+ }),
510
+ collectRefs: (e) => [...e.vertices],
511
+ emit: (e, ctx) => [{
512
+ role: "primary",
513
+ object: {
514
+ id: ctx.resolveId(e.name),
515
+ kind: "polygon",
516
+ label: e.name,
517
+ ...SHAPE_BASE_FIELDS,
518
+ attrs: { vertices: e.vertices.map((v) => ctx.resolveId(v)) }
519
+ }
520
+ }]
521
+ });
522
+ var circleCPModule = defineModule({
523
+ kind: "circleCP",
524
+ role: "circle",
525
+ category: "circles",
526
+ prefix: "c",
527
+ schema: z.object({
528
+ name: NameZ,
529
+ kind: z.literal("circleCP"),
530
+ center: NameZ,
531
+ surfacePoint: NameZ
532
+ }),
533
+ collectRefs: (e) => [e.center, e.surfacePoint],
534
+ emit: (e, ctx) => [{
535
+ role: "primary",
536
+ object: {
537
+ id: ctx.resolveId(e.name),
538
+ kind: "circle",
539
+ label: e.name,
540
+ ...SHAPE_BASE_FIELDS,
541
+ attrs: { center: ctx.resolveId(e.center), surfacePoint: ctx.resolveId(e.surfacePoint) }
542
+ }
543
+ }]
544
+ });
545
+ var circle3Module = defineModule({
546
+ kind: "circle3",
547
+ role: "circle",
548
+ category: "circles",
549
+ prefix: "c",
550
+ schema: z.object({
551
+ name: NameZ,
552
+ kind: z.literal("circle3"),
553
+ p1: NameZ,
554
+ p2: NameZ,
555
+ p3: NameZ
556
+ }),
557
+ collectRefs: (e) => [e.p1, e.p2, e.p3],
558
+ emit: (e, ctx) => [{
559
+ role: "primary",
560
+ object: {
561
+ id: ctx.resolveId(e.name),
562
+ kind: "circle",
563
+ label: e.name,
564
+ ...SHAPE_BASE_FIELDS,
565
+ attrs: {
566
+ construction: {
567
+ kind: "circumscribed",
568
+ p1: ctx.resolveId(e.p1),
569
+ p2: ctx.resolveId(e.p2),
570
+ p3: ctx.resolveId(e.p3)
571
+ }
572
+ }
573
+ }
574
+ }]
575
+ });
576
+
577
+ // src/stamps/geometry-2d/dsl/registry.ts
578
+ var ALL_MODULES = [
579
+ freeModule,
580
+ midpointModule,
581
+ onSegmentModule,
582
+ onLineModule,
583
+ onCircleModule,
584
+ perpFootModule,
585
+ circumcenterModule,
586
+ incenterModule,
587
+ centroidModule,
588
+ orthocenterModule,
589
+ intersectionModule,
590
+ segmentModule,
591
+ lineModule,
592
+ rayModule,
593
+ perpendicularModule,
594
+ parallelModule,
595
+ perpBisectorModule,
596
+ angleBisectorModule,
597
+ tangentModule,
598
+ polygonModule,
599
+ circleCPModule,
600
+ circle3Module
601
+ ];
602
+ var KIND_REGISTRY = new Map(ALL_MODULES.map((m) => [m.kind, m]));
603
+ var POINT_KINDS = new Set(
604
+ ALL_MODULES.filter((m) => m.role === "point").map((m) => m.kind)
605
+ );
606
+ var LINE_LIKE_SHAPE_KINDS = new Set(
607
+ ALL_MODULES.filter(
608
+ (m) => m.role === "segment" || m.role === "line" || m.role === "ray" || m.role === "lineConstruction"
609
+ ).map((m) => m.kind)
610
+ );
611
+ var CIRCLE_KINDS = new Set(
612
+ ALL_MODULES.filter((m) => m.role === "circle").map((m) => m.kind)
613
+ );
614
+ z.discriminatedUnion(
615
+ "kind",
616
+ ALL_MODULES.map((m) => m.schema)
617
+ );
618
+
619
+ // src/stamps/geometry-2d/dsl/serialize.ts
620
+ var NAME_REGEX = /^[A-Za-z][A-Za-z0-9_'₀-₉]{0,11}$/;
621
+ function isValidName(s) {
622
+ return NAME_REGEX.test(s);
623
+ }
624
+ function labelOf(id, state) {
625
+ const obj = state.objects[id];
626
+ return obj ? obj.label : null;
627
+ }
628
+ function resolveRefs(ids, state) {
629
+ const out = [];
630
+ for (const id of ids) {
631
+ const lab = labelOf(id, state);
632
+ if (lab == null || !isValidName(lab)) return null;
633
+ out.push(lab);
634
+ }
635
+ return out;
636
+ }
637
+ function fail(reason, detail) {
638
+ return { ok: false, reason, detail };
639
+ }
640
+ function serializePoint(obj, state) {
641
+ const c = obj.attrs?.constraint;
642
+ if (!c) return fail("unsupported-constraint", "missing");
643
+ switch (c.kind) {
644
+ case "free":
645
+ return { ok: true, entity: { name: obj.label, kind: "free", x: c.x, y: c.y } };
646
+ case "midpoint": {
647
+ const refs = resolveRefs([c.p1, c.p2], state);
648
+ if (!refs) return fail("unresolved-ref", `${c.p1},${c.p2}`);
649
+ return { ok: true, entity: { name: obj.label, kind: "midpoint", p1: refs[0], p2: refs[1] } };
650
+ }
651
+ case "onSegment": {
652
+ const refs = resolveRefs([c.segmentId], state);
653
+ if (!refs) return fail("unresolved-ref", c.segmentId);
654
+ return { ok: true, entity: { name: obj.label, kind: "onSegment", segmentId: refs[0], t: c.t } };
655
+ }
656
+ case "onLine": {
657
+ const refs = resolveRefs([c.lineId], state);
658
+ if (!refs) return fail("unresolved-ref", c.lineId);
659
+ return { ok: true, entity: { name: obj.label, kind: "onLine", lineId: refs[0], t: c.t } };
660
+ }
661
+ case "onCircle": {
662
+ const refs = resolveRefs([c.circleId], state);
663
+ if (!refs) return fail("unresolved-ref", c.circleId);
664
+ return { ok: true, entity: { name: obj.label, kind: "onCircle", circleId: refs[0], theta: c.theta } };
665
+ }
666
+ case "perpFoot": {
667
+ const refs = resolveRefs([c.from, c.onLine], state);
668
+ if (!refs) return fail("unresolved-ref", `${c.from},${c.onLine}`);
669
+ return { ok: true, entity: { name: obj.label, kind: "perpFoot", from: refs[0], onLine: refs[1] } };
670
+ }
671
+ case "circumcenter":
672
+ case "incenter":
673
+ case "centroid":
674
+ case "orthocenter": {
675
+ const refs = resolveRefs(c.vertices, state);
676
+ if (!refs || refs.length !== 3) return fail("unresolved-ref", c.vertices.join(","));
677
+ return {
678
+ ok: true,
679
+ entity: {
680
+ name: obj.label,
681
+ kind: c.kind,
682
+ vertices: [refs[0], refs[1], refs[2]]
683
+ }
684
+ };
685
+ }
686
+ // Out of DSL v1:
687
+ case "onAxis":
688
+ case "onPolygon":
689
+ case "transformed":
690
+ return fail("unsupported-constraint", c.kind);
691
+ default: {
692
+ return fail("unsupported-constraint");
693
+ }
694
+ }
695
+ }
696
+ function serializeIntersection(obj, state) {
697
+ const a = obj.attrs;
698
+ const refs = resolveRefs([a.ref1, a.ref2], state);
699
+ if (!refs) return fail("unresolved-ref", `${a.ref1},${a.ref2}`);
700
+ if (a.kind === "lineLine") {
701
+ return { ok: true, entity: { name: obj.label, kind: "intersection", ref1: refs[0], ref2: refs[1] } };
702
+ }
703
+ return {
704
+ ok: true,
705
+ entity: {
706
+ name: obj.label,
707
+ kind: "intersection",
708
+ ref1: refs[0],
709
+ ref2: refs[1],
710
+ branch: a.branch
711
+ }
712
+ };
713
+ }
714
+ function serializeSegment(obj, state) {
715
+ const refs = resolveRefs([obj.attrs.p1, obj.attrs.p2], state);
716
+ if (!refs) return fail("unresolved-ref", `${obj.attrs.p1},${obj.attrs.p2}`);
717
+ return { ok: true, entity: { name: obj.label, kind: "segment", p1: refs[0], p2: refs[1] } };
718
+ }
719
+ function serializeRay(obj, state) {
720
+ const refs = resolveRefs([obj.attrs.origin, obj.attrs.through], state);
721
+ if (!refs) return fail("unresolved-ref", `${obj.attrs.origin},${obj.attrs.through}`);
722
+ return { ok: true, entity: { name: obj.label, kind: "ray", origin: refs[0], through: refs[1] } };
723
+ }
724
+ function serializeLine(obj, state) {
725
+ const a = obj.attrs;
726
+ const c = a.construction;
727
+ if (!c) {
728
+ if (!a.p1 || !a.p2) return fail("unsupported-construction", "missing p1/p2");
729
+ const refs = resolveRefs([a.p1, a.p2], state);
730
+ if (!refs) return fail("unresolved-ref", `${a.p1},${a.p2}`);
731
+ return { ok: true, entity: { name: obj.label, kind: "line", p1: refs[0], p2: refs[1] } };
732
+ }
733
+ switch (c.kind) {
734
+ case "perpendicular":
735
+ case "parallel": {
736
+ const refs = resolveRefs([c.throughPoint, c.toLine], state);
737
+ if (!refs) return fail("unresolved-ref", `${c.throughPoint},${c.toLine}`);
738
+ return {
739
+ ok: true,
740
+ entity: { name: obj.label, kind: c.kind, throughPoint: refs[0], toLine: refs[1] }
741
+ };
742
+ }
743
+ case "perpBisector": {
744
+ const refs = resolveRefs([c.p1, c.p2], state);
745
+ if (!refs) return fail("unresolved-ref", `${c.p1},${c.p2}`);
746
+ return { ok: true, entity: { name: obj.label, kind: "perpBisector", p1: refs[0], p2: refs[1] } };
747
+ }
748
+ case "angleBisector": {
749
+ const refs = resolveRefs([c.p1, c.vertex, c.p2], state);
750
+ if (!refs) return fail("unresolved-ref", `${c.p1},${c.vertex},${c.p2}`);
751
+ return {
752
+ ok: true,
753
+ entity: {
754
+ name: obj.label,
755
+ kind: "angleBisector",
756
+ p1: refs[0],
757
+ vertex: refs[1],
758
+ p2: refs[2]
759
+ }
760
+ };
761
+ }
762
+ case "tangent": {
763
+ const refs = resolveRefs([c.throughPoint, c.toCircle], state);
764
+ if (!refs) return fail("unresolved-ref", `${c.throughPoint},${c.toCircle}`);
765
+ const entity = c.branch !== void 0 ? {
766
+ name: obj.label,
767
+ kind: "tangent",
768
+ throughPoint: refs[0],
769
+ toCircle: refs[1],
770
+ branch: c.branch
771
+ } : { name: obj.label, kind: "tangent", throughPoint: refs[0], toCircle: refs[1] };
772
+ return { ok: true, entity };
773
+ }
774
+ case "angleBisectorLines":
775
+ return fail("unsupported-construction", "angleBisectorLines");
776
+ default: {
777
+ return fail("unsupported-construction");
778
+ }
779
+ }
780
+ }
781
+ function serializePolygon(obj, state) {
782
+ const a = obj.attrs;
783
+ if (a.construction) return fail("unsupported-construction", a.construction.kind);
784
+ if (!Array.isArray(a.vertices) || a.vertices.length < 3) {
785
+ return fail("unsupported-construction", "missing vertices");
786
+ }
787
+ const refs = resolveRefs(a.vertices, state);
788
+ if (!refs) return fail("unresolved-ref", a.vertices.join(","));
789
+ return { ok: true, entity: { name: obj.label, kind: "polygon", vertices: refs } };
790
+ }
791
+ function serializeCircle(obj, state) {
792
+ const a = obj.attrs;
793
+ const c = a.construction;
794
+ if (!c) {
795
+ if (!a.center || !a.surfacePoint) {
796
+ return fail("unsupported-construction", "missing center/surfacePoint");
797
+ }
798
+ const refs = resolveRefs([a.center, a.surfacePoint], state);
799
+ if (!refs) return fail("unresolved-ref", `${a.center},${a.surfacePoint}`);
800
+ return {
801
+ ok: true,
802
+ entity: { name: obj.label, kind: "circleCP", center: refs[0], surfacePoint: refs[1] }
803
+ };
804
+ }
805
+ if (c.kind === "circumscribed") {
806
+ const refs = resolveRefs([c.p1, c.p2, c.p3], state);
807
+ if (!refs) return fail("unresolved-ref", `${c.p1},${c.p2},${c.p3}`);
808
+ return {
809
+ ok: true,
810
+ entity: { name: obj.label, kind: "circle3", p1: refs[0], p2: refs[1], p3: refs[2] }
811
+ };
812
+ }
813
+ return fail("unsupported-construction");
814
+ }
815
+ function serializeObject(obj, state) {
816
+ if (!isValidName(obj.label)) {
817
+ return fail("invalid-label", obj.label);
818
+ }
819
+ switch (obj.kind) {
820
+ case "point":
821
+ return serializePoint(obj, state);
822
+ case "segment":
823
+ return serializeSegment(obj, state);
824
+ case "ray":
825
+ return serializeRay(obj, state);
826
+ case "line":
827
+ return serializeLine(obj, state);
828
+ case "polygon":
829
+ return serializePolygon(obj, state);
830
+ case "circle":
831
+ return serializeCircle(obj, state);
832
+ case "intersection":
833
+ return serializeIntersection(obj, state);
834
+ default:
835
+ return fail("unsupported-kind", obj.kind);
836
+ }
837
+ }
838
+ function serializeState(state) {
839
+ const points = [];
840
+ const shapes = [];
841
+ const unsupported = [];
842
+ for (const id of state.order) {
843
+ const obj = state.objects[id];
844
+ if (!obj) continue;
845
+ const r = serializeObject(obj, state);
846
+ if (!r.ok) {
847
+ unsupported.push({
848
+ id: obj.id,
849
+ label: obj.label,
850
+ kind: obj.kind,
851
+ reason: r.reason,
852
+ detail: r.detail
853
+ });
854
+ continue;
855
+ }
856
+ if (POINT_KINDS.has(r.entity.kind)) {
857
+ points.push(r.entity);
858
+ } else {
859
+ shapes.push(r.entity);
860
+ }
861
+ }
862
+ return {
863
+ dsl: { version: 1, points, shapes },
864
+ unsupported
865
+ };
866
+ }
867
+
868
+ // src/stamps/geometry-2d/dsl/describeDsl.ts
869
+ function describeEntity(e) {
870
+ switch (e.kind) {
871
+ case "free":
872
+ return `${e.name} = (${e.x}, ${e.y})`;
873
+ case "midpoint":
874
+ return `${e.name} = trung \u0111i\u1EC3m ${e.p1}${e.p2}`;
875
+ case "onSegment":
876
+ return `${e.name} \u2208 \u0111o\u1EA1n ${e.segmentId} (t = ${e.t})`;
877
+ case "onLine":
878
+ return `${e.name} \u2208 \u0111\u01B0\u1EDDng ${e.lineId} (t = ${e.t})`;
879
+ case "onCircle":
880
+ return `${e.name} \u2208 \u0111\u01B0\u1EDDng tr\xF2n ${e.circleId} (\u03B8 = ${e.theta})`;
881
+ case "perpFoot":
882
+ return `${e.name} = ch\xE2n vu\xF4ng g\xF3c t\u1EEB ${e.from} xu\u1ED1ng ${e.onLine}`;
883
+ case "circumcenter":
884
+ return `${e.name} = t\xE2m ngo\u1EA1i ti\u1EBFp ${e.vertices.join("")}`;
885
+ case "incenter":
886
+ return `${e.name} = t\xE2m n\u1ED9i ti\u1EBFp ${e.vertices.join("")}`;
887
+ case "centroid":
888
+ return `${e.name} = tr\u1ECDng t\xE2m ${e.vertices.join("")}`;
889
+ case "orthocenter":
890
+ return `${e.name} = tr\u1EF1c t\xE2m ${e.vertices.join("")}`;
891
+ case "intersection": {
892
+ const branch = "branch" in e && e.branch !== void 0 ? ` (nh\xE1nh ${e.branch})` : "";
893
+ return `${e.name} = ${e.ref1} \u2229 ${e.ref2}${branch}`;
894
+ }
895
+ case "segment":
896
+ return `${e.name} = \u0111o\u1EA1n ${e.p1}${e.p2}`;
897
+ case "line":
898
+ return `${e.name} = \u0111\u01B0\u1EDDng th\u1EB3ng ${e.p1}${e.p2}`;
899
+ case "ray":
900
+ return `${e.name} = tia ${e.origin}${e.through}`;
901
+ case "polygon":
902
+ return `${e.name} = \u0111a gi\xE1c ${e.vertices.join("")}`;
903
+ case "perpendicular":
904
+ return `${e.name} \u27C2 ${e.toLine} qua ${e.throughPoint}`;
905
+ case "parallel":
906
+ return `${e.name} \u2225 ${e.toLine} qua ${e.throughPoint}`;
907
+ case "perpBisector":
908
+ return `${e.name} = trung tr\u1EF1c ${e.p1}${e.p2}`;
909
+ case "angleBisector":
910
+ return `${e.name} = ph\xE2n gi\xE1c \u2220${e.p1}${e.vertex}${e.p2}`;
911
+ case "tangent": {
912
+ const branch = "branch" in e && e.branch !== void 0 ? ` (nh\xE1nh ${e.branch})` : "";
913
+ return `${e.name} = ti\u1EBFp tuy\u1EBFn ${e.toCircle} qua ${e.throughPoint}${branch}`;
914
+ }
915
+ case "circleCP":
916
+ return `${e.name} = (${e.center}; ${e.center}${e.surfacePoint})`;
917
+ case "circle3":
918
+ return `${e.name} = \u0111\u01B0\u1EDDng tr\xF2n qua ${e.p1}${e.p2}${e.p3}`;
919
+ default: {
920
+ return "";
921
+ }
922
+ }
923
+ }
924
+ function describeDsl(obj, state) {
925
+ const r = serializeObject(obj, state);
926
+ if (r.ok) return describeEntity(r.entity);
927
+ let base;
928
+ try {
929
+ base = getKind(obj.kind).describe(obj, state);
930
+ } catch {
931
+ base = `${obj.kind} ${obj.label}`;
932
+ }
933
+ return `${base} (kh\xF4ng h\u1ED7 tr\u1EE3 DSL)`;
934
+ }
935
+
936
+ export { CIRCLE_KINDS, KIND_REGISTRY, LINE_LIKE_SHAPE_KINDS, POINT_KINDS, describeDsl, serializeState };
937
+ //# sourceMappingURL=chunk-VNCCIV6O.mjs.map
938
+ //# sourceMappingURL=chunk-VNCCIV6O.mjs.map