@tannerbroberts/about-time-core 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.
- package/README.md +53 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +9 -0
- package/dist/index.js.map +1 -0
- package/dist/templates/createBusyTemplate.d.ts +20 -0
- package/dist/templates/createBusyTemplate.d.ts.map +1 -0
- package/dist/templates/createBusyTemplate.js +24 -0
- package/dist/templates/createBusyTemplate.js.map +1 -0
- package/dist/templates/createLaneTemplate.d.ts +19 -0
- package/dist/templates/createLaneTemplate.d.ts.map +1 -0
- package/dist/templates/createLaneTemplate.js +33 -0
- package/dist/templates/createLaneTemplate.js.map +1 -0
- package/dist/templates/deleteTemplate.d.ts +18 -0
- package/dist/templates/deleteTemplate.d.ts.map +1 -0
- package/dist/templates/deleteTemplate.js +39 -0
- package/dist/templates/deleteTemplate.js.map +1 -0
- package/dist/templates/getTemplateById.d.ts +11 -0
- package/dist/templates/getTemplateById.d.ts.map +1 -0
- package/dist/templates/getTemplateById.js +12 -0
- package/dist/templates/getTemplateById.js.map +1 -0
- package/dist/templates/getTemplates.d.ts +14 -0
- package/dist/templates/getTemplates.d.ts.map +1 -0
- package/dist/templates/getTemplates.js +16 -0
- package/dist/templates/getTemplates.js.map +1 -0
- package/dist/templates/getVocabulary.d.ts +10 -0
- package/dist/templates/getVocabulary.d.ts.map +1 -0
- package/dist/templates/getVocabulary.js +23 -0
- package/dist/templates/getVocabulary.js.map +1 -0
- package/dist/templates/index.d.ts +16 -0
- package/dist/templates/index.d.ts.map +1 -0
- package/dist/templates/index.js +10 -0
- package/dist/templates/index.js.map +1 -0
- package/dist/templates/layout/addSegmentToEnd.d.ts +12 -0
- package/dist/templates/layout/addSegmentToEnd.d.ts.map +1 -0
- package/dist/templates/layout/addSegmentToEnd.js +41 -0
- package/dist/templates/layout/addSegmentToEnd.js.map +1 -0
- package/dist/templates/layout/applyLaneLayout.d.ts +16 -0
- package/dist/templates/layout/applyLaneLayout.d.ts.map +1 -0
- package/dist/templates/layout/applyLaneLayout.js +71 -0
- package/dist/templates/layout/applyLaneLayout.js.map +1 -0
- package/dist/templates/layout/distributeSegmentOffsetsByInterval.d.ts +12 -0
- package/dist/templates/layout/distributeSegmentOffsetsByInterval.d.ts.map +1 -0
- package/dist/templates/layout/distributeSegmentOffsetsByInterval.js +17 -0
- package/dist/templates/layout/distributeSegmentOffsetsByInterval.js.map +1 -0
- package/dist/templates/layout/equallyDistributeSegments.d.ts +11 -0
- package/dist/templates/layout/equallyDistributeSegments.d.ts.map +1 -0
- package/dist/templates/layout/equallyDistributeSegments.js +16 -0
- package/dist/templates/layout/equallyDistributeSegments.js.map +1 -0
- package/dist/templates/layout/fitLaneDurationToLast.d.ts +11 -0
- package/dist/templates/layout/fitLaneDurationToLast.d.ts.map +1 -0
- package/dist/templates/layout/fitLaneDurationToLast.js +32 -0
- package/dist/templates/layout/fitLaneDurationToLast.js.map +1 -0
- package/dist/templates/layout/index.d.ts +10 -0
- package/dist/templates/layout/index.d.ts.map +1 -0
- package/dist/templates/layout/index.js +10 -0
- package/dist/templates/layout/index.js.map +1 -0
- package/dist/templates/layout/insertGap.d.ts +12 -0
- package/dist/templates/layout/insertGap.d.ts.map +1 -0
- package/dist/templates/layout/insertGap.js +34 -0
- package/dist/templates/layout/insertGap.js.map +1 -0
- package/dist/templates/layout/insertSegmentAt.d.ts +14 -0
- package/dist/templates/layout/insertSegmentAt.d.ts.map +1 -0
- package/dist/templates/layout/insertSegmentAt.js +39 -0
- package/dist/templates/layout/insertSegmentAt.js.map +1 -0
- package/dist/templates/layout/packSegments.d.ts +11 -0
- package/dist/templates/layout/packSegments.d.ts.map +1 -0
- package/dist/templates/layout/packSegments.js +16 -0
- package/dist/templates/layout/packSegments.js.map +1 -0
- package/dist/templates/layout/pushSegmentToStart.d.ts +13 -0
- package/dist/templates/layout/pushSegmentToStart.d.ts.map +1 -0
- package/dist/templates/layout/pushSegmentToStart.js +36 -0
- package/dist/templates/layout/pushSegmentToStart.js.map +1 -0
- package/dist/templates/searchTemplates.d.ts +11 -0
- package/dist/templates/searchTemplates.d.ts.map +1 -0
- package/dist/templates/searchTemplates.js +13 -0
- package/dist/templates/searchTemplates.js.map +1 -0
- package/dist/templates/updateTemplate.d.ts +22 -0
- package/dist/templates/updateTemplate.d.ts.map +1 -0
- package/dist/templates/updateTemplate.js +45 -0
- package/dist/templates/updateTemplate.js.map +1 -0
- package/dist/types/index.d.ts +4 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +5 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/library.d.ts +7 -0
- package/dist/types/library.d.ts.map +1 -0
- package/dist/types/library.js +2 -0
- package/dist/types/library.js.map +1 -0
- package/dist/types/primitives.d.ts +19 -0
- package/dist/types/primitives.d.ts.map +1 -0
- package/dist/types/primitives.js +2 -0
- package/dist/types/primitives.js.map +1 -0
- package/dist/types/template.d.ts +44 -0
- package/dist/types/template.d.ts.map +1 -0
- package/dist/types/template.js +9 -0
- package/dist/types/template.js.map +1 -0
- package/dist/types/validation.d.ts +105 -0
- package/dist/types/validation.d.ts.map +1 -0
- package/dist/types/validation.js +2 -0
- package/dist/types/validation.js.map +1 -0
- package/dist/validation/index.d.ts +3 -0
- package/dist/validation/index.d.ts.map +1 -0
- package/dist/validation/index.js +3 -0
- package/dist/validation/index.js.map +1 -0
- package/dist/validation/validateLane.d.ts +22 -0
- package/dist/validation/validateLane.d.ts.map +1 -0
- package/dist/validation/validateLane.js +328 -0
- package/dist/validation/validateLane.js.map +1 -0
- package/dist/validation/validateVariableNames.d.ts +15 -0
- package/dist/validation/validateVariableNames.d.ts.map +1 -0
- package/dist/validation/validateVariableNames.js +70 -0
- package/dist/validation/validateVariableNames.js.map +1 -0
- package/package.json +54 -0
package/README.md
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
# @tannerbroberts/about-time-core
|
|
2
|
+
|
|
3
|
+
Core template operations and validation for about-time.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @tannerbroberts/about-time-core
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
```typescript
|
|
14
|
+
import {
|
|
15
|
+
createBusyTemplate,
|
|
16
|
+
createLaneTemplate,
|
|
17
|
+
validateLane,
|
|
18
|
+
validateVariableNames,
|
|
19
|
+
TemplateMap,
|
|
20
|
+
} from '@tannerbroberts/about-time-core';
|
|
21
|
+
|
|
22
|
+
// Initialize template storage
|
|
23
|
+
const templates: TemplateMap = {};
|
|
24
|
+
|
|
25
|
+
// Create a busy template (mutates templates map in place)
|
|
26
|
+
const template = createBusyTemplate({
|
|
27
|
+
intent: 'Boil water',
|
|
28
|
+
estimatedDuration: 300000,
|
|
29
|
+
willConsume: { water_cups: 2, clean_pot: 1 },
|
|
30
|
+
willProduce: { boiling_water_cups: 2 },
|
|
31
|
+
}, templates, crypto.randomUUID);
|
|
32
|
+
|
|
33
|
+
// Validate variable names
|
|
34
|
+
const validation = validateVariableNames(template.willConsume);
|
|
35
|
+
if (!validation.isValid) {
|
|
36
|
+
console.error(validation.errors);
|
|
37
|
+
}
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## Exports
|
|
41
|
+
|
|
42
|
+
- `@tannerbroberts/about-time-core` - Everything
|
|
43
|
+
- `@tannerbroberts/about-time-core/types` - Type definitions only
|
|
44
|
+
- `@tannerbroberts/about-time-core/templates` - Template CRUD + layout operations
|
|
45
|
+
- `@tannerbroberts/about-time-core/validation` - Validation functions
|
|
46
|
+
|
|
47
|
+
## Documentation
|
|
48
|
+
|
|
49
|
+
See [spec.md](./spec.md) for complete API documentation.
|
|
50
|
+
|
|
51
|
+
## License
|
|
52
|
+
|
|
53
|
+
MIT
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,cAAc,kBAAkB,CAAC;AAGjC,cAAc,sBAAsB,CAAC;AAGrC,cAAc,uBAAuB,CAAC;AAGtC,cAAc,6BAA6B,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// Types
|
|
2
|
+
export * from './types/index.js';
|
|
3
|
+
// Template operations
|
|
4
|
+
export * from './templates/index.js';
|
|
5
|
+
// Validation
|
|
6
|
+
export * from './validation/index.js';
|
|
7
|
+
// Layout utilities
|
|
8
|
+
export * from './templates/layout/index.js';
|
|
9
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,QAAQ;AACR,cAAc,kBAAkB,CAAC;AAEjC,sBAAsB;AACtB,cAAc,sBAAsB,CAAC;AAErC,aAAa;AACb,cAAc,uBAAuB,CAAC;AAEtC,mBAAmB;AACnB,cAAc,6BAA6B,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { BusyTemplate, TemplateMap, StateLedger, UUID, Duration } from '../types/index.js';
|
|
2
|
+
export interface CreateBusyTemplateInput {
|
|
3
|
+
intent: string;
|
|
4
|
+
estimatedDuration: Duration;
|
|
5
|
+
willConsume: StateLedger;
|
|
6
|
+
willProduce: StateLedger;
|
|
7
|
+
authorId?: UUID;
|
|
8
|
+
}
|
|
9
|
+
export type IdGenerator = () => string;
|
|
10
|
+
/**
|
|
11
|
+
* Creates a new BusyTemplate and adds it to the map.
|
|
12
|
+
* Mutates the map in place for O(1) performance.
|
|
13
|
+
*
|
|
14
|
+
* @param input - Template properties
|
|
15
|
+
* @param templates - Template map to add to (mutated in place)
|
|
16
|
+
* @param generateId - Function to generate unique IDs (e.g., crypto.randomUUID)
|
|
17
|
+
* @returns The created BusyTemplate
|
|
18
|
+
*/
|
|
19
|
+
export declare function createBusyTemplate(input: CreateBusyTemplateInput, templates: TemplateMap, generateId: IdGenerator): BusyTemplate;
|
|
20
|
+
//# sourceMappingURL=createBusyTemplate.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createBusyTemplate.d.ts","sourceRoot":"","sources":["../../src/templates/createBusyTemplate.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,WAAW,EAAE,WAAW,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAEhG,MAAM,WAAW,uBAAuB;IACtC,MAAM,EAAE,MAAM,CAAC;IACf,iBAAiB,EAAE,QAAQ,CAAC;IAC5B,WAAW,EAAE,WAAW,CAAC;IACzB,WAAW,EAAE,WAAW,CAAC;IACzB,QAAQ,CAAC,EAAE,IAAI,CAAC;CACjB;AAED,MAAM,MAAM,WAAW,GAAG,MAAM,MAAM,CAAC;AAEvC;;;;;;;;GAQG;AACH,wBAAgB,kBAAkB,CAChC,KAAK,EAAE,uBAAuB,EAC9B,SAAS,EAAE,WAAW,EACtB,UAAU,EAAE,WAAW,GACtB,YAAY,CAcd"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates a new BusyTemplate and adds it to the map.
|
|
3
|
+
* Mutates the map in place for O(1) performance.
|
|
4
|
+
*
|
|
5
|
+
* @param input - Template properties
|
|
6
|
+
* @param templates - Template map to add to (mutated in place)
|
|
7
|
+
* @param generateId - Function to generate unique IDs (e.g., crypto.randomUUID)
|
|
8
|
+
* @returns The created BusyTemplate
|
|
9
|
+
*/
|
|
10
|
+
export function createBusyTemplate(input, templates, generateId) {
|
|
11
|
+
const template = {
|
|
12
|
+
templateType: 'busy',
|
|
13
|
+
id: generateId(),
|
|
14
|
+
intent: input.intent,
|
|
15
|
+
authorId: input.authorId ?? 'unknown',
|
|
16
|
+
estimatedDuration: input.estimatedDuration,
|
|
17
|
+
references: [],
|
|
18
|
+
willConsume: { ...input.willConsume },
|
|
19
|
+
willProduce: { ...input.willProduce },
|
|
20
|
+
};
|
|
21
|
+
templates[template.id] = template;
|
|
22
|
+
return template;
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=createBusyTemplate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createBusyTemplate.js","sourceRoot":"","sources":["../../src/templates/createBusyTemplate.ts"],"names":[],"mappings":"AAYA;;;;;;;;GAQG;AACH,MAAM,UAAU,kBAAkB,CAChC,KAA8B,EAC9B,SAAsB,EACtB,UAAuB;IAEvB,MAAM,QAAQ,GAAiB;QAC7B,YAAY,EAAE,MAAM;QACpB,EAAE,EAAE,UAAU,EAAE;QAChB,MAAM,EAAE,KAAK,CAAC,MAAM;QACpB,QAAQ,EAAE,KAAK,CAAC,QAAQ,IAAI,SAAS;QACrC,iBAAiB,EAAE,KAAK,CAAC,iBAAiB;QAC1C,UAAU,EAAE,EAAE;QACd,WAAW,EAAE,EAAE,GAAG,KAAK,CAAC,WAAW,EAAE;QACrC,WAAW,EAAE,EAAE,GAAG,KAAK,CAAC,WAAW,EAAE;KACtC,CAAC;IAEF,SAAS,CAAC,QAAQ,CAAC,EAAE,CAAC,GAAG,QAAQ,CAAC;IAClC,OAAO,QAAQ,CAAC;AAClB,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { LaneTemplate, TemplateMap, Segment, UUID, Duration } from '../types/index.js';
|
|
2
|
+
export interface CreateLaneTemplateInput {
|
|
3
|
+
intent: string;
|
|
4
|
+
estimatedDuration: Duration;
|
|
5
|
+
segments: Segment[];
|
|
6
|
+
authorId?: UUID;
|
|
7
|
+
}
|
|
8
|
+
export type IdGenerator = () => string;
|
|
9
|
+
/**
|
|
10
|
+
* Creates a new LaneTemplate and adds it to the map.
|
|
11
|
+
* Mutates the map in place for O(1) performance.
|
|
12
|
+
*
|
|
13
|
+
* @param input - Template properties
|
|
14
|
+
* @param templates - Template map to add to (mutated in place)
|
|
15
|
+
* @param generateId - Function to generate unique IDs
|
|
16
|
+
* @returns The created LaneTemplate
|
|
17
|
+
*/
|
|
18
|
+
export declare function createLaneTemplate(input: CreateLaneTemplateInput, templates: TemplateMap, generateId: IdGenerator): LaneTemplate;
|
|
19
|
+
//# sourceMappingURL=createLaneTemplate.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createLaneTemplate.d.ts","sourceRoot":"","sources":["../../src/templates/createLaneTemplate.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,WAAW,EAAE,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAE5F,MAAM,WAAW,uBAAuB;IACtC,MAAM,EAAE,MAAM,CAAC;IACf,iBAAiB,EAAE,QAAQ,CAAC;IAC5B,QAAQ,EAAE,OAAO,EAAE,CAAC;IACpB,QAAQ,CAAC,EAAE,IAAI,CAAC;CACjB;AAED,MAAM,MAAM,WAAW,GAAG,MAAM,MAAM,CAAC;AAEvC;;;;;;;;GAQG;AACH,wBAAgB,kBAAkB,CAChC,KAAK,EAAE,uBAAuB,EAC9B,SAAS,EAAE,WAAW,EACtB,UAAU,EAAE,WAAW,GACtB,YAAY,CAwBd"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates a new LaneTemplate and adds it to the map.
|
|
3
|
+
* Mutates the map in place for O(1) performance.
|
|
4
|
+
*
|
|
5
|
+
* @param input - Template properties
|
|
6
|
+
* @param templates - Template map to add to (mutated in place)
|
|
7
|
+
* @param generateId - Function to generate unique IDs
|
|
8
|
+
* @returns The created LaneTemplate
|
|
9
|
+
*/
|
|
10
|
+
export function createLaneTemplate(input, templates, generateId) {
|
|
11
|
+
const template = {
|
|
12
|
+
templateType: 'lane',
|
|
13
|
+
id: generateId(),
|
|
14
|
+
intent: input.intent,
|
|
15
|
+
authorId: input.authorId ?? 'unknown',
|
|
16
|
+
estimatedDuration: input.estimatedDuration,
|
|
17
|
+
references: [],
|
|
18
|
+
segments: input.segments.map(s => ({ ...s })),
|
|
19
|
+
};
|
|
20
|
+
// Double-linking: update children to point back to this parent
|
|
21
|
+
for (const segment of template.segments) {
|
|
22
|
+
const child = templates[segment.templateId];
|
|
23
|
+
if (child) {
|
|
24
|
+
child.references.push({
|
|
25
|
+
parentId: template.id,
|
|
26
|
+
relationshipId: segment.relationshipId,
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
templates[template.id] = template;
|
|
31
|
+
return template;
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=createLaneTemplate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createLaneTemplate.js","sourceRoot":"","sources":["../../src/templates/createLaneTemplate.ts"],"names":[],"mappings":"AAWA;;;;;;;;GAQG;AACH,MAAM,UAAU,kBAAkB,CAChC,KAA8B,EAC9B,SAAsB,EACtB,UAAuB;IAEvB,MAAM,QAAQ,GAAiB;QAC7B,YAAY,EAAE,MAAM;QACpB,EAAE,EAAE,UAAU,EAAE;QAChB,MAAM,EAAE,KAAK,CAAC,MAAM;QACpB,QAAQ,EAAE,KAAK,CAAC,QAAQ,IAAI,SAAS;QACrC,iBAAiB,EAAE,KAAK,CAAC,iBAAiB;QAC1C,UAAU,EAAE,EAAE;QACd,QAAQ,EAAE,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,CAAC,CAAC;KAC9C,CAAC;IAEF,+DAA+D;IAC/D,KAAK,MAAM,OAAO,IAAI,QAAQ,CAAC,QAAQ,EAAE,CAAC;QACxC,MAAM,KAAK,GAAG,SAAS,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;QAC5C,IAAI,KAAK,EAAE,CAAC;YACV,KAAK,CAAC,UAAU,CAAC,IAAI,CAAC;gBACpB,QAAQ,EAAE,QAAQ,CAAC,EAAE;gBACrB,cAAc,EAAE,OAAO,CAAC,cAAc;aACvC,CAAC,CAAC;QACL,CAAC;IACH,CAAC;IAED,SAAS,CAAC,QAAQ,CAAC,EAAE,CAAC,GAAG,QAAQ,CAAC;IAClC,OAAO,QAAQ,CAAC;AAClB,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { Template, TemplateId, TemplateMap } from '../types/index.js';
|
|
2
|
+
export type DeleteTemplateResult = {
|
|
3
|
+
success: true;
|
|
4
|
+
deleted: Template;
|
|
5
|
+
} | {
|
|
6
|
+
success: false;
|
|
7
|
+
error: string;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* Deletes a template by ID in place.
|
|
11
|
+
* Mutates the map for O(1) performance.
|
|
12
|
+
*
|
|
13
|
+
* @param id - ID of template to delete
|
|
14
|
+
* @param templates - Template map (mutated in place)
|
|
15
|
+
* @returns Result with the deleted template or error
|
|
16
|
+
*/
|
|
17
|
+
export declare function deleteTemplate(id: TemplateId, templates: TemplateMap): DeleteTemplateResult;
|
|
18
|
+
//# sourceMappingURL=deleteTemplate.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deleteTemplate.d.ts","sourceRoot":"","sources":["../../src/templates/deleteTemplate.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAE3E,MAAM,MAAM,oBAAoB,GAC5B;IAAE,OAAO,EAAE,IAAI,CAAC;IAAC,OAAO,EAAE,QAAQ,CAAA;CAAE,GACpC;IAAE,OAAO,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC;AAEtC;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAC5B,EAAE,EAAE,UAAU,EACd,SAAS,EAAE,WAAW,GACrB,oBAAoB,CAsCtB"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Deletes a template by ID in place.
|
|
3
|
+
* Mutates the map for O(1) performance.
|
|
4
|
+
*
|
|
5
|
+
* @param id - ID of template to delete
|
|
6
|
+
* @param templates - Template map (mutated in place)
|
|
7
|
+
* @returns Result with the deleted template or error
|
|
8
|
+
*/
|
|
9
|
+
export function deleteTemplate(id, templates) {
|
|
10
|
+
const existing = templates[id];
|
|
11
|
+
if (!existing) {
|
|
12
|
+
return {
|
|
13
|
+
success: false,
|
|
14
|
+
error: `Template with ID ${id} not found`,
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
// 1. If it's a lane template, remove back-links from its children
|
|
18
|
+
if (existing.templateType === 'lane') {
|
|
19
|
+
for (const segment of existing.segments) {
|
|
20
|
+
const child = templates[segment.templateId];
|
|
21
|
+
if (child) {
|
|
22
|
+
child.references = child.references.filter(ref => !(ref.parentId === id && ref.relationshipId === segment.relationshipId));
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
// 2. Remove this template from its parents' segments
|
|
27
|
+
for (const ref of existing.references) {
|
|
28
|
+
const parent = templates[ref.parentId];
|
|
29
|
+
if (parent && parent.templateType === 'lane') {
|
|
30
|
+
parent.segments = parent.segments.filter(s => !(s.templateId === id && s.relationshipId === ref.relationshipId));
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
delete templates[id];
|
|
34
|
+
return {
|
|
35
|
+
success: true,
|
|
36
|
+
deleted: existing,
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=deleteTemplate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deleteTemplate.js","sourceRoot":"","sources":["../../src/templates/deleteTemplate.ts"],"names":[],"mappings":"AAMA;;;;;;;GAOG;AACH,MAAM,UAAU,cAAc,CAC5B,EAAc,EACd,SAAsB;IAEtB,MAAM,QAAQ,GAAG,SAAS,CAAC,EAAE,CAAC,CAAC;IAE/B,IAAI,CAA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|
3
|
+
* Finds a template by ID.
|
|
4
|
+
* O(1) lookup performance.
|
|
5
|
+
*
|
|
6
|
+
* @param id - The template ID to find
|
|
7
|
+
* @param templates - Template map to search
|
|
8
|
+
* @returns The template if found, undefined otherwise
|
|
9
|
+
*/
|
|
10
|
+
export declare function getTemplateById(id: TemplateId, templates: TemplateMap): Template | undefined;
|
|
11
|
+
//# sourceMappingURL=getTemplateById.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getTemplateById.d.ts","sourceRoot":"","sources":["../../src/templates/getTemplateById.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAE3E;;;;;;;GAOG;AACH,wBAAgB,eAAe,CAC7B,EAAE,EAAE,UAAU,EACd,SAAS,EAAE,WAAW,GACrB,QAAQ,GAAG,SAAS,CAEtB"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Finds a template by ID.
|
|
3
|
+
* O(1) lookup performance.
|
|
4
|
+
*
|
|
5
|
+
* @param id - The template ID to find
|
|
6
|
+
* @param templates - Template map to search
|
|
7
|
+
* @returns The template if found, undefined otherwise
|
|
8
|
+
*/
|
|
9
|
+
export function getTemplateById(id, templates) {
|
|
10
|
+
return templates[id];
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=getTemplateById.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getTemplateById.js","sourceRoot":"","sources":["../../src/templates/getTemplateById.ts"],"names":[],"mappings":"AAEA;;;;;;;GAOG;AACH,MAAM,UAAU,eAAe,CAC7B,EAAc,EACd,SAAsB;IAEtB,OAAO,SAAS,CAAC,EAAE,CAAC,CAAC;AACvB,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { Template, TemplateType, TemplateMap } from '../types/index.js';
|
|
2
|
+
export interface GetTemplatesOptions {
|
|
3
|
+
templateType?: TemplateType;
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* Gets templates as an array, optionally filtered by type.
|
|
7
|
+
* Use sparingly on large maps—iteration is O(n).
|
|
8
|
+
*
|
|
9
|
+
* @param templates - Template map
|
|
10
|
+
* @param options - Filter options
|
|
11
|
+
* @returns Array of templates
|
|
12
|
+
*/
|
|
13
|
+
export declare function getTemplates(templates: TemplateMap, options?: GetTemplatesOptions): Template[];
|
|
14
|
+
//# sourceMappingURL=getTemplates.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getTemplates.d.ts","sourceRoot":"","sources":["../../src/templates/getTemplates.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAE7E,MAAM,WAAW,mBAAmB;IAClC,YAAY,CAAC,EAAE,YAAY,CAAC;CAC7B;AAED;;;;;;;GAOG;AACH,wBAAgB,YAAY,CAC1B,SAAS,EAAE,WAAW,EACtB,OAAO,GAAE,mBAAwB,GAChC,QAAQ,EAAE,CAOZ"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Gets templates as an array, optionally filtered by type.
|
|
3
|
+
* Use sparingly on large maps—iteration is O(n).
|
|
4
|
+
*
|
|
5
|
+
* @param templates - Template map
|
|
6
|
+
* @param options - Filter options
|
|
7
|
+
* @returns Array of templates
|
|
8
|
+
*/
|
|
9
|
+
export function getTemplates(templates, options = {}) {
|
|
10
|
+
const values = Object.values(templates);
|
|
11
|
+
if (options.templateType) {
|
|
12
|
+
return values.filter(t => t.templateType === options.templateType);
|
|
13
|
+
}
|
|
14
|
+
return values;
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=getTemplates.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getTemplates.js","sourceRoot":"","sources":["../../src/templates/getTemplates.ts"],"names":[],"mappings":"AAMA;;;;;;;GAOG;AACH,MAAM,UAAU,YAAY,CAC1B,SAAsB,EACtB,UAA+B,EAAE;IAEjC,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;IAExC,IAAI,OAAO,CAAC,YAAY,EAAE,CAAC;QACzB,OAAO,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,YAAY,KAAK,OAAO,CAAC,YAAY,CAAC,CAAC;IACrE,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { VariableName, TemplateMap } from '../types/index.js';
|
|
2
|
+
/**
|
|
3
|
+
* Extracts all unique variable names from template StateLedgers.
|
|
4
|
+
* Note: Iterates all templates—O(n).
|
|
5
|
+
*
|
|
6
|
+
* @param templates - Template map
|
|
7
|
+
* @returns Sorted array of unique variable names
|
|
8
|
+
*/
|
|
9
|
+
export declare function getVocabulary(templates: TemplateMap): VariableName[];
|
|
10
|
+
//# sourceMappingURL=getVocabulary.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getVocabulary.d.ts","sourceRoot":"","sources":["../../src/templates/getVocabulary.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAgB,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEjF;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,SAAS,EAAE,WAAW,GAAG,YAAY,EAAE,CAgBpE"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Extracts all unique variable names from template StateLedgers.
|
|
3
|
+
* Note: Iterates all templates—O(n).
|
|
4
|
+
*
|
|
5
|
+
* @param templates - Template map
|
|
6
|
+
* @returns Sorted array of unique variable names
|
|
7
|
+
*/
|
|
8
|
+
export function getVocabulary(templates) {
|
|
9
|
+
const variables = new Set();
|
|
10
|
+
for (const template of Object.values(templates)) {
|
|
11
|
+
if (template.templateType === 'busy') {
|
|
12
|
+
const busy = template;
|
|
13
|
+
for (const varName of Object.keys(busy.willConsume)) {
|
|
14
|
+
variables.add(varName);
|
|
15
|
+
}
|
|
16
|
+
for (const varName of Object.keys(busy.willProduce)) {
|
|
17
|
+
variables.add(varName);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return Array.from(variables).sort();
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=getVocabulary.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getVocabulary.js","sourceRoot":"","sources":["../../src/templates/getVocabulary.ts"],"names":[],"mappings":"AAEA;;;;;;GAMG;AACH,MAAM,UAAU,aAAa,CAAC,SAAsB;IAClD,MAAM,SAAS,GAAG,IAAI,GAAG,EAAgB,CAAC;IAE1C,KAAK,MAAM,QAAQ,IAAI,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC,EAAE,CAAC;QAChD,IAAI,QAAQ,CAAC,YAAY,KAAK,MAAM,EAAE,CAAC;YACrC,MAAM,IAAI,GAAG,QAAwB,CAAC;YACtC,KAAK,MAAM,OAAO,IAAI,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,EAAE,CAAC;gBACpD,SAAS,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;YACzB,CAAC;YACD,KAAK,MAAM,OAAO,IAAI,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,EAAE,CAAC;gBACpD,SAAS,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;YACzB,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,IAAI,EAAE,CAAC;AACtC,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export { createBusyTemplate } from './createBusyTemplate.js';
|
|
2
|
+
export type { CreateBusyTemplateInput } from './createBusyTemplate.js';
|
|
3
|
+
export { createLaneTemplate } from './createLaneTemplate.js';
|
|
4
|
+
export type { CreateLaneTemplateInput } from './createLaneTemplate.js';
|
|
5
|
+
export { getTemplateById } from './getTemplateById.js';
|
|
6
|
+
export { getTemplates } from './getTemplates.js';
|
|
7
|
+
export type { GetTemplatesOptions } from './getTemplates.js';
|
|
8
|
+
export { searchTemplates } from './searchTemplates.js';
|
|
9
|
+
export { updateTemplate } from './updateTemplate.js';
|
|
10
|
+
export type { UpdateTemplateResult, TemplateUpdates } from './updateTemplate.js';
|
|
11
|
+
export { deleteTemplate } from './deleteTemplate.js';
|
|
12
|
+
export type { DeleteTemplateResult } from './deleteTemplate.js';
|
|
13
|
+
export { getVocabulary } from './getVocabulary.js';
|
|
14
|
+
export * from './layout/index.js';
|
|
15
|
+
export type { IdGenerator } from './createBusyTemplate.js';
|
|
16
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/templates/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,YAAY,EAAE,uBAAuB,EAAE,MAAM,yBAAyB,CAAC;AAEvE,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,YAAY,EAAE,uBAAuB,EAAE,MAAM,yBAAyB,CAAC;AAEvE,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,YAAY,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAE7D,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,YAAY,EAAE,oBAAoB,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAEjF,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,YAAY,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAEhE,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAEnD,cAAc,mBAAmB,CAAC;AAElC,YAAY,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export { createBusyTemplate } from './createBusyTemplate.js';
|
|
2
|
+
export { createLaneTemplate } from './createLaneTemplate.js';
|
|
3
|
+
export { getTemplateById } from './getTemplateById.js';
|
|
4
|
+
export { getTemplates } from './getTemplates.js';
|
|
5
|
+
export { searchTemplates } from './searchTemplates.js';
|
|
6
|
+
export { updateTemplate } from './updateTemplate.js';
|
|
7
|
+
export { deleteTemplate } from './deleteTemplate.js';
|
|
8
|
+
export { getVocabulary } from './getVocabulary.js';
|
|
9
|
+
export * from './layout/index.js';
|
|
10
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/templates/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAG7D,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAG7D,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAGjD,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAGrD,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAGrD,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAEnD,cAAc,mBAAmB,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { TemplateId, TemplateMap, LaneTemplate, RelationshipId } from '../../types/index.js';
|
|
2
|
+
/**
|
|
3
|
+
* Adds a new segment at the very end of the lane.
|
|
4
|
+
*
|
|
5
|
+
* @param laneId - ID of the lane
|
|
6
|
+
* @param childId - ID of the template to add as a segment
|
|
7
|
+
* @param relationshipId - Unique ID for this specific relationship
|
|
8
|
+
* @param templates - Template map (mutated in place)
|
|
9
|
+
* @returns The updated LaneTemplate or null
|
|
10
|
+
*/
|
|
11
|
+
export declare function addSegmentToEnd(laneId: TemplateId, childId: TemplateId, relationshipId: RelationshipId, templates: TemplateMap): LaneTemplate | null;
|
|
12
|
+
//# sourceMappingURL=addSegmentToEnd.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"addSegmentToEnd.d.ts","sourceRoot":"","sources":["../../../src/templates/layout/addSegmentToEnd.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAGlG;;;;;;;;GAQG;AACH,wBAAgB,eAAe,CAC7B,MAAM,EAAE,UAAU,EAClB,OAAO,EAAE,UAAU,EACnB,cAAc,EAAE,cAAc,EAC9B,SAAS,EAAE,WAAW,GACrB,YAAY,GAAG,IAAI,CAmCrB"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { isLaneTemplate } from '../../types/template.js';
|
|
2
|
+
/**
|
|
3
|
+
* Adds a new segment at the very end of the lane.
|
|
4
|
+
*
|
|
5
|
+
* @param laneId - ID of the lane
|
|
6
|
+
* @param childId - ID of the template to add as a segment
|
|
7
|
+
* @param relationshipId - Unique ID for this specific relationship
|
|
8
|
+
* @param templates - Template map (mutated in place)
|
|
9
|
+
* @returns The updated LaneTemplate or null
|
|
10
|
+
*/
|
|
11
|
+
export function addSegmentToEnd(laneId, childId, relationshipId, templates) {
|
|
12
|
+
const lane = templates[laneId];
|
|
13
|
+
const child = templates[childId];
|
|
14
|
+
if (!lane || !isLaneTemplate(lane) || !child) {
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
// Calculate current end time
|
|
18
|
+
let maxEndTime = 0;
|
|
19
|
+
for (const segment of lane.segments) {
|
|
20
|
+
const segmentChild = templates[segment.templateId];
|
|
21
|
+
if (segmentChild) {
|
|
22
|
+
const endTime = segment.offset + segmentChild.estimatedDuration;
|
|
23
|
+
if (endTime > maxEndTime) {
|
|
24
|
+
maxEndTime = endTime;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
const newSegment = {
|
|
29
|
+
templateId: childId,
|
|
30
|
+
relationshipId,
|
|
31
|
+
offset: maxEndTime,
|
|
32
|
+
};
|
|
33
|
+
lane.segments.push(newSegment);
|
|
34
|
+
// Double-linking
|
|
35
|
+
child.references.push({
|
|
36
|
+
parentId: laneId,
|
|
37
|
+
relationshipId,
|
|
38
|
+
});
|
|
39
|
+
return lane;
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=addSegmentToEnd.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"addSegmentToEnd.js","sourceRoot":"","sources":["../../../src/templates/layout/addSegmentToEnd.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAEzD;;;;;;;;GAQG;AACH,MAAM,UAAU,eAAe,CAC7B,MAAkB,EAClB,OAAmB,EACnB,cAA8B,EAC9B,SAAsB;IAEtB,MAAM,IAAI,GAAG,SAAS,CAAC,MAAM,CAAC,CAAC;IAC/B,MAAM,KAAK,GAAG,SAAS,CAAC,OAAO,CAAC,CAAC;IAEjC,IAAI,CAAC,IAAI,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC;QAC7C,OAAO,IAAI,CAAC;IACd,CAAC;IAED,6BAA6B;IAC7B,IAAI,UAAU,GAAG,CAAC,CAAC;IACnB,KAAK,MAAM,OAAO,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;QACpC,MAAM,YAAY,GAAG,SAAS,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;QACnD,IAAI,YAAY,EAAE,CAAC;YACjB,MAAM,OAAO,GAAG,OAAO,CAAC,MAAM,GAAG,YAAY,CAAC,iBAAiB,CAAC;YAChE,IAAI,OAAO,GAAG,UAAU,EAAE,CAAC;gBACzB,UAAU,GAAG,OAAO,CAAC;YACvB,CAAC;QACH,CAAC;IACH,CAAC;IAED,MAAM,UAAU,GAAG;QACjB,UAAU,EAAE,OAAO;QACnB,cAAc;QACd,MAAM,EAAE,UAAU;KACnB,CAAC;IAEF,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;IAE/B,iBAAiB;IACjB,KAAK,CAAC,UAAU,CAAC,IAAI,CAAC;QACpB,QAAQ,EAAE,MAAM;QAChB,cAAc;KACf,CAAC,CAAC;IAEH,OAAO,IAAI,CAAC;AACd,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { TemplateId, TemplateMap, LaneTemplate, Duration } from '../../types/index.js';
|
|
2
|
+
export interface LaneLayoutOptions {
|
|
3
|
+
justifyContent?: 'start' | 'end' | 'center' | 'space-between' | 'space-around' | 'space-evenly';
|
|
4
|
+
gap?: Duration;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Applies flexbox-like layout rules to a lane's segments.
|
|
8
|
+
* Sorts segments by their current offset before applying layout.
|
|
9
|
+
*
|
|
10
|
+
* @param laneId - ID of the lane to layout
|
|
11
|
+
* @param templates - Template map (mutated in place)
|
|
12
|
+
* @param options - Layout options (justifyContent, gap)
|
|
13
|
+
* @returns The updated LaneTemplate or null
|
|
14
|
+
*/
|
|
15
|
+
export declare function applyLaneLayout(laneId: TemplateId, templates: TemplateMap, options?: LaneLayoutOptions): LaneTemplate | null;
|
|
16
|
+
//# sourceMappingURL=applyLaneLayout.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"applyLaneLayout.d.ts","sourceRoot":"","sources":["../../../src/templates/layout/applyLaneLayout.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAG5F,MAAM,WAAW,iBAAiB;IAChC,cAAc,CAAC,EAAE,OAAO,GAAG,KAAK,GAAG,QAAQ,GAAG,eAAe,GAAG,cAAc,GAAG,cAAc,CAAC;IAChG,GAAG,CAAC,EAAE,QAAQ,CAAC;CAChB;AAED;;;;;;;;GAQG;AACH,wBAAgB,eAAe,CAC7B,MAAM,EAAE,UAAU,EAClB,SAAS,EAAE,WAAW,EACtB,OAAO,GAAE,iBAAsB,GAC9B,YAAY,GAAG,IAAI,CAqErB"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { isLaneTemplate } from '../../types/template.js';
|
|
2
|
+
/**
|
|
3
|
+
* Applies flexbox-like layout rules to a lane's segments.
|
|
4
|
+
* Sorts segments by their current offset before applying layout.
|
|
5
|
+
*
|
|
6
|
+
* @param laneId - ID of the lane to layout
|
|
7
|
+
* @param templates - Template map (mutated in place)
|
|
8
|
+
* @param options - Layout options (justifyContent, gap)
|
|
9
|
+
* @returns The updated LaneTemplate or null
|
|
10
|
+
*/
|
|
11
|
+
export function applyLaneLayout(laneId, templates, options = {}) {
|
|
12
|
+
const lane = templates[laneId];
|
|
13
|
+
if (!lane || !isLaneTemplate(lane)) {
|
|
14
|
+
return null;
|
|
15
|
+
}
|
|
16
|
+
if (lane.segments.length === 0) {
|
|
17
|
+
return lane;
|
|
18
|
+
}
|
|
19
|
+
const { justifyContent = 'start', gap = 0 } = options;
|
|
20
|
+
// Sort segments by current offset to maintain relative order
|
|
21
|
+
const sortedSegments = [...lane.segments].sort((a, b) => a.offset - b.offset);
|
|
22
|
+
// Calculate total duration of children
|
|
23
|
+
const childDurations = sortedSegments.map(s => {
|
|
24
|
+
const child = templates[s.templateId];
|
|
25
|
+
return child ? child.estimatedDuration : 0;
|
|
26
|
+
});
|
|
27
|
+
const totalChildDuration = childDurations.reduce((sum, d) => sum + d, 0);
|
|
28
|
+
const numSegments = sortedSegments.length;
|
|
29
|
+
const totalGapDuration = gap * (numSegments - 1);
|
|
30
|
+
const contentDuration = totalChildDuration + totalGapDuration;
|
|
31
|
+
const remainingSpace = lane.estimatedDuration - contentDuration;
|
|
32
|
+
let currentOffset = 0;
|
|
33
|
+
let extraGap = 0;
|
|
34
|
+
switch (justifyContent) {
|
|
35
|
+
case 'start':
|
|
36
|
+
currentOffset = 0;
|
|
37
|
+
break;
|
|
38
|
+
case 'end':
|
|
39
|
+
currentOffset = remainingSpace;
|
|
40
|
+
break;
|
|
41
|
+
case 'center':
|
|
42
|
+
currentOffset = remainingSpace / 2;
|
|
43
|
+
break;
|
|
44
|
+
case 'space-between':
|
|
45
|
+
currentOffset = 0;
|
|
46
|
+
if (numSegments > 1) {
|
|
47
|
+
extraGap = remainingSpace / (numSegments - 1);
|
|
48
|
+
}
|
|
49
|
+
break;
|
|
50
|
+
case 'space-around':
|
|
51
|
+
if (numSegments > 0) {
|
|
52
|
+
extraGap = remainingSpace / numSegments;
|
|
53
|
+
currentOffset = extraGap / 2;
|
|
54
|
+
}
|
|
55
|
+
break;
|
|
56
|
+
case 'space-evenly':
|
|
57
|
+
if (numSegments > 0) {
|
|
58
|
+
extraGap = remainingSpace / (numSegments + 1);
|
|
59
|
+
currentOffset = extraGap;
|
|
60
|
+
}
|
|
61
|
+
break;
|
|
62
|
+
}
|
|
63
|
+
for (let i = 0; i < numSegments; i++) {
|
|
64
|
+
sortedSegments[i].offset = currentOffset;
|
|
65
|
+
currentOffset += childDurations[i] + gap + extraGap;
|
|
66
|
+
}
|
|
67
|
+
// Update the lane's segments array with the sorted and repositioned segments
|
|
68
|
+
lane.segments = sortedSegments;
|
|
69
|
+
return lane;
|
|
70
|
+
}
|
|
71
|
+
//# sourceMappingURL=applyLaneLayout.js.map
|
|
@@ -0,0 +1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AAG,GAAG,QAAQ,CAAC;IACtD,CAAC;IAED,6EAA6E;IAC7E,IAAI,CAAC,QAAQ,GAAG,cAAc,CAAC;IAE/B,OAAO,IAAI,CAAC;AACd,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { TemplateId, TemplateMap, LaneTemplate, Duration } from '../../types/index.js';
|
|
2
|
+
/**
|
|
3
|
+
* Distributes segments with a fixed interval (gap) between them,
|
|
4
|
+
* starting from offset 0.
|
|
5
|
+
*
|
|
6
|
+
* @param laneId - ID of the lane
|
|
7
|
+
* @param interval - The gap duration between segments
|
|
8
|
+
* @param templates - Template map (mutated in place)
|
|
9
|
+
* @returns The updated LaneTemplate or null
|
|
10
|
+
*/
|
|
11
|
+
export declare function distributeSegmentOffsetsByInterval(laneId: TemplateId, interval: Duration, templates: TemplateMap): LaneTemplate | null;
|
|
12
|
+
//# sourceMappingURL=distributeSegmentOffsetsByInterval.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"distributeSegmentOffsetsByInterval.d.ts","sourceRoot":"","sources":["../../../src/templates/layout/distributeSegmentOffsetsByInterval.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAG5F;;;;;;;;GAQG;AACH,wBAAgB,kCAAkC,CAChD,MAAM,EAAE,UAAU,EAClB,QAAQ,EAAE,QAAQ,EAClB,SAAS,EAAE,WAAW,GACrB,YAAY,GAAG,IAAI,CAKrB"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { applyLaneLayout } from './applyLaneLayout.js';
|
|
2
|
+
/**
|
|
3
|
+
* Distributes segments with a fixed interval (gap) between them,
|
|
4
|
+
* starting from offset 0.
|
|
5
|
+
*
|
|
6
|
+
* @param laneId - ID of the lane
|
|
7
|
+
* @param interval - The gap duration between segments
|
|
8
|
+
* @param templates - Template map (mutated in place)
|
|
9
|
+
* @returns The updated LaneTemplate or null
|
|
10
|
+
*/
|
|
11
|
+
export function distributeSegmentOffsetsByInterval(laneId, interval, templates) {
|
|
12
|
+
return applyLaneLayout(laneId, templates, {
|
|
13
|
+
justifyContent: 'start',
|
|
14
|
+
gap: interval,
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=distributeSegmentOffsetsByInterval.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"distributeSegmentOffsetsByInterval.js","sourceRoot":"","sources":["../../../src/templates/layout/distributeSegmentOffsetsByInterval.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAEvD;;;;;;;;GAQG;AACH,MAAM,UAAU,kCAAkC,CAChD,MAAkB,EAClB,QAAkB,EAClB,SAAsB;IAEtB,OAAO,eAAe,CAAC,MAAM,EAAE,SAAS,EAAE;QACxC,cAAc,EAAE,OAAO;QACvB,GAAG,EAAE,QAAQ;KACd,CAAC,CAAC;AACL,CAAC"}
|