@aethervtt/shard-platform-tauri 0.0.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Patrick Dias
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,3 @@
1
+ # @aethervtt/shard-platform-tauri
2
+
3
+ Part of [Shard](https://github.com/aethervtt/shard), a WebGPU-first 2D/3D game engine in TypeScript. See the repository for documentation.
@@ -0,0 +1,11 @@
1
+ import type { Platform } from '@aethervtt/shard-platform';
2
+ export interface TauriPlatformOptions {
3
+ /** Absolute path of the project root. Project paths resolve against it. */
4
+ projectRoot: string;
5
+ /**
6
+ * Absolute folder for `storage` (saves, settings): the app data folder for the project, e.g.
7
+ * `<appDataDir>/<project>`. Default `<projectRoot>/.shard/user`.
8
+ */
9
+ dataDir?: string;
10
+ }
11
+ export declare function createTauriPlatform(options: TauriPlatformOptions): Platform;
package/dist/index.js ADDED
@@ -0,0 +1,88 @@
1
+ import { createWebAudioBackend, createWebWorkers } from "@aethervtt/shard-platform-web";
2
+ import {
3
+ exists,
4
+ mkdir,
5
+ readDir,
6
+ readFile,
7
+ readTextFile,
8
+ remove,
9
+ rename,
10
+ watch,
11
+ writeFile,
12
+ writeTextFile
13
+ } from "@tauri-apps/plugin-fs";
14
+ function createTauriStorage(dir) {
15
+ const path = (key) => `${dir}/${key}`;
16
+ const parent = (p) => p.slice(0, p.lastIndexOf("/"));
17
+ const walk = async (folder, prefix, out) => {
18
+ const entries = await readDir(folder).catch(() => []);
19
+ for (const e of entries) {
20
+ const key = prefix === "" ? e.name : `${prefix}/${e.name}`;
21
+ if (e.isDirectory) await walk(`${folder}/${e.name}`, key, out);
22
+ else if (e.isFile && !e.name.endsWith(".tmp")) out.push(key);
23
+ }
24
+ };
25
+ return {
26
+ read: async (key) => await exists(path(key)) ? readFile(path(key)) : void 0,
27
+ write: async (key, data) => {
28
+ const target = path(key);
29
+ await mkdir(parent(target), { recursive: true });
30
+ await writeFile(`${target}.tmp`, data);
31
+ await rename(`${target}.tmp`, target);
32
+ },
33
+ list: async (prefix) => {
34
+ const out = [];
35
+ await walk(dir, "", out);
36
+ return out.filter((k) => k.startsWith(prefix)).sort();
37
+ },
38
+ delete: async (key) => {
39
+ if (await exists(path(key))) await remove(path(key));
40
+ }
41
+ };
42
+ }
43
+ function createTauriPlatform(options) {
44
+ const root = options.projectRoot.replace(/\/+$/, "");
45
+ const resolve = (path) => path.startsWith("/") ? path : `${root}/${path}`;
46
+ const relative = (path) => path.startsWith(`${root}/`) ? path.slice(root.length + 1) : path;
47
+ const toChange = (event) => {
48
+ const type = event.type;
49
+ const kind = typeof type === "object" && "create" in type ? "create" : typeof type === "object" && "remove" in type ? "remove" : "modify";
50
+ return event.paths.map((path) => ({ kind, path: relative(path) }));
51
+ };
52
+ const fs = {
53
+ writable: true,
54
+ readText: (path) => readTextFile(resolve(path)),
55
+ readBytes: (path) => readFile(resolve(path)),
56
+ writeText: (path, data) => writeTextFile(resolve(path), data),
57
+ writeBytes: (path, data) => writeFile(resolve(path), data),
58
+ exists: (path) => exists(resolve(path)),
59
+ watch: async (path, onChange) => watch(resolve(path), (event) => toChange(event).forEach(onChange), {
60
+ recursive: true,
61
+ delayMs: 50
62
+ })
63
+ };
64
+ let audio;
65
+ let workers;
66
+ return {
67
+ name: "tauri",
68
+ // Web workers in the webview; made on first use.
69
+ get workers() {
70
+ workers ??= createWebWorkers();
71
+ return workers;
72
+ },
73
+ // The webview has Web Audio; made on first use.
74
+ get audio() {
75
+ audio ??= createWebAudioBackend();
76
+ return audio;
77
+ },
78
+ fs,
79
+ storage: createTauriStorage((options.dataDir ?? `${root}/.shard/user`).replace(/\/+$/, "")),
80
+ clock: { now: () => performance.now() },
81
+ log: {
82
+ log: (level, message, data) => console[level](`[shard] ${message}`, data ?? "")
83
+ }
84
+ };
85
+ }
86
+ export {
87
+ createTauriPlatform
88
+ };
package/package.json ADDED
@@ -0,0 +1,37 @@
1
+ {
2
+ "name": "@aethervtt/shard-platform-tauri",
3
+ "version": "0.0.1",
4
+ "license": "MIT",
5
+ "type": "module",
6
+ "sideEffects": false,
7
+ "exports": {
8
+ ".": {
9
+ "types": "./dist/index.d.ts",
10
+ "default": "./dist/index.js"
11
+ }
12
+ },
13
+ "files": [
14
+ "dist",
15
+ "LICENSE",
16
+ "README.md"
17
+ ],
18
+ "dependencies": {
19
+ "@aethervtt/shard-core": "0.0.1",
20
+ "@aethervtt/shard-platform": "0.0.1",
21
+ "@aethervtt/shard-platform-web": "0.0.1",
22
+ "@tauri-apps/api": "^2.11.1",
23
+ "@tauri-apps/plugin-fs": "^2.5.2"
24
+ },
25
+ "repository": {
26
+ "type": "git",
27
+ "url": "git+https://github.com/aethervtt/shard.git",
28
+ "directory": "packages/platform-tauri"
29
+ },
30
+ "publishConfig": {
31
+ "access": "public",
32
+ "provenance": true
33
+ },
34
+ "shard": {
35
+ "buildSha": "d6c5c6aef4675575c878b02cf2c8f738b4190229"
36
+ }
37
+ }