lecodes-cli 0.7.0 → 0.7.1
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/index.js +3 -3
- package/package.json +3 -3
- package/runtime/sdk/g2/Scene2D.ts +51 -5
- package/runtime/sdk/gl/Model.ts +9 -0
- package/runtime/sdk/gl/Scene.ts +76 -11
- package/runtime/sdk/inject.ts +14 -6
- package/runtime/sdk/plugins/camera.ts +81 -0
- package/runtime/sdk/plugins/geolocation.ts +123 -0
- package/runtime/sdk/plugins/permission.ts +7 -0
- package/runtime/sdk/plugins/qr.ts +61 -24
- package/runtime/sdk/runtime/app.ts +37 -0
- package/runtime/sdk/runtime/appEvents.ts +29 -0
- package/runtime/sdk/runtime/channel.ts +50 -0
- package/runtime/sdk/runtime/clipboard.ts +20 -0
- package/runtime/sdk/runtime/datetime.ts +2 -4
- package/runtime/sdk/runtime/device.ts +137 -4
- package/runtime/sdk/runtime/misc.ts +4 -0
- package/runtime/sdk/runtime/service.ts +82 -0
- package/runtime/sdk/runtime/touch.ts +26 -0
- package/runtime/sdk/ui/NativeView.ts +144 -0
- package/runtime/sdk/ui/UI.ts +5 -1
- package/runtime/sdk/ui/UIButton.ts +26 -3
- package/runtime/sdk/ui/UIInput.ts +2 -2
- package/runtime/sdk/ui/UINode.ts +24 -4
- package/runtime/sdk/ui/UIScreen.ts +63 -29
- package/runtime/sdk/ui/UIScreenHost.ts +3 -2
- package/runtime/sdk/ui/UIText.ts +1 -1
- package/runtime/sdk/ui/UIVideo.ts +48 -2
- package/runtime/sdk/ui/UIWidget.ts +34 -1
- package/runtime/sdk/ui/presentable.ts +116 -0
- package/runtime/sdk/ui/router.ts +73 -29
- package/runtime/sdk-types.json +1 -1
- package/runtime/sdk/runtime/camera.ts +0 -31
package/runtime/sdk/ui/router.ts
CHANGED
|
@@ -1,68 +1,112 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { _bumpNavEpoch, _descOf, _navSupported, _setCurrent, Presentable, type Transition } from "./presentable"
|
|
2
2
|
|
|
3
3
|
type RouterOptions = {
|
|
4
4
|
showDefaultBackButton?: boolean
|
|
5
5
|
}
|
|
6
6
|
|
|
7
|
+
type NavigateOptions = {
|
|
8
|
+
/** Transition to play. Defaults: `"push"` for push, `"fade"` for replace, `"pop"` for pop. */
|
|
9
|
+
transition?: Transition
|
|
10
|
+
}
|
|
11
|
+
|
|
7
12
|
type Router = {
|
|
8
|
-
get current():
|
|
9
|
-
init
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
+
get current(): Presentable
|
|
14
|
+
init(homePage: Presentable, opts?: RouterOptions): void
|
|
15
|
+
/** Push a destination onto the stack — a `UIScreen`, a `Scene`, a `Scene2D`, a `NativeView`,
|
|
16
|
+
* or a `UIVideo`. The back gesture/button pops it. Destinations with async preparation
|
|
17
|
+
* (`ARScene`: camera permission + warm render) return a Promise — the current page stays
|
|
18
|
+
* visible until they're ready, and a rejection (permission denied / superseded) leaves the
|
|
19
|
+
* stack untouched. */
|
|
20
|
+
push(page: Presentable, opts?: NavigateOptions): void | Promise<void>
|
|
21
|
+
replace(page: Presentable, opts?: NavigateOptions): void | Promise<void>
|
|
22
|
+
pop(to?: number, opts?: NavigateOptions): void
|
|
13
23
|
hide(): void
|
|
14
24
|
restore(): void
|
|
15
25
|
|
|
16
|
-
addEventListener(channel: "change", callback: (
|
|
17
|
-
removeEventListener(channel: "change", callback: (
|
|
26
|
+
addEventListener(channel: "change", callback: (page: Presentable) => void): void
|
|
27
|
+
removeEventListener(channel: "change", callback: (page: Presentable) => void): void
|
|
18
28
|
}
|
|
19
29
|
|
|
20
|
-
let
|
|
21
|
-
let onChange =
|
|
22
|
-
|
|
30
|
+
let currentPage: Presentable | null = null
|
|
31
|
+
let onChange = (page: any) => {
|
|
32
|
+
// Hosts hand back the wire object: the screen itself, or a descriptor carrying `_p`.
|
|
33
|
+
currentPage = page && page._p ? page._p : page
|
|
34
|
+
// The router's page is the visible destination (hosts fire this on every stack change,
|
|
35
|
+
// including back gestures) — keep Presentable.current in sync.
|
|
36
|
+
_setCurrent(currentPage)
|
|
23
37
|
for (let callback of (Router as any)._changeListeners) {
|
|
24
|
-
callback(
|
|
38
|
+
callback(currentPage)
|
|
25
39
|
}
|
|
26
40
|
}
|
|
27
41
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
42
|
+
// Non-screen destinations have no legacy bridge to fall back to — surface that clearly instead
|
|
43
|
+
// of letting an old host try to build a screen out of a scene descriptor.
|
|
44
|
+
const wireDesc = (page: Presentable): object => {
|
|
45
|
+
const desc = _descOf(page)
|
|
46
|
+
if (desc !== page && !_navSupported()) {
|
|
47
|
+
throw new Error("This host does not support scene/native-view navigation (requires _creatorUI.openView)")
|
|
48
|
+
}
|
|
49
|
+
return desc
|
|
31
50
|
}
|
|
32
51
|
|
|
33
52
|
export const Router: Router = /*#__PURE__*/ Object.freeze({
|
|
34
53
|
|
|
35
|
-
init(homePage:
|
|
36
|
-
|
|
37
|
-
|
|
54
|
+
init(homePage: Presentable, opts: RouterOptions = {}): void {
|
|
55
|
+
_bumpNavEpoch()
|
|
56
|
+
_creatorUI.routerOpen(wireDesc(homePage), onChange, opts.showDefaultBackButton ?? false)
|
|
57
|
+
currentPage = homePage
|
|
58
|
+
_setCurrent(homePage)
|
|
38
59
|
},
|
|
39
|
-
push(
|
|
40
|
-
|
|
60
|
+
push(page: Presentable, opts?: NavigateOptions): void | Promise<void> {
|
|
61
|
+
const desc = wireDesc(page) // throws early on unsupported hosts, before any async work
|
|
62
|
+
const go = () => {
|
|
63
|
+
_bumpNavEpoch()
|
|
64
|
+
// Legacy hosts ignore the extra transition argument.
|
|
65
|
+
_creatorUI.routerPush(desc, opts?.transition ?? "push")
|
|
66
|
+
_setCurrent(page) // optimistic — host onChange confirms (async on native hosts)
|
|
67
|
+
}
|
|
68
|
+
// A preparing destination (ARScene) keeps the current page visible until it's ready; a
|
|
69
|
+
// rejection (camera denied / superseded) propagates to the caller and nothing is pushed.
|
|
70
|
+
const prep = page._prepare?.()
|
|
71
|
+
return prep ? prep.then(go) : go()
|
|
41
72
|
},
|
|
42
|
-
replace(
|
|
43
|
-
|
|
73
|
+
replace(page: Presentable, opts?: NavigateOptions): void | Promise<void> {
|
|
74
|
+
const desc = wireDesc(page)
|
|
75
|
+
const go = () => {
|
|
76
|
+
_bumpNavEpoch()
|
|
77
|
+
_creatorUI.routerReplace(desc, opts?.transition ?? "fade")
|
|
78
|
+
_setCurrent(page) // optimistic — host onChange confirms (async on native hosts)
|
|
79
|
+
}
|
|
80
|
+
const prep = page._prepare?.()
|
|
81
|
+
return prep ? prep.then(go) : go()
|
|
44
82
|
},
|
|
45
|
-
pop(to?: number): void {
|
|
46
|
-
|
|
83
|
+
pop(to?: number, opts?: NavigateOptions): void {
|
|
84
|
+
_bumpNavEpoch()
|
|
85
|
+
_creatorUI.routerPop(to ?? -1, opts?.transition ?? "pop")
|
|
47
86
|
},
|
|
48
87
|
hide() {
|
|
88
|
+
_bumpNavEpoch()
|
|
49
89
|
_creatorUI.routerHide()
|
|
90
|
+
// hide() only blanks the router's own page — a directly-opened destination stays visible.
|
|
91
|
+
if (Presentable.current === currentPage) _setCurrent(null)
|
|
50
92
|
},
|
|
51
93
|
restore() {
|
|
94
|
+
_bumpNavEpoch()
|
|
52
95
|
_creatorUI.routerRestore()
|
|
96
|
+
_setCurrent(currentPage) // the stack top is visible again
|
|
53
97
|
},
|
|
54
98
|
|
|
55
|
-
get current():
|
|
56
|
-
return
|
|
99
|
+
get current(): Presentable {
|
|
100
|
+
return currentPage!
|
|
57
101
|
},
|
|
58
|
-
|
|
102
|
+
|
|
59
103
|
_changeListeners: [] as any[],
|
|
60
|
-
addEventListener(channel: "change", callback: (
|
|
104
|
+
addEventListener(channel: "change", callback: (page: Presentable) => void): void {
|
|
61
105
|
if (channel === "change") {
|
|
62
106
|
this._changeListeners.push(callback)
|
|
63
107
|
}
|
|
64
108
|
},
|
|
65
|
-
removeEventListener(channel: "change", callback: (
|
|
109
|
+
removeEventListener(channel: "change", callback: (page: Presentable) => void): void {
|
|
66
110
|
if (channel === "change") {
|
|
67
111
|
let index = this._changeListeners.indexOf(callback)
|
|
68
112
|
if (index >= 0) {
|