@stacksjs/mobile 0.75.88 → 0.75.90

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.
Files changed (2) hide show
  1. package/dist/index.js +1 -1
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- import{appReview as ht,biometrics as yt,camera as St,deepLinks as G,device as vt,haptics as bt,health as At,keepAwake as xt,lifecycle as wt,liveActivities as Rt,location as Et,network as Tt,notifications as kt,permissions as Lt,pushNotifications as Mt,secureStorage as Pt,share as _t,speech as It,watchConnectivity as Nt}from"craft-native/mobile";import{haptics as z}from"craft-native/mobile";function _(){if(typeof window>"u")return;return window}function k(t=_()){if(!t)return 0;if(typeof t.scrollY==="number")return t.scrollY;return t.document?.scrollingElement?.scrollTop??0}function ne(t,n=_()){if(!n)return()=>{};let r=!1,e=typeof requestAnimationFrame==="function"?requestAnimationFrame:(i)=>setTimeout(i,16),o=()=>{if(r)return;r=!0,e(()=>{r=!1,t(k(n))})};return t(k(n)),n.addEventListener("scroll",o,{passive:!0}),()=>n.removeEventListener("scroll",o)}function J(t,n){let r=Math.max(0,-t),e=t<=0?Math.max(0,n)*0.5:0;return Math.round(Math.max(r,e))}function re(t){let n=t.host??_();if(!n)return()=>{};let r=t.threshold??72,e=null,o=!1,i=!1,s=typeof requestAnimationFrame==="function"?requestAnimationFrame:(g)=>setTimeout(g,16),l=null,a=(g)=>{l=null,t.onPull?.(g,o)},c=(g)=>{let b=l!==null;if(l=g,b)return;s(()=>{if(l!==null)a(l)})},h=(g)=>{let b=g.touches?.[0];return b?b.clientY:null},d=(g)=>{if(i||k(n)>0)return;e=h(g),o=!1},f=(g)=>{if(e===null)return;let b=h(g);if(b===null)return;let x=J(k(n),b-e);if(!o&&x>=r)o=!0,Promise.resolve(z.impact("medium")).catch(()=>{});else if(o&&x<r*0.8)o=!1;c(x)},v=async()=>{if(e===null)return;if(e=null,!o){a(0);return}o=!1,i=!0,a(r);try{await t.onRefresh()}finally{i=!1,a(0)}},m=()=>{if(e===null)return;e=null,o=!1,a(0)};return n.addEventListener("touchstart",d,{passive:!0}),n.addEventListener("touchmove",f,{passive:!0}),n.addEventListener("touchend",v),n.addEventListener("touchcancel",m),()=>{l=null,n.removeEventListener("touchstart",d),n.removeEventListener("touchmove",f),n.removeEventListener("touchend",v),n.removeEventListener("touchcancel",m)}}function O(){if(typeof window>"u")return;return window}function Q(t=O()){let n=t?.history?.state;return n!==null&&n!==void 0}function ie(t=O()){if(!Q(t))return!1;return t.history.back(),!0}function se(t,n,r=50){let e=t[t.length-1];if(t.length>=2&&t[t.length-2].path===n)t.pop();else if(!e||e.path!==n)t.push({path:n,title:""});if(t.length>r)t.splice(0,t.length-r);return{current:t[t.length-1],previous:t[t.length-2]??null}}function ae(t,n,r=12){let e=t?.title.trim()??"";return e&&e.length<=r?e:n}function le(){if(typeof window>"u")return[];let t=window;return t.__stacksNavTrail??=[]}function Z(t,n=tt()){let r;try{r=new URL(t)}catch{return null}let e=`${r.search}${r.hash}`;if(r.protocol==="http:"||r.protocol==="https:"){if(!n||r.origin!==n)return null;return`${r.pathname||"/"}${e}`}return`${`/${[r.host,r.pathname.replace(/^\/+/,"")].filter(Boolean).join("/")}`}${e}`}function tt(){if(typeof window>"u")return;return window.location?.origin}var N="stacks-mobile-deep-link";function ue(t,n){let r=(e)=>{let o=Z(e);if(o)t(o)};return n.getInitialURL().then((e)=>{if(!e)return;try{if(sessionStorage.getItem(N)===e)return;sessionStorage.setItem(N,e)}catch{}r(e)}).catch(()=>{}),n.onLink((e,o)=>{if(o?.initial)return;r(e)})}var de=30;function et(t,n){let r=Math.PI/180,e=(n.latitude-t.latitude)*r,o=(n.longitude-t.longitude)*r,i=Math.sin(e/2)**2+Math.cos(t.latitude*r)*Math.cos(n.latitude*r)*Math.sin(o/2)**2;return 12742017.6*Math.asin(Math.min(1,Math.sqrt(i)))}function nt(t,n=25){let r=new Set;return t.filter((e)=>Number.isFinite(e.latitude)&&Number.isFinite(e.longitude)&&Number.isFinite(e.timestamp)&&e.accuracy>=0&&e.accuracy<=n).sort((e,o)=>e.timestamp-o.timestamp).filter((e)=>{if(r.has(e.timestamp))return!1;return r.add(e.timestamp),!0})}function H(t,n={}){let r=nt(t,n.maxAccuracyM??25),e=n.paceWindowS??30,o=[],i=0,s=0,l=null;for(let d of r){let f=o[o.length-1],v=l?(d.timestamp-l.timestamp)/1000:0;if(l=d,!f){o.push({fix:d,cumM:0});continue}if(v>30){o.push({fix:d,cumM:i});continue}let m=(d.timestamp-f.fix.timestamp)/1000,g=et(f.fix,d),b=Math.min(10,Math.max(3,f.fix.accuracy,d.accuracy));if(g<b)continue;if(i+=g,m>0&&g/m>=0.5)s+=m;o.push({fix:d,cumM:i})}let a=o[o.length-1],c=null,h=null;if(a){let d=a.fix.timestamp-e*1000,f=o.find((g)=>g.fix.timestamp>=d)??a,v=a.cumM-f.cumM,m=(a.fix.timestamp-f.fix.timestamp)/1000;if(v>=20&&m>0)h=v/m,c=m/(v/1000)}return{distanceM:i,movingS:s,paceSPerKm:c,averagePaceSPerKm:i>=50&&s>0?s/(i/1000):null,speedMps:h,accuracyM:r.length?r[r.length-1].accuracy:t.length?t[t.length-1].accuracy??null:null,fixes:r.length}}function pe(t){if(!t||!Number.isFinite(t)||t>3600)return"–";let n=Math.round(t);return`${Math.floor(n/60)}:${String(n%60).padStart(2,"0")}`}function fe(t){return t&&Number.isFinite(t)?(t*3.6).toFixed(1):"–"}var K={distanceM:0,movingS:0,paceSPerKm:null,averagePaceSPerKm:null,speedMps:null,accuracyM:null,fixes:0};function me(t){let n=t.location,r=t.intervalMs??3000,e=K,o=null,i=()=>typeof document<"u"&&document.visibilityState==="hidden";async function s(){let c=await n.readRecording();return e=H(c,t),t.onUpdate?.(e),e}function l(){a(),o=setInterval(()=>{if(!i())s().catch(()=>{})},r)}function a(){if(o)clearInterval(o);o=null}return{get stats(){return e},async start(){return await n.startRecording({enableHighAccuracy:!0,...t.locationOptions}),e=K,t.onUpdate?.(e),l(),e},async attach(){let c=await n.getRecordingState().catch(()=>null);if(!c?.active)return null;if(await s().catch(()=>{}),!c.paused)l();return c},async pause(){a(),await n.pauseRecording(),await s().catch(()=>{})},async resume(){await n.resumeRecording(),l()},async stop(){a();let h=(await n.stopRecording())?.locations??[];return e=H(h,t),t.onUpdate?.(e),h},refresh:s}}var he=150;function rt(t,n){let r=Math.PI/180,e=(n.latitude-t.latitude)*r,o=(n.longitude-t.longitude)*r,i=Math.sin(e/2)**2+Math.cos(t.latitude*r)*Math.cos(n.latitude*r)*Math.sin(o/2)**2;return 12742017.6*Math.asin(Math.min(1,Math.sqrt(i)))}function L(t,n){let r=[...t].sort((e,o)=>e-o);return r[Math.min(r.length-1,Math.floor(n*r.length))]}function ye(t,n){let r=(t||[]).filter((s)=>Number.isFinite(s?.latitude)&&Number.isFinite(s?.longitude)),e=r.map((s)=>Number(s.accuracy)).filter((s)=>Number.isFinite(s)&&s>=0),o=e.length?L(e,0.5):Number.POSITIVE_INFINITY,i=0;if(r.length){let s={latitude:L(r.map((l)=>l.latitude),0.5),longitude:L(r.map((l)=>l.longitude),0.5)};i=L(r.map((l)=>rt(s,l)),0.8)}if(r.length>=10&&i>150&&o<=15)return"outside";if(n<150)return"unsure";if(r.length<3||o>30||i<25)return"indoors";if(i<50&&o>10)return"indoors";return"unsure"}function Se(t){let r=String(t||"").trim().toLowerCase().replace(",",".").match(/^(\d+(?:\.\d+)?)\s*(km|k|m|mi)?$/);if(!r)return null;let e=Number(r[1]),o=r[2]||(e>100?"m":"km"),i=o==="m"?e/1000:o==="mi"?e*1.609344:e;return i>0&&i<1000?Math.round(i*1000)/1000:null}var be=64;var ot=/^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/,it=/^(?:0|[1-9]\d*)$/;function F(t){let n=[],r=[],e=t&&typeof t==="object"&&!Array.isArray(t)?t:{};for(let[o,i]of Object.entries(e)){let s=i&&typeof i==="object"?i:null;if(!s){r.push(`spotlight kind "${o}" is not an object`);continue}let{slots:l,route:a}=s,c=typeof s.noun==="string"&&s.noun.trim()?s.noun.trim():"Item";if(!ot.test(o)||o.includes("-slot-")){r.push(`spotlight kind "${o}" is not a usable name: lowercase letters, digits and single dashes, and never "-slot-"`);continue}if(typeof l!=="number"||!Number.isInteger(l)||l<=0||l>64){r.push(`spotlight kind "${o}" needs slots between 1 and 64, not ${String(l)}`);continue}if(typeof a!=="string"||!a.startsWith("/")||!a.includes(":id")){r.push(`spotlight kind "${o}" needs a route starting with "/" and carrying ":id", not ${String(a)}`);continue}n.push({name:o,slots:l,route:a,noun:c})}return{kinds:n,problems:r}}function E(t,n){return t.find((r)=>r.name===n)??null}function R(t,n,r){let e=E(t,n);if(!e||!Number.isInteger(r)||r<0||r>=e.slots)return null;return`${n}-slot-${r}`}function st(t,n){if(typeof n!=="string")return null;let r=n.lastIndexOf("-slot-");if(r<=0)return null;let e=n.slice(0,r),o=n.slice(r+6);if(!it.test(o))return null;let i=Number(o);return R(t,e,i)===n?{kind:e,slot:i}:null}function D(t){return t.flatMap((n)=>Array.from({length:n.slots},(r,e)=>`${n.name}-slot-${e}`))}function Ae(t,n){let r=t&&typeof t==="object"?t:{};if(r.enabled===!1)return[];let o=[...(Array.isArray(r.activityTypes)?r.activityTypes.filter((i)=>typeof i==="string"&&i.trim().length>0):[]).map((i)=>i.trim()),...D(F(r.kinds).kinds)];return[...new Set(o)].map((i)=>`${n}.${i}`)}function U(t,n,r){let e=typeof r.name==="string"?r.name.replace(/\s+/g," ").trim():"";if(!e)return`${E(t,n)?.noun??"Item"} #${r.id}`;return e.length>120?`${e.slice(0,119).trimEnd()}…`:e}function at(t,n,r,e,o=Date.now()){let i=E(t,r);if(!i||!Number.isInteger(e.id)||e.id<=0)return null;let s=n.filter((m)=>m.kind===r),l=U(t,r,e),a=s.find((m)=>m.itemId===e.id)??null,c=a?null:dt(s,i.slots),h=a||c!==null?null:pt(s),d=a?.slot??c??h?.slot;if(d===void 0||d===null)return null;let f={kind:r,slot:d,itemId:e.id,title:l,donatedAt:o},v=n.filter((m)=>m.kind!==r||m.slot!==d&&m.itemId!==e.id);return{entries:B(t,[...v,f]),entry:f,evicted:h,changed:!a||a.title!==l}}function lt(t,n,r){let e=t.find((o)=>o.kind===n&&o.itemId===r)??null;return{entries:e?t.filter((o)=>o!==e):[...t],removed:e}}function ut(t,n,r){let e=st(t,r);if(!e)return null;let o=n.find((s)=>s.kind===e.kind&&s.slot===e.slot),i=E(t,e.kind)?.route;return o&&i?i.replace(":id",String(o.itemId)):null}function ct(t,n){if(!Array.isArray(n))return[];let r=new Map,e=new Set;for(let o of n){if(!o||typeof o!=="object")continue;let i=o,{kind:s,slot:l,itemId:a,title:c,donatedAt:h}=i;if(typeof s!=="string"||typeof l!=="number"||R(t,s,l)===null)continue;if(typeof a!=="number"||!Number.isInteger(a)||a<=0)continue;let d=`${s}-slot-${l}`,f=`${s}#${a}`;if(r.has(d)||e.has(f))continue;r.set(d,{kind:s,slot:l,itemId:a,title:typeof c==="string"&&c.trim()?c:U(t,s,{id:a}),donatedAt:typeof h==="number"&&Number.isFinite(h)&&h>0?h:0}),e.add(f)}return B(t,[...r.values()])}function B(t,n){let r=new Map(t.map((e,o)=>[e.name,o]));return[...n].sort((e,o)=>(r.get(e.kind)??0)-(r.get(o.kind)??0)||e.slot-o.slot)}function dt(t,n){let r=new Set(t.map((e)=>e.slot));for(let e=0;e<n;e++)if(!r.has(e))return e;return null}function pt(t){return t.reduce((n,r)=>!n||r.donatedAt<n.donatedAt?r:n,null)}function ft(){let t=globalThis.craft;return t&&typeof t==="object"?t.siri:void 0}var mt="stacks_spotlight_index",gt=3000;function xe(t){let n=t.onProblem??((u)=>console.warn(`[spotlight] ${u}`)),r=Array.isArray(t.kinds)?{kinds:[...t.kinds],problems:[]}:F(t.kinds);for(let u of r.problems)n(u);let e=t.enabled===!1?[]:r.kinds,o=t.storageKey??mt,i=t.legacyStorageKeys??[],s=t.timeoutMs??gt,l=t.now??(()=>Date.now()),a=t.bridge??ft,c=null;function h(){try{return typeof localStorage>"u"?null:localStorage}catch{return null}}function d(){if(c)return c;c=[];let u=h();if(!u)return c;try{let p=[o,...i].map((y)=>u.getItem(y)).find((y)=>y);c=p?ct(e,JSON.parse(p)):[]}catch{c=[]}return c}function f(u){c=u;let p=h();if(!p)return;try{p.setItem(o,JSON.stringify(u));for(let y of i)p.removeItem(y)}catch{}}async function v(u){if(!u)return null;let p;try{return await Promise.race([u,new Promise((y)=>{p=setTimeout(()=>y(null),s)})])}catch{return null}finally{if(p!==void 0)clearTimeout(p)}}let m=Promise.resolve();function g(u){let p=m.then(u,u);return m=p.catch(()=>{return}),p}async function b(u,p){let y=a()?.register;if(!y||e.length===0)return!1;return g(async()=>{let S=at(e,d(),u,p,l()),A=S&&R(e,u,S.entry.slot);if(!S||!A)return!1;if(!S.changed)return f(S.entries),!0;let w=await v(y(S.entry.title,A))!==null;if(w)f(S.entries);return w})}async function x(u,p){let y=a()?.remove;if(!y)return!1;return g(async()=>{let{entries:S,removed:A}=lt(d(),u,p);if(!A)return!1;let w=R(e,u,A.slot),X=w?await v(y(w))!==null:!1;return f(S),X})}async function W(u,p){let y=E(e,u)?.slots;if(!y||!a()?.register)return 0;let S=0;for(let A of[...p].slice(0,y).reverse())if(await b(u,A))S++;return S}async function V(){let u=a()?.remove;if(!u)return f([]),0;return g(async()=>{let p=0;for(let y of d()){let S=R(e,y.kind,y.slot);if(S&&await v(u(S))!==null)p++}return f([]),p})}return{kinds:e,index:b,sync:W,remove:x,clear:V,routeFor:(u)=>ut(e,d(),u),entries:()=>d(),activityTypes:(u)=>D(e).map((p)=>`${u}.${p}`),reset:()=>{c=null}}}var C=["craftShortcut","craftSiriShortcut"];function we(t,n){let r=(e)=>{let o=e.detail,i=typeof o==="string"?o:o&&typeof o==="object"?o.action??o.type:null,s=typeof i==="string"?t.routeFor(i):null;if(s)n(s)};if(typeof globalThis.addEventListener!=="function")return()=>{};for(let e of C)globalThis.addEventListener(e,r);return()=>{for(let e of C)globalThis.removeEventListener(e,r)}}var Ot=yt,Ht=St,Kt=vt,M=bt,Ct=wt,$t=Et,Ft=kt,Dt=Lt,Ut=Pt,Bt=_t,Gt=ht;function j(t){if(typeof t==="string")return t.trim()||null;if(!t||typeof t!=="object")return null;let n=t.url;return typeof n==="string"&&n.trim()?n:null}var jt={async getInitialURL(){if(!await Y())return null;return j(await G.getInitialURL?.())},onLink(t){let n=null,r=!1,e=()=>{if(r)return;n=G.onLink?.((o,i)=>{let s=j(o);if(s)t(s,{initial:i?.initial===!0})})??null};if(T()?.craft)e();else Y().then(e);return()=>{r=!0,n?.()}}},Yt=xt,qt=It,Wt=Tt,Vt=Mt,Xt=At,zt=Rt,Jt=Nt;function T(){if(typeof window>"u")return;return window}function P(){let t=T()?.craft;if(!t||typeof t!=="object")return null;if(!("platform"in t)||t.platform!=="ios"&&t.platform!=="android")return null;let n="capabilities"in t?t.capabilities:void 0,r=n&&typeof n==="object"&&!Array.isArray(n)?Object.fromEntries(Object.entries(n).filter(([,e])=>typeof e==="boolean")):{};return{platform:t.platform,capabilities:r}}function I(){return P()!==null}function q(){if(typeof window>"u")return!1;let t=window;if(t.CraftAndroid)return!0;let n=typeof navigator>"u"?"":navigator.userAgent;return Boolean(t.webkit?.messageHandlers?.craft)&&/iPhone|iPad|iPod/.test(n)}function Qt(t=2000){if(I()||q())return Promise.resolve(!0);let n=T(),r=n;if(!n||!(r?.craft||r?.webkit?.messageHandlers?.craft))return Promise.resolve(!1);return new Promise((e)=>{let o=()=>{clearTimeout(i),n.removeEventListener("craftReady",o),e(I())},i=setTimeout(o,t);n.addEventListener("craftReady",o,{once:!0})})}function Y(t=15000){let n=T();if(n?.craft)return Promise.resolve(!0);let r=n;if(!n||!(q()||r?.webkit?.messageHandlers?.craft))return Promise.resolve(!1);return new Promise((e)=>{let o=()=>{clearTimeout(i),n.removeEventListener("craftReady",o),e(Boolean(n.craft))},i=setTimeout(o,t);n.addEventListener("craftReady",o)})}function Zt(t){let n=T();if(!n)return()=>{};if(P()){let e=!1;return queueMicrotask(()=>{if(!e)t(new Event("craftReady"))}),()=>{e=!0}}let r=(e)=>{if(!P())return;n.removeEventListener("craftReady",r),t(e)};return n.addEventListener("craftReady",r),()=>n.removeEventListener("craftReady",r)}async function te(t){await M.impact("light");try{let n=await t();return await M.notification("success"),n}catch(n){throw await M.notification("error"),n}}var Te={get nativeBridge(){return P()},biometrics:Ot,camera:Ht,device:Kt,haptics:M,lifecycle:Ct,location:$t,notifications:Ft,permissions:Dt,secureStorage:Ut,share:Bt,appReview:Gt,deepLinks:jt,keepAwake:Yt,speech:qt,network:Wt,pushNotifications:Vt,health:Xt,liveActivities:zt,watchConnectivity:Jt,isNativeMobile:I,whenNative:Qt,onReady:Zt,withFeedback:te};export{he as INDOOR_CHECK_AFTER_S,be as MAX_SPOTLIGHT_SLOTS_PER_KIND,de as ROUTE_GAP_S,Gt as appReview,ae as backLabelFor,Ot as biometrics,Ht as camera,Q as canGoBack,me as createRouteRecorder,xe as createSpotlightIndex,Z as deepLinkPath,jt as deepLinks,Kt as device,se as enterNavTrail,et as fixDistance,ue as followDeepLinks,P as getNativeMobileBridge,ie as goBack,M as haptics,q as hasNativeMobileHost,Xt as health,ye as indoorVerdict,I as isNativeMobile,Yt as keepAwake,Ct as lifecycle,zt as liveActivities,$t as location,Te as mobile,le as navTrail,Wt as network,j as normalizeDeepLinkURL,Ft as notifications,ne as observePageScroll,re as observePullToRefresh,Zt as onMobileReady,we as onSpotlightTap,pe as paceLabel,k as pageScrollTop,Dt as permissions,at as placeSpotlightItem,J as pullDistance,Vt as pushNotifications,ct as readSpotlightEntries,F as readSpotlightKinds,lt as removeSpotlightItem,H as routeStats,Ut as secureStorage,Bt as share,qt as speech,fe as speedLabel,R as spotlightAction,D as spotlightActions,Ae as spotlightActivityTypes,ft as spotlightBridge,E as spotlightKind,ut as spotlightRoute,st as spotlightSlot,U as spotlightTitle,Se as typedDistanceKm,nt as usableFixes,Jt as watchConnectivity,Y as whenBridgeReady,Qt as whenNativeMobile,te as withNativeFeedback};
1
+ import{appReview as St,biometrics as vt,camera as bt,deepLinks as j,device as At,haptics as xt,health as wt,keepAwake as Rt,lifecycle as Et,liveActivities as Tt,location as Lt,network as kt,notifications as Mt,permissions as Pt,pushNotifications as _t,secureStorage as It,share as Nt,speech as Ot,watchConnectivity as Ht}from"craft-native/mobile";import{haptics as J}from"craft-native/mobile";function _(){if(typeof window>"u")return;return window}function L(t=_()){if(!t)return 0;if(typeof t.scrollY==="number")return t.scrollY;return t.document?.scrollingElement?.scrollTop??0}function oe(t,n=_()){if(!n)return()=>{};let r=!1,e=typeof requestAnimationFrame==="function"?requestAnimationFrame:(i)=>setTimeout(i,16),o=()=>{if(r)return;r=!0,e(()=>{r=!1,t(L(n))})};return t(L(n)),n.addEventListener("scroll",o,{passive:!0}),()=>n.removeEventListener("scroll",o)}function Q(t,n){let r=Math.max(0,-t),e=t<=0?Math.max(0,n)*0.5:0;return Math.round(Math.max(r,e))}function ie(t){let n=t.host??_();if(!n)return()=>{};let r=t.threshold??72,e=null,o=!1,i=!1,s=typeof requestAnimationFrame==="function"?requestAnimationFrame:(g)=>setTimeout(g,16),u=null,a=(g)=>{u=null,t.onPull?.(g,o)},c=(g)=>{let b=u!==null;if(u=g,b)return;s(()=>{if(u!==null)a(u)})},h=(g)=>{let b=g.touches?.[0];return b?b.clientY:null},d=(g)=>{if(i||L(n)>0)return;e=h(g),o=!1},p=(g)=>{if(e===null)return;let b=h(g);if(b===null)return;let x=Q(L(n),b-e);if(!o&&x>=r)o=!0,Promise.resolve(J.impact("medium")).catch(()=>{});else if(o&&x<r*0.8)o=!1;c(x)},v=async()=>{if(e===null)return;if(e=null,!o){a(0);return}o=!1,i=!0,a(r);try{await t.onRefresh()}finally{i=!1,a(0)}},m=()=>{if(e===null)return;e=null,o=!1,a(0)};return n.addEventListener("touchstart",d,{passive:!0}),n.addEventListener("touchmove",p,{passive:!0}),n.addEventListener("touchend",v),n.addEventListener("touchcancel",m),()=>{u=null,n.removeEventListener("touchstart",d),n.removeEventListener("touchmove",p),n.removeEventListener("touchend",v),n.removeEventListener("touchcancel",m)}}function H(){if(typeof window>"u")return;return window}var N="__stxPushed",Z="__stxScroll";function tt(t=H()){let n=t?.history?.state;if(n===null||n===void 0)return!1;if(typeof n!=="object")return!0;let r=n;if(N in r)return r[N]===!0;return!(Z in r)}function ae(t=H()){if(!tt(t))return!1;return t.history.back(),!0}function ue(t,n,r=50){let e=t[t.length-1];if(t.length>=2&&t[t.length-2].path===n)t.pop();else if(!e||e.path!==n)t.push({path:n,title:""});if(t.length>r)t.splice(0,t.length-r);return{current:t[t.length-1],previous:t[t.length-2]??null}}function le(t,n,r=12){let e=t?.title.trim()??"";return e&&e.length<=r?e:n}function ce(){if(typeof window>"u")return[];let t=window;return t.__stacksNavTrail??=[]}function et(t,n=nt()){let r;try{r=new URL(t)}catch{return null}let e=`${r.search}${r.hash}`;if(r.protocol==="http:"||r.protocol==="https:"){if(!n||r.origin!==n)return null;return`${r.pathname||"/"}${e}`}return`${`/${[r.host,r.pathname.replace(/^\/+/,"")].filter(Boolean).join("/")}`}${e}`}function nt(){if(typeof window>"u")return;return window.location?.origin}var O="stacks-mobile-deep-link";function de(t,n){let r=(e)=>{let o=et(e);if(o)t(o)};return n.getInitialURL().then((e)=>{if(!e)return;try{if(sessionStorage.getItem(O)===e)return;sessionStorage.setItem(O,e)}catch{}r(e)}).catch(()=>{}),n.onLink((e,o)=>{if(o?.initial)return;r(e)})}var pe=30;function rt(t,n){let r=Math.PI/180,e=(n.latitude-t.latitude)*r,o=(n.longitude-t.longitude)*r,i=Math.sin(e/2)**2+Math.cos(t.latitude*r)*Math.cos(n.latitude*r)*Math.sin(o/2)**2;return 12742017.6*Math.asin(Math.min(1,Math.sqrt(i)))}function ot(t,n=25){let r=new Set;return t.filter((e)=>Number.isFinite(e.latitude)&&Number.isFinite(e.longitude)&&Number.isFinite(e.timestamp)&&e.accuracy>=0&&e.accuracy<=n).sort((e,o)=>e.timestamp-o.timestamp).filter((e)=>{if(r.has(e.timestamp))return!1;return r.add(e.timestamp),!0})}function K(t,n={}){let r=ot(t,n.maxAccuracyM??25),e=n.paceWindowS??30,o=[],i=0,s=0,u=null;for(let d of r){let p=o[o.length-1],v=u?(d.timestamp-u.timestamp)/1000:0;if(u=d,!p){o.push({fix:d,cumM:0});continue}if(v>30){o.push({fix:d,cumM:i});continue}let m=(d.timestamp-p.fix.timestamp)/1000,g=rt(p.fix,d),b=Math.min(10,Math.max(3,p.fix.accuracy,d.accuracy));if(g<b)continue;if(i+=g,m>0&&g/m>=0.5)s+=m;o.push({fix:d,cumM:i})}let a=o[o.length-1],c=null,h=null;if(a){let d=a.fix.timestamp-e*1000,p=o.find((g)=>g.fix.timestamp>=d)??a,v=a.cumM-p.cumM,m=(a.fix.timestamp-p.fix.timestamp)/1000;if(v>=20&&m>0)h=v/m,c=m/(v/1000)}return{distanceM:i,movingS:s,paceSPerKm:c,averagePaceSPerKm:i>=50&&s>0?s/(i/1000):null,speedMps:h,accuracyM:r.length?r[r.length-1].accuracy:t.length?t[t.length-1].accuracy??null:null,fixes:r.length}}function me(t){if(!t||!Number.isFinite(t)||t>3600)return"–";let n=Math.round(t);return`${Math.floor(n/60)}:${String(n%60).padStart(2,"0")}`}function ge(t){return t&&Number.isFinite(t)?(t*3.6).toFixed(1):"–"}var C={distanceM:0,movingS:0,paceSPerKm:null,averagePaceSPerKm:null,speedMps:null,accuracyM:null,fixes:0};function he(t){let n=t.location,r=t.intervalMs??3000,e=C,o=null,i=()=>typeof document<"u"&&document.visibilityState==="hidden";async function s(){let c=await n.readRecording();return e=K(c,t),t.onUpdate?.(e),e}function u(){a(),o=setInterval(()=>{if(!i())s().catch(()=>{})},r)}function a(){if(o)clearInterval(o);o=null}return{get stats(){return e},async start(){return await n.startRecording({enableHighAccuracy:!0,...t.locationOptions}),e=C,t.onUpdate?.(e),u(),e},async attach(){let c=await n.getRecordingState().catch(()=>null);if(!c?.active)return null;if(await s().catch(()=>{}),!c.paused)u();return c},async pause(){a(),await n.pauseRecording(),await s().catch(()=>{})},async resume(){await n.resumeRecording(),u()},async stop(){a();let h=(await n.stopRecording())?.locations??[];return e=K(h,t),t.onUpdate?.(e),h},refresh:s}}var Se=150;function it(t,n){let r=Math.PI/180,e=(n.latitude-t.latitude)*r,o=(n.longitude-t.longitude)*r,i=Math.sin(e/2)**2+Math.cos(t.latitude*r)*Math.cos(n.latitude*r)*Math.sin(o/2)**2;return 12742017.6*Math.asin(Math.min(1,Math.sqrt(i)))}function k(t,n){let r=[...t].sort((e,o)=>e-o);return r[Math.min(r.length-1,Math.floor(n*r.length))]}function ve(t,n){let r=(t||[]).filter((s)=>Number.isFinite(s?.latitude)&&Number.isFinite(s?.longitude)),e=r.map((s)=>Number(s.accuracy)).filter((s)=>Number.isFinite(s)&&s>=0),o=e.length?k(e,0.5):Number.POSITIVE_INFINITY,i=0;if(r.length){let s={latitude:k(r.map((u)=>u.latitude),0.5),longitude:k(r.map((u)=>u.longitude),0.5)};i=k(r.map((u)=>it(s,u)),0.8)}if(r.length>=10&&i>150&&o<=15)return"outside";if(n<150)return"unsure";if(r.length<3||o>30||i<25)return"indoors";if(i<50&&o>10)return"indoors";return"unsure"}function be(t){let r=String(t||"").trim().toLowerCase().replace(",",".").match(/^(\d+(?:\.\d+)?)\s*(km|k|m|mi)?$/);if(!r)return null;let e=Number(r[1]),o=r[2]||(e>100?"m":"km"),i=o==="m"?e/1000:o==="mi"?e*1.609344:e;return i>0&&i<1000?Math.round(i*1000)/1000:null}var xe=64;var st=/^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/,at=/^(?:0|[1-9]\d*)$/;function D(t){let n=[],r=[],e=t&&typeof t==="object"&&!Array.isArray(t)?t:{};for(let[o,i]of Object.entries(e)){let s=i&&typeof i==="object"?i:null;if(!s){r.push(`spotlight kind "${o}" is not an object`);continue}let{slots:u,route:a}=s,c=typeof s.noun==="string"&&s.noun.trim()?s.noun.trim():"Item";if(!st.test(o)||o.includes("-slot-")){r.push(`spotlight kind "${o}" is not a usable name: lowercase letters, digits and single dashes, and never "-slot-"`);continue}if(typeof u!=="number"||!Number.isInteger(u)||u<=0||u>64){r.push(`spotlight kind "${o}" needs slots between 1 and 64, not ${String(u)}`);continue}if(typeof a!=="string"||!a.startsWith("/")||!a.includes(":id")){r.push(`spotlight kind "${o}" needs a route starting with "/" and carrying ":id", not ${String(a)}`);continue}n.push({name:o,slots:u,route:a,noun:c})}return{kinds:n,problems:r}}function E(t,n){return t.find((r)=>r.name===n)??null}function R(t,n,r){let e=E(t,n);if(!e||!Number.isInteger(r)||r<0||r>=e.slots)return null;return`${n}-slot-${r}`}function ut(t,n){if(typeof n!=="string")return null;let r=n.lastIndexOf("-slot-");if(r<=0)return null;let e=n.slice(0,r),o=n.slice(r+6);if(!at.test(o))return null;let i=Number(o);return R(t,e,i)===n?{kind:e,slot:i}:null}function U(t){return t.flatMap((n)=>Array.from({length:n.slots},(r,e)=>`${n.name}-slot-${e}`))}function we(t,n){let r=t&&typeof t==="object"?t:{};if(r.enabled===!1)return[];let o=[...(Array.isArray(r.activityTypes)?r.activityTypes.filter((i)=>typeof i==="string"&&i.trim().length>0):[]).map((i)=>i.trim()),...U(D(r.kinds).kinds)];return[...new Set(o)].map((i)=>`${n}.${i}`)}function B(t,n,r){let e=typeof r.name==="string"?r.name.replace(/\s+/g," ").trim():"";if(!e)return`${E(t,n)?.noun??"Item"} #${r.id}`;return e.length>120?`${e.slice(0,119).trimEnd()}…`:e}function lt(t,n,r,e,o=Date.now()){let i=E(t,r);if(!i||!Number.isInteger(e.id)||e.id<=0)return null;let s=n.filter((m)=>m.kind===r),u=B(t,r,e),a=s.find((m)=>m.itemId===e.id)??null,c=a?null:pt(s,i.slots),h=a||c!==null?null:mt(s),d=a?.slot??c??h?.slot;if(d===void 0||d===null)return null;let p={kind:r,slot:d,itemId:e.id,title:u,donatedAt:o},v=n.filter((m)=>m.kind!==r||m.slot!==d&&m.itemId!==e.id);return{entries:G(t,[...v,p]),entry:p,evicted:h,changed:!a||a.title!==u}}function ct(t,n,r){let e=t.find((o)=>o.kind===n&&o.itemId===r)??null;return{entries:e?t.filter((o)=>o!==e):[...t],removed:e}}function dt(t,n,r){let e=ut(t,r);if(!e)return null;let o=n.find((s)=>s.kind===e.kind&&s.slot===e.slot),i=E(t,e.kind)?.route;return o&&i?i.replace(":id",String(o.itemId)):null}function ft(t,n){if(!Array.isArray(n))return[];let r=new Map,e=new Set;for(let o of n){if(!o||typeof o!=="object")continue;let i=o,{kind:s,slot:u,itemId:a,title:c,donatedAt:h}=i;if(typeof s!=="string"||typeof u!=="number"||R(t,s,u)===null)continue;if(typeof a!=="number"||!Number.isInteger(a)||a<=0)continue;let d=`${s}-slot-${u}`,p=`${s}#${a}`;if(r.has(d)||e.has(p))continue;r.set(d,{kind:s,slot:u,itemId:a,title:typeof c==="string"&&c.trim()?c:B(t,s,{id:a}),donatedAt:typeof h==="number"&&Number.isFinite(h)&&h>0?h:0}),e.add(p)}return G(t,[...r.values()])}function G(t,n){let r=new Map(t.map((e,o)=>[e.name,o]));return[...n].sort((e,o)=>(r.get(e.kind)??0)-(r.get(o.kind)??0)||e.slot-o.slot)}function pt(t,n){let r=new Set(t.map((e)=>e.slot));for(let e=0;e<n;e++)if(!r.has(e))return e;return null}function mt(t){return t.reduce((n,r)=>!n||r.donatedAt<n.donatedAt?r:n,null)}function gt(){let t=globalThis.craft;return t&&typeof t==="object"?t.siri:void 0}var ht="stacks_spotlight_index",yt=3000;function Re(t){let n=t.onProblem??((l)=>console.warn(`[spotlight] ${l}`)),r=Array.isArray(t.kinds)?{kinds:[...t.kinds],problems:[]}:D(t.kinds);for(let l of r.problems)n(l);let e=t.enabled===!1?[]:r.kinds,o=t.storageKey??ht,i=t.legacyStorageKeys??[],s=t.timeoutMs??yt,u=t.now??(()=>Date.now()),a=t.bridge??gt,c=null;function h(){try{return typeof localStorage>"u"?null:localStorage}catch{return null}}function d(){if(c)return c;c=[];let l=h();if(!l)return c;try{let f=[o,...i].map((y)=>l.getItem(y)).find((y)=>y);c=f?ft(e,JSON.parse(f)):[]}catch{c=[]}return c}function p(l){c=l;let f=h();if(!f)return;try{f.setItem(o,JSON.stringify(l));for(let y of i)f.removeItem(y)}catch{}}async function v(l){if(!l)return null;let f;try{return await Promise.race([l,new Promise((y)=>{f=setTimeout(()=>y(null),s)})])}catch{return null}finally{if(f!==void 0)clearTimeout(f)}}let m=Promise.resolve();function g(l){let f=m.then(l,l);return m=f.catch(()=>{return}),f}async function b(l,f){let y=a()?.register;if(!y||e.length===0)return!1;return g(async()=>{let S=lt(e,d(),l,f,u()),A=S&&R(e,l,S.entry.slot);if(!S||!A)return!1;if(!S.changed)return p(S.entries),!0;let w=await v(y(S.entry.title,A))!==null;if(w)p(S.entries);return w})}async function x(l,f){let y=a()?.remove;if(!y)return!1;return g(async()=>{let{entries:S,removed:A}=ct(d(),l,f);if(!A)return!1;let w=R(e,l,A.slot),z=w?await v(y(w))!==null:!1;return p(S),z})}async function V(l,f){let y=E(e,l)?.slots;if(!y||!a()?.register)return 0;let S=0;for(let A of[...f].slice(0,y).reverse())if(await b(l,A))S++;return S}async function X(){let l=a()?.remove;if(!l)return p([]),0;return g(async()=>{let f=0;for(let y of d()){let S=R(e,y.kind,y.slot);if(S&&await v(l(S))!==null)f++}return p([]),f})}return{kinds:e,index:b,sync:V,remove:x,clear:X,routeFor:(l)=>dt(e,d(),l),entries:()=>d(),activityTypes:(l)=>U(e).map((f)=>`${l}.${f}`),reset:()=>{c=null}}}var F=["craftShortcut","craftSiriShortcut"];function Ee(t,n){let r=(e)=>{let o=e.detail,i=typeof o==="string"?o:o&&typeof o==="object"?o.action??o.type:null,s=typeof i==="string"?t.routeFor(i):null;if(s)n(s)};if(typeof globalThis.addEventListener!=="function")return()=>{};for(let e of F)globalThis.addEventListener(e,r);return()=>{for(let e of F)globalThis.removeEventListener(e,r)}}var Kt=vt,Ct=bt,$t=At,M=xt,Ft=Et,Dt=Lt,Ut=Mt,Bt=Pt,Gt=It,jt=Nt,Yt=St;function Y(t){if(typeof t==="string")return t.trim()||null;if(!t||typeof t!=="object")return null;let n=t.url;return typeof n==="string"&&n.trim()?n:null}var qt={async getInitialURL(){if(!await q())return null;return Y(await j.getInitialURL?.())},onLink(t){let n=null,r=!1,e=()=>{if(r)return;n=j.onLink?.((o,i)=>{let s=Y(o);if(s)t(s,{initial:i?.initial===!0})})??null};if(T()?.craft)e();else q().then(e);return()=>{r=!0,n?.()}}},Wt=Rt,Vt=Ot,Xt=kt,zt=_t,Jt=wt,Qt=Tt,Zt=Ht;function T(){if(typeof window>"u")return;return window}function P(){let t=T()?.craft;if(!t||typeof t!=="object")return null;if(!("platform"in t)||t.platform!=="ios"&&t.platform!=="android")return null;let n="capabilities"in t?t.capabilities:void 0,r=n&&typeof n==="object"&&!Array.isArray(n)?Object.fromEntries(Object.entries(n).filter(([,e])=>typeof e==="boolean")):{};return{platform:t.platform,capabilities:r}}function I(){return P()!==null}function W(){if(typeof window>"u")return!1;let t=window;if(t.CraftAndroid)return!0;let n=typeof navigator>"u"?"":navigator.userAgent;return Boolean(t.webkit?.messageHandlers?.craft)&&/iPhone|iPad|iPod/.test(n)}function te(t=2000){if(I()||W())return Promise.resolve(!0);let n=T(),r=n;if(!n||!(r?.craft||r?.webkit?.messageHandlers?.craft))return Promise.resolve(!1);return new Promise((e)=>{let o=()=>{clearTimeout(i),n.removeEventListener("craftReady",o),e(I())},i=setTimeout(o,t);n.addEventListener("craftReady",o,{once:!0})})}function q(t=15000){let n=T();if(n?.craft)return Promise.resolve(!0);let r=n;if(!n||!(W()||r?.webkit?.messageHandlers?.craft))return Promise.resolve(!1);return new Promise((e)=>{let o=()=>{clearTimeout(i),n.removeEventListener("craftReady",o),e(Boolean(n.craft))},i=setTimeout(o,t);n.addEventListener("craftReady",o)})}function ee(t){let n=T();if(!n)return()=>{};if(P()){let e=!1;return queueMicrotask(()=>{if(!e)t(new Event("craftReady"))}),()=>{e=!0}}let r=(e)=>{if(!P())return;n.removeEventListener("craftReady",r),t(e)};return n.addEventListener("craftReady",r),()=>n.removeEventListener("craftReady",r)}async function ne(t){await M.impact("light");try{let n=await t();return await M.notification("success"),n}catch(n){throw await M.notification("error"),n}}var ke={get nativeBridge(){return P()},biometrics:Kt,camera:Ct,device:$t,haptics:M,lifecycle:Ft,location:Dt,notifications:Ut,permissions:Bt,secureStorage:Gt,share:jt,appReview:Yt,deepLinks:qt,keepAwake:Wt,speech:Vt,network:Xt,pushNotifications:zt,health:Jt,liveActivities:Qt,watchConnectivity:Zt,isNativeMobile:I,whenNative:te,onReady:ee,withFeedback:ne};export{Se as INDOOR_CHECK_AFTER_S,xe as MAX_SPOTLIGHT_SLOTS_PER_KIND,pe as ROUTE_GAP_S,Yt as appReview,le as backLabelFor,Kt as biometrics,Ct as camera,tt as canGoBack,he as createRouteRecorder,Re as createSpotlightIndex,et as deepLinkPath,qt as deepLinks,$t as device,ue as enterNavTrail,rt as fixDistance,de as followDeepLinks,P as getNativeMobileBridge,ae as goBack,M as haptics,W as hasNativeMobileHost,Jt as health,ve as indoorVerdict,I as isNativeMobile,Wt as keepAwake,Ft as lifecycle,Qt as liveActivities,Dt as location,ke as mobile,ce as navTrail,Xt as network,Y as normalizeDeepLinkURL,Ut as notifications,oe as observePageScroll,ie as observePullToRefresh,ee as onMobileReady,Ee as onSpotlightTap,me as paceLabel,L as pageScrollTop,Bt as permissions,lt as placeSpotlightItem,Q as pullDistance,zt as pushNotifications,ft as readSpotlightEntries,D as readSpotlightKinds,ct as removeSpotlightItem,K as routeStats,Gt as secureStorage,jt as share,Vt as speech,ge as speedLabel,R as spotlightAction,U as spotlightActions,we as spotlightActivityTypes,gt as spotlightBridge,E as spotlightKind,dt as spotlightRoute,ut as spotlightSlot,B as spotlightTitle,be as typedDistanceKm,ot as usableFixes,Zt as watchConnectivity,q as whenBridgeReady,te as whenNativeMobile,ne 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.75.88",
5
+ "version": "0.75.90",
6
6
  "description": "Craft-powered native mobile runtime for Stacks and STX applications",
7
7
  "author": "Chris Breuer",
8
8
  "license": "MIT",
@@ -35,7 +35,7 @@
35
35
  "craft-native": ">=0.0.119"
36
36
  },
37
37
  "devDependencies": {
38
- "@stacksjs/build": "0.75.88",
38
+ "@stacksjs/build": "0.75.90",
39
39
  "better-dx": "^0.2.24"
40
40
  }
41
41
  }