lecodes-cli 0.1.7 → 0.3.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 +7 -1
- package/dist/index.js +67 -101
- package/package.json +4 -5
- package/runtime/sdk/canvas/Canvas.ts +184 -0
- package/runtime/sdk/canvas/Label.ts +57 -0
- package/runtime/sdk/core/Aspect.ts +207 -0
- package/runtime/sdk/g2/Camera2D.ts +3 -43
- package/runtime/sdk/g2/CharacterController2D.ts +75 -0
- package/runtime/sdk/g2/Node2D.ts +117 -27
- package/runtime/sdk/g2/Physics2D.ts +126 -0
- package/runtime/sdk/g2/Scene2D.ts +47 -1
- package/runtime/sdk/g2/Shape.ts +63 -0
- package/runtime/sdk/g2/Sprite.ts +13 -93
- package/runtime/sdk/g2/SpriteAnimation.ts +90 -0
- package/runtime/sdk/g2/Texture2D.ts +8 -0
- package/runtime/sdk/g2/Trigger.ts +47 -0
- package/runtime/sdk/g2/loop.ts +20 -3
- package/runtime/sdk/g2/touch.ts +83 -0
- package/runtime/sdk/gl/Collider.ts +29 -0
- package/runtime/sdk/gl/Material.ts +10 -3
- package/runtime/sdk/gl/Mesh.ts +2 -25
- package/runtime/sdk/gl/Model.ts +40 -0
- package/runtime/sdk/gl/ModelAnimation.ts +64 -0
- package/runtime/sdk/gl/Node.ts +13 -86
- package/runtime/sdk/gl/{Body.ts → Physics.ts} +18 -24
- package/runtime/sdk/gl/Texture.ts +11 -0
- package/runtime/sdk/inject.ts +17 -0
- package/runtime/sdk/runtime/touch.ts +6 -0
- package/runtime/sdk/ui/UIImage.ts +26 -11
- package/runtime/sdk/ui/UIScreen.ts +7 -2
|
@@ -1,13 +1,28 @@
|
|
|
1
1
|
import type { FetchResponse } from "../runtime/fetch"
|
|
2
2
|
import type { SvgSourceValue as SvgSource } from "../runtime/misc"
|
|
3
3
|
import type { File } from "../runtime/fetch"
|
|
4
|
+
import { Canvas, isCanvas } from "../canvas/Canvas"
|
|
4
5
|
import { Element, type AnimateStyle, type Color, type ElementStyle, type OnLayoutCallback, type Style } from "./UINode"
|
|
5
6
|
|
|
6
7
|
export type UIImageStyle = ElementStyle & { borderRadius?: number, objectFit?: "cover" | "contain" | "fill", tintColor?: Color }
|
|
7
8
|
|
|
9
|
+
/** A baked Canvas surface as an image source. The UI backend resolves it to a UI texture — see
|
|
10
|
+
* docs/canvas-contract.md ("Pending"). */
|
|
11
|
+
export type CanvasImageSource = { canvasSurface: number }
|
|
12
|
+
|
|
13
|
+
/** Accepted image sources. A Canvas is baked to a surface marker on assign. */
|
|
14
|
+
export type ImageSource = string | FetchResponse | File | SvgSource | Canvas
|
|
15
|
+
|
|
16
|
+
const toSrc = (src: ImageSource): string | FetchResponse | File | SvgSource | CanvasImageSource =>
|
|
17
|
+
isCanvas(src) ? { canvasSurface: src._bakeSurface() } : src
|
|
18
|
+
|
|
19
|
+
/** The stored/resolved image source (a Canvas is resolved to a surface marker). */
|
|
20
|
+
export type ResolvedImageSource = string | FetchResponse | File | SvgSource | CanvasImageSource
|
|
21
|
+
|
|
8
22
|
export interface UIImage {
|
|
9
23
|
readonly type: "image",
|
|
10
|
-
src:
|
|
24
|
+
get src(): ResolvedImageSource
|
|
25
|
+
set src(value: ImageSource)
|
|
11
26
|
style: Style<this, UIImageStyle>
|
|
12
27
|
animateTo: AnimateStyle<this, UIImageStyle>
|
|
13
28
|
animateFrom: AnimateStyle<this, UIImageStyle>
|
|
@@ -23,23 +38,23 @@ export interface UIImage {
|
|
|
23
38
|
}
|
|
24
39
|
|
|
25
40
|
class ImageElement extends Element<"image"> {
|
|
26
|
-
private _src:
|
|
41
|
+
private _src: ResolvedImageSource
|
|
27
42
|
// Current source sub-rect; undefined until the first setSourceRect. Kept on the node (not
|
|
28
43
|
// just sent as a command) so a crop set while detached (_id == 0) is reapplied at mount —
|
|
29
44
|
// the viewer reads it when it creates the element.
|
|
30
45
|
private _sourceRect?: [number, number, number, number]
|
|
31
|
-
constructor(style: any, src:
|
|
46
|
+
constructor(style: any, src: ImageSource) {
|
|
32
47
|
super("image", style)
|
|
33
|
-
this._src = src
|
|
48
|
+
this._src = toSrc(src)
|
|
34
49
|
}
|
|
35
50
|
|
|
36
|
-
get src() {
|
|
51
|
+
get src(): ResolvedImageSource {
|
|
37
52
|
return this._src
|
|
38
53
|
}
|
|
39
|
-
set src(value) {
|
|
40
|
-
this._src = value
|
|
54
|
+
set src(value: ImageSource) {
|
|
55
|
+
this._src = toSrc(value)
|
|
41
56
|
if (this._id !== 0) {
|
|
42
|
-
_creatorUI.updateNode(this._id, "src",
|
|
57
|
+
_creatorUI.updateNode(this._id, "src", this._src)
|
|
43
58
|
}
|
|
44
59
|
}
|
|
45
60
|
|
|
@@ -57,9 +72,9 @@ class ImageElement extends Element<"image"> {
|
|
|
57
72
|
}
|
|
58
73
|
}
|
|
59
74
|
|
|
60
|
-
export function UIImage(src:
|
|
61
|
-
export function UIImage(style: UIImageStyle, src:
|
|
62
|
-
export function UIImage(...args: [
|
|
75
|
+
export function UIImage(src: ImageSource): UIImage
|
|
76
|
+
export function UIImage(style: UIImageStyle, src: ImageSource): UIImage
|
|
77
|
+
export function UIImage(...args: [ImageSource] | [UIImageStyle, ImageSource]): UIImage {
|
|
63
78
|
if (args.length === 1) {
|
|
64
79
|
return new ImageElement({}, args[0])
|
|
65
80
|
} else {
|
|
@@ -3,7 +3,12 @@ import { ContainerElement, type AnimateStyle, type BaseStyle, type Color, type C
|
|
|
3
3
|
|
|
4
4
|
export type UIScreenStyle = ContainerStyle & DrawableStyle & PaddingStyle & ScrollStyle & BaseStyle & ScrollStyle & { refreshControlColor?: Color }
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
// Default to `false`: a bare `UIScreen` means the non-scrollable screen the `UIScreen(...)`
|
|
7
|
+
// constructor returns, so `const s: UIScreen = UIScreen([...])` type-checks. The type is invariant
|
|
8
|
+
// in `Scrollable` (the fluent `style()` puts `this` in a contravariant position), so a `boolean`
|
|
9
|
+
// default wouldn't accept the constructor's `UIScreen<false>`. Opt into scrolling via
|
|
10
|
+
// `.makeScrollable(): UIScreen<true>`; write `UIScreen<boolean>` explicitly when you need the union.
|
|
11
|
+
export interface UIScreen <Scrollable extends boolean = false> {
|
|
7
12
|
readonly type: "screen",
|
|
8
13
|
scrollable: Scrollable,
|
|
9
14
|
style: Style<this, UIScreenStyle>,
|
|
@@ -31,7 +36,7 @@ export interface UIScreen <Scrollable extends boolean = boolean> {
|
|
|
31
36
|
|
|
32
37
|
onLayout(onLayout: OnLayoutCallback): this
|
|
33
38
|
|
|
34
|
-
onTouchStart(callback: (ev: TouchStartEvent<UIScreen
|
|
39
|
+
onTouchStart(callback: (ev: TouchStartEvent<UIScreen<boolean>>) => void): this,
|
|
35
40
|
}
|
|
36
41
|
|
|
37
42
|
export class ScreenElement extends ContainerElement<"screen"> {
|