@zonsh/ui 0.2.0 → 0.4.1
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/LICENSE +22 -0
- package/README.md +19 -13
- package/dist/components/alert-dialog.js +1 -1
- package/dist/components/ascii-field.d.ts +1 -1
- package/dist/components/bottom-nav.d.ts +86 -0
- package/dist/components/bottom-nav.js +175 -0
- package/dist/components/breadcrumb.d.ts +9 -0
- package/dist/components/breadcrumb.js +6 -1
- package/dist/components/button-group.d.ts +1 -1
- package/dist/components/button-group.js +2 -2
- package/dist/components/calendar.d.ts +1 -1
- package/dist/components/calendar.js +18 -3
- package/dist/components/carousel.d.ts +22 -3
- package/dist/components/carousel.js +25 -7
- package/dist/components/chart.d.ts +9 -0
- package/dist/components/chart.js +40 -3
- package/dist/components/code-block.d.ts +20 -10
- package/dist/components/code-block.js +54 -12
- package/dist/components/collapsible.js +2 -2
- package/dist/components/color-picker.d.ts +30 -8
- package/dist/components/color-picker.js +48 -27
- package/dist/components/combobox.d.ts +21 -3
- package/dist/components/combobox.js +79 -7
- package/dist/components/command.d.ts +23 -3
- package/dist/components/command.js +61 -16
- package/dist/components/conversation.d.ts +10 -1
- package/dist/components/conversation.js +14 -4
- package/dist/components/copy-button.d.ts +15 -6
- package/dist/components/copy-button.js +20 -5
- package/dist/components/data-table.d.ts +66 -6
- package/dist/components/data-table.js +376 -23
- package/dist/components/date-picker.d.ts +73 -4
- package/dist/components/date-picker.js +138 -7
- package/dist/components/dialog.d.ts +10 -1
- package/dist/components/dialog.js +6 -3
- package/dist/components/drawer.d.ts +10 -1
- package/dist/components/drawer.js +6 -3
- package/dist/components/feature-list.js +2 -2
- package/dist/components/field.d.ts +27 -8
- package/dist/components/field.js +49 -4
- package/dist/components/file-drop.d.ts +26 -4
- package/dist/components/file-drop.js +125 -64
- package/dist/components/filter-bar.d.ts +50 -3
- package/dist/components/filter-bar.js +71 -33
- package/dist/components/form.d.ts +4 -2
- package/dist/components/form.js +24 -2
- package/dist/components/graph.d.ts +41 -0
- package/dist/components/graph.js +84 -45
- package/dist/components/illustration.js +1 -1
- package/dist/components/input-group.d.ts +16 -5
- package/dist/components/input-group.js +35 -15
- package/dist/components/input.d.ts +2 -2
- package/dist/components/input.js +3 -3
- package/dist/components/kbd.d.ts +17 -0
- package/dist/components/kbd.js +8 -1
- package/dist/components/lightbox.d.ts +100 -0
- package/dist/components/lightbox.js +439 -0
- package/dist/components/locale.d.ts +44 -0
- package/dist/components/locale.js +37 -0
- package/dist/components/logo.js +1 -1
- package/dist/components/menu.js +3 -1
- package/dist/components/message.d.ts +3 -3
- package/dist/components/message.js +10 -7
- package/dist/components/meter.js +3 -1
- package/dist/components/money-input.d.ts +80 -0
- package/dist/components/money-input.js +253 -0
- package/dist/components/number-field.d.ts +21 -2
- package/dist/components/number-field.js +27 -16
- package/dist/components/otp-field.d.ts +14 -1
- package/dist/components/otp-field.js +10 -2
- package/dist/components/pagination.d.ts +13 -7
- package/dist/components/pagination.js +18 -7
- package/dist/components/pdf-viewer.d.ts +67 -2
- package/dist/components/pdf-viewer.js +88 -21
- package/dist/components/phone-input.d.ts +79 -0
- package/dist/components/phone-input.js +282 -0
- package/dist/components/popover.js +1 -1
- package/dist/components/progress.js +3 -1
- package/dist/components/prompt-input.d.ts +34 -9
- package/dist/components/prompt-input.js +28 -16
- package/dist/components/rating.d.ts +73 -0
- package/dist/components/rating.js +124 -0
- package/dist/components/reasoning.d.ts +16 -1
- package/dist/components/reasoning.js +10 -7
- package/dist/components/resizable.d.ts +10 -1
- package/dist/components/resizable.js +4 -1
- package/dist/components/response.d.ts +14 -3
- package/dist/components/response.js +36 -8
- package/dist/components/scroll-area.d.ts +1 -1
- package/dist/components/select.js +14 -3
- package/dist/components/separator.js +1 -1
- package/dist/components/sidebar.d.ts +20 -4
- package/dist/components/sidebar.js +34 -18
- package/dist/components/site-header.d.ts +46 -12
- package/dist/components/site-header.js +73 -19
- package/dist/components/slider.js +3 -1
- package/dist/components/sortable.d.ts +178 -0
- package/dist/components/sortable.js +1258 -0
- package/dist/components/sources.d.ts +17 -2
- package/dist/components/sources.js +11 -4
- package/dist/components/spinner.d.ts +13 -1
- package/dist/components/spinner.js +5 -2
- package/dist/components/stat.d.ts +91 -0
- package/dist/components/stat.js +141 -0
- package/dist/components/stepper.d.ts +71 -0
- package/dist/components/stepper.js +101 -0
- package/dist/components/switch.d.ts +2 -2
- package/dist/components/switch.js +2 -2
- package/dist/components/table.d.ts +12 -2
- package/dist/components/table.js +176 -39
- package/dist/components/tags-input.d.ts +18 -2
- package/dist/components/tags-input.js +65 -33
- package/dist/components/theme.d.ts +16 -2
- package/dist/components/theme.js +15 -7
- package/dist/components/time-field.d.ts +22 -3
- package/dist/components/time-field.js +19 -6
- package/dist/components/timeline.d.ts +18 -2
- package/dist/components/timeline.js +13 -4
- package/dist/components/tippy.d.ts +48 -0
- package/dist/components/tippy.js +648 -0
- package/dist/components/toast.d.ts +18 -2
- package/dist/components/toast.js +12 -3
- package/dist/components/tool-call.d.ts +19 -8
- package/dist/components/tool-call.js +18 -7
- package/dist/components/toolbar.js +6 -1
- package/dist/components/tour.d.ts +127 -0
- package/dist/components/tour.js +648 -0
- package/dist/components/tree.js +17 -4
- package/dist/components/video-player.d.ts +10 -2
- package/dist/components/video-player.js +73 -33
- package/dist/illustration.d.ts +2 -0
- package/dist/illustration.js +7 -0
- package/dist/index.d.ts +11 -3
- package/dist/index.js +11 -3
- package/dist/lib/code-highlight.d.ts +3 -16
- package/dist/lib/code-highlight.js +160 -10
- package/dist/lib/code-theme.js +3 -3
- package/dist/lib/digit-roll.js +8 -8
- package/dist/lib/field-errors.d.ts +28 -0
- package/dist/lib/field-errors.js +24 -0
- package/dist/lib/field-value.d.ts +13 -0
- package/dist/lib/field-value.js +44 -0
- package/dist/lib/graph-layout.js +11 -2
- package/dist/lib/money.d.ts +73 -0
- package/dist/lib/money.js +343 -0
- package/dist/lib/phone-countries.d.ts +1 -0
- package/dist/lib/phone-countries.js +281 -0
- package/dist/lib/phone.d.ts +90 -0
- package/dist/lib/phone.js +286 -0
- package/dist/lib/platform.d.ts +8 -3
- package/dist/lib/platform.js +13 -6
- package/dist/lib/row-index.d.ts +15 -0
- package/dist/lib/row-index.js +136 -0
- package/dist/lib/table-fit.js +23 -4
- package/dist/lib/theme-script.d.ts +15 -2
- package/dist/lib/theme-script.js +23 -3
- package/dist/lib/tippy/pixels.d.ts +47 -0
- package/dist/lib/tippy/pixels.js +187 -0
- package/dist/lib/tippy/sprite.d.ts +86 -0
- package/dist/lib/tippy/sprite.js +753 -0
- package/dist/messages/de.d.ts +12 -0
- package/dist/messages/de.js +326 -0
- package/dist/styles/expressive.css +20 -5
- package/dist/styles/index.css +3 -2
- package/dist/styles/material.css +7 -3
- package/dist/styles/parts/ai.css +2 -1
- package/dist/styles/parts/controls.css +62 -13
- package/dist/styles/parts/feedback.css +68 -1
- package/dist/styles/parts/foundations.css +1 -1
- package/dist/styles/parts/navigation.css +194 -2
- package/dist/styles/parts/overlays.css +7 -7
- package/dist/styles/tokens.css +12 -3
- package/dist/vite.d.ts +0 -50
- package/dist/vite.js +0 -100
- package/package.json +28 -33
- package/dist/components/code-highlight.d.ts +0 -13
- package/dist/components/code-highlight.js +0 -107
- package/dist/components/whiteboard.d.ts +0 -80
- package/dist/components/whiteboard.js +0 -389
- package/dist/styles/parts/whiteboard.css +0 -855
package/dist/lib/theme-script.js
CHANGED
|
@@ -6,6 +6,22 @@
|
|
|
6
6
|
export const THEME_STORAGE_KEY = "zon-theme";
|
|
7
7
|
/** The media query `system` follows. Not part of the public API. */
|
|
8
8
|
export const DARK_QUERY = "(prefers-color-scheme: dark)";
|
|
9
|
+
/**
|
|
10
|
+
* The page ground as one flat colour in each theme, --page-tone in tokens.css: what the grain
|
|
11
|
+
* over the background averages to. The browser's own bars (the status bar and toolbar on a
|
|
12
|
+
* phone) take it through `<meta name="theme-color">`, so they match the page.
|
|
13
|
+
*/
|
|
14
|
+
export const PAGE_TONE = { light: "#f9f9f9", dark: "#141414" };
|
|
15
|
+
/** The `theme-color` meta that names no media, made if the page has none. Not part of the public API. */
|
|
16
|
+
export function setThemeColor(dark) {
|
|
17
|
+
let meta = document.querySelector('meta[name="theme-color"]:not([media])');
|
|
18
|
+
if (!meta) {
|
|
19
|
+
meta = document.createElement("meta");
|
|
20
|
+
meta.name = "theme-color";
|
|
21
|
+
document.head.appendChild(meta);
|
|
22
|
+
}
|
|
23
|
+
meta.content = dark ? PAGE_TONE.dark : PAGE_TONE.light;
|
|
24
|
+
}
|
|
9
25
|
/**
|
|
10
26
|
* A value as a JavaScript literal that is safe inside an HTML `<script>`: its JSON, with `<`
|
|
11
27
|
* written as `\u003c`, so a `</script>` or `<!--` in it cannot end the element or change how
|
|
@@ -15,12 +31,16 @@ export const DARK_QUERY = "(prefers-color-scheme: dark)";
|
|
|
15
31
|
const literal = (value) => JSON.stringify(value).replace(/[<>&\u2028\u2029]/g, (c) => `\\u${c.charCodeAt(0).toString(16).padStart(4, "0")}`);
|
|
16
32
|
/**
|
|
17
33
|
* Build the no-flash script for `<head>`. It applies `.dark` before first paint, using the
|
|
18
|
-
* same storage key and default as `ThemeProvider
|
|
34
|
+
* same storage key and default as `ThemeProvider`, and sets `<meta name="theme-color">` to the
|
|
35
|
+
* theme's page tone (making the tag if there is none). Pass the same options to both.
|
|
19
36
|
*/
|
|
20
|
-
export function createThemeScript({ storageKey = THEME_STORAGE_KEY, defaultTheme = "system", } = {}) {
|
|
37
|
+
export function createThemeScript({ storageKey = THEME_STORAGE_KEY, defaultTheme = "system", themeColor = true, } = {}) {
|
|
21
38
|
const key = literal(storageKey);
|
|
22
39
|
const fallback = literal(defaultTheme);
|
|
23
|
-
|
|
40
|
+
const meta = themeColor
|
|
41
|
+
? `var m=document.querySelector('meta[name="theme-color"]:not([media])');if(!m){m=document.createElement("meta");m.name="theme-color";document.head.appendChild(m)}m.content=d?${literal(PAGE_TONE.dark)}:${literal(PAGE_TONE.light)};`
|
|
42
|
+
: "";
|
|
43
|
+
return `(function(){var t=null;try{t=localStorage.getItem(${key})}catch(e){}if(t!=="light"&&t!=="dark"&&t!=="system")t=${fallback};var d=t==="dark";if(t==="system"){try{d=matchMedia(${literal(DARK_QUERY)}).matches}catch(e){}}document.documentElement.classList.toggle("dark",d);${meta}})();`;
|
|
24
44
|
}
|
|
25
45
|
/**
|
|
26
46
|
* Inline this in `<head>`, before any stylesheet paints, to avoid a flash of the wrong theme:
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/** A palette index (0 darkest) or any CSS colour. */
|
|
2
|
+
export type Ink = number | string;
|
|
3
|
+
/** The pen a sprite draws with: canvas shapes in its inks. */
|
|
4
|
+
export interface Pen {
|
|
5
|
+
c: CanvasRenderingContext2D;
|
|
6
|
+
color(k: Ink): Pen;
|
|
7
|
+
rect(x: number, y: number, w: number, h: number, k?: Ink): Pen;
|
|
8
|
+
circle(x: number, y: number, r: number, k?: Ink): Pen;
|
|
9
|
+
poly(pts: [number, number][], k?: Ink): Pen;
|
|
10
|
+
line(x1: number, y1: number, x2: number, y2: number, w?: number, k?: Ink): Pen;
|
|
11
|
+
path(pts: [number, number][], w?: number, k?: Ink): Pen;
|
|
12
|
+
/** A pixel picture: rows of characters, "a" in ink `ka`, "b" in `kb`, the rest clear. */
|
|
13
|
+
bitmap(x: number, y: number, rows: string[], ka: Ink, kb: Ink, flip?: boolean): Pen;
|
|
14
|
+
}
|
|
15
|
+
/** What the engine needs of a sprite. */
|
|
16
|
+
export interface PixelSprite<Pose> {
|
|
17
|
+
/** Its inks, darkest first. */
|
|
18
|
+
palette: readonly string[];
|
|
19
|
+
/** The outline colour. */
|
|
20
|
+
outline: string;
|
|
21
|
+
/** Sprite size in pixels, and the room over it for jumps and signs. */
|
|
22
|
+
size: number;
|
|
23
|
+
headroom: number;
|
|
24
|
+
/** Draw the pose with the origin on the ground under its middle (y up is negative). */
|
|
25
|
+
draw(g: Pen, pose: Pose): void;
|
|
26
|
+
}
|
|
27
|
+
/** The size of the picture a sprite is drawn into: room either side for arms and signs. */
|
|
28
|
+
export declare function frameSize(s: {
|
|
29
|
+
size: number;
|
|
30
|
+
headroom: number;
|
|
31
|
+
}): {
|
|
32
|
+
width: number;
|
|
33
|
+
height: number;
|
|
34
|
+
};
|
|
35
|
+
export interface FrameOptions {
|
|
36
|
+
/** Sprite pixels it is lifted off the ground, and shaken sideways. */
|
|
37
|
+
lift?: number;
|
|
38
|
+
jitter?: number;
|
|
39
|
+
/** A shadow on the ground under it, smaller as it lifts. */
|
|
40
|
+
shadow?: boolean;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Draw `sprite` in `pose` and snap it to pixels: its palette (with a Bayer dither where it
|
|
44
|
+
* shades), hard edges and a one-pixel outline. Returns the frame as ImageData, ready to put on a
|
|
45
|
+
* canvas of `frameSize(sprite)`.
|
|
46
|
+
*/
|
|
47
|
+
export declare function rasterise<Pose>(sprite: PixelSprite<Pose>, pose: Pose, o?: FrameOptions): ImageData;
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* The pixel engine Tippy is drawn with, ported from the zon gallery's sprite engine (only what
|
|
3
|
+
* Tippy uses). A sprite is a small vector drawing made at sprite size that is snapped to its
|
|
4
|
+
* palette, with an ordered (Bayer) dither where the drawing shades, cut to hard edges and outlined
|
|
5
|
+
* in one pixel. The result is put on a canvas at one canvas pixel to a sprite pixel and scaled up
|
|
6
|
+
* by CSS with `image-rendering: pixelated`, a whole number of device pixels to a sprite pixel.
|
|
7
|
+
*
|
|
8
|
+
* Nothing here touches the DOM until a frame is drawn, so the module is safe to import on a server.
|
|
9
|
+
*/
|
|
10
|
+
const TAU = Math.PI * 2;
|
|
11
|
+
function pen(c, palette) {
|
|
12
|
+
const col = (k) => (typeof k === "number" ? palette[k] : k);
|
|
13
|
+
const g = {
|
|
14
|
+
c,
|
|
15
|
+
color(k) {
|
|
16
|
+
c.fillStyle = col(k);
|
|
17
|
+
c.strokeStyle = col(k);
|
|
18
|
+
return g;
|
|
19
|
+
},
|
|
20
|
+
rect(x, y, w, h, k) {
|
|
21
|
+
if (k !== undefined)
|
|
22
|
+
g.color(k);
|
|
23
|
+
c.fillRect(x, y, w, h);
|
|
24
|
+
return g;
|
|
25
|
+
},
|
|
26
|
+
circle(x, y, r, k) {
|
|
27
|
+
if (k !== undefined)
|
|
28
|
+
g.color(k);
|
|
29
|
+
c.beginPath();
|
|
30
|
+
c.arc(x, y, r, 0, TAU);
|
|
31
|
+
c.fill();
|
|
32
|
+
return g;
|
|
33
|
+
},
|
|
34
|
+
poly(pts, k) {
|
|
35
|
+
if (k !== undefined)
|
|
36
|
+
g.color(k);
|
|
37
|
+
c.beginPath();
|
|
38
|
+
pts.forEach(([x, y], i) => (i ? c.lineTo(x, y) : c.moveTo(x, y)));
|
|
39
|
+
c.closePath();
|
|
40
|
+
c.fill();
|
|
41
|
+
return g;
|
|
42
|
+
},
|
|
43
|
+
line(x1, y1, x2, y2, w = 1, k) {
|
|
44
|
+
if (k !== undefined)
|
|
45
|
+
g.color(k);
|
|
46
|
+
c.lineWidth = w;
|
|
47
|
+
c.lineCap = "round";
|
|
48
|
+
c.beginPath();
|
|
49
|
+
c.moveTo(x1, y1);
|
|
50
|
+
c.lineTo(x2, y2);
|
|
51
|
+
c.stroke();
|
|
52
|
+
return g;
|
|
53
|
+
},
|
|
54
|
+
path(pts, w = 1, k) {
|
|
55
|
+
if (k !== undefined)
|
|
56
|
+
g.color(k);
|
|
57
|
+
c.lineWidth = w;
|
|
58
|
+
c.lineCap = "round";
|
|
59
|
+
c.lineJoin = "round";
|
|
60
|
+
c.beginPath();
|
|
61
|
+
pts.forEach(([x, y], i) => (i ? c.lineTo(x, y) : c.moveTo(x, y)));
|
|
62
|
+
c.stroke();
|
|
63
|
+
return g;
|
|
64
|
+
},
|
|
65
|
+
bitmap(x, y, rows, ka, kb, flip = false) {
|
|
66
|
+
const w = rows[0].length;
|
|
67
|
+
x = Math.round(x);
|
|
68
|
+
y = Math.round(y);
|
|
69
|
+
rows.forEach((row, j) => {
|
|
70
|
+
for (let i = 0; i < row.length; i++) {
|
|
71
|
+
const ch = row[i];
|
|
72
|
+
if (ch !== "a" && ch !== "b")
|
|
73
|
+
continue;
|
|
74
|
+
c.fillStyle = col(ch === "a" ? ka : kb);
|
|
75
|
+
c.fillRect(flip ? x + w - 1 - i : x + i, y + j, 1, 1);
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
return g;
|
|
79
|
+
},
|
|
80
|
+
};
|
|
81
|
+
return g;
|
|
82
|
+
}
|
|
83
|
+
/** The size of the picture a sprite is drawn into: room either side for arms and signs. */
|
|
84
|
+
export function frameSize(s) {
|
|
85
|
+
return { width: s.size * 2, height: s.size + s.headroom };
|
|
86
|
+
}
|
|
87
|
+
const hex = (h) => [
|
|
88
|
+
parseInt(h.slice(1, 3), 16),
|
|
89
|
+
parseInt(h.slice(3, 5), 16),
|
|
90
|
+
parseInt(h.slice(5, 7), 16),
|
|
91
|
+
];
|
|
92
|
+
const BAYER = [0, 8, 2, 10, 12, 4, 14, 6, 3, 11, 1, 9, 15, 7, 13, 5];
|
|
93
|
+
/** How far the dither threshold moves a channel either way. */
|
|
94
|
+
const SPREAD = 56;
|
|
95
|
+
let scratch = null;
|
|
96
|
+
/** The drawing context frames are made on before they are snapped (made on first use). */
|
|
97
|
+
function scratchContext(width, height) {
|
|
98
|
+
if (!scratch) {
|
|
99
|
+
const canvas = document.createElement("canvas");
|
|
100
|
+
scratch = canvas.getContext("2d", { willReadFrequently: true });
|
|
101
|
+
if (!scratch)
|
|
102
|
+
throw new Error("no 2d canvas");
|
|
103
|
+
}
|
|
104
|
+
const canvas = scratch.canvas;
|
|
105
|
+
if (canvas.width !== width)
|
|
106
|
+
canvas.width = width;
|
|
107
|
+
if (canvas.height !== height)
|
|
108
|
+
canvas.height = height;
|
|
109
|
+
scratch.setTransform(1, 0, 0, 1, 0, 0);
|
|
110
|
+
scratch.clearRect(0, 0, width, height);
|
|
111
|
+
return scratch;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Draw `sprite` in `pose` and snap it to pixels: its palette (with a Bayer dither where it
|
|
115
|
+
* shades), hard edges and a one-pixel outline. Returns the frame as ImageData, ready to put on a
|
|
116
|
+
* canvas of `frameSize(sprite)`.
|
|
117
|
+
*/
|
|
118
|
+
export function rasterise(sprite, pose, o = {}) {
|
|
119
|
+
const { width: W, height: H } = frameSize(sprite);
|
|
120
|
+
const ctx = scratchContext(W, H);
|
|
121
|
+
const lift = o.lift ?? 0;
|
|
122
|
+
ctx.save();
|
|
123
|
+
ctx.translate(W / 2 + Math.round(o.jitter ?? 0), H - 2 - lift);
|
|
124
|
+
sprite.draw(pen(ctx, sprite.palette), pose);
|
|
125
|
+
ctx.restore();
|
|
126
|
+
const img = ctx.getImageData(0, 0, W, H);
|
|
127
|
+
const d = img.data;
|
|
128
|
+
const inks = sprite.palette.map(hex);
|
|
129
|
+
const outline = hex(sprite.outline);
|
|
130
|
+
const solid = new Uint8Array(W * H);
|
|
131
|
+
for (let y = 0; y < H; y++)
|
|
132
|
+
for (let x = 0; x < W; x++) {
|
|
133
|
+
const i = (y * W + x) * 4;
|
|
134
|
+
if (d[i + 3] < 128) {
|
|
135
|
+
d[i + 3] = 0;
|
|
136
|
+
continue;
|
|
137
|
+
}
|
|
138
|
+
solid[y * W + x] = 1;
|
|
139
|
+
const th = ((BAYER[((y & 3) << 2) | (x & 3)] + 0.5) / 16 - 0.5) * SPREAD;
|
|
140
|
+
let best = 0;
|
|
141
|
+
let bd = Infinity;
|
|
142
|
+
for (let p = 0; p < inks.length; p++) {
|
|
143
|
+
const q = inks[p];
|
|
144
|
+
const dd = (d[i] + th - q[0]) ** 2 + (d[i + 1] + th - q[1]) ** 2 + (d[i + 2] + th - q[2]) ** 2;
|
|
145
|
+
if (dd < bd) {
|
|
146
|
+
bd = dd;
|
|
147
|
+
best = p;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
const q = inks[best];
|
|
151
|
+
d[i] = q[0];
|
|
152
|
+
d[i + 1] = q[1];
|
|
153
|
+
d[i + 2] = q[2];
|
|
154
|
+
d[i + 3] = 255;
|
|
155
|
+
}
|
|
156
|
+
// The outline: every clear pixel beside a solid one.
|
|
157
|
+
for (let y = 0; y < H; y++)
|
|
158
|
+
for (let x = 0; x < W; x++) {
|
|
159
|
+
if (solid[y * W + x])
|
|
160
|
+
continue;
|
|
161
|
+
const n = (x > 0 && solid[y * W + x - 1]) ||
|
|
162
|
+
(x < W - 1 && solid[y * W + x + 1]) ||
|
|
163
|
+
(y > 0 && solid[(y - 1) * W + x]) ||
|
|
164
|
+
(y < H - 1 && solid[(y + 1) * W + x]);
|
|
165
|
+
if (!n)
|
|
166
|
+
continue;
|
|
167
|
+
const i = (y * W + x) * 4;
|
|
168
|
+
d[i] = outline[0];
|
|
169
|
+
d[i + 1] = outline[1];
|
|
170
|
+
d[i + 2] = outline[2];
|
|
171
|
+
d[i + 3] = 255;
|
|
172
|
+
}
|
|
173
|
+
if (o.shadow) {
|
|
174
|
+
// A soft shadow on the ground, under whatever is clear there: narrower the higher it is.
|
|
175
|
+
const S = sprite.size;
|
|
176
|
+
const half = Math.round(Math.max(S * 0.08, S * 0.32 - lift * 0.4));
|
|
177
|
+
for (const y of [H - 3, H - 2])
|
|
178
|
+
for (let x = W / 2 - half; x < W / 2 + half; x++) {
|
|
179
|
+
const i = (y * W + x) * 4;
|
|
180
|
+
if (d[i + 3])
|
|
181
|
+
continue;
|
|
182
|
+
d[i] = d[i + 1] = d[i + 2] = 0;
|
|
183
|
+
d[i + 3] = 90;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
return img;
|
|
187
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import type { Pen, PixelSprite } from "./pixels.js";
|
|
2
|
+
/** Every move Tippy plays here. */
|
|
3
|
+
export declare const TIPPY_MOVES: readonly ["idle", "walk", "run", "jump", "sit", "wave", "nod", "shake", "shrug", "think", "look", "cheer", "giggle", "love", "surprise", "shy", "error", "success"];
|
|
4
|
+
export type TippyMove = (typeof TIPPY_MOVES)[number];
|
|
5
|
+
/** How long one round of each move takes, in seconds (sit holds once it is down). */
|
|
6
|
+
export declare const MOVE_LENGTH: Record<TippyMove, number>;
|
|
7
|
+
/** The moment of each move to show when it holds still (reduced motion): the move at its clearest. */
|
|
8
|
+
export declare const STILL: Record<TippyMove, number>;
|
|
9
|
+
declare const EYES: Record<string, {
|
|
10
|
+
rows: string[];
|
|
11
|
+
mirror?: boolean;
|
|
12
|
+
}>;
|
|
13
|
+
type Eye = keyof typeof EYES;
|
|
14
|
+
declare const MOUTHS: {
|
|
15
|
+
w: string[];
|
|
16
|
+
o: string[];
|
|
17
|
+
smile: string[];
|
|
18
|
+
};
|
|
19
|
+
type Mouth = keyof typeof MOUTHS;
|
|
20
|
+
type Sign = "!" | "?" | "check" | "cross" | "heart" | "confetti";
|
|
21
|
+
/** An arm: from the shoulder at an angle outward from straight down, or with its hand put somewhere. */
|
|
22
|
+
type Arm = {
|
|
23
|
+
ang: number;
|
|
24
|
+
len?: number;
|
|
25
|
+
to?: undefined;
|
|
26
|
+
behind?: undefined;
|
|
27
|
+
} | {
|
|
28
|
+
to: [number, number];
|
|
29
|
+
behind?: boolean;
|
|
30
|
+
ang?: undefined;
|
|
31
|
+
len?: undefined;
|
|
32
|
+
} | null;
|
|
33
|
+
interface Body {
|
|
34
|
+
x: number;
|
|
35
|
+
y: number;
|
|
36
|
+
dx: number;
|
|
37
|
+
rot: number;
|
|
38
|
+
px: number;
|
|
39
|
+
py: number;
|
|
40
|
+
cx: number;
|
|
41
|
+
sx: number;
|
|
42
|
+
sy: number;
|
|
43
|
+
lift: number;
|
|
44
|
+
look: number;
|
|
45
|
+
eyeDy: number;
|
|
46
|
+
blink: boolean | null;
|
|
47
|
+
eyes: Eye | [Eye | null, Eye | null] | null;
|
|
48
|
+
mouth: Mouth | null;
|
|
49
|
+
blush: boolean;
|
|
50
|
+
mark: Sign | null;
|
|
51
|
+
markHop: number;
|
|
52
|
+
armL: Arm;
|
|
53
|
+
armR: Arm;
|
|
54
|
+
behind: ((g: Pen) => void) | null;
|
|
55
|
+
front: ((g: Pen) => void) | null;
|
|
56
|
+
/** Its highest point once grounded, for a sign over it. */
|
|
57
|
+
top: number;
|
|
58
|
+
topX: number;
|
|
59
|
+
}
|
|
60
|
+
/** The move it was in when it was changed, how far into it (seconds), and what that came from. */
|
|
61
|
+
export interface TippyFrom {
|
|
62
|
+
move: TippyMove;
|
|
63
|
+
t: number;
|
|
64
|
+
from: TippyFrom | null;
|
|
65
|
+
}
|
|
66
|
+
/** Tippy as it is drawn in one frame. */
|
|
67
|
+
export interface TippyPose {
|
|
68
|
+
body: Body;
|
|
69
|
+
/** Sprite pixels off the ground, and shaken sideways. */
|
|
70
|
+
lift: number;
|
|
71
|
+
jitter: number;
|
|
72
|
+
/** Which way it faces: the picture is mirrored for -1, and its signs are flipped back. */
|
|
73
|
+
dir: 1 | -1;
|
|
74
|
+
/** Seconds, for the confetti. */
|
|
75
|
+
t: number;
|
|
76
|
+
}
|
|
77
|
+
/** Frames a second Tippy is posed at: time is held to whole frames. */
|
|
78
|
+
export declare const FPS = 24;
|
|
79
|
+
/**
|
|
80
|
+
* Tippy in `move`, `t` seconds after it began (held to whole frames at 24 a second), grown out of
|
|
81
|
+
* `from`, facing `dir`.
|
|
82
|
+
*/
|
|
83
|
+
export declare function poseTippy(move: TippyMove, t: number, from: TippyFrom | null, dir?: 1 | -1): TippyPose;
|
|
84
|
+
/** Tippy for the pixel engine: its inks, darkest first, 64 pixels with room over it for a jump and its sign. */
|
|
85
|
+
export declare const TIPPY: PixelSprite<TippyPose>;
|
|
86
|
+
export {};
|