@displayxr/inline3d-tools 0.0.1 → 0.1.1
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/AGENTS.md +351 -0
- package/LICENSE +190 -0
- package/README.md +204 -1
- package/bin/inline3d-tools.mjs +40 -0
- package/lib/assets/asset-check.mjs +262 -0
- package/lib/assets/blender/prep.py +74 -0
- package/lib/assets/prep.mjs +50 -0
- package/lib/check/analyze.mjs +244 -0
- package/lib/check/cdp.mjs +198 -0
- package/lib/check/cli.mjs +66 -0
- package/lib/check/fake-env.js +435 -0
- package/lib/check/png.mjs +75 -0
- package/lib/check/probe.js +245 -0
- package/lib/check/run.mjs +811 -0
- package/lib/check/server.mjs +33 -0
- package/lib/gen.mjs +172 -0
- package/lib/mcp.mjs +168 -0
- package/lib/scaffold.mjs +62 -0
- package/package.json +50 -4
- package/templates/app.js +153 -0
- package/templates/esm/index.html +29 -0
- package/templates/style.css +17 -0
- package/templates/vite/index.html +20 -0
- package/templates/vite/package.template.json +18 -0
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
// inline3d-check — in-page probe, injected at document start in EVERY run (fake and plain).
|
|
2
|
+
// Records what the harness cannot see from outside: WebGL contexts per canvas, shader/program
|
|
3
|
+
// compile failures, and helpers the harness calls (CSS audit, occlusion audit). It changes no
|
|
4
|
+
// page behaviour except the MAX_TEXTURE_SIZE simulation when the harness asks for one.
|
|
5
|
+
(() => {
|
|
6
|
+
if (window.__dxrProbe) return;
|
|
7
|
+
const CFG = window.__DXR_CHECK_CFG || {};
|
|
8
|
+
const P = (window.__dxrProbe = { contexts: new WeakMap(), shaderErrors: [], glCanvases: [] });
|
|
9
|
+
|
|
10
|
+
// ---- contexts per canvas (to read drawingBufferWidth later without guessing the type) -------
|
|
11
|
+
const origGetContext = HTMLCanvasElement.prototype.getContext;
|
|
12
|
+
HTMLCanvasElement.prototype.getContext = function (type, attrs) {
|
|
13
|
+
const ctx = origGetContext.call(this, type, attrs);
|
|
14
|
+
if (ctx && !P.contexts.has(this)) {
|
|
15
|
+
P.contexts.set(this, { type, ctx, attrs: attrs ? { ...attrs } : null });
|
|
16
|
+
if (/webgl/.test(type)) P.glCanvases.push(this);
|
|
17
|
+
}
|
|
18
|
+
return ctx;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
// ---- shader / program failures: engines always query the status, so this costs nothing -----
|
|
22
|
+
const LIMIT = CFG.maxTextureSize || 0;
|
|
23
|
+
for (const C of [window.WebGLRenderingContext, window.WebGL2RenderingContext]) {
|
|
24
|
+
if (!C) continue;
|
|
25
|
+
const proto = C.prototype;
|
|
26
|
+
const gsp = proto.getShaderParameter;
|
|
27
|
+
proto.getShaderParameter = function (sh, pname) {
|
|
28
|
+
const v = gsp.call(this, sh, pname);
|
|
29
|
+
if (pname === this.COMPILE_STATUS && v === false && !this.isContextLost()) {
|
|
30
|
+
let log = '';
|
|
31
|
+
try { log = this.getShaderInfoLog(sh) || ''; } catch { /* lost */ }
|
|
32
|
+
P.shaderErrors.push(('shader compile failed: ' + log).slice(0, 400));
|
|
33
|
+
}
|
|
34
|
+
return v;
|
|
35
|
+
};
|
|
36
|
+
const gpp = proto.getProgramParameter;
|
|
37
|
+
proto.getProgramParameter = function (pr, pname) {
|
|
38
|
+
const v = gpp.call(this, pr, pname);
|
|
39
|
+
if (pname === this.LINK_STATUS && v === false && !this.isContextLost()) {
|
|
40
|
+
let log = '';
|
|
41
|
+
try { log = this.getProgramInfoLog(pr) || ''; } catch { /* lost */ }
|
|
42
|
+
P.shaderErrors.push(('program link failed: ' + log).slice(0, 400));
|
|
43
|
+
}
|
|
44
|
+
return v;
|
|
45
|
+
};
|
|
46
|
+
if (LIMIT) {
|
|
47
|
+
// The tablet's limits, so the SDK's own clamp logic (and the page's) sees what it would see
|
|
48
|
+
// there. The real clamp comes from Chrome's --webgl_or_caps_max_texture_size_limit_4096.
|
|
49
|
+
const gp = proto.getParameter;
|
|
50
|
+
proto.getParameter = function (pname) {
|
|
51
|
+
const v = gp.call(this, pname);
|
|
52
|
+
if (pname === this.MAX_TEXTURE_SIZE || pname === this.MAX_RENDERBUFFER_SIZE) return Math.min(v, LIMIT);
|
|
53
|
+
if (pname === this.MAX_VIEWPORT_DIMS && v && v.length === 2) return new Int32Array([Math.min(v[0], LIMIT), Math.min(v[1], LIMIT)]);
|
|
54
|
+
return v;
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// ---- helpers the harness calls -------------------------------------------------------------
|
|
60
|
+
function selectorOf(el) {
|
|
61
|
+
if (!el || el.nodeType !== 1) return null;
|
|
62
|
+
if (el.id) return `#${CSS.escape(el.id)}`;
|
|
63
|
+
const parts = [];
|
|
64
|
+
for (let e = el; e && e.nodeType === 1 && e !== document.documentElement; e = e.parentElement) {
|
|
65
|
+
if (e.id) { parts.unshift(`#${CSS.escape(e.id)}`); break; }
|
|
66
|
+
const tag = e.tagName.toLowerCase();
|
|
67
|
+
const sib = e.parentElement ? [...e.parentElement.children].filter((c) => c.tagName === e.tagName) : [];
|
|
68
|
+
parts.unshift(sib.length > 1 ? `${tag}:nth-of-type(${sib.indexOf(e) + 1})` : tag);
|
|
69
|
+
}
|
|
70
|
+
return parts.join(' > ');
|
|
71
|
+
}
|
|
72
|
+
P.selectorOf = selectorOf;
|
|
73
|
+
|
|
74
|
+
function rectOf(el) {
|
|
75
|
+
const r = el.getBoundingClientRect();
|
|
76
|
+
return { x: r.left, y: r.top, width: r.width, height: r.height };
|
|
77
|
+
}
|
|
78
|
+
P.rectOf = rectOf;
|
|
79
|
+
|
|
80
|
+
function isIdentityishTransform(t) {
|
|
81
|
+
if (!t || t === 'none') return true;
|
|
82
|
+
// A pure translation (incl. the SDK's own translateZ(0)) is fine: rule 7 allows a static translate.
|
|
83
|
+
try {
|
|
84
|
+
const m = new DOMMatrixReadOnly(t);
|
|
85
|
+
const eps = 1e-4;
|
|
86
|
+
const lin = [m.m11 - 1, m.m12, m.m13, m.m14, m.m21, m.m22 - 1, m.m23, m.m24, m.m31, m.m32, m.m33 - 1, m.m34, m.m44 - 1];
|
|
87
|
+
return lin.every((x) => Math.abs(x) < eps);
|
|
88
|
+
} catch {
|
|
89
|
+
return false;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// Rule 7 (no render-surface effects on a woven canvas or any ancestor) + own-box decoration.
|
|
94
|
+
P.cssAudit = function (canvas) {
|
|
95
|
+
const problems = [];
|
|
96
|
+
const decorations = [];
|
|
97
|
+
const animations = [];
|
|
98
|
+
for (let el = canvas; el && el.nodeType === 1; el = el.parentElement) {
|
|
99
|
+
const cs = getComputedStyle(el);
|
|
100
|
+
const who = el === canvas ? 'the canvas' : `ancestor ${selectorOf(el)}`;
|
|
101
|
+
const push = (prop, val) => problems.push({ element: selectorOf(el), self: el === canvas, prop, value: val, text: `${prop}: ${val} on ${who}` });
|
|
102
|
+
if (cs.filter && cs.filter !== 'none') push('filter', cs.filter);
|
|
103
|
+
if (parseFloat(cs.opacity) < 0.999) push('opacity', cs.opacity);
|
|
104
|
+
const bf = cs.backdropFilter || cs.webkitBackdropFilter;
|
|
105
|
+
if (bf && bf !== 'none') push('backdrop-filter', bf);
|
|
106
|
+
const mask = cs.maskImage || cs.webkitMaskImage;
|
|
107
|
+
if (mask && mask !== 'none') push('mask', mask);
|
|
108
|
+
if (cs.clipPath && cs.clipPath !== 'none') push('clip-path', cs.clipPath);
|
|
109
|
+
if (cs.mixBlendMode && cs.mixBlendMode !== 'normal') push('mix-blend-mode', cs.mixBlendMode);
|
|
110
|
+
if (!isIdentityishTransform(cs.transform)) push('transform', cs.transform);
|
|
111
|
+
if (cs.perspective && cs.perspective !== 'none' && el !== canvas) push('perspective', cs.perspective);
|
|
112
|
+
if (el === canvas) {
|
|
113
|
+
if (parseFloat(cs.borderTopLeftRadius) > 0 || parseFloat(cs.borderBottomRightRadius) > 0) decorations.push(`border-radius: ${cs.borderRadius}`);
|
|
114
|
+
if (cs.boxShadow && cs.boxShadow !== 'none') decorations.push(`box-shadow: ${cs.boxShadow}`);
|
|
115
|
+
const bw = ['Top', 'Right', 'Bottom', 'Left'].map((s) => parseFloat(cs[`border${s}Width`]) || 0);
|
|
116
|
+
if (bw.some((w) => w > 0)) decorations.push(`border: ${bw.join('/')} px`);
|
|
117
|
+
}
|
|
118
|
+
try {
|
|
119
|
+
for (const a of el.getAnimations()) {
|
|
120
|
+
const kf = a.effect && a.effect.getKeyframes ? a.effect.getKeyframes() : [];
|
|
121
|
+
const props = new Set();
|
|
122
|
+
for (const k of kf) for (const p of Object.keys(k)) if (!['offset', 'easing', 'composite', 'computedOffset'].includes(p)) props.add(p);
|
|
123
|
+
if (a.transitionProperty) props.add(a.transitionProperty);
|
|
124
|
+
const moving = [...props].filter((p) => /transform|translate|scale|rotate|opacity|filter|width|height|left|top|right|bottom|inset|clip/i.test(p));
|
|
125
|
+
if (moving.length && a.playState === 'running') animations.push({ element: selectorOf(el), props: moving });
|
|
126
|
+
}
|
|
127
|
+
} catch { /* no getAnimations */ }
|
|
128
|
+
}
|
|
129
|
+
return { problems, decorations, animations };
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
// What paints over the canvas (rule 9 / rule 5): hit-test a grid with pointer-events forced on
|
|
133
|
+
// (a cover with pointer-events:none still paints), walk each hit list from the top down to the
|
|
134
|
+
// canvas, and classify what sits above it.
|
|
135
|
+
function opaqueBox(el) {
|
|
136
|
+
const tag = el.tagName;
|
|
137
|
+
if (tag === 'IMG' || tag === 'VIDEO' || tag === 'CANVAS' || tag === 'svg' || tag === 'IFRAME' || tag === 'PICTURE') return true;
|
|
138
|
+
const cs = getComputedStyle(el);
|
|
139
|
+
if (cs.backgroundImage && cs.backgroundImage !== 'none') return true;
|
|
140
|
+
const m = /rgba?\(([^)]+)\)/.exec(cs.backgroundColor || '');
|
|
141
|
+
if (!m) return false;
|
|
142
|
+
const parts = m[1].split(/[ ,/]+/).filter(Boolean).map(Number);
|
|
143
|
+
const a = parts.length >= 4 ? parts[3] : 1;
|
|
144
|
+
return a >= 0.9;
|
|
145
|
+
}
|
|
146
|
+
P.occlusionAudit = function (canvas, cols = 9, rows = 6) {
|
|
147
|
+
const style = document.createElement('style');
|
|
148
|
+
style.textContent = '*{pointer-events:auto !important}';
|
|
149
|
+
document.documentElement.appendChild(style);
|
|
150
|
+
const r = canvas.getBoundingClientRect();
|
|
151
|
+
const vw = innerWidth, vh = innerHeight;
|
|
152
|
+
let total = 0, opaque = 0, frost = 0, offscreen = 0, chrome = 0;
|
|
153
|
+
const coverers = new Map();
|
|
154
|
+
const effects = new Map(); // overlapping chrome the draw-order split cannot lift as a plain quad
|
|
155
|
+
try {
|
|
156
|
+
for (let j = 0; j < rows; j++) {
|
|
157
|
+
for (let i = 0; i < cols; i++) {
|
|
158
|
+
const x = r.left + ((i + 0.5) / cols) * r.width;
|
|
159
|
+
const y = r.top + ((j + 0.5) / rows) * r.height;
|
|
160
|
+
if (x < 0 || y < 0 || x >= vw || y >= vh) { offscreen++; continue; }
|
|
161
|
+
total++;
|
|
162
|
+
const list = document.elementsFromPoint(x, y);
|
|
163
|
+
let covered = false, frosted = false;
|
|
164
|
+
for (const el of list) {
|
|
165
|
+
if (el === canvas) break;
|
|
166
|
+
if (el.contains(canvas)) continue; // an ancestor paints below its descendants
|
|
167
|
+
const cs = getComputedStyle(el);
|
|
168
|
+
const bf = cs.backdropFilter || cs.webkitBackdropFilter;
|
|
169
|
+
if (bf && bf !== 'none') frosted = true;
|
|
170
|
+
const fx = [];
|
|
171
|
+
if (cs.filter && cs.filter !== 'none') fx.push(`filter: ${cs.filter}`);
|
|
172
|
+
if (cs.mixBlendMode && cs.mixBlendMode !== 'normal') fx.push(`mix-blend-mode: ${cs.mixBlendMode}`);
|
|
173
|
+
if (cs.transformStyle === 'preserve-3d') fx.push('transform-style: preserve-3d');
|
|
174
|
+
if (fx.length) effects.set(selectorOf(el), fx.join(', '));
|
|
175
|
+
if (opaqueBox(el)) {
|
|
176
|
+
covered = true;
|
|
177
|
+
// Page chrome: a fixed/sticky element or one inside it (a header the tile scrolls under).
|
|
178
|
+
for (let a = el; a && a !== document.body; a = a.parentElement) {
|
|
179
|
+
const p = getComputedStyle(a).position;
|
|
180
|
+
if (p === 'fixed' || p === 'sticky') { chrome++; break; }
|
|
181
|
+
}
|
|
182
|
+
const s = selectorOf(el);
|
|
183
|
+
coverers.set(s, (coverers.get(s) || 0) + 1);
|
|
184
|
+
break;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
if (!list.includes(canvas) && !covered) {
|
|
188
|
+
// The canvas is not hit at all here (visibility:hidden, or under a non-opaque box that
|
|
189
|
+
// still swallowed the hit list): treat as covered by whatever is on top.
|
|
190
|
+
const top = list[0];
|
|
191
|
+
if (top && !top.contains(canvas)) {
|
|
192
|
+
covered = true;
|
|
193
|
+
const s = selectorOf(top);
|
|
194
|
+
coverers.set(s, (coverers.get(s) || 0) + 1);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
if (covered) opaque++;
|
|
198
|
+
if (frosted) frost++;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
} finally {
|
|
202
|
+
style.remove();
|
|
203
|
+
}
|
|
204
|
+
const cs = getComputedStyle(canvas);
|
|
205
|
+
return {
|
|
206
|
+
total, opaque, frost, offscreen,
|
|
207
|
+
coveredFraction: total ? opaque / total : 0,
|
|
208
|
+
chromeFraction: total ? chrome / total : 0,
|
|
209
|
+
onScreenFraction: total + offscreen ? total / (total + offscreen) : 0,
|
|
210
|
+
frostFraction: total ? frost / total : 0,
|
|
211
|
+
coverers: [...coverers.entries()].sort((a, b) => b[1] - a[1]).map(([selector, hits]) => ({ selector, hits })),
|
|
212
|
+
effects: [...effects.entries()].map(([selector, props]) => ({ selector, props })),
|
|
213
|
+
visible: r.width > 0 && r.height > 0 && cs.display !== 'none' && cs.visibility !== 'hidden',
|
|
214
|
+
rect: { x: r.left, y: r.top, width: r.width, height: r.height },
|
|
215
|
+
};
|
|
216
|
+
};
|
|
217
|
+
|
|
218
|
+
// Media elements big enough to show a picture (for the "raw side-by-side shown flat" scan).
|
|
219
|
+
P.mediaElements = function (exclude = []) {
|
|
220
|
+
const out = [];
|
|
221
|
+
for (const el of document.querySelectorAll('img, video, canvas')) {
|
|
222
|
+
if (exclude.includes(el)) continue;
|
|
223
|
+
const r = el.getBoundingClientRect();
|
|
224
|
+
if (r.width < 120 || r.height < 60) continue;
|
|
225
|
+
if (r.right <= 0 || r.bottom <= 0 || r.left >= innerWidth || r.top >= innerHeight) continue;
|
|
226
|
+
const cs = getComputedStyle(el);
|
|
227
|
+
if (cs.display === 'none' || cs.visibility === 'hidden' || parseFloat(cs.opacity) === 0) continue;
|
|
228
|
+
out.push({ selector: selectorOf(el), tag: el.tagName.toLowerCase(), rect: { x: r.left, y: r.top, width: r.width, height: r.height } });
|
|
229
|
+
}
|
|
230
|
+
return out;
|
|
231
|
+
};
|
|
232
|
+
|
|
233
|
+
P.bufferInfo = function (canvas) {
|
|
234
|
+
const rec = P.contexts.get(canvas);
|
|
235
|
+
const info = { width: canvas.width, height: canvas.height, contextType: rec ? rec.type : null, drawingBufferWidth: null, drawingBufferHeight: null, maxTextureSize: null, preserveDrawingBuffer: null };
|
|
236
|
+
if (rec && /webgl/.test(rec.type)) {
|
|
237
|
+
const gl = rec.ctx;
|
|
238
|
+
info.drawingBufferWidth = gl.drawingBufferWidth;
|
|
239
|
+
info.drawingBufferHeight = gl.drawingBufferHeight;
|
|
240
|
+
try { info.maxTextureSize = gl.getParameter(gl.MAX_TEXTURE_SIZE); } catch { /* lost */ }
|
|
241
|
+
try { const a = gl.getContextAttributes(); info.preserveDrawingBuffer = a ? a.preserveDrawingBuffer : null; } catch { /* lost */ }
|
|
242
|
+
}
|
|
243
|
+
return info;
|
|
244
|
+
};
|
|
245
|
+
})();
|