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.
@@ -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: string | FetchResponse | File | SvgSource,
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: string | FetchResponse | File | SvgSource
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: string | FetchResponse | File | SvgSource) {
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", value)
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: string | FetchResponse | File | SvgSource): UIImage
61
- export function UIImage(style: UIImageStyle, src: string | FetchResponse | File | SvgSource): UIImage
62
- export function UIImage(...args: [string | FetchResponse | File | SvgSource] | [UIImageStyle, string | FetchResponse | File | SvgSource]): UIImage {
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
- export interface UIScreen <Scrollable extends boolean = boolean> {
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>) => void): this,
39
+ onTouchStart(callback: (ev: TouchStartEvent<UIScreen<boolean>>) => void): this,
35
40
  }
36
41
 
37
42
  export class ScreenElement extends ContainerElement<"screen"> {