@philosaether/chipper 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.
Files changed (122) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +778 -0
  3. package/dist/base.css +1 -0
  4. package/dist/headless.d.ts +16 -0
  5. package/dist/headless.d.ts.map +1 -0
  6. package/dist/headless.js +18 -0
  7. package/dist/index.js +1445 -0
  8. package/dist/src/builder/index.d.ts +82 -0
  9. package/dist/src/builder/index.d.ts.map +1 -0
  10. package/dist/src/builder/predicates.d.ts +18 -0
  11. package/dist/src/builder/predicates.d.ts.map +1 -0
  12. package/dist/src/components/Chip.d.ts +15 -0
  13. package/dist/src/components/Chip.d.ts.map +1 -0
  14. package/dist/src/components/ChipInfoPopup.d.ts +12 -0
  15. package/dist/src/components/ChipInfoPopup.d.ts.map +1 -0
  16. package/dist/src/components/ChipPopup.d.ts +20 -0
  17. package/dist/src/components/ChipPopup.d.ts.map +1 -0
  18. package/dist/src/components/Chipper.d.ts +25 -0
  19. package/dist/src/components/Chipper.d.ts.map +1 -0
  20. package/dist/src/components/Clause.d.ts +13 -0
  21. package/dist/src/components/Clause.d.ts.map +1 -0
  22. package/dist/src/components/Sentence.d.ts +15 -0
  23. package/dist/src/components/Sentence.d.ts.map +1 -0
  24. package/dist/src/components/index.d.ts +12 -0
  25. package/dist/src/components/index.d.ts.map +1 -0
  26. package/dist/src/components/popups/AlternativeCoordinatePopup.d.ts +16 -0
  27. package/dist/src/components/popups/AlternativeCoordinatePopup.d.ts.map +1 -0
  28. package/dist/src/components/popups/KeywordGroupList.d.ts +29 -0
  29. package/dist/src/components/popups/KeywordGroupList.d.ts.map +1 -0
  30. package/dist/src/components/popups/KeywordOrExpressionPopup.d.ts +30 -0
  31. package/dist/src/components/popups/KeywordOrExpressionPopup.d.ts.map +1 -0
  32. package/dist/src/components/popups/MultiSelectPopup.d.ts +20 -0
  33. package/dist/src/components/popups/MultiSelectPopup.d.ts.map +1 -0
  34. package/dist/src/components/popups/NumericInput.d.ts +16 -0
  35. package/dist/src/components/popups/NumericInput.d.ts.map +1 -0
  36. package/dist/src/components/popups/ReferencePopup.d.ts +20 -0
  37. package/dist/src/components/popups/ReferencePopup.d.ts.map +1 -0
  38. package/dist/src/core/actions/set-chip-value.d.ts +17 -0
  39. package/dist/src/core/actions/set-chip-value.d.ts.map +1 -0
  40. package/dist/src/core/actions/set-context.d.ts +18 -0
  41. package/dist/src/core/actions/set-context.d.ts.map +1 -0
  42. package/dist/src/core/actions/set-display-value.d.ts +18 -0
  43. package/dist/src/core/actions/set-display-value.d.ts.map +1 -0
  44. package/dist/src/core/actions/toggle-clause.d.ts +15 -0
  45. package/dist/src/core/actions/toggle-clause.d.ts.map +1 -0
  46. package/dist/src/core/context-resolution.d.ts +36 -0
  47. package/dist/src/core/context-resolution.d.ts.map +1 -0
  48. package/dist/src/core/initialize.d.ts +43 -0
  49. package/dist/src/core/initialize.d.ts.map +1 -0
  50. package/dist/src/core/mode-switching.d.ts +10 -0
  51. package/dist/src/core/mode-switching.d.ts.map +1 -0
  52. package/dist/src/core/reducer.d.ts +16 -0
  53. package/dist/src/core/reducer.d.ts.map +1 -0
  54. package/dist/src/core/resolve-keyword-label.d.ts +7 -0
  55. package/dist/src/core/resolve-keyword-label.d.ts.map +1 -0
  56. package/dist/src/core/serialize.d.ts +34 -0
  57. package/dist/src/core/serialize.d.ts.map +1 -0
  58. package/dist/src/core/state.d.ts +59 -0
  59. package/dist/src/core/state.d.ts.map +1 -0
  60. package/dist/src/core/store.d.ts +23 -0
  61. package/dist/src/core/store.d.ts.map +1 -0
  62. package/dist/src/core/types.d.ts +242 -0
  63. package/dist/src/core/types.d.ts.map +1 -0
  64. package/dist/src/domains/alternative-coordinate.d.ts +110 -0
  65. package/dist/src/domains/alternative-coordinate.d.ts.map +1 -0
  66. package/dist/src/domains/create-domain.d.ts +30 -0
  67. package/dist/src/domains/create-domain.d.ts.map +1 -0
  68. package/dist/src/domains/facades.d.ts +134 -0
  69. package/dist/src/domains/facades.d.ts.map +1 -0
  70. package/dist/src/domains/index.d.ts +14 -0
  71. package/dist/src/domains/index.d.ts.map +1 -0
  72. package/dist/src/domains/keyword-or-expression.d.ts +148 -0
  73. package/dist/src/domains/keyword-or-expression.d.ts.map +1 -0
  74. package/dist/src/domains/multi-select.d.ts +68 -0
  75. package/dist/src/domains/multi-select.d.ts.map +1 -0
  76. package/dist/src/domains/normalize-keywords.d.ts +83 -0
  77. package/dist/src/domains/normalize-keywords.d.ts.map +1 -0
  78. package/dist/src/domains/reference.d.ts +89 -0
  79. package/dist/src/domains/reference.d.ts.map +1 -0
  80. package/dist/src/hooks/SentenceProvider.d.ts +17 -0
  81. package/dist/src/hooks/SentenceProvider.d.ts.map +1 -0
  82. package/dist/src/hooks/context.d.ts +31 -0
  83. package/dist/src/hooks/context.d.ts.map +1 -0
  84. package/dist/src/hooks/index.d.ts +13 -0
  85. package/dist/src/hooks/index.d.ts.map +1 -0
  86. package/dist/src/hooks/useChip.d.ts +21 -0
  87. package/dist/src/hooks/useChip.d.ts.map +1 -0
  88. package/dist/src/hooks/useDisplaySource.d.ts +16 -0
  89. package/dist/src/hooks/useDisplaySource.d.ts.map +1 -0
  90. package/dist/src/hooks/useKeyboardNavigation.d.ts +44 -0
  91. package/dist/src/hooks/useKeyboardNavigation.d.ts.map +1 -0
  92. package/dist/src/hooks/usePopup.d.ts +13 -0
  93. package/dist/src/hooks/usePopup.d.ts.map +1 -0
  94. package/dist/src/hooks/useReferenceDisplay.d.ts +22 -0
  95. package/dist/src/hooks/useReferenceDisplay.d.ts.map +1 -0
  96. package/dist/src/hooks/useSentence.d.ts +14 -0
  97. package/dist/src/hooks/useSentence.d.ts.map +1 -0
  98. package/dist/src/index.d.ts +25 -0
  99. package/dist/src/index.d.ts.map +1 -0
  100. package/dist/src/palette/index.d.ts +29 -0
  101. package/dist/src/palette/index.d.ts.map +1 -0
  102. package/dist/src/themes/apply-theme.d.ts +34 -0
  103. package/dist/src/themes/apply-theme.d.ts.map +1 -0
  104. package/dist/src/themes/create-hue.d.ts +23 -0
  105. package/dist/src/themes/create-hue.d.ts.map +1 -0
  106. package/dist/src/themes/index.d.ts +13 -0
  107. package/dist/src/themes/index.d.ts.map +1 -0
  108. package/dist/src/themes/midnight.d.ts +11 -0
  109. package/dist/src/themes/midnight.d.ts.map +1 -0
  110. package/dist/src/themes/praxis.d.ts +11 -0
  111. package/dist/src/themes/praxis.d.ts.map +1 -0
  112. package/dist/src/themes/terminal.d.ts +9 -0
  113. package/dist/src/themes/terminal.d.ts.map +1 -0
  114. package/dist/src/themes/types.d.ts +72 -0
  115. package/dist/src/themes/types.d.ts.map +1 -0
  116. package/dist/styles.css +1 -0
  117. package/dist/themes/index.js +256 -0
  118. package/dist/themes/midnight.css +1 -0
  119. package/dist/themes/praxis.css +1 -0
  120. package/dist/themes/terminal.css +1 -0
  121. package/dist/usePopup-Of6OHa1_.js +653 -0
  122. package/package.json +75 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mode-switching.d.ts","sourceRoot":"","sources":["../../../src/core/mode-switching.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,qFAAqF;AACrF,eAAO,MAAM,gBAAgB,eAA4B,CAAC"}
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Sentence reducer — pure state transitions for a Chipper sentence.
3
+ *
4
+ * The reducer operates on SentenceStore (state + resolved domains).
5
+ * Each action type is handled by its own file under actions/.
6
+ */
7
+ import type { SentenceStore } from './store';
8
+ import { type SetChipValueAction } from './actions/set-chip-value';
9
+ import { type ToggleClauseAction } from './actions/toggle-clause';
10
+ import { type SetContextAction } from './actions/set-context';
11
+ import { type SetDisplayValueAction } from './actions/set-display-value';
12
+ /** Union of all sentence actions. */
13
+ export type SentenceAction = SetChipValueAction | ToggleClauseAction | SetContextAction | SetDisplayValueAction;
14
+ /** Reduce a sentence action into a new store. */
15
+ export declare function sentenceReducer(store: SentenceStore, action: SentenceAction): SentenceStore;
16
+ //# sourceMappingURL=reducer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reducer.d.ts","sourceRoot":"","sources":["../../../src/core/reducer.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAC7C,OAAO,EAAsB,KAAK,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AACvF,OAAO,EAAsB,KAAK,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AACtF,OAAO,EAAoB,KAAK,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAChF,OAAO,EAAyB,KAAK,qBAAqB,EAAE,MAAM,6BAA6B,CAAC;AAEhG,qCAAqC;AACrC,MAAM,MAAM,cAAc,GACtB,kBAAkB,GAClB,kBAAkB,GAClB,gBAAgB,GAChB,qBAAqB,CAAC;AAE1B,iDAAiD;AACjD,wBAAgB,eAAe,CAC7B,KAAK,EAAE,aAAa,EACpB,MAAM,EAAE,cAAc,GACrB,aAAa,CAWf"}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Resolve a keyword's display label, handling both static strings
3
+ * and dynamic context functions.
4
+ */
5
+ import type { Keyword, SentenceContext } from './types';
6
+ export declare function resolveKeywordLabel(keyword: Keyword, context?: SentenceContext): string;
7
+ //# sourceMappingURL=resolve-keyword-label.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resolve-keyword-label.d.ts","sourceRoot":"","sources":["../../../src/core/resolve-keyword-label.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAExD,wBAAgB,mBAAmB,CACjC,OAAO,EAAE,OAAO,EAChB,OAAO,CAAC,EAAE,eAAe,GACxB,MAAM,CAKR"}
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Serialization / deserialization — save and restore sentence state.
3
+ *
4
+ * serialize() extracts chip values from active clauses into a portable object.
5
+ * deserialize() overlays saved values onto a fresh initialization pass.
6
+ *
7
+ * See designs/serialization.md for the full design.
8
+ */
9
+ import type { SentenceDefinition } from './types';
10
+ import type { SentenceState } from './state';
11
+ import type { SentenceStore } from './store';
12
+ /**
13
+ * Serialized sentence format.
14
+ *
15
+ * Keys are chip IDs with their raw values. Two reserved meta-keys:
16
+ * - `__active`: Record<string, boolean> — which optional clauses are active
17
+ * - `__expressionMode`: Record<string, boolean> — which chips are in expression mode
18
+ */
19
+ export type SerializedSentence = Record<string, unknown>;
20
+ /**
21
+ * Serialize a sentence state into a portable object.
22
+ *
23
+ * If the definition has a custom serializer, delegates to it.
24
+ * Otherwise, collects chip values from all present+active clauses.
25
+ */
26
+ export declare function serialize(definition: SentenceDefinition, state: SentenceState): SerializedSentence;
27
+ /**
28
+ * Deserialize saved data into a fully initialized SentenceStore.
29
+ *
30
+ * If the definition has a custom deserializer, calls it first to
31
+ * transform the data back into the default { chipId: value } format.
32
+ */
33
+ export declare function deserialize(definition: SentenceDefinition, data: SerializedSentence): SentenceStore;
34
+ //# sourceMappingURL=serialize.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"serialize.d.ts","sourceRoot":"","sources":["../../../src/core/serialize.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAClD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAC7C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAG7C;;;;;;GAMG;AACH,MAAM,MAAM,kBAAkB,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAEzD;;;;;GAKG;AACH,wBAAgB,SAAS,CACvB,UAAU,EAAE,kBAAkB,EAC9B,KAAK,EAAE,aAAa,GACnB,kBAAkB,CA2CpB;AAED;;;;;GAKG;AACH,wBAAgB,WAAW,CACzB,UAAU,EAAE,kBAAkB,EAC9B,IAAI,EAAE,kBAAkB,GACvB,aAAa,CAMf"}
@@ -0,0 +1,59 @@
1
+ /**
2
+ * Runtime state types for a Chipper sentence.
3
+ *
4
+ * These types represent the *current state* of a sentence instance —
5
+ * what values the user has selected, which clauses are active, etc.
6
+ * Structure definitions live in types.ts.
7
+ */
8
+ import type { SentenceContext } from './types';
9
+ /** State of a single chip. */
10
+ export interface ChipState<T = unknown> {
11
+ /** Current value */
12
+ value: T;
13
+ /** Formatted display string (shown in chip trigger) */
14
+ displayValue: string;
15
+ /** Whether the current value passes domain validation */
16
+ valid: boolean;
17
+ /** Whether the value has changed from the initial state */
18
+ dirty: boolean;
19
+ /** True when the chip is in expression mode via a trigger keyword. */
20
+ expressionMode?: boolean;
21
+ /** Whether a live source is currently fetching (live chips only) */
22
+ loading?: boolean;
23
+ /** Error message from source resolution */
24
+ error?: string;
25
+ /** Timestamp of last successful source resolution (remote/external display chips only) */
26
+ lastUpdated?: number;
27
+ }
28
+ /** State of a single clause. */
29
+ export interface ClauseState {
30
+ /** Whether the clause is rendered. Engine-controlled via contingency. */
31
+ present: boolean;
32
+ /** Whether the clause contributes to sentence value. User-controlled for optional clauses. */
33
+ active: boolean;
34
+ /** State of each chip in this clause, keyed by chip ID */
35
+ chips: Record<string, ChipState>;
36
+ /** Whether all chips in this clause are valid (derived) */
37
+ valid: boolean;
38
+ /** Chips currently visible (undefined = all visible, for clauses without segment contingency) */
39
+ visibleChips?: string[];
40
+ }
41
+ /** Context scope — one node in the contingency-scoped context tree. */
42
+ export interface ContextScope {
43
+ /** The clause ID that owns this scope */
44
+ clauseId: string;
45
+ /** Context values produced by this clause */
46
+ values: SentenceContext;
47
+ /** Parent scope (from superclause), or null for root clauses */
48
+ parentScopeId: string | null;
49
+ }
50
+ /** Complete state of a sentence instance. */
51
+ export interface SentenceState {
52
+ /** State of each clause, keyed by clause ID */
53
+ clauses: Record<string, ClauseState>;
54
+ /** Tree-scoped context (see chipper-architecture.md §1) */
55
+ contexts: ContextScope[];
56
+ /** Whether all active clauses are valid (derived) */
57
+ valid: boolean;
58
+ }
59
+ //# sourceMappingURL=state.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"state.d.ts","sourceRoot":"","sources":["../../../src/core/state.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAE/C,8BAA8B;AAC9B,MAAM,WAAW,SAAS,CAAC,CAAC,GAAG,OAAO;IACpC,oBAAoB;IACpB,KAAK,EAAE,CAAC,CAAC;IAET,uDAAuD;IACvD,YAAY,EAAE,MAAM,CAAC;IAErB,yDAAyD;IACzD,KAAK,EAAE,OAAO,CAAC;IAEf,2DAA2D;IAC3D,KAAK,EAAE,OAAO,CAAC;IAEf,sEAAsE;IACtE,cAAc,CAAC,EAAE,OAAO,CAAC;IAEzB,oEAAoE;IACpE,OAAO,CAAC,EAAE,OAAO,CAAC;IAElB,2CAA2C;IAC3C,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf,0FAA0F;IAC1F,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,gCAAgC;AAChC,MAAM,WAAW,WAAW;IAC1B,yEAAyE;IACzE,OAAO,EAAE,OAAO,CAAC;IAEjB,8FAA8F;IAC9F,MAAM,EAAE,OAAO,CAAC;IAEhB,0DAA0D;IAC1D,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;IAEjC,2DAA2D;IAC3D,KAAK,EAAE,OAAO,CAAC;IAEf,iGAAiG;IACjG,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;CACzB;AAED,uEAAuE;AACvE,MAAM,WAAW,YAAY;IAC3B,yCAAyC;IACzC,QAAQ,EAAE,MAAM,CAAC;IAEjB,6CAA6C;IAC7C,MAAM,EAAE,eAAe,CAAC;IAExB,gEAAgE;IAChE,aAAa,EAAE,MAAM,GAAG,IAAI,CAAC;CAC9B;AAED,6CAA6C;AAC7C,MAAM,WAAW,aAAa;IAC5B,+CAA+C;IAC/C,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;IAErC,2DAA2D;IAC3D,QAAQ,EAAE,YAAY,EAAE,CAAC;IAEzB,qDAAqD;IACrD,KAAK,EAAE,OAAO,CAAC;CAChB"}
@@ -0,0 +1,23 @@
1
+ /**
2
+ * SentenceStore — the combined state + resolved domains for a sentence instance.
3
+ *
4
+ * The store is the single value managed by useReducer in the React layer.
5
+ * Domains are resolved once at initialization and stored alongside state
6
+ * so the reducer can call validate/display without re-resolving from the palette.
7
+ */
8
+ import type { ClauseDefinition, Domain, SentenceDefinition } from './types';
9
+ import type { SentenceState } from './state';
10
+ /** Resolved domains keyed by chip ID. */
11
+ export type ResolvedDomains = Record<string, Domain>;
12
+ /** Combined state + domains + definition for a sentence instance. */
13
+ export interface SentenceStore {
14
+ state: SentenceState;
15
+ domains: ResolvedDomains;
16
+ /** Static sentence definition — stored for reducer access to contingency config. */
17
+ definition: SentenceDefinition;
18
+ /** Clause lookup by ID — precomputed at init, avoids repeated .find() calls. */
19
+ clauseById: Map<string, ClauseDefinition>;
20
+ /** Contingent clauses grouped by superclause ID — precomputed at init. */
21
+ clausesBySuper: Map<string, ClauseDefinition[]>;
22
+ }
23
+ //# sourceMappingURL=store.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"store.d.ts","sourceRoot":"","sources":["../../../src/core/store.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAC5E,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAE7C,yCAAyC;AACzC,MAAM,MAAM,eAAe,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AAErD,qEAAqE;AACrE,MAAM,WAAW,aAAa;IAC5B,KAAK,EAAE,aAAa,CAAC;IACrB,OAAO,EAAE,eAAe,CAAC;IACzB,oFAAoF;IACpF,UAAU,EAAE,kBAAkB,CAAC;IAC/B,gFAAgF;IAChF,UAAU,EAAE,GAAG,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAC;IAC1C,0EAA0E;IAC1E,cAAc,EAAE,GAAG,CAAC,MAAM,EAAE,gBAAgB,EAAE,CAAC,CAAC;CACjD"}
@@ -0,0 +1,242 @@
1
+ /**
2
+ * Core type definitions for the Chipper data model.
3
+ *
4
+ * Hierarchy: Sentence > Clause > Chip > Domain
5
+ *
6
+ * These types define the *structure* of a sentence definition —
7
+ * what clauses exist, what chips they contain, and how they relate.
8
+ * Runtime state is defined in state.ts.
9
+ */
10
+ /** A named preset value within a domain. */
11
+ export interface Keyword<T = any> {
12
+ /** Display label shown in the popup. Function receives sentence context. */
13
+ label: string | ((context: SentenceContext) => string);
14
+ /** Display text shown in the chip trigger (defaults to label) */
15
+ display?: string;
16
+ /** The value this keyword represents */
17
+ value: T;
18
+ /**
19
+ * If true, this keyword collapses only some DOF — the chip may still
20
+ * need additional input after selection.
21
+ */
22
+ partial?: boolean;
23
+ }
24
+ /** One way for a user to specify a value within a domain's value space. */
25
+ export interface ExpressionMode<T = any> {
26
+ /** Unique identifier for this mode */
27
+ id: string;
28
+ /** Human-readable label (shown in tabbed UI for alternative-coordinate domains) */
29
+ label: string;
30
+ /** Number of independent choices the user must make */
31
+ degreesOfFreedom: number;
32
+ /** Validate a value produced by this mode */
33
+ validate: (value: T) => boolean;
34
+ /** Format a value produced by this mode for display */
35
+ display: (value: T) => string;
36
+ /** Maximum character length for text input (omit for unlimited) */
37
+ maxLength?: number;
38
+ /** Input type — 'text' (default), 'number' (stepper UI), or 'date' (calendar picker) */
39
+ inputType?: 'text' | 'number' | 'date';
40
+ /** Minimum value (number inputs only) */
41
+ min?: number;
42
+ /** Maximum value (number inputs only) */
43
+ max?: number;
44
+ /** Step increment for +/- buttons (number inputs only, default 1) */
45
+ step?: number;
46
+ /** Text shown before the input in the popup (e.g., "in"). Function receives sentence context. */
47
+ prefix?: string | ((context: SentenceContext) => string);
48
+ /** Text shown after the input in the popup (e.g., "months"). Function receives sentence context. */
49
+ suffix?: string | ((context: SentenceContext) => string);
50
+ /** Expression input placement relative to keywords: 'above' or 'below' (default 'below'). */
51
+ position?: 'above' | 'below';
52
+ }
53
+ /**
54
+ * A domain defines the kind of data a chip accepts.
55
+ * Every chip has exactly one domain.
56
+ */
57
+ export interface Domain<T = any> {
58
+ /** Unique identifier for this domain type */
59
+ type: string;
60
+ /** Semantic color key — maps to a CSS custom property (--chip-color-{color}) */
61
+ color: string;
62
+ /** Named presets. Full keywords collapse all DOF; partial keywords leave some open. */
63
+ keywords: Keyword<T>[];
64
+ /** Grouped keywords for popup rendering. When present, popups render from this instead of keywords. */
65
+ keywordGroups?: import('../domains/normalize-keywords').NormalizedKeywordGroup<T>[];
66
+ /** Available ways to specify a value (besides keywords) */
67
+ expressionModes: ExpressionMode<T>[];
68
+ /** Context keys this domain reads from ancestor producers */
69
+ consumes?: string[];
70
+ /** Context keys this domain writes for descendant consumers */
71
+ produces?: string[];
72
+ /** Validate a value */
73
+ validate: (value: T) => boolean;
74
+ /** Format a value for display in the chip trigger. Context is available when called from the reducer. */
75
+ display: (value: T, context?: SentenceContext) => string;
76
+ /** Default value (may or may not be valid) */
77
+ defaultValue: T;
78
+ /** Text shown in the chip trigger when the current value is invalid */
79
+ placeholder?: string;
80
+ /** Reconfigure domain based on context from ancestor clauses */
81
+ onContextChange?: (context: SentenceContext) => Partial<Domain<T>>;
82
+ /** Archetype-specific configuration passed through to popup rendering */
83
+ meta?: Record<string, unknown>;
84
+ }
85
+ /** A display chip whose value is fixed at definition time. */
86
+ export interface StaticDisplaySource<T = unknown> {
87
+ type: 'static';
88
+ value: T;
89
+ }
90
+ /** A display chip whose value derives from sentence context or state. */
91
+ export interface DerivedDisplaySource<T = unknown> {
92
+ type: 'derived';
93
+ compute: (context: SentenceContext, state: import('./state').SentenceState) => T;
94
+ }
95
+ /** A display chip whose value is fetched from a URL. */
96
+ export interface RemoteDisplaySource<T = unknown> {
97
+ type: 'remote';
98
+ /** URL to fetch from */
99
+ url: string;
100
+ /** Extract value from JSON response */
101
+ extract: (response: unknown) => T;
102
+ /** Poll interval in ms. If omitted, fetch once on mount. */
103
+ interval?: number;
104
+ }
105
+ /** A display chip whose value is pushed by a consumer-managed subscription. */
106
+ export interface ExternalDisplaySource<T = unknown> {
107
+ type: 'external';
108
+ /** Subscribe to value updates. Returns an unsubscribe cleanup function. */
109
+ subscribe: (callback: (value: T) => void) => (() => void);
110
+ }
111
+ /** Source strategy for a display chip. */
112
+ export type DisplaySource<T = unknown> = StaticDisplaySource<T> | DerivedDisplaySource<T> | RemoteDisplaySource<T> | ExternalDisplaySource<T>;
113
+ /** Configuration for a display chip's info popup. */
114
+ export interface DisplayConfig<T = unknown> {
115
+ source: DisplaySource<T>;
116
+ /** Content shown in info popup. Omit for no popup. */
117
+ info?: string | ((value: T, state: import('./state').SentenceState) => string);
118
+ }
119
+ export type ChipMode = {
120
+ type: 'interactive';
121
+ } | {
122
+ type: 'display';
123
+ source: DisplaySource;
124
+ info?: DisplayConfig['info'];
125
+ };
126
+ /** Definition of a single chip within a clause. */
127
+ export interface ChipDefinition {
128
+ /** Unique identifier within the sentence */
129
+ id: string;
130
+ /** Domain name (resolved from the palette) */
131
+ domainName: string;
132
+ /** Chip mode — defaults to interactive */
133
+ mode: ChipMode;
134
+ }
135
+ /** Contingency configuration — how a clause depends on its superclause. */
136
+ export interface ContingencyConfig {
137
+ /** The ID of the superclause */
138
+ superclauseId: string;
139
+ /** When is this clause present? Receives scoped context from ancestors. */
140
+ present?: (context: SentenceContext) => boolean;
141
+ /** How should this clause reconfigure based on context? */
142
+ configure?: (context: SentenceContext) => ClauseOverrides;
143
+ }
144
+ /** Overrides applied to a clause when its superclause context changes. */
145
+ export interface ClauseOverrides {
146
+ chipOverrides?: Record<string, Partial<Domain>>;
147
+ }
148
+ /** A text span within a clause (lead text, trailing text, interleaved text). */
149
+ export interface TextSegment {
150
+ type: 'text';
151
+ /** Static string or function resolved at render time (e.g., context-aware punctuation). */
152
+ value: string | ((state: import('./state').SentenceState) => string);
153
+ /** When should this text be visible? Omit = always visible. */
154
+ present?: (context: SentenceContext) => boolean;
155
+ }
156
+ /** A chip reference within a clause. */
157
+ export interface ChipSegment {
158
+ type: 'chip';
159
+ chipId: string;
160
+ /** When should this chip be visible? Omit = always visible. */
161
+ present?: (context: SentenceContext) => boolean;
162
+ }
163
+ /** One piece of a clause's rendering order. */
164
+ export type ClauseSegment = TextSegment | ChipSegment;
165
+ /** Definition of a single clause within a sentence. */
166
+ export interface ClauseDefinition {
167
+ /** Unique identifier within the sentence */
168
+ id: string;
169
+ /** Whether the user can toggle this clause */
170
+ necessity: 'required' | 'optional';
171
+ /** Rendering order: interleaved text spans and chip references */
172
+ segments: ClauseSegment[];
173
+ /** Extracted chip definitions (derived from segments for initializer/reducer convenience) */
174
+ chips: ChipDefinition[];
175
+ /** Placeholder text shown when an optional clause is dormant */
176
+ placeholder?: string;
177
+ /** Contingency on a superclause */
178
+ contingency?: ContingencyConfig;
179
+ /** Context keys this clause produces (mapped from chip values) */
180
+ contextProductions?: Record<string, string>;
181
+ }
182
+ /** Configuration for a repeating clause group. */
183
+ export interface RepeatingClauseConfig {
184
+ /** Lead text for the first instance */
185
+ firstLead: string;
186
+ /** Lead text for subsequent instances */
187
+ restLead: string;
188
+ /** Minimum number of instances (0 = all optional) */
189
+ min: number;
190
+ /** Maximum number of instances */
191
+ max: number;
192
+ /** The clause template to repeat */
193
+ template: ClauseDefinition;
194
+ }
195
+ /** A visual line within a sentence — groups one or more clauses into a single row. */
196
+ export interface LineDefinition {
197
+ /** Clause IDs rendered on this line, in order */
198
+ clauseIds: string[];
199
+ /** Whether this line is visually indented (e.g., subordinate contingent clauses) */
200
+ indent?: boolean;
201
+ }
202
+ /** Complete definition of a sentence. */
203
+ export interface SentenceDefinition {
204
+ /** Ordered list of clause definitions */
205
+ clauses: ClauseDefinition[];
206
+ /** Visual line groupings. If omitted, each clause gets its own line. */
207
+ lines?: LineDefinition[];
208
+ /** Repeating clause groups, keyed by group ID */
209
+ repeatingClauses?: Record<string, RepeatingClauseConfig>;
210
+ /** The palette this sentence was built from */
211
+ palette: Palette;
212
+ /** Custom serializer (if not provided, default flat serialization is used) */
213
+ serializer?: (state: import('./state').SentenceState) => Record<string, unknown>;
214
+ /** Custom deserializer (if not provided, default flat deserialization is used) */
215
+ deserializer?: (data: Record<string, unknown>) => Record<string, unknown>;
216
+ }
217
+ /** A clause template — a reusable clause pattern within a palette. */
218
+ export interface ClauseTemplate {
219
+ /** Human-readable description */
220
+ description: string;
221
+ /** The clause definition template */
222
+ definition: Omit<ClauseDefinition, 'id'>;
223
+ }
224
+ /**
225
+ * A palette provides pre-configured domains and reusable clause templates.
226
+ * It sits between Chipper core and the consumer application.
227
+ */
228
+ export interface Palette {
229
+ /** Named domain configurations */
230
+ domains: Record<string, Domain>;
231
+ /** Named clause templates (optional convenience) */
232
+ clauseTemplates?: Record<string, ClauseTemplate>;
233
+ }
234
+ /**
235
+ * Sentence context — tree-scoped shared state.
236
+ *
237
+ * Context propagates down the contingency tree. A producing clause writes
238
+ * keys visible to its contingent descendants. A consuming clause walks up
239
+ * its contingency chain to the nearest ancestor producer.
240
+ */
241
+ export type SentenceContext = Record<string, unknown>;
242
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/core/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAMH,4CAA4C;AAC5C,MAAM,WAAW,OAAO,CAAC,CAAC,GAAG,GAAG;IAC9B,4EAA4E;IAC5E,KAAK,EAAE,MAAM,GAAG,CAAC,CAAC,OAAO,EAAE,eAAe,KAAK,MAAM,CAAC,CAAC;IAEvD,iEAAiE;IACjE,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB,wCAAwC;IACxC,KAAK,EA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EAAE,IAAI,CAAC,CAAC;CAC1C;AAED;;;GAGG;AACH,MAAM,WAAW,OAAO;IACtB,kCAAkC;IAClC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAEhC,oDAAoD;IACpD,eAAe,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC;CAClD;AAMD;;;;;;GAMG;AACH,MAAM,MAAM,eAAe,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC"}
@@ -0,0 +1,110 @@
1
+ /**
2
+ * Alternative-coordinate domain — multiple expression modes (tabs) over
3
+ * the same value space.
4
+ *
5
+ * The fourth archetype. Each mode can have one or more "slots" —
6
+ * independent selection dimensions that compose into a single value.
7
+ * Single-slot modes are the simple case (pick one keyword). Multi-slot
8
+ * modes compose N selections (e.g., ordinal × weekday → "first wednesday").
9
+ *
10
+ * Covers day-of-month (date vs weekday), month-in-period (quarter vs year),
11
+ * and any domain where the same value can be specified through different
12
+ * coordinate systems.
13
+ */
14
+ import type { Domain, Keyword, SentenceContext } from '../core/types';
15
+ import type { ExpressionConfig } from './keyword-or-expression';
16
+ import { type KeywordGroupItem } from './normalize-keywords';
17
+ /** One selection dimension within a mode. */
18
+ export interface ModeSlot {
19
+ /** Keywords for this slot. Accepts groups for visual grouping within a slot. */
20
+ keywords: KeywordGroupItem<string>[] | Keyword<string>[];
21
+ /** Prefix text rendered before the keywords (e.g., "the") */
22
+ prefix?: string;
23
+ }
24
+ /** One coordinate mode — one tab in the popup. */
25
+ export interface AlternativeCoordinateMode {
26
+ /** Unique mode identifier */
27
+ id: string;
28
+ /** Tab label */
29
+ label: string;
30
+ /** Independent selection dimensions within this mode */
31
+ slots: ModeSlot[];
32
+ /** Compose slot selections into the domain value */
33
+ compose: (...selections: string[]) => string;
34
+ /** Decompose existing value back into slot selections (for reopening) */
35
+ decompose?: (value: string) => (string | undefined)[];
36
+ /** Validate the composed value (default: non-empty string) */
37
+ validate?: (value: string) => boolean;
38
+ /** Display the composed value */
39
+ display?: (value: string) => string;
40
+ /** Expression input as alternative to slot selection */
41
+ expression?: ExpressionConfig;
42
+ }
43
+ /** Resolved mode with normalized slot keywords — used by popup rendering. */
44
+ export interface ResolvedAlternativeCoordinateMode extends Omit<AlternativeCoordinateMode, 'slots'> {
45
+ slots: ResolvedModeSlot[];
46
+ }
47
+ /** Resolved slot with flat keywords and optional groups. */
48
+ export interface ResolvedModeSlot {
49
+ keywords: Keyword<string>[];
50
+ keywordGroups?: import('./normalize-keywords').NormalizedKeywordGroup<string>[];
51
+ prefix?: string;
52
+ }
53
+ /** Configuration for an alternative-coordinate domain. */
54
+ export interface AlternativeCoordinateDomainConfig {
55
+ /** Semantic color key */
56
+ color: string;
57
+ /** Available coordinate modes — one tab per mode */
58
+ modes: AlternativeCoordinateMode[];
59
+ /** Default value — empty string if omitted (invalid → placeholder) */
60
+ default?: string;
61
+ /** Text shown when value is invalid */
62
+ placeholder?: string;
63
+ /** Context keys this domain reads from ancestor producers */
64
+ consumes?: string[];
65
+ /** Context keys this domain writes for descendant consumers */
66
+ produces?: string[];
67
+ /** Reconfigure domain when ancestor context changes */
68
+ onContextChange?: (context: SentenceContext) => Partial<Domain<string>>;
69
+ }
70
+ /**
71
+ * Create an alternative-coordinate domain.
72
+ *
73
+ * @example
74
+ * ```typescript
75
+ * const calendarDay = alternativeCoordinateDomain({
76
+ * color: 'sage',
77
+ * modes: [
78
+ * {
79
+ * id: 'date',
80
+ * label: 'Date',
81
+ * slots: [{ prefix: 'the', keywords: [
82
+ * { label: '1st', value: '1' },
83
+ * { label: '15th', value: '15' },
84
+ * ]}],
85
+ * compose: (day) => day,
86
+ * decompose: (v) => [v],
87
+ * },
88
+ * {
89
+ * id: 'weekday',
90
+ * label: 'Weekday',
91
+ * slots: [
92
+ * { prefix: 'the', keywords: [
93
+ * { label: 'first', value: 'first' },
94
+ * { label: 'last', value: 'last' },
95
+ * ]},
96
+ * { keywords: [
97
+ * { label: 'Mon', value: 'monday' },
98
+ * { label: 'Tue', value: 'tuesday' },
99
+ * ]},
100
+ * ],
101
+ * compose: (ordinal, day) => `${ordinal} ${day}`,
102
+ * decompose: (v) => v.split(' '),
103
+ * },
104
+ * ],
105
+ * placeholder: 'which day',
106
+ * });
107
+ * ```
108
+ */
109
+ export declare function alternativeCoordinateDomain(config: AlternativeCoordinateDomainConfig): Domain<string>;
110
+ //# sourceMappingURL=alternative-coordinate.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"alternative-coordinate.d.ts","sourceRoot":"","sources":["../../../src/domains/alternative-coordinate.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAkB,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AACtF,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAEhE,OAAO,EAEL,KAAK,gBAAgB,EACtB,MAAM,sBAAsB,CAAC;AAE9B,6CAA6C;AAC7C,MAAM,WAAW,QAAQ;IACvB,gFAAgF;IAChF,QAAQ,EAAE,gBAAgB,CAAC,MAAM,CAAC,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;IAEzD,6DAA6D;IAC7D,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,kDAAkD;AAClD,MAAM,WAAW,yBAAyB;IACxC,6BAA6B;IAC7B,EAAE,EAAE,MAAM,CAAC;IAEX,gBAAgB;IAChB,KAAK,EAAE,MAAM,CAAC;IAEd,wDAAwD;IACxD,KAAK,EAAE,QAAQ,EAAE,CAAC;IAElB,oDAAoD;IACpD,OAAO,EAAE,CAAC,GAAG,UAAU,EAAE,MAAM,EAAE,KAAK,MAAM,CAAC;IAE7C,yEAAyE;IACzE,SAAS,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,CAAC,MAAM,GAAG,SAAS,CAAC,EAAE,CAAC;IAEtD,8DAA8D;IAC9D,QAAQ,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to src/domains/.
3
+ *
4
+ * All archetype factories call createDomain to produce a conformant
5
+ * Domain<T>. This function fills defaults for omitted fields and
6
+ * passes through everything else. It contains no archetype-specific logic.
7
+ *
8
+ * Not exported from the package. Consumers use archetype factories.
9
+ */
10
+ import type { Domain, ExpressionMode, Keyword, SentenceContext } from '../core/types';
11
+ import type { NormalizedKeywordGroup } from './normalize-keywords';
12
+ /** Fields accepted by the internal createDomain function. */
13
+ export interface BaseDomainConfig<T> {
14
+ type: string;
15
+ color: string;
16
+ keywords?: Keyword<T>[];
17
+ keywordGroups?: NormalizedKeywordGroup<T>[];
18
+ expressionModes?: ExpressionMode<T>[];
19
+ defaultValue: T;
20
+ placeholder?: string;
21
+ validate?: (value: T) => boolean;
22
+ display?: (value: T) => string;
23
+ consumes?: string[];
24
+ produces?: string[];
25
+ onContextChange?: (context: SentenceContext) => Partial<Domain<T>>;
26
+ meta?: Record<string, unknown>;
27
+ }
28
+ /** Assemble a Domain<T> from config, filling sensible defaults. */
29
+ export declare function createDomain<T>(config: BaseDomainConfig<T>): Domain<T>;
30
+ //# sourceMappingURL=create-domain.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-domain.d.ts","sourceRoot":"","sources":["../../../src/domains/create-domain.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,cAAc,EAAE,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AACtF,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,sBAAsB,CAAC;AAEnE,6DAA6D;AAC7D,MAAM,WAAW,gBAAgB,CAAC,CAAC;IACjC,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC;IACxB,aAAa,CAAC,EAAE,sBAAsB,CAAC,CAAC,CAAC,EAAE,CAAC;IAC5C,eAAe,CAAC,EAAE,cAAc,CAAC,CAAC,CAAC,EAAE,CAAC;IACtC,YAAY,EAAE,CAAC,CAAC;IAChB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,OAAO,CAAC;IACjC,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,MAAM,CAAC;IAC/B,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;IACpB,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;IACpB,eAAe,CAAC,EAAE,CAAC,OAAO,EAAE,eAAe,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;IACnE,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAChC;AAED,mEAAmE;AACnE,wBAAgB,YAAY,CAAC,CAAC,EAAE,MAAM,EAAE,gBAAgB,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,CAgBtE"}