@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.
- package/LICENSE +201 -0
- package/NOTICE +4 -0
- package/README.md +197 -2
- package/dist/blend.d.ts +33 -0
- package/dist/blend.js +185 -0
- package/dist/dom-CgZN0DP1.js +17 -0
- package/dist/dom.d.ts +2 -0
- package/dist/errors-fc4i1pSL.js +7 -0
- package/dist/gl-j8yV2Jj1.js +31 -0
- package/dist/gl.d.ts +4 -0
- package/dist/index.d.ts +88 -0
- package/dist/index.js +614 -0
- package/dist/inline.d.ts +13 -0
- package/dist/inline.js +153 -0
- package/dist/pass-BVRaGB09.js +16 -0
- package/dist/texture-gl.d.ts +17 -0
- package/dist/texture-gl.js +103 -0
- package/dist/texture-kX-VTlgW.js +313 -0
- package/dist/texture.d.ts +126 -0
- package/dist/texture.js +1 -0
- package/dist/view-rect-Be4T67Kk.js +16 -0
- package/package.json +64 -4
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
/// <reference lib="esnext.disposable" preserve="true" />
|
|
2
|
+
import type { EngineKernel, Mesh } from '@margoengine/core';
|
|
3
|
+
import { type Engine, type FrameGraph } from '@margoengine/core/extension';
|
|
4
|
+
/** Options of one HTML surface: its size in world units, its texture density and the transform it follows. */
|
|
5
|
+
export interface HTMLSurfaceOptions {
|
|
6
|
+
/** Width in world units. Default: the element's CSS width / 100 (100 CSS pixels a metre). */
|
|
7
|
+
width?: number;
|
|
8
|
+
/** Height in world units. Default: the element's CSS height / 100. */
|
|
9
|
+
height?: number;
|
|
10
|
+
/** Texture pixels per CSS pixel, 0.25 to 4. Default `devicePixelRatio` (1 without one). */
|
|
11
|
+
pixelRatio?: number;
|
|
12
|
+
/** Follow this mesh's world transform. The surface lies in its local XY plane, centred, facing +Z. */
|
|
13
|
+
mesh?: Mesh;
|
|
14
|
+
/** Column-major 4 x 4 world matrix, used without `mesh`. Default identity. */
|
|
15
|
+
matrix?: ArrayLike<number>;
|
|
16
|
+
/** Route the page's pointer to the element where it hits the surface. Default true. */
|
|
17
|
+
interactive?: boolean;
|
|
18
|
+
}
|
|
19
|
+
/** Which rasterizer draws the element: the browser's HTML-in-canvas `drawElementImage`, or an SVG `foreignObject`. */
|
|
20
|
+
export type HTMLSurfaceRasterizer = 'element-image' | 'foreign-object';
|
|
21
|
+
/** Prepares a self-contained element copy for foreignObject; receives the surface's removal signal. */
|
|
22
|
+
export type HTMLResourceInliner = (element: HTMLElement, signal: AbortSignal) => Promise<Element>;
|
|
23
|
+
/** Rasterizer, plugin name and optional external-resource preparation. */
|
|
24
|
+
export interface HTMLTextureOptions {
|
|
25
|
+
name?: string;
|
|
26
|
+
rasterizer?: HTMLSurfaceRasterizer;
|
|
27
|
+
/** Optional foreignObject preparation, e.g. resourceInliner() from html/inline. Default computed-style copy only. */
|
|
28
|
+
prepare?: HTMLResourceInliner;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Where the pointer at clip-space point (x, y) meets a surface of `width` x `height` in the XY plane of `model`: its UV
|
|
32
|
+
* (0,0 top left) and its clip depth, or null. The plane's points (px, py) project by the 3 x 3 homography of columns x,
|
|
33
|
+
* y and w of viewProjection x model, so (px, py) solves two linear equations; no matrix is inverted, and it holds on
|
|
34
|
+
* both depth conventions.
|
|
35
|
+
*/
|
|
36
|
+
export declare function surfaceHit(viewProjection: ArrayLike<number>, model: ArrayLike<number>, width: number, height: number, x: number, y: number): {
|
|
37
|
+
u: number;
|
|
38
|
+
v: number;
|
|
39
|
+
t: number;
|
|
40
|
+
} | null;
|
|
41
|
+
/** One element drawn on a quad in the scene. */
|
|
42
|
+
export declare class HTMLSurface {
|
|
43
|
+
private readonly owner;
|
|
44
|
+
readonly element: HTMLElement;
|
|
45
|
+
width: number;
|
|
46
|
+
height: number;
|
|
47
|
+
mesh: Mesh | null;
|
|
48
|
+
readonly matrix: Float32Array<ArrayBuffer>;
|
|
49
|
+
interactive: boolean;
|
|
50
|
+
/** Raster drawn so far; the texture is redrawn after the element changes. */
|
|
51
|
+
draws: number;
|
|
52
|
+
/** @internal */ readonly holder: HTMLElement;
|
|
53
|
+
/** @internal The 2D canvas a foreignObject image is drawn into before its upload. */
|
|
54
|
+
scratch?: HTMLCanvasElement;
|
|
55
|
+
/** @internal */ texture?: GPUTexture;
|
|
56
|
+
/** @internal */ group?: GPUBindGroup;
|
|
57
|
+
/** @internal The pipeline `group` was made for: an 'auto' layout fits only the pipeline it came from. */
|
|
58
|
+
pipeline?: GPURenderPipeline;
|
|
59
|
+
/** @internal */ uniform?: GPUBuffer;
|
|
60
|
+
/** @internal */ dirty: boolean;
|
|
61
|
+
/** @internal */ busy: boolean;
|
|
62
|
+
/** @internal */ readonly pixelRatio: number;
|
|
63
|
+
/** @internal */ readonly world: Float32Array<ArrayBuffer>;
|
|
64
|
+
private readonly observer?;
|
|
65
|
+
private readonly cancellation;
|
|
66
|
+
/** @internal Cancels resource preparation when this surface is removed. */
|
|
67
|
+
get signal(): AbortSignal;
|
|
68
|
+
/** @internal A raster waiting for the holder canvas's next paint event (HTML-in-canvas draws only there). */
|
|
69
|
+
painting?: () => void;
|
|
70
|
+
private readonly mark;
|
|
71
|
+
private readonly paint;
|
|
72
|
+
constructor(owner: HTMLTexture, element: HTMLElement, options: HTMLSurfaceOptions);
|
|
73
|
+
/** Sets the world matrix (column-major) used without `mesh`. */
|
|
74
|
+
setMatrix(matrix: ArrayLike<number>): this;
|
|
75
|
+
/** Redraws the texture on the next frame, for changes no mutation shows (a style sheet, a loaded font). */
|
|
76
|
+
invalidate(): void;
|
|
77
|
+
/** The element's size in CSS pixels, as drawn on the surface. */
|
|
78
|
+
get cssSize(): [number, number];
|
|
79
|
+
remove(): void;
|
|
80
|
+
/** @internal */ detach(): void;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* HTML elements drawn as textures on quads in the scene, depth-tested with it, with the page's pointer routed to the
|
|
84
|
+
* element where it hits a quad. WebGPU only.
|
|
85
|
+
*/
|
|
86
|
+
export declare class HTMLTexture {
|
|
87
|
+
readonly name: string;
|
|
88
|
+
/** How elements are drawn: the HTML-in-canvas API where the browser has it, else an SVG `foreignObject` image. */
|
|
89
|
+
readonly rasterizer: HTMLSurfaceRasterizer;
|
|
90
|
+
protected runtime?: Engine;
|
|
91
|
+
protected readonly surfaces: Set<HTMLSurface>;
|
|
92
|
+
/** Optional backends opt in without adding their code to this entry. */
|
|
93
|
+
protected readonly preview: boolean;
|
|
94
|
+
private pipelines;
|
|
95
|
+
private sampler?;
|
|
96
|
+
private disposed;
|
|
97
|
+
private hovered;
|
|
98
|
+
/** Depth convention of the last frame: reversed depth is nearer when larger. */
|
|
99
|
+
private reversed;
|
|
100
|
+
/** Colour and depth loaded and stored, so later passes see the quads' depth too. */
|
|
101
|
+
private readonly descriptor;
|
|
102
|
+
private readonly values;
|
|
103
|
+
private readonly pointer;
|
|
104
|
+
private readonly prepare?;
|
|
105
|
+
constructor(options?: HTMLTextureOptions);
|
|
106
|
+
static attach(engine: EngineKernel, options?: HTMLTextureOptions): HTMLTexture;
|
|
107
|
+
/** Draws `element` on a quad in the scene. The element moves into an invisible holder in `document.body`. */
|
|
108
|
+
add(element: HTMLElement, options?: HTMLSurfaceOptions): HTMLSurface;
|
|
109
|
+
remove(surface: HTMLSurface): void;
|
|
110
|
+
get size(): number;
|
|
111
|
+
setup(instance: EngineKernel): void;
|
|
112
|
+
registerPasses(graph: FrameGraph): void;
|
|
113
|
+
/** World matrix of a surface this frame: its mesh's, or its own. */
|
|
114
|
+
worldMatrix(surface: HTMLSurface): Float32Array;
|
|
115
|
+
/** Moves the hit surface's element under the pointer so the browser's own hit test, focus and hover reach it. */
|
|
116
|
+
private route;
|
|
117
|
+
private pipeline;
|
|
118
|
+
protected refresh(surface: HTMLSurface): void;
|
|
119
|
+
/** Upload hook for optional renderer entries; the rasterizer and interaction stay shared. */
|
|
120
|
+
protected upload(surface: HTMLSurface, source: HTMLCanvasElement, width: number, height: number): void;
|
|
121
|
+
private rasterize;
|
|
122
|
+
private draw;
|
|
123
|
+
onDeviceRestored(): void;
|
|
124
|
+
dispose(): void;
|
|
125
|
+
[Symbol.dispose]: () => void;
|
|
126
|
+
}
|
package/dist/texture.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { t as HTMLSurface, n as HTMLTexture, r as surfaceHit } from "./texture-kX-VTlgW.js";
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
//#region ../shared/view-rect.js
|
|
2
|
+
function e(e) {
|
|
3
|
+
return e?.view?.viewport;
|
|
4
|
+
}
|
|
5
|
+
function t(t, n) {
|
|
6
|
+
let r = e(n);
|
|
7
|
+
if (!r) return;
|
|
8
|
+
t.setViewport(r[0], r[1], r[2], r[3], 0, 1);
|
|
9
|
+
let i = n.view.scissor ?? r;
|
|
10
|
+
t.setScissorRect(i[0], i[1], i[2], i[3]);
|
|
11
|
+
}
|
|
12
|
+
function n(e, t = "clear") {
|
|
13
|
+
return e?.view?.index ? "load" : t;
|
|
14
|
+
}
|
|
15
|
+
//#endregion
|
|
16
|
+
export { n, t };
|
package/package.json
CHANGED
|
@@ -1,6 +1,66 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@margoengine/html",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "World-space DOM anchors, CSS3D placement and scene-depth occlusion.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"margoengine",
|
|
7
|
+
"webgpu",
|
|
8
|
+
"3d",
|
|
9
|
+
"html"
|
|
10
|
+
],
|
|
11
|
+
"homepage": "https://margoengine.com",
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/scottcampbelldata/margoengine/issues"
|
|
14
|
+
},
|
|
15
|
+
"repository": {
|
|
16
|
+
"type": "git",
|
|
17
|
+
"url": "git+https://github.com/scottcampbelldata/margoengine.git",
|
|
18
|
+
"directory": "packages/html"
|
|
19
|
+
},
|
|
20
|
+
"license": "Apache-2.0",
|
|
21
|
+
"author": "Scott Campbell",
|
|
22
|
+
"type": "module",
|
|
23
|
+
"sideEffects": false,
|
|
24
|
+
"exports": {
|
|
25
|
+
".": {
|
|
26
|
+
"types": "./dist/index.d.ts",
|
|
27
|
+
"import": "./dist/index.js"
|
|
28
|
+
},
|
|
29
|
+
"./texture": {
|
|
30
|
+
"types": "./dist/texture.d.ts",
|
|
31
|
+
"import": "./dist/texture.js"
|
|
32
|
+
},
|
|
33
|
+
"./texture-gl": {
|
|
34
|
+
"types": "./dist/texture-gl.d.ts",
|
|
35
|
+
"import": "./dist/texture-gl.js"
|
|
36
|
+
},
|
|
37
|
+
"./blend": {
|
|
38
|
+
"types": "./dist/blend.d.ts",
|
|
39
|
+
"import": "./dist/blend.js"
|
|
40
|
+
},
|
|
41
|
+
"./inline": {
|
|
42
|
+
"types": "./dist/inline.d.ts",
|
|
43
|
+
"import": "./dist/inline.js"
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
"files": [
|
|
47
|
+
"dist",
|
|
48
|
+
"LICENSE",
|
|
49
|
+
"NOTICE"
|
|
50
|
+
],
|
|
51
|
+
"publishConfig": {
|
|
52
|
+
"access": "public"
|
|
53
|
+
},
|
|
54
|
+
"dependencies": {
|
|
55
|
+
"@margoengine/labels": "^1.0.0"
|
|
56
|
+
},
|
|
57
|
+
"peerDependencies": {
|
|
58
|
+
"@margoengine/core": "^1.0.0"
|
|
59
|
+
},
|
|
60
|
+
"scripts": {
|
|
61
|
+
"build": "node ../../scripts/build-optional.js html",
|
|
62
|
+
"test": "npm run build && node --test test/*.test.js",
|
|
63
|
+
"test:browser": "npm run build && node scripts/test-browser.js",
|
|
64
|
+
"prepack": "npm run build"
|
|
65
|
+
}
|
|
66
|
+
}
|