@pritzlaff/nano-ui 0.4.0 → 0.5.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.
@@ -0,0 +1,5 @@
1
+ import { Implementation } from '@pritzlaff/nano-core';
2
+ /** The real random: `next` is Math.random. */
3
+ export declare const random: Implementation;
4
+ /** A seeded random (mulberry32): the same seed gives the same sequence, and a restart begins it again. */
5
+ export declare const seededRandom: Implementation;
@@ -0,0 +1,3 @@
1
+ import { Implementation } from '@pritzlaff/nano-core';
2
+ /** A clock that moves only by `advance` and `set`, firing due timers in due order (ties in start order), one at a time. */
3
+ export declare const simClock: Implementation;
@@ -0,0 +1,72 @@
1
+ /** A queued value and when it arrived (ms since the epoch). */
2
+ export type Queued = {
3
+ value: unknown;
4
+ at: number;
5
+ };
6
+ /** Stage geometry and motion (px, slots, ms). Slot 0 sits on the hatch; higher slots run back along the switchback. */
7
+ export declare const G: {
8
+ readonly rows: 3;
9
+ readonly perRow: 18;
10
+ readonly sp: 54;
11
+ readonly xEnd: 1110;
12
+ readonly xStart: 192;
13
+ readonly rowY: readonly [176, 106, 36];
14
+ readonly maxPos: 53;
15
+ readonly hidePos: -2.3;
16
+ readonly bucketTop: 290;
17
+ readonly bucketH: 270;
18
+ readonly pitch: 122;
19
+ readonly history: 8;
20
+ readonly enterSpeed: 0.07;
21
+ readonly flushSpeed: 0.06;
22
+ readonly hatchLeadMs: 180;
23
+ readonly settleMs: 260;
24
+ readonly slideMs: 480;
25
+ };
26
+ export type Reason = 'quiet' | 'max wait';
27
+ /** A batch dropping through the hatch: its values (with when each arrived), and when it lands. */
28
+ export type Flushing = {
29
+ events: Queued[];
30
+ at: number;
31
+ doneAt: number;
32
+ reason: Reason;
33
+ };
34
+ export type Batch = {
35
+ id: number;
36
+ events: Queued[];
37
+ reason: Reason;
38
+ };
39
+ /** Why a queue flushed (or will): whichever deadline comes first. */
40
+ export declare const reasonFor: (q: Queued[], quiet: number, maxWait?: number) => Reason;
41
+ /** When a queue flushes: whichever deadline comes first (no max wait: only quiet). */
42
+ export declare const dueAt: (q: Queued[], quiet: number, maxWait?: number) => number;
43
+ /** Where a queued value is: it slides in from the back of the queue to its slot. */
44
+ export declare const arrivalPos: (slot: number, at: number, now: number) => number;
45
+ /** How far a dropping batch has travelled towards the hatch. */
46
+ export declare const flushTravel: (f: Flushing, now: number) => number;
47
+ /** A batch starts dropping now; it lands once its farthest value has passed the hatch. */
48
+ export declare function startFlush(events: Queued[], now: number, reason: Reason): Flushing;
49
+ /** A (fractional) queue position as stage coordinates along the switchback. */
50
+ export declare function slotXY(pos: number): {
51
+ x: number;
52
+ y: number;
53
+ };
54
+ /** A value's colour, by its JSON type (the prototype coloured by event type): a series token. */
55
+ export declare function colorOf(v: unknown): "var(--nano-s1, #4C8DFF)" | "var(--nano-s2, #FF9F1C)" | "var(--nano-s3, #2EC4A6)" | "var(--nano-s5, #B48CFF)";
56
+ /** A colour (a token) at an opacity. */
57
+ export declare const tint: (color: string, a: number) => string;
58
+ export declare const label: (v: unknown, n: number) => string;
59
+ export declare const clamp01: (v: number) => number;
60
+ /** A bucket's contents: cells stacked from the bottom, thinner the fuller it is. */
61
+ export declare function bucketView(events: Queued[]): {
62
+ n: number;
63
+ gap: number;
64
+ solid: boolean;
65
+ countTop: number;
66
+ cells: {
67
+ color: string;
68
+ bg: string;
69
+ h: number;
70
+ text: string;
71
+ }[];
72
+ };
@@ -0,0 +1,12 @@
1
+ import { bucketView } from './debounce-model.js';
2
+ export declare const MONO = "'JetBrains Mono', ui-monospace, monospace";
3
+ /** A setting's slider: the value (shown while dragging), how much of it has elapsed, and `set` on release. */
4
+ export declare const slider: (name: string, aria: string, min: number, max: number, step: number, value: number, elapsed: number, color: string, drag: (v: number) => void, set: (v: number) => void, off?: {
5
+ on: boolean;
6
+ toggle: (on: boolean) => void;
7
+ }) => import("lit").TemplateResult<1>;
8
+ /** The switchback track the queue runs along, from the entry at the top-left down to the hatch. */
9
+ export declare const track: () => import("lit").TemplateResult<1>;
10
+ /** A batch bucket: its count, its cells stacked from the bottom, and its id and reason underneath. The live one is
11
+ * the bucket under the hatch. */
12
+ export declare function bucket(v: ReturnType<typeof bucketView>, left: number, opacity: number, id: string, reason: string, reasonColor: string, live: boolean, border?: string): import("lit").TemplateResult<1>;
@@ -0,0 +1,36 @@
1
+ import { type AppEvent } from '@pritzlaff/nano-core';
2
+ import { type Batch, type Flushing, type Queued } from './debounce-model.js';
3
+ import { ViewElement, type ViewTarget } from './view.js';
4
+ export declare class NanoDebounce extends ViewElement {
5
+ static styles: import("lit").CSSResult[];
6
+ pending: Queued[];
7
+ flushing: Flushing | null;
8
+ batches: Batch[];
9
+ batchSeq: number;
10
+ committed: number;
11
+ lastCommitAt: number;
12
+ /** A slider's value while it is dragged, before the config is applied. */
13
+ private dragged;
14
+ private valued;
15
+ private unsub?;
16
+ private raf;
17
+ private fit;
18
+ private ro?;
19
+ private config;
20
+ private quiet;
21
+ private maxWait;
22
+ /** Values come from `subscribe(push)` when this runtime has one debounce; else arrivals are counted from `sent`. */
23
+ protected started(tg: ViewTarget): void;
24
+ protected hear(e: AppEvent, tg: ViewTarget): void;
25
+ private arrive;
26
+ private flush;
27
+ private commit;
28
+ /** Applies the pod's config with `c` merged in (the pod restarts with it). */
29
+ private set;
30
+ firstUpdated(): void;
31
+ connectedCallback(): void;
32
+ disconnectedCallback(): void;
33
+ willUpdate(changed: Map<string, unknown>): void;
34
+ updated(): void;
35
+ protected face(tg: ViewTarget): import("lit").TemplateResult<1>;
36
+ }
package/views/faces.d.ts CHANGED
@@ -1,18 +1,5 @@
1
1
  import { type AppEvent } from '@pritzlaff/nano-core';
