@tidal-ts/terminal 0.1.0 → 0.1.2

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/context.d.ts CHANGED
@@ -12,13 +12,16 @@ export interface TerminalProviderProps {
12
12
  * A host's own vocabulary — palette names its chart resolves, or CSS colours.
13
13
  * Omit to let a new leg keep its pair's colour. */
14
14
  palette?: readonly string[];
15
+ /** What a new SPREAD draws in, when the host reserves a colour for one —
16
+ * see {@link TerminalInput.spreadColor}. Absent ⇒ the first free palette key. */
17
+ spreadColor?: string;
15
18
  /** An XState inspector (`@statelyai/inspect`'s `inspect`, or any observer of
16
19
  * inspection events). The host decides whether and when to attach one; the
17
20
  * machine has no opinion and no build-time flag. */
18
21
  inspect?: Observer<InspectionEvent> | ((event: InspectionEvent) => void);
19
22
  children: ReactNode;
20
23
  }
21
- export declare function TerminalProvider({ initialRows, catalog, storage, palette, inspect, children, }: TerminalProviderProps): import("react").JSX.Element;
24
+ export declare function TerminalProvider({ initialRows, catalog, storage, palette, spreadColor, inspect, children, }: TerminalProviderProps): import("react").JSX.Element;
22
25
  export declare function useRows(): RowState[];
23
26
  export declare function useSelectedSeries(): string | null;
24
27
  /** The control-panel expansion (the row whose controls are open) — overrides the
package/dist/context.js CHANGED
@@ -8,9 +8,15 @@ import { activeSlot, terminalMachine, } from './terminalMachine.js';
8
8
  * barrel re-exports these + the event union; the actor + machine stay private.
9
9
  */
10
10
  const TerminalContext = createActorContext(terminalMachine);
