@g9tm/lynxcontrols-native 2.5.7 → 2.5.9
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/README.md +5 -0
- package/android/src/main/java/com/g9lynx/g9native/G9NativeImages.kt +24 -0
- package/android/src/main/java/com/g9lynx/g9native/blurhash/G9BlurhashUI.kt +76 -0
- package/android/src/main/java/com/g9lynx/g9native/blurhash/core/G9Blurhash.kt +100 -0
- package/android/src/main/java/com/g9lynx/g9native/canvas/G9CanvasModel.kt +94 -0
- package/android/src/main/java/com/g9lynx/g9native/canvas/G9CanvasPaths.kt +192 -0
- package/android/src/main/java/com/g9lynx/g9native/canvas/G9CanvasUI.kt +162 -0
- package/android/src/main/java/com/g9lynx/g9native/canvas/G9CanvasView.kt +1053 -0
- package/android/src/main/java/com/g9lynx/g9native/richtext/G9PictureSpan.kt +99 -0
- package/android/src/main/java/com/g9lynx/g9native/richtext/G9RichEditText.kt +458 -0
- package/android/src/main/java/com/g9lynx/g9native/richtext/G9RichStyle.kt +343 -0
- package/android/src/main/java/com/g9lynx/g9native/richtext/G9RichTextUI.kt +94 -0
- package/catalog/catalog.json +1 -1
- package/catalog/index.md +1 -1
- package/dist/.tsbuildinfo +1 -1
- package/ios/g9lynx-native-swift.podspec +20 -0
- package/ios/g9lynx-native.podspec +6 -2
- package/ios/src/G9LCBlurhashUI.h +14 -0
- package/ios/src/G9LCBlurhashUI.m +28 -0
- package/ios/src/G9LCCanvasUI.h +18 -0
- package/ios/src/G9LCCanvasUI.m +81 -0
- package/ios/src/G9LCRichTextUI.h +16 -0
- package/ios/src/G9LCRichTextUI.m +71 -0
- package/ios/swift/blurhash/G9LCBlurhashView.swift +165 -0
- package/ios/swift/canvas/G9LCCanvasCore.swift +848 -0
- package/ios/swift/canvas/G9LCCanvasView.swift +482 -0
- package/ios/swift/richtext/G9LCRichStyle.swift +238 -0
- package/ios/swift/richtext/G9LCRichTextView.swift +647 -0
- package/ios/swift/shared/G9LCColors.swift +78 -0
- package/ios/swift/shared/G9LCFonts.swift +38 -0
- package/ios/swift/shared/G9LCImages.swift +28 -0
- package/ios/swift/shared/G9LCJson.swift +73 -0
- package/package.json +6 -4
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import UIKit
|
|
2
|
+
|
|
3
|
+
/// CSS colours as the theme engine writes them (`setSystemBars({background})`, the rich-text palette) → RGBA:
|
|
4
|
+
/// `#rgb`, `#rgba`, `#rrggbb`, `#rrggbbaa` (alpha last), `rgb()`/`rgba()` with commas or spaces (`rgb(5 22 31 / 50%)`),
|
|
5
|
+
/// `transparent`, `black`, `white`. Nil for anything else. The Android host's G9LCColors rules.
|
|
6
|
+
enum G9LCColors {
|
|
7
|
+
struct RGBA: Equatable {
|
|
8
|
+
let r: Int, g: Int, b: Int, a: Int
|
|
9
|
+
|
|
10
|
+
var color: UIColor {
|
|
11
|
+
UIColor(red: CGFloat(r) / 255, green: CGFloat(g) / 255, blue: CGFloat(b) / 255, alpha: CGFloat(a) / 255)
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/// Relative luminance below 0.5: light status-bar text looks right on it.
|
|
15
|
+
var isDark: Bool {
|
|
16
|
+
0.2126 * Double(r) / 255 + 0.7152 * Double(g) / 255 + 0.0722 * Double(b) / 255 < 0.5
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
static func parse(_ raw: String?) -> RGBA? {
|
|
21
|
+
guard let text = raw?.trimmingCharacters(in: .whitespaces).lowercased(), !text.isEmpty else { return nil }
|
|
22
|
+
if text.hasPrefix("#") { return hex(String(text.dropFirst())) }
|
|
23
|
+
if text.hasPrefix("rgb(") || text.hasPrefix("rgba(") { return functional(text) }
|
|
24
|
+
switch text {
|
|
25
|
+
case "transparent": return RGBA(r: 0, g: 0, b: 0, a: 0)
|
|
26
|
+
case "black": return RGBA(r: 0, g: 0, b: 0, a: 255)
|
|
27
|
+
case "white": return RGBA(r: 255, g: 255, b: 255, a: 255)
|
|
28
|
+
default: return nil
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
static func color(_ raw: String?) -> UIColor? { parse(raw)?.color }
|
|
33
|
+
|
|
34
|
+
private static func hex(_ digits: String) -> RGBA? {
|
|
35
|
+
let values = digits.map { $0.hexDigitValue ?? -1 }
|
|
36
|
+
guard !values.contains(-1) else { return nil }
|
|
37
|
+
switch values.count {
|
|
38
|
+
case 3: return RGBA(r: values[0] * 17, g: values[1] * 17, b: values[2] * 17, a: 255)
|
|
39
|
+
case 4: return RGBA(r: values[0] * 17, g: values[1] * 17, b: values[2] * 17, a: values[3] * 17)
|
|
40
|
+
case 6: return RGBA(r: values[0] * 16 + values[1], g: values[2] * 16 + values[3], b: values[4] * 16 + values[5], a: 255)
|
|
41
|
+
case 8:
|
|
42
|
+
return RGBA(r: values[0] * 16 + values[1], g: values[2] * 16 + values[3], b: values[4] * 16 + values[5],
|
|
43
|
+
a: values[6] * 16 + values[7])
|
|
44
|
+
default: return nil
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
private static func functional(_ text: String) -> RGBA? {
|
|
49
|
+
guard text.hasSuffix(")"), let open = text.firstIndex(of: "(") else { return nil }
|
|
50
|
+
let inner = text[text.index(after: open)..<text.index(before: text.endIndex)]
|
|
51
|
+
let parts = inner.replacingOccurrences(of: "/", with: " / ")
|
|
52
|
+
.components(separatedBy: CharacterSet(charactersIn: ", "))
|
|
53
|
+
.map { $0.trimmingCharacters(in: .whitespaces) }
|
|
54
|
+
.filter { !$0.isEmpty && $0 != "/" }
|
|
55
|
+
guard parts.count == 3 || parts.count == 4,
|
|
56
|
+
let r = channel(parts[0]), let g = channel(parts[1]), let b = channel(parts[2]) else { return nil }
|
|
57
|
+
var a = 255
|
|
58
|
+
if parts.count == 4 {
|
|
59
|
+
guard let alpha = alpha(parts[3]) else { return nil }
|
|
60
|
+
a = alpha
|
|
61
|
+
}
|
|
62
|
+
return RGBA(r: r, g: g, b: b, a: a)
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
private static func channel(_ value: String) -> Int? {
|
|
66
|
+
if value.hasSuffix("%") {
|
|
67
|
+
return Double(value.dropLast()).map { Int((min(max($0, 0), 100) / 100 * 255).rounded()) }
|
|
68
|
+
}
|
|
69
|
+
return Double(value).map { Int(min(max($0, 0), 255).rounded()) }
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
private static func alpha(_ value: String) -> Int? {
|
|
73
|
+
if value.hasSuffix("%") {
|
|
74
|
+
return Double(value.dropLast()).map { Int((min(max($0, 0), 100) / 100 * 255).rounded()) }
|
|
75
|
+
}
|
|
76
|
+
return Double(value).map { Int((min(max($0, 0), 1) * 255).rounded()) }
|
|
77
|
+
}
|
|
78
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import CoreText
|
|
2
|
+
import UIKit
|
|
3
|
+
|
|
4
|
+
/// The fonts the native elements draw with (2.5.8). The page's text: `textFont` (the host sets its own, e.g. Inter with a
|
|
5
|
+
/// Persian cascade; default the system font). The whiteboard's faces: `fonts/<file>.ttf` in the app's bundle
|
|
6
|
+
/// (Excalifont, Nunito, ComicShanns), registered on first use; the system font without them.
|
|
7
|
+
enum G9LCFonts {
|
|
8
|
+
/// The app's text font at a weight (100–900). The host may replace it.
|
|
9
|
+
static var textFont: (CGFloat, CGFloat) -> UIFont = { size, weight in
|
|
10
|
+
let w: UIFont.Weight = weight >= 700 ? .bold : weight >= 600 ? .semibold : weight >= 500 ? .medium : .regular
|
|
11
|
+
return UIFont.systemFont(ofSize: size, weight: w)
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
private static var names: [String: String] = [:]
|
|
15
|
+
private static var tried = Set<String>()
|
|
16
|
+
|
|
17
|
+
/// The app's text font at `weight`.
|
|
18
|
+
static func text(size: CGFloat, weight: CGFloat = 400) -> UIFont { textFont(size, weight) }
|
|
19
|
+
|
|
20
|
+
/// A whiteboard face by file name, or the system font.
|
|
21
|
+
static func font(file: String, size: CGFloat) -> UIFont {
|
|
22
|
+
if !tried.contains(file) {
|
|
23
|
+
tried.insert(file)
|
|
24
|
+
if let name = register(file) { names[file] = name }
|
|
25
|
+
}
|
|
26
|
+
if let name = names[file], let font = UIFont(name: name, size: size) { return font }
|
|
27
|
+
return UIFont.systemFont(ofSize: size)
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
private static func register(_ file: String) -> String? {
|
|
31
|
+
guard let url = Bundle.main.url(forResource: file, withExtension: "ttf", subdirectory: "fonts") else { return nil }
|
|
32
|
+
var error: Unmanaged<CFError>?
|
|
33
|
+
_ = CTFontManagerRegisterFontsForURL(url as CFURL, .process, &error)
|
|
34
|
+
guard let descriptors = CTFontManagerCreateFontDescriptorsFromURL(url as CFURL) as? [CTFontDescriptor],
|
|
35
|
+
let first = descriptors.first else { return nil }
|
|
36
|
+
return CTFontDescriptorCopyAttribute(first, kCTFontNameAttribute) as? String
|
|
37
|
+
}
|
|
38
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import Foundation
|
|
2
|
+
|
|
3
|
+
/// How `<g9-richtext>` and `<g9-canvas>` fetch pictures (2.5.8): `session` is the host's to set (a pinned one) before the
|
|
4
|
+
/// first page opens; plain http is fetched only from this device or the local network.
|
|
5
|
+
@objc(G9LCImages)
|
|
6
|
+
final class G9LCImages: NSObject {
|
|
7
|
+
/// The session pictures are fetched with. Default `URLSession.shared`.
|
|
8
|
+
@objc static var session: URLSession = .shared
|
|
9
|
+
|
|
10
|
+
/// Whether a host is on this device or the local network.
|
|
11
|
+
static func isLocal(_ host: String?) -> Bool {
|
|
12
|
+
guard let host = host?.lowercased() else { return false }
|
|
13
|
+
if host == "localhost" || host.hasSuffix(".local") || host == "::1" { return true }
|
|
14
|
+
let parts = host.split(separator: ".").compactMap { Int($0) }
|
|
15
|
+
guard parts.count == 4 else { return false }
|
|
16
|
+
return parts[0] == 10 || parts[0] == 127 || (parts[0] == 192 && parts[1] == 168) || (parts[0] == 172 && (16...31).contains(parts[1]))
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/// How an exported board becomes the app's file (2.5.8): the PNG's bytes, its name and type → the `cvexport` event's
|
|
21
|
+
/// `file` (`id`, `name`, `size`, `mime`, `uri`). The default writes it to the temporary folder.
|
|
22
|
+
enum G9LCCanvasFiles {
|
|
23
|
+
static var register: (Data, String, String) throws -> [String: Any] = { data, name, mime in
|
|
24
|
+
let url = FileManager.default.temporaryDirectory.appendingPathComponent("g9canvas-\(UUID().uuidString).png")
|
|
25
|
+
try data.write(to: url)
|
|
26
|
+
return ["id": url.path, "name": name, "size": data.count, "mime": mime, "uri": url.absoluteString]
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import Foundation
|
|
2
|
+
|
|
3
|
+
/// JSON helpers for the bridge: native calls take objects as JSON strings and reply with JSON (client/app
|
|
4
|
+
/// `lib/platform/native.ts`).
|
|
5
|
+
enum G9LCJson {
|
|
6
|
+
/// `value` as JSON text (objects, arrays, strings, numbers, booleans, NSNull). "null" when it cannot be encoded.
|
|
7
|
+
static func encode(_ value: Any?) -> String {
|
|
8
|
+
guard let value = value, !(value is NSNull) else { return "null" }
|
|
9
|
+
guard JSONSerialization.isValidJSONObject([value]),
|
|
10
|
+
let data = try? JSONSerialization.data(withJSONObject: value, options: [.fragmentsAllowed, .withoutEscapingSlashes]),
|
|
11
|
+
let text = String(data: data, encoding: .utf8) else { return "null" }
|
|
12
|
+
return text
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/// A JSON string literal for `text`.
|
|
16
|
+
static func quote(_ text: String) -> String { encode(text) }
|
|
17
|
+
|
|
18
|
+
/// The JSON object in `text`, or nil when it is missing or not an object.
|
|
19
|
+
static func object(_ text: String?) -> [String: Any]? {
|
|
20
|
+
guard let text = text, !text.isEmpty, let data = text.data(using: .utf8),
|
|
21
|
+
let value = try? JSONSerialization.jsonObject(with: data, options: []) else { return nil }
|
|
22
|
+
return value as? [String: Any]
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/// The JSON array in `text`, or nil.
|
|
26
|
+
static func array(_ text: String?) -> [Any]? {
|
|
27
|
+
guard let text = text, !text.isEmpty, let data = text.data(using: .utf8),
|
|
28
|
+
let value = try? JSONSerialization.jsonObject(with: data, options: []) else { return nil }
|
|
29
|
+
return value as? [Any]
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/// `text` is one complete JSON value (any type).
|
|
33
|
+
static func isValid(_ data: Data) -> Bool {
|
|
34
|
+
(try? JSONSerialization.jsonObject(with: data, options: [.fragmentsAllowed])) != nil
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// Typed reads of decoded objects (numbers arrive as NSNumber, booleans too).
|
|
38
|
+
|
|
39
|
+
static func string(_ object: [String: Any]?, _ key: String) -> String? {
|
|
40
|
+
guard let value = object?[key] else { return nil }
|
|
41
|
+
if let text = value as? String { return text }
|
|
42
|
+
if let number = value as? NSNumber, !isBoolean(number) { return number.stringValue }
|
|
43
|
+
return nil
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/// A JSON `true`/`false` (CFBoolean), not the numbers 1/0 (Swift's `is Bool` cannot tell them apart).
|
|
47
|
+
static func isBoolean(_ number: NSNumber) -> Bool {
|
|
48
|
+
CFGetTypeID(number) == CFBooleanGetTypeID()
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
static func bool(_ object: [String: Any]?, _ key: String) -> Bool? {
|
|
52
|
+
guard let value = object?[key] else { return nil }
|
|
53
|
+
if let flag = value as? Bool { return flag }
|
|
54
|
+
if let number = value as? NSNumber { return number.boolValue }
|
|
55
|
+
if let text = value as? String { return text == "true" || text == "1" }
|
|
56
|
+
return nil
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
static func double(_ object: [String: Any]?, _ key: String) -> Double? {
|
|
60
|
+
guard let value = object?[key] else { return nil }
|
|
61
|
+
if let number = value as? NSNumber { return number.doubleValue }
|
|
62
|
+
if let text = value as? String { return Double(text) }
|
|
63
|
+
return nil
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
static func int(_ object: [String: Any]?, _ key: String) -> Int? {
|
|
67
|
+
double(object, key).flatMap { $0.isFinite ? Int($0) : nil }
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
static func strings(_ object: [String: Any]?, _ key: String) -> [String] {
|
|
71
|
+
(object?[key] as? [Any])?.compactMap { $0 as? String } ?? []
|
|
72
|
+
}
|
|
73
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@g9tm/lynxcontrols-native",
|
|
3
|
-
"version": "2.5.
|
|
3
|
+
"version": "2.5.9",
|
|
4
4
|
"description": "Android and iOS platform layer: the G9SqliteModule and G9HostModule native modules (Autolink) and their JS adapters.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -24,7 +24,9 @@
|
|
|
24
24
|
"android/consumer-rules.pro",
|
|
25
25
|
"android/src/main",
|
|
26
26
|
"ios/g9lynx-native.podspec",
|
|
27
|
+
"ios/g9lynx-native-swift.podspec",
|
|
27
28
|
"ios/src",
|
|
29
|
+
"ios/swift",
|
|
28
30
|
"ios/fonts/*.ttf",
|
|
29
31
|
"ios/fonts/OFL.txt",
|
|
30
32
|
"ios/Tests/G9NativeTestSuite.h",
|
|
@@ -42,14 +44,14 @@
|
|
|
42
44
|
"check:android-types": "node scripts/android-bridge-types.mjs"
|
|
43
45
|
},
|
|
44
46
|
"dependencies": {
|
|
45
|
-
"@g9tm/lynxcontrols-foundation": "2.5.
|
|
46
|
-
"@g9tm/lynxcontrols-sqlite": "2.5.
|
|
47
|
+
"@g9tm/lynxcontrols-foundation": "2.5.9",
|
|
48
|
+
"@g9tm/lynxcontrols-sqlite": "2.5.9"
|
|
47
49
|
},
|
|
48
50
|
"peerDependencies": {
|
|
49
51
|
"@lynx-js/react": ">=0.129.3 <0.130.0"
|
|
50
52
|
},
|
|
51
53
|
"devDependencies": {
|
|
52
|
-
"@g9tm/lynxcontrols-lynxtron": "2.5.
|
|
54
|
+
"@g9tm/lynxcontrols-lynxtron": "2.5.9",
|
|
53
55
|
"@lynx-js/autolink-codegen": "0.6.0"
|
|
54
56
|
}
|
|
55
57
|
}
|