craft-native 0.0.124 → 0.0.125

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/mobile.js CHANGED
@@ -762,6 +762,69 @@ var splash = {
762
762
  return postChrome({ type: "ready" });
763
763
  }
764
764
  };
765
+ function hybridHandler() {
766
+ if (typeof window === "undefined")
767
+ return null;
768
+ const handler = window.webkit?.messageHandlers?.craftHybrid;
769
+ return handler && typeof handler.postMessage === "function" ? handler : null;
770
+ }
771
+ function postHybrid(message) {
772
+ const handler = hybridHandler();
773
+ if (!handler)
774
+ return false;
775
+ try {
776
+ handler.postMessage(message);
777
+ return true;
778
+ } catch {
779
+ return false;
780
+ }
781
+ }
782
+ function isSnapshotName(name) {
783
+ return typeof name === "string" && /^[A-Za-z0-9_-][\w.-]{0,127}$/.test(name);
784
+ }
785
+ var snapshots = {
786
+ isAvailable() {
787
+ return hybridHandler() !== null;
788
+ },
789
+ set(name, value) {
790
+ if (!isSnapshotName(name))
791
+ throw new TypeError(`Snapshot names are letters, digits, ".", "_" and "-": ${String(name)}`);
792
+ const json = JSON.stringify(value);
793
+ if (json === undefined)
794
+ throw new TypeError(`Snapshot ${name} is not JSON`);
795
+ return postHybrid({ type: "snapshotSet", name, json });
796
+ },
797
+ remove(name) {
798
+ if (!isSnapshotName(name))
799
+ return false;
800
+ return postHybrid({ type: "snapshotRemove", name });
801
+ },
802
+ clear() {
803
+ return postHybrid({ type: "snapshotClear" });
804
+ }
805
+ };
806
+ function hybridPage() {
807
+ if (typeof window === "undefined")
808
+ return;
809
+ const page = window.__craftHybrid;
810
+ return page && typeof page.match === "function" ? page : undefined;
811
+ }
812
+ var hybrid = {
813
+ isActive() {
814
+ return hybridHandler() !== null;
815
+ },
816
+ nativeScreenFor(path) {
817
+ return hybridPage()?.match(path) ?? null;
818
+ },
819
+ open(path) {
820
+ if (typeof path !== "string" || !path.startsWith("/"))
821
+ throw new TypeError(`hybrid.open needs an app path: ${String(path)}`);
822
+ return postHybrid({ type: "open", path });
823
+ },
824
+ back() {
825
+ return postHybrid({ type: "back" });
826
+ }
827
+ };
765
828
  async function callNative(namespace, method, args, fallback) {
766
829
  const target = getCraftRoot()?.[namespace];
767
830
  if (!target || typeof target[method] !== "function")
@@ -1060,6 +1123,7 @@ export {
1060
1123
  statusBar,
1061
1124
  splash,
1062
1125
  speech,
1126
+ snapshots,
1063
1127
  share,
1064
1128
  secureStorage,
1065
1129
  refresh,
@@ -1072,6 +1136,8 @@ export {
1072
1136
  liveActivities,
1073
1137
  lifecycle,
1074
1138
  keepAwake,
1139
+ isSnapshotName,
1140
+ hybrid,
1075
1141
  health,
1076
1142
  haptics,
1077
1143
  dialog,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "craft-native",
3
- "version": "0.0.124",
3
+ "version": "0.0.125",
4
4
  "type": "module",
5
5
  "description": "Build desktop apps with web languages - TypeScript SDK for Craft",
6
6
  "author": "Chris Breuer <chris@stacksjs.org>",