@legendapp/spark 0.0.2 → 0.0.3

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 (87) hide show
  1. package/package.json +2 -2
  2. package/patches/dependencies.json +252 -0
  3. package/patches/expo-application@55.0.19.patch +54 -0
  4. package/patches/expo-blur@55.0.18.patch +130 -0
  5. package/patches/expo-device@55.0.21.patch +149 -0
  6. package/patches/expo-font@55.0.8.patch +55 -0
  7. package/patches/expo-glass-effect@55.0.11.patch +304 -0
  8. package/patches/expo-haptics@55.0.18.patch +54 -0
  9. package/patches/expo-image-manipulator@55.0.21.patch +312 -0
  10. package/patches/expo-image-picker@55.0.24.patch +327 -0
  11. package/patches/expo-image@55.0.11.patch +158 -0
  12. package/patches/expo-keep-awake@55.0.8.patch +41 -0
  13. package/patches/expo-localization@55.0.19.patch +32 -0
  14. package/patches/expo-location@55.1.15.patch +190 -0
  15. package/patches/expo-symbols@55.0.9.patch +286 -0
  16. package/patches/expo-system-ui@55.0.22.patch +61 -0
  17. package/patches/expo-web-browser@55.0.20.patch +13 -0
  18. package/patches/react-native-app-logs@0.3.1.patch +20 -0
  19. package/patches/react-native-blurhash@2.1.3.patch +318 -0
  20. package/patches/react-native-community-blur@4.4.1.patch +415 -0
  21. package/patches/react-native-community-datetimepicker@9.2.2.patch +320 -0
  22. package/patches/react-native-fast-image@10.9.9.patch +131 -0
  23. package/patches/react-native-graph@1.4.0.patch +157 -0
  24. package/patches/react-native-keyboard-controller@1.22.9.patch +16 -0
  25. package/patches/react-native-masked-view-masked-view@0.3.2.patch +140 -0
  26. package/patches/react-native-mmkv@4.3.2.patch +40 -0
  27. package/patches/react-native-nitro-fetch@1.9.0.patch +130 -0
  28. package/patches/react-native-nitro-zxing@0.3.0.patch +13 -0
  29. package/patches/react-native-quick-base64@3.0.1.patch +13 -0
  30. package/patches/react-native-quick-crypto@1.1.9.patch +31 -0
  31. package/patches/react-native-release-profiler@0.4.5.patch +37 -0
  32. package/patches/react-native-screen-corner-radius@0.2.3.patch +13 -0
  33. package/patches/react-native-screens@4.23.0.patch +160 -0
  34. package/patches/react-native-svg@15.15.3.patch +31 -0
  35. package/patches/react-native-unistyles@3.6.0.patch +203 -0
  36. package/patches/react-native-worklets-core@1.6.3.patch +13 -0
  37. package/patches/react-navigation-native-stack@7.21.0.patch +16 -0
  38. package/patches/sentry-react-native@8.32.0.patch +76 -0
  39. package/skills/spark/UPGRADING.md +34 -0
  40. package/vendor/node_modules/@legendapp/spark-ai/package.json +3 -3
  41. package/vendor/node_modules/@legendapp/spark-audio/package.json +2 -2
  42. package/vendor/node_modules/@legendapp/spark-auth-session/package.json +3 -3
  43. package/vendor/node_modules/@legendapp/spark-cli/dist/build.js +6 -3
  44. package/vendor/node_modules/@legendapp/spark-cli/dist/dev.js +7 -2
  45. package/vendor/node_modules/@legendapp/spark-cli/dist/migrations.cjs +3 -0
  46. package/vendor/node_modules/@legendapp/spark-cli/dist/project.js +13 -1
  47. package/vendor/node_modules/@legendapp/spark-cli/dist/release.json +11 -11
  48. package/vendor/node_modules/@legendapp/spark-cli/dist/runtime-input-cache.js +140 -0
  49. package/vendor/node_modules/@legendapp/spark-cli/package.json +3 -3
  50. package/vendor/node_modules/@legendapp/spark-cli/templates/blank-typescript/package.json +2 -2
  51. package/vendor/node_modules/@legendapp/spark-cli/templates/universal/package.json +2 -2
  52. package/vendor/node_modules/@legendapp/spark-cli/templates/windows/package.json +2 -2
  53. package/vendor/node_modules/@legendapp/spark-clipboard/package.json +2 -2
  54. package/vendor/node_modules/@legendapp/spark-codex/package.json +2 -2
  55. package/vendor/node_modules/@legendapp/spark-commands/package.json +5 -5
  56. package/vendor/node_modules/@legendapp/spark-context-menu/package.json +2 -2
  57. package/vendor/node_modules/@legendapp/spark-desktop-app/macos/SparkTestDriver.mm +64 -2
  58. package/vendor/node_modules/@legendapp/spark-desktop-app/package.json +1 -1
  59. package/vendor/node_modules/@legendapp/spark-desktop-config/autolinking.cjs +3 -2
  60. package/vendor/node_modules/@legendapp/spark-desktop-config/native-patches.cjs +28 -10
  61. package/vendor/node_modules/@legendapp/spark-desktop-config/package.json +3 -3
  62. package/vendor/node_modules/@legendapp/spark-desktop-host/package.json +2 -2
  63. package/vendor/node_modules/@legendapp/spark-desktop-links/package.json +2 -2
  64. package/vendor/node_modules/@legendapp/spark-desktop-shortcuts/package.json +2 -2
  65. package/vendor/node_modules/@legendapp/spark-desktop-windows/package.json +3 -3
  66. package/vendor/node_modules/@legendapp/spark-documents/package.json +7 -7
  67. package/vendor/node_modules/@legendapp/spark-drag-drop/package.json +2 -2
  68. package/vendor/node_modules/@legendapp/spark-file-dialog/package.json +2 -2
  69. package/vendor/node_modules/@legendapp/spark-file-system/package.json +2 -2
  70. package/vendor/node_modules/@legendapp/spark-global-shortcuts/package.json +2 -2
  71. package/vendor/node_modules/@legendapp/spark-html/package.json +2 -2
  72. package/vendor/node_modules/@legendapp/spark-markdown/package.json +2 -2
  73. package/vendor/node_modules/@legendapp/spark-message-dialog/package.json +2 -2
  74. package/vendor/node_modules/@legendapp/spark-native-menu/package.json +2 -2
  75. package/vendor/node_modules/@legendapp/spark-notifications/package.json +2 -2
  76. package/vendor/node_modules/@legendapp/spark-processes/package.json +2 -2
  77. package/vendor/node_modules/@legendapp/spark-rich-text/package.json +2 -2
  78. package/vendor/node_modules/@legendapp/spark-secure-storage/package.json +2 -2
  79. package/vendor/node_modules/@legendapp/spark-settings/package.json +3 -3
  80. package/vendor/node_modules/@legendapp/spark-settings-ui/package.json +4 -4
  81. package/vendor/node_modules/@legendapp/spark-sqlite/package.json +3 -3
  82. package/vendor/node_modules/@legendapp/spark-system/package.json +2 -2
  83. package/vendor/node_modules/@legendapp/spark-tray/package.json +2 -2
  84. package/vendor/node_modules/@legendapp/spark-ui/package.json +2 -2
  85. package/vendor/node_modules/@legendapp/spark-updates/package.json +2 -2
  86. package/vendor/node_modules/@legendapp/spark-webview/package.json +2 -2
  87. package/vendor/node_modules/@legendapp/spark-window-options/package.json +1 -1