2
2
  import { ViewElement, type ViewTarget } from './view.js';
3
- export declare class NanoInput extends ViewElement {
4
- private enter;
5
- protected face(tg: ViewTarget): import("lit").TemplateResult<1>;
6
- }
7
- export declare class NanoDebounce extends ViewElement {
8
- static styles: import("lit").CSSResult[];
9
- private pending;
10
- private flash;
11
- private timer?;
12
- protected hear(e: AppEvent, tg: ViewTarget): void;
13
- disconnectedCallback(): void;
14
- protected face(): import("lit").TemplateResult<1>;
15
- }
16
3
  export declare class NanoMap extends ViewElement {
17
4
  private mine;
18
5
  private output?;
@@ -0,0 +1,9 @@
1
+ import { ViewElement, type ViewTarget } from './view.js';
2
+ export declare class NanoInput extends ViewElement {
3
+ private value;
4
+ private kind;
5
+ private edit;
6
+ private send;
7
+ private setKind;
8
+ protected face(tg: ViewTarget): import("lit").TemplateResult<1>;
9
+ }
package/views/view.d.ts CHANGED
@@ -2,7 +2,7 @@
2
2
  * The view contract: a view is a custom element over one pod, with a `target: ViewTarget` property. It reaches its pod
3
3
  * only through `target.app.call(target.runtime, target.pod)` and `target.app.listen`. `viewFor` picks the tag.
4
4
  *
5
- * viewFor('up', { ...app.deployment(), views }, defaults) // the selector, else the default, else 'nano-pod-view'
5
+ * viewFor('up', app.deployment(), defaults, overrides) // the pod's override, else the default, else 'nano-pod-view'
6
6
  */
7
7
  import { LitElement } from 'lit';
8
8
  import type { AppDeployment, AppEvent, Application, Registry } from '@pritzlaff/nano-core';
@@ -14,7 +14,8 @@ export type ViewTarget = {
14
14
  };
15
15
  /** An implementation coordinate → a custom-element tag. */
16
16
  export type ViewMap = Record<string, string>;
17
- export declare function viewFor(pod: string, deployment: AppDeployment, defaults: ViewMap): string;
17
+ /** `overrides`: pod → tag (a host's, e.g. the host document's `host.views`). */
18
+ export declare function viewFor(pod: string, deployment: AppDeployment, defaults: ViewMap, overrides?: Record<string, string>): string;
18
19
  /**
19
20
  * What every view here shares: listening while connected and its pod is placed; "removed" once an `applied` removes it.
20
21
  * Not exported from the package: a view is any element with `target`, this is only how these ones are made.