@almadar/std 1.0.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/LICENSE +72 -0
- package/dist/behaviors/action-affinity.d.ts +88 -0
- package/dist/behaviors/action-affinity.js +290 -0
- package/dist/behaviors/action-affinity.js.map +1 -0
- package/dist/behaviors/async.d.ts +20 -0
- package/dist/behaviors/async.js +542 -0
- package/dist/behaviors/async.js.map +1 -0
- package/dist/behaviors/data-management.d.ts +40 -0
- package/dist/behaviors/data-management.js +495 -0
- package/dist/behaviors/data-management.js.map +1 -0
- package/dist/behaviors/feedback.d.ts +18 -0
- package/dist/behaviors/feedback.js +307 -0
- package/dist/behaviors/feedback.js.map +1 -0
- package/dist/behaviors/game-core.d.ts +40 -0
- package/dist/behaviors/game-core.js +443 -0
- package/dist/behaviors/game-core.js.map +1 -0
- package/dist/behaviors/game-entity.d.ts +39 -0
- package/dist/behaviors/game-entity.js +643 -0
- package/dist/behaviors/game-entity.js.map +1 -0
- package/dist/behaviors/game-ui.d.ts +29 -0
- package/dist/behaviors/game-ui.js +493 -0
- package/dist/behaviors/game-ui.js.map +1 -0
- package/dist/behaviors/index.d.ts +11 -0
- package/dist/behaviors/index.js +4539 -0
- package/dist/behaviors/index.js.map +1 -0
- package/dist/behaviors/registry.d.ts +103 -0
- package/dist/behaviors/registry.js +4166 -0
- package/dist/behaviors/registry.js.map +1 -0
- package/dist/behaviors/types.d.ts +179 -0
- package/dist/behaviors/types.js +111 -0
- package/dist/behaviors/types.js.map +1 -0
- package/dist/behaviors/ui-interaction.d.ts +36 -0
- package/dist/behaviors/ui-interaction.js +1104 -0
- package/dist/behaviors/ui-interaction.js.map +1 -0
- package/dist/index.d.ts +195 -0
- package/dist/index.js +8209 -0
- package/dist/index.js.map +1 -0
- package/dist/modules/array.d.ts +28 -0
- package/dist/modules/array.js +556 -0
- package/dist/modules/array.js.map +1 -0
- package/dist/modules/async.d.ts +22 -0
- package/dist/modules/async.js +112 -0
- package/dist/modules/async.js.map +1 -0
- package/dist/modules/format.d.ts +21 -0
- package/dist/modules/format.js +129 -0
- package/dist/modules/format.js.map +1 -0
- package/dist/modules/index.d.ts +12 -0
- package/dist/modules/index.js +3131 -0
- package/dist/modules/index.js.map +1 -0
- package/dist/modules/math.d.ts +22 -0
- package/dist/modules/math.js +215 -0
- package/dist/modules/math.js.map +1 -0
- package/dist/modules/nn.d.ts +23 -0
- package/dist/modules/nn.js +189 -0
- package/dist/modules/nn.js.map +1 -0
- package/dist/modules/object.d.ts +22 -0
- package/dist/modules/object.js +257 -0
- package/dist/modules/object.js.map +1 -0
- package/dist/modules/str.d.ts +21 -0
- package/dist/modules/str.js +344 -0
- package/dist/modules/str.js.map +1 -0
- package/dist/modules/tensor.d.ts +23 -0
- package/dist/modules/tensor.js +427 -0
- package/dist/modules/tensor.js.map +1 -0
- package/dist/modules/time.d.ts +24 -0
- package/dist/modules/time.js +323 -0
- package/dist/modules/time.js.map +1 -0
- package/dist/modules/train.d.ts +23 -0
- package/dist/modules/train.js +308 -0
- package/dist/modules/train.js.map +1 -0
- package/dist/modules/validate.d.ts +23 -0
- package/dist/modules/validate.js +301 -0
- package/dist/modules/validate.js.map +1 -0
- package/dist/registry.d.ts +140 -0
- package/dist/registry.js +3240 -0
- package/dist/registry.js.map +1 -0
- package/dist/types-I95R8_FN.d.ts +91 -0
- package/package.json +59 -0
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
import { SExpr, RequiredField } from '@almadar/core/types';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Standard Behaviors Types
|
|
5
|
+
*
|
|
6
|
+
* Standard Behaviors are reusable Traits with a `std/` naming convention.
|
|
7
|
+
* They use a more flexible state machine format optimized for authoring.
|
|
8
|
+
*
|
|
9
|
+
* ARCHITECTURE: Behaviors ARE Traits conceptually. They use:
|
|
10
|
+
* - stateMachine: BehaviorStateMachine (flexible states, events, transitions)
|
|
11
|
+
* - ticks: BehaviorTick[] (frame-by-frame execution for games)
|
|
12
|
+
* - dataEntities: BehaviorDataEntity[] (runtime state)
|
|
13
|
+
*
|
|
14
|
+
* @packageDocumentation
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Categories of Standard Behaviors
|
|
19
|
+
*/
|
|
20
|
+
declare const BEHAVIOR_CATEGORIES: readonly ["ui-interaction", "data-management", "async", "feedback", "game-core", "game-entity", "game-ui"];
|
|
21
|
+
type BehaviorCategory = (typeof BEHAVIOR_CATEGORIES)[number];
|
|
22
|
+
type FieldType = 'string' | 'number' | 'boolean' | 'array' | 'object' | 'entity' | 'slot' | 'pattern' | 'event' | 'action[]';
|
|
23
|
+
interface ConfigField {
|
|
24
|
+
name: string;
|
|
25
|
+
type: FieldType;
|
|
26
|
+
description: string;
|
|
27
|
+
default?: unknown;
|
|
28
|
+
enum?: string[];
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* State definition - can be string or object
|
|
32
|
+
*/
|
|
33
|
+
interface BehaviorState {
|
|
34
|
+
name: string;
|
|
35
|
+
isInitial?: boolean;
|
|
36
|
+
isFinal?: boolean;
|
|
37
|
+
description?: string;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Event definition - simplified, only key required
|
|
41
|
+
*/
|
|
42
|
+
interface BehaviorEvent {
|
|
43
|
+
key: string;
|
|
44
|
+
name?: string;
|
|
45
|
+
description?: string;
|
|
46
|
+
payload?: Record<string, unknown>;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Transition definition - flexible from/to
|
|
50
|
+
*/
|
|
51
|
+
interface BehaviorTransition {
|
|
52
|
+
/** Source state(s) - string, '*' for any, or array */
|
|
53
|
+
from?: string | string[] | '*';
|
|
54
|
+
/** Target state - optional for self-transitions */
|
|
55
|
+
to?: string;
|
|
56
|
+
/** Event that triggers this transition */
|
|
57
|
+
event: string;
|
|
58
|
+
/** Guard condition (S-expression) */
|
|
59
|
+
guard?: SExpr;
|
|
60
|
+
/** Effects to execute (S-expressions) */
|
|
61
|
+
effects?: SExpr[];
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* State machine for behaviors - more flexible than core StateMachine
|
|
65
|
+
*/
|
|
66
|
+
interface BehaviorStateMachine {
|
|
67
|
+
initial: string;
|
|
68
|
+
states: (string | BehaviorState)[];
|
|
69
|
+
events: (string | BehaviorEvent)[];
|
|
70
|
+
transitions: BehaviorTransition[];
|
|
71
|
+
guards?: Array<{
|
|
72
|
+
name: string;
|
|
73
|
+
condition: SExpr;
|
|
74
|
+
description?: string;
|
|
75
|
+
}>;
|
|
76
|
+
}
|
|
77
|
+
interface BehaviorTick {
|
|
78
|
+
name: string;
|
|
79
|
+
description?: string;
|
|
80
|
+
priority?: number;
|
|
81
|
+
interval: 'frame' | number;
|
|
82
|
+
appliesTo?: string[];
|
|
83
|
+
guard?: SExpr;
|
|
84
|
+
effects: SExpr[];
|
|
85
|
+
}
|
|
86
|
+
interface BehaviorEntityField {
|
|
87
|
+
name: string;
|
|
88
|
+
type: string;
|
|
89
|
+
default?: unknown;
|
|
90
|
+
required?: boolean;
|
|
91
|
+
description?: string;
|
|
92
|
+
}
|
|
93
|
+
interface BehaviorDataEntity {
|
|
94
|
+
name: string;
|
|
95
|
+
runtime?: boolean;
|
|
96
|
+
singleton?: boolean;
|
|
97
|
+
fields: BehaviorEntityField[];
|
|
98
|
+
description?: string;
|
|
99
|
+
}
|
|
100
|
+
interface ItemAction {
|
|
101
|
+
label: string;
|
|
102
|
+
event?: string;
|
|
103
|
+
navigatesTo?: string;
|
|
104
|
+
placement?: 'row' | 'bulk' | 'card' | 'footer' | 'header';
|
|
105
|
+
variant?: 'primary' | 'secondary' | 'ghost' | 'danger';
|
|
106
|
+
showWhen?: SExpr | string;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Configuration schema for documentation and IDE hints
|
|
110
|
+
*/
|
|
111
|
+
interface BehaviorConfig {
|
|
112
|
+
required: ConfigField[];
|
|
113
|
+
optional: ConfigField[];
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Standard Behavior definition
|
|
117
|
+
*/
|
|
118
|
+
interface StandardBehavior {
|
|
119
|
+
/** Behavior identifier (e.g., 'std/List', 'std/Form') */
|
|
120
|
+
name: string;
|
|
121
|
+
/** Category for organization */
|
|
122
|
+
category: BehaviorCategory;
|
|
123
|
+
/** Human-readable description */
|
|
124
|
+
description: string;
|
|
125
|
+
/** When to use this behavior */
|
|
126
|
+
suggestedFor?: string[];
|
|
127
|
+
/** Configuration schema for IDE hints */
|
|
128
|
+
configSchema?: BehaviorConfig;
|
|
129
|
+
/** State machine definition */
|
|
130
|
+
stateMachine?: BehaviorStateMachine;
|
|
131
|
+
/** Required fields from linked entity */
|
|
132
|
+
requiredFields?: RequiredField[];
|
|
133
|
+
/** Runtime data entities */
|
|
134
|
+
dataEntities?: BehaviorDataEntity[];
|
|
135
|
+
/** Frame-by-frame execution */
|
|
136
|
+
ticks?: BehaviorTick[];
|
|
137
|
+
/** Cross-behavior event listeners */
|
|
138
|
+
listens?: Array<{
|
|
139
|
+
event: string;
|
|
140
|
+
triggers: string;
|
|
141
|
+
guard?: SExpr;
|
|
142
|
+
}>;
|
|
143
|
+
/** Initial effects on behavior activation */
|
|
144
|
+
initialEffects?: SExpr[];
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Behavior metadata for quick lookup
|
|
148
|
+
*/
|
|
149
|
+
interface BehaviorMetadata {
|
|
150
|
+
name: string;
|
|
151
|
+
category: BehaviorCategory;
|
|
152
|
+
description: string;
|
|
153
|
+
suggestedFor: string[];
|
|
154
|
+
states: string[];
|
|
155
|
+
events: string[];
|
|
156
|
+
tickCount: number;
|
|
157
|
+
transitionCount: number;
|
|
158
|
+
hasDataEntities: boolean;
|
|
159
|
+
}
|
|
160
|
+
declare function isBehaviorCategory(value: string): value is BehaviorCategory;
|
|
161
|
+
declare function isGameBehaviorCategory(category: BehaviorCategory): boolean;
|
|
162
|
+
/**
|
|
163
|
+
* Extract metadata from a StandardBehavior
|
|
164
|
+
*/
|
|
165
|
+
declare function getBehaviorMetadata(behavior: StandardBehavior): BehaviorMetadata;
|
|
166
|
+
/**
|
|
167
|
+
* Validate behavior structure
|
|
168
|
+
*/
|
|
169
|
+
declare function validateBehaviorStructure(behavior: StandardBehavior): string[];
|
|
170
|
+
/**
|
|
171
|
+
* Validate behavior events match transitions
|
|
172
|
+
*/
|
|
173
|
+
declare function validateBehaviorEvents(behavior: StandardBehavior): string[];
|
|
174
|
+
/**
|
|
175
|
+
* Validate behavior states match transitions
|
|
176
|
+
*/
|
|
177
|
+
declare function validateBehaviorStates(behavior: StandardBehavior): string[];
|
|
178
|
+
|
|
179
|
+
export { BEHAVIOR_CATEGORIES, type BehaviorCategory, type BehaviorConfig, type BehaviorDataEntity, type BehaviorEntityField, type BehaviorEvent, type BehaviorMetadata, type BehaviorState, type BehaviorStateMachine, type BehaviorTick, type BehaviorTransition, type ConfigField, type FieldType, type ItemAction, type StandardBehavior, getBehaviorMetadata, isBehaviorCategory, isGameBehaviorCategory, validateBehaviorEvents, validateBehaviorStates, validateBehaviorStructure };
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
// behaviors/types.ts
|
|
2
|
+
var BEHAVIOR_CATEGORIES = [
|
|
3
|
+
"ui-interaction",
|
|
4
|
+
// User interface state management
|
|
5
|
+
"data-management",
|
|
6
|
+
// Data operations and state
|
|
7
|
+
"async",
|
|
8
|
+
// Asynchronous workflows
|
|
9
|
+
"feedback",
|
|
10
|
+
// User feedback and confirmations
|
|
11
|
+
"game-core",
|
|
12
|
+
// Game loop and systems
|
|
13
|
+
"game-entity",
|
|
14
|
+
// Game entity behaviors
|
|
15
|
+
"game-ui"
|
|
16
|
+
// Game interface
|
|
17
|
+
];
|
|
18
|
+
function isBehaviorCategory(value) {
|
|
19
|
+
return BEHAVIOR_CATEGORIES.includes(value);
|
|
20
|
+
}
|
|
21
|
+
function isGameBehaviorCategory(category) {
|
|
22
|
+
return category.startsWith("game-");
|
|
23
|
+
}
|
|
24
|
+
function getBehaviorMetadata(behavior) {
|
|
25
|
+
const sm = behavior.stateMachine;
|
|
26
|
+
const states = (sm?.states || []).map(
|
|
27
|
+
(s) => typeof s === "string" ? s : s.name
|
|
28
|
+
);
|
|
29
|
+
const events = (sm?.events || []).map(
|
|
30
|
+
(e) => typeof e === "string" ? e : e.key
|
|
31
|
+
);
|
|
32
|
+
return {
|
|
33
|
+
name: behavior.name,
|
|
34
|
+
category: behavior.category,
|
|
35
|
+
description: behavior.description || "",
|
|
36
|
+
suggestedFor: behavior.suggestedFor || [],
|
|
37
|
+
states,
|
|
38
|
+
events,
|
|
39
|
+
tickCount: behavior.ticks?.length || 0,
|
|
40
|
+
transitionCount: sm?.transitions?.length || 0,
|
|
41
|
+
hasDataEntities: (behavior.dataEntities?.length || 0) > 0
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
function validateBehaviorStructure(behavior) {
|
|
45
|
+
const errors = [];
|
|
46
|
+
if (!behavior.name) {
|
|
47
|
+
errors.push("Behavior must have a name");
|
|
48
|
+
}
|
|
49
|
+
if (!behavior.name.startsWith("std/")) {
|
|
50
|
+
errors.push(`Behavior name should start with 'std/' (got: ${behavior.name})`);
|
|
51
|
+
}
|
|
52
|
+
if (!behavior.category) {
|
|
53
|
+
errors.push("Behavior must have a category");
|
|
54
|
+
}
|
|
55
|
+
if (!isBehaviorCategory(behavior.category)) {
|
|
56
|
+
errors.push(`Invalid category: ${behavior.category}`);
|
|
57
|
+
}
|
|
58
|
+
const sm = behavior.stateMachine;
|
|
59
|
+
if (sm) {
|
|
60
|
+
if (!sm.states || sm.states.length === 0) {
|
|
61
|
+
errors.push("State machine must have at least one state");
|
|
62
|
+
}
|
|
63
|
+
if (!sm.initial) {
|
|
64
|
+
errors.push("State machine must have an initial state");
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return errors;
|
|
68
|
+
}
|
|
69
|
+
function validateBehaviorEvents(behavior) {
|
|
70
|
+
const errors = [];
|
|
71
|
+
const sm = behavior.stateMachine;
|
|
72
|
+
if (!sm) return errors;
|
|
73
|
+
const declaredEvents = new Set(
|
|
74
|
+
(sm.events || []).map((e) => typeof e === "string" ? e : e.key)
|
|
75
|
+
);
|
|
76
|
+
const transitionEvents = new Set(
|
|
77
|
+
(sm.transitions || []).map((t) => t.event)
|
|
78
|
+
);
|
|
79
|
+
for (const event of transitionEvents) {
|
|
80
|
+
if (event && !declaredEvents.has(event)) {
|
|
81
|
+
errors.push(`Transition uses undeclared event: ${event}`);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
return errors;
|
|
85
|
+
}
|
|
86
|
+
function validateBehaviorStates(behavior) {
|
|
87
|
+
const errors = [];
|
|
88
|
+
const sm = behavior.stateMachine;
|
|
89
|
+
if (!sm) return errors;
|
|
90
|
+
const declaredStates = new Set(
|
|
91
|
+
(sm.states || []).map((s) => typeof s === "string" ? s : s.name)
|
|
92
|
+
);
|
|
93
|
+
for (const t of sm.transitions || []) {
|
|
94
|
+
if (t.from && t.from !== "*") {
|
|
95
|
+
const fromStates = Array.isArray(t.from) ? t.from : [t.from];
|
|
96
|
+
for (const state of fromStates) {
|
|
97
|
+
if (!declaredStates.has(state)) {
|
|
98
|
+
errors.push(`Transition from undeclared state: ${state}`);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
if (t.to && !declaredStates.has(t.to)) {
|
|
103
|
+
errors.push(`Transition to undeclared state: ${t.to}`);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
return errors;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export { BEHAVIOR_CATEGORIES, getBehaviorMetadata, isBehaviorCategory, isGameBehaviorCategory, validateBehaviorEvents, validateBehaviorStates, validateBehaviorStructure };
|
|
110
|
+
//# sourceMappingURL=types.js.map
|
|
111
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
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SAAS,UAAA,EAAY;AAC9B,QAAA,IAAI,CAAC,cAAA,CAAe,GAAA,CAAI,KAAK,CAAA,EAAG;AAC9B,UAAA,MAAA,CAAO,IAAA,CAAK,CAAA,kCAAA,EAAqC,KAAK,CAAA,CAAE,CAAA;AAAA,QAC1D;AAAA,MACF;AAAA,IACF;AAGA,IAAA,IAAI,EAAE,EAAA,IAAM,CAAC,eAAe,GAAA,CAAI,CAAA,CAAE,EAAE,CAAA,EAAG;AACrC,MAAA,MAAA,CAAO,IAAA,CAAK,CAAA,gCAAA,EAAmC,CAAA,CAAE,EAAE,CAAA,CAAE,CAAA;AAAA,IACvD;AAAA,EACF;AAEA,EAAA,OAAO,MAAA;AACT","file":"types.js","sourcesContent":["/**\n * Standard Behaviors Types\n *\n * Standard Behaviors are reusable Traits with a `std/` naming convention.\n * They use a more flexible state machine format optimized for authoring.\n *\n * ARCHITECTURE: Behaviors ARE Traits conceptually. They use:\n * - stateMachine: BehaviorStateMachine (flexible states, events, transitions)\n * - ticks: BehaviorTick[] (frame-by-frame execution for games)\n * - dataEntities: BehaviorDataEntity[] (runtime state)\n *\n * @packageDocumentation\n */\n\nimport type { SExpr, RequiredField } from '@almadar/core/types';\n\n// ============================================================================\n// Behavior Categories\n// ============================================================================\n\n/**\n * Categories of Standard Behaviors\n */\nexport const BEHAVIOR_CATEGORIES = [\n 'ui-interaction', // User interface state management\n 'data-management', // Data operations and state\n 'async', // Asynchronous workflows\n 'feedback', // User feedback and confirmations\n 'game-core', // Game loop and systems\n 'game-entity', // Game entity behaviors\n 'game-ui', // Game interface\n] as const;\n\nexport type BehaviorCategory = (typeof BEHAVIOR_CATEGORIES)[number];\n\n// ============================================================================\n// Config Field Types (for IDE hints and documentation)\n// ============================================================================\n\nexport type FieldType =\n | 'string'\n | 'number'\n | 'boolean'\n | 'array'\n | 'object'\n | 'entity'\n | 'slot'\n | 'pattern'\n | 'event'\n | 'action[]';\n\nexport interface ConfigField {\n name: string;\n type: FieldType;\n description: string;\n default?: unknown;\n enum?: string[];\n}\n\n// ============================================================================\n// Behavior State Machine Types (flexible for authoring)\n// ============================================================================\n\n/**\n * State definition - can be string or object\n */\nexport interface BehaviorState {\n name: string;\n isInitial?: boolean;\n isFinal?: boolean;\n description?: string;\n}\n\n/**\n * Event definition - simplified, only key required\n */\nexport interface BehaviorEvent {\n key: string;\n name?: string;\n description?: string;\n payload?: Record<string, unknown>;\n}\n\n/**\n * Transition definition - flexible from/to\n */\nexport interface BehaviorTransition {\n /** Source state(s) - string, '*' for any, or array */\n from?: string | string[] | '*';\n /** Target state - optional for self-transitions */\n to?: string;\n /** Event that triggers this transition */\n event: string;\n /** Guard condition (S-expression) */\n guard?: SExpr;\n /** Effects to execute (S-expressions) */\n effects?: SExpr[];\n}\n\n/**\n * State machine for behaviors - more flexible than core StateMachine\n */\nexport interface BehaviorStateMachine {\n initial: string;\n states: (string | BehaviorState)[];\n events: (string | BehaviorEvent)[];\n transitions: BehaviorTransition[];\n guards?: Array<{\n name: string;\n condition: SExpr;\n description?: string;\n }>;\n}\n\n// ============================================================================\n// Behavior Tick (for frame-by-frame execution)\n// ============================================================================\n\nexport interface BehaviorTick {\n name: string;\n description?: string;\n priority?: number;\n interval: 'frame' | number;\n appliesTo?: string[];\n guard?: SExpr;\n effects: SExpr[];\n}\n\n// ============================================================================\n// Behavior Data Entity (runtime state)\n// ============================================================================\n\nexport interface BehaviorEntityField {\n name: string;\n type: string;\n default?: unknown;\n required?: boolean;\n description?: string;\n}\n\nexport interface BehaviorDataEntity {\n name: string;\n runtime?: boolean;\n singleton?: boolean;\n fields: BehaviorEntityField[];\n description?: string;\n}\n\n// ============================================================================\n// Item Action (for render_ui props)\n// ============================================================================\n\nexport interface ItemAction {\n label: string;\n event?: string;\n navigatesTo?: string;\n placement?: 'row' | 'bulk' | 'card' | 'footer' | 'header';\n variant?: 'primary' | 'secondary' | 'ghost' | 'danger';\n showWhen?: SExpr | string;\n}\n\n// ============================================================================\n// Standard Behavior Interface\n// ============================================================================\n\n/**\n * Configuration schema for documentation and IDE hints\n */\nexport interface BehaviorConfig {\n required: ConfigField[];\n optional: ConfigField[];\n}\n\n/**\n * Standard Behavior definition\n */\nexport interface StandardBehavior {\n /** Behavior identifier (e.g., 'std/List', 'std/Form') */\n name: string;\n\n /** Category for organization */\n category: BehaviorCategory;\n\n /** Human-readable description */\n description: string;\n\n // ========== Documentation Extensions ==========\n\n /** When to use this behavior */\n suggestedFor?: string[];\n\n /** Configuration schema for IDE hints */\n configSchema?: BehaviorConfig;\n\n // ========== State Machine ==========\n\n /** State machine definition */\n stateMachine?: BehaviorStateMachine;\n\n // ========== Trait Features ==========\n\n /** Required fields from linked entity */\n requiredFields?: RequiredField[];\n\n /** Runtime data entities */\n dataEntities?: BehaviorDataEntity[];\n\n /** Frame-by-frame execution */\n ticks?: BehaviorTick[];\n\n /** Cross-behavior event listeners */\n listens?: Array<{\n event: string;\n triggers: string;\n guard?: SExpr;\n }>;\n\n /** Initial effects on behavior activation */\n initialEffects?: SExpr[];\n}\n\n/**\n * Behavior metadata for quick lookup\n */\nexport interface BehaviorMetadata {\n name: string;\n category: BehaviorCategory;\n description: string;\n suggestedFor: string[];\n states: string[];\n events: string[];\n tickCount: number;\n transitionCount: number;\n hasDataEntities: boolean;\n}\n\n// ============================================================================\n// Helper Functions\n// ============================================================================\n\nexport function isBehaviorCategory(value: string): value is BehaviorCategory {\n return BEHAVIOR_CATEGORIES.includes(value as BehaviorCategory);\n}\n\nexport function isGameBehaviorCategory(category: BehaviorCategory): boolean {\n return category.startsWith('game-');\n}\n\n/**\n * Extract metadata from a StandardBehavior\n */\nexport function getBehaviorMetadata(behavior: StandardBehavior): BehaviorMetadata {\n const sm = behavior.stateMachine;\n\n const states: string[] = (sm?.states || []).map(s =>\n typeof s === 'string' ? s : s.name\n );\n\n const events: string[] = (sm?.events || []).map(e =>\n typeof e === 'string' ? e : e.key\n );\n\n return {\n name: behavior.name,\n category: behavior.category,\n description: behavior.description || '',\n suggestedFor: behavior.suggestedFor || [],\n states,\n events,\n tickCount: behavior.ticks?.length || 0,\n transitionCount: sm?.transitions?.length || 0,\n hasDataEntities: (behavior.dataEntities?.length || 0) > 0,\n };\n}\n\n/**\n * Validate behavior structure\n */\nexport function validateBehaviorStructure(behavior: StandardBehavior): string[] {\n const errors: string[] = [];\n\n if (!behavior.name) {\n errors.push('Behavior must have a name');\n }\n\n if (!behavior.name.startsWith('std/')) {\n errors.push(`Behavior name should start with 'std/' (got: ${behavior.name})`);\n }\n\n if (!behavior.category) {\n errors.push('Behavior must have a category');\n }\n\n if (!isBehaviorCategory(behavior.category)) {\n errors.push(`Invalid category: ${behavior.category}`);\n }\n\n const sm = behavior.stateMachine;\n if (sm) {\n if (!sm.states || sm.states.length === 0) {\n errors.push('State machine must have at least one state');\n }\n\n if (!sm.initial) {\n errors.push('State machine must have an initial state');\n }\n }\n\n return errors;\n}\n\n/**\n * Validate behavior events match transitions\n */\nexport function validateBehaviorEvents(behavior: StandardBehavior): string[] {\n const errors: string[] = [];\n const sm = behavior.stateMachine;\n if (!sm) return errors;\n\n const declaredEvents = new Set(\n (sm.events || []).map(e => typeof e === 'string' ? e : e.key)\n );\n\n const transitionEvents = new Set(\n (sm.transitions || []).map(t => t.event)\n );\n\n for (const event of transitionEvents) {\n if (event && !declaredEvents.has(event)) {\n errors.push(`Transition uses undeclared event: ${event}`);\n }\n }\n\n return errors;\n}\n\n/**\n * Validate behavior states match transitions\n */\nexport function validateBehaviorStates(behavior: StandardBehavior): string[] {\n const errors: string[] = [];\n const sm = behavior.stateMachine;\n if (!sm) return errors;\n\n const declaredStates = new Set(\n (sm.states || []).map(s => typeof s === 'string' ? s : s.name)\n );\n\n for (const t of sm.transitions || []) {\n // Check 'from' states (allow '*' and arrays)\n if (t.from && t.from !== '*') {\n const fromStates = Array.isArray(t.from) ? t.from : [t.from];\n for (const state of fromStates) {\n if (!declaredStates.has(state)) {\n errors.push(`Transition from undeclared state: ${state}`);\n }\n }\n }\n\n // Check 'to' state (optional)\n if (t.to && !declaredStates.has(t.to)) {\n errors.push(`Transition to undeclared state: ${t.to}`);\n }\n }\n\n return errors;\n}\n"]}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { StandardBehavior } from './types.js';
|
|
2
|
+
import '@almadar/core/types';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* UI Interaction Behaviors
|
|
6
|
+
*
|
|
7
|
+
* Standard behaviors for common UI interaction patterns.
|
|
8
|
+
* These use the Trait architecture with stateMachine.
|
|
9
|
+
*
|
|
10
|
+
* IMPORTANT: These are GENERATION TEMPLATES for LLMs.
|
|
11
|
+
* They must use correct syntax:
|
|
12
|
+
* - render-ui (not render)
|
|
13
|
+
* - Explicit from states (not '*')
|
|
14
|
+
* - Valid pattern types (form-section, entity-detail, etc.)
|
|
15
|
+
*
|
|
16
|
+
* @packageDocumentation
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* std/List - The core behavior for displaying and interacting with entity collections.
|
|
21
|
+
*
|
|
22
|
+
* States: Browsing → Creating/Viewing/Editing/Deleting
|
|
23
|
+
* Implements complete CRUD operations with modal/drawer UI patterns.
|
|
24
|
+
*/
|
|
25
|
+
declare const LIST_BEHAVIOR: StandardBehavior;
|
|
26
|
+
declare const DETAIL_BEHAVIOR: StandardBehavior;
|
|
27
|
+
declare const FORM_BEHAVIOR: StandardBehavior;
|
|
28
|
+
declare const MODAL_BEHAVIOR: StandardBehavior;
|
|
29
|
+
declare const DRAWER_BEHAVIOR: StandardBehavior;
|
|
30
|
+
declare const TABS_BEHAVIOR: StandardBehavior;
|
|
31
|
+
declare const WIZARD_BEHAVIOR: StandardBehavior;
|
|
32
|
+
declare const MASTER_DETAIL_BEHAVIOR: StandardBehavior;
|
|
33
|
+
declare const FILTER_BEHAVIOR: StandardBehavior;
|
|
34
|
+
declare const UI_INTERACTION_BEHAVIORS: StandardBehavior[];
|
|
35
|
+
|
|
36
|
+
export { DETAIL_BEHAVIOR, DRAWER_BEHAVIOR, FILTER_BEHAVIOR, FORM_BEHAVIOR, LIST_BEHAVIOR, MASTER_DETAIL_BEHAVIOR, MODAL_BEHAVIOR, TABS_BEHAVIOR, UI_INTERACTION_BEHAVIORS, WIZARD_BEHAVIOR };
|