@wovvmap/renderer-three 0.0.0-stage → 1.2.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.
Files changed (116) hide show
  1. package/dist/controllers/ImageController.d.ts +95 -0
  2. package/dist/controllers/ImageController.d.ts.map +1 -0
  3. package/dist/controllers/ImageController.js +129 -0
  4. package/dist/controllers/ShapeController.d.ts +95 -0
  5. package/dist/controllers/ShapeController.d.ts.map +1 -0
  6. package/dist/controllers/ShapeController.js +139 -0
  7. package/dist/controllers/TextController.d.ts +120 -0
  8. package/dist/controllers/TextController.d.ts.map +1 -0
  9. package/dist/controllers/TextController.js +161 -0
  10. package/dist/controllers/ViewerElementsController.d.ts +254 -0
  11. package/dist/controllers/ViewerElementsController.d.ts.map +1 -0
  12. package/dist/controllers/ViewerElementsController.js +490 -0
  13. package/dist/engine/CameraFollow.d.ts +13 -0
  14. package/dist/engine/CameraFollow.d.ts.map +1 -0
  15. package/dist/engine/CameraFollow.js +52 -0
  16. package/dist/engine/CameraManager.d.ts +143 -0
  17. package/dist/engine/CameraManager.d.ts.map +1 -0
  18. package/dist/engine/CameraManager.js +566 -0
  19. package/dist/engine/ControlsManager.d.ts +123 -0
  20. package/dist/engine/ControlsManager.d.ts.map +1 -0
  21. package/dist/engine/ControlsManager.js +604 -0
  22. package/dist/engine/InteractionManager.d.ts +45 -0
  23. package/dist/engine/InteractionManager.d.ts.map +1 -0
  24. package/dist/engine/InteractionManager.js +99 -0
  25. package/dist/engine/LightingManager.d.ts +25 -0
  26. package/dist/engine/LightingManager.d.ts.map +1 -0
  27. package/dist/engine/LightingManager.js +74 -0
  28. package/dist/engine/MapViewerEngine.d.ts +350 -0
  29. package/dist/engine/MapViewerEngine.d.ts.map +1 -0
  30. package/dist/engine/MapViewerEngine.js +1041 -0
  31. package/dist/engine/RendererManager.d.ts +77 -0
  32. package/dist/engine/RendererManager.d.ts.map +1 -0
  33. package/dist/engine/RendererManager.js +243 -0
  34. package/dist/index.d.ts +40 -0
  35. package/dist/index.d.ts.map +1 -0
  36. package/dist/index.js +39 -0
  37. package/dist/services/image-services/ImageCacheService.d.ts +49 -0
  38. package/dist/services/image-services/ImageCacheService.d.ts.map +1 -0
  39. package/dist/services/image-services/ImageCacheService.js +121 -0
  40. package/dist/services/image-services/ImagePlaneService.d.ts +29 -0
  41. package/dist/services/image-services/ImagePlaneService.d.ts.map +1 -0
  42. package/dist/services/image-services/ImagePlaneService.js +82 -0
  43. package/dist/services/image-services/ImageService.d.ts +170 -0
  44. package/dist/services/image-services/ImageService.d.ts.map +1 -0
  45. package/dist/services/image-services/ImageService.js +537 -0
  46. package/dist/services/image-services/ImageSpriteService.d.ts +39 -0
  47. package/dist/services/image-services/ImageSpriteService.d.ts.map +1 -0
  48. package/dist/services/image-services/ImageSpriteService.js +135 -0
  49. package/dist/services/routes/RouteArrows.d.ts +34 -0
  50. package/dist/services/routes/RouteArrows.d.ts.map +1 -0
  51. package/dist/services/routes/RouteArrows.js +157 -0
  52. package/dist/services/routes/RouteCursor.d.ts +19 -0
  53. package/dist/services/routes/RouteCursor.d.ts.map +1 -0
  54. package/dist/services/routes/RouteCursor.js +68 -0
  55. package/dist/services/routes/RouteMotion.d.ts +31 -0
  56. package/dist/services/routes/RouteMotion.d.ts.map +1 -0
  57. package/dist/services/routes/RouteMotion.js +132 -0
  58. package/dist/services/routes/RouteRenderer.d.ts +52 -0
  59. package/dist/services/routes/RouteRenderer.d.ts.map +1 -0
  60. package/dist/services/routes/RouteRenderer.js +445 -0
  61. package/dist/services/routes/RouteStepHighlight.d.ts +22 -0
  62. package/dist/services/routes/RouteStepHighlight.d.ts.map +1 -0
  63. package/dist/services/routes/RouteStepHighlight.js +84 -0
  64. package/dist/services/routes/routeMarkers.d.ts +6 -0
  65. package/dist/services/routes/routeMarkers.d.ts.map +1 -0
  66. package/dist/services/routes/routeMarkers.js +41 -0
  67. package/dist/services/selectionPaint.d.ts +12 -0
  68. package/dist/services/selectionPaint.d.ts.map +1 -0
  69. package/dist/services/selectionPaint.js +8 -0
  70. package/dist/services/shape-services/ExtrudeShapeService.d.ts +54 -0
  71. package/dist/services/shape-services/ExtrudeShapeService.d.ts.map +1 -0
  72. package/dist/services/shape-services/ExtrudeShapeService.js +204 -0
  73. package/dist/services/shape-services/FlatShapeService.d.ts +25 -0
  74. package/dist/services/shape-services/FlatShapeService.d.ts.map +1 -0
  75. package/dist/services/shape-services/FlatShapeService.js +49 -0
  76. package/dist/services/shape-services/IShapeService.d.ts +24 -0
  77. package/dist/services/shape-services/IShapeService.d.ts.map +1 -0
  78. package/dist/services/shape-services/IShapeService.js +6 -0
  79. package/dist/services/shape-services/MaterialUtils.d.ts +15 -0
  80. package/dist/services/shape-services/MaterialUtils.d.ts.map +1 -0
  81. package/dist/services/shape-services/MaterialUtils.js +71 -0
  82. package/dist/services/shape-services/ShapeFactory.d.ts +20 -0
  83. package/dist/services/shape-services/ShapeFactory.d.ts.map +1 -0
  84. package/dist/services/shape-services/ShapeFactory.js +28 -0
  85. package/dist/services/shape-services/ShapeHighlightService.d.ts +13 -0
  86. package/dist/services/shape-services/ShapeHighlightService.d.ts.map +1 -0
  87. package/dist/services/shape-services/ShapeHighlightService.js +57 -0
  88. package/dist/services/shape-services/ShapeService.d.ts +129 -0
  89. package/dist/services/shape-services/ShapeService.d.ts.map +1 -0
  90. package/dist/services/shape-services/ShapeService.js +480 -0
  91. package/dist/services/shape-services/preparedGeometry.d.ts +13 -0
  92. package/dist/services/shape-services/preparedGeometry.d.ts.map +1 -0
  93. package/dist/services/shape-services/preparedGeometry.js +37 -0
  94. package/dist/services/text-services/ITextRenderStrategy.d.ts +79 -0
  95. package/dist/services/text-services/ITextRenderStrategy.d.ts.map +1 -0
  96. package/dist/services/text-services/ITextRenderStrategy.js +7 -0
  97. package/dist/services/text-services/Text2DService.d.ts +66 -0
  98. package/dist/services/text-services/Text2DService.d.ts.map +1 -0
  99. package/dist/services/text-services/Text2DService.js +483 -0
  100. package/dist/services/text-services/Text3DService.d.ts +51 -0
  101. package/dist/services/text-services/Text3DService.d.ts.map +1 -0
  102. package/dist/services/text-services/Text3DService.js +246 -0
  103. package/dist/services/text-services/TextCollisionService.d.ts +29 -0
  104. package/dist/services/text-services/TextCollisionService.d.ts.map +1 -0
  105. package/dist/services/text-services/TextCollisionService.js +117 -0
  106. package/dist/services/text-services/TextService.d.ts +159 -0
  107. package/dist/services/text-services/TextService.d.ts.map +1 -0
  108. package/dist/services/text-services/TextService.js +398 -0
  109. package/dist/services/text-services/TextStrategyRegistry.d.ts +36 -0
  110. package/dist/services/text-services/TextStrategyRegistry.d.ts.map +1 -0
  111. package/dist/services/text-services/TextStrategyRegistry.js +44 -0
  112. package/dist/services/threeDisposeHelper.d.ts +12 -0
  113. package/dist/services/threeDisposeHelper.d.ts.map +1 -0
  114. package/dist/services/threeDisposeHelper.js +57 -0
  115. package/package.json +40 -3
  116. package/README.md +0 -3
