@ifc-lite/viewer 1.17.4 → 1.17.6

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 (80) hide show
  1. package/.turbo/turbo-build.log +16 -16
  2. package/.turbo/turbo-typecheck.log +1 -1
  3. package/CHANGELOG.md +117 -0
  4. package/DESKTOP_CONTRACT_VERSION +1 -1
  5. package/dist/assets/{basketViewActivator-BmnNtVfZ.js → basketViewActivator-86rgogji.js} +1 -1
  6. package/dist/assets/drawing-2d-DoxKMqbO.js +257 -0
  7. package/dist/assets/{exporters-ChAtBmlj.js → exporters-CcPS9MK5.js} +2274 -2227
  8. package/dist/assets/{geometry.worker-BQ0rzNo-.js → geometry.worker-BFUYA08u.js} +1 -1
  9. package/dist/assets/ids-DQ5jY0E8.js +1 -0
  10. package/dist/assets/ifc-lite_bg-BINvzoCP.wasm +0 -0
  11. package/dist/assets/{index-Co8E2-FE.js → index-Bfms9I4A.js} +35160 -33084
  12. package/dist/assets/index-_bfZsDCC.css +1 -0
  13. package/dist/assets/{native-bridge-BRvbckFQ.js → native-bridge-DUyLCMZS.js} +104 -104
  14. package/dist/assets/{sandbox-DZiNLNMk.js → sandbox-C8575tul.js} +4340 -4322
  15. package/dist/assets/{server-client-BV8zHZ7Y.js → server-client-BuZK7OST.js} +1 -1
  16. package/dist/assets/{wasm-bridge-g01g7T9b.js → wasm-bridge-JsqEGDV8.js} +1 -1
  17. package/dist/index.html +8 -7
  18. package/index.html +1 -0
  19. package/package.json +7 -7
  20. package/src/App.tsx +16 -2
  21. package/src/components/viewer/CesiumOverlay.tsx +62 -19
  22. package/src/components/viewer/ChatPanel.tsx +195 -91
  23. package/src/components/viewer/MainToolbar.tsx +4 -3
  24. package/src/components/viewer/PropertiesPanel.tsx +16 -2
  25. package/src/components/viewer/SettingsPage.tsx +252 -101
  26. package/src/components/viewer/ThemeSwitch.tsx +63 -7
  27. package/src/components/viewer/ViewerLayout.tsx +1 -0
  28. package/src/components/viewer/Viewport.tsx +14 -2
  29. package/src/components/viewer/ViewportContainer.tsx +49 -64
  30. package/src/components/viewer/ViewportOverlays.tsx +5 -2
  31. package/src/components/viewer/bcf/BCFTopicDetail.tsx +4 -4
  32. package/src/components/viewer/chat/ModelSelector.tsx +90 -54
  33. package/src/components/viewer/properties/GeoreferencingPanel.tsx +113 -51
  34. package/src/components/viewer/properties/LocationMap.tsx +9 -7
  35. package/src/components/viewer/properties/ModelMetadataPanel.tsx +1 -1
  36. package/src/components/viewer/tools/SectionCapControls.tsx +237 -0
  37. package/src/components/viewer/tools/SectionPanel.tsx +39 -18
  38. package/src/components/viewer/useAnimationLoop.ts +9 -1
  39. package/src/components/viewer/useRenderUpdates.ts +1 -1
  40. package/src/hooks/ids/idsDataAccessor.ts +60 -24
  41. package/src/hooks/ingest/viewerModelIngest.ts +7 -2
  42. package/src/hooks/useIfcFederation.ts +326 -71
  43. package/src/hooks/useIfcLoader.ts +1 -0
  44. package/src/hooks/useViewControls.ts +13 -5
  45. package/src/index.css +484 -10
  46. package/src/lib/desktop-entitlement.ts +2 -4
  47. package/src/lib/geo/cesium-bridge.ts +15 -7
  48. package/src/lib/geo/effective-georef.test.ts +73 -0
  49. package/src/lib/geo/effective-georef.ts +111 -0
  50. package/src/lib/geo/reproject.ts +105 -19
  51. package/src/lib/llm/byok-guard.test.ts +77 -0
  52. package/src/lib/llm/byok-guard.ts +39 -0
  53. package/src/lib/llm/free-models.test.ts +0 -6
  54. package/src/lib/llm/models.ts +104 -42
  55. package/src/lib/llm/stream-client.ts +74 -110
  56. package/src/lib/llm/stream-direct.test.ts +130 -0
  57. package/src/lib/llm/stream-direct.ts +316 -0
  58. package/src/lib/llm/types.ts +14 -2
  59. package/src/main.tsx +1 -10
  60. package/src/services/api-keys.ts +73 -0
  61. package/src/store/constants.ts +20 -2
  62. package/src/store/index.ts +12 -5
  63. package/src/store/slices/cesiumSlice.ts +5 -0
  64. package/src/store/slices/chatSlice.test.ts +6 -76
  65. package/src/store/slices/chatSlice.ts +17 -58
  66. package/src/store/slices/sectionSlice.test.ts +87 -7
  67. package/src/store/slices/sectionSlice.ts +151 -5
  68. package/src/store/slices/uiSlice.ts +28 -5
  69. package/src/store/types.ts +26 -0
  70. package/src/utils/nativeSpatialDataStore.ts +4 -1
  71. package/src/utils/viewportUtils.ts +7 -2
  72. package/src/vite-env.d.ts +0 -4
  73. package/dist/assets/drawing-2d-gWfpdfYe.js +0 -257
  74. package/dist/assets/ids-B4jTqB1O.js +0 -1
  75. package/dist/assets/ifc-lite_bg-BX4E7TX8.wasm +0 -0
  76. package/dist/assets/index-DckuDqlv.css +0 -1
  77. package/src/components/viewer/UpgradePage.tsx +0 -71
  78. package/src/lib/desktop/ClerkDesktopEntitlementSync.tsx +0 -175
  79. package/src/lib/llm/ClerkChatSync.tsx +0 -74
  80. package/src/lib/llm/clerk-auth.ts +0 -62
