flagstaff 1.8.0 → 1.8.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/dist/box.js CHANGED
@@ -26,14 +26,11 @@ function fitTitle(title, cells) {
26
26
  function topBorder(style, inner, title) {
27
27
  if (style.top === '')
28
28
  return '';
29
- if (title === undefined || title === '')
30
- return style.topLeft + style.top.repeat(inner) + style.topRight;
31
- const fitted = fitTitle(title, Math.max(0, inner - BORDER_CELLS - BORDER_CELLS));
29
+ const fitted = fitTitle(title ?? '', Math.max(0, inner - BORDER_CELLS - BORDER_CELLS));
32
30
  if (fitted === '')
33
31
  return style.topLeft + style.top.repeat(inner) + style.topRight;
34
32
  const label = ` ${fitted} `;
35
- const rest = Math.max(0, inner - width(label) - 1);
36
- return `${style.topLeft}${style.top}${label}${style.top.repeat(rest)}${style.topRight}`;
33
+ return `${style.topLeft}${style.top}${label}${style.top.repeat(inner - width(label) - 1)}${style.topRight}`;
37
34
  }
38
35
  export function box(text, options = {}) {
39
36
  const style = resolve(options.border ?? 'round');
package/dist/conforms.js CHANGED
@@ -7,25 +7,28 @@ function typeOf(value) {
7
7
  return Number.isInteger(value) ? 'integer' : 'number';
8
8
  return typeof value;
9
9
  }
10
+ function checkString(value, node, path) {
11
+ if (value.length < (node.minLength ?? 0))
12
+ return `${path}: must not be empty`;
13
+ if (!new RegExp(node.pattern ?? '').test(value))
14
+ return `${path}: ${JSON.stringify(value)} does not match ${String(node.pattern)}`;
15
+ return undefined;
16
+ }
10
17
  function checkScalar(value, node, path) {
11
18
  if (node.const !== undefined && value !== node.const)
12
19
  return `${path}: expected ${JSON.stringify(node.const)}, got ${JSON.stringify(value)}`;
13
20
  if (node.enum !== undefined && !node.enum.includes(value))
14
21
  return `${path}: not one of ${JSON.stringify(node.enum)}`;
15
- if (typeof value === 'string') {
16
- if (node.minLength !== undefined && value.length < node.minLength)
17
- return `${path}: must not be empty`;
18
- if (node.pattern !== undefined && !new RegExp(node.pattern).test(value))
19
- return `${path}: ${JSON.stringify(value)} does not match ${node.pattern}`;
20
- }
21
- if (typeof value === 'number' && node.minimum !== undefined && value < node.minimum)
22
- return `${path}: must be at least ${node.minimum}`;
23
- if (typeof value === 'number' && node.maximum !== undefined && value > node.maximum)
24
- return `${path}: must be at most ${node.maximum}`;
22
+ if (typeof value === 'string')
23
+ return checkString(value, node, path);
24
+ if (typeof value === 'number' && value < (node.minimum ?? -Infinity))
25
+ return `${path}: must be at least ${String(node.minimum)}`;
26
+ if (typeof value === 'number' && value > (node.maximum ?? Infinity))
27
+ return `${path}: must be at most ${String(node.maximum)}`;
25
28
  return undefined;
26
29
  }
27
30
  function checkArray(value, node, path, root) {
28
- if (node.minItems !== undefined && value.length < node.minItems)
31
+ if (value.length < (node.minItems ?? 0))
29
32
  return `${path}: needs at least ${node.minItems} item(s)`;
30
33
  const { items } = node;
31
34
  if (items === undefined)
@@ -38,13 +41,20 @@ function checkArray(value, node, path, root) {
38
41
  return undefined;
39
42
  }
40
43
  const isSchema = (x) => typeof x === 'object' && x !== null;
44
+ const present = (record, key) => Object.hasOwn(record, key) || (Reflect.has(record, key) && !Reflect.has(Object.prototype, key));
45
+ function ruleFor(node, key) {
46
+ const { properties = {}, additionalProperties } = node;
47
+ if (Object.hasOwn(properties, key))
48
+ return properties[key];
49
+ return isSchema(additionalProperties) ? additionalProperties : undefined;
50
+ }
41
51
  function checkObject(record, node, path, root) {
42
52
  for (const key of node.required ?? []) {
43
- if (!(key in record))
53
+ if (!present(record, key))
44
54
  return `${path}.${key}: required`;
45
55
  }
46
56
  for (const [key, child] of Object.entries(record)) {
47
- const rule = node.properties?.[key] ?? (isSchema(node.additionalProperties) ? node.additionalProperties : undefined);
57
+ const rule = ruleFor(node, key);
48
58
  if (rule === undefined) {
49
59
  if (node.additionalProperties === false)
50
60
  return `${path}.${key}: not allowed`;
package/dist/link.d.ts CHANGED
@@ -45,6 +45,7 @@ export interface Linked {
45
45
  /** A table cell: text, or text with somewhere to go. A plain string stays a plain string. */
46
46
  export type Cell = string | Linked;
47
47
  export declare const cellText: (cell: Cell | undefined) => string;
48
+ /** A plain string has no `href`, so reading one off it is the `undefined` a plain cell means. */
48
49
  export declare const cellHref: (cell: Cell | undefined) => string | undefined;
49
50
  /**
50
51
  * What the content reads as **before** the drawing measures it: the bare text where the
package/dist/link.js CHANGED
@@ -10,11 +10,9 @@ export function painter(terminal) {
10
10
  return { live: supportsLink(runtime), paint: linkFor(runtime) };
11
11
  }
12
12
  export const cellText = (cell) => (typeof cell === 'string' ? cell : (cell?.text ?? ''));
13
- export const cellHref = (cell) => (typeof cell === 'string' || cell === undefined ? undefined : cell.href);
13
+ export const cellHref = (cell) => cell?.href;
14
14
  export function laid(text, href, painted) {
15
- if (href === undefined || href === '')
16
- return text;
17
- return painted.live ? text : painted.paint(text, href);
15
+ return painted.live ? text : painted.paint(text, href ?? '');
18
16
  }
19
17
  export function painted(line, href, painter_) {
20
18
  if (!painter_.live || href === undefined || href === '' || line === '')
package/dist/log-tail.js CHANGED
@@ -20,8 +20,11 @@ export function logTail({ height = HEIGHT } = {}) {
20
20
  frame: (_t, { lines }) => {
21
21
  const current = lines.findLastIndex((entry) => typeof entry !== 'string');
22
22
  let window = [];
23
- for (let i = lines.length - 1; i >= 0 && window.length < shown; i -= 1)
23
+ for (let i = lines.length - 1; i >= 0; i -= 1) {
24
+ if (window.length >= shown)
25
+ break;
24
26
  window = [...rows(lines[i], i === current), ...window];
27
+ }
25
28
  window = window.slice(-shown);
26
29
  if (current >= 0 && !window.some((row) => row.current))
27
30
  window = [...rows(lines[current], true).slice(0, 1), ...window.slice(window.length - (shown - 1))];
package/dist/loop.js CHANGED
@@ -35,19 +35,18 @@ export function hoist(component, rt, initial, opts = {}) {
35
35
  }
36
36
  const TICK_CAP = 1000;
37
37
  function nextDue(timers, until) {
38
- return timers.filter((t) => t.at <= until).sort((a, b) => a.at - b.at || a.id - b.id)[0];
38
+ return timers.filter((t) => t.at <= until).sort((a, b) => a.at - b.at)[0];
39
39
  }
40
40
  export function manualClock(start = 0) {
41
41
  let now = start;
42
- let nextId = 0;
43
42
  let timers = [];
44
43
  return {
45
44
  now: () => now,
46
45
  schedule(fn, ms) {
47
- const id = nextId++;
48
- timers.push({ id, at: now + Math.max(0, ms), fn });
46
+ const timer = { at: now + Math.max(0, ms), fn };
47
+ timers.push(timer);
49
48
  return () => {
50
- timers = timers.filter((t) => t.id !== id);
49
+ timers = timers.filter((t) => t !== timer);
51
50
  };
52
51
  },
53
52
  tick(ms) {
@@ -55,10 +54,10 @@ export function manualClock(start = 0) {
55
54
  let ran = 0;
56
55
  let due = nextDue(timers, until);
57
56
  while (due !== undefined && ran < TICK_CAP) {
58
- const { id, at, fn } = due;
59
- timers = timers.filter((t) => t.id !== id);
60
- now = Math.max(now, at);
61
- fn();
57
+ const timer = due;
58
+ timers = timers.filter((t) => t !== timer);
59
+ now = Math.max(now, timer.at);
60
+ timer.fn();
62
61
  ran += 1;
63
62
  due = nextDue(timers, until);
64
63
  }
package/dist/markdown.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { command, heading, muted, value } from 'roundel/tokens';
2
- const FENCE = /^ {0,3}(`{3,}|~{3,})/;
2
+ const FENCE = /^ {0,3}(`{3,}(?=[^`]*$)|~{3,})/;
3
3
  const HEADING = /^ {0,3}#{1,6}(?=[ \t]|$)/;
4
4
  const BLANK = /^[ \t]*$/;
5
5
  const ITEM = /^ {0,3}(?:[-*+]|\d{1,9}[.)])[ \t]/;
@@ -47,7 +47,7 @@ class Splitter {
47
47
  return;
48
48
  }
49
49
  this.commit();
50
- const opened = { kind, lines: [], end, fence: FENCE.exec(line)?.[1] ?? '' };
50
+ const opened = { kind, lines: [], end, fence: FENCE.exec(line)?.[1] };
51
51
  this.#open = opened;
52
52
  extend(opened, line, end);
53
53
  if (kind === 'heading')
@@ -90,14 +90,15 @@ function inline(line) {
90
90
  }
91
91
  return drawn + line.slice(at);
92
92
  }
93
+ const CLOSING = /[ \t]#+[ \t]*$/;
93
94
  function draw(block) {
94
95
  if (block.kind === 'heading')
95
- return styled(heading, block.source.slice(HEADING.exec(block.source)[0].length).trim(), block.source);
96
+ return styled(heading, block.source.slice(HEADING.exec(block.source)[0].length).replace(CLOSING, '').trim(), block.source);
96
97
  const lines = block.source.split('\n');
97
98
  if (block.kind !== 'code')
98
99
  return lines.map(inline).join('\n');
99
- const fence = FENCE.exec(block.source)[1];
100
- return lines.map((line, i) => (i === 0 || (i === lines.length - 1 && closes(line, fence)) ? muted(line) : command(line))).join('\n');
100
+ const fence = FENCE.exec(lines[0])[1];
101
+ return lines.map((line, i) => (i === 0 || closes(line, fence) ? muted(line) : command(line))).join('\n');
101
102
  }
102
103
  export function markdown() {
103
104
  return {
package/dist/plugin.js CHANGED
@@ -24,7 +24,7 @@ export function validate(plugin) {
24
24
  throw new PluginError('E_PLUGIN_SCHEMA', problem, 'compare the object against flagstaff/schema.json');
25
25
  }
26
26
  const { contract, components = {} } = plugin;
27
- if (contract !== undefined && contract > CONTRACT) {
27
+ if ((contract ?? CONTRACT) > CONTRACT) {
28
28
  throw new PluginError('E_PLUGIN_CONTRACT', `plugin declares contract ${contract}; this flagstaff knows ${CONTRACT}`, `upgrade flagstaff, or set contract: ${CONTRACT}`);
29
29
  }
30
30
  for (const [name, component] of Object.entries(components)) {
@@ -47,7 +47,7 @@ function deepFrozen(value, seen = new WeakMap()) {
47
47
  const copy = (Array.isArray(value) ? [] : {});
48
48
  seen.set(value, copy);
49
49
  for (const [k, v] of Object.entries(value))
50
- Object.defineProperty(copy, k, { value: deepFrozen(v, seen), writable: true, enumerable: true, configurable: true });
50
+ Object.defineProperty(copy, k, { value: deepFrozen(v, seen), enumerable: true });
51
51
  return frozen(copy);
52
52
  }
53
53
  export function register(plugin) {
@@ -10,8 +10,8 @@ const END_SYNC = `${CSI}?2026l`;
10
10
  const SAVE = '\u001B7';
11
11
  const RESTORE = '\u001B8';
12
12
  function columnsOf(out) {
13
- const { columns } = out;
14
- return columns !== undefined && columns > 0 ? columns : DEFAULT_COLUMNS;
13
+ const { columns = 0 } = out;
14
+ return columns > 0 ? columns : DEFAULT_COLUMNS;
15
15
  }
16
16
  function diff(was, now, sameWidth) {
17
17
  const { lines: before, rows: beforeRows } = was;
@@ -34,7 +34,7 @@ function diff(was, now, sameWidth) {
34
34
  }
35
35
  row += beforeRows[line];
36
36
  }
37
- if (sameWidth && line === last && before.length === after.length && before[line] === after[line])
37
+ if (sameWidth && before.length === after.length && before[line] === after[line])
38
38
  return out === '' ? '' : `${SAVE}${out}${RESTORE}`;
39
39
  move(row);
40
40
  return `${out}${CSI}0J${after.slice(line).join('\n')}`;
@@ -42,7 +42,7 @@ function diff(was, now, sameWidth) {
42
42
  export function frameWriter(out) {
43
43
  let shown;
44
44
  let whole;
45
- let size = '';
45
+ let size;
46
46
  const write = (bytes) => {
47
47
  if (bytes !== '')
48
48
  out.write(`${BEGIN_SYNC}${bytes}${END_SYNC}`);
@@ -51,13 +51,14 @@ export function frameWriter(out) {
51
51
  paint(lines) {
52
52
  let frame = lines.length === 0 ? [''] : [...lines];
53
53
  const columns = columnsOf(out);
54
- const tall = (out.rows ?? 0) > 0 ? out.rows : Number.POSITIVE_INFINITY;
54
+ const { rows: height = 0 } = out;
55
+ const tall = height > 0 ? height : Number.POSITIVE_INFINITY;
55
56
  const heights = () => frame.map((line) => lineCount(line, columns));
56
57
  let rows = heights();
57
58
  whole = undefined;
58
59
  if (rows.reduce((sum, n) => sum + n, 0) > tall) {
59
60
  let cut = frame.length;
60
- for (let used = 1; cut > 0 && (used += rows[cut - 1]) <= tall;)
61
+ for (let used = 1; (used += rows[cut - 1]) <= tall;)
61
62
  cut -= 1;
62
63
  whole = frame;
63
64
  frame = [muted(`… ${cut} more`), ...frame.slice(cut)];
@@ -70,7 +71,7 @@ export function frameWriter(out) {
70
71
  shown = now;
71
72
  },
72
73
  release() {
73
- if (shown !== undefined && whole !== undefined)
74
+ if (whole !== undefined)
74
75
  write(diff(shown, { lines: whole, rows: [] }, false));
75
76
  shown = whole = undefined;
76
77
  },
@@ -127,16 +128,14 @@ export function ttyProjection(component, out, clock) {
127
128
  return new TtyProjection(component, out, clock);
128
129
  }
129
130
  export function staticProjection(component, out) {
130
- let written = [];
131
+ let written;
131
132
  const emit = (state) => {
132
133
  const text = component.static(state);
133
134
  if (text === '')
134
135
  return;
135
136
  const lines = text.split('\n');
136
- let shared = 0;
137
- while (shared < written.length && shared < lines.length && written[shared] === lines[shared])
138
- shared += 1;
139
- const fresh = lines.slice(shared);
137
+ const shared = lines.findIndex((line, i) => line !== written?.[i]);
138
+ const fresh = shared === -1 ? [] : lines.slice(shared);
140
139
  written = lines;
141
140
  if (fresh.length > 0)
142
141
  out.write(`${fresh.join('\n')}\n`);
package/dist/table.js CHANGED
@@ -8,9 +8,9 @@ const CHROME_PER_COLUMN = 3;
8
8
  const MIN_COLUMN = 3;
9
9
  const V = '│';
10
10
  const lay = (cell, paint) => laid(cellText(cell), cellHref(cell), paint);
11
- function fitWidths(widths, available, { columns: bounds = [] }) {
11
+ function fitWidths(widths, available, { columns: bounds }) {
12
12
  for (let total = widths.reduce((sum, w) => sum + w, 0); total > available; total--) {
13
- const pick = widths.reduce((best, w, i) => (w > (bounds[i]?.min ?? MIN_COLUMN) && (best < 0 || w > widths[best]) ? i : best), -1);
13
+ const pick = widths.reduce((best, w, i) => (w > (bounds?.[i]?.min ?? MIN_COLUMN) && (best < 0 || w > widths[best]) ? i : best), -1);
14
14
  if (pick < 0)
15
15
  break;
16
16
  widths.splice(pick, 1, widths[pick] - 1);
@@ -27,11 +27,12 @@ function layoutRow(row, widths, options, paint) {
27
27
  const line = painted(plain, cellHref(row[i]), paint);
28
28
  return options.align?.[i] === 'right' ? gap + line : line + gap;
29
29
  };
30
- return Array.from({ length: Math.max(1, ...cells.map((lines) => lines.length)) }, (_, line) => `${V} ${widths.map((w, i) => pad(cells[i]?.[line] ?? '', w, i)).join(` ${V} `)} ${V}`);
30
+ return Array.from({ length: Math.max(...cells.map((lines) => lines.length)) }, (_, line) => `${V} ${cells.map((lines, i) => pad(lines[line] ?? '', widths[i], i)).join(` ${V} `)} ${V}`);
31
31
  }
32
32
  const rule = (widths, [left, mid, right]) => `${left}${widths.map((w) => '─'.repeat(w + 2)).join(mid)}${right}`;
33
33
  export function table(rows, options = {}) {
34
- const columns = Math.max(options.head?.length ?? 0, ...rows.map((row) => row.length), 1);
34
+ const all = options.head === undefined ? rows : [options.head, ...rows];
35
+ const columns = Math.max(1, ...all.map((row) => row.length));
35
36
  options.columns?.forEach((column, i) => {
36
37
  const { min = 0, max = min || 1 } = column ?? {};
37
38
  if ((min % 1) + (max % 1) !== 0 || min < 0 || max < Math.max(min, 1))
@@ -39,7 +40,6 @@ export function table(rows, options = {}) {
39
40
  });
40
41
  const available = Math.max(columns * MIN_COLUMN, (options.width ?? DEFAULT_WIDTH) - columns * CHROME_PER_COLUMN - 1);
41
42
  const paint = painter(options.terminal);
42
- const all = options.head === undefined ? rows : [options.head, ...rows];
43
43
  const widths = fitWidths(Array.from({ length: columns }, (_, i) => Math.min(options.columns?.[i]?.max ?? Infinity, Math.max(0, ...all.map((row) => width(lay(row[i], paint)))))), available, options);
44
44
  const out = [rule(widths, '┌┬┐')];
45
45
  if (options.head !== undefined) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "flagstaff",
3
- "version": "1.8.0",
3
+ "version": "1.8.1",
4
4
  "description": "Spinners, progress, boxes and tables on one terminal frame loop, with a static projection for pipes, screen readers and agents, and a plugin host. No dependency outside the burgee family. Drop-in paths for ora, log-update, boxen and cli-table3.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -165,8 +165,8 @@
165
165
  "dependencies": {
166
166
  "closeout": "^1.1.8",
167
167
  "linegauge": "^1.2.0",
168
- "paratext": "^1.0.11",
169
- "roundel": "^1.2.1"
168
+ "paratext": "^1.0.12",
169
+ "roundel": "^1.3.1"
170
170
  },
171
171
  "devDependencies": {
172
172
  "fast-check": "^4.10.2",