lecodes-cli 0.10.4 → 0.11.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/README.md +1 -1
- package/dist/index.js +3117 -1575
- package/package.json +1 -1
- package/runtime/scene-harness.json +1 -1
- package/runtime/sdk/compile/aspectMacro.ts +42 -0
- package/runtime/sdk/compile/assetIconMacro.ts +382 -0
- package/runtime/sdk/compile/assetMacro.ts +45 -0
- package/runtime/sdk/compile/assetName.ts +50 -0
- package/runtime/sdk/compile/bundler.ts +244 -0
- package/runtime/sdk/compile/compileProject.ts +106 -0
- package/runtime/sdk/compile/detectEntry.ts +125 -0
- package/runtime/sdk/compile/fontMacro.ts +459 -0
- package/runtime/sdk/compile/fontRegistry.ts +78 -0
- package/runtime/sdk/compile/header.ts +55 -0
- package/runtime/sdk/compile/index.ts +53 -0
- package/runtime/sdk/compile/libraryImports.ts +52 -0
- package/runtime/sdk/compile/sceneEditor.ts +78 -0
- package/runtime/sdk/compile/sfnt.ts +98 -0
- package/runtime/sdk/compile/sourcemap.ts +25 -0
- package/runtime/sdk/inject.ts +2 -0
- package/runtime/sdk/ui/NativeView.ts +3 -0
- package/runtime/sdk/ui/UI.ts +9 -1
- package/runtime/sdk/ui/UIBottomSheet.ts +10 -16
- package/runtime/sdk/ui/UIButton.ts +18 -16
- package/runtime/sdk/ui/UIContainer.ts +38 -46
- package/runtime/sdk/ui/UIImage.ts +8 -5
- package/runtime/sdk/ui/UIInput.ts +6 -6
- package/runtime/sdk/ui/UIModal.ts +10 -16
- package/runtime/sdk/ui/UINode.ts +105 -36
- package/runtime/sdk/ui/UIPager.ts +27 -15
- package/runtime/sdk/ui/UIPopover.ts +10 -16
- package/runtime/sdk/ui/UIScreen.ts +20 -21
- package/runtime/sdk/ui/UIScrollable.ts +37 -29
- package/runtime/sdk/ui/UISpacer.ts +2 -0
- package/runtime/sdk/ui/UITabs.ts +175 -0
- package/runtime/sdk/ui/UIText.ts +5 -0
- package/runtime/sdk/ui/UIVideo.ts +5 -0
- package/runtime/sdk/ui/UIVirtualizedList.ts +33 -39
- package/runtime/sdk/ui/UIWidget.ts +22 -18
- package/runtime/sdk/ui/fonts.ts +3 -0
- package/runtime/sdk/ui/router.ts +13 -0
- package/runtime/sdk/ui/theme.ts +21 -30
- package/runtime/sdk-types.json +1 -1
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import { PagerElement, type UIPager } from "./UIPager"
|
|
2
|
+
import { ScreenElement, type UIScreen } from "./UIScreen"
|
|
3
|
+
import { UIButton } from "./UIButton"
|
|
4
|
+
import { UIRow, UIColumn, type UIRow as UIRowType } from "./UIContainer"
|
|
5
|
+
import { UIText } from "./UIText"
|
|
6
|
+
import { UIImage, type ImageSource } from "./UIImage"
|
|
7
|
+
|
|
8
|
+
// UITabs — the standard bottom-tab shell, prewired: a UIScreen composing [ UIPager (flexGrow: 1),
|
|
9
|
+
// tab bar ]. Pure SDK composition over the pager — zero new ABI, works wherever UIPager does.
|
|
10
|
+
// The build-mode twin of the design scaffold's `defineTabs` (lecodes-design/tabbar-surface.md):
|
|
11
|
+
// same keyed config, same `tab-<id>` button names, same theme variables with the same fallbacks,
|
|
12
|
+
// so a designed mockup and the built app render identically.
|
|
13
|
+
|
|
14
|
+
/** Active/inactive/bar colors ride the theme — one `theme({ primaryColor, mutedColor, tabbarBg })`
|
|
15
|
+
* call restyles the bar app-wide; the fallbacks keep an unthemed app looking right. */
|
|
16
|
+
const ACTIVE = "var(--primaryColor, #5b8cff)"
|
|
17
|
+
const INACTIVE = "var(--mutedColor, #8a919e)"
|
|
18
|
+
const BAR_BG = "var(--tabbarBg, #15171c)"
|
|
19
|
+
const BAR_BORDER = "var(--tabbarBorder, #23262e)"
|
|
20
|
+
const SCREEN_BG = "var(--screenBg, #101114)"
|
|
21
|
+
const BADGE_BG = "var(--badgeColor, #ff453a)"
|
|
22
|
+
|
|
23
|
+
export type UITabDef = {
|
|
24
|
+
label: string,
|
|
25
|
+
/** Tab icon — typically `assetIcon("lucide:…")`. Tinted active/inactive by the bar. */
|
|
26
|
+
icon?: ImageSource,
|
|
27
|
+
/** The tab's root screen. Tabs are fixed at construction (like UIPager's). */
|
|
28
|
+
screen: UIScreen,
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* A bottom-tab app shell: swipeable tabs (a `UIPager`) plus a themed tab bar, as one
|
|
33
|
+
* `UIScreen` — present it directly (`Router.init(tabs)`). Keys are tab ids, in tab order:
|
|
34
|
+
*
|
|
35
|
+
* ```ts
|
|
36
|
+
* const tabs = UITabs({
|
|
37
|
+
* home: { label: "Home", icon: assetIcon("lucide:house"), screen: homeScreen },
|
|
38
|
+
* profile: { label: "Profile", icon: assetIcon("lucide:user"), screen: profileScreen },
|
|
39
|
+
* })
|
|
40
|
+
* Router.init(tabs)
|
|
41
|
+
* ```
|
|
42
|
+
*
|
|
43
|
+
* In-tab navigation stays the pager's: `UIPager.push(detail)` from any screen (bar stays);
|
|
44
|
+
* `Router.push` opens above the shell (bar covered). Restyle via `theme()` (primaryColor,
|
|
45
|
+
* mutedColor, tabbarBg, …) or the `bar` handle; for a fully custom bar build on `UIPager`.
|
|
46
|
+
*/
|
|
47
|
+
export interface UITabs extends UIScreen {
|
|
48
|
+
/** The active tab id. */
|
|
49
|
+
readonly tab: string,
|
|
50
|
+
/** Switch tabs (instant, the tab-bar convention; `animated: true` slides). */
|
|
51
|
+
select(id: string, animated?: boolean): this,
|
|
52
|
+
/** Fires when the active tab changes and has settled — a bar tap, swipe, or `select()`. */
|
|
53
|
+
onSelect(callback: (id: string, index: number) => void): this,
|
|
54
|
+
/** Show a badge on a tab: `true` = dot, a number/string = count pill, `false`/`null`/`0` clears. */
|
|
55
|
+
badge(id: string, value: number | string | boolean | null): this,
|
|
56
|
+
/** The pager under the bar — in-tab stacks (`push`/`pop`/`depth`). */
|
|
57
|
+
readonly pager: UIPager,
|
|
58
|
+
/** The bar row (named "tabbar") — for restyling beyond the theme variables. */
|
|
59
|
+
readonly bar: UIRowType,
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export class TabsElement extends ScreenElement {
|
|
63
|
+
private readonly ids: string[]
|
|
64
|
+
private readonly _pagerEl: PagerElement
|
|
65
|
+
private readonly _bar: any
|
|
66
|
+
private readonly _icons: (any | null)[] = []
|
|
67
|
+
private readonly _labels: any[] = []
|
|
68
|
+
private readonly _badges: any[] = []
|
|
69
|
+
private readonly _badgeTexts: any[] = []
|
|
70
|
+
private readonly _buttons: any[] = []
|
|
71
|
+
private readonly _selectListeners: ((id: string, index: number) => void)[] = []
|
|
72
|
+
|
|
73
|
+
constructor(defs: Record<string, UITabDef>) {
|
|
74
|
+
super("screen", { bgColor: SCREEN_BG }, [])
|
|
75
|
+
this.ids = Object.keys(defs)
|
|
76
|
+
if (this.ids.length === 0) console.warn("UITabs: no tabs declared")
|
|
77
|
+
|
|
78
|
+
this._pagerEl = new PagerElement({ flexGrow: 1 }, this.ids.map((id) => defs[id].screen))
|
|
79
|
+
|
|
80
|
+
const buttons = this.ids.map((id, i) => {
|
|
81
|
+
const def = defs[id]
|
|
82
|
+
const icon = def.icon ? UIImage(def.icon).style({ width: 22, height: 22, tintColor: INACTIVE }) : null
|
|
83
|
+
const label = UIText(def.label).style({ fontSize: 10, color: INACTIVE })
|
|
84
|
+
const badgeText = UIText("").style({ fontSize: 9, fontWeight: 700, color: "white" })
|
|
85
|
+
const badge = UIRow(badgeText).style({
|
|
86
|
+
position: "absolute", top: -3, right: -6, display: "none",
|
|
87
|
+
bgColor: BADGE_BG, borderRadius: 99, justifyContent: "center", alignItems: "center",
|
|
88
|
+
})
|
|
89
|
+
// The badge anchors to the icon (or the label when there is none) — its wrap must not clip.
|
|
90
|
+
const anchor = UIColumn(icon ?? label, badge).style({ overflow: "visible", alignItems: "center" })
|
|
91
|
+
this._icons.push(icon)
|
|
92
|
+
this._labels.push(label)
|
|
93
|
+
this._badges.push(badge)
|
|
94
|
+
this._badgeTexts.push(badgeText)
|
|
95
|
+
const button = UIButton(anchor, icon ? label : null)
|
|
96
|
+
.style({ name: `tab-${id}`, flexDirection: "column", gap: 3, flex: 1, pt: 8, pb: 6 })
|
|
97
|
+
.onClick(() => this.select(id))
|
|
98
|
+
this._buttons.push(button)
|
|
99
|
+
return button
|
|
100
|
+
})
|
|
101
|
+
|
|
102
|
+
this._bar = UIRow(buttons).style({
|
|
103
|
+
name: "tabbar", bgColor: BAR_BG, pb: "comfort-bottom",
|
|
104
|
+
borderTopWidth: 1, borderTopColor: BAR_BORDER,
|
|
105
|
+
})
|
|
106
|
+
|
|
107
|
+
this._pagerEl.onSelect((i) => {
|
|
108
|
+
this._applyActive(i)
|
|
109
|
+
for (const cb of this._selectListeners) cb(this.ids[i], i)
|
|
110
|
+
})
|
|
111
|
+
this._applyActive(0)
|
|
112
|
+
this.append(this._pagerEl as any, this._bar)
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
private _applyActive(index: number): void {
|
|
116
|
+
for (let i = 0; i < this.ids.length; i++) {
|
|
117
|
+
const on = i === index
|
|
118
|
+
const color = on ? ACTIVE : INACTIVE
|
|
119
|
+
// Imperative writes carry the visual on every host; the class is the styling hook — custom
|
|
120
|
+
// content inside a tab button can declare `$active` blocks (class state cascades down).
|
|
121
|
+
this._buttons[i].class.active = on
|
|
122
|
+
if (this._icons[i]) this._icons[i].style.tintColor = color
|
|
123
|
+
this._labels[i].style.color = color
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
get tab(): string {
|
|
128
|
+
return this.ids[this._pagerEl.index]
|
|
129
|
+
}
|
|
130
|
+
get pager(): any {
|
|
131
|
+
return this._pagerEl
|
|
132
|
+
}
|
|
133
|
+
get bar(): any {
|
|
134
|
+
return this._bar
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
select(id: string, animated = false): this {
|
|
138
|
+
const index = this.ids.indexOf(id)
|
|
139
|
+
if (index < 0) {
|
|
140
|
+
console.warn(`UITabs.select: unknown tab "${id}"`)
|
|
141
|
+
return this
|
|
142
|
+
}
|
|
143
|
+
this._pagerEl.select(index, animated)
|
|
144
|
+
return this
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
onSelect(callback: (id: string, index: number) => void): this {
|
|
148
|
+
this._selectListeners.push(callback)
|
|
149
|
+
return this
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
badge(id: string, value: number | string | boolean | null | undefined): this {
|
|
153
|
+
const i = this.ids.indexOf(id)
|
|
154
|
+
if (i < 0) {
|
|
155
|
+
console.warn(`UITabs.badge: unknown tab "${id}"`)
|
|
156
|
+
return this
|
|
157
|
+
}
|
|
158
|
+
if (value === null || value === undefined || value === false || value === 0 || value === "") {
|
|
159
|
+
this._badges[i].style.display = "none"
|
|
160
|
+
} else if (value === true) {
|
|
161
|
+
this._badgeTexts[i].text = ""
|
|
162
|
+
this._badges[i].style({ display: "flex", width: 9, height: 9, minWidth: 0, px: 0 })
|
|
163
|
+
} else {
|
|
164
|
+
this._badgeTexts[i].text = String(value)
|
|
165
|
+
this._badges[i].style({ display: "flex", width: "auto", height: 14, minWidth: 14, px: 4 })
|
|
166
|
+
}
|
|
167
|
+
return this
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/** Create the standard bottom-tab shell — see {@link UITabs}. Keys are tab ids in tab order;
|
|
172
|
+
* each tab needs a `label` and its root `screen` (plus an optional `icon`). */
|
|
173
|
+
export function UITabs(tabs: Record<string, UITabDef>): UITabs {
|
|
174
|
+
return new TabsElement(tabs) as unknown as UITabs
|
|
175
|
+
}
|
package/runtime/sdk/ui/UIText.ts
CHANGED
|
@@ -3,8 +3,10 @@ import { Element, type AnimateStyle, type BaseStyle, type DrawableStyle, type El
|
|
|
3
3
|
|
|
4
4
|
export type UITextStyle = ElementStyle & TextStyle & DrawableStyle
|
|
5
5
|
|
|
6
|
+
/** A text label. */
|
|
6
7
|
export interface UIText {
|
|
7
8
|
readonly type: "text",
|
|
9
|
+
/** The displayed string — writable at any time. */
|
|
8
10
|
text: string,
|
|
9
11
|
style: Style<this, UITextStyle>,
|
|
10
12
|
animateTo: AnimateStyle<this, DrawableStyle & BaseStyle & TextStyle>
|
|
@@ -46,7 +48,10 @@ export class TextElement extends Element<"text"> {
|
|
|
46
48
|
}
|
|
47
49
|
}
|
|
48
50
|
|
|
51
|
+
/** Create a text label — a string, or `() => string` for reactive text that re-renders when a
|
|
52
|
+
* signal it read changes. */
|
|
49
53
|
export function UIText(text: string | (() => string)): UIText;
|
|
54
|
+
/** @deprecated Style as the first argument is legacy — use chained `.style({...})`. */
|
|
50
55
|
export function UIText(style: UITextStyle, text: string | (() => string)): UIText;
|
|
51
56
|
export function UIText(...args: [string | (() => string)] | [UITextStyle, string | (() => string)]): UIText {
|
|
52
57
|
if (args.length === 1) {
|
|
@@ -4,8 +4,11 @@ import { Element, type AnimateStyle, type AppearStyle, type BaseStyle, type Disa
|
|
|
4
4
|
|
|
5
5
|
export type UIVideoStyle = ElementStyle & DrawableStyle & { objectFit?: "cover" | "contain" | "fill" }
|
|
6
6
|
|
|
7
|
+
/** A video surface showing a `VideoPlayer`'s output — embeddable in a screen AND
|
|
8
|
+
* fullscreen-presentable (`open()`), with seamless promotion between the two. */
|
|
7
9
|
export interface UIVideo {
|
|
8
10
|
readonly type: "video",
|
|
11
|
+
/** The player driving this surface (playback control lives on it). */
|
|
9
12
|
player: VideoPlayer
|
|
10
13
|
style: Style<this, UIVideoStyle>
|
|
11
14
|
animateTo: AnimateStyle<this, DrawableStyle & BaseStyle>
|
|
@@ -79,7 +82,9 @@ class VideoElement extends Element<"video"> implements Presentable {
|
|
|
79
82
|
}
|
|
80
83
|
}
|
|
81
84
|
|
|
85
|
+
/** Create a video node showing `player`'s output. */
|
|
82
86
|
export function UIVideo(player: VideoPlayer): UIVideo
|
|
87
|
+
/** @deprecated Style as the first argument is legacy — use chained `.style({...})`. */
|
|
83
88
|
export function UIVideo(style: UIVideoStyle, player: VideoPlayer): UIVideo
|
|
84
89
|
export function UIVideo(...args: [VideoPlayer] | [UIVideoStyle, VideoPlayer]): UIVideo {
|
|
85
90
|
if (args.length === 1) {
|
|
@@ -1,41 +1,43 @@
|
|
|
1
1
|
import { Element, type Color, type DrawableStyle, type ElementStyle, type OnLayoutCallback, type BoundingClientRect, type PaddingStyle, type Classes, type Style, type UINodeChild } from "./UINode"
|
|
2
2
|
|
|
3
|
-
// refreshControlColor tints the native pull-to-refresh spinner (pairs with onRefresh).
|
|
4
|
-
// keyboardDismissMode: same key and semantics as UIScrollable's — hosts treat a vlist as a scroll
|
|
5
|
-
// container, so it always honored this; only the type was missing. A chat is the reason it exists:
|
|
6
|
-
// "none" keeps the composer's keyboard up no matter how the history is scrolled.
|
|
7
3
|
export type UIVirtualizedListStyle = DrawableStyle & ElementStyle & {
|
|
4
|
+
/** Tint of the native pull-to-refresh spinner (pairs with `onRefresh`). */
|
|
8
5
|
refreshControlColor?: Color,
|
|
6
|
+
/** Same key and semantics as UIScrollable's; `"none"` keeps a chat composer's keyboard up no
|
|
7
|
+
* matter how the history is scrolled. */
|
|
9
8
|
keyboardDismissMode?: "interactive" | "scroll" | "none",
|
|
10
9
|
}
|
|
11
10
|
|
|
12
11
|
export interface VListConfig<T> {
|
|
13
|
-
/**
|
|
12
|
+
/** Stable unique key of an item. */
|
|
14
13
|
keyOf: (item: T) => string
|
|
15
|
-
/**
|
|
14
|
+
/** Subtree factory — called when the item enters the window; the subtree lives until it
|
|
15
|
+
* leaves. */
|
|
16
16
|
render: (item: T) => UINodeChild
|
|
17
|
-
/**
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
* Вычисляется один раз при добавлении айтема, в нативку уходит готовое число.
|
|
21
|
-
*/
|
|
17
|
+
/** Height estimate (px) used before the first measurement — a number, or a per-item function
|
|
18
|
+
* (chat: `msg => 40 + Math.ceil(msg.text.length / 35) * 20`). Computed once when the item is
|
|
19
|
+
* added. */
|
|
22
20
|
estimatedHeight: number | ((item: T) => number)
|
|
23
|
-
/** px
|
|
21
|
+
/** Extra px around the viewport kept mounted. Default: one viewport height. */
|
|
24
22
|
overscan?: number
|
|
25
|
-
/**
|
|
23
|
+
/** Chat mode: the first layout starts scrolled to the end, and appends auto-scroll while the
|
|
24
|
+
* list sits at the bottom. */
|
|
26
25
|
inverted?: boolean
|
|
27
26
|
}
|
|
28
27
|
|
|
28
|
+
/** A windowed (virtualized) list: only the items near the viewport are mounted — for long feeds
|
|
29
|
+
* and chats. Items are keyed; feed it via `setData`/`append`/`prepend`. */
|
|
29
30
|
export interface UIVirtualizedList<T = unknown> {
|
|
30
31
|
readonly type: "vlist"
|
|
31
32
|
style: Style<this, UIVirtualizedListStyle>
|
|
32
33
|
|
|
33
|
-
/**
|
|
34
|
+
/** Replace the data wholesale — vanished keys are unmounted by the host's window sync. */
|
|
34
35
|
setData(items: T[]): this
|
|
35
36
|
append(...items: T[]): this
|
|
36
|
-
/**
|
|
37
|
+
/** Insert at the start WITHOUT a scroll jump (the host compensates the offset). */
|
|
37
38
|
prepend(...items: T[]): this
|
|
38
|
-
/**
|
|
39
|
+
/** Update items with the same keys: mounted ones re-render; the cached height persists until
|
|
40
|
+
* re-measured. */
|
|
39
41
|
update(...items: T[]): this
|
|
40
42
|
removeByKey(...keys: string[]): this
|
|
41
43
|
|
|
@@ -47,12 +49,13 @@ export interface UIVirtualizedList<T = unknown> {
|
|
|
47
49
|
scrollToEnd(animated?: boolean): void
|
|
48
50
|
|
|
49
51
|
onScroll(callback: (scrollPosition: number) => void): this
|
|
50
|
-
/** Pull-to-refresh:
|
|
51
|
-
* (
|
|
52
|
+
/** Pull-to-refresh: the spinner stays until the returned promise settles. Attach BEFORE the
|
|
53
|
+
* node mounts (hosts read it at creation). Native hosts only — no-op on web. */
|
|
52
54
|
onRefresh(callback: () => void | Promise<void>): this
|
|
53
|
-
/**
|
|
55
|
+
/** Fires within `thresholdPx` of the content's bottom edge — once, re-armed after leaving the
|
|
56
|
+
* edge (host-side latch). Infinite-scroll loading. */
|
|
54
57
|
onEndReached(thresholdPx: number, callback: () => void): this
|
|
55
|
-
/**
|
|
58
|
+
/** Same, for the top edge — chat history loading. */
|
|
56
59
|
onStartReached(thresholdPx: number, callback: () => void): this
|
|
57
60
|
onLayout(onLayout: OnLayoutCallback): this
|
|
58
61
|
getBoundingClientRect(): BoundingClientRect | null
|
|
@@ -65,11 +68,11 @@ export interface UIVirtualizedList<T = unknown> {
|
|
|
65
68
|
|
|
66
69
|
export class VListElement<T> extends Element<"vlist"> implements UIVirtualizedList<T> {
|
|
67
70
|
|
|
68
|
-
// ---
|
|
69
|
-
_overscan: number
|
|
71
|
+
// --- read by native side in createUINode (copyProperty / copyNodePtr) ---
|
|
72
|
+
_overscan: number
|
|
70
73
|
_inverted: boolean
|
|
71
|
-
_keys: string[] = []
|
|
72
|
-
_estimates: number[] = []
|
|
74
|
+
_keys: string[] = []
|
|
75
|
+
_estimates: number[] = []
|
|
73
76
|
_endThreshold = 0
|
|
74
77
|
_startThreshold = 0
|
|
75
78
|
|
|
@@ -123,12 +126,8 @@ export class VListElement<T> extends Element<"vlist"> implements UIVirtualizedLi
|
|
|
123
126
|
this._keys = keys
|
|
124
127
|
this._estimates = estimates
|
|
125
128
|
if (this.isAttached) {
|
|
126
|
-
// нативка диффает по ключам: исчезнувшие смонтированные ключи придут в _syncWindow как unmount
|
|
127
129
|
_creatorUI.vlistSetKeys(this, keys, estimates)
|
|
128
|
-
|
|
129
|
-
// старое поддерево. Если объект данных изменился, перерисовываем их (как update), иначе
|
|
130
|
-
// строки остаются со старым содержимым. На вебе экран в истории держит айтемы
|
|
131
|
-
// смонтированными, поэтому без этого повторный setData их не обновлял.
|
|
130
|
+
|
|
132
131
|
for (const k of prevMounted) {
|
|
133
132
|
if (this.mounted.has(k) && this.items.get(k) !== prevItems.get(k)) {
|
|
134
133
|
_creatorUI.vlistInvalidate(this, k)
|
|
@@ -143,7 +142,6 @@ export class VListElement<T> extends Element<"vlist"> implements UIVirtualizedLi
|
|
|
143
142
|
this._keys.push(...keys)
|
|
144
143
|
this._estimates.push(...estimates)
|
|
145
144
|
if (this.isAttached) {
|
|
146
|
-
// inverted + позиция внизу → нативка автоскроллит к концу
|
|
147
145
|
_creatorUI.vlistInsertKeys(this, -1, keys, estimates)
|
|
148
146
|
}
|
|
149
147
|
return this
|
|
@@ -154,7 +152,6 @@ export class VListElement<T> extends Element<"vlist"> implements UIVirtualizedLi
|
|
|
154
152
|
this._keys.unshift(...keys)
|
|
155
153
|
this._estimates.unshift(...estimates)
|
|
156
154
|
if (this.isAttached) {
|
|
157
|
-
// нативка компенсирует scrollY на сумму estimates — позиция не прыгает
|
|
158
155
|
_creatorUI.vlistInsertKeys(this, 0, keys, estimates)
|
|
159
156
|
}
|
|
160
157
|
return this
|
|
@@ -166,8 +163,6 @@ export class VListElement<T> extends Element<"vlist"> implements UIVirtualizedLi
|
|
|
166
163
|
if (!this.items.has(k)) continue
|
|
167
164
|
this.items.set(k, item)
|
|
168
165
|
if (this.isAttached && this.mounted.has(k)) {
|
|
169
|
-
// unmount+mount, кэш высоты сохраняется до повторного измерения.
|
|
170
|
-
// Несмонтированный айтем перерендерится сам при входе в окно
|
|
171
166
|
_creatorUI.vlistInvalidate(this, k)
|
|
172
167
|
}
|
|
173
168
|
}
|
|
@@ -221,12 +216,9 @@ export class VListElement<T> extends Element<"vlist"> implements UIVirtualizedLi
|
|
|
221
216
|
return this
|
|
222
217
|
}
|
|
223
218
|
|
|
224
|
-
/**
|
|
225
|
-
*
|
|
226
|
-
*
|
|
227
|
-
* Порядок: сначала unmount (нативка уже снесла поддеревья и обнулила _id,
|
|
228
|
-
* здесь только чистим JS-ссылки), потом mount.
|
|
229
|
-
*/
|
|
219
|
+
/** @internal The one host→JS callback (via jsPtr, like button). Fires ONLY when the window
|
|
220
|
+
* crossed a boundary — not per scroll frame. Order: unmounts first (the host already tore the
|
|
221
|
+
* subtrees down and zeroed _id; only JS refs are cleaned here), then mounts. */
|
|
230
222
|
_syncWindow(unmountKeys: string[], mountKeys: string[]): void {
|
|
231
223
|
for (const k of unmountKeys) {
|
|
232
224
|
this.mounted.delete(k)
|
|
@@ -242,6 +234,8 @@ export class VListElement<T> extends Element<"vlist"> implements UIVirtualizedLi
|
|
|
242
234
|
}
|
|
243
235
|
}
|
|
244
236
|
|
|
237
|
+
/** Create a virtualized list from a config (`keyOf` + `render` + `estimatedHeight` required),
|
|
238
|
+
* then feed it via `setData`/`append`/`prepend`. Give it a size (`flexGrow: 1` as a screen body). */
|
|
245
239
|
export function UIVirtualizedList<T>(config: VListConfig<T>): UIVirtualizedList<T> {
|
|
246
240
|
return new VListElement<T>(config)
|
|
247
241
|
}
|
|
@@ -1,15 +1,18 @@
|
|
|
1
1
|
import { TouchStartEvent } from "../runtime/touch"
|
|
2
2
|
import { _descOf, _navSupported, Presentable } from "./presentable"
|
|
3
|
-
import { ContainerElement, type AnimateStyle, type BaseStyle, type Color, type ContainerStyle, type DrawableStyle, type OnLayoutCallback, type BoundingClientRect, type PaddingStyle, type PositionStyle, type Classes, type Style, type UINodeChild, type ChildrenFn } from "./UINode"
|
|
3
|
+
import { ContainerElement, buildUI, type AnimateStyle, type BaseStyle, type Color, type ContainerStyle, type DrawableStyle, type OnLayoutCallback, type BoundingClientRect, type PaddingStyle, type PositionStyle, type Classes, type Style, type UIChildArg, type UINodeChild, type ChildrenFn } from "./UINode"
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
export type UIWidgetStyle = ContainerStyle & DrawableStyle & PaddingStyle & BaseStyle & PositionStyle & {
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
/** A layer behind the widget that intercepts clicks — `"transparent"` still intercepts, `null`
|
|
8
|
+
* removes the layer. A tap on it fires `onOverlayTap`. */
|
|
9
9
|
overlayColor?: Color | null
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
|
|
13
|
+
/** A floating overlay — absolutely positioned in device coordinates, mounted above the page as
|
|
14
|
+
* its own layout root (never a child of what's underneath). The base of dialogs, toasts,
|
|
15
|
+
* mini-players and scene HUDs; `UIModal`/`UIPopover`/`UIBottomSheet` build on it. */
|
|
13
16
|
export interface UIWidget {
|
|
14
17
|
readonly type: "widget",
|
|
15
18
|
style: Style<this, UIWidgetStyle>,
|
|
@@ -33,8 +36,10 @@ export interface UIWidget {
|
|
|
33
36
|
* widget was attached via `attachTo(owner)`, it mounts on that page's layer instead and is
|
|
34
37
|
* only visible while the owner is presented. */
|
|
35
38
|
show(): void,
|
|
39
|
+
/** Unmount the widget. */
|
|
36
40
|
hide(): void,
|
|
37
41
|
|
|
42
|
+
/** Mounted right now (`show()` ran, `hide()` hasn't). */
|
|
38
43
|
readonly isShow: boolean,
|
|
39
44
|
|
|
40
45
|
append(...nodes: UINodeChild[]): UIWidget
|
|
@@ -47,7 +52,9 @@ export interface UIWidget {
|
|
|
47
52
|
onLayout(onLayout: OnLayoutCallback): this
|
|
48
53
|
getBoundingClientRect(): BoundingClientRect | null
|
|
49
54
|
onTouchStart(callback: (ev: TouchStartEvent<UIWidget>) => void): this,
|
|
55
|
+
/** Tap on the overlay layer (requires an `overlayColor`). */
|
|
50
56
|
onOverlayTap(callback: () => void): this,
|
|
57
|
+
/** Hardware/system back while the widget is shown. */
|
|
51
58
|
onBackPressed(callback: () => void): this
|
|
52
59
|
|
|
53
60
|
/** Style-class proxy — read `el.class.checked`, set `el.class.checked = true`, toggle with
|
|
@@ -120,20 +127,17 @@ export class WidgetElement extends ContainerElement<"widget"> {
|
|
|
120
127
|
}
|
|
121
128
|
|
|
122
129
|
|
|
123
|
-
|
|
130
|
+
const makeWidget = (style: any, children: any) => new WidgetElement("widget", style, children)
|
|
131
|
+
|
|
132
|
+
/** @internal Compiler fast path (chisel `flatten_ui` raw lowering) — see UIContainer. */
|
|
133
|
+
export const __UIWidget = (children: UINodeChild[] | ChildrenFn): UIWidget => makeWidget({}, children)
|
|
134
|
+
|
|
135
|
+
/** Create a widget (same argument forms as `UIColumn`). Position it with absolute-style props
|
|
136
|
+
* (`top`/`left`/`bottom`/`right`), then `show()`/`hide()`. */
|
|
137
|
+
export function UIWidget(...children: UIChildArg[]): UIWidget;
|
|
124
138
|
export function UIWidget(children: UINodeChild[] | ChildrenFn): UIWidget;
|
|
125
|
-
|
|
126
|
-
export function UIWidget(style: UIWidgetStyle, children
|
|
127
|
-
export function UIWidget(...args: []
|
|
128
|
-
|
|
129
|
-
return new WidgetElement("widget", {}, [])
|
|
130
|
-
} else if (args.length === 1) {
|
|
131
|
-
if (Array.isArray(args[0]) || typeof args[0] === "function") {
|
|
132
|
-
return new WidgetElement("widget", {}, args[0])
|
|
133
|
-
} else {
|
|
134
|
-
return new WidgetElement("widget", args[0], [])
|
|
135
|
-
}
|
|
136
|
-
} else {
|
|
137
|
-
return new WidgetElement("widget", args[0], args[1])
|
|
138
|
-
}
|
|
139
|
+
/** @deprecated Style as the first argument is legacy — use chained `.style({...})`. */
|
|
140
|
+
export function UIWidget(style: UIWidgetStyle, children?: UINodeChild[] | ChildrenFn): UIWidget;
|
|
141
|
+
export function UIWidget(...args: any[]): UIWidget {
|
|
142
|
+
return buildUI(args, null, makeWidget)
|
|
139
143
|
}
|
package/runtime/sdk/ui/fonts.ts
CHANGED
|
@@ -3,6 +3,9 @@ type FontOptions = {
|
|
|
3
3
|
style?: "normal" | "italic"
|
|
4
4
|
}
|
|
5
5
|
|
|
6
|
+
/** Register a font face from a URL at runtime under `fontFamily`; resolves once it's ready to
|
|
7
|
+
* use in styles. For registry/project fonts prefer the compile-time `font()` macro — this is the
|
|
8
|
+
* dynamic escape hatch. */
|
|
6
9
|
export async function registerFont (fontFamily: string, url: string, options: FontOptions = {}): Promise<void> {
|
|
7
10
|
return new Promise<void>((res, rej) => {
|
|
8
11
|
_creatorUI.registerFont(fontFamily, url, options, res, rej)
|
package/runtime/sdk/ui/router.ts
CHANGED
|
@@ -11,8 +11,13 @@ type NavigateOptions = {
|
|
|
11
11
|
transition?: Transition
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
+
/** Stack navigation over `Presentable` destinations. `init` once with the home page, then
|
|
15
|
+
* `push`/`replace`/`pop`; the back gesture/button pops natively. A direct `page.open()` suspends
|
|
16
|
+
* the router until `restore()`. */
|
|
14
17
|
type Router = {
|
|
18
|
+
/** The top of the router stack (not necessarily what's on screen — see `Presentable.current`). */
|
|
15
19
|
get current(): Presentable
|
|
20
|
+
/** Mount the router with `homePage` as the stack root — the app's navigation entry point. */
|
|
16
21
|
init(homePage: Presentable, opts?: RouterOptions): void
|
|
17
22
|
/** Push a destination onto the stack — a `UIScreen`, a `Scene`, a `Scene2D`, a `NativeView`,
|
|
18
23
|
* or a `UIVideo`. The back gesture/button pops it. Destinations with async preparation
|
|
@@ -20,11 +25,19 @@ type Router = {
|
|
|
20
25
|
* visible until they're ready, and a rejection (permission denied / superseded) leaves the
|
|
21
26
|
* stack untouched. */
|
|
22
27
|
push(page: Presentable, opts?: NavigateOptions): void | Promise<void>
|
|
28
|
+
/** Swap the top of the stack for `page` — no back entry to the replaced one. */
|
|
23
29
|
replace(page: Presentable, opts?: NavigateOptions): void | Promise<void>
|
|
30
|
+
/** Pop the top destination (the programmatic twin of the back gesture); `to` unwinds to a
|
|
31
|
+
* stack index in one step. */
|
|
24
32
|
pop(to?: number, opts?: NavigateOptions): void
|
|
33
|
+
/** Blank the router's page, keeping the stack — `restore()` brings it back. A destination
|
|
34
|
+
* opened directly stays visible. */
|
|
25
35
|
hide(): void
|
|
36
|
+
/** Re-present the stack top after `hide()` or a direct `open()` suspended the router. */
|
|
26
37
|
restore(): void
|
|
27
38
|
|
|
39
|
+
/** `"change"` fires on every stack change — pushes, pops, and native back gestures — with the
|
|
40
|
+
* new top destination. */
|
|
28
41
|
addEventListener(channel: "change", callback: (page: Presentable) => void): void
|
|
29
42
|
removeEventListener(channel: "change", callback: (page: Presentable) => void): void
|
|
30
43
|
}
|
package/runtime/sdk/ui/theme.ts
CHANGED
|
@@ -1,29 +1,7 @@
|
|
|
1
|
-
// theme() — app theme variables (docs/ui-theme-plan.md).
|
|
2
|
-
//
|
|
3
|
-
//
|
|
4
|
-
// `
|
|
5
|
-
// theme() with new values re-styles the LIVE UI (dark mode is just a second call). Two access
|
|
6
|
-
// forms with one rule: bare style tokens (`pt: "comfort-top"`) are keywords that may expand to
|
|
7
|
-
// formulas (max(safe-top, knob)); `var(--comfort-top)` always reads the raw table value (the
|
|
8
|
-
// knob itself).
|
|
9
|
-
//
|
|
10
|
-
// theme(values) MERGES into the table and returns typed accessors whose values ARE the var()
|
|
11
|
-
// strings — define once in a module, import where custom keys need typing:
|
|
12
|
-
//
|
|
13
|
-
// export const T = theme({ primaryColor: "#0A84FF", cardBg: "#1C1C1E" })
|
|
14
|
-
// card.style({ bgColor: T.cardBg }) // T.cardBg === "var(--cardBg)"
|
|
15
|
-
//
|
|
16
|
-
// System vars need no import — they're static properties on the callable itself:
|
|
17
|
-
// theme.primaryColor, theme.fontFamily, theme["comfort-top"], …
|
|
18
|
-
//
|
|
19
|
-
// Values: strings pass through (colors, fonts, expressions like "max(safe-top, 24px)");
|
|
20
|
-
// numbers are LENGTHS (px). `null` removes a key (comfort knobs reset to their defaults:
|
|
21
|
-
// 12 vertical, 16 horizontal — the page gutter). Env names (safe-*, vw/vh/vmin/vmax) are
|
|
22
|
-
// host-owned facts, never theme keys — they're skipped with a warning.
|
|
23
|
-
//
|
|
24
|
-
// One key is not a style var: `replaceTransition` — the app-wide default for
|
|
25
|
-
// `Router.replace` (any Transition, name or custom spec; `null` resets to "none"). The
|
|
26
|
-
// router resolves it in the SDK, so it's consumed here and never sent to the host table.
|
|
1
|
+
// theme() — app theme variables (docs/ui-theme-plan.md). One global var table lives in the UI
|
|
2
|
+
// core; `var(--key)` references resolve at style-apply time, so re-calling theme() re-styles the
|
|
3
|
+
// LIVE UI. Bare style tokens (`pt: "comfort-top"`) are keywords that may expand to formulas
|
|
4
|
+
// (max(safe-top, knob)); `var(--comfort-top)` always reads the raw table value.
|
|
27
5
|
|
|
28
6
|
import type { Transition } from "./presentable"
|
|
29
7
|
|
|
@@ -41,10 +19,20 @@ export type ThemeAccessors<T> = {
|
|
|
41
19
|
|
|
42
20
|
const RESERVED = ["safe-top", "safe-bottom", "safe-left", "safe-right", "vw", "vh", "vmin", "vmax"]
|
|
43
21
|
|
|
44
|
-
/**
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
*
|
|
22
|
+
/**
|
|
23
|
+
* Merge app theme variables into the live table and get typed `var(--key)` accessors back:
|
|
24
|
+
*
|
|
25
|
+
* ```ts
|
|
26
|
+
* export const T = theme({ primaryColor: "#0A84FF", cardBg: "#1C1C1E" })
|
|
27
|
+
* card.style({ bgColor: T.cardBg }) // T.cardBg === "var(--cardBg)"
|
|
28
|
+
* ```
|
|
29
|
+
*
|
|
30
|
+
* Strings pass through (colors, fonts, expressions like `"max(safe-top, 24px)"`); numbers are
|
|
31
|
+
* lengths (px); `null` removes a key (comfort knobs reset to their defaults). Env names
|
|
32
|
+
* (`safe-*`, `vw`/`vh`/…) are host-owned — skipped with a warning. One special key:
|
|
33
|
+
* `replaceTransition` — the app-wide default transition for `Router.replace` (consumed SDK-side,
|
|
34
|
+
* never sent to the host table).
|
|
35
|
+
*/
|
|
48
36
|
const setTheme = <T extends Record<string, string | number | Transition | null>>(
|
|
49
37
|
// Only `replaceTransition` may carry a Transition — every other key is a style value.
|
|
50
38
|
values: T & { [K in Exclude<keyof T, "replaceTransition">]: string | number | null }
|
|
@@ -73,6 +61,9 @@ const setTheme = <T extends Record<string, string | number | Transition | null>>
|
|
|
73
61
|
return accessors as ThemeAccessors<Omit<T, "replaceTransition">>
|
|
74
62
|
}
|
|
75
63
|
|
|
64
|
+
/** App theme: callable to merge variables (`theme({...})` — re-calling re-styles the live UI, so
|
|
65
|
+
* dark mode is just a second call), with the system vars as static properties
|
|
66
|
+
* (`theme.primaryColor`, `theme["comfort-top"]`, …). */
|
|
76
67
|
export const theme = Object.assign(setTheme, {
|
|
77
68
|
/** The app accent color. Kit components will read it via `var(--primaryColor, <fallback>)`. */
|
|
78
69
|
primaryColor: "var(--primaryColor)",
|