@@ -13,6 +13,7 @@ import { coerceModelForEntitlement, DEFAULT_FREE_MODEL } from '../../lib/llm/mod
13
13
  import { extractCodeBlocks } from '../../lib/llm/code-extractor.js';
14
14
  import type { ScriptDiagnostic } from '../../lib/llm/script-diagnostics.js';
15
15
  import { formatDiagnosticsForPrompt, getPrimaryRootCause, groupDiagnosticsByRootCause } from '../../lib/llm/script-diagnostics.js';
16
+ import { hasAnyApiKey as hasAnyApiKeyAtInit } from '../../services/api-keys.js';
16
17
 
17
18
  const MODEL_STORAGE_KEY = 'ifc-lite-chat-model';
18
19
  const MESSAGES_STORAGE_KEY = 'ifc-lite-chat-messages';
@@ -43,11 +44,9 @@ export interface ChatSlice {
43
44
  chatPendingRepairRequest: ChatRepairRequest | null;
44
45
  /** Auto-captured viewport screenshot (base64 data URL) to include with next LLM message */
45
46
  chatViewportScreenshot: string | null;
46
- /** Clerk JWT for authenticated API calls (null for anonymous/free tier) */
47
- chatAuthToken: string | null;
48
- /** Whether the current user has a pro subscription */
49
- chatHasPro: boolean;
50
- /** Usage info from the server: credits (pro) or request count (free) */
47
+ /** Whether the user has at least one BYOK API key configured */
48
+ chatHasByokKey: boolean;
49
+ /** Usage info from the proxy: request count for free tier */
51
50
  chatUsage: ChatUsage | null;
52
51
  /** User ID used to scope persisted model preference (null for anonymous). */
53
52
  chatStorageUserId: string | null;
@@ -78,18 +77,10 @@ export interface ChatSlice {
78
77
  sendErrorFeedback: (code: string, error: string) => void;
79
78
  /** Store a viewport screenshot to include with the next LLM message */
80
79
  setChatViewportScreenshot: (dataUrl: string | null) => void;
81
- /** Set the Clerk auth token (called by ClerkProvider wrapper when user signs in) */
82
- setChatAuthToken: (token: string | null) => void;
83
- /** Set whether user has pro subscription (called by ClerkProvider wrapper) */
84
- setChatHasPro: (hasPro: boolean) => void;
80
+ /** Set whether user has at least one BYOK API key configured */
81
+ setChatHasByokKey: (hasByokKey: boolean) => void;
85
82
  /** Update usage info from server response headers */
86
83
  setChatUsage: (usage: ChatUsage | null) => void;
87
- /** Switch the active chat user/session context. */
88
- switchChatUserContext: (
89
- userId: string | null,
90
- hasPro: boolean,
91
- options?: { clearPersistedCurrent?: boolean; restoreMessages?: boolean },
92
- ) => void;
93
84
  }
94
85
 
95
86
  export interface ChatUsage {
@@ -279,7 +270,7 @@ export const createChatSlice: StateCreator<ChatSlice, [], [], ChatSlice> = (set,
279
270
  chatMessages: loadStoredMessages(null),
280
271
  chatStatus: 'idle',
281
272
  chatStreamingContent: '',
282
- chatActiveModel: loadValidStoredModel(null, false),
273
+ chatActiveModel: loadValidStoredModel(null, hasAnyApiKeyAtInit()),
283
274
  chatAutoExecute: loadStoredAutoExecute(),
284
275
  chatError: null,
285
276
  chatAbortController: null,
@@ -287,8 +278,7 @@ export const createChatSlice: StateCreator<ChatSlice, [], [], ChatSlice> = (set,
287
278
  chatPendingPrompt: null,
288
279
  chatPendingRepairRequest: null,
289
280
  chatViewportScreenshot: null,
290
- chatAuthToken: null,
291
- chatHasPro: false,
281
+ chatHasByokKey: false,
292
282
  chatUsage: null,
293
283
  chatStorageUserId: null,
294
284
 
@@ -340,12 +330,15 @@ export const createChatSlice: StateCreator<ChatSlice, [], [], ChatSlice> = (set,
340
330
  setChatStreamingContent: (chatStreamingContent) => set({ chatStreamingContent }),
341
331
 
342
332
  setChatActiveModel: (chatActiveModel) => {
343
- const nextModel = coerceModelForEntitlement(chatActiveModel, get().chatHasPro);
333
+ // Accept any model the user picks — the ChatPanel shows an inline key
334
+ // prompt if the selected BYOK model doesn't have a key yet, and guards
335
+ // the send path. Coercion only happens on init and when keys are removed
336
+ // (via setChatHasByokKey).
344
337
  try {
345
338
  const key = getModelStorageKey(get().chatStorageUserId);
346
- localStorage.setItem(key, nextModel);
339
+ localStorage.setItem(key, chatActiveModel);
347
340
  } catch { /* ignore */ }
348
- set({ chatActiveModel: nextModel });
341
+ set({ chatActiveModel });
349
342
  },
350
343
 
351
344
  setChatAutoExecute: (chatAutoExecute) => {
@@ -404,51 +397,17 @@ export const createChatSlice: StateCreator<ChatSlice, [], [], ChatSlice> = (set,
404
397
 
405
398
  setChatViewportScreenshot: (chatViewportScreenshot) => set({ chatViewportScreenshot }),
406
399
 
407
- setChatAuthToken: (chatAuthToken) => set({ chatAuthToken }),
408
-
409
- setChatHasPro: (chatHasPro) => {
410
- const nextModel = coerceModelForEntitlement(get().chatActiveModel, chatHasPro);
400
+ setChatHasByokKey: (chatHasByokKey) => {
401
+ const nextModel = coerceModelForEntitlement(get().chatActiveModel, chatHasByokKey);
411
402
  try {
412
403
  const key = getModelStorageKey(get().chatStorageUserId);
413
404
  localStorage.setItem(key, nextModel);
414
405
  } catch { /* ignore */ }
415
- set({ chatHasPro, chatActiveModel: nextModel });
406
+ set({ chatHasByokKey, chatActiveModel: nextModel });
416
407
  },
417
408
 
418
409
  setChatUsage: (chatUsage) => set({ chatUsage }),
419
410
 
420
- switchChatUserContext: (chatStorageUserId, chatHasPro, options) => {
421
- const state = get();
422
- state.chatAbortController?.abort();
423
- if (options?.clearPersistedCurrent) {
424
- try {
425
- localStorage.removeItem(getMessagesStorageKey(state.chatStorageUserId));
426
- } catch { /* ignore */ }
427
- }
428
- const restoredModel = coerceModelForEntitlement(
429
- loadStoredModel(chatStorageUserId, state.chatActiveModel),
430
- chatHasPro,
431
- );
432
- const restoredMessages = options?.restoreMessages === false
433
- ? []
434
- : loadStoredMessages(chatStorageUserId);
435
- set({
436
- chatStorageUserId,
437
- chatHasPro,
438
- chatActiveModel: restoredModel,
439
- chatMessages: restoredMessages,
440
- chatStatus: 'idle',
441
- chatStreamingContent: '',
442
- chatError: null,
443
- chatAbortController: null,
444
- chatAttachments: [],
445
- chatPendingPrompt: null,
446
- chatPendingRepairRequest: null,
447
- chatViewportScreenshot: null,
448
- chatUsage: null,
449
- });
450
- },
451
-
452
411
  sendErrorFeedback: (code, error) => {
453
412
  const feedbackMessage: ChatMessage = {
454
413
  id: crypto.randomUUID(),
@@ -47,6 +47,14 @@ describe('SectionSlice', () => {
47
47
  assert.strictEqual(state.sectionPlane.axis, 'side');
48
48
  assert.strictEqual(state.sectionPlane.position, 75);
49
49
  });
50
+
51
+ it('should auto-enable the clip so the axis change is immediately visible', () => {
52
+ // Simulate a user who disabled clipping, then picks a new axis — they
53
+ // almost certainly want to see the new cut, not stay in "Clip off".
54
+ state.sectionPlane.enabled = false;
55
+ state.setSectionPlaneAxis('front');
56
+ assert.strictEqual(state.sectionPlane.enabled, true);
57
+ });
50
58
  });
51
59
 
52
60
  describe('setSectionPlanePosition', () => {
@@ -74,6 +82,74 @@ describe('SectionSlice', () => {
74
82
  state.setSectionPlanePosition('50' as any);
75
83
  assert.strictEqual(state.sectionPlane.position, 50);
76
84
  });
85
+
86
+ it('should auto-enable the clip when the slider moves', () => {
87
+ // This is the fix for the "it jitters, doesn't cut" user report: moving
88
+ // the slider implicitly turns on clipping so the user doesn't have to
89
+ // hunt for the toggle.
90
+ state.sectionPlane.enabled = false;
91
+ state.setSectionPlanePosition(42);
92
+ assert.strictEqual(state.sectionPlane.enabled, true);
93
+ assert.strictEqual(state.sectionPlane.position, 42);
94
+ });
95
+ });
96
+
97
+ describe('setSectionPlaneEnabled', () => {
98
+ it('should set enabled to true explicitly', () => {
99
+ state.sectionPlane.enabled = false;
100
+ state.setSectionPlaneEnabled(true);
101
+ assert.strictEqual(state.sectionPlane.enabled, true);
102
+ });
103
+
104
+ it('should set enabled to false explicitly', () => {
105
+ state.setSectionPlaneEnabled(false);
106
+ assert.strictEqual(state.sectionPlane.enabled, false);
107
+ });
108
+ });
109
+
110
+ describe('setSectionShowCap', () => {
111
+ it('should toggle the showCap flag without touching clipping', () => {
112
+ assert.strictEqual(state.sectionPlane.showCap, true);
113
+ state.setSectionShowCap(false);
114
+ assert.strictEqual(state.sectionPlane.showCap, false);
115
+ // Clipping unchanged — cap is a visual-only add-on.
116
+ assert.strictEqual(state.sectionPlane.enabled, true);
117
+ });
118
+ });
119
+
120
+ describe('setSectionShowOutlines', () => {
121
+ it('should toggle the showOutlines flag independently of showCap and clipping', () => {
122
+ assert.strictEqual(state.sectionPlane.showOutlines, true);
123
+ state.setSectionShowOutlines(false);
124
+ assert.strictEqual(state.sectionPlane.showOutlines, false);
125
+ assert.strictEqual(state.sectionPlane.showCap, true);
126
+ assert.strictEqual(state.sectionPlane.enabled, true);
127
+ });
128
+
129
+ it('should set showOutlines back to true', () => {
130
+ state.setSectionShowOutlines(false);
131
+ state.setSectionShowOutlines(true);
132
+ assert.strictEqual(state.sectionPlane.showOutlines, true);
133
+ });
134
+ });
135
+
136
+ describe('setSectionCapStyle', () => {
137
+ it('should partially update the cap style without clobbering other fields', () => {
138
+ const before = state.sectionPlane.capStyle;
139
+ state.setSectionCapStyle({ pattern: 'concrete' });
140
+ assert.strictEqual(state.sectionPlane.capStyle.pattern, 'concrete');
141
+ assert.strictEqual(state.sectionPlane.capStyle.spacingPx, before.spacingPx);
142
+ assert.strictEqual(state.sectionPlane.capStyle.angleRad, before.angleRad);
143
+ });
144
+
145
+ it('should accept custom fill and stroke colours', () => {
146
+ state.setSectionCapStyle({
147
+ fillColor: [0.2, 0.3, 0.4, 1.0],
148
+ strokeColor: [0.9, 0.1, 0.1, 1.0],
149
+ });
150
+ assert.deepStrictEqual(state.sectionPlane.capStyle.fillColor, [0.2, 0.3, 0.4, 1.0]);
151
+ assert.deepStrictEqual(state.sectionPlane.capStyle.strokeColor, [0.9, 0.1, 0.1, 1.0]);
152
+ });
77
153
  });
78
154
 
79
155
  describe('toggleSectionPlane', () => {
@@ -106,13 +182,13 @@ describe('SectionSlice', () => {
106
182
 
107
183
  describe('resetSectionPlane', () => {
108
184
  it('should reset to default values', () => {
109
- // Modify state
110
- state.sectionPlane = {
111
- axis: 'side',
112
- position: 25,
113
- enabled: false,
114
- flipped: true,
115
- };
185
+ state.setSectionPlaneAxis('side');
186
+ state.setSectionPlanePosition(25);
187
+ state.setSectionPlaneEnabled(false);
188
+ state.flipSectionPlane();
189
+ state.setSectionShowCap(false);
190
+ state.setSectionShowOutlines(false);
191
+ state.setSectionCapStyle({ pattern: 'brick' });
116
192
 
117
193
  state.resetSectionPlane();
118
194
 
@@ -120,6 +196,10 @@ describe('SectionSlice', () => {
120
196
  assert.strictEqual(state.sectionPlane.position, SECTION_PLANE_DEFAULTS.POSITION);
121
197
  assert.strictEqual(state.sectionPlane.enabled, SECTION_PLANE_DEFAULTS.ENABLED);
122
198
  assert.strictEqual(state.sectionPlane.flipped, SECTION_PLANE_DEFAULTS.FLIPPED);
199
+ assert.strictEqual(state.sectionPlane.showCap, SECTION_PLANE_DEFAULTS.SHOW_CAP);
200
+ assert.strictEqual(state.sectionPlane.showOutlines, SECTION_PLANE_DEFAULTS.SHOW_OUTLINES);
201
+ // Default cap pattern restored.
202
+ assert.strictEqual(state.sectionPlane.capStyle.pattern, 'diagonal');
123
203
  });
124
204
  });
125
205
  });
@@ -7,8 +7,103 @@
7
7
  */
8
8
 
9
9
  import type { StateCreator } from 'zustand';
10
- import type { SectionPlane, SectionPlaneAxis } from '../types.js';
11
- import { SECTION_PLANE_DEFAULTS } from '../constants.js';
10
+ import type { SectionPlane, SectionPlaneAxis, SectionCapStyle, SectionCapHatchId } from '../types.js';
11
+ import { SECTION_PLANE_DEFAULTS, SECTION_CAP_DEFAULTS } from '../constants.js';
12
+
13
+ // ─── Persistence ─────────────────────────────────────────────────────────
14
+ // Cap appearance (hatch pattern, colours, spacing, angle, whether the cap is
15
+ // shown at all) persists across reloads via localStorage, so the user's
16
+ // preferred cut surface survives closing and re-opening the app. Axis and
17
+ // position are session-scoped because they only make sense relative to a
18
+ // loaded model. See chatSlice.ts for the same direct-localStorage pattern
19
+ // used elsewhere in the store.
20
+ const CAP_STYLE_STORAGE_KEY = 'ifc-lite:section-cap-style';
21
+ const CAP_SHOW_STORAGE_KEY = 'ifc-lite:section-cap-show';
22
+ const OUTLINES_SHOW_STORAGE_KEY = 'ifc-lite:section-outlines-show';
23
+
24
+ const HATCH_IDS: readonly SectionCapHatchId[] = [
25
+ 'solid', 'diagonal', 'crossHatch', 'horizontal',
26
+ 'vertical', 'concrete', 'brick', 'insulation',
27
+ ] as const;
28
+
29
+ function isHatchId(v: unknown): v is SectionCapHatchId {
30
+ return typeof v === 'string' && (HATCH_IDS as readonly string[]).includes(v);
31
+ }
32
+
33
+ function isRgba(v: unknown): v is [number, number, number, number] {
34
+ return Array.isArray(v) && v.length === 4 && v.every((n) => typeof n === 'number' && Number.isFinite(n));
35
+ }
36
+
37
+ function loadCapStyle(): SectionCapStyle {
38
+ const fallback: SectionCapStyle = {
39
+ fillColor: [...SECTION_CAP_DEFAULTS.FILL_COLOR],
40
+ strokeColor: [...SECTION_CAP_DEFAULTS.STROKE_COLOR],
41
+ pattern: SECTION_CAP_DEFAULTS.PATTERN,
42
+ spacingPx: SECTION_CAP_DEFAULTS.SPACING_PX,
43
+ angleRad: SECTION_CAP_DEFAULTS.ANGLE_RAD,
44
+ widthPx: SECTION_CAP_DEFAULTS.WIDTH_PX,
45
+ secondaryAngleRad: SECTION_CAP_DEFAULTS.SECONDARY_ANGLE_RAD,
46
+ };
47
+ if (typeof window === 'undefined') return fallback;
48
+ try {
49
+ const raw = window.localStorage.getItem(CAP_STYLE_STORAGE_KEY);
50
+ if (!raw) return fallback;
51
+ const parsed = JSON.parse(raw) as Record<string, unknown>;
52
+ return {
53
+ fillColor: isRgba(parsed.fillColor) ? parsed.fillColor : fallback.fillColor,
54
+ strokeColor: isRgba(parsed.strokeColor) ? parsed.strokeColor : fallback.strokeColor,
55
+ pattern: isHatchId(parsed.pattern) ? parsed.pattern : fallback.pattern,
56
+ spacingPx: typeof parsed.spacingPx === 'number' && Number.isFinite(parsed.spacingPx)
57
+ ? Math.max(2, parsed.spacingPx) : fallback.spacingPx,
58
+ angleRad: typeof parsed.angleRad === 'number' && Number.isFinite(parsed.angleRad)
59
+ ? parsed.angleRad : fallback.angleRad,
60
+ widthPx: typeof parsed.widthPx === 'number' && Number.isFinite(parsed.widthPx)
61
+ ? Math.max(1, parsed.widthPx) : fallback.widthPx,
62
+ secondaryAngleRad: typeof parsed.secondaryAngleRad === 'number' && Number.isFinite(parsed.secondaryAngleRad)
63
+ ? parsed.secondaryAngleRad : fallback.secondaryAngleRad,
64
+ };
65
+ } catch (error) {
66
+ console.warn('[section] failed to load cap style from localStorage', error);
67
+ return fallback;
68
+ }
69
+ }
70
+
71
+ function saveCapStyle(style: SectionCapStyle): void {
72
+ if (typeof window === 'undefined') return;
73
+ try {
74
+ window.localStorage.setItem(CAP_STYLE_STORAGE_KEY, JSON.stringify(style));
75
+ } catch (error) {
76
+ // Storage quota, private mode etc. — preference just doesn't persist this
77
+ // session; log so a missing setting is at least diagnosable in devtools.
78
+ console.warn('[section] failed to save cap style to localStorage', error);
79
+ }
80
+ }
81
+
82
+ function loadBoolean(key: string, fallback: boolean): boolean {
83
+ if (typeof window === 'undefined') return fallback;
84
+ try {
85
+ const raw = window.localStorage.getItem(key);
86
+ if (raw === 'true') return true;
87
+ if (raw === 'false') return false;
88
+ } catch (error) {
89
+ console.warn(`[section] failed to load preference '${key}' from localStorage`, error);
90
+ }
91
+ return fallback;
92
+ }
93
+
94
+ function saveBoolean(key: string, value: boolean): void {
95
+ if (typeof window === 'undefined') return;
96
+ try {
97
+ window.localStorage.setItem(key, String(value));
98
+ } catch (error) {
99
+ console.warn(`[section] failed to save preference '${key}' to localStorage`, error);
100
+ }
101
+ }
102
+
103
+ const loadShowCap = () => loadBoolean(CAP_SHOW_STORAGE_KEY, SECTION_PLANE_DEFAULTS.SHOW_CAP);
104
+ const saveShowCap = (v: boolean) => saveBoolean(CAP_SHOW_STORAGE_KEY, v);
105
+ const loadShowOutlines = () => loadBoolean(OUTLINES_SHOW_STORAGE_KEY, SECTION_PLANE_DEFAULTS.SHOW_OUTLINES);
106
+ const saveShowOutlines = (v: boolean) => saveBoolean(OUTLINES_SHOW_STORAGE_KEY, v);
12
107
 
13
108
  export interface SectionSlice {
14
109
  // State
@@ -18,15 +113,28 @@ export interface SectionSlice {
18
113
  setSectionPlaneAxis: (axis: SectionPlaneAxis) => void;
19
114
  setSectionPlanePosition: (position: number) => void;
20
115
  toggleSectionPlane: () => void;
116
+ setSectionPlaneEnabled: (enabled: boolean) => void;
21
117
  flipSectionPlane: () => void;
118
+ setSectionShowCap: (show: boolean) => void;
119
+ setSectionShowOutlines: (show: boolean) => void;
120
+ setSectionCapStyle: (style: Partial<SectionCapStyle>) => void;
22
121
  resetSectionPlane: () => void;
23
122
  }
24
123
 
124
+ const getDefaultCapStyle = (): SectionCapStyle => loadCapStyle();
125
+
25
126
  const getDefaultSectionPlane = (): SectionPlane => ({
26
127
  axis: SECTION_PLANE_DEFAULTS.AXIS,
27
128
  position: SECTION_PLANE_DEFAULTS.POSITION,
28
129
  enabled: SECTION_PLANE_DEFAULTS.ENABLED,
29
130
  flipped: SECTION_PLANE_DEFAULTS.FLIPPED,
131
+ // showCap + showOutlines + capStyle come from localStorage so the
132
+ // user's preferred cut-surface appearance survives reloads; the axis,
133
+ // position, and enabled fields stay session-scoped because they only
134
+ // make sense for the currently loaded model.
135
+ showCap: loadShowCap(),
136
+ showOutlines: loadShowOutlines(),
137
+ capStyle: getDefaultCapStyle(),
30
138
  });
31
139
 
32
140
  export const createSectionSlice: StateCreator<SectionSlice, [], [], SectionSlice> = (set) => ({
@@ -35,14 +143,19 @@ export const createSectionSlice: StateCreator<SectionSlice, [], [], SectionSlice
35
143
 
36
144
  // Actions
37
145
  setSectionPlaneAxis: (axis) => set((state) => ({
38
- sectionPlane: { ...state.sectionPlane, axis },
146
+ // Changing the axis implicitly means "I want to cut now" — enable the clip
147
+ // so users don't get stuck in a confusing no-op preview.
148
+ sectionPlane: { ...state.sectionPlane, axis, enabled: true },
39
149
  })),
40
150
 
41
151
  setSectionPlanePosition: (position) => set((state) => {
42
152
  // Clamp position to valid range [0, 100]
43
153
  const clampedPosition = Math.min(100, Math.max(0, Number(position) || 0));
44
154
  return {
45
- sectionPlane: { ...state.sectionPlane, position: clampedPosition },
155
+ // Moving the slider also enables the cut — previously you had to press
156
+ // "Cutting" separately, which led to the "it just jitters, doesn't cut"
157
+ // feedback from users.
158
+ sectionPlane: { ...state.sectionPlane, position: clampedPosition, enabled: true },
46
159
  };
47
160
  }),
48
161
 
@@ -50,9 +163,42 @@ export const createSectionSlice: StateCreator<SectionSlice, [], [], SectionSlice
50
163
  sectionPlane: { ...state.sectionPlane, enabled: !state.sectionPlane.enabled },
51
164
  })),
52
165
 
166
+ setSectionPlaneEnabled: (enabled) => set((state) => ({
167
+ sectionPlane: { ...state.sectionPlane, enabled },
168
+ })),
169
+
53
170
  flipSectionPlane: () => set((state) => ({
54
171
  sectionPlane: { ...state.sectionPlane, flipped: !state.sectionPlane.flipped },
55
172
  })),
56
173
 
57
- resetSectionPlane: () => set({ sectionPlane: getDefaultSectionPlane() }),
174
+ setSectionShowCap: (showCap) => set((state) => {
175
+ saveShowCap(showCap);
176
+ return { sectionPlane: { ...state.sectionPlane, showCap } };
177
+ }),
178
+
179
+ setSectionShowOutlines: (showOutlines) => set((state) => {
180
+ saveShowOutlines(showOutlines);
181
+ return { sectionPlane: { ...state.sectionPlane, showOutlines } };
182
+ }),
183
+
184
+ setSectionCapStyle: (style) => set((state) => {
185
+ const capStyle: SectionCapStyle = { ...state.sectionPlane.capStyle, ...style };
186
+ saveCapStyle(capStyle);
187
+ return { sectionPlane: { ...state.sectionPlane, capStyle } };
188
+ }),
189
+
190
+ resetSectionPlane: () => set(() => {
191
+ // Reset clears persisted cap style too — users asking for defaults expect
192
+ // the defaults to stick on the next reload.
193
+ try {
194
+ if (typeof window !== 'undefined') {
195
+ window.localStorage.removeItem(CAP_STYLE_STORAGE_KEY);
196
+ window.localStorage.removeItem(CAP_SHOW_STORAGE_KEY);
197
+ window.localStorage.removeItem(OUTLINES_SHOW_STORAGE_KEY);
198
+ }
199
+ } catch (error) {
200
+ console.warn('[section] failed to clear persisted cap preferences', error);
201
+ }
202
+ return { sectionPlane: getDefaultSectionPlane() };
203
+ }),
58
204
  });
@@ -10,12 +10,14 @@ import type { StateCreator } from 'zustand';
10
10
  import { UI_DEFAULTS } from '../constants.js';
11
11
  import type { ContactShadingQuality, SeparationLinesQuality } from '@ifc-lite/renderer';
12
12
 
13
+ export type ThemeMode = 'light' | 'dark' | 'colorful';
14
+
13
15
  export interface UISlice {
14
16
  // State
15
17
  leftPanelCollapsed: boolean;
16
18
  rightPanelCollapsed: boolean;
17
19
  activeTool: string;
18
- theme: 'light' | 'dark';
20
+ theme: ThemeMode;
19
21
  isMobile: boolean;
20
22
  hoverTooltipsEnabled: boolean;
21
23
  visualEnhancementsEnabled: boolean;
@@ -33,8 +35,10 @@ export interface UISlice {
33
35
  setLeftPanelCollapsed: (collapsed: boolean) => void;
34
36
  setRightPanelCollapsed: (collapsed: boolean) => void;
35
37
  setActiveTool: (tool: string) => void;
36
- setTheme: (theme: 'light' | 'dark') => void;
38
+ setTheme: (theme: ThemeMode) => void;
37
39
  toggleTheme: () => void;
40
+ /** Shift+click secret: toggle colorful mode on/off */
41
+ toggleColorful: () => void;
38
42
  setIsMobile: (isMobile: boolean) => void;
39
43
  toggleHoverTooltips: () => void;
40
44
  setVisualEnhancementsEnabled: (enabled: boolean) => void;
@@ -49,6 +53,13 @@ export interface UISlice {
49
53
  setSeparationLinesRadius: (radius: number) => void;
50
54
  }
51
55
 
56
+ /** Apply the correct CSS classes on <html> for the given theme */
57
+ function applyThemeClasses(theme: ThemeMode) {
58
+ const el = document.documentElement;
59
+ el.classList.toggle('dark', theme === 'dark');
60
+ el.classList.toggle('colorful', theme === 'colorful');
61
+ }
62
+
52
63
  export const createUISlice: StateCreator<UISlice, [], [], UISlice> = (set, get) => ({
53
64
  // Initial state
54
65
  leftPanelCollapsed: false,
@@ -74,14 +85,26 @@ export const createUISlice: StateCreator<UISlice, [], [], UISlice> = (set, get)
74
85
  setActiveTool: (activeTool) => set({ activeTool }),
75
86
 
76
87
  setTheme: (theme) => {
77
- document.documentElement.classList.toggle('dark', theme === 'dark');
88
+ applyThemeClasses(theme);
78
89
  localStorage.setItem('ifc-lite-theme', theme);
79
90
  set({ theme });
80
91
  },
81
92
 
82
93
  toggleTheme: () => {
83
- const newTheme = get().theme === 'dark' ? 'light' : 'dark';
84
- document.documentElement.classList.toggle('dark', newTheme === 'dark');
94
+ // Normal toggle: dark ↔ light. If currently colorful, drop to dark.
95
+ const current = get().theme;
96
+ const newTheme = current === 'dark' ? 'light' : 'dark';
97
+ applyThemeClasses(newTheme);
98
+ localStorage.setItem('ifc-lite-theme', newTheme);
99
+ set({ theme: newTheme });
100
+ },
101
+
102
+ toggleColorful: () => {
103
+ // Shift+click secret: toggle colorful on/off
104
+ // Into colorful from any state. Out of colorful → light (the storm clears).
105
+ const current = get().theme;
106
+ const newTheme: ThemeMode = current === 'colorful' ? 'light' : 'colorful';
107
+ applyThemeClasses(newTheme);
85
108
  localStorage.setItem('ifc-lite-theme', newTheme);
86
109
  set({ theme: newTheme });
87
110
  },
@@ -86,6 +86,12 @@ export interface EdgeLockState {
86
86
  /** Semantic axis names: down (Y), front (Z), side (X) for intuitive user experience */
87
87
  export type SectionPlaneAxis = 'down' | 'front' | 'side';
88
88
 
89
+ // Re-export the renderer's canonical cap-styling types so the viewer store and
90
+ // the WebGPU renderer share a single source of truth. Adding a new hatch
91
+ // pattern only requires editing `packages/renderer/src/section-cap-style.ts`.
92
+ export type { HatchPatternId as SectionCapHatchId, SectionCapStyle } from '@ifc-lite/renderer';
93
+ import type { SectionCapStyle } from '@ifc-lite/renderer';
94
+
89
95
  export interface SectionPlane {
90
96
  axis: SectionPlaneAxis;
91
97
  /** 0-100 percentage of model bounds */
@@ -93,6 +99,17 @@ export interface SectionPlane {
93
99
  enabled: boolean;
94
100
  /** If true, show the opposite side of the cut */
95
101
  flipped: boolean;
102
+ /** Whether to render the filled, hatched cap surface at the plane. Defaults to true. */
103
+ showCap: boolean;
104
+ /**
105
+ * Whether to draw polygon outlines on top of the cut (the crisp black
106
+ * line the architect expects around each sliced element). Independent
107
+ * from `showCap` so users can have a hatched fill without outlines,
108
+ * or vice versa. Defaults to true.
109
+ */
110
+ showOutlines: boolean;
111
+ /** User-defined colour + hatch for the cut surface. */
112
+ capStyle: SectionCapStyle;
96
113
  }
97
114
 
98
115
  // ============================================================================
@@ -272,6 +289,13 @@ export interface NativeMetadataSnapshot {
272
289
  spatialTree: NativeMetadataSpatialNode | null;
273
290
  }
274
291
 
292
+ export type ModelSourceFile = File | {
293
+ path: string;
294
+ name: string;
295
+ size: number;
296
+ modifiedMs?: number | null;
297
+ };
298
+
275
299
  /** Complete model container for federation */
276
300
  export interface FederatedModel {
277
301
  /** Unique identifier (UUID generated on load) */
@@ -292,6 +316,8 @@ export interface FederatedModel {
292
316
  loadedAt: number;
293
317
  /** Original file size in bytes */
294
318
  fileSize: number;
319
+ /** Original source handle used for explicit reload/reposition operations. */
320
+ sourceFile?: ModelSourceFile;
295
321
  /**
296
322
  * ID offset for this model (from FederationRegistry)
297
323
  * All mesh expressIds are globalIds = originalExpressId + idOffset
@@ -4,6 +4,7 @@
4
4
 
5
5
  import {
6
6
  IfcTypeEnumFromString,
7
+ IfcTypeEnumToString,
7
8
  isBuildingLikeSpatialType,
8
9
  isStoreyLikeSpatialType,
9
10
  type SpatialHierarchy,
@@ -103,7 +104,9 @@ function buildEntityLookup() {
103
104
  return typeNameById.get(expressId) ?? 'Unknown';
104
105
  },
105
106
  getByType(type: string | number) {
106
- const key = typeof type === 'string' ? type.toUpperCase() : String(type);
107
+ const key = typeof type === 'string'
108
+ ? type.toUpperCase()
109
+ : IfcTypeEnumToString(type).toUpperCase();
107
110
  return byType.get(key) ?? [];
108
111
  },
109
112
  };
@@ -301,13 +301,18 @@ export function getRenderThrottleMs(meshCount: number): number {
301
301
 
302
302
  /**
303
303
  * Get clear color based on theme
304
- * @param theme - 'light' or 'dark'
304
+ * @param theme - 'light', 'dark', or 'colorful'
305
305
  * @returns RGBA clear color tuple
306
306
  */
307
- export function getThemeClearColor(theme: 'light' | 'dark'): [number, number, number, number] {
307
+ export function getThemeClearColor(theme: 'light' | 'dark' | 'colorful'): [number, number, number, number] {
308
308
  if (theme === 'light') {
309
309
  return [0.96, 0.96, 0.97, 1]; // Light gray
310
310
  }
311
+ if (theme === 'colorful') {
312
+ // Transparent — the CSS gradient on the canvas element shows through.
313
+ // alphaMode:'premultiplied' + fragment alpha=1 keeps models fully opaque.
314
+ return [0, 0, 0, 0];
315
+ }
311
316
  return [0.102, 0.106, 0.149, 1]; // Tokyo Night storm (#1a1b26)
312
317
  }
313
318
 
package/src/vite-env.d.ts CHANGED
@@ -13,10 +13,6 @@ interface ImportMetaEnv {
13
13
  readonly VITE_USE_SERVER?: string;
14
14
  /** Comma-separated free-tier model IDs */
15
15
  readonly VITE_LLM_FREE_MODELS?: string;
16
- /** Comma-separated pro model IDs grouped by relative cost */
17
- readonly VITE_LLM_PRO_MODELS_LOW?: string;
18
- readonly VITE_LLM_PRO_MODELS_MEDIUM?: string;
19
- readonly VITE_LLM_PRO_MODELS_HIGH?: string;
20
16
  /** Comma-separated model IDs that support image inputs */
21
17
  readonly VITE_LLM_IMAGE_MODELS?: string;
22
18
  /** Comma-separated model IDs that support file attachment context */