craft-native 0.0.395 → 0.0.408

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 (37) hide show
  1. package/README.md +7 -0
  2. package/dist/android/templates/CraftBridge.kt.template +2 -0
  3. package/dist/android/templates/CraftNative.kt.template +7 -0
  4. package/dist/android/templates/CraftNativeFlatList.kt.template +7 -0
  5. package/dist/android/templates/CraftNativeMapGoogle.kt.template +3 -0
  6. package/dist/android/templates/CraftNativeMapLibre.kt.template +3 -0
  7. package/dist/android/templates/CraftNativeRefreshableFlatList.kt.template +9 -0
  8. package/dist/android/templates/CraftNativeServices.kt.template +2 -1
  9. package/dist/android/templates/CraftNativeShell.kt.template +12 -2
  10. package/dist/android/templates/LocationRecordingService.kt.template +125 -6
  11. package/dist/android/templates/MainActivityNative.kt.template +338 -21
  12. package/dist/api/mobile.d.ts +59 -2
  13. package/dist/cli.js +1 -1
  14. package/dist/components/index.d.ts +16 -0
  15. package/dist/index.cjs +54 -7
  16. package/dist/index.d.cts +1 -1
  17. package/dist/index.d.ts +1 -1
  18. package/dist/index.js +54 -7
  19. package/dist/ios/src/index.d.ts +7 -0
  20. package/dist/ios/templates/CraftApp.swift +268 -12
  21. package/dist/ios/templates/CraftHybrid.swift +1 -0
  22. package/dist/ios/templates/CraftNativeActions.swift +3 -1
  23. package/dist/ios/templates/CraftNativeFlatList.swift +4 -0
  24. package/dist/ios/templates/CraftNativeMutation.swift +27 -2
  25. package/dist/ios/templates/CraftNativeScreen.swift +293 -44
  26. package/dist/ios/templates/CraftNativeUI.swift +89 -0
  27. package/dist/ios/templates/testing/DriverTests.swift.template +17 -1
  28. package/dist/macos/src/index.d.ts +14 -3
  29. package/dist/macos/src/index.js +124 -27
  30. package/dist/macos/src/toolchain.d.ts +56 -0
  31. package/dist/macos/templates/CraftMacApplication.swift +54 -9
  32. package/dist/macos/templates/CraftMacRenderer.swift +376 -18
  33. package/dist/macos/templates/CraftMacRuntime.swift +114 -1
  34. package/dist/macos/templates/CraftMacWebView.swift +416 -0
  35. package/dist/macos/templates/CraftNativeMutation.swift +27 -2
  36. package/dist/mobile.js +53 -6
  37. package/package.json +1 -1
package/dist/mobile.js CHANGED
@@ -430,6 +430,7 @@ var session = {
430
430
  return onCraftEvent(SESSION_EVENT, (detail) => callback(sessionToken(detail.token), sessionToken(detail.previous)));
431
431
  }
432
432
  };
