craft-native 0.0.122 → 0.0.124

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
@@ -139,6 +139,14 @@ var haptics = {
139
139
  navigator.vibrate(5);
140
140
  }
141
141
  },
142
+ async prepare(kind) {
143
+ const craft = getCraftMobile();
144
+ if (typeof window !== "undefined" && craft?.haptics?.prepare) {
145
+ try {
146
+ await craft.haptics.prepare(kind);
147
+ } catch {}
148
+ }
149
+ },
142
150
  async vibrate(pattern) {
143
151
  const craft = getCraftMobile();
144
152
  if (typeof window !== "undefined" && craft?.haptics) {
@@ -510,6 +518,12 @@ var lifecycle = {
510
518
  };
511
519
  document.addEventListener("visibilitychange", handler);
512
520
  return () => document.removeEventListener("visibilitychange", handler);
521
+ },
522
+ onResume(callback) {
523
+ return onCraftEvent("craftResume", (detail) => callback({ backgroundedMs: Number(detail.backgroundedMs) || 0 }));
524
+ },
525
+ onMemoryWarning(callback) {
526
+ return onCraftEvent("craftMemoryWarning", () => callback());
513
527
  }
514
528
  };
515
529
  function bridgeNotification(options, now = Date.now()) {
@@ -701,6 +715,168 @@ var network = {
701
715
  };
702
716
  }
703
717
  };
