@margoengine/html 0.0.0-stage → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ //#region ../shared/errors.js
2
+ var e = (e, t) => Object.assign(Error(t), {
3
+ name: "MargoError",
4
+ code: e
5
+ });
6
+ //#endregion
7
+ export { e as t };
@@ -0,0 +1,31 @@
1
+ import { t as e } from "./errors-fc4i1pSL.js";
2
+ //#region src/gl.ts
3
+ function t(t, n, r) {
4
+ let i = t.createProgram();
5
+ for (let [e, a] of [[t.VERTEX_SHADER, n], [t.FRAGMENT_SHADER, r]]) {
6
+ let n = t.createShader(e);
7
+ t.shaderSource(n, a), t.compileShader(n), t.attachShader(i, n), t.deleteShader(n);
8
+ }
9
+ if (t.linkProgram(i), !t.getProgramParameter(i, t.LINK_STATUS)) {
10
+ let n = t.getProgramInfoLog(i);
11
+ throw t.deleteProgram(i), e("failed", `HTML preview shader failed: ${n}; check WebGL2 support`);
12
+ }
13
+ return i;
14
+ }
15
+ function n(e) {
16
+ let t = e.getParameter(e.CURRENT_PROGRAM), n = e.getParameter(e.VERTEX_ARRAY_BINDING), r = e.getParameter(e.VIEWPORT), i = e.getParameter(e.SCISSOR_BOX), a = e.getParameter(e.COLOR_WRITEMASK), o = e.getParameter(e.DEPTH_WRITEMASK), s = e.getParameter(e.DEPTH_FUNC), c = e.getParameter(e.BLEND_SRC_RGB), l = e.getParameter(e.BLEND_DST_RGB), u = e.getParameter(e.BLEND_SRC_ALPHA), d = e.getParameter(e.BLEND_DST_ALPHA), f = e.getParameter(e.BLEND_EQUATION_RGB), p = e.getParameter(e.BLEND_EQUATION_ALPHA), m = e.getParameter(e.ACTIVE_TEXTURE), h = [
17
+ e.BLEND,
18
+ e.CULL_FACE,
19
+ e.DEPTH_TEST,
20
+ e.SCISSOR_TEST
21
+ ].map((t) => [t, e.isEnabled(t)]);
22
+ e.activeTexture(e.TEXTURE0);
23
+ let g = e.getParameter(e.TEXTURE_BINDING_2D), _ = e.getParameter(e.SAMPLER_BINDING);
24
+ return () => {
25
+ e.useProgram(t), e.bindVertexArray(n), e.viewport(r[0], r[1], r[2], r[3]), e.scissor(i[0], i[1], i[2], i[3]), e.colorMask(a[0], a[1], a[2], a[3]), e.depthMask(o), e.depthFunc(s), e.blendFuncSeparate(c, l, u, d), e.blendEquationSeparate(f, p);
26
+ for (let [t, n] of h) n ? e.enable(t) : e.disable(t);
27
+ e.activeTexture(e.TEXTURE0), e.bindTexture(e.TEXTURE_2D, g), e.bindSampler(0, _), e.activeTexture(m);
28
+ };
29
+ }
30
+ //#endregion
31
+ export { t as n, n as t };
package/dist/gl.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ /** Internal clean-room GL program builder, shared by HTML's optional preview passes. */
2
+ export declare function htmlProgram(gl: WebGL2RenderingContext, vertex: string, fragment: string): WebGLProgram;
3
+ /** Preserve every draw state changed by either HTML pass, including texture unit zero's sampler. */
4
+ export declare function htmlGLState(gl: WebGL2RenderingContext): () => void;
@@ -0,0 +1,88 @@
1
+ /// <reference lib="esnext.disposable" preserve="true" />
2
+ import type { EngineKernel } from '@margoengine/core';
3
+ import { type FrameGraph } from '@margoengine/core/extension';
4
+ import { LabelRenderer, type Label, type CSS3DObject, type LabelRendererOptions, type LabelOptions } from '@margoengine/labels';
5
+ export type { Label, CSS3DObject } from '@margoengine/labels';
6
+ export type { LabelOptions, CSS3DOptions, LabelInfo } from '@margoengine/labels';
7
+ /**
8
+ * Options of HTML: label renderer options plus optional depth-texture occlusion, the anchor capacity and a depth bias.
9
+ */
10
+ export interface HTMLOptions extends LabelRendererOptions {
11
+ depth?: false | (() => GPUTexture | undefined);
12
+ /** Most anchors at once, 1 to 1,048,576 (default 1024). Storage starts at 64 slots and doubles as anchors are added. */
13
+ capacity?: number;
14
+ depthBias?: number;
15
+ /**
16
+ * Fade an anchor as geometry covers it instead of hiding it at once: its element's opacity follows the share of a
17
+ * grid of depth tests around the anchor that pass. `true` uses the defaults of {@link HTMLFadeOptions}. Default off.
18
+ */
19
+ fade?: boolean | HTMLFadeOptions;
20
+ }
21
+ /** How HTML fades partly occluded anchors. */
22
+ export interface HTMLFadeOptions {
23
+ /** Half the side of the sampled square around the anchor, in CSS pixels, 0 to 256. Default 8. */
24
+ radius?: number;
25
+ /** Depth tests per side of the square's grid, 2 to 8. Default 4 (16 tests an anchor). */
26
+ samples?: number;
27
+ /** Seconds the opacity takes to go from 1 to 0, 0 to 10; 0 follows each result at once. Default 0.15. */
28
+ duration?: number;
29
+ }
30
+ /** DOM projection from labels, with asynchronous rendered-depth occlusion for 2D anchors. */
31
+ export declare class HTML extends LabelRenderer {
32
+ private readonly settings;
33
+ private runtime?;
34
+ private readonly records;
35
+ private readonly slots;
36
+ /** Point data of every slot up to `allocated`; grows by doubling as anchors are added. */
37
+ private values;
38
+ private readonly capacity;
39
+ /** Slots with storage on the CPU, and on the GPU (the GPU buffers grow at the next depth sample). */
40
+ private allocated;
41
+ private gpuSlots;
42
+ /** One past the highest slot ever used: per-frame work runs to here, not to `capacity`. */
43
+ private used;
44
+ private readonly free;
45
+ private shared?;
46
+ private source?;
47
+ private input?;
48
+ private output?;
49
+ private read?;
50
+ private pipeline?;
51
+ private pending;
52
+ private generation;
53
+ private disposed;
54
+ private sampledDepth?;
55
+ private depthGroup?;
56
+ /** Snapshot of the slots submitted with the current depth read. The next sample waits until that read finishes. */
57
+ private readonly depthRequests;
58
+ private readonly fade?;
59
+ private radius?;
60
+ private readonly radiusValues;
61
+ private delta;
62
+ private glOcclusion?;
63
+ constructor(settings?: HTMLOptions);
64
+ static attach(engine: EngineKernel, options?: HTMLOptions): HTML;
65
+ add(element: HTMLElement, options?: LabelOptions): Label;
66
+ private grow;
67
+ remove(item: Label | CSS3DObject): void;
68
+ setup(instance: EngineKernel): void;
69
+ private setupGPU;
70
+ /** Point, result and readback buffers for `allocated` slots. Only called while no depth read is in flight. */
71
+ private buffers;
72
+ onPreUpdate(delta: number): void;
73
+ /** Positions every anchor; with `fade`, first moves each opacity toward its visible share, then writes it. */
74
+ update(): void;
75
+ registerPasses(graph: FrameGraph): void;
76
+ private sample;
77
+ /**
78
+ * WebGL2: reads every finished query round, then draws a new round for each anchor that has none in flight. Results
79
+ * become available a frame or more later (WebGL 2.0 never makes them available in the frame that issued them).
80
+ */
81
+ private query;
82
+ private releaseGL;
83
+ /** Frees this overlay's own GPU objects; with `lease`, also its share of the scene depth (which restores itself). */
84
+ private release;
85
+ onDeviceRestored(): void;
86
+ dispose(): void;
87
+ [Symbol.dispose]: () => void;
88
+ }