11
- export function TerminalProvider({ initialRows, catalog, storage, palette, inspect, children, }) {
11
+ export function TerminalProvider({ initialRows, catalog, storage, palette, spreadColor, inspect, children, }) {
12
12
  return (_jsxs(TerminalContext.Provider, { options: {
13
- input: { initialRows, catalog, storage, ...(palette ? { palette } : {}) },
13
+ input: {
14
+ initialRows,
15
+ catalog,
16
+ storage,
17
+ ...(palette ? { palette } : {}),
18
+ ...(spreadColor ? { spreadColor } : {}),
19
+ },
14
20
  ...(inspect ? { inspect } : {}),
15
21
  }, children: [_jsx(PersistActive, { storage: storage }), children] }));
16
22
  }
package/dist/index.d.ts CHANGED
@@ -7,3 +7,4 @@
7
7
  */
8
8
  export { TerminalProvider, useRows, useSelectedSeries, useExpandedSeries, useControlsOpen, usePresetSaved, useActiveSlot, useAddSeries, useAddPair, useCompareAll, useAddStudy, useSetStudyParam, useOrderSeries, useReindexSeries, useMoveSeriesToRow, useMoveToAxis, useRemoveSeries, usePatchSeries, useToggleVisible, useToggleGroupVisible, useRemoveGroup, useSelectSeries, useExpandSeries, useSetControlsOpen, useSelectPreset, useSavePreset, useSetRowHeights, useAddRow, useRemoveRow, useAxisRanges, useToggleAxisLink, useSwapAxisSide, useSetAxisRange, useSetAxisAuto, useSetAxisLocks, useSetAxisAutoOpts, useSetAxisFormat, useTerminalHotkeys, type TerminalProviderProps, } from './context.js';
9
9
  export { PRESET_SLOTS, MAX_ROWS, activeSlot, canonRows, columnLabel, columnUnits, entryColumn, groupMembers, mintId, axisMoveAllowed, linkToggleAllowed, respecAllowed, studyChainTail, studyOfferable, SOURCE_COLUMNS, swapAllowed, type EditScope, type RowState, type TerminalPreset, type MetricEntry, type PairLegInput, type PresetStorage, type TerminalEvent, type TerminalInput, } from './terminalMachine.js';
10
+ export { axisBindings, allowedAxes, canAddUnit, axisForAdd, type AxisMember, } from './axisPolicy.js';
package/dist/index.js CHANGED
@@ -7,3 +7,7 @@
7
7
  */
8
8
  export { TerminalProvider, useRows, useSelectedSeries, useExpandedSeries, useControlsOpen, usePresetSaved, useActiveSlot, useAddSeries, useAddPair, useCompareAll, useAddStudy, useSetStudyParam, useOrderSeries, useReindexSeries, useMoveSeriesToRow, useMoveToAxis, useRemoveSeries, usePatchSeries, useToggleVisible, useToggleGroupVisible, useRemoveGroup, useSelectSeries, useExpandSeries, useSetControlsOpen, useSelectPreset, useSavePreset, useSetRowHeights, useAddRow, useRemoveRow, useAxisRanges, useToggleAxisLink, useSwapAxisSide, useSetAxisRange, useSetAxisAuto, useSetAxisLocks, useSetAxisAutoOpts, useSetAxisFormat, useTerminalHotkeys, } from './context.js';
9
9
  export { PRESET_SLOTS, MAX_ROWS, activeSlot, canonRows, columnLabel, columnUnits, entryColumn, groupMembers, mintId, axisMoveAllowed, linkToggleAllowed, respecAllowed, studyChainTail, studyOfferable, SOURCE_COLUMNS, swapAllowed, } from './terminalMachine.js';
10
+ // The axis policy a host's MENUS gate on — the same predicates the machine's
11
+ // guards enforce, exported so the two cannot disagree (0.1.0 left them internal;
12
+ // a host had to keep its own copy).
13
+ export { axisBindings, allowedAxes, canAddUnit, axisForAdd, } from './axisPolicy.js';
@@ -82,6 +82,8 @@ export declare const mintId: (seq: number) => string;
82
82
  interface TerminalContext {
83
83
  /** The host's colour keys for new series, in hand-out order. */
84
84
  palette: readonly string[];
85
+ /** What a new spread draws in, when the host reserves a colour for one. */
86
+ spreadColor: string | undefined;
85
87
  rows: RowState[];
86
88
  /** Per-axis range state, keyed by axis id (`configAxisId` — `rowId:side` for a
87
89
  * shared axis, `rowId:side:configId` for an unlinked series' own axis). No
@@ -297,6 +299,12 @@ export interface TerminalInput {
297
299
  /** The colour keys the host hands a new series, in order — see
298
300
  * `TerminalProviderProps.palette`. Default: none (a leg keeps its pair's). */
299
301
  palette?: readonly string[];
302
+ /** What a new SPREAD draws in, when the host reserves a colour for one (a
303
+ * palette key its chart resolves, or a CSS colour). A spread is a different
304
+ * KIND of line from the series it is built from, and a palette that means
305
+ * something — a hue reserved for comparison, say — cannot express that by
306
+ * position. Absent ⇒ the first free palette key. */
307
+ spreadColor?: string;
300
308
  }
301
309
  /**
302
310
  * The row's configs as **blocks** — each root with the studies layered on it,
@@ -382,10 +390,13 @@ export declare const columnUnits: (catalog: EditScope["catalog"], configs?: read
382
390
  * construction (oscillates about 0 or 1), so it starts on its own scale and
383
391
  * binds no side's unit — one re-link click away from sharing if wanted (the
384
392
  * axis panel). Unit rules still matter for that re-link: a diff of like units
385
- * reads in that unit; a ratio/log-ratio is unitless. Purple default so a
386
- * spread reads distinctly from studies (amber); the user recolours. */
387
- /** The spread's colour when the host supplies no palette — a plain CSS colour
388
- * (a soft violet) any `resolveColor` passes through unchanged. */
393
+ * reads in that unit; a ratio/log-ratio is unitless. Its colour is the host's
394
+ * {@link TerminalInput.spreadColor} when set — a spread should read
395
+ * distinctly from the series it is built from, and only the host knows what
396
+ * its palette reserves for what; the user recolours either way. */
397
+ /** The spread's colour when the host names neither a `spreadColor` nor a
398
+ * palette — a plain CSS colour (a soft violet) any `resolveColor` passes
399
+ * through unchanged. */
389
400
  export declare const DEFAULT_SPREAD_COLOR = "#8b7cf6";
390
401
  /** The display name of a column — its catalog entry's, else a seated config's,
391
402
  * else the raw column. Exported because the PANEL names pair parts too (it
@@ -602,24 +602,28 @@ const pairSpec = (a, aIn, b, bIn, op) => {
602
602
  * construction (oscillates about 0 or 1), so it starts on its own scale and
603
603
  * binds no side's unit — one re-link click away from sharing if wanted (the
604
604
  * axis panel). Unit rules still matter for that re-link: a diff of like units
605
- * reads in that unit; a ratio/log-ratio is unitless. Purple default so a
606
- * spread reads distinctly from studies (amber); the user recolours. */
607
- /** The spread's colour when the host supplies no palette — a plain CSS colour
608
- * (a soft violet) any `resolveColor` passes through unchanged. */
605
+ * reads in that unit; a ratio/log-ratio is unitless. Its colour is the host's
606
+ * {@link TerminalInput.spreadColor} when set — a spread should read
607
+ * distinctly from the series it is built from, and only the host knows what
608
+ * its palette reserves for what; the user recolours either way. */
609
+ /** The spread's colour when the host names neither a `spreadColor` nor a
610
+ * palette — a plain CSS colour (a soft violet) any `resolveColor` passes
611
+ * through unchanged. */
609
612
  export const DEFAULT_SPREAD_COLOR = '#8b7cf6';
610
613
  function pairConfig(a, aIn, b, bIn, op, id, unitOf,
611
- /** The host's colour keys, and the colours already drawn — the spread takes
612
- * the first key not in use, else the palette's first, else
613
- * {@link DEFAULT_SPREAD_COLOR}: a config needs SOME colour, and a host that
614
- * supplies no palette gets a plain CSS one its resolver passes through. */
615
- palette = [], taken = []) {
614
+ /** What the host reserves for a spread, if anything; else its colour keys and
615
+ * the colours already drawn — the spread takes `spreadColor`, else the first
616
+ * key not in use, else the palette's first, else {@link DEFAULT_SPREAD_COLOR}.
617
+ * A config needs SOME colour, and a host that names neither gets a plain CSS
618
+ * one its resolver passes through. */
619
+ palette = [], taken = [], spreadColor) {
616
620
  const la = boundLeg(a, aIn);
617
621
  const lb = boundLeg(b, bIn);
618
622
  const derive = { op, inputs: [la.graph, lb.graph] };
619
623
  return {
620
624
  id,
621
625
  label: PAIR_LABEL[op](la.label, lb.label),
622
- color: palette.find((k) => !taken.includes(k)) ?? palette[0] ?? DEFAULT_SPREAD_COLOR,
626
+ color: spreadColor ?? palette.find((k) => !taken.includes(k)) ?? palette[0] ?? DEFAULT_SPREAD_COLOR,
623
627
  axis: 'R',
624
628
  axisGroup: id, // its own scale — the key IS its id, so the axis id is stable
625
629
  style: 'line',
@@ -688,7 +692,7 @@ function planAddGroup(context, event, row) {
688
692
  // to build its plan with. It is scaffolding, not memory: f() is fixed at
689
693
  // creation, and nothing reads this back or restores it.
690
694
  const join = event.op === 'none' ? 'diff' : event.op;
691
- const pair = pairConfig(a, event.a, b, event.b, join, mintId(context.cfgSeq), unitOfColumn(context), context.palette, row.configs.map((c) => c.color));
695
+ const pair = pairConfig(a, event.a, b, event.b, join, mintId(context.cfgSeq), unitOfColumn(context), context.palette, row.configs.map((c) => c.color), context.spreadColor);
692
696
  return planSplit(context, pair, row.configs, context.cfgSeq + 1, true);
693
697
  }
694
698
  /** Whether an `addPair` will actually seat a config — the same early returns the
@@ -1529,7 +1533,7 @@ export const terminalMachine = setup({
1529
1533
  // axis (pairConfig), binding no unit — the old `axisForAdd` dance (and
1530
1534
  // its guard/action-agreement hazard, PR #128) retires with it.
1531
1535
  const cfg = pairConfig(a, event.a, b, event.b, event.op, // 'none' returned above
1532
- mintId(context.cfgSeq), unitOfColumn(context), context.palette, flatConfigs(context.rows).map((c) => c.color));
1536
+ mintId(context.cfgSeq), unitOfColumn(context), context.palette, flatConfigs(context.rows).map((c) => c.color), context.spreadColor);
1533
1537
  // In front of leg A when it is seated — the spread is the signal and
1534
1538
  // must read over its legs (a study's insertion rule). An UNSEATED leg
1535
1539
  // adds nothing: the spread lands alone at the front of A's source row.
@@ -2166,6 +2170,7 @@ export const terminalMachine = setup({
2166
2170
  // straight into the stuck-seam state rather than being healed on first edit.
2167
2171
  rows: withRemainder(input.initialRows),
2168
2172
  palette: input.palette ?? [],
2173
+ spreadColor: input.spreadColor,
2169
2174
  axisRanges: {},
2170
2175
  rowSeq: input.initialRows.length,
2171
2176
  cfgSeq: cfgSeqAfter(input.initialRows),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tidal-ts/terminal",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "private": false,
5
5
  "description": "The terminal machine — an XState v5 statechart that owns a chart's configuration (rows, series, studies, pairs, axes, presets) and never its data.",
6
6
  "license": "MIT",
@@ -36,8 +36,8 @@
36
36
  "xstate": "^5.28.0"
37
37
  },
38
38
  "dependencies": {
39
- "@tidal-ts/chart": "0.1.0",
40
- "@tidal-ts/core": "0.1.0"
39
+ "@tidal-ts/chart": "0.1.2",
40
+ "@tidal-ts/core": "0.1.2"
41
41
  },
42
42
  "devDependencies": {
43
43
  "@pond-ts/financial": "^0.69.0",