@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.
- package/dist/controllers/ImageController.d.ts +95 -0
- package/dist/controllers/ImageController.d.ts.map +1 -0
- package/dist/controllers/ImageController.js +129 -0
- package/dist/controllers/ShapeController.d.ts +95 -0
- package/dist/controllers/ShapeController.d.ts.map +1 -0
- package/dist/controllers/ShapeController.js +139 -0
- package/dist/controllers/TextController.d.ts +120 -0
- package/dist/controllers/TextController.d.ts.map +1 -0
- package/dist/controllers/TextController.js +161 -0
- package/dist/controllers/ViewerElementsController.d.ts +254 -0
- package/dist/controllers/ViewerElementsController.d.ts.map +1 -0
- package/dist/controllers/ViewerElementsController.js +490 -0
- package/dist/engine/CameraFollow.d.ts +13 -0
- package/dist/engine/CameraFollow.d.ts.map +1 -0
- package/dist/engine/CameraFollow.js +52 -0
- package/dist/engine/CameraManager.d.ts +143 -0
- package/dist/engine/CameraManager.d.ts.map +1 -0
- package/dist/engine/CameraManager.js +566 -0
- package/dist/engine/ControlsManager.d.ts +123 -0
- package/dist/engine/ControlsManager.d.ts.map +1 -0
- package/dist/engine/ControlsManager.js +604 -0
- package/dist/engine/InteractionManager.d.ts +45 -0
- package/dist/engine/InteractionManager.d.ts.map +1 -0
- package/dist/engine/InteractionManager.js +99 -0
- package/dist/engine/LightingManager.d.ts +25 -0
- package/dist/engine/LightingManager.d.ts.map +1 -0
- package/dist/engine/LightingManager.js +74 -0
- package/dist/engine/MapViewerEngine.d.ts +350 -0
- package/dist/engine/MapViewerEngine.d.ts.map +1 -0
- package/dist/engine/MapViewerEngine.js +1041 -0
- package/dist/engine/RendererManager.d.ts +77 -0
- package/dist/engine/RendererManager.d.ts.map +1 -0
- package/dist/engine/RendererManager.js +243 -0
- package/dist/index.d.ts +40 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +39 -0
- package/dist/services/image-services/ImageCacheService.d.ts +49 -0
- package/dist/services/image-services/ImageCacheService.d.ts.map +1 -0
- package/dist/services/image-services/ImageCacheService.js +121 -0
- package/dist/services/image-services/ImagePlaneService.d.ts +29 -0
- package/dist/services/image-services/ImagePlaneService.d.ts.map +1 -0
- package/dist/services/image-services/ImagePlaneService.js +82 -0
- package/dist/services/image-services/ImageService.d.ts +170 -0
- package/dist/services/image-services/ImageService.d.ts.map +1 -0
- package/dist/services/image-services/ImageService.js +537 -0
- package/dist/services/image-services/ImageSpriteService.d.ts +39 -0
- package/dist/services/image-services/ImageSpriteService.d.ts.map +1 -0
- package/dist/services/image-services/ImageSpriteService.js +135 -0
- package/dist/services/routes/RouteArrows.d.ts +34 -0
- package/dist/services/routes/RouteArrows.d.ts.map +1 -0
- package/dist/services/routes/RouteArrows.js +157 -0
- package/dist/services/routes/RouteCursor.d.ts +19 -0
- package/dist/services/routes/RouteCursor.d.ts.map +1 -0
- package/dist/services/routes/RouteCursor.js +68 -0
- package/dist/services/routes/RouteMotion.d.ts +31 -0
- package/dist/services/routes/RouteMotion.d.ts.map +1 -0
- package/dist/services/routes/RouteMotion.js +132 -0
- package/dist/services/routes/RouteRenderer.d.ts +52 -0
- package/dist/services/routes/RouteRenderer.d.ts.map +1 -0
- package/dist/services/routes/RouteRenderer.js +445 -0
- package/dist/services/routes/RouteStepHighlight.d.ts +22 -0
- package/dist/services/routes/RouteStepHighlight.d.ts.map +1 -0
- package/dist/services/routes/RouteStepHighlight.js +84 -0
- package/dist/services/routes/routeMarkers.d.ts +6 -0
- package/dist/services/routes/routeMarkers.d.ts.map +1 -0
- package/dist/services/routes/routeMarkers.js +41 -0
- package/dist/services/selectionPaint.d.ts +12 -0
- package/dist/services/selectionPaint.d.ts.map +1 -0
- package/dist/services/selectionPaint.js +8 -0
- package/dist/services/shape-services/ExtrudeShapeService.d.ts +54 -0
- package/dist/services/shape-services/ExtrudeShapeService.d.ts.map +1 -0
- package/dist/services/shape-services/ExtrudeShapeService.js +204 -0
- package/dist/services/shape-services/FlatShapeService.d.ts +25 -0
- package/dist/services/shape-services/FlatShapeService.d.ts.map +1 -0
- package/dist/services/shape-services/FlatShapeService.js +49 -0
- package/dist/services/shape-services/IShapeService.d.ts +24 -0
- package/dist/services/shape-services/IShapeService.d.ts.map +1 -0
- package/dist/services/shape-services/IShapeService.js +6 -0
- package/dist/services/shape-services/MaterialUtils.d.ts +15 -0
- package/dist/services/shape-services/MaterialUtils.d.ts.map +1 -0
- package/dist/services/shape-services/MaterialUtils.js +71 -0
- package/dist/services/shape-services/ShapeFactory.d.ts +20 -0
- package/dist/services/shape-services/ShapeFactory.d.ts.map +1 -0
- package/dist/services/shape-services/ShapeFactory.js +28 -0
- package/dist/services/shape-services/ShapeHighlightService.d.ts +13 -0
- package/dist/services/shape-services/ShapeHighlightService.d.ts.map +1 -0
- package/dist/services/shape-services/ShapeHighlightService.js +57 -0
- package/dist/services/shape-services/ShapeService.d.ts +129 -0
- package/dist/services/shape-services/ShapeService.d.ts.map +1 -0
- package/dist/services/shape-services/ShapeService.js +480 -0
- package/dist/services/shape-services/preparedGeometry.d.ts +13 -0
- package/dist/services/shape-services/preparedGeometry.d.ts.map +1 -0
- package/dist/services/shape-services/preparedGeometry.js +37 -0
- package/dist/services/text-services/ITextRenderStrategy.d.ts +79 -0
- package/dist/services/text-services/ITextRenderStrategy.d.ts.map +1 -0
- package/dist/services/text-services/ITextRenderStrategy.js +7 -0
- package/dist/services/text-services/Text2DService.d.ts +66 -0
- package/dist/services/text-services/Text2DService.d.ts.map +1 -0
- package/dist/services/text-services/Text2DService.js +483 -0
- package/dist/services/text-services/Text3DService.d.ts +51 -0
- package/dist/services/text-services/Text3DService.d.ts.map +1 -0
- package/dist/services/text-services/Text3DService.js +246 -0
- package/dist/services/text-services/TextCollisionService.d.ts +29 -0
- package/dist/services/text-services/TextCollisionService.d.ts.map +1 -0
- package/dist/services/text-services/TextCollisionService.js +117 -0
- package/dist/services/text-services/TextService.d.ts +159 -0
- package/dist/services/text-services/TextService.d.ts.map +1 -0
- package/dist/services/text-services/TextService.js +398 -0
- package/dist/services/text-services/TextStrategyRegistry.d.ts +36 -0
- package/dist/services/text-services/TextStrategyRegistry.d.ts.map +1 -0
- package/dist/services/text-services/TextStrategyRegistry.js +44 -0
- package/dist/services/threeDisposeHelper.d.ts +12 -0
- package/dist/services/threeDisposeHelper.d.ts.map +1 -0
- package/dist/services/threeDisposeHelper.js +57 -0
- package/package.json +40 -3
- package/README.md +0 -3
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file ITextRenderStrategy.ts
|
|
3
|
+
* @description Strategy interface for rendering text labels in the 3D scene (2D DOM vs 3D Troika mesh).
|
|
4
|
+
* English: Strategy interface defining text creation, DOM lifecycle, view mode elevation, color styling, and rotation contracts.
|
|
5
|
+
* Hinglish: 2D DOM aur 3D Mesh text labels render karne ke liye strategy interface jo creation, colors aur lifecycle define karta hai.
|
|
6
|
+
*/
|
|
7
|
+
import type * as THREE from 'three';
|
|
8
|
+
import type { NodePoint, DynamicDepthConfig, MapViewMode } from '@wovvmap/contracts';
|
|
9
|
+
export type TextType = '2D' | '3D';
|
|
10
|
+
export interface TextRenderOptions {
|
|
11
|
+
scale?: number;
|
|
12
|
+
showIcon?: boolean;
|
|
13
|
+
viewMode?: MapViewMode;
|
|
14
|
+
depthConfig?: Partial<DynamicDepthConfig>;
|
|
15
|
+
mallId?: string;
|
|
16
|
+
onInvalidate?: () => void;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Text rendering strategy contract for 2D DOM and 3D Troika mesh labels.
|
|
20
|
+
* 2D DOM aur 3D mesh labels ke liye strategy pattern interface.
|
|
21
|
+
*/
|
|
22
|
+
export interface ITextRenderStrategy {
|
|
23
|
+
/**
|
|
24
|
+
* Identifies the strategy type ("2D" or "3D").
|
|
25
|
+
* Strategy ka type identifier ('2D' ya '3D').
|
|
26
|
+
*/
|
|
27
|
+
readonly type: TextType;
|
|
28
|
+
/**
|
|
29
|
+
* Indicates whether this strategy participates in screen-space 2D collision culling.
|
|
30
|
+
* True for 2D DOM labels, false for 3D in-scene meshes.
|
|
31
|
+
* Kya ye strategy 2D screen-space collision culling use karti hai.
|
|
32
|
+
*/
|
|
33
|
+
readonly supportsCollision: boolean;
|
|
34
|
+
/**
|
|
35
|
+
* Creates a Three.js text object (CSS2DObject or Troika Text Mesh) for a given node point.
|
|
36
|
+
* Node point ke liye Three.js text object banayein.
|
|
37
|
+
*/
|
|
38
|
+
createText(node: NodePoint, options: TextRenderOptions): THREE.Object3D | null;
|
|
39
|
+
/**
|
|
40
|
+
* Updates vertical elevation of a single text object across 2D/3D map modes.
|
|
41
|
+
* Mode ke anusaar single text object ki vertical elevation adjust karein.
|
|
42
|
+
*/
|
|
43
|
+
applyViewMode(child: THREE.Object3D, mode: MapViewMode, depthConfig?: Partial<DynamicDepthConfig>): void;
|
|
44
|
+
/**
|
|
45
|
+
* Optional method to resolve target vertical elevation for smooth 2D/3D mode transitions.
|
|
46
|
+
* English: Strategies supporting animated elevation should return the computed target Y position.
|
|
47
|
+
* If omitted by custom strategies, TextService executes a documented fallback (probes applyViewMode
|
|
48
|
+
* at transition start to derive target elevation and smoothly interpolate from start to target).
|
|
49
|
+
* Hinglish: Smooth elevation transition support karne wali strategy target elevation return kare.
|
|
50
|
+
* Agar custom strategy ise omit kare toh TextService transition start par applyViewMode probe karke
|
|
51
|
+
* target elevation derive karta hai taaki animation ke end me sudden jump na ho.
|
|
52
|
+
*/
|
|
53
|
+
resolveTargetElevation?(child: THREE.Object3D, mode: MapViewMode, depthConfig?: Partial<DynamicDepthConfig>): number;
|
|
54
|
+
/**
|
|
55
|
+
* Optional hook for camera rotation (e.g. flipping 3D text to prevent upside-down reading).
|
|
56
|
+
* Camera ghumne par text orientation adjust karne ka optional hook.
|
|
57
|
+
*/
|
|
58
|
+
updateRotation?(rotationRad: number, floorGroup?: THREE.Group, onInvalidate?: () => void): void;
|
|
59
|
+
/**
|
|
60
|
+
* Optional hook to update text colors across strategies supporting dynamic color styling.
|
|
61
|
+
* English: Updates color styling on text meshes or DOM wrappers based on single color or per-type mapping.
|
|
62
|
+
* Hinglish: Single color ya per-type mapping ke mutabik text color update karne ka optional hook.
|
|
63
|
+
*/
|
|
64
|
+
updateTextColor?(object: THREE.Object3D, colorOrMap?: string | number | Record<string, string | number>): void;
|
|
65
|
+
/** Apply a temporary selection color while retaining the latest base styling.
|
|
66
|
+
* Hinglish: Selection ka rang temporary hai; clear par latest normal rang vapas mile. */
|
|
67
|
+
setSelected?(object: THREE.Object3D, selected: boolean, color: string): void;
|
|
68
|
+
/**
|
|
69
|
+
* Optional hook to detach temporary DOM elements on floor switch without disposing 3D WebGL meshes.
|
|
70
|
+
* Floor switch par sirf DOM elements detach karein; 3D meshes ke GPU resources untouched rahein.
|
|
71
|
+
*/
|
|
72
|
+
cleanupDOM?(object: THREE.Object3D): void;
|
|
73
|
+
/**
|
|
74
|
+
* Disposes the text object and associated DOM / WebGL resources permanently on removal.
|
|
75
|
+
* Text object aur uske resources ko permanently remove hone par dispose karein.
|
|
76
|
+
*/
|
|
77
|
+
disposeText?(object: THREE.Object3D): void;
|
|
78
|
+
}
|
|
79
|
+
//# sourceMappingURL=ITextRenderStrategy.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ITextRenderStrategy.d.ts","sourceRoot":"","sources":["../../../src/services/text-services/ITextRenderStrategy.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,KAAK,KAAK,MAAM,OAAO,CAAA;AACnC,OAAO,KAAK,EAAE,SAAS,EAAE,kBAAkB,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAA;AAEpF,MAAM,MAAM,QAAQ,GAAG,IAAI,GAAG,IAAI,CAAA;AAElC,MAAM,WAAW,iBAAiB;IAChC,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,QAAQ,CAAC,EAAE,WAAW,CAAA;IACtB,WAAW,CAAC,EAAE,OAAO,CAAC,kBAAkB,CAAC,CAAA;IACzC,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,YAAY,CAAC,EAAE,MAAM,IAAI,CAAA;CAC1B;AAED;;;GAGG;AACH,MAAM,WAAW,mBAAmB;IAClC;;;OAGG;IACH,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAA;IAEvB;;;;OAIG;IACH,QAAQ,CAAC,iBAAiB,EAAE,OAAO,CAAA;IAEnC;;;OAGG;IACH,UAAU,CAAC,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,iBAAiB,GAAG,KAAK,CAAC,QAAQ,GAAG,IAAI,CAAA;IAE9E;;;OAGG;IACH,aAAa,CACX,KAAK,EAAE,KAAK,CAAC,QAAQ,EACrB,IAAI,EAAE,WAAW,EACjB,WAAW,CAAC,EAAE,OAAO,CAAC,kBAAkB,CAAC,GACxC,IAAI,CAAA;IAEP;;;;;;;;OAQG;IACH,sBAAsB,CAAC,CACrB,KAAK,EAAE,KAAK,CAAC,QAAQ,EACrB,IAAI,EAAE,WAAW,EACjB,WAAW,CAAC,EAAE,OAAO,CAAC,kBAAkB,CAAC,GACxC,MAAM,CAAA;IAET;;;OAGG;IACH,cAAc,CAAC,CAAC,WAAW,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,KAAK,CAAC,KAAK,EAAE,YAAY,CAAC,EAAE,MAAM,IAAI,GAAG,IAAI,CAAA;IAE/F;;;;OAIG;IACH,eAAe,CAAC,CACd,MAAM,EAAE,KAAK,CAAC,QAAQ,EACtB,UAAU,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,GAC7D,IAAI,CAAA;IAEP;6FACyF;IACzF,WAAW,CAAC,CAAC,MAAM,EAAE,KAAK,CAAC,QAAQ,EAAE,QAAQ,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAAA;IAE5E;;;OAGG;IACH,UAAU,CAAC,CAAC,MAAM,EAAE,KAAK,CAAC,QAAQ,GAAG,IAAI,CAAA;IAEzC;;;OAGG;IACH,WAAW,CAAC,CAAC,MAAM,EAAE,KAAK,CAAC,QAAQ,GAAG,IAAI,CAAA;CAC3C"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file ITextRenderStrategy.ts
|
|
3
|
+
* @description Strategy interface for rendering text labels in the 3D scene (2D DOM vs 3D Troika mesh).
|
|
4
|
+
* English: Strategy interface defining text creation, DOM lifecycle, view mode elevation, color styling, and rotation contracts.
|
|
5
|
+
* Hinglish: 2D DOM aur 3D Mesh text labels render karne ke liye strategy interface jo creation, colors aur lifecycle define karta hai.
|
|
6
|
+
*/
|
|
7
|
+
export {};
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file Text2DService.ts
|
|
3
|
+
* @description 2D HTML/CSS label service creating camera-facing DOM elements via Three.js CSS2DRenderer.
|
|
4
|
+
* Three.js CSS2DRenderer ke sath camera-facing 2D HTML labels banane wali service.
|
|
5
|
+
*/
|
|
6
|
+
import type * as THREE from 'three';
|
|
7
|
+
import { CSS2DObject } from 'three/examples/jsm/renderers/CSS2DRenderer.js';
|
|
8
|
+
import type { NodePoint, DynamicDepthConfig, MapViewMode } from '@wovvmap/contracts';
|
|
9
|
+
import type { ITextRenderStrategy, TextRenderOptions, TextType } from './ITextRenderStrategy.js';
|
|
10
|
+
export declare class Text2DService implements ITextRenderStrategy {
|
|
11
|
+
readonly type: TextType;
|
|
12
|
+
readonly supportsCollision: boolean;
|
|
13
|
+
private stylesInjected;
|
|
14
|
+
/**
|
|
15
|
+
* Injects CSS stylesheet into document head for styling 2D labels and state transitions.
|
|
16
|
+
* Document head me viewer label CSS styles inject karein.
|
|
17
|
+
*/
|
|
18
|
+
injectStyles(): void;
|
|
19
|
+
/**
|
|
20
|
+
* Strategy interface implementation creating a 2D DOM label.
|
|
21
|
+
* ITextRenderStrategy interface method jo 2D DOM label banata hai.
|
|
22
|
+
*/
|
|
23
|
+
createText(node: NodePoint, options?: TextRenderOptions): THREE.Object3D | null;
|
|
24
|
+
/**
|
|
25
|
+
* Constructs a CSS2DObject label for a node point.
|
|
26
|
+
* Node point ke liye 2D HTML text label create karein.
|
|
27
|
+
*/
|
|
28
|
+
/**
|
|
29
|
+
* Updates text color on a 2D DOM label supporting explicit color overrides, node types, and theme tokens.
|
|
30
|
+
* 2D DOM label ka text color update karein; explicit overrides CSS classes par precedence lete hain.
|
|
31
|
+
*/
|
|
32
|
+
/**
|
|
33
|
+
* Updates text color on a 2D DOM label using CSS variable so that .state-highlighted !important takes precedence.
|
|
34
|
+
* 2D DOM label ka text color CSS variable se update karein taaki .state-highlighted !important color override na ho.
|
|
35
|
+
*/
|
|
36
|
+
updateTextColor(object: THREE.Object3D, colorOrMap?: string | number | Record<string, string | number>): void;
|
|
37
|
+
/** Selection is a CSS overlay; explicit text colors and hidden group intent stay untouched.
|
|
38
|
+
* Hinglish: Sirf selection class/rang badle; normal override aur group visibility nahi badalti. */
|
|
39
|
+
setSelected(object: THREE.Object3D, selected: boolean, color: string): void;
|
|
40
|
+
create2DText(node: NodePoint, scale?: number, showIcon?: boolean, viewMode?: MapViewMode, depthConfig?: Partial<DynamicDepthConfig>): CSS2DObject | null;
|
|
41
|
+
/**
|
|
42
|
+
* Adjusts vertical elevation across view modes.
|
|
43
|
+
* View mode ke anusaar 2D label ki vertical unchai update karein.
|
|
44
|
+
*/
|
|
45
|
+
/**
|
|
46
|
+
* Resolves target vertical elevation across view modes.
|
|
47
|
+
* View mode ke anusaar 2D label ki target elevation calculate karein.
|
|
48
|
+
*/
|
|
49
|
+
resolveTargetElevation(child: THREE.Object3D, mode?: MapViewMode, depthConfig?: Partial<DynamicDepthConfig>): number;
|
|
50
|
+
applyViewMode(child: THREE.Object3D, mode?: MapViewMode, depthConfig?: Partial<DynamicDepthConfig>): void;
|
|
51
|
+
/**
|
|
52
|
+
* Safely detaches CSS2D HTML element from DOM.
|
|
53
|
+
* DOM tree se label elements remove karein.
|
|
54
|
+
*/
|
|
55
|
+
/**
|
|
56
|
+
* Safely detaches CSS2D HTML element from DOM tree.
|
|
57
|
+
* DOM tree se label elements remove karein.
|
|
58
|
+
*/
|
|
59
|
+
cleanupDOM(object: THREE.Object3D): void;
|
|
60
|
+
disposeText(object: THREE.Object3D): void;
|
|
61
|
+
/**
|
|
62
|
+
* Creates the container HTML element for the label.
|
|
63
|
+
*/
|
|
64
|
+
private createContainerElement;
|
|
65
|
+
}
|
|
66
|
+
//# sourceMappingURL=Text2DService.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Text2DService.d.ts","sourceRoot":"","sources":["../../../src/services/text-services/Text2DService.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,KAAK,KAAK,MAAM,OAAO,CAAA;AACnC,OAAO,EAAE,WAAW,EAAE,MAAM,+CAA+C,CAAA;AAC3E,OAAO,KAAK,EAAE,SAAS,EAAE,kBAAkB,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAA;AAEpF,OAAO,KAAK,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAA;AAE7F,qBAAa,aAAc,YAAW,mBAAmB;IACvD,SAAgB,IAAI,EAAE,QAAQ,CAAO;IACrC,SAAgB,iBAAiB,EAAE,OAAO,CAAO;IACjD,OAAO,CAAC,cAAc,CAAQ;IAE9B;;;OAGG;IACI,YAAY,IAAI,IAAI;IA4H3B;;;OAGG;IACI,UAAU,CAAC,IAAI,EAAE,SAAS,EAAE,OAAO,GAAE,iBAAsB,GAAG,KAAK,CAAC,QAAQ,GAAG,IAAI;IAU1F;;;OAGG;IACH;;;OAGG;IACH;;;OAGG;IACI,eAAe,CACpB,MAAM,EAAE,KAAK,CAAC,QAAQ,EACtB,UAAU,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,GAC7D,IAAI;IA2EP;uGACmG;IAC5F,WAAW,CAAC,MAAM,EAAE,KAAK,CAAC,QAAQ,EAAE,QAAQ,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI;IAa3E,YAAY,CACjB,IAAI,EAAE,SAAS,EACf,KAAK,GAAE,MAAU,EACjB,QAAQ,GAAE,OAAc,EACxB,QAAQ,GAAE,WAAkB,EAC5B,WAAW,CAAC,EAAE,OAAO,CAAC,kBAAkB,CAAC,GACxC,WAAW,GAAG,IAAI;IA+FrB;;;OAGG;IACH;;;OAGG;IACI,sBAAsB,CAC3B,KAAK,EAAE,KAAK,CAAC,QAAQ,EACrB,IAAI,GAAE,WAAkB,EACxB,WAAW,CAAC,EAAE,OAAO,CAAC,kBAAkB,CAAC,GACxC,MAAM;IAwBF,aAAa,CAClB,KAAK,EAAE,KAAK,CAAC,QAAQ,EACrB,IAAI,GAAE,WAAkB,EACxB,WAAW,CAAC,EAAE,OAAO,CAAC,kBAAkB,CAAC,GACxC,IAAI;IAIP;;;OAGG;IACH;;;OAGG;IACI,UAAU,CAAC,MAAM,EAAE,KAAK,CAAC,QAAQ,GAAG,IAAI;IAOxC,WAAW,CAAC,MAAM,EAAE,KAAK,CAAC,QAAQ,GAAG,IAAI;IAOhD;;OAEG;IACH,OAAO,CAAC,sBAAsB;CAuH/B"}
|
|
@@ -0,0 +1,483 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file Text2DService.ts
|
|
3
|
+
* @description 2D HTML/CSS label service creating camera-facing DOM elements via Three.js CSS2DRenderer.
|
|
4
|
+
* Three.js CSS2DRenderer ke sath camera-facing 2D HTML labels banane wali service.
|
|
5
|
+
*/
|
|
6
|
+
import { CSS2DObject } from 'three/examples/jsm/renderers/CSS2DRenderer.js';
|
|
7
|
+
import { resolveModeDepth, resolveSurfaceElevation } from '@wovvmap/contracts';
|
|
8
|
+
export class Text2DService {
|
|
9
|
+
type = '2D';
|
|
10
|
+
supportsCollision = true;
|
|
11
|
+
stylesInjected = false;
|
|
12
|
+
/**
|
|
13
|
+
* Injects CSS stylesheet into document head for styling 2D labels and state transitions.
|
|
14
|
+
* Document head me viewer label CSS styles inject karein.
|
|
15
|
+
*/
|
|
16
|
+
injectStyles() {
|
|
17
|
+
if (this.stylesInjected || typeof document === 'undefined')
|
|
18
|
+
return;
|
|
19
|
+
const style = document.createElement('style');
|
|
20
|
+
style.id = 'wovvmap-viewer-labels-style';
|
|
21
|
+
style.textContent = `
|
|
22
|
+
.viewer-base-label {
|
|
23
|
+
position: absolute;
|
|
24
|
+
pointer-events: none;
|
|
25
|
+
transform-origin: left center;
|
|
26
|
+
display: flex;
|
|
27
|
+
align-items: center;
|
|
28
|
+
gap: 6px;
|
|
29
|
+
/* No transition on outer container: Three.js CSS2DRenderer updates transform directly per frame.
|
|
30
|
+
Outer container par transform transition nahi honi chahiye taaki Three.js camera movement ke sath 1:1 sync rahe. */
|
|
31
|
+
}
|
|
32
|
+
.viewer-base-label .label-content {
|
|
33
|
+
display: flex;
|
|
34
|
+
align-items: center;
|
|
35
|
+
gap: 6px;
|
|
36
|
+
}
|
|
37
|
+
.viewer-base-label .label-visual {
|
|
38
|
+
background: var(--viewer-bg-color, rgba(255, 255, 255, 0.95));
|
|
39
|
+
border-radius: 50%;
|
|
40
|
+
box-shadow: 0 2px 5px rgba(0,0,0,0.2);
|
|
41
|
+
padding: 4px;
|
|
42
|
+
display: flex;
|
|
43
|
+
align-items: center;
|
|
44
|
+
justify-content: center;
|
|
45
|
+
width: 20px;
|
|
46
|
+
height: 20px;
|
|
47
|
+
box-sizing: content-box;
|
|
48
|
+
}
|
|
49
|
+
.viewer-base-label .label-visual.visual-no-bg {
|
|
50
|
+
background: transparent;
|
|
51
|
+
box-shadow: none;
|
|
52
|
+
padding: 0;
|
|
53
|
+
width: 8px;
|
|
54
|
+
height: 8px;
|
|
55
|
+
}
|
|
56
|
+
.viewer-base-label .label-icon {
|
|
57
|
+
width: 100%;
|
|
58
|
+
height: 100%;
|
|
59
|
+
object-fit: contain;
|
|
60
|
+
display: block;
|
|
61
|
+
}
|
|
62
|
+
.viewer-base-label .label-primary-dot {
|
|
63
|
+
width: 100%;
|
|
64
|
+
height: 100%;
|
|
65
|
+
background-color: var(--viewer-dot-color, #3b82f6);
|
|
66
|
+
border: 1px solid white;
|
|
67
|
+
border-radius: 50%;
|
|
68
|
+
box-shadow: 0 1px 2px rgba(0,0,0,0.2);
|
|
69
|
+
}
|
|
70
|
+
.viewer-base-label .label-text {
|
|
71
|
+
font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
|
|
72
|
+
font-size: 13px;
|
|
73
|
+
font-weight: 600;
|
|
74
|
+
color: var(--label-override-color, var(--viewer-text-color, #1a1a1a));
|
|
75
|
+
white-space: normal;
|
|
76
|
+
max-width: 140px;
|
|
77
|
+
line-height: 1.25;
|
|
78
|
+
text-shadow: 0 0 3px var(--viewer-bg-color, rgba(255, 255, 255, 0.8)), 0 0 10px var(--viewer-bg-color, rgba(255, 255, 255, 0.5));
|
|
79
|
+
}
|
|
80
|
+
.viewer-base-label .label-collision-dot {
|
|
81
|
+
width: 8px;
|
|
82
|
+
height: 8px;
|
|
83
|
+
background-color: var(--viewer-dot-color, #3b82f6);
|
|
84
|
+
border: 2px solid white;
|
|
85
|
+
border-radius: 50%;
|
|
86
|
+
box-shadow: 0 1px 4px rgba(0,0,0,0.2);
|
|
87
|
+
display: none;
|
|
88
|
+
}
|
|
89
|
+
.viewer-base-label.state-icon-only .label-text {
|
|
90
|
+
display: none;
|
|
91
|
+
}
|
|
92
|
+
.viewer-base-label.state-dot-only .label-content {
|
|
93
|
+
display: none;
|
|
94
|
+
}
|
|
95
|
+
.viewer-base-label.state-dot-only .label-collision-dot {
|
|
96
|
+
display: block;
|
|
97
|
+
}
|
|
98
|
+
.viewer-base-label.state-hidden {
|
|
99
|
+
opacity: 0;
|
|
100
|
+
transform: scale(0.8);
|
|
101
|
+
}
|
|
102
|
+
.viewer-base-label.state-highlighted {
|
|
103
|
+
z-index: 10000 !important;
|
|
104
|
+
filter: drop-shadow(0 4px 6px rgba(0,0,0,0.3));
|
|
105
|
+
}
|
|
106
|
+
.viewer-base-label.state-highlighted .label-visual {
|
|
107
|
+
transform: scale(1.4);
|
|
108
|
+
transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
|
|
109
|
+
border-color: var(--highlight-color, #CFA44E);
|
|
110
|
+
}
|
|
111
|
+
.viewer-base-label.state-highlighted .label-text {
|
|
112
|
+
color: var(--highlight-color, #CFA44E) !important;
|
|
113
|
+
font-size: 15px;
|
|
114
|
+
font-weight: 800;
|
|
115
|
+
text-shadow: 0 0 4px #fff, 0 0 4px #fff;
|
|
116
|
+
}
|
|
117
|
+
.viewer-base-label.state-highlighted.role-startpoint .label-text {
|
|
118
|
+
color: var(--viewer-startpoint-2d, var(--highlight-color, #CFA44E)) !important;
|
|
119
|
+
}
|
|
120
|
+
.viewer-base-label.state-highlighted.role-endpoint .label-text {
|
|
121
|
+
color: var(--viewer-endpoint-2d, var(--highlight-color, #CFA44E)) !important;
|
|
122
|
+
}
|
|
123
|
+
.viewer-base-label.state-highlighted.role-amenity .label-text {
|
|
124
|
+
color: var(--viewer-amenity-2d, var(--highlight-color, #CFA44E)) !important;
|
|
125
|
+
}
|
|
126
|
+
.viewer-base-label.state-highlighted.role-subcategory .label-text {
|
|
127
|
+
color: var(--viewer-subcategory-2d, var(--highlight-color, #CFA44E)) !important;
|
|
128
|
+
}
|
|
129
|
+
.viewer-base-label.state-highlighted.role-category .label-text {
|
|
130
|
+
color: var(--viewer-category-2d, var(--highlight-color, #CFA44E)) !important;
|
|
131
|
+
}
|
|
132
|
+
.viewer-base-label.state-highlighted.role-normal .label-text {
|
|
133
|
+
color: var(--highlight-color, var(--selection-text-color, #CFA44E)) !important;
|
|
134
|
+
}
|
|
135
|
+
`;
|
|
136
|
+
document.head.appendChild(style);
|
|
137
|
+
this.stylesInjected = true;
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Strategy interface implementation creating a 2D DOM label.
|
|
141
|
+
* ITextRenderStrategy interface method jo 2D DOM label banata hai.
|
|
142
|
+
*/
|
|
143
|
+
createText(node, options = {}) {
|
|
144
|
+
return this.create2DText(node, options.scale ?? 0.1, options.showIcon ?? true, options.viewMode ?? '3D', options.depthConfig);
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Constructs a CSS2DObject label for a node point.
|
|
148
|
+
* Node point ke liye 2D HTML text label create karein.
|
|
149
|
+
*/
|
|
150
|
+
/**
|
|
151
|
+
* Updates text color on a 2D DOM label supporting explicit color overrides, node types, and theme tokens.
|
|
152
|
+
* 2D DOM label ka text color update karein; explicit overrides CSS classes par precedence lete hain.
|
|
153
|
+
*/
|
|
154
|
+
/**
|
|
155
|
+
* Updates text color on a 2D DOM label using CSS variable so that .state-highlighted !important takes precedence.
|
|
156
|
+
* 2D DOM label ka text color CSS variable se update karein taaki .state-highlighted !important color override na ho.
|
|
157
|
+
*/
|
|
158
|
+
updateTextColor(object, colorOrMap) {
|
|
159
|
+
const element = object.element;
|
|
160
|
+
const textEl = element?.querySelector?.('.label-text');
|
|
161
|
+
let newColor;
|
|
162
|
+
if (colorOrMap === undefined) {
|
|
163
|
+
newColor = undefined;
|
|
164
|
+
}
|
|
165
|
+
else if (typeof colorOrMap === 'string' || typeof colorOrMap === 'number') {
|
|
166
|
+
newColor = colorOrMap;
|
|
167
|
+
}
|
|
168
|
+
else if (typeof colorOrMap === 'object' && colorOrMap !== null) {
|
|
169
|
+
const nodeType = object.userData.nodeType;
|
|
170
|
+
const category = object.userData.category;
|
|
171
|
+
const subCategory = object.userData.subCategory;
|
|
172
|
+
const nodeId = (object.userData.nodeId ?? object.userData.id);
|
|
173
|
+
if (nodeId && colorOrMap[nodeId] !== undefined) {
|
|
174
|
+
newColor = colorOrMap[nodeId];
|
|
175
|
+
}
|
|
176
|
+
else if ((nodeType === 'StartPoint' || nodeType === 'startPoint') &&
|
|
177
|
+
(colorOrMap['startPoint2D'] !== undefined || colorOrMap['StartPoint'] !== undefined)) {
|
|
178
|
+
newColor = colorOrMap['startPoint2D'] ?? colorOrMap['StartPoint'];
|
|
179
|
+
}
|
|
180
|
+
else if ((nodeType === 'EndPoint' || nodeType === 'endPoint') &&
|
|
181
|
+
(colorOrMap['endPoint2D'] !== undefined || colorOrMap['EndPoint'] !== undefined)) {
|
|
182
|
+
newColor = colorOrMap['endPoint2D'] ?? colorOrMap['EndPoint'];
|
|
183
|
+
}
|
|
184
|
+
else if ((nodeType === 'Amenity' ||
|
|
185
|
+
nodeType === 'amenity' ||
|
|
186
|
+
nodeType === 'Transit' ||
|
|
187
|
+
nodeType === 'transit') &&
|
|
188
|
+
(colorOrMap['amenity2D'] !== undefined ||
|
|
189
|
+
colorOrMap['transit2D'] !== undefined ||
|
|
190
|
+
colorOrMap['Amenity'] !== undefined)) {
|
|
191
|
+
newColor = colorOrMap['amenity2D'] ?? colorOrMap['transit2D'] ?? colorOrMap['Amenity'];
|
|
192
|
+
}
|
|
193
|
+
else if (nodeType && colorOrMap[nodeType] !== undefined) {
|
|
194
|
+
newColor = colorOrMap[nodeType];
|
|
195
|
+
}
|
|
196
|
+
else if (subCategory && colorOrMap[subCategory] !== undefined) {
|
|
197
|
+
newColor = colorOrMap[subCategory];
|
|
198
|
+
}
|
|
199
|
+
else if (subCategory && colorOrMap['subCategory2D'] !== undefined) {
|
|
200
|
+
newColor = colorOrMap['subCategory2D'];
|
|
201
|
+
}
|
|
202
|
+
else if (category && colorOrMap[category] !== undefined) {
|
|
203
|
+
newColor = colorOrMap[category];
|
|
204
|
+
}
|
|
205
|
+
else if (category && colorOrMap['category2D'] !== undefined) {
|
|
206
|
+
newColor = colorOrMap['category2D'];
|
|
207
|
+
}
|
|
208
|
+
else if (colorOrMap['default'] !== undefined) {
|
|
209
|
+
newColor = colorOrMap['default'];
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
const colorStr = newColor !== undefined
|
|
213
|
+
? typeof newColor === 'number'
|
|
214
|
+
? `#${newColor.toString(16).padStart(6, '0')}`
|
|
215
|
+
: newColor
|
|
216
|
+
: undefined;
|
|
217
|
+
if (element && element.style) {
|
|
218
|
+
if (typeof element.style.setProperty === 'function') {
|
|
219
|
+
if (colorStr) {
|
|
220
|
+
element.style.setProperty('--label-override-color', colorStr);
|
|
221
|
+
}
|
|
222
|
+
else {
|
|
223
|
+
element.style.removeProperty('--label-override-color');
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
// Clear any inline style on textEl so CSS variable and .state-highlighted !important take full effect
|
|
228
|
+
if (textEl && textEl.style) {
|
|
229
|
+
textEl.style.color = '';
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
/** Selection is a CSS overlay; explicit text colors and hidden group intent stay untouched.
|
|
233
|
+
* Hinglish: Sirf selection class/rang badle; normal override aur group visibility nahi badalti. */
|
|
234
|
+
setSelected(object, selected, color) {
|
|
235
|
+
const element = object.element;
|
|
236
|
+
if (!element)
|
|
237
|
+
return;
|
|
238
|
+
if (selected) {
|
|
239
|
+
element.classList.remove('state-hidden', 'state-dot-only', 'state-icon-only');
|
|
240
|
+
element.classList.add('state-highlighted', 'role-normal');
|
|
241
|
+
element.style.setProperty('--selection-text-color', color);
|
|
242
|
+
}
|
|
243
|
+
else {
|
|
244
|
+
element.classList.remove('state-highlighted', 'role-normal');
|
|
245
|
+
element.style.removeProperty('--selection-text-color');
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
create2DText(node, scale = 1, showIcon = true, viewMode = '3D', depthConfig) {
|
|
249
|
+
this.injectStyles();
|
|
250
|
+
const locationName = node.assets?.locationName;
|
|
251
|
+
if (!locationName || !locationName.text || locationName.text.trim() === '') {
|
|
252
|
+
return null;
|
|
253
|
+
}
|
|
254
|
+
const { text, width, height, area, pinpoint: propPinpoint } = locationName;
|
|
255
|
+
// Pinpoint target coordinate resolution
|
|
256
|
+
let pinpoint = propPinpoint;
|
|
257
|
+
if (!pinpoint && area && width && height) {
|
|
258
|
+
pinpoint = {
|
|
259
|
+
x: area.x - width / 2,
|
|
260
|
+
y: area.y - height / 2,
|
|
261
|
+
};
|
|
262
|
+
}
|
|
263
|
+
if (!pinpoint) {
|
|
264
|
+
pinpoint = { x: node.x, y: node.y };
|
|
265
|
+
}
|
|
266
|
+
// Dynamic surface elevation: solid roof, hollow room floor, or 2D unitDepth
|
|
267
|
+
const shapeType = node.shapeDetail?.shapeType?.toLowerCase();
|
|
268
|
+
const isHollow = shapeType === 'hollow' ||
|
|
269
|
+
shapeType === 'open' ||
|
|
270
|
+
shapeType === 'flat' ||
|
|
271
|
+
shapeType === 'hollow-box' ||
|
|
272
|
+
shapeType === 'courtyard';
|
|
273
|
+
const surfaceElevation = resolveSurfaceElevation(node, viewMode, depthConfig);
|
|
274
|
+
const isSolidUnit = !isHollow && surfaceElevation > (depthConfig?.floorBaseDepth ?? 0);
|
|
275
|
+
const effectiveElevation = viewMode === '3D' && isSolidUnit && depthConfig?.defaultUnitDepth !== undefined
|
|
276
|
+
? depthConfig.defaultUnitDepth
|
|
277
|
+
: surfaceElevation;
|
|
278
|
+
const yPos = effectiveElevation + 0.2; // slight clearance offset
|
|
279
|
+
// Resolve semantic role class for 2D label token styling
|
|
280
|
+
const nodeType = (node.type || '').toLowerCase();
|
|
281
|
+
let roleClass = '';
|
|
282
|
+
if (nodeType.includes('start')) {
|
|
283
|
+
roleClass = 'role-startpoint';
|
|
284
|
+
}
|
|
285
|
+
else if (nodeType.includes('end')) {
|
|
286
|
+
roleClass = 'role-endpoint';
|
|
287
|
+
}
|
|
288
|
+
else if (nodeType.includes('amenity') ||
|
|
289
|
+
nodeType.includes('restroom') ||
|
|
290
|
+
nodeType.includes('elevator') ||
|
|
291
|
+
nodeType.includes('escalator') ||
|
|
292
|
+
nodeType.includes('transit')) {
|
|
293
|
+
roleClass = 'role-amenity';
|
|
294
|
+
}
|
|
295
|
+
else if (node.subCategoryCode !== undefined) {
|
|
296
|
+
roleClass = 'role-subcategory';
|
|
297
|
+
}
|
|
298
|
+
else if (node.categoryCode !== undefined) {
|
|
299
|
+
roleClass = 'role-category';
|
|
300
|
+
}
|
|
301
|
+
// Create DOM elements (or lightweight mock when document is undefined in headless tests)
|
|
302
|
+
const container = this.createContainerElement(node.key, text, showIcon, node.assets?.logo, roleClass);
|
|
303
|
+
const label = new CSS2DObject(container);
|
|
304
|
+
label.center.set(0, 0.5); // Left-center anchor
|
|
305
|
+
const posX = pinpoint.x * scale;
|
|
306
|
+
const posZ = pinpoint.y * scale;
|
|
307
|
+
label.position.set(posX, yPos, posZ);
|
|
308
|
+
label.name = `text-${node.key}`;
|
|
309
|
+
label.userData = {
|
|
310
|
+
id: node.key,
|
|
311
|
+
nodeId: node.key,
|
|
312
|
+
nodeType: node.type,
|
|
313
|
+
category: node.categoryCode !== undefined ? String(node.categoryCode) : undefined,
|
|
314
|
+
subCategory: node.subCategoryCode !== undefined ? String(node.subCategoryCode) : undefined,
|
|
315
|
+
type: 'text',
|
|
316
|
+
is2D: true,
|
|
317
|
+
isHtml: true,
|
|
318
|
+
hasIcon: showIcon && Boolean(node.assets?.logo),
|
|
319
|
+
originalDepth: node.shapeDetail?.depth ?? 6,
|
|
320
|
+
floorBash: Boolean(node.shapeDetail?.floorBash),
|
|
321
|
+
isFloorBase: Boolean(node.shapeDetail?.floorBash),
|
|
322
|
+
isHollow,
|
|
323
|
+
};
|
|
324
|
+
return label;
|
|
325
|
+
}
|
|
326
|
+
/**
|
|
327
|
+
* Adjusts vertical elevation across view modes.
|
|
328
|
+
* View mode ke anusaar 2D label ki vertical unchai update karein.
|
|
329
|
+
*/
|
|
330
|
+
/**
|
|
331
|
+
* Resolves target vertical elevation across view modes.
|
|
332
|
+
* View mode ke anusaar 2D label ki target elevation calculate karein.
|
|
333
|
+
*/
|
|
334
|
+
resolveTargetElevation(child, mode = '3D', depthConfig) {
|
|
335
|
+
if (child.userData.type === 'text' && child.userData.originalDepth !== undefined) {
|
|
336
|
+
const modeConfig = resolveModeDepth(mode, depthConfig);
|
|
337
|
+
const isBaseOrHollow = child.userData.floorBash === true ||
|
|
338
|
+
child.userData.isFloorBase === true ||
|
|
339
|
+
child.userData.isHollow === true ||
|
|
340
|
+
Number(child.userData.originalDepth) <= 0.2;
|
|
341
|
+
// English: Align 2D CSS labels to dynamic unit surface height, hollow courtyard, or thin floor base.
|
|
342
|
+
// Hinglish: 2D CSS labels ko dynamic unit surface height, hollow courtyard ya thin floor base ke sath sync karein.
|
|
343
|
+
const baseHeight = isBaseOrHollow
|
|
344
|
+
? mode === '2D'
|
|
345
|
+
? modeConfig.unitDepth
|
|
346
|
+
: (depthConfig?.floorBaseDepth ?? 0)
|
|
347
|
+
: mode === '2D'
|
|
348
|
+
? modeConfig.unitDepth
|
|
349
|
+
: (depthConfig?.defaultUnitDepth ?? Number(child.userData.originalDepth));
|
|
350
|
+
return baseHeight + 0.2;
|
|
351
|
+
}
|
|
352
|
+
return child.position.y;
|
|
353
|
+
}
|
|
354
|
+
applyViewMode(child, mode = '3D', depthConfig) {
|
|
355
|
+
child.position.y = this.resolveTargetElevation(child, mode, depthConfig);
|
|
356
|
+
}
|
|
357
|
+
/**
|
|
358
|
+
* Safely detaches CSS2D HTML element from DOM.
|
|
359
|
+
* DOM tree se label elements remove karein.
|
|
360
|
+
*/
|
|
361
|
+
/**
|
|
362
|
+
* Safely detaches CSS2D HTML element from DOM tree.
|
|
363
|
+
* DOM tree se label elements remove karein.
|
|
364
|
+
*/
|
|
365
|
+
cleanupDOM(object) {
|
|
366
|
+
const element = object.element;
|
|
367
|
+
if (element && element.parentNode) {
|
|
368
|
+
element.parentNode.removeChild(element);
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
disposeText(object) {
|
|
372
|
+
const element = object.element;
|
|
373
|
+
if (element && element.parentNode) {
|
|
374
|
+
element.parentNode.removeChild(element);
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
/**
|
|
378
|
+
* Creates the container HTML element for the label.
|
|
379
|
+
*/
|
|
380
|
+
createContainerElement(key, text, showIcon, logoUrl, roleClass = '') {
|
|
381
|
+
if (typeof document === 'undefined') {
|
|
382
|
+
// Headless / SSR mock element supporting Three.js CSS2DObject removed event
|
|
383
|
+
class MockElement {
|
|
384
|
+
}
|
|
385
|
+
const mockOwnerDocument = {
|
|
386
|
+
defaultView: {
|
|
387
|
+
Element: MockElement,
|
|
388
|
+
},
|
|
389
|
+
};
|
|
390
|
+
const createMockStyle = (initialColor = '') => {
|
|
391
|
+
const store = { color: initialColor };
|
|
392
|
+
return {
|
|
393
|
+
get color() {
|
|
394
|
+
return store['color'] ?? '';
|
|
395
|
+
},
|
|
396
|
+
set color(val) {
|
|
397
|
+
store['color'] = val;
|
|
398
|
+
},
|
|
399
|
+
setProperty(prop, val) {
|
|
400
|
+
store[prop] = val;
|
|
401
|
+
},
|
|
402
|
+
getPropertyValue(prop) {
|
|
403
|
+
return store[prop] ?? '';
|
|
404
|
+
},
|
|
405
|
+
removeProperty(prop) {
|
|
406
|
+
delete store[prop];
|
|
407
|
+
},
|
|
408
|
+
};
|
|
409
|
+
};
|
|
410
|
+
const mockTextEl = {
|
|
411
|
+
style: createMockStyle(),
|
|
412
|
+
};
|
|
413
|
+
const dummy = Object.create(MockElement.prototype);
|
|
414
|
+
Object.assign(dummy, {
|
|
415
|
+
className: `viewer-base-label label-${key} ${roleClass}`.trim(),
|
|
416
|
+
querySelector: (sel) => (sel && sel.includes('label-text') ? mockTextEl : null),
|
|
417
|
+
querySelectorAll: () => [],
|
|
418
|
+
classList: {
|
|
419
|
+
add: () => { },
|
|
420
|
+
remove: () => { },
|
|
421
|
+
contains: () => false,
|
|
422
|
+
},
|
|
423
|
+
style: createMockStyle(),
|
|
424
|
+
setAttribute: () => { },
|
|
425
|
+
getAttribute: () => null,
|
|
426
|
+
appendChild: () => { },
|
|
427
|
+
removeChild: () => { },
|
|
428
|
+
parentNode: null,
|
|
429
|
+
ownerDocument: mockOwnerDocument,
|
|
430
|
+
getBoundingClientRect: () => ({
|
|
431
|
+
x: 0,
|
|
432
|
+
y: 0,
|
|
433
|
+
width: 100,
|
|
434
|
+
height: 20,
|
|
435
|
+
top: 0,
|
|
436
|
+
bottom: 20,
|
|
437
|
+
left: 0,
|
|
438
|
+
right: 100,
|
|
439
|
+
}),
|
|
440
|
+
});
|
|
441
|
+
return dummy;
|
|
442
|
+
}
|
|
443
|
+
const container = document.createElement('div');
|
|
444
|
+
container.className = `viewer-base-label label-${key} ${roleClass}`.trim();
|
|
445
|
+
const content = document.createElement('div');
|
|
446
|
+
content.className = 'label-content';
|
|
447
|
+
const visualWrapper = document.createElement('div');
|
|
448
|
+
visualWrapper.className = 'label-visual';
|
|
449
|
+
if (showIcon && logoUrl) {
|
|
450
|
+
const img = document.createElement('img');
|
|
451
|
+
img.className = 'label-icon';
|
|
452
|
+
img.loading = 'lazy';
|
|
453
|
+
img.decoding = 'async';
|
|
454
|
+
img.src = logoUrl;
|
|
455
|
+
img.onerror = () => {
|
|
456
|
+
// If logo fails to load, remove broken img element and replace with default clean dot
|
|
457
|
+
img.remove();
|
|
458
|
+
const pDot = document.createElement('div');
|
|
459
|
+
pDot.className = 'label-primary-dot';
|
|
460
|
+
visualWrapper.classList.add('visual-no-bg');
|
|
461
|
+
visualWrapper.appendChild(pDot);
|
|
462
|
+
};
|
|
463
|
+
visualWrapper.appendChild(img);
|
|
464
|
+
}
|
|
465
|
+
else {
|
|
466
|
+
const pDot = document.createElement('div');
|
|
467
|
+
pDot.className = 'label-primary-dot';
|
|
468
|
+
visualWrapper.classList.add('visual-no-bg');
|
|
469
|
+
visualWrapper.appendChild(pDot);
|
|
470
|
+
}
|
|
471
|
+
content.appendChild(visualWrapper);
|
|
472
|
+
const span = document.createElement('span');
|
|
473
|
+
span.textContent = text;
|
|
474
|
+
span.className = 'label-text';
|
|
475
|
+
content.appendChild(span);
|
|
476
|
+
container.appendChild(content);
|
|
477
|
+
// Collision fallback dot
|
|
478
|
+
const cDot = document.createElement('div');
|
|
479
|
+
cDot.className = 'label-collision-dot';
|
|
480
|
+
container.appendChild(cDot);
|
|
481
|
+
return container;
|
|
482
|
+
}
|
|
483
|
+
}
|