@mark1russell7/visuals 0.3.1 → 0.3.2
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 +55 -1
- package/build/extent-D2SsHJnP.js +154 -0
- package/build/extent-D2SsHJnP.js.map +1 -0
- package/build/globe.d.ts +1 -1
- package/build/globe.js +1 -1
- package/build/index.js +3 -2
- package/build/index.js.map +1 -1
- package/build/labels.d.ts +1 -1
- package/build/mark-AZ5AuAIJ.js +98 -0
- package/build/mark-AZ5AuAIJ.js.map +1 -0
- package/build/mark-D8AdQYAS.d.ts +154 -0
- package/build/mark-D8AdQYAS.d.ts.map +1 -0
- package/build/markers.d.ts +67 -0
- package/build/markers.d.ts.map +1 -0
- package/build/markers.js +687 -0
- package/build/markers.js.map +1 -0
- package/build/marks.d.ts +2 -153
- package/build/marks.d.ts.map +1 -1
- package/build/marks.js +2 -95
- package/build/marks.js.map +1 -1
- package/build/{motion-dvvkaDwv.js → motion-BvRKIWAC.js} +2 -2
- package/build/{motion-dvvkaDwv.js.map → motion-BvRKIWAC.js.map} +1 -1
- package/build/{stage-Bhu1f7Dw.d.ts → stage-DmFfah2e.d.ts} +6 -1
- package/build/stage-DmFfah2e.d.ts.map +1 -0
- package/build/three.d.ts +4 -2
- package/build/three.d.ts.map +1 -1
- package/build/three.js +11 -4
- package/build/three.js.map +1 -1
- package/build/{extent-DC0qrxC5.js → view-BB_EQx3I.js} +2 -152
- package/build/view-BB_EQx3I.js.map +1 -0
- package/package.json +6 -1
- package/build/extent-DC0qrxC5.js.map +0 -1
- package/build/stage-Bhu1f7Dw.d.ts.map +0 -1
package/build/three.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"three.js","names":["World"],"sources":["../src/stage/stage.ts","../src/stage/stack.ts"],"sourcesContent":["import { DirectionalLight, HemisphereLight, PerspectiveCamera, Raycaster, Scene as World, Vector2, WebGLRenderer, type Object3D } from \"three\";\nimport { OrbitControls } from \"three/addons/controls/OrbitControls.js\";\nimport { nearDepth, stageLimits, surfaceOf, type StageExtent, type StageLimits, type StageView, type ViewFrame } from \"../extent.ts\";\nimport { keyAction } from \"../keys.ts\";\nimport { isClick, highlightOf, NO_HIGHLIGHTS, type Highlight, type Highlights } from \"../highlight.ts\";\nimport { moveAt, type Move } from \"../motion.ts\";\nimport type { StageTheme } from \"../theme.ts\";\nimport { cameraPosition, clampPlace, FIELD_OF_VIEW, speedAt, turnAcross, viewOf, type Place } from \"../view.ts\";\n\nexport { FIELD_OF_VIEW };\n\n/** The record under the pointer: its name, and the value that the content gives for it. */\nexport interface StagePick<P> {\n /** The name of the record. The highlights of the stage use this name. */\n readonly record: string;\n /** The value of the record for the page, for example its kind and its source. */\n readonly value: P;\n}\n\n/** One picture of a stage, for the step of its content. */\nexport interface StageFrame {\n readonly camera: PerspectiveCamera;\n /** The time since the last picture, in seconds. */\n readonly seconds: number;\n /**\n * This value is true for the first picture of a content, and for a person who asks for less motion.\n * Each change then has no time: the content sets each value to its goal immediately.\n */\n readonly settle: boolean;\n /** The height of the picture, in CSS pixels. */\n readonly height: number;\n /** The vertical angle of the picture, in degrees. */\n readonly fieldOfView: number;\n}\n\n/**\n * The content of a stage: the three.js objects of one scene, and what the stage asks of them.\n * `P` is the type of the value of a pick, and `T` is the type of the theme.\n */\nexport interface StageContent<P, T extends StageTheme = StageTheme> {\n /** The three.js objects of the content. The stage adds them to its world, and removes them. */\n readonly objects: readonly Object3D[];\n /** The space that the content fills. */\n readonly extent: StageExtent;\n /** This function tells if the content has a record with a name. */\n has(record: string): boolean;\n /** This function gives the record that a ray from the camera finds first, or `undefined` for no record. */\n pick(ray: Raycaster): StagePick<P> | undefined;\n /** This function gives each part its colors, from the theme and the highlight of its record. */\n paint(theme: T, highlight: (record: string) => Highlight): void;\n /**\n * This function changes the parts that depend on the camera or on the time, before each picture.\n * It gives true while a part continues to change. The stage then makes the next picture.\n */\n step?(frame: StageFrame): boolean;\n /** This function releases the memory of the graphics card that the content uses. */\n dispose(): void;\n}\n\n/** The lights of a stage. A content with materials that use no light ignores them. */\nexport interface StageLights {\n /** The strength of the light from above and below. */\n readonly sky: number;\n /** The strength of the light from one direction. */\n readonly sun: number;\n /** The position that the light from one direction comes from. */\n readonly from: { readonly x: number; readonly y: number; readonly z: number };\n}\n\n/** The options of a stage. */\nexport interface StageOptions<P, T extends StageTheme = StageTheme> {\n /** The first content. The stage disposes each content that it gets. */\n readonly content: StageContent<P, T>;\n readonly theme: T;\n /** The name of the picture for a screen reader. */\n readonly label: string;\n /** The views of the stage, each with a name. */\n readonly views: Readonly<Record<string, StageView>>;\n /** The name of the first view. The keys `Home` and `0` show it. */\n readonly home: string;\n /** The name of the view of a key, for example `{ t: \"top\" }`. A letter has no case. */\n readonly keys?: Readonly<Record<string, string>> | undefined;\n /** The vertical angle of the picture, in degrees. A small angle gives the look of a drawing. The default is 32. */\n readonly fieldOfView?: number | undefined;\n /** The smallest and the largest polar angle of the camera, in radians. The default keeps the camera above the plane of the target. */\n readonly polar?: { readonly min?: number | undefined; readonly max?: number | undefined } | undefined;\n /** This value is true if a person can move the target with a drag of the second button. The default is true. */\n readonly pan?: boolean | undefined;\n readonly lights?: StageLights | undefined;\n /** The stage starts this function when the pointer goes to a different record, or to no record. */\n readonly onHover?: ((pick: P | undefined) => void) | undefined;\n /** The stage starts this function when a person selects a record with the pointer, or selects no record. */\n readonly onSelect?: ((pick: P | undefined) => void) | undefined;\n}\n\n/** A stage in a page: one canvas with a camera that a person moves, and one content. */\nexport interface Stage<P, T extends StageTheme = StageTheme> {\n /** The canvas of the stage. It is in the container. */\n readonly canvas: HTMLCanvasElement;\n /** This function shows a different content, and disposes the old content. The view stays if a person moved it. */\n setContent(content: StageContent<P, T>): void;\n /** This function changes the colors. */\n setTheme(theme: T): void;\n /** This function moves the camera to a view: a name of the options, or a view function. `animate` has the default true. */\n setView(view: string | StageView, animate?: boolean): void;\n /** This function gives the place of the camera. */\n place(): Place;\n /** This function highlights records by their names, as the pointer does. An empty list removes the highlights. */\n highlight(records: readonly string[]): void;\n /** This function selects one record by its name, or no record. It does not start `onSelect`. */\n select(record: string | undefined): void;\n /** This function paints the content again and makes a new picture. Use it after a change of the content. */\n refresh(): void;\n /** This function removes the canvas and releases the memory of the graphics card. It disposes the content. */\n dispose(): void;\n}\n\n/** The default lights: a strong light from above and below, and a light from the front left. */\nexport const STAGE_LIGHTS: StageLights = { sky: 2.2, sun: 1.5, from: { x: -10, y: 24, z: 15 } };\n\n/** The time of the move between two views, in milliseconds. */\nconst MOVE_TIME = 380;\n\n/**\n * The largest turn of the camera for a drag across the height of the picture, as a part of a full turn.\n * A camera far from a ball, or with no ball, turns by this part.\n */\nconst TURN_SPEED = 0.9;\n\n/** The smallest polar angle. At 0, the azimuth of a camera has no meaning. */\nconst SMALLEST_POLAR = 0.0005;\n\n/** The default largest polar angle: the camera stays above the plane of the target. */\nconst LARGEST_POLAR = Math.PI / 2 - 0.05;\n\n/** This function tells if the person asks for less motion. */\nfunction lessMotion(): boolean {\n return typeof matchMedia === \"function\" && matchMedia(\"(prefers-reduced-motion: reduce)\").matches;\n}\n\n/**\n * This function makes a stage in a container of a page. The stage fills the container, so give the container a size.\n *\n * A person turns the content with a drag, and moves nearer with the wheel after a click in the picture.\n * A click selects the record under the pointer. With the keyboard, the arrow keys turn the content, `+` and `-` change the distance,\n * and `Home` shows the first view. The stage makes a picture only after a change.\n *\n * The function gives `undefined` when the browser has no WebGL 2. It does not throw, and it writes no error to the console.\n * The page then shows a different picture of the same data.\n */\nexport function createStage<P, T extends StageTheme = StageTheme>(container: HTMLElement, options: StageOptions<P, T>): Stage<P, T> | undefined {\n const canvas = container.ownerDocument.createElement(\"canvas\");\n const context = canvas.getContext(\"webgl2\", { alpha: true, antialias: true, depth: true, stencil: false, premultipliedAlpha: true, powerPreference: \"default\" });\n if (context === null) return undefined;\n let renderer: WebGLRenderer;\n try {\n renderer = new WebGLRenderer({ canvas, context, alpha: true, antialias: true });\n } catch {\n return undefined;\n }\n renderer.setClearColor(0x000000, 0);\n\n canvas.style.display = \"block\";\n canvas.style.width = \"100%\";\n canvas.style.height = \"100%\";\n canvas.style.cursor = \"grab\";\n canvas.style.touchAction = \"none\";\n canvas.tabIndex = 0;\n canvas.setAttribute(\"role\", \"application\");\n canvas.setAttribute(\"aria-label\", options.label);\n container.append(canvas);\n\n const fieldOfView = options.fieldOfView ?? FIELD_OF_VIEW;\n const polar = { min: options.polar?.min ?? SMALLEST_POLAR, max: options.polar?.max ?? LARGEST_POLAR };\n const lights = options.lights ?? STAGE_LIGHTS;\n const world = new World();\n const sky = new HemisphereLight(\"#ffffff\", \"#ffffff\", lights.sky);\n const sun = new DirectionalLight(\"#ffffff\", lights.sun);\n sun.position.set(lights.from.x, lights.from.y, lights.from.z);\n world.add(sky, sun);\n const camera = new PerspectiveCamera(fieldOfView, 1, 0.05, 1000);\n\n let content = options.content;\n let theme = options.theme;\n for (const object of content.objects) world.add(object);\n\n let highlights: Highlights = NO_HIGHLIGHTS;\n let view: string | StageView = options.home;\n let move: Move | undefined;\n /** This value is true after a person moved the view. Then a new size of the container does not move the camera. */\n let moved = false;\n /** This value is true until the content had a step with no time. */\n let settle = true;\n /** The height of the picture, in CSS pixels. */\n let height = 1;\n let frame = 0;\n let lastTime = 0;\n let disposed = false;\n\n const invalidate = (): void => {\n if (frame === 0 && !disposed) frame = requestAnimationFrame(tick);\n };\n\n const controls = new OrbitControls(camera, canvas);\n controls.enableDamping = !lessMotion();\n controls.dampingFactor = 0.14;\n controls.minPolarAngle = polar.min;\n controls.maxPolarAngle = polar.max;\n controls.rotateSpeed = TURN_SPEED;\n controls.screenSpacePanning = true;\n controls.enablePan = options.pan ?? true;\n // The wheel moves the page until a person uses the picture. Thus the picture does not stop a person who reads down the page.\n controls.enableZoom = false;\n\n const viewFrame = (): ViewFrame => ({ extent: content.extent, fieldOfView, aspect: camera.aspect });\n let limits: StageLimits = stageLimits(viewFrame(), Object.values(options.views), polar);\n\n const paint = (): void => {\n const now = highlights;\n content.paint(theme, (record) => highlightOf(now, record));\n invalidate();\n };\n\n /**\n * This function sets the turn speed and the zoom speed from the height of the camera above the surface.\n * The surface of a ball at the middle of the picture follows the pointer in a drag.\n */\n const setSpeed = (): void => {\n const distance = camera.position.distanceTo(controls.target);\n const surface = surfaceOf(content.extent);\n // The controls turn the camera by a full turn times the speed for a drag across the height of the picture.\n controls.rotateSpeed = Math.min(TURN_SPEED, turnAcross(distance, surface, fieldOfView) / (2 * Math.PI));\n controls.zoomSpeed = speedAt(distance, surface);\n };\n const placeNow = (): Place => {\n const target = { x: controls.target.x, y: controls.target.y, z: controls.target.z };\n return { target, ...viewOf(camera.position, target) };\n };\n const put = (to: Place): void => {\n const next = clampPlace(to, limits);\n const eye = cameraPosition(next.target, next, next.distance);\n controls.target.set(next.target.x, next.target.y, next.target.z);\n camera.position.set(eye.x, eye.y, eye.z);\n camera.lookAt(controls.target);\n setSpeed();\n };\n /** This function gives the view function of a view, or `undefined` for a name that the options do not have. */\n const viewFunction = (of: string | StageView): StageView | undefined => (typeof of === \"string\" ? options.views[of] : of);\n\n /**\n * This function sets the nearest depth that the camera draws, from the distance of the camera to the content.\n * A camera far from the content then has small steps of depth at the content, so a layer near a surface stays above it.\n */\n const setDepth = (): void => {\n const { center } = content.extent;\n const distance = Math.hypot(camera.position.x - center.x, camera.position.y - center.y, camera.position.z - center.z);\n const near = nearDepth(limits, content.extent, distance);\n if (near === camera.near && limits.far === camera.far) return;\n camera.near = near;\n camera.far = limits.far;\n camera.updateProjectionMatrix();\n };\n /** This function sets the limits of the camera from the content and the shape of the picture. */\n const setLimits = (): void => {\n limits = stageLimits(viewFrame(), Object.values(options.views), polar);\n controls.minDistance = limits.minDistance;\n controls.maxDistance = limits.maxDistance;\n setDepth();\n };\n /**\n * This function stops the turn that continues after a drag. The camera stays where it is.\n * Without it, the camera continues to turn after a move to a view, and the view is not exact.\n */\n const stopDrift = (): void => {\n if (!controls.enableDamping) return;\n const now = placeNow();\n // With no damping, an update of the controls uses all of the turn that remains. The camera then goes back.\n controls.enableDamping = false;\n controls.update();\n controls.enableDamping = true;\n put(now);\n };\n const goTo = (next: string | StageView, animate: boolean): void => {\n const found = viewFunction(next);\n if (found === undefined) return;\n view = next;\n moved = false;\n stopDrift();\n const to = found(viewFrame());\n if (animate && !lessMotion()) {\n move = { from: placeNow(), to, start: performance.now(), duration: MOVE_TIME };\n } else {\n move = undefined;\n put(to);\n }\n invalidate();\n };\n\n /** This function sets the size of the picture from the size of the container. It gives false for a container with no size. */\n const setSize = (): boolean => {\n const width = container.clientWidth;\n const tall = container.clientHeight;\n if (width === 0 || tall === 0) return false;\n height = tall;\n renderer.setPixelRatio(Math.min(globalThis.devicePixelRatio, 2));\n renderer.setSize(width, tall, false);\n camera.aspect = width / tall;\n camera.updateProjectionMatrix();\n return true;\n };\n\n /** This function moves the camera one step of a move between two views. It gives true while the move continues. */\n const stepMove = (now: number): boolean => {\n if (move === undefined) return false;\n const step = moveAt(move, now, surfaceOf(content.extent));\n put(step.place);\n if (step.done) move = undefined;\n return true;\n };\n\n function tick(now: number): void {\n frame = 0;\n if (disposed) return;\n const seconds = lastTime === 0 ? 1 / 60 : Math.min((now - lastTime) / 1000, 0.1);\n let active = stepMove(now);\n setSpeed();\n active = controls.update() || active;\n setDepth();\n const stepped = content.step?.({ camera, seconds, settle: settle || lessMotion(), height, fieldOfView }) ?? false;\n settle = false;\n renderer.render(world, camera);\n active = stepped || active;\n lastTime = active ? now : 0;\n if (active) invalidate();\n }\n\n const raycaster = new Raycaster();\n const pointer = new Vector2();\n /** This function gives the record under a pointer. */\n const pickAt = (event: PointerEvent): StagePick<P> | undefined => {\n const box = canvas.getBoundingClientRect();\n if (box.width === 0 || box.height === 0) return undefined;\n pointer.set(((event.clientX - box.left) / box.width) * 2 - 1, 1 - ((event.clientY - box.top) / box.height) * 2);\n raycaster.setFromCamera(pointer, camera);\n return content.pick(raycaster);\n };\n\n const setHover = (pick: StagePick<P> | undefined): void => {\n const record = pick?.record;\n if (record === highlights.hovered) return;\n highlights = { ...highlights, hovered: record };\n canvas.style.cursor = record === undefined ? \"grab\" : \"pointer\";\n paint();\n options.onHover?.(pick?.value);\n };\n\n const listeners = new AbortController();\n const signal = listeners.signal;\n let down: { readonly id: number; readonly x: number; readonly y: number } | undefined;\n const setInUse = (inUse: boolean): void => {\n controls.enableZoom = inUse;\n };\n canvas.addEventListener(\n \"pointerdown\",\n (event) => {\n setInUse(true);\n canvas.focus({ preventScroll: true });\n down = { id: event.pointerId, x: event.clientX, y: event.clientY };\n },\n { signal },\n );\n canvas.addEventListener(\n \"pointermove\",\n (event) => {\n if (event.buttons === 0 && event.pointerType !== \"touch\") setHover(pickAt(event));\n },\n { signal },\n );\n canvas.addEventListener(\n \"pointerup\",\n (event) => {\n const start = down;\n down = undefined;\n if (start === undefined || start.id !== event.pointerId) return;\n if (!isClick(start, { x: event.clientX, y: event.clientY })) return;\n const pick = pickAt(event);\n highlights = { ...highlights, selected: pick?.record };\n paint();\n options.onSelect?.(pick?.value);\n },\n { signal },\n );\n canvas.addEventListener(\n \"pointercancel\",\n () => {\n down = undefined;\n },\n { signal },\n );\n canvas.addEventListener(\n \"pointerleave\",\n (event) => {\n setHover(undefined);\n if (event.pointerType === \"mouse\") setInUse(false);\n },\n { signal },\n );\n canvas.addEventListener(\"blur\", () => setInUse(false), { signal });\n canvas.addEventListener(\n \"keydown\",\n (event) => {\n if (event.altKey || event.ctrlKey || event.metaKey) return;\n const action = keyAction(event.key, placeNow(), { home: options.home, views: options.keys, surface: surfaceOf(content.extent), fieldOfView });\n if (action === undefined) return;\n event.preventDefault();\n setInUse(true);\n if (action.type === \"view\") {\n goTo(action.view, true);\n return;\n }\n moved = true;\n move = undefined;\n stopDrift();\n put(action.place);\n invalidate();\n },\n { signal },\n );\n canvas.addEventListener(\"webglcontextlost\", (event) => event.preventDefault(), { signal });\n canvas.addEventListener(\"webglcontextrestored\", invalidate, { signal });\n\n controls.addEventListener(\"start\", () => {\n moved = true;\n move = undefined;\n canvas.style.cursor = \"grabbing\";\n invalidate();\n });\n controls.addEventListener(\"end\", () => {\n canvas.style.cursor = highlights.hovered === undefined ? \"grab\" : \"pointer\";\n });\n controls.addEventListener(\"change\", invalidate);\n\n const applyTheme = (): void => {\n sky.color.set(theme.sky);\n sky.groundColor.set(theme.ground);\n paint();\n };\n\n const observer = new ResizeObserver(() => {\n if (disposed || !setSize()) return;\n setLimits();\n if (!moved) goTo(view, false);\n invalidate();\n });\n\n setSize();\n setLimits();\n goTo(options.home, false);\n applyTheme();\n observer.observe(container);\n\n return {\n canvas,\n setContent(next: StageContent<P, T>): void {\n if (disposed || next === content) return;\n for (const object of content.objects) world.remove(object);\n content.dispose();\n content = next;\n for (const object of content.objects) world.add(object);\n const selected = highlights.selected !== undefined && content.has(highlights.selected) ? highlights.selected : undefined;\n highlights = { ...highlights, hovered: undefined, selected };\n settle = true;\n setLimits();\n if (!moved) goTo(view, false);\n paint();\n },\n setTheme(next: T): void {\n theme = next;\n applyTheme();\n },\n setView(next: string | StageView, animate: boolean = true): void {\n goTo(next, animate);\n },\n place: placeNow,\n highlight(records: readonly string[]): void {\n highlights = { ...highlights, highlighted: new Set(records) };\n paint();\n },\n select(record: string | undefined): void {\n highlights = { ...highlights, selected: record };\n paint();\n },\n refresh: paint,\n dispose(): void {\n if (disposed) return;\n disposed = true;\n cancelAnimationFrame(frame);\n observer.disconnect();\n listeners.abort();\n controls.dispose();\n for (const object of content.objects) world.remove(object);\n content.dispose();\n renderer.dispose();\n canvas.remove();\n },\n };\n}\n","import type { StageTheme } from \"../theme.ts\";\nimport type { StageContent, StagePick } from \"./stage.ts\";\n\n/**\n * This function makes one content from a list of contents, for a stage that shows them together.\n * An example is a globe with a layer of labels, or a room with its marks.\n *\n * - The first content gives the extent: the views and the limits of the camera come from it.\n * - The last content is on top. A pick asks the last content first, and it stops at the first record.\n * - A record that two contents have is one record: each of them gets its highlight.\n * - The stage disposes the stack, and the stack disposes each content.\n */\nexport function stackContents<P, T extends StageTheme = StageTheme>(contents: readonly [StageContent<P, T>, ...StageContent<P, T>[]]): StageContent<P, T> {\n const [first] = contents;\n return {\n objects: contents.flatMap((content) => content.objects),\n get extent() {\n return first.extent;\n },\n has: (record) => contents.some((content) => content.has(record)),\n pick(ray): StagePick<P> | undefined {\n for (let at = contents.length - 1; at >= 0; at -= 1) {\n const pick = contents[at]?.pick(ray);\n if (pick !== undefined) return pick;\n }\n return undefined;\n },\n paint(theme, highlight): void {\n for (const content of contents) content.paint(theme, highlight);\n },\n step(frame): boolean {\n let active = false;\n // Each content has its step, also after a content that continues to change.\n for (const content of contents) active = (content.step?.(frame) ?? false) || active;\n return active;\n },\n dispose(): void {\n for (const content of contents) content.dispose();\n },\n };\n}\n"],"mappings":";;;;;;AAsHA,MAAa,eAA4B;CAAE,KAAK;CAAK,KAAK;CAAK,MAAM;EAAE,GAAG;EAAK,GAAG;EAAI,GAAG;CAAG;AAAE;;AAG9F,MAAM,YAAY;;;;;AAMlB,MAAM,aAAa;;AAGnB,MAAM,iBAAiB;;AAGvB,MAAM,gBAAgB,KAAK,KAAK,IAAI;;AAGpC,SAAS,aAAsB;CAC7B,OAAO,OAAO,eAAe,cAAc,WAAW,kCAAkC,CAAC,CAAC;AAC5F;;;;;;;;;;;AAYA,SAAgB,YAAkD,WAAwB,SAAsD;CAC9I,MAAM,SAAS,UAAU,cAAc,cAAc,QAAQ;CAC7D,MAAM,UAAU,OAAO,WAAW,UAAU;EAAE,OAAO;EAAM,WAAW;EAAM,OAAO;EAAM,SAAS;EAAO,oBAAoB;EAAM,iBAAiB;CAAU,CAAC;CAC/J,IAAI,YAAY,MAAM,OAAO,KAAA;CAC7B,IAAI;CACJ,IAAI;EACF,WAAW,IAAI,cAAc;GAAE;GAAQ;GAAS,OAAO;GAAM,WAAW;EAAK,CAAC;CAChF,QAAQ;EACN;CACF;CACA,SAAS,cAAc,GAAU,CAAC;CAElC,OAAO,MAAM,UAAU;CACvB,OAAO,MAAM,Q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OAAO;EACT;EACA,UAAgB;GACd,KAAK,MAAM,WAAW,UAAU,QAAQ,QAAQ;EAClD;CACF;AACF"}
|
|
1
|
+
{"version":3,"file":"three.js","names":["World"],"sources":["../src/stage/stage.ts","../src/stage/stack.ts"],"sourcesContent":["import { DirectionalLight, HemisphereLight, PerspectiveCamera, Raycaster, Scene as World, Vector2, WebGLRenderer, type Object3D } from \"three\";\nimport { OrbitControls } from \"three/addons/controls/OrbitControls.js\";\nimport { nearDepth, stageLimits, surfaceOf, type StageExtent, type StageLimits, type StageView, type ViewFrame } from \"../extent.ts\";\nimport { keyAction } from \"../keys.ts\";\nimport { isClick, highlightOf, NO_HIGHLIGHTS, type Highlight, type Highlights } from \"../highlight.ts\";\nimport { moveAt, type Move } from \"../motion.ts\";\nimport type { StageTheme } from \"../theme.ts\";\nimport { cameraPosition, clampPlace, FIELD_OF_VIEW, speedAt, turnAcross, viewOf, type Place } from \"../view.ts\";\n\nexport { FIELD_OF_VIEW };\n\n/** The record under the pointer: its name, and the value that the content gives for it. */\nexport interface StagePick<P> {\n /** The name of the record. The highlights of the stage use this name. */\n readonly record: string;\n /** The value of the record for the page, for example its kind and its source. */\n readonly value: P;\n /**\n * The distance from the start of the ray to the record, in the unit of the space.\n * A stack of contents uses it to find the nearest record. A pick with no distance is above each other record.\n */\n readonly distance?: number | undefined;\n}\n\n/** One picture of a stage, for the step of its content. */\nexport interface StageFrame {\n readonly camera: PerspectiveCamera;\n /** The time since the last picture, in seconds. */\n readonly seconds: number;\n /**\n * This value is true for the first picture of a content, and for a person who asks for less motion.\n * Each change then has no time: the content sets each value to its goal immediately.\n */\n readonly settle: boolean;\n /** The height of the picture, in CSS pixels. */\n readonly height: number;\n /** The vertical angle of the picture, in degrees. */\n readonly fieldOfView: number;\n}\n\n/**\n * The content of a stage: the three.js objects of one scene, and what the stage asks of them.\n * `P` is the type of the value of a pick, and `T` is the type of the theme.\n */\nexport interface StageContent<P, T extends StageTheme = StageTheme> {\n /** The three.js objects of the content. The stage adds them to its world, and removes them. */\n readonly objects: readonly Object3D[];\n /** The space that the content fills. */\n readonly extent: StageExtent;\n /** This function tells if the content has a record with a name. */\n has(record: string): boolean;\n /** This function gives the record that a ray from the camera finds first, or `undefined` for no record. */\n pick(ray: Raycaster): StagePick<P> | undefined;\n /** This function gives each part its colors, from the theme and the highlight of its record. */\n paint(theme: T, highlight: (record: string) => Highlight): void;\n /**\n * This function changes the parts that depend on the camera or on the time, before each picture.\n * It gives true while a part continues to change. The stage then makes the next picture.\n */\n step?(frame: StageFrame): boolean;\n /** This function releases the memory of the graphics card that the content uses. */\n dispose(): void;\n}\n\n/** The lights of a stage. A content with materials that use no light ignores them. */\nexport interface StageLights {\n /** The strength of the light from above and below. */\n readonly sky: number;\n /** The strength of the light from one direction. */\n readonly sun: number;\n /** The position that the light from one direction comes from. */\n readonly from: { readonly x: number; readonly y: number; readonly z: number };\n}\n\n/** The options of a stage. */\nexport interface StageOptions<P, T extends StageTheme = StageTheme> {\n /** The first content. The stage disposes each content that it gets. */\n readonly content: StageContent<P, T>;\n readonly theme: T;\n /** The name of the picture for a screen reader. */\n readonly label: string;\n /** The views of the stage, each with a name. */\n readonly views: Readonly<Record<string, StageView>>;\n /** The name of the first view. The keys `Home` and `0` show it. */\n readonly home: string;\n /** The name of the view of a key, for example `{ t: \"top\" }`. A letter has no case. */\n readonly keys?: Readonly<Record<string, string>> | undefined;\n /** The vertical angle of the picture, in degrees. A small angle gives the look of a drawing. The default is 32. */\n readonly fieldOfView?: number | undefined;\n /** The smallest and the largest polar angle of the camera, in radians. The default keeps the camera above the plane of the target. */\n readonly polar?: { readonly min?: number | undefined; readonly max?: number | undefined } | undefined;\n /** This value is true if a person can move the target with a drag of the second button. The default is true. */\n readonly pan?: boolean | undefined;\n readonly lights?: StageLights | undefined;\n /** The stage starts this function when the pointer goes to a different record, or to no record. */\n readonly onHover?: ((pick: P | undefined) => void) | undefined;\n /** The stage starts this function when a person selects a record with the pointer, or selects no record. */\n readonly onSelect?: ((pick: P | undefined) => void) | undefined;\n}\n\n/** A stage in a page: one canvas with a camera that a person moves, and one content. */\nexport interface Stage<P, T extends StageTheme = StageTheme> {\n /** The canvas of the stage. It is in the container. */\n readonly canvas: HTMLCanvasElement;\n /** This function shows a different content, and disposes the old content. The view stays if a person moved it. */\n setContent(content: StageContent<P, T>): void;\n /** This function changes the colors. */\n setTheme(theme: T): void;\n /** This function moves the camera to a view: a name of the options, or a view function. `animate` has the default true. */\n setView(view: string | StageView, animate?: boolean): void;\n /** This function gives the place of the camera. */\n place(): Place;\n /** This function highlights records by their names, as the pointer does. An empty list removes the highlights. */\n highlight(records: readonly string[]): void;\n /** This function selects one record by its name, or no record. It does not start `onSelect`. */\n select(record: string | undefined): void;\n /** This function paints the content again and makes a new picture. Use it after a change of the content. */\n refresh(): void;\n /** This function removes the canvas and releases the memory of the graphics card. It disposes the content. */\n dispose(): void;\n}\n\n/** The default lights: a strong light from above and below, and a light from the front left. */\nexport const STAGE_LIGHTS: StageLights = { sky: 2.2, sun: 1.5, from: { x: -10, y: 24, z: 15 } };\n\n/** The time of the move between two views, in milliseconds. */\nconst MOVE_TIME = 380;\n\n/**\n * The largest turn of the camera for a drag across the height of the picture, as a part of a full turn.\n * A camera far from a ball, or with no ball, turns by this part.\n */\nconst TURN_SPEED = 0.9;\n\n/** The smallest polar angle. At 0, the azimuth of a camera has no meaning. */\nconst SMALLEST_POLAR = 0.0005;\n\n/** The default largest polar angle: the camera stays above the plane of the target. */\nconst LARGEST_POLAR = Math.PI / 2 - 0.05;\n\n/** This function tells if the person asks for less motion. */\nfunction lessMotion(): boolean {\n return typeof matchMedia === \"function\" && matchMedia(\"(prefers-reduced-motion: reduce)\").matches;\n}\n\n/**\n * This function makes a stage in a container of a page. The stage fills the container, so give the container a size.\n *\n * A person turns the content with a drag, and moves nearer with the wheel after a click in the picture.\n * A click selects the record under the pointer. With the keyboard, the arrow keys turn the content, `+` and `-` change the distance,\n * and `Home` shows the first view. The stage makes a picture only after a change.\n *\n * The function gives `undefined` when the browser has no WebGL 2. It does not throw, and it writes no error to the console.\n * The page then shows a different picture of the same data.\n */\nexport function createStage<P, T extends StageTheme = StageTheme>(container: HTMLElement, options: StageOptions<P, T>): Stage<P, T> | undefined {\n const canvas = container.ownerDocument.createElement(\"canvas\");\n const context = canvas.getContext(\"webgl2\", { alpha: true, antialias: true, depth: true, stencil: false, premultipliedAlpha: true, powerPreference: \"default\" });\n if (context === null) return undefined;\n let renderer: WebGLRenderer;\n try {\n renderer = new WebGLRenderer({ canvas, context, alpha: true, antialias: true });\n } catch {\n return undefined;\n }\n renderer.setClearColor(0x000000, 0);\n\n canvas.style.display = \"block\";\n canvas.style.width = \"100%\";\n canvas.style.height = \"100%\";\n canvas.style.cursor = \"grab\";\n canvas.style.touchAction = \"none\";\n canvas.tabIndex = 0;\n canvas.setAttribute(\"role\", \"application\");\n canvas.setAttribute(\"aria-label\", options.label);\n container.append(canvas);\n\n const fieldOfView = options.fieldOfView ?? FIELD_OF_VIEW;\n const polar = { min: options.polar?.min ?? SMALLEST_POLAR, max: options.polar?.max ?? LARGEST_POLAR };\n const lights = options.lights ?? STAGE_LIGHTS;\n const world = new World();\n const sky = new HemisphereLight(\"#ffffff\", \"#ffffff\", lights.sky);\n const sun = new DirectionalLight(\"#ffffff\", lights.sun);\n sun.position.set(lights.from.x, lights.from.y, lights.from.z);\n world.add(sky, sun);\n const camera = new PerspectiveCamera(fieldOfView, 1, 0.05, 1000);\n\n let content = options.content;\n let theme = options.theme;\n for (const object of content.objects) world.add(object);\n\n let highlights: Highlights = NO_HIGHLIGHTS;\n let view: string | StageView = options.home;\n let move: Move | undefined;\n /** This value is true after a person moved the view. Then a new size of the container does not move the camera. */\n let moved = false;\n /** This value is true until the content had a step with no time. */\n let settle = true;\n /** The height of the picture, in CSS pixels. */\n let height = 1;\n let frame = 0;\n let lastTime = 0;\n let disposed = false;\n\n const invalidate = (): void => {\n if (frame === 0 && !disposed) frame = requestAnimationFrame(tick);\n };\n\n const controls = new OrbitControls(camera, canvas);\n controls.enableDamping = !lessMotion();\n controls.dampingFactor = 0.14;\n controls.minPolarAngle = polar.min;\n controls.maxPolarAngle = polar.max;\n controls.rotateSpeed = TURN_SPEED;\n controls.screenSpacePanning = true;\n controls.enablePan = options.pan ?? true;\n // The wheel moves the page until a person uses the picture. Thus the picture does not stop a person who reads down the page.\n controls.enableZoom = false;\n\n const viewFrame = (): ViewFrame => ({ extent: content.extent, fieldOfView, aspect: camera.aspect });\n let limits: StageLimits = stageLimits(viewFrame(), Object.values(options.views), polar);\n\n const paint = (): void => {\n const now = highlights;\n content.paint(theme, (record) => highlightOf(now, record));\n invalidate();\n };\n\n /**\n * This function sets the turn speed and the zoom speed from the height of the camera above the surface.\n * The surface of a ball at the middle of the picture follows the pointer in a drag.\n */\n const setSpeed = (): void => {\n const distance = camera.position.distanceTo(controls.target);\n const surface = surfaceOf(content.extent);\n // The controls turn the camera by a full turn times the speed for a drag across the height of the picture.\n controls.rotateSpeed = Math.min(TURN_SPEED, turnAcross(distance, surface, fieldOfView) / (2 * Math.PI));\n controls.zoomSpeed = speedAt(distance, surface);\n };\n const placeNow = (): Place => {\n const target = { x: controls.target.x, y: controls.target.y, z: controls.target.z };\n return { target, ...viewOf(camera.position, target) };\n };\n const put = (to: Place): void => {\n const next = clampPlace(to, limits);\n const eye = cameraPosition(next.target, next, next.distance);\n controls.target.set(next.target.x, next.target.y, next.target.z);\n camera.position.set(eye.x, eye.y, eye.z);\n camera.lookAt(controls.target);\n setSpeed();\n };\n /** This function gives the view function of a view, or `undefined` for a name that the options do not have. */\n const viewFunction = (of: string | StageView): StageView | undefined => (typeof of === \"string\" ? options.views[of] : of);\n\n /**\n * This function sets the nearest depth that the camera draws, from the distance of the camera to the content.\n * A camera far from the content then has small steps of depth at the content, so a layer near a surface stays above it.\n */\n const setDepth = (): void => {\n const { center } = content.extent;\n const distance = Math.hypot(camera.position.x - center.x, camera.position.y - center.y, camera.position.z - center.z);\n const near = nearDepth(limits, content.extent, distance);\n if (near === camera.near && limits.far === camera.far) return;\n camera.near = near;\n camera.far = limits.far;\n camera.updateProjectionMatrix();\n };\n /** This function sets the limits of the camera from the content and the shape of the picture. */\n const setLimits = (): void => {\n limits = stageLimits(viewFrame(), Object.values(options.views), polar);\n controls.minDistance = limits.minDistance;\n controls.maxDistance = limits.maxDistance;\n setDepth();\n };\n /**\n * This function stops the turn that continues after a drag. The camera stays where it is.\n * Without it, the camera continues to turn after a move to a view, and the view is not exact.\n */\n const stopDrift = (): void => {\n if (!controls.enableDamping) return;\n const now = placeNow();\n // With no damping, an update of the controls uses all of the turn that remains. The camera then goes back.\n controls.enableDamping = false;\n controls.update();\n controls.enableDamping = true;\n put(now);\n };\n const goTo = (next: string | StageView, animate: boolean): void => {\n const found = viewFunction(next);\n if (found === undefined) return;\n view = next;\n moved = false;\n stopDrift();\n const to = found(viewFrame());\n if (animate && !lessMotion()) {\n move = { from: placeNow(), to, start: performance.now(), duration: MOVE_TIME };\n } else {\n move = undefined;\n put(to);\n }\n invalidate();\n };\n\n /** This function sets the size of the picture from the size of the container. It gives false for a container with no size. */\n const setSize = (): boolean => {\n const width = container.clientWidth;\n const tall = container.clientHeight;\n if (width === 0 || tall === 0) return false;\n height = tall;\n renderer.setPixelRatio(Math.min(globalThis.devicePixelRatio, 2));\n renderer.setSize(width, tall, false);\n camera.aspect = width / tall;\n camera.updateProjectionMatrix();\n return true;\n };\n\n /** This function moves the camera one step of a move between two views. It gives true while the move continues. */\n const stepMove = (now: number): boolean => {\n if (move === undefined) return false;\n const step = moveAt(move, now, surfaceOf(content.extent));\n put(step.place);\n if (step.done) move = undefined;\n return true;\n };\n\n function tick(now: number): void {\n frame = 0;\n if (disposed) return;\n const seconds = lastTime === 0 ? 1 / 60 : Math.min((now - lastTime) / 1000, 0.1);\n let active = stepMove(now);\n setSpeed();\n active = controls.update() || active;\n setDepth();\n const stepped = content.step?.({ camera, seconds, settle: settle || lessMotion(), height, fieldOfView }) ?? false;\n settle = false;\n renderer.render(world, camera);\n active = stepped || active;\n lastTime = active ? now : 0;\n if (active) invalidate();\n }\n\n const raycaster = new Raycaster();\n const pointer = new Vector2();\n /** This function gives the record under a pointer. */\n const pickAt = (event: PointerEvent): StagePick<P> | undefined => {\n const box = canvas.getBoundingClientRect();\n if (box.width === 0 || box.height === 0) return undefined;\n pointer.set(((event.clientX - box.left) / box.width) * 2 - 1, 1 - ((event.clientY - box.top) / box.height) * 2);\n raycaster.setFromCamera(pointer, camera);\n return content.pick(raycaster);\n };\n\n const setHover = (pick: StagePick<P> | undefined): void => {\n const record = pick?.record;\n if (record === highlights.hovered) return;\n highlights = { ...highlights, hovered: record };\n canvas.style.cursor = record === undefined ? \"grab\" : \"pointer\";\n paint();\n options.onHover?.(pick?.value);\n };\n\n const listeners = new AbortController();\n const signal = listeners.signal;\n let down: { readonly id: number; readonly x: number; readonly y: number } | undefined;\n const setInUse = (inUse: boolean): void => {\n controls.enableZoom = inUse;\n };\n canvas.addEventListener(\n \"pointerdown\",\n (event) => {\n setInUse(true);\n canvas.focus({ preventScroll: true });\n down = { id: event.pointerId, x: event.clientX, y: event.clientY };\n },\n { signal },\n );\n canvas.addEventListener(\n \"pointermove\",\n (event) => {\n if (event.buttons === 0 && event.pointerType !== \"touch\") setHover(pickAt(event));\n },\n { signal },\n );\n canvas.addEventListener(\n \"pointerup\",\n (event) => {\n const start = down;\n down = undefined;\n if (start === undefined || start.id !== event.pointerId) return;\n if (!isClick(start, { x: event.clientX, y: event.clientY })) return;\n const pick = pickAt(event);\n highlights = { ...highlights, selected: pick?.record };\n paint();\n options.onSelect?.(pick?.value);\n },\n { signal },\n );\n canvas.addEventListener(\n \"pointercancel\",\n () => {\n down = undefined;\n },\n { signal },\n );\n canvas.addEventListener(\n \"pointerleave\",\n (event) => {\n setHover(undefined);\n if (event.pointerType === \"mouse\") setInUse(false);\n },\n { signal },\n );\n canvas.addEventListener(\"blur\", () => setInUse(false), { signal });\n canvas.addEventListener(\n \"keydown\",\n (event) => {\n if (event.altKey || event.ctrlKey || event.metaKey) return;\n const action = keyAction(event.key, placeNow(), { home: options.home, views: options.keys, surface: surfaceOf(content.extent), fieldOfView });\n if (action === undefined) return;\n event.preventDefault();\n setInUse(true);\n if (action.type === \"view\") {\n goTo(action.view, true);\n return;\n }\n moved = true;\n move = undefined;\n stopDrift();\n put(action.place);\n invalidate();\n },\n { signal },\n );\n canvas.addEventListener(\"webglcontextlost\", (event) => event.preventDefault(), { signal });\n canvas.addEventListener(\"webglcontextrestored\", invalidate, { signal });\n\n controls.addEventListener(\"start\", () => {\n moved = true;\n move = undefined;\n canvas.style.cursor = \"grabbing\";\n invalidate();\n });\n controls.addEventListener(\"end\", () => {\n canvas.style.cursor = highlights.hovered === undefined ? \"grab\" : \"pointer\";\n });\n controls.addEventListener(\"change\", invalidate);\n\n const applyTheme = (): void => {\n sky.color.set(theme.sky);\n sky.groundColor.set(theme.ground);\n paint();\n };\n\n const observer = new ResizeObserver(() => {\n if (disposed || !setSize()) return;\n setLimits();\n if (!moved) goTo(view, false);\n invalidate();\n });\n\n setSize();\n setLimits();\n goTo(options.home, false);\n applyTheme();\n observer.observe(container);\n\n return {\n canvas,\n setContent(next: StageContent<P, T>): void {\n if (disposed || next === content) return;\n for (const object of content.objects) world.remove(object);\n content.dispose();\n content = next;\n for (const object of content.objects) world.add(object);\n const selected = highlights.selected !== undefined && content.has(highlights.selected) ? highlights.selected : undefined;\n highlights = { ...highlights, hovered: undefined, selected };\n settle = true;\n setLimits();\n if (!moved) goTo(view, false);\n paint();\n },\n setTheme(next: T): void {\n theme = next;\n applyTheme();\n },\n setView(next: string | StageView, animate: boolean = true): void {\n goTo(next, animate);\n },\n place: placeNow,\n highlight(records: readonly string[]): void {\n highlights = { ...highlights, highlighted: new Set(records) };\n paint();\n },\n select(record: string | undefined): void {\n highlights = { ...highlights, selected: record };\n paint();\n },\n refresh: paint,\n dispose(): void {\n if (disposed) return;\n disposed = true;\n cancelAnimationFrame(frame);\n observer.disconnect();\n listeners.abort();\n controls.dispose();\n for (const object of content.objects) world.remove(object);\n content.dispose();\n renderer.dispose();\n canvas.remove();\n },\n };\n}\n","import type { StageTheme } from \"../theme.ts\";\nimport type { StageContent, StagePick } from \"./stage.ts\";\n\n/**\n * This function makes one content from a list of contents, for a stage that shows them together.\n * An example is a globe with a layer of labels, or a room with its marks.\n *\n * - The first content gives the extent: the views and the limits of the camera come from it.\n * - The last content is on top. A pick asks the last content first.\n * - A pick with no distance ends the search, if no earlier pick has a distance. That pick is the record.\n * - A pick with a distance does not end the search. The record is then the pick with the smallest distance.\n * - A record that two contents have is one record: each of them gets its highlight.\n * - The stage disposes the stack, and the stack disposes each content.\n */\nexport function stackContents<P, T extends StageTheme = StageTheme>(contents: readonly [StageContent<P, T>, ...StageContent<P, T>[]]): StageContent<P, T> {\n const [first] = contents;\n return {\n objects: contents.flatMap((content) => content.objects),\n get extent() {\n return first.extent;\n },\n has: (record) => contents.some((content) => content.has(record)),\n pick(ray): StagePick<P> | undefined {\n // The nearest of the picks that have a distance. A content on top gets the pick when two distances are equal.\n let nearest: StagePick<P> | undefined;\n for (let at = contents.length - 1; at >= 0; at -= 1) {\n const pick = contents[at]?.pick(ray);\n if (pick === undefined) continue;\n // A pick with no distance tells nothing of its depth, so the search stops: a nearer pick of a content on top stays the record.\n if (pick.distance === undefined) return nearest ?? pick;\n if (nearest?.distance === undefined || pick.distance < nearest.distance) nearest = pick;\n }\n return nearest;\n },\n paint(theme, highlight): void {\n for (const content of contents) content.paint(theme, highlight);\n },\n step(frame): boolean {\n let active = false;\n // Each content has its step, also after a content that continues to change.\n for (const content of contents) active = (content.step?.(frame) ?? false) || active;\n return active;\n },\n dispose(): void {\n for (const content of contents) content.dispose();\n },\n };\n}\n"],"mappings":";;;;;;;AA2HA,MAAa,eAA4B;CAAE,KAAK;CAAK,KAAK;CAAK,MAAM;EAAE,GAAG;EAAK,GAAG;EAAI,GAAG;CAAG;AAAE;;AAG9F,MAAM,YAAY;;;;;AAMlB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;CACF;AACF;;;;;;;;;;;;;ACjfA,SAAgB,cAAoD,UAAsF;CACxJ,MAAM,CAAC,SAAS;CAChB,OAAO;EACL,SAAS,SAAS,SAAS,YAAY,QAAQ,OAAO;EACtD,IAAI,SAAS;GACX,OAAO,MAAM;EACf;EACA,MAAM,WAAW,SAAS,MAAM,YAAY,QAAQ,IAAI,MAAM,CAAC;EAC/D,KAAK,KAA+B;GAElC,IAAI;GACJ,KAAK,IAAI,KAAK,SAAS,SAAS,GAAG,MAAM,GAAG,MAAM,GAAG;IACnD,MAAM,OAAO,SAAS,GAAG,EAAE,KAAK,GAAG;IACnC,IAAI,SAAS,KAAA,GAAW;IAExB,IAAI,KAAK,aAAa,KAAA,GAAW,OAAO,WAAW;IACnD,IAAI,SAAS,aAAa,KAAA,KAAa,KAAK,WAAW,QAAQ,UAAU,UAAU;GACrF;GACA,OAAO;EACT;EACA,MAAM,OAAO,WAAiB;GAC5B,KAAK,MAAM,WAAW,UAAU,QAAQ,MAAM,OAAO,SAAS;EAChE;EACA,KAAK,OAAgB;GACnB,IAAI,SAAS;GAEb,KAAK,MAAM,WAAW,UAAU,UAAU,QAAQ,OAAO,KAAK,KAAK,UAAU;GAC7E,OAAO;EACT;EACA,UAAgB;GACd,KAAK,MAAM,WAAW,UAAU,QAAQ,QAAQ;EAClD;CACF;AACF"}
|
|
@@ -160,156 +160,6 @@ function placeBetween(from, to, part, surface = 0) {
|
|
|
160
160
|
distance: surface + height
|
|
161
161
|
};
|
|
162
162
|
}
|
|
163
|
-
|
|
164
|
-
/** The space around the content in a view that shows all of it, as a factor of the distance. */
|
|
165
|
-
const FIT_MARGIN = 1.06;
|
|
166
|
-
/** This function gives the radius of the ball around the center of an extent, or 0 for no ball. */
|
|
167
|
-
function surfaceOf(extent) {
|
|
168
|
-
const surface = extent.surface ?? 0;
|
|
169
|
-
return surface > 0 ? surface : 0;
|
|
170
|
-
}
|
|
171
|
-
/**
|
|
172
|
-
* This function makes a view that shows each corner of the content from one direction.
|
|
173
|
-
* `margin` is the space around the content, as a factor of the distance. An extent with no corners gives the distance 1.
|
|
174
|
-
*/
|
|
175
|
-
function fitView(angles, margin = FIT_MARGIN) {
|
|
176
|
-
return ({ extent, fieldOfView, aspect }) => {
|
|
177
|
-
const distance = fitDistance(extent.corners, extent.center, angles, fieldOfView, aspect) * margin;
|
|
178
|
-
return {
|
|
179
|
-
target: extent.center,
|
|
180
|
-
polar: angles.polar,
|
|
181
|
-
azimuth: angles.azimuth,
|
|
182
|
-
distance: distance > 0 ? distance : 1
|
|
183
|
-
};
|
|
184
|
-
};
|
|
185
|
-
}
|
|
186
|
-
/**
|
|
187
|
-
* This function makes a view of a part of the ball of the content: a cap around the point of the ball below the camera.
|
|
188
|
-
*
|
|
189
|
-
* `angles` is the direction from the center of the ball to the camera. `angle` is the angle of the cap at the center of the ball, in radians.
|
|
190
|
-
* `margin` is the space around the cap, as a factor of the height above the ball. An extent with no ball gives the distance 1.
|
|
191
|
-
*/
|
|
192
|
-
function capView(angles, angle, margin = FIT_MARGIN) {
|
|
193
|
-
return ({ extent, fieldOfView, aspect }) => {
|
|
194
|
-
const surface = surfaceOf(extent);
|
|
195
|
-
const height = Math.max(capDistance(surface, angle, fieldOfView, aspect) - surface, 0);
|
|
196
|
-
return {
|
|
197
|
-
target: extent.center,
|
|
198
|
-
polar: angles.polar,
|
|
199
|
-
azimuth: angles.azimuth,
|
|
200
|
-
distance: surface > 0 ? surface + height * margin : 1
|
|
201
|
-
};
|
|
202
|
-
};
|
|
203
|
-
}
|
|
204
|
-
/**
|
|
205
|
-
* This function makes a view of points on the ball of the content. The camera is above the middle of the points, and the picture shows each point.
|
|
206
|
-
*
|
|
207
|
-
* The middle is the center of the box of the points. The camera is at the smallest distance that shows each point in the width and in the height of the picture.
|
|
208
|
-
* Thus wide points fill a wide picture. `margin` is the space around the points, as a factor of the height above the ball.
|
|
209
|
-
* A list with no points gives a view of all of the ball from the front. Points with their middle at the center of the ball give the same view.
|
|
210
|
-
*/
|
|
211
|
-
function ballView(points, margin = FIT_MARGIN) {
|
|
212
|
-
let found;
|
|
213
|
-
return (frame) => {
|
|
214
|
-
const { extent } = frame;
|
|
215
|
-
const { center } = extent;
|
|
216
|
-
if (found === void 0 || found.center.x !== center.x || found.center.y !== center.y || found.center.z !== center.z) found = {
|
|
217
|
-
center,
|
|
218
|
-
angles: middleOf(points, center)
|
|
219
|
-
};
|
|
220
|
-
const { angles } = found;
|
|
221
|
-
if (angles === void 0) return capView({
|
|
222
|
-
polar: Math.PI / 2,
|
|
223
|
-
azimuth: 0
|
|
224
|
-
}, Math.PI / 2, margin)(frame);
|
|
225
|
-
const surface = surfaceOf(extent);
|
|
226
|
-
const height = Math.max(fitDistance(points, center, angles, frame.fieldOfView, frame.aspect) - surface, 0);
|
|
227
|
-
return {
|
|
228
|
-
target: center,
|
|
229
|
-
polar: angles.polar,
|
|
230
|
-
azimuth: angles.azimuth,
|
|
231
|
-
distance: surface > 0 ? surface + height * margin : 1
|
|
232
|
-
};
|
|
233
|
-
};
|
|
234
|
-
}
|
|
235
|
-
/** This function gives the direction from `center` to the middle of the box of the points. It gives `undefined` when the middle has no direction. */
|
|
236
|
-
function middleOf(points, center) {
|
|
237
|
-
const low = {
|
|
238
|
-
x: 1e400,
|
|
239
|
-
y: 1e400,
|
|
240
|
-
z: 1e400
|
|
241
|
-
};
|
|
242
|
-
const high = {
|
|
243
|
-
x: -1e400,
|
|
244
|
-
y: -1e400,
|
|
245
|
-
z: -1e400
|
|
246
|
-
};
|
|
247
|
-
for (const point of points) {
|
|
248
|
-
low.x = Math.min(low.x, point.x);
|
|
249
|
-
low.y = Math.min(low.y, point.y);
|
|
250
|
-
low.z = Math.min(low.z, point.z);
|
|
251
|
-
high.x = Math.max(high.x, point.x);
|
|
252
|
-
high.y = Math.max(high.y, point.y);
|
|
253
|
-
high.z = Math.max(high.z, point.z);
|
|
254
|
-
}
|
|
255
|
-
const middle = {
|
|
256
|
-
x: (low.x + high.x) / 2 - center.x,
|
|
257
|
-
y: (low.y + high.y) / 2 - center.y,
|
|
258
|
-
z: (low.z + high.z) / 2 - center.z
|
|
259
|
-
};
|
|
260
|
-
const length = Math.hypot(middle.x, middle.y, middle.z);
|
|
261
|
-
if (!(length > 0) || !Number.isFinite(length)) return void 0;
|
|
262
|
-
const { polar, azimuth } = viewOf(middle, {
|
|
263
|
-
x: 0,
|
|
264
|
-
y: 0,
|
|
265
|
-
z: 0
|
|
266
|
-
});
|
|
267
|
-
return {
|
|
268
|
-
polar,
|
|
269
|
-
azimuth
|
|
270
|
-
};
|
|
271
|
-
}
|
|
272
|
-
/** This function gives the radius of the ball around the center of an extent that holds the ball of the extent and each corner. */
|
|
273
|
-
function reachOf(extent) {
|
|
274
|
-
let reach = surfaceOf(extent);
|
|
275
|
-
for (const corner of extent.corners) reach = Math.max(reach, Math.hypot(corner.x - extent.center.x, corner.y - extent.center.y, corner.z - extent.center.z));
|
|
276
|
-
return reach;
|
|
277
|
-
}
|
|
278
|
-
/**
|
|
279
|
-
* This function gives the nearest depth that a camera draws, from the distance of the camera to the center of the content.
|
|
280
|
-
*
|
|
281
|
-
* A camera far from the content gets a large value. The depths of the content then have more steps, so two surfaces that are near stay apart.
|
|
282
|
-
* The result is not less than the nearest depth of the limits, and it is in front of all the content.
|
|
283
|
-
*/
|
|
284
|
-
function nearDepth(limits, extent, distance) {
|
|
285
|
-
const free = (distance - reachOf(extent)) / 8;
|
|
286
|
-
return free > limits.near ? Math.min(free, limits.far / 4) : limits.near;
|
|
287
|
-
}
|
|
288
|
-
/**
|
|
289
|
-
* This function gives the limits of the camera of a stage for a picture.
|
|
290
|
-
*
|
|
291
|
-
* The largest distance of the views is the base. The camera goes out to 3 times this distance, and in to 3 % of the height of that view.
|
|
292
|
-
* The extent can give each distance. The nearest depth is small against the height of the nearest camera, and the farthest depth is behind all the content.
|
|
293
|
-
*/
|
|
294
|
-
function stageLimits(frame, views, polar) {
|
|
295
|
-
const { extent } = frame;
|
|
296
|
-
const surface = surfaceOf(extent);
|
|
297
|
-
let widest = 0;
|
|
298
|
-
for (const view of views) widest = Math.max(widest, view(frame).distance);
|
|
299
|
-
if (!(widest > surface)) widest = surface + 1;
|
|
300
|
-
const reach = reachOf(extent);
|
|
301
|
-
const minDistance = extent.minDistance ?? surface + (widest - surface) * .03;
|
|
302
|
-
const maxDistance = Math.max(extent.maxDistance ?? surface + (widest - surface) * 3, minDistance);
|
|
303
|
-
const height = Math.max(minDistance - surface, 1e-6);
|
|
304
|
-
return {
|
|
305
|
-
minPolar: polar.min,
|
|
306
|
-
maxPolar: polar.max,
|
|
307
|
-
minDistance,
|
|
308
|
-
maxDistance,
|
|
309
|
-
near: height / 8,
|
|
310
|
-
far: (maxDistance + reach) * 1.5
|
|
311
|
-
};
|
|
312
|
-
}
|
|
313
|
-
export { turnBetween as _, nearDepth as a, surfaceOf as c, capDistance as d, clampPlace as f, turnAcross as g, speedAt as h, fitView as i, FIELD_OF_VIEW as l, placeBetween as m, ballView as n, reachOf as o, fitDistance as p, capView as r, stageLimits as s, FIT_MARGIN as t, cameraPosition as u, viewAxes as v, viewOf as y };
|
|
163
|
+
export { fitDistance as a, turnAcross as c, viewOf as d, clampPlace as i, turnBetween as l, cameraPosition as n, placeBetween as o, capDistance as r, speedAt as s, FIELD_OF_VIEW as t, viewAxes as u };
|
|
314
164
|
|
|
315
|
-
//# sourceMappingURL=
|
|
165
|
+
//# sourceMappingURL=view-BB_EQx3I.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"view-BB_EQx3I.js","names":[],"sources":["../src/view.ts"],"sourcesContent":["import type { Point3 } from \"@mark1russell7/layout-contract\";\n\n/**\n * The direction of a view: where the camera is, as seen from the point that it looks at.\n * The space of a stage has the y axis up.\n */\nexport interface ViewAngles {\n /** The angle from the up axis to the camera, in radians. At 0, the camera looks down from above. */\n readonly polar: number;\n /** The angle around the up axis, in radians. At 0, the camera is on the positive z side of the point. */\n readonly azimuth: number;\n}\n\n/** A place of a camera: the point that it looks at, the angles of its view and its distance from the point. */\nexport interface Place extends ViewAngles {\n readonly target: Point3;\n readonly distance: number;\n}\n\n/** The three axes of a camera, as unit vectors in the space of the stage. */\nexport interface ViewAxes {\n /** The vector from the point that the camera looks at to the camera. */\n readonly back: Point3;\n /** The vector to the right side of the picture. */\n readonly right: Point3;\n /** The vector to the top of the picture. */\n readonly up: Point3;\n}\n\n/** The limits of the place of a camera. */\nexport interface PlaceLimits {\n /** The smallest polar angle. At 0, the azimuth of a camera has no meaning. */\n readonly minPolar: number;\n /** The largest polar angle. */\n readonly maxPolar: number;\n /** The smallest distance from the target. */\n readonly minDistance: number;\n /** The largest distance from the target. */\n readonly maxDistance: number;\n}\n\n/** This function gives the axes of the camera of a view. At a polar angle of 0, the top of the picture is the negative z axis. */\nexport function viewAxes(view: ViewAngles): ViewAxes {\n const sinPolar = Math.sin(view.polar);\n const cosPolar = Math.cos(view.polar);\n const sinAzimuth = Math.sin(view.azimuth);\n const cosAzimuth = Math.cos(view.azimuth);\n return {\n back: { x: sinPolar * sinAzimuth, y: cosPolar, z: sinPolar * cosAzimuth },\n right: { x: cosAzimuth, y: 0, z: 0 - sinAzimuth },\n up: { x: 0 - cosPolar * sinAzimuth, y: sinPolar, z: 0 - cosPolar * cosAzimuth },\n };\n}\n\n/** This function gives the dot product of the vector from `origin` to `point` with `axis`. */\nfunction along(point: Point3, origin: Point3, axis: Point3): number {\n return (point.x - origin.x) * axis.x + (point.y - origin.y) * axis.y + (point.z - origin.z) * axis.z;\n}\n\n/**\n * This function gives the smallest distance from `target` at which a camera shows each point.\n *\n * The camera looks at `target` along the direction of `view`. `fov` is the vertical angle of the picture in degrees,\n * and `aspect` is the width of the picture divided by its height.\n * The function gives 0 for no points, and for an angle or an aspect that makes no picture.\n */\nexport function fitDistance(points: readonly Point3[], target: Point3, view: ViewAngles, fov: number, aspect: number): number {\n const tanUp = Math.tan((fov * Math.PI) / 360);\n const tanRight = tanUp * aspect;\n if (!(tanUp > 0) || !(tanRight > 0) || !Number.isFinite(tanRight)) return 0;\n const axes = viewAxes(view);\n let distance = 0;\n for (const point of points) {\n const depth = along(point, target, axes.back);\n const needed = Math.max(Math.abs(along(point, target, axes.right)) / tanRight, Math.abs(along(point, target, axes.up)) / tanUp);\n distance = Math.max(distance, depth + needed);\n }\n return distance;\n}\n\n/**\n * This function gives the smallest distance from the center of a ball at which a camera shows a cap of the ball.\n *\n * The camera looks at the center of the ball, and the center of the cap is on the line to the camera.\n * `radius` is the radius of the ball. `angle` is the angle of the cap at the center of the ball, in radians, from 0 to π / 2.\n * `fov` is the vertical angle of the picture in degrees, and `aspect` is the width of the picture divided by its height.\n * The function gives 0 for an angle or an aspect that makes no picture.\n */\nexport function capDistance(radius: number, angle: number, fov: number, aspect: number): number {\n const tanUp = Math.tan((fov * Math.PI) / 360);\n const tan = Math.min(tanUp, tanUp * aspect);\n if (!(tan > 0) || !Number.isFinite(tan) || !(radius > 0)) return 0;\n const cap = Math.min(Math.max(angle, 0), Math.PI / 2);\n const half = Math.atan(tan);\n // A cap this large has its edge behind the outline of the ball. Then the outline of the ball is the limit.\n if (cap >= Math.PI / 2 - half) return radius / Math.sin(half);\n // The edge of the cap is at the height r sin(a) from the line, and at the depth r cos(a) from the center.\n return radius * Math.cos(cap) + (radius * Math.sin(cap)) / tan;\n}\n\n/** This function gives the position of a camera at a distance from `target`, in the direction of `view`. */\nexport function cameraPosition(target: Point3, view: ViewAngles, distance: number): Point3 {\n const { back } = viewAxes(view);\n return { x: target.x + back.x * distance, y: target.y + back.y * distance, z: target.z + back.z * distance };\n}\n\n/** This function gives the angles of the view from `target` to a camera, and the distance between them. A camera at the target gives the angles 0. */\nexport function viewOf(camera: Point3, target: Point3): ViewAngles & { readonly distance: number } {\n const x = camera.x - target.x;\n const y = camera.y - target.y;\n const z = camera.z - target.z;\n const distance = Math.hypot(x, y, z);\n if (!(distance > 0)) return { polar: 0, azimuth: 0, distance: 0 };\n return { polar: Math.acos(Math.min(Math.max(y / distance, -1), 1)), azimuth: Math.atan2(x, z), distance };\n}\n\n/** This function gives the angle between two azimuths along the shortest way, from −π to π. */\nexport function turnBetween(from: number, to: number): number {\n const full = 2 * Math.PI;\n const turn = (((to - from) % full) + full) % full;\n return turn > Math.PI ? turn - full : turn;\n}\n\n/** This function gives a place in its limits. The target and the azimuth stay as they are. */\nexport function clampPlace(place: Place, limits: PlaceLimits): Place {\n return {\n target: place.target,\n azimuth: place.azimuth,\n polar: Math.min(Math.max(place.polar, limits.minPolar), limits.maxPolar),\n distance: Math.min(Math.max(place.distance, limits.minDistance), limits.maxDistance),\n };\n}\n\n/**\n * This function gives the height of a camera above the surface of a stage, as a part of its distance from the target.\n *\n * `surface` is the radius of the ball around the target that the camera stays out of. A stage with no ball has the value 0.\n * The result is the factor of the zoom speed of a camera: near the surface, a camera moves slowly.\n * The result is 0.02 at least, so a camera on the surface can move away.\n */\nexport function speedAt(distance: number, surface: number): number {\n if (!(distance > 0)) return 1;\n return Math.min(Math.max((distance - surface) / distance, 0.02), 1);\n}\n\n/** The default vertical angle of the picture of a stage, in degrees. */\nexport const FIELD_OF_VIEW = 32;\n\n/** The smallest result of `turnAcross`, in radians. A camera on a ball, or in it, can thus turn. */\nconst SMALLEST_TURN = 1e-6;\n\n/**\n * This function gives the turn of a camera around a ball that moves the surface by the height of the picture, in radians.\n *\n * `surface` is the radius of the ball around the target. `fieldOfView` is the vertical angle of the picture, in degrees.\n *\n * The result is exact for the surface at the middle of the picture. Thus that surface follows the pointer in a drag.\n * The ball is round, so a long drag moves that surface by a smaller distance than the pointer.\n * Thus the surface does not go before the pointer.\n *\n * The result is `Infinity` for a stage with no ball, because such a stage has no surface that follows the pointer.\n * A turn about the up axis moves a point between the equator and a pole of the ball by a smaller distance.\n */\nexport function turnAcross(distance: number, surface: number, fieldOfView: number): number {\n const half = (fieldOfView * Math.PI) / 360;\n if (!(surface > 0) || !(distance > 0) || !(half > 0 && half < Math.PI / 2)) return Number.POSITIVE_INFINITY;\n // The surface at the middle of the picture is at the distance `distance - surface` from the camera.\n // There, the height of the picture shows this length of the surface. The turn is that length as an angle of the ball.\n const shown = 2 * (distance - surface) * Math.tan(half);\n return Math.max(shown / surface, SMALLEST_TURN);\n}\n\n/**\n * This function gives the place at a part of the way between two places. `part` goes from 0 to 1.\n *\n * The azimuth goes along the shortest way. The height above the surface changes by an equal factor for each equal step,\n * so a zoom has one speed in the picture. `surface` is the radius of the ball around the target, or 0 for no ball.\n */\nexport function placeBetween(from: Place, to: Place, part: number, surface: number = 0): Place {\n const between = (a: number, b: number): number => a + (b - a) * part;\n const low = from.distance - surface;\n const high = to.distance - surface;\n const height = low > 0 && high > 0 ? low * (high / low) ** part : between(low, high);\n return {\n target: { x: between(from.target.x, to.target.x), y: between(from.target.y, to.target.y), z: between(from.target.z, to.target.z) },\n polar: between(from.polar, to.polar),\n azimuth: from.azimuth + turnBetween(from.azimuth, to.azimuth) * part,\n distance: surface + height,\n };\n}\n"],"mappings":";;AA0CA,SAAgB,SAAS,MAA4B;CACnD,MAAM,WAAW,KAAK,IAAI,KAAK,KAAK;CACpC,MAAM,WAAW,KAAK,IAAI,KAAK,KAAK;CACpC,MAAM,aAAa,KAAK,IAAI,KAAK,OAAO;CACxC,MAAM,aAAa,KAAK,IAAI,KAAK,OAAO;CACxC,OAAO;EACL,MAAM;GAAE,GAAG,WAAW;GAAY,GAAG;GAAU,GAAG,WAAW;EAAW;EACxE,OAAO;GAAE,GAAG;GAAY,GAAG;GAAG,GAAG,IAAI;EAAW;EAChD,IAAI;GAAE,GAAG,IAAI,WAAW;GAAY,GAAG;GAAU,GAAG,IAAI,WAAW;EAAW;CAChF;AACF;;AAGA,SAAS,MAAM,OAAe,QAAgB,MAAsB;CAClE,QAAQ,MAAM,IAAI,OAAO,KAAK,KAAK,KAAK,MAAM,IAAI,OAAO,KAAK,KAAK,KAAK,MAAM,IAAI,OAAO,KAAK,KAAK;AACrG;;;;;;;;AASA,SAAgB,YAAY,QAA2B,QAAgB,MAAkB,KAAa,QA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AAK,IAAI,OAAO,OAAO;CAG1F,MAAM,QAAQ,KAAK,WAAW,WAAW,KAAK,IAAI,IAAI;CACtD,OAAO,KAAK,IAAI,QAAQ,SAAS,aAAa;AAChD;;;;;;;AAQA,SAAgB,aAAa,MAAa,IAAW,MAAc,UAAkB,GAAU;CAC7F,MAAM,WAAW,GAAW,MAAsB,KAAK,IAAI,KAAK;CAChE,MAAM,MAAM,KAAK,WAAW;CAC5B,MAAM,OAAO,GAAG,WAAW;CAC3B,MAAM,SAAS,MAAM,KAAK,OAAO,IAAI,OAAO,OAAO,QAAQ,OAAO,QAAQ,KAAK,IAAI;CACnF,OAAO;EACL,QAAQ;GAAE,GAAG,QAAQ,KAAK,OAAO,GAAG,GAAG,OAAO,CAAC;GAAG,GAAG,QAAQ,KAAK,OAAO,GAAG,GAAG,OAAO,CAAC;GAAG,GAAG,QAAQ,KAAK,OAAO,GAAG,GAAG,OAAO,CAAC;EAAE;EACjI,OAAO,QAAQ,KAAK,OAAO,GAAG,KAAK;EACnC,SAAS,KAAK,UAAU,YAAY,KAAK,SAAS,GAAG,OAAO,IAAI;EAChE,UAAU,UAAU;CACtB;AACF"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://json.schemastore.org/package",
|
|
3
3
|
"name": "@mark1russell7/visuals",
|
|
4
|
-
"version": "0.3.
|
|
4
|
+
"version": "0.3.2",
|
|
5
5
|
"description": "3D stages for data on three.js: a camera that a person moves, views by name, picking, highlights and themes, a globe of the Earth, and the shared marks of the viewers as data.",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"repository": {
|
|
@@ -51,6 +51,11 @@
|
|
|
51
51
|
"import": "./build/marks.js",
|
|
52
52
|
"default": "./build/marks.js"
|
|
53
53
|
},
|
|
54
|
+
"./markers": {
|
|
55
|
+
"types": "./build/markers.d.ts",
|
|
56
|
+
"import": "./build/markers.js",
|
|
57
|
+
"default": "./build/markers.js"
|
|
58
|
+
},
|
|
54
59
|
"./scrubber": {
|
|
55
60
|
"types": "./build/scrubber.d.ts",
|
|
56
61
|
"import": "./build/scrubber.js",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"extent-DC0qrxC5.js","names":[],"sources":["../src/view.ts","../src/extent.ts"],"sourcesContent":["import type { Point3 } from \"@mark1russell7/layout-contract\";\n\n/**\n * The direction of a view: where the camera is, as seen from the point that it looks at.\n * The space of a stage has the y axis up.\n */\nexport interface ViewAngles {\n /** The angle from the up axis to the camera, in radians. At 0, the camera looks down from above. */\n readonly polar: number;\n /** The angle around the up axis, in radians. At 0, the camera is on the positive z side of the point. */\n readonly azimuth: number;\n}\n\n/** A place of a camera: the point that it looks at, the angles of its view and its distance from the point. */\nexport interface Place extends ViewAngles {\n readonly target: Point3;\n readonly distance: number;\n}\n\n/** The three axes of a camera, as unit vectors in the space of the stage. */\nexport interface ViewAxes {\n /** The vector from the point that the camera looks at to the camera. */\n readonly back: Point3;\n /** The vector to the right side of the picture. */\n readonly right: Point3;\n /** The vector to the top of the picture. */\n readonly up: Point3;\n}\n\n/** The limits of the place of a camera. */\nexport interface PlaceLimits {\n /** The smallest polar angle. At 0, the azimuth of a camera has no meaning. */\n readonly minPolar: number;\n /** The largest polar angle. */\n readonly maxPolar: number;\n /** The smallest distance from the target. */\n readonly minDistance: number;\n /** The largest distance from the target. */\n readonly maxDistance: number;\n}\n\n/** This function gives the axes of the camera of a view. At a polar angle of 0, the top of the picture is the negative z axis. */\nexport function viewAxes(view: ViewAngles): ViewAxes {\n const sinPolar = Math.sin(view.polar);\n const cosPolar = Math.cos(view.polar);\n const sinAzimuth = Math.sin(view.azimuth);\n const cosAzimuth = Math.cos(view.azimuth);\n return {\n back: { x: sinPolar * sinAzimuth, y: cosPolar, z: sinPolar * cosAzimuth },\n right: { x: cosAzimuth, y: 0, z: 0 - sinAzimuth },\n up: { x: 0 - cosPolar * sinAzimuth, y: sinPolar, z: 0 - cosPolar * cosAzimuth },\n };\n}\n\n/** This function gives the dot product of the vector from `origin` to `point` with `axis`. */\nfunction along(point: Point3, origin: Point3, axis: Point3): number {\n return (point.x - origin.x) * axis.x + (point.y - origin.y) * axis.y + (point.z - origin.z) * axis.z;\n}\n\n/**\n * This function gives the smallest distance from `target` at which a camera shows each point.\n *\n * The camera looks at `target` along the direction of `view`. `fov` is the vertical angle of the picture in degrees,\n * and `aspect` is the width of the picture divided by its height.\n * The function gives 0 for no points, and for an angle or an aspect that makes no picture.\n */\nexport function fitDistance(points: readonly Point3[], target: Point3, view: ViewAngles, fov: number, aspect: number): number {\n const tanUp = Math.tan((fov * Math.PI) / 360);\n const tanRight = tanUp * aspect;\n if (!(tanUp > 0) || !(tanRight > 0) || !Number.isFinite(tanRight)) return 0;\n const axes = viewAxes(view);\n let distance = 0;\n for (const point of points) {\n const depth = along(point, target, axes.back);\n const needed = Math.max(Math.abs(along(point, target, axes.right)) / tanRight, Math.abs(along(point, target, axes.up)) / tanUp);\n distance = Math.max(distance, depth + needed);\n }\n return distance;\n}\n\n/**\n * This function gives the smallest distance from the center of a ball at which a camera shows a cap of the ball.\n *\n * The camera looks at the center of the ball, and the center of the cap is on the line to the camera.\n * `radius` is the radius of the ball. `angle` is the angle of the cap at the center of the ball, in radians, from 0 to π / 2.\n * `fov` is the vertical angle of the picture in degrees, and `aspect` is the width of the picture divided by its height.\n * The function gives 0 for an angle or an aspect that makes no picture.\n */\nexport function capDistance(radius: number, angle: number, fov: number, aspect: number): number {\n const tanUp = Math.tan((fov * Math.PI) / 360);\n const tan = Math.min(tanUp, tanUp * aspect);\n if (!(tan > 0) || !Number.isFinite(tan) || !(radius > 0)) return 0;\n const cap = Math.min(Math.max(angle, 0), Math.PI / 2);\n const half = Math.atan(tan);\n // A cap this large has its edge behind the outline of the ball. Then the outline of the ball is the limit.\n if (cap >= Math.PI / 2 - half) return radius / Math.sin(half);\n // The edge of the cap is at the height r sin(a) from the line, and at the depth r cos(a) from the center.\n return radius * Math.cos(cap) + (radius * Math.sin(cap)) / tan;\n}\n\n/** This function gives the position of a camera at a distance from `target`, in the direction of `view`. */\nexport function cameraPosition(target: Point3, view: ViewAngles, distance: number): Point3 {\n const { back } = viewAxes(view);\n return { x: target.x + back.x * distance, y: target.y + back.y * distance, z: target.z + back.z * distance };\n}\n\n/** This function gives the angles of the view from `target` to a camera, and the distance between them. A camera at the target gives the angles 0. */\nexport function viewOf(camera: Point3, target: Point3): ViewAngles & { readonly distance: number } {\n const x = camera.x - target.x;\n const y = camera.y - target.y;\n const z = camera.z - target.z;\n const distance = Math.hypot(x, y, z);\n if (!(distance > 0)) return { polar: 0, azimuth: 0, distance: 0 };\n return { polar: Math.acos(Math.min(Math.max(y / distance, -1), 1)), azimuth: Math.atan2(x, z), distance };\n}\n\n/** This function gives the angle between two azimuths along the shortest way, from −π to π. */\nexport function turnBetween(from: number, to: number): number {\n const full = 2 * Math.PI;\n const turn = (((to - from) % full) + full) % full;\n return turn > Math.PI ? turn - full : turn;\n}\n\n/** This function gives a place in its limits. The target and the azimuth stay as they are. */\nexport function clampPlace(place: Place, limits: PlaceLimits): Place {\n return {\n target: place.target,\n azimuth: place.azimuth,\n polar: Math.min(Math.max(place.polar, limits.minPolar), limits.maxPolar),\n distance: Math.min(Math.max(place.distance, limits.minDistance), limits.maxDistance),\n };\n}\n\n/**\n * This function gives the height of a camera above the surface of a stage, as a part of its distance from the target.\n *\n * `surface` is the radius of the ball around the target that the camera stays out of. A stage with no ball has the value 0.\n * The result is the factor of the zoom speed of a camera: near the surface, a camera moves slowly.\n * The result is 0.02 at least, so a camera on the surface can move away.\n */\nexport function speedAt(distance: number, surface: number): number {\n if (!(distance > 0)) return 1;\n return Math.min(Math.max((distance - surface) / distance, 0.02), 1);\n}\n\n/** The default vertical angle of the picture of a stage, in degrees. */\nexport const FIELD_OF_VIEW = 32;\n\n/** The smallest result of `turnAcross`, in radians. A camera on a ball, or in it, can thus turn. */\nconst SMALLEST_TURN = 1e-6;\n\n/**\n * This function gives the turn of a camera around a ball that moves the surface by the height of the picture, in radians.\n *\n * `surface` is the radius of the ball around the target. `fieldOfView` is the vertical angle of the picture, in degrees.\n *\n * The result is exact for the surface at the middle of the picture. Thus that surface follows the pointer in a drag.\n * The ball is round, so a long drag moves that surface by a smaller distance than the pointer.\n * Thus the surface does not go before the pointer.\n *\n * The result is `Infinity` for a stage with no ball, because such a stage has no surface that follows the pointer.\n * A turn about the up axis moves a point between the equator and a pole of the ball by a smaller distance.\n */\nexport function turnAcross(distance: number, surface: number, fieldOfView: number): number {\n const half = (fieldOfView * Math.PI) / 360;\n if (!(surface > 0) || !(distance > 0) || !(half > 0 && half < Math.PI / 2)) return Number.POSITIVE_INFINITY;\n // The surface at the middle of the picture is at the distance `distance - surface` from the camera.\n // There, the height of the picture shows this length of the surface. The turn is that length as an angle of the ball.\n const shown = 2 * (distance - surface) * Math.tan(half);\n return Math.max(shown / surface, SMALLEST_TURN);\n}\n\n/**\n * This function gives the place at a part of the way between two places. `part` goes from 0 to 1.\n *\n * The azimuth goes along the shortest way. The height above the surface changes by an equal factor for each equal step,\n * so a zoom has one speed in the picture. `surface` is the radius of the ball around the target, or 0 for no ball.\n */\nexport function placeBetween(from: Place, to: Place, part: number, surface: number = 0): Place {\n const between = (a: number, b: number): number => a + (b - a) * part;\n const low = from.distance - surface;\n const high = to.distance - surface;\n const height = low > 0 && high > 0 ? low * (high / low) ** part : between(low, high);\n return {\n target: { x: between(from.target.x, to.target.x), y: between(from.target.y, to.target.y), z: between(from.target.z, to.target.z) },\n polar: between(from.polar, to.polar),\n azimuth: from.azimuth + turnBetween(from.azimuth, to.azimuth) * part,\n distance: surface + height,\n };\n}\n","import type { Point3 } from \"@mark1russell7/layout-contract\";\nimport { capDistance, fitDistance, viewOf, type Place, type PlaceLimits, type ViewAngles } from \"./view.ts\";\n\n/** The space that the content of a stage fills. A view and the limits of the camera come from it. */\nexport interface StageExtent {\n /** The points that a view of all the content shows, for example each corner of each solid. */\n readonly corners: readonly Point3[];\n /** The point that the camera looks at. */\n readonly center: Point3;\n /**\n * The radius of the ball around the center that the camera stays out of, for example the radius of a globe.\n * The default is 0: the content has no ball.\n */\n readonly surface?: number | undefined;\n /** The smallest distance of the camera from the center. The default comes from the views of the stage. */\n readonly minDistance?: number | undefined;\n /** The largest distance of the camera from the center. The default comes from the views of the stage. */\n readonly maxDistance?: number | undefined;\n}\n\n/** The picture that a view is for: the content, and the angle and the shape of the picture. */\nexport interface ViewFrame {\n readonly extent: StageExtent;\n /** The vertical angle of the picture, in degrees. */\n readonly fieldOfView: number;\n /** The width of the picture divided by its height. */\n readonly aspect: number;\n}\n\n/** A view of a stage: a function that gives the place of the camera for a picture. A new size of the picture gives a new place. */\nexport type StageView = (frame: ViewFrame) => Place;\n\n/** The limits of the camera of a stage: the limits of its place, and the nearest and the farthest depth that it draws. */\nexport interface StageLimits extends PlaceLimits {\n readonly near: number;\n readonly far: number;\n}\n\n/** The space around the content in a view that shows all of it, as a factor of the distance. */\nexport const FIT_MARGIN = 1.06;\n\n/** This function gives the radius of the ball around the center of an extent, or 0 for no ball. */\nexport function surfaceOf(extent: StageExtent): number {\n const surface = extent.surface ?? 0;\n return surface > 0 ? surface : 0;\n}\n\n/**\n * This function makes a view that shows each corner of the content from one direction.\n * `margin` is the space around the content, as a factor of the distance. An extent with no corners gives the distance 1.\n */\nexport function fitView(angles: ViewAngles, margin: number = FIT_MARGIN): StageView {\n return ({ extent, fieldOfView, aspect }) => {\n const distance = fitDistance(extent.corners, extent.center, angles, fieldOfView, aspect) * margin;\n return { target: extent.center, polar: angles.polar, azimuth: angles.azimuth, distance: distance > 0 ? distance : 1 };\n };\n}\n\n/**\n * This function makes a view of a part of the ball of the content: a cap around the point of the ball below the camera.\n *\n * `angles` is the direction from the center of the ball to the camera. `angle` is the angle of the cap at the center of the ball, in radians.\n * `margin` is the space around the cap, as a factor of the height above the ball. An extent with no ball gives the distance 1.\n */\nexport function capView(angles: ViewAngles, angle: number, margin: number = FIT_MARGIN): StageView {\n return ({ extent, fieldOfView, aspect }) => {\n const surface = surfaceOf(extent);\n const height = Math.max(capDistance(surface, angle, fieldOfView, aspect) - surface, 0);\n return { target: extent.center, polar: angles.polar, azimuth: angles.azimuth, distance: surface > 0 ? surface + height * margin : 1 };\n };\n}\n\n/**\n * This function makes a view of points on the ball of the content. The camera is above the middle of the points, and the picture shows each point.\n *\n * The middle is the center of the box of the points. The camera is at the smallest distance that shows each point in the width and in the height of the picture.\n * Thus wide points fill a wide picture. `margin` is the space around the points, as a factor of the height above the ball.\n * A list with no points gives a view of all of the ball from the front. Points with their middle at the center of the ball give the same view.\n */\nexport function ballView(points: readonly Point3[], margin: number = FIT_MARGIN): StageView {\n let found: { readonly center: Point3; readonly angles: ViewAngles | undefined } | undefined;\n return (frame) => {\n const { extent } = frame;\n const { center } = extent;\n // The middle is the same for each picture of one content. So the function calculates it one time for each center.\n if (found === undefined || found.center.x !== center.x || found.center.y !== center.y || found.center.z !== center.z) {\n found = { center, angles: middleOf(points, center) };\n }\n const { angles } = found;\n if (angles === undefined) return capView({ polar: Math.PI / 2, azimuth: 0 }, Math.PI / 2, margin)(frame);\n const surface = surfaceOf(extent);\n // A point of the ball needs no more distance than the outline of the ball. Thus the camera is not farther than a view of all of the ball.\n const height = Math.max(fitDistance(points, center, angles, frame.fieldOfView, frame.aspect) - surface, 0);\n return { target: center, polar: angles.polar, azimuth: angles.azimuth, distance: surface > 0 ? surface + height * margin : 1 };\n };\n}\n\n/** This function gives the direction from `center` to the middle of the box of the points. It gives `undefined` when the middle has no direction. */\nfunction middleOf(points: readonly Point3[], center: Point3): ViewAngles | undefined {\n const low = { x: Infinity, y: Infinity, z: Infinity };\n const high = { x: -Infinity, y: -Infinity, z: -Infinity };\n for (const point of points) {\n low.x = Math.min(low.x, point.x);\n low.y = Math.min(low.y, point.y);\n low.z = Math.min(low.z, point.z);\n high.x = Math.max(high.x, point.x);\n high.y = Math.max(high.y, point.y);\n high.z = Math.max(high.z, point.z);\n }\n const middle = { x: (low.x + high.x) / 2 - center.x, y: (low.y + high.y) / 2 - center.y, z: (low.z + high.z) / 2 - center.z };\n const length = Math.hypot(middle.x, middle.y, middle.z);\n if (!(length > 0) || !Number.isFinite(length)) return undefined;\n const { polar, azimuth } = viewOf(middle, { x: 0, y: 0, z: 0 });\n return { polar, azimuth };\n}\n\n/** This function gives the radius of the ball around the center of an extent that holds the ball of the extent and each corner. */\nexport function reachOf(extent: StageExtent): number {\n let reach = surfaceOf(extent);\n for (const corner of extent.corners) reach = Math.max(reach, Math.hypot(corner.x - extent.center.x, corner.y - extent.center.y, corner.z - extent.center.z));\n return reach;\n}\n\n/**\n * This function gives the nearest depth that a camera draws, from the distance of the camera to the center of the content.\n *\n * A camera far from the content gets a large value. The depths of the content then have more steps, so two surfaces that are near stay apart.\n * The result is not less than the nearest depth of the limits, and it is in front of all the content.\n */\nexport function nearDepth(limits: StageLimits, extent: StageExtent, distance: number): number {\n const free = (distance - reachOf(extent)) / 8;\n return free > limits.near ? Math.min(free, limits.far / 4) : limits.near;\n}\n\n/**\n * This function gives the limits of the camera of a stage for a picture.\n *\n * The largest distance of the views is the base. The camera goes out to 3 times this distance, and in to 3 % of the height of that view.\n * The extent can give each distance. The nearest depth is small against the height of the nearest camera, and the farthest depth is behind all the content.\n */\nexport function stageLimits(frame: ViewFrame, views: readonly StageView[], polar: { readonly min: number; readonly max: number }): StageLimits {\n const { extent } = frame;\n const surface = surfaceOf(extent);\n let widest = 0;\n for (const view of views) widest = Math.max(widest, view(frame).distance);\n if (!(widest > surface)) widest = surface + 1;\n const reach = reachOf(extent);\n const minDistance = extent.minDistance ?? surface + (widest - surface) * 0.03;\n const maxDistance = Math.max(extent.maxDistance ?? surface + (widest - surface) * 3, minDistance);\n const height = Math.max(minDistance - surface, 1e-6);\n return { minPolar: polar.min, maxPolar: polar.max, minDistance, maxDistance, near: height / 8, far: (maxDistance + reach) * 1.5 };\n}\n"],"mappings":";;AA0CA,SAAgB,SAAS,MAA4B;CACnD,MAAM,WAAW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