@@ -0,0 +1,304 @@
1
+ diff --git a/build/GlassContainer.macos.js b/build/GlassContainer.macos.js
2
+ new file mode 100644
3
+ index 0000000..7218bec
4
+ --- /dev/null
5
+ +++ b/build/GlassContainer.macos.js
6
+ @@ -0,0 +1,3 @@
7
+ +// macOS uses the native glass views, like iOS.
8
+ +export * from './GlassContainer.ios';
9
+ +export { default } from './GlassContainer.ios';
10
+ diff --git a/build/GlassView.macos.js b/build/GlassView.macos.js
11
+ new file mode 100644
12
+ index 0000000..181ff73
13
+ --- /dev/null
14
+ +++ b/build/GlassView.macos.js
15
+ @@ -0,0 +1,3 @@
16
+ +// macOS uses the native glass views, like iOS.
17
+ +export * from './GlassView.ios';
18
+ +export { default } from './GlassView.ios';
19
+ diff --git a/build/isGlassEffectAPIAvailable.macos.js b/build/isGlassEffectAPIAvailable.macos.js
20
+ new file mode 100644
21
+ index 0000000..561ff57
22
+ --- /dev/null
23
+ +++ b/build/isGlassEffectAPIAvailable.macos.js
24
+ @@ -0,0 +1,2 @@
25
+ +// macOS uses the native glass views, like iOS.
26
+ +export * from './isGlassEffectAPIAvailable.ios';
27
+ diff --git a/build/isLiquidGlassAvailable.macos.js b/build/isLiquidGlassAvailable.macos.js
28
+ new file mode 100644
29
+ index 0000000..178f450
30
+ --- /dev/null
31
+ +++ b/build/isLiquidGlassAvailable.macos.js
32
+ @@ -0,0 +1,2 @@
33
+ +// macOS uses the native glass views, like iOS.
34
+ +export * from './isLiquidGlassAvailable.ios';
35
+ diff --git a/ios/ExpoGlassEffect.podspec b/ios/ExpoGlassEffect.podspec
36
+ index c05b50d..241f6b2 100644
37
+ --- a/ios/ExpoGlassEffect.podspec
38
+ +++ b/ios/ExpoGlassEffect.podspec
39
+ @@ -13,6 +13,7 @@ Pod::Spec.new do |s|
40
+ s.platforms = {
41
+ :ios => '15.1',
42
+ :tvos => '15.1',
43
+ + :osx => '14.0',
44
+ }
45
+ s.source = { git: 'https://github.com/expo/expo.git' }
46
+
47
+ diff --git a/ios/GlassContainer.swift b/ios/GlassContainer.swift
48
+ index 61fb67c..3866f84 100644
49
+ --- a/ios/GlassContainer.swift
50
+ +++ b/ios/GlassContainer.swift
51
+ @@ -1,5 +1,6 @@
52
+ // Copyright 2022-present 650 Industries. All rights reserved.
53
+
54
+ +#if !os(macOS)
55
+ import ExpoModulesCore
56
+
57
+ public final class GlassContainer: ExpoView {
58
+ @@ -54,3 +55,4 @@ public final class GlassContainer: ExpoView {
59
+ childComponentView.removeFromSuperview()
60
+ }
61
+ }
62
+ +#endif
63
+ diff --git a/ios/GlassEffectModule.swift b/ios/GlassEffectModule.swift
64
+ index e036302..2e47cfa 100644
65
+ --- a/ios/GlassEffectModule.swift
66
+ +++ b/ios/GlassEffectModule.swift
67
+ @@ -23,6 +23,9 @@ public final class GlassEffectModule: Module {
68
+ Constant("isGlassEffectAPIAvailable") {
69
+ #if compiler(>=6.2)
70
+ if #available(iOS 26.0, tvOS 26.0, macOS 26.0, *) {
71
+ + #if os(macOS)
72
+ + return NSClassFromString("NSGlassEffectView") != nil
73
+ + #endif
74
+ guard let glassEffectClass = NSClassFromString("UIGlassEffect") as? NSObject.Type else {
75
+ return false
76
+ }
77
+ diff --git a/ios/GlassStyle.swift b/ios/GlassStyle.swift
78
+ index bfd913c..239e7d2 100644
79
+ --- a/ios/GlassStyle.swift
80
+ +++ b/ios/GlassStyle.swift
81
+ @@ -1,12 +1,14 @@
82
+ import ExpoModulesCore
83
+ +#if !os(macOS)
84
+ import UIKit
85
+ +#endif
86
+
87
+ public enum GlassStyle: String, Enumerable {
88
+ case clear
89
+ case regular
90
+ case none
91
+
92
+ - #if compiler(>=6.2) // Xcode 26
93
+ + #if compiler(>=6.2) && !os(macOS) // Xcode 26
94
+ @available(iOS 26.0, tvOS 26.0, macOS 26.0, *)
95
+ func toUIGlassEffectStyle() -> UIGlassEffect.Style? {
96
+ switch self {
97
+ @@ -37,6 +39,18 @@ internal enum GlassColorScheme: String, Enumerable {
98
+ case light
99
+ case dark
100
+
101
+ + #if os(macOS)
102
+ + func toAppearance() -> NSAppearance? {
103
+ + switch self {
104
+ + case .auto:
105
+ + return nil
106
+ + case .light:
107
+ + return NSAppearance(named: .aqua)
108
+ + case .dark:
109
+ + return NSAppearance(named: .darkAqua)
110
+ + }
111
+ + }
112
+ + #else
113
+ func toUIUserInterfaceStyle() -> UIUserInterfaceStyle {
114
+ switch self {
115
+ case .auto:
116
+ @@ -47,4 +61,5 @@ internal enum GlassColorScheme: String, Enumerable {
117
+ return .dark
118
+ }
119
+ }
120
+ + #endif
121
+ }
122
+ diff --git a/ios/GlassView.swift b/ios/GlassView.swift
123
+ index 35cd8f3..23d9a01 100644
124
+ --- a/ios/GlassView.swift
125
+ +++ b/ios/GlassView.swift
126
+ @@ -1,5 +1,6 @@
127
+ // Copyright 2022-present 650 Industries. All rights reserved.
128
+
129
+ +#if !os(macOS)
130
+ import ExpoModulesCore
131
+ import React
132
+
133
+ @@ -279,3 +280,4 @@ public final class GlassView: ExpoView {
134
+ childComponentView.removeFromSuperview()
135
+ }
136
+ }
137
+ +#endif
138
+ diff --git a/ios/GlassViewMacOS.swift b/ios/GlassViewMacOS.swift
139
+ new file mode 100644
140
+ index 0000000..3e3816c
141
+ --- /dev/null
142
+ +++ b/ios/GlassViewMacOS.swift
143
+ @@ -0,0 +1,161 @@
144
+ +// macOS: NSGlassEffectView (macOS 26) hosts the children; earlier systems show them without glass.
145
+ +#if os(macOS)
146
+ +import ExpoModulesCore
147
+ +
148
+ +// React frames children from the top-left, so their container must be flipped.
149
+ +final class GlassContentView: NSView {
150
+ + override var isFlipped: Bool { true }
151
+ +}
152
+ +
153
+ +public final class GlassView: ExpoView {
154
+ + private let contentView = GlassContentView()
155
+ + private var glassView: NSView?
156
+ + private var glassStyle: GlassStyle = .regular
157
+ + private var glassTintColor: NSColor?
158
+ + private var radius: CGFloat?
159
+ + private var cornerRadii = [String: CGFloat]()
160
+ +
161
+ + public required init(appContext: AppContext? = nil) {
162
+ + super.init(appContext: appContext)
163
+ + contentView.autoresizingMask = [.width, .height]
164
+ + #if compiler(>=6.2)
165
+ + if #available(macOS 26.0, *) {
166
+ + let glass = NSGlassEffectView(frame: bounds)
167
+ + glass.autoresizingMask = [.width, .height]
168
+ + glass.contentView = contentView
169
+ + glassView = glass
170
+ + addSubview(glass)
171
+ + return
172
+ + }
173
+ + #endif
174
+ + addSubview(contentView)
175
+ + }
176
+ +
177
+ + // Children are framed by React; size the glass and its content to this view explicitly.
178
+ + public override func layoutSubviews() {
179
+ + super.layoutSubviews()
180
+ + glassView?.frame = bounds
181
+ + contentView.frame = glassView?.bounds ?? bounds
182
+ + }
183
+ +
184
+ + func setGlassStyle(_ config: GlassEffectStyleConfig) {
185
+ + setGlassStyle(config.style)
186
+ + }
187
+ +
188
+ + func setGlassStyle(_ style: GlassStyle) {
189
+ + glassStyle = style
190
+ + updateEffect()
191
+ + }
192
+ +
193
+ + func setTintColor(_ color: NSColor?) {
194
+ + glassTintColor = color
195
+ + updateEffect()
196
+ + }
197
+ +
198
+ + // AppKit glass has no interactive variant.
199
+ + func setInteractive(_ interactive: Bool) {}
200
+ +
201
+ + func setColorScheme(_ colorScheme: GlassColorScheme) {
202
+ + glassView?.appearance = colorScheme.toAppearance()
203
+ + }
204
+ +
205
+ + // NSGlassEffectView has one corner radius; per-corner radii use the largest given.
206
+ + func setBorderRadius(_ radius: CGFloat?) {
207
+ + self.radius = radius
208
+ + updateEffect()
209
+ + }
210
+ + func setBorderCurve(_: String?) {}
211
+ + func setBorderBottomLeftRadius(_ radius: CGFloat?) { setCornerRadius("bottomLeft", radius) }
212
+ + func setBorderBottomRightRadius(_ radius: CGFloat?) { setCornerRadius("bottomRight", radius) }
213
+ + func setBorderTopLeftRadius(_ radius: CGFloat?) { setCornerRadius("topLeft", radius) }
214
+ + func setBorderTopRightRadius(_ radius: CGFloat?) { setCornerRadius("topRight", radius) }
215
+ + func setBorderBottomStartRadius(_ radius: CGFloat?) { setCornerRadius("bottomStart", radius) }
216
+ + func setBorderBottomEndRadius(_ radius: CGFloat?) { setCornerRadius("bottomEnd", radius) }
217
+ + func setBorderTopStartRadius(_ radius: CGFloat?) { setCornerRadius("topStart", radius) }
218
+ + func setBorderTopEndRadius(_ radius: CGFloat?) { setCornerRadius("topEnd", radius) }
219
+ +
220
+ + private func setCornerRadius(_ corner: String, _ value: CGFloat?) {
221
+ + cornerRadii[corner] = value
222
+ + updateEffect()
223
+ + }
224
+ +
225
+ + private func updateEffect() {
226
+ + #if compiler(>=6.2)
227
+ + if #available(macOS 26.0, *), let glass = glassView as? NSGlassEffectView {
228
+ + // `none` keeps the children but drops the glass.
229
+ + if glassStyle == .none {
230
+ + glass.contentView = nil
231
+ + contentView.frame = bounds
232
+ + addSubview(contentView)
233
+ + } else if glass.contentView !== contentView {
234
+ + contentView.removeFromSuperview()
235
+ + glass.contentView = contentView
236
+ + }
237
+ + glass.isHidden = glassStyle == .none
238
+ + glass.style = glassStyle == .clear ? .clear : .regular
239
+ + glass.tintColor = glassTintColor
240
+ + glass.cornerRadius = radius ?? cornerRadii.values.max() ?? 0
241
+ + }
242
+ + #endif
243
+ + }
244
+ +
245
+ + public override func mountChildComponentView(_ childComponentView: UIView, index: Int) {
246
+ + if index < contentView.subviews.count {
247
+ + contentView.addSubview(childComponentView, positioned: .below, relativeTo: contentView.subviews[index])
248
+ + } else {
249
+ + contentView.addSubview(childComponentView)
250
+ + }
251
+ + }
252
+ +
253
+ + public override func unmountChildComponentView(_ childComponentView: UIView, index: Int) {
254
+ + childComponentView.removeFromSuperview()
255
+ + }
256
+ +}
257
+ +
258
+ +public final class GlassContainer: ExpoView {
259
+ + private let contentView = GlassContentView()
260
+ + private var containerView: NSView?
261
+ +
262
+ + public required init(appContext: AppContext? = nil) {
263
+ + super.init(appContext: appContext)
264
+ + contentView.autoresizingMask = [.width, .height]
265
+ + #if compiler(>=6.2)
266
+ + if #available(macOS 26.0, *) {
267
+ + let container = NSGlassEffectContainerView(frame: bounds)
268
+ + container.autoresizingMask = [.width, .height]
269
+ + container.contentView = contentView
270
+ + containerView = container
271
+ + addSubview(container)
272
+ + return
273
+ + }
274
+ + #endif
275
+ + addSubview(contentView)
276
+ + }
277
+ +
278
+ + public override func layoutSubviews() {
279
+ + super.layoutSubviews()
280
+ + containerView?.frame = bounds
281
+ + contentView.frame = bounds
282
+ + }
283
+ +
284
+ + func setSpacing(_ spacing: CGFloat?) {
285
+ + #if compiler(>=6.2)
286
+ + if #available(macOS 26.0, *), let container = containerView as? NSGlassEffectContainerView {
287
+ + container.spacing = spacing ?? 0
288
+ + }
289
+ + #endif
290
+ + }
291
+ +
292
+ + public override func mountChildComponentView(_ childComponentView: UIView, index: Int) {
293
+ + if index < contentView.subviews.count {
294
+ + contentView.addSubview(childComponentView, positioned: .below, relativeTo: contentView.subviews[index])
295
+ + } else {
296
+ + contentView.addSubview(childComponentView)
297
+ + }
298
+ + }
299
+ +
300
+ + public override func unmountChildComponentView(_ childComponentView: UIView, index: Int) {
301
+ + childComponentView.removeFromSuperview()
302
+ + }
303
+ +}
304
+ +#endif
@@ -0,0 +1,54 @@
1
+ diff --git a/ios/ExpoHaptics.podspec b/ios/ExpoHaptics.podspec
2
+ index a7f5bc7..93bb683 100644
3
+ --- a/ios/ExpoHaptics.podspec
4
+ +++ b/ios/ExpoHaptics.podspec
5
+ @@ -11,7 +11,8 @@ Pod::Spec.new do |s|
6
+ s.author = package['author']
7
+ s.homepage = package['homepage']
8
+ s.platforms = {
9
+ - :ios => '15.1'
10
+ + :ios => '15.1',
11
+ + :osx => '14.0'
12
+ }
13
+ s.swift_version = '5.9'
14
+ s.source = { git: 'https://github.com/expo/expo.git' }
15
+ diff --git a/ios/HapticsModule.swift b/ios/HapticsModule.swift
16
+ index 41659a0..e07500b 100644
17
+ --- a/ios/HapticsModule.swift
18
+ +++ b/ios/HapticsModule.swift
19
+ @@ -1,5 +1,30 @@
20
+ import ExpoModulesCore
21
+
22
+ +#if os(macOS)
23
+ +import AppKit
24
+ +
25
+ +// Macs give haptic feedback through Force Touch trackpads, while the user's finger rests on one.
26
+ +public class HapticsModule: Module {
27
+ + public func definition() -> ModuleDefinition {
28
+ + Name("ExpoHaptics")
29
+ +
30
+ + AsyncFunction("notificationAsync") { (_: String) in
31
+ + NSHapticFeedbackManager.defaultPerformer.perform(.levelChange, performanceTime: .now)
32
+ + }
33
+ + .runOnQueue(.main)
34
+ +
35
+ + AsyncFunction("impactAsync") { (_: String) in
36
+ + NSHapticFeedbackManager.defaultPerformer.perform(.generic, performanceTime: .now)
37
+ + }
38
+ + .runOnQueue(.main)
39
+ +
40
+ + AsyncFunction("selectionAsync") {
41
+ + NSHapticFeedbackManager.defaultPerformer.perform(.alignment, performanceTime: .now)
42
+ + }
43
+ + .runOnQueue(.main)
44
+ + }
45
+ +}
46
+ +#else
47
+ public class HapticsModule: Module {
48
+ public func definition() -> ModuleDefinition {
49
+ Name("ExpoHaptics")
50
+ @@ -66,3 +91,4 @@ public class HapticsModule: Module {
51
+ }
52
+ }
53
+ }
54
+ +#endif
@@ -0,0 +1,312 @@
1
+ diff --git a/ios/ExpoImageManipulator.podspec b/ios/ExpoImageManipulator.podspec
2
+ index ea6d6dc..5e9de70 100644
3
+ --- a/ios/ExpoImageManipulator.podspec
4
+ +++ b/ios/ExpoImageManipulator.podspec
5
+ @@ -12,7 +12,8 @@ Pod::Spec.new do |s|
6
+ s.homepage = package['homepage']
7
+ s.platforms = {
8
+ :ios => '15.1',
9
+ - :tvos => '15.1'
10
+ + :tvos => '15.1',
11
+ + :osx => '14.0'
12
+ }
13
+ s.swift_version = '5.9'
14
+ s.source = { git: 'https://github.com/expo/expo.git' }
15
+ diff --git a/ios/ImageManipulatorMacOS.swift b/ios/ImageManipulatorMacOS.swift
16
+ new file mode 100644
17
+ index 0000000..329b05c
18
+ --- /dev/null
19
+ +++ b/ios/ImageManipulatorMacOS.swift
20
+ @@ -0,0 +1,154 @@
21
+ +// Copyright 2024-present 650 Industries. All rights reserved.
22
+ +
23
+ +// macOS: NSImage stands in for UIImage (ExpoModulesCore aliases it), sized in pixels at scale 1.
24
+ +#if os(macOS)
25
+ +import AppKit
26
+ +import ImageIO
27
+ +
28
+ +// Files that don't import ExpoModulesCore don't see its UIImage alias.
29
+ +typealias UIImage = NSImage
30
+ +
31
+ +extension NSImage {
32
+ + // Decoded images are already oriented up, so only `.up` occurs.
33
+ + enum Orientation {
34
+ + case up, down, left, right, upMirrored, downMirrored, leftMirrored, rightMirrored
35
+ + }
36
+ +
37
+ + var imageOrientation: Orientation { .up }
38
+ + var scale: CGFloat { 1 }
39
+ + var cgImage: CGImage? { cgImage(forProposedRect: nil, context: nil, hints: nil) }
40
+ +
41
+ + convenience init(cgImage: CGImage) {
42
+ + self.init(cgImage: cgImage, size: NSSize(width: cgImage.width, height: cgImage.height))
43
+ + }
44
+ +
45
+ + convenience init(cgImage: CGImage, scale: CGFloat, orientation: Orientation) {
46
+ + self.init(cgImage: cgImage)
47
+ + }
48
+ +
49
+ + func jpegData(compressionQuality: CGFloat) -> Data? {
50
+ + cgImage.flatMap { NSBitmapImageRep(cgImage: $0).representation(using: .jpeg, properties: [.compressionFactor: compressionQuality]) }
51
+ + }
52
+ +
53
+ + func pngData() -> Data? {
54
+ + cgImage.flatMap { NSBitmapImageRep(cgImage: $0).representation(using: .png, properties: [:]) }
55
+ + }
56
+ +}
57
+ +
58
+ +// Applies EXIF orientation while decoding, as UIImage(data:) does on iOS.
59
+ +internal func decodeImage(_ data: Data) -> NSImage? {
60
+ + guard let source = CGImageSourceCreateWithData(data as CFData, nil),
61
+ + let properties = CGImageSourceCopyPropertiesAtIndex(source, 0, nil) as? [CFString: Any],
62
+ + let width = properties[kCGImagePropertyPixelWidth] as? Int,
63
+ + let height = properties[kCGImagePropertyPixelHeight] as? Int else {
64
+ + return nil
65
+ + }
66
+ + let options: [CFString: Any] = [
67
+ + kCGImageSourceCreateThumbnailFromImageAlways: true,
68
+ + kCGImageSourceCreateThumbnailWithTransform: true,
69
+ + kCGImageSourceThumbnailMaxPixelSize: max(width, height)
70
+ + ]
71
+ + return CGImageSourceCreateThumbnailAtIndex(source, 0, options as CFDictionary).map { NSImage(cgImage: $0) }
72
+ +}
73
+ +
74
+ +internal func loadImageFromPhotoLibrary(url: URL) async throws -> NSImage {
75
+ + throw ImageNotFoundException()
76
+ +}
77
+ +
78
+ +// Spark's host exports SparkNamespace(); look it up at runtime so this keeps no link dependency on Spark.
79
+ +internal let appNamespace: String = {
80
+ + typealias Namespace = @convention(c) () -> Unmanaged<NSString>
81
+ + if let symbol = dlsym(UnsafeMutableRawPointer(bitPattern: -2), "SparkNamespace") {
82
+ + return unsafeBitCast(symbol, to: Namespace.self)().takeUnretainedValue() as String
83
+ + }
84
+ + return Bundle.main.bundleIdentifier ?? ProcessInfo.processInfo.processName
85
+ +}()
86
+ +
87
+ +// A bitmap context in CoreGraphics' own orientation: origin bottom-left, so CGImages draw upright.
88
+ +private func render(size: CGSize, drawing: (CGContext) -> Void) -> NSImage? {
89
+ + guard let context = CGContext(
90
+ + data: nil,
91
+ + width: Int(size.width),
92
+ + height: Int(size.height),
93
+ + bitsPerComponent: 8,
94
+ + bytesPerRow: 0,
95
+ + space: CGColorSpaceCreateDeviceRGB(),
96
+ + bitmapInfo: CGImageAlphaInfo.premultipliedLast.rawValue
97
+ + ) else {
98
+ + return nil
99
+ + }
100
+ + drawing(context)
101
+ + return context.makeImage().map { NSImage(cgImage: $0) }
102
+ +}
103
+ +
104
+ +extension ImageFlipTransformer {
105
+ + func transform(image: NSImage) async throws -> NSImage {
106
+ + guard let cgImage = image.cgImage else {
107
+ + throw ImageNotFoundException()
108
+ + }
109
+ + let size = CGSize(width: cgImage.width, height: cgImage.height)
110
+ + let flipped = render(size: size) { context in
111
+ + switch flip {
112
+ + case .vertical:
113
+ + context.concatenate(CGAffineTransform(a: 1, b: 0, c: 0, d: -1, tx: 0, ty: size.height))
114
+ + case .horizontal:
115
+ + context.concatenate(CGAffineTransform(a: -1, b: 0, c: 0, d: 1, tx: size.width, ty: 0))
116
+ + }
117
+ + context.draw(cgImage, in: CGRect(origin: .zero, size: size))
118
+ + }
119
+ + guard let flipped else {
120
+ + throw ImageDrawingFailedException()
121
+ + }
122
+ + return flipped
123
+ + }
124
+ +}
125
+ +
126
+ +extension ImageRotateTransformer {
127
+ + func transform(image: NSImage) async throws -> NSImage {
128
+ + guard let cgImage = image.cgImage else {
129
+ + throw ImageNotFoundException()
130
+ + }
131
+ + let rads = rotate * .pi / 180
132
+ + let size = CGSize(width: cgImage.width, height: cgImage.height)
133
+ + let bounds = CGRect(origin: .zero, size: size).applying(CGAffineTransform(rotationAngle: rads))
134
+ + let rotatedSize = CGSize(width: bounds.width.rounded(.down), height: bounds.height.rounded(.down))
135
+ + let rotated = render(size: rotatedSize) { context in
136
+ + context.translateBy(x: rotatedSize.width / 2, y: rotatedSize.height / 2)
137
+ + // Positive angles turn clockwise, as on iOS; CoreGraphics turns counterclockwise.
138
+ + context.rotate(by: -rads)
139
+ + context.draw(cgImage, in: CGRect(origin: CGPoint(x: -size.width / 2, y: -size.height / 2), size: size))
140
+ + }
141
+ + guard let rotated else {
142
+ + throw ImageDrawingFailedException()
143
+ + }
144
+ + return rotated
145
+ + }
146
+ +}
147
+ +
148
+ +extension ImageResizeTransformer {
149
+ + func transform(image: NSImage) async throws -> NSImage {
150
+ + guard let cgImage = image.cgImage else {
151
+ + throw ImageNotFoundException()
152
+ + }
153
+ + let imageRatio = CGFloat(cgImage.width) / CGFloat(cgImage.height)
154
+ + var targetSize = CGSize.zero
155
+ +
156
+ + if let width = options.width {
157
+ + targetSize.width = width
158
+ + targetSize.height = width / imageRatio
159
+ + }
160
+ + if let height = options.height {
161
+ + targetSize.height = height
162
+ + targetSize.width = targetSize.width == 0 ? imageRatio * targetSize.height : targetSize.width
163
+ + }
164
+ + let resized = render(size: targetSize) { context in
165
+ + context.interpolationQuality = .high
166
+ + context.draw(cgImage, in: CGRect(origin: .zero, size: targetSize))
167
+ + }
168
+ + guard let resized else {
169
+ + throw ImageDrawingFailedException()
170
+ + }
171
+ + return resized
172
+ + }
173
+ +}
174
+ +#endif
175
+ diff --git a/ios/ImageManipulatorModule.swift b/ios/ImageManipulatorModule.swift
176
+ index 1f8c73a..ca0588c 100644
177
+ --- a/ios/ImageManipulatorModule.swift
178
+ +++ b/ios/ImageManipulatorModule.swift
179
+ @@ -2,7 +2,9 @@
180
+
181
+ import CoreGraphics
182
+ import Photos
183
+ +#if !os(macOS)
184
+ import UIKit
185
+ +#endif
186
+ import ExpoModulesCore
187
+ internal import SDWebImageWebPCoder
188
+
189
+ diff --git a/ios/ImageManipulatorUtils.swift b/ios/ImageManipulatorUtils.swift
190
+ index 13739d5..b5d1d92 100644
191
+ --- a/ios/ImageManipulatorUtils.swift
192
+ +++ b/ios/ImageManipulatorUtils.swift
193
+ @@ -9,7 +9,7 @@ internal typealias SaveImageResult = (url: URL, data: Data)
194
+ */
195
+ internal func loadImage(atUrl url: URL, appContext: AppContext) async throws -> UIImage {
196
+ if url.scheme == "data" {
197
+ - guard let data = try? Data(contentsOf: url), let image = UIImage(data: data) else {
198
+ + guard let data = try? Data(contentsOf: url), let image = decodeImage(data) else {
199
+ throw CorruptedImageDataException()
200
+ }
201
+ return image
202
+ @@ -35,12 +35,17 @@ internal func loadImage(atUrl url: URL, appContext: AppContext) async throws ->
203
+ }
204
+
205
+ // Read local files directly so UIKit preserves HEIC/EXIF orientation metadata.
206
+ - guard let data = try? Data(contentsOf: url), let image = UIImage(data: data) else {
207
+ + guard let data = try? Data(contentsOf: url), let image = decodeImage(data) else {
208
+ throw FileSystemReadPermissionException(url.absoluteString)
209
+ }
210
+ return image
211
+ }
212
+
213
+ +#if !os(macOS)
214
+ +internal func decodeImage(_ data: Data) -> UIImage? {
215
+ + return UIImage(data: data)
216
+ +}
217
+ +
218
+ /**
219
+ Loads the image from user's photo library.
220
+ */
221
+ @@ -67,6 +72,8 @@ internal func loadImageFromPhotoLibrary(url: URL) async throws -> UIImage {
222
+ }
223
+ }
224
+
225
+ +#endif
226
+ +
227
+ /**
228
+ Returns pixel data representation of the image.
229
+ */
230
+ @@ -81,6 +88,7 @@ func imageData(from image: UIImage, format: ImageFormat, compression: Double) ->
231
+ }
232
+ }
233
+
234
+ +#if !os(macOS)
235
+ /**
236
+ Checks if we are dealing with a ph asset URL and uses the correct method to fetch it.
237
+ */
238
+ @@ -106,6 +114,7 @@ internal func drawInNewContext(size: CGSize, drawing: (UIGraphicsImageRendererCo
239
+ drawing(context)
240
+ }
241
+ }
242
+ +#endif
243
+
244
+ /**
245
+ Saves the image as a file.
246
+ @@ -115,7 +124,12 @@ internal func saveImage(_ image: UIImage, options: ManipulateOptions, appContext
247
+ throw FileSystemNotFoundException()
248
+ }
249
+
250
+ + #if os(macOS)
251
+ + // macOS shares the user's Caches folder between apps, so each app gets its own subfolder.
252
+ + let directory = URL(fileURLWithPath: cachesDirectory.path).appendingPathComponent(appNamespace).appendingPathComponent("ImageManipulator")
253
+ + #else
254
+ let directory = URL(fileURLWithPath: cachesDirectory.path).appendingPathComponent("ImageManipulator")
255
+ + #endif
256
+ let filename = UUID().uuidString.appending(options.format.fileExtension)
257
+ let fileUrl = directory.appendingPathComponent(filename)
258
+
259
+ diff --git a/ios/Transformers/ImageFlipTransformer.swift b/ios/Transformers/ImageFlipTransformer.swift
260
+ index 2272c13..a64a3a8 100644
261
+ --- a/ios/Transformers/ImageFlipTransformer.swift
262
+ +++ b/ios/Transformers/ImageFlipTransformer.swift
263
+ @@ -6,6 +6,7 @@
264
+ internal struct ImageFlipTransformer: ImageTransformer {
265
+ let flip: FlipType
266
+
267
+ +#if !os(macOS)
268
+ @MainActor
269
+ func transform(image: UIImage) async -> UIImage {
270
+ let imageView = UIImageView(image: image)
271
+ @@ -22,4 +23,5 @@ internal struct ImageFlipTransformer: ImageTransformer {
272
+ imageView.layer.render(in: context.cgContext)
273
+ }
274
+ }
275
+ +#endif
276
+ }
277
+ diff --git a/ios/Transformers/ImageResizeTransformer.swift b/ios/Transformers/ImageResizeTransformer.swift
278
+ index e3ef679..1b578a4 100644
279
+ --- a/ios/Transformers/ImageResizeTransformer.swift
280
+ +++ b/ios/Transformers/ImageResizeTransformer.swift
281
+ @@ -6,6 +6,7 @@
282
+ internal struct ImageResizeTransformer: ImageTransformer {
283
+ let options: ResizeOptions
284
+
285
+ +#if !os(macOS)
286
+ func transform(image: UIImage) async -> UIImage {
287
+ let imageWidth = image.size.width
288
+ let imageHeight = image.size.height
289
+ @@ -31,4 +32,5 @@ internal struct ImageResizeTransformer: ImageTransformer {
290
+ image.draw(in: CGRect(origin: .zero, size: targetSize))
291
+ }
292
+ }
293
+ +#endif
294
+ }
295
+ diff --git a/ios/Transformers/ImageRotateTransformer.swift b/ios/Transformers/ImageRotateTransformer.swift
296
+ index 66aa5cb..158eaf0 100644
297
+ --- a/ios/Transformers/ImageRotateTransformer.swift
298
+ +++ b/ios/Transformers/ImageRotateTransformer.swift
299
+ @@ -6,6 +6,7 @@
300
+ internal struct ImageRotateTransformer: ImageTransformer {
301
+ let rotate: Double
302
+
303
+ +#if !os(macOS)
304
+ @MainActor
305
+ func transform(image: UIImage) async throws -> UIImage {
306
+ guard let cgImage = image.cgImage else {
307
+ @@ -27,4 +28,5 @@ internal struct ImageRotateTransformer: ImageTransformer {
308
+ cgContext.draw(cgImage, in: CGRect(origin: origin, size: image.size))
309
+ }
310
+ }
311
+ +#endif
312
+ }