@floless/app 0.138.2 → 0.139.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/autostart.mjs +6 -2
- package/desktop-access-production-manifest.mjs +7 -0
- package/dist/floless-server.cjs +157202 -70901
- package/dist/schemas/model.continuation.v1.schema.json +19 -0
- package/dist/schemas/model.continuation.v2.schema.json +19 -0
- package/dist/schemas/model.query-response.v1.schema.json +95 -0
- package/dist/schemas/model.query-response.v2.schema.json +80 -0
- package/dist/schemas/model.query.v1.schema.json +87 -0
- package/dist/schemas/model.query.v2.schema.json +87 -0
- package/dist/schemas/model.snap-candidate.v1.schema.json +48 -0
- package/dist/schemas/model.snap-constraint.v1.schema.json +18 -0
- package/dist/schemas/model.snap-query.v1.schema.json +24 -0
- package/dist/schemas/model.snap-result.v1.schema.json +33 -0
- package/dist/schemas/model.snapshot.v1.schema.json +136 -0
- package/dist/schemas/revit.model.v1.schema.json +24 -0
- package/dist/schemas/steel.model.v2.schema.json +45 -6
- package/dist/skills/floless-app-approval/SKILL.md +19 -5
- package/dist/skills/floless-app-bridge/SKILL.md +19 -6
- package/dist/skills/floless-app-knowledge/SKILL.md +22 -1
- package/dist/skills/floless-app-new-workflow/SKILL.md +31 -27
- package/dist/skills/floless-app-new-workflow/references/build-and-verify.md +13 -12
- package/dist/skills/floless-app-onboarding/SKILL.md +3 -3
- package/dist/skills/floless-app-onboarding/references/floless-app-tour.md +16 -9
- package/dist/skills/floless-app-steel-model/SKILL.md +11 -2
- package/dist/skills/floless-app-steel-model/references/detail-from-a-screenshot.md +95 -0
- package/dist/skills/floless-app-steel-takeoff/SKILL.md +142 -21
- package/dist/skills/floless-app-steel-takeoff/references/elevation-registration.md +19 -0
- package/dist/skills/floless-app-tweak-contract/SKILL.md +42 -8
- package/dist/skills/floless-app-vectorize/SKILL.md +19 -6
- package/dist/skills/floless-app-workflows/SKILL.md +30 -3
- package/dist/skills/floless-app-workflows/references/workspace-data.md +77 -4
- package/dist/templates/floless-workspace-model-report.flo +77 -0
- package/dist/templates/revit-model.flo +111 -0
- package/dist/web/app.css +415 -177
- package/dist/web/app.js +302 -51
- package/dist/web/aware.js +1357 -1032
- package/dist/web/chat.css +692 -0
- package/dist/web/chat.js +2651 -0
- package/dist/web/commands-revit.js +42 -0
- package/dist/web/commands-shell.js +531 -70
- package/dist/web/commands-steel.js +344 -146
- package/dist/web/commands.js +1 -1
- package/dist/web/index.html +283 -77
- package/dist/web/instructor.js +217 -36
- package/dist/web/left-pane.js +636 -0
- package/dist/web/model-artifact-loader.js +75 -0
- package/dist/web/model-authoring-gestures.js +141 -0
- package/dist/web/model-cad-tools.js +20 -0
- package/dist/web/model-clip-gesture.js +148 -0
- package/dist/web/model-clip-list.js +156 -0
- package/dist/web/model-clip-session.js +274 -0
- package/dist/web/model-clip-three-overlay.js +295 -0
- package/dist/web/model-clip-three-preview.js +59 -0
- package/dist/web/model-editor-contract.js +519 -0
- package/dist/web/model-editor-revit-adapter.js +139 -0
- package/dist/web/model-editor-shell.js +271 -0
- package/dist/web/model-editor-state-recovery.js +44 -0
- package/dist/web/model-editor-steel-adapter.js +410 -0
- package/dist/web/model-editor.css +268 -0
- package/dist/web/model-frame.js +192 -0
- package/dist/web/model-inspector.js +128 -0
- package/dist/web/model-measure.js +390 -0
- package/dist/web/model-navigation-controls.js +246 -0
- package/dist/web/model-orientation-overlay.js +217 -0
- package/dist/web/model-panel-bridge.js +230 -0
- package/dist/web/model-pointer-dock.js +164 -0
- package/dist/web/model-revit-module.js +83 -0
- package/dist/web/model-selection-coordinator.js +151 -0
- package/dist/web/model-selection-tools.js +290 -0
- package/dist/web/model-snap-contract.js +267 -0
- package/dist/web/model-snapping.js +497 -0
- package/dist/web/model-spatial-panel.js +294 -0
- package/dist/web/model-spatial-tools.js +249 -0
- package/dist/web/model-tree.js +47 -0
- package/dist/web/model-viewport-lighting.js +166 -0
- package/dist/web/model-viewport-revit-adapter.js +1224 -0
- package/dist/web/model-viewport-state.js +505 -0
- package/dist/web/model-viewport-steel-adapter.js +150 -0
- package/dist/web/model-viewport-toolbar.js +516 -0
- package/dist/web/model-viewport.js +717 -0
- package/dist/web/panels.js +8 -15
- package/dist/web/renderers.js +3 -0
- package/dist/web/revit-editor.css +35 -0
- package/dist/web/revit-editor.html +74 -0
- package/dist/web/revit-editor.js +845 -0
- package/dist/web/steel-3d-core.js +16 -44
- package/dist/web/steel-3d-view.js +1384 -633
- package/dist/web/steel-canvas-guidance.js +3 -1
- package/dist/web/steel-editor.html +2121 -1253
- package/dist/web/steel-filter.html +5 -1
- package/dist/web/steel-model-v2-commands.js +72 -1
- package/dist/web/steel-split-view.js +5 -39
- package/dist/web/steel-view-generation.js +107 -17
- package/dist/web/vector-3d.html +12 -0
- package/dist/web/workspaces.js +2154 -283
- package/distribution-profile-active.mjs +2 -0
- package/distribution-profile-production.mjs +47 -0
- package/distribution-profile-shared.mjs +8 -0
- package/distribution-profile.mjs +18 -0
- package/distribution-resource-inventory.mjs +81 -0
- package/launch.mjs +18 -10
- package/log.mjs +2 -1
- package/managed-runtime-policy.mjs +104 -0
- package/model-reader-policy-active.mjs +7 -0
- package/network-policy-active.mjs +6 -0
- package/package.json +17 -2
- package/post-update-marker.mjs +3 -1
- package/rvt-production-uat-authority.mjs +60 -0
- package/teardown.mjs +4 -3
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
import * as THREE from 'three';
|
|
2
|
+
|
|
3
|
+
export const MODEL_ORIENTATION_POSE_VERSION = 1;
|
|
4
|
+
export const MODEL_ORIENTATION_PORT = 'model.orientation.v1';
|
|
5
|
+
export const MODEL_VIEW_CUBE_PX = 84;
|
|
6
|
+
export const MODEL_AXIS_TRIAD_PX = 78;
|
|
7
|
+
|
|
8
|
+
export const MODEL_CUBE_FACES = Object.freeze([
|
|
9
|
+
Object.freeze({ label: 'RIGHT', view: 'right' }), Object.freeze({ label: 'LEFT', view: 'left' }),
|
|
10
|
+
Object.freeze({ label: 'BACK', view: 'back' }), Object.freeze({ label: 'FRONT', view: 'front' }),
|
|
11
|
+
Object.freeze({ label: 'TOP', view: 'top' }), Object.freeze({ label: 'BOTTOM', view: 'bottom' }),
|
|
12
|
+
]);
|
|
13
|
+
|
|
14
|
+
const FACE_LABELS = Object.freeze(Object.fromEntries(MODEL_CUBE_FACES.map(({ view, label }) => [view, label])));
|
|
15
|
+
const TRIAD_AXES = Object.freeze([
|
|
16
|
+
Object.freeze(['X', '#ef4444', Object.freeze([1, 0, 0])]),
|
|
17
|
+
Object.freeze(['Y', '#22c55e', Object.freeze([0, 1, 0])]),
|
|
18
|
+
Object.freeze(['Z', '#3b82f6', Object.freeze([0, 0, 1])]),
|
|
19
|
+
]);
|
|
20
|
+
const KEY_ADJACENCY = Object.freeze({
|
|
21
|
+
front: Object.freeze({ ArrowUp: 'top', ArrowDown: 'bottom', ArrowLeft: 'left', ArrowRight: 'right' }),
|
|
22
|
+
back: Object.freeze({ ArrowUp: 'top', ArrowDown: 'bottom', ArrowLeft: 'right', ArrowRight: 'left' }),
|
|
23
|
+
right: Object.freeze({ ArrowUp: 'top', ArrowDown: 'bottom', ArrowLeft: 'front', ArrowRight: 'back' }),
|
|
24
|
+
left: Object.freeze({ ArrowUp: 'top', ArrowDown: 'bottom', ArrowLeft: 'back', ArrowRight: 'front' }),
|
|
25
|
+
top: Object.freeze({ ArrowUp: 'back', ArrowDown: 'front', ArrowLeft: 'left', ArrowRight: 'right' }),
|
|
26
|
+
bottom: Object.freeze({ ArrowUp: 'front', ArrowDown: 'back', ArrowLeft: 'left', ArrowRight: 'right' }),
|
|
27
|
+
iso: Object.freeze({ ArrowUp: 'top', ArrowDown: 'front', ArrowLeft: 'left', ArrowRight: 'right' }),
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
const finiteVec3 = (value) => Array.isArray(value) && value.length === 3 && value.every(Number.isFinite);
|
|
31
|
+
|
|
32
|
+
/** Validate and copy the exact provider-neutral pose boundary used by shared model chrome. */
|
|
33
|
+
export function modelOrientationPose(value) {
|
|
34
|
+
const camera = value?.camera;
|
|
35
|
+
if (value?.v !== MODEL_ORIENTATION_POSE_VERSION || !finiteVec3(camera?.position)
|
|
36
|
+
|| !finiteVec3(camera?.target) || !finiteVec3(camera?.up)) {
|
|
37
|
+
throw new TypeError('model.orientation.v1 requires finite camera position, target, and up vectors.');
|
|
38
|
+
}
|
|
39
|
+
if (new THREE.Vector3().fromArray(camera.position).distanceToSquared(new THREE.Vector3().fromArray(camera.target)) <= Number.EPSILON) {
|
|
40
|
+
throw new TypeError('model.orientation.v1 camera position must differ from its target.');
|
|
41
|
+
}
|
|
42
|
+
if (new THREE.Vector3().fromArray(camera.up).lengthSq() <= Number.EPSILON) {
|
|
43
|
+
throw new TypeError('model.orientation.v1 camera up vector must be non-zero.');
|
|
44
|
+
}
|
|
45
|
+
return Object.freeze({
|
|
46
|
+
v: MODEL_ORIENTATION_POSE_VERSION,
|
|
47
|
+
camera: Object.freeze({
|
|
48
|
+
position: Object.freeze([...camera.position]),
|
|
49
|
+
target: Object.freeze([...camera.target]),
|
|
50
|
+
up: Object.freeze([...camera.up]),
|
|
51
|
+
}),
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** Convert a cube hit into the target-to-camera direction convention shared by every provider. */
|
|
56
|
+
export function modelCubeDirection(point) {
|
|
57
|
+
if (!finiteVec3(point)) throw new TypeError('ViewCube hit point must be a finite vector.');
|
|
58
|
+
const snap = (value) => Math.abs(value) > 0.6 ? Math.sign(value) : 0;
|
|
59
|
+
const direction = point.map(snap);
|
|
60
|
+
return direction.some(Boolean) ? Object.freeze(direction) : null;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export function nextModelCubeKeyboardView(current, key) {
|
|
64
|
+
if (key === 'Home') return 'iso';
|
|
65
|
+
return KEY_ADJACENCY[current]?.[key] ?? current;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function faceTexture(label) {
|
|
69
|
+
const canvas = document.createElement('canvas'); canvas.width = canvas.height = 128;
|
|
70
|
+
const context = canvas.getContext('2d');
|
|
71
|
+
context.fillStyle = '#1e293b'; context.fillRect(0, 0, 128, 128);
|
|
72
|
+
context.strokeStyle = '#475569'; context.lineWidth = 6; context.strokeRect(4, 4, 120, 120);
|
|
73
|
+
context.fillStyle = '#e2e8f0'; context.font = 'bold 20px ui-sans-serif,system-ui,sans-serif';
|
|
74
|
+
context.textAlign = 'center'; context.textBaseline = 'middle'; context.fillText(label, 64, 64);
|
|
75
|
+
return new THREE.CanvasTexture(canvas);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function triadTip(label, color, position) {
|
|
79
|
+
const canvas = document.createElement('canvas'); canvas.width = canvas.height = 64;
|
|
80
|
+
const context = canvas.getContext('2d');
|
|
81
|
+
context.font = 'bold 46px ui-sans-serif,system-ui,sans-serif'; context.textAlign = 'center'; context.textBaseline = 'middle';
|
|
82
|
+
context.lineWidth = 8; context.lineJoin = 'round'; context.strokeStyle = 'rgba(2,8,23,.9)'; context.strokeText(label, 32, 34);
|
|
83
|
+
context.fillStyle = color; context.fillText(label, 32, 34);
|
|
84
|
+
const sprite = new THREE.Sprite(new THREE.SpriteMaterial({ map: new THREE.CanvasTexture(canvas) }));
|
|
85
|
+
sprite.position.copy(position); sprite.scale.setScalar(0.85);
|
|
86
|
+
return sprite;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function disposeScene(scene) {
|
|
90
|
+
const geometries = new Set(); const materials = new Set(); const textures = new Set();
|
|
91
|
+
scene.traverse((object) => {
|
|
92
|
+
if (object.geometry) geometries.add(object.geometry);
|
|
93
|
+
for (const material of Array.isArray(object.material) ? object.material : (object.material ? [object.material] : [])) {
|
|
94
|
+
materials.add(material); if (material.map) textures.add(material.map);
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
for (const texture of textures) texture.dispose();
|
|
98
|
+
for (const material of materials) material.dispose();
|
|
99
|
+
for (const geometry of geometries) geometry.dispose();
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
function renderAccessibleName(canvas, status, highlighted) {
|
|
103
|
+
const face = FACE_LABELS[highlighted];
|
|
104
|
+
const label = highlighted === 'iso' ? 'Isometric' : `${face[0]}${face.slice(1).toLowerCase()}`;
|
|
105
|
+
canvas.setAttribute('aria-label', `ViewCube. ${label} view selected. Arrow keys choose a face, Home chooses isometric, Enter applies.`);
|
|
106
|
+
status.textContent = `${label} view selected`;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/** Mount Steel's canonical WebGL ViewCube and world-axis triad against a model.orientation.v1 port. */
|
|
110
|
+
export function mountModelOrientationOverlay({
|
|
111
|
+
cubeHost, triadHost, orientation, escapeTarget = null,
|
|
112
|
+
createRenderer = (options) => new THREE.WebGLRenderer(options),
|
|
113
|
+
}) {
|
|
114
|
+
if (!cubeHost || !triadHost) throw new Error('Orientation overlay needs separate cube and triad hosts.');
|
|
115
|
+
if (!orientation || typeof orientation.getPose !== 'function' || typeof orientation.subscribe !== 'function'
|
|
116
|
+
|| typeof orientation.applyView !== 'function' || typeof orientation.applyDirection !== 'function') {
|
|
117
|
+
throw new TypeError('Orientation overlay needs a model.orientation.v1 port.');
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
const cleanups = []; let destroyed = false;
|
|
121
|
+
const cleanup = (fn) => { let done = false; const once = () => { if (!done) { done = true; fn(); } }; cleanups.push(once); return once; };
|
|
122
|
+
const rollback = () => { for (let i = cleanups.length - 1; i >= 0; i -= 1) { try { cleanups[i](); } catch (_) {} } };
|
|
123
|
+
|
|
124
|
+
try {
|
|
125
|
+
cubeHost.classList.add('model-view-cube-host'); cleanup(() => cubeHost.classList.remove('model-view-cube-host'));
|
|
126
|
+
triadHost.classList.add('model-axis-triad-host'); cleanup(() => triadHost.classList.remove('model-axis-triad-host'));
|
|
127
|
+
|
|
128
|
+
const cubeRenderer = createRenderer({ antialias: true, alpha: true }, 'view-cube');
|
|
129
|
+
cleanup(() => { cubeRenderer.dispose(); cubeRenderer.forceContextLoss?.(); });
|
|
130
|
+
cubeRenderer.setPixelRatio(Math.min(window.devicePixelRatio || 1, 2)); cubeRenderer.setSize(MODEL_VIEW_CUBE_PX, MODEL_VIEW_CUBE_PX);
|
|
131
|
+
const cubeCanvas = cubeRenderer.domElement; cubeCanvas.tabIndex = 0; cubeCanvas.setAttribute('role', 'button');
|
|
132
|
+
cubeCanvas.dataset.tip = 'ViewCube: arrows choose a face, Home chooses ISO, Enter applies, Escape returns to the model';
|
|
133
|
+
cubeHost.appendChild(cubeCanvas); cleanup(() => cubeCanvas.remove());
|
|
134
|
+
|
|
135
|
+
const status = document.createElement('span'); status.className = 'model-view-cube-status'; status.setAttribute('aria-live', 'polite'); status.setAttribute('aria-atomic', 'true');
|
|
136
|
+
cubeHost.appendChild(status); cleanup(() => status.remove());
|
|
137
|
+
|
|
138
|
+
const cubeScene = new THREE.Scene(); cleanup(() => disposeScene(cubeScene));
|
|
139
|
+
const cubeCamera = new THREE.PerspectiveCamera(40, 1, 0.1, 20); cubeCamera.position.set(0, 0, 5); cubeCamera.up.set(0, 0, 1);
|
|
140
|
+
const faceMaterials = MODEL_CUBE_FACES.map((face) => new THREE.MeshBasicMaterial({ map: faceTexture(face.label) }));
|
|
141
|
+
const cubeMesh = new THREE.Mesh(new THREE.BoxGeometry(1.9, 1.9, 1.9), faceMaterials);
|
|
142
|
+
cubeMesh.add(new THREE.LineSegments(new THREE.EdgesGeometry(cubeMesh.geometry), new THREE.LineBasicMaterial({ color: 0x64748b })));
|
|
143
|
+
cubeScene.add(cubeMesh);
|
|
144
|
+
|
|
145
|
+
const triadRenderer = createRenderer({ antialias: true, alpha: true }, 'world-axes');
|
|
146
|
+
cleanup(() => { triadRenderer.dispose(); triadRenderer.forceContextLoss?.(); });
|
|
147
|
+
triadRenderer.setPixelRatio(Math.min(window.devicePixelRatio || 1, 2)); triadRenderer.setSize(MODEL_AXIS_TRIAD_PX, MODEL_AXIS_TRIAD_PX);
|
|
148
|
+
const triadCanvas = triadRenderer.domElement; triadCanvas.setAttribute('aria-hidden', 'true');
|
|
149
|
+
triadHost.appendChild(triadCanvas); cleanup(() => triadCanvas.remove());
|
|
150
|
+
const triadScene = new THREE.Scene(); cleanup(() => disposeScene(triadScene));
|
|
151
|
+
const triadCamera = new THREE.OrthographicCamera(-2.1, 2.1, 2.1, -2.1, 0.1, 20); triadCamera.position.set(0, 0, 5);
|
|
152
|
+
const triadGroup = new THREE.Group(); const sourceY = new THREE.Vector3(0, 1, 0);
|
|
153
|
+
for (const [label, color, rawDirection] of TRIAD_AXES) {
|
|
154
|
+
const direction = new THREE.Vector3().fromArray(rawDirection); const material = new THREE.MeshBasicMaterial({ color });
|
|
155
|
+
const shaft = new THREE.Mesh(new THREE.CylinderGeometry(0.06, 0.06, 1.05, 8), material);
|
|
156
|
+
shaft.quaternion.setFromUnitVectors(sourceY, direction); shaft.position.copy(direction).multiplyScalar(0.525);
|
|
157
|
+
const head = new THREE.Mesh(new THREE.ConeGeometry(0.16, 0.34, 12), material);
|
|
158
|
+
head.quaternion.copy(shaft.quaternion); head.position.copy(direction).multiplyScalar(1.22);
|
|
159
|
+
triadGroup.add(shaft, head, triadTip(label, color, direction.clone().multiplyScalar(1.62)));
|
|
160
|
+
}
|
|
161
|
+
triadGroup.add(new THREE.Mesh(new THREE.SphereGeometry(0.1, 12, 8), new THREE.MeshBasicMaterial({ color: 0xe2e8f0 })));
|
|
162
|
+
triadScene.add(triadGroup);
|
|
163
|
+
|
|
164
|
+
let highlighted = 'front';
|
|
165
|
+
const reflectHighlight = () => {
|
|
166
|
+
faceMaterials.forEach((material, index) => material.color.setHex(MODEL_CUBE_FACES[index].view === highlighted ? 0x93c5fd : 0xffffff));
|
|
167
|
+
renderAccessibleName(cubeCanvas, status, highlighted); cubeRenderer.render(cubeScene, cubeCamera);
|
|
168
|
+
};
|
|
169
|
+
const pointerRay = new THREE.Raycaster(); const pointer = new THREE.Vector2();
|
|
170
|
+
const onPointerDown = (event) => {
|
|
171
|
+
event.preventDefault(); cubeCanvas.focus();
|
|
172
|
+
const rect = cubeCanvas.getBoundingClientRect();
|
|
173
|
+
pointer.set(((event.clientX - rect.left) / rect.width) * 2 - 1, -((event.clientY - rect.top) / rect.height) * 2 + 1);
|
|
174
|
+
pointerRay.setFromCamera(pointer, cubeCamera);
|
|
175
|
+
const hit = pointerRay.intersectObject(cubeMesh, false)[0]; if (!hit?.face) return;
|
|
176
|
+
const direction = modelCubeDirection(cubeMesh.worldToLocal(hit.point.clone()).toArray()); if (!direction) return;
|
|
177
|
+
if (direction.filter(Boolean).length === 1) {
|
|
178
|
+
const face = MODEL_CUBE_FACES[hit.face.materialIndex]; if (!face) return;
|
|
179
|
+
highlighted = face.view; reflectHighlight(); orientation.applyView(face.view);
|
|
180
|
+
} else {
|
|
181
|
+
orientation.applyDirection(direction);
|
|
182
|
+
}
|
|
183
|
+
};
|
|
184
|
+
cubeCanvas.addEventListener('pointerdown', onPointerDown); cleanup(() => cubeCanvas.removeEventListener('pointerdown', onPointerDown));
|
|
185
|
+
const onKeyDown = (event) => {
|
|
186
|
+
if (event.key === 'Enter' || event.key === ' ') { event.preventDefault(); orientation.applyView(highlighted); return; }
|
|
187
|
+
if (event.key === 'Escape') { event.preventDefault(); (escapeTarget ?? cubeHost.closest('[data-model-stage]') ?? cubeHost.parentElement)?.focus?.(); return; }
|
|
188
|
+
const next = nextModelCubeKeyboardView(highlighted, event.key);
|
|
189
|
+
if (next !== highlighted) { event.preventDefault(); highlighted = next; reflectHighlight(); }
|
|
190
|
+
};
|
|
191
|
+
cubeCanvas.addEventListener('keydown', onKeyDown); cleanup(() => cubeCanvas.removeEventListener('keydown', onKeyDown));
|
|
192
|
+
|
|
193
|
+
const displayQuaternion = new THREE.Quaternion(); const look = new THREE.Matrix4();
|
|
194
|
+
const update = (rawPose) => {
|
|
195
|
+
if (destroyed) return;
|
|
196
|
+
const pose = modelOrientationPose(rawPose); const position = new THREE.Vector3().fromArray(pose.camera.position);
|
|
197
|
+
const target = new THREE.Vector3().fromArray(pose.camera.target); const up = new THREE.Vector3().fromArray(pose.camera.up).normalize();
|
|
198
|
+
look.lookAt(position, target, up); displayQuaternion.setFromRotationMatrix(look).invert();
|
|
199
|
+
cubeMesh.quaternion.copy(displayQuaternion); triadGroup.quaternion.copy(displayQuaternion);
|
|
200
|
+
cubeRenderer.render(cubeScene, cubeCamera); triadRenderer.render(triadScene, triadCamera);
|
|
201
|
+
};
|
|
202
|
+
let emittedSynchronously = false;
|
|
203
|
+
const unsubscribe = orientation.subscribe((pose) => { emittedSynchronously = true; update(pose); });
|
|
204
|
+
cleanup(typeof unsubscribe === 'function' ? unsubscribe : () => {});
|
|
205
|
+
if (!emittedSynchronously) throw new Error('model.orientation.v1 subscribe() must synchronously emit its current pose.');
|
|
206
|
+
// Read once as an explicit contract check too; providers must keep getPose and the initial emission aligned.
|
|
207
|
+
modelOrientationPose(orientation.getPose()); reflectHighlight();
|
|
208
|
+
|
|
209
|
+
return Object.freeze({
|
|
210
|
+
port: MODEL_ORIENTATION_PORT, update,
|
|
211
|
+
render() { if (!destroyed) { cubeRenderer.render(cubeScene, cubeCamera); triadRenderer.render(triadScene, triadCamera); } },
|
|
212
|
+
destroy() { if (destroyed) return; destroyed = true; rollback(); },
|
|
213
|
+
});
|
|
214
|
+
} catch (error) {
|
|
215
|
+
destroyed = true; rollback(); throw error;
|
|
216
|
+
}
|
|
217
|
+
}
|
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* THE LEFT MODEL SECTION CONTRACT — one for every model editor (Steel, Revit, and the ones after them).
|
|
3
|
+
*
|
|
4
|
+
* The main window (web/left-pane.js) owns the Model section of its left panel: its tab strip, its layout and
|
|
5
|
+
* where it sits. A model editor contributes that section's tabs over this channel — from the workspace's model
|
|
6
|
+
* frame (#ws-frame-model), or opened full-window from Workflows → Edit contract (#contract-editor-frame, which
|
|
7
|
+
* then leaves the left panel beside it) — and can ask for one of them to be shown (`reveal`). Two kinds of tab,
|
|
8
|
+
* chosen per tab:
|
|
9
|
+
*
|
|
10
|
+
* - LIST tabs (snapshot.tabs, contents in snapshot.bodies): data — groups and objects. The main window draws
|
|
11
|
+
* them the same way for every model, and owns selecting (Ctrl and Shift included: it sends the ids the click
|
|
12
|
+
* selects, and the editor's select(id, ids) selects them), expanding and following the selection. An editor
|
|
13
|
+
* whose contents are a list of its model's objects contributes this kind.
|
|
14
|
+
* - PANEL tabs (snapshot.panelTabs): the editor's own controls. The main window shows a frame in the section;
|
|
15
|
+
* the editor moves its real elements into it (createPanelHost) and they keep their own code, listeners,
|
|
16
|
+
* menus, focus and caret. Nothing is drawn twice and there is no second copy to keep in step. An editor
|
|
17
|
+
* whose tab is a tool rather than a list contributes this kind. A panel tab that shows where the selection is
|
|
18
|
+
* (steel's Objects) declares `follows: true`: it gets the Follow selection switch, and does the following itself.
|
|
19
|
+
*
|
|
20
|
+
* Neither kind floats over the canvas: an editor has no panel of its own for these. Messages carry the
|
|
21
|
+
* main window's generation, which changes whenever it mounts a model, so a departing editor cannot write
|
|
22
|
+
* into the next one's section.
|
|
23
|
+
*/
|
|
24
|
+
const CHANNEL = 'floless:model-panel';
|
|
25
|
+
const VERSION = 1;
|
|
26
|
+
|
|
27
|
+
export function createModelSelectionOriginGuard() {
|
|
28
|
+
let programmaticDepth = 0;
|
|
29
|
+
return Object.freeze({
|
|
30
|
+
run(action) {
|
|
31
|
+
programmaticDepth += 1;
|
|
32
|
+
try { return action(); }
|
|
33
|
+
finally { programmaticDepth -= 1; }
|
|
34
|
+
},
|
|
35
|
+
isProgrammatic() { return programmaticDepth > 0; },
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function serializeModelPanelNodes(host, path = 'root') {
|
|
40
|
+
const nodes = [];
|
|
41
|
+
for (const [index, child] of [...(host?.children || [])].entries()) {
|
|
42
|
+
if (child.classList.contains('revit-explorer-label')) { nodes.push({ kind: 'label', label: child.textContent || '' }); continue; }
|
|
43
|
+
if (child.classList.contains('explorer-empty')) { nodes.push({ kind: 'note', label: child.textContent || '' }); continue; }
|
|
44
|
+
if (child.classList.contains('revit-tree-branch')) {
|
|
45
|
+
const trigger = child.querySelector(':scope > .explorer-row');
|
|
46
|
+
const group = child.querySelector(':scope > .revit-tree-children');
|
|
47
|
+
if (trigger) {
|
|
48
|
+
const children = serializeModelPanelNodes(group, `${path}.${index}`);
|
|
49
|
+
nodes.push({ label: trigger.querySelector('.row-label')?.textContent || trigger.textContent || '',
|
|
50
|
+
count: trigger.querySelector('.explorer-count')?.textContent || null, children,
|
|
51
|
+
tip: trigger.dataset.tip || null,
|
|
52
|
+
lazy: !children.length && Number(trigger.querySelector('.explorer-count')?.textContent || 0) > 0,
|
|
53
|
+
expanded: trigger.getAttribute('aria-expanded') === 'true', groupId: `${path}.${index}` });
|
|
54
|
+
}
|
|
55
|
+
continue;
|
|
56
|
+
}
|
|
57
|
+
if (child.classList.contains('explorer-row')) nodes.push({ label: child.querySelector('.row-label')?.textContent || child.textContent || '',
|
|
58
|
+
count: child.querySelector('.explorer-count')?.textContent || null, entityId: child.dataset.entityId || null,
|
|
59
|
+
tip: child.dataset.tip || null });
|
|
60
|
+
}
|
|
61
|
+
return nodes;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export function expandModelPanelGroup(tabs, byId, groupId) {
|
|
65
|
+
const parts = String(groupId || '').split('.');
|
|
66
|
+
const tabKey = parts.shift();
|
|
67
|
+
const tab = tabs.find((item) => item.key === tabKey);
|
|
68
|
+
if (!tab || !parts.length) return false;
|
|
69
|
+
let host = byId(tab.bodyId);
|
|
70
|
+
for (const raw of parts) {
|
|
71
|
+
if (!/^\d+$/.test(raw)) return false;
|
|
72
|
+
const branch = [...(host?.children || [])][Number(raw)];
|
|
73
|
+
if (!branch?.classList.contains('revit-tree-branch')) return false;
|
|
74
|
+
const trigger = branch.querySelector(':scope > .explorer-row');
|
|
75
|
+
const children = branch.querySelector(':scope > .revit-tree-children');
|
|
76
|
+
if (!trigger || !children) return false;
|
|
77
|
+
if (!children.children.length) trigger.click();
|
|
78
|
+
host = children;
|
|
79
|
+
}
|
|
80
|
+
return true;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// The main window's panel frame is an about:blank iframe, so it shares this origin and an editor may move its
|
|
84
|
+
// own elements into it. It gets the editor's stylesheets and follows the editor's <html> attributes (the
|
|
85
|
+
// theme), so what moves renders as it did at home. Returns the function that stops following.
|
|
86
|
+
export function prepareHostDocument(hostDoc, sourceDoc) {
|
|
87
|
+
// about:blank has no doctype, so it opens in quirks mode; the editors' CSS is written for standards mode.
|
|
88
|
+
if (hostDoc.compatMode === 'BackCompat') { hostDoc.open(); hostDoc.write('<!DOCTYPE html><html><head></head><body></body></html>'); hostDoc.close(); }
|
|
89
|
+
for (const node of sourceDoc.querySelectorAll('link[rel~="stylesheet"], style')) {
|
|
90
|
+
const copy = hostDoc.importNode(node, true);
|
|
91
|
+
if (node.href) copy.href = node.href; // resolved here: the copy must not depend on the host's base URL
|
|
92
|
+
hostDoc.head.append(copy);
|
|
93
|
+
}
|
|
94
|
+
const follow = () => {
|
|
95
|
+
const from = sourceDoc.documentElement, to = hostDoc.documentElement;
|
|
96
|
+
for (const { name } of [...to.attributes]) if (!from.hasAttribute(name)) to.removeAttribute(name);
|
|
97
|
+
for (const { name, value } of [...from.attributes]) to.setAttribute(name, value);
|
|
98
|
+
};
|
|
99
|
+
follow();
|
|
100
|
+
const observer = new sourceDoc.defaultView.MutationObserver(follow);
|
|
101
|
+
observer.observe(sourceDoc.documentElement, { attributes: true });
|
|
102
|
+
return () => observer.disconnect();
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// An editor's PANEL tabs (see the contract above). The main window makes a frame, #left-model-panel, for each
|
|
106
|
+
// model it mounts; `root` MOVES into it, so every tab keeps its own code, listeners, menus, focus and caret.
|
|
107
|
+
// `bodies` maps a tab key to its element inside `root`; the one shown gets `.on`. `install(doc)` adds what the
|
|
108
|
+
// editor's page has and a bare document lacks — its tooltips.
|
|
109
|
+
// A key pressed in the tabs reaches the editor's shortcuts, as it did on the editor's page, except: a key typed
|
|
110
|
+
// into a field stays with the field (but F1 and Ctrl/Cmd+S, which the editor always took from a field, still
|
|
111
|
+
// go); Enter or Space on a control is that control's own click; and a key a control handled stays handled.
|
|
112
|
+
export function createPanelHost({ win = window, root, bodies, install = (_doc) => {} }) {
|
|
113
|
+
let host = null;
|
|
114
|
+
const refuse = (key, reason) => {
|
|
115
|
+
try { win.console?.warn?.(`[model-panel] cannot show the "${key}" tab: ${reason}`); } catch { /* reporting must not throw */ }
|
|
116
|
+
return false;
|
|
117
|
+
};
|
|
118
|
+
const forwardKey = (event) => {
|
|
119
|
+
const target = event.target;
|
|
120
|
+
const typing = /^(INPUT|SELECT|TEXTAREA)$/.test(target?.tagName || '') || !!target?.isContentEditable;
|
|
121
|
+
const always = event.key === 'F1' || ((event.ctrlKey || event.metaKey) && String(event.key).toLowerCase() === 's');
|
|
122
|
+
const activates = (event.key === 'Enter' || event.key === ' ')
|
|
123
|
+
&& !!target?.closest?.('button,a[href],[role=button],[role=menuitem],[role=checkbox],[role=switch],[role=tab],[role=option]');
|
|
124
|
+
if (event.defaultPrevented || activates || (typing && !always)) return;
|
|
125
|
+
const copy = new win.KeyboardEvent('keydown', { key: event.key, code: event.code, ctrlKey: event.ctrlKey, shiftKey: event.shiftKey,
|
|
126
|
+
altKey: event.altKey, metaKey: event.metaKey, repeat: event.repeat, bubbles: true, cancelable: true });
|
|
127
|
+
win.document.dispatchEvent(copy);
|
|
128
|
+
if (copy.defaultPrevented) event.preventDefault();
|
|
129
|
+
};
|
|
130
|
+
return Object.freeze({
|
|
131
|
+
show(key) {
|
|
132
|
+
if (!Object.hasOwn(bodies, key)) return refuse(key, 'this editor has no such tab');
|
|
133
|
+
let doc = null;
|
|
134
|
+
try { doc = win.parent.document.getElementById('left-model-panel')?.contentDocument || null; }
|
|
135
|
+
catch (error) { return refuse(key, `the main window cannot be reached (${error?.message || error})`); }
|
|
136
|
+
if (!doc?.body) return refuse(key, 'the main window has no Model panel frame');
|
|
137
|
+
if (host?.doc !== doc) { // a new frame: the main window makes one per model it mounts
|
|
138
|
+
host?.stopFollowing();
|
|
139
|
+
const stopFollowing = prepareHostDocument(doc, win.document);
|
|
140
|
+
host = { doc, stopFollowing };
|
|
141
|
+
// When the main window replaces the frame, stop following the theme into the one it discarded.
|
|
142
|
+
doc.defaultView?.addEventListener('pagehide', () => { stopFollowing(); if (host?.doc === doc) host = null; }, { once: true });
|
|
143
|
+
doc.body.classList.add('model-panel-host'); root.hidden = false; doc.body.append(root);
|
|
144
|
+
install(doc); doc.addEventListener('keydown', forwardKey);
|
|
145
|
+
}
|
|
146
|
+
for (const [name, body] of Object.entries(bodies)) body.classList.toggle('on', name === key);
|
|
147
|
+
return true;
|
|
148
|
+
},
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
export function createModelPanelBridge({ win = window, origin = location.origin, snapshot, selectedId, selectedIds = () => {
|
|
153
|
+
const id = selectedId(); return typeof id === 'string' ? [id] : [];
|
|
154
|
+
}, select, expand, panel = (_tab, _person, _follow) => false }) {
|
|
155
|
+
let requested = false;
|
|
156
|
+
let generation = null;
|
|
157
|
+
let revision = 0;
|
|
158
|
+
let lifecycle = 'loading';
|
|
159
|
+
let datasetKey = null;
|
|
160
|
+
let disposed = false;
|
|
161
|
+
|
|
162
|
+
const send = (message) => {
|
|
163
|
+
if (!requested || disposed || win.parent === win) return false;
|
|
164
|
+
win.parent.postMessage({ channel: CHANNEL, version: VERSION, generation, revision: ++revision, ...message }, origin);
|
|
165
|
+
return true;
|
|
166
|
+
};
|
|
167
|
+
const publishStatus = (message = '') => send({ type: 'status', state: lifecycle, message });
|
|
168
|
+
const publishSnapshot = () => {
|
|
169
|
+
if (lifecycle !== 'ready') return false;
|
|
170
|
+
return send({ type: 'snapshot', snapshot: { ...snapshot(), datasetKey } });
|
|
171
|
+
};
|
|
172
|
+
const publishSelection = (selectionOrigin = 'tree') => lifecycle === 'ready' && send({ type: 'selection', selectedId: selectedId(), selectedIds: selectedIds(), selectionOrigin });
|
|
173
|
+
const actionResult = (requestId, ok, message = '') => send({ type: 'action-result', requestId, ok, message });
|
|
174
|
+
|
|
175
|
+
const receive = (event) => {
|
|
176
|
+
if (disposed || win.parent === win || event.source !== win.parent || event.origin !== origin) return;
|
|
177
|
+
const data = event.data;
|
|
178
|
+
if (data?.channel !== CHANNEL || data.version !== VERSION) return;
|
|
179
|
+
if (data.type === 'hello' && Number.isInteger(data.generation)) {
|
|
180
|
+
if (generation !== data.generation) revision = 0;
|
|
181
|
+
generation = data.generation; requested = true;
|
|
182
|
+
if (lifecycle === 'ready') publishSnapshot(); else publishStatus();
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
if (!requested || data.generation !== generation) return;
|
|
186
|
+
if (data.type === 'release') { requested = false; generation = null; return; }
|
|
187
|
+
if (data.type !== 'action' || typeof data.requestId !== 'string') return;
|
|
188
|
+
if (data.action === 'select' && typeof data.entityId === 'string') {
|
|
189
|
+
let ok = false;
|
|
190
|
+
// entityId is the row clicked; entityIds what the click selects (a Ctrl/Shift click: more rows, or none left).
|
|
191
|
+
const ids = Array.isArray(data.entityIds) ? data.entityIds.filter((id) => typeof id === 'string') : [data.entityId];
|
|
192
|
+
try { ok = !!select(data.entityId, ids); if (ok) publishSnapshot(); publishSelection('tree'); }
|
|
193
|
+
catch (error) { try { win.console?.error?.('[model-panel] select action failed', error); } catch { /* reporting must still continue */ } }
|
|
194
|
+
actionResult(data.requestId, ok, ok ? '' : 'That object is no longer in this model revision.');
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
if (data.action === 'expand' && typeof data.groupId === 'string') {
|
|
198
|
+
let ok = false;
|
|
199
|
+
try { ok = data.datasetKey === datasetKey && !!expand(data.groupId); if (ok) publishSnapshot(); }
|
|
200
|
+
catch (error) { try { win.console?.error?.('[model-panel] expand action failed', error); } catch { /* reporting must still continue */ } ok = false; }
|
|
201
|
+
actionResult(data.requestId, ok, ok ? '' : 'That model group has changed. Try opening it again.');
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
204
|
+
// The main window shows one of the snapshot's panelTabs (tab: its key) or has left them (tab: null). `person` is
|
|
205
|
+
// true when a person chose it (a click on the tab), not the main window restoring or following the editor's reveal.
|
|
206
|
+
// `follow` is the Follow selection switch, for a panel tab that declared `follows` (it re-arrives when the switch flips).
|
|
207
|
+
if (data.action === 'panel' && (data.tab === null || typeof data.tab === 'string')) {
|
|
208
|
+
let ok = false;
|
|
209
|
+
try { ok = lifecycle === 'ready' && !!panel(data.tab, data.person === true, data.follow === true); }
|
|
210
|
+
catch (error) { try { win.console?.error?.('[model-panel] panel action failed', error); } catch { /* reporting must still continue */ } }
|
|
211
|
+
actionResult(data.requestId, ok, ok ? '' : 'This tab could not open here. Choose it again, or reopen the model.');
|
|
212
|
+
return;
|
|
213
|
+
}
|
|
214
|
+
actionResult(data.requestId, false, 'That model action is unavailable.');
|
|
215
|
+
};
|
|
216
|
+
|
|
217
|
+
win.addEventListener('message', receive);
|
|
218
|
+
// An editor that boots through async imports is listening only after the parent's load-time hello has
|
|
219
|
+
// already gone by, so it says it is available and the parent says hello again.
|
|
220
|
+
if (win.parent !== win) win.parent.postMessage({ channel: CHANNEL, version: VERSION, type: 'available' }, origin);
|
|
221
|
+
return Object.freeze({
|
|
222
|
+
publishSnapshot,
|
|
223
|
+
publishSelection,
|
|
224
|
+
// Ask the main window to show one of the snapshot's tabs — what a toolbar button that opens a tab does.
|
|
225
|
+
reveal: (tab) => lifecycle === 'ready' && send({ type: 'reveal', tab }),
|
|
226
|
+
ready(key) { lifecycle = 'ready'; datasetKey = key; publishSnapshot(); },
|
|
227
|
+
failed(message) { lifecycle = 'failed'; datasetKey = null; publishStatus(message); },
|
|
228
|
+
dispose() { if (disposed) return; disposed = true; requested = false; win.removeEventListener('message', receive); },
|
|
229
|
+
});
|
|
230
|
+
}
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Canonical pointer/snap chrome for every model editor.
|
|
3
|
+
*
|
|
4
|
+
* Steel owns the visual language. Providers supply only plans and small state ports; this module owns
|
|
5
|
+
* the rendered anatomy, glyphs, ARIA reflection, focus order, and subscription lifecycle. It does not
|
|
6
|
+
* know how a Steel member or Revit mesh is selected and it never stores provider state.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
const MEMBER_ICON = '<svg viewBox="0 0 18 18" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" aria-hidden="true"><path d="M4 4h10M4 14h10M9 4v10"/></svg>';
|
|
10
|
+
const CONNECTION_ICON = '<svg viewBox="0 0 18 18" fill="none" stroke="currentColor" stroke-width="1.4" aria-hidden="true"><rect x="4" y="4" width="10" height="10" rx="1"/><circle cx="6.5" cy="6.5" r="1.15" fill="currentColor" stroke="none"/><circle cx="11.5" cy="6.5" r="1.15" fill="currentColor" stroke="none"/><circle cx="6.5" cy="11.5" r="1.15" fill="currentColor" stroke="none"/><circle cx="11.5" cy="11.5" r="1.15" fill="currentColor" stroke="none"/></svg>';
|
|
11
|
+
const GRID_ICON = '<svg viewBox="0 0 18 18" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" aria-hidden="true"><path d="M6 2v14M12 2v14M2 6h14M2 12h14"/></svg>';
|
|
12
|
+
const DIM_ICON = '<svg viewBox="0 0 18 18" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" aria-hidden="true"><path d="M3 5v8M15 5v8M3 9h12M3 9l3-2M3 9l3 2M15 9l-3-2M15 9l-3 2"/></svg>';
|
|
13
|
+
const REFERENCE_ICON = '<svg viewBox="0 0 18 18" fill="none" stroke="currentColor" stroke-width="1.35" stroke-linejoin="round" aria-hidden="true"><path d="M2.5 5.5l5-2.5 5 2.5-5 2.5-5-2.5Z"/><path d="M2.5 5.5v5l5 2.5 5-2.5v-5M7.5 8v5"/><path d="M10.5 8.5l2-1 3 1.5v3l-3 1.5"/></svg>';
|
|
14
|
+
const CATEGORY_ICON = '<svg viewBox="0 0 18 18" fill="none" stroke="currentColor" stroke-width="1.4" aria-hidden="true"><rect x="2.5" y="2.5" width="5" height="5" rx="1"/><rect x="10.5" y="2.5" width="5" height="5" rx="1"/><rect x="2.5" y="10.5" width="5" height="5" rx="1"/><rect x="10.5" y="10.5" width="5" height="5" rx="1"/></svg>';
|
|
15
|
+
const TYPE_ICON = '<svg viewBox="0 0 18 18" fill="none" stroke="currentColor" stroke-width="1.4" stroke-linecap="round" aria-hidden="true"><path d="M3 4h12M5 9h8M7 14h4"/></svg>';
|
|
16
|
+
const CLASS_ICON = '<svg viewBox="0 0 18 18" fill="none" stroke="currentColor" stroke-width="1.4" stroke-linejoin="round" aria-hidden="true"><path d="M9 2.5l6 3.2v6.6L9 15.5l-6-3.2V5.7L9 2.5Z"/><path d="M3 5.7L9 9l6-3.3M9 9v6.5"/></svg>';
|
|
17
|
+
|
|
18
|
+
const frozen = (value) => Object.freeze(value);
|
|
19
|
+
const selection = (id, command, carrier, label, tip, icon, extra = {}) => frozen({ id, command, carrier, label, tip, icon, ...extra });
|
|
20
|
+
const snap = (id, command, carrier, label, tip, glyph, extra = {}) => frozen({ id, command, carrier, label, tip, glyph, ...extra });
|
|
21
|
+
|
|
22
|
+
export const STEEL_POINTER_DOCK_PLAN = frozen({
|
|
23
|
+
schema: 'floless.model-pointer-dock/v1',
|
|
24
|
+
selection: frozen([
|
|
25
|
+
selection('member', 'steel.selection-filter#members', 'data-command-id="steel.selection-filter#members"', 'Members', 'Members — click to choose which member types can be selected · Alt+click: toggle all types', MEMBER_ICON, { fly: 'members', caret: true }),
|
|
26
|
+
selection('connection', 'steel.selection-filter#connections', 'data-command-id="steel.selection-filter#connections"', 'Connections', 'Connections — click to choose which connection types can be selected · Alt+click: toggle all types', CONNECTION_ICON, { fly: 'connections', caret: true }),
|
|
27
|
+
selection('grid', 'steel.selection-filter#grid lines', 'data-command-id="steel.selection-filter#grid lines"', 'Grid lines', 'Grid lines — allow selecting grid lines (area-select / Ctrl+A)', GRID_ICON),
|
|
28
|
+
selection('dim', 'steel.selection-filter#dimensions', 'data-command-id="steel.selection-filter#dimensions"', 'Dimensions', 'Dimensions — allow selecting dimensions', DIM_ICON),
|
|
29
|
+
selection('reference', 'steel.selection-filter#reference models', 'data-command-id="steel.selection-filter#reference models"', 'Reference models', 'Reference models — allow selecting reference models. Visibility and snapping are controlled separately.', REFERENCE_ICON),
|
|
30
|
+
]),
|
|
31
|
+
snaps: frozen([
|
|
32
|
+
snap('end', 'steel.snap-toggle#Endpoint', 'data-command-id="steel.snap-toggle#Endpoint"', 'Endpoint', 'Endpoint snap', '◻'),
|
|
33
|
+
snap('int', 'steel.snap-toggle#Intersection', 'data-command-id="steel.snap-toggle#Intersection"', 'Intersection', 'Intersection snap', '✕'),
|
|
34
|
+
snap('mid', 'steel.snap-toggle#Midpoint', 'data-command-id="steel.snap-toggle#Midpoint"', 'Midpoint', 'Midpoint snap', '△'),
|
|
35
|
+
snap('line', 'steel.snap-toggle#Nearest', 'data-command-id="steel.snap-toggle#Nearest"', 'Nearest', 'Nearest snap', '⧗'),
|
|
36
|
+
snap('perp', 'steel.snap-toggle#Perpendicular', 'data-command-id="steel.snap-toggle#Perpendicular"', 'Perpendicular', 'Perpendicular snap — square (90°) to a target line from your first point', '⟂'),
|
|
37
|
+
snap('par', 'steel.snap-toggle#Parallel', 'data-command-id="steel.snap-toggle#Parallel"', 'Parallel', 'Parallel snap — run parallel to a nearby line', '∥'),
|
|
38
|
+
snap('ext', 'steel.snap-toggle#Extension', 'data-command-id="steel.snap-toggle#Extension"', 'Extension', 'Extension snap', '┈'),
|
|
39
|
+
snap('3d', 'steel.snap-3d', 'data-command-id="steel.snap-3d"', '3D snapping', 'On: snap to points at any elevation. Off: stay on the working plane when adding, or the endpoint’s original elevation when dragging. Hold Alt when starting an endpoint drag to change only its elevation.', '3D', { mode3d: true }),
|
|
40
|
+
]),
|
|
41
|
+
actions: frozen([]),
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
export const REVIT_POINTER_DOCK_PLAN = frozen({
|
|
45
|
+
schema: 'floless.model-pointer-dock/v1',
|
|
46
|
+
selection: frozen([
|
|
47
|
+
selection('category', 'revit.selection-filter#category', 'data-command-id="revit.selection-filter#category"', 'Categories', 'Choose which Revit categories can be selected', CATEGORY_ICON, { fly: 'category', caret: true }),
|
|
48
|
+
selection('type', 'revit.selection-filter#type', 'data-command-id="revit.selection-filter#type"', 'Types', 'Choose which Revit types can be selected', TYPE_ICON, { fly: 'type', caret: true }),
|
|
49
|
+
selection('family', 'revit.selection-filter#family', 'data-command-id="revit.selection-filter#family"', 'Families or classes', 'Choose which Revit families or provider classes can be selected', CLASS_ICON, { fly: 'family', caret: true }),
|
|
50
|
+
]),
|
|
51
|
+
snaps: frozen([
|
|
52
|
+
snap('mesh-vertex', 'revit.snap-mesh-vertex', 'data-command-id="revit.snap-mesh-vertex"', 'Mesh vertex', 'Snap to an authenticated triangle-mesh vertex — not a Revit semantic endpoint', '◻'),
|
|
53
|
+
snap('mesh-edge-midpoint', 'revit.snap-mesh-edge-midpoint', 'data-command-id="revit.snap-mesh-edge-midpoint"', 'Mesh edge midpoint', 'Snap to the midpoint of an authenticated triangle edge', '△'),
|
|
54
|
+
snap('mesh-edge-nearest', 'revit.snap-mesh-edge-nearest', 'data-command-id="revit.snap-mesh-edge-nearest"', 'Mesh edge nearest', 'Snap to the nearest point on an authenticated triangle edge', '⧗'),
|
|
55
|
+
snap('surface', 'revit.snap-surface', 'data-command-id="revit.snap-surface"', 'Mesh surface', 'Snap to the authenticated model surface under the pointer', '●'),
|
|
56
|
+
]),
|
|
57
|
+
actions: frozen([
|
|
58
|
+
frozen({ id: 'measure', command: 'revit.measure', carrier: 'data-command-id="revit.measure"', label: 'Dimension', tip: 'Measure between two snapped model points (D)', kind: 'toggle' }),
|
|
59
|
+
frozen({ id: 'axis-f', command: 'revit.measure-axis-free', carrier: 'data-command-id="revit.measure-axis-free"', label: 'F', tip: 'Free/aligned measurement — clear X/Y/Z locks (F)', kind: 'toggle', axis: 'f' }),
|
|
60
|
+
frozen({ id: 'axis-x', command: 'revit.measure-axis-x', carrier: 'data-command-id="revit.measure-axis-x"', label: 'X', tip: 'Lock measurement to active-frame X — combine with Y/Z (X)', kind: 'toggle', axis: 'x' }),
|
|
61
|
+
frozen({ id: 'axis-y', command: 'revit.measure-axis-y', carrier: 'data-command-id="revit.measure-axis-y"', label: 'Y', tip: 'Lock measurement to active-frame Y — combine with X/Z (Y)', kind: 'toggle', axis: 'y' }),
|
|
62
|
+
frozen({ id: 'axis-z', command: 'revit.measure-axis-z', carrier: 'data-command-id="revit.measure-axis-z"', label: 'Z', tip: 'Lock measurement to active-frame Z / elevation — Alt is temporary vertical (Z)', kind: 'toggle', axis: 'z' }),
|
|
63
|
+
frozen({ id: 'clear', command: 'revit.measure-clear', carrier: 'data-command-id="revit.measure-clear"', label: 'Clear', tip: 'Clear session dimensions', kind: 'button' }),
|
|
64
|
+
]),
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
function escapeAttr(value) {
|
|
68
|
+
return String(value ?? '').replaceAll('&', '&').replaceAll('"', '"').replaceAll('<', '<').replaceAll('>', '>');
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export function pointerDockCarriers(plan) {
|
|
72
|
+
return [...(plan.selection ?? []), ...(plan.snaps ?? []), ...(plan.actions ?? [])].map((item) => item.command).filter(Boolean);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export function renderSelectionBarMarkup(plan) {
|
|
76
|
+
if (!plan.selection?.length) return '';
|
|
77
|
+
return '<span class="lbl">Select</span>' + plan.selection.map((item) => {
|
|
78
|
+
const fly = item.fly ? ` data-fly="${escapeAttr(item.fly)}"` : '';
|
|
79
|
+
const caret = item.caret ? '<span class="car" aria-hidden="true">▾</span>' : '';
|
|
80
|
+
return `<button type="button" ${item.carrier} data-cls="${escapeAttr(item.id)}"${fly} aria-label="${escapeAttr(item.label)}" data-tip="${escapeAttr(item.tip)}">${item.icon ?? ''}${caret}</button>`;
|
|
81
|
+
}).join('');
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export function renderSnapBarMarkup(plan) {
|
|
85
|
+
if (!plan.snaps?.length) return '';
|
|
86
|
+
return '<span class="lbl">Snap</span>' + plan.snaps.map((item) => {
|
|
87
|
+
const mode = item.mode3d ? ' data-snap3d' : ` data-snap="${escapeAttr(item.id)}"`;
|
|
88
|
+
return `<button type="button" ${item.carrier}${mode} aria-label="${escapeAttr(item.label)}" data-tip="${escapeAttr(item.tip)}" aria-pressed="false">${escapeAttr(item.glyph)}</button>`;
|
|
89
|
+
}).join('');
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export function renderModuleActionsMarkup(plan) {
|
|
93
|
+
if (!plan.actions?.length) return '';
|
|
94
|
+
return plan.actions.map((item) => `<button type="button" data-model-action="${escapeAttr(item.id)}"${item.axis ? ` data-model-axis="${escapeAttr(item.axis)}"` : ''} ${item.carrier} data-tip="${escapeAttr(item.tip)}"${item.kind === 'toggle' ? ' aria-pressed="false"' : ''}>${escapeAttr(item.label)}</button>`).join('')
|
|
95
|
+
+ '<span class="model-dock-status" data-model-action-status role="status" aria-live="polite">Ready</span>';
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function validatePort(port, name) {
|
|
99
|
+
if (!port) return;
|
|
100
|
+
for (const method of ['getState', 'subscribe']) if (typeof port[method] !== 'function') throw new Error(`${name} port is missing ${method}().`);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/** Render and optionally wire the shared pointer chrome. Provider ports remain the only state owners. */
|
|
104
|
+
export function mountModelPointerDock({ selectionHost = null, snapHost = null, actionsHost = null, plan, ports = {} }) {
|
|
105
|
+
if (!plan || plan.schema !== 'floless.model-pointer-dock/v1') throw new Error('Unsupported model pointer-dock plan.');
|
|
106
|
+
validatePort(ports.selection, 'selection'); validatePort(ports.snap, 'snap'); validatePort(ports.measure, 'measure');
|
|
107
|
+
const cleanup = []; let destroyed = false;
|
|
108
|
+
const listen = (node, type, handler) => { node.addEventListener(type, handler); cleanup.push(() => node.removeEventListener(type, handler)); };
|
|
109
|
+
try {
|
|
110
|
+
if (selectionHost) { selectionHost.classList.add('model-select-bar'); selectionHost.innerHTML = renderSelectionBarMarkup(plan); selectionHost.hidden = !plan.selection?.length; }
|
|
111
|
+
if (snapHost) { snapHost.classList.add('model-snap-bar'); snapHost.innerHTML = renderSnapBarMarkup(plan); snapHost.hidden = !plan.snaps?.length; }
|
|
112
|
+
if (actionsHost) { actionsHost.classList.add('model-module-actions'); actionsHost.innerHTML = renderModuleActionsMarkup(plan); actionsHost.hidden = !plan.actions?.length; }
|
|
113
|
+
|
|
114
|
+
const reflectSelection = (state = ports.selection?.getState?.() ?? {}) => {
|
|
115
|
+
selectionHost?.querySelectorAll('[data-cls]').forEach((button) => {
|
|
116
|
+
const value = state[button.dataset.cls]; const partial = value === 'partial'; const on = value !== false && value !== 'off';
|
|
117
|
+
button.classList.toggle('on', on && !partial); button.classList.toggle('partial', partial); button.classList.toggle('off', !on);
|
|
118
|
+
button.setAttribute('aria-pressed', partial ? 'true' : String(on));
|
|
119
|
+
let dot = button.querySelector('.seldot');
|
|
120
|
+
if (partial && !dot) { dot = selectionHost.ownerDocument.createElement('span'); dot.className = 'seldot'; button.appendChild(dot); }
|
|
121
|
+
else if (!partial) dot?.remove();
|
|
122
|
+
});
|
|
123
|
+
};
|
|
124
|
+
const reflectSnap = (state = ports.snap?.getState?.() ?? {}) => {
|
|
125
|
+
snapHost?.querySelectorAll('[data-snap],[data-snap3d]').forEach((button) => { const key = button.dataset.snap ?? '3d'; const on = state[key] !== false; button.classList.toggle('on', on); button.setAttribute('aria-pressed', String(on)); });
|
|
126
|
+
};
|
|
127
|
+
const reflectMeasure = (state = ports.measure?.getState?.() ?? {}) => {
|
|
128
|
+
const button = actionsHost?.querySelector('[data-model-action="measure"]');
|
|
129
|
+
if (button) { button.classList.toggle('on', state.armed === true); button.setAttribute('aria-pressed', String(state.armed === true)); }
|
|
130
|
+
const status = actionsHost?.querySelector('[data-model-action-status]');
|
|
131
|
+
if (status) status.textContent = state.status ?? (state.armed ? (state.hasDraft ? 'Pick point 2' : 'Pick point 1') : (state.count ? `${state.count} placed` : 'Ready'));
|
|
132
|
+
const locks = new Set(state.locks ?? []);
|
|
133
|
+
actionsHost?.querySelectorAll('[data-model-axis]').forEach((axisButton) => {
|
|
134
|
+
const on = axisButton.dataset.modelAxis === 'f' ? locks.size === 0 : locks.has(axisButton.dataset.modelAxis);
|
|
135
|
+
axisButton.classList.toggle('on', on); axisButton.setAttribute('aria-pressed', String(on));
|
|
136
|
+
axisButton.hidden = state.armed !== true;
|
|
137
|
+
});
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
selectionHost?.querySelectorAll('[data-cls]').forEach((button) => {
|
|
141
|
+
listen(button, 'click', (event) => {
|
|
142
|
+
// Selection flyouts are mounted at document.body. Keep this opening click
|
|
143
|
+
// from reaching their shared outside-click closer in the same event turn.
|
|
144
|
+
event.stopPropagation();
|
|
145
|
+
ports.selection?.toggle?.(button.dataset.cls, event);
|
|
146
|
+
});
|
|
147
|
+
listen(button, 'keydown', (event) => { if ((event.key === 'Enter' || event.key === ' ') && !event.repeat) { event.preventDefault(); event.stopPropagation(); ports.selection?.toggle?.(button.dataset.cls, event); } });
|
|
148
|
+
});
|
|
149
|
+
snapHost?.querySelectorAll('[data-snap],[data-snap3d]').forEach((button) => listen(button, 'click', () => ports.snap?.toggle?.(button.dataset.snap ?? '3d')));
|
|
150
|
+
const measure = actionsHost?.querySelector('[data-model-action="measure"]'); if (measure) listen(measure, 'click', () => ports.measure?.toggle?.());
|
|
151
|
+
actionsHost?.querySelectorAll('[data-model-axis]').forEach((button) => listen(button, 'click', () => ports.measure?.setAxisLock?.(button.dataset.modelAxis)));
|
|
152
|
+
const clear = actionsHost?.querySelector('[data-model-action="clear"]'); if (clear) listen(clear, 'click', () => ports.measure?.clear?.());
|
|
153
|
+
|
|
154
|
+
for (const [port, reflect] of [[ports.selection, reflectSelection], [ports.snap, reflectSnap], [ports.measure, reflectMeasure]]) {
|
|
155
|
+
if (!port) continue; reflect(port.getState()); const unsub = port.subscribe(reflect); if (typeof unsub === 'function') cleanup.push(unsub);
|
|
156
|
+
}
|
|
157
|
+
} catch (error) {
|
|
158
|
+
while (cleanup.length) { try { cleanup.pop()(); } catch {} }
|
|
159
|
+
throw error;
|
|
160
|
+
}
|
|
161
|
+
return Object.freeze({
|
|
162
|
+
destroy() { if (destroyed) return; destroyed = true; while (cleanup.length) { try { cleanup.pop()(); } catch {} } },
|
|
163
|
+
});
|
|
164
|
+
}
|