718
+ function chromeHandler() {
719
+ if (typeof window === "undefined")
720
+ return null;
721
+ const handler = window.webkit?.messageHandlers?.craftChrome;
722
+ return handler && typeof handler.postMessage === "function" ? handler : null;
723
+ }
724
+ function postChrome(message) {
725
+ const handler = chromeHandler();
726
+ if (!handler)
727
+ return false;
728
+ try {
729
+ handler.postMessage(message);
730
+ return true;
731
+ } catch {
732
+ return false;
733
+ }
734
+ }
735
+ var tabBar = {
736
+ isAvailable() {
737
+ return chromeHandler() !== null;
738
+ },
739
+ set(tabs, options = {}) {
740
+ return postChrome({ type: "tabBar", tabs, ...options });
741
+ },
742
+ select(id) {
743
+ return postChrome({ type: "selectTab", id });
744
+ },
745
+ hide() {
746
+ return postChrome({ type: "hideTabBar" });
747
+ },
748
+ onSelect(callback) {
749
+ if (typeof window === "undefined")
750
+ return () => {};
751
+ const listener = (event) => {
752
+ const id = event.detail?.id;
753
+ if (typeof id === "string")
754
+ callback(id);
755
+ };
756
+ window.addEventListener("craftTabSelect", listener);
757
+ return () => window.removeEventListener("craftTabSelect", listener);
758
+ }
759
+ };
760
+ var splash = {
761
+ hide() {
762
+ return postChrome({ type: "ready" });
763
+ }
764
+ };
765
+ async function callNative(namespace, method, args, fallback) {
766
+ const target = getCraftRoot()?.[namespace];
767
+ if (!target || typeof target[method] !== "function")
768
+ return fallback;
769
+ try {
770
+ const value = await target[method](...args);
771
+ return value === undefined || value === null ? fallback : value;
772
+ } catch {
773
+ return fallback;
774
+ }
775
+ }
776
+ function hasNative(namespace) {
777
+ return Boolean(getCraftRoot()?.[namespace]);
778
+ }
779
+ var dialog = {
780
+ isAvailable() {
781
+ return hasNative("dialog");
782
+ },
783
+ async alert(options) {
784
+ await callNative("dialog", "alert", [options], undefined);
785
+ },
786
+ confirm(options) {
787
+ return callNative("dialog", "confirm", [options], false);
788
+ },
789
+ actionSheet(options) {
790
+ return callNative("dialog", "actionSheet", [options], null);
791
+ }
792
+ };
793
+ var contextMenu = {
794
+ isAvailable() {
795
+ return hasNative("contextMenu");
796
+ },
797
+ show(options) {
798
+ return callNative("contextMenu", "show", [options], null);
799
+ }
800
+ };
801
+ var browser = {
802
+ isAvailable() {
803
+ return hasNative("browser");
804
+ },
805
+ async open(url, options = {}) {
806
+ if (hasNative("browser"))
807
+ return callNative("browser", "open", [url, options], { cancelled: true });
808
+ if (options.mode !== "auth" && typeof window !== "undefined" && typeof window.open === "function") {
809
+ window.open(url, "_blank", "noopener");
810
+ return { cancelled: false };
811
+ }
812
+ return { cancelled: true };
813
+ }
814
+ };
815
+ var symbols = {
816
+ image(name, options = {}) {
817
+ return callNative("symbols", "image", [name, options], null);
818
+ }
819
+ };
820
+ var statusBar = {
821
+ setStyle(style) {
822
+ return callNative("statusBar", "setStyle", [style], false);
823
+ }
824
+ };
825
+ var chrome = {
826
+ setUnderPageColor(color) {
827
+ return callNative("chrome", "setUnderPageColor", [color], false);
828
+ },
829
+ setKeyboardAccessory(visible) {
830
+ return callNative("chrome", "setKeyboardAccessory", [visible], false);
831
+ }
832
+ };
833
+ var refresh = {
834
+ isAvailable() {
835
+ return hasNative("refresh");
836
+ },
837
+ enable(options = {}) {
838
+ return callNative("refresh", "enable", [options], false);
839
+ },
840
+ disable() {
841
+ return callNative("refresh", "disable", [], false);
842
+ },
843
+ end() {
844
+ return callNative("refresh", "end", [], false);
845
+ },
846
+ onRefresh(callback) {
847
+ return onCraftEvent("craftRefresh", () => callback());
848
+ }
849
+ };
850
+ var background = {
851
+ complete(ok = true, id) {
852
+ return callNative("background", "complete", [ok, id], false);
853
+ },
854
+ onRefresh(callback) {
855
+ return onCraftEvent("craftBackgroundRefresh", (detail) => callback(detail));
856
+ },
857
+ onSilentPush(callback) {
858
+ return onCraftEvent("craftSilentPush", (detail) => callback(detail));
859
+ }
860
+ };
861
+ var appearance = {
862
+ get() {
863
+ const native = getCraftRoot()?.appearance;
864
+ if (native)
865
+ return native;
866
+ if (typeof window === "undefined" || typeof window.matchMedia !== "function")
867
+ return null;
868
+ return {
869
+ contentSizeCategory: "large",
870
+ fontScale: 1,
871
+ reduceMotion: window.matchMedia("(prefers-reduced-motion: reduce)").matches,
872
+ reduceTransparency: window.matchMedia("(prefers-reduced-transparency: reduce)").matches,
873
+ colorScheme: window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light"
874
+ };
875
+ },
876
+ onChange(callback) {
877
+ return onCraftEvent("craftAppearance", (detail) => callback(detail));
878
+ }
879
+ };
704
880
  var appReview = {
705
881
  async request() {
706
882
  const craft = getCraftRoot();
@@ -879,9 +1055,14 @@ function getCraftMobile() {
879
1055
  }
880
1056
  export {
881
1057
  watchConnectivity,
1058
+ tabBar,
1059
+ symbols,
1060
+ statusBar,
1061
+ splash,
882
1062
  speech,
883
1063
  share,
884
1064
  secureStorage,
1065
+ refresh,
885
1066
  pushNotifications,
886
1067
  permissions,
887
1068
  notifications,
@@ -893,11 +1074,17 @@ export {
893
1074
  keepAwake,
894
1075
  health,
895
1076
  haptics,
1077
+ dialog,
896
1078
  device,
897
1079
  deepLinks,
1080
+ contextMenu,
1081
+ chrome,
898
1082
  camera,
1083
+ browser,
899
1084
  bridgeNotification,
900
1085
  biometrics,
1086
+ background,
1087
+ appearance,
901
1088
  appReview,
902
1089
  _webFallbackDeviceId,
903
1090
  _resetWebFallbackDeviceIdForTests
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "craft-native",
3
- "version": "0.0.122",
3
+ "version": "0.0.124",
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>",