@craft-native/vue 0.0.91 → 0.0.94

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,541 @@
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
+ try {
454
+ await craft.value.haptic(type);
455
+ } catch (error) {
456
+ if (error?.code !== "CAPABILITY_DISABLED") throw error;
457
+ }
458
+ };
459
+ return { haptic };
460
+ }
461
+ function usePermission(permission) {
462
+ const { craft, isReady } = useCraft();
463
+ const granted = ref6(null);
464
+ const loading = ref6(false);
465
+ const error = ref6(null);
466
+ const request = async () => {
467
+ if (!isReady.value || !craft.value) {
468
+ console.warn("Craft not ready");
469
+ return;
470
+ }
471
+ loading.value = true;
472
+ try {
473
+ const result = await craft.value.requestPermission(permission);
474
+ granted.value = result.granted;
475
+ } catch (err) {
476
+ error.value = err;
477
+ } finally {
478
+ loading.value = false;
479
+ }
480
+ };
481
+ return { granted, request, loading, error };
482
+ }
483
+ function useCraftEvent(event, callback) {
484
+ const { craft, isReady } = useCraft();
485
+ const unsubscribe = () => {
486
+ if (craft.value) {
487
+ craft.value.off(event, callback);
488
+ }
489
+ };
490
+ watch(isReady, (ready) => {
491
+ if (ready && craft.value) {
492
+ craft.value.on(event, callback);
493
+ }
494
+ }, { immediate: true });
495
+ onUnmounted(unsubscribe);
496
+ return { unsubscribe };
497
+ }
498
+ function useCraftInvoke() {
499
+ const { craft, isReady } = useCraft();
500
+ const invoke = async (method, params) => {
501
+ if (!isReady.value || !craft.value) {
502
+ throw new Error("Craft not ready");
503
+ }
504
+ return await craft.value.invoke(method, params);
505
+ };
506
+ return { invoke, isReady };
507
+ }
508
+ function useIsMobile() {
509
+ const { platform } = usePlatform();
510
+ const isMobile = computed(() => {
511
+ if (!platform.value) return false;
512
+ return platform.value.platform === "ios" || platform.value.platform === "android";
513
+ });
514
+ return isMobile;
515
+ }
516
+ function useIsDesktop() {
517
+ const { platform } = usePlatform();
518
+ const isDesktop = computed(() => {
519
+ if (!platform.value) return false;
520
+ return ["macos", "windows", "linux"].includes(platform.value.platform);
521
+ });
522
+ return isDesktop;
523
+ }
524
+ export {
525
+ useCraft,
526
+ useCraftEvent,
527
+ useCraftInvoke,
528
+ useDatabase,
529
+ useDeviceInfo,
530
+ useFileSystem,
531
+ useHaptic,
532
+ useHttp,
533
+ useIsDesktop,
534
+ useIsMobile,
535
+ useNotification,
536
+ usePermission,
537
+ usePlatform,
538
+ useToast,
539
+ useTray,
540
+ useWindow
541
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@craft-native/vue",
3
- "version": "0.0.91",
3
+ "version": "0.0.94",
4
4
  "homepage": "https://github.com/craft-native/craft/tree/main/packages/vue#readme",
5
5
  "repository": {
6
6
  "type": "git",
@@ -19,9 +19,9 @@
19
19
  "types": "dist/index.d.ts",
20
20
  "exports": {
21
21
  ".": {
22
+ "types": "./dist/index.d.ts",
22
23
  "import": "./dist/index.mjs",
23
- "require": "./dist/index.js",
24
- "types": "./dist/index.d.ts"
24
+ "require": "./dist/index.js"
25
25
  }
26
26
  },
27
27
  "scripts": {
@@ -42,7 +42,7 @@
42
42
  "vue": "^3.0.0"
43
43
  },
44
44
  "devDependencies": {
45
- "vue": "^3.3.0",
45
+ "vue": "^3.5.43",
46
46
  "tsup": "^8.0.0",
47
47
  "typescript": "^7.0.2"
48
48
  }
package/LICENSE.md DELETED
@@ -1,21 +0,0 @@
1
- # MIT License
2
-
3
- Copyright (c) 2025 Stacks.js
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.