xbintsc 0.7.6 → 0.7.7
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/dist/src/binder/references.js +13 -7
- package/dist/src/binder/references.js.map +1 -1
- package/dist/src/cli/help.d.ts +1 -1
- package/dist/src/driver/version.d.ts +1 -1
- package/dist/src/driver/version.js +1 -1
- package/dist/src/extensions/gui/index.js +5 -0
- package/dist/src/extensions/gui/index.js.map +1 -1
- package/dist/tests/binder/binder.test.js +26 -4
- package/dist/tests/binder/binder.test.js.map +1 -1
- package/dist/tests/checker/checker.test.js +16 -0
- package/dist/tests/checker/checker.test.js.map +1 -1
- package/dist/tests/e2e/gui-browser.test.js +31 -0
- package/dist/tests/e2e/gui-browser.test.js.map +1 -1
- package/dist/tests/e2e/gui-events.test.js +89 -0
- package/dist/tests/e2e/gui-events.test.js.map +1 -1
- package/dist/tests/e2e/gui-webgl2-anisotropy.test.d.ts +10 -0
- package/dist/tests/e2e/gui-webgl2-anisotropy.test.js +105 -0
- package/dist/tests/e2e/gui-webgl2-anisotropy.test.js.map +1 -0
- package/dist/tests/e2e/gui-webgl2-sampler-array.test.d.ts +11 -0
- package/dist/tests/e2e/gui-webgl2-sampler-array.test.js +117 -0
- package/dist/tests/e2e/gui-webgl2-sampler-array.test.js.map +1 -0
- package/doc/gui/api.md +9 -0
- package/doc/gui/input.md +8 -0
- package/doc/gui/known-issues.md +8 -0
- package/doc/implemented/binder.md +1 -1
- package/doc/zh-CN/gui/api.md +8 -0
- package/doc/zh-CN/gui/input.md +7 -0
- package/doc/zh-CN/gui/known-issues.md +6 -0
- package/doc/zh-CN/implemented/binder.md +1 -1
- package/package.json +7 -7
- package/runtime/ext_gui/browser.cpp +2 -0
- package/runtime/ext_gui/dom_api.cpp +4 -0
- package/runtime/ext_gui/dom_api_events.cpp +2 -1
- package/runtime/ext_gui/dom_api_internal.h +8 -0
- package/runtime/ext_gui/dom_api_mutation.cpp +49 -0
- package/runtime/ext_gui/dom_api_proto.cpp +3 -0
- package/runtime/ext_gui/dom_api_webgl_state.cpp +7 -0
- package/runtime/ext_gui/gui.cpp +2 -0
- package/runtime/ext_gui/gui_engine.h +18 -2
- package/runtime/ext_gui/gui_events.cpp +18 -118
- package/runtime/ext_gui/gui_input.cpp +148 -0
- package/runtime/ext_gui/pointer_lock.cpp +137 -0
- package/runtime/ext_gui/webgl_buffer.cpp +6 -0
- package/runtime/ext_gui/webgl_context.cpp +2 -0
- package/runtime/ext_gui/webgl_glsl.h +4 -0
- package/runtime/ext_gui/webgl_glsl_scan.cpp +14 -0
- package/runtime/ext_gui/webgl_objects.h +2 -0
- package/runtime/ext_gui/webgl_shader.cpp +1 -1
- package/runtime/ext_gui/window.cpp +3 -83
- package/runtime/ext_gui/window_diagnostics.cpp +94 -1
- package/src/binder/references.ts +13 -7
- package/src/driver/version.ts +1 -1
- package/src/extensions/gui/index.ts +5 -0
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* GUI e2e: `EXT_texture_filter_anisotropic`.
|
|
3
|
+
*
|
|
4
|
+
* three.js asks for the extension and sizes `texture.anisotropy` from
|
|
5
|
+
* `MAX_TEXTURE_MAX_ANISOTROPY_EXT`. Without it every grazing-angle surface
|
|
6
|
+
* (wet ground, walls) falls back to a high mip level and reads as coarse
|
|
7
|
+
* blocks, so the extension, the parameter clamp and sampling are checked
|
|
8
|
+
* here.
|
|
9
|
+
*/
|
|
10
|
+
import { afterAll, beforeAll, describe, expect, it } from "vitest";
|
|
11
|
+
import { createGuiHarness, guiAvailable } from "./gui-helpers.js";
|
|
12
|
+
const harness = createGuiHarness();
|
|
13
|
+
const PAGE = `
|
|
14
|
+
<html><head><title>webgl2-anisotropy</title></head>
|
|
15
|
+
<body style="margin:0">
|
|
16
|
+
<canvas id="c" width="64" height="64"></canvas>
|
|
17
|
+
</body></html>`;
|
|
18
|
+
describe.skipIf(!guiAvailable)("gui extension — anisotropic filtering", () => {
|
|
19
|
+
beforeAll(() => harness.setup());
|
|
20
|
+
afterAll(() => harness.cleanup());
|
|
21
|
+
it("exposes the extension, clamps the parameter and samples", () => {
|
|
22
|
+
const { value } = harness.compileAndRun("webgl2-anisotropy", `
|
|
23
|
+
import { createWindow } from "gui";
|
|
24
|
+
import page from "./page.html";
|
|
25
|
+
|
|
26
|
+
const win = createWindow({ title: "anisotropy", width: 320, height: 240 });
|
|
27
|
+
const label = (name: string, value: any): void => console.log(name + "=" + value);
|
|
28
|
+
|
|
29
|
+
win.on("ready", () => {
|
|
30
|
+
const canvas: any = document.getElementById("c");
|
|
31
|
+
const gl: any = canvas.getContext("webgl2");
|
|
32
|
+
if (gl == null) {
|
|
33
|
+
label("webgl2", false);
|
|
34
|
+
win.close();
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
const ext: any = gl.getExtension("EXT_texture_filter_anisotropic");
|
|
38
|
+
label("extension", ext != null);
|
|
39
|
+
if (ext == null) {
|
|
40
|
+
win.close();
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
label("max", gl.getParameter(ext.MAX_TEXTURE_MAX_ANISOTROPY_EXT));
|
|
44
|
+
label("supported",
|
|
45
|
+
gl.getSupportedExtensions().indexOf("EXT_texture_filter_anisotropic") >= 0);
|
|
46
|
+
|
|
47
|
+
const vs: any = gl.createShader(gl.VERTEX_SHADER);
|
|
48
|
+
gl.shaderSource(vs, "#version 300 es\\n" +
|
|
49
|
+
"in vec2 a_pos; out vec2 v_uv; void main() { v_uv = a_pos * 0.5 + 0.5; gl_Position = vec4(a_pos, 0.0, 1.0); }");
|
|
50
|
+
gl.compileShader(vs);
|
|
51
|
+
const fs: any = gl.createShader(gl.FRAGMENT_SHADER);
|
|
52
|
+
gl.shaderSource(fs, "#version 300 es\\n" +
|
|
53
|
+
"precision highp float; uniform sampler2D u_tex; in vec2 v_uv; out vec4 o;\\n" +
|
|
54
|
+
"void main() { o = texture(u_tex, v_uv); }");
|
|
55
|
+
gl.compileShader(fs);
|
|
56
|
+
const program: any = gl.createProgram();
|
|
57
|
+
gl.attachShader(program, vs);
|
|
58
|
+
gl.attachShader(program, fs);
|
|
59
|
+
gl.linkProgram(program);
|
|
60
|
+
gl.useProgram(program);
|
|
61
|
+
|
|
62
|
+
const texture: any = gl.createTexture();
|
|
63
|
+
gl.activeTexture(gl.TEXTURE0);
|
|
64
|
+
gl.bindTexture(gl.TEXTURE_2D, texture);
|
|
65
|
+
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 1, 1, 0, gl.RGBA, gl.UNSIGNED_BYTE,
|
|
66
|
+
new Uint8Array([0, 255, 0, 255]));
|
|
67
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
|
|
68
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
|
|
69
|
+
gl.texParameterf(gl.TEXTURE_2D, ext.TEXTURE_MAX_ANISOTROPY_EXT, 8);
|
|
70
|
+
label("read8", gl.getTexParameter(gl.TEXTURE_2D, ext.TEXTURE_MAX_ANISOTROPY_EXT));
|
|
71
|
+
gl.texParameterf(gl.TEXTURE_2D, ext.TEXTURE_MAX_ANISOTROPY_EXT, 32);
|
|
72
|
+
label("clampHigh", gl.getTexParameter(gl.TEXTURE_2D, ext.TEXTURE_MAX_ANISOTROPY_EXT));
|
|
73
|
+
gl.texParameterf(gl.TEXTURE_2D, ext.TEXTURE_MAX_ANISOTROPY_EXT, 0);
|
|
74
|
+
label("clampLow", gl.getTexParameter(gl.TEXTURE_2D, ext.TEXTURE_MAX_ANISOTROPY_EXT));
|
|
75
|
+
gl.texParameterf(gl.TEXTURE_2D, ext.TEXTURE_MAX_ANISOTROPY_EXT, 4);
|
|
76
|
+
|
|
77
|
+
gl.uniform1i(gl.getUniformLocation(program, "u_tex"), 0);
|
|
78
|
+
const buffer: any = gl.createBuffer();
|
|
79
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
|
|
80
|
+
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([-1, -1, 3, -1, -1, 3]), gl.STATIC_DRAW);
|
|
81
|
+
const loc: any = gl.getAttribLocation(program, "a_pos");
|
|
82
|
+
gl.enableVertexAttribArray(loc);
|
|
83
|
+
gl.vertexAttribPointer(loc, 2, gl.FLOAT, false, 0, 0);
|
|
84
|
+
gl.viewport(0, 0, 64, 64);
|
|
85
|
+
gl.clearColor(0, 0, 0, 0);
|
|
86
|
+
gl.clear(gl.COLOR_BUFFER_BIT);
|
|
87
|
+
gl.drawArrays(gl.TRIANGLES, 0, 3);
|
|
88
|
+
const px = new Uint8Array(4);
|
|
89
|
+
gl.readPixels(32, 32, 1, 1, gl.RGBA, gl.UNSIGNED_BYTE, px);
|
|
90
|
+
label("pixel", px[0] + "," + px[1] + "," + px[2] + "," + px[3]);
|
|
91
|
+
win.close();
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
win.loadHTML(page);
|
|
95
|
+
`, { files: { "page.html": PAGE } });
|
|
96
|
+
expect(value("extension")).toBe("true");
|
|
97
|
+
expect(value("max")).toBe("16");
|
|
98
|
+
expect(value("supported")).toBe("true");
|
|
99
|
+
expect(value("read8")).toBe("8");
|
|
100
|
+
expect(value("clampHigh")).toBe("16");
|
|
101
|
+
expect(value("clampLow")).toBe("1");
|
|
102
|
+
expect(value("pixel")).toBe("0,255,0,255");
|
|
103
|
+
});
|
|
104
|
+
});
|
|
105
|
+
//# sourceMappingURL=gui-webgl2-anisotropy.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gui-webgl2-anisotropy.test.js","sourceRoot":"","sources":["../../../tests/e2e/gui-webgl2-anisotropy.test.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AACnE,OAAO,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAElE,MAAM,OAAO,GAAG,gBAAgB,EAAE,CAAC;AAEnC,MAAM,IAAI,GAAG;;;;eAIE,CAAC;AAEhB,QAAQ,CAAC,MAAM,CAAC,CAAC,YAAY,CAAC,CAAC,uCAAuC,EAAE,GAAG,EAAE;IAC3E,SAAS,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC,CAAC;IACjC,QAAQ,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC;IAElC,EAAE,CAAC,yDAAyD,EAAE,GAAG,EAAE;QACjE,MAAM,EAAE,KAAK,EAAE,GAAG,OAAO,CAAC,aAAa,CACrC,mBAAmB,EACnB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAyEC,EACD,EAAE,KAAK,EAAE,EAAE,WAAW,EAAE,IAAI,EAAE,EAAE,CACjC,CAAC;QACF,MAAM,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QACxC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAChC,MAAM,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QACxC,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QACjC,MAAM,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACtC,MAAM,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QACpC,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;IAC7C,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* GUI e2e: sampler arrays through the WebGL 2 reflection API.
|
|
3
|
+
*
|
|
4
|
+
* three.js builds its uniform uploaders from `gl.getActiveUniform`: a sampler
|
|
5
|
+
* declared as an array must be reported as `name[0]` with its element count,
|
|
6
|
+
* or three.js treats the array as one texture and binds the array object
|
|
7
|
+
* itself (a shadow map then reads the renderer's empty texture and every lit
|
|
8
|
+
* surface turns black). The declaration size is spelled with a macro, as
|
|
9
|
+
* three.js does for `directionalShadowMap[NUM_DIR_LIGHT_SHADOWS]`.
|
|
10
|
+
*/
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* GUI e2e: sampler arrays through the WebGL 2 reflection API.
|
|
3
|
+
*
|
|
4
|
+
* three.js builds its uniform uploaders from `gl.getActiveUniform`: a sampler
|
|
5
|
+
* declared as an array must be reported as `name[0]` with its element count,
|
|
6
|
+
* or three.js treats the array as one texture and binds the array object
|
|
7
|
+
* itself (a shadow map then reads the renderer's empty texture and every lit
|
|
8
|
+
* surface turns black). The declaration size is spelled with a macro, as
|
|
9
|
+
* three.js does for `directionalShadowMap[NUM_DIR_LIGHT_SHADOWS]`.
|
|
10
|
+
*/
|
|
11
|
+
import { afterAll, beforeAll, describe, expect, it } from "vitest";
|
|
12
|
+
import { createGuiHarness, guiAvailable } from "./gui-helpers.js";
|
|
13
|
+
const harness = createGuiHarness();
|
|
14
|
+
const PAGE = `
|
|
15
|
+
<html><head><title>webgl2-sampler-array</title></head>
|
|
16
|
+
<body style="margin:0">
|
|
17
|
+
<canvas id="c" width="64" height="64"></canvas>
|
|
18
|
+
</body></html>`;
|
|
19
|
+
describe.skipIf(!guiAvailable)("gui extension — sampler arrays and reflection", () => {
|
|
20
|
+
beforeAll(() => harness.setup());
|
|
21
|
+
afterAll(() => harness.cleanup());
|
|
22
|
+
it("reports array names/sizes and samples each element", () => {
|
|
23
|
+
const { value } = harness.compileAndRun("webgl2-sampler-array", `
|
|
24
|
+
import { createWindow } from "gui";
|
|
25
|
+
import page from "./page.html";
|
|
26
|
+
|
|
27
|
+
const win = createWindow({ title: "sampler-array", width: 320, height: 240 });
|
|
28
|
+
const label = (name: string, value: any): void => console.log(name + "=" + value);
|
|
29
|
+
|
|
30
|
+
win.on("ready", () => {
|
|
31
|
+
const canvas: any = document.getElementById("c");
|
|
32
|
+
const gl: any = canvas.getContext("webgl2");
|
|
33
|
+
if (gl == null) {
|
|
34
|
+
label("webgl2", false);
|
|
35
|
+
win.close();
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
const vs: any = gl.createShader(gl.VERTEX_SHADER);
|
|
39
|
+
gl.shaderSource(vs, "#version 300 es\\n" +
|
|
40
|
+
"in vec2 a_pos; out vec2 v_uv;\\n" +
|
|
41
|
+
"void main() { v_uv = a_pos * 0.5 + 0.5; gl_Position = vec4(a_pos, 0.0, 1.0); }");
|
|
42
|
+
gl.compileShader(vs);
|
|
43
|
+
const fs: any = gl.createShader(gl.FRAGMENT_SHADER);
|
|
44
|
+
gl.shaderSource(fs, "#version 300 es\\n" +
|
|
45
|
+
"precision highp float;\\n" +
|
|
46
|
+
"#define MAP_COUNT 1\\n" +
|
|
47
|
+
"uniform sampler2D u_literal[1];\\n" +
|
|
48
|
+
"uniform sampler2D u_macro[1];\\n" +
|
|
49
|
+
"in vec2 v_uv; out vec4 fragColor;\\n" +
|
|
50
|
+
"void main() {\\n" +
|
|
51
|
+
" fragColor = vec4(texture(u_literal[0], v_uv).r, texture(u_macro[0], v_uv).g, 0.0, 1.0);\\n" +
|
|
52
|
+
"}");
|
|
53
|
+
gl.compileShader(fs);
|
|
54
|
+
const program: any = gl.createProgram();
|
|
55
|
+
gl.attachShader(program, vs);
|
|
56
|
+
gl.attachShader(program, fs);
|
|
57
|
+
gl.linkProgram(program);
|
|
58
|
+
label("linked", gl.getProgramParameter(program, gl.LINK_STATUS));
|
|
59
|
+
gl.useProgram(program);
|
|
60
|
+
|
|
61
|
+
const count: number = gl.getProgramParameter(program, gl.ACTIVE_UNIFORMS);
|
|
62
|
+
let macroName = "";
|
|
63
|
+
let macroSize = 0;
|
|
64
|
+
for (let i = 0; i < count; i++) {
|
|
65
|
+
const info: any = gl.getActiveUniform(program, i);
|
|
66
|
+
if (info != null && info.name.indexOf("u_macro") === 0) {
|
|
67
|
+
macroName = info.name;
|
|
68
|
+
macroSize = info.size;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
label("macro-name", macroName);
|
|
72
|
+
label("macro-size", macroSize);
|
|
73
|
+
label("macro-location", gl.getUniformLocation(program, "u_macro[0]") != null);
|
|
74
|
+
|
|
75
|
+
const make = (rgba: number[]): any => {
|
|
76
|
+
const texture: any = gl.createTexture();
|
|
77
|
+
gl.activeTexture(gl.TEXTURE0);
|
|
78
|
+
gl.bindTexture(gl.TEXTURE_2D, texture);
|
|
79
|
+
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 1, 1, 0, gl.RGBA, gl.UNSIGNED_BYTE,
|
|
80
|
+
new Uint8Array(rgba));
|
|
81
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
|
|
82
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
|
|
83
|
+
return texture;
|
|
84
|
+
};
|
|
85
|
+
const green: any = make([0, 255, 0, 255]);
|
|
86
|
+
|
|
87
|
+
gl.activeTexture(gl.TEXTURE0);
|
|
88
|
+
gl.bindTexture(gl.TEXTURE_2D, green);
|
|
89
|
+
gl.uniform1iv(gl.getUniformLocation(program, "u_macro[0]"), [0]);
|
|
90
|
+
|
|
91
|
+
const buffer: any = gl.createBuffer();
|
|
92
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
|
|
93
|
+
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([-1, -1, 3, -1, -1, 3]), gl.STATIC_DRAW);
|
|
94
|
+
const loc: any = gl.getAttribLocation(program, "a_pos");
|
|
95
|
+
gl.enableVertexAttribArray(loc);
|
|
96
|
+
gl.vertexAttribPointer(loc, 2, gl.FLOAT, false, 0, 0);
|
|
97
|
+
gl.viewport(0, 0, 64, 64);
|
|
98
|
+
gl.clearColor(0, 0, 0, 0);
|
|
99
|
+
gl.clear(gl.COLOR_BUFFER_BIT);
|
|
100
|
+
gl.drawArrays(gl.TRIANGLES, 0, 3);
|
|
101
|
+
|
|
102
|
+
const px = new Uint8Array(4);
|
|
103
|
+
gl.readPixels(32, 32, 1, 1, gl.RGBA, gl.UNSIGNED_BYTE, px);
|
|
104
|
+
label("pixel", px[0] + "," + px[1] + "," + px[2] + "," + px[3]);
|
|
105
|
+
win.close();
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
win.loadHTML(page);
|
|
109
|
+
`, { files: { "page.html": PAGE } });
|
|
110
|
+
expect(value("linked")).toBe("true");
|
|
111
|
+
expect(value("macro-name")).toBe("u_macro[0]");
|
|
112
|
+
expect(value("macro-size")).toBe("1");
|
|
113
|
+
expect(value("macro-location")).toBe("true");
|
|
114
|
+
expect(value("pixel")).toBe("0,255,0,255");
|
|
115
|
+
});
|
|
116
|
+
});
|
|
117
|
+
//# sourceMappingURL=gui-webgl2-sampler-array.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gui-webgl2-sampler-array.test.js","sourceRoot":"","sources":["../../../tests/e2e/gui-webgl2-sampler-array.test.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AACnE,OAAO,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAElE,MAAM,OAAO,GAAG,gBAAgB,EAAE,CAAC;AAEnC,MAAM,IAAI,GAAG;;;;eAIE,CAAC;AAEhB,QAAQ,CAAC,MAAM,CAAC,CAAC,YAAY,CAAC,CAAC,+CAA+C,EAAE,GAAG,EAAE;IACnF,SAAS,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC,CAAC;IACjC,QAAQ,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC;IAElC,EAAE,CAAC,oDAAoD,EAAE,GAAG,EAAE;QAC5D,MAAM,EAAE,KAAK,EAAE,GAAG,OAAO,CAAC,aAAa,CACrC,sBAAsB,EACtB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAsFC,EACD,EAAE,KAAK,EAAE,EAAE,WAAW,EAAE,IAAI,EAAE,EAAE,CACjC,CAAC;QACF,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QACrC,MAAM,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;QAC/C,MAAM,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QACtC,MAAM,CAAC,KAAK,CAAC,gBAAgB,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAC7C,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;IAC7C,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
package/doc/gui/api.md
CHANGED
|
@@ -49,6 +49,13 @@ and hit testing follow it), and `scrollX` / `scrollY` / `pageXOffset` /
|
|
|
49
49
|
`compositionstart` / `compositionupdate` / `compositionend`, `beforeinput`,
|
|
50
50
|
`input`, `change`, `submit` and `reset`.
|
|
51
51
|
|
|
52
|
+
Pointer Lock is implemented through SDL's relative mouse mode:
|
|
53
|
+
`element.requestPointerLock()` returns a promise that resolves once the lock is
|
|
54
|
+
active (and `pointerlockchange` has fired), `document.pointerLockElement` is the
|
|
55
|
+
locked element, `document.exitPointerLock()` releases it, and a request the host
|
|
56
|
+
cannot honour rejects and fires `pointerlockerror`. `Escape` and losing window
|
|
57
|
+
focus release the lock.
|
|
58
|
+
|
|
52
59
|
Exceptions thrown by code the engine invokes (an element or window listener, a
|
|
53
60
|
timer, an animation frame, a media event) are page errors, not process
|
|
54
61
|
termination: the engine catches them at its callback boundary and mirrors the
|
|
@@ -112,6 +119,7 @@ requestAnimationFrame(frame);
|
|
|
112
119
|
| `fetch(input, init)` | the core runtime's HTTP/1.1 client, available to GUI programs too: `http://` and `https://` (the latter links the optional `tls` feature), plus local `file://` and relative paths; responses are buffered. See [Implemented fetch](../implemented/fetch.md). |
|
|
113
120
|
| `Event`, `CustomEvent`, `ProgressEvent`, `MouseEvent`, `KeyboardEvent`, `PointerEvent`, `WheelEvent`, `FocusEvent`, `InputEvent`, `SubmitEvent` | event constructors; the `init` argument is kept as given (`detail`, `composed`, mouse/keyboard fields, …) |
|
|
114
121
|
| `AbortController`, `AbortSignal` | a real controller/signal pair for `{ signal }` listener removal, with `abort()`, `aborted`, `reason`, `onabort` and `throwIfAborted()` |
|
|
122
|
+
| `MutationObserver` | a real constructor whose observers are **inert**: `observe(target, options)`, `disconnect()` and `takeRecords()` (always `[]`) exist, but no record is ever queued and the callback never fires. Bundlers install one unconditionally — Vite's `modulepreload` polyfill calls `new MutationObserver(…).observe(document, …)` before the page runs — so the name and the methods have to exist or the whole script aborts with a `TypeError` (see [Known issues](./known-issues.md)) |
|
|
115
123
|
| `HTMLCanvasElement`, `HTMLImageElement`, `WebGLRenderingContext`, `WebGL2RenderingContext`, `WebGLBuffer`/`WebGLTexture`/`WebGLShader`/`WebGLProgram`/`WebGLFramebuffer`/`WebGLRenderbuffer`/`WebGLUniformLocation`/`WebGLActiveInfo`/`WebGLVertexArrayObject`/`WebGLSampler`/`WebGLQuery`/`WebGLSync`/`WebGLTransformFeedback` | real constructor values. `canvas.getContext("webgl")` and `getContext("webgl2")` return GPU contexts (see [WebGL](./webgl.md)). |
|
|
116
124
|
| `ImageBitmap`, `createImageBitmap(source)` | immutable bitmaps backed by decoded pixels (`<img>`, `<canvas>`, `<video>` frames, `OffscreenCanvas` and `ImageData` shapes); the promise resolves immediately and `texImage2D` accepts the result |
|
|
117
125
|
| `OffscreenCanvas` | a real 2D offscreen bitmap with `getContext("2d")`, `width`/`height`, `transferToImageBitmap()` and `convertToBlob()`; `canvas.transferControlToOffscreen()` hands an element's bitmap over (see [Canvas](./canvas.md)). There is no offscreen WebGL context. |
|
|
@@ -216,6 +224,7 @@ bubbles from the focused element or `<body>`, before the window listeners run.
|
|
|
216
224
|
| Field | Events | Meaning |
|
|
217
225
|
| --- | --- | --- |
|
|
218
226
|
| `x`, `y` / `clientX`, `clientY` | pointer, wheel | viewport-relative logical pixels |
|
|
227
|
+
| `movementX`, `movementY` | pointer | raw motion since the previous event (pointer-lock aiming); `0` on button events |
|
|
219
228
|
| `button` | pointer | `0` left, `1` middle, `2` right (`-1` for move) |
|
|
220
229
|
| `clicks` | pointer | click count reported by the OS |
|
|
221
230
|
| `deltaX`, `deltaY` | wheel | scroll amount (`deltaY` positive = down) |
|
package/doc/gui/input.md
CHANGED
|
@@ -14,6 +14,14 @@ follows the artwork, not the box flow left behind.
|
|
|
14
14
|
- SDL pointer/wheel/key events are routed to the owning window, hit tested, and
|
|
15
15
|
delivered to the handlers registered with `on`. `mousedown` also moves focus
|
|
16
16
|
and places the caret in a text field.
|
|
17
|
+
- Pointer Lock is the browser API: `element.requestPointerLock()` (a promise),
|
|
18
|
+
`document.pointerLockElement`, `document.exitPointerLock()` and the
|
|
19
|
+
`pointerlockchange` / `pointerlockerror` events on `document` and `window`.
|
|
20
|
+
While locked, SDL runs in relative mouse mode (the cursor is hidden and
|
|
21
|
+
captured): `mousemove` targets the locked element, skips hit testing and
|
|
22
|
+
`:hover`, and carries the raw delta in `movementX`/`movementY`, so a
|
|
23
|
+
first-person game aims from `e.movementX` instead of the cursor position.
|
|
24
|
+
`Escape` and losing window focus release the lock, as in a browser.
|
|
17
25
|
- Keyboard events also follow the DOM path: the target is the focused element (or
|
|
18
26
|
`<body>` when nothing is focused), the event bubbles through its ancestors to
|
|
19
27
|
`document`, and finally reaches `window` listeners. This is what lets a page
|
package/doc/gui/known-issues.md
CHANGED
|
@@ -5,6 +5,14 @@
|
|
|
5
5
|
|
|
6
6
|
## Known issues
|
|
7
7
|
|
|
8
|
+
- **`MutationObserver` exists but is inert.** The constructor and `observe` /
|
|
9
|
+
`disconnect` / `takeRecords` are real, yet the engine queues no mutation
|
|
10
|
+
records and never calls the callback, so code that *waits* for records
|
|
11
|
+
(lazy hydration keyed on inserted nodes, `innerHTML` post-processing, …) gets
|
|
12
|
+
nothing. The shape still matters: bundlers install an observer
|
|
13
|
+
unconditionally — Vite's `modulepreload` polyfill runs
|
|
14
|
+
`new MutationObserver(…).observe(document, …)` as the page starts — and a
|
|
15
|
+
`TypeError` there aborts the whole script, which is why the name must resolve.
|
|
8
16
|
- **Web Audio has no `MediaStream`/capture pipeline, and two node behaviours are
|
|
9
17
|
approximations.** `createMediaElementSource` and `createMediaStreamSource`
|
|
10
18
|
return valid, *silent* nodes: the engine has no microphone/camera capture and
|
|
@@ -8,7 +8,7 @@ Location: `src/binder/binder.ts`
|
|
|
8
8
|
- Symbol kinds: `var` / `let` / `const` / `function` / `parameter` / `class` / `interface` / `type` / `enum` / `import` / `namespace`
|
|
9
9
|
- `var` and function declarations hoist to the function scope; `let` / `const` stay block-scoped. A `var` written inside a nested block or in a `for` head reuses that one hoisted symbol, so `{ var x = 1 }` is visible (and assignable) after the block
|
|
10
10
|
- A destructuring *parameter* pre-declares its names and then binds the default values nested inside the pattern, so `({ a = () => 1 }) => a()` gets a function of its own
|
|
11
|
-
- A `switch` body is
|
|
11
|
+
- A `switch` body is a block scope of its own (a child of the enclosing one) shared by every `case` / `default` clause: their declarations are pre-declared before any clause is bound, so a clause-level `let` / `const` shadows an outer binding instead of colliding with it (`function f(t) { switch (…) { case 1: let t = 0 } }` is legal)
|
|
12
12
|
- A `static { ... }` class block is bound as a hidden static function of the class (see [Classes](../unimplemented/classes.md))
|
|
13
13
|
- Identifier → declaration resolution; unresolved identifier collection (`CannotFindName`)
|
|
14
14
|
- Closure capture analysis: outer variables referenced by an inner function are marked `captured` / `boxed`, and capture indices are threaded through intermediate closures
|
package/doc/zh-CN/gui/api.md
CHANGED
|
@@ -47,6 +47,12 @@ API 编写的文档可以原样运行。
|
|
|
47
47
|
`compositionstart` / `compositionupdate` / `compositionend`、`beforeinput`、
|
|
48
48
|
`input`、`change`、`submit` 与 `reset`。
|
|
49
49
|
|
|
50
|
+
指针锁定通过 SDL 的相对鼠标模式实现:`element.requestPointerLock()` 返回
|
|
51
|
+
Promise,在锁定生效(并已触发 `pointerlockchange`)后 resolve;
|
|
52
|
+
`document.pointerLockElement` 是被锁定元素,`document.exitPointerLock()` 释放
|
|
53
|
+
锁定;宿主无法满足的请求会 reject 并触发 `pointerlockerror`。按下 `Escape` 或
|
|
54
|
+
窗口失焦会释放锁定。
|
|
55
|
+
|
|
50
56
|
由引擎调用的代码(元素/窗口监听器、定时器、动画帧、媒体事件)抛出的异常会被
|
|
51
57
|
当作页面错误,而不是终止进程:引擎在回调边界捕获它,并对齐浏览器接口。
|
|
52
58
|
`window.onerror` 收到 `(message, source, line, column, error)`,
|
|
@@ -105,6 +111,7 @@ requestAnimationFrame(frame);
|
|
|
105
111
|
| `fetch(input, init)` | 核心运行时的 HTTP/1.1 客户端,GUI 程序同样可用:支持 `http://` 与 `https://`(后者链接可选的 `tls` 特性)、本地 `file://` 与相对路径;响应整体缓冲。见[已实现的 fetch](../../implemented/fetch.md)。 |
|
|
106
112
|
| `Event`、`CustomEvent`、`ProgressEvent`、`MouseEvent`、`KeyboardEvent`、`PointerEvent`、`WheelEvent`、`FocusEvent`、`InputEvent`、`SubmitEvent` | 事件构造器;`init` 参数按原样保留(`detail`、`composed`、鼠标/键盘字段等) |
|
|
107
113
|
| `AbortController`、`AbortSignal` | 真实的 controller/signal 对,用于 `{ signal }` 移除监听器,支持 `abort()`、`aborted`、`reason`、`onabort` 与 `throwIfAborted()` |
|
|
114
|
+
| `MutationObserver` | 真实的构造器,但观察者是**惰性**的:`observe(target, options)`、`disconnect()`、`takeRecords()`(始终返回 `[]`)都存在,只是引擎不排队任何变更记录,回调永远不会触发。打包器会无条件装上它——Vite 的 `modulepreload` polyfill 在页面启动前就执行 `new MutationObserver(…).observe(document, …)`——名字或方法缺失会让整个脚本以 `TypeError` 中止(见[已知问题](./known-issues.md)) |
|
|
108
115
|
| `HTMLCanvasElement`、`HTMLImageElement`、`WebGLRenderingContext`、`WebGL2RenderingContext`、`WebGLBuffer`/`WebGLTexture`/`WebGLShader`/`WebGLProgram`/`WebGLFramebuffer`/`WebGLRenderbuffer`/`WebGLUniformLocation`/`WebGLActiveInfo`/`WebGLVertexArrayObject`/`WebGLSampler`/`WebGLQuery`/`WebGLSync`/`WebGLTransformFeedback` | 真实的构造函数值。`canvas.getContext("webgl")` 与 `getContext("webgl2")` 返回 GPU 上下文(见 [WebGL](./webgl.md))。 |
|
|
109
116
|
| `ImageBitmap`、`createImageBitmap(source)` | 由已解码像素支撑的不可变位图(`<img>`、`<canvas>`、`<video>` 帧、`OffscreenCanvas` 与 `ImageData` 形状);promise 立即 settle,`texImage2D` 可直接接受该对象 |
|
|
110
117
|
| `OffscreenCanvas` | 真正的 2D 离屏位图,带 `getContext("2d")`、`width`/`height`、`transferToImageBitmap()` 与 `convertToBlob()`;`canvas.transferControlToOffscreen()` 会把元素位图交给它(见 [Canvas](./canvas.md))。离屏 WebGL 上下文不提供。 |
|
|
@@ -192,6 +199,7 @@ win.on("keydown", (e) => console.log(e.key, e.code, e.ctrlKey, e.shiftKey));
|
|
|
192
199
|
| 字段 | 事件 | 含义 |
|
|
193
200
|
| --- | --- | --- |
|
|
194
201
|
| `x`、`y` / `clientX`、`clientY` | pointer、wheel | 相对于视口的逻辑像素 |
|
|
202
|
+
| `movementX`、`movementY` | pointer | 距上一次事件的原始位移(指针锁定瞄准用);按键事件为 `0` |
|
|
195
203
|
| `button` | pointer | `0` 左键、`1` 中键、`2` 右键(移动时为 `-1`) |
|
|
196
204
|
| `clicks` | pointer | 操作系统报告的点击次数 |
|
|
197
205
|
| `deltaX`、`deltaY` | wheel | 滚动量(`deltaY` 为正表示向下) |
|
package/doc/zh-CN/gui/input.md
CHANGED
|
@@ -12,6 +12,13 @@
|
|
|
12
12
|
|
|
13
13
|
- SDL 指针/滚轮/键盘事件会被路由到所属窗口,进行命中测试,并投递给用 `on`
|
|
14
14
|
注册的处理器。`mousedown` 还会移动焦点,并在文本框中放置光标。
|
|
15
|
+
- 指针锁定(Pointer Lock)遵循浏览器 API:`element.requestPointerLock()`(返回
|
|
16
|
+
Promise)、`document.pointerLockElement`、`document.exitPointerLock()`,以及
|
|
17
|
+
`document` 与 `window` 上的 `pointerlockchange`/`pointerlockerror` 事件。锁定时
|
|
18
|
+
SDL 进入相对鼠标模式(隐藏并捕获光标):`mousemove` 以被锁定元素为目标、跳过
|
|
19
|
+
命中测试与 `:hover`,并在 `movementX`/`movementY` 中携带原始位移,因此第一人称
|
|
20
|
+
游戏用 `e.movementX` 而不是光标坐标来瞄准。按下 `Escape` 或窗口失焦会释放锁定,
|
|
21
|
+
与浏览器一致。
|
|
15
22
|
- 键盘事件同时走 DOM 路径:目标为聚焦元素(没有焦点时为 `<body>`),事件沿祖先
|
|
16
23
|
冒泡到 `document`,最后到达 `window` 监听器。因此按浏览器写的
|
|
17
24
|
`document.addEventListener("keydown", …)` 可以直接工作。负载使用浏览器
|
|
@@ -6,6 +6,12 @@
|
|
|
6
6
|
|
|
7
7
|
## 已知问题
|
|
8
8
|
|
|
9
|
+
- **`MutationObserver` 存在但惰性。** 构造器与 `observe` / `disconnect` /
|
|
10
|
+
`takeRecords` 都是真的,但引擎不排队任何变更记录、也从不调用回调,因此*等待*记录的代码
|
|
11
|
+
(按插入节点触发的惰性 hydration、`innerHTML` 后处理等)什么也拿不到。但这个形状仍然重要:
|
|
12
|
+
打包器会无条件装上观察者——Vite 的 `modulepreload` polyfill 在页面启动时就执行
|
|
13
|
+
`new MutationObserver(…).observe(document, …)`——那里的 `TypeError` 会中止整个脚本,
|
|
14
|
+
所以名字必须能解析。
|
|
9
15
|
- **Web Audio 没有 `MediaStream`/采集管线,且两个节点的行为是近似实现。**
|
|
10
16
|
`createMediaElementSource` 与 `createMediaStreamSource` 返回合法但**静音**的节点:引擎没有
|
|
11
17
|
麦克风/摄像头采集,也不会把媒体元素自身的播放接入音频图,因此页面把二者接入图里得到的是静音,
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
- 符号种类:`var` / `let` / `const` / `function` / `parameter` / `class` / `interface` / `type` / `enum` / `import` / `namespace`
|
|
9
9
|
- `var` 与函数声明提升到函数作用域;`let` / `const` 保持块作用域。写在嵌套块内或 `for` 头部的 `var` 复用同一个提升符号,因此 `{ var x = 1 }` 在块之后依然可见(可赋值)
|
|
10
10
|
- 解构**参数**先声明其名字,再绑定模式内部的默认值,因此 `({ a = () => 1 }) => a()` 中的箭头函数能拿到自己的函数信息
|
|
11
|
-
- `switch`
|
|
11
|
+
- `switch` 主体是自成一级的块作用域(外层作用域的子作用域),由所有 `case` / `default` 子句共享:子句中的声明会在绑定任意子句之前预先声明,因此子句里直接写的 `let` / `const` 会遮蔽外层绑定而不是与之冲突(`function f(t) { switch (…) { case 1: let t = 0 } }` 合法)
|
|
12
12
|
- `static { ... }` 类静态块绑定为类的隐藏静态函数(见[类与面向对象](../unimplemented/classes.md))
|
|
13
13
|
- 标识符 → 声明 的解析;未解析标识符收集(`CannotFindName`)
|
|
14
14
|
- 闭包捕获分析:被内层函数引用的外部变量标记 `captured` / `boxed`,并穿过中间闭包传递捕获索引
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "xbintsc",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.7",
|
|
4
4
|
"description": "xbintsc - a TypeScript binary compiler (TypeScript -> LLVM IR -> native binary)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -81,12 +81,12 @@
|
|
|
81
81
|
"vitest": "^2.1.8"
|
|
82
82
|
},
|
|
83
83
|
"optionalDependencies": {
|
|
84
|
-
"@xbintsc/linux-x64": "0.7.
|
|
85
|
-
"@xbintsc/linux-arm64": "0.7.
|
|
86
|
-
"@xbintsc/darwin-x64": "0.7.
|
|
87
|
-
"@xbintsc/darwin-arm64": "0.7.
|
|
88
|
-
"@xbintsc/win32-x64": "0.7.
|
|
89
|
-
"@xbintsc/win32-arm64": "0.7.
|
|
84
|
+
"@xbintsc/linux-x64": "0.7.7",
|
|
85
|
+
"@xbintsc/linux-arm64": "0.7.7",
|
|
86
|
+
"@xbintsc/darwin-x64": "0.7.7",
|
|
87
|
+
"@xbintsc/darwin-arm64": "0.7.7",
|
|
88
|
+
"@xbintsc/win32-x64": "0.7.7",
|
|
89
|
+
"@xbintsc/win32-arm64": "0.7.7"
|
|
90
90
|
},
|
|
91
91
|
"engines": {
|
|
92
92
|
"node": ">=22"
|
|
@@ -328,6 +328,7 @@ xt_value host_type_construct(xt_value self, xt_value env, int32_t argc, xt_value
|
|
|
328
328
|
xt_value type_proto(const std::string &name) {
|
|
329
329
|
if (name == "AbortController") return domapi::abort_controller_proto();
|
|
330
330
|
if (name == "AbortSignal") return domapi::abort_signal_proto();
|
|
331
|
+
if (name == "MutationObserver") return domapi::mutation_observer_proto();
|
|
331
332
|
if (name == "Event" || name == "CustomEvent" || name == "ProgressEvent" ||
|
|
332
333
|
name == "UIEvent" || name == "MouseEvent" || name == "PointerEvent" ||
|
|
333
334
|
name == "WheelEvent" || name == "KeyboardEvent" || name == "FocusEvent" ||
|
|
@@ -426,6 +427,7 @@ void install_window_globals(xt_value win) {
|
|
|
426
427
|
set_prop(win, "Audio", type_value("Audio"));
|
|
427
428
|
set_prop(win, "Event", type_value("Event"));
|
|
428
429
|
set_prop(win, "CustomEvent", type_value("CustomEvent"));
|
|
430
|
+
set_prop(win, "MutationObserver", type_value("MutationObserver"));
|
|
429
431
|
set_prop(win, "WebGLRenderingContext", type_value("WebGLRenderingContext"));
|
|
430
432
|
set_prop(win, "WebGL2RenderingContext", type_value("WebGL2RenderingContext"));
|
|
431
433
|
set_prop(win, "isSecureContext", XT_TRUE);
|
|
@@ -198,6 +198,10 @@ xt_value xt_gui_node_handle(XtGuiWindow *win, const xtgui::Node *node) {
|
|
|
198
198
|
|
|
199
199
|
void xt_gui_node_handle_forget(XtGuiWindow *win, const xtgui::Node *node) {
|
|
200
200
|
if (win == nullptr || node == nullptr) return;
|
|
201
|
+
/* Removing the locked element ends the Pointer Lock, as in the DOM. Release
|
|
202
|
+
* silently here: the removal is mid-mutation, so running page code for a
|
|
203
|
+
* `pointerlockchange` now could re-enter the tree being torn down. */
|
|
204
|
+
if (win->pointer_lock_node == node) xt_gui_pointer_lock_release(win);
|
|
201
205
|
/* The node is about to be destroyed (a removal, or `innerHTML = …` dropping
|
|
202
206
|
* the old children). Drop its slot as well as its handle: the slot is what
|
|
203
207
|
* `resolve_node` reads, and leaving a freed pointer there is a
|
|
@@ -26,7 +26,8 @@ static xt_value make_dom_event(XtGuiWindow *win, const char *type, const xtgui::
|
|
|
26
26
|
xt_object_set(event, xt_string_from_cstr("timeStamp"), xt_number((double)SDL_GetTicks()));
|
|
27
27
|
if (XT_IS_OBJECT(legacy)) {
|
|
28
28
|
static const char *const fields[] = {
|
|
29
|
-
"x", "y", "clientX", "clientY", "
|
|
29
|
+
"x", "y", "clientX", "clientY", "movementX", "movementY",
|
|
30
|
+
"button", "clicks",
|
|
30
31
|
"deltaX", "deltaY", "key", "code", "repeat", "ctrl",
|
|
31
32
|
"shift", "alt", "meta", "ctrlKey", "shiftKey", "altKey",
|
|
32
33
|
"metaKey", "data", "inputType", "isComposing", "value", "charCode",
|
|
@@ -78,6 +78,10 @@ xt_value abort_controller_proto();
|
|
|
78
78
|
xt_value abort_signal_proto();
|
|
79
79
|
xt_value abort_controller_new();
|
|
80
80
|
xt_value abort_signal_new(bool aborted);
|
|
81
|
+
/** `MutationObserver.prototype`: an inert observer (`observe` / `disconnect` /
|
|
82
|
+
* `takeRecords` exist, no callback ever fires). The constructor itself is the
|
|
83
|
+
* generic host type, so `new MutationObserver(…)` needs no runtime entry. */
|
|
84
|
+
xt_value mutation_observer_proto();
|
|
81
85
|
/** The prototype a WebGL object of `kind` inherits (`buffer`, `texture`, …),
|
|
82
86
|
* so `buffer instanceof WebGLBuffer` holds. */
|
|
83
87
|
xt_value webgl_object_proto(const std::string &kind);
|
|
@@ -165,6 +169,9 @@ METHOD(doc_body_get);
|
|
|
165
169
|
METHOD(doc_head_get);
|
|
166
170
|
METHOD(doc_document_element_get);
|
|
167
171
|
METHOD(doc_active_element_get);
|
|
172
|
+
/* Pointer Lock (`pointer_lock.cpp`). */
|
|
173
|
+
METHOD(doc_exit_pointer_lock);
|
|
174
|
+
METHOD(doc_pointer_lock_element_get);
|
|
168
175
|
|
|
169
176
|
/* node getters */
|
|
170
177
|
METHOD(node_tag_name_get);
|
|
@@ -269,6 +276,7 @@ METHOD(node_click);
|
|
|
269
276
|
METHOD(node_add_event_listener);
|
|
270
277
|
METHOD(node_remove_event_listener);
|
|
271
278
|
METHOD(node_dispatch_event);
|
|
279
|
+
METHOD(node_request_pointer_lock);
|
|
272
280
|
|
|
273
281
|
/* event construction (a detached `Event`/`CustomEvent` handle) */
|
|
274
282
|
xt_value event_construct(xt_value type, xt_value init);
|
|
@@ -154,6 +154,55 @@ METHOD(node_insert_adjacent_html) {
|
|
|
154
154
|
return XT_UNDEFINED;
|
|
155
155
|
}
|
|
156
156
|
|
|
157
|
+
/* -- MutationObserver ----------------------------------------------------- */
|
|
158
|
+
|
|
159
|
+
/* The engine keeps no mutation queue to report on, so an observer is *inert*:
|
|
160
|
+
* `observe` records nothing and the callback never fires (see
|
|
161
|
+
* doc/gui/known-issues.md). It exists as a real constructor because pages and
|
|
162
|
+
* bundlers build one unconditionally — Vite's `modulepreload` polyfill does
|
|
163
|
+
* `new MutationObserver(…).observe(document, …)` before the page runs — and a
|
|
164
|
+
* `TypeError` there aborts the whole script. Code that only *installs* an
|
|
165
|
+
* observer therefore runs unchanged; code that waits for records has nothing
|
|
166
|
+
* to receive yet. */
|
|
167
|
+
|
|
168
|
+
METHOD(observer_observe) {
|
|
169
|
+
(void)self;
|
|
170
|
+
(void)env;
|
|
171
|
+
(void)argc;
|
|
172
|
+
(void)argv;
|
|
173
|
+
return XT_UNDEFINED;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
METHOD(observer_disconnect) {
|
|
177
|
+
(void)self;
|
|
178
|
+
(void)env;
|
|
179
|
+
(void)argc;
|
|
180
|
+
(void)argv;
|
|
181
|
+
return XT_UNDEFINED;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/** `takeRecords()`: an inert observer has no queued records. */
|
|
185
|
+
METHOD(observer_take_records) {
|
|
186
|
+
(void)argc;
|
|
187
|
+
(void)argv;
|
|
188
|
+
(void)env;
|
|
189
|
+
return xt_array_new(0, nullptr);
|
|
190
|
+
}
|
|
191
|
+
|
|
157
192
|
#undef METHOD
|
|
158
193
|
|
|
194
|
+
xt_value mutation_observer_proto() {
|
|
195
|
+
static xt_value proto = XT_UNDEFINED;
|
|
196
|
+
if (XT_IS_OBJECT(proto)) return proto;
|
|
197
|
+
proto = xt_object_new();
|
|
198
|
+
xt_gc_add_root(&proto);
|
|
199
|
+
xt_object_set(proto, xt_string_from_cstr("observe"),
|
|
200
|
+
xt_closure_new((void *)observer_observe, 0, nullptr));
|
|
201
|
+
xt_object_set(proto, xt_string_from_cstr("disconnect"),
|
|
202
|
+
xt_closure_new((void *)observer_disconnect, 0, nullptr));
|
|
203
|
+
xt_object_set(proto, xt_string_from_cstr("takeRecords"),
|
|
204
|
+
xt_closure_new((void *)observer_take_records, 0, nullptr));
|
|
205
|
+
return proto;
|
|
206
|
+
}
|
|
207
|
+
|
|
159
208
|
} // namespace domapi
|
|
@@ -155,6 +155,7 @@ xt_value node_proto() {
|
|
|
155
155
|
define_method(proto, "addEventListener", (void *)node_add_event_listener);
|
|
156
156
|
define_method(proto, "removeEventListener", (void *)node_remove_event_listener);
|
|
157
157
|
define_method(proto, "dispatchEvent", (void *)node_dispatch_event);
|
|
158
|
+
define_method(proto, "requestPointerLock", (void *)node_request_pointer_lock);
|
|
158
159
|
define_method(proto, "play", (void *)node_play);
|
|
159
160
|
define_method(proto, "pause", (void *)node_pause);
|
|
160
161
|
define_method(proto, "load", (void *)node_load);
|
|
@@ -193,6 +194,8 @@ xt_value document_proto() {
|
|
|
193
194
|
define_method(proto, "addEventListener", (void *)node_add_event_listener);
|
|
194
195
|
define_method(proto, "removeEventListener", (void *)node_remove_event_listener);
|
|
195
196
|
define_method(proto, "dispatchEvent", (void *)node_dispatch_event);
|
|
197
|
+
define_method(proto, "exitPointerLock", (void *)doc_exit_pointer_lock);
|
|
198
|
+
define_getter(proto, "pointerLockElement", (void *)doc_pointer_lock_element_get);
|
|
196
199
|
g_document_proto = proto;
|
|
197
200
|
return proto;
|
|
198
201
|
}
|
|
@@ -429,6 +429,7 @@ METHOD(webgl_get_supported_extensions) {
|
|
|
429
429
|
xt_array_push(list, xt_string_from_cstr("EXT_color_buffer_float"));
|
|
430
430
|
xt_array_push(list, xt_string_from_cstr("EXT_color_buffer_half_float"));
|
|
431
431
|
xt_array_push(list, xt_string_from_cstr("WEBGL_lose_context"));
|
|
432
|
+
xt_array_push(list, xt_string_from_cstr("EXT_texture_filter_anisotropic"));
|
|
432
433
|
xtgui::WebGLContext *context = webgl_from_context(self);
|
|
433
434
|
if (context != nullptr && context->supports_texture_format(0x83F1)) {
|
|
434
435
|
xt_array_push(list, xt_string_from_cstr("WEBGL_compressed_texture_s3tc"));
|
|
@@ -455,6 +456,12 @@ METHOD(webgl_get_extension) {
|
|
|
455
456
|
name == "EXT_color_buffer_half_float") {
|
|
456
457
|
return xt_object_new();
|
|
457
458
|
}
|
|
459
|
+
if (name == "EXT_texture_filter_anisotropic") {
|
|
460
|
+
xt_value e = xt_object_new();
|
|
461
|
+
xt_object_set(e, xt_string_from_cstr("MAX_TEXTURE_MAX_ANISOTROPY_EXT"), xt_number(0x84FF));
|
|
462
|
+
xt_object_set(e, xt_string_from_cstr("TEXTURE_MAX_ANISOTROPY_EXT"), xt_number(0x84FE));
|
|
463
|
+
return e;
|
|
464
|
+
}
|
|
458
465
|
if (name == "WEBGL_lose_context") {
|
|
459
466
|
xt_value object = xt_object_new();
|
|
460
467
|
/* The closures receive this object as `this`, so carry the context id and
|
package/runtime/ext_gui/gui.cpp
CHANGED
|
@@ -170,6 +170,7 @@ void xt_gui_quit_window(XtGuiWindow *win) {
|
|
|
170
170
|
win->media_lists.clear();
|
|
171
171
|
win->media_lists_by_query.clear();
|
|
172
172
|
win->window_listeners.clear();
|
|
173
|
+
xt_gui_pointer_lock_release(win);
|
|
173
174
|
xt_gui_media_shutdown(win);
|
|
174
175
|
xt_gui_canvas_shutdown(win);
|
|
175
176
|
xt_gui_handles_reset(win);
|
|
@@ -240,6 +241,7 @@ static XtGuiWindow *create_window_record(const char *title, int width, int heigh
|
|
|
240
241
|
record->expose_pending = 0;
|
|
241
242
|
record->present_deferred = 0;
|
|
242
243
|
record->sync_dirty = 1;
|
|
244
|
+
record->pointer_lock_node = nullptr;
|
|
243
245
|
record->width = width;
|
|
244
246
|
record->height = height;
|
|
245
247
|
record->html.clear();
|
|
@@ -180,6 +180,11 @@ struct XtGuiWindow {
|
|
|
180
180
|
float scroll_y = 0;
|
|
181
181
|
/** `document.hasFocus()` state, toggled by `window.focus()` / `blur()`. */
|
|
182
182
|
int focused = 0;
|
|
183
|
+
/** Element holding the Pointer Lock (`Element.requestPointerLock`), or null
|
|
184
|
+
* when the pointer is free. While set, SDL is in relative mouse mode, the
|
|
185
|
+
* cursor is hidden and `mousemove` targets this element with the raw motion
|
|
186
|
+
* in `movementX`/`movementY` — the shape a first-person game listens for. */
|
|
187
|
+
const xtgui::Node *pointer_lock_node = nullptr;
|
|
183
188
|
/** Live `matchMedia` lists for this window (one per query string). */
|
|
184
189
|
std::vector<xt_value> media_lists;
|
|
185
190
|
std::unordered_map<std::string, xt_value> media_lists_by_query;
|
|
@@ -322,9 +327,20 @@ xt_value xt_browser_prompt(XtGuiWindow *win, int32_t argc, xt_value *argv);
|
|
|
322
327
|
void xt_browser_install_window_navigation(xt_value proto);
|
|
323
328
|
/** CSS-like descriptor of the deepest element at (x, y), or `""` (test/debug). */
|
|
324
329
|
std::string xt_gui_hit_test(XtGuiWindow *win, float x, float y);
|
|
325
|
-
/** Synthesise a pointer event (`mousemove`/`mousedown`/`mouseup`/`click`).
|
|
330
|
+
/** Synthesise a pointer event (`mousemove`/`mousedown`/`mouseup`/`click`).
|
|
331
|
+
* `movement_x`/`movement_y` are the raw deltas carried by `movementX`/
|
|
332
|
+
* `movementY`; real motion passes SDL's `xrel`/`yrel`. */
|
|
326
333
|
void xt_gui_dispatch_pointer(XtGuiWindow *win, const char *type, float x, float y, int button,
|
|
327
|
-
int clicks);
|
|
334
|
+
int clicks, float movement_x = 0.0f, float movement_y = 0.0f);
|
|
335
|
+
/** Enter pointer lock on `node`, or leave it when `node` is null. Returns
|
|
336
|
+
* false when SDL cannot enable relative mouse mode. Fires `pointerlockchange`
|
|
337
|
+
* on a state change. */
|
|
338
|
+
bool xt_gui_set_pointer_lock(XtGuiWindow *win, const xtgui::Node *node);
|
|
339
|
+
/** Leave pointer lock without firing an event (window close, document
|
|
340
|
+
* replacement, or the locked element leaving the document). */
|
|
341
|
+
void xt_gui_pointer_lock_release(XtGuiWindow *win);
|
|
342
|
+
/** Fire `pointerlockerror` at `document` and `window` (the request failed). */
|
|
343
|
+
void xt_gui_pointer_lock_error(XtGuiWindow *win);
|
|
328
344
|
/** Synthesise a wheel event. */
|
|
329
345
|
void xt_gui_dispatch_wheel(XtGuiWindow *win, float x, float y, float delta_x, float delta_y);
|
|
330
346
|
/** Synthesise a key event (`keydown`/`keyup`). */
|