qmlbox 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +106 -60
- package/dist/index.cjs +174 -10
- package/dist/index.d.cts +18 -3
- package/dist/index.d.ts +18 -3
- package/dist/index.js +171 -9
- package/package.json +2 -2
- package/wasm/qml_engine.js +1 -1
- package/wasm/qml_engine.wasm +0 -0
package/README.md
CHANGED
|
@@ -1,61 +1,36 @@
|
|
|
1
|
-
# qml-web-viewer
|
|
1
|
+
# qmlbox (`qml-web-viewer`)
|
|
2
2
|
|
|
3
|
-
Render interactive Qt Quick QML files and multi-file SDDM login themes in a browser. The TypeScript SDK writes each preview's files to an in-memory filesystem
|
|
3
|
+
Render interactive Qt Quick QML files and multi-file SDDM login themes in a browser. The TypeScript SDK writes each preview's files to an in-memory filesystem, and a single-threaded Qt 6.8.3 WebAssembly runtime renders them onto a canvas without `SharedArrayBuffer` or cross-origin isolation (`COOP`/`COEP`) headers.
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## Installation
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
### 1. Build the Qt WebAssembly runtime
|
|
10
|
-
|
|
11
|
-
Run this Docker Buildx command from the repository root.
|
|
12
|
-
|
|
13
|
-
```sh
|
|
14
|
-
docker buildx build --platform linux/amd64 --output type=local,dest=wasm .
|
|
15
|
-
```
|
|
16
|
-
|
|
17
|
-
For a local build, install the Qt **6.8.3** desktop and `wasm_singlethread` kits, CMake, Ninja, and the Emscripten SDK. Qt 6.8 uses Emscripten **3.1.56**. [Qt for WebAssembly toolchain documentation](https://doc.qt.io/qt-6.8/ja/wasm.html)
|
|
7
|
+
Install the package from npm:
|
|
18
8
|
|
|
19
9
|
```sh
|
|
20
|
-
|
|
21
|
-
./emsdk install 3.1.56
|
|
22
|
-
./emsdk activate 3.1.56
|
|
23
|
-
source ./emsdk_env.sh
|
|
24
|
-
cd /path/to/qml-web-viewer
|
|
25
|
-
|
|
26
|
-
/path/to/Qt/6.8.3/wasm_singlethread/bin/qt-cmake \
|
|
27
|
-
-S cpp -B build/wasm -G Ninja -DCMAKE_BUILD_TYPE=Release
|
|
28
|
-
cmake --build build/wasm
|
|
29
|
-
cmake --install build/wasm --prefix "$PWD/wasm"
|
|
30
|
-
```
|
|
31
|
-
|
|
32
|
-
Both builds put `qtloader.js`, `qml_engine.js`, and `qml_engine.wasm` in `wasm/`. The GitHub Actions workflow builds the same runtime, runs a Chromium smoke test, and uploads the runtime and npm tarball.
|
|
33
|
-
|
|
34
|
-
### 2. Build the npm package
|
|
35
|
-
|
|
36
|
-
```sh
|
|
37
|
-
npm ci
|
|
38
|
-
npm run typecheck
|
|
39
|
-
npm run build
|
|
40
|
-
npm pack
|
|
10
|
+
npm install qmlbox
|
|
41
11
|
```
|
|
42
12
|
|
|
43
|
-
|
|
13
|
+
### Copy the WebAssembly runtime assets
|
|
44
14
|
|
|
45
|
-
|
|
15
|
+
`qmlbox` ships the compiled Qt WebAssembly runtime (`qtloader.js`, `qml_engine.js`, and `qml_engine.wasm`) in `node_modules/qmlbox/wasm/`. Copy that directory to a static assets path served by your app (for example `public/qml-runtime/` in Vite or Next.js):
|
|
46
16
|
|
|
47
17
|
```sh
|
|
48
|
-
|
|
18
|
+
mkdir -p public/qml-runtime
|
|
19
|
+
cp node_modules/qmlbox/wasm/* public/qml-runtime/
|
|
49
20
|
```
|
|
50
21
|
|
|
51
|
-
|
|
22
|
+
Requirements when hosting the runtime:
|
|
23
|
+
- Serve `.wasm` files with the `application/wasm` MIME type.
|
|
24
|
+
- Point `wasmBaseUrl` to the URL where those three files are served (defaults to `"./wasm/"`).
|
|
25
|
+
- If hosted on a separate origin, enable CORS for the page origin.
|
|
26
|
+
- `Cross-Origin-Opener-Policy` / `Cross-Origin-Embedder-Policy` headers are **not** required.
|
|
52
27
|
|
|
53
|
-
##
|
|
28
|
+
## Quick Start
|
|
54
29
|
|
|
55
|
-
|
|
30
|
+
Give the mount element an explicit width and height, initialize `QmlViewer` in browser code, and call `renderCode()` or `renderThemeFiles()`.
|
|
56
31
|
|
|
57
32
|
```html
|
|
58
|
-
<div id="preview" style="width: 100%; height:
|
|
33
|
+
<div id="preview" style="width: 100%; height: 480px"></div>
|
|
59
34
|
```
|
|
60
35
|
|
|
61
36
|
```ts
|
|
@@ -64,16 +39,21 @@ import { QmlViewer, fromGitHubRepo } from "qmlbox";
|
|
|
64
39
|
const viewer = new QmlViewer({
|
|
65
40
|
container: document.querySelector<HTMLElement>("#preview")!,
|
|
66
41
|
wasmBaseUrl: "/qml-runtime/",
|
|
67
|
-
|
|
42
|
+
qmlVersion: "auto", // "auto" | "6.8" | "2.15" | "2.12" | "2.0"
|
|
43
|
+
onProgress: (percent) => console.log(`Qt runtime: ${percent}%`),
|
|
68
44
|
onError: (message) => console.warn(message),
|
|
69
45
|
sddmConfig: {
|
|
70
46
|
hostName: "preview",
|
|
71
47
|
users: [{ name: "demo", realName: "Demo User" }],
|
|
48
|
+
sessions: [
|
|
49
|
+
{ name: "Wayland", file: "wayland.desktop", type: "wayland" },
|
|
50
|
+
{ name: "X11", file: "x11.desktop", type: "x11" },
|
|
51
|
+
],
|
|
72
52
|
loginSucceeds: true,
|
|
73
53
|
},
|
|
74
54
|
});
|
|
75
55
|
|
|
76
|
-
|
|
56
|
+
// Render inline QML
|
|
77
57
|
await viewer.renderCode(`
|
|
78
58
|
import QtQuick
|
|
79
59
|
import QtQuick.Controls
|
|
@@ -82,40 +62,106 @@ await viewer.renderCode(`
|
|
|
82
62
|
color: "#172133"
|
|
83
63
|
Button {
|
|
84
64
|
anchors.centerIn: parent
|
|
85
|
-
text: "
|
|
86
|
-
onClicked:
|
|
65
|
+
text: "Hello, " + userModel.lastUser
|
|
66
|
+
onClicked: sddm.login(userModel.lastUser, "", sessionModel.lastIndex)
|
|
87
67
|
}
|
|
88
68
|
}
|
|
89
69
|
`);
|
|
90
70
|
|
|
71
|
+
// Or load and render a multi-file SDDM theme from GitHub
|
|
91
72
|
const files = await fromGitHubRepo(
|
|
92
73
|
"https://github.com/sddm/sddm/tree/develop/data/themes/maldives",
|
|
93
74
|
{ ref: "develop", subdirectory: "data/themes/maldives" },
|
|
94
75
|
);
|
|
95
76
|
await viewer.renderThemeFiles(files);
|
|
96
77
|
|
|
97
|
-
//
|
|
78
|
+
// Clean up when unmounting
|
|
98
79
|
viewer.destroy();
|
|
99
80
|
```
|
|
100
81
|
|
|
101
|
-
|
|
82
|
+
> **Framework / SSR note (Next.js, React, Vue):** `QmlViewer` creates an `<iframe>` and loads WebAssembly in the browser. Instantiate it inside client-only code (such as `useEffect` in React) and call `viewer.destroy()` in the cleanup callback.
|
|
83
|
+
|
|
84
|
+
## API Overview
|
|
85
|
+
|
|
86
|
+
### `new QmlViewer(options)`
|
|
87
|
+
|
|
88
|
+
| Option | Type | Default | Description |
|
|
89
|
+
| --- | --- | --- | --- |
|
|
90
|
+
| `container` | `HTMLElement` | required | Container element that hosts the viewer `<iframe>`. Must have non-zero size. |
|
|
91
|
+
| `wasmBaseUrl` | `string` | `"./wasm/"` | Base URL containing `qtloader.js`, `qml_engine.js`, and `qml_engine.wasm`. |
|
|
92
|
+
| `qmlVersion` | `QmlVersion` | `"auto"` | Target QML import version (`"auto"`, `"6.8"`, `"6"`, `"2.15"`, `"2.12"`, `"2.0"`). |
|
|
93
|
+
| `sddmConfig` | `SddmMockConfig` | default mock user/sessions | Mock `sddm`, `userModel`, `sessionModel`, and `config` values. |
|
|
94
|
+
| `maxPixelRatio` | `number` | `2` | Upper bound for `devicePixelRatio` inside the preview frame. |
|
|
95
|
+
| `onProgress` | `(percent: number) => void` | — | Download/compilation progress callback (`0`–`100`). |
|
|
96
|
+
| `onError` | `(message: string) => void` | — | Receives QML compile/runtime warnings and load errors. |
|
|
97
|
+
|
|
98
|
+
### Viewer Methods
|
|
99
|
+
- `viewer.init(): Promise<void>` — Pre-loads the Qt WebAssembly runtime (called automatically on first render).
|
|
100
|
+
- `viewer.renderCode(qmlSource, qmlVersion?): Promise<void>` — Renders a standalone QML string as `Main.qml`.
|
|
101
|
+
- `viewer.renderThemeFiles(files, entryOrOptions?): Promise<void>` — Renders a multi-file theme map (`Record<string, Uint8Array | string>`). Accepts either an explicit entry filename string or `{ entryFile?, qmlVersion? }`.
|
|
102
|
+
- `viewer.setQmlVersion(version)` / `viewer.getQmlVersion()` — Gets or updates the default `QmlVersion` used on subsequent renders.
|
|
103
|
+
- `viewer.setSddmConfig(config)` — Updates mock users, sessions, power capabilities, config overrides, and login outcome.
|
|
104
|
+
- `viewer.destroy(): void` — Shuts down the Qt runtime and removes the preview `<iframe>`.
|
|
105
|
+
|
|
106
|
+
### Input Loaders
|
|
107
|
+
|
|
108
|
+
| Input | Loader | Notes |
|
|
109
|
+
| --- | --- | --- |
|
|
110
|
+
| QML text | `fromCodeString(source)` | Creates `{ "Main.qml": Uint8Array }`. |
|
|
111
|
+
| Single `.qml` file | `await fromSingleFile(file)` | Reads a browser `File`. |
|
|
112
|
+
| Folder picker | `await fromFolderInput(input.files)` | Strips a shared root folder from `<input webkitdirectory>`. |
|
|
113
|
+
| ZIP archive | `await fromZipFile(file)` | Unpacks up to 4,096 files / 128 MiB with `fflate`. |
|
|
114
|
+
| GitHub repository / folder URL | `await fromGitHubRepo(url, options?)` | Reads the Git tree and downloads public blobs from `raw.githubusercontent.com` (pass `{ ref, subdirectory, token, signal }`). |
|
|
115
|
+
|
|
116
|
+
### SDDM Theme Resolution & Helpers
|
|
117
|
+
* `renderThemeFiles()` reads `metadata.desktop` (`MainScript` and `ConfigFile`), defaulting to `Main.qml` and `theme.conf` (or the first `.conf` file found if the declared `ConfigFile` is missing), merges `<config>.user`, and applies `sddmConfig.config` overrides.
|
|
118
|
+
* `parseIni` and `parseThemeConfig` are exported for parsing `.conf` / `.desktop` files directly.
|
|
119
|
+
* `SUPPORTED_QML_VERSIONS` and `transformQmlImports(source, version)` are exported for inspecting or rewriting QML import versions.
|
|
120
|
+
|
|
121
|
+
## Supported Qt Modules, QML Versions & Shims
|
|
122
|
+
|
|
123
|
+
The runtime is built on **Qt 6.8.3** (`wasm_singlethread`) and supports:
|
|
124
|
+
* **Qt modules:** `QtQuick`, `QtQuick.Window`, `QtQuick.Controls` (`Basic` style), `QtQuick.Layouts`, `QtQuick.Shapes`, `QtQuick.Effects`, `QtQml.Models`, `QtQml.WorkerScript`, and SVG image support (`Qt6::QSvgPlugin`).
|
|
125
|
+
* **QML versions:** Choose `"auto"` to preserve a file's existing imports (Qt 6 unversioned or QtQuick `2.x`), `"6.8"`/`"6"` to normalize standard Qt imports to unversioned Qt 6 / `Qt5Compat.GraphicalEffects`, or `"2.15"` / `"2.12"` / `"2.0"` to target QtQuick `2.x` module versions.
|
|
126
|
+
* **Bundled shims & SDDM mocks:**
|
|
127
|
+
* Mock SDDM globals: `sddm`, `userModel`, `sessionModel`, `config`, `keyboard`, `screenModel`, and `primaryScreen`.
|
|
128
|
+
* `SddmComponents 2.0`
|
|
129
|
+
* `org.kde.plasma.components` (`2.0` / `3.0`: `Button`, `TextField`, `Label`) and `org.kde.plasma.core` (`2.0`: `Theme`, `Units`, `IconItem`)
|
|
130
|
+
* `Qt5Compat.GraphicalEffects` & `QtGraphicalEffects` (`FastBlur`, `GaussianBlur`, `ColorOverlay`, `DropShadow`, `Glow`, `OpacityMask`, `ThresholdMask`, `BrightnessContrast`, `Desaturate`, `Colorize`, `HueSaturation`, `LinearGradient`, `RadialGradient`, `RectangularGlow`)
|
|
131
|
+
* `QtMultimedia` (`MediaPlayer`, `VideoOutput`, `AudioOutput`, `MediaDevices` — renders image/GIF backgrounds and safely stubs video containers without crashing)
|
|
132
|
+
* `QtQuick.VirtualKeyboard` (`InputPanel` on-screen keyboard)
|
|
133
|
+
|
|
134
|
+
## Building from Source
|
|
135
|
+
|
|
136
|
+
Use Node.js 22 or later for the TypeScript SDK and playground.
|
|
102
137
|
|
|
103
|
-
|
|
138
|
+
### 1. Build the Qt WebAssembly runtime
|
|
104
139
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
| Browser QML file | `await fromSingleFile(file)` |
|
|
109
|
-
| Folder picker | `await fromFolderInput(input.files)` |
|
|
110
|
-
| ZIP archive | `await fromZipFile(file)` |
|
|
111
|
-
| GitHub repository or folder URL | `await fromGitHubRepo(url, options)` |
|
|
140
|
+
```sh
|
|
141
|
+
docker buildx build --platform linux/amd64 --output type=local,dest=wasm .
|
|
142
|
+
```
|
|
112
143
|
|
|
113
|
-
|
|
144
|
+
For a local build without Docker, install Qt **6.8.3** (`gcc_64` and `wasm_singlethread`), CMake, Ninja, and Emscripten **3.1.56** ([Qt for WebAssembly docs](https://doc.qt.io/qt-6.8/wasm.html)):
|
|
114
145
|
|
|
115
|
-
|
|
146
|
+
```sh
|
|
147
|
+
/path/to/Qt/6.8.3/wasm_singlethread/bin/qt-cmake \
|
|
148
|
+
-S cpp -B build/wasm -G Ninja -DCMAKE_BUILD_TYPE=Release \
|
|
149
|
+
-DQT_HOST_PATH=/path/to/Qt/6.8.3/gcc_64
|
|
150
|
+
cmake --build build/wasm
|
|
151
|
+
cmake --install build/wasm --prefix "$PWD/wasm"
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
### 2. Build and run locally
|
|
155
|
+
|
|
156
|
+
```sh
|
|
157
|
+
npm ci
|
|
158
|
+
npm run typecheck
|
|
159
|
+
npm run build
|
|
160
|
+
npm run dev
|
|
161
|
+
```
|
|
116
162
|
|
|
117
|
-
|
|
163
|
+
Open `http://localhost:5173/example/` to use the local playground.
|
|
118
164
|
|
|
119
165
|
## License
|
|
120
166
|
|
|
121
|
-
|
|
167
|
+
This project is licensed under **GPL-3.0-only**. The Qt WebAssembly platform plugin is available under GPL-3.0-only or a Qt commercial license. Bundled SDDM QML components retain their original MIT notices. [Qt 6.8.3 sources](https://download.qt.io/archive/qt/6.8/6.8.3/single/) · [SDDM sources](https://github.com/sddm/sddm)
|
package/dist/index.cjs
CHANGED
|
@@ -21,13 +21,15 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
21
21
|
var index_exports = {};
|
|
22
22
|
__export(index_exports, {
|
|
23
23
|
QmlViewer: () => QmlViewer,
|
|
24
|
+
SUPPORTED_QML_VERSIONS: () => SUPPORTED_QML_VERSIONS,
|
|
24
25
|
fromCodeString: () => fromCodeString,
|
|
25
26
|
fromFolderInput: () => fromFolderInput,
|
|
26
27
|
fromGitHubRepo: () => fromGitHubRepo,
|
|
27
28
|
fromSingleFile: () => fromSingleFile,
|
|
28
29
|
fromZipFile: () => fromZipFile,
|
|
29
30
|
parseIni: () => parseIni,
|
|
30
|
-
parseThemeConfig: () => parseThemeConfig
|
|
31
|
+
parseThemeConfig: () => parseThemeConfig,
|
|
32
|
+
transformQmlImports: () => transformQmlImports
|
|
31
33
|
});
|
|
32
34
|
module.exports = __toCommonJS(index_exports);
|
|
33
35
|
|
|
@@ -206,16 +208,29 @@ async function fromGitHubRepo(url, options = {}) {
|
|
|
206
208
|
if (!blobs.length) throw new Error(`GitHub returned no regular files${folder ? ` in "${folder}"` : ""}.`);
|
|
207
209
|
const files = newFileMap();
|
|
208
210
|
const downloads = /* @__PURE__ */ new Map();
|
|
211
|
+
const rawBase = `https://raw.githubusercontent.com/${encodeURIComponent(owner)}/${encodeURIComponent(repo)}/${encodeURIComponent(ref)}`;
|
|
209
212
|
let next = 0;
|
|
210
213
|
async function downloadFiles() {
|
|
211
214
|
while (!signal.aborted && next < blobs.length) {
|
|
212
215
|
const { path, sha } = blobs[next++];
|
|
216
|
+
const normalized = normalizePath(path);
|
|
213
217
|
let download = downloads.get(sha);
|
|
214
218
|
if (!download) {
|
|
215
|
-
|
|
219
|
+
if (!options.token) {
|
|
220
|
+
const fullRepoPath = prefix ? `${prefix}${normalized}` : normalized;
|
|
221
|
+
const rawUrl = `${rawBase}/${fullRepoPath.split("/").map(encodeURIComponent).join("/")}`;
|
|
222
|
+
download = fetch(rawUrl, { signal }).then(async (response) => {
|
|
223
|
+
if (!response.ok) {
|
|
224
|
+
throw new GitHubRequestError(response.status, `GitHub returned HTTP ${response.status} for ${fullRepoPath}.`);
|
|
225
|
+
}
|
|
226
|
+
return new Uint8Array(await response.arrayBuffer());
|
|
227
|
+
});
|
|
228
|
+
} else {
|
|
229
|
+
download = request(`/git/blobs/${encodeURIComponent(sha)}`, true).then((response) => response.arrayBuffer()).then((buffer) => new Uint8Array(buffer));
|
|
230
|
+
}
|
|
216
231
|
downloads.set(sha, download);
|
|
217
232
|
}
|
|
218
|
-
insertFile(files,
|
|
233
|
+
insertFile(files, normalized, await download);
|
|
219
234
|
}
|
|
220
235
|
signal.throwIfAborted();
|
|
221
236
|
}
|
|
@@ -228,6 +243,119 @@ async function fromGitHubRepo(url, options = {}) {
|
|
|
228
243
|
return files;
|
|
229
244
|
}
|
|
230
245
|
|
|
246
|
+
// src/qmlShims.ts
|
|
247
|
+
var FALLBACK_QML_SHIMS = {
|
|
248
|
+
"QtMultimedia/AudioOutput.qml": "import QtQuick\n\nQtObject {\n property real volume: 1.0\n property bool muted: false\n property var device: null\n}\n",
|
|
249
|
+
"QtMultimedia/MediaDevices.qml": "import QtQuick\n\nQtObject {\n readonly property var audioInputs: []\n readonly property var audioOutputs: []\n readonly property var videoInputs: []\n readonly property var defaultAudioInput: null\n readonly property var defaultAudioOutput: null\n readonly property var defaultVideoInput: null\n}\n",
|
|
250
|
+
"QtMultimedia/MediaPlayer.qml": 'import QtQuick\n\nQtObject {\n id: player\n\n enum Loops {\n Once = 1,\n Infinite = -1\n }\n enum PlaybackState {\n StoppedState = 0,\n PlayingState = 1,\n PausedState = 2\n }\n enum MediaStatus {\n NoMedia = 0,\n LoadingMedia = 1,\n LoadedMedia = 2,\n StalledMedia = 3,\n BufferingMedia = 4,\n BufferedMedia = 5,\n EndOfMedia = 6,\n InvalidMedia = 7\n }\n enum Error {\n NoError = 0,\n ResourceError = 1,\n FormatError = 2,\n NetworkError = 3,\n AccessDeniedError = 4\n }\n\n property url source: ""\n property var videoOutput: null\n property var audioOutput: null\n property bool autoPlay: false\n property real playbackRate: 1.0\n property int loops: 1\n property bool muted: false\n property real volume: 1.0\n property int playbackState: 0\n readonly property bool playing: playbackState === 1\n property int mediaStatus: 0\n property int position: 0\n property int duration: 0\n property bool hasVideo: false\n property bool hasAudio: false\n property int error: 0\n property string errorString: ""\n\n onSourceChanged: {\n syncVideoOutput()\n if (autoPlay && source.toString() !== "")\n play()\n }\n\n onVideoOutputChanged: syncVideoOutput()\n\n function syncVideoOutput() {\n if (!videoOutput)\n return\n if ("source" in videoOutput)\n videoOutput.source = source\n }\n\n function play() {\n const uri = source.toString()\n if (uri === "")\n return\n syncVideoOutput()\n const isImage = /\\.(gif|png|jpe?g|webp|svg|bmp)(\\?|#|$)/i.test(uri)\n hasVideo = isImage\n mediaStatus = 2\n playbackState = isImage ? 1 : 0\n }\n\n function pause() {\n if (playbackState === 1)\n playbackState = 2\n }\n\n function stop() {\n playbackState = 0\n position = 0\n }\n\n function setPosition(pos) {\n position = pos\n }\n}\n',
|
|
251
|
+
"QtMultimedia/VideoOutput.qml": 'import QtQuick\n\nItem {\n id: output\n\n enum FillMode {\n Stretch = 0,\n PreserveAspectFit = 1,\n PreserveAspectCrop = 2\n }\n\n property int fillMode: Image.PreserveAspectFit\n property int orientation: 0\n property url source: ""\n property rect contentRect: Qt.rect(0, 0, width, height)\n property rect sourceRect: Qt.rect(0, 0, width, height)\n\n readonly property bool isImageSource: /\\.(gif|png|jpe?g|webp|svg|bmp)(\\?|#|$)/i.test(source.toString())\n\n AnimatedImage {\n id: fallbackImage\n anchors.fill: parent\n source: output.isImageSource ? output.source : ""\n fillMode: output.fillMode\n visible: output.isImageSource && status === AnimatedImage.Ready\n playing: visible\n clip: true\n }\n}\n',
|
|
252
|
+
"QtMultimedia/qmldir": "module QtMultimedia\n\nMediaPlayer 1.0 MediaPlayer.qml\nMediaPlayer 5.0 MediaPlayer.qml\nMediaPlayer 5.12 MediaPlayer.qml\nMediaPlayer 5.15 MediaPlayer.qml\nMediaPlayer 6.0 MediaPlayer.qml\nVideoOutput 1.0 VideoOutput.qml\nVideoOutput 5.0 VideoOutput.qml\nVideoOutput 5.12 VideoOutput.qml\nVideoOutput 5.15 VideoOutput.qml\nVideoOutput 6.0 VideoOutput.qml\nAudioOutput 1.0 AudioOutput.qml\nAudioOutput 6.0 AudioOutput.qml\nMediaDevices 1.0 MediaDevices.qml\nMediaDevices 6.0 MediaDevices.qml\n",
|
|
253
|
+
"Qt5Compat/GraphicalEffects/BrightnessContrast.qml": "import QtQuick\nimport QtQuick.Effects\n\nMultiEffect {\n property bool cached: false\n}\n",
|
|
254
|
+
"Qt5Compat/GraphicalEffects/ColorOverlay.qml": 'import QtQuick\nimport QtQuick.Effects\n\nMultiEffect {\n property color color: "#000000"\n property bool cached: false\n\n colorization: 1.0\n colorizationColor: color\n}\n',
|
|
255
|
+
"Qt5Compat/GraphicalEffects/Colorize.qml": "import QtQuick\nimport QtQuick.Effects\n\nMultiEffect {\n property real hue: 0.0\n property real saturation: 0.5\n property real lightness: 0.0\n property bool cached: false\n\n colorization: 1.0\n colorizationColor: Qt.hsla(hue, saturation, Math.max(0.0, Math.min(1.0, 0.5 + lightness * 0.5)), 1.0)\n}\n",
|
|
256
|
+
"Qt5Compat/GraphicalEffects/Desaturate.qml": "import QtQuick\nimport QtQuick.Effects\n\nMultiEffect {\n property real desaturation: 0.0\n property bool cached: false\n\n saturation: -Math.max(0.0, Math.min(1.0, desaturation))\n}\n",
|
|
257
|
+
"Qt5Compat/GraphicalEffects/DropShadow.qml": 'import QtQuick\nimport QtQuick.Effects\n\nMultiEffect {\n property color color: "#80000000"\n property real horizontalOffset: 0\n property real verticalOffset: 0\n property real radius: 0\n property int samples: 9\n property real spread: 0\n property bool fast: false\n property bool transparentBorder: true\n property bool cached: false\n\n shadowEnabled: true\n shadowColor: color\n shadowHorizontalOffset: horizontalOffset\n shadowVerticalOffset: verticalOffset\n shadowBlur: Math.min(1.0, Math.max(0.0, radius / 32.0))\n shadowScale: 1.0 + Math.max(0.0, spread) * 0.2\n autoPaddingEnabled: transparentBorder\n}\n',
|
|
258
|
+
"Qt5Compat/GraphicalEffects/FastBlur.qml": "import QtQuick\nimport QtQuick.Effects\n\nMultiEffect {\n property real radius: 0\n property bool transparentBorder: false\n property bool cached: false\n\n blurEnabled: radius > 0\n blurMax: 64\n blur: Math.min(1.0, Math.max(0.0, radius / 64.0))\n autoPaddingEnabled: transparentBorder\n}\n",
|
|
259
|
+
"Qt5Compat/GraphicalEffects/GaussianBlur.qml": "import QtQuick\nimport QtQuick.Effects\n\nMultiEffect {\n property real radius: 0\n property int samples: 9\n property real deviation: 0\n property bool transparentBorder: false\n property bool cached: false\n\n blurEnabled: radius > 0\n blurMax: 64\n blur: Math.min(1.0, Math.max(0.0, radius / 64.0))\n autoPaddingEnabled: transparentBorder\n}\n",
|
|
260
|
+
"Qt5Compat/GraphicalEffects/Glow.qml": 'import QtQuick\nimport QtQuick.Effects\n\nMultiEffect {\n property color color: "#ffffff"\n property real radius: 0\n property int samples: 9\n property real spread: 0\n property bool fast: false\n property bool transparentBorder: true\n property bool cached: false\n\n shadowEnabled: true\n shadowColor: color\n shadowHorizontalOffset: 0\n shadowVerticalOffset: 0\n shadowBlur: Math.min(1.0, Math.max(0.0, radius / 32.0))\n shadowScale: 1.0 + Math.max(0.0, spread) * 0.2\n autoPaddingEnabled: transparentBorder\n}\n',
|
|
261
|
+
"Qt5Compat/GraphicalEffects/HueSaturation.qml": "import QtQuick\nimport QtQuick.Effects\n\nMultiEffect {\n property real hue: 0.0\n property bool cached: false\n}\n",
|
|
262
|
+
"Qt5Compat/GraphicalEffects/LinearGradient.qml": 'import QtQuick\n\nItem {\n id: root\n property point start: Qt.point(0, 0)\n property point end: Qt.point(0, height)\n property var source: null\n property bool cached: false\n default property list<GradientStop> stops\n\n Canvas {\n anchors.fill: parent\n onPaint: {\n const ctx = getContext("2d")\n ctx.clearRect(0, 0, width, height)\n const g = ctx.createLinearGradient(root.start.x, root.start.y, root.end.x, root.end.y)\n for (let i = 0; i < root.stops.length; i++) {\n const s = root.stops[i]\n g.addColorStop(Math.max(0, Math.min(1, s.position)), s.color.toString())\n }\n ctx.fillStyle = g\n ctx.fillRect(0, 0, width, height)\n }\n onWidthChanged: requestPaint()\n onHeightChanged: requestPaint()\n }\n}\n',
|
|
263
|
+
"Qt5Compat/GraphicalEffects/OpacityMask.qml": "import QtQuick\nimport QtQuick.Effects\n\nMultiEffect {\n property bool invert: false\n property bool cached: false\n\n maskEnabled: true\n maskInverted: invert\n}\n",
|
|
264
|
+
"Qt5Compat/GraphicalEffects/RadialGradient.qml": 'import QtQuick\n\nItem {\n id: root\n property real horizontalOffset: 0\n property real verticalOffset: 0\n property real horizontalRadius: width / 2\n property real verticalRadius: height / 2\n property real angle: 0\n property var source: null\n property bool cached: false\n default property list<GradientStop> stops\n\n Canvas {\n anchors.fill: parent\n onPaint: {\n const ctx = getContext("2d")\n ctx.clearRect(0, 0, width, height)\n const cx = width / 2 + root.horizontalOffset\n const cy = height / 2 + root.verticalOffset\n const r = Math.max(1, Math.max(root.horizontalRadius, root.verticalRadius))\n const g = ctx.createRadialGradient(cx, cy, 0, cx, cy, r)\n for (let i = 0; i < root.stops.length; i++) {\n const s = root.stops[i]\n g.addColorStop(Math.max(0, Math.min(1, s.position)), s.color.toString())\n }\n ctx.fillStyle = g\n ctx.fillRect(0, 0, width, height)\n }\n onWidthChanged: requestPaint()\n onHeightChanged: requestPaint()\n }\n}\n',
|
|
265
|
+
"Qt5Compat/GraphicalEffects/RectangularGlow.qml": "import QtQuick\n\nRectangle {\n property real glowRadius: 0\n property real spread: 0\n property real cornerRadius: 0\n property bool cached: false\n\n radius: cornerRadius + glowRadius * 0.5\n opacity: 0.45\n}\n",
|
|
266
|
+
"Qt5Compat/GraphicalEffects/ThresholdMask.qml": "import QtQuick\nimport QtQuick.Effects\n\nMultiEffect {\n property real threshold: 0.5\n property real spread: 0.0\n property bool cached: false\n\n maskEnabled: true\n maskThresholdMin: Math.max(0.0, threshold - spread)\n maskSpreadAtMin: Math.max(0.0, spread)\n}\n",
|
|
267
|
+
"Qt5Compat/GraphicalEffects/qmldir": "module Qt5Compat.GraphicalEffects\n\nBrightnessContrast 1.0 BrightnessContrast.qml\nBrightnessContrast 1.15 BrightnessContrast.qml\nBrightnessContrast 6.0 BrightnessContrast.qml\nColorize 1.0 Colorize.qml\nColorize 1.15 Colorize.qml\nColorize 6.0 Colorize.qml\nColorOverlay 1.0 ColorOverlay.qml\nColorOverlay 1.15 ColorOverlay.qml\nColorOverlay 6.0 ColorOverlay.qml\nDesaturate 1.0 Desaturate.qml\nDesaturate 1.15 Desaturate.qml\nDesaturate 6.0 Desaturate.qml\nDropShadow 1.0 DropShadow.qml\nDropShadow 1.15 DropShadow.qml\nDropShadow 6.0 DropShadow.qml\nFastBlur 1.0 FastBlur.qml\nFastBlur 1.15 FastBlur.qml\nFastBlur 6.0 FastBlur.qml\nGaussianBlur 1.0 GaussianBlur.qml\nGaussianBlur 1.15 GaussianBlur.qml\nGaussianBlur 6.0 GaussianBlur.qml\nGlow 1.0 Glow.qml\nGlow 1.15 Glow.qml\nGlow 6.0 Glow.qml\nHueSaturation 1.0 HueSaturation.qml\nHueSaturation 1.15 HueSaturation.qml\nHueSaturation 6.0 HueSaturation.qml\nLinearGradient 1.0 LinearGradient.qml\nLinearGradient 1.15 LinearGradient.qml\nLinearGradient 6.0 LinearGradient.qml\nOpacityMask 1.0 OpacityMask.qml\nOpacityMask 1.15 OpacityMask.qml\nOpacityMask 6.0 OpacityMask.qml\nRadialGradient 1.0 RadialGradient.qml\nRadialGradient 1.15 RadialGradient.qml\nRadialGradient 6.0 RadialGradient.qml\nRectangularGlow 1.0 RectangularGlow.qml\nRectangularGlow 1.15 RectangularGlow.qml\nRectangularGlow 6.0 RectangularGlow.qml\nThresholdMask 1.0 ThresholdMask.qml\nThresholdMask 1.15 ThresholdMask.qml\nThresholdMask 6.0 ThresholdMask.qml\n",
|
|
268
|
+
"QtGraphicalEffects/qmldir": "module QtGraphicalEffects\n\nBrightnessContrast 1.0 ../Qt5Compat/GraphicalEffects/BrightnessContrast.qml\nBrightnessContrast 1.15 ../Qt5Compat/GraphicalEffects/BrightnessContrast.qml\nColorize 1.0 ../Qt5Compat/GraphicalEffects/Colorize.qml\nColorize 1.15 ../Qt5Compat/GraphicalEffects/Colorize.qml\nColorOverlay 1.0 ../Qt5Compat/GraphicalEffects/ColorOverlay.qml\nColorOverlay 1.15 ../Qt5Compat/GraphicalEffects/ColorOverlay.qml\nDesaturate 1.0 ../Qt5Compat/GraphicalEffects/Desaturate.qml\nDesaturate 1.15 ../Qt5Compat/GraphicalEffects/Desaturate.qml\nDropShadow 1.0 ../Qt5Compat/GraphicalEffects/DropShadow.qml\nDropShadow 1.15 ../Qt5Compat/GraphicalEffects/DropShadow.qml\nFastBlur 1.0 ../Qt5Compat/GraphicalEffects/FastBlur.qml\nFastBlur 1.15 ../Qt5Compat/GraphicalEffects/FastBlur.qml\nGaussianBlur 1.0 ../Qt5Compat/GraphicalEffects/GaussianBlur.qml\nGaussianBlur 1.15 ../Qt5Compat/GraphicalEffects/GaussianBlur.qml\nGlow 1.0 ../Qt5Compat/GraphicalEffects/Glow.qml\nGlow 1.15 ../Qt5Compat/GraphicalEffects/Glow.qml\nHueSaturation 1.0 ../Qt5Compat/GraphicalEffects/HueSaturation.qml\nHueSaturation 1.15 ../Qt5Compat/GraphicalEffects/HueSaturation.qml\nLinearGradient 1.0 ../Qt5Compat/GraphicalEffects/LinearGradient.qml\nLinearGradient 1.15 ../Qt5Compat/GraphicalEffects/LinearGradient.qml\nOpacityMask 1.0 ../Qt5Compat/GraphicalEffects/OpacityMask.qml\nOpacityMask 1.15 ../Qt5Compat/GraphicalEffects/OpacityMask.qml\nRadialGradient 1.0 ../Qt5Compat/GraphicalEffects/RadialGradient.qml\nRadialGradient 1.15 ../Qt5Compat/GraphicalEffects/RadialGradient.qml\nRectangularGlow 1.0 ../Qt5Compat/GraphicalEffects/RectangularGlow.qml\nRectangularGlow 1.15 ../Qt5Compat/GraphicalEffects/RectangularGlow.qml\nThresholdMask 1.0 ../Qt5Compat/GraphicalEffects/ThresholdMask.qml\nThresholdMask 1.15 ../Qt5Compat/GraphicalEffects/ThresholdMask.qml\n",
|
|
269
|
+
"QtQuick/VirtualKeyboard/InputPanel.qml": 'import QtQuick\nimport QtQuick.Controls\nimport QtQuick.Layouts\n\nItem {\n id: panel\n property bool active: false\n property bool externalLanguageSwitchEnabled: false\n signal externalLanguageSwitchRequested(var localeList, int currentIndex)\n\n implicitWidth: 640\n implicitHeight: 210\n visible: active\n\n readonly property var rows: [\n ["1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "\u232B"],\n ["q", "w", "e", "r", "t", "y", "u", "i", "o", "p"],\n ["a", "s", "d", "f", "g", "h", "j", "k", "l", "\u21B5"],\n ["\u21E7", "z", "x", "c", "v", "b", "n", "m", "Space"]\n ]\n property bool shifted: false\n\n function dispatchKey(label) {\n if (label === "\u21E7") {\n shifted = !shifted\n return\n }\n if (label === "\u232B") {\n const target = panel.Window.activeFocusItem\n if (target && typeof target.text === "string" && typeof target.cursorPosition === "number") {\n const pos = target.cursorPosition\n if (pos > 0) {\n target.text = target.text.slice(0, pos - 1) + target.text.slice(pos)\n target.cursorPosition = pos - 1\n }\n }\n return\n }\n if (label === "\u21B5") {\n const target = panel.Window.activeFocusItem\n if (target && typeof target.accepted === "function")\n target.accepted()\n return\n }\n const ch = label === "Space" ? " " : (shifted ? label.toUpperCase() : label)\n const target = panel.Window.activeFocusItem\n if (target && typeof target.text === "string" && typeof target.cursorPosition === "number") {\n const pos = target.cursorPosition\n target.text = target.text.slice(0, pos) + ch + target.text.slice(pos)\n target.cursorPosition = pos + ch.length\n }\n }\n\n Rectangle {\n anchors.fill: parent\n radius: 10\n color: "#e6181d25"\n border.color: "#384454"\n border.width: 1\n\n ColumnLayout {\n anchors.fill: parent\n anchors.margins: 10\n spacing: 6\n\n Repeater {\n model: panel.rows\n RowLayout {\n Layout.fillWidth: true\n Layout.fillHeight: true\n spacing: 6\n\n Repeater {\n model: modelData\n Button {\n Layout.fillWidth: true\n Layout.fillHeight: true\n Layout.preferredWidth: modelData === "Space" ? 160 : 40\n text: (modelData.length === 1 && panel.shifted) ? modelData.toUpperCase() : modelData\n focusPolicy: Qt.NoFocus\n onClicked: panel.dispatchKey(modelData)\n }\n }\n }\n }\n }\n }\n}\n',
|
|
270
|
+
"QtQuick/VirtualKeyboard/qmldir": "module QtQuick.VirtualKeyboard\n\nInputPanel 2.0 InputPanel.qml\nInputPanel 2.12 InputPanel.qml\nInputPanel 2.15 InputPanel.qml\nInputPanel 6.0 InputPanel.qml\n"
|
|
271
|
+
};
|
|
272
|
+
|
|
273
|
+
// src/qmlVersion.ts
|
|
274
|
+
var SUPPORTED_QML_VERSIONS = ["auto", "6.8", "2.15", "2.12", "2.0"];
|
|
275
|
+
var QT_QUICK_2_MODULES = /* @__PURE__ */ new Set([
|
|
276
|
+
"QtQuick",
|
|
277
|
+
"QtQuick.Window",
|
|
278
|
+
"QtQuick.Controls",
|
|
279
|
+
"QtQuick.Controls.Basic",
|
|
280
|
+
"QtQuick.VirtualKeyboard",
|
|
281
|
+
"QtQml",
|
|
282
|
+
"QtQml.Models",
|
|
283
|
+
"QtQml.WorkerScript"
|
|
284
|
+
]);
|
|
285
|
+
var QT_LAYOUT_MODULES = /* @__PURE__ */ new Set([
|
|
286
|
+
"QtQuick.Layouts",
|
|
287
|
+
"QtQuick.Shapes"
|
|
288
|
+
]);
|
|
289
|
+
var QT6_ONLY_OR_UNVERSIONED_MODULES = /* @__PURE__ */ new Set([
|
|
290
|
+
"QtQuick.Effects"
|
|
291
|
+
]);
|
|
292
|
+
var GRAPHICAL_EFFECT_MODULES = /* @__PURE__ */ new Set([
|
|
293
|
+
"QtGraphicalEffects",
|
|
294
|
+
"Qt5Compat.GraphicalEffects"
|
|
295
|
+
]);
|
|
296
|
+
var MULTIMEDIA_MODULES = /* @__PURE__ */ new Set([
|
|
297
|
+
"QtMultimedia"
|
|
298
|
+
]);
|
|
299
|
+
var IMPORT_LINE = /^(\s*import\s+)([A-Za-z_][\w.]*)(?:\s+(\d+(?:\.\d+)?))?(\s+as\s+[A-Za-z_]\w*)?(\s*;?\s*(?:\/\/.*)?)$/;
|
|
300
|
+
function parseTargetVersion(version) {
|
|
301
|
+
const trimmed = version.trim();
|
|
302
|
+
if (!trimmed || trimmed.toLowerCase() === "auto") return { mode: "auto" };
|
|
303
|
+
if (trimmed === "6" || /^6\.\d+$/.test(trimmed)) return { mode: "qt6" };
|
|
304
|
+
if (trimmed === "5" || /^5\.\d+$/.test(trimmed)) {
|
|
305
|
+
const minor = trimmed === "5" ? 15 : Number(trimmed.split(".")[1]);
|
|
306
|
+
const clamped = Math.max(0, Math.min(15, Number.isFinite(minor) ? minor : 15));
|
|
307
|
+
return { mode: "qtquick2", version: `2.${clamped}`, minor: clamped };
|
|
308
|
+
}
|
|
309
|
+
const qtQuickMatch = /^2\.(\d+)$/.exec(trimmed);
|
|
310
|
+
if (qtQuickMatch) {
|
|
311
|
+
const minor = Number(qtQuickMatch[1]);
|
|
312
|
+
return { mode: "qtquick2", version: trimmed, minor };
|
|
313
|
+
}
|
|
314
|
+
throw new RangeError(`Unsupported QML version "${version}". Use "auto", "6.8", "2.15", "2.12", or "2.0".`);
|
|
315
|
+
}
|
|
316
|
+
function normalizeQmlVersion(version) {
|
|
317
|
+
if (!version) return "auto";
|
|
318
|
+
const parsed = parseTargetVersion(version);
|
|
319
|
+
if (parsed.mode === "auto") return "auto";
|
|
320
|
+
if (parsed.mode === "qt6") return version.trim() === "6" ? "6" : version.trim();
|
|
321
|
+
return parsed.version;
|
|
322
|
+
}
|
|
323
|
+
function transformQmlImports(source, version) {
|
|
324
|
+
const target = parseTargetVersion(version);
|
|
325
|
+
if (target.mode === "auto") return source;
|
|
326
|
+
return source.split(/\r?\n/).map((line) => {
|
|
327
|
+
const match = IMPORT_LINE.exec(line);
|
|
328
|
+
if (!match) return line;
|
|
329
|
+
const [, prefix, moduleName, , alias = "", suffix = ""] = match;
|
|
330
|
+
if (!prefix || !moduleName) return line;
|
|
331
|
+
if (target.mode === "qt6") {
|
|
332
|
+
if (GRAPHICAL_EFFECT_MODULES.has(moduleName)) {
|
|
333
|
+
return `${prefix}Qt5Compat.GraphicalEffects${alias}${suffix}`;
|
|
334
|
+
}
|
|
335
|
+
if (QT_QUICK_2_MODULES.has(moduleName) || QT_LAYOUT_MODULES.has(moduleName) || QT6_ONLY_OR_UNVERSIONED_MODULES.has(moduleName) || MULTIMEDIA_MODULES.has(moduleName)) {
|
|
336
|
+
return `${prefix}${moduleName}${alias}${suffix}`;
|
|
337
|
+
}
|
|
338
|
+
return line;
|
|
339
|
+
}
|
|
340
|
+
if (QT_QUICK_2_MODULES.has(moduleName)) {
|
|
341
|
+
return `${prefix}${moduleName} ${target.version}${alias}${suffix}`;
|
|
342
|
+
}
|
|
343
|
+
if (QT_LAYOUT_MODULES.has(moduleName)) {
|
|
344
|
+
const layoutMinor = Math.min(target.minor, 15);
|
|
345
|
+
return `${prefix}${moduleName} 1.${layoutMinor}${alias}${suffix}`;
|
|
346
|
+
}
|
|
347
|
+
if (GRAPHICAL_EFFECT_MODULES.has(moduleName)) {
|
|
348
|
+
const effectMinor = target.minor >= 15 ? "1.15" : "1.0";
|
|
349
|
+
return `${prefix}${moduleName} ${effectMinor}${alias}${suffix}`;
|
|
350
|
+
}
|
|
351
|
+
if (MULTIMEDIA_MODULES.has(moduleName)) {
|
|
352
|
+
const mediaVersion = target.minor >= 15 ? "5.15" : target.minor >= 12 ? "5.12" : "5.0";
|
|
353
|
+
return `${prefix}${moduleName} ${mediaVersion}${alias}${suffix}`;
|
|
354
|
+
}
|
|
355
|
+
return line;
|
|
356
|
+
}).join("\n");
|
|
357
|
+
}
|
|
358
|
+
|
|
231
359
|
// src/sddmParser.ts
|
|
232
360
|
var decoder = new TextDecoder();
|
|
233
361
|
function parseIni(source) {
|
|
@@ -310,7 +438,8 @@ function resolveTheme(files, entryFile) {
|
|
|
310
438
|
throw new Error(`QML entry file "${entry}" was not found.`);
|
|
311
439
|
}
|
|
312
440
|
const root = metadataPath ? metadataRoot : directory(entry);
|
|
313
|
-
const
|
|
441
|
+
const declaredConfigPath = root + normalizePath(metadata.configFile || "theme.conf");
|
|
442
|
+
const configPath = Object.hasOwn(files, declaredConfigPath) ? declaredConfigPath : Object.hasOwn(files, `${root}theme.conf`) ? `${root}theme.conf` : paths.filter((path) => path.startsWith(root) && /\.conf$/i.test(path)).sort()[0] ?? declaredConfigPath;
|
|
314
443
|
const config = Object.assign(
|
|
315
444
|
parseThemeConfig(readText(files, configPath)),
|
|
316
445
|
parseThemeConfig(readText(files, `${configPath}.user`))
|
|
@@ -434,6 +563,8 @@ async function loadWasmRuntime(frame, baseUrl, maxPixelRatio, signal, progress,
|
|
|
434
563
|
}
|
|
435
564
|
|
|
436
565
|
// src/index.ts
|
|
566
|
+
var decoder2 = new TextDecoder();
|
|
567
|
+
var encoder2 = new TextEncoder();
|
|
437
568
|
var workspace = "/workspace";
|
|
438
569
|
var defaults = {
|
|
439
570
|
hostName: "qml-preview",
|
|
@@ -474,6 +605,7 @@ var QmlViewer = class {
|
|
|
474
605
|
this.options = options;
|
|
475
606
|
this.document = options.container.ownerDocument;
|
|
476
607
|
this.sddmConfig = options.sddmConfig;
|
|
608
|
+
this.qmlVersion = normalizeQmlVersion(options.qmlVersion);
|
|
477
609
|
this.maxPixelRatio = options.maxPixelRatio ?? 2;
|
|
478
610
|
if (!Number.isFinite(this.maxPixelRatio) || this.maxPixelRatio <= 0) {
|
|
479
611
|
throw new RangeError("maxPixelRatio must be a positive finite number.");
|
|
@@ -489,6 +621,7 @@ var QmlViewer = class {
|
|
|
489
621
|
observer;
|
|
490
622
|
sddmConfig;
|
|
491
623
|
themeConfig;
|
|
624
|
+
qmlVersion;
|
|
492
625
|
generation = 0;
|
|
493
626
|
destroyed = false;
|
|
494
627
|
inViewport = true;
|
|
@@ -538,12 +671,15 @@ var QmlViewer = class {
|
|
|
538
671
|
throw error;
|
|
539
672
|
}
|
|
540
673
|
}
|
|
541
|
-
async renderThemeFiles(input,
|
|
674
|
+
async renderThemeFiles(input, entryOrOptions) {
|
|
675
|
+
const options = typeof entryOrOptions === "string" ? { entryFile: entryOrOptions } : entryOrOptions ?? {};
|
|
676
|
+
let targetVersion;
|
|
542
677
|
let prepared;
|
|
543
678
|
let theme;
|
|
544
679
|
try {
|
|
680
|
+
targetVersion = normalizeQmlVersion(options.qmlVersion ?? this.qmlVersion);
|
|
545
681
|
prepared = prepareFiles(input);
|
|
546
|
-
theme = resolveTheme(prepared.files, entryFile);
|
|
682
|
+
theme = resolveTheme(prepared.files, options.entryFile);
|
|
547
683
|
} catch (error2) {
|
|
548
684
|
this.reportError(messageOf(error2));
|
|
549
685
|
throw error2;
|
|
@@ -557,7 +693,24 @@ var QmlViewer = class {
|
|
|
557
693
|
if (!runtime.clearWorkspace()) throw new Error("Could not clear the Qt workspace.");
|
|
558
694
|
runtime.FS.mkdirTree(root);
|
|
559
695
|
for (const dir of prepared.directories) runtime.FS.mkdirTree(`${root}/${dir}`);
|
|
560
|
-
for (const [path, data] of Object.entries(prepared.files))
|
|
696
|
+
for (const [path, data] of Object.entries(prepared.files)) {
|
|
697
|
+
const content = targetVersion !== "auto" && /\.qml$/i.test(path) ? encoder2.encode(transformQmlImports(typeof data === "string" ? data : decoder2.decode(data), targetVersion)) : data;
|
|
698
|
+
runtime.FS.writeFile(`${root}/${path}`, content);
|
|
699
|
+
}
|
|
700
|
+
const importRoot = theme.root ? `${root}/${theme.root.slice(0, -1)}` : root;
|
|
701
|
+
const shimDirs = /* @__PURE__ */ new Set();
|
|
702
|
+
for (const [shimPath, shimSource] of Object.entries(FALLBACK_QML_SHIMS)) {
|
|
703
|
+
if (Object.hasOwn(prepared.files, `${theme.root}${shimPath}`)) continue;
|
|
704
|
+
const slash = shimPath.lastIndexOf("/");
|
|
705
|
+
if (slash > 0) {
|
|
706
|
+
const dir = `${importRoot}/${shimPath.slice(0, slash)}`;
|
|
707
|
+
if (!shimDirs.has(dir)) {
|
|
708
|
+
runtime.FS.mkdirTree(dir);
|
|
709
|
+
shimDirs.add(dir);
|
|
710
|
+
}
|
|
711
|
+
}
|
|
712
|
+
runtime.FS.writeFile(`${importRoot}/${shimPath}`, shimSource);
|
|
713
|
+
}
|
|
561
714
|
runtime.updateSddmConfig(config);
|
|
562
715
|
this.themeConfig = theme.config;
|
|
563
716
|
} catch (error2) {
|
|
@@ -569,8 +722,17 @@ var QmlViewer = class {
|
|
|
569
722
|
const error = runtime.loadMainQml(`${root}/${theme.entryFile}`, importDirectory);
|
|
570
723
|
if (error) throw new Error(error);
|
|
571
724
|
}
|
|
572
|
-
renderCode(qmlSource) {
|
|
573
|
-
return this.renderThemeFiles(fromCodeString(qmlSource), "Main.qml");
|
|
725
|
+
renderCode(qmlSource, qmlVersion) {
|
|
726
|
+
return this.renderThemeFiles(fromCodeString(qmlSource), { entryFile: "Main.qml", qmlVersion });
|
|
727
|
+
}
|
|
728
|
+
/** Return the active default QML target version used when rendering. */
|
|
729
|
+
getQmlVersion() {
|
|
730
|
+
return this.qmlVersion;
|
|
731
|
+
}
|
|
732
|
+
/** Set the default QML target version for subsequent renders. */
|
|
733
|
+
setQmlVersion(version) {
|
|
734
|
+
if (this.destroyed) throw new Error("This QmlViewer has been destroyed.");
|
|
735
|
+
this.qmlVersion = normalizeQmlVersion(version);
|
|
574
736
|
}
|
|
575
737
|
/** Update the mock environment used by the current and subsequent previews. */
|
|
576
738
|
setSddmConfig(config) {
|
|
@@ -620,11 +782,13 @@ var QmlViewer = class {
|
|
|
620
782
|
// Annotate the CommonJS export names for ESM import in node:
|
|
621
783
|
0 && (module.exports = {
|
|
622
784
|
QmlViewer,
|
|
785
|
+
SUPPORTED_QML_VERSIONS,
|
|
623
786
|
fromCodeString,
|
|
624
787
|
fromFolderInput,
|
|
625
788
|
fromGitHubRepo,
|
|
626
789
|
fromSingleFile,
|
|
627
790
|
fromZipFile,
|
|
628
791
|
parseIni,
|
|
629
|
-
parseThemeConfig
|
|
792
|
+
parseThemeConfig,
|
|
793
|
+
transformQmlImports
|
|
630
794
|
});
|
package/dist/index.d.cts
CHANGED
|
@@ -2,6 +2,11 @@
|
|
|
2
2
|
type ThemeFileMap = Record<string, Uint8Array>;
|
|
3
3
|
type ThemeFiles = Record<string, Uint8Array | string>;
|
|
4
4
|
type ThemeConfigValue = string | number | boolean;
|
|
5
|
+
type QmlVersion = "auto" | "6.8" | "6" | "2.15" | "2.12" | "2.0" | (string & {});
|
|
6
|
+
interface RenderThemeOptions {
|
|
7
|
+
entryFile?: string;
|
|
8
|
+
qmlVersion?: QmlVersion;
|
|
9
|
+
}
|
|
5
10
|
interface SddmUser {
|
|
6
11
|
name: string;
|
|
7
12
|
realName?: string;
|
|
@@ -38,6 +43,8 @@ interface QmlViewerOptions {
|
|
|
38
43
|
/** Directory containing qtloader.js, qml_engine.js and qml_engine.wasm. Defaults to ./wasm/. */
|
|
39
44
|
wasmBaseUrl?: string;
|
|
40
45
|
sddmConfig?: SddmMockConfig;
|
|
46
|
+
/** Target QML version for standard Qt imports ("auto" preserves source imports). */
|
|
47
|
+
qmlVersion?: QmlVersion;
|
|
41
48
|
/** Positive upper bound for the viewer's device pixel ratio. Defaults to 2. */
|
|
42
49
|
maxPixelRatio?: number;
|
|
43
50
|
onProgress?: (percent: number) => void;
|
|
@@ -63,6 +70,9 @@ type IniFile = Record<string, IniSection>;
|
|
|
63
70
|
declare function parseIni(source: string): IniFile;
|
|
64
71
|
declare function parseThemeConfig(source: string): Record<string, string>;
|
|
65
72
|
|
|
73
|
+
declare const SUPPORTED_QML_VERSIONS: readonly ["auto", "6.8", "2.15", "2.12", "2.0"];
|
|
74
|
+
declare function transformQmlImports(source: string, version: QmlVersion): string;
|
|
75
|
+
|
|
66
76
|
declare class QmlViewer {
|
|
67
77
|
private readonly options;
|
|
68
78
|
private readonly maxPixelRatio;
|
|
@@ -74,14 +84,19 @@ declare class QmlViewer {
|
|
|
74
84
|
private observer?;
|
|
75
85
|
private sddmConfig?;
|
|
76
86
|
private themeConfig?;
|
|
87
|
+
private qmlVersion;
|
|
77
88
|
private generation;
|
|
78
89
|
private destroyed;
|
|
79
90
|
private inViewport;
|
|
80
91
|
constructor(options: QmlViewerOptions);
|
|
81
92
|
init(): Promise<void>;
|
|
82
93
|
private start;
|
|
83
|
-
renderThemeFiles(input: ThemeFiles,
|
|
84
|
-
renderCode(qmlSource: string): Promise<void>;
|
|
94
|
+
renderThemeFiles(input: ThemeFiles, entryOrOptions?: string | RenderThemeOptions): Promise<void>;
|
|
95
|
+
renderCode(qmlSource: string, qmlVersion?: QmlVersion): Promise<void>;
|
|
96
|
+
/** Return the active default QML target version used when rendering. */
|
|
97
|
+
getQmlVersion(): QmlVersion;
|
|
98
|
+
/** Set the default QML target version for subsequent renders. */
|
|
99
|
+
setQmlVersion(version: QmlVersion): void;
|
|
85
100
|
/** Update the mock environment used by the current and subsequent previews. */
|
|
86
101
|
setSddmConfig(config: SddmMockConfig): void;
|
|
87
102
|
destroy(): void;
|
|
@@ -91,4 +106,4 @@ declare class QmlViewer {
|
|
|
91
106
|
private stop;
|
|
92
107
|
}
|
|
93
108
|
|
|
94
|
-
export { type GitHubRepoOptions, type IniFile, QmlViewer, type QmlViewerOptions, type SddmMockConfig, type SddmSession, type SddmUser, type ThemeConfigValue, type ThemeFileMap, type ThemeFiles, fromCodeString, fromFolderInput, fromGitHubRepo, fromSingleFile, fromZipFile, parseIni, parseThemeConfig };
|
|
109
|
+
export { type GitHubRepoOptions, type IniFile, type QmlVersion, QmlViewer, type QmlViewerOptions, type RenderThemeOptions, SUPPORTED_QML_VERSIONS, type SddmMockConfig, type SddmSession, type SddmUser, type ThemeConfigValue, type ThemeFileMap, type ThemeFiles, fromCodeString, fromFolderInput, fromGitHubRepo, fromSingleFile, fromZipFile, parseIni, parseThemeConfig, transformQmlImports };
|