@g9tm/lynxcontrols-native 2.6.18 → 2.7.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.
Files changed (53) hide show
  1. package/README.md +40 -1
  2. package/android/build.gradle.kts +7 -0
  3. package/android/src/main/java/com/g9lynx/g9native/G9NativeImages.kt +16 -0
  4. package/android/src/main/java/com/g9lynx/g9native/canvas/G9CanvasModel.kt +2 -2
  5. package/android/src/main/java/com/g9lynx/g9native/canvas/G9CanvasPaths.kt +7 -26
  6. package/android/src/main/java/com/g9lynx/g9native/canvas/G9CanvasView.kt +9 -4
  7. package/android/src/main/java/com/g9lynx/g9native/generated/G9ImageModuleSpec.java +27 -0
  8. package/android/src/main/java/com/g9lynx/g9native/image/G9HostTypeface.kt +49 -0
  9. package/android/src/main/java/com/g9lynx/g9native/image/G9ImageDraw.kt +222 -0
  10. package/android/src/main/java/com/g9lynx/g9native/image/G9ImageModule.kt +54 -0
  11. package/android/src/main/java/com/g9lynx/g9native/image/G9ImageProcessor.kt +464 -0
  12. package/android/src/main/java/com/g9lynx/g9native/image/core/G9HostFont.kt +28 -0
  13. package/android/src/main/java/com/g9lynx/g9native/image/core/G9ImageBudget.kt +54 -0
  14. package/android/src/main/java/com/g9lynx/g9native/image/core/G9ImageColor.kt +48 -0
  15. package/android/src/main/java/com/g9lynx/g9native/image/core/G9ImageError.kt +19 -0
  16. package/android/src/main/java/com/g9lynx/g9native/image/core/G9ImageExifTags.kt +61 -0
  17. package/android/src/main/java/com/g9lynx/g9native/image/core/G9ImageFiles.kt +99 -0
  18. package/android/src/main/java/com/g9lynx/g9native/image/core/G9ImageGeometry.kt +150 -0
  19. package/android/src/main/java/com/g9lynx/g9native/image/core/G9ImageJson.kt +200 -0
  20. package/android/src/main/java/com/g9lynx/g9native/image/core/G9ImageQuality.kt +65 -0
  21. package/android/src/main/java/com/g9lynx/g9native/image/core/G9ImageRedaction.kt +77 -0
  22. package/android/src/main/java/com/g9lynx/g9native/image/core/G9ImageService.kt +102 -0
  23. package/android/src/main/java/com/g9lynx/g9native/image/core/G9ImageSniff.kt +63 -0
  24. package/android/src/main/java/com/g9lynx/g9native/image/core/G9ImageSpec.kt +237 -0
  25. package/catalog/catalog.json +161 -1
  26. package/catalog/index.md +1 -1
  27. package/dist/.tsbuildinfo +1 -1
  28. package/dist/image.d.ts +219 -0
  29. package/dist/image.d.ts.map +1 -0
  30. package/dist/image.js +116 -0
  31. package/dist/image.js.map +1 -0
  32. package/dist/index.d.ts +1 -0
  33. package/dist/index.d.ts.map +1 -1
  34. package/dist/index.js +1 -0
  35. package/dist/protocol.d.ts +12 -0
  36. package/dist/protocol.d.ts.map +1 -1
  37. package/generated/G9ImageModule.ts +64 -0
  38. package/ios/Tests/G9NativeTestSuite.h +8 -0
  39. package/ios/Tests/G9NativeTestSuite.m +350 -0
  40. package/ios/Tests/G9NativeTests.m +16 -0
  41. package/ios/g9lynx-native-swift.podspec +1 -1
  42. package/ios/g9lynx-native.podspec +5 -4
  43. package/ios/src/G9ImageModule.h +30 -0
  44. package/ios/src/G9ImageModule.m +986 -0
  45. package/ios/src/core/G9ImageCore.h +201 -0
  46. package/ios/src/core/G9ImageCore.m +1039 -0
  47. package/ios/src/generated/G9ImageModuleSpec.h +16 -0
  48. package/ios/src/generated/G9ImageModuleSpec.m +2 -0
  49. package/ios/swift/canvas/G9LCCanvasCore.swift +3 -2
  50. package/ios/swift/canvas/G9LCCanvasView.swift +15 -4
  51. package/ios/swift/shared/G9LCFonts.swift +18 -2
  52. package/package.json +4 -4
  53. package/types/platform-native-module.d.ts +18 -0