433
+ var RECORDING_POWER_MODES = ["default", "saver", "auto"];
433
434
  function storageHost(method) {
434
435
  const host = getCraftRoot()?.storage;
435
436
  if (typeof host?.[method] !== "function")
@@ -508,6 +509,23 @@ function recordingIntentSupported(namespace) {
508
509
  const advertised = Array.isArray(caps) ? caps.includes(flag) : caps?.[flag] === true;
509
510
  return advertised && recordingOwnershipSupported(namespace) && typeof root?.[namespace]?.startRecording === "function";
510
511
  }
512
+ function recordingPowerModeSupported() {
513
+ const root = getCraftRoot();
514
+ const caps = root?.capabilities;
515
+ const advertised = Array.isArray(caps) ? caps.includes("locationRecordingPowerMode") : caps?.locationRecordingPowerMode === true;
516
+ return advertised && recordingOwnershipSupported("location") && typeof root?.location?.setRecordingPowerMode === "function";
517
+ }
518
+ function validatePowerMode(value) {
519
+ if (typeof value !== "string" || !RECORDING_POWER_MODES.includes(value))
520
+ throw Object.assign(new Error("powerMode must be 'default', 'saver' or 'auto'"), { code: "INVALID_ARGUMENT" });
521
+ return value;
522
+ }
523
+ function validateRecordingPowerStart(options) {
524
+ if (!Object.prototype.hasOwnProperty.call(options, "powerMode") || options.powerMode === undefined)
525
+ return;
526
+ if (validatePowerMode(options.powerMode) === "auto" && getCraftRoot() && !recordingPowerModeSupported())
527
+ throw Object.assign(new Error("This app build cannot start a recording in powerMode 'auto'"), { code: "RECORDING_POWER_MODE_UNSUPPORTED" });
528
+ }
511
529
  function validateRecordingStart(namespace, options) {
512
530
  if (!Object.prototype.hasOwnProperty.call(options, "recordingId"))
513
531
  return;
@@ -538,10 +556,20 @@ var webLocationRecording = {
538
556
  startedAt: null,
539
557
  locations: []
540
558
  };
559
+ var webLocationPowerMode = "default";
560
+ function webLocationRecordingState() {
561
+ return {
562
+ ...webLocationRecording,
563
+ sampleCount: webLocationRecording.locations.length,
564
+ powerMode: webLocationPowerMode,
565
+ effectivePowerMode: webLocationRecording.active && webLocationPowerMode === "saver" ? "saver" : "default"
566
+ };
567
+ }
541
568
  var webLocationRecordingWatchId = null;
542
569
  var location = {
543
570
  supportsRecordingOwnership: () => recordingOwnershipSupported("location"),
544
571
  supportsRecordingIntentIdentity: () => recordingIntentSupported("location"),
572
+ supportsRecordingPowerMode: () => recordingPowerModeSupported(),
545
573
  async getCurrentPosition(options = {}) {
546
574
  const craft = getCraftMobile();
547
575
  if (typeof window !== "undefined" && craft?.location) {
@@ -591,6 +619,7 @@ var location = {
591
619
  },
592
620
  async startRecording(options = {}) {
593
621
  validateRecordingStart("location", options);
622
+ validateRecordingPowerStart(options);
594
623
  const craft = getCraftMobile();
595
624
  if (typeof window !== "undefined" && craft?.location?.startRecording)
596
625
  return verifyRecordingStart(options, await craft.location.startRecording(options));
@@ -605,11 +634,27 @@ var location = {
605
634
  startedAt: Date.now(),
606
635
  locations: []
607
636
  };
637
+ webLocationPowerMode = options.powerMode ?? "default";
608
638
  webLocationRecordingWatchId = location.watchPosition((position) => {
609
639
  if (!webLocationRecording.paused)
610
640
  webLocationRecording.locations.push(position);
611
641
  }, options);
612
- return { ...webLocationRecording, sampleCount: 0 };
642
+ return webLocationRecordingState();
643
+ },
644
+ async setRecordingPowerMode(options) {
645
+ if (!options || !Object.prototype.hasOwnProperty.call(options, "expectedId"))
646
+ throw Object.assign(new Error("setRecordingPowerMode needs expectedId"), { code: "INVALID_ARGUMENT" });
647
+ validateRecordingOwnership("location", options);
648
+ const powerMode = validatePowerMode(options.powerMode);
649
+ if (getCraftRoot() && !recordingPowerModeSupported())
650
+ throw Object.assign(new Error("This app build cannot change the recording power mode"), { code: "RECORDING_POWER_MODE_UNSUPPORTED" });
651
+ const craft = getCraftMobile();
652
+ if (typeof window !== "undefined" && craft?.location?.setRecordingPowerMode)
653
+ return craft.location.setRecordingPowerMode({ expectedId: options.expectedId, powerMode });
654
+ if (!webLocationRecording.active)
655
+ throw Object.assign(new Error("No active location recording"), { code: "NO_ACTIVE_RECORDING" });
656
+ webLocationPowerMode = powerMode;
657
+ return webLocationRecordingState();
613
658
  },
614
659
  async pauseRecording(options) {
615
660
  validateRecordingOwnership("location", options);
@@ -617,7 +662,7 @@ var location = {
617
662
  if (typeof window !== "undefined" && craft?.location?.pauseRecording)
618
663
  return craft.location.pauseRecording(options);
619
664
  webLocationRecording.paused = true;
620
- return { ...webLocationRecording, sampleCount: webLocationRecording.locations.length };
665
+ return webLocationRecordingState();
621
666
  },
622
667
  async resumeRecording(options) {
623
668
  validateRecordingOwnership("location", options);
@@ -625,7 +670,7 @@ var location = {
625
670
  if (typeof window !== "undefined" && craft?.location?.resumeRecording)
626
671
  return craft.location.resumeRecording(options);
627
672
  webLocationRecording.paused = false;
628
- return { ...webLocationRecording, sampleCount: webLocationRecording.locations.length };
673
+ return webLocationRecordingState();
629
674
  },
630
675
  async stopRecording(options) {
631
676
  validateRecordingOwnership("location", options);
@@ -638,14 +683,14 @@ var location = {
638
683
  }
639
684
  webLocationRecording.active = false;
640
685
  webLocationRecording.paused = false;
641
- return { ...webLocationRecording, locations: [...webLocationRecording.locations] };
686
+ return { ...webLocationRecordingState(), locations: [...webLocationRecording.locations] };
642
687
  },
643
688
  async getRecordingState(options) {
644
689
  validateRecordingOwnership("location", options);
645
690
  const craft = getCraftMobile();
646
691
  if (typeof window !== "undefined" && craft?.location?.getRecordingState)
647
692
  return craft.location.getRecordingState(options);
648
- return { ...webLocationRecording, sampleCount: webLocationRecording.locations.length };
693
+ return webLocationRecordingState();
649
694
  },
650
695
  async acknowledgeRecording(options) {
651
696
  if (!options || !Object.prototype.hasOwnProperty.call(options, "expectedId"))
@@ -657,6 +702,7 @@ var location = {
657
702
  if (webLocationRecording.active)
658
703
  throw Object.assign(new Error("The recording is still active"), { code: "RECORDING_ALREADY_ACTIVE" });
659
704
  webLocationRecording = { id: null, active: false, paused: false, startedAt: null, locations: [] };
705
+ webLocationPowerMode = "default";
660
706
  return true;
661
707
  },
662
708
  async readRecording(options) {
@@ -664,7 +710,8 @@ var location = {
664
710
  const craft = getCraftMobile();
665
711
  if (typeof window !== "undefined" && craft?.location?.readRecording)
666
712
  return craft.location.readRecording(options);
667
- return [...webLocationRecording.locations];
713
+ const since = options?.since;
714
+ return typeof since === "number" && Number.isFinite(since) ? webLocationRecording.locations.filter((location) => location.timestamp > since) : [...webLocationRecording.locations];
668
715
  }
669
716
  };
670
717
  var share = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "craft-native",
3
- "version": "0.0.395",
3
+ "version": "0.0.408",
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>",