@g9tm/lynxcontrols-native 2.5.6 → 2.5.8
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 +6 -1
- package/android/build.gradle.kts +11 -2
- package/android/src/main/java/com/g9lynx/g9native/G9Bridge.kt +47 -2
- 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 +2 -2
- package/catalog/index.md +1 -1
- package/dist/.tsbuildinfo +1 -1
- package/dist/media.d.ts +1 -1
- package/dist/media.d.ts.map +1 -1
- package/dist/services.d.ts +8 -0
- package/dist/services.d.ts.map +1 -1
- package/dist/services.js +4 -2
- package/dist/services.js.map +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/src/{G9VideoUI.h → G9LCVideoUI.h} +5 -5
- package/ios/src/{G9VideoUI.m → G9LCVideoUI.m} +9 -8
- package/ios/src/G9PointerEventsHitTest.h +5 -1
- package/ios/src/G9PointerEventsHitTest.m +6 -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,162 @@
|
|
|
1
|
+
package com.g9lynx.g9native.canvas
|
|
2
|
+
|
|
3
|
+
import android.content.Context
|
|
4
|
+
import android.graphics.Bitmap
|
|
5
|
+
import com.lynx.react.bridge.Callback
|
|
6
|
+
import com.lynx.react.bridge.JavaOnlyMap
|
|
7
|
+
import com.lynx.react.bridge.ReadableMap
|
|
8
|
+
import com.lynx.tasm.behavior.Behavior
|
|
9
|
+
import com.lynx.tasm.behavior.LynxContext
|
|
10
|
+
import com.lynx.tasm.behavior.LynxProp
|
|
11
|
+
import com.lynx.tasm.behavior.LynxUIMethod
|
|
12
|
+
import com.lynx.tasm.behavior.LynxUIMethodConstants
|
|
13
|
+
import com.lynx.tasm.behavior.ui.LynxUI
|
|
14
|
+
import com.lynx.tasm.event.LynxDetailEvent
|
|
15
|
+
import org.json.JSONObject
|
|
16
|
+
import java.util.concurrent.Executors
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* `<g9-canvas tool editable theme background accent stroke bindcv…>` (Plan-Lynx §6, W11): the drawing surface of a
|
|
20
|
+
* whiteboard ([G9CanvasView]). The scene, editing and sync are the app's (client/app `features/whiteboard`); this
|
|
21
|
+
* element draws the items it is sent and reports gestures. Protocol: `canvas/protocol.ts`; gesture rules:
|
|
22
|
+
* `canvas/element-core.ts`.
|
|
23
|
+
*
|
|
24
|
+
* Methods: `apply({ json })` (a message), `exportImage({ token, scale, padding, background, name })` → `cvexport`.
|
|
25
|
+
*/
|
|
26
|
+
class G9CanvasUI(context: LynxContext) : LynxUI<G9CanvasView>(context) {
|
|
27
|
+
// LynxUI's constructor calls createView before this class's initialisers run: no initialiser here.
|
|
28
|
+
private lateinit var surface: G9CanvasView
|
|
29
|
+
|
|
30
|
+
override fun createView(context: Context): G9CanvasView {
|
|
31
|
+
val view = G9CanvasView(context)
|
|
32
|
+
view.emitter = { name, detail -> emit(name, detail) }
|
|
33
|
+
surface = view
|
|
34
|
+
return view
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
@LynxProp(name = "tool")
|
|
38
|
+
fun setTool(value: String?) {
|
|
39
|
+
mView?.tool = value ?: "selection"
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
@LynxProp(name = "editable", defaultBoolean = false)
|
|
43
|
+
fun setEditable(value: Boolean) {
|
|
44
|
+
mView?.editable = value
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
@LynxProp(name = "theme")
|
|
48
|
+
fun setTheme(value: String?) {
|
|
49
|
+
mView?.setDark(value == "dark")
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
@LynxProp(name = "background")
|
|
53
|
+
fun setBackground(value: String?) {
|
|
54
|
+
mView?.background = G9CanvasPaths.color(value, android.graphics.Color.WHITE)
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
@LynxProp(name = "accent")
|
|
58
|
+
fun setAccent(value: String?) {
|
|
59
|
+
mView?.accent = G9CanvasPaths.color(value, android.graphics.Color.rgb(0x69, 0x65, 0xdb))
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
@LynxProp(name = "stroke")
|
|
63
|
+
fun setStroke(value: String?) {
|
|
64
|
+
val view = mView ?: return
|
|
65
|
+
val o = runCatching { JSONObject(value ?: "{}") }.getOrNull() ?: return
|
|
66
|
+
view.strokeColor = G9CanvasPaths.color(o.optString("color"), android.graphics.Color.BLACK)
|
|
67
|
+
view.strokeWidthStyle = o.optDouble("width", 2.0).toFloat()
|
|
68
|
+
view.fillColor = if (o.has("fill")) G9CanvasPaths.color(o.optString("fill")) else null
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** The app's message (`invoke({ method: 'apply', params: { json } })`). */
|
|
72
|
+
@LynxUIMethod
|
|
73
|
+
fun apply(params: ReadableMap, callback: Callback) {
|
|
74
|
+
val json = params.getString("json")
|
|
75
|
+
if (!json.isNullOrEmpty()) runCatching { mView?.apply(JSONObject(json)) }.onFailure { android.util.Log.w(TAG, "apply failed", it) }
|
|
76
|
+
callback.invoke(LynxUIMethodConstants.SUCCESS)
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** Renders the board to a PNG registered in the file store (like a picked file); answers with `cvexport`. */
|
|
80
|
+
@LynxUIMethod
|
|
81
|
+
fun exportImage(params: ReadableMap, callback: Callback) {
|
|
82
|
+
callback.invoke(LynxUIMethodConstants.SUCCESS)
|
|
83
|
+
val view = mView ?: return
|
|
84
|
+
val token = if (params.hasKey("token")) params.getString("token") ?: "" else ""
|
|
85
|
+
val scale = if (params.hasKey("scale")) params.getDouble("scale").toFloat() else 2f
|
|
86
|
+
val padding = if (params.hasKey("padding")) params.getDouble("padding").toFloat() else 24f
|
|
87
|
+
val background = !params.hasKey("background") || params.getBoolean("background")
|
|
88
|
+
val name = (if (params.hasKey("name")) params.getString("name") else null)?.takeIf { it.isNotBlank() } ?: "whiteboard.png"
|
|
89
|
+
val bitmap = runCatching { view.renderExport(scale, padding, background) }.getOrNull()
|
|
90
|
+
if (bitmap == null) {
|
|
91
|
+
emit("cvexport", mapOf("token" to token, "error" to "empty"))
|
|
92
|
+
return
|
|
93
|
+
}
|
|
94
|
+
io.execute {
|
|
95
|
+
try {
|
|
96
|
+
val app = view.context.applicationContext
|
|
97
|
+
val dir = java.io.File(app.cacheDir, "g9canvas").apply { mkdirs() }
|
|
98
|
+
val file = java.io.File(dir, "board-${System.currentTimeMillis()}.png")
|
|
99
|
+
file.outputStream().use { bitmap.compress(Bitmap.CompressFormat.PNG, 100, it) }
|
|
100
|
+
val entry = G9CanvasFiles.register(file, name, "image/png") + mapOf("width" to bitmap.width, "height" to bitmap.height)
|
|
101
|
+
val ref = JavaOnlyMap()
|
|
102
|
+
for ((key, value) in entry) {
|
|
103
|
+
when (value) {
|
|
104
|
+
null -> ref.putNull(key)
|
|
105
|
+
is Int -> ref.putInt(key, value)
|
|
106
|
+
is Long -> ref.putDouble(key, value.toDouble())
|
|
107
|
+
is Double -> ref.putDouble(key, value)
|
|
108
|
+
is Boolean -> ref.putBoolean(key, value)
|
|
109
|
+
else -> ref.putString(key, value.toString())
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
view.post { emit("cvexport", mapOf("token" to token, "file" to ref)) }
|
|
113
|
+
} catch (e: Exception) {
|
|
114
|
+
view.post { emit("cvexport", mapOf("token" to token, "error" to (e.message ?: "export_failed"))) }
|
|
115
|
+
} finally {
|
|
116
|
+
bitmap.recycle()
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
private fun emit(name: String, detail: Map<String, Any?>) {
|
|
122
|
+
// The event adds its own fields to the map: a mutable copy.
|
|
123
|
+
lynxContext.eventEmitter.sendCustomEvent(LynxDetailEvent(sign, name, HashMap(detail)))
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
override fun destroy() {
|
|
127
|
+
if (::surface.isInitialized) surface.emitter = null
|
|
128
|
+
super.destroy()
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
companion object {
|
|
132
|
+
private val io = Executors.newSingleThreadExecutor { runnable -> Thread(runnable, "g9-canvas-export").apply { isDaemon = true } }
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
private const val TAG = "G9Canvas"
|
|
137
|
+
|
|
138
|
+
/** Registers `<g9-canvas>` on the app's page (host/G9Pages.kt). */
|
|
139
|
+
/**
|
|
140
|
+
* How an exported board becomes the app's file (2.5.8): the PNG written to the app's cache, then [register] gives the
|
|
141
|
+
* `cvexport` event its `file` (`id`, `name`, `size`, `mime`, `uri`). A host with its own file store sets [register].
|
|
142
|
+
*/
|
|
143
|
+
object G9CanvasFiles {
|
|
144
|
+
@Volatile
|
|
145
|
+
var register: (java.io.File, String, String) -> Map<String, Any?> = { file, name, mime ->
|
|
146
|
+
mapOf("id" to file.absolutePath, "name" to name, "size" to file.length(), "mime" to mime, "uri" to "file://${file.absolutePath}")
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* The behaviour of `<g9-canvas>` (`@g9tm/lynxcontrols-native`, 2.5.8). Add it with the host's own:
|
|
152
|
+
* `LynxViewBuilder().addBehaviors(hostBehaviors + G9CanvasBehaviors.create())`. The board's fonts are the app's
|
|
153
|
+
* assets `fonts/Excalifont.ttf`, `fonts/Nunito.ttf`, `fonts/ComicShanns.ttf` (the default typeface without them).
|
|
154
|
+
*/
|
|
155
|
+
object G9CanvasBehaviors {
|
|
156
|
+
fun create(): List<Behavior> =
|
|
157
|
+
listOf(
|
|
158
|
+
object : Behavior("g9-canvas", false, false, false) {
|
|
159
|
+
override fun createUI(context: LynxContext): LynxUI<*> = G9CanvasUI(context)
|
|
160
|
+
},
|
|
161
|
+
)
|
|
162
|
+
}
|