@things-factory/figure-ui 10.1.263 → 10.1.266

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 (54) hide show
  1. package/client/graphql/index.ts +14 -5
  2. package/client/graphql/store.ts +1 -1
  3. package/client/modeller/align.ts +13 -1
  4. package/client/modeller/clips.ts +90 -1
  5. package/client/modeller/editor-styles.ts +36 -0
  6. package/client/modeller/editor.ts +53 -6
  7. package/client/modeller/figure-clips.ts +82 -34
  8. package/client/modeller/joint-drag.ts +32 -2
  9. package/client/modeller/product-session.ts +53 -5
  10. package/client/modeller/refusals.ts +23 -0
  11. package/dist-client/graphql/index.d.ts +7 -1
  12. package/dist-client/graphql/index.js +7 -5
  13. package/dist-client/graphql/index.js.map +1 -1
  14. package/dist-client/graphql/store.js +1 -1
  15. package/dist-client/graphql/store.js.map +1 -1
  16. package/dist-client/modeller/align.d.ts +5 -0
  17. package/dist-client/modeller/align.js +10 -1
  18. package/dist-client/modeller/align.js.map +1 -1
  19. package/dist-client/modeller/clips.d.ts +58 -6
  20. package/dist-client/modeller/clips.js +89 -0
  21. package/dist-client/modeller/clips.js.map +1 -1
  22. package/dist-client/modeller/editor-styles.js +36 -0
  23. package/dist-client/modeller/editor-styles.js.map +1 -1
  24. package/dist-client/modeller/editor.d.ts +7 -0
  25. package/dist-client/modeller/editor.js +58 -5
  26. package/dist-client/modeller/editor.js.map +1 -1
  27. package/dist-client/modeller/figure-clips.d.ts +13 -1
  28. package/dist-client/modeller/figure-clips.js +87 -34
  29. package/dist-client/modeller/figure-clips.js.map +1 -1
  30. package/dist-client/modeller/joint-drag.d.ts +21 -2
  31. package/dist-client/modeller/joint-drag.js +20 -1
  32. package/dist-client/modeller/joint-drag.js.map +1 -1
  33. package/dist-client/modeller/links.d.ts +1 -1
  34. package/dist-client/modeller/product-session.d.ts +14 -2
  35. package/dist-client/modeller/product-session.js +43 -3
  36. package/dist-client/modeller/product-session.js.map +1 -1
  37. package/dist-client/modeller/refusals.d.ts +5 -0
  38. package/dist-client/modeller/refusals.js +22 -1
  39. package/dist-client/modeller/refusals.js.map +1 -1
  40. package/dist-client/route.d.ts +1 -1
  41. package/dist-client/tsconfig.tsbuildinfo +1 -1
  42. package/package.json +8 -8
  43. package/test/align.test.ts +18 -0
  44. package/test/clips.test.ts +83 -0
  45. package/test/data-motion.test.ts +13 -4
  46. package/test/joint-drag.test.ts +49 -0
  47. package/test/joint-frames.test.ts +3 -2
  48. package/test/product-session.test.ts +98 -0
  49. package/translations/en.json +24 -2
  50. package/translations/es.json +24 -2
  51. package/translations/ja.json +24 -2
  52. package/translations/ko.json +24 -2
  53. package/translations/ms.json +24 -2
  54. package/translations/zh.json +24 -2