@@ -0,0 +1,398 @@
1
+ /**
2
+ * @file TextService.ts
3
+ * @description Central coordinator service for 2D DOM labels and 3D Troika mesh text labels.
4
+ * English: Text coordinator applying saved overrides to new labels with typed strategy contracts.
5
+ * Hinglish: 2D aur 3D text labels ko manage karne wali service jo naye labels par bhi saved color overrides lagati hai.
6
+ */
7
+ import * as THREE from 'three';
8
+ import { uniformSelectionPaint } from '../selectionPaint.js';
9
+ import { TextCollisionService } from './TextCollisionService.js';
10
+ import { TextStrategyRegistry } from './TextStrategyRegistry.js';
11
+ import { Text2DService } from './Text2DService.js';
12
+ import { Text3DService } from './Text3DService.js';
13
+ /**
14
+ * Central coordinator service managing text render strategies, floor groupings, rotation, and collisions.
15
+ * SOLID principles ke anusar sabhi text strategies (2D DOM aur 3D Mesh), floor groupings aur collision culling ko manage karne wali central coordinator service.
16
+ */
17
+ export class TextService {
18
+ textMap = new Map();
19
+ floorWiseTextMap = new Map();
20
+ textType = '3D';
21
+ isLabelsVisible = true;
22
+ strategyRegistry;
23
+ textCollisionService;
24
+ onInvalidate;
25
+ currentTextColor;
26
+ currentTextColors;
27
+ selectionPaint = new Map();
28
+ constructor(strategyRegistry, collisionService) {
29
+ this.textCollisionService = collisionService || new TextCollisionService();
30
+ if (strategyRegistry) {
31
+ this.strategyRegistry = strategyRegistry;
32
+ }
33
+ else {
34
+ this.strategyRegistry = new TextStrategyRegistry();
35
+ this.strategyRegistry.register(new Text2DService());
36
+ this.strategyRegistry.register(new Text3DService());
37
+ }
38
+ }
39
+ /**
40
+ * Sets callback to trigger redraw when asynchronous text assets or flips occur.
41
+ * Asynchronous text assets sync hone par redraw trigger karne wala callback.
42
+ */
43
+ setOnInvalidate(callback) {
44
+ this.onInvalidate = callback;
45
+ }
46
+ /**
47
+ * Returns currently active text rendering type ('2D' or '3D').
48
+ * Current active text display type prapt karein.
49
+ */
50
+ getTextType() {
51
+ return this.textType;
52
+ }
53
+ /**
54
+ * Switches active text rendering type ('2D' or '3D').
55
+ * Active text display type switch karein.
56
+ */
57
+ setTextType(type) {
58
+ this.textType = type;
59
+ }
60
+ /**
61
+ * Exposes strategy registry for extension with custom text strategies (Open/Closed Principle).
62
+ * Custom text strategies register karne ke liye strategy registry prapt karein.
63
+ */
64
+ getStrategyRegistry() {
65
+ return this.strategyRegistry;
66
+ }
67
+ /**
68
+ * Registers a new or custom text render strategy (Open/Closed Principle).
69
+ * Nayi text rendering strategy register karein.
70
+ */
71
+ registerStrategy(strategy) {
72
+ this.strategyRegistry.register(strategy);
73
+ }
74
+ /**
75
+ * Constructs a text label object using the registered strategy for current textType.
76
+ * Current textType ki registered strategy use karke text label banayein.
77
+ */
78
+ createText(node, options = {}) {
79
+ if (this.textMap.has(node.key)) {
80
+ this.removeText(node.key);
81
+ }
82
+ const scale = options.scale ?? 0.1;
83
+ const strategy = this.strategyRegistry.get(this.textType) ?? this.strategyRegistry.get('2D');
84
+ const textObject = strategy.createText(node, {
85
+ ...options,
86
+ scale,
87
+ onInvalidate: options.onInvalidate ?? this.onInvalidate,
88
+ });
89
+ if (textObject) {
90
+ // Apply saved color overrides to newly created label if present
91
+ const savedOverride = this.currentTextColors ?? this.currentTextColor;
92
+ if (savedOverride !== undefined && typeof strategy.updateTextColor === 'function') {
93
+ strategy.updateTextColor(textObject, savedOverride);
94
+ }
95
+ this.textMap.set(node.key, textObject);
96
+ const paint = this.selectionPaint.get(node.key);
97
+ if (paint)
98
+ this.paintSelection(textObject, true, paint);
99
+ const floorIndex = node.floorIndex ?? node.z ?? 0;
100
+ let group = this.floorWiseTextMap.get(floorIndex);
101
+ if (!group) {
102
+ group = new THREE.Group();
103
+ group.name = `floor-text-${floorIndex}`;
104
+ group.userData.floorIndex = floorIndex;
105
+ group.visible = this.isLabelsVisible;
106
+ this.floorWiseTextMap.set(floorIndex, group);
107
+ }
108
+ group.add(textObject);
109
+ }
110
+ return textObject;
111
+ }
112
+ /**
113
+ * Toggles visibility across all floor-wise text label groups and retains state for future floors/regenerations.
114
+ * English: Synchronizes visibility across all floor text groups and stores visibility intent for newly created groups.
115
+ * Hinglish: Sabhi floor text groups ki visibility update karein aur naye floors ke liye state save rakhein.
116
+ */
117
+ toggleLabels(visible) {
118
+ this.isLabelsVisible = visible;
119
+ this.floorWiseTextMap.forEach((group) => {
120
+ group.visible = visible;
121
+ });
122
+ }
123
+ /**
124
+ * Retrieves container group for text labels on a specific floor.
125
+ * Specific floor ke text labels ka group prapt karein.
126
+ */
127
+ getFloorTexts(z) {
128
+ return this.floorWiseTextMap.get(z);
129
+ }
130
+ /**
131
+ * Convenience alias matching getFloorWiseShapes / getFloorWiseImages.
132
+ * getFloorTexts ka alias method.
133
+ */
134
+ getFloorWiseTexts(z) {
135
+ return this.floorWiseTextMap.get(z);
136
+ }
137
+ /**
138
+ * Returns all active text label objects.
139
+ * Sabhi text labels ki array prapt karein.
140
+ */
141
+ getAllTexts() {
142
+ return Array.from(this.textMap.values());
143
+ }
144
+ /**
145
+ * Looks up a text label object by node key.
146
+ * Unique key se specific text label dhoondein.
147
+ */
148
+ getTextByKey(key) {
149
+ return this.textMap.get(key);
150
+ }
151
+ /** Preserve the single-key API through the shared selection projection.
152
+ * Hinglish: Purana single-key API bhi isi common selection projection ko use karta hai. */
153
+ setSelection(key, colors) {
154
+ this.setSelectionKeys(key === null ? [] : [key], colors);
155
+ }
156
+ /** Diff selected keys only; unchanged members keep their paint and future labels inherit it.
157
+ * Hinglish: Sirf selection keys ka farak dekhein; same members dobara paint nahi hote. */
158
+ setSelectionKeys(keys, colors) {
159
+ this.setSelectionPaint(uniformSelectionPaint(keys, { color: colors.text2D, ...colors }));
160
+ }
161
+ /** Resolve colors once upstream; this owner diffs only affected label keys and keeps base colors.
162
+ * Hinglish: Role colors upstream resolve hon; yahan sirf changed labels paint hon, base safe rahe. */
163
+ setSelectionPaint(next) {
164
+ for (const [key, previous] of this.selectionPaint) {
165
+ if (!next.has(key)) {
166
+ const text = this.textMap.get(key);
167
+ if (text)
168
+ this.paintSelection(text, false, previous);
169
+ }
170
+ }
171
+ for (const [key, paint] of next) {
172
+ const previous = this.selectionPaint.get(key);
173
+ if (paint.text2D !== previous?.text2D || paint.text3D !== previous?.text3D) {
174
+ const text = this.textMap.get(key);
175
+ if (text)
176
+ this.paintSelection(text, true, paint);
177
+ }
178
+ }
179
+ this.selectionPaint = next;
180
+ }
181
+ paintSelection(text, selected, colors) {
182
+ const type = text.userData.is3D ? '3D' : '2D';
183
+ const strategy = this.strategyRegistry.get(type) ?? this.strategyRegistry.get('2D');
184
+ strategy?.setSelected?.(text, selected, type === '3D' ? colors.text3D : colors.text2D);
185
+ }
186
+ /**
187
+ * Removes a text label and disposes its resources via its owning strategy.
188
+ * Text label ko remove aur uske resources clean karein.
189
+ */
190
+ removeText(key) {
191
+ const text = this.textMap.get(key);
192
+ if (!text)
193
+ return false;
194
+ if (text.parent) {
195
+ text.parent.remove(text);
196
+ }
197
+ const strategyType = text.userData.is3D ? '3D' : '2D';
198
+ const strategy = this.strategyRegistry.get(strategyType) ?? this.strategyRegistry.get('2D');
199
+ strategy.disposeText?.(text);
200
+ this.textMap.delete(key);
201
+ return true;
202
+ }
203
+ activeViewModeAnimationId = 0;
204
+ activeAnimationRafId = null;
205
+ /**
206
+ * Cancels active view mode text height animations.
207
+ * Chalu view mode text height animation ko cancel karein.
208
+ */
209
+ cancelAnimation() {
210
+ this.activeViewModeAnimationId++;
211
+ if (this.activeAnimationRafId !== null && typeof cancelAnimationFrame !== 'undefined') {
212
+ cancelAnimationFrame(this.activeAnimationRafId);
213
+ this.activeAnimationRafId = null;
214
+ }
215
+ }
216
+ /**
217
+ * Smoothly animates vertical position of text labels between 2D and 3D mode.
218
+ * Mode ke aadhar par text labels ki height smoothly animate karein.
219
+ */
220
+ animateViewModeToGroup(group, mode = '3D', depthConfig, onUpdate, durationMs = 400, onComplete) {
221
+ this.cancelAnimation();
222
+ if (typeof requestAnimationFrame === 'undefined') {
223
+ this.applyViewModeToGroup(group, mode, depthConfig);
224
+ if (onUpdate)
225
+ onUpdate();
226
+ if (onComplete)
227
+ onComplete();
228
+ return;
229
+ }
230
+ const animId = ++this.activeViewModeAnimationId;
231
+ const startTime = performance.now();
232
+ // English: Resolve target elevation using owning strategy so animated and instant results are identical.
233
+ // Hinglish: Owning strategy se target elevation resolve karein taaki animated aur instant dono me exact same height mile.
234
+ const targets = new Map();
235
+ group.children.forEach((child) => {
236
+ if (child.userData.type === 'text') {
237
+ const strategyType = child.userData.is3D ? '3D' : '2D';
238
+ const strategy = this.strategyRegistry.get(strategyType) ?? this.strategyRegistry.get('2D');
239
+ let targetY;
240
+ if (typeof strategy.resolveTargetElevation === 'function') {
241
+ targetY = strategy.resolveTargetElevation(child, mode, depthConfig);
242
+ }
243
+ else {
244
+ // English: Documented probe fallback for custom strategies without explicit resolver:
245
+ // Invoke applyViewMode to obtain target elevation, then restore starting position
246
+ // so the label smoothly interpolates from start to target without an end-of-transition jump.
247
+ // Hinglish: Resolver absent hone par documented fallback: applyViewMode call karke target Y read karein,
248
+ // fir starting position restore karein taaki end par jump hone ke bajaye smooth interpolation ho sake.
249
+ const startY = child.position.y;
250
+ strategy.applyViewMode(child, mode, depthConfig);
251
+ targetY = child.position.y;
252
+ child.position.y = startY;
253
+ }
254
+ targets.set(child.uuid, { startY: child.position.y, targetY });
255
+ }
256
+ });
257
+ const step = (time) => {
258
+ if (this.activeViewModeAnimationId !== animId)
259
+ return;
260
+ const elapsed = time - startTime;
261
+ const progress = Math.min(elapsed / durationMs, 1);
262
+ const ease = 1 - Math.pow(1 - progress, 3);
263
+ group.children.forEach((child) => {
264
+ const item = targets.get(child.uuid);
265
+ if (item) {
266
+ child.position.y = item.startY + (item.targetY - item.startY) * ease;
267
+ }
268
+ });
269
+ if (onUpdate)
270
+ onUpdate();
271
+ if (progress < 1) {
272
+ this.activeAnimationRafId = requestAnimationFrame(step);
273
+ }
274
+ else {
275
+ this.activeAnimationRafId = null;
276
+ this.applyViewModeToGroup(group, mode, depthConfig);
277
+ if (onUpdate)
278
+ onUpdate();
279
+ if (onComplete)
280
+ onComplete();
281
+ }
282
+ };
283
+ this.activeAnimationRafId = requestAnimationFrame(step);
284
+ }
285
+ applyViewModeToGroup(group, mode = '3D', depthConfig) {
286
+ this.cancelAnimation();
287
+ group.children.forEach((child) => {
288
+ if (child.userData.type === 'text') {
289
+ const strategyType = child.userData.is3D ? '3D' : '2D';
290
+ const strategy = this.strategyRegistry.get(strategyType) ?? this.strategyRegistry.get('2D');
291
+ strategy.applyViewMode(child, mode, depthConfig);
292
+ }
293
+ });
294
+ }
295
+ /**
296
+ * Updates text colors across all active 3D Troika text meshes (single color or per-type mapping).
297
+ * Typed strategy contract ke zariye sabhi text meshes ka color update karein.
298
+ */
299
+ /**
300
+ * Compares two per-type text color mapping objects for shallow equality.
301
+ * English: Compares key-value pairs between text color records to prevent redundant scene updates.
302
+ * Hinglish: Text color maps ke beech equality check karta hai taaki duplicate update skip ho sakein.
303
+ */
304
+ areTextColorsEqual(a, b) {
305
+ if (!a && !b)
306
+ return true;
307
+ if (!a || !b)
308
+ return false;
309
+ const keysA = Object.keys(a);
310
+ const keysB = Object.keys(b);
311
+ if (keysA.length !== keysB.length)
312
+ return false;
313
+ return keysA.every((k) => a[k] === b[k]);
314
+ }
315
+ updateTextColors(colorOrMap) {
316
+ let newDefault;
317
+ let newPerType;
318
+ if (typeof colorOrMap === 'object' && colorOrMap !== null) {
319
+ newPerType = { ...colorOrMap };
320
+ newDefault = colorOrMap['default'];
321
+ }
322
+ else if (colorOrMap !== undefined) {
323
+ newDefault = colorOrMap;
324
+ newPerType = undefined;
325
+ }
326
+ else {
327
+ newDefault = undefined;
328
+ newPerType = undefined;
329
+ }
330
+ // Skip processing if effective text colors are identical
331
+ // English: Early return if requested text colors match active text colors.
332
+ // Hinglish: Agar text colors already applied hain toh redundant strategy sync skip karein.
333
+ const isDefaultEqual = this.currentTextColor === newDefault;
334
+ const isPerTypeEqual = this.areTextColorsEqual(this.currentTextColors, newPerType);
335
+ if (isDefaultEqual && isPerTypeEqual) {
336
+ return;
337
+ }
338
+ this.currentTextColor = newDefault;
339
+ this.currentTextColors = newPerType;
340
+ this.strategyRegistry.getAll().forEach((strategy) => {
341
+ if (typeof strategy.updateTextColor === 'function') {
342
+ this.textMap.forEach((object) => {
343
+ strategy.updateTextColor(object, colorOrMap);
344
+ });
345
+ }
346
+ });
347
+ }
348
+ /**
349
+ * Flips or rotates text objects when camera rotates (e.g. 3D text auto-flip).
350
+ * Camera angle ke anusaar text rotation update karein.
351
+ */
352
+ updateTextRotation(rotation, activeFloor) {
353
+ const strategy = this.strategyRegistry.get(this.textType) ?? this.strategyRegistry.get('2D');
354
+ if (typeof strategy.updateRotation === 'function') {
355
+ const group = activeFloor !== undefined ? this.getFloorTexts(activeFloor) : undefined;
356
+ strategy.updateRotation(rotation, group, this.onInvalidate);
357
+ }
358
+ }
359
+ /**
360
+ * Runs collision resolution if the active strategy supports collision decluttering.
361
+ * Agar active strategy collision support karti hai to labels ko auto-declutter karein.
362
+ */
363
+ updateCollision(camera, activeFloor) {
364
+ const strategy = this.strategyRegistry.get(this.textType) ?? this.strategyRegistry.get('2D');
365
+ if (strategy.supportsCollision) {
366
+ this.textCollisionService.update(this.textMap, camera, activeFloor);
367
+ }
368
+ }
369
+ /**
370
+ * Disposes all text labels and removes associated resources.
371
+ * Sabhi labels aur resources ko clean karein.
372
+ */
373
+ clear() {
374
+ this.cancelAnimation();
375
+ this.selectionPaint = new Map();
376
+ this.textMap.forEach((text) => {
377
+ const strategyType = text.userData.is3D ? '3D' : '2D';
378
+ const strategy = this.strategyRegistry.get(strategyType) ?? this.strategyRegistry.get('2D');
379
+ strategy.disposeText?.(text);
380
+ });
381
+ this.textMap.clear();
382
+ this.floorWiseTextMap.forEach((group) => {
383
+ group.clear();
384
+ });
385
+ this.floorWiseTextMap.clear();
386
+ }
387
+ /**
388
+ * Cleans up orphaned DOM elements from the document tree on floor switch without disposing 3D WebGL meshes.
389
+ * Floor switch par sirf DOM elements detach karta hai; reusable 3D Troika meshes dispose nahi hote.
390
+ */
391
+ cleanupTextDOM() {
392
+ this.textMap.forEach((text) => {
393
+ const strategyType = text.userData.is3D ? '3D' : '2D';
394
+ const strategy = this.strategyRegistry.get(strategyType) ?? this.strategyRegistry.get('2D');
395
+ strategy.cleanupDOM?.(text);
396
+ });
397
+ }
398
+ }
@@ -0,0 +1,36 @@
1
+ /**
2
+ * @file TextStrategyRegistry.ts
3
+ * @description Registry managing 2D and 3D text render strategies.
4
+ * English: Manages 2D DOM and 3D Troika text rendering strategies without conditional branching in business logic.
5
+ * Hinglish: 2D DOM aur 3D Troika text render strategies ko manage karne wali registry taaki call paths me if/else branching na karni pade.
6
+ */
7
+ import type { ITextRenderStrategy, TextType } from './ITextRenderStrategy.js';
8
+ export declare class TextStrategyRegistry {
9
+ private readonly strategies;
10
+ /**
11
+ * Registers a text render strategy.
12
+ * Strategy registry me nayi strategy register karein.
13
+ */
14
+ register(strategy: ITextRenderStrategy): void;
15
+ /**
16
+ * Retrieves registered strategy for a given text type.
17
+ * Text type ke liye registered strategy prapt karein.
18
+ */
19
+ get(type: TextType): ITextRenderStrategy | undefined;
20
+ /**
21
+ * Checks whether a strategy exists for a given text type.
22
+ * Check karein ki strategy registered hai ya nahi.
23
+ */
24
+ has(type: TextType): boolean;
25
+ /**
26
+ * Returns all registered text render strategies.
27
+ * Sabhi registered strategies prapt karein.
28
+ */
29
+ getAll(): ITextRenderStrategy[];
30
+ /**
31
+ * Returns all currently supported text types.
32
+ * Sabhi registered text types ki array prapt karein.
33
+ */
34
+ getSupportedTypes(): TextType[];
35
+ }
36
+ //# sourceMappingURL=TextStrategyRegistry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TextStrategyRegistry.d.ts","sourceRoot":"","sources":["../../../src/services/text-services/TextStrategyRegistry.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,mBAAmB,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAA;AAE1E,qBAAa,oBAAoB;IAC/B,OAAO,CAAC,QAAQ,CAAC,UAAU,CAA2C;IAEtE;;;OAGG;IACI,QAAQ,CAAC,QAAQ,EAAE,mBAAmB,GAAG,IAAI;IAIpD;;;OAGG;IACI,GAAG,CAAC,IAAI,EAAE,QAAQ,GAAG,mBAAmB,GAAG,SAAS;IAI3D;;;OAGG;IACI,GAAG,CAAC,IAAI,EAAE,QAAQ,GAAG,OAAO;IAInC;;;OAGG;IACI,MAAM,IAAI,mBAAmB,EAAE;IAItC;;;OAGG;IACI,iBAAiB,IAAI,QAAQ,EAAE;CAGvC"}
@@ -0,0 +1,44 @@
1
+ /**
2
+ * @file TextStrategyRegistry.ts
3
+ * @description Registry managing 2D and 3D text render strategies.
4
+ * English: Manages 2D DOM and 3D Troika text rendering strategies without conditional branching in business logic.
5
+ * Hinglish: 2D DOM aur 3D Troika text render strategies ko manage karne wali registry taaki call paths me if/else branching na karni pade.
6
+ */
7
+ export class TextStrategyRegistry {
8
+ strategies = new Map();
9
+ /**
10
+ * Registers a text render strategy.
11
+ * Strategy registry me nayi strategy register karein.
12
+ */
13
+ register(strategy) {
14
+ this.strategies.set(strategy.type, strategy);
15
+ }
16
+ /**
17
+ * Retrieves registered strategy for a given text type.
18
+ * Text type ke liye registered strategy prapt karein.
19
+ */
20
+ get(type) {
21
+ return this.strategies.get(type);
22
+ }
23
+ /**
24
+ * Checks whether a strategy exists for a given text type.
25
+ * Check karein ki strategy registered hai ya nahi.
26
+ */
27
+ has(type) {
28
+ return this.strategies.has(type);
29
+ }
30
+ /**
31
+ * Returns all registered text render strategies.
32
+ * Sabhi registered strategies prapt karein.
33
+ */
34
+ getAll() {
35
+ return Array.from(this.strategies.values());
36
+ }
37
+ /**
38
+ * Returns all currently supported text types.
39
+ * Sabhi registered text types ki array prapt karein.
40
+ */
41
+ getSupportedTypes() {
42
+ return Array.from(this.strategies.keys());
43
+ }
44
+ }
@@ -0,0 +1,12 @@
1
+ /**
2
+ * @file threeDisposeHelper.ts
3
+ * @description Safe recursive disposal utility for Three.js objects, geometries, and materials.
4
+ * WebGL memory leaks se bachane ke liye Three.js meshes, geometries aur materials ko safely dispose karne wala helper.
5
+ */
6
+ import type * as THREE from 'three';
7
+ /**
8
+ * Recursively disposes all geometries, materials, and textures attached to a Three.js Object3D.
9
+ * Ek Three.js object aur uske sabhi child meshes ko memory se clean karein.
10
+ */
11
+ export declare function disposeThreeObject(object: THREE.Object3D): void;
12
+ //# sourceMappingURL=threeDisposeHelper.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"threeDisposeHelper.d.ts","sourceRoot":"","sources":["../../src/services/threeDisposeHelper.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,KAAK,KAAK,MAAM,OAAO,CAAA;AAEnC;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,KAAK,CAAC,QAAQ,GAAG,IAAI,CAkC/D"}
@@ -0,0 +1,57 @@
1
+ /**
2
+ * @file threeDisposeHelper.ts
3
+ * @description Safe recursive disposal utility for Three.js objects, geometries, and materials.
4
+ * WebGL memory leaks se bachane ke liye Three.js meshes, geometries aur materials ko safely dispose karne wala helper.
5
+ */
6
+ /**
7
+ * Recursively disposes all geometries, materials, and textures attached to a Three.js Object3D.
8
+ * Ek Three.js object aur uske sabhi child meshes ko memory se clean karein.
9
+ */
10
+ export function disposeThreeObject(object) {
11
+ if (!object || typeof object.traverse !== 'function')
12
+ return;
13
+ if (object.userData) {
14
+ object.userData.isDisposed = true;
15
+ }
16
+ object.traverse((child) => {
17
+ if (child.userData) {
18
+ child.userData.isDisposed = true;
19
+ }
20
+ const mesh = child;
21
+ // Dispose geometry
22
+ if (mesh.geometry) {
23
+ mesh.geometry.dispose();
24
+ }
25
+ // Dispose material(s)
26
+ if (mesh.material) {
27
+ if (Array.isArray(mesh.material)) {
28
+ mesh.material.forEach((mat) => {
29
+ disposeMaterial(mat);
30
+ });
31
+ }
32
+ else {
33
+ disposeMaterial(mesh.material);
34
+ }
35
+ }
36
+ });
37
+ // Remove from parent if still attached
38
+ if (object.parent) {
39
+ object.parent.remove(object);
40
+ }
41
+ }
42
+ /**
43
+ * Disposes a single material and its associated texture maps.
44
+ * Material aur uske textures ko dispose karein.
45
+ */
46
+ function disposeMaterial(material) {
47
+ if (!material)
48
+ return;
49
+ const mat = material;
50
+ mat.map?.dispose();
51
+ mat.lightMap?.dispose();
52
+ mat.bumpMap?.dispose();
53
+ mat.normalMap?.dispose();
54
+ mat.specularMap?.dispose();
55
+ mat.envMap?.dispose();
56
+ material.dispose();
57
+ }
package/package.json CHANGED
@@ -1,6 +1,43 @@
1
1
  {
2
2
  "name": "@wovvmap/renderer-three",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "1.2.0",
4
+ "description": "Three.js renderer adapter and resource lifecycle for WovVMap.",
5
+ "license": "UNLICENSED",
6
+ "type": "module",
7
+ "sideEffects": false,
8
+ "main": "./dist/index.js",
9
+ "module": "./dist/index.js",
10
+ "types": "./dist/index.d.ts",
11
+ "files": [
12
+ "dist"
13
+ ],
14
+ "exports": {
15
+ ".": {
16
+ "types": "./dist/index.d.ts",
17
+ "import": "./dist/index.js",
18
+ "default": "./dist/index.js"
19
+ },
20
+ "./package.json": "./package.json"
21
+ },
22
+ "publishConfig": {
23
+ "access": "public"
24
+ },
25
+ "dependencies": {
26
+ "gsap": "^3.15.0",
27
+ "three": "^0.182.0",
28
+ "troika-three-text": "0.52.5",
29
+ "@wovvmap/contracts": "1.2.0",
30
+ "@wovvmap/runtime-core": "1.2.0",
31
+ "@wovvmap/geometry": "1.2.0"
32
+ },
33
+ "devDependencies": {
34
+ "@types/three": "^0.182.0"
35
+ },
36
+ "scripts": {
37
+ "benchmark": "pnpm run build && node --expose-gc scripts/benchmarkRenderer.mjs",
38
+ "build": "tsc -p tsconfig.build.json",
39
+ "lint": "eslint src",
40
+ "test": "vitest run --passWithNoTests",
41
+ "typecheck": "tsc -p tsconfig.build.json --noEmit"
42
+ }
6
43
  }
package/README.md DELETED
@@ -1,3 +0,0 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.