@@ -0,0 +1,16 @@
1
+ // Generated by @lynx-js/autolink-codegen. Do not edit.
2
+ #import <Foundation/Foundation.h>
3
+ #import <Lynx/LynxModule.h>
4
+
5
+ NS_ASSUME_NONNULL_BEGIN
6
+
7
+ @protocol G9ImageModuleSpec <LynxModule>
8
+
9
+ - (void)probe:(NSString *)json callback:(id)callback;
10
+ - (void)preview:(NSString *)json callback:(id)callback;
11
+ - (void)process:(NSString *)json callback:(id)callback;
12
+ - (void)cancel:(NSString *)json callback:(id)callback;
13
+
14
+ @end
15
+
16
+ NS_ASSUME_NONNULL_END
@@ -0,0 +1,2 @@
1
+ // Generated by @lynx-js/autolink-codegen. Do not edit.
2
+ #import "G9ImageModuleSpec.h"
@@ -42,7 +42,7 @@ final class G9LCCanvasCore {
42
42
  enum Op {
43
43
  case path(path: CGPath, stroke: G9LCColors.RGBA?, width: Double, dash: [Double], fill: G9LCColors.RGBA?, evenOdd: Bool)
44
44
  case text(lines: [String], x: Double, y: Double, lineHeight: Double, size: Double, font: Int, color: G9LCColors.RGBA?,
45
- align: String, width: Double, rtl: Bool)
45
+ align: String, width: Double, rtl: Bool, weight: Double)
46
46
  case image(file: String, w: Double, h: Double, radius: Double, crop: [Double]?)
47
47
  }
48
48
 
@@ -90,8 +90,9 @@ final class G9LCCanvasCore {
90
90
  let align: String = G9LCJson.string(o, "al") ?? "left"
91
91
  let width: Double = G9LCJson.double(o, "w") ?? 0
92
92
  let rtl: Bool = G9LCJson.bool(o, "rtl") ?? false
93
+ let weight: Double = G9LCJson.double(o, "wt") ?? 400
93
94
  return .text(lines: lines, x: x, y: y, lineHeight: lineHeight, size: size, font: font, color: color, align: align,
94
- width: width, rtl: rtl)
95
+ width: width, rtl: rtl, weight: weight)
95
96
  case "i":
96
97
  let file: String = G9LCJson.string(o, "file") ?? ""
97
98
  let w: Double = G9LCJson.double(o, "w") ?? 0
@@ -9,6 +9,9 @@ import UIKit
9
9
  /// item version). Main thread.
10
10
  @objc(G9LCCanvasView)
