@geastack/apple 0.2.13 → 0.2.15

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/index.js CHANGED
@@ -2421,6 +2421,13 @@ function declarationForFramework(framework) {
2421
2421
  if ((framework.constants ?? []).length > 0)
2422
2422
  lines.push('');
2423
2423
  for (const fn of framework.functions ?? []) {
2424
+ // Every framework function is a native bridge: its arguments cross as
2425
+ // native carriers, so it cannot write, define or delete a property on any
2426
+ // script object. Without the contract, geatsc's global mutation census
2427
+ // reads each call as able to rewrite every intrinsic its arguments reach
2428
+ // (an `NSView` reaches `Object` through `.constructor`), which revokes the
2429
+ // stock `Object.assign` for the whole program.
2430
+ lines.push('/** @gea-host-no-property-writes */');
2424
2431
  lines.push(`export declare function ${fn.name}(${parametersSignature(fn.parameters ?? [], framework.name)}): ${typeScriptType(fn.returns, framework.name)}`);
2425
2432
  }
2426
2433
  if ((framework.functions ?? []).length > 0)
@@ -1,5 +1,8 @@
1
+ /** @gea-host-no-property-writes */
1
2
  export declare function requestLiveActivity(attributesJSON: string, contentStateJSON: string): LiveActivityHandle
3
+ /** @gea-host-no-property-writes */
2
4
  export declare function updateLiveActivity(activity: LiveActivityHandle, contentStateJSON: string): void
5
+ /** @gea-host-no-property-writes */
3
6
  export declare function endLiveActivity(activity: LiveActivityHandle): void
4
7
 
5
8
  export declare class LiveActivityHandle {
@@ -54,10 +54,15 @@ export declare const NSLayoutPriorityDefaultLow: number
54
54
  export declare const NSBoxCustom: number
55
55
  export declare const ObjCTargetAction: Selector
56
56
 
57
+ /** @gea-host-no-property-writes */
57
58
  export declare function installRootView(view: NSView): void
59
+ /** @gea-host-no-property-writes */
58
60
  export declare function installRootViewController(viewController: NSViewController): void
61
+ /** @gea-host-no-property-writes */
59
62
  export declare function installToolbar(spec: string, newNoteTarget: NSObject | null): void
63
+ /** @gea-host-no-property-writes */
60
64
  export declare function runDeviceCommand(command: string): string
65
+ /** @gea-host-no-property-writes */
61
66
  export declare function setScrollDocumentTopAligned(scrollView: NSScrollView, content: NSView): void
62
67
 
63
68
  export declare class NSColor extends NSObject {
@@ -1,5 +1,8 @@
1
+ /** @gea-host-no-property-writes */
1
2
  export declare function CGRectMake(x: number, y: number, width: number, height: number): CGRect
3
+ /** @gea-host-no-property-writes */
2
4
  export declare function CGPointMake(x: number, y: number): CGPoint
5
+ /** @gea-host-no-property-writes */
3
6
  export declare function CGSizeMake(width: number, height: number): CGSize
4
7
 
5
8
  export interface CGPoint {
@@ -5,6 +5,7 @@ export declare const CLDistanceFilterNone: number
5
5
  export declare const CLAuthorizationStatusNotDetermined: number
6
6
  export declare const CLAuthorizationStatusAuthorizedWhenInUse: number
7
7
 
8
+ /** @gea-host-no-property-writes */
8
9
  export declare function CLLocationCoordinate2DMake(latitude: number, longitude: number): CLLocationCoordinate2D
9
10
 
10
11
  export interface CLLocationCoordinate2D {
@@ -1,3 +1,4 @@
1
+ /** @gea-host-no-property-writes */
1
2
  export declare function CMTimeMakeWithSeconds(seconds: number, preferredTimescale: number): CMTime
2
3
 
3
4
  export interface CMTime {
@@ -1,2 +1,4 @@
1
+ /** @gea-host-no-property-writes */
1
2
  export declare function dispatchAsyncGlobal(execute: () => void): void
3
+ /** @gea-host-no-property-writes */
2
4
  export declare function dispatchAsyncMain(execute: () => void): void
@@ -1,9 +1,16 @@
1
+ /** @gea-host-no-property-writes */
1
2
  export declare function randomUUID(): string
3
+ /** @gea-host-no-property-writes */
2
4
  export declare function localTimeZone(): string
5
+ /** @gea-host-no-property-writes */
3
6
  export declare function sharedContainerPath(groupIdentifier: string): string
7
+ /** @gea-host-no-property-writes */
4
8
  export declare function readTextFile(path: string): string
9
+ /** @gea-host-no-property-writes */
5
10
  export declare function writeTextFile(path: string, text: string): void
11
+ /** @gea-host-no-property-writes */
6
12
  export declare function watchPath(path: string, changed: () => void): number
13
+ /** @gea-host-no-property-writes */
7
14
  export declare function stopWatchingPath(handle: number): void
8
15
 
9
16
  export declare class NSObject {
@@ -7,6 +7,7 @@ export declare const MKMapTypeSatellite: number
7
7
  export declare const MKUserTrackingModeNone: number
8
8
  export declare const MKUserTrackingModeFollow: number
9
9
 
10
+ /** @gea-host-no-property-writes */
10
11
  export declare function MKCoordinateRegionMakeWithDistance(centerCoordinate: CLLocationCoordinate2D, latitudinalMeters: number, longitudinalMeters: number): MKCoordinateRegion
11
12
 
12
13
  export interface MKCoordinateSpan {
@@ -5,7 +5,9 @@ export declare const MTLPrimitiveTypeTriangle: number
5
5
  export declare const MTLResourceStorageModeShared: number
6
6
  export declare const MTLCompareFunctionLess: number
7
7
 
8
+ /** @gea-host-no-property-writes */
8
9
  export declare function MTLCreateSystemDefaultDevice(): MTLDevice | null
10
+ /** @gea-host-no-property-writes */
9
11
  export declare function MTLClearColorMake(red: number, green: number, blue: number, alpha: number): MTLClearColor
10
12
 
11
13
  export interface MTLClearColor {
@@ -1,3 +1,6 @@
1
+ /** @gea-host-no-property-writes */
1
2
  export declare function writePassword(service: string, account: string, password: string): number
3
+ /** @gea-host-no-property-writes */
2
4
  export declare function readPassword(service: string, account: string): string
5
+ /** @gea-host-no-property-writes */
3
6
  export declare function deletePassword(service: string, account: string): number
@@ -1,7 +1,12 @@
1
+ /** @gea-host-no-property-writes */
1
2
  export declare function openModelContainer(schemaJSON: string): ModelContainer
3
+ /** @gea-host-no-property-writes */
2
4
  export declare function mainModelContext(container: ModelContainer): ModelContext
5
+ /** @gea-host-no-property-writes */
3
6
  export declare function insertModelJSON(context: ModelContext, modelJSON: string): void
7
+ /** @gea-host-no-property-writes */
4
8
  export declare function saveModelContext(context: ModelContext): void
9
+ /** @gea-host-no-property-writes */
5
10
  export declare function fetchModelsJSON(context: ModelContext, descriptorJSON: string): string
6
11
 
7
12
  export declare class ModelContainer {
@@ -17,6 +17,7 @@ export declare const UIControlEventTouchCancel: number
17
17
  export declare const UIControlEventValueChanged: number
18
18
  export declare const ObjCTargetAction: Selector
19
19
 
20
+ /** @gea-host-no-property-writes */
20
21
  export declare function installRootView(view: UIView): void
21
22
 
22
23
  export declare class UIColor extends NSObject {
@@ -1,3 +1,6 @@
1
+ /** @gea-host-no-property-writes */
1
2
  export declare function requestAuthorization(completed: (granted: boolean, error: string) => void): void
3
+ /** @gea-host-no-property-writes */
2
4
  export declare function scheduleNotification(identifier: string, title: string, body: string, delaySeconds: number, completed: (error: string) => void): void
5
+ /** @gea-host-no-property-writes */
3
6
  export declare function cancelNotification(identifier: string): void
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@geastack/apple",
3
- "version": "0.2.13",
3
+ "version": "0.2.15",
4
4
  "description": "Generated Apple SDK bindings plus the macOS and iOS native build targets for Gea apps.",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -111,14 +111,14 @@
111
111
  "access": "public"
112
112
  },
113
113
  "dependencies": {
114
- "@geastack/compiler": "^1.0.18",
115
- "@geastack/core": "^0.1.33",
116
- "@geastack/elements": "^0.1.2",
117
- "@geastack/engine": "^0.1.5",
114
+ "@geastack/compiler": "^1.0.29",
115
+ "@geastack/core": "^0.1.40",
116
+ "@geastack/elements": "^0.1.6",
117
+ "@geastack/engine": "^0.1.16",
118
118
  "@geastack/geaos": "^0.1.3",
119
119
  "@geastack/geatsc-plugin-apple-native": "^0.1.4",
120
- "@geastack/geatsc-plugin-gea": "^0.1.14",
121
- "@geastack/host": "^0.1.8"
120
+ "@geastack/geatsc-plugin-gea": "^0.1.22",
121
+ "@geastack/host": "^0.1.15"
122
122
  },
123
123
  "scripts": {
124
124
  "prepublishOnly": "npm run build",
@@ -153,7 +153,7 @@ resolve_gea_package() {
153
153
  fi
154
154
  done
155
155
  }
156
- GEA_CORE="$(resolve_gea_package @geastack/core)"
156
+ GEA_CORE="${GEA_CORE:-$(resolve_gea_package @geastack/core)}"
157
157
  GEA_APPLE_NATIVE_PLUGIN="$(resolve_gea_package @geastack/geatsc-plugin-apple-native)"
158
158
  # An app that installs @geastack/apple gets the plugin from node_modules; inside
159
159
  # this repository it is a sibling package that nothing links, so name it there.
@@ -161,8 +161,8 @@ if [[ -z "$GEA_APPLE_NATIVE_PLUGIN" && -d "$ROOT_DIR/../geatsc-plugin-apple-nati
161
161
  GEA_APPLE_NATIVE_PLUGIN="$(cd "$ROOT_DIR/../geatsc-plugin-apple-native" && pwd)"
162
162
  fi
163
163
  [ -n "$GEA_APPLE_NATIVE_PLUGIN" ] && [ -f "$GEA_APPLE_NATIVE_PLUGIN/dist/index.js" ] || { echo "Cannot resolve @geastack/geatsc-plugin-apple-native" >&2; exit 1; }
164
- GEA_COMPILER="$(resolve_gea_package @geastack/compiler)"
165
- GEA_PLUGIN="$(resolve_gea_package @geastack/geatsc-plugin-gea)"
164
+ GEA_COMPILER="${GEA_COMPILER:-$(resolve_gea_package @geastack/compiler)}"
165
+ GEA_PLUGIN="${GEA_PLUGIN:-$(resolve_gea_package @geastack/geatsc-plugin-gea)}"
166
166
  [ -n "$GEA_CORE" ] && [ -f "$GEA_CORE/package.json" ] || { echo "Cannot resolve @geastack/core via node_modules — run 'npm install' in $ROOT_DIR" >&2; exit 1; }
167
167
  GEA_HOST_DIR="${GEA_HOST_DIR:-$GEA_CORE/../host}"
168
168
  GEA_ENGINE_DIR="${GEA_ENGINE_DIR:-$GEA_CORE/../engine}"
@@ -549,22 +549,17 @@ generate_app() {
549
549
  --isolate-symbols
550
550
  )
551
551
  fi
552
- if [[ "${GEA_VITE_MODULE_GRAPH:-0}" == "1" || ( "$id" == "three-angle-metal" && "${GEA_THREE_MODULE_GRAPH:-1}" != "0" ) ]]; then
553
- extraArgs+=(--module-graph-out "$outDir/module-graph")
554
- fi
555
- # One generated C++ unit per source module instead of one for the whole app.
556
- # `read_geatsc_sources` already compiles every line of geatsc-sources.txt, so
557
- # this only changes how many lines there are; see the compiler's
558
- # docs/TRANSLATION-UNITS.md for the measured trade.
559
- if [[ "${GEA_PER_FILE_UNITS:-0}" == "1" ]]; then
560
- extraArgs+=(--per-file-units)
561
- fi
562
- if [[ "$id" == "three-angle-metal" && "${GEA_THREE_MODULE_GRAPH_ONLY:-0}" == "1" ]]; then
563
- extraArgs+=(--module-graph-only)
564
- fi
565
- if [[ "$id" == "three-angle-metal" && "${GEA_THREE_MODULE_GRAPH_COMPILE:-1}" != "0" ]]; then
566
- extraArgs+=(--compile-module-graph --allow-any)
552
+ local buildConfig="$outDir/gea-build-config.json"
553
+ mkdir -p "$outDir"
554
+ local debugConfigArgs=()
555
+ [[ "${GEA_NATIVE_DEBUGGER:-0}" != "1" ]] || debugConfigArgs+=(--debug)
556
+ if ! node "${GEA_CLI_BIN:?Use gea build --target macos}" config --project "$appDir" --target macos "${debugConfigArgs[@]+"${debugConfigArgs[@]}"}" > "$buildConfig"; then
557
+ echo "Cannot resolve macOS build configuration for '$id'" >&2
558
+ return 1
567
559
  fi
560
+ extraArgs+=(--build-config "$buildConfig")
561
+ local moduleGraphOnly
562
+ moduleGraphOnly="$(node -e 'console.log(require(process.argv[1]).settings.compiler?.moduleGraph === "only" ? "1" : "0")' "$buildConfig")"
568
563
  # `gea build` resolves which compiler plugins this app's packages ship and
569
564
  # names them here, so no app needs a stub file re-exporting one. The appDir
570
565
  # fallback is for a direct invocation of this script, not a decision.
@@ -582,17 +577,11 @@ generate_app() {
582
577
  local envSignatureFile="$outDir/.gea-build-env"
583
578
  local compilerFingerprint
584
579
  compilerFingerprint="$(node "$ROOT_DIR/targets/macos/compiler-input-fingerprint.mjs" "$GEA_COMPILER")"
585
- local envSignature="GEA_THREE_USE_UPSTREAM=${GEA_THREE_USE_UPSTREAM:-}
586
- GEA_THREE_REFERENCE_DEMO=${GEA_THREE_REFERENCE_DEMO:-}
587
- GEA_THREE_MODULE_GRAPH=${GEA_THREE_MODULE_GRAPH:-1}
588
- GEA_VITE_MODULE_GRAPH=${GEA_VITE_MODULE_GRAPH:-0}
589
- GEA_THREE_MODULE_GRAPH_ONLY=${GEA_THREE_MODULE_GRAPH_ONLY:-0}
590
- GEA_THREE_MODULE_GRAPH_COMPILE=${GEA_THREE_MODULE_GRAPH_COMPILE:-1}
591
- GEA_PER_FILE_UNITS=${GEA_PER_FILE_UNITS:-0}
592
- GEA_CPP_TRANSLATION_UNITS=${GEA_CPP_TRANSLATION_UNITS:-}
580
+ local envSignature="GEA_BUILD_CONFIG=$(cat "$buildConfig")
593
581
  GEA_WEBGL_AUTO_INSTANCE=${GEA_WEBGL_AUTO_INSTANCE:-}
594
582
  GEA_WEBGL_AUTO_INSTANCE_TEST=${GEA_WEBGL_AUTO_INSTANCE_TEST:-}
595
583
  GEA_COMPILER_FINGERPRINT=${compilerFingerprint}"
584
+
596
585
  # Only when an alternate compiler was named, so the default signature -- and
597
586
  # therefore every existing generated directory's freshness -- is unchanged.
598
587
  if [[ -n "${GEA_GEATSC_BIN:-}" ]]; then
@@ -605,6 +594,17 @@ GEA_GEATSC_FINGERPRINT=$(tree_fingerprint "$(dirname "$GEA_GEATSC_BIN")")"
605
594
  local generationSentinel="$outDir/.gea-generation.stamp"
606
595
  local appleStateFile="$outDir/.gea-current-apple-native"
607
596
  local moduleGraphFile="$outDir/module-graph/gea-module-graph.json"
597
+ # Explicit native-only iteration uses the last generated snapshot. Do not
598
+ # update freshness stamps: a normal build must still regenerate changed TS.
599
+ if [[ "${GEA_MACOS_REUSE_GENERATED:-0}" == "1" ]]; then
600
+ [[ -s "$sourceList" ]] || { echo "No generated C++ snapshot for '$id'" >&2; return 1; }
601
+ local snapshotSource
602
+ while IFS= read -r snapshotSource; do
603
+ [[ -s "$snapshotSource" ]] || { echo "Missing generated source: $snapshotSource" >&2; return 1; }
604
+ done < <(read_geatsc_sources "$outDir")
605
+ echo "Reusing generated C++ snapshot for '$id' (native-only rebuild)"
606
+ return 0
607
+ fi
608
608
  if [[ -f "$sourceList" && -f "$generationSentinel" ]]; then
609
609
  local generationInputDirs=()
610
610
  # Every plugin that feeds generation is a generation input: an edit to one
@@ -635,8 +635,8 @@ GEA_GEATSC_FINGERPRINT=$(tree_fingerprint "$(dirname "$GEA_GEATSC_BIN")")"
635
635
  newer="${newer:-env:apple-native-output-inconsistent}"
636
636
  fi
637
637
  fi
638
- if [[ "$id" == "three-angle-metal" && "${GEA_THREE_MODULE_GRAPH_ONLY:-0}" == "1" && ! -f "$outDir/module-graph/gea-module-graph.json" ]]; then
639
- newer="${newer:-env:three-module-graph-only}"
638
+ if [[ "$moduleGraphOnly" == "1" && ! -f "$outDir/module-graph/gea-module-graph.json" ]]; then
639
+ newer="${newer:-env:module-graph-only}"
640
640
  fi
641
641
  fi
642
642
  if [[ ! -f "$sourceList" || ! -f "$generationSentinel" || -n "$newer" ]]; then
@@ -651,7 +651,7 @@ GEA_GEATSC_FINGERPRINT=$(tree_fingerprint "$(dirname "$GEA_GEATSC_BIN")")"
651
651
  --apple-platform macos \
652
652
  --geatsc-apple-native-plugin "$GEA_APPLE_NATIVE_PLUGIN/dist/index.js" \
653
653
  "${extraArgs[@]+"${extraArgs[@]}"}"; then
654
- if [[ "$id" == "three-angle-metal" && "${GEA_THREE_MODULE_GRAPH_ONLY:-0}" == "1" ]]; then
654
+ if [[ "$moduleGraphOnly" == "1" ]]; then
655
655
  echo "Module graph generation failed for '$id'; native generation state is unchanged" >&2
656
656
  return 1
657
657
  fi
@@ -659,7 +659,7 @@ GEA_GEATSC_FINGERPRINT=$(tree_fingerprint "$(dirname "$GEA_GEATSC_BIN")")"
659
659
  echo "C++ generation failed for '$id'; invalidated freshness state" >&2
660
660
  return 1
661
661
  fi
662
- if [[ "$id" == "three-angle-metal" && "${GEA_THREE_MODULE_GRAPH_ONLY:-0}" == "1" ]]; then
662
+ if [[ "$moduleGraphOnly" == "1" ]]; then
663
663
  echo "Generated module graph only for '$id' at $outDir/module-graph"
664
664
  exit 0
665
665
  fi
@@ -686,7 +686,7 @@ GEA_GEATSC_FINGERPRINT=$(tree_fingerprint "$(dirname "$GEA_GEATSC_BIN")")"
686
686
  touch "$generationSentinel"
687
687
  generatedNow=1
688
688
  fi
689
- if [[ "$id" == "three-angle-metal" && "${GEA_THREE_MODULE_GRAPH_ONLY:-0}" == "1" ]]; then
689
+ if [[ "$moduleGraphOnly" == "1" ]]; then
690
690
  echo "Module graph already fresh for '$id' at $outDir/module-graph"
691
691
  exit 0
692
692
  fi
@@ -864,6 +864,10 @@ fi
864
864
 
865
865
  CXX_DEFINES=(
866
866
  -DGEA_EMBEDDED_ENABLE_VIRTUAL_KEYBOARD=0
867
+ # Desktop screens exceed the embedded default of 512 nodes. Apply the
868
+ # capacity consistently to generated app code and every framework TU.
869
+ -DGEA_EMBEDDED_MAX_NODES=8192
870
+ -DGEA_EMBEDDED_MAX_IMAGES=8192
867
871
  # Canvas ctx.fillText glyphs: rasterize at runtime from the bundle's
868
872
  # Resources/Fonts TTFs (font_registry.mm's lookupRuntimeTtfFontForFamily).
869
873
  # Windowed builds link no baked font atlas, so without this canvas text
@@ -872,6 +876,40 @@ CXX_DEFINES=(
872
876
  # registered TTF bytes there, and falls through.
873
877
  -DGEA_EMBEDDED_TTF_RUNTIME_FONTS=1
874
878
  )
879
+ if [[ "${GEA_NATIVE_DEBUGGER:-0}" == "1" ]]; then
880
+ [[ -f "${GEA_DEBUGGER_NATIVE_SOURCE:-}" ]] || { echo "GEA_DEBUGGER_NATIVE_SOURCE must name debugger/native/macos.mm" >&2; exit 2; }
881
+ # Run the same declaration model in the host adapter and native inspector JSC.
882
+ node --input-type=module - "$GEA_DEBUGGER_NATIVE_SOURCE" "$GENERATED_DIR/gea_debugger_css.h" <<'NODE'
883
+ import { readFileSync, writeFileSync, existsSync } from 'node:fs'
884
+ import path from 'node:path'
885
+ const [nativeSource, output] = process.argv.slice(2)
886
+ const source = readFileSync(path.resolve(path.dirname(nativeSource), '../src/css.mjs'), 'utf8')
887
+ const names = [...source.matchAll(/export function (\w+)/g)].map(m => m[1])
888
+ const script = source.replace(/export function /g, 'function ') +
889
+ '\nglobalThis.__geaCSS = {' + names.join(',') + '};\n'
890
+ const header = 'static const char geaDebuggerCss[] = {' +
891
+ [...Buffer.from(script)].join(',') + ',0};\n'
892
+ if (!existsSync(output) || readFileSync(output, 'utf8') !== header) writeFileSync(output, header)
893
+ NODE
894
+ # JSX handlers are delegated to the body; the runtime's listener hook tells
895
+ # the inspector which element registered each one. Its callers are runtime
896
+ # helpers of varying depth, so record several frames; the inspector picks
897
+ # the first one that maps to the app's original source.
898
+ debuggerHooks="$GENERATED_DIR/gea_debugger_hooks.h"
899
+ hooksText='#pragma once
900
+ #ifdef __cplusplus
901
+ extern "C" void gea_debugger_note_listener(int node, const char *type, void *const *sites, int count);
902
+ #define GEA_JSX_NODE_LISTENER_HOOK(node, type) do { \
903
+ _Pragma("clang diagnostic push") _Pragma("clang diagnostic ignored \"-Wframe-address\"") \
904
+ void *const geaDebuggerSites[] = {__builtin_return_address(1), __builtin_return_address(2), \
905
+ __builtin_return_address(3), __builtin_return_address(4)}; \
906
+ _Pragma("clang diagnostic pop") \
907
+ gea_debugger_note_listener((node), (type), geaDebuggerSites, 4); \
908
+ } while (0)
909
+ #endif'
910
+ [[ -f "$debuggerHooks" && "$(cat "$debuggerHooks")" == "$hooksText" ]] || printf '%s\n' "$hooksText" > "$debuggerHooks"
911
+ CXX_DEFINES+=(-DGEA_NATIVE_DEBUGGER=1 -include "$debuggerHooks")
912
+ fi
875
913
  MACOS_SHARED_RUNTIME_BUILTINS="${GEA_MACOS_SHARED_RUNTIME_BUILTINS:-0}"
876
914
  case "$MACOS_SHARED_RUNTIME_BUILTINS" in
877
915
  0) ;;
@@ -922,6 +960,9 @@ case "${GEA_MACOS_THERMALRIGHT_PRODUCT_ID:-}" in
922
960
  THERMALRIGHT_DEFAULT_PRODUCT_ID="${GEA_MACOS_THERMALRIGHT_PRODUCT_ID}"
923
961
  ;;
924
962
  esac
963
+ if [[ "$THERMALRIGHT_DISPLAY_TARGET" == "0" ]]; then
964
+ CXX_DEFINES+=(-DGEA_EMBEDDED_PIXEL_FORMAT=1) # RGBA8888 for AppKit
965
+ fi
925
966
  if [[ "$THERMALRIGHT_DISPLAY_TARGET" == "1" ]]; then
926
967
  THERMALRIGHT_WIDTH="${GEA_MACOS_THERMALRIGHT_WIDTH:-$THERMALRIGHT_DEFAULT_WIDTH}"
927
968
  THERMALRIGHT_HEIGHT="${GEA_MACOS_THERMALRIGHT_HEIGHT:-$THERMALRIGHT_DEFAULT_HEIGHT}"
@@ -1029,6 +1070,10 @@ MM_SOURCES=(
1029
1070
  "$ROOT_DIR/targets/macos/main/macos_network.mm"
1030
1071
  )
1031
1072
 
1073
+ if [[ "${GEA_NATIVE_DEBUGGER:-0}" == "1" ]]; then
1074
+ MM_SOURCES+=("$GEA_DEBUGGER_NATIVE_SOURCE")
1075
+ fi
1076
+
1032
1077
  if [[ -n "$SINGLE_APP_DIR" ]]; then
1033
1078
  while IFS= read -r native_src; do
1034
1079
  [[ -n "$native_src" ]] || continue
@@ -1884,7 +1929,10 @@ timing_mark compile
1884
1929
  # AVFoundation is unconditional: targets/shared/apple_audio.mm (the real audio
1885
1930
  # backend, oscillators + file/PCM playback) is built into every macOS app, not
1886
1931
  # just apple-native ones.
1887
- LINK_FRAMEWORKS=(-framework Cocoa -framework QuartzCore -framework CoreText -framework IOKit -framework ImageIO -framework CoreGraphics -framework SystemConfiguration -framework AVFoundation)
1932
+ LINK_FRAMEWORKS=(-framework GameController -framework Cocoa -framework QuartzCore -framework CoreText -framework IOKit -framework ImageIO -framework CoreGraphics -framework SystemConfiguration -framework AVFoundation)
1933
+ if [[ "${GEA_NATIVE_DEBUGGER:-0}" == "1" ]]; then
1934
+ LINK_FRAMEWORKS+=(-framework JavaScriptCore)
1935
+ fi
1888
1936
  if [[ "$APPLE_NATIVE" == "1" ]]; then
1889
1937
  # The apple-native bridge emits Objective-C++ for every framework in the
1890
1938
  # metadata (UIKit + the iOS-only AVFoundation camera shims are compiled out
@@ -55,7 +55,7 @@ void ${prefix}_frame(int timestamp_ms)
55
55
  \t{
56
56
  \t\tgea::CycleCollectionDeferral deferCycleCollection;
57
57
  \t\tgea::framework::app::generated::${prefix}::drainMicrotasks();
58
- \t\tgea::host::runAnimationFrameCallbacks(static_cast<double>(timestamp_ms));
58
+ \t\tgea::host::runAnimationFrameCallbacks(timestamp_ms);
59
59
  \t\tgea::host::websocket::runCallbacks();
60
60
  \t\tgea::host::rtc::runCallbacks();
61
61
  \t\tgea::embedded::ui::Document::instance().frame(timestamp_ms);
@@ -141,7 +141,7 @@ std::uint8_t *ensureScratch(size_t bytes)
141
141
  if (self.nodeId >= tree.nodeCount()) return;
142
142
  const auto *canvas = tree.canvas(self.nodeId);
143
143
  if (!canvas) return;
144
- const std::uint16_t *src = canvas->pixels();
144
+ const gea::framework::graphics::pixel::native_t *src = canvas->pixels();
145
145
  const int w = canvas->width();
146
146
  const int h = canvas->height();
147
147
  if (!src || w <= 0 || h <= 0) return;
@@ -150,17 +150,17 @@ std::uint8_t *ensureScratch(size_t bytes)
150
150
  std::uint8_t *dst = ensureScratch(bytes);
151
151
  if (!dst) return;
152
152
  for (int i = 0; i < w * h; i++) {
153
- int r, g, b;
154
- gea::framework::graphics::pixel::unpackRgb565(src[i], &r, &g, &b);
155
- dst[i * 4 + 0] = static_cast<std::uint8_t>((r * 255 + 15) / 31);
156
- dst[i * 4 + 1] = static_cast<std::uint8_t>((g * 255 + 31) / 63);
157
- dst[i * 4 + 2] = static_cast<std::uint8_t>((b * 255 + 15) / 31);
158
- dst[i * 4 + 3] = 0xFF;
153
+ int r, g, b, a;
154
+ gea::framework::graphics::pixel::unpackNative8(src[i], &r, &g, &b, &a);
155
+ dst[i * 4 + 0] = static_cast<std::uint8_t>(r);
156
+ dst[i * 4 + 1] = static_cast<std::uint8_t>(g);
157
+ dst[i * 4 + 2] = static_cast<std::uint8_t>(b);
158
+ dst[i * 4 + 3] = static_cast<std::uint8_t>(a);
159
159
  }
160
160
 
161
161
  CGColorSpaceRef cs = CGColorSpaceCreateWithName(kCGColorSpaceSRGB);
162
162
  CGDataProviderRef provider = CGDataProviderCreateWithData(NULL, dst, bytes, NULL);
163
- const uint32_t bitmapInfo = (uint32_t)kCGImageAlphaNoneSkipLast | (uint32_t)kCGBitmapByteOrder32Big;
163
+ const uint32_t bitmapInfo = (uint32_t)kCGImageAlphaLast | (uint32_t)kCGBitmapByteOrder32Big;
164
164
  CGImageRef img = CGImageCreate((size_t)w, (size_t)h, 8, 32, (size_t)w * 4,
165
165
  cs, bitmapInfo,
166
166
  provider, NULL, false, kCGRenderingIntentDefault);
@@ -1,6 +1,6 @@
1
1
  #pragma once
2
2
 
3
- #include <cstdint>
3
+ #include "pixel.h"
4
4
 
5
5
  #ifdef __OBJC__
6
6
  @class NSColor;
@@ -9,10 +9,10 @@
9
9
  namespace gea::macos {
10
10
 
11
11
  #ifdef __OBJC__
12
- NSColor *rgb565ToNSColor(std::uint16_t rgb565);
12
+ NSColor *nativeToNSColor(gea::framework::graphics::pixel::native_t color);
13
13
  #endif
14
14
 
15
15
  // Caller-owns the returned CGColorRef; release with CGColorRelease.
16
- struct CGColor *rgb565ToCGColor(std::uint16_t rgb565);
16
+ struct CGColor *nativeToCGColor(gea::framework::graphics::pixel::native_t color);
17
17
 
18
18
  } // namespace gea::macos
@@ -7,33 +7,33 @@ namespace gea::macos {
7
7
 
8
8
  namespace {
9
9
 
10
- void unpack(std::uint16_t rgb565, CGFloat *r, CGFloat *g, CGFloat *b)
10
+ void unpack(gea::framework::graphics::pixel::native_t color, CGFloat *r, CGFloat *g, CGFloat *b)
11
11
  {
12
- int ri, gi, bi;
13
- gea::framework::graphics::pixel::unpackRgb565(rgb565, &ri, &gi, &bi);
14
- *r = static_cast<CGFloat>(ri) / 31.0;
15
- *g = static_cast<CGFloat>(gi) / 63.0;
16
- *b = static_cast<CGFloat>(bi) / 31.0;
12
+ int ri, gi, bi, ai;
13
+ gea::framework::graphics::pixel::unpackNative8(color, &ri, &gi, &bi, &ai);
14
+ *r = static_cast<CGFloat>(ri) / 255.0;
15
+ *g = static_cast<CGFloat>(gi) / 255.0;
16
+ *b = static_cast<CGFloat>(bi) / 255.0;
17
17
  }
18
18
 
19
19
  } // namespace
20
20
 
21
- NSColor *rgb565ToNSColor(std::uint16_t rgb565)
21
+ NSColor *nativeToNSColor(gea::framework::graphics::pixel::native_t color)
22
22
  {
23
23
  CGFloat r, g, b;
24
- unpack(rgb565, &r, &g, &b);
24
+ unpack(color, &r, &g, &b);
25
25
  return [NSColor colorWithSRGBRed:r green:g blue:b alpha:1.0];
26
26
  }
27
27
 
28
- CGColor *rgb565ToCGColor(std::uint16_t rgb565)
28
+ CGColor *nativeToCGColor(gea::framework::graphics::pixel::native_t color)
29
29
  {
30
30
  CGFloat r, g, b;
31
- unpack(rgb565, &r, &g, &b);
31
+ unpack(color, &r, &g, &b);
32
32
  CGFloat comps[4] = {r, g, b, 1.0};
33
33
  CGColorSpaceRef cs = CGColorSpaceCreateWithName(kCGColorSpaceSRGB);
34
- CGColorRef color = CGColorCreate(cs, comps);
34
+ CGColorRef result = CGColorCreate(cs, comps);
35
35
  CGColorSpaceRelease(cs);
36
- return color;
36
+ return result;
37
37
  }
38
38
 
39
39
  } // namespace gea::macos
@@ -8,9 +8,12 @@ namespace gea::macos {
8
8
 
9
9
  #ifdef __OBJC__
10
10
  // Returns an NSImage built from the ImageStore slot at imageId, or nil if
11
- // the slot is empty / invalid. Pixels are converted from RGB565 (+ optional
12
- // alpha channel) to RGBA8888. Caller owns the result via ARC.
11
+ // the slot is empty / invalid. Native color channels are preserved as RGBA8888.
12
+ // Caller owns the result via ARC.
13
13
  NSImage *imageForId(int imageId);
14
+ NSImage *imageForNode(int nodeId);
15
+ NSImage *imageForIdRegion(int imageId, int x, int y, int width, int height);
16
+ NSImage *imageForIdCover(int imageId, int width, int height);
14
17
  #endif
15
18
 
16
19
  } // namespace gea::macos
@@ -3,17 +3,54 @@
3
3
  #include "image_bridge.h"
4
4
  #include "image.h"
5
5
  #include "pixel.h"
6
+ #include "ui/tree_internal.h"
7
+ #include <cstdlib>
8
+ #include <algorithm>
9
+ #include <cmath>
6
10
 
7
11
  namespace gea::macos {
8
12
 
13
+ NSImage *imageForNode(int nodeId)
14
+ {
15
+ auto &tree = gea::embedded::ui::Tree::instance();
16
+ if (nodeId < 0 || nodeId >= tree.nodeCount()) return nil;
17
+ const auto &node = tree.node(nodeId);
18
+ const char *width = tree.getAttribute(nodeId, "data-source-width");
19
+ if (width && width[0]) {
20
+ auto crop = [&](const char *name) { const char *value = tree.getAttribute(nodeId, name); return value ? std::atoi(value) : 0; };
21
+ return imageForIdRegion(node.image_id, crop("data-source-x"), crop("data-source-y"), std::atoi(width), crop("data-source-height"));
22
+ }
23
+ if (node.style.image_fit == 2) return imageForIdCover(node.image_id, node.layout.width, node.layout.height);
24
+ return imageForId(node.image_id);
25
+ }
26
+
9
27
  NSImage *imageForId(int imageId)
28
+ {
29
+ auto &store = gea::framework::graphics::ImageStore::instance();
30
+ return imageForIdRegion(imageId, 0, 0, store.width(imageId), store.height(imageId));
31
+ }
32
+
33
+ NSImage *imageForIdCover(int imageId, int width, int height)
34
+ {
35
+ auto &store = gea::framework::graphics::ImageStore::instance();
36
+ const int sw = store.width(imageId), sh = store.height(imageId);
37
+ if (width <= 0 || height <= 0 || sw <= 0 || sh <= 0) return nil;
38
+ const double ratio = static_cast<double>(width) / height;
39
+ int cw = sw, ch = sh;
40
+ if (static_cast<double>(sw) / sh > ratio) cw = std::clamp(static_cast<int>(std::lround(sh * ratio)), 1, sw);
41
+ else ch = std::clamp(static_cast<int>(std::lround(sw / ratio)), 1, sh);
42
+ return imageForIdRegion(imageId, (sw - cw) / 2, (sh - ch) / 2, cw, ch);
43
+ }
44
+
45
+ NSImage *imageForIdRegion(int imageId, int x, int y, int w, int h)
10
46
  {
11
47
  using namespace gea::framework::graphics;
12
48
  if (imageId < 0) return nil;
13
49
  auto &store = ImageStore::instance();
14
- const int w = store.width(imageId);
15
- const int h = store.height(imageId);
16
- const std::uint16_t *src = store.currentPixels(imageId);
50
+ const int sourceWidth = store.width(imageId);
51
+ const int sourceHeight = store.height(imageId);
52
+ if (x < 0 || y < 0 || w <= 0 || h <= 0 || x > sourceWidth - w || y > sourceHeight - h) return nil;
53
+ const pixel::native_t *src = store.currentPixels(imageId);
17
54
  const std::uint8_t *alpha = store.currentAlpha(imageId);
18
55
  if (w <= 0 || h <= 0 || !src) return nil;
19
56
 
@@ -21,12 +58,13 @@ NSImage *imageForId(int imageId)
21
58
  NSMutableData *rgba = [NSMutableData dataWithLength:(NSUInteger)(pixelCount * 4)];
22
59
  std::uint8_t *dst = static_cast<std::uint8_t *>(rgba.mutableBytes);
23
60
  for (NSInteger i = 0; i < pixelCount; i++) {
24
- int r, g, b;
25
- pixel::unpackRgb565(src[i], &r, &g, &b);
26
- dst[i * 4 + 0] = static_cast<std::uint8_t>((r * 255 + 15) / 31);
27
- dst[i * 4 + 1] = static_cast<std::uint8_t>((g * 255 + 31) / 63);
28
- dst[i * 4 + 2] = static_cast<std::uint8_t>((b * 255 + 15) / 31);
29
- dst[i * 4 + 3] = alpha ? alpha[i] : 0xFF;
61
+ int r, g, b, a;
62
+ const NSInteger sourceIndex = (y + i / w) * sourceWidth + x + i % w;
63
+ pixel::unpackNative8(src[sourceIndex], &r, &g, &b, &a);
64
+ dst[i * 4 + 0] = static_cast<std::uint8_t>(r);
65
+ dst[i * 4 + 1] = static_cast<std::uint8_t>(g);
66
+ dst[i * 4 + 2] = static_cast<std::uint8_t>(b);
67
+ dst[i * 4 + 3] = alpha ? alpha[sourceIndex] : static_cast<std::uint8_t>(a);
30
68
  }
31
69
 
32
70
  NSBitmapImageRep *rep =