buninu-browser 0.3.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSES/jsmdcui.txt +22 -0
- package/README.md +40 -4
- package/frontends/wayland/LICENSE-land +21 -0
- package/frontends/wayland/README.md +152 -0
- package/frontends/wayland/casty/LICENSE +21 -0
- package/frontends/wayland/casty/bookmarks.js +32 -0
- package/frontends/wayland/casty/click.js +96 -0
- package/frontends/wayland/casty/commands.js +61 -0
- package/frontends/wayland/casty/config.js +45 -0
- package/frontends/wayland/casty/download-directory.js +28 -0
- package/frontends/wayland/casty/download.js +49 -0
- package/frontends/wayland/casty/hints.js +334 -0
- package/frontends/wayland/casty/keys.js +56 -0
- package/frontends/wayland/casty/page-commands.js +80 -0
- package/frontends/wayland/casty/prompt-width.js +148 -0
- package/frontends/wayland/casty/urlbar.js +606 -0
- package/frontends/wayland/client.js +88 -0
- package/frontends/wayland/clipboard.js +80 -0
- package/frontends/wayland/index.js +130 -0
- package/frontends/wayland/input.js +75 -0
- package/frontends/wayland/protocol.js +55 -0
- package/frontends/wayland/protocols/wayland.xml +3248 -0
- package/frontends/wayland/protocols/xdg-shell.xml +1415 -0
- package/frontends/wayland/transport.js +120 -0
- package/frontends/wayland/urlbar.js +162 -0
- package/index.js +28 -1
- package/lib/audio/shared-connection.js +31 -0
- package/lib/cdp-server.js +15 -2
- package/lib/clipboard-command.js +10 -0
- package/lib/clipboard-powershell.js +22 -0
- package/lib/clipboard.js +37 -2
- package/lib/document-types.js +11 -0
- package/lib/headless-shell.js +54 -12
- package/lib/layout/text-layout.js +17 -9
- package/lib/paint/display-list.js +6 -1
- package/lib/qml/README.md +1427 -0
- package/lib/qml/builtins.js +771 -0
- package/lib/qml/canvas-dom.js +115 -0
- package/lib/qml/canvas.js +76 -0
- package/lib/qml/document.js +1199 -0
- package/lib/qml/fonts.js +69 -0
- package/lib/qml/format.js +9 -0
- package/lib/qml/host.js +352 -0
- package/lib/qml/images.js +199 -0
- package/lib/qml/launcher.js +132 -0
- package/lib/qml/loader.js +521 -0
- package/lib/qml/media-renderer.js +49 -0
- package/lib/qml/media.js +86 -0
- package/lib/qml/models.js +622 -0
- package/lib/qml/parser.js +381 -0
- package/lib/qml/qs +5 -0
- package/lib/qml/qscasty +3 -0
- package/lib/qml/qsheadless +3 -0
- package/lib/qml/qswayland +3 -0
- package/lib/qml/reactive.js +182 -0
- package/lib/qml/runtime.js +3603 -0
- package/lib/qml/shader/fragment.js +83 -0
- package/lib/qml/shader/qsb.js +27 -0
- package/lib/qml/shader/renderer.js +39 -0
- package/lib/qml/shader/runtime.js +61 -0
- package/lib/qml/shapes.js +251 -0
- package/lib/qml/shortcuts.js +65 -0
- package/lib/qml/text.js +109 -0
- package/lib/qml/textures.js +126 -0
- package/lib/qml/wayland-clipboard.js +32 -0
- package/lib/qml/window-constraints.js +16 -0
- package/lib/qml/worker-thread.js +70 -0
- package/lib/render-tree/index.js +16 -1
- package/lib/renderer/bindings.js +16 -1
- package/lib/renderer/canvas-2d.js +29 -0
- package/lib/renderer/document-selection.js +19 -0
- package/lib/renderer/host.js +45 -17
- package/lib/renderer/main.js +21 -6
- package/lib/renderer/page-realm.js +20 -10
- package/lib/renderer/page-renderer.js +497 -42
- package/lib/renderer/pointer-move.js +5 -3
- package/lib/renderer/render-interval.js +9 -0
- package/lib/renderer/text-input-paint.js +54 -0
- package/lib/renderer/text-input.js +57 -0
- package/lib/style/computed-style.js +10 -4
- package/package.json +1 -1
- package/test/audio-connection-lifetime.test.js +46 -0
- package/test/canvas-paint.test.js +8 -0
- package/test/clipboard.test.js +19 -0
- package/test/computed-style.test.js +12 -0
- package/test/document-selection.test.js +27 -0
- package/test/double-click.test.js +85 -0
- package/test/fixtures/canvas-damage.js +40 -0
- package/test/fixtures/fake-renderer.js +1 -0
- package/test/fixtures/flea-helpers/Dockerfile +36 -0
- package/test/fixtures/flea-helpers/bat.mjs +43 -0
- package/test/fixtures/flea-helpers/bin/bat +3 -0
- package/test/fixtures/flea-helpers/bin/bwrap +10 -0
- package/test/fixtures/flea-helpers/bin/bwrap-real-filter +9 -0
- package/test/fixtures/flea-helpers/bin/glow +3 -0
- package/test/fixtures/flea-helpers/bin/qs +3 -0
- package/test/fixtures/flea-helpers/bin/unsupported +3 -0
- package/test/fixtures/flea-helpers/check-highlighting.mjs +47 -0
- package/test/fixtures/flea-helpers/check-media.mjs +29 -0
- package/test/fixtures/flea-helpers/check-preview.mjs +27 -0
- package/test/fixtures/flea-helpers/check.mjs +36 -0
- package/test/fixtures/flea-helpers/highlight-cases.json +227 -0
- package/test/fixtures/flea-helpers/source-mime.xml +28 -0
- package/test/fixtures/flea-helpers/syntax-compat.mjs +23 -0
- package/test/fixtures/flea-thumbnail-stub/flea-placeholder.thumbnailer +4 -0
- package/test/fixtures/flea-thumbnail-stub/flea-thumbnail-stub +3 -0
- package/test/fixtures/omastorm-helpers/Dockerfile +35 -0
- package/test/fixtures/omastorm-helpers/check.mjs +56 -0
- package/test/fixtures/omastorm-helpers/launch.mjs +24 -0
- package/test/fixtures/omastorm-helpers/prepare.mjs +17 -0
- package/test/fixtures/omastorm-helpers/runtime.mjs +32 -0
- package/test/fixtures/pointer-paint-batching.js +23 -0
- package/test/fixtures/qml/flea/EscapeHint.qml +11 -0
- package/test/fixtures/qml/flea/LICENSE +21 -0
- package/test/fixtures/qml/flea/README.md +25 -0
- package/test/fixtures/qml/flea/Theme.qml +8 -0
- package/test/fixtures/qml/flea/demo.qml +24 -0
- package/test/fixtures/qml/flea/qmldir +3 -0
- package/test/fixtures/qml/flea-theme/LICENSE-Flea +21 -0
- package/test/fixtures/qml/flea-theme/LICENSE-Omarchy +20 -0
- package/test/fixtures/qml/flea-theme/README.md +70 -0
- package/test/fixtures/qml/flea-theme/button.qml +17 -0
- package/test/fixtures/qml/flea-theme/demo.qml +27 -0
- package/test/fixtures/qml/flea-theme/field.qml +21 -0
- package/test/fixtures/qml/flea-theme/imports/qs/Commons/BorderGeometry.js +373 -0
- package/test/fixtures/qml/flea-theme/imports/qs/Commons/Color.qml +258 -0
- package/test/fixtures/qml/flea-theme/imports/qs/Commons/I18n.qml +118 -0
- package/test/fixtures/qml/flea-theme/imports/qs/Commons/Numbers.js +19 -0
- package/test/fixtures/qml/flea-theme/imports/qs/Commons/Plural.js +91 -0
- package/test/fixtures/qml/flea-theme/imports/qs/Commons/Style.qml +561 -0
- package/test/fixtures/qml/flea-theme/imports/qs/Commons/Util.qml +188 -0
- package/test/fixtures/qml/flea-theme/imports/qs/Commons/qmldir +13 -0
- package/test/fixtures/qml/flea-theme/segment.qml +17 -0
- package/test/fixtures/qml/flea-theme/settings.qml +58 -0
- package/test/fixtures/qml/flea-theme/text-metrics.qml +10 -0
- package/test/fixtures/qml/flea-theme/ui/DialogButton.qml +150 -0
- package/test/fixtures/qml/flea-theme/ui/DialogField.qml +147 -0
- package/test/fixtures/qml/flea-theme/ui/EscapeHint.qml +11 -0
- package/test/fixtures/qml/flea-theme/ui/Glass.qml +114 -0
- package/test/fixtures/qml/flea-theme/ui/Glyph.qml +54 -0
- package/test/fixtures/qml/flea-theme/ui/GlyphSolid.qml +22 -0
- package/test/fixtures/qml/flea-theme/ui/Reveal.qml +54 -0
- package/test/fixtures/qml/flea-theme/ui/SettingsRuler.qml +85 -0
- package/test/fixtures/qml/flea-theme/ui/SettingsSegment.qml +85 -0
- package/test/fixtures/qml/flea-theme/ui/StableModel.qml +89 -0
- package/test/fixtures/qml/flea-theme/ui/Theme.qml +460 -0
- package/test/fixtures/qml/flea-theme/ui/ThemeColors.qml +43 -0
- package/test/fixtures/qml/flea-theme/ui/ViewState.qml +565 -0
- package/test/fixtures/qml/flea-theme/ui/js/Anchor.js +379 -0
- package/test/fixtures/qml/flea-theme/ui/js/AnchorHold.js +162 -0
- package/test/fixtures/qml/flea-theme/ui/js/Archive.js +157 -0
- package/test/fixtures/qml/flea-theme/ui/js/BackReturn.js +110 -0
- package/test/fixtures/qml/flea-theme/ui/js/Buttons.js +54 -0
- package/test/fixtures/qml/flea-theme/ui/js/ColumnMenu.js +111 -0
- package/test/fixtures/qml/flea-theme/ui/js/Columns.js +298 -0
- package/test/fixtures/qml/flea-theme/ui/js/Contrast.js +157 -0
- package/test/fixtures/qml/flea-theme/ui/js/Density.js +44 -0
- package/test/fixtures/qml/flea-theme/ui/js/DirSizes.js +129 -0
- package/test/fixtures/qml/flea-theme/ui/js/ExtThumbs.js +115 -0
- package/test/fixtures/qml/flea-theme/ui/js/Filter.js +284 -0
- package/test/fixtures/qml/flea-theme/ui/js/FolderSorts.js +108 -0
- package/test/fixtures/qml/flea-theme/ui/js/Format.js +305 -0
- package/test/fixtures/qml/flea-theme/ui/js/Icons.js +206 -0
- package/test/fixtures/qml/flea-theme/ui/js/Input.js +39 -0
- package/test/fixtures/qml/flea-theme/ui/js/KeyName.js +64 -0
- package/test/fixtures/qml/flea-theme/ui/js/Keymap.js +370 -0
- package/test/fixtures/qml/flea-theme/ui/js/Kinds.js +145 -0
- package/test/fixtures/qml/flea-theme/ui/js/Lists.js +11 -0
- package/test/fixtures/qml/flea-theme/ui/js/MakeDefault.js +186 -0
- package/test/fixtures/qml/flea-theme/ui/js/Match.js +27 -0
- package/test/fixtures/qml/flea-theme/ui/js/Material.js +109 -0
- package/test/fixtures/qml/flea-theme/ui/js/Menu.js +513 -0
- package/test/fixtures/qml/flea-theme/ui/js/Motion.js +16 -0
- package/test/fixtures/qml/flea-theme/ui/js/Mounts.js +320 -0
- package/test/fixtures/qml/flea-theme/ui/js/MouseNav.js +13 -0
- package/test/fixtures/qml/flea-theme/ui/js/Nav.js +328 -0
- package/test/fixtures/qml/flea-theme/ui/js/Palette.js +33 -0
- package/test/fixtures/qml/flea-theme/ui/js/Places.js +236 -0
- package/test/fixtures/qml/flea-theme/ui/js/Protocols.js +296 -0
- package/test/fixtures/qml/flea-theme/ui/js/RecentMode.js +154 -0
- package/test/fixtures/qml/flea-theme/ui/js/Search.js +396 -0
- package/test/fixtures/qml/flea-theme/ui/js/Settings.js +476 -0
- package/test/fixtures/qml/flea-theme/ui/js/SettingsAbout.js +99 -0
- package/test/fixtures/qml/flea-theme/ui/js/SettingsShelf.js +52 -0
- package/test/fixtures/qml/flea-theme/ui/js/Sort.js +127 -0
- package/test/fixtures/qml/flea-theme/ui/js/StateWords.js +42 -0
- package/test/fixtures/qml/flea-theme/ui/js/Swap.js +166 -0
- package/test/fixtures/qml/flea-theme/ui/js/TextSize.js +107 -0
- package/test/fixtures/qml/flea-theme/ui/js/Thumbs.js +158 -0
- package/test/fixtures/qml/flea-theme/ui/js/UiState.js +438 -0
- package/test/fixtures/qml/flea-theme/ui/js/Update.js +132 -0
- package/test/fixtures/qml/flea-theme/ui/js/UserDirs.js +56 -0
- package/test/fixtures/qml/flea-theme/ui/qmldir +227 -0
- package/test/fixtures/qml/hello.qml +26 -0
- package/test/fixtures/qml/imports/Demo/Toolkit/VersionLabel.qml +2 -0
- package/test/fixtures/qml/imports/Demo/Toolkit/VersionLabelNew.qml +2 -0
- package/test/fixtures/qml/imports/Demo/Toolkit/qmldir +3 -0
- package/test/fixtures/qml/imports/components/Badge.qml +15 -0
- package/test/fixtures/qml/imports/logic/base.js +2 -0
- package/test/fixtures/qml/imports/logic/counter.js +4 -0
- package/test/fixtures/qml/imports/logic/math.js +3 -0
- package/test/fixtures/qml/imports/logic/shared.js +3 -0
- package/test/fixtures/qml/imports/main.qml +21 -0
- package/test/fixtures/qml/imports/theme/Theme.qml +8 -0
- package/test/fixtures/qml/imports/theme/qmldir +2 -0
- package/test/fixtures/qml/multiply.qml +61 -0
- package/test/fixtures/qml-canvas-dom.js +90 -0
- package/test/fixtures/qml-fonts/main.qml +10 -0
- package/test/fixtures/qml-locale/check.mjs +6 -0
- package/test/fixtures/qml-locale/main.qml +8 -0
- package/test/fixtures/qml-media-audio.js +39 -0
- package/test/fixtures/qml-shader/grab.qml +14 -0
- package/test/fixtures/qml-shader/gradient.frag +5 -0
- package/test/fixtures/qml-shader/main.qml +14 -0
- package/test/fixtures/qml-shader/texture-grab.qml +25 -0
- package/test/fixtures/qml-shader/texture-size.frag +5 -0
- package/test/fixtures/qml-shader-check.mjs +24 -0
- package/test/fixtures/title-no-paint.js +20 -0
- package/test/helpers/flea-sandbox.js +48 -0
- package/test/helpers/quickshell-fixture.js +125 -0
- package/test/html-clipboard-wayland.test.js +47 -0
- package/test/index.test.js +13 -0
- package/test/manual-casty-without-qml.js +87 -0
- package/test/manual-double-click.html +21 -0
- package/test/manual-flea-application.js +49 -0
- package/test/manual-flea-binary.js +62 -0
- package/test/manual-flea-qml.js +9 -0
- package/test/manual-flea-settings.js +40 -0
- package/test/manual-flea-theme.js +40 -0
- package/test/manual-mouse-buttons.html +18 -0
- package/test/manual-omastorm-engine.mjs +19 -0
- package/test/manual-omastorm-shaders.mjs +28 -0
- package/test/manual-omastorm-software.mjs +25 -0
- package/test/manual-pointer-scroll.html +43 -0
- package/test/manual-qml-removal.js +46 -0
- package/test/manual-without-qml.js +45 -0
- package/test/pointer-drag.test.js +104 -0
- package/test/qml-canvas-dom.test.js +37 -0
- package/test/qml-canvas.test.js +21 -0
- package/test/qml-clipboard-bridge.test.js +25 -0
- package/test/qml-clipboard-wayland.test.js +40 -0
- package/test/qml-connections-timing.test.js +95 -0
- package/test/qml-controls-window.test.js +182 -0
- package/test/qml-dynamic.test.js +401 -0
- package/test/qml-flea-app.test.js +146 -0
- package/test/qml-flea-backend.test.js +78 -0
- package/test/qml-flea-columns-backend.test.js +38 -0
- package/test/qml-flea-compile.test.js +78 -0
- package/test/qml-flea-launcher.test.js +88 -0
- package/test/qml-flea-markdown-backend.test.js +31 -0
- package/test/qml-flea-media.test.js +28 -0
- package/test/qml-flea-navigation-backend.test.js +35 -0
- package/test/qml-flea-navigation-timing.test.js +147 -0
- package/test/qml-flea-preview-backend.test.js +53 -0
- package/test/qml-flea-previews.test.js +163 -0
- package/test/qml-flea-rows.test.js +101 -0
- package/test/qml-flea-textures.test.js +59 -0
- package/test/qml-flea-view-switch.test.js +33 -0
- package/test/qml-flea-wayland.test.js +68 -0
- package/test/qml-flea.test.js +34 -0
- package/test/qml-fonts.test.js +31 -0
- package/test/qml-grid-multiline.test.js +48 -0
- package/test/qml-host.test.js +238 -0
- package/test/qml-imports.test.js +102 -0
- package/test/qml-inherited-handlers.test.js +51 -0
- package/test/qml-input-selection.test.js +66 -0
- package/test/qml-interactions.test.js +309 -0
- package/test/qml-language.test.js +167 -0
- package/test/qml-launcher.test.js +54 -0
- package/test/qml-layout-text.test.js +205 -0
- package/test/qml-locale.test.js +45 -0
- package/test/qml-media.test.js +63 -0
- package/test/qml-nonvisual-visible.test.js +19 -0
- package/test/qml-persisted-delegates.test.js +45 -0
- package/test/qml-quickshell-controls.test.js +65 -0
- package/test/qml-quickshell-settings.test.js +62 -0
- package/test/qml-repeater.test.js +72 -0
- package/test/qml-shader-runtime.test.js +6 -0
- package/test/qml-shortcuts.test.js +39 -0
- package/test/qml-socket.test.js +60 -0
- package/test/qml-software-shader.test.js +55 -0
- package/test/qml-style-updates.test.js +124 -0
- package/test/qml-textures.test.js +66 -0
- package/test/qml-views.test.js +332 -0
- package/test/qml-window-update.test.js +36 -0
- package/test/qml-worker.test.js +69 -0
- package/test/qml.test.js +83 -0
- package/test/render-interval.test.js +33 -0
- package/test/renderer-host.test.js +11 -0
- package/test/text-input-pointer.test.js +31 -0
- package/test/text-input-scroll.test.js +29 -0
- package/test/text-input.test.js +47 -0
- package/test/title-no-paint.test.js +6 -0
- package/test/wayland-frontend.test.js +83 -0
- package/test/wayland-scroll.test.js +40 -0
- package/test/wayland-urlbar.test.js +61 -0
|
@@ -0,0 +1,381 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Parser,
|
|
3
|
+
parse,
|
|
4
|
+
parseExpressionAt,
|
|
5
|
+
tokenizer,
|
|
6
|
+
} from '../../vendor/acorn/dist/acorn.mjs';
|
|
7
|
+
|
|
8
|
+
// Small, strict QML subset. Acorn owns JavaScript tokenization/parsing, including
|
|
9
|
+
// strings, comments, regexes and template literals; unsupported QML fails loudly.
|
|
10
|
+
export function parseQml(source) {
|
|
11
|
+
// Preserve offsets while Acorn parses QML's cast operator as a binary operator.
|
|
12
|
+
// The compiler recognizes the original 'as' spelling and emits a checked cast.
|
|
13
|
+
const js = (code) => {
|
|
14
|
+
const parts = [...tokenizer(code, { ecmaVersion: 'latest' })];
|
|
15
|
+
for (let n = parts.length - 2; n >= 0; n--) {
|
|
16
|
+
const t = parts[n],
|
|
17
|
+
next = parts[n + 1];
|
|
18
|
+
if (
|
|
19
|
+
code.slice(t.start, t.end) === 'as' &&
|
|
20
|
+
/^[A-Z]/.test(code.slice(next.start, next.end))
|
|
21
|
+
)
|
|
22
|
+
code = code.slice(0, t.start) + 'in' + code.slice(t.end);
|
|
23
|
+
}
|
|
24
|
+
return code;
|
|
25
|
+
};
|
|
26
|
+
if (source.length > 256 * 1024)
|
|
27
|
+
throw new SyntaxError('QML experiment: source exceeds 256 KiB');
|
|
28
|
+
const tokens = [...tokenizer(source, { ecmaVersion: 'latest' })];
|
|
29
|
+
const javascriptSource = js(source);
|
|
30
|
+
let i = 0,
|
|
31
|
+
count = 0;
|
|
32
|
+
const text = () => source.slice(tokens[i]?.start, tokens[i]?.end);
|
|
33
|
+
const fail = (message) => {
|
|
34
|
+
throw new SyntaxError(
|
|
35
|
+
`QML: ${message} at offset ${tokens[i]?.start ?? source.length}`,
|
|
36
|
+
);
|
|
37
|
+
};
|
|
38
|
+
const take = (value) => {
|
|
39
|
+
if (text() !== value) fail(`expected ${value}, got ${text()}`);
|
|
40
|
+
i++;
|
|
41
|
+
};
|
|
42
|
+
const name = () => {
|
|
43
|
+
if (!/^[A-Za-z_$][\w$]*$/.test(text())) fail('expected identifier');
|
|
44
|
+
let result = text();
|
|
45
|
+
i++;
|
|
46
|
+
while (text() === '.') {
|
|
47
|
+
i++;
|
|
48
|
+
result += '.' + text();
|
|
49
|
+
i++;
|
|
50
|
+
}
|
|
51
|
+
return result;
|
|
52
|
+
};
|
|
53
|
+
const imports = [],
|
|
54
|
+
pragmas = [];
|
|
55
|
+
while (text() === 'pragma') {
|
|
56
|
+
const start = tokens[i++].end;
|
|
57
|
+
while (
|
|
58
|
+
i < tokens.length &&
|
|
59
|
+
!/[\r\n]/.test(source.slice(start, tokens[i].start)) &&
|
|
60
|
+
text() !== ';'
|
|
61
|
+
)
|
|
62
|
+
i++;
|
|
63
|
+
pragmas.push(source.slice(start, tokens[i - 1]?.end ?? start).trim());
|
|
64
|
+
if (text() === ';') i++;
|
|
65
|
+
}
|
|
66
|
+
while (text() === 'import') {
|
|
67
|
+
const start = tokens[i++].end;
|
|
68
|
+
while (
|
|
69
|
+
i < tokens.length &&
|
|
70
|
+
!/[\r\n]/.test(source.slice(start, tokens[i].start)) &&
|
|
71
|
+
text() !== ';'
|
|
72
|
+
)
|
|
73
|
+
i++;
|
|
74
|
+
imports.push(source.slice(start, tokens[i - 1]?.end ?? start).trim());
|
|
75
|
+
if (text() === ';') i++;
|
|
76
|
+
}
|
|
77
|
+
function object(depth = 0) {
|
|
78
|
+
if (depth > 64 || ++count > 2000) fail('object limit exceeded');
|
|
79
|
+
const type = name();
|
|
80
|
+
let bindingTarget = null;
|
|
81
|
+
if (text() === 'on') {
|
|
82
|
+
i++;
|
|
83
|
+
bindingTarget = name();
|
|
84
|
+
}
|
|
85
|
+
take('{');
|
|
86
|
+
const properties = [],
|
|
87
|
+
children = [],
|
|
88
|
+
components = [];
|
|
89
|
+
while (i < tokens.length && text() !== '}') {
|
|
90
|
+
if (text() === ';') {
|
|
91
|
+
i++;
|
|
92
|
+
continue;
|
|
93
|
+
}
|
|
94
|
+
if (text() === 'component') {
|
|
95
|
+
i++;
|
|
96
|
+
const componentName = name();
|
|
97
|
+
take(':');
|
|
98
|
+
components.push({ name: componentName, object: object(depth + 1) });
|
|
99
|
+
continue;
|
|
100
|
+
}
|
|
101
|
+
let afterName = i + 1;
|
|
102
|
+
while (tokens[afterName]?.type.label === '.') afterName += 2;
|
|
103
|
+
if (
|
|
104
|
+
tokens[afterName]?.type.label === '{' ||
|
|
105
|
+
source.slice(tokens[afterName]?.start, tokens[afterName]?.end) === 'on'
|
|
106
|
+
) {
|
|
107
|
+
const child = object(depth + 1);
|
|
108
|
+
if (/^[a-z]/.test(child.type)) {
|
|
109
|
+
if (child.children.length || child.components.length)
|
|
110
|
+
fail('unsupported nested property group');
|
|
111
|
+
for (const p of child.properties)
|
|
112
|
+
properties.push({ ...p, key: child.type + '.' + p.key });
|
|
113
|
+
} else children.push(child);
|
|
114
|
+
continue;
|
|
115
|
+
}
|
|
116
|
+
if (text() === 'function') {
|
|
117
|
+
const start = tokens[i].start;
|
|
118
|
+
// Acorn parses the complete remaining JS prefix; QML's outer closing
|
|
119
|
+
// brace is not JavaScript, so locate the function body with tokens first.
|
|
120
|
+
let params = i;
|
|
121
|
+
while (params < tokens.length && tokens[params].type.label !== '(')
|
|
122
|
+
params++;
|
|
123
|
+
let endParams = params,
|
|
124
|
+
paren = 0;
|
|
125
|
+
do {
|
|
126
|
+
const label = tokens[endParams++]?.type.label;
|
|
127
|
+
if (label === '(') paren++;
|
|
128
|
+
if (label === ')') paren--;
|
|
129
|
+
} while (endParams < tokens.length && paren);
|
|
130
|
+
let body = endParams;
|
|
131
|
+
while (body < tokens.length && tokens[body].type.label !== '{') body++;
|
|
132
|
+
if (body === tokens.length) fail('missing function body');
|
|
133
|
+
let j = body,
|
|
134
|
+
level = 0;
|
|
135
|
+
do {
|
|
136
|
+
const label = tokens[j++]?.type.label;
|
|
137
|
+
if (label === '{' || label === '${') level++;
|
|
138
|
+
if (label === '}') level--;
|
|
139
|
+
} while (j < tokens.length && level);
|
|
140
|
+
let code = source.slice(start, tokens[j - 1].end);
|
|
141
|
+
// Erase QML annotations only at parameter/return-type positions. Braces
|
|
142
|
+
// in destructuring and default values are JavaScript, not the body.
|
|
143
|
+
const erase = (from, to) => {
|
|
144
|
+
code =
|
|
145
|
+
code.slice(0, from - start) +
|
|
146
|
+
' '.repeat(to - from) +
|
|
147
|
+
code.slice(to - start);
|
|
148
|
+
};
|
|
149
|
+
let depth = 0,
|
|
150
|
+
braces = 0,
|
|
151
|
+
brackets = 0,
|
|
152
|
+
hasDefault = false;
|
|
153
|
+
for (let at = params; at < endParams; at++) {
|
|
154
|
+
const label = tokens[at].type.label;
|
|
155
|
+
if (label === '(') depth++;
|
|
156
|
+
else if (label === ')') depth--;
|
|
157
|
+
else if (label === '{' || label === '${') braces++;
|
|
158
|
+
else if (label === '}') braces--;
|
|
159
|
+
else if (label === '[') brackets++;
|
|
160
|
+
else if (label === ']') brackets--;
|
|
161
|
+
if (depth !== 1 || braces || brackets) continue;
|
|
162
|
+
if (label === ',') hasDefault = false;
|
|
163
|
+
if (label === '=') hasDefault = true;
|
|
164
|
+
if (label === ':' && !hasDefault) {
|
|
165
|
+
let end = at + 1;
|
|
166
|
+
while (
|
|
167
|
+
end < endParams &&
|
|
168
|
+
!['=', ',', ')'].includes(tokens[end].type.label)
|
|
169
|
+
)
|
|
170
|
+
end++;
|
|
171
|
+
erase(tokens[at].start, tokens[end].start);
|
|
172
|
+
at = end - 1;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
if (tokens[endParams]?.type.label === ':')
|
|
176
|
+
erase(tokens[endParams].start, tokens[body].start);
|
|
177
|
+
const ast = parse(js(code), { ecmaVersion: 'latest' });
|
|
178
|
+
if (ast.body.length !== 1 || ast.body[0].type !== 'FunctionDeclaration')
|
|
179
|
+
fail('invalid function');
|
|
180
|
+
properties.push({ key: ast.body[0].id.name, code, ast, method: true });
|
|
181
|
+
i = j;
|
|
182
|
+
continue;
|
|
183
|
+
}
|
|
184
|
+
if (text() === 'signal') {
|
|
185
|
+
i++;
|
|
186
|
+
const key = name();
|
|
187
|
+
const args = [];
|
|
188
|
+
if (text() !== '(') {
|
|
189
|
+
properties.push({ key, signal: true, args });
|
|
190
|
+
continue;
|
|
191
|
+
}
|
|
192
|
+
take('(');
|
|
193
|
+
while (text() !== ')') {
|
|
194
|
+
const type = name(),
|
|
195
|
+
argument = name();
|
|
196
|
+
args.push(argument);
|
|
197
|
+
if (text() === ',') i++;
|
|
198
|
+
else break;
|
|
199
|
+
}
|
|
200
|
+
take(')');
|
|
201
|
+
properties.push({ key, signal: true, args });
|
|
202
|
+
continue;
|
|
203
|
+
}
|
|
204
|
+
let custom = false,
|
|
205
|
+
propertyType = null,
|
|
206
|
+
readonly = false,
|
|
207
|
+
required = false,
|
|
208
|
+
defaultProperty = false;
|
|
209
|
+
if (text() === 'default') {
|
|
210
|
+
defaultProperty = true;
|
|
211
|
+
i++;
|
|
212
|
+
}
|
|
213
|
+
if (text() === 'required') {
|
|
214
|
+
required = true;
|
|
215
|
+
i++;
|
|
216
|
+
}
|
|
217
|
+
if (text() === 'readonly') {
|
|
218
|
+
readonly = true;
|
|
219
|
+
i++;
|
|
220
|
+
}
|
|
221
|
+
if (
|
|
222
|
+
text() === 'property' &&
|
|
223
|
+
source.slice(tokens[i + 1]?.start, tokens[i + 1]?.end) !== ':'
|
|
224
|
+
) {
|
|
225
|
+
i++;
|
|
226
|
+
custom = true;
|
|
227
|
+
propertyType = name();
|
|
228
|
+
}
|
|
229
|
+
const key = name();
|
|
230
|
+
if (custom && text() !== ':') {
|
|
231
|
+
const code = required
|
|
232
|
+
? 'undefined'
|
|
233
|
+
: ({
|
|
234
|
+
int: '0',
|
|
235
|
+
real: '0',
|
|
236
|
+
double: '0',
|
|
237
|
+
bool: 'false',
|
|
238
|
+
string: '""',
|
|
239
|
+
url: '""',
|
|
240
|
+
var: 'undefined',
|
|
241
|
+
point: '({x:0,y:0})',
|
|
242
|
+
size: '({width:0,height:0})',
|
|
243
|
+
rect: '({x:0,y:0,width:0,height:0})',
|
|
244
|
+
color: '"transparent"',
|
|
245
|
+
}[propertyType] ?? 'null');
|
|
246
|
+
properties.push({
|
|
247
|
+
key,
|
|
248
|
+
custom,
|
|
249
|
+
propertyType,
|
|
250
|
+
required,
|
|
251
|
+
readonly,
|
|
252
|
+
defaultProperty,
|
|
253
|
+
code,
|
|
254
|
+
ast: parseExpressionAt(code, 0, { ecmaVersion: 'latest' }),
|
|
255
|
+
});
|
|
256
|
+
continue;
|
|
257
|
+
}
|
|
258
|
+
take(':');
|
|
259
|
+
let objectEnd = i + 1;
|
|
260
|
+
while (tokens[objectEnd]?.type.label === '.') objectEnd += 2;
|
|
261
|
+
if (
|
|
262
|
+
/^[A-Za-z_$][\w$]*$/.test(text()) &&
|
|
263
|
+
tokens[objectEnd]?.type.label === '{'
|
|
264
|
+
) {
|
|
265
|
+
properties.push({
|
|
266
|
+
key,
|
|
267
|
+
custom,
|
|
268
|
+
propertyType,
|
|
269
|
+
readonly,
|
|
270
|
+
required,
|
|
271
|
+
defaultProperty,
|
|
272
|
+
object: object(depth + 1),
|
|
273
|
+
});
|
|
274
|
+
continue;
|
|
275
|
+
}
|
|
276
|
+
const start = tokens[i]?.start;
|
|
277
|
+
if (start === undefined) fail('missing value');
|
|
278
|
+
let ast,
|
|
279
|
+
end,
|
|
280
|
+
block = false;
|
|
281
|
+
if (
|
|
282
|
+
/^(?:.*\.)?on[A-Z_]/.test(key) &&
|
|
283
|
+
[
|
|
284
|
+
'if',
|
|
285
|
+
'for',
|
|
286
|
+
'while',
|
|
287
|
+
'do',
|
|
288
|
+
'switch',
|
|
289
|
+
'try',
|
|
290
|
+
'throw',
|
|
291
|
+
'return',
|
|
292
|
+
].includes(text())
|
|
293
|
+
) {
|
|
294
|
+
const parser = new Parser(
|
|
295
|
+
{ ecmaVersion: 'latest', allowReturnOutsideFunction: true },
|
|
296
|
+
javascriptSource,
|
|
297
|
+
start,
|
|
298
|
+
);
|
|
299
|
+
parser.nextToken();
|
|
300
|
+
const statement = parser.parseStatement(null);
|
|
301
|
+
end = statement.end;
|
|
302
|
+
const code = '{' + source.slice(start, end) + '}';
|
|
303
|
+
ast = parse(js(code), {
|
|
304
|
+
ecmaVersion: 'latest',
|
|
305
|
+
allowReturnOutsideFunction: true,
|
|
306
|
+
});
|
|
307
|
+
properties.push({
|
|
308
|
+
key,
|
|
309
|
+
custom,
|
|
310
|
+
propertyType,
|
|
311
|
+
code,
|
|
312
|
+
ast,
|
|
313
|
+
block: true,
|
|
314
|
+
readonly,
|
|
315
|
+
defaultProperty,
|
|
316
|
+
});
|
|
317
|
+
while (tokens[i]?.start < end) i++;
|
|
318
|
+
continue;
|
|
319
|
+
}
|
|
320
|
+
if (text() === '{') {
|
|
321
|
+
block = true;
|
|
322
|
+
let nesting = 0,
|
|
323
|
+
j = i;
|
|
324
|
+
do {
|
|
325
|
+
const label = tokens[j]?.type.label;
|
|
326
|
+
if (label === '{' || label === '${') nesting++;
|
|
327
|
+
if (label === '}') nesting--;
|
|
328
|
+
j++;
|
|
329
|
+
} while (j < tokens.length && nesting);
|
|
330
|
+
if (nesting) fail('unterminated block');
|
|
331
|
+
end = tokens[j - 1].end;
|
|
332
|
+
const body = source.slice(start, end);
|
|
333
|
+
let literal;
|
|
334
|
+
if (!/^(?:.*\.)?on[A-Z_]/.test(key))
|
|
335
|
+
try {
|
|
336
|
+
literal = parseExpressionAt(js(body), 0, { ecmaVersion: 'latest' });
|
|
337
|
+
} catch {}
|
|
338
|
+
if (
|
|
339
|
+
literal?.type === 'ObjectExpression' &&
|
|
340
|
+
literal.end === body.length
|
|
341
|
+
) {
|
|
342
|
+
ast = literal;
|
|
343
|
+
block = false;
|
|
344
|
+
} else
|
|
345
|
+
ast = parse(js(body), {
|
|
346
|
+
ecmaVersion: 'latest',
|
|
347
|
+
allowReturnOutsideFunction: true,
|
|
348
|
+
});
|
|
349
|
+
} else {
|
|
350
|
+
ast = parseExpressionAt(javascriptSource, start, {
|
|
351
|
+
ecmaVersion: 'latest',
|
|
352
|
+
preserveParens: true,
|
|
353
|
+
});
|
|
354
|
+
end = ast.end;
|
|
355
|
+
}
|
|
356
|
+
const code = source.slice(start, end);
|
|
357
|
+
// Normalize offsets to each expression for the compiler's identifier rewrite.
|
|
358
|
+
if (!block)
|
|
359
|
+
ast = parseExpressionAt(js(code), 0, {
|
|
360
|
+
ecmaVersion: 'latest',
|
|
361
|
+
preserveParens: true,
|
|
362
|
+
});
|
|
363
|
+
properties.push({
|
|
364
|
+
key,
|
|
365
|
+
custom,
|
|
366
|
+
propertyType,
|
|
367
|
+
code,
|
|
368
|
+
ast,
|
|
369
|
+
block,
|
|
370
|
+
readonly,
|
|
371
|
+
defaultProperty,
|
|
372
|
+
});
|
|
373
|
+
while (tokens[i]?.start < end) i++;
|
|
374
|
+
}
|
|
375
|
+
take('}');
|
|
376
|
+
return { type, properties, children, components, bindingTarget };
|
|
377
|
+
}
|
|
378
|
+
const root = object();
|
|
379
|
+
if (i !== tokens.length) fail('unexpected trailing input');
|
|
380
|
+
return { imports, pragmas, root };
|
|
381
|
+
}
|
package/lib/qml/qs
ADDED
package/lib/qml/qscasty
ADDED
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
// Serialized into the existing page realm; no host callbacks or native APIs.
|
|
2
|
+
export function createReactive() {
|
|
3
|
+
let revision = 0;
|
|
4
|
+
let active = null,
|
|
5
|
+
pending = new Set(),
|
|
6
|
+
scheduled = false;
|
|
7
|
+
let invalidationDepth = 0, drainingSync = false;
|
|
8
|
+
const synchronous = new Set();
|
|
9
|
+
const track = new WeakMap(),
|
|
10
|
+
raw = new WeakMap();
|
|
11
|
+
const mark = (job) => {
|
|
12
|
+
if (job.stopped || job.dirty || job.running) return;
|
|
13
|
+
job.dirty = true;
|
|
14
|
+
pending.add(job);
|
|
15
|
+
if (job.sync) synchronous.add(job);
|
|
16
|
+
job.invalidate?.();
|
|
17
|
+
};
|
|
18
|
+
const invalidate = (target, key) => {
|
|
19
|
+
invalidationDepth++;
|
|
20
|
+
try {
|
|
21
|
+
for (const job of track.get(raw.get(target) ?? target)?.get(key) ?? []) mark(job);
|
|
22
|
+
} finally {
|
|
23
|
+
invalidationDepth--;
|
|
24
|
+
}
|
|
25
|
+
// Invalidate the whole dependency chain before synchronous observers read
|
|
26
|
+
// it. Their handlers may write more properties; drain without recursive
|
|
27
|
+
// Set iteration, while ordinary rendering effects remain batched.
|
|
28
|
+
if (invalidationDepth || drainingSync) return;
|
|
29
|
+
drainingSync = true;
|
|
30
|
+
try {
|
|
31
|
+
let passes = 0;
|
|
32
|
+
while (synchronous.size) {
|
|
33
|
+
if (++passes > 100) throw new Error('QML binding cycle');
|
|
34
|
+
const jobs = [...synchronous];
|
|
35
|
+
synchronous.clear();
|
|
36
|
+
for (const job of jobs) { pending.delete(job); run(job); }
|
|
37
|
+
}
|
|
38
|
+
} finally { drainingSync = false; }
|
|
39
|
+
};
|
|
40
|
+
const clean = (job) => {
|
|
41
|
+
for (const set of job.deps) set.delete(job);
|
|
42
|
+
job.deps.clear();
|
|
43
|
+
};
|
|
44
|
+
const run = (job) => {
|
|
45
|
+
if (job.stopped || !job.dirty) return;
|
|
46
|
+
if (job.running) throw Error('QML binding cycle');
|
|
47
|
+
job.dirty = false;
|
|
48
|
+
job.running = true;
|
|
49
|
+
clean(job);
|
|
50
|
+
const previous = active;
|
|
51
|
+
active = job;
|
|
52
|
+
try {
|
|
53
|
+
job.fn();
|
|
54
|
+
} catch (error) {
|
|
55
|
+
job.dirty = true;
|
|
56
|
+
throw error;
|
|
57
|
+
} finally {
|
|
58
|
+
job.running = false;
|
|
59
|
+
active = previous;
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
const flush = (allowIncomplete = false) => {
|
|
63
|
+
scheduled = false;
|
|
64
|
+
let passes = 0,
|
|
65
|
+
last;
|
|
66
|
+
while (pending.size) {
|
|
67
|
+
if (++passes > 100) throw new Error('QML binding cycle');
|
|
68
|
+
const jobs = [...pending],
|
|
69
|
+
failed = [];
|
|
70
|
+
pending.clear();
|
|
71
|
+
for (const job of jobs) {
|
|
72
|
+
if (job.running) {
|
|
73
|
+
pending.add(job);
|
|
74
|
+
continue;
|
|
75
|
+
}
|
|
76
|
+
try {
|
|
77
|
+
run(job);
|
|
78
|
+
} catch (error) {
|
|
79
|
+
if (error.qmlFatal) throw error;
|
|
80
|
+
last = error;
|
|
81
|
+
failed.push(job);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
if (failed.length && !pending.size) {
|
|
85
|
+
if (allowIncomplete) {
|
|
86
|
+
for (const job of failed) pending.add(job);
|
|
87
|
+
return last;
|
|
88
|
+
}
|
|
89
|
+
throw last;
|
|
90
|
+
}
|
|
91
|
+
for (const job of failed) pending.add(job);
|
|
92
|
+
if (pending.size && [...pending].every((job) => job.running)) return null;
|
|
93
|
+
}
|
|
94
|
+
return null;
|
|
95
|
+
};
|
|
96
|
+
const state = (initial, interceptSet) => {
|
|
97
|
+
const proxy = new Proxy(initial, {
|
|
98
|
+
get(target, key) {
|
|
99
|
+
if (active) {
|
|
100
|
+
let map = track.get(target);
|
|
101
|
+
if (!map) track.set(target, (map = new Map()));
|
|
102
|
+
let set = map.get(key);
|
|
103
|
+
if (!set) map.set(key, (set = new Set()));
|
|
104
|
+
set.add(active);
|
|
105
|
+
active.deps.add(set);
|
|
106
|
+
}
|
|
107
|
+
return target[key];
|
|
108
|
+
},
|
|
109
|
+
set(target, key, value) {
|
|
110
|
+
if (interceptSet?.(proxy, target, key, value)) return true;
|
|
111
|
+
// A setter may detach a binding even when its value does not change.
|
|
112
|
+
if (Object.hasOwn(target, key) && Object.is(target[key], value)) {
|
|
113
|
+
if (Object.getOwnPropertyDescriptor(target, key)?.set) target[key] = value;
|
|
114
|
+
return true;
|
|
115
|
+
}
|
|
116
|
+
target[key] = value;
|
|
117
|
+
revision++;
|
|
118
|
+
invalidate(target, key);
|
|
119
|
+
if (pending.size && !scheduled) {
|
|
120
|
+
scheduled = true;
|
|
121
|
+
queueMicrotask(flush);
|
|
122
|
+
}
|
|
123
|
+
return true;
|
|
124
|
+
},
|
|
125
|
+
});
|
|
126
|
+
raw.set(proxy, initial);
|
|
127
|
+
return proxy;
|
|
128
|
+
};
|
|
129
|
+
const effect = (fn, { sync = false } = {}) => {
|
|
130
|
+
const job = {
|
|
131
|
+
fn,
|
|
132
|
+
sync,
|
|
133
|
+
deps: new Set(),
|
|
134
|
+
stopped: false,
|
|
135
|
+
dirty: true,
|
|
136
|
+
running: false,
|
|
137
|
+
};
|
|
138
|
+
try {
|
|
139
|
+
run(job);
|
|
140
|
+
} catch (error) {
|
|
141
|
+
job.stopped = true;
|
|
142
|
+
clean(job);
|
|
143
|
+
pending.delete(job);
|
|
144
|
+
throw error;
|
|
145
|
+
}
|
|
146
|
+
const stop = () => {
|
|
147
|
+
job.stopped = true;
|
|
148
|
+
clean(job);
|
|
149
|
+
pending.delete(job);
|
|
150
|
+
synchronous.delete(job);
|
|
151
|
+
};
|
|
152
|
+
stop.run = () => run(job);
|
|
153
|
+
Object.defineProperty(stop, 'onInvalidate', {
|
|
154
|
+
set: (fn) => {
|
|
155
|
+
job.invalidate = fn;
|
|
156
|
+
},
|
|
157
|
+
});
|
|
158
|
+
Object.defineProperty(stop, 'dirty', {
|
|
159
|
+
get: () => job.dirty && !job.stopped,
|
|
160
|
+
});
|
|
161
|
+
return stop;
|
|
162
|
+
};
|
|
163
|
+
const untrack = (fn) => {
|
|
164
|
+
const previous = active;
|
|
165
|
+
active = null;
|
|
166
|
+
try {
|
|
167
|
+
return fn();
|
|
168
|
+
} finally {
|
|
169
|
+
active = previous;
|
|
170
|
+
}
|
|
171
|
+
};
|
|
172
|
+
return {
|
|
173
|
+
state,
|
|
174
|
+
effect,
|
|
175
|
+
flush,
|
|
176
|
+
untrack,
|
|
177
|
+
invalidate,
|
|
178
|
+
get revision() {
|
|
179
|
+
return revision;
|
|
180
|
+
},
|
|
181
|
+
};
|
|
182
|
+
}
|