11
11
  final class G9LCCanvasView: UIView {
12
+ /// Text op font id of the host's text font (`G9LCFonts.textFont`); Excalidraw's ids stay below it.
13
+ static let hostFont = 100
14
+
12
15
  /// `(event name, detail)` → the element (G9CanvasUI).
13
16
  @objc var emitter: ((String, [String: Any]) -> Void)?
14
17
 
@@ -266,23 +269,28 @@ final class G9LCCanvasView: UIView {
266
269
  context.strokePath()
267
270
  context.setLineDash(phase: 0, lengths: [])
268
271
  }
269
- case let .text(lines, x, y, lineHeight, size, font, color, align, _, _):
272
+ case let .text(lines, x, y, lineHeight, size, font, color, align, _, rtl, weight):
270
273
  let face: UIFont
271
274
  switch font {
275
+ case G9LCCanvasView.hostFont: face = G9LCFonts.text(size: CGFloat(size), weight: CGFloat(weight))
272
276
  case 6: face = G9LCFonts.font(file: "Nunito", size: CGFloat(size))
273
277
  case 8, 3: face = G9LCFonts.font(file: "ComicShanns", size: CGFloat(size))
274
278
  case 2, 9: face = UIFont.systemFont(ofSize: CGFloat(size))
275
279
  default: face = G9LCFonts.font(file: "Excalifont", size: CGFloat(size))
276
280
  }
277
281
  let ink = UIColor(cgColor: paint(color ?? G9LCColors.RGBA(r: 0x1e, g: 0x1e, b: 0x1e, a: 255), alpha: alpha))
278
- let attributes: [NSAttributedString.Key: Any] = [.font: face, .foregroundColor: ink]
282
+ let style = NSMutableParagraphStyle()
283
+ style.baseWritingDirection = rtl ? .rightToLeft : .leftToRight
284
+ let attributes: [NSAttributedString.Key: Any] = [.font: face, .foregroundColor: ink, .paragraphStyle: style]
285
+ // font 100: `y` is the first line's middle, the glyph box (ascender − descender) centred on it (the render's rule)
286
+ let first = font == G9LCCanvasView.hostFont ? y + Double(face.ascender + face.descender) / 2 : y
279
287
  UIGraphicsPushContext(context)
280
288
  for (index, line) in lines.enumerated() {
281
289
  let text = line as NSString
282
290
  let measured = text.size(withAttributes: attributes).width
283
291
  var left = CGFloat(x)
284
292
  if align == "center" { left -= measured / 2 } else if align == "right" { left -= measured }
285
- let baseline = CGFloat(y + Double(index) * lineHeight)
293
+ let baseline = CGFloat(first + Double(index) * lineHeight)
286
294
  text.draw(at: CGPoint(x: left, y: baseline - face.ascender), withAttributes: attributes)
287
295
  }
288
296
  UIGraphicsPopContext()
@@ -321,6 +329,8 @@ final class G9LCCanvasView: UIView {
321
329
  switch preview {
322
330
  case let .stroke(points):
323
331
  guard points.count >= 2 else { break }
332
+ // a live freehand stroke is 2.4 × the style width, as on Android and the web (Excalidraw's look)
333
+ context.setLineWidth(CGFloat(strokeWidth * 2.4))
324
334
  context.move(to: CGPoint(x: points[0], y: points[1]))
325
335
  var i = 2
326
336
  while i + 1 < points.count {
@@ -432,7 +442,8 @@ final class G9LCCanvasView: UIView {
432
442
  /// A picture of the board (through the pinned session), or nil while it loads.
433
443
  private func picture(_ url: String) -> UIImage? {
434
444
  if let image = images[url] { return image }
435
- guard !loading.contains(url), let target = URL(string: url) else { return nil }
445
+ // a bare absolute path is a local file (the photo editor's preview); URLSession reads file: URLs
446
+ guard !loading.contains(url), let target = url.hasPrefix("/") ? Optional(URL(fileURLWithPath: url)) : URL(string: url) else { return nil }
436
447
  if target.scheme?.lowercased() == "http", !G9LCImages.isLocal(target.host) { return nil }
437
448
  loading.insert(url)
438
449
  G9LCImages.session.dataTask(with: target) { [weak self] data, _, _ in
@@ -5,12 +5,15 @@ import UIKit
5
5
  /// Persian cascade; default the system font). The whiteboard's faces: `fonts/<file>.ttf` in the app's bundle
6
6
  /// (Excalifont, Nunito, ComicShanns), registered on first use; the system font without them.
7
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
8
+ /// The system font at a weight (100–900): `textFont` until the host sets its own.
9
+ static let systemTextFont: (CGFloat, CGFloat) -> UIFont = { size, weight in
10
10
  let w: UIFont.Weight = weight >= 700 ? .bold : weight >= 600 ? .semibold : weight >= 500 ? .medium : .regular
11
11
  return UIFont.systemFont(ofSize: size, weight: w)
12
12
  }
13
13
 
14
+ /// The app's text font at a weight (100–900). The host may replace it.
15
+ static var textFont: (CGFloat, CGFloat) -> UIFont = systemTextFont
16
+
14
17
  private static var names: [String: String] = [:]
15
18
  private static var tried = Set<String>()
16
19
 
@@ -36,3 +39,16 @@ enum G9LCFonts {
36
39
  return CTFontDescriptorCopyAttribute(first, kCTFontNameAttribute) as? String
37
40
  }
38
41
  }
42
+
43
+ /// `G9LCFonts.textFont` for Objective-C (2.7.0): G9ImageModule draws a text overlay whose `font` is empty with it, and a
44
+ /// host sets its own text font for every native element through `setTextFont:` (or `G9ImageModule.setTextFontProvider:`).
45
+ /// Reached through the runtime (`NSClassFromString(@"G9LCFontsBridge")`), like the views.
46
+ @objc(G9LCFontsBridge)
47
+ final class G9LCFontsBridge: NSObject {
48
+ @objc static func textFont(size: CGFloat, weight: CGFloat) -> UIFont { G9LCFonts.text(size: size, weight: weight) }
49
+
50
+ /// nil restores the system font.
51
+ @objc static func setTextFont(_ provider: ((CGFloat, CGFloat) -> UIFont)?) {
52
+ G9LCFonts.textFont = provider ?? G9LCFonts.systemTextFont
53
+ }
54
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@g9tm/lynxcontrols-native",
3
- "version": "2.6.18",
3
+ "version": "2.7.0",
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",
@@ -44,14 +44,14 @@
44
44
  "check:android-types": "node scripts/android-bridge-types.mjs"
45
45
  },
46
46
  "dependencies": {
47
- "@g9tm/lynxcontrols-foundation": "2.6.18",
48
- "@g9tm/lynxcontrols-sqlite": "2.6.18"
47
+ "@g9tm/lynxcontrols-foundation": "2.7.0",
48
+ "@g9tm/lynxcontrols-sqlite": "2.7.0"
49
49
  },
50
50
  "peerDependencies": {
51
51
  "@lynx-js/react": ">=0.129.3 <0.130.0"
52
52
  },
53
53
  "devDependencies": {
54
- "@g9tm/lynxcontrols-lynxtron": "2.6.18",
54
+ "@g9tm/lynxcontrols-lynxtron": "2.7.0",
55
55
  "@lynx-js/autolink-codegen": "0.6.0"
56
56
  }
57
57
  }
@@ -65,3 +65,21 @@ export declare class G9SpeechModule {
65
65
  /** Ends `session` early: its `listen` replies `cancelled`. Unknown or finished sessions are ignored. */
66
66
  cancel(session: string): void;
67
67
  }
68
+
69
+ /**
70
+ * Image processing for the photo editor and the headless "process this photo" API (2.7.0): Android `BitmapFactory` /
71
+ * `BitmapRegionDecoder` / `ExifInterface`, iOS ImageIO. Every method takes ONE JSON string and replies ONE JSON string,
72
+ * `{"ok":true,"value":{…}}` or `{"ok":false,"error":{"code","message"}}`; all work runs off the UI thread.
73
+ *
74
+ * @lynxmodule
75
+ */
76
+ export declare class G9ImageModule {
77
+ /** `{ path }` → `{ width, height, orientation, mime, bytes, hasAlpha }` (size after the EXIF orientation, no decode). */
78
+ probe(args: string, callback: (reply: string) => void): void;
79
+ /** `{ path, maxSide, dir? }` → `{ path, width, height, sourceWidth, sourceHeight }`: an oriented screen-sized copy. */
80
+ preview(args: string, callback: (reply: string) => void): void;
81
+ /** The process spec → `{ path, mime, width, height, bytes, quality, format, downscaled }`. */
82
+ process(args: string, callback: (reply: string) => void): void;
83
+ /** `{ token }` → `{}`: the running or queued process with that token ends with `cancelled` and leaves no file. */
84
+ cancel(args: string, callback: (reply: string) => void): void;
85
+ }