@botzcore/ui 0.0.0-stage → 0.1.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/bar/Bar.svelte ADDED
@@ -0,0 +1,45 @@
1
+ <script lang="ts">let { title, end } = $props();
2
+ export {};
3
+ </script>
4
+
5
+ <header class="bar">
6
+ <h1>{title}</h1>
7
+ <div class="end">{@render end?.()}</div>
8
+ </header>
9
+
10
+ <style>
11
+ /* As tall as the page is told it is (ui/look/tokens.css), from the top of the window down: all else stands under it. */
12
+ .bar {
13
+ position: fixed;
14
+ inset: 0 0 auto;
15
+ z-index: 20;
16
+ display: grid;
17
+ /* The name in the middle, whatever stands at either end. */
18
+ grid-template-columns: minmax(0, 1fr) minmax(0, auto) minmax(0, 1fr);
19
+ align-items: center;
20
+ gap: 0.5rem;
21
+ height: var(--under);
22
+ padding: env(safe-area-inset-top) max(0.75rem, env(safe-area-inset-right)) 0 max(0.75rem, env(safe-area-inset-left));
23
+ border-bottom: 1px solid var(--color-line);
24
+ /* A surface of its own, over the page's: plain, as a card is. */
25
+ background-color: var(--color-card);
26
+ }
27
+
28
+ h1 {
29
+ grid-column: 2;
30
+ overflow: hidden;
31
+ font-size: 0.8125rem;
32
+ font-weight: 500;
33
+ text-overflow: ellipsis;
34
+ white-space: nowrap;
35
+ }
36
+
37
+ .end {
38
+ display: flex;
39
+ grid-column: 3;
40
+ align-items: center;
41
+ justify-content: flex-end;
42
+ gap: 0.25rem;
43
+ min-width: 0;
44
+ }
45
+ </style>
@@ -0,0 +1,9 @@
1
+ import type { Snippet } from 'svelte';
2
+ type Props = {
3
+ title: string;
4
+ /** What stands at its far end. */
5
+ end?: Snippet;
6
+ };
7
+ declare const Bar: import("svelte").Component<Props, {}, "">;
8
+ type Bar = ReturnType<typeof Bar>;
9
+ export default Bar;
package/index.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ export { default as Bar } from './bar/Bar.svelte';
2
+ export { default as Input } from './input/Input.svelte';
3
+ export { default as ThemeToggle } from './look/ThemeToggle.svelte';
package/index.js ADDED
@@ -0,0 +1,5 @@
1
+ // The pieces of botzcore's interface that any app of it can stand on: made of the look (./look), which
2
+ // the app puts on its page for them (look.css), and nothing else of the app they are in.
3
+ export { default as Bar } from './bar/Bar.svelte';
4
+ export { default as Input } from './input/Input.svelte';
5
+ export { default as ThemeToggle } from './look/ThemeToggle.svelte';
@@ -0,0 +1,87 @@
1
+ <script lang="ts">import ArrowUp from '@lucide/svelte/icons/arrow-up';
2
+ /** `onsend` tells whether it took what was written: only then is the box emptied. */
3
+ let { onsend } = $props();
4
+ let text = $state('');
5
+ let box = $state();
6
+ const empty = $derived(!text.trim());
7
+ function send() {
8
+ if (onsend(text))
9
+ text = '';
10
+ box?.focus();
11
+ }
12
+ function key(event) {
13
+ // Enter sends and Shift+Enter breaks the line; not while composing an accent or a glyph.
14
+ if (event.key === 'Enter' && !event.shiftKey && !event.isComposing) {
15
+ event.preventDefault();
16
+ send();
17
+ }
18
+ }
19
+ </script>
20
+
21
+ <form class="input" onsubmit={(event) => (event.preventDefault(), send())}>
22
+ <!-- svelte-ignore a11y_autofocus -->
23
+ <textarea bind:this={box} bind:value={text} onkeydown={key} rows="1" placeholder="Escribe un mensaje" aria-label="Mensaje" autofocus
24
+ ></textarea>
25
+ <button type="submit" disabled={empty} aria-label="Enviar"><ArrowUp size={18} /></button>
26
+ </form>
27
+
28
+ <style>
29
+ .input {
30
+ display: flex;
31
+ align-items: flex-end;
32
+ gap: 0.5rem;
33
+ padding: 0.4rem 0.4rem 0.4rem 0.9rem;
34
+ border: 1px solid var(--color-line);
35
+ border-radius: var(--radius);
36
+ background: var(--surface);
37
+ transition: border-color 200ms var(--ease-fluid);
38
+ }
39
+
40
+ .input:focus-within {
41
+ border-color: var(--color-line-strong);
42
+ }
43
+
44
+ textarea {
45
+ flex: 1;
46
+ /* Grows with what is written, up to a few lines. */
47
+ field-sizing: content;
48
+ max-height: 12rem;
49
+ padding: 0.4rem 0;
50
+ outline: 0;
51
+ resize: none;
52
+ line-height: 1.45;
53
+ }
54
+
55
+ textarea::placeholder {
56
+ color: var(--color-muted);
57
+ }
58
+
59
+ button {
60
+ display: grid;
61
+ place-items: center;
62
+ width: 2.1rem;
63
+ height: 2.1rem;
64
+ /* Inside the box by its padding: its corner stays concentric with the box's. */
65
+ border-radius: var(--round-md);
66
+ background: var(--color-ink);
67
+ color: var(--color-card);
68
+ cursor: pointer;
69
+ transition:
70
+ opacity 200ms var(--ease-fluid),
71
+ transform 200ms var(--ease-fluid);
72
+ }
73
+
74
+ button:disabled {
75
+ opacity: 0.25;
76
+ cursor: default;
77
+ }
78
+
79
+ button:not(:disabled):active {
80
+ transform: scale(0.92);
81
+ }
82
+
83
+ button:focus-visible {
84
+ outline: 2px solid var(--color-line-strong);
85
+ outline-offset: 2px;
86
+ }
87
+ </style>
@@ -0,0 +1,6 @@
1
+ type $$ComponentProps = {
2
+ onsend: (text: string) => boolean;
3
+ };
4
+ declare const Input: import("svelte").Component<$$ComponentProps, {}, "">;
5
+ type Input = ReturnType<typeof Input>;
6
+ export default Input;
@@ -0,0 +1,124 @@
1
+ <script lang="ts">import { onMount } from 'svelte';
2
+ let { dark } = $props();
3
+ // What the bite is taken out with is told from any other on the page.
4
+ const cut = $props.id();
5
+ // Whether it has been shown as it stands: until then it is put that way at once, and not turned into it.
6
+ let settled = $state(false);
7
+ onMount(() => {
8
+ const shown = requestAnimationFrame(() => requestAnimationFrame(() => (settled = true)));
9
+ return () => cancelAnimationFrame(shown);
10
+ });
11
+ </script>
12
+
13
+ <svg class="sign" class:dark class:settled viewBox="0 0 24 24" aria-hidden="true">
14
+ <mask id={cut}>
15
+ <rect width="24" height="24" fill="white" />
16
+ <circle class="cut" cx="17" cy="7.5" r="7.5" fill="black" />
17
+ </mask>
18
+ <g mask="url(#{cut})">
19
+ <circle class="core" cx="12" cy="12" r="9" />
20
+ </g>
21
+ <g class="rays">
22
+ <line x1="12" y1="1.6" x2="12" y2="3.8" />
23
+ <line x1="12" y1="20.2" x2="12" y2="22.4" />
24
+ <line x1="1.6" y1="12" x2="3.8" y2="12" />
25
+ <line x1="20.2" y1="12" x2="22.4" y2="12" />
26
+ <line x1="4.65" y1="4.65" x2="6.2" y2="6.2" />
27
+ <line x1="17.8" y1="17.8" x2="19.35" y2="19.35" />
28
+ <line x1="4.65" y1="19.35" x2="6.2" y2="17.8" />
29
+ <line x1="17.8" y1="6.2" x2="19.35" y2="4.65" />
30
+ </g>
31
+ </svg>
32
+
33
+ <style>
34
+ .sign {
35
+ --ease: cubic-bezier(0.22, 0.8, 0.24, 1);
36
+ --spring: cubic-bezier(0.34, 1.4, 0.64, 1);
37
+ flex: none;
38
+ width: var(--theme-icon, 1.125rem);
39
+ height: var(--theme-icon, 1.125rem);
40
+ overflow: visible;
41
+ }
42
+
43
+ /* The sun: small, with its rays out. */
44
+ .core {
45
+ fill: currentcolor;
46
+ transform-box: fill-box;
47
+ transform-origin: center;
48
+ transform: scale(0.52);
49
+ }
50
+
51
+ /* What takes the bite out of it, kept off to one side until it is a moon. */
52
+ .cut {
53
+ transform: translate(11px, -11px);
54
+ }
55
+
56
+ .rays {
57
+ fill: none;
58
+ stroke: currentcolor;
59
+ stroke-width: 1.8;
60
+ stroke-linecap: round;
61
+ transform-origin: 12px 12px;
62
+ }
63
+
64
+ /* The moon: the whole of it, bitten, with no rays; and the lot turned a little. */
65
+ .sign.dark {
66
+ transform: rotate(-24deg);
67
+ }
68
+
69
+ .dark .core {
70
+ transform: none;
71
+ }
72
+
73
+ .dark .cut {
74
+ transform: none;
75
+ }
76
+
77
+ .dark .rays {
78
+ opacity: 0;
79
+ transform: rotate(-60deg) scale(0.4);
80
+ }
81
+
82
+ /* One turns into the other, once it has been shown as it stands: the sun's rays come out a moment after the rest. */
83
+ .sign.settled {
84
+ transition: transform 700ms var(--spring);
85
+ }
86
+
87
+ .settled .core {
88
+ transition: transform 600ms var(--spring);
89
+ }
90
+
91
+ .settled .cut {
92
+ transition: transform 600ms var(--ease);
93
+ }
94
+
95
+ .settled .rays {
96
+ transition:
97
+ transform 550ms var(--spring) 80ms,
98
+ opacity 350ms var(--ease) 80ms;
99
+ }
100
+
101
+ .settled.dark .rays {
102
+ transition:
103
+ transform 400ms var(--ease),
104
+ opacity 220ms var(--ease);
105
+ }
106
+
107
+ /* Under the pointer of the button it is in it leans, either way. */
108
+ @media (hover: hover) {
109
+ :global(button:hover) > .sign {
110
+ transform: rotate(18deg);
111
+ }
112
+
113
+ :global(button:hover) > .sign.dark {
114
+ transform: rotate(-8deg);
115
+ }
116
+ }
117
+
118
+ @media (prefers-reduced-motion: reduce) {
119
+ .sign.settled,
120
+ .settled :is(.core, .cut, .rays) {
121
+ transition: none;
122
+ }
123
+ }
124
+ </style>
@@ -0,0 +1,7 @@
1
+ type Props = {
2
+ /** Whether what it is the sign of is dark: a moon then, and a sun otherwise. */
3
+ dark: boolean;
4
+ };
5
+ declare const ThemeIcon: import("svelte").Component<Props, {}, "">;
6
+ type ThemeIcon = ReturnType<typeof ThemeIcon>;
7
+ export default ThemeIcon;
@@ -0,0 +1,36 @@
1
+ /*
2
+ * How the page turns to the other theme when its button says so (ThemeToggle.svelte): the
3
+ * new one spreads over the old from where the button is, as a circle with a soft edge. Said to the
4
+ * whole page, which is what turns: the old one stays as it was underneath, and the new one is
5
+ * shown through a hole that grows until nothing of the old is left.
6
+ */
7
+ @property --theme-reveal {
8
+ syntax: '<length>';
9
+ inherits: false;
10
+ initial-value: 0px;
11
+ }
12
+
13
+ ::view-transition-old(root) {
14
+ animation: none;
15
+ mix-blend-mode: normal;
16
+ }
17
+
18
+ ::view-transition-new(root) {
19
+ mix-blend-mode: normal;
20
+ mask-image: radial-gradient(
21
+ circle at var(--reveal-x) var(--reveal-y),
22
+ #000 calc(var(--theme-reveal) - 140px),
23
+ transparent var(--theme-reveal)
24
+ );
25
+ animation: theme-reveal-spread 0.85s cubic-bezier(0.22, 0.8, 0.24, 1) both;
26
+ }
27
+
28
+ @keyframes theme-reveal-spread {
29
+ from {
30
+ --theme-reveal: 0px;
31
+ }
32
+
33
+ to {
34
+ --theme-reveal: var(--reveal-r);
35
+ }
36
+ }
@@ -0,0 +1,38 @@
1
+ <script lang="ts">import { onMount, tick } from 'svelte';
2
+ import { spread, told, worn } from './theme.js';
3
+ import ThemeIcon from './ThemeIcon.svelte';
4
+ import './ThemeToggle.css';
5
+ // The button that turns the page dark, or light again. A sun that turns into a moon
6
+ // (ThemeIcon.svelte); and the new theme spreads over the page from the button
7
+ // (ThemeToggle.css). Which theme the page wears, and keeping it, is theme.ts's: this only says
8
+ // which. A tool of the bar (tool.css), for whichever page wants it.
9
+ let dark = $state(false);
10
+ onMount(() => {
11
+ const follow = () => (dark = worn() === 'dark');
12
+ follow();
13
+ // While the page was told no theme it wears the system's, and so does this.
14
+ const system = matchMedia('(prefers-color-scheme: dark)');
15
+ system.addEventListener('change', follow);
16
+ // Told one from somewhere else, this follows too.
17
+ addEventListener(told, follow);
18
+ return () => {
19
+ system.removeEventListener('change', follow);
20
+ removeEventListener(told, follow);
21
+ };
22
+ });
23
+ /** The new theme spreads over the page from the button (theme.ts, `spread`); which one it is by then, this hears as anything does. */
24
+ function toggle(event) {
25
+ spread(dark ? 'light' : 'dark', event.currentTarget, tick);
26
+ }
27
+ </script>
28
+
29
+ <button
30
+ type="button"
31
+ class="tool"
32
+ aria-label={dark ? 'Cambiar a modo claro' : 'Cambiar a modo oscuro'}
33
+ aria-pressed={dark}
34
+ title={dark ? 'Modo claro' : 'Modo oscuro'}
35
+ onclick={toggle}
36
+ >
37
+ <ThemeIcon {dark} />
38
+ </button>
@@ -0,0 +1,4 @@
1
+ import './ThemeToggle.css';
2
+ declare const ThemeToggle: import("svelte").Component<Record<string, never>, {}, "">;
3
+ type ThemeToggle = ReturnType<typeof ThemeToggle>;
4
+ export default ThemeToggle;
@@ -0,0 +1,47 @@
1
+ /** A token: the property it is, the range it moves in, in steps, the unit it is put on in, and what it is when nobody says. */
2
+ export type Token = {
3
+ property: string;
4
+ least: number;
5
+ most: number;
6
+ step: number;
7
+ unit: string;
8
+ usual: number;
9
+ };
10
+ export declare const tokens: {
11
+ readonly radius: {
12
+ readonly property: "--radius";
13
+ readonly least: 0;
14
+ readonly most: 1.25;
15
+ readonly step: 0.0625;
16
+ readonly unit: "rem";
17
+ readonly usual: 0.625;
18
+ };
19
+ readonly measure: {
20
+ readonly property: "--spread";
21
+ readonly least: 0;
22
+ readonly most: 1;
23
+ readonly step: 1;
24
+ readonly unit: "";
25
+ readonly usual: 0;
26
+ };
27
+ };
28
+ /** How wide the conversation can be: its comfortable measure, or all the room the page leaves it. */
29
+ export declare const measures: {
30
+ readonly comfortable: 0;
31
+ readonly whole: 1;
32
+ };
33
+ export type TokenName = keyof typeof tokens;
34
+ export type Told = Partial<Record<TokenName, number>>;
35
+ /** What the window is told as what is kept changes: whatever shows it follows (`addEventListener(changed, …)`). */
36
+ export declare const changed = "botzcore:appearance";
37
+ /** What this browser was told, of the tokens there are: what is not one of them, or makes no sense, is left out. */
38
+ export declare function told(): Told;
39
+ /** What a token is now: what this browser was told, or what it usually is. */
40
+ export declare const valueOf: (name: TokenName, from?: Told) => number;
41
+ /**
42
+ * Puts a token on the page at once, as it is being chosen: nothing is kept until it is `kept`.
43
+ * Its usual value takes it off the root, so that the styles' own is the one that counts.
44
+ */
45
+ export declare function show(name: TokenName, value: number): void;
46
+ /** Puts what is told on the page, and has this browser keep it; a token told nothing goes back to what it usually is. */
47
+ export declare function keep(said: Told): void;
@@ -0,0 +1,79 @@
1
+ // How the page looks, past its theme (theme.ts): the tokens of its style the person can change,
2
+ // each a custom property on the page's root that the styles are measured from (tokens.css), so
3
+ // that changing one changes everything made of it at once, without anything of the page being
4
+ // made anew. Kept on this browser, as the theme is, and put on before the page is first drawn by
5
+ // what src/app.html runs, so that it never shows as it usually is and then turns.
6
+ //
7
+ // How round its corners are: those of what stands inside something are made of it (`--round-*`,
8
+ // in tokens.css), and keep in proportion as it changes. And how wide the conversation is: a choice
9
+ // of two, kept as a number like any other token, how far it spreads from its comfortable measure
10
+ // to all the room the page leaves it (`--spread`, from which tokens.css makes `--measure`), so that
11
+ // going from one to the other can ease instead of jumping.
12
+ export const tokens = {
13
+ radius: { property: '--radius', least: 0, most: 1.25, step: 0.0625, unit: 'rem', usual: 0.625 },
14
+ measure: { property: '--spread', least: 0, most: 1, step: 1, unit: '', usual: 0 }
15
+ };
16
+ /** How wide the conversation can be: its comfortable measure, or all the room the page leaves it. */
17
+ export const measures = { comfortable: 0, whole: 1 };
18
+ /** What the window is told as what is kept changes: whatever shows it follows (`addEventListener(changed, …)`). */
19
+ export const changed = 'botzcore:appearance';
20
+ /** Under this name the browser keeps what it was told. What src/app.html reads, too, and checks the same way. */
21
+ const kept = 'botzcore:appearance';
22
+ /** A value for a token, within its range and on one of its steps; none, for what is not a number. */
23
+ function fitted(name, value) {
24
+ const { least, most, step } = tokens[name];
25
+ if (typeof value !== 'number' || !Number.isFinite(value))
26
+ return undefined;
27
+ return Math.min(most, Math.max(least, Math.round(value / step) * step));
28
+ }
29
+ /** What this browser was told, of the tokens there are: what is not one of them, or makes no sense, is left out. */
30
+ export function told() {
31
+ try {
32
+ const said = JSON.parse(localStorage.getItem(kept) ?? '{}');
33
+ const out = {};
34
+ if (said && typeof said === 'object')
35
+ for (const name of Object.keys(tokens)) {
36
+ const value = fitted(name, said[name]);
37
+ if (value !== undefined)
38
+ out[name] = value;
39
+ }
40
+ return out;
41
+ }
42
+ catch {
43
+ return {};
44
+ }
45
+ }
46
+ /** What a token is now: what this browser was told, or what it usually is. */
47
+ export const valueOf = (name, from = told()) => from[name] ?? tokens[name].usual;
48
+ /**
49
+ * Puts a token on the page at once, as it is being chosen: nothing is kept until it is `kept`.
50
+ * Its usual value takes it off the root, so that the styles' own is the one that counts.
51
+ */
52
+ export function show(name, value) {
53
+ const root = document.documentElement.style;
54
+ const fit = fitted(name, value) ?? tokens[name].usual;
55
+ if (fit === tokens[name].usual)
56
+ root.removeProperty(tokens[name].property);
57
+ else
58
+ root.setProperty(tokens[name].property, `${fit}${tokens[name].unit}`);
59
+ }
60
+ /** Puts what is told on the page, and has this browser keep it; a token told nothing goes back to what it usually is. */
61
+ export function keep(said) {
62
+ const out = {};
63
+ for (const name of Object.keys(tokens)) {
64
+ const value = fitted(name, said[name]);
65
+ show(name, value ?? tokens[name].usual);
66
+ if (value !== undefined && value !== tokens[name].usual)
67
+ out[name] = value;
68
+ }
69
+ try {
70
+ if (Object.keys(out).length)
71
+ localStorage.setItem(kept, JSON.stringify(out));
72
+ else
73
+ localStorage.removeItem(kept);
74
+ }
75
+ catch {
76
+ // A browser that will not keep it only forgets it on the next visit.
77
+ }
78
+ dispatchEvent(new Event(changed));
79
+ }
package/look/fold.css ADDED
@@ -0,0 +1,17 @@
1
+ /*
2
+ * What folds away: as tall as what it holds, or as nothing while it is inert, eased from one to
3
+ * the other. What it holds is one box, which hides what no longer fits (`min-height: 0`,
4
+ * `overflow: hidden`).
5
+ */
6
+ .fold {
7
+ display: grid;
8
+ grid-template-rows: 1fr;
9
+ transition:
10
+ grid-template-rows 280ms var(--ease-fluid),
11
+ opacity 220ms var(--ease-fluid);
12
+
13
+ &[inert] {
14
+ grid-template-rows: 0fr;
15
+ opacity: 0;
16
+ }
17
+ }
@@ -0,0 +1,3 @@
1
+ export * as theme from './theme.js';
2
+ export * as appearance from './appearance.js';
3
+ export { eased } from './motion.js';
package/look/index.js ADDED
@@ -0,0 +1,7 @@
1
+ // The look, as code: which theme the page wears, what the person changes of its style, and how what
2
+ // moves eases. No component comes with it (they are the package's own entry), so that an app may wear
3
+ // the look and write all its pieces itself. Theme and appearance each say `told` of their own, so
4
+ // each comes under its name.
5
+ export * as theme from "./theme.js";
6
+ export * as appearance from "./appearance.js";
7
+ export { eased } from "./motion.js";
package/look/look.css ADDED
@@ -0,0 +1,18 @@
1
+ /*
2
+ * How botzcore looks, said once for the whole page: its tokens, the page itself and its scrollbars.
3
+ * What a piece looks like is said with the piece, made of these.
4
+ *
5
+ * Tailwind is not imported here: it is the app's, which imports it first and then this (an app's own
6
+ * layout.css), so that the look is made into the app's one stylesheet with whatever Tailwind it has.
7
+ * Tailwind only looks for classes in the app's own folder, never outside it nor in node_modules, where
8
+ * this package is: so it is told here where the package's pieces are, from this file, wherever the
9
+ * package was put, but for its own tooling.
10
+ */
11
+ @import './tokens.css';
12
+ @import './page.css';
13
+ @import './scrollbars.css';
14
+ @import './tool.css';
15
+ @import './fold.css';
16
+ @import './tip.css';
17
+ @source '..';
18
+ @source not '../scripts';
@@ -0,0 +1,10 @@
1
+ import { cubicOut } from 'svelte/easing';
2
+ /**
3
+ * How long a transition the page makes takes, and how it eases: as long as it is said to, coming
4
+ * to rest gently; and no time at all for whoever asked for less motion, which such a transition
5
+ * does not see to by itself as the styles do (page.css).
6
+ */
7
+ export declare const eased: (duration: number) => {
8
+ duration: number;
9
+ easing: typeof cubicOut;
10
+ };
package/look/motion.js ADDED
@@ -0,0 +1,10 @@
1
+ import { cubicOut } from 'svelte/easing';
2
+ /**
3
+ * How long a transition the page makes takes, and how it eases: as long as it is said to, coming
4
+ * to rest gently; and no time at all for whoever asked for less motion, which such a transition
5
+ * does not see to by itself as the styles do (page.css).
6
+ */
7
+ export const eased = (duration) => ({
8
+ duration: typeof matchMedia === 'function' && matchMedia('(prefers-reduced-motion: reduce)').matches ? 0 : duration,
9
+ easing: cubicOut
10
+ });
package/look/page.css ADDED
@@ -0,0 +1,62 @@
1
+ html {
2
+ /* The page never scrolls, and is not to be dragged past its edges either: said here, where the window listens. */
3
+ overscroll-behavior: none;
4
+ background-color: var(--color-page);
5
+ color: var(--color-ink);
6
+ -webkit-font-smoothing: antialiased;
7
+ -moz-osx-font-smoothing: grayscale;
8
+ -webkit-tap-highlight-color: transparent;
9
+ text-rendering: optimizeLegibility;
10
+ }
11
+
12
+ body {
13
+ min-height: 100dvh;
14
+ overflow: hidden;
15
+ /* Light that falls from above and fades toward the edges. */
16
+ background-image:
17
+ radial-gradient(120% 80% at 50% 0%, var(--sheen), transparent 60%),
18
+ radial-gradient(140% 120% at 50% 45%, transparent 55%, var(--vignette));
19
+ }
20
+
21
+ /*
22
+ * The rough surface: a lit relief under a fine grain, over everything that is not content. Part of
23
+ * the page and not of the window: wherever a browser shows what lies past the page's edge, there is
24
+ * no page there for it to blend with, and it would show as it is, pale.
25
+ */
26
+ body::before,
27
+ body::after {
28
+ content: '';
29
+ position: absolute;
30
+ inset: 0;
31
+ z-index: 1;
32
+ pointer-events: none;
33
+ }
34
+
35
+ /* Each shows more or less in the dark: 0.6 in the light and 1 in the dark; 0.5 and 0.35. */
36
+ body::before {
37
+ background-image: url('./texture/relief.svg');
38
+ background-size: 400px 400px;
39
+ mix-blend-mode: multiply;
40
+ opacity: calc(0.6 + 0.4 * var(--dark));
41
+ }
42
+
43
+ body::after {
44
+ background-image: url('./texture/grain.svg');
45
+ background-size: 200px 200px;
46
+ mix-blend-mode: soft-light;
47
+ opacity: calc(0.5 - 0.15 * var(--dark));
48
+ }
49
+
50
+ ::selection {
51
+ background-color: color-mix(in oklab, var(--color-ink) 18%, transparent);
52
+ }
53
+
54
+ @media (prefers-reduced-motion: reduce) {
55
+ *,
56
+ *::before,
57
+ *::after {
58
+ animation-duration: 0.01ms !important;
59
+ transition-duration: 0.01ms !important;
60
+ scroll-behavior: auto !important;
61
+ }
62
+ }
@@ -0,0 +1,51 @@
1
+ /*
2
+ * The scrollbars, everywhere, said once: a fine rounded thumb with no track and no arrows, fainter
3
+ * until its box is pointed at. A box that scrolls down keeps the room of its bar whether it has one
4
+ * or not (`scrollbar-gutter: stable`, said where the box is), so that nothing moves aside as one
5
+ * comes. A browser that draws its own bars over the page (macOS, a phone) is left to.
6
+ *
7
+ * Where these are drawn the standard `scrollbar-width` and `scrollbar-color` must not be said for a
8
+ * box, short of `none`: said, the browser draws its own bar, arrows and all, and not this one.
9
+ */
10
+ @supports selector(::-webkit-scrollbar) {
11
+ ::-webkit-scrollbar {
12
+ width: 8px;
13
+ height: 8px;
14
+ background: transparent;
15
+ }
16
+
17
+ ::-webkit-scrollbar-track,
18
+ ::-webkit-scrollbar-corner {
19
+ background: transparent;
20
+ }
21
+
22
+ ::-webkit-scrollbar-button {
23
+ display: none;
24
+ }
25
+
26
+ /* Four of its eight pixels are the thumb: the rest is room around it, which takes the pointer too. */
27
+ ::-webkit-scrollbar-thumb {
28
+ border: 2px solid transparent;
29
+ border-radius: 999px;
30
+ background-color: color-mix(in oklab, var(--color-ink) 10%, transparent);
31
+ background-clip: content-box;
32
+ }
33
+
34
+ :hover::-webkit-scrollbar-thumb {
35
+ background-color: color-mix(in oklab, var(--color-ink) 24%, transparent);
36
+ }
37
+
38
+ ::-webkit-scrollbar-thumb:hover,
39
+ ::-webkit-scrollbar-thumb:active {
40
+ border-width: 1px;
41
+ background-color: color-mix(in oklab, var(--color-ink) 42%, transparent);
42
+ }
43
+ }
44
+
45
+ /* Where there are none of those to draw, the browser's own, as fine as it makes them and in the same ink. */
46
+ @supports not selector(::-webkit-scrollbar) {
47
+ * {
48
+ scrollbar-width: thin;
49
+ scrollbar-color: color-mix(in oklab, var(--color-ink) 22%, transparent) transparent;
50
+ }
51
+ }
@@ -0,0 +1,11 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" width="200" height="200" viewBox="0 0 200 200">
2
+ <!-- Fine opaque grey grain around mid grey, which soft-light leaves untouched. -->
3
+ <filter id="g" x="0" y="0" width="100%" height="100%" color-interpolation-filters="sRGB">
4
+ <feTurbulence type="fractalNoise" baseFrequency="0.9" numOctaves="3" seed="4" stitchTiles="stitch"/>
5
+ <feColorMatrix type="saturate" values="0"/>
6
+ <feComponentTransfer>
7
+ <feFuncA type="linear" slope="0" intercept="1"/>
8
+ </feComponentTransfer>
9
+ </filter>
10
+ <rect width="200" height="200" filter="url(#g)"/>
11
+ </svg>
@@ -0,0 +1,11 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" width="400" height="400" viewBox="0 0 400 400">
2
+ <!-- Noise that repeats every 400 px, tiled past the edges so the light has neighbours there: no seams. -->
3
+ <filter id="r" filterUnits="userSpaceOnUse" x="-40" y="-40" width="480" height="480" color-interpolation-filters="sRGB">
4
+ <feTurbulence type="fractalNoise" baseFrequency="0.035" numOctaves="5" seed="11" stitchTiles="stitch" x="0" y="0" width="400" height="400" result="noise"/>
5
+ <feTile in="noise" x="-40" y="-40" width="480" height="480" result="tiled"/>
6
+ <feDiffuseLighting in="tiled" surfaceScale="1.4" diffuseConstant="1.05" lighting-color="#ffffff">
7
+ <feDistantLight azimuth="225" elevation="62"/>
8
+ </feDiffuseLighting>
9
+ </filter>
10
+ <rect x="-40" y="-40" width="480" height="480" filter="url(#r)"/>
11
+ </svg>
@@ -0,0 +1,16 @@
1
+ export type Theme = 'light' | 'dark';
2
+ /** What the window hears each time the page is told a theme, or told none. */
3
+ export declare const told = "botzcore:theme";
4
+ /** The theme the page was told to wear, if it was told one. */
5
+ export declare function chosen(): Theme | undefined;
6
+ /** The theme the page is wearing: the one it was told, or the system's. */
7
+ export declare const worn: () => Theme;
8
+ /** Tells the page which theme to wear from now on; with none, it goes back to wearing the system's. */
9
+ export declare function wear(theme: Theme | undefined): void;
10
+ /**
11
+ * Tells the page a theme as `wear` does, the new one spreading over the old from something on the
12
+ * page (ThemeToggle.css): whatever it was told from. `drawn` waits for the page to be as it is
13
+ * from then on, which is what is spread. With no change to see (told the one it wears already),
14
+ * and where nothing is to move, it is only told.
15
+ */
16
+ export declare function spread(theme: Theme | undefined, from: Element, drawn?: () => Promise<void>): void;
package/look/theme.js ADDED
@@ -0,0 +1,75 @@
1
+ // Which theme the page wears. Left alone it wears the system's, light or dark, and changes with
2
+ // it. It can also be told one, which it then wears whatever the system says, and goes on wearing
3
+ // on this browser until it is told otherwise.
4
+ //
5
+ // What is told is on the page's root (`data-theme`), which is all the styles go by (tokens.css);
6
+ // and it is put there before the page is first drawn, by what src/app.html runs, so that the page
7
+ // never shows in one theme and then turns to the other.
8
+ /** Under this name the browser keeps the theme the page was told to wear. What src/app.html reads, too. */
9
+ const kept = 'botzcore:theme';
10
+ /** What the window hears each time the page is told a theme, or told none. */
11
+ export const told = 'botzcore:theme';
12
+ const dark = '(prefers-color-scheme: dark)';
13
+ /** The theme the page was told to wear, if it was told one. */
14
+ export function chosen() {
15
+ const { theme } = document.documentElement.dataset;
16
+ return theme === 'light' || theme === 'dark' ? theme : undefined;
17
+ }
18
+ /** The theme the page is wearing: the one it was told, or the system's. */
19
+ export const worn = () => chosen() ?? (matchMedia(dark).matches ? 'dark' : 'light');
20
+ /**
21
+ * Has the browser's own edges follow. The page says the colour of each theme once (the two
22
+ * `theme-color` tints in src/app.html), each for when the system asks for its theme: told a
23
+ * theme, its tint is the one that counts whatever the system asks for. As src/app.html does.
24
+ */
25
+ function tint(theme) {
26
+ for (const meta of document.querySelectorAll('meta[name="theme-color"][data-theme]')) {
27
+ const its = meta.dataset.theme;
28
+ meta.media = theme ? (its === theme ? 'all' : 'not all') : `(prefers-color-scheme: ${its})`;
29
+ }
30
+ }
31
+ /** Tells the page which theme to wear from now on; with none, it goes back to wearing the system's. */
32
+ export function wear(theme) {
33
+ const root = document.documentElement;
34
+ if (theme)
35
+ root.dataset.theme = theme;
36
+ else
37
+ delete root.dataset.theme;
38
+ tint(theme);
39
+ // Whatever shows which theme it is hears it, wherever it was told from.
40
+ dispatchEvent(new CustomEvent(told));
41
+ try {
42
+ if (theme)
43
+ localStorage.setItem(kept, theme);
44
+ else
45
+ localStorage.removeItem(kept);
46
+ }
47
+ catch {
48
+ // A browser that will not keep it only forgets it on the next visit.
49
+ }
50
+ }
51
+ /**
52
+ * Tells the page a theme as `wear` does, the new one spreading over the old from something on the
53
+ * page (ThemeToggle.css): whatever it was told from. `drawn` waits for the page to be as it is
54
+ * from then on, which is what is spread. With no change to see (told the one it wears already),
55
+ * and where nothing is to move, it is only told.
56
+ */
57
+ export function spread(theme, from, drawn = async () => { }) {
58
+ const to = theme ?? (matchMedia(dark).matches ? 'dark' : 'light');
59
+ const turn = async () => {
60
+ wear(theme);
61
+ await drawn();
62
+ };
63
+ if (to === worn() || !document.startViewTransition || matchMedia('(prefers-reduced-motion: reduce)').matches)
64
+ return void turn();
65
+ // From its middle, as far as the corner of the window that is furthest from it.
66
+ const { left, top, width, height } = from.getBoundingClientRect();
67
+ const x = left + width / 2;
68
+ const y = top + height / 2;
69
+ const radius = Math.hypot(Math.max(x, innerWidth - x), Math.max(y, innerHeight - y)) + 140;
70
+ const root = document.documentElement.style;
71
+ root.setProperty('--reveal-x', `${x}px`);
72
+ root.setProperty('--reveal-y', `${y}px`);
73
+ root.setProperty('--reveal-r', `${radius}px`);
74
+ document.startViewTransition(turn);
75
+ }
package/look/tip.css ADDED
@@ -0,0 +1,12 @@
1
+ /*
2
+ * The arrow of a card that points at what it was asked from (Ark's): a square on its corner, half
3
+ * of it out of the card. Ark turns it so that the corner drawn here, with the card's edge on its
4
+ * two sides, is the one that points. The card says its edge (`--tip-edge`), its size and its
5
+ * ground (`--arrow-size`, `--arrow-background`). The tip itself, the small card that says what
6
+ * something is, is not here yet.
7
+ */
8
+ .tip-arrow-tip {
9
+ border-top: 1px solid var(--tip-edge);
10
+ border-left: 1px solid var(--tip-edge);
11
+ border-top-left-radius: 0.125rem;
12
+ }
@@ -0,0 +1,97 @@
1
+ /*
2
+ * The tokens everything is made of. Each colour is said once, for both themes: `light-dark()`
3
+ * takes the one of the theme the page wears, which is its `color-scheme` (below).
4
+ */
5
+ @theme {
6
+ /* The brand's greys: the favicon's tile and its symbol. */
7
+ --color-page: light-dark(#e9e9eb, #2b2b2f);
8
+ --color-ink: light-dark(#1f1f23, #e7e7ea);
9
+ --color-muted: light-dark(#6b6b74, #8e8e98);
10
+ /* The dark one is also what a browser tints its own edges with (src/app.html). */
11
+ --color-card: light-dark(#ffffff, #26262a);
12
+ --color-line: light-dark(rgb(31 31 35 / 0.1), rgb(231 231 234 / 0.09));
13
+ --color-line-strong: light-dark(rgb(31 31 35 / 0.2), rgb(231 231 234 / 0.2));
14
+ --color-problem: light-dark(#b4372d, #ee8d84);
15
+ /* An address written out among words: told apart from them, as one is anywhere. */
16
+ --color-link: light-dark(#2459c7, #8fb4ff);
17
+
18
+ --ease-fluid: cubic-bezier(0.22, 1, 0.36, 1);
19
+ /* A spring let go: a little past where it is going, and back. For what pops into place. */
20
+ --ease-spring: linear(
21
+ 0, 0.007 1%, 0.025 1.9%, 0.06 3%, 0.115 4.2%, 0.191 5.7%, 0.287 7.3%, 0.399 9%, 0.521 10.9%, 0.646 12.9%,
22
+ 0.766 15%, 0.876 17.2%, 0.969 19.6%, 1.041 22.1%, 1.091 24.6%, 1.118 27.3%, 1.126 30.1%, 1.119 33%, 1.1 36%,
23
+ 1.076 39%, 1.05 42.2%, 1.026 45.5%, 1.007 48.8%, 0.994 52.3%, 0.987 55.8%, 0.984 59.4%, 0.985 63.1%,
24
+ 0.988 66.9%, 0.992 70.8%, 0.996 74.7%, 0.999 78.7%, 1.001 82.8%, 1.002 87%, 1.002 91.3%, 1
25
+ );
26
+ }
27
+
28
+ /*
29
+ * How far the conversation spreads from its comfortable measure to all the room the page leaves
30
+ * it, from none to all (appearance.ts). A number in its own right, so that it can ease from one to
31
+ * the other: easing `max-width` itself from a measure to none would jump, and from one to a very
32
+ * large one would be over long before it ends.
33
+ */
34
+ @property --spread {
35
+ syntax: '<number>';
36
+ inherits: true;
37
+ initial-value: 0;
38
+ }
39
+
40
+ :root {
41
+ /* The system's theme, unless the page is told one (theme.ts). */
42
+ color-scheme: light dark;
43
+ /* Whether the theme worn is the dark one, as a number, for what is no colour and so cannot be said with `light-dark()`. */
44
+ --dark: 0;
45
+
46
+ transition: --spread 360ms var(--ease-fluid);
47
+
48
+ /*
49
+ * How wide the conversation's column is, and all that stands in line with it: comfortable to
50
+ * read, or, spread, all of what it stands in. Its `100%` is that of whoever reads it, which is
51
+ * why it is left unresolved here; where that is narrower than the measure, spreading only takes
52
+ * it to that same width.
53
+ */
54
+ --measure: calc(42rem + (100% - 42rem) * var(--spread));
55
+
56
+ /* The light that falls on the page from above, and the shade toward its edges. */
57
+ --sheen: light-dark(rgb(255 255 255 / 0.55), rgb(255 255 255 / 0.06));
58
+ --vignette: light-dark(rgb(31 31 35 / 0.1), rgb(0 0 0 / 0.4));
59
+
60
+ /* The bar across the top of the page: how tall it is, and where it ends, below which all else stands. */
61
+ --bar: 2.125rem;
62
+ --under: calc(env(safe-area-inset-top) + var(--bar));
63
+ /* The height of the page that is in view: what whatever fills the window is as tall as. */
64
+ --view: 100dvh;
65
+ /* How wide the panel that lists the bots is, which what lies beside it makes room for. */
66
+ --dock: 15rem;
67
+ /* What dims the page behind a dialog. */
68
+ --scrim: light-dark(rgb(31 31 35 / 0.3), rgb(0 0 0 / 0.5));
69
+
70
+ /* What sits on the surface: its corner and its fill. */
71
+ --radius: 0.625rem;
72
+ /*
73
+ * The corners of what stands inside it, made of it, so that changing it (appearance.ts) changes
74
+ * them all in proportion: a card or a field, a row or a button, a mark or a tag. At no corner
75
+ * at all, none of them has one either.
76
+ */
77
+ --round-md: calc(var(--radius) * 0.6);
78
+ --round-sm: calc(var(--radius) * 0.45);
79
+ --round-xs: calc(var(--radius) * 0.3);
80
+ --surface: color-mix(in oklab, var(--color-card) 88%, transparent);
81
+ }
82
+
83
+ /* The theme the page was told to wear, whatever the system asks for. */
84
+ :root[data-theme='light'] {
85
+ color-scheme: light;
86
+ }
87
+
88
+ :root[data-theme='dark'] {
89
+ color-scheme: dark;
90
+ --dark: 1;
91
+ }
92
+
93
+ @media (prefers-color-scheme: dark) {
94
+ :root:not([data-theme='light']) {
95
+ --dark: 1;
96
+ }
97
+ }
package/look/tool.css ADDED
@@ -0,0 +1,39 @@
1
+ /*
2
+ * A tool of the bar: a small square button that is its sign and no more, with a ground only under
3
+ * the pointer. Said once, here, for whatever stands in the bar.
4
+ */
5
+ .tool {
6
+ display: grid;
7
+ flex: none;
8
+ place-items: center;
9
+ width: 1.75rem;
10
+ height: 1.75rem;
11
+ border-radius: max(var(--round-sm), calc(var(--radius) - 0.375rem));
12
+ color: var(--color-muted);
13
+ cursor: pointer;
14
+ outline-offset: -2px;
15
+ transition:
16
+ color 180ms var(--ease-fluid),
17
+ background-color 180ms var(--ease-fluid),
18
+ transform 180ms var(--ease-fluid);
19
+
20
+ @media (hover: hover) {
21
+ &:hover {
22
+ background-color: var(--color-line);
23
+ color: var(--color-ink);
24
+ }
25
+ }
26
+
27
+ &[data-state='open'] {
28
+ background-color: var(--color-line);
29
+ color: var(--color-ink);
30
+ }
31
+
32
+ &:active {
33
+ transform: scale(0.92);
34
+ }
35
+
36
+ &:focus-visible {
37
+ outline: 2px solid var(--color-ink);
38
+ }
39
+ }
package/package.json CHANGED
@@ -1,6 +1,40 @@
1
1
  {
2
- "name": "@botzcore/ui",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
2
+ "name": "@botzcore/ui",
3
+ "version": "0.1.0",
4
+ "description": "What botzcore looks like, for the apps that want it: its theme and its pieces.",
5
+ "license": "UNLICENSED",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/JuanZea/botzcore.git",
9
+ "directory": "ui"
10
+ },
11
+ "type": "module",
12
+ "publishConfig": {
13
+ "access": "public"
14
+ },
15
+ "exports": {
16
+ ".": {
17
+ "types": "./index.d.ts",
18
+ "svelte": "./index.js",
19
+ "default": "./index.js"
20
+ },
21
+ "./look": {
22
+ "types": "./look/index.d.ts",
23
+ "svelte": "./look/index.js",
24
+ "default": "./look/index.js"
25
+ },
26
+ "./look.css": {
27
+ "style": "./look/look.css",
28
+ "default": "./look/look.css"
29
+ },
30
+ "./parts.css": {
31
+ "style": "./parts/parts.css",
32
+ "default": "./parts/parts.css"
33
+ }
34
+ },
35
+ "peerDependencies": {
36
+ "@lucide/svelte": "^1.87.0",
37
+ "svelte": "^5.57.2",
38
+ "tailwindcss": "^4.3.0"
39
+ }
40
+ }
@@ -0,0 +1,113 @@
1
+ /*
2
+ * What a section of the settings is written with: its parts, each under its name, and what is pressed and typed
3
+ * in them. Said apart from the settings themselves (Shell.svelte, in botzcore's app), for whatever else is written the same way.
4
+ *
5
+ * A section may hold more than one thing: each under its name, and a line between one and
6
+ * the next. Some of them are there by what is chosen above them, and come in together.
7
+ */
8
+ .settings-part + .settings-part {
9
+ margin-top: 1.75rem;
10
+ padding-top: 1.5rem;
11
+ border-top: 1px solid var(--color-line);
12
+ }
13
+
14
+ .settings-heading {
15
+ display: flex;
16
+ align-items: center;
17
+ gap: 0.5rem;
18
+ margin-bottom: 0.375rem;
19
+ font-size: 0.9375rem;
20
+ font-weight: 600;
21
+ letter-spacing: -0.01em;
22
+ }
23
+
24
+ .settings-description {
25
+ color: var(--color-muted);
26
+ font-size: 0.875rem;
27
+ line-height: 1.375rem;
28
+ }
29
+
30
+ .settings-problem {
31
+ overflow: hidden;
32
+ min-height: 0;
33
+ color: var(--color-problem);
34
+ font-size: 0.8125rem;
35
+ line-height: 1.25rem;
36
+
37
+ /* Its breathing room is part of what folds. */
38
+ &::before {
39
+ content: '';
40
+ display: block;
41
+ height: 0.5rem;
42
+ }
43
+ }
44
+
45
+ .settings-button {
46
+ display: inline-grid;
47
+ grid-auto-flow: column;
48
+ place-items: center;
49
+ gap: 0.375rem;
50
+ height: 2.25rem;
51
+ padding: 0 0.875rem;
52
+ border-radius: var(--round-md);
53
+ color: var(--color-muted);
54
+ font-size: 0.875rem;
55
+ font-weight: 500;
56
+ cursor: pointer;
57
+ outline-offset: 2px;
58
+ transition:
59
+ color 180ms var(--ease-fluid),
60
+ background-color 180ms var(--ease-fluid),
61
+ opacity 180ms var(--ease-fluid),
62
+ transform 180ms var(--ease-fluid);
63
+
64
+ &:hover:not(:disabled) {
65
+ background-color: var(--color-line);
66
+ color: var(--color-ink);
67
+ }
68
+
69
+ &:active:not(:disabled) {
70
+ transform: scale(0.97);
71
+ }
72
+
73
+ &.primary,
74
+ &.primary:hover {
75
+ background-color: var(--color-ink);
76
+ color: var(--color-page);
77
+ }
78
+
79
+ &:disabled {
80
+ cursor: default;
81
+ }
82
+
83
+ /* Dimmed when it cannot be used, but not while it is at work. */
84
+ &:disabled:not([aria-busy='true']) {
85
+ opacity: 0.45;
86
+ }
87
+
88
+ &:focus-visible {
89
+ outline: 2px solid var(--color-ink);
90
+ }
91
+ }
92
+
93
+ /* Something typed on one line. */
94
+ .settings-input {
95
+ height: 2.5rem;
96
+ padding: 0 0.75rem;
97
+ border-radius: var(--round-md);
98
+ background-color: color-mix(in oklab, var(--color-ink) 5%, transparent);
99
+ box-shadow: inset 0 0 0 1px var(--color-line);
100
+ color: var(--color-ink);
101
+ font-size: 1rem;
102
+ outline: none;
103
+ transition: box-shadow 180ms var(--ease-fluid);
104
+
105
+ &::placeholder {
106
+ color: var(--color-muted);
107
+ opacity: 0.7;
108
+ }
109
+
110
+ &:focus {
111
+ box-shadow: inset 0 0 0 1px var(--color-line-strong);
112
+ }
113
+ }
package/README.md DELETED
@@ -1,3 +0,0 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.