xbintsc 0.6.20 → 0.6.22
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/cli/help.d.ts +1 -1
- package/dist/src/cli/main.js +1 -0
- package/dist/src/cli/main.js.map +1 -1
- package/dist/src/driver/build-key.d.ts +3 -0
- package/dist/src/driver/build-key.js +3 -1
- package/dist/src/driver/build-key.js.map +1 -1
- package/dist/src/driver/compiler.js +11 -0
- package/dist/src/driver/compiler.js.map +1 -1
- package/dist/src/driver/config.d.ts +12 -0
- package/dist/src/driver/config.js +22 -0
- package/dist/src/driver/config.js.map +1 -1
- package/dist/src/driver/index.d.ts +2 -1
- package/dist/src/driver/index.js +1 -0
- package/dist/src/driver/index.js.map +1 -1
- package/dist/src/driver/options.d.ts +8 -1
- package/dist/src/driver/storage.d.ts +34 -0
- package/dist/src/driver/storage.js +67 -0
- package/dist/src/driver/storage.js.map +1 -0
- package/dist/src/driver/version.d.ts +1 -1
- package/dist/src/driver/version.js +1 -1
- package/dist/src/extensions/gui/features.d.ts +1 -1
- package/dist/src/extensions/gui/features.js +2 -2
- package/dist/src/extensions/gui/features.js.map +1 -1
- package/dist/src/extensions/gui/index.js +3 -1
- package/dist/src/extensions/gui/index.js.map +1 -1
- package/dist/src/extensions/registry.d.ts +4 -1
- package/dist/src/extensions/registry.js +8 -2
- package/dist/src/extensions/registry.js.map +1 -1
- package/dist/src/extensions/storage.d.ts +22 -0
- package/dist/src/extensions/storage.js +50 -0
- package/dist/src/extensions/storage.js.map +1 -0
- package/dist/tests/driver/config.test.js +31 -0
- package/dist/tests/driver/config.test.js.map +1 -1
- package/dist/tests/driver/link-features.test.js +4 -2
- package/dist/tests/driver/link-features.test.js.map +1 -1
- package/dist/tests/driver/storage.test.d.ts +1 -0
- package/dist/tests/driver/storage.test.js +29 -0
- package/dist/tests/driver/storage.test.js.map +1 -0
- package/dist/tests/e2e/storage.test.d.ts +7 -0
- package/dist/tests/e2e/storage.test.js +86 -0
- package/dist/tests/e2e/storage.test.js.map +1 -0
- package/dist/tests/extensions/gui-features.test.js +1 -1
- package/dist/tests/extensions/gui-features.test.js.map +1 -1
- package/dist/tests/extensions/storage.test.d.ts +1 -0
- package/dist/tests/extensions/storage.test.js +50 -0
- package/dist/tests/extensions/storage.test.js.map +1 -0
- package/doc/ai/cli.md +2 -0
- package/doc/ai/extensions.md +26 -0
- package/doc/ai/zh-CN/cli.md +2 -0
- package/doc/ai/zh-CN/extensions.md +23 -0
- package/doc/gui/build.md +3 -3
- package/doc/gui/media.md +4 -4
- package/doc/gui.md +2 -2
- package/doc/implemented/extensions.md +1 -1
- package/doc/implemented/storage.md +64 -0
- package/doc/implemented.md +2 -0
- package/doc/xbintsc.config.schema.json +16 -1
- package/doc/zh-CN/gui/build.md +3 -3
- package/doc/zh-CN/gui/media.md +3 -3
- package/doc/zh-CN/gui.md +2 -2
- package/doc/zh-CN/implemented/extensions.md +1 -1
- package/doc/zh-CN/implemented/storage.md +51 -0
- package/doc/zh-CN/implemented.md +2 -0
- package/package.json +7 -7
- package/runtime/ext_gui/dom_api_form.cpp +10 -0
- package/runtime/ext_gui/gui_media.cpp +1 -1
- package/runtime/ext_gui/media.cpp +1 -1
- package/runtime/ext_gui/media_api.h +2 -2
- package/runtime/xt_storage/indexed_db.c +408 -0
- package/runtime/xt_storage/indexed_db_internal.h +26 -0
- package/runtime/xt_storage/indexed_db_store.c +305 -0
- package/runtime/xt_storage/sqlite3/sqlite3.c +271131 -0
- package/runtime/xt_storage/sqlite3/sqlite3.h +14447 -0
- package/runtime/xt_storage/storage.c +209 -0
- package/runtime/xt_storage/storage_internal.h +66 -0
- package/scripts/build-gui.ts +1 -1
- package/scripts/build-media.ts +2 -2
- package/scripts/check-file-length.ts +4 -0
- package/src/cli/main.ts +1 -0
- package/src/driver/build-key.ts +6 -1
- package/src/driver/compiler.ts +13 -0
- package/src/driver/config.ts +35 -0
- package/src/driver/index.ts +8 -0
- package/src/driver/options.ts +8 -1
- package/src/driver/storage.ts +84 -0
- package/src/driver/version.ts +1 -1
- package/src/extensions/gui/features.ts +2 -2
- package/src/extensions/gui/index.ts +3 -1
- package/src/extensions/registry.ts +8 -2
- package/src/extensions/storage.ts +57 -0
- /package/runtime/{ext_media → xt_media}/decode_audio.cpp +0 -0
- /package/runtime/{ext_media → xt_media}/media.cpp +0 -0
- /package/runtime/{ext_media → xt_media}/media_bridge.c +0 -0
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { DiagnosticBag } from "../../src/diagnostics/diagnostic.js";
|
|
3
|
+
import { resolveLinkFeatures } from "../../src/driver/link-features.js";
|
|
4
|
+
import { collectUsage } from "../../src/driver/usage.js";
|
|
5
|
+
import { createDefaultRegistry, coreExtension } from "../../src/extensions/registry.js";
|
|
6
|
+
import { hasStorageUsage } from "../../src/extensions/storage.js";
|
|
7
|
+
import { parse } from "../helpers.js";
|
|
8
|
+
describe("core extension storage globals", () => {
|
|
9
|
+
it("exposes the three storage globals", () => {
|
|
10
|
+
const globals = coreExtension.globalValues?.() ?? {};
|
|
11
|
+
expect(globals.localStorage?.symbol).toBe("xt_storage_local");
|
|
12
|
+
expect(globals.sessionStorage?.symbol).toBe("xt_storage_session");
|
|
13
|
+
expect(globals.indexedDB?.symbol).toBe("xt_storage_indexed_db");
|
|
14
|
+
});
|
|
15
|
+
it("declares the storage link feature carrying the SQLite sources", () => {
|
|
16
|
+
const features = coreExtension.linkFeatures?.() ?? [];
|
|
17
|
+
expect(features.map((feature) => feature.name)).toEqual(["storage"]);
|
|
18
|
+
const sources = features[0]?.runtimeSources?.() ?? [];
|
|
19
|
+
expect(sources.some((source) => /sqlite3\.c$/.test(source))).toBe(true);
|
|
20
|
+
expect(sources.some((source) => /xt_storage[\\/]storage\.c$/.test(source))).toBe(true);
|
|
21
|
+
expect(sources.some((source) => /xt_storage[\\/]indexed_db\.c$/.test(source))).toBe(true);
|
|
22
|
+
expect(sources.some((source) => /xt_storage[\\/]indexed_db_store\.c$/.test(source))).toBe(true);
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
describe("hasStorageUsage", () => {
|
|
26
|
+
const usage = (text) => collectUsage(parse(text).file);
|
|
27
|
+
it("detects localStorage, sessionStorage and indexedDB", () => {
|
|
28
|
+
expect(hasStorageUsage(usage("localStorage.setItem('k', 'v');"))).toBe(true);
|
|
29
|
+
expect(hasStorageUsage(usage("const n = sessionStorage.length;"))).toBe(true);
|
|
30
|
+
expect(hasStorageUsage(usage("indexedDB.open('db', 1);"))).toBe(true);
|
|
31
|
+
});
|
|
32
|
+
it("detects the globals reached through window or self", () => {
|
|
33
|
+
expect(hasStorageUsage(usage("window.localStorage.clear();"))).toBe(true);
|
|
34
|
+
expect(hasStorageUsage(usage("self.indexedDB.deleteDatabase('db');"))).toBe(true);
|
|
35
|
+
});
|
|
36
|
+
it("does not fire for a program that never touches storage", () => {
|
|
37
|
+
expect(hasStorageUsage(usage("console.log('hello');"))).toBe(false);
|
|
38
|
+
expect(hasStorageUsage(usage("const db = { open() {} }; db.open();"))).toBe(false);
|
|
39
|
+
});
|
|
40
|
+
it("is selected by resolveLinkFeatures only for a storage-using program", () => {
|
|
41
|
+
const registry = createDefaultRegistry();
|
|
42
|
+
const bag = new DiagnosticBag();
|
|
43
|
+
const using = resolveLinkFeatures(registry, usage("localStorage.clear();"), {}, bag);
|
|
44
|
+
expect(using.map((feature) => feature.name)).toContain("storage");
|
|
45
|
+
const unused = resolveLinkFeatures(registry, usage("console.log(1);"), {}, bag);
|
|
46
|
+
expect(unused.map((feature) => feature.name)).not.toContain("storage");
|
|
47
|
+
expect(bag.diagnostics).toEqual([]);
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
//# sourceMappingURL=storage.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"storage.test.js","sourceRoot":"","sources":["../../../tests/extensions/storage.test.ts"],"names":[],"mappings":"AAAA,OAAO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,CAAC,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;IACtC,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
package/doc/ai/cli.md
CHANGED
|
@@ -126,6 +126,8 @@ matching field. `--no-config` skips discovery entirely.
|
|
|
126
126
|
| `features` | string[] | Optional link features to force on, e.g. `["media"]` / `["all"]` |
|
|
127
127
|
| `noFeatures` | string[] | Optional link features to keep out even when detected |
|
|
128
128
|
| `force` | boolean | Ignore the incremental cache |
|
|
129
|
+
| `storage.backend` | `"memory"|"file"` | Storage backend for `localStorage` / `sessionStorage` / `indexedDB` (default `memory`) |
|
|
130
|
+
| `storage.path` | string | Database file for `backend: "file"`, resolved against this config |
|
|
129
131
|
| `app.name` / `app.icon` / `app.bundle` / `app.bundleId` | | Application metadata ([icon.md](../icon.md)) |
|
|
130
132
|
|
|
131
133
|
JSON schema: [xbintsc.config.schema.json](../xbintsc.config.schema.json). An
|
package/doc/ai/extensions.md
CHANGED
|
@@ -132,6 +132,32 @@ is **not** a GUI extension feature: the core runtime provides it (`http://`,
|
|
|
132
132
|
plus local `file://` and relative paths; no HTTPS or streaming), so GUI
|
|
133
133
|
programs can use it too. See [../implemented/fetch.md](../implemented/fetch.md).
|
|
134
134
|
|
|
135
|
+
### `storage` — SQLite-backed Web Storage and IndexedDB (a core link feature)
|
|
136
|
+
|
|
137
|
+
`localStorage`, `sessionStorage` and `indexedDB` are always-available globals
|
|
138
|
+
(contributed by the core extension), implemented on a vendored SQLite (see
|
|
139
|
+
[../implemented/storage.md](../implemented/storage.md)). No extension flag is
|
|
140
|
+
needed:
|
|
141
|
+
|
|
142
|
+
```bash
|
|
143
|
+
xbintsc run app.ts
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
The backend is chosen at build time from `storage` in `xbintsc.config.json`; it
|
|
147
|
+
defaults to an **in-memory** database, and `sessionStorage` is always in-memory:
|
|
148
|
+
|
|
149
|
+
```json
|
|
150
|
+
{ "storage": { "backend": "file", "path": "data/app.db" } }
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
`storage.path` resolves against the config file (absolute paths are used
|
|
154
|
+
as-is). SQLite is heavy, so the whole implementation is a **link feature** named
|
|
155
|
+
`storage`: the compiler scans the program and links it only when the code
|
|
156
|
+
reaches one of the globals — a program that never touches storage pays nothing.
|
|
157
|
+
`--feature storage` / `--no-feature storage` override the detection. `indexedDB`
|
|
158
|
+
is a focused subset (`open`, object stores, `put`/`add`/`get`/`getAll`/`delete`/
|
|
159
|
+
`clear`/`count`); no indexes, cursors or `IDBKeyRange`.
|
|
160
|
+
|
|
135
161
|
### Optional link features (`media`, `gpu`, `images`, `shaping`, `webgl`)
|
|
136
162
|
|
|
137
163
|
`gui` is one extension, but its heavy halves are optional **link features**. The
|
package/doc/ai/zh-CN/cli.md
CHANGED
|
@@ -107,6 +107,8 @@ profile 数据可能独立于源码变化。
|
|
|
107
107
|
| `features` | string[] | 强制开启的可选链接特性,如 `["media"]` / `["all"]` |
|
|
108
108
|
| `noFeatures` | string[] | 即使检测到也保持关闭的可选链接特性 |
|
|
109
109
|
| `force` | boolean | 忽略增量缓存 |
|
|
110
|
+
| `storage.backend` | `"memory"|"file"` | `localStorage` / `sessionStorage` / `indexedDB` 的存储后端(默认 `memory`) |
|
|
111
|
+
| `storage.path` | string | `backend: "file"` 时的数据库文件,相对本配置解析 |
|
|
110
112
|
| `app.name` / `app.icon` / `app.bundle` / `app.bundleId` | | 应用元信息([icon.md](../../zh-CN/icon.md)) |
|
|
111
113
|
|
|
112
114
|
JSON schema:[xbintsc.config.schema.json](../../xbintsc.config.schema.json)。配置读不了
|
|
@@ -119,6 +119,29 @@ VAO、实例化、整数属性、采样器对象、`texStorage2D` 与缓冲拷
|
|
|
119
119
|
运行时提供(`http://`,以及本地 `file://` 与相对路径;不支持 HTTPS 与流式),
|
|
120
120
|
因此 GUI 程序同样可用。见 [../../implemented/fetch.md](../../implemented/fetch.md)。
|
|
121
121
|
|
|
122
|
+
### `storage` —— 基于 SQLite 的 Web Storage 与 IndexedDB(核心链接特性)
|
|
123
|
+
|
|
124
|
+
`localStorage`、`sessionStorage` 与 `indexedDB` 是**始终可用**的全局变量(由核心扩展贡献),
|
|
125
|
+
基于内置的 SQLite 实现(见 [../../zh-CN/implemented/storage.md](../../zh-CN/implemented/storage.md))。
|
|
126
|
+
无需任何扩展开关:
|
|
127
|
+
|
|
128
|
+
```bash
|
|
129
|
+
xbintsc run app.ts
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
后端在编译期由 `xbintsc.config.json` 里的 `storage` 决定,默认是**内存**数据库,
|
|
133
|
+
且 `sessionStorage` 始终在内存中:
|
|
134
|
+
|
|
135
|
+
```json
|
|
136
|
+
{ "storage": { "backend": "file", "path": "data/app.db" } }
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
`storage.path` 相对配置文件解析(绝对路径原样使用)。SQLite 很重,因此整个实现是名为
|
|
140
|
+
`storage` 的**链接特性**:编译器扫描程序,只有当代码触达这些全局之一时才链接它 ——
|
|
141
|
+
从不使用存储的程序不会付出任何体积。`--feature storage` / `--no-feature storage`
|
|
142
|
+
可覆盖自动检测。`indexedDB` 是精简子集(`open`、对象仓库、
|
|
143
|
+
`put`/`add`/`get`/`getAll`/`delete`/`clear`/`count`);没有索引、游标或 `IDBKeyRange`。
|
|
144
|
+
|
|
122
145
|
### 可选链接特性(media、gpu、images、shaping、webgl)
|
|
123
146
|
|
|
124
147
|
`gui` 仍然只有一个扩展,但其中的重型部分是可选的**链接特性**。编译器扫描打包后的
|
package/doc/gui/build.md
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
|
|
6
6
|
- Sources live in `runtime/ext_gui/` (C/C++) plus vendored libs under `vendor/`
|
|
7
7
|
(gitignored; fetched on demand). Media decoding lives in
|
|
8
|
-
`runtime/
|
|
8
|
+
`runtime/xt_media/` and is built separately.
|
|
9
9
|
- `npm run gui` (`scripts/build-gui.ts`) fetches a pinned SDL3 (`SDL3_TAG`,
|
|
10
10
|
default `release-3.2.10`), builds a static SDL3, fetches and builds static
|
|
11
11
|
**FreeType** (`FREETYPE_VERSION`, default `2.13.3`) and **HarfBuzz**
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
- `npm run media` (`scripts/build-media.ts`) builds the optional **FFmpeg**
|
|
44
44
|
backend. It fetches FFmpeg (`FFMPEG_VERSION`, default `7.1`), configures a
|
|
45
45
|
minimal static build with only the demuxers/parsers/decoders the media
|
|
46
|
-
elements need, compiles `runtime/
|
|
46
|
+
elements need, compiles `runtime/xt_media/media.cpp` against it and merges
|
|
47
47
|
everything into `runtime/lib/<os>-<arch>/media.a` (`media.lib` with the MSVC
|
|
48
48
|
ABI on Windows). The download retries the transient TLS failures the release
|
|
49
49
|
host is prone to, and the tarball is kept at
|
|
@@ -148,7 +148,7 @@ features conservatively.
|
|
|
148
148
|
When a feature is active, the driver compiles its C **bridge only for that
|
|
149
149
|
build** and links it before `gui.a`:
|
|
150
150
|
|
|
151
|
-
- `media` → `runtime/
|
|
151
|
+
- `media` → `runtime/xt_media/media_bridge.c`; its constructor installs the
|
|
152
152
|
decoder table and references `xt_media_backend_*`, which is what extracts the
|
|
153
153
|
FFmpeg members from `media.a`.
|
|
154
154
|
- `gpu` → `runtime/ext_gui/gpu_bridge.c`; its constructor calls
|
package/doc/gui/media.md
CHANGED
|
@@ -84,9 +84,9 @@ not a separate extension:
|
|
|
84
84
|
dispatches through a table the media backend installs at startup
|
|
85
85
|
(`runtime/ext_gui/media_api.h`).
|
|
86
86
|
- **`media`** (`media.a`, or `media.lib` with the MSVC ABI on Windows;
|
|
87
|
-
`runtime/
|
|
88
|
-
`runtime/
|
|
89
|
-
and `runtime/
|
|
87
|
+
`runtime/xt_media/`) is the optional decoder backend:
|
|
88
|
+
`runtime/xt_media/media.cpp` wraps a statically vendored **FFmpeg** build,
|
|
89
|
+
and `runtime/xt_media/media_bridge.c` registers it with the engine. The
|
|
90
90
|
compiler selects the feature when the program may use it (a `<video>`/`<audio>`
|
|
91
91
|
element in imported HTML, `createElement("video"/"audio")`, `new Audio()`,
|
|
92
92
|
`decodeAudioData`, or runtime-built markup) and only then compiles the bridge
|
|
@@ -128,7 +128,7 @@ platform media framework in the path either way.
|
|
|
128
128
|
decoding happens on the main thread inside `xt_gui_media_tick` — no decode
|
|
129
129
|
thread, no cross-thread GC exposure.
|
|
130
130
|
- **`decodeAudioData`.** The same FFmpeg build also decodes an in-memory audio
|
|
131
|
-
file for `AudioContext.decodeAudioData` (`runtime/
|
|
131
|
+
file for `AudioContext.decodeAudioData` (`runtime/xt_media/decode_audio.cpp`,
|
|
132
132
|
through the media table); WAV is handled by the GUI engine itself
|
|
133
133
|
(`audio_decode.cpp`), so only compressed formats need this extension.
|
|
134
134
|
- **DOM API.** Element handles expose the media surface directly (see
|
package/doc/gui.md
CHANGED
|
@@ -289,7 +289,7 @@ engine were Rust.
|
|
|
289
289
|
`tests/e2e/gui-retention.test.ts` (see [Memory & GC](./gui/runtime.md#memory--gc)).
|
|
290
290
|
13. **M13 — video & audio** ✅
|
|
291
291
|
- `<video>` / `<audio>` decode through a statically vendored minimal FFmpeg
|
|
292
|
-
in the optional `media` link feature (`runtime/
|
|
292
|
+
in the optional `media` link feature (`runtime/xt_media/media.cpp`); the
|
|
293
293
|
compiler selects it from the program and only then compiles the bridge and
|
|
294
294
|
links `media.a`. Frames
|
|
295
295
|
upload to GPU textures through the existing image pipeline, audio is
|
|
@@ -505,7 +505,7 @@ engine were Rust.
|
|
|
505
505
|
merges it into `media.a` (or `media.lib` from clang-cl/MSVC objects on
|
|
506
506
|
Windows). The compiler selects the feature from the program and only then
|
|
507
507
|
compiles `media_bridge.c` and links `media.a`; a DOM/CSS program never links
|
|
508
|
-
FFmpeg. `runtime/
|
|
508
|
+
FFmpeg. `runtime/xt_media/media.cpp` decodes video to RGBA
|
|
509
509
|
frames and audio to 48 kHz stereo PCM on the main thread,
|
|
510
510
|
`runtime/ext_gui/gui_media.cpp` owns the players, implements the SDL audio
|
|
511
511
|
sink and pumps the media clock and events each frame,
|
|
@@ -11,7 +11,7 @@ Location: `src/extensions/registry.ts`, `src/extensions/node/`, `src/extensions/
|
|
|
11
11
|
- The driver builds `ProgramUsage` from the bundled AST (`collectUsage` in `src/driver/usage.ts`): string literals (including imported HTML and inlined CSS), identifiers/property names, `getContext(...)` kinds, and whether markup can be built at run time. Simple `const` aliases are resolved; unresolved markup makes the program conservative.
|
|
12
12
|
- `resolveLinkFeatures` applies `--feature` / `--no-feature` (and `all`), expands `requires`, reports an unavailable auto-detected feature as a warning and a forced one as an error, and returns the bridges/archives/flags to link.
|
|
13
13
|
- The bridge is the strong reference: its constructor installs the feature's dispatch table and its references force the linker to extract the implementation. With no bridge, the table stays null and the implementation members are never linked.
|
|
14
|
-
- Current clients: `media` (FFmpeg, `runtime/
|
|
14
|
+
- Current clients: `media` (FFmpeg, `runtime/xt_media/media_bridge.c` + `media.a`), `gpu` (glslang/SPIRV-Cross, `runtime/ext_gui/gpu_bridge.c` + `gpu_feature.cpp` inside `gui.a`), `images` (stb_image/NanoSVG, `runtime/ext_gui/image_bridge.c` + `image_feature.cpp`), `shaping` (HarfBuzz/FreeType, `runtime/ext_gui/text_bridge.c` + `text_hb.cpp`), `webgl` (context/DOM bindings, `runtime/ext_gui/webgl_bridge.c` + `webgl_feature.cpp`, requiring `gpu`), and `storage` (SQLite-backed Web Storage/IndexedDB, whose implementation lives entirely in the feature's `runtimeSources` — `runtime/xt_storage/*.c` — because the globals themselves are the strong references).
|
|
15
15
|
- The built-in core extension `core`: exposes `print` (mapped to `xt_println`), always registered.
|
|
16
16
|
- The Node extension `node`:
|
|
17
17
|
- Modular organisation: `src/extensions/node/fs/` + `runtime/ext_node/fs/read_file.c`
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
# Storage (localStorage / sessionStorage / indexedDB)
|
|
2
|
+
|
|
3
|
+
> Part of [Implemented syntax and features](../implemented.md) · [简体中文](../zh-CN/implemented/storage.md)
|
|
4
|
+
|
|
5
|
+
The three browser storage globals — `localStorage`, `sessionStorage` and
|
|
6
|
+
`indexedDB` — are always available (they are core globals), backed by a
|
|
7
|
+
vendored SQLite (`runtime/xt_storage/sqlite3`). No extension flag is needed.
|
|
8
|
+
|
|
9
|
+
## Backend selection
|
|
10
|
+
|
|
11
|
+
The backend is chosen at build time from the `storage` object in
|
|
12
|
+
`xbintsc.config.json`; it defaults to an **in-memory** SQLite database:
|
|
13
|
+
|
|
14
|
+
```json
|
|
15
|
+
{ "storage": { "backend": "memory" } }
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
```json
|
|
19
|
+
{ "storage": { "backend": "file", "path": "data/app.db" } }
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
`storage.path` resolves against the config file's directory (absolute paths are
|
|
23
|
+
used as-is). `sessionStorage` is **always** in-memory regardless of the backend,
|
|
24
|
+
because a session never outlives the process; `localStorage` and `indexedDB`
|
|
25
|
+
follow the configured backend. The driver embeds the resolved backend and path
|
|
26
|
+
as a small object the runtime reads at first use (`src/driver/storage.ts`).
|
|
27
|
+
|
|
28
|
+
## It is a link feature
|
|
29
|
+
|
|
30
|
+
SQLite is heavy, so the whole implementation is a **link feature** named
|
|
31
|
+
`storage`, declared by the always-on core extension: the driver scans the
|
|
32
|
+
bundled program and links it only when the code may reach one of the three
|
|
33
|
+
globals. A program that never touches storage pays nothing for SQLite.
|
|
34
|
+
`--feature storage` forces the backend on (for storage reached through names
|
|
35
|
+
the scan cannot see) and `--no-feature storage` keeps it out.
|
|
36
|
+
|
|
37
|
+
## Surface
|
|
38
|
+
|
|
39
|
+
| Global | Notes |
|
|
40
|
+
| --- | --- |
|
|
41
|
+
| `localStorage` | `getItem` / `setItem` / `removeItem` / `clear` / `key(i)` / `length`, backed by the configured backend. |
|
|
42
|
+
| `sessionStorage` | the same surface, always in-memory. |
|
|
43
|
+
| `indexedDB` | `open(name, version?)`, `deleteDatabase(name)`; databases with `createObjectStore` / `deleteObjectStore` / `transaction`; object stores with `put` / `add` / `get` / `getAll` / `getKey` / `delete` / `clear` / `count`; requests with `onsuccess` / `onerror` / `onupgradeneeded` / `result` / `error`. |
|
|
44
|
+
|
|
45
|
+
IndexedDB requests settle from a microtask, so the `onsuccess` / `onerror` /
|
|
46
|
+
`onupgradeneeded` handlers fire asynchronously like the browser. Values are
|
|
47
|
+
serialised as JSON; keys are canonicalised so a number key `5` and a string key
|
|
48
|
+
`"5"` stay distinct. `keyPath` and `autoIncrement` are supported on
|
|
49
|
+
`createObjectStore`.
|
|
50
|
+
|
|
51
|
+
## Limits
|
|
52
|
+
|
|
53
|
+
- The indexedDB subset is focused: no `index`, `IDBKeyRange`, cursors,
|
|
54
|
+
`createIndex`, or `count(key)`/`getAll(query, count)` filtering; `getAll`
|
|
55
|
+
returns the whole store and `count` the whole store.
|
|
56
|
+
- Transactions are not atomic — each object-store operation is committed
|
|
57
|
+
immediately — and `abort` is not implemented.
|
|
58
|
+
- JSON serialisation means non-JSON values (`undefined`, functions, `Date`
|
|
59
|
+
identity) round-trip as `null` or are dropped.
|
|
60
|
+
- The key returned by `key(i)` / `objectStoreNames` uses insertion order
|
|
61
|
+
(`rowid`); re-setting a Web Storage key keeps its original position.
|
|
62
|
+
- The `gui` extension keeps `window.localStorage` as its engine's own in-memory
|
|
63
|
+
store; the bare `localStorage` global (and `sessionStorage` / `indexedDB`)
|
|
64
|
+
are the SQLite-backed globals described here.
|
package/doc/implemented.md
CHANGED
|
@@ -46,6 +46,7 @@ small file instead of a single monolithic document.
|
|
|
46
46
|
- [Module system](./implemented/modules.md) — import/export, bundling, `node_modules`, `import.meta`
|
|
47
47
|
- [Extension mechanism](./implemented/extensions.md) — registry, the `node` extension, native C++/Rust extensions
|
|
48
48
|
- [Node extension](./implemented/node.md) — 21 Node built-in modules, one page per module
|
|
49
|
+
- [Storage extension](./implemented/storage.md) — SQLite-backed `localStorage`, `sessionStorage` and `indexedDB`
|
|
49
50
|
- [Driver, incremental compilation and toolchain](./implemented/driver.md) — cache, clang/LTO/PGO, config, icons
|
|
50
51
|
- [CLI and programmatic API](./implemented/cli.md) — commands, flags, embedder API
|
|
51
52
|
- [Tests](./implemented/tests.md) — unit, e2e and the differential harness
|
|
@@ -74,6 +75,7 @@ same file.
|
|
|
74
75
|
| import/export and bundling | [Modules](./implemented/modules.md) |
|
|
75
76
|
| extension registry or the `node` extension | [Extensions](./implemented/extensions.md) |
|
|
76
77
|
| a specific Node module (`fs`, `path`, `http`, ...) | [Node extension](./implemented/node.md) |
|
|
78
|
+
| `localStorage` / `sessionStorage` / `indexedDB` | [Storage extension](./implemented/storage.md) |
|
|
77
79
|
| build cache, clang, LTO/PGO, config, icons | [Driver](./implemented/driver.md) |
|
|
78
80
|
| CLI flags or the embedder API | [CLI](./implemented/cli.md) |
|
|
79
81
|
| tests and the differential harness | [Tests](./implemented/tests.md) |
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
"features": {
|
|
52
52
|
"type": "array",
|
|
53
53
|
"items": { "type": "string" },
|
|
54
|
-
"description": "Optional link features to force on, e.g. [\"media\", \"gpu\", \"images\", \"shaping\", \"webgl\"] or [\"all\"]."
|
|
54
|
+
"description": "Optional link features to force on, e.g. [\"media\", \"gpu\", \"images\", \"shaping\", \"webgl\", \"storage\"] or [\"all\"]."
|
|
55
55
|
},
|
|
56
56
|
"noFeatures": {
|
|
57
57
|
"type": "array",
|
|
@@ -62,6 +62,21 @@
|
|
|
62
62
|
"type": "boolean",
|
|
63
63
|
"description": "Ignore the incremental cache."
|
|
64
64
|
},
|
|
65
|
+
"storage": {
|
|
66
|
+
"type": "object",
|
|
67
|
+
"description": "Storage backend for the storage extension (localStorage, sessionStorage, indexedDB). Defaults to memory.",
|
|
68
|
+
"additionalProperties": false,
|
|
69
|
+
"properties": {
|
|
70
|
+
"backend": {
|
|
71
|
+
"enum": ["memory", "file"],
|
|
72
|
+
"description": "Where the database lives. Default: memory (an in-memory SQLite database)."
|
|
73
|
+
},
|
|
74
|
+
"path": {
|
|
75
|
+
"type": "string",
|
|
76
|
+
"description": "Database file path for backend: file, resolved against this config's directory (absolute paths are used as-is)."
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
},
|
|
65
80
|
"app": {
|
|
66
81
|
"type": "object",
|
|
67
82
|
"description": "Application metadata and packaging.",
|
package/doc/zh-CN/gui/build.md
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
> 属于 [GUI 扩展](../gui.md) 的一部分;引擎总览、锁定决策与路线图在那里。
|
|
6
6
|
|
|
7
7
|
- 源码位于 `runtime/ext_gui/`(C/C++),外加 `vendor/` 下的 vendored 库
|
|
8
|
-
(被 gitignore;按需获取)。媒体解码位于 `runtime/
|
|
8
|
+
(被 gitignore;按需获取)。媒体解码位于 `runtime/xt_media/`,单独构建。
|
|
9
9
|
- `npm run gui`(`scripts/build-gui.ts`)获取固定版本的 SDL3(`SDL3_TAG`,
|
|
10
10
|
默认 `release-3.2.10`),构建静态 SDL3,获取并构建静态 **FreeType**
|
|
11
11
|
(`FREETYPE_VERSION`,默认 `2.13.3`)与 **HarfBuzz**(`HARFBUZZ_VERSION`,
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
- `npm run media`(`scripts/build-media.ts`)构建可选的 **FFmpeg** 后端。它获取
|
|
38
38
|
FFmpeg(`FFMPEG_VERSION`,默认 `7.1`),配置一个只启用媒体元素所需
|
|
39
39
|
demuxer/parser/decoder 的最小静态构建,用它编译
|
|
40
|
-
`runtime/
|
|
40
|
+
`runtime/xt_media/media.cpp`,并把所有内容合并到
|
|
41
41
|
`runtime/lib/<os>-<arch>/media.a`(Windows 上 MSVC ABI 则为 `media.lib`)。
|
|
42
42
|
下载会重试发布主机常见的瞬时 TLS 故障;解压后 tarball 保留为
|
|
43
43
|
`vendor/ffmpeg-<version>.tar.xz`,因此重建(或按 `FFMPEG_VERSION` 缓存它的
|
|
@@ -121,7 +121,7 @@ markup 会让程序按“动态 markup”保守处理,启用可选特性。
|
|
|
121
121
|
|
|
122
122
|
特性启用时,driver 只为本构建编译它的 C **bridge**,并链接在 `gui.a` 之前:
|
|
123
123
|
|
|
124
|
-
- `media` → `runtime/
|
|
124
|
+
- `media` → `runtime/xt_media/media_bridge.c`;构造函数安装解码表并引用
|
|
125
125
|
`xt_media_backend_*`,从而把 FFmpeg 成员从 `media.a` 里取出。
|
|
126
126
|
- `gpu` → `runtime/ext_gui/gpu_bridge.c`;构造函数调用 `gpu_feature.cpp` 里的
|
|
127
127
|
`xt_gpu_feature_register`,安装 `XtGpuShaderApi` 表并引用 `compile_glsl` /
|
package/doc/zh-CN/gui/media.md
CHANGED
|
@@ -70,8 +70,8 @@ opacity、`display`——与任何其他元素一样。盒子内部的艺术内
|
|
|
70
70
|
声明播放器接口,并通过媒体后端在启动时安装的函数表分发
|
|
71
71
|
(`runtime/ext_gui/media_api.h`)。
|
|
72
72
|
- **`media`**(`media.a`,Windows 上 MSVC ABI 则为 `media.lib`;
|
|
73
|
-
`runtime/
|
|
74
|
-
封装静态 vendored 的 **FFmpeg** 构建,`runtime/
|
|
73
|
+
`runtime/xt_media/`)是可选的解码后端:`runtime/xt_media/media.cpp`
|
|
74
|
+
封装静态 vendored 的 **FFmpeg** 构建,`runtime/xt_media/media_bridge.c`
|
|
75
75
|
把它注册进引擎。编译器在程序可能用到媒体时(导入 HTML 里的
|
|
76
76
|
`<video>`/`<audio>`、`createElement("video"/"audio")`、`new Audio()`、
|
|
77
77
|
`decodeAudioData`,或运行时拼出的 HTML)自动选中该特性,只在那时才编译
|
|
@@ -104,7 +104,7 @@ opacity、`display`——与任何其他元素一样。盒子内部的艺术内
|
|
|
104
104
|
- **线程。** 引擎是单线程且非线程感知,因此所有解码都在主线程的
|
|
105
105
|
`xt_gui_media_tick` 内完成——没有解码线程,也没有跨线程 GC 暴露。
|
|
106
106
|
- **`decodeAudioData`。** 同一套 FFmpeg 还会为 `AudioContext.decodeAudioData`
|
|
107
|
-
解码内存中的音频文件(`runtime/
|
|
107
|
+
解码内存中的音频文件(`runtime/xt_media/decode_audio.cpp`,经媒体表分发);
|
|
108
108
|
WAV 由 GUI 引擎自身处理(`audio_decode.cpp`),因此只有压缩格式需要该扩展。
|
|
109
109
|
- **DOM API。** 元素句柄直接暴露媒体接口(见
|
|
110
110
|
`runtime/ext_gui/dom_api_media.cpp` 与 `dom_api_proto.cpp` 中的原型):
|
package/doc/zh-CN/gui.md
CHANGED
|
@@ -217,7 +217,7 @@
|
|
|
217
217
|
- `win.stats()` 暴露引擎计数器;e2e 覆盖见
|
|
218
218
|
`tests/e2e/gui-retention.test.ts`(见[内存与 GC](./gui/runtime.md))。
|
|
219
219
|
13. **M13 — 视频与音频** ✅
|
|
220
|
-
- `<video>` / `<audio>` 通过可选的 `media` **链接特性**(`runtime/
|
|
220
|
+
- `<video>` / `<audio>` 通过可选的 `media` **链接特性**(`runtime/xt_media/media.cpp`)
|
|
221
221
|
使用静态 vendored 的最小 FFmpeg 解码。编译器从程序里检测到媒体用法时才编译
|
|
222
222
|
`media_bridge.c` 并链接 `media.a`,只做 DOM/CSS 的程序不会链接 FFmpeg。
|
|
223
223
|
帧沿用现有图像管线上传到 GPU 纹理,
|
|
@@ -405,7 +405,7 @@
|
|
|
405
405
|
最小化的静态 FFmpeg(`scripts/build-media.ts`),合并进 `media.a`。编译器从程序里
|
|
406
406
|
选中该特性后才编译 `media_bridge.c` 并链接 `media.a`;只做 DOM/CSS 的程序不会链接
|
|
407
407
|
FFmpeg。
|
|
408
|
-
`runtime/
|
|
408
|
+
`runtime/xt_media/media.cpp` 在主线程把视频解码为 RGBA 帧、把音频解码为
|
|
409
409
|
48 kHz 立体声 PCM,`runtime/ext_gui/gui_media.cpp` 持有播放器、实现 SDL 音频
|
|
410
410
|
sink 并在每帧推进媒体时钟与事件,`renderer_image.cpp` 把每个新视频帧沿图像纹理
|
|
411
411
|
路径上传,`dom_api_media.cpp` 在元素句柄上暴露 `play`/`pause`/`load` 与媒体
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
- driver 从打包后的 AST 构造 `ProgramUsage`(`src/driver/usage.ts` 的 `collectUsage`):字符串字面量(含导入 HTML 与内联 CSS)、标识符/属性名、`getContext(...)` 的 kind,以及 markup 是否可能在运行时拼出。简单的 `const` 别名会被解析;无法解析的 markup 让程序走保守回退。
|
|
12
12
|
- `resolveLinkFeatures` 应用 `--feature` / `--no-feature`(以及 `all`),展开 `requires`,把自动检测到但不可用的特性报为 warning、把强制开启却不可用的报为 error,并返回要链接的 bridge/归档/参数。
|
|
13
13
|
- bridge 就是强引用:构造函数安装特性的分发表,其引用迫使链接器取出实现;没有 bridge 时表保持 null,实现成员永不被链接。
|
|
14
|
-
- 当前客户端:`media`(FFmpeg,`runtime/
|
|
14
|
+
- 当前客户端:`media`(FFmpeg,`runtime/xt_media/media_bridge.c` + `media.a`)、`gpu`(glslang/SPIRV-Cross,`runtime/ext_gui/gpu_bridge.c` + `gui.a` 内的 `gpu_feature.cpp`)、`images`(stb_image/NanoSVG,`runtime/ext_gui/image_bridge.c` + `image_feature.cpp`)、`shaping`(HarfBuzz/FreeType,`runtime/ext_gui/text_bridge.c` + `text_hb.cpp`)、`webgl`(context/DOM 绑定,`runtime/ext_gui/webgl_bridge.c` + `webgl_feature.cpp`,依赖 `gpu`)以及 `storage`(基于 SQLite 的 Web Storage/IndexedDB,其实现完全位于该特性的 `runtimeSources` —— `runtime/xt_storage/*.c`,因为这些全局变量本身就是强引用)。
|
|
15
15
|
- 内置核心扩展 `core`:暴露 `print`(映射 `xt_println`),始终注册。
|
|
16
16
|
- Node 扩展 `node`:
|
|
17
17
|
- 模块化组织:`src/extensions/node/fs/` + `runtime/ext_node/fs/read_file.c`
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# Storage(localStorage / sessionStorage / indexedDB)
|
|
2
|
+
|
|
3
|
+
> 属于[已实现语法与功能](../implemented.md) · [English](../../implemented/storage.md)
|
|
4
|
+
|
|
5
|
+
三个浏览器存储全局变量 —— `localStorage`、`sessionStorage` 与 `indexedDB` —— **始终可用**
|
|
6
|
+
(它们是核心全局),由内置的 SQLite(`runtime/xt_storage/sqlite3`)支撑。无需任何扩展开关。
|
|
7
|
+
|
|
8
|
+
## 后端选择
|
|
9
|
+
|
|
10
|
+
后端在编译期由 `xbintsc.config.json` 里的 `storage` 对象决定,默认是**内存** SQLite 数据库:
|
|
11
|
+
|
|
12
|
+
```json
|
|
13
|
+
{ "storage": { "backend": "memory" } }
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
```json
|
|
17
|
+
{ "storage": { "backend": "file", "path": "data/app.db" } }
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
`storage.path` 相对配置文件所在目录解析(绝对路径原样使用)。`sessionStorage` **始终**在内存中,
|
|
21
|
+
因为会话不会比进程活得更久;`localStorage` 与 `indexedDB` 遵循配置的后端。驱动程序把解析好的后端与
|
|
22
|
+
路径嵌入为一个小对象,运行时在第一次使用时读取(`src/driver/storage.ts`)。
|
|
23
|
+
|
|
24
|
+
## 它是一个链接特性
|
|
25
|
+
|
|
26
|
+
SQLite 很重,因此整个实现是一个名为 `storage` 的**链接特性**,由始终开启的核心扩展声明:
|
|
27
|
+
驱动程序扫描打包后的程序,只有当代码可能触达这三个全局变量之一时才链接它。从不使用存储的程序
|
|
28
|
+
不会为 SQLite 付出任何体积。`--feature storage` 强制开启后端(用于扫描无法看见的存储访问),
|
|
29
|
+
`--no-feature storage` 则关闭它。
|
|
30
|
+
|
|
31
|
+
## 接口
|
|
32
|
+
|
|
33
|
+
| 全局变量 | 说明 |
|
|
34
|
+
| --- | --- |
|
|
35
|
+
| `localStorage` | `getItem` / `setItem` / `removeItem` / `clear` / `key(i)` / `length`,由配置的后端支撑。 |
|
|
36
|
+
| `sessionStorage` | 同样的接口,始终在内存中。 |
|
|
37
|
+
| `indexedDB` | `open(name, version?)`、`deleteDatabase(name)`;数据库支持 `createObjectStore` / `deleteObjectStore` / `transaction`;对象仓库支持 `put` / `add` / `get` / `getAll` / `getKey` / `delete` / `clear` / `count`;请求支持 `onsuccess` / `onerror` / `onupgradeneeded` / `result` / `error`。 |
|
|
38
|
+
|
|
39
|
+
indexedDB 请求从微任务中 settle,因此 `onsuccess` / `onerror` / `onupgradeneeded` 处理器像浏览器一样
|
|
40
|
+
异步触发。值以 JSON 序列化;键会被规范化,使数字键 `5` 与字符串键 `"5"` 保持区分。`createObjectStore`
|
|
41
|
+
支持 `keyPath` 与 `autoIncrement`。
|
|
42
|
+
|
|
43
|
+
## 限制
|
|
44
|
+
|
|
45
|
+
- indexedDB 子集是精简的:没有 `index`、`IDBKeyRange`、游标、`createIndex`,也没有
|
|
46
|
+
`count(key)` / `getAll(query, count)` 过滤;`getAll` 返回整个仓库,`count` 统计整个仓库。
|
|
47
|
+
- 事务不是原子的 —— 每个对象仓库操作都会立即提交 —— 且未实现 `abort`。
|
|
48
|
+
- JSON 序列化意味着非 JSON 值(`undefined`、函数、`Date` 身份)会以 `null` 往返或被丢弃。
|
|
49
|
+
- `key(i)` / `objectStoreNames` 返回的键按插入顺序(`rowid`);重复设置同一个 Web Storage 键会保持其原始位置。
|
|
50
|
+
- `gui` 扩展仍把 `window.localStorage` 作为引擎自己的内存存储;裸的 `localStorage` 全局(以及
|
|
51
|
+
`sessionStorage` / `indexedDB`)则是这里描述的基于 SQLite 的全局。
|
package/doc/zh-CN/implemented.md
CHANGED
|
@@ -40,6 +40,7 @@
|
|
|
40
40
|
- [模块系统](./implemented/modules.md) —— import/export、打包、`node_modules`、`import.meta`
|
|
41
41
|
- [扩展机制](./implemented/extensions.md) —— 注册表、`node` 扩展、原生 C++/Rust 扩展
|
|
42
42
|
- [Node 扩展](./implemented/node.md) —— 21 个 Node 内置模块,每个模块一页
|
|
43
|
+
- [Storage 扩展](./implemented/storage.md) —— 基于 SQLite 的 `localStorage`、`sessionStorage` 与 `indexedDB`
|
|
43
44
|
- [驱动、增量编译与工具链](./implemented/driver.md) —— 缓存、clang/LTO/PGO、配置、图标
|
|
44
45
|
- [CLI 与编程接口](./implemented/cli.md) —— 命令、参数、嵌入式 API
|
|
45
46
|
- [测试](./implemented/tests.md) —— 单元测试、e2e 与差分测试
|
|
@@ -67,6 +68,7 @@
|
|
|
67
68
|
| import/export 与打包 | [模块系统](./implemented/modules.md) |
|
|
68
69
|
| 扩展注册表或 `node` 扩展 | [扩展机制](./implemented/extensions.md) |
|
|
69
70
|
| 某个 Node 模块(`fs`、`path`、`http` 等) | [Node 扩展](./implemented/node.md) |
|
|
71
|
+
| `localStorage` / `sessionStorage` / `indexedDB` | [Storage 扩展](./implemented/storage.md) |
|
|
70
72
|
| 构建缓存、clang、LTO/PGO、配置、图标 | [驱动](./implemented/driver.md) |
|
|
71
73
|
| CLI 参数或嵌入式 API | [CLI](./implemented/cli.md) |
|
|
72
74
|
| 测试与差分测试 | [测试](./implemented/tests.md) |
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "xbintsc",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.22",
|
|
4
4
|
"description": "xbintsc - a TypeScript binary compiler (TypeScript -> LLVM IR -> native binary)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -72,12 +72,12 @@
|
|
|
72
72
|
"vitest": "^2.1.8"
|
|
73
73
|
},
|
|
74
74
|
"optionalDependencies": {
|
|
75
|
-
"@xbintsc/linux-x64": "0.6.
|
|
76
|
-
"@xbintsc/linux-arm64": "0.6.
|
|
77
|
-
"@xbintsc/darwin-x64": "0.6.
|
|
78
|
-
"@xbintsc/darwin-arm64": "0.6.
|
|
79
|
-
"@xbintsc/win32-x64": "0.6.
|
|
80
|
-
"@xbintsc/win32-arm64": "0.6.
|
|
75
|
+
"@xbintsc/linux-x64": "0.6.22",
|
|
76
|
+
"@xbintsc/linux-arm64": "0.6.22",
|
|
77
|
+
"@xbintsc/darwin-x64": "0.6.22",
|
|
78
|
+
"@xbintsc/darwin-arm64": "0.6.22",
|
|
79
|
+
"@xbintsc/win32-x64": "0.6.22",
|
|
80
|
+
"@xbintsc/win32-arm64": "0.6.22"
|
|
81
81
|
},
|
|
82
82
|
"engines": {
|
|
83
83
|
"node": ">=22"
|
|
@@ -162,12 +162,22 @@ METHOD(node_type_set) {
|
|
|
162
162
|
node->tag != "textarea") {
|
|
163
163
|
return XT_UNDEFINED;
|
|
164
164
|
}
|
|
165
|
+
/* Switching a text-like `<input>` to another text-like kind (the `text` <->
|
|
166
|
+
* `password` toggle a reveal-password button performs) keeps the live value:
|
|
167
|
+
* `xt_form_init` below would otherwise re-read the authored `value` attribute
|
|
168
|
+
* and drop what the user just typed. */
|
|
169
|
+
const bool was_text_like = xtgui::xt_form_is_text_like(node);
|
|
170
|
+
std::string live_value;
|
|
171
|
+
if (was_text_like) live_value = xtgui::xt_form_value(node);
|
|
165
172
|
set_attribute(win, node, "type", argc >= 1 ? to_string_value(xt_arg(argc, argv, 0)) : "text");
|
|
166
173
|
if (node->form) node->form->initialized = false;
|
|
167
174
|
if (xtgui::xt_form_is_control(node)) {
|
|
168
175
|
xtgui::xt_form_init(node);
|
|
169
176
|
form_dirty(win);
|
|
170
177
|
}
|
|
178
|
+
if (was_text_like && xtgui::xt_form_is_text_like(node)) {
|
|
179
|
+
xtgui::xt_form_set_value(node, live_value);
|
|
180
|
+
}
|
|
171
181
|
return XT_UNDEFINED;
|
|
172
182
|
}
|
|
173
183
|
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* This unit bridges three pieces:
|
|
5
5
|
* - the DOM (`Node`) and the per-window media table on `XtGuiWindow`;
|
|
6
6
|
* - the optional decoders the `media` extension installs (the engine's
|
|
7
|
-
* `media.cpp` dispatch; FFmpeg itself lives in `runtime/
|
|
7
|
+
* `media.cpp` dispatch; FFmpeg itself lives in `runtime/xt_media/`);
|
|
8
8
|
* - the renderer (`renderer_image.cpp`), which owns the GPU textures.
|
|
9
9
|
*
|
|
10
10
|
* It also provides the SDL audio sink the decoder writes PCM to, which keeps
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* optional backend supplied by the separate `media` extension. That backend
|
|
6
6
|
* installs its table through `xt_media_install` from a bridge object that is
|
|
7
7
|
* linked directly when the extension is enabled (see
|
|
8
|
-
* `runtime/
|
|
8
|
+
* `runtime/xt_media/media_bridge.c`), so this translation unit stays tiny and
|
|
9
9
|
* FFmpeg-free.
|
|
10
10
|
*
|
|
11
11
|
* A program built with `--ext gui` alone leaves `g_api` null. `MediaPlayer::open`
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
*
|
|
7
7
|
* The engine knows how to model `<video>`/`<audio>` elements and how to draw
|
|
8
8
|
* their frames, but it deliberately contains no decoder: FFmpeg lives in the
|
|
9
|
-
* optional `media` link feature (`runtime/
|
|
9
|
+
* optional `media` link feature (`runtime/xt_media/`, linked as
|
|
10
10
|
* `media.a`, or `media.lib` with the MSVC ABI on Windows). Keeping the boundary C-only means the backend can be a prebuilt
|
|
11
11
|
* C++ archive that is compiled independently of the engine.
|
|
12
12
|
*
|
|
@@ -71,7 +71,7 @@ typedef struct XtMediaApi {
|
|
|
71
71
|
* media backend's bridge object before `main`. */
|
|
72
72
|
void xt_media_install(const XtMediaApi *api);
|
|
73
73
|
|
|
74
|
-
/** Decoder backend entry points, implemented by `runtime/
|
|
74
|
+
/** Decoder backend entry points, implemented by `runtime/xt_media/media.cpp`
|
|
75
75
|
* (inside `media.a`/`media.lib`). The bridge references them, which is what makes the
|
|
76
76
|
* linker extract the archive member when the `media` feature is selected. */
|
|
77
77
|
XtMediaPlayerHandle xt_media_backend_open(const char *path, char *error,
|