@craft-native/vue 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/dist/index.mjs ADDED
@@ -0,0 +1,537 @@
1
+ // src/index.ts
2
+ import { ref as ref6, onMounted, onUnmounted, computed, watch } from "vue";
3
+
4
+ // src/composables/useWindow.ts
5
+ import { ref } from "vue";
6
+ function useWindow() {
7
+ const { craft, isReady } = useCraft();
8
+ const isFullscreen = ref(false);
9
+ const isMaximized = ref(false);
10
+ const isMinimized = ref(false);
11
+ const setTitle = async (title) => {
12
+ if (!isReady.value || !craft.value) return;
13
+ await craft.value.invoke("window.setTitle", { title });
14
+ };
15
+ const setSize = async (width, height) => {
16
+ if (!isReady.value || !craft.value) return;
17
+ await craft.value.invoke("window.setSize", { width, height });
18
+ };
19
+ const setPosition = async (x, y) => {
20
+ if (!isReady.value || !craft.value) return;
21
+ await craft.value.invoke("window.setPosition", { x, y });
22
+ };
23
+ const maximize = async () => {
24
+ if (!isReady.value || !craft.value) return;
25
+ await craft.value.invoke("window.maximize");
26
+ isMaximized.value = true;
27
+ };
28
+ const minimize = async () => {
29
+ if (!isReady.value || !craft.value) return;
30
+ await craft.value.invoke("window.minimize");
31
+ isMinimized.value = true;
32
+ };
33
+ const restore = async () => {
34
+ if (!isReady.value || !craft.value) return;
35
+ await craft.value.invoke("window.restore");
36
+ isMaximized.value = false;
37
+ isMinimized.value = false;
38
+ };
39
+ const toggleFullscreen = async () => {
40
+ if (!isReady.value || !craft.value) return;
41
+ await craft.value.invoke("window.toggleFullscreen");
42
+ isFullscreen.value = !isFullscreen.value;
43
+ };
44
+ const close = async () => {
45
+ if (!isReady.value || !craft.value) return;
46
+ await craft.value.invoke("window.close");
47
+ };
48
+ const center = async () => {
49
+ if (!isReady.value || !craft.value) return;
50
+ await craft.value.invoke("window.center");
51
+ };
52
+ const setAlwaysOnTop = async (alwaysOnTop) => {
53
+ if (!isReady.value || !craft.value) return;
54
+ await craft.value.invoke("window.setAlwaysOnTop", { alwaysOnTop });
55
+ };
56
+ return {
57
+ isFullscreen,
58
+ isMaximized,
59
+ isMinimized,
60
+ setTitle,
61
+ setSize,
62
+ setPosition,
63
+ maximize,
64
+ minimize,
65
+ restore,
66
+ toggleFullscreen,
67
+ close,
68
+ center,
69
+ setAlwaysOnTop
70
+ };
71
+ }
72
+
73
+ // src/composables/useTray.ts
74
+ import { ref as ref2 } from "vue";
75
+ function useTray() {
76
+ const { craft, isReady } = useCraft();
77
+ const isVisible = ref2(false);
78
+ const create = async (icon, tooltip) => {
79
+ if (!isReady.value || !craft.value) return;
80
+ await craft.value.invoke("tray.create", { icon, tooltip });
81
+ isVisible.value = true;
82
+ };
83
+ const destroy = async () => {
84
+ if (!isReady.value || !craft.value) return;
85
+ await craft.value.invoke("tray.destroy");
86
+ isVisible.value = false;
87
+ };
88
+ const setIcon = async (icon) => {
89
+ if (!isReady.value || !craft.value) return;
90
+ await craft.value.invoke("tray.setIcon", { icon });
91
+ };
92
+ const setTooltip = async (tooltip) => {
93
+ if (!isReady.value || !craft.value) return;
94
+ await craft.value.invoke("tray.setTooltip", { tooltip });
95
+ };
96
+ const setMenu = async (menu) => {
97
+ if (!isReady.value || !craft.value) return;
98
+ await craft.value.invoke("tray.setMenu", { menu });
99
+ };
100
+ const setTitle = async (title) => {
101
+ if (!isReady.value || !craft.value) return;
102
+ await craft.value.invoke("tray.setTitle", { title });
103
+ };
104
+ return {
105
+ isVisible,
106
+ create,
107
+ destroy,
108
+ setIcon,
109
+ setTooltip,
110
+ setMenu,
111
+ setTitle
112
+ };
113
+ }
114
+
115
+ // src/composables/useNotification.ts
116
+ function useNotification() {
117
+ const { craft, isReady } = useCraft();
118
+ const send = async (options) => {
119
+ if (!isReady.value || !craft.value) return;
120
+ await craft.value.invoke("notification.send", options);
121
+ };
122
+ const requestPermission = async () => {
123
+ if (!isReady.value || !craft.value) return false;
124
+ const result = await craft.value.requestPermission("notifications");
125
+ return result.granted;
126
+ };
127
+ return {
128
+ send,
129
+ requestPermission
130
+ };
131
+ }
132
+
133
+ // src/composables/useFileSystem.ts
134
+ import { ref as ref3 } from "vue";
135
+ function useFileSystem() {
136
+ const { craft, isReady } = useCraft();
137
+ const loading = ref3(false);
138
+ const error = ref3(null);
139
+ const readFile = async (path, encoding = "utf8") => {
140
+ if (!isReady.value || !craft.value) throw new Error("Craft not ready");
141
+ loading.value = true;
142
+ error.value = null;
143
+ try {
144
+ const result = await craft.value.invoke("fs.readFile", { path, encoding });
145
+ return result;
146
+ } catch (err) {
147
+ error.value = err;
148
+ throw err;
149
+ } finally {
150
+ loading.value = false;
151
+ }
152
+ };
153
+ const writeFile = async (path, data, encoding = "utf8") => {
154
+ if (!isReady.value || !craft.value) throw new Error("Craft not ready");
155
+ loading.value = true;
156
+ error.value = null;
157
+ try {
158
+ await craft.value.invoke("fs.writeFile", { path, data, encoding });
159
+ } catch (err) {
160
+ error.value = err;
161
+ throw err;
162
+ } finally {
163
+ loading.value = false;
164
+ }
165
+ };
166
+ const readDir = async (path) => {
167
+ if (!isReady.value || !craft.value) throw new Error("Craft not ready");
168
+ loading.value = true;
169
+ error.value = null;
170
+ try {
171
+ const result = await craft.value.invoke("fs.readDir", { path });
172
+ return result;
173
+ } catch (err) {
174
+ error.value = err;
175
+ throw err;
176
+ } finally {
177
+ loading.value = false;
178
+ }
179
+ };
180
+ const mkdir = async (path, recursive = false) => {
181
+ if (!isReady.value || !craft.value) throw new Error("Craft not ready");
182
+ loading.value = true;
183
+ error.value = null;
184
+ try {
185
+ await craft.value.invoke("fs.mkdir", { path, recursive });
186
+ } catch (err) {
187
+ error.value = err;
188
+ throw err;
189
+ } finally {
190
+ loading.value = false;
191
+ }
192
+ };
193
+ const remove = async (path, recursive = false) => {
194
+ if (!isReady.value || !craft.value) throw new Error("Craft not ready");
195
+ loading.value = true;
196
+ error.value = null;
197
+ try {
198
+ await craft.value.invoke("fs.remove", { path, recursive });
199
+ } catch (err) {
200
+ error.value = err;
201
+ throw err;
202
+ } finally {
203
+ loading.value = false;
204
+ }
205
+ };
206
+ const exists = async (path) => {
207
+ if (!isReady.value || !craft.value) throw new Error("Craft not ready");
208
+ try {
209
+ const result = await craft.value.invoke("fs.exists", { path });
210
+ return result;
211
+ } catch (err) {
212
+ error.value = err;
213
+ return false;
214
+ }
215
+ };
216
+ const stat = async (path) => {
217
+ if (!isReady.value || !craft.value) throw new Error("Craft not ready");
218
+ loading.value = true;
219
+ error.value = null;
220
+ try {
221
+ const result = await craft.value.invoke("fs.stat", { path });
222
+ return result;
223
+ } catch (err) {
224
+ error.value = err;
225
+ throw err;
226
+ } finally {
227
+ loading.value = false;
228
+ }
229
+ };
230
+ return {
231
+ readFile,
232
+ writeFile,
233
+ readDir,
234
+ mkdir,
235
+ remove,
236
+ exists,
237
+ stat,
238
+ loading,
239
+ error
240
+ };
241
+ }
242
+
243
+ // src/composables/useDatabase.ts
244
+ import { ref as ref4 } from "vue";
245
+ function useDatabase(dbPath) {
246
+ const { craft, isReady } = useCraft();
247
+ const loading = ref4(false);
248
+ const error = ref4(null);
249
+ const execute = async (sql, params = []) => {
250
+ if (!isReady.value || !craft.value) throw new Error("Craft not ready");
251
+ loading.value = true;
252
+ error.value = null;
253
+ try {
254
+ const result = await craft.value.invoke("db.execute", { path: dbPath, sql, params });
255
+ return result;
256
+ } catch (err) {
257
+ error.value = err;
258
+ throw err;
259
+ } finally {
260
+ loading.value = false;
261
+ }
262
+ };
263
+ const query = async (sql, params = []) => {
264
+ if (!isReady.value || !craft.value) throw new Error("Craft not ready");
265
+ loading.value = true;
266
+ error.value = null;
267
+ try {
268
+ const result = await craft.value.invoke("db.query", { path: dbPath, sql, params });
269
+ return result;
270
+ } catch (err) {
271
+ error.value = err;
272
+ throw err;
273
+ } finally {
274
+ loading.value = false;
275
+ }
276
+ };
277
+ const transaction = async (callback) => {
278
+ if (!isReady.value || !craft.value) throw new Error("Craft not ready");
279
+ loading.value = true;
280
+ error.value = null;
281
+ try {
282
+ await craft.value.invoke("db.transaction.begin", { path: dbPath });
283
+ try {
284
+ await callback({
285
+ execute: async (sql, params = []) => {
286
+ return await craft.value.invoke("db.execute", { path: dbPath, sql, params });
287
+ }
288
+ });
289
+ await craft.value.invoke("db.transaction.commit", { path: dbPath });
290
+ } catch (err) {
291
+ await craft.value.invoke("db.transaction.rollback", { path: dbPath });
292
+ throw err;
293
+ }
294
+ } catch (err) {
295
+ error.value = err;
296
+ throw err;
297
+ } finally {
298
+ loading.value = false;
299
+ }
300
+ };
301
+ return {
302
+ execute,
303
+ query,
304
+ transaction,
305
+ loading,
306
+ error
307
+ };
308
+ }
309
+
310
+ // src/composables/useHttp.ts
311
+ import { ref as ref5 } from "vue";
312
+ function useHttp() {
313
+ const { craft, isReady } = useCraft();
314
+ const loading = ref5(false);
315
+ const error = ref5(null);
316
+ const fetch = async (url, options = {}) => {
317
+ if (!isReady.value || !craft.value) throw new Error("Craft not ready");
318
+ loading.value = true;
319
+ error.value = null;
320
+ try {
321
+ const result = await craft.value.invoke("http.fetch", { url, ...options });
322
+ return result;
323
+ } catch (err) {
324
+ error.value = err;
325
+ throw err;
326
+ } finally {
327
+ loading.value = false;
328
+ }
329
+ };
330
+ const download = async (url, path, options = {}) => {
331
+ if (!isReady.value || !craft.value) throw new Error("Craft not ready");
332
+ loading.value = true;
333
+ error.value = null;
334
+ if (options.onProgress) {
335
+ craft.value.on("download.progress", options.onProgress);
336
+ }
337
+ try {
338
+ await craft.value.invoke("http.download", { url, path });
339
+ } catch (err) {
340
+ error.value = err;
341
+ throw err;
342
+ } finally {
343
+ if (options.onProgress) {
344
+ craft.value.off("download.progress", options.onProgress);
345
+ }
346
+ loading.value = false;
347
+ }
348
+ };
349
+ const upload = async (url, filePath, options = {}) => {
350
+ if (!isReady.value || !craft.value) throw new Error("Craft not ready");
351
+ loading.value = true;
352
+ error.value = null;
353
+ if (options.onProgress) {
354
+ craft.value.on("upload.progress", options.onProgress);
355
+ }
356
+ try {
357
+ const result = await craft.value.invoke("http.upload", { url, filePath, ...options });
358
+ return result;
359
+ } catch (err) {
360
+ error.value = err;
361
+ throw err;
362
+ } finally {
363
+ if (options.onProgress) {
364
+ craft.value.off("upload.progress", options.onProgress);
365
+ }
366
+ loading.value = false;
367
+ }
368
+ };
369
+ return {
370
+ fetch,
371
+ download,
372
+ upload,
373
+ loading,
374
+ error
375
+ };
376
+ }
377
+
378
+ // src/index.ts
379
+ function useCraft() {
380
+ const craft = ref6(null);
381
+ const isReady = ref6(false);
382
+ onMounted(() => {
383
+ if (window.craft) {
384
+ craft.value = window.craft;
385
+ isReady.value = true;
386
+ } else {
387
+ const checkCraft = setInterval(() => {
388
+ if (window.craft) {
389
+ craft.value = window.craft;
390
+ isReady.value = true;
391
+ clearInterval(checkCraft);
392
+ }
393
+ }, 100);
394
+ onUnmounted(() => clearInterval(checkCraft));
395
+ }
396
+ });
397
+ return { craft, isReady };
398
+ }
399
+ function usePlatform() {
400
+ const { craft, isReady } = useCraft();
401
+ const platform = ref6(null);
402
+ const loading = ref6(true);
403
+ const error = ref6(null);
404
+ watch(isReady, async (ready) => {
405
+ if (ready && craft.value) {
406
+ try {
407
+ platform.value = await craft.value.getPlatform();
408
+ } catch (err) {
409
+ error.value = err;
410
+ } finally {
411
+ loading.value = false;
412
+ }
413
+ }
414
+ }, { immediate: true });
415
+ return { platform, loading, error };
416
+ }
417
+ function useDeviceInfo() {
418
+ const { craft, isReady } = useCraft();
419
+ const deviceInfo = ref6(null);
420
+ const loading = ref6(true);
421
+ const error = ref6(null);
422
+ watch(isReady, async (ready) => {
423
+ if (ready && craft.value) {
424
+ try {
425
+ deviceInfo.value = await craft.value.getDeviceInfo();
426
+ } catch (err) {
427
+ error.value = err;
428
+ } finally {
429
+ loading.value = false;
430
+ }
431
+ }
432
+ }, { immediate: true });
433
+ return { deviceInfo, loading, error };
434
+ }
435
+ function useToast() {
436
+ const { craft, isReady } = useCraft();
437
+ const showToast = async (message, duration = "short") => {
438
+ if (!isReady.value || !craft.value) {
439
+ console.warn("Craft not ready");
440
+ return;
441
+ }
442
+ await craft.value.showToast(message, duration);
443
+ };
444
+ return { showToast };
445
+ }
446
+ function useHaptic() {
447
+ const { craft, isReady } = useCraft();
448
+ const haptic = async (type = "selection") => {
449
+ if (!isReady.value || !craft.value) {
450
+ console.warn("Craft not ready");
451
+ return;
452
+ }
453
+ await craft.value.haptic(type);
454
+ };
455
+ return { haptic };
456
+ }
457
+ function usePermission(permission) {
458
+ const { craft, isReady } = useCraft();
459
+ const granted = ref6(null);
460
+ const loading = ref6(false);
461
+ const error = ref6(null);
462
+ const request = async () => {
463
+ if (!isReady.value || !craft.value) {
464
+ console.warn("Craft not ready");
465
+ return;
466
+ }
467
+ loading.value = true;
468
+ try {
469
+ const result = await craft.value.requestPermission(permission);
470
+ granted.value = result.granted;
471
+ } catch (err) {
472
+ error.value = err;
473
+ } finally {
474
+ loading.value = false;
475
+ }
476
+ };
477
+ return { granted, request, loading, error };
478
+ }
479
+ function useCraftEvent(event, callback) {
480
+ const { craft, isReady } = useCraft();
481
+ const unsubscribe = () => {
482
+ if (craft.value) {
483
+ craft.value.off(event, callback);
484
+ }
485
+ };
486
+ watch(isReady, (ready) => {
487
+ if (ready && craft.value) {
488
+ craft.value.on(event, callback);
489
+ }
490
+ }, { immediate: true });
491
+ onUnmounted(unsubscribe);
492
+ return { unsubscribe };
493
+ }
494
+ function useCraftInvoke() {
495
+ const { craft, isReady } = useCraft();
496
+ const invoke = async (method, params) => {
497
+ if (!isReady.value || !craft.value) {
498
+ throw new Error("Craft not ready");
499
+ }
500
+ return await craft.value.invoke(method, params);
501
+ };
502
+ return { invoke, isReady };
503
+ }
504
+ function useIsMobile() {
505
+ const { platform } = usePlatform();
506
+ const isMobile = computed(() => {
507
+ if (!platform.value) return false;
508
+ return platform.value.platform === "ios" || platform.value.platform === "android";
509
+ });
510
+ return isMobile;
511
+ }
512
+ function useIsDesktop() {
513
+ const { platform } = usePlatform();
514
+ const isDesktop = computed(() => {
515
+ if (!platform.value) return false;
516
+ return ["macos", "windows", "linux"].includes(platform.value.platform);
517
+ });
518
+ return isDesktop;
519
+ }
520
+ export {
521
+ useCraft,
522
+ useCraftEvent,
523
+ useCraftInvoke,
524
+ useDatabase,
525
+ useDeviceInfo,
526
+ useFileSystem,
527
+ useHaptic,
528
+ useHttp,
529
+ useIsDesktop,
530
+ useIsMobile,
531
+ useNotification,
532
+ usePermission,
533
+ usePlatform,
534
+ useToast,
535
+ useTray,
536
+ useWindow
537
+ };
package/package.json ADDED
@@ -0,0 +1,49 @@
1
+ {
2
+ "name": "@craft-native/vue",
3
+ "version": "0.0.72",
4
+ "homepage": "https://github.com/craft-native/craft/tree/main/packages/vue#readme",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "git+https://github.com/craft-native/craft.git",
8
+ "directory": "packages/vue"
9
+ },
10
+ "bugs": {
11
+ "url": "https://github.com/craft-native/craft/issues"
12
+ },
13
+ "files": [
14
+ "dist"
15
+ ],
16
+ "description": "Vue 3 bindings for Craft framework",
17
+ "main": "dist/index.js",
18
+ "module": "dist/index.mjs",
19
+ "types": "dist/index.d.ts",
20
+ "exports": {
21
+ ".": {
22
+ "import": "./dist/index.mjs",
23
+ "require": "./dist/index.js",
24
+ "types": "./dist/index.d.ts"
25
+ }
26
+ },
27
+ "scripts": {
28
+ "build": "tsup src/index.ts --format cjs,esm && tsc --emitDeclarationOnly",
29
+ "dev": "tsup src/index.ts --format cjs,esm --watch"
30
+ },
31
+ "keywords": [
32
+ "craft",
33
+ "vue",
34
+ "vue3",
35
+ "composition-api",
36
+ "composables",
37
+ "native"
38
+ ],
39
+ "author": "Craft Team",
40
+ "license": "MIT",
41
+ "peerDependencies": {
42
+ "vue": "^3.0.0"
43
+ },
44
+ "devDependencies": {
45
+ "vue": "^3.3.0",
46
+ "tsup": "^8.0.0",
47
+ "typescript": "^7.0.2"
48
+ }
49
+ }