@things-factory/figure-ui 10.1.245 → 10.1.247

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 (127) hide show
  1. package/client/modeller/align.ts +51 -13
  2. package/client/modeller/clips.ts +51 -1
  3. package/client/modeller/data-interface.ts +16 -0
  4. package/client/modeller/editor-styles.ts +6 -0
  5. package/client/modeller/editor.ts +112 -25
  6. package/client/modeller/fasten-form.ts +8 -1
  7. package/client/modeller/fasten-geometry.ts +24 -2
  8. package/client/modeller/figure-clips.ts +137 -4
  9. package/client/modeller/figure-fasten-dialog.ts +1 -0
  10. package/client/modeller/figure-fasten-drawing.ts +11 -5
  11. package/client/modeller/figure-links.ts +25 -0
  12. package/client/modeller/figure-material-panel.ts +54 -4
  13. package/client/modeller/figure-parts.ts +7 -2
  14. package/client/modeller/figure-pipe-panel.ts +215 -0
  15. package/client/modeller/figure-preview.ts +125 -4
  16. package/client/modeller/figure-section-editor.ts +36 -3
  17. package/client/modeller/links.ts +24 -2
  18. package/client/modeller/material-edit.ts +9 -0
  19. package/client/modeller/maturity.ts +15 -4
  20. package/client/modeller/palette.ts +9 -0
  21. package/client/modeller/pipe-path.ts +21 -0
  22. package/client/modeller/refusals.ts +66 -1
  23. package/client/modeller/section-controls.ts +2 -1
  24. package/client/modeller/section-drawing.ts +20 -1
  25. package/client/modeller/starting-shape.ts +8 -5
  26. package/dist-client/modeller/align.d.ts +28 -7
  27. package/dist-client/modeller/align.js +37 -12
  28. package/dist-client/modeller/align.js.map +1 -1
  29. package/dist-client/modeller/clips.d.ts +24 -0
  30. package/dist-client/modeller/clips.js +53 -1
  31. package/dist-client/modeller/clips.js.map +1 -1
  32. package/dist-client/modeller/data-interface.d.ts +6 -0
  33. package/dist-client/modeller/data-interface.js +17 -0
  34. package/dist-client/modeller/data-interface.js.map +1 -1
  35. package/dist-client/modeller/editor-styles.js +6 -0
  36. package/dist-client/modeller/editor-styles.js.map +1 -1
  37. package/dist-client/modeller/editor.d.ts +10 -1
  38. package/dist-client/modeller/editor.js +117 -26
  39. package/dist-client/modeller/editor.js.map +1 -1
  40. package/dist-client/modeller/fasten-form.d.ts +2 -0
  41. package/dist-client/modeller/fasten-form.js +5 -1
  42. package/dist-client/modeller/fasten-form.js.map +1 -1
  43. package/dist-client/modeller/fasten-geometry.d.ts +8 -1
  44. package/dist-client/modeller/fasten-geometry.js +22 -1
  45. package/dist-client/modeller/fasten-geometry.js.map +1 -1
  46. package/dist-client/modeller/figure-clips.d.ts +9 -0
  47. package/dist-client/modeller/figure-clips.js +137 -4
  48. package/dist-client/modeller/figure-clips.js.map +1 -1
  49. package/dist-client/modeller/figure-fasten-dialog.js +1 -0
  50. package/dist-client/modeller/figure-fasten-dialog.js.map +1 -1
  51. package/dist-client/modeller/figure-fasten-drawing.d.ts +3 -1
  52. package/dist-client/modeller/figure-fasten-drawing.js +13 -5
  53. package/dist-client/modeller/figure-fasten-drawing.js.map +1 -1
  54. package/dist-client/modeller/figure-links.d.ts +5 -0
  55. package/dist-client/modeller/figure-links.js +22 -0
  56. package/dist-client/modeller/figure-links.js.map +1 -1
  57. package/dist-client/modeller/figure-material-panel.d.ts +2 -0
  58. package/dist-client/modeller/figure-material-panel.js +53 -4
  59. package/dist-client/modeller/figure-material-panel.js.map +1 -1
  60. package/dist-client/modeller/figure-parts.d.ts +1 -1
  61. package/dist-client/modeller/figure-parts.js +5 -1
  62. package/dist-client/modeller/figure-parts.js.map +1 -1
  63. package/dist-client/modeller/figure-pipe-panel.d.ts +29 -0
  64. package/dist-client/modeller/figure-pipe-panel.js +221 -0
  65. package/dist-client/modeller/figure-pipe-panel.js.map +1 -0
  66. package/dist-client/modeller/figure-preview.d.ts +8 -0
  67. package/dist-client/modeller/figure-preview.js +128 -4
  68. package/dist-client/modeller/figure-preview.js.map +1 -1
  69. package/dist-client/modeller/figure-section-editor.d.ts +5 -0
  70. package/dist-client/modeller/figure-section-editor.js +33 -3
  71. package/dist-client/modeller/figure-section-editor.js.map +1 -1
  72. package/dist-client/modeller/links.d.ts +6 -0
  73. package/dist-client/modeller/links.js +17 -2
  74. package/dist-client/modeller/links.js.map +1 -1
  75. package/dist-client/modeller/material-edit.d.ts +8 -0
  76. package/dist-client/modeller/material-edit.js +8 -0
  77. package/dist-client/modeller/material-edit.js.map +1 -1
  78. package/dist-client/modeller/maturity.js +16 -5
  79. package/dist-client/modeller/maturity.js.map +1 -1
  80. package/dist-client/modeller/palette.js +9 -0
  81. package/dist-client/modeller/palette.js.map +1 -1
  82. package/dist-client/modeller/pipe-path.d.ts +19 -0
  83. package/dist-client/modeller/pipe-path.js +14 -0
  84. package/dist-client/modeller/pipe-path.js.map +1 -0
  85. package/dist-client/modeller/refusals.d.ts +12 -1
  86. package/dist-client/modeller/refusals.js +67 -0
  87. package/dist-client/modeller/refusals.js.map +1 -1
  88. package/dist-client/modeller/section-controls.js +2 -1
  89. package/dist-client/modeller/section-controls.js.map +1 -1
  90. package/dist-client/modeller/section-drawing.d.ts +5 -0
  91. package/dist-client/modeller/section-drawing.js +19 -1
  92. package/dist-client/modeller/section-drawing.js.map +1 -1
  93. package/dist-client/modeller/starting-shape.d.ts +9 -2
  94. package/dist-client/modeller/starting-shape.js +8 -3
  95. package/dist-client/modeller/starting-shape.js.map +1 -1
  96. package/dist-client/tsconfig.tsbuildinfo +1 -1
  97. package/package.json +8 -8
  98. package/test/align.test.ts +28 -6
  99. package/test/browser/editing-page.js +21 -1
  100. package/test/browser/editing.check.mjs +124 -0
  101. package/test/browser/links.check.mjs +49 -8
  102. package/test/browser/modeller.check.mjs +27 -1
  103. package/test/browser/part-ids.check.mjs +60 -3
  104. package/test/browser/parts.check.mjs +2 -2
  105. package/test/browser/places-mesh.check.mjs +14 -8
  106. package/test/browser/screen.check.mjs +54 -1
  107. package/test/browser/section-page.js +7 -1
  108. package/test/browser/section.check.mjs +81 -0
  109. package/test/browser/side-panel-sweep.check.mjs +13 -0
  110. package/test/clips.test.ts +30 -1
  111. package/test/data-motion.test.ts +14 -1
  112. package/test/fasten-geometry.test.ts +13 -2
  113. package/test/joint-frames.test.ts +12 -2
  114. package/test/links.test.ts +24 -0
  115. package/test/material.test.ts +15 -1
  116. package/test/maturity.test.ts +19 -1
  117. package/test/palette-icons.test.ts +2 -1
  118. package/test/pipe-panel.test.ts +33 -0
  119. package/test/refusals.test.ts +29 -0
  120. package/test/revision.test.ts +1 -1
  121. package/test/section-editor.test.ts +17 -1
  122. package/translations/en.json +86 -3
  123. package/translations/es.json +86 -3
  124. package/translations/ja.json +86 -3
  125. package/translations/ko.json +86 -3
  126. package/translations/ms.json +86 -3
  127. package/translations/zh.json +86 -3
