@expofp/renderer 0.0.0-experimental.cf063fc
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/README.md +145 -0
- package/dist/Renderer.d.ts +102 -0
- package/dist/Renderer.js +96 -0
- package/dist/controls/CameraControls.d.ts +108 -0
- package/dist/controls/CameraControls.js +203 -0
- package/dist/controls/Controls.d.ts +53 -0
- package/dist/controls/Controls.js +54 -0
- package/dist/controls/camera-api.d.ts +226 -0
- package/dist/controls/camera-api.js +179 -0
- package/dist/controls/gestures.d.ts +71 -0
- package/dist/controls/gestures.js +98 -0
- package/dist/controls/handlers/DoubleTapZoom.d.ts +23 -0
- package/dist/controls/handlers/DoubleTapZoom.js +82 -0
- package/dist/controls/handlers/Inertia.d.ts +60 -0
- package/dist/controls/handlers/Inertia.js +222 -0
- package/dist/controls/handlers/Pan.d.ts +23 -0
- package/dist/controls/handlers/Pan.js +212 -0
- package/dist/controls/handlers/Pitch.d.ts +19 -0
- package/dist/controls/handlers/Pitch.js +200 -0
- package/dist/controls/handlers/Roll.d.ts +30 -0
- package/dist/controls/handlers/Roll.js +196 -0
- package/dist/controls/handlers/Zoom.d.ts +28 -0
- package/dist/controls/handlers/Zoom.js +34 -0
- package/dist/controls/hooks.d.ts +136 -0
- package/dist/controls/hooks.js +200 -0
- package/dist/controls/index.d.ts +9 -0
- package/dist/controls/index.js +7 -0
- package/dist/controls/zoom-to.d.ts +89 -0
- package/dist/controls/zoom-to.js +91 -0
- package/dist/core/InstanceUniforms.d.ts +108 -0
- package/dist/core/InstanceUniforms.js +298 -0
- package/dist/core/SquareDataTexture.d.ts +277 -0
- package/dist/core/SquareDataTexture.js +476 -0
- package/dist/core/batch/BatchedMesh.d.ts +74 -0
- package/dist/core/batch/BatchedMesh.js +155 -0
- package/dist/core/instanced/FrustumCulling.d.ts +141 -0
- package/dist/core/instanced/FrustumCulling.js +246 -0
- package/dist/core/instanced/InstancedMesh.d.ts +302 -0
- package/dist/core/instanced/InstancedMesh.js +497 -0
- package/dist/core/instanced/Instances.d.ts +119 -0
- package/dist/core/instanced/Instances.js +230 -0
- package/dist/core/instanced/Raycasting.d.ts +118 -0
- package/dist/core/instanced/Raycasting.js +134 -0
- package/dist/core/instanced/instanced-material.d.ts +77 -0
- package/dist/core/instanced/instanced-material.js +228 -0
- package/dist/core/lines/BatchedLines.d.ts +137 -0
- package/dist/core/lines/BatchedLines.js +215 -0
- package/dist/core/lines/FrustumCullingLines.d.ts +44 -0
- package/dist/core/lines/FrustumCullingLines.js +85 -0
- package/dist/core/lines/RaycastingLines.d.ts +45 -0
- package/dist/core/lines/RaycastingLines.js +91 -0
- package/dist/core/lines/lines-material.d.ts +47 -0
- package/dist/core/lines/lines-material.js +124 -0
- package/dist/core/shader-source.d.ts +70 -0
- package/dist/core/shader-source.js +110 -0
- package/dist/core/sprites/BatchedSprites.d.ts +115 -0
- package/dist/core/sprites/BatchedSprites.js +173 -0
- package/dist/core/sprites/RaycastingSprites.d.ts +41 -0
- package/dist/core/sprites/RaycastingSprites.js +71 -0
- package/dist/core/sprites/sprite-material.d.ts +59 -0
- package/dist/core/sprites/sprite-material.js +192 -0
- package/dist/core/text/BatchedText.d.ts +233 -0
- package/dist/core/text/BatchedText.js +473 -0
- package/dist/core/text/MemberTexture.d.ts +90 -0
- package/dist/core/text/MemberTexture.js +289 -0
- package/dist/core/text/Text.d.ts +88 -0
- package/dist/core/text/Text.js +230 -0
- package/dist/core/text/batched-text-material.d.ts +56 -0
- package/dist/core/text/batched-text-material.js +123 -0
- package/dist/core/text/glyph-packing.d.ts +17 -0
- package/dist/core/text/glyph-packing.js +61 -0
- package/dist/core/typed-array.d.ts +16 -0
- package/dist/core/typed-array.js +20 -0
- package/dist/debug/components/DebugPanelProvider.d.ts +20 -0
- package/dist/debug/components/DebugPanelProvider.js +50 -0
- package/dist/debug/components/DebugTools.d.ts +22 -0
- package/dist/debug/components/DebugTools.js +28 -0
- package/dist/debug/components/Gui.d.ts +22 -0
- package/dist/debug/components/Gui.js +42 -0
- package/dist/debug/components/MemoryInfo.d.ts +22 -0
- package/dist/debug/components/MemoryInfo.js +42 -0
- package/dist/debug/components/Panel.d.ts +31 -0
- package/dist/debug/components/Panel.js +104 -0
- package/dist/debug/components/Stats.d.ts +9 -0
- package/dist/debug/components/Stats.js +24 -0
- package/dist/debug/debug-chunk.d.ts +26 -0
- package/dist/debug/debug-chunk.js +32 -0
- package/dist/debug/debug-context.d.ts +41 -0
- package/dist/debug/debug-context.js +59 -0
- package/dist/debug/index.d.ts +41 -0
- package/dist/debug/index.js +43 -0
- package/dist/events/LayoutDriver.d.ts +36 -0
- package/dist/events/LayoutDriver.js +192 -0
- package/dist/events/PointerMissed.d.ts +23 -0
- package/dist/events/PointerMissed.js +58 -0
- package/dist/events/def-culling.d.ts +46 -0
- package/dist/events/def-culling.js +69 -0
- package/dist/events/layout-targets.d.ts +151 -0
- package/dist/events/layout-targets.js +397 -0
- package/dist/events/placement/box.d.ts +59 -0
- package/dist/events/placement/box.js +96 -0
- package/dist/events/placement/grid.d.ts +161 -0
- package/dist/events/placement/grid.js +235 -0
- package/dist/events/placement/index.d.ts +2 -0
- package/dist/events/placement/index.js +1 -0
- package/dist/events/placement/pass.d.ts +70 -0
- package/dist/events/placement/pass.js +617 -0
- package/dist/events/pointer.d.ts +194 -0
- package/dist/events/pointer.js +356 -0
- package/dist/external/ExternalCanvas.d.ts +56 -0
- package/dist/external/ExternalCanvas.js +177 -0
- package/dist/external/external-camera.d.ts +18 -0
- package/dist/external/external-camera.js +103 -0
- package/dist/external/external-events.d.ts +14 -0
- package/dist/external/external-events.js +33 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.js +14 -0
- package/dist/objects/Background.d.ts +31 -0
- package/dist/objects/Background.js +37 -0
- package/dist/objects/containers/SlotContainer.d.ts +312 -0
- package/dist/objects/containers/SlotContainer.js +311 -0
- package/dist/objects/containers/hooks.d.ts +61 -0
- package/dist/objects/containers/hooks.js +196 -0
- package/dist/objects/containers/index.d.ts +6 -0
- package/dist/objects/containers/index.js +4 -0
- package/dist/objects/containers/keys.d.ts +10 -0
- package/dist/objects/containers/keys.js +18 -0
- package/dist/objects/containers/mesh-writes.d.ts +106 -0
- package/dist/objects/containers/mesh-writes.js +97 -0
- package/dist/objects/containers/props.d.ts +33 -0
- package/dist/objects/containers/props.js +1 -0
- package/dist/objects/images/ImageInstance.d.ts +29 -0
- package/dist/objects/images/ImageInstance.js +152 -0
- package/dist/objects/images/Images.d.ts +49 -0
- package/dist/objects/images/Images.js +394 -0
- package/dist/objects/images/atlas-packer.d.ts +129 -0
- package/dist/objects/images/atlas-packer.js +287 -0
- package/dist/objects/images/image-container.d.ts +74 -0
- package/dist/objects/images/image-container.js +100 -0
- package/dist/objects/images/index.d.ts +2 -0
- package/dist/objects/images/index.js +1 -0
- package/dist/objects/images/pack-sources.d.ts +190 -0
- package/dist/objects/images/pack-sources.js +272 -0
- package/dist/objects/images/texture-budget.d.ts +120 -0
- package/dist/objects/images/texture-budget.js +215 -0
- package/dist/objects/images/worker/atlas-worker.d.ts +56 -0
- package/dist/objects/images/worker/atlas-worker.js +123 -0
- package/dist/objects/images/worker/client.d.ts +62 -0
- package/dist/objects/images/worker/client.js +249 -0
- package/dist/objects/images/worker/index.d.ts +10 -0
- package/dist/objects/images/worker/index.js +1 -0
- package/dist/objects/layer/Layer.d.ts +28 -0
- package/dist/objects/layer/Layer.js +134 -0
- package/dist/objects/layer/index.d.ts +2 -0
- package/dist/objects/layer/index.js +1 -0
- package/dist/objects/layer/layer-context.d.ts +74 -0
- package/dist/objects/layer/layer-context.js +82 -0
- package/dist/objects/layer/mount-scheduler.d.ts +131 -0
- package/dist/objects/layer/mount-scheduler.js +289 -0
- package/dist/objects/layer/visibility-gui.d.ts +19 -0
- package/dist/objects/layer/visibility-gui.js +93 -0
- package/dist/objects/lighting/Lighting.d.ts +92 -0
- package/dist/objects/lighting/Lighting.js +384 -0
- package/dist/objects/lighting/OcclusionPasses.d.ts +23 -0
- package/dist/objects/lighting/OcclusionPasses.js +271 -0
- package/dist/objects/lighting/index.d.ts +11 -0
- package/dist/objects/lighting/index.js +10 -0
- package/dist/objects/lighting/lighting-gui.d.ts +24 -0
- package/dist/objects/lighting/lighting-gui.js +114 -0
- package/dist/objects/lighting/occluder.d.ts +34 -0
- package/dist/objects/lighting/occluder.js +62 -0
- package/dist/objects/lighting/occlusion-targets.d.ts +143 -0
- package/dist/objects/lighting/occlusion-targets.js +276 -0
- package/dist/objects/lines/LineInstance.d.ts +21 -0
- package/dist/objects/lines/LineInstance.js +73 -0
- package/dist/objects/lines/Lines.d.ts +17 -0
- package/dist/objects/lines/Lines.js +31 -0
- package/dist/objects/lines/index.d.ts +2 -0
- package/dist/objects/lines/index.js +1 -0
- package/dist/objects/lines/line-container.d.ts +35 -0
- package/dist/objects/lines/line-container.js +40 -0
- package/dist/objects/materials/ColorMaterial.d.ts +92 -0
- package/dist/objects/materials/ColorMaterial.js +124 -0
- package/dist/objects/materials/LineMaterial.d.ts +44 -0
- package/dist/objects/materials/LineMaterial.js +74 -0
- package/dist/objects/materials/ModelMaterial.d.ts +53 -0
- package/dist/objects/materials/ModelMaterial.js +111 -0
- package/dist/objects/materials/TextureMaterial.d.ts +33 -0
- package/dist/objects/materials/TextureMaterial.js +48 -0
- package/dist/objects/materials/effects/ao/ambient-occlusion-pass.d.ts +77 -0
- package/dist/objects/materials/effects/ao/ambient-occlusion-pass.js +296 -0
- package/dist/objects/materials/effects/ao/ambient-occlusion-patch.d.ts +29 -0
- package/dist/objects/materials/effects/ao/ambient-occlusion-patch.js +115 -0
- package/dist/objects/materials/effects/ao/blur-pass.d.ts +61 -0
- package/dist/objects/materials/effects/ao/blur-pass.js +101 -0
- package/dist/objects/materials/effects/ao/index.d.ts +129 -0
- package/dist/objects/materials/effects/ao/index.js +72 -0
- package/dist/objects/materials/effects/color-dim.d.ts +115 -0
- package/dist/objects/materials/effects/color-dim.js +206 -0
- package/dist/objects/materials/effects/contact-shadow.d.ts +100 -0
- package/dist/objects/materials/effects/contact-shadow.js +167 -0
- package/dist/objects/materials/effects/effects-context.d.ts +53 -0
- package/dist/objects/materials/effects/effects-context.js +24 -0
- package/dist/objects/materials/shared.d.ts +24 -0
- package/dist/objects/materials/shared.js +72 -0
- package/dist/objects/models/ModelInstance.d.ts +22 -0
- package/dist/objects/models/ModelInstance.js +33 -0
- package/dist/objects/models/Models.d.ts +22 -0
- package/dist/objects/models/Models.js +186 -0
- package/dist/objects/models/gltf-cache.d.ts +17 -0
- package/dist/objects/models/gltf-cache.js +50 -0
- package/dist/objects/models/index.d.ts +2 -0
- package/dist/objects/models/index.js +1 -0
- package/dist/objects/models/model-asset.d.ts +48 -0
- package/dist/objects/models/model-asset.js +77 -0
- package/dist/objects/models/model-container.d.ts +123 -0
- package/dist/objects/models/model-container.js +207 -0
- package/dist/objects/shapes/ShapeInstance.d.ts +26 -0
- package/dist/objects/shapes/ShapeInstance.js +39 -0
- package/dist/objects/shapes/Shapes.d.ts +21 -0
- package/dist/objects/shapes/Shapes.js +131 -0
- package/dist/objects/shapes/index.d.ts +2 -0
- package/dist/objects/shapes/index.js +1 -0
- package/dist/objects/shapes/shape-container.d.ts +141 -0
- package/dist/objects/shapes/shape-container.js +242 -0
- package/dist/objects/shapes/shape-geometry.d.ts +27 -0
- package/dist/objects/shapes/shape-geometry.js +94 -0
- package/dist/objects/text/TextInstance.d.ts +22 -0
- package/dist/objects/text/TextInstance.js +95 -0
- package/dist/objects/text/Texts.d.ts +30 -0
- package/dist/objects/text/Texts.js +43 -0
- package/dist/objects/text/index.d.ts +2 -0
- package/dist/objects/text/index.js +1 -0
- package/dist/objects/text/text-container.d.ts +121 -0
- package/dist/objects/text/text-container.js +229 -0
- package/dist/objects/text/text-layout.d.ts +92 -0
- package/dist/objects/text/text-layout.js +180 -0
- package/dist/space/Camera.d.ts +103 -0
- package/dist/space/Camera.js +321 -0
- package/dist/space/Scene.d.ts +47 -0
- package/dist/space/Scene.js +127 -0
- package/dist/space/Space.d.ts +325 -0
- package/dist/space/Space.js +359 -0
- package/dist/space/VisibleRect.d.ts +45 -0
- package/dist/space/VisibleRect.js +129 -0
- package/dist/space/camera-handle.d.ts +67 -0
- package/dist/space/camera-handle.js +63 -0
- package/dist/space/camera-kind.d.ts +26 -0
- package/dist/space/camera-kind.js +30 -0
- package/dist/space/canvas-size.d.ts +24 -0
- package/dist/space/canvas-size.js +20 -0
- package/dist/space/clipping.d.ts +69 -0
- package/dist/space/clipping.js +130 -0
- package/dist/space/layout-measure.d.ts +67 -0
- package/dist/space/layout-measure.js +175 -0
- package/dist/space/viewport.d.ts +112 -0
- package/dist/space/viewport.js +67 -0
- package/dist/types/defs.d.ts +234 -0
- package/dist/types/defs.js +1 -0
- package/dist/types/events.d.ts +198 -0
- package/dist/types/events.js +1 -0
- package/dist/types/guards.d.ts +21 -0
- package/dist/types/guards.js +52 -0
- package/dist/update/index.d.ts +3 -0
- package/dist/update/index.js +2 -0
- package/dist/update/slot-writers.d.ts +30 -0
- package/dist/update/slot-writers.js +76 -0
- package/dist/update/store.d.ts +41 -0
- package/dist/update/store.js +104 -0
- package/dist/utils/arrays.d.ts +13 -0
- package/dist/utils/arrays.js +20 -0
- package/dist/utils/colors.d.ts +19 -0
- package/dist/utils/colors.js +27 -0
- package/dist/utils/hot-state.d.ts +41 -0
- package/dist/utils/hot-state.js +37 -0
- package/dist/utils/logging.d.ts +29 -0
- package/dist/utils/logging.js +55 -0
- package/dist/utils/math.d.ts +52 -0
- package/dist/utils/math.js +76 -0
- package/package.json +79 -0
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { useThree } from '@react-three/fiber';
|
|
2
|
+
import { Vector2 } from 'three';
|
|
3
|
+
import { useSpace, } from './Space';
|
|
4
|
+
/**
|
|
5
|
+
* The scene's coordinate conversions.
|
|
6
|
+
*
|
|
7
|
+
* A hook for the same reason `useCameraAPI` is one: it resolves only inside a component mounted
|
|
8
|
+
* under `<Renderer>`, so "the plan cannot be measured before the scene exists" is enforced by where
|
|
9
|
+
* the code can live rather than by a null check every caller has to remember. A host that needs to
|
|
10
|
+
* convert coordinates from outside React publishes this object from an effect.
|
|
11
|
+
*
|
|
12
|
+
* **Nothing here subscribes to the canvas size**, and it does not need to: `Space` is refitted in
|
|
13
|
+
* place on every resize, so the object below reads the current fit through the same reference for as
|
|
14
|
+
* long as the scene lives, and the camera is read at the moment of asking. That is the reading
|
|
15
|
+
* discipline `Space` documents — and the reason it is safe here is that no render output is derived
|
|
16
|
+
* from these answers.
|
|
17
|
+
*
|
|
18
|
+
* **The returned object is new on every render, deliberately**, as `useCameraAPI`'s is: this module
|
|
19
|
+
* memoizes nothing, so a consumer that cannot re-subscribe cheaply holds it in a ref and pays that
|
|
20
|
+
* cost where the cost is understood.
|
|
21
|
+
* @returns The conversions.
|
|
22
|
+
*/
|
|
23
|
+
export function useViewport() {
|
|
24
|
+
const get = useThree((state) => state.get);
|
|
25
|
+
const space = useSpace();
|
|
26
|
+
return new Viewport({ get, space });
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* The coordinate conversions, over whatever the scene currently holds.
|
|
30
|
+
*
|
|
31
|
+
* A class rather than an object literal because it is the renderer's published surface, and built
|
|
32
|
+
* fresh rather than mutated so that nothing here is state — every answer is composed from the space
|
|
33
|
+
* and the camera as they stand when the method is called.
|
|
34
|
+
*/
|
|
35
|
+
export class Viewport {
|
|
36
|
+
context;
|
|
37
|
+
/**
|
|
38
|
+
* @param context - What the scene holds; the instance is rebuilt whenever it moves.
|
|
39
|
+
*/
|
|
40
|
+
constructor(context) {
|
|
41
|
+
this.context = context;
|
|
42
|
+
}
|
|
43
|
+
/** @inheritdoc */
|
|
44
|
+
canvasToPlan(point, out) {
|
|
45
|
+
const { space, get } = this.context;
|
|
46
|
+
return space.canvasToPlan(point, get().camera, out);
|
|
47
|
+
}
|
|
48
|
+
/** @inheritdoc */
|
|
49
|
+
planToCanvas(point, out) {
|
|
50
|
+
const { space, get } = this.context;
|
|
51
|
+
// Never a shared scratch when the caller named none: this is public, and a caller that kept the
|
|
52
|
+
// point it was handed must never find it moved under them. An `out` they passed is theirs, and
|
|
53
|
+
// the aliasing is then a choice they made rather than one made for them.
|
|
54
|
+
return space.planToCanvas(point, get().camera, out);
|
|
55
|
+
}
|
|
56
|
+
/** @inheritdoc */
|
|
57
|
+
isVisible(point) {
|
|
58
|
+
const { space, get } = this.context;
|
|
59
|
+
// Tested in normalized device coordinates rather than in canvas pixels, which is the same test
|
|
60
|
+
// — `ndcToCanvas` maps `[-1, 1]` onto the canvas and nothing else — arrived at without the
|
|
61
|
+
// canvas size, and so with nothing to disagree with when a resize is halfway through.
|
|
62
|
+
const ndc = space.planToNdc(point, get().camera, _ndc);
|
|
63
|
+
return !!ndc && Math.abs(ndc.x) <= 1 && Math.abs(ndc.y) <= 1;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
/** Where {@link Viewport.isVisible} projects to; it never escapes the method. */
|
|
67
|
+
const _ndc = new Vector2();
|
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
import { type Box, type LineLike, type Rect, type Shape } from '@expofp/geometry';
|
|
2
|
+
import { type LayoutHandlers, type LayoutView, type PointerHandlers } from './events';
|
|
3
|
+
/** A color as a CSS string or a packed number. */
|
|
4
|
+
export type ColorInput = string | number;
|
|
5
|
+
/**
|
|
6
|
+
* An image the renderer can upload as a texture. Pass fetched images as a `Blob`: the renderer
|
|
7
|
+
* decodes it off the main thread. `HTMLImageElement` and URL strings are not accepted.
|
|
8
|
+
*/
|
|
9
|
+
export type ImageSource = HTMLCanvasElement | ImageBitmap | OffscreenCanvas | Blob;
|
|
10
|
+
/** Scene definition. */
|
|
11
|
+
export interface SceneDef {
|
|
12
|
+
/** The root layer of the scene tree. */
|
|
13
|
+
rootLayer: LayerDef;
|
|
14
|
+
/** The background color. */
|
|
15
|
+
background?: ColorInput;
|
|
16
|
+
/** The SVG viewbox. */
|
|
17
|
+
viewbox: Box;
|
|
18
|
+
/**
|
|
19
|
+
* A plan-to-world matrix that replaces the viewbox fit, in the host's coordinates. It must keep
|
|
20
|
+
* plan space's handedness.
|
|
21
|
+
*/
|
|
22
|
+
staticTransform?: number[];
|
|
23
|
+
}
|
|
24
|
+
/** Fields every renderable def shares. */
|
|
25
|
+
export interface SharedDef extends LayoutHandlers {
|
|
26
|
+
/** Whether the def is hidden. */
|
|
27
|
+
hidden?: boolean;
|
|
28
|
+
/**
|
|
29
|
+
* How much the def is dimmed, from `0` (none) to `1` (full). `undefined` inherits from the
|
|
30
|
+
* nearest ancestor, so a def can set `0` to stay undimmed inside a dimmed layer. Animate it
|
|
31
|
+
* freely: a change costs one uniform write per layer.
|
|
32
|
+
*/
|
|
33
|
+
dim?: number;
|
|
34
|
+
}
|
|
35
|
+
/** Any def that can be rendered into a scene. */
|
|
36
|
+
export type RenderableDef = LayerDef | ShapeDef | ImageDef | TextDef | LineDef | ModelDef;
|
|
37
|
+
/** An array of one {@link RenderableDef} kind. Mixed arrays do not type-check. */
|
|
38
|
+
export type RenderableDefCollection<T = RenderableDef> = T extends RenderableDef ? T[] : never;
|
|
39
|
+
/**
|
|
40
|
+
* Layer definition. Its {@link PointerHandlers} make its subtree pickable, and its
|
|
41
|
+
* {@link LayoutHandlers} run like any other def's.
|
|
42
|
+
*/
|
|
43
|
+
export interface LayerDef<T extends RenderableDef = RenderableDef> extends SharedDef, PointerHandlers<T> {
|
|
44
|
+
/** The layer's name. */
|
|
45
|
+
readonly name: string;
|
|
46
|
+
/** The layer's children, all of one kind. */
|
|
47
|
+
children: RenderableDefCollection<T>;
|
|
48
|
+
/**
|
|
49
|
+
* Draws the subtree above 3D content, with depth testing off. For flat content only: solid
|
|
50
|
+
* shapes and models ignore it. Descendants cannot opt out.
|
|
51
|
+
*/
|
|
52
|
+
overlay?: boolean;
|
|
53
|
+
/**
|
|
54
|
+
* Placement defs compete only with defs in layers that share this key. Without it, the layer
|
|
55
|
+
* competes only with itself. Prefix the key with its owner.
|
|
56
|
+
*/
|
|
57
|
+
collisionGroup?: string;
|
|
58
|
+
/**
|
|
59
|
+
* Turns collisions in this layer's collision scope into clusters. Both colliding defs are hidden
|
|
60
|
+
* through their own `onPlace`, and the cluster is reported to {@link ClusterOptions.onCluster}.
|
|
61
|
+
*/
|
|
62
|
+
clustering?: ClusterOptions;
|
|
63
|
+
}
|
|
64
|
+
/** Clustering options of a layer. */
|
|
65
|
+
export interface ClusterOptions {
|
|
66
|
+
/**
|
|
67
|
+
* The size of the marker you draw for a cluster. Any def or cluster that this marker would
|
|
68
|
+
* cover joins the cluster. Without it, the marker takes the size of the cluster's first member.
|
|
69
|
+
* When several clustering layers share a scope, the first layer's marker is used.
|
|
70
|
+
*/
|
|
71
|
+
marker?: ClusterMarker;
|
|
72
|
+
/**
|
|
73
|
+
* Receives the full current set of clusters whenever it changes. A layer that loses all its
|
|
74
|
+
* clusters receives an empty array once.
|
|
75
|
+
*
|
|
76
|
+
* Changes are held while the plan moves on screen and are reported once it has stood still for a
|
|
77
|
+
* moment. A registration, an unregistration or a def whose bounds you update is reported at once.
|
|
78
|
+
* `onPlace` calls arrive first, in the same synchronous call.
|
|
79
|
+
*
|
|
80
|
+
* Return the defs that changed. Never call `update()` here. Keep the options object stable: a
|
|
81
|
+
* new object is not noticed while the set stays the same.
|
|
82
|
+
* @param clusters - A new array on each call, in placement order.
|
|
83
|
+
* @param view - The current camera view.
|
|
84
|
+
* @returns The defs that changed, or nothing.
|
|
85
|
+
*/
|
|
86
|
+
onCluster(this: void, clusters: readonly Cluster[], view: LayoutView): readonly RenderableDef[] | void;
|
|
87
|
+
}
|
|
88
|
+
/** The screen box of a cluster's marker. */
|
|
89
|
+
export interface ClusterMarker {
|
|
90
|
+
/** The width in CSS pixels. */
|
|
91
|
+
width: number;
|
|
92
|
+
/** The height in CSS pixels. */
|
|
93
|
+
height: number;
|
|
94
|
+
/** The point that stands on the cluster's anchor, as in {@link ImageDef.origin}. */
|
|
95
|
+
origin?: [number, number];
|
|
96
|
+
}
|
|
97
|
+
/** One cluster of colliding defs. */
|
|
98
|
+
export interface Cluster {
|
|
99
|
+
/** How many units it holds, at least two. A `placement.group` counts as one unit. */
|
|
100
|
+
readonly unitCount: number;
|
|
101
|
+
/** The mean x of the units' anchors, in plan units. */
|
|
102
|
+
readonly x: number;
|
|
103
|
+
/** The mean y of the units' anchors, in plan units. */
|
|
104
|
+
readonly y: number;
|
|
105
|
+
/** The greatest elevation of its members, in plan units. */
|
|
106
|
+
readonly elevation: number;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* How a def competes for room on screen.
|
|
110
|
+
*
|
|
111
|
+
* - `never` (default): it is placed only where nothing placed before covers it, and then it
|
|
112
|
+
* blocks the defs after it.
|
|
113
|
+
* - `always`: it is always placed, blocks nothing and never clusters. In a group, it takes the
|
|
114
|
+
* group's verdict.
|
|
115
|
+
*/
|
|
116
|
+
export type OverlapMode = 'never' | 'always';
|
|
117
|
+
/** Placement options of a screen-space def. */
|
|
118
|
+
export interface PlacementOptions {
|
|
119
|
+
/**
|
|
120
|
+
* Receives the placement verdict: on the first pass after the def registers, then each time the
|
|
121
|
+
* verdict changes. Changes are reported when the camera stops, as for
|
|
122
|
+
* {@link ClusterOptions.onCluster}.
|
|
123
|
+
*
|
|
124
|
+
* Return the defs that changed. Never call `update()` here.
|
|
125
|
+
* @param placed - Whether the def got room on screen.
|
|
126
|
+
* @param view - The current camera view.
|
|
127
|
+
* @returns The defs that changed, or nothing.
|
|
128
|
+
*/
|
|
129
|
+
onPlace(this: void, placed: boolean, view: LayoutView): readonly RenderableDef[] | void;
|
|
130
|
+
/**
|
|
131
|
+
* Defs that share this key compete and cluster as one unit, with the union of their boxes. All
|
|
132
|
+
* members get the same verdict. The first member in order sets the unit's priority. Keys apply
|
|
133
|
+
* per collision scope. Prefix the key with its owner, and unregister old defs before you reuse
|
|
134
|
+
* their key.
|
|
135
|
+
*/
|
|
136
|
+
group?: string;
|
|
137
|
+
/** CSS pixels added around the tested box: one value, or `[horizontal, vertical]`. */
|
|
138
|
+
padding?: number | [number, number];
|
|
139
|
+
/** How the def competes. Defaults to `never`. */
|
|
140
|
+
overlap?: OverlapMode;
|
|
141
|
+
}
|
|
142
|
+
/** Fields of the def kinds that can face the camera: {@link ImageDef} and {@link TextDef}. */
|
|
143
|
+
export interface ScreenSpaceDef extends SharedDef {
|
|
144
|
+
/**
|
|
145
|
+
* Faces the def toward the camera. It pivots about `bounds.center` at `bounds.elevation`, sized
|
|
146
|
+
* by `bounds.size` in plan units. `bounds.rotation` spins it in the screen plane. Use an
|
|
147
|
+
* `onScale` rule to keep a constant pixel size.
|
|
148
|
+
*/
|
|
149
|
+
screenSpace?: boolean;
|
|
150
|
+
/**
|
|
151
|
+
* Enters the def into the placement pass, which hides it where a def earlier in order already
|
|
152
|
+
* covers the screen. Works only when {@link screenSpace} is true.
|
|
153
|
+
*/
|
|
154
|
+
placement?: PlacementOptions;
|
|
155
|
+
}
|
|
156
|
+
/** Shape definition. */
|
|
157
|
+
export interface ShapeDef extends SharedDef {
|
|
158
|
+
/**
|
|
159
|
+
* The shape to render. To change it, assign a new `Shape` and call `update(def)`. A polygon
|
|
160
|
+
* changed in place does not rebuild.
|
|
161
|
+
*/
|
|
162
|
+
shape: Shape;
|
|
163
|
+
/** The shape's color. */
|
|
164
|
+
color: ColorInput;
|
|
165
|
+
}
|
|
166
|
+
/** Image definition. */
|
|
167
|
+
export interface ImageDef extends ScreenSpaceDef {
|
|
168
|
+
/** The image source. Fixed for the def's life: use a new def for a new image. */
|
|
169
|
+
readonly source: ImageSource;
|
|
170
|
+
/** The image's bounds. */
|
|
171
|
+
bounds: Rect;
|
|
172
|
+
/**
|
|
173
|
+
* The point of the image that `bounds.center` names. `[0, 0]` is the top-left corner,
|
|
174
|
+
* `[0.5, 0.5]` the center (default), `[1, 1]` the bottom-right corner.
|
|
175
|
+
*/
|
|
176
|
+
origin?: [number, number];
|
|
177
|
+
/** How opaque the image is, from `0` to `1`. Defaults to `1`. It blends as alpha does. */
|
|
178
|
+
opacity?: number;
|
|
179
|
+
}
|
|
180
|
+
/** Text definition. */
|
|
181
|
+
export interface TextDef extends ScreenSpaceDef {
|
|
182
|
+
/** The text lines, stacked inside {@link bounds}. A line with `fontSize` `0` is not drawn. */
|
|
183
|
+
lines: TextLineDef[];
|
|
184
|
+
/** The text's bounds. */
|
|
185
|
+
bounds: Rect;
|
|
186
|
+
/** The text's padding, `[horizontal, vertical]`. */
|
|
187
|
+
padding: [number, number];
|
|
188
|
+
/** How the text is aligned. */
|
|
189
|
+
alignment: TextAlignment;
|
|
190
|
+
}
|
|
191
|
+
/** One line of a text def. */
|
|
192
|
+
export interface TextLineDef {
|
|
193
|
+
/** The line's text. */
|
|
194
|
+
text: string;
|
|
195
|
+
/** The line's color. */
|
|
196
|
+
color: ColorInput;
|
|
197
|
+
/** The font URL. Not updatable. Supports .ttf, .otf and .woff, not .woff2. */
|
|
198
|
+
fontUrl: string;
|
|
199
|
+
/** The em height in plan units. `0` hides the line. */
|
|
200
|
+
fontSize: number;
|
|
201
|
+
/** The stroke color, and its width in the same units as {@link fontSize}. */
|
|
202
|
+
stroke?: {
|
|
203
|
+
color: ColorInput;
|
|
204
|
+
width: number;
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
/** Text alignment. */
|
|
208
|
+
export interface TextAlignment {
|
|
209
|
+
/** The horizontal alignment. */
|
|
210
|
+
horizontal: 'left' | 'center' | 'right';
|
|
211
|
+
/** The vertical alignment. */
|
|
212
|
+
vertical: 'top' | 'center' | 'bottom';
|
|
213
|
+
/** The alignment of text inside a line. */
|
|
214
|
+
text?: 'left' | 'center' | 'right';
|
|
215
|
+
}
|
|
216
|
+
/** Line definition. */
|
|
217
|
+
export interface LineDef extends SharedDef {
|
|
218
|
+
/** The endpoints, with an optional elevation. Assign a new value and call `update(def)`. */
|
|
219
|
+
points: LineLike;
|
|
220
|
+
/** The line's color. */
|
|
221
|
+
color: ColorInput;
|
|
222
|
+
/** The width in screen pixels, constant at every zoom. `0` draws nothing. */
|
|
223
|
+
width: number;
|
|
224
|
+
}
|
|
225
|
+
/** External 3D model definition. */
|
|
226
|
+
export interface ModelDef extends SharedDef {
|
|
227
|
+
/** The model URL. Not updatable. */
|
|
228
|
+
url: string;
|
|
229
|
+
/** The model's bounds. */
|
|
230
|
+
bounds: Rect;
|
|
231
|
+
/** The model's opacity, from `0` to `1`. */
|
|
232
|
+
opacity?: number;
|
|
233
|
+
}
|
|
234
|
+
//# sourceMappingURL=defs.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
import { type PlanPoint } from '../space/Space';
|
|
2
|
+
import { type LayerDef, type RenderableDef } from './defs';
|
|
3
|
+
/**
|
|
4
|
+
* The def one of a layer's {@link PointerHandlers} is handed: a content layer's own child type, and —
|
|
5
|
+
* because a layer whose children are layers stands above every kind — any renderable at all for one
|
|
6
|
+
* of those. Never a {@link LayerDef} in practice: a hit resolves to the primitive under the pointer.
|
|
7
|
+
*/
|
|
8
|
+
export type SubtreeDef<T extends RenderableDef> = T extends LayerDef ? RenderableDef : T;
|
|
9
|
+
/** A pointer event delivered to one of a layer's {@link PointerHandlers}. */
|
|
10
|
+
export interface PointerEventData<T extends RenderableDef = RenderableDef> {
|
|
11
|
+
/**
|
|
12
|
+
* The def under the pointer — the nearest hit inside the subtree of the layer whose handler is
|
|
13
|
+
* running. A hit the renderer cannot trace back to a def is dropped rather than reported, so this
|
|
14
|
+
* is never absent.
|
|
15
|
+
*/
|
|
16
|
+
def: SubtreeDef<T>;
|
|
17
|
+
/**
|
|
18
|
+
* Where the pointer struck {@link def}, in plan units — the ray's own intersection with the
|
|
19
|
+
* geometry, taken back into plan space, so `z` is the elevation it was drawn at and a click on the
|
|
20
|
+
* roof of a raised model reports the roof.
|
|
21
|
+
*
|
|
22
|
+
* The same kind of answer {@link PointerMissedEventData} carries, which searches the scene for
|
|
23
|
+
* itself. A caller that wants the floor coordinate under an elevated hit instead — "which square
|
|
24
|
+
* metre of the hall is this" rather than "what did I touch" — converts the canvas position through
|
|
25
|
+
* `ViewportAPI.canvasToPlan`, which crosses the plan plane on purpose.
|
|
26
|
+
*
|
|
27
|
+
* A fresh instance per event, so keeping a reference to it is safe.
|
|
28
|
+
*/
|
|
29
|
+
point: PlanPoint;
|
|
30
|
+
/**
|
|
31
|
+
* Ends the event's delivery: neither the ancestors of the layer whose handler is running nor any
|
|
32
|
+
* def farther along the ray receives it. A handler that wants only the nearest of several
|
|
33
|
+
* overlapping defs calls this.
|
|
34
|
+
*/
|
|
35
|
+
stopPropagation(): void;
|
|
36
|
+
/** The DOM event this was dispatched from. */
|
|
37
|
+
nativeEvent: MouseEvent;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* A click that reached no layer handler — empty background, or a def whose layer declares no
|
|
41
|
+
* handlers and so is not picked at all. Delivered to the renderer's `onPointerMissed`.
|
|
42
|
+
*/
|
|
43
|
+
export interface PointerMissedEventData {
|
|
44
|
+
/**
|
|
45
|
+
* Where the click landed, in plan units — the nearest geometry under the pointer, with the
|
|
46
|
+
* elevation it was struck at, exactly as {@link PointerEventData.point} reports for a hit.
|
|
47
|
+
*
|
|
48
|
+
* **Reaching no handler is not the same as striking nothing.** A layer declaring no pointer
|
|
49
|
+
* handlers is never raycast, so a click arrives here as readily from the middle of a wall as from
|
|
50
|
+
* open background. The scene is searched along the same ray to tell those apart, and only the case
|
|
51
|
+
* that really is empty — past the edge of every piece of geometry — falls back to where the ray
|
|
52
|
+
* crosses the plan plane (`z = 0`).
|
|
53
|
+
*/
|
|
54
|
+
point: PlanPoint;
|
|
55
|
+
/** The DOM event this was dispatched from. */
|
|
56
|
+
nativeEvent: MouseEvent;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* The pointer handlers a {@link LayerDef} may carry. Kept apart from {@link LayoutHandlers} so that
|
|
60
|
+
* `keyof PointerHandlers` is exactly the dispatchable names.
|
|
61
|
+
*
|
|
62
|
+
* **Declaring one is what makes a layer interactive.** A layer with none is never raycast; a layer
|
|
63
|
+
* with any is raycast together with its whole subtree; a layer that is off screen — hidden, or under
|
|
64
|
+
* something hidden — is not picked at all.
|
|
65
|
+
*
|
|
66
|
+
* **Events travel upward and away.** The nearest def's layer handler runs first, then each ancestor
|
|
67
|
+
* that declares the same handler, then the next def along the ray, until one calls
|
|
68
|
+
* {@link PointerEventData.stopPropagation}; `event.def` stays the def that was hit. Overlapping defs
|
|
69
|
+
* deliver one event apiece, even within one layer. Defs at the same distance, such as coplanar flat
|
|
70
|
+
* defs, arrive in the order their slots were claimed (mount order), not paint order;
|
|
71
|
+
* `Pointer/Overlap` pins that.
|
|
72
|
+
*
|
|
73
|
+
* **Everything else occludes.** Geometry in a layer with no handlers is never hit itself, but it
|
|
74
|
+
* hides the defs behind it, opaque or translucent: a booth behind a wall or a model receives no
|
|
75
|
+
* event, and a click there is a miss. Geometry coplanar with a def, such as its label, does not
|
|
76
|
+
* hide it.
|
|
77
|
+
*
|
|
78
|
+
* **Handlers return nothing.** One that mutates defs calls `update()` afterward, like any other code.
|
|
79
|
+
*
|
|
80
|
+
* **Handlers take no receiver.** They are read off the layer and called as plain functions —
|
|
81
|
+
* `this: void` makes reading `this` a compile error rather than an `undefined` at runtime — so a
|
|
82
|
+
* handler shared across layers keys off `event.def`. Declared as methods rather than function-typed
|
|
83
|
+
* fields on purpose: a method's parameters are checked bivariantly, which is what keeps a
|
|
84
|
+
* `LayerDef<ShapeDef>` assignable to a plain `RenderableDef`.
|
|
85
|
+
*/
|
|
86
|
+
export interface PointerHandlers<T extends RenderableDef = RenderableDef> {
|
|
87
|
+
/**
|
|
88
|
+
* Called for a click on a def in this layer — a press and release that stayed within a few pixels,
|
|
89
|
+
* so a pan gesture ending over a def does not click it.
|
|
90
|
+
* @param event - The def that was clicked, and where.
|
|
91
|
+
*/
|
|
92
|
+
onClick?(this: void, event: PointerEventData<T>): void;
|
|
93
|
+
/**
|
|
94
|
+
* Called while the pointer is over a def in this layer, on every move it stays over one, including
|
|
95
|
+
* the move that first entered it.
|
|
96
|
+
* @param event - The def under the pointer, and where.
|
|
97
|
+
*/
|
|
98
|
+
onPointerMove?(this: void, event: PointerEventData<T>): void;
|
|
99
|
+
/**
|
|
100
|
+
* Called when the pointer leaves the def it was over, naming that def — so a handler mirroring
|
|
101
|
+
* hover state clears it here.
|
|
102
|
+
* @param event - The def the pointer left, and where the pointer was.
|
|
103
|
+
*/
|
|
104
|
+
onPointerOut?(this: void, event: PointerEventData<T>): void;
|
|
105
|
+
}
|
|
106
|
+
/** The pointer handlers by name, so dispatch can name one without repeating the list. */
|
|
107
|
+
export type PointerHandlerName = keyof PointerHandlers;
|
|
108
|
+
/** A def's re-layout handler, named so a caller can annotate one apart from the def it serves. */
|
|
109
|
+
export type ScaleHandler = NonNullable<LayoutHandlers['onScale']>;
|
|
110
|
+
/** A def's counter-rotation handler, named like {@link ScaleHandler}. */
|
|
111
|
+
export type RollHandler = NonNullable<LayoutHandlers['onRoll']>;
|
|
112
|
+
/**
|
|
113
|
+
* What the camera currently shows, as a layout rule sees it — every {@link LayoutHandlers} handler
|
|
114
|
+
* receives the same view, whichever axis's move invoked it, so a rule that turns a label can re-fit
|
|
115
|
+
* it at the size it is drawn at without asking anyone.
|
|
116
|
+
*
|
|
117
|
+
* **Valid during the call.** The registry reuses one instance across a sweep, so destructure or
|
|
118
|
+
* copy what you need rather than retaining the object.
|
|
119
|
+
*/
|
|
120
|
+
export interface LayoutView {
|
|
121
|
+
/**
|
|
122
|
+
* How much of the plan one CSS pixel spans, in plan units — the factor anything sized in
|
|
123
|
+
* pixels is laid out against, and the quantity the imperative renderer published as `ptScale`.
|
|
124
|
+
*
|
|
125
|
+
* CSS pixels, so a size authored in them comes out the same at every screen density. The device
|
|
126
|
+
* ratio never reaches a rule because a rule never needs it: the ratio sets how crisp a def is
|
|
127
|
+
* drawn, not how big.
|
|
128
|
+
*/
|
|
129
|
+
readonly pixelSize: number;
|
|
130
|
+
/**
|
|
131
|
+
* Which way the plan is turned, in **radians** clockwise from north — the same quantity, in the
|
|
132
|
+
* same unit, the imperative renderer's `navigation:roll` event carried, so ported rules keep the
|
|
133
|
+
* quarter-turn thresholds they were written against. (`CameraState.roll` reports the same angle
|
|
134
|
+
* in degrees, for people; rules get the unit their arithmetic wants.)
|
|
135
|
+
*/
|
|
136
|
+
readonly roll: number;
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* The layout handlers a def may carry — camera-driven rules that re-derive a def's geometry, one
|
|
140
|
+
* per axis the camera moves on: `onScale` for the pixel size, `onRoll` for the turn. Both receive
|
|
141
|
+
* the same {@link LayoutView}.
|
|
142
|
+
*
|
|
143
|
+
* Where {@link PointerHandlers} hang off the layer that gets picked — picking is a query over a
|
|
144
|
+
* subtree — a layout handler hangs off the one def it lays out, a layer included (which is how a
|
|
145
|
+
* layer whose *membership* depends on the camera re-derives it), and never propagates: a def's
|
|
146
|
+
* geometry has exactly one owner.
|
|
147
|
+
*
|
|
148
|
+
* A handler takes no def parameter: it is typically a closure built where its def is built, closing
|
|
149
|
+
* over the def or the plan-lived object that owns it. **What such a closure captures is the one
|
|
150
|
+
* thing to watch.** Defs live for the plan's lifetime, so a handler must capture nothing
|
|
151
|
+
* shorter-lived than the def — an owner alive as long as the plan is safe, since the closure then
|
|
152
|
+
* retains nothing the def was not already keeping alive, while a build-time temporary (a parse
|
|
153
|
+
* buffer, a raw config) captured even incidentally would stay pinned in memory for as long as the
|
|
154
|
+
* def exists. Should defs ever stop being built by plan-lived owners, keep that property by moving
|
|
155
|
+
* per-def data onto the defs themselves and capturing only the def.
|
|
156
|
+
*/
|
|
157
|
+
export interface LayoutHandlers {
|
|
158
|
+
/**
|
|
159
|
+
* Lays the def this handler is declared on out for a new pixel size — the hook everything sized
|
|
160
|
+
* in pixels rather than plan units hangs off: label font steps, badge and marker rescaling, a
|
|
161
|
+
* bookmark's clamp.
|
|
162
|
+
*
|
|
163
|
+
* Called once when the def is first registered, and again whenever the pixel size moves — hidden
|
|
164
|
+
* defs included, since whether a def draws at all can be exactly what its rule decides (a booth's
|
|
165
|
+
* dot appears only once the plan is far enough out for its label to stop fitting).
|
|
166
|
+
*
|
|
167
|
+
* **Returns what changed, and the renderer writes it** by the cheapest route that is correct for
|
|
168
|
+
* each def: a layer is reconciled, anything else goes straight into its slot with no render — what
|
|
169
|
+
* makes it affordable for every label on a plan to re-lay out while the camera moves. Return
|
|
170
|
+
* nothing when nothing changed and the write — the expensive half — is skipped; the def still
|
|
171
|
+
* counts as laid out either way. Do not call `update()` here: returning *is* this handler's
|
|
172
|
+
* update.
|
|
173
|
+
*
|
|
174
|
+
* Called as a plain function with no receiver, like the pointer handlers.
|
|
175
|
+
* @param view - What the camera shows; multiply pixel-authored sizes by `view.pixelSize`.
|
|
176
|
+
* @returns The defs that changed and need writing, or nothing.
|
|
177
|
+
*/
|
|
178
|
+
onScale?(this: void, view: LayoutView): readonly RenderableDef[] | void;
|
|
179
|
+
/**
|
|
180
|
+
* Lays the def out for a new camera roll — the hook everything that stays upright, or snaps to the
|
|
181
|
+
* nearest cardinal direction, hangs off: label and bookmark counter-rotation, a badge walking its
|
|
182
|
+
* anchor corner, a marker turning with the plan.
|
|
183
|
+
*
|
|
184
|
+
* Called once when the def is first registered — so a def added while the plan is turned is
|
|
185
|
+
* correct before its first paint — and again whenever the roll moves at all. There is no epsilon:
|
|
186
|
+
* the rules themselves step in quarter turns, so nearly every call returns nothing, exactly as the
|
|
187
|
+
* imperative renderer's `navigation:roll` handlers did.
|
|
188
|
+
*
|
|
189
|
+
* The same write contract as {@link onScale}: return what changed, return nothing when nothing
|
|
190
|
+
* did, and never call `update()` here. Called as a plain function with no receiver.
|
|
191
|
+
* @param view - What the camera shows — `view.roll` is the angle to lay out against, and
|
|
192
|
+
* `view.pixelSize` rides along because a rule that turns a label re-fits it at the size it is
|
|
193
|
+
* currently drawn at.
|
|
194
|
+
* @returns The defs that changed and need writing, or nothing.
|
|
195
|
+
*/
|
|
196
|
+
onRoll?(this: void, view: LayoutView): readonly RenderableDef[] | void;
|
|
197
|
+
}
|
|
198
|
+
//# sourceMappingURL=events.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { type ImageDef, type LayerDef, type LineDef, type ModelDef, type RenderableDef, type RenderableDefCollection, type ShapeDef, type TextDef } from './defs';
|
|
2
|
+
export declare function isShapeDef(def: RenderableDef): def is ShapeDef;
|
|
3
|
+
export declare function isImageDef(def: RenderableDef): def is ImageDef;
|
|
4
|
+
export declare function isTextDef(def: RenderableDef): def is TextDef;
|
|
5
|
+
export declare function isLineDef(def: RenderableDef): def is LineDef;
|
|
6
|
+
export declare function isModelDef(def: RenderableDef): def is ModelDef;
|
|
7
|
+
export declare function isLayerDef(def: RenderableDef): def is LayerDef;
|
|
8
|
+
/**
|
|
9
|
+
* Whether a def takes part in the placement pass: it declares placement options, and it faces the
|
|
10
|
+
* camera. A flat def carrying options is not a target, which is what the pass warns about.
|
|
11
|
+
* @param def - The def to test.
|
|
12
|
+
* @returns Whether the pass tests it.
|
|
13
|
+
*/
|
|
14
|
+
export declare function isPlacementTarget(def: RenderableDef): def is ImageDef | TextDef;
|
|
15
|
+
export declare function isLayerDefs(defs: Readonly<RenderableDefCollection>): defs is readonly LayerDef[];
|
|
16
|
+
export declare function isShapeDefs(defs: Readonly<RenderableDefCollection>): defs is readonly ShapeDef[];
|
|
17
|
+
export declare function isImageDefs(defs: Readonly<RenderableDefCollection>): defs is readonly ImageDef[];
|
|
18
|
+
export declare function isTextDefs(defs: Readonly<RenderableDefCollection>): defs is readonly TextDef[];
|
|
19
|
+
export declare function isLineDefs(defs: Readonly<RenderableDefCollection>): defs is readonly LineDef[];
|
|
20
|
+
export declare function isModelDefs(defs: Readonly<RenderableDefCollection>): defs is readonly ModelDef[];
|
|
21
|
+
//# sourceMappingURL=guards.d.ts.map
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
export function isShapeDef(def) {
|
|
2
|
+
return def.shape !== undefined;
|
|
3
|
+
}
|
|
4
|
+
export function isImageDef(def) {
|
|
5
|
+
return def.source !== undefined;
|
|
6
|
+
}
|
|
7
|
+
export function isTextDef(def) {
|
|
8
|
+
return def.lines !== undefined;
|
|
9
|
+
}
|
|
10
|
+
export function isLineDef(def) {
|
|
11
|
+
return def.points !== undefined;
|
|
12
|
+
}
|
|
13
|
+
export function isModelDef(def) {
|
|
14
|
+
return def.url !== undefined;
|
|
15
|
+
}
|
|
16
|
+
export function isLayerDef(def) {
|
|
17
|
+
return def.children !== undefined;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Whether a def takes part in the placement pass: it declares placement options, and it faces the
|
|
21
|
+
* camera. A flat def carrying options is not a target, which is what the pass warns about.
|
|
22
|
+
* @param def - The def to test.
|
|
23
|
+
* @returns Whether the pass tests it.
|
|
24
|
+
*/
|
|
25
|
+
export function isPlacementTarget(def) {
|
|
26
|
+
const target = def;
|
|
27
|
+
return target.placement !== undefined && target.screenSpace === true;
|
|
28
|
+
}
|
|
29
|
+
// The array guards below take the collection type, not `readonly RenderableDef[]`: the collection
|
|
30
|
+
// is a union of single-kind arrays, so a first-element check is sound for the whole array. A plain
|
|
31
|
+
// `RenderableDef[]` parameter would admit mixed arrays the check cannot speak for. The `Readonly`
|
|
32
|
+
// wrapper widens, not narrows: mutable collections are assignable to readonly parameters (and
|
|
33
|
+
// narrowing a mutable union member keeps it mutable), while the reverse would reject the readonly
|
|
34
|
+
// snapshots from `useStagedChildren`.
|
|
35
|
+
export function isLayerDefs(defs) {
|
|
36
|
+
return defs[0] !== undefined && isLayerDef(defs[0]);
|
|
37
|
+
}
|
|
38
|
+
export function isShapeDefs(defs) {
|
|
39
|
+
return defs[0] !== undefined && isShapeDef(defs[0]);
|
|
40
|
+
}
|
|
41
|
+
export function isImageDefs(defs) {
|
|
42
|
+
return defs[0] !== undefined && isImageDef(defs[0]);
|
|
43
|
+
}
|
|
44
|
+
export function isTextDefs(defs) {
|
|
45
|
+
return defs[0] !== undefined && isTextDef(defs[0]);
|
|
46
|
+
}
|
|
47
|
+
export function isLineDefs(defs) {
|
|
48
|
+
return defs[0] !== undefined && isLineDef(defs[0]);
|
|
49
|
+
}
|
|
50
|
+
export function isModelDefs(defs) {
|
|
51
|
+
return defs[0] !== undefined && isModelDef(defs[0]);
|
|
52
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { type RenderableDef } from '../types/defs';
|
|
2
|
+
/**
|
|
3
|
+
* Registers a def's sync closure, paired with the frame request that shows what it writes.
|
|
4
|
+
*
|
|
5
|
+
* The two are registered together rather than left to each caller because a slot write nobody asked
|
|
6
|
+
* a frame for is invisible: the renderer runs a demand frameloop, so the write lands in GPU memory
|
|
7
|
+
* and waits for a frame that never comes. Pairing them here is what makes every write path — React's
|
|
8
|
+
* and the frame loop's — correct without remembering anything. The frame loop's writes ask for a
|
|
9
|
+
* frame they are already inside, which costs one more after the camera stops.
|
|
10
|
+
* @param def - The def the instance component renders.
|
|
11
|
+
* @param sync - Writes the def's current state into its slot.
|
|
12
|
+
* @param invalidate - Requests the frame that draws it.
|
|
13
|
+
* @returns An unregister function, which removes this writer and leaves the def's others alone.
|
|
14
|
+
*/
|
|
15
|
+
export declare function registerSlotWriter(def: RenderableDef, sync: () => void, invalidate: () => void): () => void;
|
|
16
|
+
/**
|
|
17
|
+
* Runs every write registered for a def — each of its slots, and the frame that draws them. A no-op
|
|
18
|
+
* for defs that are not mounted.
|
|
19
|
+
* @param def - The def to re-sync.
|
|
20
|
+
*/
|
|
21
|
+
export declare function syncNow(def: RenderableDef): void;
|
|
22
|
+
/**
|
|
23
|
+
* Writes the defs a layout handler reported changed, by the cheapest route that is correct for
|
|
24
|
+
* each: a layer means its membership moved, which only React can reconcile, while anything else is
|
|
25
|
+
* a field write that goes straight into the slot, with no render at all behind the frame that draws
|
|
26
|
+
* it. This is what a layout handler returning defs buys — see `LayoutHandlers.onScale`.
|
|
27
|
+
* @param defs - The defs the handler reported changed, or nothing when it changed nothing.
|
|
28
|
+
*/
|
|
29
|
+
export declare function writeChanged(defs: readonly RenderableDef[] | undefined): void;
|
|
30
|
+
//# sourceMappingURL=slot-writers.d.ts.map
|