@stacksjs/mobile 0.73.2 → 0.74.0
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.js +1 -1
- package/package.json +6 -4
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var C=Object.defineProperty;var S=(e)=>e;function E(e,t){this[e]=S.bind(null,t)}var x=(e,t)=>{for(var n in t)C(e,n,{get:t[n],enumerable:!0,configurable:!0,set:E.bind(t,n)})};var y={};x(y,{_resetWebFallbackDeviceIdForTests:()=>T,_webFallbackDeviceId:()=>m,appReview:()=>K,biometrics:()=>W,camera:()=>N,deepLinks:()=>B,device:()=>P,haptics:()=>I,health:()=>j,keepAwake:()=>q,lifecycle:()=>M,liveActivities:()=>O,location:()=>v,network:()=>F,normalizeDeepLinkURL:()=>d,notifications:()=>_,permissions:()=>D,pushNotifications:()=>z,secureStorage:()=>U,share:()=>H,watchConnectivity:()=>V});function g(){let e=globalThis.crypto;if(e&&typeof e.randomUUID==="function")return e.randomUUID();if(e&&typeof e.getRandomValues==="function"){let t=new Uint8Array(16);e.getRandomValues(t),t[6]=t[6]&15|64,t[8]=t[8]&63|128;let n=Array.from(t,(r)=>r.toString(16).padStart(2,"0")).join("");return`${n.slice(0,8)}-${n.slice(8,12)}-${n.slice(12,16)}-${n.slice(16,20)}-${n.slice(20,32)}`}throw Error("[Craft] No Web Crypto available; cannot generate secure IDs")}var h="__craft_web_device_id__";function m(){if(typeof globalThis<"u"&&globalThis.localStorage)try{let e=globalThis.localStorage,t=e.getItem(h);if(t&&/^web-[0-9a-f-]+$/i.test(t))return t;let n=`web-${g()}`;return e.setItem(h,n),n}catch{}return`web-${g()}`}function T(){if(typeof globalThis<"u"&&globalThis.localStorage)try{globalThis.localStorage.removeItem(h)}catch{}}var P={async getInfo(){let e=i();if(typeof window<"u"&&e?.device)return e.device.getInfo();return{platform:u(),osVersion:"unknown",model:"unknown",manufacturer:"unknown",deviceId:m(),isTablet:!1,screen:{width:typeof window<"u"?window.innerWidth||0:0,height:typeof window<"u"?window.innerHeight||0:0,scale:typeof window<"u"?window.devicePixelRatio||1:1},battery:{level:100,isCharging:!1},network:{type:"wifi",isConnected:typeof navigator<"u"?navigator.onLine??!0:!0}}},async getCapabilities(){let e=i();if(typeof window<"u"&&e?.device)return e.device.getCapabilities();return{camera:!0,biometrics:!1,nfc:!1,bluetooth:!1,gps:"geolocation"in navigator,accelerometer:!1,gyroscope:!1,haptics:"vibrate"in navigator,ar:!1,faceId:!1,touchId:!1}},isMobile(){let e=u();return e==="ios"||e==="android"},isIOS(){return u()==="ios"},isAndroid(){return u()==="android"},getLocale(){return navigator?.language||"en-US"},getTimezone(){return Intl.DateTimeFormat().resolvedOptions().timeZone}},I={async impact(e="medium"){let t=i();if(typeof window<"u"&&t?.haptics)return t.haptics.impact(e);if("vibrate"in navigator){let n={light:10,medium:20,heavy:30,soft:5,rigid:25}[e];navigator.vibrate(n)}},async notification(e="success"){let t=i();if(typeof window<"u"&&t?.haptics)return t.haptics.notification(e);if("vibrate"in navigator){let n={success:[10,30,10],warning:[30,30,30],error:[50,50,50,50,50]};navigator.vibrate(n[e])}},async selection(){let e=i();if(typeof window<"u"&&e?.haptics)return e.haptics.selection();if("vibrate"in navigator)navigator.vibrate(5)},async vibrate(e){let t=i();if(typeof window<"u"&&t?.haptics)return t.haptics.vibrate(e);if("vibrate"in navigator)navigator.vibrate(e)}},D={async check(e){let t=i();if(typeof window<"u"&&t?.permissions)return t.permissions.check(e);try{let n=Y(e);if(n&&navigator.permissions){let r=await navigator.permissions.query({name:n});return Z(r.state)}}catch{}return"undetermined"},async request(e){let t=i();if(typeof window<"u"&&t?.permissions)return t.permissions.request(e);try{if(e==="camera"||e==="microphone"){let n={};if(e==="camera")n.video=!0;if(e==="microphone")n.audio=!0;return(await navigator.mediaDevices.getUserMedia(n)).getTracks().forEach((a)=>a.stop()),"granted"}if(e==="location")return new Promise((n)=>{navigator.geolocation.getCurrentPosition(()=>n("granted"),()=>n("denied"))});if(e==="notifications")return await Notification.requestPermission()==="granted"?"granted":"denied"}catch{return"denied"}return"undetermined"},async checkMultiple(e){let t={};for(let n of e)t[n]=await this.check(n);return t},async requestMultiple(e){let t={};for(let n of e)t[n]=await this.request(n);return t},async openSettings(){let e=i();if(typeof window<"u"&&e?.permissions)return e.permissions.openSettings()}},N={async takePicture(e={}){let t=i();if(typeof window<"u"&&t?.camera)return t.camera.takePicture(e);throw Error("Camera API not available. Must run in Craft environment.")},async pickImage(){let e=i();if(typeof window<"u"&&e?.camera)return e.camera.pickImage();return new Promise((t,n)=>{let r=document.createElement("input");r.type="file",r.accept="image/*",r.onchange=async()=>{let a=r.files?.[0];if(a){let f=new FileReader;f.onload=()=>{let R=f.result.split(",")[1];t({base64:R,uri:URL.createObjectURL(a),width:0,height:0,mimeType:a.type})},f.onerror=()=>n(Error("Failed to read file")),f.readAsDataURL(a)}else n(Error("No file selected"))},r.click()})},async pickMultiple(e={}){let t=i();if(typeof window<"u"&&t?.camera)return t.camera.pickMultiple(e);throw Error("Camera API not available. Must run in Craft environment.")},async isAvailable(){let e=i();if(typeof window<"u"&&e?.camera)return e.camera.isAvailable();try{return(await navigator.mediaDevices.enumerateDevices()).some((n)=>n.kind==="videoinput")}catch{return!1}}},W={async isAvailable(){let e=i();if(typeof window<"u"&&e?.biometrics)return e.biometrics.isAvailable();return!1},async getBiometricType(){let e=i();if(typeof window<"u"&&e?.biometrics)return e.biometrics.getBiometricType();return null},async authenticate(e){let t=i();if(typeof window<"u"&&t?.biometrics)return t.biometrics.authenticate(e);throw Error("Biometrics not available")}},U={async set(e,t){let n=i();if(typeof window<"u"&&n?.secureStorage)return n.secureStorage.set(e,t);if(typeof window<"u"&&window.craft)throw Error("Craft secure storage bridge is unavailable");localStorage.setItem(`secure_${e}`,t)},async get(e){let t=i();if(typeof window<"u"&&t?.secureStorage)return t.secureStorage.get(e);if(typeof window<"u"&&window.craft)throw Error("Craft secure storage bridge is unavailable");return localStorage.getItem(`secure_${e}`)},async delete(e){let t=i();if(typeof window<"u"&&t?.secureStorage)return t.secureStorage.delete(e);if(typeof window<"u"&&window.craft)throw Error("Craft secure storage bridge is unavailable");localStorage.removeItem(`secure_${e}`)},async clear(){let e=i();if(typeof window<"u"&&e?.secureStorage)return e.secureStorage.clear();if(typeof window<"u"&&window.craft)throw Error("Craft secure storage bridge is unavailable");Object.keys(localStorage).filter((t)=>t.startsWith("secure_")).forEach((t)=>localStorage.removeItem(t))}},o={id:null,active:!1,paused:!1,startedAt:null,locations:[]},s=null,v={async getCurrentPosition(e={}){let t=i();if(typeof window<"u"&&t?.location)return t.location.getCurrentPosition(e);return new Promise((n,r)=>{navigator.geolocation.getCurrentPosition((a)=>n({latitude:a.coords.latitude,longitude:a.coords.longitude,altitude:a.coords.altitude??void 0,accuracy:a.coords.accuracy,heading:a.coords.heading??void 0,speed:a.coords.speed??void 0,timestamp:a.timestamp}),r,{enableHighAccuracy:e.enableHighAccuracy,timeout:e.timeout,maximumAge:e.maximumAge})})},watchPosition(e,t={}){let n=i();if(typeof window<"u"&&n?.location)return n.location.watchPosition(e,t);return navigator.geolocation.watchPosition((r)=>e({latitude:r.coords.latitude,longitude:r.coords.longitude,altitude:r.coords.altitude??void 0,accuracy:r.coords.accuracy,heading:r.coords.heading??void 0,speed:r.coords.speed??void 0,timestamp:r.timestamp}),console.error,{enableHighAccuracy:t.enableHighAccuracy,timeout:t.timeout,maximumAge:t.maximumAge})},clearWatch(e){let t=i();if(typeof window<"u"&&t?.location)return t.location.clearWatch(e);navigator.geolocation.clearWatch(e)},async startRecording(e={}){let t=i();if(typeof window<"u"&&t?.location?.startRecording)return t.location.startRecording(e);if(s!==null)navigator.geolocation.clearWatch(s);return o={id:g(),active:!0,paused:!1,startedAt:Date.now(),locations:[]},s=v.watchPosition((n)=>{if(!o.paused)o.locations.push(n)},e),{...o,sampleCount:0}},async pauseRecording(){let e=i();if(typeof window<"u"&&e?.location?.pauseRecording)return e.location.pauseRecording();return o.paused=!0,{...o,sampleCount:o.locations.length}},async resumeRecording(){let e=i();if(typeof window<"u"&&e?.location?.resumeRecording)return e.location.resumeRecording();return o.paused=!1,{...o,sampleCount:o.locations.length}},async stopRecording(){let e=i();if(typeof window<"u"&&e?.location?.stopRecording)return e.location.stopRecording();if(s!==null)v.clearWatch(s),s=null;return o.active=!1,o.paused=!1,{...o,locations:[...o.locations]}},async getRecordingState(){let e=i();if(typeof window<"u"&&e?.location?.getRecordingState)return e.location.getRecordingState();return{...o,sampleCount:o.locations.length}},async readRecording(){let e=i();if(typeof window<"u"&&e?.location?.readRecording)return e.location.readRecording();return[...o.locations]}},H={async share(e){let t=i();if(typeof window<"u"&&t?.share)return t.share.share(e);if(navigator.share)await navigator.share({title:e.title,text:e.text,url:e.url});else throw Error("Share API not available")},isAvailable(){let e=i();if(typeof window<"u"&&e?.share)return!0;return"share"in navigator}},M={getState(){let e=i();if(typeof window<"u"&&e?.lifecycle)return e.lifecycle.getState();return document.visibilityState==="visible"?"active":"background"},onStateChange(e){let t=i();if(typeof window<"u"&&t?.lifecycle)return t.lifecycle.onStateChange(e);let n=()=>{e(document.visibilityState==="visible"?"active":"background")};return document.addEventListener("visibilitychange",n),()=>document.removeEventListener("visibilitychange",n)}},_={async show(e){let t=i();if(typeof window<"u"&&t?.notifications)return t.notifications.show(e);if("Notification"in window&&Notification.permission==="granted")new Notification(e.title,{body:e.body})},async schedule(e){let t=i();if(typeof window<"u"&&t?.notifications)return t.notifications.schedule(e);throw Error("Scheduled notifications not available in web")},async cancelAll(){let e=i();if(typeof window<"u"&&e?.notifications)return e.notifications.cancelAll()},async setBadge(e){let t=i();if(typeof window<"u"&&t?.notifications)return t.notifications.setBadge(e)}},p=null,q={async enable(){let e=c();if(e?.setKeepAwake){await e.setKeepAwake(!0);return}p=await navigator.wakeLock?.request("screen")??null},async disable(){let e=c();if(e?.setKeepAwake){await e.setKeepAwake(!1);return}await p?.release(),p=null}},B={async getInitialURL(){return d(await c()?.deepLinks?.getInitialURL?.())},onLink(e){let t=c();if(t?.deepLinks?.onLink)return t.deepLinks.onLink((r)=>{let a=d(r);if(a)e(a)})??(()=>{});if(typeof globalThis>"u")return()=>{};let n=(r)=>{let a=d(r.detail);if(a)e(a)};return globalThis.addEventListener("craftDeepLink",n),()=>globalThis.removeEventListener("craftDeepLink",n)}};function d(e){if(typeof e==="string")return e.trim()||null;if(!e||typeof e!=="object")return null;let t=e.url;return typeof t==="string"&&t.trim()?t:null}var F={async getStatus(){let e=c();if(e?.getNetworkStatus)return await e.getNetworkStatus();return{type:"unknown",isConnected:typeof navigator>"u"?!1:navigator.onLine}},onChange(e){let t=c();if(t?.onNetworkChange)return t.onNetworkChange(e),()=>t.offNetworkChange?.();if(typeof globalThis>"u")return()=>{};let n=()=>e({type:"unknown",isConnected:navigator.onLine});return globalThis.addEventListener("online",n),globalThis.addEventListener("offline",n),()=>{globalThis.removeEventListener("online",n),globalThis.removeEventListener("offline",n)}}},K={async request(){let e=c();if(!e?.requestReview)return!1;return Boolean(await e.requestReview())}},z={async register(){let e=c();if(!e?.registerPush)throw Error("Push notifications are unavailable");return e.registerPush()},onToken(e){return l("craftPushToken",(t)=>e(String(t.token??"")))},onNotification(e){return l("craftNotificationResponse",(t)=>e(t))}},j={async requestAuthorization(e){let t=c();if(!t?.health?.requestAuthorization)throw Error("Health data is unavailable");return Boolean(await t.health.requestAuthorization(e))},async getData(e,t={}){let n=c();if(!n?.health?.getData)throw Error("Health data is unavailable");return n.health.getData(e,t)},async saveWorkout(e){let t=c();if(!t?.health?.saveWorkout)throw Error("Saving health workouts is unavailable");return t.health.saveWorkout(e)}},O={async start(e){let t=c();if(!t?.liveActivity?.start)throw Error("Live Activities are unavailable");return t.liveActivity.start(e)},async update(e){let t=c();if(!t?.liveActivity?.update)return;await t.liveActivity.update(e)},async end(){let e=c();if(!e?.liveActivity?.end)return;await e.liveActivity.end()}},V={async send(e){let t=c();if(!t?.watch?.send)throw Error("Apple Watch connectivity is unavailable");return t.watch.send(e)},async updateContext(e){let t=c();if(!t?.watch?.updateContext)throw Error("Apple Watch connectivity is unavailable");await t.watch.updateContext(e)},async isReachable(){let e=await c()?.watch?.isReachable?.();return Boolean(e?.reachable)},onMessage(e){return l("craftWatchMessage",e)},onReachabilityChange(e){return l("craftWatchReachability",(t)=>e(Boolean(t.reachable)))}};function l(e,t){if(typeof globalThis>"u")return()=>{};let n=(r)=>t(r.detail??{});return globalThis.addEventListener(e,n),()=>globalThis.removeEventListener(e,n)}function c(){if(typeof window>"u")return;return window.craft}function u(){if(typeof window>"u")return"linux";let e=navigator.userAgent.toLowerCase();if(/iphone|ipad|ipod/.test(e))return"ios";if(/android/.test(e))return"android";if(/macintosh|mac os x/.test(e))return"macos";if(/windows/.test(e))return"windows";return"linux"}function Y(e){return{camera:"camera",microphone:"microphone",location:"geolocation",notifications:"notifications"}[e]||null}function Z(e){return{granted:"granted",denied:"denied",prompt:"undetermined"}[e]}function i(){if(typeof window<"u")return window.craft;return}var{biometrics:G,camera:J,device:Q,haptics:X,lifecycle:ee,location:te,notifications:ne,permissions:ie,secureStorage:re,share:ae,appReview:oe,deepLinks:b,keepAwake:ce,network:se,pushNotifications:fe,health:ue,liveActivities:de,watchConnectivity:le}=y,we=G,pe=J,k=Q,w=X,ge=ee,he=te,ve=ne,ye=ie,me=re,be=ae,Ae=oe;function A(e){if(typeof e==="string")return e.trim()||null;if(!e||typeof e!=="object")return null;let t=e.url;return typeof t==="string"&&t.trim()?t:null}var ke={async getInitialURL(){return A(await b.getInitialURL?.())},onLink(e){return b.onLink?.((t)=>{let n=A(t);if(n)e(n)})??(()=>{})}},Le=ce,Re=se,Ce=fe,Se=ue,Ee=de,xe=le;function L(){if(typeof globalThis>"u")return;return globalThis}function Te(){let e=L();return Boolean(e?.craft)&&k.isMobile()}function Pe(e){let t=L();if(!t)return()=>{};if(t.craft)return queueMicrotask(()=>e(new Event("craftReady"))),()=>{};let n=(r)=>e(r);return t.addEventListener("craftReady",n,{once:!0}),()=>t.removeEventListener("craftReady",n)}async function Ie(e){await w.impact("light");try{let t=await e();return await w.notification("success"),t}catch(t){throw await w.notification("error"),t}}var Ne={biometrics:we,camera:pe,device:k,haptics:w,lifecycle:ge,location:he,notifications:ve,permissions:ye,secureStorage:me,share:be,appReview:Ae,deepLinks:ke,keepAwake:Le,network:Re,pushNotifications:Ce,health:Se,liveActivities:Ee,watchConnectivity:xe,isNativeMobile:Te,onReady:Pe,withFeedback:Ie};export{Ae as appReview,we as biometrics,pe as camera,ke as deepLinks,k as device,w as haptics,Se as health,Te as isNativeMobile,Le as keepAwake,ge as lifecycle,Ee as liveActivities,he as location,Ne as mobile,Re as network,A as normalizeDeepLinkURL,ve as notifications,Pe as onMobileReady,ye as permissions,Ce as pushNotifications,me as secureStorage,be as share,xe as watchConnectivity,Ie as withNativeFeedback};
|
|
1
|
+
import*as p from"craft-native/mobile";var{biometrics:f,camera:A,device:u,haptics:l,lifecycle:v,location:h,notifications:w,permissions:m,secureStorage:d,share:y,appReview:k,deepLinks:n,keepAwake:x,network:L,pushNotifications:R,health:g,liveActivities:C,watchConnectivity:N}=p,b=f,S=A,c=u,o=l,E=v,H=h,P=w,D=m,T=d,M=y,B=k;function r(t){if(typeof t==="string")return t.trim()||null;if(!t||typeof t!=="object")return null;let e=t.url;return typeof e==="string"&&e.trim()?e:null}var K={async getInitialURL(){return r(await n.getInitialURL?.())},onLink(t){return n.onLink?.((e)=>{let i=r(e);if(i)t(i)})??(()=>{})}},U=x,W=L,F=R,I=g,j=C,q=N;function a(){if(typeof globalThis>"u")return;return globalThis}function z(){let t=a();return Boolean(t?.craft)&&c.isMobile()}function G(t){let e=a();if(!e)return()=>{};if(e.craft)return queueMicrotask(()=>t(new Event("craftReady"))),()=>{};let i=(s)=>t(s);return e.addEventListener("craftReady",i,{once:!0}),()=>e.removeEventListener("craftReady",i)}async function J(t){await o.impact("light");try{let e=await t();return await o.notification("success"),e}catch(e){throw await o.notification("error"),e}}var O={biometrics:b,camera:S,device:c,haptics:o,lifecycle:E,location:H,notifications:P,permissions:D,secureStorage:T,share:M,appReview:B,deepLinks:K,keepAwake:U,network:W,pushNotifications:F,health:I,liveActivities:j,watchConnectivity:q,isNativeMobile:z,onReady:G,withFeedback:J};export{B as appReview,b as biometrics,S as camera,K as deepLinks,c as device,o as haptics,I as health,z as isNativeMobile,U as keepAwake,E as lifecycle,j as liveActivities,H as location,O as mobile,W as network,r as normalizeDeepLinkURL,P as notifications,G as onMobileReady,D as permissions,F as pushNotifications,T as secureStorage,M as share,q as watchConnectivity,J as withNativeFeedback};
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@stacksjs/mobile",
|
|
3
3
|
"type": "module",
|
|
4
4
|
"sideEffects": false,
|
|
5
|
-
"version": "0.
|
|
5
|
+
"version": "0.74.0",
|
|
6
6
|
"description": "Craft-powered native mobile runtime for Stacks and STX applications",
|
|
7
7
|
"author": "Chris Breuer",
|
|
8
8
|
"license": "MIT",
|
|
@@ -31,9 +31,11 @@
|
|
|
31
31
|
"typecheck": "bun tsc --noEmit",
|
|
32
32
|
"test": "bun test"
|
|
33
33
|
},
|
|
34
|
+
"dependencies": {
|
|
35
|
+
"craft-native": ">=0.0.72"
|
|
36
|
+
},
|
|
34
37
|
"devDependencies": {
|
|
35
|
-
"@stacksjs/build": "0.
|
|
36
|
-
"better-dx": "^0.2.24"
|
|
37
|
-
"craft-native": "^0.0.76"
|
|
38
|
+
"@stacksjs/build": "0.74.0",
|
|
39
|
+
"better-dx": "^0.2.24"
|
|
38
40
|
}
|
|
39
41
|
}
|