@reearth/core 0.0.7-alpha.57 → 0.0.7-alpha.59

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/dist/index.d.ts CHANGED
@@ -280,7 +280,7 @@ declare type CommonProps = {
280
280
  sketchEditingFeature?: SketchEditingFeature;
281
281
  };
282
282
 
283
- export declare function computeAtom(cache?: typeof globalDataFeaturesCache): WritableAtom<ComputedLayer | undefined, Command, void>;
283
+ export declare function computeAtom(cache?: typeof globalDataFeaturesCache): WritableAtom<ComputedLayer | undefined, [Command], void>;
284
284
 
285
285
  export declare type ComputedFeature = CommonFeature<"computedFeature"> & Partial<AppearanceTypes>;
286
286
 
@@ -794,11 +794,11 @@ export declare function getCompat(l: Layer | undefined): LayerCompat | undefined
794
794
 
795
795
  declare const globalDataFeaturesCache: {
796
796
  get: Atom_2<(key: string, key2: string) => Feature[] | undefined>;
797
- set: WritableAtom<null, {
797
+ set: WritableAtom<null, [value: {
798
798
  key: string;
799
799
  key2: string;
800
800
  value?: Feature[] | undefined;
801
- }, void> & {
801
+ }], void> & {
802
802
  init: null;
803
803
  };
804
804
  getAll: Atom_2<(key: string) => Feature[][] | undefined>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reearth/core",
3
- "version": "0.0.7-alpha.57",
3
+ "version": "0.0.7-alpha.59",
4
4
  "author": "Re:Earth contributors <community@reearth.io>",
5
5
  "license": "Apache-2.0",
6
6
  "description": "A library that abstracts a map engine as one common API.",
@@ -42,21 +42,21 @@
42
42
  "@radix-ui/react-slot": "^1.2.4",
43
43
  "@radix-ui/react-switch": "^1.2.6",
44
44
  "@radix-ui/react-toggle": "^1.1.10",
45
- "@reearth/cesium-mvt-imagery-provider": "1.6.1",
45
+ "@reearth/cesium-mvt-imagery-provider": "1.6.2",
46
46
  "@reearth/spatial-id-sdk": "0.0.0",
47
47
  "@rot1024/use-transition": "1.0.0",
48
48
  "@seznam/compose-react-refs": "1.0.6",
49
49
  "@turf/invariant": "^7.3.3",
50
50
  "@turf/turf": "^7.3.3",
51
51
  "@ungap/event-target": "0.2.4",
52
- "@xstate/react": "3.2.1",
52
+ "@xstate/react": "^6.1.0",
53
53
  "cesium-dnd": "1.1.0",
54
54
  "csv-parse": "^6.1.0",
55
55
  "d3": "^7.9.0",
56
56
  "fast-xml-parser": "^5.3.3",
57
57
  "framer-motion": "^12.29.2",
58
58
  "geojson": "0.5.0",
59
- "jotai": "1.12.1",
59
+ "jotai": "^2.18.0",
60
60
  "js-md5": "^0.8.3",
61
61
  "jsep": "^1.4.0",
62
62
  "jsonpath-plus": "^10.3.0",
@@ -65,7 +65,7 @@
65
65
  "lru-cache": "^11.2.5",
66
66
  "pbf": "^4.0.1",
67
67
  "proj4": "^2.20.2",
68
- "protomaps": "1.23.1",
68
+ "protomaps-leaflet": "^5.1.0",
69
69
  "react-dnd": "16.0.1",
70
70
  "react-dnd-html5-backend": "16.0.1",
71
71
  "react-error-boundary": "^6.1.0",
@@ -73,14 +73,14 @@
73
73
  "react-use": "^17.6.0",
74
74
  "resium": "^1.19.3",
75
75
  "suspend-react": "0.1.3",
76
- "tailwind-merge": "^2.5.5",
77
- "tailwindcss": "^3.4.17",
76
+ "tailwind-merge": "^3.5.0",
77
+ "tailwindcss": "^4.2.1",
78
78
  "tailwindcss-animate": "^1.0.7",
79
79
  "tiny-invariant": "1.3.3",
80
80
  "use-callback-ref": "1.3.3",
81
81
  "use-custom-compare": "1.5.0",
82
82
  "uuid": "^13.0.0",
83
- "xstate": "4.38.2"
83
+ "xstate": "^5.28.0"
84
84
  },
85
85
  "devDependencies": {
86
86
  "@apollo/client": "^4.1.2",
@@ -105,6 +105,7 @@
105
105
  "@types/scheduler": "^0.26.0",
106
106
  "@vitejs/plugin-react": "^5.1.2",
107
107
  "@xstate/cli": "0.5.17",
108
+ "@tailwindcss/postcss": "^4.2.1",
108
109
  "autoprefixer": "^10.4.23",
109
110
  "cesium": "^1.137.0",
110
111
  "class-variance-authority": "^0.7.1",
@@ -112,7 +113,7 @@
112
113
  "eslint": "8.57.0",
113
114
  "eslint-config-reearth": "0.3.0",
114
115
  "eslint-plugin-storybook": "^10.2.3",
115
- "jsdom": "^27.4.0",
116
+ "jsdom": "^28.1.0",
116
117
  "postcss": "^8.5.6",
117
118
  "prettier": "^3.8.1",
118
119
  "react": "^19.2.4",
@@ -13,7 +13,7 @@ import {
13
13
  useState,
14
14
  } from "react";
15
15
  import { v4 as uuidv4 } from "uuid";
16
- import { InterpreterFrom, StateFrom } from "xstate";
16
+ import { ActorRefFrom, StateFrom } from "xstate";
17
17
 
18
18
  import { ControlPointMouseEventHandler } from "../../engines/Cesium/Sketch";
19
19
  import { InteractionModeType } from "../../shared/interactionMode";
@@ -65,7 +65,7 @@ type Props = {
65
65
  const sketchMachine = createSketchMachine();
66
66
 
67
67
  export type sketchState = StateFrom<typeof sketchMachine>;
68
- export type SketchInterpreter = InterpreterFrom<typeof sketchMachine>;
68
+ export type SketchInterpreter = ActorRefFrom<typeof sketchMachine>;
69
69
 
70
70
  export default function ({
71
71
  ref,
@@ -1,6 +1,6 @@
1
1
  // TODO: Refactor: move cesium related code to engine.
2
2
  import invariant from "tiny-invariant";
3
- import { createMachine, type StateFrom } from "xstate";
3
+ import { createMachine, assign, type StateFrom } from "xstate";
4
4
 
5
5
  import { type SketchType } from "./types";
6
6
 
@@ -133,6 +133,7 @@ export function createSketchMachine() {
133
133
  },
134
134
  },
135
135
  drawing: {
136
+ initial: "marker",
136
137
  states: {
137
138
  marker: {
138
139
  initial: "vertex",
@@ -147,7 +148,7 @@ export function createSketchMachine() {
147
148
  on: {
148
149
  NEXT: {
149
150
  target: "vertex",
150
- internal: true,
151
+ reenter: false,
151
152
  actions: ["pushPosition"],
152
153
  },
153
154
  },
@@ -175,7 +176,7 @@ export function createSketchMachine() {
175
176
  NEXT: [
176
177
  {
177
178
  target: "vertex",
178
- internal: true,
179
+ reenter: false,
179
180
  actions: ["pushPosition"],
180
181
  },
181
182
  ],
@@ -191,12 +192,12 @@ export function createSketchMachine() {
191
192
  NEXT: [
192
193
  {
193
194
  target: "#sketch.extruding",
194
- cond: "willRectangleComplete",
195
+ guard: "willRectangleComplete",
195
196
  actions: ["pushPosition", "recordOriginalControlPoint"],
196
197
  },
197
198
  {
198
199
  target: "vertex",
199
- internal: true,
200
+ reenter: false,
200
201
  actions: ["pushPosition"],
201
202
  },
202
203
  ],
@@ -211,7 +212,7 @@ export function createSketchMachine() {
211
212
  on: {
212
213
  NEXT: {
213
214
  target: "vertex",
214
- internal: true,
215
+ reenter: false,
215
216
  actions: ["pushPosition"],
216
217
  },
217
218
  },
@@ -225,7 +226,7 @@ export function createSketchMachine() {
225
226
  on: {
226
227
  NEXT: {
227
228
  target: "vertex",
228
- internal: true,
229
+ reenter: false,
229
230
  actions: ["pushPosition"],
230
231
  },
231
232
  EXTRUDE: {
@@ -244,7 +245,7 @@ export function createSketchMachine() {
244
245
  CANCEL: [
245
246
  {
246
247
  target: ".history",
247
- cond: "canPopPosition",
248
+ guard: "canPopPosition",
248
249
  actions: ["popPosition"],
249
250
  },
250
251
  {
@@ -279,6 +280,7 @@ export function createSketchMachine() {
279
280
  },
280
281
  },
281
282
  editing: {
283
+ initial: "marker",
282
284
  states: {
283
285
  marker: {
284
286
  initial: "waiting",
@@ -287,7 +289,7 @@ export function createSketchMachine() {
287
289
  on: {
288
290
  CATCH: {
289
291
  target: "moving",
290
- internal: true,
292
+ reenter: false,
291
293
  actions: ["catchControlPoint"],
292
294
  },
293
295
  },
@@ -296,7 +298,7 @@ export function createSketchMachine() {
296
298
  on: {
297
299
  MOVE: {
298
300
  target: "moving",
299
- internal: true,
301
+ reenter: false,
300
302
  actions: ["moveControlPoint"],
301
303
  },
302
304
  RELEASE: {
@@ -314,12 +316,12 @@ export function createSketchMachine() {
314
316
  on: {
315
317
  CATCH: {
316
318
  target: "moving",
317
- internal: true,
319
+ reenter: false,
318
320
  actions: ["catchControlPoint"],
319
321
  },
320
322
  UPDATE: {
321
323
  target: "waiting",
322
- internal: true,
324
+ reenter: false,
323
325
  actions: ["updateControlPoints"],
324
326
  },
325
327
  },
@@ -328,7 +330,7 @@ export function createSketchMachine() {
328
330
  on: {
329
331
  MOVE: {
330
332
  target: "moving",
331
- internal: true,
333
+ reenter: false,
332
334
  actions: ["moveControlPoint"],
333
335
  },
334
336
  RELEASE: {
@@ -346,7 +348,7 @@ export function createSketchMachine() {
346
348
  on: {
347
349
  CATCH: {
348
350
  target: "moving",
349
- internal: true,
351
+ reenter: false,
350
352
  actions: ["catchControlPoint"],
351
353
  },
352
354
  },
@@ -355,7 +357,7 @@ export function createSketchMachine() {
355
357
  on: {
356
358
  MOVE: {
357
359
  target: "moving",
358
- internal: true,
360
+ reenter: false,
359
361
  actions: ["moveControlPoint"],
360
362
  },
361
363
  RELEASE: {
@@ -373,7 +375,7 @@ export function createSketchMachine() {
373
375
  on: {
374
376
  CATCH: {
375
377
  target: "moving",
376
- internal: true,
378
+ reenter: false,
377
379
  actions: ["catchControlPoint"],
378
380
  },
379
381
  },
@@ -382,7 +384,7 @@ export function createSketchMachine() {
382
384
  on: {
383
385
  MOVE: {
384
386
  target: "moving",
385
- internal: true,
387
+ reenter: false,
386
388
  actions: ["moveControlPoint"],
387
389
  },
388
390
  RELEASE: {
@@ -400,12 +402,12 @@ export function createSketchMachine() {
400
402
  on: {
401
403
  CATCH: {
402
404
  target: "moving",
403
- internal: true,
405
+ reenter: false,
404
406
  actions: ["catchControlPoint"],
405
407
  },
406
408
  UPDATE: {
407
409
  target: "waiting",
408
- internal: true,
410
+ reenter: false,
409
411
  actions: ["updateControlPoints"],
410
412
  },
411
413
  },
@@ -414,7 +416,7 @@ export function createSketchMachine() {
414
416
  on: {
415
417
  MOVE: {
416
418
  target: "moving",
417
- internal: true,
419
+ reenter: false,
418
420
  actions: ["moveControlPoint"],
419
421
  },
420
422
  RELEASE: {
@@ -432,7 +434,7 @@ export function createSketchMachine() {
432
434
  on: {
433
435
  CATCH: {
434
436
  target: "moving",
435
- internal: true,
437
+ reenter: false,
436
438
  actions: ["catchControlPoint"],
437
439
  },
438
440
  },
@@ -441,7 +443,7 @@ export function createSketchMachine() {
441
443
  on: {
442
444
  MOVE: {
443
445
  target: "moving",
444
- internal: true,
446
+ reenter: false,
445
447
  actions: ["moveControlPoint"],
446
448
  },
447
449
  RELEASE: {
@@ -459,7 +461,7 @@ export function createSketchMachine() {
459
461
  on: {
460
462
  CATCH: {
461
463
  target: "moving",
462
- internal: true,
464
+ reenter: false,
463
465
  actions: ["catchControlPoint"],
464
466
  },
465
467
  },
@@ -468,7 +470,7 @@ export function createSketchMachine() {
468
470
  on: {
469
471
  MOVE: {
470
472
  target: "moving",
471
- internal: true,
473
+ reenter: false,
472
474
  actions: ["moveControlPoint"],
473
475
  },
474
476
  RELEASE: {
@@ -486,12 +488,12 @@ export function createSketchMachine() {
486
488
  on: {
487
489
  CATCH: {
488
490
  target: "moving",
489
- internal: true,
491
+ reenter: false,
490
492
  actions: ["catchControlPoint"],
491
493
  },
492
494
  UPDATE: {
493
495
  target: "waiting",
494
- internal: true,
496
+ reenter: false,
495
497
  actions: ["updateControlPoints"],
496
498
  },
497
499
  },
@@ -500,7 +502,7 @@ export function createSketchMachine() {
500
502
  on: {
501
503
  MOVE: {
502
504
  target: "moving",
503
- internal: true,
505
+ reenter: false,
504
506
  actions: ["moveControlPoint"],
505
507
  },
506
508
  RELEASE: {
@@ -520,158 +522,126 @@ export function createSketchMachine() {
520
522
  },
521
523
  },
522
524
  },
523
- schema: {
524
- events: {} as unknown as EventObject,
525
- },
526
- predictableActionArguments: true,
527
- preserveActionOrder: true,
528
- tsTypes: {} as import("./sketchMachine.typegen").Typegen0,
529
525
  },
530
- {
531
- guards: {
532
- canPopPosition: context => {
533
- return context.controlPoints != null && context.controlPoints.length > 1;
534
- },
535
- willRectangleComplete: context => {
536
- return context.controlPoints != null && context.controlPoints.length === 2;
537
- },
538
- },
539
- actions: {
540
- createMarker: (context, event) => {
541
- context.lastPointerPosition = [...event.pointerPosition];
542
- const controlPoint = [...event.controlPoint] as Position3d;
543
- context.lastControlPoint = controlPoint;
544
- context.type = "marker";
545
- context.controlPoints = [controlPoint];
546
- },
547
- editMarker: (context, event) => {
548
- context.lastControlPoint = undefined;
549
- context.type = "marker";
550
- context.controlPoints = event.controlPoints;
551
- },
552
- createPolyline: (context, event) => {
553
- context.lastPointerPosition = [...event.pointerPosition];
554
- const controlPoint = [...event.controlPoint] as Position3d;
555
- context.lastControlPoint = controlPoint;
556
- context.type = "polyline";
557
- context.controlPoints = [controlPoint];
558
- },
559
- editPolyline: (context, event) => {
560
- context.lastControlPoint = undefined;
561
- context.type = "polyline";
562
- context.controlPoints = event.controlPoints;
563
- },
564
- createCircle: (context, event) => {
565
- context.lastPointerPosition = [...event.pointerPosition];
566
- const controlPoint = [...event.controlPoint] as Position3d;
567
- context.lastControlPoint = controlPoint;
568
- context.type = "circle";
569
- context.controlPoints = [controlPoint];
570
- },
571
- editCircle: (context, event) => {
572
- context.lastControlPoint = undefined;
573
- context.type = "circle";
574
- context.controlPoints = event.controlPoints;
575
- },
576
- createRectangle: (context, event) => {
577
- context.lastPointerPosition = [...event.pointerPosition];
578
- const controlPoint = [...event.controlPoint] as Position3d;
579
- context.lastControlPoint = controlPoint;
580
- context.type = "rectangle";
581
- context.controlPoints = [controlPoint];
582
- },
583
- editRectangle: (context, event) => {
584
- context.lastControlPoint = undefined;
585
- context.type = "rectangle";
586
- context.controlPoints = event.controlPoints;
587
- },
588
- createPolygon: (context, event) => {
589
- context.lastPointerPosition = [...event.pointerPosition];
590
- const controlPoint = [...event.controlPoint] as Position3d;
591
- context.lastControlPoint = controlPoint;
592
- context.type = "polygon";
593
- context.controlPoints = [controlPoint];
594
- },
595
- editPolygon: (context, event) => {
596
- context.lastControlPoint = undefined;
597
- context.type = "polygon";
598
- context.controlPoints = event.controlPoints;
599
- },
600
- createExtrudedCircle: (context, event) => {
601
- context.lastPointerPosition = [...event.pointerPosition];
602
- const controlPoint = [...event.controlPoint] as Position3d;
603
- context.lastControlPoint = controlPoint;
604
- context.type = "extrudedCircle";
605
- context.controlPoints = [controlPoint];
606
- },
607
- editExtrudedCircle: (context, event) => {
608
- context.lastControlPoint = undefined;
609
- context.type = "extrudedCircle";
610
- context.controlPoints = event.controlPoints;
611
- },
612
- createExtrudedRectangle: (context, event) => {
613
- context.lastPointerPosition = [...event.pointerPosition];
614
- const controlPoint = [...event.controlPoint] as Position3d;
615
- context.lastControlPoint = controlPoint;
616
- context.type = "extrudedRectangle";
617
- context.controlPoints = [controlPoint];
618
- },
619
- editExtrudedRectangle: (context, event) => {
620
- context.lastControlPoint = undefined;
621
- context.type = "extrudedRectangle";
622
- context.controlPoints = event.controlPoints;
623
- },
624
- createExtrudedPolygon: (context, event) => {
625
- context.lastPointerPosition = [...event.pointerPosition];
626
- const controlPoint = [...event.controlPoint] as Position3d;
627
- context.lastControlPoint = controlPoint;
628
- context.type = "extrudedPolygon";
629
- context.controlPoints = [controlPoint];
630
- },
631
- editExtrudedPolygon: (context, event) => {
632
- context.lastControlPoint = undefined;
633
- context.type = "extrudedPolygon";
634
- context.controlPoints = event.controlPoints;
635
- },
636
- pushPosition: (context, event) => {
637
- context.lastPointerPosition = [...event.pointerPosition];
638
- const controlPoint = [...event.controlPoint] as Position3d;
639
- context.lastControlPoint = controlPoint;
640
- context.controlPoints?.push(controlPoint);
641
- },
642
- popPosition: context => {
643
- invariant(context.controlPoints != null);
644
- invariant(context.controlPoints.length > 1);
645
- context.controlPoints.pop();
646
- },
647
- clearDrawing: context => {
648
- delete context.lastControlPoint;
649
- delete context.type;
650
- delete context.controlPoints;
651
- delete context.catchedControlPointIndex;
652
- delete context.catchedExtrudedPoint;
653
- delete context.originalControlPoint;
654
- },
655
- catchControlPoint: (context, event) => {
656
- context.catchedControlPointIndex = event.catchedControlPointIndex;
657
- context.catchedExtrudedPoint = event.catchedExtrudedPoint;
658
- },
659
- moveControlPoint: (context, event) => {
660
- context.controlPoints = event.controlPoints;
661
- },
662
- releaseControlPoint: context => {
663
- delete context.catchedControlPointIndex;
664
- delete context.catchedExtrudedPoint;
665
- },
666
- updateControlPoints: (context, event) => {
667
- context.controlPoints = event.controlPoints;
668
- },
669
- recordOriginalControlPoint: (context, event) => {
670
- context.originalControlPoint = [...event.controlPoint] as Position3d;
671
- },
672
- },
526
+ ).provide({
527
+ guards: {
528
+ canPopPosition: ({ context }) => context.controlPoints != null && context.controlPoints.length > 1,
529
+ willRectangleComplete: ({ context }) => context.controlPoints != null && context.controlPoints.length === 2,
530
+ },
531
+ actions: {
532
+ createMarker: assign(({ event }) => {
533
+ const e = event as Extract<EventObject, { type: "MARKER" }>;
534
+ const controlPoint = [...e.controlPoint] as Position3d;
535
+ return { lastPointerPosition: [...e.pointerPosition] as Position2d, lastControlPoint: controlPoint, type: "marker" as SketchType, controlPoints: [controlPoint] };
536
+ }),
537
+ editMarker: assign(({ event }) => {
538
+ const e = event as Extract<EventObject, { type: "EDIT_MARKER" }>;
539
+ return { lastControlPoint: undefined, type: "marker" as SketchType, controlPoints: e.controlPoints };
540
+ }),
541
+ createPolyline: assign(({ event }) => {
542
+ const e = event as Extract<EventObject, { type: "POLYLINE" }>;
543
+ const controlPoint = [...e.controlPoint] as Position3d;
544
+ return { lastPointerPosition: [...e.pointerPosition] as Position2d, lastControlPoint: controlPoint, type: "polyline" as SketchType, controlPoints: [controlPoint] };
545
+ }),
546
+ editPolyline: assign(({ event }) => {
547
+ const e = event as Extract<EventObject, { type: "EDIT_POLYLINE" }>;
548
+ return { lastControlPoint: undefined, type: "polyline" as SketchType, controlPoints: e.controlPoints };
549
+ }),
550
+ createCircle: assign(({ event }) => {
551
+ const e = event as Extract<EventObject, { type: "CIRCLE" }>;
552
+ const controlPoint = [...e.controlPoint] as Position3d;
553
+ return { lastPointerPosition: [...e.pointerPosition] as Position2d, lastControlPoint: controlPoint, type: "circle" as SketchType, controlPoints: [controlPoint] };
554
+ }),
555
+ editCircle: assign(({ event }) => {
556
+ const e = event as Extract<EventObject, { type: "EDIT_CIRCLE" }>;
557
+ return { lastControlPoint: undefined, type: "circle" as SketchType, controlPoints: e.controlPoints };
558
+ }),
559
+ createRectangle: assign(({ event }) => {
560
+ const e = event as Extract<EventObject, { type: "RECTANGLE" }>;
561
+ const controlPoint = [...e.controlPoint] as Position3d;
562
+ return { lastPointerPosition: [...e.pointerPosition] as Position2d, lastControlPoint: controlPoint, type: "rectangle" as SketchType, controlPoints: [controlPoint] };
563
+ }),
564
+ editRectangle: assign(({ event }) => {
565
+ const e = event as Extract<EventObject, { type: "EDIT_RECTANGLE" }>;
566
+ return { lastControlPoint: undefined, type: "rectangle" as SketchType, controlPoints: e.controlPoints };
567
+ }),
568
+ createPolygon: assign(({ event }) => {
569
+ const e = event as Extract<EventObject, { type: "POLYGON" }>;
570
+ const controlPoint = [...e.controlPoint] as Position3d;
571
+ return { lastPointerPosition: [...e.pointerPosition] as Position2d, lastControlPoint: controlPoint, type: "polygon" as SketchType, controlPoints: [controlPoint] };
572
+ }),
573
+ editPolygon: assign(({ event }) => {
574
+ const e = event as Extract<EventObject, { type: "EDIT_POLYGON" }>;
575
+ return { lastControlPoint: undefined, type: "polygon" as SketchType, controlPoints: e.controlPoints };
576
+ }),
577
+ createExtrudedCircle: assign(({ event }) => {
578
+ const e = event as Extract<EventObject, { type: "EXTRUDED_CIRCLE" }>;
579
+ const controlPoint = [...e.controlPoint] as Position3d;
580
+ return { lastPointerPosition: [...e.pointerPosition] as Position2d, lastControlPoint: controlPoint, type: "extrudedCircle" as SketchType, controlPoints: [controlPoint] };
581
+ }),
582
+ editExtrudedCircle: assign(({ event }) => {
583
+ const e = event as Extract<EventObject, { type: "EDIT_EXTRUDED_CIRCLE" }>;
584
+ return { lastControlPoint: undefined, type: "extrudedCircle" as SketchType, controlPoints: e.controlPoints };
585
+ }),
586
+ createExtrudedRectangle: assign(({ event }) => {
587
+ const e = event as Extract<EventObject, { type: "EXTRUDED_RECTANGLE" }>;
588
+ const controlPoint = [...e.controlPoint] as Position3d;
589
+ return { lastPointerPosition: [...e.pointerPosition] as Position2d, lastControlPoint: controlPoint, type: "extrudedRectangle" as SketchType, controlPoints: [controlPoint] };
590
+ }),
591
+ editExtrudedRectangle: assign(({ event }) => {
592
+ const e = event as Extract<EventObject, { type: "EDIT_EXTRUDED_RECTANGLE" }>;
593
+ return { lastControlPoint: undefined, type: "extrudedRectangle" as SketchType, controlPoints: e.controlPoints };
594
+ }),
595
+ createExtrudedPolygon: assign(({ event }) => {
596
+ const e = event as Extract<EventObject, { type: "EXTRUDED_POLYGON" }>;
597
+ const controlPoint = [...e.controlPoint] as Position3d;
598
+ return { lastPointerPosition: [...e.pointerPosition] as Position2d, lastControlPoint: controlPoint, type: "extrudedPolygon" as SketchType, controlPoints: [controlPoint] };
599
+ }),
600
+ editExtrudedPolygon: assign(({ event }) => {
601
+ const e = event as Extract<EventObject, { type: "EDIT_EXTRUDED_POLYGON" }>;
602
+ return { lastControlPoint: undefined, type: "extrudedPolygon" as SketchType, controlPoints: e.controlPoints };
603
+ }),
604
+ pushPosition: assign(({ context, event }) => {
605
+ const e = event as Extract<EventObject, { type: "NEXT" | "EXTRUDE" }>;
606
+ const controlPoint = [...e.controlPoint] as Position3d;
607
+ return {
608
+ lastPointerPosition: [...e.pointerPosition] as Position2d,
609
+ lastControlPoint: controlPoint,
610
+ controlPoints: [...(context.controlPoints ?? []), controlPoint],
611
+ };
612
+ }),
613
+ popPosition: assign(({ context }) => {
614
+ invariant(context.controlPoints != null);
615
+ invariant(context.controlPoints.length > 1);
616
+ return { controlPoints: context.controlPoints.slice(0, -1) };
617
+ }),
618
+ clearDrawing: assign(() => ({
619
+ lastControlPoint: undefined,
620
+ type: undefined,
621
+ controlPoints: undefined,
622
+ catchedControlPointIndex: undefined,
623
+ catchedExtrudedPoint: undefined,
624
+ originalControlPoint: undefined,
625
+ })),
626
+ catchControlPoint: assign(({ event }) => {
627
+ const e = event as Extract<EventObject, { type: "CATCH" }>;
628
+ return { catchedControlPointIndex: e.catchedControlPointIndex, catchedExtrudedPoint: e.catchedExtrudedPoint };
629
+ }),
630
+ moveControlPoint: assign(({ event }) => {
631
+ const e = event as Extract<EventObject, { type: "MOVE" }>;
632
+ return { controlPoints: e.controlPoints };
633
+ }),
634
+ releaseControlPoint: assign(() => ({ catchedControlPointIndex: undefined, catchedExtrudedPoint: undefined })),
635
+ updateControlPoints: assign(({ event }) => {
636
+ const e = event as Extract<EventObject, { type: "UPDATE" }>;
637
+ return { controlPoints: e.controlPoints };
638
+ }),
639
+ recordOriginalControlPoint: assign(({ event }) => {
640
+ const e = event as Extract<EventObject, { type: "NEXT" }>;
641
+ return { originalControlPoint: [...e.controlPoint] as Position3d };
642
+ }),
673
643
  },
674
- );
644
+ });
675
645
  }
676
646
 
677
647
  export type SketchMachine = ReturnType<typeof createSketchMachine>;