@almadar/ui 5.94.1 → 5.96.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,58 @@
1
+ /**
2
+ * AlgorithmCanvas
3
+ *
4
+ * A field-scoped learning molecule for computer-science algorithm visualizations.
5
+ * Projects semantic `bars` (sorting/histograms), `cells` (grids/arrays/DP tables),
6
+ * and `pointers` (index cursors) into pixel-space shapes on the declarative
7
+ * `LearningCanvas` atom, so a `.lolo` behavior never computes pixel coordinates —
8
+ * it just sets `bars`/`cells`/`pointers` and lets this molecule lay them out.
9
+ * Graph/tree algorithms reuse `BiologyCanvas` (nodes + edges); this canvas owns
10
+ * only the bar/cell/pointer vocabulary.
11
+ *
12
+ * @packageDocumentation
13
+ */
14
+ import * as React from 'react';
15
+ import type { LearningShape } from '../atoms/LearningCanvas';
16
+ import type { UiError } from '../../core/atoms/types';
17
+ export interface AlgorithmBar {
18
+ value: number;
19
+ color?: string;
20
+ label?: string;
21
+ }
22
+ export interface AlgorithmCell {
23
+ row: number;
24
+ col: number;
25
+ value?: number;
26
+ color?: string;
27
+ label?: string;
28
+ }
29
+ export interface AlgorithmPointer {
30
+ index: number;
31
+ label?: string;
32
+ color?: string;
33
+ }
34
+ export interface AlgorithmCanvasProps {
35
+ className?: string;
36
+ width?: number;
37
+ height?: number;
38
+ title?: string;
39
+ backgroundColor?: string;
40
+ /** Sorting/histogram bars; laid out left-to-right, height proportional to value. */
41
+ bars?: AlgorithmBar[];
42
+ /** Grid/array/DP cells; laid out on a row/col lattice sized to the extent. */
43
+ cells?: AlgorithmCell[];
44
+ /** Index cursors (i/j/lo/hi/mid); drawn as markers beneath the referenced bar/cell column. */
45
+ pointers?: AlgorithmPointer[];
46
+ /** Extra declarative shapes in canvas pixel coordinates. */
47
+ shapes?: LearningShape[];
48
+ interactive?: boolean;
49
+ animate?: boolean;
50
+ onShapeClick?: (payload: {
51
+ id?: string;
52
+ type?: string;
53
+ index: number;
54
+ }) => void;
55
+ isLoading?: boolean;
56
+ error?: UiError | null;
57
+ }
58
+ export declare const AlgorithmCanvas: React.FC<AlgorithmCanvasProps>;
@@ -0,0 +1,58 @@
1
+ /**
2
+ * atlasSlice — the ONLY place a packed sheet is cut at runtime.
3
+ *
4
+ * An `Asset` may carry `{ url: <sheet.png>, atlas: <atlas.json>, sprite: <name|index> }`. This
5
+ * module fetches + caches the atlas JSON (a `TextureAtlas` of named sub-rects or a uniform
6
+ * `Tilesheet`) and resolves the source rectangle for a `sprite`, so the canvas can `drawImage`
7
+ * exactly that sub-region of the sheet. Coexists with the whole-PNG path (an Asset with no
8
+ * `atlas`/`sprite` draws the whole image) and the `useUnitSpriteAtlas` animation path.
9
+ *
10
+ * See `docs/Almadar_Std_Assets.md` §2, §7.
11
+ *
12
+ * @packageDocumentation
13
+ */
14
+ import type { TextureAtlas, Tilesheet } from '@almadar/core';
15
+ /** The minimal draw-relevant projection of an `Asset` — a sheet URL plus an optional atlas
16
+ * sub-texture reference. A full `@almadar/core` `Asset` is structurally assignable. */
17
+ export interface SpriteRef {
18
+ url?: string;
19
+ atlas?: string;
20
+ sprite?: string;
21
+ }
22
+ type ParsedAtlas = TextureAtlas | Tilesheet;
23
+ /**
24
+ * Get a parsed atlas by URL, fetching+caching on first request. Returns undefined until loaded;
25
+ * `onReady` fires once when the fetch resolves so the caller can trigger a re-render.
26
+ */
27
+ export declare function getAtlas(url: string, onReady: () => void): ParsedAtlas | undefined;
28
+ export interface SubRect {
29
+ sx: number;
30
+ sy: number;
31
+ sw: number;
32
+ sh: number;
33
+ }
34
+ /**
35
+ * Resolve the source rect for `sprite` in `atlas`.
36
+ * - `TextureAtlas`: `sprite` is a SubTexture name (e.g. `"blockBrown.png"`).
37
+ * - `Tilesheet`: `sprite` is `"col,row"` or a flat index into the row-major grid.
38
+ * Returns null if the name/index doesn't resolve.
39
+ */
40
+ export declare function subRectFor(atlas: ParsedAtlas, sprite: string): SubRect | null;
41
+ /** True when the asset points into a sheet (needs slicing) rather than being a whole PNG. */
42
+ export declare function isAtlasAsset(asset: SpriteRef | undefined | null): boolean;
43
+ export interface AssetSource {
44
+ img: HTMLImageElement;
45
+ /** Sub-rect to blit; null = draw the whole image. */
46
+ rect: SubRect | null;
47
+ /** Source aspect ratio (width/height) — sub-rect for a slice, natural otherwise. */
48
+ aspect: number;
49
+ }
50
+ /**
51
+ * Resolve what to draw for `asset` given its loaded sheet `img`. Returns null when the asset is
52
+ * an atlas ref whose JSON isn't loaded yet (or whose sprite name doesn't resolve) — `onReady`
53
+ * will trigger a re-render once the fetch lands. Callers use `.aspect` to size, then `blit`.
54
+ */
55
+ export declare function resolveAssetSource(img: HTMLImageElement, asset: SpriteRef | undefined | null, onReady: () => void): AssetSource | null;
56
+ /** Draw a resolved source at `(dx,dy,dw,dh)` — sliced sub-rect or whole image. */
57
+ export declare function blit(ctx: CanvasRenderingContext2D, src: AssetSource, dx: number, dy: number, dw: number, dh: number): void;
58
+ export {};