lecodes-cli 0.10.3 → 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 +2 -1
- package/dist/index.js +3480 -1527
- 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/runtime/channel.ts +14 -3
- package/runtime/sdk/runtime/service.ts +1 -1
- package/runtime/sdk/ui/NativeView.ts +4 -1
- 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 +37 -37
- package/runtime/sdk/ui/UIWidget.ts +24 -19
- 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
|
@@ -1,19 +1,26 @@
|
|
|
1
1
|
import type { UIContainerStyle } from "./UIContainer"
|
|
2
|
-
import { type Classes, type Style, type AnimateStyle, type UINodeChild, type ChildrenFn, type OnLayoutCallback, type BoundingClientRect, type Color, ContainerElement } from "./UINode"
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
2
|
+
import { type Classes, type Style, type AnimateStyle, type UIChildArg, type UINodeChild, type ChildrenFn, type OnLayoutCallback, type BoundingClientRect, type Color, ContainerElement, buildUI } from "./UINode"
|
|
3
|
+
|
|
4
|
+
export type ScrollStyle = {
|
|
5
|
+
showScrollbar?: boolean,
|
|
6
|
+
overscrollMode?: "none" | "absorb" | "default",
|
|
7
|
+
/** Tint of the native pull-to-refresh spinner (pairs with `onRefresh`). */
|
|
8
|
+
refreshControlColor?: Color,
|
|
9
|
+
/** How a scroll gesture in THIS scrollable dismisses the keyboard: `"interactive"` (default) —
|
|
10
|
+
* dragging over the keyboard slides it away (chat feel); `"scroll"` — any drag dismisses
|
|
11
|
+
* immediately; `"none"` — never (tap-outside policy still applies). */
|
|
12
|
+
keyboardDismissMode?: "interactive" | "scroll" | "none",
|
|
13
|
+
/** Paging: when the drag ends, rest on a direct child's boundary along the scroll axis — the
|
|
14
|
+
* value picks where the child sits in the viewport; `"none"` (default) is free scrolling. Snap
|
|
15
|
+
* targets are the children themselves, so item widths can differ (card-carousel-with-peek); a
|
|
16
|
+
* carousel is a horizontal scrollable of full-width children + `snap: "start"`. */
|
|
17
|
+
snap?: "none" | "start" | "center" | "end"
|
|
18
|
+
}
|
|
14
19
|
|
|
15
20
|
export type UIScrollableStyle = UIContainerStyle & ScrollStyle & { scrollDirection?: "horizontal" | "vertical" }
|
|
16
21
|
|
|
22
|
+
/** A scroll container — vertical by default, `scrollDirection: "horizontal"` for carousels/chip
|
|
23
|
+
* rows. The scrolling body of a screen (screens themselves never scroll). */
|
|
17
24
|
export interface UIScrollable {
|
|
18
25
|
readonly type: "scrollable",
|
|
19
26
|
style: Style<this, UIScrollableStyle>,
|
|
@@ -33,8 +40,11 @@ export interface UIScrollable {
|
|
|
33
40
|
* Classes cascade to descendants. See {@link Classes}. */
|
|
34
41
|
readonly class: Classes<this>
|
|
35
42
|
|
|
43
|
+
/** Scroll position changed (px from the start edge). */
|
|
36
44
|
onScroll(callback: (scrollPosition: number) => void): UIScrollable,
|
|
45
|
+
/** The scroll gesture ended (finger lifted). */
|
|
37
46
|
onScrollRelease(callback: () => void): UIScrollable,
|
|
47
|
+
/** Pulled past the content edge by `delta` px. */
|
|
38
48
|
onOverscroll(callback: (delta: number) => void): UIScrollable
|
|
39
49
|
/** Pull-to-refresh: the spinner stays until the returned promise settles. Attach BEFORE the
|
|
40
50
|
* node mounts (hosts read it at creation). Vertical only; native hosts — no-op on web. */
|
|
@@ -76,22 +86,20 @@ class ScrollableElement extends ContainerElement<"scrollable"> {
|
|
|
76
86
|
}
|
|
77
87
|
}
|
|
78
88
|
|
|
79
|
-
|
|
89
|
+
// flexShrink: 1 default (SDK-owned, like UIRow's flexDirection): without it a scrollable in a
|
|
90
|
+
// flex parent grows to its content height and overflows instead of scrolling.
|
|
91
|
+
const SCROLLABLE_DEFAULTS = { flexShrink: 1 } as const
|
|
92
|
+
const makeScrollable = (style: any, children: any) => new ScrollableElement("scrollable", style, children)
|
|
93
|
+
|
|
94
|
+
/** @internal Compiler fast path (chisel `flatten_ui` raw lowering) — see UIContainer. */
|
|
95
|
+
export const __UIScrollable = (children: UINodeChild[] | ChildrenFn): UIScrollable => makeScrollable({ ...SCROLLABLE_DEFAULTS }, children)
|
|
96
|
+
|
|
97
|
+
/** Create a scroll container (same argument forms as `UIColumn`). As a screen body, pair with
|
|
98
|
+
* `flexGrow: 1`. */
|
|
99
|
+
export function UIScrollable(...children: UIChildArg[]): UIScrollable
|
|
80
100
|
export function UIScrollable(children: UINodeChild[] | ChildrenFn): UIScrollable
|
|
81
|
-
|
|
82
|
-
export function UIScrollable(style: UIScrollableStyle, children
|
|
83
|
-
export function UIScrollable(...args: []
|
|
84
|
-
|
|
85
|
-
// flex parent grows to its content height and overflows instead of scrolling.
|
|
86
|
-
if (args.length === 0) {
|
|
87
|
-
return new ScrollableElement("scrollable", { flexShrink: 1 }, [])
|
|
88
|
-
} else if (args.length === 1) {
|
|
89
|
-
if (Array.isArray(args[0]) || typeof args[0] === "function") {
|
|
90
|
-
return new ScrollableElement("scrollable", { flexShrink: 1 }, args[0])
|
|
91
|
-
} else {
|
|
92
|
-
return new ScrollableElement("scrollable", { flexShrink: 1, ...args[0] }, [])
|
|
93
|
-
}
|
|
94
|
-
} else {
|
|
95
|
-
return new ScrollableElement("scrollable", { flexShrink: 1, ...args[0] }, args[1])
|
|
96
|
-
}
|
|
101
|
+
/** @deprecated Style as the first argument is legacy — use chained `.style({...})`. */
|
|
102
|
+
export function UIScrollable(style: UIScrollableStyle, children?: UINodeChild[] | ChildrenFn): UIScrollable
|
|
103
|
+
export function UIScrollable(...args: any[]): UIScrollable {
|
|
104
|
+
return buildUI(args, SCROLLABLE_DEFAULTS, makeScrollable)
|
|
97
105
|
}
|
|
@@ -2,6 +2,7 @@ import { Element, type ElementStyle, type Classes, type Style, type StyleFn } fr
|
|
|
2
2
|
|
|
3
3
|
export type UISpacerStyle = ElementStyle
|
|
4
4
|
|
|
5
|
+
/** A flexible gap — `flexGrow: 1` by default, pushes its siblings apart. */
|
|
5
6
|
export interface UISpacer {
|
|
6
7
|
readonly type: "spacer",
|
|
7
8
|
style: Style<this, UISpacerStyle>,
|
|
@@ -11,6 +12,7 @@ export interface UISpacer {
|
|
|
11
12
|
* Classes cascade to descendants. See {@link Classes}. */
|
|
12
13
|
readonly class: Classes<this>
|
|
13
14
|
}
|
|
15
|
+
/** Create a flexible gap (`flexGrow: 1`) — e.g. between a header's title and its actions. */
|
|
14
16
|
export function UISpacer(): UISpacer
|
|
15
17
|
export function UISpacer(style: UISpacerStyle): UISpacer
|
|
16
18
|
export function UISpacer(style?: UISpacerStyle): UISpacer {
|
|
@@ -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,35 +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
|
-
|
|
4
|
-
|
|
3
|
+
export type UIVirtualizedListStyle = DrawableStyle & ElementStyle & {
|
|
4
|
+
/** Tint of the native pull-to-refresh spinner (pairs with `onRefresh`). */
|
|
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. */
|
|
8
|
+
keyboardDismissMode?: "interactive" | "scroll" | "none",
|
|
9
|
+
}
|
|
5
10
|
|
|
6
11
|
export interface VListConfig<T> {
|
|
7
|
-
/**
|
|
12
|
+
/** Stable unique key of an item. */
|
|
8
13
|
keyOf: (item: T) => string
|
|
9
|
-
/**
|
|
14
|
+
/** Subtree factory — called when the item enters the window; the subtree lives until it
|
|
15
|
+
* leaves. */
|
|
10
16
|
render: (item: T) => UINodeChild
|
|
11
|
-
/**
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
* Вычисляется один раз при добавлении айтема, в нативку уходит готовое число.
|
|
15
|
-
*/
|
|
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. */
|
|
16
20
|
estimatedHeight: number | ((item: T) => number)
|
|
17
|
-
/** px
|
|
21
|
+
/** Extra px around the viewport kept mounted. Default: one viewport height. */
|
|
18
22
|
overscan?: number
|
|
19
|
-
/**
|
|
23
|
+
/** Chat mode: the first layout starts scrolled to the end, and appends auto-scroll while the
|
|
24
|
+
* list sits at the bottom. */
|
|
20
25
|
inverted?: boolean
|
|
21
26
|
}
|
|
22
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`. */
|
|
23
30
|
export interface UIVirtualizedList<T = unknown> {
|
|
24
31
|
readonly type: "vlist"
|
|
25
32
|
style: Style<this, UIVirtualizedListStyle>
|
|
26
33
|
|
|
27
|
-
/**
|
|
34
|
+
/** Replace the data wholesale — vanished keys are unmounted by the host's window sync. */
|
|
28
35
|
setData(items: T[]): this
|
|
29
36
|
append(...items: T[]): this
|
|
30
|
-
/**
|
|
37
|
+
/** Insert at the start WITHOUT a scroll jump (the host compensates the offset). */
|
|
31
38
|
prepend(...items: T[]): this
|
|
32
|
-
/**
|
|
39
|
+
/** Update items with the same keys: mounted ones re-render; the cached height persists until
|
|
40
|
+
* re-measured. */
|
|
33
41
|
update(...items: T[]): this
|
|
34
42
|
removeByKey(...keys: string[]): this
|
|
35
43
|
|
|
@@ -41,12 +49,13 @@ export interface UIVirtualizedList<T = unknown> {
|
|
|
41
49
|
scrollToEnd(animated?: boolean): void
|
|
42
50
|
|
|
43
51
|
onScroll(callback: (scrollPosition: number) => void): this
|
|
44
|
-
/** Pull-to-refresh:
|
|
45
|
-
* (
|
|
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. */
|
|
46
54
|
onRefresh(callback: () => void | Promise<void>): this
|
|
47
|
-
/**
|
|
55
|
+
/** Fires within `thresholdPx` of the content's bottom edge — once, re-armed after leaving the
|
|
56
|
+
* edge (host-side latch). Infinite-scroll loading. */
|
|
48
57
|
onEndReached(thresholdPx: number, callback: () => void): this
|
|
49
|
-
/**
|
|
58
|
+
/** Same, for the top edge — chat history loading. */
|
|
50
59
|
onStartReached(thresholdPx: number, callback: () => void): this
|
|
51
60
|
onLayout(onLayout: OnLayoutCallback): this
|
|
52
61
|
getBoundingClientRect(): BoundingClientRect | null
|
|
@@ -59,11 +68,11 @@ export interface UIVirtualizedList<T = unknown> {
|
|
|
59
68
|
|
|
60
69
|
export class VListElement<T> extends Element<"vlist"> implements UIVirtualizedList<T> {
|
|
61
70
|
|
|
62
|
-
// ---
|
|
63
|
-
_overscan: number
|
|
71
|
+
// --- read by native side in createUINode (copyProperty / copyNodePtr) ---
|
|
72
|
+
_overscan: number
|
|
64
73
|
_inverted: boolean
|
|
65
|
-
_keys: string[] = []
|
|
66
|
-
_estimates: number[] = []
|
|
74
|
+
_keys: string[] = []
|
|
75
|
+
_estimates: number[] = []
|
|
67
76
|
_endThreshold = 0
|
|
68
77
|
_startThreshold = 0
|
|
69
78
|
|
|
@@ -117,12 +126,8 @@ export class VListElement<T> extends Element<"vlist"> implements UIVirtualizedLi
|
|
|
117
126
|
this._keys = keys
|
|
118
127
|
this._estimates = estimates
|
|
119
128
|
if (this.isAttached) {
|
|
120
|
-
// нативка диффает по ключам: исчезнувшие смонтированные ключи придут в _syncWindow как unmount
|
|
121
129
|
_creatorUI.vlistSetKeys(this, keys, estimates)
|
|
122
|
-
|
|
123
|
-
// старое поддерево. Если объект данных изменился, перерисовываем их (как update), иначе
|
|
124
|
-
// строки остаются со старым содержимым. На вебе экран в истории держит айтемы
|
|
125
|
-
// смонтированными, поэтому без этого повторный setData их не обновлял.
|
|
130
|
+
|
|
126
131
|
for (const k of prevMounted) {
|
|
127
132
|
if (this.mounted.has(k) && this.items.get(k) !== prevItems.get(k)) {
|
|
128
133
|
_creatorUI.vlistInvalidate(this, k)
|
|
@@ -137,7 +142,6 @@ export class VListElement<T> extends Element<"vlist"> implements UIVirtualizedLi
|
|
|
137
142
|
this._keys.push(...keys)
|
|
138
143
|
this._estimates.push(...estimates)
|
|
139
144
|
if (this.isAttached) {
|
|
140
|
-
// inverted + позиция внизу → нативка автоскроллит к концу
|
|
141
145
|
_creatorUI.vlistInsertKeys(this, -1, keys, estimates)
|
|
142
146
|
}
|
|
143
147
|
return this
|
|
@@ -148,7 +152,6 @@ export class VListElement<T> extends Element<"vlist"> implements UIVirtualizedLi
|
|
|
148
152
|
this._keys.unshift(...keys)
|
|
149
153
|
this._estimates.unshift(...estimates)
|
|
150
154
|
if (this.isAttached) {
|
|
151
|
-
// нативка компенсирует scrollY на сумму estimates — позиция не прыгает
|
|
152
155
|
_creatorUI.vlistInsertKeys(this, 0, keys, estimates)
|
|
153
156
|
}
|
|
154
157
|
return this
|
|
@@ -160,8 +163,6 @@ export class VListElement<T> extends Element<"vlist"> implements UIVirtualizedLi
|
|
|
160
163
|
if (!this.items.has(k)) continue
|
|
161
164
|
this.items.set(k, item)
|
|
162
165
|
if (this.isAttached && this.mounted.has(k)) {
|
|
163
|
-
// unmount+mount, кэш высоты сохраняется до повторного измерения.
|
|
164
|
-
// Несмонтированный айтем перерендерится сам при входе в окно
|
|
165
166
|
_creatorUI.vlistInvalidate(this, k)
|
|
166
167
|
}
|
|
167
168
|
}
|
|
@@ -215,12 +216,9 @@ export class VListElement<T> extends Element<"vlist"> implements UIVirtualizedLi
|
|
|
215
216
|
return this
|
|
216
217
|
}
|
|
217
218
|
|
|
218
|
-
/**
|
|
219
|
-
*
|
|
220
|
-
*
|
|
221
|
-
* Порядок: сначала unmount (нативка уже снесла поддеревья и обнулила _id,
|
|
222
|
-
* здесь только чистим JS-ссылки), потом mount.
|
|
223
|
-
*/
|
|
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. */
|
|
224
222
|
_syncWindow(unmountKeys: string[], mountKeys: string[]): void {
|
|
225
223
|
for (const k of unmountKeys) {
|
|
226
224
|
this.mounted.delete(k)
|
|
@@ -236,6 +234,8 @@ export class VListElement<T> extends Element<"vlist"> implements UIVirtualizedLi
|
|
|
236
234
|
}
|
|
237
235
|
}
|
|
238
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). */
|
|
239
239
|
export function UIVirtualizedList<T>(config: VListConfig<T>): UIVirtualizedList<T> {
|
|
240
240
|
return new VListElement<T>(config)
|
|
241
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>,
|
|
@@ -23,7 +26,8 @@ export interface UIWidget {
|
|
|
23
26
|
* (= back to a global overlay). Set it while the widget is hidden. The widget is always its own
|
|
24
27
|
* overlay root mounted into the owner's page view — it never becomes a child of the owner, so it
|
|
25
28
|
* stays topmost and its updates never trigger the owner's relayout. Works with a `UIScreen` that
|
|
26
|
-
* is a page inside a `UIPager`: the widget mounts into that tab and rides its swipe.
|
|
29
|
+
* is a page inside a `UIPager`: the widget mounts into that tab and rides its swipe. (Web shows
|
|
30
|
+
* and hides it with the owner but does not yet ride the transition.)
|
|
27
31
|
*/
|
|
28
32
|
attachTo(owner: Presentable | null): this,
|
|
29
33
|
|
|
@@ -32,8 +36,10 @@ export interface UIWidget {
|
|
|
32
36
|
* widget was attached via `attachTo(owner)`, it mounts on that page's layer instead and is
|
|
33
37
|
* only visible while the owner is presented. */
|
|
34
38
|
show(): void,
|
|
39
|
+
/** Unmount the widget. */
|
|
35
40
|
hide(): void,
|
|
36
41
|
|
|
42
|
+
/** Mounted right now (`show()` ran, `hide()` hasn't). */
|
|
37
43
|
readonly isShow: boolean,
|
|
38
44
|
|
|
39
45
|
append(...nodes: UINodeChild[]): UIWidget
|
|
@@ -46,7 +52,9 @@ export interface UIWidget {
|
|
|
46
52
|
onLayout(onLayout: OnLayoutCallback): this
|
|
47
53
|
getBoundingClientRect(): BoundingClientRect | null
|
|
48
54
|
onTouchStart(callback: (ev: TouchStartEvent<UIWidget>) => void): this,
|
|
55
|
+
/** Tap on the overlay layer (requires an `overlayColor`). */
|
|
49
56
|
onOverlayTap(callback: () => void): this,
|
|
57
|
+
/** Hardware/system back while the widget is shown. */
|
|
50
58
|
onBackPressed(callback: () => void): this
|
|
51
59
|
|
|
52
60
|
/** Style-class proxy — read `el.class.checked`, set `el.class.checked = true`, toggle with
|
|
@@ -119,20 +127,17 @@ export class WidgetElement extends ContainerElement<"widget"> {
|
|
|
119
127
|
}
|
|
120
128
|
|
|
121
129
|
|
|
122
|
-
|
|
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;
|
|
123
138
|
export function UIWidget(children: UINodeChild[] | ChildrenFn): UIWidget;
|
|
124
|
-
|
|
125
|
-
export function UIWidget(style: UIWidgetStyle, children
|
|
126
|
-
export function UIWidget(...args: []
|
|
127
|
-
|
|
128
|
-
return new WidgetElement("widget", {}, [])
|
|
129
|
-
} else if (args.length === 1) {
|
|
130
|
-
if (Array.isArray(args[0]) || typeof args[0] === "function") {
|
|
131
|
-
return new WidgetElement("widget", {}, args[0])
|
|
132
|
-
} else {
|
|
133
|
-
return new WidgetElement("widget", args[0], [])
|
|
134
|
-
}
|
|
135
|
-
} else {
|
|
136
|
-
return new WidgetElement("widget", args[0], args[1])
|
|
137
|
-
}
|
|
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)
|
|
138
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
|
}
|