@@ -1 +1 @@
1
- {"version":3,"file":"joint-drag.js","sourceRoot":"","sources":["../../client/modeller/joint-drag.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAC9B,OAAO,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,eAAe,EAAE,eAAe,EAA0B,MAAM,wBAAwB,CAAA;AAIzI,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAsB9D,MAAM,IAAI,GAAW,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAA;AACpC,wFAAwF;AACxF,MAAM,SAAS,GAAyB,EAAE,IAAI,EAAE,GAAG,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG,EAAE,KAAK,EAAE,GAAG,EAAE,CAAA;AAC/G,MAAM,SAAS,GAA2B,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,CAAA;AAExG,MAAM,QAAQ,G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AO,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,EAAE,gBAAgB,EAAE,KAAK,EAAE,CAAC,CAAC,EAAE,EAAE,CAAA;QACnF,MAAM,CAAC,KAAK,GAAG,EAAE,GAAG,CAAC,MAAM,CAAC,KAAK,IAAI,EAAE,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,EAAE,EAAE,EAAE,KAAK,CAAC,GAAG,GAAG,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAA;IAC/E,CAAC;IACD,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,EAAE,GAAG,CAAC,EAAE,MAAM,EAAE,EAAE,CAAA;AACnD,CAAC","sourcesContent":["import * as THREE from 'three'\nimport { compileFigureAsset, figureMimicTermsOf, figureMotionsOf, motionStateIdOf, type FigureNamedMotion } from '@hatiolab/figure-model'\nimport type { FigureAsset, FigureJoint } from '@hatiolab/figure-model'\n\nimport type { GizmoResult } from './gizmo.js'\nimport { jointAxisUnit, jointAxisWord } from './joint-axis.js'\nimport type { FigureRenderPart } from './renderer.js'\n\n/*\n * A gizmo drag on a part that hangs from a joint edits the joint, not the part (ADR-0093; r3 §3: the modeller changes\n * the inputs of the relation, and never breaks it because a computed place was moved):\n *\n * - turning a part on a revolute or continuous joint sets the joint's value -- the turn about the joint's axis;\n * - sliding a part on a prismatic joint along its axis sets its value;\n * - moving a part any other way moves the joint's origin: the gap along the face it sits on, the offset across it;\n * at a parent's origin (ADR-0107 decision 4), its `origin.offset` in the parent's frame.\n *\n * What would break a relation is refused and said: an origin that follows another part's size, a joint that mimics\n * another, a turn on a joint that does not turn.\n */\n\nexport type JointDrag =\n | { kind: 'value'; input: string; unit: 'deg' | 'mm' | 'ratio'; value: number }\n | { kind: 'joint'; joint: FigureJoint }\n | { kind: 'refused'; reason: 'mimic' | 'fixed-turn' | 'origin-follows' | 'turned-slide' | 'off-axis' | 'several-axes'; joint: string; leader?: string; axis?: string }\n\ntype Axis = 'x' | 'y' | 'z'\nconst AXES: Axis[] = ['x', 'y', 'z']\n/** The axis each face faces along, and which way (as figure-model's `FIGURE_FACES`). */\nconst FACE_AXIS: Record<string, Axis> = { left: 'x', right: 'x', bottom: 'y', top: 'y', back: 'z', front: 'z' }\nconst FACE_SIGN: Record<string, number> = { left: -1, right: 1, bottom: -1, top: 1, back: -1, front: 1 }\n\nconst matrixOf = (r: number[][]) => new THREE.Matrix4().set(r[0]![0]!, r[0]![1]!, r[0]![2]!, 0, r[1]![0]!, r[1]![1]!, r[1]![2]!, 0, r[2]![0]!, r[2]![1]!, r[2]![2]!, 0, 0, 0, 0, 1)\nconst eulerMatrix = (deg: number[]) => new THREE.Matrix4().makeRotationFromEuler(new THREE.Euler(...(deg.map(THREE.MathUtils.degToRad) as [number, number, number]), 'XYZ'))\nconst unit = (axis: unknown) => new THREE.Vector3(...(jointAxisUnit(axis) ?? [0, 0, 0]))\nconst round = (v: number, step: number) => Number((Math.round(v / step) * step).toFixed(Math.max(0, -Math.floor(Math.log10(step)))))\n\n/** `origin.parentRotate` (ADR-0107, named for its end by ADR-0140 3.6), URDF's rpy: Rz·Ry·Rx about the fixed axes. */\nconst rotateMatrix = (j: FigureJoint) => eulerMatrixOrder(AXES.map(a => j.origin?.parentRotate?.[a] ?? 0), 'ZYX')\nconst eulerMatrixOrder = (deg: number[], order: THREE.EulerOrder) => new THREE.Matrix4().makeRotationFromEuler(new THREE.Euler(...(deg.map(THREE.MathUtils.degToRad) as [number, number, number]), order))\n\n/** The part's own pose on its end, any angle, as the record says it (`origin.childRotate`, Rz·Ry·Rx, ADR-0140 3.11). */\nconst turnMatrix = (j: FigureJoint) => eulerMatrixOrder(AXES.map(a => j.origin?.childRotate?.[a] ?? 0), 'ZYX')\n\n/** The joint frame's rotation in the figure: the part's rotation now, less its own turn and less its one axis's. */\nfunction jointFrameRotation(j: FigureJoint, a: FigureNamedMotion | undefined, part: FigureRenderPart, angle: number): THREE.Matrix4 {\n const now = matrixOf(part.pose.r as number[][])\n const own = turnMatrix(j)\n const turn = a?.type === 'revolute' ? new THREE.Matrix4().makeRotationAxis(unit(a.axis), THREE.MathUtils.degToRad(angle)) : new THREE.Matrix4()\n return now.multiply(own.invert()).multiply(turn.invert())\n}\n\nexport function jointDragOf(asset: FigureAsset, id: string, part: FigureRenderPart, result: GizmoResult, values: Record<string, number>): JointDrag | null {\n const j = asset.joints?.find(joint => joint.body1.part === id)\n /* A size is the part's own, not the joint's: a scale drag goes to the part's measures (the editor drops the shift). */\n if (!j || result.scale || (!result.rotation && !result.position)) return null\n /* A drag moves one axis, or the joint's place: a joint of several axes (ADR-0159) is moved by its controls. */\n const axes = figureMotionsOf(j)\n if (axes.length > 1) return { kind: 'refused', reason: 'several-axes', joint: j.id }\n const a = axes[0]\n const stateId = a ? motionStateIdOf(a) : j.id\n const now = values[stateId] ?? asset.stateDefaults[stateId] ?? 0\n const turns = a?.type === 'revolute'\n /* A revolute axis without limits turns without end (USD). */\n const endless = turns && a.lowerLimit === undefined && a.upperLimit === undefined\n\n if (result.rotation) {\n if (!turns) return { kind: 'refused', reason: a?.type === 'prismatic' ? 'turned-slide' : 'fixed-turn', joint: j.id }\n if (a.mimic) return { kind: 'refused', reason: 'mimic', joint: j.id, leader: figureMimicTermsOf(a.mimic)!.sum.map(t => t.joint).join(', ') }\n /* The turn about the joint's axis (the twist of the change): the only turn the joint can make. */\n const before = new THREE.Quaternion().setFromRotationMatrix(matrixOf(part.pose.r as number[][]))\n const after = new THREE.Quaternion().setFromRotationMatrix(eulerMatrix(result.rotation))\n const change = after.multiply(before.invert())\n const axis = unit(a.axis).applyMatrix4(jointFrameRotation(j, a, part, now)).normalize()\n const twist = 2 * Math.atan2(change.x * axis.x + change.y * axis.y + change.z * axis.z, change.w)\n /* Turned about another axis: the joint cannot make that turn, and nothing is written for it. */\n const whole = 2 * Math.acos(Math.min(1, Math.abs(change.w)))\n if (Math.abs(twist) < whole * 0.5) return { kind: 'refused', reason: 'off-axis', joint: j.id, axis: jointAxisWord(a.axis) }\n let value = now + THREE.MathUtils.radToDeg(twist)\n if (endless) value = ((((value + 180) % 360) + 360) % 360) - 180\n else value = Math.min(Math.max(value, a.lowerLimit!), a.upperLimit!)\n return { kind: 'value', input: stateId, unit: 'deg', value: round(value, 0.1) }\n }\n\n const moved = new THREE.Vector3(...result.position!).sub(new THREE.Vector3(...(part.pose.t as [number, number, number])))\n if (moved.length() < 0.5) return null\n const frame = jointFrameRotation(j, a, part, turns ? now : 0)\n\n if (a?.type === 'prismatic') {\n if (a.mimic) return { kind: 'refused', reason: 'mimic', joint: j.id, leader: figureMimicTermsOf(a.mimic)!.sum.map(t => t.joint).join(', ') }\n /* How far one unit of the value moves the part along its axis, measured on the figure itself (a ratio travels a length). */\n const along = unit(a.axis).applyMatrix4(frame).normalize()\n const at = (v: number) => {\n const g = compileFigureAsset(asset).evaluate({ ...values, [stateId]: v }).geometry.find(g => g.id === id && 'pose' in g) as { pose: { t: number[] } } | undefined\n return g ? new THREE.Vector3(...(g.pose.t as [number, number, number])).dot(along) : 0\n }\n const step = a.travel ? 0.01 : 1\n const rate = (at(now + step) - at(now)) / step\n if (Math.abs(rate) > 1e-9 && Math.abs(moved.dot(along)) >= moved.length() * 0.7) {\n const value = Math.min(Math.max(now + moved.dot(along) / rate, a.lowerLimit!), a.upperLimit!)\n return { kind: 'value', input: stateId, unit: a.travel ? 'ratio' : 'mm', value: round(value, a.travel ? 0.001 : 1) }\n }\n }\n\n /* Moving the joint's origin: the change in the frame it is placed in, before `origin.parentRotate` turns the joint frame. */\n const local = moved.clone().applyMatrix4(frame.clone().multiply(rotateMatrix(j).invert()).invert())\n const origin: NonNullable<FigureJoint['origin']> = { ...(j.origin ?? {}) }\n if (!('plane' in j.body0) && !('face' in j.body0)) {\n /* At the parent's origin there is no face: the frame moves by its offset, along the parent's axes. */\n const offset = { ...(j.origin?.offset ?? {}) }\n for (const axis of AXES) {\n const d = local[axis]\n if (Math.abs(d) < 0.5) continue\n const was = offset[axis] ?? 0\n if (typeof was !== 'number') return { kind: 'refused', reason: 'origin-follows', joint: j.id }\n offset[axis] = round(was + d, 1)\n }\n return { kind: 'joint', joint: { ...j, origin: { ...origin, offset } } as FigureJoint }\n }\n const normal: Axis = 'plane' in j.body0 ? (asset.placement === 'wall' ? 'z' : 'y') : FACE_AXIS[j.body0.face]!\n /* Which way a larger gap moves the part: out of the face it meets or sits by its middle on, into it when flush with it (ADR-0140 3.11). */\n const outward = ((j.origin?.facing ?? 'meet') === 'flush' ? -1 : 1) * ('plane' in j.body0 ? 1 : FACE_SIGN[j.body0.face]!)\n const along = local[normal]\n if (Math.abs(along) >= 0.5) {\n const gap = origin.gap ?? 0\n if (typeof gap !== 'number') return { kind: 'refused', reason: 'origin-follows', joint: j.id }\n origin.gap = round(gap + outward * along, 1)\n }\n for (const axis of AXES.filter(a => a !== normal)) {\n const d = local[axis]\n if (Math.abs(d) < 0.5) continue\n const how = origin.align?.[axis] ?? 'centre'\n const was = how === 'centre' ? 0 : typeof how === 'object' && typeof how.mm === 'number' ? how.mm : null\n if (was === null) return { kind: 'refused', reason: 'origin-follows', joint: j.id }\n origin.align = { ...(origin.align ?? {}), [axis]: { mm: round(was + d, 1) } }\n }\n return { kind: 'joint', joint: { ...j, origin } }\n}\n"]}
1
+ {"version":3,"file":"joint-drag.js","sourceRoot":"","sources":["../../client/modeller/joint-drag.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAC9B,OAAO,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,eAAe,EAAE,eAAe,EAA0B,MAAM,wBAAwB,CAAA;AAIzI,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AA0B9D,MAAM,IAAI,GAAW,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAA;AACpC,wFAAwF;AACxF,MAAM,SAAS,GAAyB,EAAE,IAAI,EAAE,GAAG,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,EAAE,G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CAAC,IAAI,CAAC,MAAM;QAAE,OAAO,IAAI,CAAA;IAC7B,IAAI,IAAI,CAAC,MAAM,GAAG,CAAC;QAAE,OAAO,EAAE,IAAI,EAAE,cAAc,EAAE,KAAK,EAAE,CAAC,CAAC,EAAE,EAAE,CAAA;IACjE,MAAM,CAAC,GAAG,IAAI,CAAC,CAAC,CAAE,CAAA;IAClB,IAAI,CAAC,CAAC,KAAK,EAAE,CAAC;QACZ,MAAM,MAAM,GAAG,kBAAkB,CAAC,CAAC,CAAC,KAAK,CAAE,CAAC,GAAG,CAAC,CAAC,CAAE,CAAC,KAAK,CAAA;QACzD,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC,CAAC,EAAE,EAAE,MAAM,EAAE,UAAU,EAAE,KAAK,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,MAAM,CAAC,EAAE,KAAK,CAAC,IAAI,EAAE,CAAA;IACjH,CAAC;IACD,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,KAAK,UAAU,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,EAAE,KAAK,EAAE,CAAC,CAAC,EAAE,EAAE,CAAA;AACxE,CAAC","sourcesContent":["import * as THREE from 'three'\nimport { compileFigureAsset, figureMimicTermsOf, figureMotionsOf, motionStateIdOf, type FigureNamedMotion } from '@hatiolab/figure-model'\nimport type { FigureAsset, FigureJoint } from '@hatiolab/figure-model'\n\nimport type { GizmoResult } from './gizmo.js'\nimport { jointAxisUnit, jointAxisWord } from './joint-axis.js'\nimport type { FigureRenderPart } from './renderer.js'\n\n/*\n * A gizmo drag on a part that hangs from a joint edits the joint, not the part (ADR-0093; r3 §3: the modeller changes\n * the inputs of the relation, and never breaks it because a computed place was moved):\n *\n * - turning a part on a revolute or continuous joint sets the joint's value -- the turn about the joint's axis;\n * - sliding a part on a prismatic joint along its axis sets its value;\n * - moving a part any other way moves the joint's origin: the gap along the face it sits on, the offset across it;\n * at a parent's origin (ADR-0107 decision 4), its `origin.offset` in the parent's frame.\n *\n * What would break a relation is refused and said: an origin that follows another part's size, a joint that mimics\n * another, a turn on a joint that does not turn.\n *\n * **Posing and placing are two things** (review 2026-11-09): on a joint that moves, a drag changes the pose -- its value.\n * Where the joint sits is moved only while 「관절 위치 편집」 is on (`place`); off, such a drag is refused with the way to\n * turn it on, so a pose being made never moves the joint unseen. A fixed joint has no pose: a drag on it places it.\n */\n\nexport type JointDrag =\n | { kind: 'value'; input: string; unit: 'deg' | 'mm' | 'ratio'; value: number }\n | { kind: 'joint'; joint: FigureJoint }\n | { kind: 'refused'; reason: 'mimic' | 'fixed-turn' | 'origin-follows' | 'turned-slide' | 'off-axis' | 'several-axes' | 'place-off'; joint: string; leader?: string; axis?: string }\n\ntype Axis = 'x' | 'y' | 'z'\nconst AXES: Axis[] = ['x', 'y', 'z']\n/** The axis each face faces along, and which way (as figure-model's `FIGURE_FACES`). */\nconst FACE_AXIS: Record<string, Axis> = { left: 'x', right: 'x', bottom: 'y', top: 'y', back: 'z', front: 'z' }\nconst FACE_SIGN: Record<string, number> = { left: -1, right: 1, bottom: -1, top: 1, back: -1, front: 1 }\n\nconst matrixOf = (r: number[][]) => new THREE.Matrix4().set(r[0]![0]!, r[0]![1]!, r[0]![2]!, 0, r[1]![0]!, r[1]![1]!, r[1]![2]!, 0, r[2]![0]!, r[2]![1]!, r[2]![2]!, 0, 0, 0, 0, 1)\nconst eulerMatrix = (deg: number[]) => new THREE.Matrix4().makeRotationFromEuler(new THREE.Euler(...(deg.map(THREE.MathUtils.degToRad) as [number, number, number]), 'XYZ'))\nconst unit = (axis: unknown) => new THREE.Vector3(...(jointAxisUnit(axis) ?? [0, 0, 0]))\nconst round = (v: number, step: number) => Number((Math.round(v / step) * step).toFixed(Math.max(0, -Math.floor(Math.log10(step)))))\n\n/** `origin.parentRotate` (ADR-0107, named for its end by ADR-0140 3.6), URDF's rpy: Rz·Ry·Rx about the fixed axes. */\nconst rotateMatrix = (j: FigureJoint) => eulerMatrixOrder(AXES.map(a => j.origin?.parentRotate?.[a] ?? 0), 'ZYX')\nconst eulerMatrixOrder = (deg: number[], order: THREE.EulerOrder) => new THREE.Matrix4().makeRotationFromEuler(new THREE.Euler(...(deg.map(THREE.MathUtils.degToRad) as [number, number, number]), order))\n\n/** The part's own pose on its end, any angle, as the record says it (`origin.childRotate`, Rz·Ry·Rx, ADR-0140 3.11). */\nconst turnMatrix = (j: FigureJoint) => eulerMatrixOrder(AXES.map(a => j.origin?.childRotate?.[a] ?? 0), 'ZYX')\n\n/** The joint frame's rotation in the figure: the part's rotation now, less its own turn and less its one axis's. */\nfunction jointFrameRotation(j: FigureJoint, a: FigureNamedMotion | undefined, part: FigureRenderPart, angle: number): THREE.Matrix4 {\n const now = matrixOf(part.pose.r as number[][])\n const own = turnMatrix(j)\n const turn = a?.type === 'revolute' ? new THREE.Matrix4().makeRotationAxis(unit(a.axis), THREE.MathUtils.degToRad(angle)) : new THREE.Matrix4()\n return now.multiply(own.invert()).multiply(turn.invert())\n}\n\nexport function jointDragOf(asset: FigureAsset, id: string, part: FigureRenderPart, result: GizmoResult, values: Record<string, number>, options: { place?: boolean } = {}): JointDrag | null {\n const j = asset.joints?.find(joint => joint.body1.part === id)\n /* A size is the part's own, not the joint's: a scale drag goes to the part's measures (the editor drops the shift). */\n if (!j || result.scale || (!result.rotation && !result.position)) return null\n /* A drag moves one axis, or the joint's place: a joint of several axes (ADR-0159) is moved by its controls. */\n const axes = figureMotionsOf(j)\n if (axes.length > 1) return { kind: 'refused', reason: 'several-axes', joint: j.id }\n const a = axes[0]\n const stateId = a ? motionStateIdOf(a) : j.id\n const now = values[stateId] ?? asset.stateDefaults[stateId] ?? 0\n const turns = a?.type === 'revolute'\n /* A revolute axis without limits turns without end (USD). */\n const endless = turns && a.lowerLimit === undefined && a.upperLimit === undefined\n\n if (result.rotation) {\n if (!turns) return { kind: 'refused', reason: a?.type === 'prismatic' ? 'turned-slide' : 'fixed-turn', joint: j.id }\n if (a.mimic) return { kind: 'refused', reason: 'mimic', joint: j.id, leader: figureMimicTermsOf(a.mimic)!.sum.map(t => t.joint).join(', ') }\n /* The turn about the joint's axis (the twist of the change): the only turn the joint can make. */\n const before = new THREE.Quaternion().setFromRotationMatrix(matrixOf(part.pose.r as number[][]))\n const after = new THREE.Quaternion().setFromRotationMatrix(eulerMatrix(result.rotation))\n const change = after.multiply(before.invert())\n const axis = unit(a.axis).applyMatrix4(jointFrameRotation(j, a, part, now)).normalize()\n const twist = 2 * Math.atan2(change.x * axis.x + change.y * axis.y + change.z * axis.z, change.w)\n /* Turned about another axis: the joint cannot make that turn, and nothing is written for it. */\n const whole = 2 * Math.acos(Math.min(1, Math.abs(change.w)))\n if (Math.abs(twist) < whole * 0.5) return { kind: 'refused', reason: 'off-axis', joint: j.id, axis: jointAxisWord(a.axis) }\n let value = now + THREE.MathUtils.radToDeg(twist)\n if (endless) value = ((((value + 180) % 360) + 360) % 360) - 180\n else value = Math.min(Math.max(value, a.lowerLimit!), a.upperLimit!)\n return { kind: 'value', input: stateId, unit: 'deg', value: round(value, 0.1) }\n }\n\n const moved = new THREE.Vector3(...result.position!).sub(new THREE.Vector3(...(part.pose.t as [number, number, number])))\n if (moved.length() < 0.5) return null\n const frame = jointFrameRotation(j, a, part, turns ? now : 0)\n\n if (a?.type === 'prismatic') {\n if (a.mimic) return { kind: 'refused', reason: 'mimic', joint: j.id, leader: figureMimicTermsOf(a.mimic)!.sum.map(t => t.joint).join(', ') }\n /* How far one unit of the value moves the part along its axis, measured on the figure itself (a ratio travels a length). */\n const along = unit(a.axis).applyMatrix4(frame).normalize()\n const at = (v: number) => {\n const g = compileFigureAsset(asset).evaluate({ ...values, [stateId]: v }).geometry.find(g => g.id === id && 'pose' in g) as { pose: { t: number[] } } | undefined\n return g ? new THREE.Vector3(...(g.pose.t as [number, number, number])).dot(along) : 0\n }\n const step = a.travel ? 0.01 : 1\n const rate = (at(now + step) - at(now)) / step\n if (Math.abs(rate) > 1e-9 && Math.abs(moved.dot(along)) >= moved.length() * 0.7) {\n const value = Math.min(Math.max(now + moved.dot(along) / rate, a.lowerLimit!), a.upperLimit!)\n return { kind: 'value', input: stateId, unit: a.travel ? 'ratio' : 'mm', value: round(value, a.travel ? 0.001 : 1) }\n }\n }\n\n /* A joint that moves is posed by a drag; its place is moved only while placing is on. */\n if (a && !options.place) return { kind: 'refused', reason: 'place-off', joint: j.id }\n\n /* Moving the joint's origin: the change in the frame it is placed in, before `origin.parentRotate` turns the joint frame. */\n const local = moved.clone().applyMatrix4(frame.clone().multiply(rotateMatrix(j).invert()).invert())\n const origin: NonNullable<FigureJoint['origin']> = { ...(j.origin ?? {}) }\n if (!('plane' in j.body0) && !('face' in j.body0)) {\n /* At the parent's origin there is no face: the frame moves by its offset, along the parent's axes. */\n const offset = { ...(j.origin?.offset ?? {}) }\n for (const axis of AXES) {\n const d = local[axis]\n if (Math.abs(d) < 0.5) continue\n const was = offset[axis] ?? 0\n if (typeof was !== 'number') return { kind: 'refused', reason: 'origin-follows', joint: j.id }\n offset[axis] = round(was + d, 1)\n }\n return { kind: 'joint', joint: { ...j, origin: { ...origin, offset } } as FigureJoint }\n }\n const normal: Axis = 'plane' in j.body0 ? (asset.placement === 'wall' ? 'z' : 'y') : FACE_AXIS[j.body0.face]!\n /* Which way a larger gap moves the part: out of the face it meets or sits by its middle on, into it when flush with it (ADR-0140 3.11). */\n const outward = ((j.origin?.facing ?? 'meet') === 'flush' ? -1 : 1) * ('plane' in j.body0 ? 1 : FACE_SIGN[j.body0.face]!)\n const along = local[normal]\n if (Math.abs(along) >= 0.5) {\n const gap = origin.gap ?? 0\n if (typeof gap !== 'number') return { kind: 'refused', reason: 'origin-follows', joint: j.id }\n origin.gap = round(gap + outward * along, 1)\n }\n for (const axis of AXES.filter(a => a !== normal)) {\n const d = local[axis]\n if (Math.abs(d) < 0.5) continue\n const how = origin.align?.[axis] ?? 'centre'\n const was = how === 'centre' ? 0 : typeof how === 'object' && typeof how.mm === 'number' ? how.mm : null\n if (was === null) return { kind: 'refused', reason: 'origin-follows', joint: j.id }\n origin.align = { ...(origin.align ?? {}), [axis]: { mm: round(was + d, 1) } }\n }\n return { kind: 'joint', joint: { ...j, origin } }\n}\n\n/**\n * What a drag on the part does, said before it is dragged (review 2026-11-09: 「왜 안 움직이지?」): which handle changes\n * its pose, or why none does and where it is moved from instead. Null for a part on no joint, or on a fixed one.\n */\nexport type JointHandle =\n | { kind: 'turn' | 'slide'; joint: string }\n | { kind: 'mimic'; joint: string; leader: string; leaderPart?: string }\n | { kind: 'several-axes'; joint: string }\n\nexport function jointHandleOf(asset: FigureAsset, part: string): JointHandle | null {\n const j = asset.joints?.find(joint => joint.body1.part === part)\n if (!j) return null\n const axes = figureMotionsOf(j)\n if (!axes.length) return null\n if (axes.length > 1) return { kind: 'several-axes', joint: j.id }\n const a = axes[0]!\n if (a.mimic) {\n const leader = figureMimicTermsOf(a.mimic)!.sum[0]!.joint\n return { kind: 'mimic', joint: j.id, leader, leaderPart: asset.joints?.find(o => o.id === leader)?.body1.part }\n }\n return { kind: a.type === 'revolute' ? 'turn' : 'slide', joint: j.id }\n}\n"]}
@@ -227,7 +227,7 @@ export declare function placeKeptOf(revision: FigureRevision, part: string, targ
227
227
  export declare function alignOf(asset: FigureAsset, target: {
228
228
  part: string;
229
229
  face: string;
230
- } | 'plane', how: Partial<Record<Axis, Alignment>>, mm: Partial<Record<Axis, number>>, inputs?: Partial<Record<Axis, string>>): Partial<Record<Axis, "max" | "min" | {
230
+ } | 'plane', how: Partial<Record<Axis, Alignment>>, mm: Partial<Record<Axis, number>>, inputs?: Partial<Record<Axis, string>>): Partial<Record<Axis, "min" | "max" | {
231
231
  mm: number | {
232
232
  from: {
233
233
  of: "instance";
@@ -18,6 +18,15 @@ export interface FigureCatalogPatch {
18
18
  category?: string;
19
19
  tags?: string[];
20
20
  }
21
+ /** A catalogue field as the editor saw it before changing it; null when it was empty. */
22
+ export type FigureCatalogSeen = {
23
+ [K in keyof FigureCatalogPatch]?: FigureCatalogPatch[K] | null;
24
+ };
25
+ /** Another editor changed a catalogue field first: which, and what the row holds now. */
26
+ export interface FigureCatalogConflict {
27
+ field: keyof FigureCatalogPatch;
28
+ now: string | string[] | null;
29
+ }
21
30
  /** Persistence is injected; neither the model engine nor the renderer owns the product ID. */
22
31
  export interface FigureProductStore {
23
32
  load(id: string): Promise<FigureProductRecord>;
@@ -40,8 +49,11 @@ export interface FigureProductStore {
40
49
  /** Keys of the AI proposals whose steps the source holds: the server records them with the save. */
41
50
  proposalKeys?: string[];
42
51
  }): Promise<FigureProductRecord>;
43
- /** Writes the row's catalogue fields of a saved figure. */
44
- updateCatalog(id: string, patch: FigureCatalogPatch): Promise<unknown>;
52
+ /**
53
+ * Writes the row's catalogue fields of a saved figure, only while the row still holds them as `seen` says -- else it
54
+ * is refused with FIGURE_CATALOG_CONFLICT and the fields the row holds now.
55
+ */
56
+ updateCatalog(id: string, patch: FigureCatalogPatch, seen: FigureCatalogSeen): Promise<unknown>;
45
57
  }
46
58
  /** Product lifecycle boundary. A late response can never change another editor's asset or ID. */
47
59
  export declare function createFigureProductSession(store: FigureProductStore): {
@@ -10,6 +10,12 @@ function refusal(code, message) {
10
10
  return Object.assign(Error(message), { code });
11
11
  }
12
12
  const sameValue = (a, b) => JSON.stringify(a ?? null) === JSON.stringify(b ?? null);
13
+ /**
14
+ * A catalogue value as the server compares it (figure-service catalogConflictsOf): an empty category or type, or an
15
+ * empty tag list, is no value -- null; tags keep their order, which is part of the value.
16
+ */
17
+ const catalogValue = (value) => (value === '' || (Array.isArray(value) && !value.length) ? null : (value ?? null));
18
+ const sameCatalogValue = (a, b) => sameValue(catalogValue(a), catalogValue(b));
13
19
  /** Product lifecycle boundary. A late response can never change another editor's asset or ID. */
14
20
  export function createFigureProductSession(store) {
15
21
  const workspace = createFigureEditorWorkspace();
@@ -37,6 +43,12 @@ export function createFigureProductSession(store) {
37
43
  with them before it has read the row again (2026-11-01 third re-check). Empty from the start of each save.
38
44
  */
39
45
  let catalogWritten = {};
46
+ /*
47
+ What the row held for each field held in `catalog`, as the editor saw it when it first changed it: sent with the
48
+ save, which goes on only while the row still holds it (outside review 2026-11-09: a later tab wrote over another's
49
+ category without a word). After a conflict it is what the row holds then, so saving again writes over it knowingly.
50
+ */
51
+ let catalogSeen = {};
40
52
  const catalogHeld = () => Object.keys(catalog).length > 0;
41
53
  /* The author's size ends the last step moved without being asked (ADR-0087 decision 6), told once. */
42
54
  let fitted = [];
@@ -123,6 +135,7 @@ export function createFigureProductSession(store) {
123
135
  creationId = undefined;
124
136
  catalog = {};
125
137
  catalogWritten = {};
138
+ catalogSeen = {};
126
139
  conflict = undefined;
127
140
  done = [];
128
141
  undone = [];
@@ -153,13 +166,20 @@ export function createFigureProductSession(store) {
153
166
  if (!id)
154
167
  throw refusal('SESSION_NOT_SAVED', '먼저 저장해 주세요.');
155
168
  const next = { ...catalog };
169
+ const seen = { ...catalogSeen };
156
170
  for (const key of Object.keys(patch)) {
157
- if (!(catalogSending && key in catalogSending) && sameValue(patch[key], saved[key]))
171
+ if (!(catalogSending && key in catalogSending) && sameCatalogValue(patch[key], saved[key])) {
158
172
  delete next[key];
159
- else
173
+ delete seen[key];
174
+ }
175
+ else {
160
176
  next[key] = patch[key];
177
+ if (!(key in seen))
178
+ seen[key] = catalogValue(saved[key]);
179
+ }
161
180
  }
162
181
  catalog = next;
182
+ catalogSeen = seen;
163
183
  return read();
164
184
  },
165
185
  /**
@@ -192,6 +212,8 @@ export function createFigureProductSession(store) {
192
212
  /* The category and tags changed go with the copy, written once its first save gives it a row; its type is asked anew. */
193
213
  const { type: _type, ...kept } = catalog;
194
214
  catalog = kept;
215
+ /* A copy has no row yet: nothing it could have been changed on. */
216
+ catalogSeen = {};
195
217
  unconfirmed.clear();
196
218
  return read();
197
219
  },
@@ -352,10 +374,28 @@ export function createFigureProductSession(store) {
352
374
  if (requestEpoch !== epoch)
353
375
  return read();
354
376
  if (id !== undefined && Object.keys(sentCatalog).length) {
355
- await store.updateCatalog(id, sentCatalog);
377
+ const seen = Object.fromEntries(Object.keys(sentCatalog).map(key => [key, catalogSeen[key] ?? null]));
378
+ try {
379
+ await store.updateCatalog(id, sentCatalog, seen);
380
+ }
381
+ catch (failure) {
382
+ /* The fields stay held, as typed; what the row holds now is what the next save expects -- it writes over it. */
383
+ const fields = failure?.extensions?.fields;
384
+ if (failure?.code === 'FIGURE_CATALOG_CONFLICT' && requestEpoch === epoch && fields)
385
+ for (const { field, now } of fields)
386
+ if (field in catalog)
387
+ catalogSeen[field] = now;
388
+ throw failure;
389
+ }
356
390
  if (requestEpoch !== epoch)
357
391
  return read();
358
392
  catalogWritten = sentCatalog;
393
+ /* The row holds what was sent: a field changed again on the way is next compared with that. */
394
+ for (const key of Object.keys(sentCatalog))
395
+ if (sameValue(catalog[key], sentCatalog[key]))
396
+ delete catalogSeen[key];
397
+ else
398
+ catalogSeen[key] = catalogValue(sentCatalog[key]);
359
399
  /* What was sent is saved; a field changed again while it was on its way stays held. */
360
400
  const next = { ...catalog };
361
401
  for (const key of Object.keys(sentCatalog))
@@ -1 +1 @@
1
- {"version":3,"file":"product-session.js","sourceRoot":"","sources":["../../client/modeller/product-session.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAA;AACrD,OAAO,EAAE,gBAAgB,EAAuB,MAAM,eAAe,CAAA;AACrE,OAAO,EACL,iBAAiB,EACjB,2BAA2B,EAC3B,oBAAoB,EACpB,gBAAgB,EAChB,qBAAqB,EAQtB,MAAM,wBAAwB,CAAA;AAE/B,2EAA2E;AAE3E;;;GAGG;AACH,SAAS,OAAO,CAAC,IAAY,EAAE,OAAe;IAC5C,OAAO,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,EAAE,EAAE,IAAI,EAAE,CAAC,CAAA;AAChD,CAAC;AA8CD,MAAM,SAAS,GAAG,CAAC,CAAU,E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,EAAE,CAAC,CAAA;oBACvM,CAAC;yBAAM,CAAC;wBACN,IAAI,IAAI,KAAK,kBAAkB;4BAAE,WAAW,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,EAAE,EAAE,SAAS,EAAE,CAAC,CAAA;wBAC9E,IAAI,IAAI,KAAK,wBAAwB,IAAI,YAAY,KAAK,KAAK;4BAAE,QAAQ,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,CAAA;wBACtG,MAAM,KAAK,CAAA;oBACb,CAAC;gBACH,CAAC;gBACD,IAAI,YAAY,KAAK,KAAK;oBAAE,OAAO,IAAI,EAAE,CAAA;gBACzC,IAAI,CAAC,MAAM,CAAC,EAAE,IAAI,CAAC,EAAE,KAAK,SAAS,IAAI,MAAM,CAAC,EAAE,KAAK,EAAE,CAAC;oBAAE,MAAM,KAAK,CAAC,yBAAyB,CAAC,CAAA;gBAChG,IAAI,oBAAoB,CAAC,gBAAgB,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,KAAK,QAAQ,CAAC,IAAI;oBACzE,MAAM,KAAK,CAAC,wCAAwC,CAAC,CAAA;gBACvD,yFAAyF;gBACzF,EAAE,GAAG,MAAM,CAAC,EAAE,CAAA;gBACd,QAAQ,GAAG,MAAM,CAAC,MAAM,CAAA;gBACxB,WAAW,CAAC,KAAK,EAAE,CAAA;gBACnB,QAAQ,GAAG,SAAS,CAAA;gBACpB;;;kBAGE;gBACF,IAAI,SAAS,CAAC,IAAI,EAAE,CAAC,QAAQ,KAAK,QAAQ,CAAC,QAAQ;oBAAE,SAAS,CAAC,gBAAgB,CAAC,QAAQ,CAAC,CAAA;YAC3F,CAAC;QACH,CAAC;KACF,CAAA;AACH,CAAC","sourcesContent":["import { thumbnailHashOf } from './thumbnail-hash.js'\nimport { revisionFromView, type FigureRevision } from './revision.js'\nimport {\n createFigureAsset,\n createFigureEditorWorkspace,\n serializeFigureAsset,\n parseFigureAsset,\n figureSizeRangeFitsOf,\n type FigureSizeRangeFit,\n type FigureInputChange,\n type FigurePrimitiveCreation,\n type FigurePartEdit,\n type FigureAuthoringAction,\n type FigureProposalStep,\n type FigureClipConsent\n} from '@hatiolab/figure-model'\n\n/** Consent to let clips go, and the figure and version it was given on. */\n\n/**\n * A request the session refuses, with its code: a screen says it from the code (`sessionRefusalOf`), never from the\n * message, which stays for logs (ADR-0054; figure audit 2026-10-16 N6 -- an AI card put the message in its note).\n */\nfunction refusal(code: string, message: string): Error & { code: string } {\n return Object.assign(Error(message), { code })\n}\n\nexport interface FigureClipConsentFor extends FigureClipConsent {\n context: string\n revision: number\n}\n\nexport interface FigureProductRecord {\n id: string\n source: string\n}\n\n/**\n * The row's catalogue fields -- the type (before release), the category, the tags. Kept on the row, not in the asset,\n * and saved with it by 「저장」: written at once on change, they stayed after 「저장하지 않고 떠나기」 and the save\n * button never lit for them (2026-11-01 audit item 5).\n */\nexport interface FigureCatalogPatch {\n type?: string\n category?: string\n tags?: string[]\n}\n\n/** Persistence is injected; neither the model engine nor the renderer owns the product ID. */\nexport interface FigureProductStore {\n load(id: string): Promise<FigureProductRecord>\n /** Every field a save writes, as the server holds it now: to tell whether a save whose answer was lost landed. */\n readBack?(id: string): Promise<FigureProductRecord & { thumbnailHash?: string; type?: string }>\n save(request: {\n id?: string\n source: string\n expectedSource?: string\n creationId?: string\n /** The card's picture. Absent when the browser could not draw one; the source is saved either way. */\n thumbnail?: string\n /** The type name a new figure is created under (the first save asks for it). Not sent for an existing one. */\n type?: string\n /** The namespace a new figure is created under, when the first save chose one. Not sent for an existing one. */\n namespace?: string\n /** Keys of the AI proposals whose steps the source holds: the server records them with the save. */\n proposalKeys?: string[]\n }): Promise<FigureProductRecord>\n /** Writes the row's catalogue fields of a saved figure. */\n updateCatalog(id: string, patch: FigureCatalogPatch): Promise<unknown>\n}\n\nconst sameValue = (a: unknown, b: unknown) => JSON.stringify(a ?? null) === JSON.stringify(b ?? null)\n\n/** Product lifecycle boundary. A late response can never change another editor's asset or ID. */\nexport function createFigureProductSession(store: FigureProductStore) {\n const workspace = createFigureEditorWorkspace()\n let epoch = 0,\n id: string | undefined,\n baseline: string | undefined\n let loading = false,\n saving = false,\n error: string | undefined\n let creationId: string | undefined\n /*\n The history as steps, each tagged with the AI proposal it came from (or nothing): mirrored here, since the\n workspace's history does not say where a step came from. A proposal is in the model while its step is on `done` --\n undone, it is not; undone and written past, it never comes back. What a save sends as `proposalKeys`.\n */\n let done: Array<string | undefined> = [],\n undone: Array<string | undefined> = []\n /*\n A save refused because the server holds another source than the one opened (FIGURE_SOURCE_CONFLICT, not one of\n this session's own sends): the edits stay, and the server's latest is kept here to compare with and, if the person\n says so, to write over (2026-11-01 audit item 6). Undefined source: the latest could not be read.\n */\n let conflict: { source?: string } | undefined\n /* The catalogue fields changed and not saved yet; none of the history -- undo is the figure's steps. */\n let catalog: FigureCatalogPatch = {}\n /* The catalogue fields a save is writing now: what the row will hold, not what it held, until it is done. */\n let catalogSending: FigureCatalogPatch | undefined\n /*\n The catalogue fields the last save wrote, known to be on the row from the moment it answered: a screen compares\n with them before it has read the row again (2026-11-01 third re-check). Empty from the start of each save.\n */\n let catalogWritten: FigureCatalogPatch = {}\n const catalogHeld = () => Object.keys(catalog).length > 0\n /* The author's size ends the last step moved without being asked (ADR-0087 decision 6), told once. */\n let fitted: FigureSizeRangeFit[] = []\n function tracked<T>(kind: 'do' | 'undo' | 'redo', run: () => T, tag?: string, setsRange = false): T {\n const was = workspace.read()\n const result = run()\n const now = workspace.read()\n if (now.revision === was.revision) return result\n fitted = kind === 'do' && !setsRange && was.asset && now.asset ? figureSizeRangeFitsOf(was.asset, now.asset) : []\n if (kind === 'do') {\n done.push(tag)\n undone = []\n } else if (kind === 'undo') undone.push(done.pop())\n else done.push(undone.pop())\n return result\n }\n const inEffect = () => [...new Set(done.filter((tag): tag is string => !!tag))]\n /*\n The creation id is read with the rest: a figure not saved yet is named by it (ADR-0061 decision 3) -- its AI\n conversation is anchored on it, and its first save inserts the row under it, so the name holds across that save.\n */\n function read() {\n const view = workspace.read()\n return { ...view, dirty: view.dirty || catalogHeld(), catalog: { ...catalog }, catalogWritten: { ...catalogWritten }, conflict: conflict ? { latest: conflict.source } : undefined, id, creationId, loading, saving, error }\n }\n /*\n The version on screen, one object for as long as it is the version: the workspace hands out one asset per version\n (and another once a save is acknowledged, or the figure moves on), so that object says whether the last one holds.\n */\n let shown: FigureRevision | undefined\n function revisionNow(): FigureRevision | undefined {\n const view = workspace.read()\n if (!view.context || view.revision === null) return (shown = undefined)\n const context = view.context\n if (shown?.asset !== view.asset) shown = revisionFromView(view, () => workspace.export({ context }).text)\n return shown\n }\n /* Texts sent whose save was never answered: found on the server, the server is confirmed to hold what was sent. */\n const unconfirmed = new Map<string, { thumbnail?: string }>()\n /*\n Consent to let clips go: given for one edit, on the figure and the version it was asked on. The first edit made under\n it takes it; an edit on another figure or another version is refused rather than let clips go that were never named\n for it (designer 2026-09-27).\n */\n let consent: FigureClipConsentFor | undefined\n const consented = () => {\n if (!consent) return {}\n const given = consent\n consent = undefined\n const view = workspace.read()\n if (view.context !== given.context || view.revision !== given.revision) {\n const stale = Object.assign(Error('확인한 뒤 모델이 바뀌어 적용하지 않았습니다. 다시 해 주세요.'), { code: 'CONSENT_STALE' })\n throw stale\n }\n return { dropClips: given.dropClips }\n }\n /* A model open to read: the draft is read during a save too -- the dock reads it when the person sends (audit N5). */\n function readable() {\n const view = workspace.read()\n if (loading || error || !view.context || view.revision === null) throw refusal('SESSION_NOT_OPEN', '먼저 모델을 정상적으로 열어 주세요.')\n return { context: view.context, expectedRevision: view.revision, origin: 'ui' as const }\n }\n function writable() {\n const open = readable()\n // Serializing writes also makes create retries safe: no second create while the first is pending.\n if (saving) throw refusal('SESSION_SAVING', '저장이 끝난 뒤 편집해 주세요.')\n return open\n }\n function clear() {\n workspace.close({ discardDesignChanges: true })\n id = undefined\n baseline = undefined\n error = undefined\n saving = false\n creationId = undefined\n catalog = {}\n catalogWritten = {}\n conflict = undefined\n done = []\n undone = []\n }\n function canLeave(discard: boolean) {\n if (saving) throw Error('저장이 끝난 뒤 모델을 전환해 주세요.')\n if ((workspace.read().dirty || catalogHeld()) && !discard) throw Error('저장하지 않은 변경이 있습니다.')\n }\n return {\n read,\n /** The figure on screen at its version, for every panel and helper to read; none while nothing is open. Readable while saving. */\n revisionNow,\n /**\n * The source the server is confirmed to hold: loaded, or answered by a save. What a revert sends as `expectedSource`\n * -- the server writes over it only while it still holds this. Nothing for a figure not saved yet.\n */\n confirmedSource: () => (id ? baseline : undefined),\n /**\n * A catalogue field changed, held for the next save; one changed back to what the row holds (`saved`) is no\n * change. Only a saved figure has a row to write: a new figure's type goes with its first save. Taken while a save\n * is on its way too: the field shows it, so it is held for the save after (2026-11-01 re-check). A field that save\n * is writing is held whatever it is changed to -- back to the old value too, which the save is about to replace;\n * the save done lets go only of a value it wrote (2026-11-01 second re-check).\n */\n editCatalog(patch: FigureCatalogPatch, saved: FigureCatalogPatch) {\n if (!id) throw refusal('SESSION_NOT_SAVED', '먼저 저장해 주세요.')\n const next = { ...catalog }\n for (const key of Object.keys(patch) as (keyof FigureCatalogPatch)[]) {\n if (!(catalogSending && key in catalogSending) && sameValue(patch[key], saved[key])) delete next[key]\n else (next as Record<string, unknown>)[key] = patch[key]\n }\n catalog = next\n return read()\n },\n /**\n * After a conflict, the edits written over the server's latest: the next save expects that latest, so it goes\n * through only while the server still holds it -- a third change meanwhile is a conflict again.\n */\n overwriteConflict() {\n if (saving) throw refusal('SESSION_SAVING', '저장이 끝난 뒤 편집해 주세요.')\n if (!conflict?.source) throw refusal('SESSION_NO_CONFLICT', '덮어쓸 최신본을 읽지 못했습니다.')\n baseline = conflict.source\n conflict = undefined\n unconfirmed.clear()\n return read()\n },\n /**\n * After a conflict, the edits kept as a figure of their own: from here they are a new figure, under a new creation\n * id, saved by the first save's question; the figure they came from is left as the server holds it.\n */\n detachAsCopy() {\n if (saving) throw refusal('SESSION_SAVING', '저장이 끝난 뒤 편집해 주세요.')\n if (!conflict) throw refusal('SESSION_NO_CONFLICT', '충돌한 저장이 없습니다.')\n id = undefined\n baseline = undefined\n creationId = crypto.randomUUID()\n conflict = undefined\n /* The category and tags changed go with the copy, written once its first save gives it a row; its type is asked anew. */\n const { type: _type, ...kept } = catalog\n catalog = kept\n unconfirmed.clear()\n return read()\n },\n /** A new figure, named in the screen's language by the page: the session has no words of its own. */\n startNew({ discard = false, name }: { discard?: boolean; name: string }) {\n canLeave(discard)\n ++epoch\n clear()\n loading = false\n workspace.open(serializeFigureAsset(createFigureAsset(name)))\n creationId = crypto.randomUUID()\n return read()\n },\n async open(nextId: string, { discard = false } = {}) {\n canLeave(discard)\n const requestEpoch = ++epoch\n clear()\n loading = true\n try {\n const record = await store.load(nextId)\n if (requestEpoch !== epoch) return read()\n if (record.id !== nextId) throw Error('요청한 Figure와 응답의 대상이 다릅니다.')\n workspace.open(record.source)\n id = nextId\n baseline = record.source\n } catch (cause) {\n if (requestEpoch === epoch) error = cause instanceof Error ? cause.message : String(cause)\n } finally {\n if (requestEpoch === epoch) loading = false\n }\n return read()\n },\n close({ discard = false } = {}) {\n canLeave(discard)\n ++epoch\n clear()\n loading = false\n return read()\n },\n apply(changes: FigureInputChange[], origin: 'ui' | 'ai' = 'ui', expectedRevision?: number, context?: string) {\n const control = writable()\n // AI must supply the context AND revision captured when it started. Never substitute current values.\n if (origin === 'ai' && (context === undefined || expectedRevision === undefined))\n throw refusal('SESSION_VERSION_MISSING', 'AI 편집에는 요청 당시의 모델 문맥과 리비전이 필요합니다.')\n return tracked('do', () =>\n workspace.apply({\n ...control,\n origin,\n context: context ?? control.context,\n expectedRevision: expectedRevision ?? control.expectedRevision,\n changes\n })\n )\n },\n /**\n * An AI proposal (ADR-0094): the modeller's commands, as one step of the history, on the version the model saw.\n * Never on the current one instead -- a person's edit in between makes the proposal stale, and it is refused.\n */\n applyProposal(steps: readonly FigureProposalStep[], expectedRevision: number, context: string, key?: string) {\n writable()\n /* Never with consent: only the person may let a clip go, and an AI proposal is not the person (designer 2026-09-27). */\n return tracked('do', () => workspace.applyProposal({ origin: 'ai', context, expectedRevision, steps }), key)\n },\n /**\n * A new figure opened for an AI proposal from another screen is created under the proposal's key (ADR-0097 §5.6\n * item 5). Only before the modeller names the figure to the AI dock: once a conversation is anchored on the creation\n * id it stays (ADR-0061 decision 3), and the save's record of the proposal keeps one proposal one figure. Only on a\n * new figure not yet touched -- one being made is the person's, and keeps its own.\n */\n createUnder(key: string) {\n if (id || workspace.read().dirty) throw refusal('SESSION_NEW_FIGURE_TOUCHED', '손대지 않은 새 모델에만 쓸 수 있습니다.')\n if (!/^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(key)) throw refusal('SESSION_PROPOSAL_KEY', '제안 식별자가 올바르지 않습니다.')\n creationId = key\n },\n /** The AI proposals whose steps are in the model now, each once. */\n proposalsInEffect: inEffect,\n /**\n * A recipe put in by the person (ADR-0095): its resolved commands, as one step of the history, on the version open\n * now. The same path as a proposal; the person is its origin.\n */\n applyRecipe(steps: readonly FigureProposalStep[]) {\n const at = writable()\n return tracked('do', () => workspace.applyProposal({ origin: 'ui', context: at.context, expectedRevision: at.expectedRevision, steps, ...consented() }))\n },\n add(part: FigurePrimitiveCreation) {\n return tracked('do', () => workspace.addPrimitive({ ...writable(), part }))\n },\n edit(edit: FigurePartEdit) {\n return tracked('do', () => workspace.editPart({ ...writable(), edit, ...consented() }))\n },\n /** What a command would do, on a copy (ADR-0097 §5.5): nothing is written, and the answer names its version. */\n previewCommand(action: FigureAuthoringAction) {\n const view = workspace.read()\n if (loading || error || !view.context || view.revision === null) throw refusal('SESSION_NOT_OPEN', '먼저 모델을 정상적으로 열어 주세요.')\n return workspace.previewCommand({ context: view.context, action })\n },\n /** One authoring command — what a person means, not a graph edit — as one step of the same history. */\n command(action: FigureAuthoringAction) {\n return tracked('do', () => workspace.command({ ...writable(), action, ...consented() }), undefined, action.kind === 'declare-instance-size')\n },\n /** The ends of the size on a drawing the last step moved in to what the parts allow, once: then nothing until the next. */\n takeSizeRangeFits(): FigureSizeRangeFit[] {\n const out = fitted\n fitted = []\n return out\n },\n /**\n * The first edit made inside `run` may let go of exactly these clips -- the ones a CLIPS_DROPPED refusal named and\n * the person agreed to -- on the figure and version they were named on (designer 2026-09-27). Any other edit that\n * would stop a clip is refused and asked about.\n */\n withConsent<T>(given: FigureClipConsentFor, run: () => T): T {\n consent = given\n try {\n return run()\n } finally {\n consent = undefined\n }\n },\n undo() {\n return tracked('undo', () => workspace.undo(writable()))\n },\n redo() {\n return tracked('redo', () => workspace.redo(writable()))\n },\n source() {\n const { context } = readable()\n return workspace.export({ context }).text\n },\n /**\n * Saves the model, and the card's picture when the caller managed to take one.\n *\n * The picture is the caller's because taking it needs a canvas, and this session is the place that knows\n * nothing about drawing. A save with no picture is a save: a tab in the background cannot draw, and the\n * source matters more than the card (see `thumbnail.ts`).\n */\n async save({ thumbnail, type, namespace }: { thumbnail?: string; type?: string; namespace?: string } = {}) {\n const control = writable(),\n requestEpoch = epoch\n const exported = workspace.export(control)\n /* Read with the text it goes with: an edit while saving is not what this save holds. */\n const proposalKeys = inEffect()\n const sentCatalog = { ...catalog }\n saving = true\n catalogSending = sentCatalog\n catalogWritten = {}\n try {\n /* Only the catalogue changed: the source is not written again -- a released figure would be made a draft for nothing. */\n if (id === undefined || workspace.read().dirty) await saveSource()\n if (requestEpoch !== epoch) return read()\n if (id !== undefined && Object.keys(sentCatalog).length) {\n await store.updateCatalog(id, sentCatalog)\n if (requestEpoch !== epoch) return read()\n catalogWritten = sentCatalog\n /* What was sent is saved; a field changed again while it was on its way stays held. */\n const next = { ...catalog }\n for (const key of Object.keys(sentCatalog) as (keyof FigureCatalogPatch)[]) if (sameValue(next[key], sentCatalog[key])) delete next[key]\n catalog = next\n }\n } finally {\n if (requestEpoch === epoch) saving = false\n catalogSending = undefined\n }\n return read()\n\n async function saveSource() {\n let record: FigureProductRecord\n try {\n record = await store.save({ id, source: exported.text, expectedSource: baseline, creationId, thumbnail, proposalKeys, ...(id || !type ? {} : { type }), ...(id || !namespace ? {} : { namespace }) })\n } catch (error) {\n /*\n A save that failed may still have landed: the answer lost on the way back (SAVE_UNREACHABLE), or a second\n try refused because the first did land -- its expected source is the old one (FIGURE_SOURCE_CONFLICT). Only\n those are read back; a refusal on grounds -- permission, validation -- stays a failure whatever the row\n holds. Read back, every field the save writes must be what was sent: the source, the picture, the type\n (designer 2026-09-27: a network failure alone does not say nothing was saved; nor does a matching source\n alone say it was).\n */\n const code = (error as { code?: string })?.code\n const unknown = code === 'SAVE_UNREACHABLE' || code === 'FIGURE_SOURCE_CONFLICT'\n const landed = unknown && id !== undefined && requestEpoch === epoch && store.readBack ? await store.readBack(id).catch(() => undefined) : undefined\n const held = landed ? serializeFigureAsset(parseFigureAsset(landed.source)) : undefined\n /* The picture is compared by the name the server keeps it under: the hash of its bytes (ADR-0104). */\n const holds = async (sent?: string) => sent === undefined || (!!landed && landed.thumbnailHash !== undefined && landed.thumbnailHash === (await thumbnailHashOf(sent)))\n const same = !!landed && held === exported.text && (await holds(thumbnail)) && (type === undefined || landed.type === type)\n if (same) record = landed!\n else if (\n code === 'FIGURE_SOURCE_CONFLICT' &&\n landed &&\n held !== undefined &&\n unconfirmed.has(held) &&\n /* Every field that earlier save wrote, not the source alone: nothing not compared is written over. */\n (await holds(unconfirmed.get(held)!.thumbnail))\n ) {\n /*\n The row holds a text this session sent and never heard back about -- edited further since, the new text\n is not it. The server is known to hold what was sent: this save is sent again, once, conditional on that\n server text as the expected source (designer 2026-09-27: \"the sent content is confirmed on the server\").\n */\n baseline = landed.source\n unconfirmed.clear()\n record = await store.save({ id, source: exported.text, expectedSource: baseline, creationId, thumbnail, proposalKeys, ...(id || !type ? {} : { type }), ...(id || !namespace ? {} : { namespace }) })\n } else {\n if (code === 'SAVE_UNREACHABLE') unconfirmed.set(exported.text, { thumbnail })\n if (code === 'FIGURE_SOURCE_CONFLICT' && requestEpoch === epoch) conflict = { source: landed?.source }\n throw error\n }\n }\n if (requestEpoch !== epoch) return read()\n if (!record.id || (id !== undefined && record.id !== id)) throw Error('저장 응답의 Figure 대상이 다릅니다.')\n if (serializeFigureAsset(parseFigureAsset(record.source)) !== exported.text)\n throw Error('저장 응답이 보낸 모델과 다릅니다. 저장 상태를 다시 확인해 주세요.')\n /* The server has it: the next save expects it, whatever happened on screen meanwhile. */\n id = record.id\n baseline = record.source\n unconfirmed.clear()\n conflict = undefined\n /*\n Edited while it was saving: what was sent is saved, the edits since are not -- they stay, and the model stays\n unsaved (the workspace refuses a stale acknowledgement). Never marked saved, never wiped.\n */\n if (workspace.read().revision === exported.revision) workspace.acknowledgeSaved(exported)\n }\n }\n }\n}\nexport type FigureProductSession = ReturnType<typeof createFigureProductSession>\n"]}
1
+ {"version":3,"file":"product-session.js","sourceRoot":"","sources":["../../client/modeller/product-session.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAA;AACrD,OAAO,EAAE,gBAAgB,EAAuB,MAAM,eAAe,CAAA;AACrE,OAAO,EACL,iBAAiB,EACjB,2BAA2B,EAC3B,oBAAoB,EACpB,gBAAgB,EAChB,qBAAqB,EAQtB,MAAM,wBAAwB,CAAA;AAE/B,2EAA2E;AAE3E;;;GAGG;AACH,SAAS,OAAO,CAAC,IAAY,EAAE,OAAe;IAC5C,OAAO,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,EAAE,EAAE,IAAI,EAAE,CAAC,CAAA;AAChD,CAAC;AA0DD,MAAM,SAAS,GAAG,CAAC,CAAU,EAAE,CAAU,EAAE,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,IAAI,IAAI,CAAC,KAAK,IAAI,CAAC,SAAS,CAAC,CAAC,IAAI,IAAI,CAAC,CAAA;AAErG;;;GAGG;AACH,MAAM,YAAY,GAAG,CAAC,KAAc,EAAE,EAAE,CAAC,CAAC,KAAK,KAAK,EAAE,I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,EAAE,CAAC,QAAQ,KAAK,QAAQ,CAAC,QAAQ;oBAAE,SAAS,CAAC,gBAAgB,CAAC,QAAQ,CAAC,CAAA;YAC3F,CAAC;QACH,CAAC;KACF,CAAA;AACH,CAAC","sourcesContent":["import { thumbnailHashOf } from './thumbnail-hash.js'\nimport { revisionFromView, type FigureRevision } from './revision.js'\nimport {\n createFigureAsset,\n createFigureEditorWorkspace,\n serializeFigureAsset,\n parseFigureAsset,\n figureSizeRangeFitsOf,\n type FigureSizeRangeFit,\n type FigureInputChange,\n type FigurePrimitiveCreation,\n type FigurePartEdit,\n type FigureAuthoringAction,\n type FigureProposalStep,\n type FigureClipConsent\n} from '@hatiolab/figure-model'\n\n/** Consent to let clips go, and the figure and version it was given on. */\n\n/**\n * A request the session refuses, with its code: a screen says it from the code (`sessionRefusalOf`), never from the\n * message, which stays for logs (ADR-0054; figure audit 2026-10-16 N6 -- an AI card put the message in its note).\n */\nfunction refusal(code: string, message: string): Error & { code: string } {\n return Object.assign(Error(message), { code })\n}\n\nexport interface FigureClipConsentFor extends FigureClipConsent {\n context: string\n revision: number\n}\n\nexport interface FigureProductRecord {\n id: string\n source: string\n}\n\n/**\n * The row's catalogue fields -- the type (before release), the category, the tags. Kept on the row, not in the asset,\n * and saved with it by 「저장」: written at once on change, they stayed after 「저장하지 않고 떠나기」 and the save\n * button never lit for them (2026-11-01 audit item 5).\n */\nexport interface FigureCatalogPatch {\n type?: string\n category?: string\n tags?: string[]\n}\n\n/** A catalogue field as the editor saw it before changing it; null when it was empty. */\nexport type FigureCatalogSeen = { [K in keyof FigureCatalogPatch]?: FigureCatalogPatch[K] | null }\n\n/** Another editor changed a catalogue field first: which, and what the row holds now. */\nexport interface FigureCatalogConflict {\n field: keyof FigureCatalogPatch\n now: string | string[] | null\n}\n\n/** Persistence is injected; neither the model engine nor the renderer owns the product ID. */\nexport interface FigureProductStore {\n load(id: string): Promise<FigureProductRecord>\n /** Every field a save writes, as the server holds it now: to tell whether a save whose answer was lost landed. */\n readBack?(id: string): Promise<FigureProductRecord & { thumbnailHash?: string; type?: string }>\n save(request: {\n id?: string\n source: string\n expectedSource?: string\n creationId?: string\n /** The card's picture. Absent when the browser could not draw one; the source is saved either way. */\n thumbnail?: string\n /** The type name a new figure is created under (the first save asks for it). Not sent for an existing one. */\n type?: string\n /** The namespace a new figure is created under, when the first save chose one. Not sent for an existing one. */\n namespace?: string\n /** Keys of the AI proposals whose steps the source holds: the server records them with the save. */\n proposalKeys?: string[]\n }): Promise<FigureProductRecord>\n /**\n * Writes the row's catalogue fields of a saved figure, only while the row still holds them as `seen` says -- else it\n * is refused with FIGURE_CATALOG_CONFLICT and the fields the row holds now.\n */\n updateCatalog(id: string, patch: FigureCatalogPatch, seen: FigureCatalogSeen): Promise<unknown>\n}\n\nconst sameValue = (a: unknown, b: unknown) => JSON.stringify(a ?? null) === JSON.stringify(b ?? null)\n\n/**\n * A catalogue value as the server compares it (figure-service catalogConflictsOf): an empty category or type, or an\n * empty tag list, is no value -- null; tags keep their order, which is part of the value.\n */\nconst catalogValue = (value: unknown) => (value === '' || (Array.isArray(value) && !value.length) ? null : (value ?? null))\nconst sameCatalogValue = (a: unknown, b: unknown) => sameValue(catalogValue(a), catalogValue(b))\n\n/** Product lifecycle boundary. A late response can never change another editor's asset or ID. */\nexport function createFigureProductSession(store: FigureProductStore) {\n const workspace = createFigureEditorWorkspace()\n let epoch = 0,\n id: string | undefined,\n baseline: string | undefined\n let loading = false,\n saving = false,\n error: string | undefined\n let creationId: string | undefined\n /*\n The history as steps, each tagged with the AI proposal it came from (or nothing): mirrored here, since the\n workspace's history does not say where a step came from. A proposal is in the model while its step is on `done` --\n undone, it is not; undone and written past, it never comes back. What a save sends as `proposalKeys`.\n */\n let done: Array<string | undefined> = [],\n undone: Array<string | undefined> = []\n /*\n A save refused because the server holds another source than the one opened (FIGURE_SOURCE_CONFLICT, not one of\n this session's own sends): the edits stay, and the server's latest is kept here to compare with and, if the person\n says so, to write over (2026-11-01 audit item 6). Undefined source: the latest could not be read.\n */\n let conflict: { source?: string } | undefined\n /* The catalogue fields changed and not saved yet; none of the history -- undo is the figure's steps. */\n let catalog: FigureCatalogPatch = {}\n /* The catalogue fields a save is writing now: what the row will hold, not what it held, until it is done. */\n let catalogSending: FigureCatalogPatch | undefined\n /*\n The catalogue fields the last save wrote, known to be on the row from the moment it answered: a screen compares\n with them before it has read the row again (2026-11-01 third re-check). Empty from the start of each save.\n */\n let catalogWritten: FigureCatalogPatch = {}\n /*\n What the row held for each field held in `catalog`, as the editor saw it when it first changed it: sent with the\n save, which goes on only while the row still holds it (outside review 2026-11-09: a later tab wrote over another's\n category without a word). After a conflict it is what the row holds then, so saving again writes over it knowingly.\n */\n let catalogSeen: FigureCatalogSeen = {}\n const catalogHeld = () => Object.keys(catalog).length > 0\n /* The author's size ends the last step moved without being asked (ADR-0087 decision 6), told once. */\n let fitted: FigureSizeRangeFit[] = []\n function tracked<T>(kind: 'do' | 'undo' | 'redo', run: () => T, tag?: string, setsRange = false): T {\n const was = workspace.read()\n const result = run()\n const now = workspace.read()\n if (now.revision === was.revision) return result\n fitted = kind === 'do' && !setsRange && was.asset && now.asset ? figureSizeRangeFitsOf(was.asset, now.asset) : []\n if (kind === 'do') {\n done.push(tag)\n undone = []\n } else if (kind === 'undo') undone.push(done.pop())\n else done.push(undone.pop())\n return result\n }\n const inEffect = () => [...new Set(done.filter((tag): tag is string => !!tag))]\n /*\n The creation id is read with the rest: a figure not saved yet is named by it (ADR-0061 decision 3) -- its AI\n conversation is anchored on it, and its first save inserts the row under it, so the name holds across that save.\n */\n function read() {\n const view = workspace.read()\n return { ...view, dirty: view.dirty || catalogHeld(), catalog: { ...catalog }, catalogWritten: { ...catalogWritten }, conflict: conflict ? { latest: conflict.source } : undefined, id, creationId, loading, saving, error }\n }\n /*\n The version on screen, one object for as long as it is the version: the workspace hands out one asset per version\n (and another once a save is acknowledged, or the figure moves on), so that object says whether the last one holds.\n */\n let shown: FigureRevision | undefined\n function revisionNow(): FigureRevision | undefined {\n const view = workspace.read()\n if (!view.context || view.revision === null) return (shown = undefined)\n const context = view.context\n if (shown?.asset !== view.asset) shown = revisionFromView(view, () => workspace.export({ context }).text)\n return shown\n }\n /* Texts sent whose save was never answered: found on the server, the server is confirmed to hold what was sent. */\n const unconfirmed = new Map<string, { thumbnail?: string }>()\n /*\n Consent to let clips go: given for one edit, on the figure and the version it was asked on. The first edit made under\n it takes it; an edit on another figure or another version is refused rather than let clips go that were never named\n for it (designer 2026-09-27).\n */\n let consent: FigureClipConsentFor | undefined\n const consented = () => {\n if (!consent) return {}\n const given = consent\n consent = undefined\n const view = workspace.read()\n if (view.context !== given.context || view.revision !== given.revision) {\n const stale = Object.assign(Error('확인한 뒤 모델이 바뀌어 적용하지 않았습니다. 다시 해 주세요.'), { code: 'CONSENT_STALE' })\n throw stale\n }\n return { dropClips: given.dropClips }\n }\n /* A model open to read: the draft is read during a save too -- the dock reads it when the person sends (audit N5). */\n function readable() {\n const view = workspace.read()\n if (loading || error || !view.context || view.revision === null) throw refusal('SESSION_NOT_OPEN', '먼저 모델을 정상적으로 열어 주세요.')\n return { context: view.context, expectedRevision: view.revision, origin: 'ui' as const }\n }\n function writable() {\n const open = readable()\n // Serializing writes also makes create retries safe: no second create while the first is pending.\n if (saving) throw refusal('SESSION_SAVING', '저장이 끝난 뒤 편집해 주세요.')\n return open\n }\n function clear() {\n workspace.close({ discardDesignChanges: true })\n id = undefined\n baseline = undefined\n error = undefined\n saving = false\n creationId = undefined\n catalog = {}\n catalogWritten = {}\n catalogSeen = {}\n conflict = undefined\n done = []\n undone = []\n }\n function canLeave(discard: boolean) {\n if (saving) throw Error('저장이 끝난 뒤 모델을 전환해 주세요.')\n if ((workspace.read().dirty || catalogHeld()) && !discard) throw Error('저장하지 않은 변경이 있습니다.')\n }\n return {\n read,\n /** The figure on screen at its version, for every panel and helper to read; none while nothing is open. Readable while saving. */\n revisionNow,\n /**\n * The source the server is confirmed to hold: loaded, or answered by a save. What a revert sends as `expectedSource`\n * -- the server writes over it only while it still holds this. Nothing for a figure not saved yet.\n */\n confirmedSource: () => (id ? baseline : undefined),\n /**\n * A catalogue field changed, held for the next save; one changed back to what the row holds (`saved`) is no\n * change. Only a saved figure has a row to write: a new figure's type goes with its first save. Taken while a save\n * is on its way too: the field shows it, so it is held for the save after (2026-11-01 re-check). A field that save\n * is writing is held whatever it is changed to -- back to the old value too, which the save is about to replace;\n * the save done lets go only of a value it wrote (2026-11-01 second re-check).\n */\n editCatalog(patch: FigureCatalogPatch, saved: FigureCatalogPatch) {\n if (!id) throw refusal('SESSION_NOT_SAVED', '먼저 저장해 주세요.')\n const next = { ...catalog }\n const seen = { ...catalogSeen }\n for (const key of Object.keys(patch) as (keyof FigureCatalogPatch)[]) {\n if (!(catalogSending && key in catalogSending) && sameCatalogValue(patch[key], saved[key])) {\n delete next[key]\n delete seen[key]\n } else {\n (next as Record<string, unknown>)[key] = patch[key]\n if (!(key in seen)) (seen as Record<string, unknown>)[key] = catalogValue(saved[key])\n }\n }\n catalog = next\n catalogSeen = seen\n return read()\n },\n /**\n * After a conflict, the edits written over the server's latest: the next save expects that latest, so it goes\n * through only while the server still holds it -- a third change meanwhile is a conflict again.\n */\n overwriteConflict() {\n if (saving) throw refusal('SESSION_SAVING', '저장이 끝난 뒤 편집해 주세요.')\n if (!conflict?.source) throw refusal('SESSION_NO_CONFLICT', '덮어쓸 최신본을 읽지 못했습니다.')\n baseline = conflict.source\n conflict = undefined\n unconfirmed.clear()\n return read()\n },\n /**\n * After a conflict, the edits kept as a figure of their own: from here they are a new figure, under a new creation\n * id, saved by the first save's question; the figure they came from is left as the server holds it.\n */\n detachAsCopy() {\n if (saving) throw refusal('SESSION_SAVING', '저장이 끝난 뒤 편집해 주세요.')\n if (!conflict) throw refusal('SESSION_NO_CONFLICT', '충돌한 저장이 없습니다.')\n id = undefined\n baseline = undefined\n creationId = crypto.randomUUID()\n conflict = undefined\n /* The category and tags changed go with the copy, written once its first save gives it a row; its type is asked anew. */\n const { type: _type, ...kept } = catalog\n catalog = kept\n /* A copy has no row yet: nothing it could have been changed on. */\n catalogSeen = {}\n unconfirmed.clear()\n return read()\n },\n /** A new figure, named in the screen's language by the page: the session has no words of its own. */\n startNew({ discard = false, name }: { discard?: boolean; name: string }) {\n canLeave(discard)\n ++epoch\n clear()\n loading = false\n workspace.open(serializeFigureAsset(createFigureAsset(name)))\n creationId = crypto.randomUUID()\n return read()\n },\n async open(nextId: string, { discard = false } = {}) {\n canLeave(discard)\n const requestEpoch = ++epoch\n clear()\n loading = true\n try {\n const record = await store.load(nextId)\n if (requestEpoch !== epoch) return read()\n if (record.id !== nextId) throw Error('요청한 Figure와 응답의 대상이 다릅니다.')\n workspace.open(record.source)\n id = nextId\n baseline = record.source\n } catch (cause) {\n if (requestEpoch === epoch) error = cause instanceof Error ? cause.message : String(cause)\n } finally {\n if (requestEpoch === epoch) loading = false\n }\n return read()\n },\n close({ discard = false } = {}) {\n canLeave(discard)\n ++epoch\n clear()\n loading = false\n return read()\n },\n apply(changes: FigureInputChange[], origin: 'ui' | 'ai' = 'ui', expectedRevision?: number, context?: string) {\n const control = writable()\n // AI must supply the context AND revision captured when it started. Never substitute current values.\n if (origin === 'ai' && (context === undefined || expectedRevision === undefined))\n throw refusal('SESSION_VERSION_MISSING', 'AI 편집에는 요청 당시의 모델 문맥과 리비전이 필요합니다.')\n return tracked('do', () =>\n workspace.apply({\n ...control,\n origin,\n context: context ?? control.context,\n expectedRevision: expectedRevision ?? control.expectedRevision,\n changes\n })\n )\n },\n /**\n * An AI proposal (ADR-0094): the modeller's commands, as one step of the history, on the version the model saw.\n * Never on the current one instead -- a person's edit in between makes the proposal stale, and it is refused.\n */\n applyProposal(steps: readonly FigureProposalStep[], expectedRevision: number, context: string, key?: string) {\n writable()\n /* Never with consent: only the person may let a clip go, and an AI proposal is not the person (designer 2026-09-27). */\n return tracked('do', () => workspace.applyProposal({ origin: 'ai', context, expectedRevision, steps }), key)\n },\n /**\n * A new figure opened for an AI proposal from another screen is created under the proposal's key (ADR-0097 §5.6\n * item 5). Only before the modeller names the figure to the AI dock: once a conversation is anchored on the creation\n * id it stays (ADR-0061 decision 3), and the save's record of the proposal keeps one proposal one figure. Only on a\n * new figure not yet touched -- one being made is the person's, and keeps its own.\n */\n createUnder(key: string) {\n if (id || workspace.read().dirty) throw refusal('SESSION_NEW_FIGURE_TOUCHED', '손대지 않은 새 모델에만 쓸 수 있습니다.')\n if (!/^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(key)) throw refusal('SESSION_PROPOSAL_KEY', '제안 식별자가 올바르지 않습니다.')\n creationId = key\n },\n /** The AI proposals whose steps are in the model now, each once. */\n proposalsInEffect: inEffect,\n /**\n * A recipe put in by the person (ADR-0095): its resolved commands, as one step of the history, on the version open\n * now. The same path as a proposal; the person is its origin.\n */\n applyRecipe(steps: readonly FigureProposalStep[]) {\n const at = writable()\n return tracked('do', () => workspace.applyProposal({ origin: 'ui', context: at.context, expectedRevision: at.expectedRevision, steps, ...consented() }))\n },\n add(part: FigurePrimitiveCreation) {\n return tracked('do', () => workspace.addPrimitive({ ...writable(), part }))\n },\n edit(edit: FigurePartEdit) {\n return tracked('do', () => workspace.editPart({ ...writable(), edit, ...consented() }))\n },\n /** What a command would do, on a copy (ADR-0097 §5.5): nothing is written, and the answer names its version. */\n previewCommand(action: FigureAuthoringAction) {\n const view = workspace.read()\n if (loading || error || !view.context || view.revision === null) throw refusal('SESSION_NOT_OPEN', '먼저 모델을 정상적으로 열어 주세요.')\n return workspace.previewCommand({ context: view.context, action })\n },\n /** One authoring command — what a person means, not a graph edit — as one step of the same history. */\n command(action: FigureAuthoringAction) {\n return tracked('do', () => workspace.command({ ...writable(), action, ...consented() }), undefined, action.kind === 'declare-instance-size')\n },\n /** The ends of the size on a drawing the last step moved in to what the parts allow, once: then nothing until the next. */\n takeSizeRangeFits(): FigureSizeRangeFit[] {\n const out = fitted\n fitted = []\n return out\n },\n /**\n * The first edit made inside `run` may let go of exactly these clips -- the ones a CLIPS_DROPPED refusal named and\n * the person agreed to -- on the figure and version they were named on (designer 2026-09-27). Any other edit that\n * would stop a clip is refused and asked about.\n */\n withConsent<T>(given: FigureClipConsentFor, run: () => T): T {\n consent = given\n try {\n return run()\n } finally {\n consent = undefined\n }\n },\n undo() {\n return tracked('undo', () => workspace.undo(writable()))\n },\n redo() {\n return tracked('redo', () => workspace.redo(writable()))\n },\n source() {\n const { context } = readable()\n return workspace.export({ context }).text\n },\n /**\n * Saves the model, and the card's picture when the caller managed to take one.\n *\n * The picture is the caller's because taking it needs a canvas, and this session is the place that knows\n * nothing about drawing. A save with no picture is a save: a tab in the background cannot draw, and the\n * source matters more than the card (see `thumbnail.ts`).\n */\n async save({ thumbnail, type, namespace }: { thumbnail?: string; type?: string; namespace?: string } = {}) {\n const control = writable(),\n requestEpoch = epoch\n const exported = workspace.export(control)\n /* Read with the text it goes with: an edit while saving is not what this save holds. */\n const proposalKeys = inEffect()\n const sentCatalog = { ...catalog }\n saving = true\n catalogSending = sentCatalog\n catalogWritten = {}\n try {\n /* Only the catalogue changed: the source is not written again -- a released figure would be made a draft for nothing. */\n if (id === undefined || workspace.read().dirty) await saveSource()\n if (requestEpoch !== epoch) return read()\n if (id !== undefined && Object.keys(sentCatalog).length) {\n const seen = Object.fromEntries(Object.keys(sentCatalog).map(key => [key, catalogSeen[key as keyof FigureCatalogPatch] ?? null])) as FigureCatalogSeen\n try {\n await store.updateCatalog(id, sentCatalog, seen)\n } catch (failure) {\n /* The fields stay held, as typed; what the row holds now is what the next save expects -- it writes over it. */\n const fields = (failure as { extensions?: { fields?: FigureCatalogConflict[] } })?.extensions?.fields\n if ((failure as { code?: string })?.code === 'FIGURE_CATALOG_CONFLICT' && requestEpoch === epoch && fields)\n for (const { field, now } of fields) if (field in catalog) (catalogSeen as Record<string, unknown>)[field] = now\n throw failure\n }\n if (requestEpoch !== epoch) return read()\n catalogWritten = sentCatalog\n /* The row holds what was sent: a field changed again on the way is next compared with that. */\n for (const key of Object.keys(sentCatalog) as (keyof FigureCatalogPatch)[])\n if (sameValue(catalog[key], sentCatalog[key])) delete catalogSeen[key]\n else (catalogSeen as Record<string, unknown>)[key] = catalogValue(sentCatalog[key])\n /* What was sent is saved; a field changed again while it was on its way stays held. */\n const next = { ...catalog }\n for (const key of Object.keys(sentCatalog) as (keyof FigureCatalogPatch)[]) if (sameValue(next[key], sentCatalog[key])) delete next[key]\n catalog = next\n }\n } finally {\n if (requestEpoch === epoch) saving = false\n catalogSending = undefined\n }\n return read()\n\n async function saveSource() {\n let record: FigureProductRecord\n try {\n record = await store.save({ id, source: exported.text, expectedSource: baseline, creationId, thumbnail, proposalKeys, ...(id || !type ? {} : { type }), ...(id || !namespace ? {} : { namespace }) })\n } catch (error) {\n /*\n A save that failed may still have landed: the answer lost on the way back (SAVE_UNREACHABLE), or a second\n try refused because the first did land -- its expected source is the old one (FIGURE_SOURCE_CONFLICT). Only\n those are read back; a refusal on grounds -- permission, validation -- stays a failure whatever the row\n holds. Read back, every field the save writes must be what was sent: the source, the picture, the type\n (designer 2026-09-27: a network failure alone does not say nothing was saved; nor does a matching source\n alone say it was).\n */\n const code = (error as { code?: string })?.code\n const unknown = code === 'SAVE_UNREACHABLE' || code === 'FIGURE_SOURCE_CONFLICT'\n const landed = unknown && id !== undefined && requestEpoch === epoch && store.readBack ? await store.readBack(id).catch(() => undefined) : undefined\n const held = landed ? serializeFigureAsset(parseFigureAsset(landed.source)) : undefined\n /* The picture is compared by the name the server keeps it under: the hash of its bytes (ADR-0104). */\n const holds = async (sent?: string) => sent === undefined || (!!landed && landed.thumbnailHash !== undefined && landed.thumbnailHash === (await thumbnailHashOf(sent)))\n const same = !!landed && held === exported.text && (await holds(thumbnail)) && (type === undefined || landed.type === type)\n if (same) record = landed!\n else if (\n code === 'FIGURE_SOURCE_CONFLICT' &&\n landed &&\n held !== undefined &&\n unconfirmed.has(held) &&\n /* Every field that earlier save wrote, not the source alone: nothing not compared is written over. */\n (await holds(unconfirmed.get(held)!.thumbnail))\n ) {\n /*\n The row holds a text this session sent and never heard back about -- edited further since, the new text\n is not it. The server is known to hold what was sent: this save is sent again, once, conditional on that\n server text as the expected source (designer 2026-09-27: \"the sent content is confirmed on the server\").\n */\n baseline = landed.source\n unconfirmed.clear()\n record = await store.save({ id, source: exported.text, expectedSource: baseline, creationId, thumbnail, proposalKeys, ...(id || !type ? {} : { type }), ...(id || !namespace ? {} : { namespace }) })\n } else {\n if (code === 'SAVE_UNREACHABLE') unconfirmed.set(exported.text, { thumbnail })\n if (code === 'FIGURE_SOURCE_CONFLICT' && requestEpoch === epoch) conflict = { source: landed?.source }\n throw error\n }\n }\n if (requestEpoch !== epoch) return read()\n if (!record.id || (id !== undefined && record.id !== id)) throw Error('저장 응답의 Figure 대상이 다릅니다.')\n if (serializeFigureAsset(parseFigureAsset(record.source)) !== exported.text)\n throw Error('저장 응답이 보낸 모델과 다릅니다. 저장 상태를 다시 확인해 주세요.')\n /* The server has it: the next save expects it, whatever happened on screen meanwhile. */\n id = record.id\n baseline = record.source\n unconfirmed.clear()\n conflict = undefined\n /*\n Edited while it was saving: what was sent is saved, the edits since are not -- they stay, and the model stays\n unsaved (the workspace refuses a stale acknowledgement). Never marked saved, never wiped.\n */\n if (workspace.read().revision === exported.revision) workspace.acknowledgeSaved(exported)\n }\n }\n }\n}\nexport type FigureProductSession = ReturnType<typeof createFigureProductSession>\n"]}
@@ -77,6 +77,11 @@ export declare function sessionRefusalOf(error: unknown, say: Say): string | nul
77
77
  export declare function pipeRefusalOf(error: unknown, say: Say): string | null;
78
78
  export declare function paletteRefusalOf(error: unknown, say: Say): string | null;
79
79
  export declare function fieldRefusalOf(error: unknown, say: Say): string | null;
80
+ /**
81
+ * Another editor changed a catalogue field first (FIGURE_CATALOG_CONFLICT): each field by its label, with what the row
82
+ * holds now. The values typed are still held; saving again writes them over. Nothing for any other error.
83
+ */
84
+ export declare function catalogConflictOf(error: unknown, say: Say): string | null;
80
85
  export declare function editRefusalOf(error: unknown, say: Say): string;
81
86
  /**
82
87
  * A data field, a binding, a status port, a motion group or a clip's tracks refused (ADR-0051 §8, §3.2), said with the ids
@@ -363,7 +363,8 @@ export function fieldRefusalOf(error, say) {
363
363
  }
364
364
  /** A refusal said in the author's words, or nothing when the screen has none for it. */
365
365
  function knownRefusalOf(error, say) {
366
- return (sessionRefusalOf(error, say) ??
366
+ return (catalogConflictOf(error, say) ??
367
+ sessionRefusalOf(error, say) ??
367
368
  sizeRangeRefusalOf(error, say) ??
368
369
  inputRangeRefusalOf(error, say) ??
369
370
  repeatPitchRefusalOf(error, say) ??
@@ -381,6 +382,26 @@ function knownRefusalOf(error, say) {
381
382
  slotLayoutRefusalOf(error, say) ??
382
383
  dataMotionRefusalOf(error, say));
383
384
  }
385
+ /** The words for each catalogue field, as the properties tab labels it. */
386
+ const CATALOG_FIELD_LABEL = {
387
+ type: 'figure.label.figure-identifier',
388
+ category: 'figure.label.category',
389
+ tags: 'figure.label.tags'
390
+ };
391
+ /**
392
+ * Another editor changed a catalogue field first (FIGURE_CATALOG_CONFLICT): each field by its label, with what the row
393
+ * holds now. The values typed are still held; saving again writes them over. Nothing for any other error.
394
+ */
395
+ export function catalogConflictOf(error, say) {
396
+ const failure = error;
397
+ if (failure?.code !== 'FIGURE_CATALOG_CONFLICT')
398
+ return null;
399
+ const valueOf = (now) => now === null || (Array.isArray(now) && !now.length) ? say('figure.text.catalog-value-empty', {}) : Array.isArray(now) ? now.join(', ') : now;
400
+ const changes = (failure.extensions?.fields ?? [])
401
+ .map(({ field, now }) => `${CATALOG_FIELD_LABEL[field] ? say(CATALOG_FIELD_LABEL[field], {}) : field}: ${valueOf(now)}`)
402
+ .join(' · ');
403
+ return say('figure.text.catalog-conflict', { changes });
404
+ }
384
405
  export function editRefusalOf(error, say) {
385
406
  return knownRefusalOf(error, say) ?? say('figure.text.edit-refused', { code: codeOf(error) ?? '' });
386
407
  }