@apliteni/apliteni-ui 0.142.0 → 0.142.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.
@@ -10,6 +10,10 @@
10
10
  // ship in styles/feedback.css (part of the kit stylesheet). Accent-aware.
11
11
  import { esc } from './index.js';
12
12
  import { playEntrance } from '../motion.js';
13
+ import { nearestSection } from '../logic/feedback.js';
14
+
15
+ export { nearestSection };
16
+
13
17
 
14
18
  // Decorative, like every glyph in the kit — the pill and the buttons carry their
15
19
  // own text or aria-label, so the SVGs stay out of the accessibility tree.
@@ -57,21 +61,6 @@ export function feedbackWidget({
57
61
  </div>`;
58
62
  }
59
63
 
60
- // Pure: the closest ancestor-or-preceding h2|h3 that carries an id, else the
61
- // first such heading in `root`. Exported for testing.
62
- export function nearestSection(node, root) {
63
- let el = node && node.nodeType === 3 ? node.parentNode : node;
64
- while (el && el !== root) {
65
- let p = el;
66
- while (p) {
67
- if (p.tagName && /^H[23]$/.test(p.tagName) && p.id) return p;
68
- p = p.previousElementSibling;
69
- }
70
- el = el.parentElement;
71
- }
72
- return root ? root.querySelector('h2[id],h3[id]') : null;
73
- }
74
-
75
64
  const defaultSection = (h) => {
76
65
  if (!h) return { label: 'this page', title: '', anchor: '' };
77
66
  const t = (h.textContent || '').replace(/\s+/g, ' ').trim();
@@ -346,79 +346,7 @@ export function snippet({ label = 'shell', code = '', reveal = false, copy = tru
346
346
  return `<div class="${cx('ui-snippet', reveal && 'ui-snippet--reveal')}"><div class="ui-snippet__bar"><span>${esc(label)}</span>${copyBtn}</div><pre>${code}</pre></div>`;
347
347
  }
348
348
 
349
- // Tiny highlighters. Each escapes first, then wraps the tokens its language
350
- // shows, using the class names in styles/code.css (.k .f .s .u .c). Shell is
351
- // ported from viz/account.mjs; JSON and TypeScript were added for the snippets
352
- // the kit's own docs show.
353
- //
354
- // Every pattern runs over ESCAPED text, so a quoted string ends at &quot; and a
355
- // shell URL stops at any entity. The group order is the class order beside it.
356
- //
357
- // They are small on purpose — they colour short documentation snippets, not
358
- // arbitrary programs. Known limits: no nested template expressions, no regex
359
- // literals, and in TypeScript a `//` inside a string reads as a comment unless a
360
- // `:` precedes it, which is what keeps a URL in a string whole.
361
- const LANGUAGES = {
362
- shell: {
363
- pattern: /(#[^\n]*)|(&quot;(?:[^&]|&(?!quot;))*&quot;|'[^']*')|(https?:\/\/[^\s"'&]+)|(\B--?[A-Za-z][\w-]*)|(^[a-z][\w.-]*)/gm,
364
- classes: ['c', 's', 'u', 'f', 'k'],
365
- },
366
- // A key is a string followed by a colon, matched by lookahead so the colon
367
- // stays unpainted. Keys, string values and scalars take three different
368
- // classes, because a number that looks exactly like a key is not highlighting.
369
- json: {
370
- pattern: /(&quot;(?:[^&]|&(?!quot;))*&quot;)(?=\s*:)|(&quot;(?:[^&]|&(?!quot;))*&quot;)|(\b(?:true|false|null)\b|-?\d+(?:\.\d+)?(?:[eE][+-]?\d+)?)/g,
371
- classes: ['k', 's', 'f'],
372
- },
373
- ts: {
374
- pattern: /(\/\*[\s\S]*?\*\/|(?<![:/])\/\/[^\n]*)|(&quot;(?:[^&]|&(?!quot;))*&quot;|'[^']*'|`[^`]*`)|(\b(?:import|export|from|const|let|var|function|return|async|await|class|extends|implements|interface|type|enum|new|if|else|for|while|of|in|as|default|readonly|void)\b)|(\b(?:true|false|null|undefined)\b|\b\d+(?:\.\d+)?\b)/g,
375
- classes: ['c', 's', 'k', 'f'],
376
- },
377
- };
378
-
379
- /** The languages codeTokens and hlCode understand, so a gate can discover them. */
380
- export const codeLanguages = Object.keys(LANGUAGES);
381
-
382
- const ENTITY = { amp: '&', lt: '<', gt: '>', quot: '"' };
383
- // The exact inverse of esc: every & in escaped text starts one of these four.
384
- const unesc = (text) => text.replace(/&(amp|lt|gt|quot);/g, (_, name) => ENTITY[name]);
385
-
386
- /**
387
- * A language's tokens, as `[{ cls, text }]` with `cls` null between tokens and
388
- * `text` the original unescaped source. Concatenating `text` returns `raw`, so a
389
- * React caller renders the spans from the same string it copies instead of
390
- * keeping a second hand-written copy in step. hlCode joins the same tokens into
391
- * HTML; neither can drift from the other. An unrecognised `lang` is read as
392
- * shell, the way the kit reads every other unknown option name.
393
- *
394
- * No pattern ever matches inside an entity — `#`, `h`, `-`, `/`, `*`, a digit and
395
- * `^[a-z]` do not occur in `&amp;`, `&lt;`, `&gt;` or `&quot;`, no keyword is one
396
- * of `amp`, `lt`, `gt` or `quot`, and every alternative either stops before `&` or
397
- * consumes a whole `&quot;` — so each slice is entity-complete and
398
- * `esc(unesc(slice))` returns the slice unchanged. hlCode's output is therefore
399
- * byte-identical to wrapping the matches in place, which
400
- * src/components/snippet-tokens.test.js holds for every language, against a copy
401
- * of the one-pass implementation hlShell had before #474.
402
- */
403
- export function codeTokens(raw, lang = 'shell') {
404
- const { pattern, classes } = LANGUAGES[lang] || LANGUAGES.shell;
405
- const escaped = esc(raw);
406
- const out = [];
407
- let at = 0;
408
- pattern.lastIndex = 0;
409
- for (const match of escaped.matchAll(pattern)) {
410
- if (match.index > at) out.push({ cls: null, text: unesc(escaped.slice(at, match.index)) });
411
- out.push({ cls: classes[match.slice(1).findIndex(Boolean)], text: unesc(match[0]) });
412
- at = match.index + match[0].length;
413
- }
414
- if (at < escaped.length) out.push({ cls: null, text: unesc(escaped.slice(at)) });
415
- return out;
416
- }
417
-
418
- export const hlCode = (raw, lang = 'shell') =>
419
- codeTokens(raw, lang).map(({ cls, text }) => (cls ? `<span class="${cls}">${esc(text)}</span>` : esc(text))).join('');
420
-
421
- export const hlShell = (raw) => hlCode(raw, 'shell');
349
+ export { codeLanguages, codeTokens, hlCode, hlShell } from '../logic/code.js';
422
350
 
423
351
  export { icon };
424
352
  export { illo, illoNames } from '../assets/illustrations.js';
@@ -7,10 +7,11 @@ import { wireDropdown } from './dropdown.js';
7
7
  import { avatar } from './avatar.js';
8
8
  import { accountMenuNav, initials, toMenuTuple } from './account-nav.js';
9
9
  import { trustedAttr, trustedUrl } from '../html.js';
10
+ import { themeIcon } from '../logic/theme.js';
10
11
  const THEME_KEY = 'apliteni-strategy-theme';
11
12
 
12
13
  // The icon and name show the saved choice, including automatic mode.
13
- export const themeIcon = (t) => t === 'auto' ? icon('monitor') : t === 'light' ? sun : moon;
14
+ export { themeIcon };
14
15
  export const themeName = (t) => t === 'auto' ? 'Theme: Auto. Switch to dark.' :
15
16
  t === 'light' ? 'Theme: Light. Switch to auto.' : 'Theme: Dark. Switch to light.';
16
17
 
@@ -0,0 +1,9 @@
1
+ // The one account navigation definition: the kit's default rows for a consumer's
2
+ // /account page. Labels are raw text, because every nav primitive escapes. `key` means
3
+ // credentials; `plug` means integration. A screen the kit does not ship belongs in the
4
+ // caller's own nav, not here. The vanilla shell and the React AppShell both read it.
5
+ // why: docs/components.md#the-page-shell
6
+ export const ACCOUNT_NAV = [
7
+ { id: 'prefs', icon: 'gear', label: 'Preferences' },
8
+ { id: 'access', icon: 'key', label: 'Access & agents' },
9
+ ];
@@ -0,0 +1,75 @@
1
+ import { esc } from '../html.js';
2
+
3
+ // Tiny highlighters. Each escapes first, then wraps the tokens its language
4
+ // shows, using the class names in styles/code.css (.k .f .s .u .c). Shell is
5
+ // ported from viz/account.mjs; JSON and TypeScript were added for the snippets
6
+ // the kit's own docs show.
7
+ //
8
+ // Every pattern runs over ESCAPED text, so a quoted string ends at &quot; and a
9
+ // shell URL stops at any entity. The group order is the class order beside it.
10
+ //
11
+ // They are small on purpose — they colour short documentation snippets, not
12
+ // arbitrary programs. Known limits: no nested template expressions, no regex
13
+ // literals, and in TypeScript a `//` inside a string reads as a comment unless a
14
+ // `:` precedes it, which is what keeps a URL in a string whole.
15
+ const LANGUAGES = {
16
+ shell: {
17
+ pattern: /(#[^\n]*)|(&quot;(?:[^&]|&(?!quot;))*&quot;|'[^']*')|(https?:\/\/[^\s"'&]+)|(\B--?[A-Za-z][\w-]*)|(^[a-z][\w.-]*)/gm,
18
+ classes: ['c', 's', 'u', 'f', 'k'],
19
+ },
20
+ // A key is a string followed by a colon, matched by lookahead so the colon
21
+ // stays unpainted. Keys, string values and scalars take three different
22
+ // classes, because a number that looks exactly like a key is not highlighting.
23
+ json: {
24
+ pattern: /(&quot;(?:[^&]|&(?!quot;))*&quot;)(?=\s*:)|(&quot;(?:[^&]|&(?!quot;))*&quot;)|(\b(?:true|false|null)\b|-?\d+(?:\.\d+)?(?:[eE][+-]?\d+)?)/g,
25
+ classes: ['k', 's', 'f'],
26
+ },
27
+ ts: {
28
+ pattern: /(\/\*[\s\S]*?\*\/|(?<![:/])\/\/[^\n]*)|(&quot;(?:[^&]|&(?!quot;))*&quot;|'[^']*'|`[^`]*`)|(\b(?:import|export|from|const|let|var|function|return|async|await|class|extends|implements|interface|type|enum|new|if|else|for|while|of|in|as|default|readonly|void)\b)|(\b(?:true|false|null|undefined)\b|\b\d+(?:\.\d+)?\b)/g,
29
+ classes: ['c', 's', 'k', 'f'],
30
+ },
31
+ };
32
+
33
+ /** The languages codeTokens and hlCode understand, so a gate can discover them. */
34
+ export const codeLanguages = Object.keys(LANGUAGES);
35
+
36
+ const ENTITY = { amp: '&', lt: '<', gt: '>', quot: '"' };
37
+ // The exact inverse of esc: every & in escaped text starts one of these four.
38
+ const unesc = (text) => text.replace(/&(amp|lt|gt|quot);/g, (_, name) => ENTITY[name]);
39
+
40
+ /**
41
+ * A language's tokens, as `[{ cls, text }]` with `cls` null between tokens and
42
+ * `text` the original unescaped source. Concatenating `text` returns `raw`, so a
43
+ * React caller renders the spans from the same string it copies instead of
44
+ * keeping a second hand-written copy in step. hlCode joins the same tokens into
45
+ * HTML; neither can drift from the other. An unrecognised `lang` is read as
46
+ * shell, the way the kit reads every other unknown option name.
47
+ *
48
+ * No pattern ever matches inside an entity — `#`, `h`, `-`, `/`, `*`, a digit and
49
+ * `^[a-z]` do not occur in `&amp;`, `&lt;`, `&gt;` or `&quot;`, no keyword is one
50
+ * of `amp`, `lt`, `gt` or `quot`, and every alternative either stops before `&` or
51
+ * consumes a whole `&quot;` — so each slice is entity-complete and
52
+ * `esc(unesc(slice))` returns the slice unchanged. hlCode's output is therefore
53
+ * byte-identical to wrapping the matches in place, which
54
+ * src/logic/code.test.js holds for every language, against a copy
55
+ * of the one-pass implementation hlShell had before #474.
56
+ */
57
+ export function codeTokens(raw, lang = 'shell') {
58
+ const { pattern, classes } = LANGUAGES[lang] || LANGUAGES.shell;
59
+ const escaped = esc(raw);
60
+ const out = [];
61
+ let at = 0;
62
+ pattern.lastIndex = 0;
63
+ for (const match of escaped.matchAll(pattern)) {
64
+ if (match.index > at) out.push({ cls: null, text: unesc(escaped.slice(at, match.index)) });
65
+ out.push({ cls: classes[match.slice(1).findIndex(Boolean)], text: unesc(match[0]) });
66
+ at = match.index + match[0].length;
67
+ }
68
+ if (at < escaped.length) out.push({ cls: null, text: unesc(escaped.slice(at)) });
69
+ return out;
70
+ }
71
+
72
+ export const hlCode = (raw, lang = 'shell') =>
73
+ codeTokens(raw, lang).map(({ cls, text }) => (cls ? `<span class="${cls}">${esc(text)}</span>` : esc(text))).join('');
74
+
75
+ export const hlShell = (raw) => hlCode(raw, 'shell');