@thelacanians/vue-native-cli 0.4.15 → 0.6.0
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/cli.js +329 -15
- package/native/android/VueNativeCore/src/main/kotlin/com/vuenative/core/Bridge/NativeBridge.kt +118 -0
- package/native/android/VueNativeCore/src/main/kotlin/com/vuenative/core/Components/Factories/VViewFactory.kt +178 -1
- package/native/android/VueNativeCore/src/main/kotlin/com/vuenative/core/Modules/GeneratedModuleRegistry.kt +28 -0
- package/native/android/VueNativeCore/src/main/kotlin/com/vuenative/core/Modules/NativeModuleRegistry.kt +3 -0
- package/native/android/VueNativeCore/src/test/kotlin/com/vuenative/core/ComponentFactoryTest.kt +674 -0
- package/native/android/VueNativeCore/src/test/kotlin/com/vuenative/core/ErrorOverlayViewTest.kt +183 -0
- package/native/android/VueNativeCore/src/test/kotlin/com/vuenative/core/EventThrottleTest.kt +203 -0
- package/native/android/VueNativeCore/src/test/kotlin/com/vuenative/core/HotReloadManagerTest.kt +162 -0
- package/native/android/VueNativeCore/src/test/kotlin/com/vuenative/core/JSPolyfillsTest.kt +153 -0
- package/native/android/VueNativeCore/src/test/kotlin/com/vuenative/core/NativeBridgeTest.kt +6 -3
- package/native/android/VueNativeCore/src/test/kotlin/com/vuenative/core/NativeModuleTest.kt +475 -0
- package/native/android/gradle.properties +1 -0
- package/native/android/gradlew +1 -1
- package/native/ios/VueNativeCore/Package.swift +1 -1
- package/native/ios/VueNativeCore/Sources/VueNativeCore/Bridge/EventThrottle.swift +1 -0
- package/native/ios/VueNativeCore/Sources/VueNativeCore/Bridge/NativeBridge.swift +143 -5
- package/native/ios/VueNativeCore/Sources/VueNativeCore/Components/Factories/VTextFactory.swift +43 -0
- package/native/ios/VueNativeCore/Sources/VueNativeCore/Components/Factories/VViewFactory.swift +116 -4
- package/native/ios/VueNativeCore/Sources/VueNativeCore/Helpers/GestureWrapper.swift +100 -0
- package/native/ios/VueNativeCore/Sources/VueNativeCore/Modules/GeneratedModuleRegistry.swift +28 -0
- package/native/ios/VueNativeCore/Sources/VueNativeCore/Modules/NativeModuleRegistry.swift +3 -0
- package/native/ios/VueNativeCore/Tests/VueNativeCoreTests/CertificatePinningTests.swift +190 -0
- package/native/ios/VueNativeCore/Tests/VueNativeCoreTests/ComponentFactoryTests.swift +585 -0
- package/native/ios/VueNativeCore/Tests/VueNativeCoreTests/EventThrottleTests.swift +161 -0
- package/native/ios/VueNativeCore/Tests/VueNativeCoreTests/HotReloadManagerTests.swift +88 -0
- package/native/ios/VueNativeCore/Tests/VueNativeCoreTests/JSPolyfillsTests.swift +319 -0
- package/native/ios/VueNativeCore/Tests/VueNativeCoreTests/NativeModuleTests.swift +400 -0
- package/native/macos/VueNativeMacOS/Package.swift +34 -0
- package/native/macos/VueNativeMacOS/Sources/VueNativeMacOS/Bridge/ErrorOverlayView.swift +112 -0
- package/native/macos/VueNativeMacOS/Sources/VueNativeMacOS/Bridge/EventThrottle.swift +58 -0
- package/native/macos/VueNativeMacOS/Sources/VueNativeMacOS/Bridge/HotReloadManager.swift +153 -0
- package/native/macos/VueNativeMacOS/Sources/VueNativeMacOS/Bridge/JSPolyfills.swift +696 -0
- package/native/macos/VueNativeMacOS/Sources/VueNativeMacOS/Bridge/JSRuntime.swift +347 -0
- package/native/macos/VueNativeMacOS/Sources/VueNativeMacOS/Bridge/NativeBridge.swift +877 -0
- package/native/macos/VueNativeMacOS/Sources/VueNativeMacOS/Bridge/VueNativeWindowController.swift +125 -0
- package/native/macos/VueNativeMacOS/Sources/VueNativeMacOS/Components/ComponentRegistry.swift +209 -0
- package/native/macos/VueNativeMacOS/Sources/VueNativeMacOS/Components/Factories/VActionSheetFactory.swift +155 -0
- package/native/macos/VueNativeMacOS/Sources/VueNativeMacOS/Components/Factories/VActivityIndicatorFactory.swift +85 -0
- package/native/macos/VueNativeMacOS/Sources/VueNativeMacOS/Components/Factories/VAlertDialogFactory.swift +132 -0
- package/native/macos/VueNativeMacOS/Sources/VueNativeMacOS/Components/Factories/VButtonFactory.swift +83 -0
- package/native/macos/VueNativeMacOS/Sources/VueNativeMacOS/Components/Factories/VCheckboxFactory.swift +108 -0
- package/native/macos/VueNativeMacOS/Sources/VueNativeMacOS/Components/Factories/VDropdownFactory.swift +155 -0
- package/native/macos/VueNativeMacOS/Sources/VueNativeMacOS/Components/Factories/VImageFactory.swift +270 -0
- package/native/macos/VueNativeMacOS/Sources/VueNativeMacOS/Components/Factories/VInputFactory.swift +257 -0
- package/native/macos/VueNativeMacOS/Sources/VueNativeMacOS/Components/Factories/VKeyboardAvoidingFactory.swift +22 -0
- package/native/macos/VueNativeMacOS/Sources/VueNativeMacOS/Components/Factories/VListFactory.swift +324 -0
- package/native/macos/VueNativeMacOS/Sources/VueNativeMacOS/Components/Factories/VModalFactory.swift +231 -0
- package/native/macos/VueNativeMacOS/Sources/VueNativeMacOS/Components/Factories/VOutlineViewFactory.swift +276 -0
- package/native/macos/VueNativeMacOS/Sources/VueNativeMacOS/Components/Factories/VPickerFactory.swift +134 -0
- package/native/macos/VueNativeMacOS/Sources/VueNativeMacOS/Components/Factories/VPressableFactory.swift +120 -0
- package/native/macos/VueNativeMacOS/Sources/VueNativeMacOS/Components/Factories/VProgressBarFactory.swift +71 -0
- package/native/macos/VueNativeMacOS/Sources/VueNativeMacOS/Components/Factories/VRadioFactory.swift +193 -0
- package/native/macos/VueNativeMacOS/Sources/VueNativeMacOS/Components/Factories/VRefreshControlFactory.swift +25 -0
- package/native/macos/VueNativeMacOS/Sources/VueNativeMacOS/Components/Factories/VSafeAreaFactory.swift +46 -0
- package/native/macos/VueNativeMacOS/Sources/VueNativeMacOS/Components/Factories/VScrollViewFactory.swift +190 -0
- package/native/macos/VueNativeMacOS/Sources/VueNativeMacOS/Components/Factories/VSectionListFactory.swift +374 -0
- package/native/macos/VueNativeMacOS/Sources/VueNativeMacOS/Components/Factories/VSegmentedControlFactory.swift +125 -0
- package/native/macos/VueNativeMacOS/Sources/VueNativeMacOS/Components/Factories/VSliderFactory.swift +131 -0
- package/native/macos/VueNativeMacOS/Sources/VueNativeMacOS/Components/Factories/VSplitViewFactory.swift +215 -0
- package/native/macos/VueNativeMacOS/Sources/VueNativeMacOS/Components/Factories/VStatusBarFactory.swift +25 -0
- package/native/macos/VueNativeMacOS/Sources/VueNativeMacOS/Components/Factories/VSwitchFactory.swift +92 -0
- package/native/macos/VueNativeMacOS/Sources/VueNativeMacOS/Components/Factories/VTextFactory.swift +336 -0
- package/native/macos/VueNativeMacOS/Sources/VueNativeMacOS/Components/Factories/VToolbarFactory.swift +212 -0
- package/native/macos/VueNativeMacOS/Sources/VueNativeMacOS/Components/Factories/VVideoFactory.swift +245 -0
- package/native/macos/VueNativeMacOS/Sources/VueNativeMacOS/Components/Factories/VViewFactory.swift +314 -0
- package/native/macos/VueNativeMacOS/Sources/VueNativeMacOS/Components/Factories/VWebViewFactory.swift +162 -0
- package/native/macos/VueNativeMacOS/Sources/VueNativeMacOS/Components/NativeComponentFactory.swift +54 -0
- package/native/macos/VueNativeMacOS/Sources/VueNativeMacOS/Helpers/ClickableView.swift +100 -0
- package/native/macos/VueNativeMacOS/Sources/VueNativeMacOS/Helpers/Extensions.swift +23 -0
- package/native/macos/VueNativeMacOS/Sources/VueNativeMacOS/Helpers/GestureWrapper.swift +183 -0
- package/native/macos/VueNativeMacOS/Sources/VueNativeMacOS/Helpers/NSColor+Hex.swift +78 -0
- package/native/macos/VueNativeMacOS/Sources/VueNativeMacOS/Layout/FlippedView.swift +19 -0
- package/native/macos/VueNativeMacOS/Sources/VueNativeMacOS/Layout/LayoutNode.swift +493 -0
- package/native/macos/VueNativeMacOS/Sources/VueNativeMacOS/Modules/AnimationModule.swift +354 -0
- package/native/macos/VueNativeMacOS/Sources/VueNativeMacOS/Modules/AppStateModule.swift +62 -0
- package/native/macos/VueNativeMacOS/Sources/VueNativeMacOS/Modules/BiometryModule.swift +60 -0
- package/native/macos/VueNativeMacOS/Sources/VueNativeMacOS/Modules/CameraModule.swift +167 -0
- package/native/macos/VueNativeMacOS/Sources/VueNativeMacOS/Modules/ClipboardModule.swift +34 -0
- package/native/macos/VueNativeMacOS/Sources/VueNativeMacOS/Modules/DeviceInfoModule.swift +49 -0
- package/native/macos/VueNativeMacOS/Sources/VueNativeMacOS/Modules/DragDropModule.swift +50 -0
- package/native/macos/VueNativeMacOS/Sources/VueNativeMacOS/Modules/FileDialogModule.swift +86 -0
- package/native/macos/VueNativeMacOS/Sources/VueNativeMacOS/Modules/HapticsModule.swift +42 -0
- package/native/macos/VueNativeMacOS/Sources/VueNativeMacOS/Modules/KeyboardModule.swift +28 -0
- package/native/macos/VueNativeMacOS/Sources/VueNativeMacOS/Modules/LinkingModule.swift +49 -0
- package/native/macos/VueNativeMacOS/Sources/VueNativeMacOS/Modules/MenuModule.swift +95 -0
- package/native/macos/VueNativeMacOS/Sources/VueNativeMacOS/Modules/NativeModuleRegistry.swift +63 -0
- package/native/macos/VueNativeMacOS/Sources/VueNativeMacOS/Modules/NotificationsModule.swift +112 -0
- package/native/macos/VueNativeMacOS/Sources/VueNativeMacOS/Modules/PermissionsModule.swift +149 -0
- package/native/macos/VueNativeMacOS/Sources/VueNativeMacOS/Modules/ShareModule.swift +37 -0
- package/native/macos/VueNativeMacOS/Sources/VueNativeMacOS/Modules/WindowModule.swift +71 -0
- package/native/macos/VueNativeMacOS/Sources/VueNativeMacOS/Resources/vue-native-placeholder.js +2 -0
- package/native/macos/VueNativeMacOS/Sources/VueNativeMacOS/Styling/StyleEngine.swift +885 -0
- package/native/macos/VueNativeMacOS/Tests/VueNativeMacOSTests/ComponentFactoryTests.swift +80 -0
- package/native/macos/VueNativeMacOS/Tests/VueNativeMacOSTests/VueNativeMacOSTests.swift +149 -0
- package/native/shared/VueNativeShared/AGENTS.md +129 -0
- package/native/shared/VueNativeShared/Package.swift +14 -0
- package/native/shared/VueNativeShared/Sources/VueNativeShared/CertificatePinning.swift +134 -0
- package/native/shared/VueNativeShared/Sources/VueNativeShared/EventThrottle.swift +78 -0
- package/native/shared/VueNativeShared/Sources/VueNativeShared/HotReloadManager.swift +162 -0
- package/native/shared/VueNativeShared/Sources/VueNativeShared/JSRuntime.swift +412 -0
- package/native/shared/VueNativeShared/Sources/VueNativeShared/Modules/AsyncStorageModule.swift +68 -0
- package/native/shared/VueNativeShared/Sources/VueNativeShared/Modules/AudioModule.swift +359 -0
- package/native/shared/VueNativeShared/Sources/VueNativeShared/Modules/DatabaseModule.swift +259 -0
- package/native/shared/VueNativeShared/Sources/VueNativeShared/Modules/FileSystemModule.swift +233 -0
- package/native/shared/VueNativeShared/Sources/VueNativeShared/Modules/GeolocationModule.swift +156 -0
- package/native/shared/VueNativeShared/Sources/VueNativeShared/Modules/NetworkModule.swift +59 -0
- package/native/shared/VueNativeShared/Sources/VueNativeShared/Modules/PerformanceModule.swift +113 -0
- package/native/shared/VueNativeShared/Sources/VueNativeShared/Modules/SecureStorageModule.swift +119 -0
- package/native/shared/VueNativeShared/Sources/VueNativeShared/Modules/WebSocketModule.swift +212 -0
- package/native/shared/VueNativeShared/Sources/VueNativeShared/NativeEventDispatcher.swift +6 -0
- package/native/shared/VueNativeShared/Sources/VueNativeShared/NativeModule.swift +26 -0
- package/native/shared/VueNativeShared/Sources/VueNativeShared/NativeModuleRegistry.swift +37 -0
- package/native/shared/VueNativeShared/Sources/VueNativeShared/SharedJSPolyfills.swift +673 -0
- package/native/shared/VueNativeShared/Tests/VueNativeSharedTests/VueNativeSharedTests.swift +44 -0
- package/package.json +8 -2
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
import AppKit
|
|
2
|
+
|
|
3
|
+
/// ObjC-compatible wrapper for gesture recognizer action handlers.
|
|
4
|
+
/// Allows attaching Swift closure-based event handlers to NSGestureRecognizers
|
|
5
|
+
/// that require an @objc selector target.
|
|
6
|
+
@objc final class ClickGestureWrapper: NSObject {
|
|
7
|
+
|
|
8
|
+
private let handler: (Any?) -> Void
|
|
9
|
+
|
|
10
|
+
init(handler: @escaping (Any?) -> Void) {
|
|
11
|
+
self.handler = handler
|
|
12
|
+
super.init()
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
@objc func handleGesture(_ gesture: NSGestureRecognizer) {
|
|
16
|
+
handler(nil)
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
@objc func handleGestureWithState(_ gesture: NSGestureRecognizer) {
|
|
20
|
+
guard let view = gesture.view else {
|
|
21
|
+
handler(nil)
|
|
22
|
+
return
|
|
23
|
+
}
|
|
24
|
+
let location = gesture.location(in: view)
|
|
25
|
+
let payload: [String: Any] = [
|
|
26
|
+
"locationX": location.x,
|
|
27
|
+
"locationY": location.y
|
|
28
|
+
]
|
|
29
|
+
handler(payload)
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// MARK: - PanGestureWrapper
|
|
34
|
+
|
|
35
|
+
/// ObjC-compatible wrapper for NSPanGestureRecognizer action handlers.
|
|
36
|
+
@objc final class PanGestureWrapper: NSObject {
|
|
37
|
+
private let handler: (Any?) -> Void
|
|
38
|
+
|
|
39
|
+
init(handler: @escaping (Any?) -> Void) {
|
|
40
|
+
self.handler = handler
|
|
41
|
+
super.init()
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
@objc func handle(_ recognizer: NSPanGestureRecognizer) {
|
|
45
|
+
guard let view = recognizer.view else { return }
|
|
46
|
+
let translation = recognizer.translation(in: view.superview)
|
|
47
|
+
let velocity = recognizer.velocity(in: view.superview)
|
|
48
|
+
let stateStr: String
|
|
49
|
+
switch recognizer.state {
|
|
50
|
+
case .began: stateStr = "began"
|
|
51
|
+
case .changed: stateStr = "changed"
|
|
52
|
+
case .ended: stateStr = "ended"
|
|
53
|
+
case .cancelled, .failed: stateStr = "cancelled"
|
|
54
|
+
default: stateStr = "unknown"
|
|
55
|
+
}
|
|
56
|
+
handler([
|
|
57
|
+
"translationX": translation.x,
|
|
58
|
+
"translationY": translation.y,
|
|
59
|
+
"velocityX": velocity.x,
|
|
60
|
+
"velocityY": velocity.y,
|
|
61
|
+
"state": stateStr
|
|
62
|
+
] as [String: Any])
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// MARK: - MagnificationGestureWrapper
|
|
67
|
+
|
|
68
|
+
/// ObjC-compatible wrapper for NSMagnificationGestureRecognizer action handlers.
|
|
69
|
+
/// macOS equivalent of iOS PinchWrapper.
|
|
70
|
+
@objc final class MagnificationGestureWrapper: NSObject {
|
|
71
|
+
private let handler: (Any?) -> Void
|
|
72
|
+
|
|
73
|
+
init(handler: @escaping (Any?) -> Void) {
|
|
74
|
+
self.handler = handler
|
|
75
|
+
super.init()
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
@objc func handle(_ recognizer: NSMagnificationGestureRecognizer) {
|
|
79
|
+
let stateStr: String
|
|
80
|
+
switch recognizer.state {
|
|
81
|
+
case .began: stateStr = "began"
|
|
82
|
+
case .changed: stateStr = "changed"
|
|
83
|
+
case .ended: stateStr = "ended"
|
|
84
|
+
default: stateStr = "cancelled"
|
|
85
|
+
}
|
|
86
|
+
// Magnification is relative (0 = no change), convert to scale (1 = no change)
|
|
87
|
+
// to match iOS pinch gesture API
|
|
88
|
+
handler([
|
|
89
|
+
"scale": 1.0 + recognizer.magnification,
|
|
90
|
+
"state": stateStr
|
|
91
|
+
] as [String: Any])
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// MARK: - RotationGestureWrapper
|
|
96
|
+
|
|
97
|
+
/// ObjC-compatible wrapper for NSRotationGestureRecognizer action handlers.
|
|
98
|
+
@objc final class RotationGestureWrapper: NSObject {
|
|
99
|
+
private let handler: (Any?) -> Void
|
|
100
|
+
|
|
101
|
+
init(handler: @escaping (Any?) -> Void) {
|
|
102
|
+
self.handler = handler
|
|
103
|
+
super.init()
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
@objc func handle(_ recognizer: NSRotationGestureRecognizer) {
|
|
107
|
+
let stateStr: String
|
|
108
|
+
switch recognizer.state {
|
|
109
|
+
case .began: stateStr = "began"
|
|
110
|
+
case .changed: stateStr = "changed"
|
|
111
|
+
case .ended: stateStr = "ended"
|
|
112
|
+
default: stateStr = "cancelled"
|
|
113
|
+
}
|
|
114
|
+
handler([
|
|
115
|
+
"rotation": recognizer.rotation,
|
|
116
|
+
"state": stateStr
|
|
117
|
+
] as [String: Any])
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// MARK: - DoubleClickWrapper
|
|
122
|
+
|
|
123
|
+
/// ObjC-compatible wrapper for double-click gesture handlers.
|
|
124
|
+
@objc final class DoubleClickWrapper: NSObject {
|
|
125
|
+
private let handler: (Any?) -> Void
|
|
126
|
+
|
|
127
|
+
init(handler: @escaping (Any?) -> Void) {
|
|
128
|
+
self.handler = handler
|
|
129
|
+
super.init()
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
@objc func handleGesture(_ gesture: NSClickGestureRecognizer) {
|
|
133
|
+
let location = gesture.location(in: gesture.view)
|
|
134
|
+
let payload: [String: Any] = [
|
|
135
|
+
"locationX": location.x,
|
|
136
|
+
"locationY": location.y
|
|
137
|
+
]
|
|
138
|
+
handler(payload)
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// MARK: - HoverWrapper
|
|
143
|
+
|
|
144
|
+
/// Wrapper for hover gesture handlers (tracking area based).
|
|
145
|
+
@objc final class HoverWrapper: NSObject {
|
|
146
|
+
private let handler: (Any?) -> Void
|
|
147
|
+
|
|
148
|
+
init(handler: @escaping (Any?) -> Void) {
|
|
149
|
+
self.handler = handler
|
|
150
|
+
super.init()
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
func handleHover(location: NSPoint, isEntering: Bool) {
|
|
154
|
+
let payload: [String: Any] = [
|
|
155
|
+
"locationX": location.x,
|
|
156
|
+
"locationY": location.y,
|
|
157
|
+
"state": isEntering ? "entered" : "exited"
|
|
158
|
+
]
|
|
159
|
+
handler(payload)
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
// MARK: - PressureWrapper
|
|
164
|
+
|
|
165
|
+
/// Wrapper for pressure/force gesture handlers (Force Touch on macOS).
|
|
166
|
+
@objc final class PressureWrapper: NSObject {
|
|
167
|
+
private let handler: (Any?) -> Void
|
|
168
|
+
|
|
169
|
+
init(handler: @escaping (Any?) -> Void) {
|
|
170
|
+
self.handler = handler
|
|
171
|
+
super.init()
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
func handlePressure(pressure: CGFloat, location: NSPoint, stage: Int) {
|
|
175
|
+
let payload: [String: Any] = [
|
|
176
|
+
"force": pressure,
|
|
177
|
+
"locationX": location.x,
|
|
178
|
+
"locationY": location.y,
|
|
179
|
+
"stage": stage
|
|
180
|
+
]
|
|
181
|
+
handler(payload)
|
|
182
|
+
}
|
|
183
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import AppKit
|
|
2
|
+
|
|
3
|
+
extension NSColor {
|
|
4
|
+
|
|
5
|
+
// MARK: - Named color lookup
|
|
6
|
+
|
|
7
|
+
private static let namedColors: [String: NSColor] = [
|
|
8
|
+
"transparent": .clear,
|
|
9
|
+
"black": .black,
|
|
10
|
+
"white": .white,
|
|
11
|
+
"red": .red,
|
|
12
|
+
"green": .green,
|
|
13
|
+
"blue": .blue,
|
|
14
|
+
"gray": .gray,
|
|
15
|
+
"grey": .gray,
|
|
16
|
+
"orange": .orange,
|
|
17
|
+
"yellow": .yellow,
|
|
18
|
+
"purple": .purple,
|
|
19
|
+
"cyan": .cyan,
|
|
20
|
+
"magenta": .magenta,
|
|
21
|
+
"brown": .brown
|
|
22
|
+
]
|
|
23
|
+
|
|
24
|
+
// MARK: - Hex initializer
|
|
25
|
+
|
|
26
|
+
/// Creates an NSColor from a hex string.
|
|
27
|
+
/// Supports formats: "#RGB", "#RRGGBB", "#RRGGBBAA"
|
|
28
|
+
/// Also supports named colors: "transparent", "black", "white", "red", "green", "blue", "gray"
|
|
29
|
+
/// Returns .clear for invalid input.
|
|
30
|
+
static func fromHex(_ hex: String) -> NSColor {
|
|
31
|
+
let trimmed = hex.trimmingCharacters(in: .whitespacesAndNewlines).lowercased()
|
|
32
|
+
|
|
33
|
+
// Check named colors first
|
|
34
|
+
if let named = namedColors[trimmed] {
|
|
35
|
+
return named
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// Must start with '#'
|
|
39
|
+
guard trimmed.hasPrefix("#") else {
|
|
40
|
+
return .clear
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
let hexString = String(trimmed.dropFirst())
|
|
44
|
+
let scanner = Scanner(string: hexString)
|
|
45
|
+
var hexNumber: UInt64 = 0
|
|
46
|
+
|
|
47
|
+
guard scanner.scanHexInt64(&hexNumber) else {
|
|
48
|
+
return .clear
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
switch hexString.count {
|
|
52
|
+
case 3:
|
|
53
|
+
// #RGB -> #RRGGBB
|
|
54
|
+
let r = CGFloat((hexNumber & 0xF00) >> 8) / 15.0
|
|
55
|
+
let g = CGFloat((hexNumber & 0x0F0) >> 4) / 15.0
|
|
56
|
+
let b = CGFloat(hexNumber & 0x00F) / 15.0
|
|
57
|
+
return NSColor(red: r, green: g, blue: b, alpha: 1.0)
|
|
58
|
+
|
|
59
|
+
case 6:
|
|
60
|
+
// #RRGGBB
|
|
61
|
+
let r = CGFloat((hexNumber & 0xFF0000) >> 16) / 255.0
|
|
62
|
+
let g = CGFloat((hexNumber & 0x00FF00) >> 8) / 255.0
|
|
63
|
+
let b = CGFloat(hexNumber & 0x0000FF) / 255.0
|
|
64
|
+
return NSColor(red: r, green: g, blue: b, alpha: 1.0)
|
|
65
|
+
|
|
66
|
+
case 8:
|
|
67
|
+
// #RRGGBBAA
|
|
68
|
+
let r = CGFloat((hexNumber & 0xFF000000) >> 24) / 255.0
|
|
69
|
+
let g = CGFloat((hexNumber & 0x00FF0000) >> 16) / 255.0
|
|
70
|
+
let b = CGFloat((hexNumber & 0x0000FF00) >> 8) / 255.0
|
|
71
|
+
let a = CGFloat(hexNumber & 0x000000FF) / 255.0
|
|
72
|
+
return NSColor(red: r, green: g, blue: b, alpha: a)
|
|
73
|
+
|
|
74
|
+
default:
|
|
75
|
+
return .clear
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import AppKit
|
|
2
|
+
|
|
3
|
+
/// Base NSView subclass with flipped coordinate system (origin at top-left).
|
|
4
|
+
/// All Vue Native views should inherit from this to match CSS/Yoga layout coordinates.
|
|
5
|
+
/// NSView's default coordinate system has origin at bottom-left, which conflicts with
|
|
6
|
+
/// web/CSS layout conventions where origin is top-left.
|
|
7
|
+
open class FlippedView: NSView {
|
|
8
|
+
override open var isFlipped: Bool { true }
|
|
9
|
+
|
|
10
|
+
override public init(frame: NSRect) {
|
|
11
|
+
super.init(frame: frame)
|
|
12
|
+
wantsLayer = true // Enable layer-backed drawing for all views
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
required public init?(coder: NSCoder) {
|
|
16
|
+
super.init(coder: coder)
|
|
17
|
+
wantsLayer = true
|
|
18
|
+
}
|
|
19
|
+
}
|