@@ -3,12 +3,14 @@
3
3
  * 원기둥, 문틀, 구, 원뿔, 그린 단면, 뿔. A word for the screen, read from the shape node's own params; it is not a kind of
4
4
  * stored shape, and nothing is decided by it.
5
5
  */
6
- export type StartingShapeKind = 'cube' | 'rounded-box' | 'hollow-box' | 'cylinder' | 'portal' | 'sphere' | 'frustum' | 'polygon' | 'pyramid'
6
+ export type StartingShapeKind = 'cube' | 'rounded-box' | 'hollow-box' | 'cylinder' | 'portal' | 'sphere' | 'frustum' | 'polygon' | 'pyramid' | 'tapered-box' | 'pipe' | 'duct'
7
7
 
8
8
  export function startingShapeKindOf(shape: { op: string; params?: Record<string, unknown> } | undefined): StartingShapeKind | undefined {
9
9
  const p = shape?.params ?? {}
10
10
  if (shape?.op === 'revolve@1') return p.profile === 'taper' ? 'frustum' : 'sphere'
11
- if (shape?.op === 'loft@1') return 'pyramid'
11
+ if (shape?.op === 'loft@1') return p.section === 'rectangle' ? 'tapered-box' : 'pyramid'
12
+ /* A section along a path (ADR-0100 §16.2): a round one is a pipe, a bent bar without a wall; a rectangle's a duct. */
13
+ if (shape?.op === 'sweep@1') return p.section === 'ellipse' ? 'pipe' : 'duct'
12
14
  if (shape?.op !== 'extrude@1') return undefined
13
15
  if (p.section === 'ellipse') return 'cylinder'
14
16
  if (p.section === 'polygon') return 'polygon'
@@ -21,8 +23,9 @@ export function startingShapeKindOf(shape: { op: string; params?: Record<string,
21
23
  * The same word for an evaluated body, when only the shape the kernel evaluated is in hand (a row of the parts list):
22
24
  * a door frame is the section with jambs, a drawn section the rest of the drawn ones.
23
25
  */
24
- export function startingShapeKindOfBody(shape: { provider?: string; dimensions?: Record<string, number>; extrusion?: { section: { kind: string; corner?: unknown } }; cavity?: unknown; revolution?: { profile: { kind: string } }; loft?: unknown } | undefined): StartingShapeKind | undefined {
25
- if (shape?.loft) return 'pyramid'
26
+ export function startingShapeKindOfBody(shape: { provider?: string; dimensions?: Record<string, number>; extrusion?: { section: { kind: string; corner?: unknown } }; cavity?: unknown; revolution?: { profile: { kind: string } }; loft?: { to?: unknown }; sweep?: { section: { kind: string } } } | undefined): StartingShapeKind | undefined {
27
+ if (shape?.loft) return shape.loft.to ? 'tapered-box' : 'pyramid'
28
+ if (shape?.sweep) return shape.sweep.section.kind === 'ellipse' ? 'pipe' : 'duct'
26
29
  if (shape?.revolution) return shape.revolution.profile.kind === 'taper' ? 'frustum' : 'sphere'
27
30
  const s = shape?.extrusion?.section
28
31
  if (!s) return undefined
@@ -33,4 +36,4 @@ export function startingShapeKindOfBody(shape: { provider?: string; dimensions?:
33
36
  }
34
37
 
35
38
  /** Whether a body is round across -- a circle or an ellipse pushed, anything turned: it takes a segment count. */
36
- export const isRoundBody = (shape: Parameters<typeof startingShapeKindOfBody>[0]) => ['cylinder', 'sphere', 'frustum'].includes(startingShapeKindOfBody(shape) ?? '')
39
+ export const isRoundBody = (shape: Parameters<typeof startingShapeKindOfBody>[0]) => ['cylinder', 'sphere', 'frustum', 'pipe'].includes(startingShapeKindOfBody(shape) ?? '')
@@ -1,9 +1,9 @@
1
- import type { FigureInputChange, FigureWorldBox } from '@hatiolab/figure-model';
1
+ import type { FigureAsset, FigureInputChange, FigurePartEdit, FigureWorldBox } from '@hatiolab/figure-model';
2
2
  import { type FigureRevision } from './revision.js';
3
3
  import type { GizmoReach } from './gizmo.js';
4
4
  /**
5
5
  * 맞추기 — the align tools on a part: centre on X, centre on Z, stand on the floor,
6
- * mirror on X or Z, snap to the grid.
6
+ * snap to the grid; and whether a mirrored copy is offered.
7
7
  *
8
8
  * The asset's frame has the floor at y 0 and X and Z centred on 0, so centring puts the part's box centre on 0 and the floor puts its lowest point on
9
9
  * y 0. The part's box is its evaluated, rotated extent (`figureOccupiedBoxesOf`), so a turned part lands by what it
@@ -23,12 +23,33 @@ export declare function boxOf(revision: FigureRevision, part: string): FigureWor
23
23
  export declare function gridStepOf(revision: FigureRevision): number;
24
24
  export declare function alignChanges(revision: FigureRevision, part: string, reach: GizmoReach, tool: AlignTool): FigureInputChange[];
25
25
  /**
26
- * Where a mirrored copy goes: the same distance on the other side of the centre plane. The copy is made by
27
- * `duplicate-part` first; this is the position the copy is then given.
26
+ * Mirroring a part that already sits on the centre plane would put the copy inside it, so it is not offered. The copy
27
+ * itself is figure-model's `mirror-part`, which places it -- fastened or not -- and refuses what it cannot mirror.
28
28
  */
29
- export declare function mirrorChanges(revision: FigureRevision, part: string, copy: string, axis: 'x' | 'z'): FigureInputChange[];
30
- /** Mirroring a part that already sits on the centre plane would put the copy inside it, so it is refused. */
31
- export declare function canMirror(revision: FigureRevision, part: string, axis: 'x' | 'z', reach: GizmoReach): boolean;
29
+ export declare function canMirror(revision: FigureRevision, part: string, axis: 'x' | 'z'): boolean;
30
+ /** How a mirrored copy is made: with what hangs from the part, under which names, turning as a mirror or as the original. */
31
+ export interface MirrorForm {
32
+ axis: 'x' | 'z';
33
+ chain: boolean;
34
+ /** The beginning swapped in the copies' names (\`fl\` → \`fr\`); empty, the copies take \`-copy\`. */
35
+ from: string;
36
+ to: string;
37
+ keepMotion: boolean;
38
+ }
39
+ /**
40
+ * What a mirror of this part asks before it is made: the parts hanging from it (a leg from its hip), whether any of them
41
+ * moves, and the form started -- the chain taken, the names' beginning guessed from the part's own (\`fl-hip\` across Z
42
+ * is \`bl-\`, across X \`fr-\`, by the figure's faces), the motion mirrored. A part with nothing hanging and nothing
43
+ * moving asks nothing.
44
+ */
45
+ export declare function mirrorPlanOf(asset: FigureAsset, part: string, axis: 'x' | 'z'): {
46
+ hanging: string[];
47
+ moves: boolean;
48
+ asks: boolean;
49
+ form: MirrorForm;
50
+ };
51
+ /** The one edit the form comes to. */
52
+ export declare function mirrorEditOf(part: string, form: MirrorForm): FigurePartEdit;
32
53
  /**
33
54
  * A **readable** grid step for a length: about five cells, rounded up to a 1, 2 or 5 multiple as rulers and charts do.
34
55
  * Divided plainly it gives 27 or 33, and coordinates snapped to that read as 54 and 81. Never 0.
@@ -1,4 +1,4 @@
1
- import { figureOccupiedBoxesOf, figureWritersOf } from '@hatiolab/figure-model';
1
+ import { figureHangingChainOf, figureOccupiedBoxesOf, figureWritersOf } from '@hatiolab/figure-model';
2
2
  import { derivedOf } from './revision.js';
3
3
  const AXES = ['x', 'y', 'z'];
4
4
  /**
@@ -50,21 +50,46 @@ export function alignChanges(revision, part, reach, tool) {
50
50
  }
51
51
  }
52
52
  /**
53
- * Where a mirrored copy goes: the same distance on the other side of the centre plane. The copy is made by
54
- * `duplicate-part` first; this is the position the copy is then given.
53
+ * Mirroring a part that already sits on the centre plane would put the copy inside it, so it is not offered. The copy
54
+ * itself is figure-model's `mirror-part`, which places it -- fastened or not -- and refuses what it cannot mirror.
55
55
  */
56
- export function mirrorChanges(revision, part, copy, axis) {
56
+ export function canMirror(revision, part, axis) {
57
57
  const box = boxOf(revision, part);
58
- if (!box)
59
- return [];
60
- const id = `${part}.position.${axis}`;
61
- return [{ kind: 'set-design', input: `${copy}.position.${axis}`, unit: 'mm', value: Math.round((revision.asset.designInputs[id] ?? 0) - 2 * box.centre[axis]) }];
62
- }
63
- /** Mirroring a part that already sits on the centre plane would put the copy inside it, so it is refused. */
64
- export function canMirror(revision, part, axis, reach) {
65
- const box = reach.translate ? boxOf(revision, part) : undefined;
66
58
  return !!box && Math.abs(box.centre[axis]) >= 0.5;
67
59
  }
60
+ /* The beginning a mirror across each axis swaps, by the figure's faces: X is its left and right, Z its front and back. */
61
+ const SWAPS = { x: { l: 'r', r: 'l' }, z: { f: 'b', b: 'f' } };
62
+ /**
63
+ * What a mirror of this part asks before it is made: the parts hanging from it (a leg from its hip), whether any of them
64
+ * moves, and the form started -- the chain taken, the names' beginning guessed from the part's own (\`fl-hip\` across Z
65
+ * is \`bl-\`, across X \`fr-\`, by the figure's faces), the motion mirrored. A part with nothing hanging and nothing
66
+ * moving asks nothing.
67
+ */
68
+ export function mirrorPlanOf(asset, part, axis) {
69
+ const chain = figureHangingChainOf(asset, part);
70
+ const moves = (asset.joints ?? []).some(j => chain.includes(j.body1.part) && !!j.motion?.length);
71
+ const head = /^([a-zA-Z]{1,3})-/.exec(part)?.[1] ?? '';
72
+ const swapped = [...head].map(c => SWAPS[axis][c.toLowerCase()] ?? c).join('');
73
+ const named = head && swapped !== head && chain.every(p => p.startsWith(`${head}-`));
74
+ const hanging = chain.slice(1);
75
+ return {
76
+ hanging,
77
+ moves,
78
+ asks: hanging.length > 0 || moves,
79
+ form: { axis, chain: true, from: named ? `${head}-` : '', to: named ? `${swapped}-` : '', keepMotion: false }
80
+ };
81
+ }
82
+ /** The one edit the form comes to. */
83
+ export function mirrorEditOf(part, form) {
84
+ return {
85
+ kind: 'mirror-part',
86
+ target: part,
87
+ axis: form.axis,
88
+ ...(form.chain ? { chain: true } : {}),
89
+ ...(form.from && form.to && form.from !== form.to ? { prefix: { from: form.from, to: form.to } } : {}),
90
+ ...(form.keepMotion ? { keepMotion: true } : {})
91
+ };
92
+ }
68
93
  /**
69
94
  * A **readable** grid step for a length: about five cells, rounded up to a 1, 2 or 5 multiple as rulers and charts do.
70
95
  * Divided plainly it gives 27 or 33, and coordinates snapped to that read as 54 and 81. Never 0.
@@ -1 +1 @@
1
- {"version":3,"file":"align.js","sourceRoot":"","sources":["../../client/modeller/align.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAA;A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AClK,CAAC;AAED,6GAA6G;AAC7G,MAAM,UAAU,SAAS,CAAC,QAAwB,EAAE,IAAY,EAAE,IAAe,EAAE,KAAiB;IAClG,MAAM,GAAG,GAAG,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS,CAAA;IAC/D,OAAO,CAAC,CAAC,GAAG,IAAI,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,IAAI,GAAG,CAAA;AACnD,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,QAAQ,CAAC,IAAY;IACnC,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,CAAA;IACjC,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAA;IAC3D,MAAM,CAAC,GAAG,GAAG,GAAG,SAAS,CAAA;IACzB,MAAM,QAAQ,GAAG,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAA;IAC7D,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,QAAQ,GAAG,SAAS,CAAC,CAAA;AAC1C,CAAC","sourcesContent":["import { figureOccupiedBoxesOf, figureWritersOf } from '@hatiolab/figure-model'\nimport type { FigureInputChange, FigureWorldBox } from '@hatiolab/figure-model'\n\nimport { derivedOf, type FigureRevision } from './revision.js'\n\nimport type { GizmoReach } from './gizmo.js'\n\n/**\n * 맞추기 — the align tools on a part: centre on X, centre on Z, stand on the floor,\n * mirror on X or Z, snap to the grid.\n *\n * The asset's frame has the floor at y 0 and X and Z centred on 0, so centring puts the part's box centre on 0 and the floor puts its lowest point on\n * y 0. The part's box is its evaluated, rotated extent (`figureOccupiedBoxesOf`), so a turned part lands by what it\n * actually covers, not by its unturned size.\n *\n * Every tool writes the part's own position (and, for snap, size) inputs — the same ones the gizmo writes, and only\n * where the gizmo could (`GizmoReach`).\n */\n/* The plane tool is figure-model's now, by placement (`figurePlaneAlignChanges`); these stay the screen's. */\nexport type AlignTool = 'centre-x' | 'centre-z' | 'snap'\n\nconst AXES = ['x', 'y', 'z'] as const\n\n/**\n * Every part's box at this version, as drawn: the pose set with the controls included, as the canvas shows it and as a\n * command sees it (a fastening keeps a part where it is drawn).\n */\nexport function boxesOf(revision: FigureRevision): FigureWorldBox[] {\n return derivedOf(revision, 'boxes', () => figureOccupiedBoxesOf(revision.geometry, figureWritersOf(revision.asset)))\n}\n\nexport function boxOf(revision: FigureRevision, part: string): FigureWorldBox | undefined {\n return boxesOf(revision).find(box => box.part === part)\n}\n\n/** The snapping grid: about five steps across the figure, on 1 · 2 · 5 multiples. */\nexport function gridStepOf(revision: FigureRevision): number {\n const boxes = boxesOf(revision)\n if (!boxes.length) return 1\n const span = Math.max(\n ...AXES.map(axis => {\n const lo = Math.min(...boxes.map(b => b.centre[axis] - b.extent[axis] / 2))\n const hi = Math.max(...boxes.map(b => b.centre[axis] + b.extent[axis] / 2))\n return hi - lo\n })\n )\n return niceStep(span)\n}\n\nexport function alignChanges(revision: FigureRevision, part: string, reach: GizmoReach, tool: AlignTool): FigureInputChange[] {\n if (!reach.translate) return []\n const box = boxOf(revision, part)\n if (!box) return []\n const value = (id: string) => revision.asset.designInputs[id] ?? 0\n const set = (input: string, next: number): FigureInputChange => ({ kind: 'set-design', input, unit: 'mm', value: Math.round(next) })\n const at = (axis: 'x' | 'y' | 'z') => `${part}.position.${axis}`\n switch (tool) {\n case 'centre-x':\n return [set(at('x'), value(at('x')) - box.centre.x)]\n case 'centre-z':\n return [set(at('z'), value(at('z')) - box.centre.z)]\n case 'snap': {\n const step = gridStepOf(revision)\n const round = (n: number) => Math.round(n / step) * step\n const changes = AXES.map(axis => set(at(axis), round(value(at(axis)))))\n /* A size never snaps to 0 — the part would look gone. */\n if (reach.scale && reach.sizes)\n for (const id of reach.sizes) changes.push(set(id, Math.max(step, round(value(id)))))\n return changes\n }\n }\n}\n\n/**\n * Where a mirrored copy goes: the same distance on the other side of the centre plane. The copy is made by\n * `duplicate-part` first; this is the position the copy is then given.\n */\nexport function mirrorChanges(revision: FigureRevision, part: string, copy: string, axis: 'x' | 'z'): FigureInputChange[] {\n const box = boxOf(revision, part)\n if (!box) return []\n const id = `${part}.position.${axis}`\n return [{ kind: 'set-design', input: `${copy}.position.${axis}`, unit: 'mm', value: Math.round((revision.asset.designInputs[id] ?? 0) - 2 * box.centre[axis]) }]\n}\n\n/** Mirroring a part that already sits on the centre plane would put the copy inside it, so it is refused. */\nexport function canMirror(revision: FigureRevision, part: string, axis: 'x' | 'z', reach: GizmoReach): boolean {\n const box = reach.translate ? boxOf(revision, part) : undefined\n return !!box && Math.abs(box.centre[axis]) >= 0.5\n}\n\n/**\n * A **readable** grid step for a length: about five cells, rounded up to a 1, 2 or 5 multiple as rulers and charts do.\n * Divided plainly it gives 27 or 33, and coordinates snapped to that read as 54 and 81. Never 0.\n */\nexport function niceStep(span: number): number {\n const raw = Math.max(span, 1) / 5\n const magnitude = Math.pow(10, Math.floor(Math.log10(raw)))\n const n = raw / magnitude\n const multiple = n < 1.5 ? 1 : n < 3.5 ? 2 : n < 7.5 ? 5 : 10\n return Math.max(1, multiple * magnitude)\n}\n"]}
1
+ {"version":3,"file":"align.js","sourceRoot":"","sources":["../../client/modeller/align.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,qBAAqB,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAA;AAGrG,OAAO,EAAE,SAAS,EAAuB,MAAM,eAAe,CAAA;AAkB9D,MAAM,IAAI,GA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xesOf, figureWritersOf } from '@hatiolab/figure-model'\nimport type { FigureAsset, FigureInputChange, FigurePartEdit, FigureWorldBox } from '@hatiolab/figure-model'\n\nimport { derivedOf, type FigureRevision } from './revision.js'\n\nimport type { GizmoReach } from './gizmo.js'\n\n/**\n * 맞추기 — the align tools on a part: centre on X, centre on Z, stand on the floor,\n * snap to the grid; and whether a mirrored copy is offered.\n *\n * The asset's frame has the floor at y 0 and X and Z centred on 0, so centring puts the part's box centre on 0 and the floor puts its lowest point on\n * y 0. The part's box is its evaluated, rotated extent (`figureOccupiedBoxesOf`), so a turned part lands by what it\n * actually covers, not by its unturned size.\n *\n * Every tool writes the part's own position (and, for snap, size) inputs — the same ones the gizmo writes, and only\n * where the gizmo could (`GizmoReach`).\n */\n/* The plane tool is figure-model's now, by placement (`figurePlaneAlignChanges`); these stay the screen's. */\nexport type AlignTool = 'centre-x' | 'centre-z' | 'snap'\n\nconst AXES = ['x', 'y', 'z'] as const\n\n/**\n * Every part's box at this version, as drawn: the pose set with the controls included, as the canvas shows it and as a\n * command sees it (a fastening keeps a part where it is drawn).\n */\nexport function boxesOf(revision: FigureRevision): FigureWorldBox[] {\n return derivedOf(revision, 'boxes', () => figureOccupiedBoxesOf(revision.geometry, figureWritersOf(revision.asset)))\n}\n\nexport function boxOf(revision: FigureRevision, part: string): FigureWorldBox | undefined {\n return boxesOf(revision).find(box => box.part === part)\n}\n\n/** The snapping grid: about five steps across the figure, on 1 · 2 · 5 multiples. */\nexport function gridStepOf(revision: FigureRevision): number {\n const boxes = boxesOf(revision)\n if (!boxes.length) return 1\n const span = Math.max(\n ...AXES.map(axis => {\n const lo = Math.min(...boxes.map(b => b.centre[axis] - b.extent[axis] / 2))\n const hi = Math.max(...boxes.map(b => b.centre[axis] + b.extent[axis] / 2))\n return hi - lo\n })\n )\n return niceStep(span)\n}\n\nexport function alignChanges(revision: FigureRevision, part: string, reach: GizmoReach, tool: AlignTool): FigureInputChange[] {\n if (!reach.translate) return []\n const box = boxOf(revision, part)\n if (!box) return []\n const value = (id: string) => revision.asset.designInputs[id] ?? 0\n const set = (input: string, next: number): FigureInputChange => ({ kind: 'set-design', input, unit: 'mm', value: Math.round(next) })\n const at = (axis: 'x' | 'y' | 'z') => `${part}.position.${axis}`\n switch (tool) {\n case 'centre-x':\n return [set(at('x'), value(at('x')) - box.centre.x)]\n case 'centre-z':\n return [set(at('z'), value(at('z')) - box.centre.z)]\n case 'snap': {\n const step = gridStepOf(revision)\n const round = (n: number) => Math.round(n / step) * step\n const changes = AXES.map(axis => set(at(axis), round(value(at(axis)))))\n /* A size never snaps to 0 — the part would look gone. */\n if (reach.scale && reach.sizes)\n for (const id of reach.sizes) changes.push(set(id, Math.max(step, round(value(id)))))\n return changes\n }\n }\n}\n\n/**\n * Mirroring a part that already sits on the centre plane would put the copy inside it, so it is not offered. The copy\n * itself is figure-model's `mirror-part`, which places it -- fastened or not -- and refuses what it cannot mirror.\n */\nexport function canMirror(revision: FigureRevision, part: string, axis: 'x' | 'z'): boolean {\n const box = boxOf(revision, part)\n return !!box && Math.abs(box.centre[axis]) >= 0.5\n}\n\n/** How a mirrored copy is made: with what hangs from the part, under which names, turning as a mirror or as the original. */\nexport interface MirrorForm {\n axis: 'x' | 'z'\n chain: boolean\n /** The beginning swapped in the copies' names (\\`fl\\` → \\`fr\\`); empty, the copies take \\`-copy\\`. */\n from: string\n to: string\n keepMotion: boolean\n}\n\n/* The beginning a mirror across each axis swaps, by the figure's faces: X is its left and right, Z its front and back. */\nconst SWAPS: Record<'x' | 'z', Record<string, string>> = { x: { l: 'r', r: 'l' }, z: { f: 'b', b: 'f' } }\n\n/**\n * What a mirror of this part asks before it is made: the parts hanging from it (a leg from its hip), whether any of them\n * moves, and the form started -- the chain taken, the names' beginning guessed from the part's own (\\`fl-hip\\` across Z\n * is \\`bl-\\`, across X \\`fr-\\`, by the figure's faces), the motion mirrored. A part with nothing hanging and nothing\n * moving asks nothing.\n */\nexport function mirrorPlanOf(asset: FigureAsset, part: string, axis: 'x' | 'z'): { hanging: string[]; moves: boolean; asks: boolean; form: MirrorForm } {\n const chain = figureHangingChainOf(asset, part)\n const moves = (asset.joints ?? []).some(j => chain.includes(j.body1.part) && !!j.motion?.length)\n const head = /^([a-zA-Z]{1,3})-/.exec(part)?.[1] ?? ''\n const swapped = [...head].map(c => SWAPS[axis][c.toLowerCase()] ?? c).join('')\n const named = head && swapped !== head && chain.every(p => p.startsWith(`${head}-`))\n const hanging = chain.slice(1)\n return {\n hanging,\n moves,\n asks: hanging.length > 0 || moves,\n form: { axis, chain: true, from: named ? `${head}-` : '', to: named ? `${swapped}-` : '', keepMotion: false }\n }\n}\n\n/** The one edit the form comes to. */\nexport function mirrorEditOf(part: string, form: MirrorForm): FigurePartEdit {\n return {\n kind: 'mirror-part',\n target: part,\n axis: form.axis,\n ...(form.chain ? { chain: true } : {}),\n ...(form.from && form.to && form.from !== form.to ? { prefix: { from: form.from, to: form.to } } : {}),\n ...(form.keepMotion ? { keepMotion: true } : {})\n }\n}\n\n/**\n * A **readable** grid step for a length: about five cells, rounded up to a 1, 2 or 5 multiple as rulers and charts do.\n * Divided plainly it gives 27 or 33, and coordinates snapped to that read as 54 and 81. Never 0.\n */\nexport function niceStep(span: number): number {\n const raw = Math.max(span, 1) / 5\n const magnitude = Math.pow(10, Math.floor(Math.log10(raw)))\n const n = raw / magnitude\n const multiple = n < 1.5 ? 1 : n < 3.5 ? 2 : n < 7.5 ? 5 : 10\n return Math.max(1, multiple * magnitude)\n}\n"]}
@@ -56,8 +56,32 @@ export declare const groupEdit: (group: ClipGroup, patch?: Partial<Omit<ClipGrou
56
56
  export declare function poseAt(asset: FigureAsset, clip: string, seconds: number): FigureInputChange[];
57
57
  /** A key added at a moment, replacing one already there; the keys stay in time order. */
58
58
  export declare function withKey(keys: readonly ClipKey[], key: ClipKey): ClipKey[];
59
+ /**
60
+ * A key typed where it stands: its moment, its value, or both. The first key stays at 0 (a track starts there); a moment
61
+ * outside the clip, or on another key's, is refused (null) rather than taking that key's place unseen.
62
+ */
63
+ export declare function withKeyChanged(keys: readonly ClipKey[], index: number, patch: Partial<ClipKey>, duration: number): ClipKey[] | null;
59
64
  /** A track's keys without one; a track keeps at least its two ends, as the format asks. */
60
65
  export declare function withoutKey(keys: readonly ClipKey[], index: number): ClipKey[] | null;
66
+ /** A name no clip has, for a copy: `walk-copy`, then `walk-copy-2`, … */
67
+ export declare function freeClipNameOf(asset: FigureAsset, clip: string): string;
68
+ /** The controls a track of `clip` can be copied onto: those it plays already, and those it may take. */
69
+ export declare const copyTargetsOf: (asset: FigureAsset, clip: string) => string[];
70
+ /** Whether a track can be moved round its loop: one that wraps and does not add up (figure-model's rule). */
71
+ export declare const shiftable: (track: ClipTrack) => boolean;
72
+ /**
73
+ * A track copied onto `target` -- itself, or another control -- played `seconds` later round its loop (robot dog
74
+ * 2026-11-03: a leg's swing half a period after another's). One edit; a track the clip plays on `target` is replaced.
75
+ */
76
+ export declare function copiedTrackEdit(asset: FigureAsset, clip: Clip, track: ClipTrack, target: string, seconds: number): {
77
+ kind: "set-driver";
78
+ state: string;
79
+ clip: string;
80
+ keys: ClipKey[];
81
+ loop: "wrap" | "hold";
82
+ interpolation: "step" | "linear";
83
+ accumulates: boolean;
84
+ };
61
85
  /** The edit that writes a track back. */
62
86
  export declare const trackEdit: (clip: Clip, track: ClipTrack, patch?: Partial<Pick<ClipTrack, "keys" | "loop" | "interpolation">>) => {
63
87
  kind: "set-driver";
@@ -1,4 +1,4 @@
1
- import { driverValue } from '@hatiolab/figure-model';
1
+ import { driverValue, figureShiftedDriverKeys } from '@hatiolab/figure-model';
2
2
  const round = (n) => Math.round(n * 1000) / 1000;
3
3
  export function clipsOf(asset) {
4
4
  const inputs = new Map(asset.document.model.inputs.map(i => [i.id, i]));
@@ -68,12 +68,64 @@ export function poseAt(asset, clip, seconds) {
68
68
  export function withKey(keys, key) {
69
69
  return [...keys.filter(k => k.seconds !== key.seconds), key].sort((a, b) => a.seconds - b.seconds);
70
70
  }
71
+ /**
72
+ * A key typed where it stands: its moment, its value, or both. The first key stays at 0 (a track starts there); a moment
73
+ * outside the clip, or on another key's, is refused (null) rather than taking that key's place unseen.
74
+ */
75
+ export function withKeyChanged(keys, index, patch, duration) {
76
+ const was = keys[index];
77
+ if (!was)
78
+ return null;
79
+ const next = { seconds: patch.seconds ?? was.seconds, value: patch.value ?? was.value };
80
+ if (!Number.isFinite(next.seconds) || !Number.isFinite(next.value))
81
+ return null;
82
+ if (index === 0 && next.seconds !== 0)
83
+ return null;
84
+ if (next.seconds < 0 || next.seconds > duration)
85
+ return null;
86
+ if (keys.some((k, i) => i !== index && k.seconds === next.seconds))
87
+ return null;
88
+ return keys.map((k, i) => (i === index ? next : k)).sort((a, b) => a.seconds - b.seconds);
89
+ }
71
90
  /** A track's keys without one; a track keeps at least its two ends, as the format asks. */
72
91
  export function withoutKey(keys, index) {
73
92
  if (keys.length <= 2 || index === 0)
74
93
  return null;
75
94
  return keys.filter((_, i) => i !== index);
76
95
  }
96
+ /** A name no clip has, for a copy: `walk-copy`, then `walk-copy-2`, … */
97
+ export function freeClipNameOf(asset, clip) {
98
+ const taken = new Set((asset.drivers ?? []).map(d => d.clip));
99
+ const base = `${clip}-copy`;
100
+ if (!taken.has(base))
101
+ return base;
102
+ let n = 2;
103
+ while (taken.has(`${base}-${n}`))
104
+ n++;
105
+ return `${base}-${n}`;
106
+ }
107
+ /** The controls a track of `clip` can be copied onto: those it plays already, and those it may take. */
108
+ export const copyTargetsOf = (asset, clip) => [
109
+ ...new Set([...(asset.drivers ?? []).filter(d => d.clip === clip).map(d => d.state), ...undrivenOf(asset, clip)])
110
+ ];
111
+ /** Whether a track can be moved round its loop: one that wraps and does not add up (figure-model's rule). */
112
+ export const shiftable = (track) => track.loop === 'wrap' && !track.accumulates;
113
+ /**
114
+ * A track copied onto `target` -- itself, or another control -- played `seconds` later round its loop (robot dog
115
+ * 2026-11-03: a leg's swing half a period after another's). One edit; a track the clip plays on `target` is replaced.
116
+ */
117
+ export function copiedTrackEdit(asset, clip, track, target, seconds) {
118
+ const driver = (asset.drivers ?? []).find(d => d.clip === clip.name && d.state === track.state);
119
+ return {
120
+ kind: 'set-driver',
121
+ state: target,
122
+ clip: clip.name,
123
+ keys: seconds ? figureShiftedDriverKeys(driver, seconds) : track.keys,
124
+ loop: track.loop,
125
+ interpolation: track.interpolation,
126
+ accumulates: track.accumulates
127
+ };
128
+ }
77
129
  /** The edit that writes a track back. */
78
130
  export const trackEdit = (clip, track, patch = {}) => ({
79
131
  kind: 'set-driver',
@@ -1 +1 @@
1
- {"version":3,"file":"clips.js","sourceRoot":"","sources":["../../client/modeller/clips.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAA;AA4BpD,MAAM,KAAK,GAAG,CAAC,CAAS,EAAE,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,IAAI,CAAA;AAExD,MAAM,UAAU,OAAO,CAAC,KAAkB;IACxC,MAAM,MAAM,GAAG,IAAI,GAAG,CAAC,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAA;IACvE,MAAM,KAAK,GAAG,IAAI,GAAG,EAAgB,CAAA;IACrC,KAAK,MAAM,CAAC,IAAI,KAAK,CAAC,OAAO,IAAI,EAAE,EAAE,CAAC;QACpC,MAAM,KAAK,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,CAAA;QACjC,MAAM,IAAI,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,QAAQ,EAAE,CAAC,CAAC,IAAI,CAAC,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,CAAA;QACzF,IAAI,CAAC,M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AC,CAAA;AAC3C,CAAC;AAED,yCAAyC;AACzC,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,IAAU,EAAE,KAAgB,EAAE,QAAqE,EAAE,EAAE,EAAE,CAAC,CAAC;IACnI,IAAI,EAAE,YAAqB;IAC3B,KAAK,EAAE,KAAK,CAAC,KAAK;IAClB,IAAI,EAAE,IAAI,CAAC,IAAI;IACf,IAAI,EAAE,KAAK,CAAC,IAAI,IAAI,KAAK,CAAC,IAAI;IAC9B,IAAI,EAAE,KAAK,CAAC,IAAI,IAAI,KAAK,CAAC,IAAI;IAC9B,aAAa,EAAE,KAAK,CAAC,aAAa,IAAI,KAAK,CAAC,aAAa;CAC1D,CAAC,CAAA","sourcesContent":["import { driverValue } from '@hatiolab/figure-model'\nimport type { FigureAsset, FigureDriver, FigureInputChange } from '@hatiolab/figure-model'\n\n/*\n * The figure's clips: controls played by keys over time, grouped into clips that each run on one\n * clock. Kept apart from the element so the reading is tested without a browser.\n */\nexport interface ClipKey {\n seconds: number\n value: number\n}\nexport interface ClipTrack {\n state: string\n label: string\n unit: string\n min: number\n max: number\n keys: ClipKey[]\n interpolation: 'linear' | 'step'\n loop: 'wrap' | 'hold'\n accumulates: boolean\n}\nexport interface Clip {\n name: string\n duration: number\n tracks: ClipTrack[]\n}\n\nconst round = (n: number) => Math.round(n * 1000) / 1000\n\nexport function clipsOf(asset: FigureAsset): Clip[] {\n const inputs = new Map(asset.document.model.inputs.map(i => [i.id, i]))\n const clips = new Map<string, Clip>()\n for (const d of asset.drivers ?? []) {\n const input = inputs.get(d.state)\n const clip = clips.get(d.clip) ?? { name: d.clip, duration: d.time.duration, tracks: [] }\n clip.tracks.push({\n state: d.state,\n label: asset.stateInputs?.[d.state]?.label ?? d.state,\n unit: input?.unit ?? '',\n min: input?.min ?? 0,\n max: input?.max ?? 0,\n keys: d.keys.map(k => ({ seconds: round(k.at * d.time.duration), value: k.value })),\n interpolation: d.interpolation,\n loop: d.loop,\n accumulates: d.accumulates\n })\n clips.set(d.clip, clip)\n }\n return [...clips.values()]\n}\n\n/**\n * The controls a new track of `clip` can take (ADR-0051 §3.2): one the clip does not play yet, and that no clip plays\n * outside the clip's motion group -- `group` for a clip not made yet. A clip in no group takes only a control no clip\n * plays. Without a clip, the controls no clip plays at all.\n */\nexport function undrivenOf(asset: FigureAsset, clip = '', group?: string): string[] {\n const groupOf = new Map((asset.motionGroups ?? []).flatMap(g => g.clips.map(c => [c, g.id] as const)))\n const mine = group ?? (clip ? groupOf.get(clip) : undefined)\n const taken = (state: string) =>\n (asset.drivers ?? []).some(d => d.state === state && (d.clip === clip || mine === undefined || groupOf.get(d.clip) !== mine))\n return asset.document.model.inputs.filter(i => i.role === 'state' && !taken(i.id)).map(i => i.id)\n}\n\n/** A motion group as the panel shows it: its setting, and the clips it holds in the clips' order. */\nexport interface ClipGroup {\n id: string\n label: string\n clips: string[]\n defaultClip: string\n transitionSeconds: number\n}\n\n/** The figure's motion groups, and the clips in none -- the ones a group can take. */\nexport function clipGroupsOf(asset: FigureAsset): { groups: ClipGroup[]; free: string[] } {\n const groups = (asset.motionGroups ?? []).map(g => ({ ...g, clips: [...g.clips] }))\n const grouped = new Set(groups.flatMap(g => g.clips))\n const free = [...new Set((asset.drivers ?? []).map(d => d.clip))].filter(c => !grouped.has(c))\n return { groups, free }\n}\n\n/** A group id not yet taken: `motion`, then `motion-2`, `motion-3`, … An id is not made from a label a person types. */\nexport function freeGroupIdOf(asset: FigureAsset): string {\n const taken = new Set((asset.motionGroups ?? []).map(g => g.id))\n if (!taken.has('motion')) return 'motion'\n let n = 2\n while (taken.has(`motion-${n}`)) n++\n return `motion-${n}`\n}\n\n/** The edit that writes a group back with a change: one whole group, as the kernel takes it. */\nexport const groupEdit = (group: ClipGroup, patch: Partial<Omit<ClipGroup, 'id'>> = {}) => ({\n kind: 'set-motion-group' as const,\n group: { id: group.id, label: patch.label ?? group.label, clips: patch.clips ?? group.clips, defaultClip: patch.defaultClip ?? group.defaultClip, transitionSeconds: patch.transitionSeconds ?? group.transitionSeconds }\n})\n\n/** The pose a clip gives at a moment, as one batch of state changes -- one step of the history. */\nexport function poseAt(asset: FigureAsset, clip: string, seconds: number): FigureInputChange[] {\n const units = new Map(asset.document.model.inputs.map(i => [i.id, i.unit]))\n return (asset.drivers ?? [])\n .filter((d: FigureDriver) => d.clip === clip)\n .map(d => {\n const unit = units.get(d.state)!\n return { kind: 'set-state' as const, input: d.state, unit, value: driverValue(d, seconds, unit === 'deg' || unit === 'rad' ? unit : 'other') }\n })\n}\n\n/** A key added at a moment, replacing one already there; the keys stay in time order. */\nexport function withKey(keys: readonly ClipKey[], key: ClipKey): ClipKey[] {\n return [...keys.filter(k => k.seconds !== key.seconds), key].sort((a, b) => a.seconds - b.seconds)\n}\n\n/** A track's keys without one; a track keeps at least its two ends, as the format asks. */\nexport function withoutKey(keys: readonly ClipKey[], index: number): ClipKey[] | null {\n if (keys.length <= 2 || index === 0) return null\n return keys.filter((_, i) => i !== index)\n}\n\n/** The edit that writes a track back. */\nexport const trackEdit = (clip: Clip, track: ClipTrack, patch: Partial<Pick<ClipTrack, 'keys' | 'loop' | 'interpolation'>> = {}) => ({\n kind: 'set-driver' as const,\n state: track.state,\n clip: clip.name,\n keys: patch.keys ?? track.keys,\n loop: patch.loop ?? track.loop,\n interpolation: patch.interpolation ?? track.interpolation\n})\n"]}
1
+ {"version":3,"file":"clips.js","sourceRoot":"","sources":["../../client/modeller/clips.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,uBAAuB,EAAE,MAAM,wBAAwB,CAAA;AA4B7E,MAAM,KAAK,GAAG,CAAC,CAAS,EAAE,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,IAAI,CAAA;AAExD,MAAM,UAAU,OAAO,CAAC,KAAkB;IACxC,MAAM,MAAM,GAAG,IAAI,GAAG,CAAC,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,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I,KAAK,CAAC,IAAI;IAC9B,IAAI,EAAE,KAAK,CAAC,IAAI,IAAI,KAAK,CAAC,IAAI;IAC9B,aAAa,EAAE,KAAK,CAAC,aAAa,IAAI,KAAK,CAAC,aAAa;CAC1D,CAAC,CAAA","sourcesContent":["import { driverValue, figureShiftedDriverKeys } from '@hatiolab/figure-model'\nimport type { FigureAsset, FigureDriver, FigureInputChange } from '@hatiolab/figure-model'\n\n/*\n * The figure's clips: controls played by keys over time, grouped into clips that each run on one\n * clock. Kept apart from the element so the reading is tested without a browser.\n */\nexport interface ClipKey {\n seconds: number\n value: number\n}\nexport interface ClipTrack {\n state: string\n label: string\n unit: string\n min: number\n max: number\n keys: ClipKey[]\n interpolation: 'linear' | 'step'\n loop: 'wrap' | 'hold'\n accumulates: boolean\n}\nexport interface Clip {\n name: string\n duration: number\n tracks: ClipTrack[]\n}\n\nconst round = (n: number) => Math.round(n * 1000) / 1000\n\nexport function clipsOf(asset: FigureAsset): Clip[] {\n const inputs = new Map(asset.document.model.inputs.map(i => [i.id, i]))\n const clips = new Map<string, Clip>()\n for (const d of asset.drivers ?? []) {\n const input = inputs.get(d.state)\n const clip = clips.get(d.clip) ?? { name: d.clip, duration: d.time.duration, tracks: [] }\n clip.tracks.push({\n state: d.state,\n label: asset.stateInputs?.[d.state]?.label ?? d.state,\n unit: input?.unit ?? '',\n min: input?.min ?? 0,\n max: input?.max ?? 0,\n keys: d.keys.map(k => ({ seconds: round(k.at * d.time.duration), value: k.value })),\n interpolation: d.interpolation,\n loop: d.loop,\n accumulates: d.accumulates\n })\n clips.set(d.clip, clip)\n }\n return [...clips.values()]\n}\n\n/**\n * The controls a new track of `clip` can take (ADR-0051 §3.2): one the clip does not play yet, and that no clip plays\n * outside the clip's motion group -- `group` for a clip not made yet. A clip in no group takes only a control no clip\n * plays. Without a clip, the controls no clip plays at all.\n */\nexport function undrivenOf(asset: FigureAsset, clip = '', group?: string): string[] {\n const groupOf = new Map((asset.motionGroups ?? []).flatMap(g => g.clips.map(c => [c, g.id] as const)))\n const mine = group ?? (clip ? groupOf.get(clip) : undefined)\n const taken = (state: string) =>\n (asset.drivers ?? []).some(d => d.state === state && (d.clip === clip || mine === undefined || groupOf.get(d.clip) !== mine))\n return asset.document.model.inputs.filter(i => i.role === 'state' && !taken(i.id)).map(i => i.id)\n}\n\n/** A motion group as the panel shows it: its setting, and the clips it holds in the clips' order. */\nexport interface ClipGroup {\n id: string\n label: string\n clips: string[]\n defaultClip: string\n transitionSeconds: number\n}\n\n/** The figure's motion groups, and the clips in none -- the ones a group can take. */\nexport function clipGroupsOf(asset: FigureAsset): { groups: ClipGroup[]; free: string[] } {\n const groups = (asset.motionGroups ?? []).map(g => ({ ...g, clips: [...g.clips] }))\n const grouped = new Set(groups.flatMap(g => g.clips))\n const free = [...new Set((asset.drivers ?? []).map(d => d.clip))].filter(c => !grouped.has(c))\n return { groups, free }\n}\n\n/** A group id not yet taken: `motion`, then `motion-2`, `motion-3`, … An id is not made from a label a person types. */\nexport function freeGroupIdOf(asset: FigureAsset): string {\n const taken = new Set((asset.motionGroups ?? []).map(g => g.id))\n if (!taken.has('motion')) return 'motion'\n let n = 2\n while (taken.has(`motion-${n}`)) n++\n return `motion-${n}`\n}\n\n/** The edit that writes a group back with a change: one whole group, as the kernel takes it. */\nexport const groupEdit = (group: ClipGroup, patch: Partial<Omit<ClipGroup, 'id'>> = {}) => ({\n kind: 'set-motion-group' as const,\n group: { id: group.id, label: patch.label ?? group.label, clips: patch.clips ?? group.clips, defaultClip: patch.defaultClip ?? group.defaultClip, transitionSeconds: patch.transitionSeconds ?? group.transitionSeconds }\n})\n\n/** The pose a clip gives at a moment, as one batch of state changes -- one step of the history. */\nexport function poseAt(asset: FigureAsset, clip: string, seconds: number): FigureInputChange[] {\n const units = new Map(asset.document.model.inputs.map(i => [i.id, i.unit]))\n return (asset.drivers ?? [])\n .filter((d: FigureDriver) => d.clip === clip)\n .map(d => {\n const unit = units.get(d.state)!\n return { kind: 'set-state' as const, input: d.state, unit, value: driverValue(d, seconds, unit === 'deg' || unit === 'rad' ? unit : 'other') }\n })\n}\n\n/** A key added at a moment, replacing one already there; the keys stay in time order. */\nexport function withKey(keys: readonly ClipKey[], key: ClipKey): ClipKey[] {\n return [...keys.filter(k => k.seconds !== key.seconds), key].sort((a, b) => a.seconds - b.seconds)\n}\n\n/**\n * A key typed where it stands: its moment, its value, or both. The first key stays at 0 (a track starts there); a moment\n * outside the clip, or on another key's, is refused (null) rather than taking that key's place unseen.\n */\nexport function withKeyChanged(keys: readonly ClipKey[], index: number, patch: Partial<ClipKey>, duration: number): ClipKey[] | null {\n const was = keys[index]\n if (!was) return null\n const next = { seconds: patch.seconds ?? was.seconds, value: patch.value ?? was.value }\n if (!Number.isFinite(next.seconds) || !Number.isFinite(next.value)) return null\n if (index === 0 && next.seconds !== 0) return null\n if (next.seconds < 0 || next.seconds > duration) return null\n if (keys.some((k, i) => i !== index && k.seconds === next.seconds)) return null\n return keys.map((k, i) => (i === index ? next : k)).sort((a, b) => a.seconds - b.seconds)\n}\n\n/** A track's keys without one; a track keeps at least its two ends, as the format asks. */\nexport function withoutKey(keys: readonly ClipKey[], index: number): ClipKey[] | null {\n if (keys.length <= 2 || index === 0) return null\n return keys.filter((_, i) => i !== index)\n}\n\n/** A name no clip has, for a copy: `walk-copy`, then `walk-copy-2`, … */\nexport function freeClipNameOf(asset: FigureAsset, clip: string): string {\n const taken = new Set((asset.drivers ?? []).map(d => d.clip))\n const base = `${clip}-copy`\n if (!taken.has(base)) return base\n let n = 2\n while (taken.has(`${base}-${n}`)) n++\n return `${base}-${n}`\n}\n\n/** The controls a track of `clip` can be copied onto: those it plays already, and those it may take. */\nexport const copyTargetsOf = (asset: FigureAsset, clip: string): string[] => [\n ...new Set([...(asset.drivers ?? []).filter(d => d.clip === clip).map(d => d.state), ...undrivenOf(asset, clip)])\n]\n\n/** Whether a track can be moved round its loop: one that wraps and does not add up (figure-model's rule). */\nexport const shiftable = (track: ClipTrack) => track.loop === 'wrap' && !track.accumulates\n\n/**\n * A track copied onto `target` -- itself, or another control -- played `seconds` later round its loop (robot dog\n * 2026-11-03: a leg's swing half a period after another's). One edit; a track the clip plays on `target` is replaced.\n */\nexport function copiedTrackEdit(asset: FigureAsset, clip: Clip, track: ClipTrack, target: string, seconds: number) {\n const driver = (asset.drivers ?? []).find(d => d.clip === clip.name && d.state === track.state)!\n return {\n kind: 'set-driver' as const,\n state: target,\n clip: clip.name,\n keys: seconds ? figureShiftedDriverKeys(driver, seconds) : track.keys,\n loop: track.loop,\n interpolation: track.interpolation,\n accumulates: track.accumulates\n }\n}\n\n/** The edit that writes a track back. */\nexport const trackEdit = (clip: Clip, track: ClipTrack, patch: Partial<Pick<ClipTrack, 'keys' | 'loop' | 'interpolation'>> = {}) => ({\n kind: 'set-driver' as const,\n state: track.state,\n clip: clip.name,\n keys: patch.keys ?? track.keys,\n loop: patch.loop ?? track.loop,\n interpolation: patch.interpolation ?? track.interpolation\n})\n"]}
@@ -124,6 +124,12 @@ export declare function sampleOf(asset: FigureAsset, sample: unknown, legends?:
124
124
  };
125
125
  /** The rows a person gives a value by hand, as a board's saved values: one value, read by a binding, not inside a list. */
126
126
  export declare const valueRowsOf: (asset: FigureAsset) => FigureDataRow[];
127
+ /**
128
+ * What the data gives a row, read the way a placed figure reads its data: when it is there, it is what the figure shows,
129
+ * and a value saved by hand for the row is not read (things-scene's FigureDataReader: live data first). Undefined when
130
+ * the data leaves the row out, or gives it null.
131
+ */
132
+ export declare function dataValueAt(data: unknown, path: string): unknown;
127
133
  /** A value typed or chosen for a row, as its kind reads it: a number (NaN when empty), true or false, or the text. */
128
134
  export declare function typedValueOf(node: FigureDataNode, typed: string): FigureDataValue;
129
135
  /** The parts a table may show on: the parts the figure's appearance names. */
@@ -340,6 +340,23 @@ export function sampleOf(asset, sample, legends = {}) {
340
340
  }
341
341
  /** The rows a person gives a value by hand, as a board's saved values: one value, read by a binding, not inside a list. */
342
342
  export const valueRowsOf = (asset) => schemaRowsOf(asset).filter(r => isValue(r.node) && r.bindings.length > 0 && !r.path.includes('[]'));
343
+ /**
344
+ * What the data gives a row, read the way a placed figure reads its data: when it is there, it is what the figure shows,
345
+ * and a value saved by hand for the row is not read (things-scene's FigureDataReader: live data first). Undefined when
346
+ * the data leaves the row out, or gives it null.
347
+ */
348
+ export function dataValueAt(data, path) {
349
+ const steps = parseFigureAccessor(path);
350
+ if (!steps)
351
+ return undefined;
352
+ let at = data;
353
+ for (const step of steps) {
354
+ if (at === null || typeof at !== 'object')
355
+ return undefined;
356
+ at = 'field' in step ? at[step.field] : at[step.index];
357
+ }
358
+ return at === null ? undefined : at;
359
+ }
343
360
  /** A value typed or chosen for a row, as its kind reads it: a number (NaN when empty), true or false, or the text. */
344
361
  export function typedValueOf(node, typed) {
345
362
  if (node.kind === 'number')