craft-native 0.0.123 → 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()) {
@@ -748,6 +762,121 @@ var splash = {
748
762
  return postChrome({ type: "ready" });
749
763
  }
750
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
+ };
751
880
  var appReview = {
752
881
  async request() {
753
882
  const craft = getCraftRoot();
@@ -927,10 +1056,13 @@ function getCraftMobile() {
927
1056
  export {
928
1057
  watchConnectivity,
929
1058
  tabBar,
1059
+ symbols,
1060
+ statusBar,
930
1061
  splash,
931
1062
  speech,
932
1063
  share,
933
1064
  secureStorage,
1065
+ refresh,
934
1066
  pushNotifications,
935
1067
  permissions,
936
1068
  notifications,
@@ -942,11 +1074,17 @@ export {
942
1074
  keepAwake,
943
1075
  health,
944
1076
  haptics,
1077
+ dialog,
945
1078
  device,
946
1079
  deepLinks,
1080
+ contextMenu,
1081
+ chrome,
947
1082
  camera,
1083
+ browser,
948
1084
  bridgeNotification,
949
1085
  biometrics,
1086
+ background,
1087
+ appearance,
950
1088
  appReview,
951
1089
  _webFallbackDeviceId,
952
1090
  _resetWebFallbackDeviceIdForTests
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "craft-native",
3
- "version": "0.0.123",
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>",