@craft-native/svelte 0.0.72
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 +123 -0
- package/dist/actions/haptic.d.ts +4 -0
- package/dist/actions/haptic.d.ts.map +1 -0
- package/dist/actions/toast.d.ts +2 -0
- package/dist/actions/toast.d.ts.map +1 -0
- package/dist/api/database.d.ts +5 -0
- package/dist/api/database.d.ts.map +1 -0
- package/dist/api/filesystem.d.ts +9 -0
- package/dist/api/filesystem.d.ts.map +1 -0
- package/dist/api/http.d.ts +13 -0
- package/dist/api/http.d.ts.map +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +254 -0
- package/dist/index.mjs +213 -0
- package/dist/stores/craft.d.ts +32 -0
- package/dist/stores/craft.d.ts.map +1 -0
- package/dist/stores/platform.d.ts +19 -0
- package/dist/stores/platform.d.ts.map +1 -0
- package/dist/stores/tray.d.ts +7 -0
- package/dist/stores/tray.d.ts.map +1 -0
- package/dist/stores/window.d.ts +12 -0
- package/dist/stores/window.d.ts.map +1 -0
- package/package.json +50 -0
package/README.md
ADDED
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
# @craft-native/svelte
|
|
2
|
+
|
|
3
|
+
Svelte bindings for the Craft framework using stores and actions.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @craft-native/svelte
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
### Stores
|
|
14
|
+
|
|
15
|
+
```svelte
|
|
16
|
+
<script>
|
|
17
|
+
import { craft, isReady, platform } from '@craft-native/svelte';
|
|
18
|
+
</script>
|
|
19
|
+
|
|
20
|
+
{#if $isReady}
|
|
21
|
+
<p>Platform: {$platform?.platform}</p>
|
|
22
|
+
{/if}
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
### Window Management
|
|
26
|
+
|
|
27
|
+
```svelte
|
|
28
|
+
<script>
|
|
29
|
+
import { windowActions, isFullscreen } from '@craft-native/svelte';
|
|
30
|
+
</script>
|
|
31
|
+
|
|
32
|
+
<button on:click={windowActions.maximize}>Maximize</button>
|
|
33
|
+
<button on:click={windowActions.toggleFullscreen}>
|
|
34
|
+
{$isFullscreen ? 'Exit' : 'Enter'} Fullscreen
|
|
35
|
+
</button>
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
### Haptic Action
|
|
39
|
+
|
|
40
|
+
```svelte
|
|
41
|
+
<script>
|
|
42
|
+
import { haptic } from '@craft-native/svelte';
|
|
43
|
+
</script>
|
|
44
|
+
|
|
45
|
+
<button use:haptic={'impact_medium'}>Tap Me</button>
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
### Toast
|
|
49
|
+
|
|
50
|
+
```svelte
|
|
51
|
+
<script>
|
|
52
|
+
import { showToast } from '@craft-native/svelte';
|
|
53
|
+
</script>
|
|
54
|
+
|
|
55
|
+
<button on:click={() => showToast('Hello!')}>Show Toast</button>
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
### File System
|
|
59
|
+
|
|
60
|
+
```svelte
|
|
61
|
+
<script>
|
|
62
|
+
import { filesystem } from '@craft-native/svelte';
|
|
63
|
+
|
|
64
|
+
let content = '';
|
|
65
|
+
|
|
66
|
+
async function load() {
|
|
67
|
+
content = await filesystem.readFile('/path/to/file.txt');
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
async function save() {
|
|
71
|
+
await filesystem.writeFile('/path/to/file.txt', content);
|
|
72
|
+
}
|
|
73
|
+
</script>
|
|
74
|
+
|
|
75
|
+
<textarea bind:value={content} />
|
|
76
|
+
<button on:click={load}>Load</button>
|
|
77
|
+
<button on:click={save}>Save</button>
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
### Database
|
|
81
|
+
|
|
82
|
+
```svelte
|
|
83
|
+
<script>
|
|
84
|
+
import { onMount } from 'svelte';
|
|
85
|
+
import { createDatabase } from '@craft-native/svelte';
|
|
86
|
+
|
|
87
|
+
const db = createDatabase('/path/to/db.sqlite');
|
|
88
|
+
let todos = [];
|
|
89
|
+
|
|
90
|
+
onMount(async () => {
|
|
91
|
+
todos = await db.query('SELECT * FROM todos');
|
|
92
|
+
});
|
|
93
|
+
</script>
|
|
94
|
+
|
|
95
|
+
<ul>
|
|
96
|
+
{#each todos as todo}
|
|
97
|
+
<li>{todo.title}</li>
|
|
98
|
+
{/each}
|
|
99
|
+
</ul>
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
### HTTP
|
|
103
|
+
|
|
104
|
+
```svelte
|
|
105
|
+
<script>
|
|
106
|
+
import { http } from '@craft-native/svelte';
|
|
107
|
+
|
|
108
|
+
let data = null;
|
|
109
|
+
|
|
110
|
+
async function loadData() {
|
|
111
|
+
data = await http.fetch('https://api.example.com/data');
|
|
112
|
+
}
|
|
113
|
+
</script>
|
|
114
|
+
|
|
115
|
+
<button on:click={loadData}>Load Data</button>
|
|
116
|
+
{#if data}
|
|
117
|
+
<pre>{JSON.stringify(data, null, 2)}</pre>
|
|
118
|
+
{/if}
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
## License
|
|
122
|
+
|
|
123
|
+
MIT
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"haptic.d.ts","sourceRoot":"","sources":["../../src/actions/haptic.ts"],"names":[],"mappings":"AAGA,wBAAgB,MAAM,CAAC,IAAI,EAAE,WAAW,EAAE,IAAI,GAAE,MAAoB;;EAcnE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"toast.d.ts","sourceRoot":"","sources":["../../src/actions/toast.ts"],"names":[],"mappings":"AAGA,wBAAsB,SAAS,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,GAAE,OAAO,GAAG,MAAgB,iBAIpF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"database.d.ts","sourceRoot":"","sources":["../../src/api/database.ts"],"names":[],"mappings":"AAGA,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM;iBAEtB,MAAM,WAAU,GAAG,EAAE;UAM5B,CAAC,aAAa,MAAM,WAAU,GAAG,EAAE,GAAQ,OAAO,CAAC,CAAC,EAAE,CAAC;EAMtE"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export declare const filesystem: {
|
|
2
|
+
readFile(path: string, encoding?: "utf8" | "binary"): Promise<any>;
|
|
3
|
+
writeFile(path: string, data: string | Uint8Array, encoding?: "utf8" | "binary"): Promise<void>;
|
|
4
|
+
readDir(path: string): Promise<any>;
|
|
5
|
+
mkdir(path: string, recursive?: boolean): Promise<void>;
|
|
6
|
+
remove(path: string, recursive?: boolean): Promise<void>;
|
|
7
|
+
exists(path: string): Promise<any>;
|
|
8
|
+
};
|
|
9
|
+
//# sourceMappingURL=filesystem.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"filesystem.d.ts","sourceRoot":"","sources":["../../src/api/filesystem.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,UAAU;mBACA,MAAM,aAAY,MAAM,GAAG,QAAQ;oBAMlC,MAAM,QAAQ,MAAM,GAAG,UAAU,aAAY,MAAM,GAAG,QAAQ;kBAMhE,MAAM;gBAMR,MAAM;iBAML,MAAM;iBAMN,MAAM;CAK1B,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
interface HttpOptions {
|
|
2
|
+
method?: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
|
|
3
|
+
headers?: Record<string, string>;
|
|
4
|
+
body?: any;
|
|
5
|
+
timeout?: number;
|
|
6
|
+
}
|
|
7
|
+
export declare const http: {
|
|
8
|
+
fetch<T = any>(url: string, options?: HttpOptions): Promise<T>;
|
|
9
|
+
download(url: string, path: string): Promise<void>;
|
|
10
|
+
upload(url: string, filePath: string, options?: HttpOptions): Promise<any>;
|
|
11
|
+
};
|
|
12
|
+
export {};
|
|
13
|
+
//# sourceMappingURL=http.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../../src/api/http.ts"],"names":[],"mappings":"AAGA,UAAU,WAAW;IACnB,MAAM,CAAC,EAAE,KAAK,GAAG,MAAM,GAAG,KAAK,GAAG,QAAQ,GAAG,OAAO,CAAC;IACrD,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,IAAI,CAAC,EAAE,GAAG,CAAC;IACX,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,eAAO,MAAM,IAAI;UACH,CAAC,aAAa,MAAM,YAAW,WAAW,GAAQ,OAAO,CAAC,CAAC,CAAC;kBAMpD,MAAM,QAAQ,MAAM;gBAMtB,MAAM,YAAY,MAAM,YAAW,WAAW;CAKjE,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export * from './stores/craft';
|
|
2
|
+
export * from './stores/platform';
|
|
3
|
+
export * from './stores/window';
|
|
4
|
+
export * from './stores/tray';
|
|
5
|
+
export * from './actions/haptic';
|
|
6
|
+
export * from './actions/toast';
|
|
7
|
+
export * from './api/filesystem';
|
|
8
|
+
export * from './api/database';
|
|
9
|
+
export * from './api/http';
|
|
10
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,mBAAmB,CAAC;AAClC,cAAc,iBAAiB,CAAC;AAChC,cAAc,eAAe,CAAC;AAC9B,cAAc,kBAAkB,CAAC;AACjC,cAAc,iBAAiB,CAAC;AAChC,cAAc,kBAAkB,CAAC;AACjC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,YAAY,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
craft: () => craft,
|
|
24
|
+
createDatabase: () => createDatabase,
|
|
25
|
+
createPlatformStore: () => createPlatformStore,
|
|
26
|
+
filesystem: () => filesystem,
|
|
27
|
+
haptic: () => haptic,
|
|
28
|
+
http: () => http,
|
|
29
|
+
isFullscreen: () => isFullscreen,
|
|
30
|
+
isMaximized: () => isMaximized,
|
|
31
|
+
isMinimized: () => isMinimized,
|
|
32
|
+
isReady: () => isReady,
|
|
33
|
+
platform: () => platform,
|
|
34
|
+
showToast: () => showToast,
|
|
35
|
+
trayActions: () => trayActions,
|
|
36
|
+
trayVisible: () => trayVisible,
|
|
37
|
+
windowActions: () => windowActions
|
|
38
|
+
});
|
|
39
|
+
module.exports = __toCommonJS(index_exports);
|
|
40
|
+
|
|
41
|
+
// src/stores/craft.ts
|
|
42
|
+
var import_store = require("svelte/store");
|
|
43
|
+
function createCraftStore() {
|
|
44
|
+
const { subscribe, set } = (0, import_store.writable)(null);
|
|
45
|
+
if (typeof window !== "undefined") {
|
|
46
|
+
if (window.craft) {
|
|
47
|
+
set(window.craft);
|
|
48
|
+
} else {
|
|
49
|
+
const checkCraft = setInterval(() => {
|
|
50
|
+
if (window.craft) {
|
|
51
|
+
set(window.craft);
|
|
52
|
+
clearInterval(checkCraft);
|
|
53
|
+
}
|
|
54
|
+
}, 100);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return {
|
|
58
|
+
subscribe
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
var craft = createCraftStore();
|
|
62
|
+
var isReady = (0, import_store.derived)(craft, (_$craft) => _$craft !== null);
|
|
63
|
+
|
|
64
|
+
// src/stores/platform.ts
|
|
65
|
+
var import_store2 = require("svelte/store");
|
|
66
|
+
function createPlatformStore() {
|
|
67
|
+
const { subscribe, set } = (0, import_store2.writable)(null);
|
|
68
|
+
craft.subscribe(async (_$craft) => {
|
|
69
|
+
if (_$craft) {
|
|
70
|
+
const info = await _$craft.getPlatform();
|
|
71
|
+
set(info);
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
return { subscribe };
|
|
75
|
+
}
|
|
76
|
+
var platform = createPlatformStore();
|
|
77
|
+
|
|
78
|
+
// src/stores/window.ts
|
|
79
|
+
var import_store3 = require("svelte/store");
|
|
80
|
+
var isFullscreen = (0, import_store3.writable)(false);
|
|
81
|
+
var isMaximized = (0, import_store3.writable)(false);
|
|
82
|
+
var isMinimized = (0, import_store3.writable)(false);
|
|
83
|
+
var windowActions = {
|
|
84
|
+
async setTitle(title) {
|
|
85
|
+
const _$craft = (0, import_store3.get)(craft);
|
|
86
|
+
if (!_$craft) return;
|
|
87
|
+
await _$craft.invoke("window.setTitle", { title });
|
|
88
|
+
},
|
|
89
|
+
async setSize(width, height) {
|
|
90
|
+
const _$craft = (0, import_store3.get)(craft);
|
|
91
|
+
if (!_$craft) return;
|
|
92
|
+
await _$craft.invoke("window.setSize", { width, height });
|
|
93
|
+
},
|
|
94
|
+
async maximize() {
|
|
95
|
+
const _$craft = (0, import_store3.get)(craft);
|
|
96
|
+
if (!_$craft) return;
|
|
97
|
+
await _$craft.invoke("window.maximize");
|
|
98
|
+
isMaximized.set(true);
|
|
99
|
+
},
|
|
100
|
+
async minimize() {
|
|
101
|
+
const _$craft = (0, import_store3.get)(craft);
|
|
102
|
+
if (!_$craft) return;
|
|
103
|
+
await _$craft.invoke("window.minimize");
|
|
104
|
+
isMinimized.set(true);
|
|
105
|
+
},
|
|
106
|
+
async toggleFullscreen() {
|
|
107
|
+
const _$craft = (0, import_store3.get)(craft);
|
|
108
|
+
if (!_$craft) return;
|
|
109
|
+
await _$craft.invoke("window.toggleFullscreen");
|
|
110
|
+
isFullscreen.update((v) => !v);
|
|
111
|
+
},
|
|
112
|
+
async close() {
|
|
113
|
+
const _$craft = (0, import_store3.get)(craft);
|
|
114
|
+
if (!_$craft) return;
|
|
115
|
+
await _$craft.invoke("window.close");
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
// src/stores/tray.ts
|
|
120
|
+
var import_store4 = require("svelte/store");
|
|
121
|
+
var trayVisible = (0, import_store4.writable)(false);
|
|
122
|
+
var trayActions = {
|
|
123
|
+
async create(icon, tooltip) {
|
|
124
|
+
const _$craft = (0, import_store4.get)(craft);
|
|
125
|
+
if (!_$craft) return;
|
|
126
|
+
await _$craft.invoke("tray.create", { icon, tooltip });
|
|
127
|
+
trayVisible.set(true);
|
|
128
|
+
},
|
|
129
|
+
async destroy() {
|
|
130
|
+
const _$craft = (0, import_store4.get)(craft);
|
|
131
|
+
if (!_$craft) return;
|
|
132
|
+
await _$craft.invoke("tray.destroy");
|
|
133
|
+
trayVisible.set(false);
|
|
134
|
+
},
|
|
135
|
+
async setIcon(icon) {
|
|
136
|
+
const _$craft = (0, import_store4.get)(craft);
|
|
137
|
+
if (!_$craft) return;
|
|
138
|
+
await _$craft.invoke("tray.setIcon", { icon });
|
|
139
|
+
}
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
// src/actions/haptic.ts
|
|
143
|
+
var import_store5 = require("svelte/store");
|
|
144
|
+
function haptic(node, type = "selection") {
|
|
145
|
+
const handleClick = async () => {
|
|
146
|
+
const _$craft = (0, import_store5.get)(craft);
|
|
147
|
+
if (!_$craft) return;
|
|
148
|
+
await _$craft.haptic(type);
|
|
149
|
+
};
|
|
150
|
+
node.addEventListener("click", handleClick);
|
|
151
|
+
return {
|
|
152
|
+
destroy() {
|
|
153
|
+
node.removeEventListener("click", handleClick);
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
// src/actions/toast.ts
|
|
159
|
+
var import_store6 = require("svelte/store");
|
|
160
|
+
async function showToast(message, duration = "short") {
|
|
161
|
+
const _$craft = (0, import_store6.get)(craft);
|
|
162
|
+
if (!_$craft) return;
|
|
163
|
+
await _$craft.showToast(message, duration);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
// src/api/filesystem.ts
|
|
167
|
+
var import_store7 = require("svelte/store");
|
|
168
|
+
var filesystem = {
|
|
169
|
+
async readFile(path, encoding = "utf8") {
|
|
170
|
+
const _$craft = (0, import_store7.get)(craft);
|
|
171
|
+
if (!_$craft) throw new Error("Craft not ready");
|
|
172
|
+
return await _$craft.invoke("fs.readFile", { path, encoding });
|
|
173
|
+
},
|
|
174
|
+
async writeFile(path, data, encoding = "utf8") {
|
|
175
|
+
const _$craft = (0, import_store7.get)(craft);
|
|
176
|
+
if (!_$craft) throw new Error("Craft not ready");
|
|
177
|
+
await _$craft.invoke("fs.writeFile", { path, data, encoding });
|
|
178
|
+
},
|
|
179
|
+
async readDir(path) {
|
|
180
|
+
const _$craft = (0, import_store7.get)(craft);
|
|
181
|
+
if (!_$craft) throw new Error("Craft not ready");
|
|
182
|
+
return await _$craft.invoke("fs.readDir", { path });
|
|
183
|
+
},
|
|
184
|
+
async mkdir(path, recursive = false) {
|
|
185
|
+
const _$craft = (0, import_store7.get)(craft);
|
|
186
|
+
if (!_$craft) throw new Error("Craft not ready");
|
|
187
|
+
await _$craft.invoke("fs.mkdir", { path, recursive });
|
|
188
|
+
},
|
|
189
|
+
async remove(path, recursive = false) {
|
|
190
|
+
const _$craft = (0, import_store7.get)(craft);
|
|
191
|
+
if (!_$craft) throw new Error("Craft not ready");
|
|
192
|
+
await _$craft.invoke("fs.remove", { path, recursive });
|
|
193
|
+
},
|
|
194
|
+
async exists(path) {
|
|
195
|
+
const _$craft = (0, import_store7.get)(craft);
|
|
196
|
+
if (!_$craft) throw new Error("Craft not ready");
|
|
197
|
+
return await _$craft.invoke("fs.exists", { path });
|
|
198
|
+
}
|
|
199
|
+
};
|
|
200
|
+
|
|
201
|
+
// src/api/database.ts
|
|
202
|
+
var import_store8 = require("svelte/store");
|
|
203
|
+
function createDatabase(dbPath) {
|
|
204
|
+
return {
|
|
205
|
+
async execute(sql, params = []) {
|
|
206
|
+
const _$craft = (0, import_store8.get)(craft);
|
|
207
|
+
if (!_$craft) throw new Error("Craft not ready");
|
|
208
|
+
return await _$craft.invoke("db.execute", { path: dbPath, sql, params });
|
|
209
|
+
},
|
|
210
|
+
async query(sql, params = []) {
|
|
211
|
+
const _$craft = (0, import_store8.get)(craft);
|
|
212
|
+
if (!_$craft) throw new Error("Craft not ready");
|
|
213
|
+
return await _$craft.invoke("db.query", { path: dbPath, sql, params });
|
|
214
|
+
}
|
|
215
|
+
};
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
// src/api/http.ts
|
|
219
|
+
var import_store9 = require("svelte/store");
|
|
220
|
+
var http = {
|
|
221
|
+
async fetch(url, options = {}) {
|
|
222
|
+
const _$craft = (0, import_store9.get)(craft);
|
|
223
|
+
if (!_$craft) throw new Error("Craft not ready");
|
|
224
|
+
return await _$craft.invoke("http.fetch", { url, ...options });
|
|
225
|
+
},
|
|
226
|
+
async download(url, path) {
|
|
227
|
+
const _$craft = (0, import_store9.get)(craft);
|
|
228
|
+
if (!_$craft) throw new Error("Craft not ready");
|
|
229
|
+
await _$craft.invoke("http.download", { url, path });
|
|
230
|
+
},
|
|
231
|
+
async upload(url, filePath, options = {}) {
|
|
232
|
+
const _$craft = (0, import_store9.get)(craft);
|
|
233
|
+
if (!_$craft) throw new Error("Craft not ready");
|
|
234
|
+
return await _$craft.invoke("http.upload", { url, filePath, ...options });
|
|
235
|
+
}
|
|
236
|
+
};
|
|
237
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
238
|
+
0 && (module.exports = {
|
|
239
|
+
craft,
|
|
240
|
+
createDatabase,
|
|
241
|
+
createPlatformStore,
|
|
242
|
+
filesystem,
|
|
243
|
+
haptic,
|
|
244
|
+
http,
|
|
245
|
+
isFullscreen,
|
|
246
|
+
isMaximized,
|
|
247
|
+
isMinimized,
|
|
248
|
+
isReady,
|
|
249
|
+
platform,
|
|
250
|
+
showToast,
|
|
251
|
+
trayActions,
|
|
252
|
+
trayVisible,
|
|
253
|
+
windowActions
|
|
254
|
+
});
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
// src/stores/craft.ts
|
|
2
|
+
import { writable, derived } from "svelte/store";
|
|
3
|
+
function createCraftStore() {
|
|
4
|
+
const { subscribe, set } = writable(null);
|
|
5
|
+
if (typeof window !== "undefined") {
|
|
6
|
+
if (window.craft) {
|
|
7
|
+
set(window.craft);
|
|
8
|
+
} else {
|
|
9
|
+
const checkCraft = setInterval(() => {
|
|
10
|
+
if (window.craft) {
|
|
11
|
+
set(window.craft);
|
|
12
|
+
clearInterval(checkCraft);
|
|
13
|
+
}
|
|
14
|
+
}, 100);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
return {
|
|
18
|
+
subscribe
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
var craft = createCraftStore();
|
|
22
|
+
var isReady = derived(craft, (_$craft) => _$craft !== null);
|
|
23
|
+
|
|
24
|
+
// src/stores/platform.ts
|
|
25
|
+
import { writable as writable2 } from "svelte/store";
|
|
26
|
+
function createPlatformStore() {
|
|
27
|
+
const { subscribe, set } = writable2(null);
|
|
28
|
+
craft.subscribe(async (_$craft) => {
|
|
29
|
+
if (_$craft) {
|
|
30
|
+
const info = await _$craft.getPlatform();
|
|
31
|
+
set(info);
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
return { subscribe };
|
|
35
|
+
}
|
|
36
|
+
var platform = createPlatformStore();
|
|
37
|
+
|
|
38
|
+
// src/stores/window.ts
|
|
39
|
+
import { writable as writable3, get as get2 } from "svelte/store";
|
|
40
|
+
var isFullscreen = writable3(false);
|
|
41
|
+
var isMaximized = writable3(false);
|
|
42
|
+
var isMinimized = writable3(false);
|
|
43
|
+
var windowActions = {
|
|
44
|
+
async setTitle(title) {
|
|
45
|
+
const _$craft = get2(craft);
|
|
46
|
+
if (!_$craft) return;
|
|
47
|
+
await _$craft.invoke("window.setTitle", { title });
|
|
48
|
+
},
|
|
49
|
+
async setSize(width, height) {
|
|
50
|
+
const _$craft = get2(craft);
|
|
51
|
+
if (!_$craft) return;
|
|
52
|
+
await _$craft.invoke("window.setSize", { width, height });
|
|
53
|
+
},
|
|
54
|
+
async maximize() {
|
|
55
|
+
const _$craft = get2(craft);
|
|
56
|
+
if (!_$craft) return;
|
|
57
|
+
await _$craft.invoke("window.maximize");
|
|
58
|
+
isMaximized.set(true);
|
|
59
|
+
},
|
|
60
|
+
async minimize() {
|
|
61
|
+
const _$craft = get2(craft);
|
|
62
|
+
if (!_$craft) return;
|
|
63
|
+
await _$craft.invoke("window.minimize");
|
|
64
|
+
isMinimized.set(true);
|
|
65
|
+
},
|
|
66
|
+
async toggleFullscreen() {
|
|
67
|
+
const _$craft = get2(craft);
|
|
68
|
+
if (!_$craft) return;
|
|
69
|
+
await _$craft.invoke("window.toggleFullscreen");
|
|
70
|
+
isFullscreen.update((v) => !v);
|
|
71
|
+
},
|
|
72
|
+
async close() {
|
|
73
|
+
const _$craft = get2(craft);
|
|
74
|
+
if (!_$craft) return;
|
|
75
|
+
await _$craft.invoke("window.close");
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
// src/stores/tray.ts
|
|
80
|
+
import { writable as writable4, get as get3 } from "svelte/store";
|
|
81
|
+
var trayVisible = writable4(false);
|
|
82
|
+
var trayActions = {
|
|
83
|
+
async create(icon, tooltip) {
|
|
84
|
+
const _$craft = get3(craft);
|
|
85
|
+
if (!_$craft) return;
|
|
86
|
+
await _$craft.invoke("tray.create", { icon, tooltip });
|
|
87
|
+
trayVisible.set(true);
|
|
88
|
+
},
|
|
89
|
+
async destroy() {
|
|
90
|
+
const _$craft = get3(craft);
|
|
91
|
+
if (!_$craft) return;
|
|
92
|
+
await _$craft.invoke("tray.destroy");
|
|
93
|
+
trayVisible.set(false);
|
|
94
|
+
},
|
|
95
|
+
async setIcon(icon) {
|
|
96
|
+
const _$craft = get3(craft);
|
|
97
|
+
if (!_$craft) return;
|
|
98
|
+
await _$craft.invoke("tray.setIcon", { icon });
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
// src/actions/haptic.ts
|
|
103
|
+
import { get as get4 } from "svelte/store";
|
|
104
|
+
function haptic(node, type = "selection") {
|
|
105
|
+
const handleClick = async () => {
|
|
106
|
+
const _$craft = get4(craft);
|
|
107
|
+
if (!_$craft) return;
|
|
108
|
+
await _$craft.haptic(type);
|
|
109
|
+
};
|
|
110
|
+
node.addEventListener("click", handleClick);
|
|
111
|
+
return {
|
|
112
|
+
destroy() {
|
|
113
|
+
node.removeEventListener("click", handleClick);
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// src/actions/toast.ts
|
|
119
|
+
import { get as get5 } from "svelte/store";
|
|
120
|
+
async function showToast(message, duration = "short") {
|
|
121
|
+
const _$craft = get5(craft);
|
|
122
|
+
if (!_$craft) return;
|
|
123
|
+
await _$craft.showToast(message, duration);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// src/api/filesystem.ts
|
|
127
|
+
import { get as get6 } from "svelte/store";
|
|
128
|
+
var filesystem = {
|
|
129
|
+
async readFile(path, encoding = "utf8") {
|
|
130
|
+
const _$craft = get6(craft);
|
|
131
|
+
if (!_$craft) throw new Error("Craft not ready");
|
|
132
|
+
return await _$craft.invoke("fs.readFile", { path, encoding });
|
|
133
|
+
},
|
|
134
|
+
async writeFile(path, data, encoding = "utf8") {
|
|
135
|
+
const _$craft = get6(craft);
|
|
136
|
+
if (!_$craft) throw new Error("Craft not ready");
|
|
137
|
+
await _$craft.invoke("fs.writeFile", { path, data, encoding });
|
|
138
|
+
},
|
|
139
|
+
async readDir(path) {
|
|
140
|
+
const _$craft = get6(craft);
|
|
141
|
+
if (!_$craft) throw new Error("Craft not ready");
|
|
142
|
+
return await _$craft.invoke("fs.readDir", { path });
|
|
143
|
+
},
|
|
144
|
+
async mkdir(path, recursive = false) {
|
|
145
|
+
const _$craft = get6(craft);
|
|
146
|
+
if (!_$craft) throw new Error("Craft not ready");
|
|
147
|
+
await _$craft.invoke("fs.mkdir", { path, recursive });
|
|
148
|
+
},
|
|
149
|
+
async remove(path, recursive = false) {
|
|
150
|
+
const _$craft = get6(craft);
|
|
151
|
+
if (!_$craft) throw new Error("Craft not ready");
|
|
152
|
+
await _$craft.invoke("fs.remove", { path, recursive });
|
|
153
|
+
},
|
|
154
|
+
async exists(path) {
|
|
155
|
+
const _$craft = get6(craft);
|
|
156
|
+
if (!_$craft) throw new Error("Craft not ready");
|
|
157
|
+
return await _$craft.invoke("fs.exists", { path });
|
|
158
|
+
}
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
// src/api/database.ts
|
|
162
|
+
import { get as get7 } from "svelte/store";
|
|
163
|
+
function createDatabase(dbPath) {
|
|
164
|
+
return {
|
|
165
|
+
async execute(sql, params = []) {
|
|
166
|
+
const _$craft = get7(craft);
|
|
167
|
+
if (!_$craft) throw new Error("Craft not ready");
|
|
168
|
+
return await _$craft.invoke("db.execute", { path: dbPath, sql, params });
|
|
169
|
+
},
|
|
170
|
+
async query(sql, params = []) {
|
|
171
|
+
const _$craft = get7(craft);
|
|
172
|
+
if (!_$craft) throw new Error("Craft not ready");
|
|
173
|
+
return await _$craft.invoke("db.query", { path: dbPath, sql, params });
|
|
174
|
+
}
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
// src/api/http.ts
|
|
179
|
+
import { get as get8 } from "svelte/store";
|
|
180
|
+
var http = {
|
|
181
|
+
async fetch(url, options = {}) {
|
|
182
|
+
const _$craft = get8(craft);
|
|
183
|
+
if (!_$craft) throw new Error("Craft not ready");
|
|
184
|
+
return await _$craft.invoke("http.fetch", { url, ...options });
|
|
185
|
+
},
|
|
186
|
+
async download(url, path) {
|
|
187
|
+
const _$craft = get8(craft);
|
|
188
|
+
if (!_$craft) throw new Error("Craft not ready");
|
|
189
|
+
await _$craft.invoke("http.download", { url, path });
|
|
190
|
+
},
|
|
191
|
+
async upload(url, filePath, options = {}) {
|
|
192
|
+
const _$craft = get8(craft);
|
|
193
|
+
if (!_$craft) throw new Error("Craft not ready");
|
|
194
|
+
return await _$craft.invoke("http.upload", { url, filePath, ...options });
|
|
195
|
+
}
|
|
196
|
+
};
|
|
197
|
+
export {
|
|
198
|
+
craft,
|
|
199
|
+
createDatabase,
|
|
200
|
+
createPlatformStore,
|
|
201
|
+
filesystem,
|
|
202
|
+
haptic,
|
|
203
|
+
http,
|
|
204
|
+
isFullscreen,
|
|
205
|
+
isMaximized,
|
|
206
|
+
isMinimized,
|
|
207
|
+
isReady,
|
|
208
|
+
platform,
|
|
209
|
+
showToast,
|
|
210
|
+
trayActions,
|
|
211
|
+
trayVisible,
|
|
212
|
+
windowActions
|
|
213
|
+
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
interface CraftAPI {
|
|
2
|
+
getPlatform(): Promise<{
|
|
3
|
+
platform: string;
|
|
4
|
+
version: string;
|
|
5
|
+
}>;
|
|
6
|
+
getDeviceInfo(): Promise<{
|
|
7
|
+
platform: string;
|
|
8
|
+
model: string;
|
|
9
|
+
os_version: string;
|
|
10
|
+
}>;
|
|
11
|
+
showToast(message: string, duration: 'short' | 'long'): Promise<void>;
|
|
12
|
+
haptic(type: string): Promise<void>;
|
|
13
|
+
requestPermission(permission: string): Promise<{
|
|
14
|
+
granted: boolean;
|
|
15
|
+
message: string;
|
|
16
|
+
}>;
|
|
17
|
+
on(event: string, callback: (...args: any[]) => void): void;
|
|
18
|
+
off(event: string, callback: (...args: any[]) => void): void;
|
|
19
|
+
emit(event: string, data?: any): void;
|
|
20
|
+
invoke(method: string, params?: any): Promise<any>;
|
|
21
|
+
}
|
|
22
|
+
declare global {
|
|
23
|
+
interface Window {
|
|
24
|
+
craft?: CraftAPI;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
export declare const craft: {
|
|
28
|
+
subscribe: (this: void, run: import("svelte/store").Subscriber<CraftAPI | null>, invalidate?: import("svelte/store").Invalidator<CraftAPI | null> | undefined) => import("svelte/store").Unsubscriber;
|
|
29
|
+
};
|
|
30
|
+
export declare const isReady: import("svelte/store").Readable<boolean>;
|
|
31
|
+
export {};
|
|
32
|
+
//# sourceMappingURL=craft.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"craft.d.ts","sourceRoot":"","sources":["../../src/stores/craft.ts"],"names":[],"mappings":"AAEA,UAAU,QAAQ;IAChB,WAAW,IAAI,OAAO,CAAC;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAC9D,aAAa,IAAI,OAAO,CAAC;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,UAAU,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAClF,SAAS,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,GAAG,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACtE,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACpC,iBAAiB,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC;QAAE,OAAO,EAAE,OAAO,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IACtF,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,GAAG,IAAI,CAAC;IAC5D,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,GAAG,IAAI,CAAC;IAC7D,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,GAAG,GAAG,IAAI,CAAC;IACtC,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC;CACpD;AAED,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,MAAM;QACd,KAAK,CAAC,EAAE,QAAQ,CAAC;KAClB;CACF;AAwBD,eAAO,MAAM,KAAK;;CAAqB,CAAC;AACxC,eAAO,MAAM,OAAO,0CAAgD,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export declare function createPlatformStore(): {
|
|
2
|
+
subscribe: (this: void, run: import("svelte/store").Subscriber<{
|
|
3
|
+
platform: string;
|
|
4
|
+
version: string;
|
|
5
|
+
} | null>, invalidate?: import("svelte/store").Invalidator<{
|
|
6
|
+
platform: string;
|
|
7
|
+
version: string;
|
|
8
|
+
} | null> | undefined) => import("svelte/store").Unsubscriber;
|
|
9
|
+
};
|
|
10
|
+
export declare const platform: {
|
|
11
|
+
subscribe: (this: void, run: import("svelte/store").Subscriber<{
|
|
12
|
+
platform: string;
|
|
13
|
+
version: string;
|
|
14
|
+
} | null>, invalidate?: import("svelte/store").Invalidator<{
|
|
15
|
+
platform: string;
|
|
16
|
+
version: string;
|
|
17
|
+
} | null> | undefined) => import("svelte/store").Unsubscriber;
|
|
18
|
+
};
|
|
19
|
+
//# sourceMappingURL=platform.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"platform.d.ts","sourceRoot":"","sources":["../../src/stores/platform.ts"],"names":[],"mappings":"AAGA,wBAAgB,mBAAmB;;kBACe,MAAM;iBAAW,MAAM;;kBAAvB,MAAM;iBAAW,MAAM;;EAUxE;AAED,eAAO,MAAM,QAAQ;;kBAZ6B,MAAM;iBAAW,MAAM;;kBAAvB,MAAM;iBAAW,MAAM;;CAY5B,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare const trayVisible: import("svelte/store").Writable<boolean>;
|
|
2
|
+
export declare const trayActions: {
|
|
3
|
+
create(icon?: string, tooltip?: string): Promise<void>;
|
|
4
|
+
destroy(): Promise<void>;
|
|
5
|
+
setIcon(icon: string): Promise<void>;
|
|
6
|
+
};
|
|
7
|
+
//# sourceMappingURL=tray.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tray.d.ts","sourceRoot":"","sources":["../../src/stores/tray.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,WAAW,0CAAkB,CAAC;AAE3C,eAAO,MAAM,WAAW;kBACF,MAAM,YAAY,MAAM;;kBAcxB,MAAM;CAK3B,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export declare const isFullscreen: import("svelte/store").Writable<boolean>;
|
|
2
|
+
export declare const isMaximized: import("svelte/store").Writable<boolean>;
|
|
3
|
+
export declare const isMinimized: import("svelte/store").Writable<boolean>;
|
|
4
|
+
export declare const windowActions: {
|
|
5
|
+
setTitle(title: string): Promise<void>;
|
|
6
|
+
setSize(width: number, height: number): Promise<void>;
|
|
7
|
+
maximize(): Promise<void>;
|
|
8
|
+
minimize(): Promise<void>;
|
|
9
|
+
toggleFullscreen(): Promise<void>;
|
|
10
|
+
close(): Promise<void>;
|
|
11
|
+
};
|
|
12
|
+
//# sourceMappingURL=window.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"window.d.ts","sourceRoot":"","sources":["../../src/stores/window.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,YAAY,0CAAkB,CAAC;AAC5C,eAAO,MAAM,WAAW,0CAAkB,CAAC;AAC3C,eAAO,MAAM,WAAW,0CAAkB,CAAC;AAE3C,eAAO,MAAM,aAAa;oBACF,MAAM;mBAMP,MAAM,UAAU,MAAM;;;;;CAgC5C,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@craft-native/svelte",
|
|
3
|
+
"version": "0.0.72",
|
|
4
|
+
"homepage": "https://github.com/craft-native/craft/tree/main/packages/svelte#readme",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "git+https://github.com/craft-native/craft.git",
|
|
8
|
+
"directory": "packages/svelte"
|
|
9
|
+
},
|
|
10
|
+
"bugs": {
|
|
11
|
+
"url": "https://github.com/craft-native/craft/issues"
|
|
12
|
+
},
|
|
13
|
+
"files": [
|
|
14
|
+
"dist"
|
|
15
|
+
],
|
|
16
|
+
"description": "Svelte bindings for Craft framework",
|
|
17
|
+
"svelte": "src/index.ts",
|
|
18
|
+
"main": "dist/index.js",
|
|
19
|
+
"module": "dist/index.mjs",
|
|
20
|
+
"types": "dist/index.d.ts",
|
|
21
|
+
"exports": {
|
|
22
|
+
".": {
|
|
23
|
+
"svelte": "./src/index.ts",
|
|
24
|
+
"import": "./dist/index.mjs",
|
|
25
|
+
"require": "./dist/index.js",
|
|
26
|
+
"types": "./dist/index.d.ts"
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
"scripts": {
|
|
30
|
+
"build": "tsup src/index.ts --format cjs,esm && tsc --emitDeclarationOnly",
|
|
31
|
+
"dev": "tsup src/index.ts --format cjs,esm --watch"
|
|
32
|
+
},
|
|
33
|
+
"keywords": [
|
|
34
|
+
"craft",
|
|
35
|
+
"svelte",
|
|
36
|
+
"stores",
|
|
37
|
+
"actions",
|
|
38
|
+
"native"
|
|
39
|
+
],
|
|
40
|
+
"author": "Craft Team",
|
|
41
|
+
"license": "MIT",
|
|
42
|
+
"peerDependencies": {
|
|
43
|
+
"svelte": "^3.0.0 || ^4.0.0"
|
|
44
|
+
},
|
|
45
|
+
"devDependencies": {
|
|
46
|
+
"svelte": "^4.0.0",
|
|
47
|
+
"tsup": "^8.0.0",
|
|
48
|
+
"typescript": "^7.0.2"
|
|
49
|
+
}
|
|
50
|
+
}
|