@media-quest/engine 0.0.1 → 0.0.3

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 (65) hide show
  1. package/dist/public-api.d.mts +543 -0
  2. package/dist/public-api.d.ts +543 -0
  3. package/dist/public-api.js +2187 -0
  4. package/dist/public-api.mjs +2150 -0
  5. package/package.json +10 -3
  6. package/src/Delement/AudioContainer.ts +169 -0
  7. package/src/Delement/DAuto-play.ts +36 -0
  8. package/src/Delement/DElement.ts +263 -0
  9. package/src/Delement/DImg.ts +78 -0
  10. package/src/Delement/DStyle-utils.ts +616 -0
  11. package/src/Delement/DStyle.ts +165 -0
  12. package/src/Delement/DText.ts +29 -0
  13. package/src/Delement/Ddiv.ts +38 -0
  14. package/src/Delement/VideoContainer.ts +199 -0
  15. package/src/Delement/css.spec.ts +36 -0
  16. package/src/Delement/css.ts +46 -0
  17. package/src/commands/DCommand.ts +62 -0
  18. package/src/commands/DCommandBus.ts +60 -0
  19. package/src/common/DMaybe.ts +46 -0
  20. package/src/common/DTimestamp.ts +20 -0
  21. package/src/common/DTmestamp.spec.ts +11 -0
  22. package/src/common/result.ts +41 -0
  23. package/src/dto/AnimationDto.ts +4 -0
  24. package/src/dto/DElement.dto.ts +50 -0
  25. package/src/dto/SchemaDto.ts +65 -0
  26. package/src/engine/DPage.ts +55 -0
  27. package/src/engine/SchemaEngine.ts +210 -0
  28. package/src/engine/element-factory.ts +52 -0
  29. package/src/engine/scale.spec.ts +38 -0
  30. package/src/engine/scale.ts +70 -0
  31. package/src/event-handlers/DEventHandler.ts +29 -0
  32. package/src/events/DEvents.ts +94 -0
  33. package/src/events/event-bus.spec.ts +21 -0
  34. package/src/events/event-bus.ts +81 -0
  35. package/src/kladd/context-menu-manager.ts +56 -0
  36. package/src/player/dplayer.spec.ts +108 -0
  37. package/src/player/dplayer.ts +70 -0
  38. package/src/player/history-que.spec.ts +45 -0
  39. package/src/player/history-que.ts +38 -0
  40. package/src/player/next-que.spec.ts +108 -0
  41. package/src/player/next-que.ts +93 -0
  42. package/src/public-api.ts +18 -5
  43. package/src/rules/__test__/complex-condition.spec.ts +15 -0
  44. package/src/rules/__test__/conditon.spec.ts +124 -0
  45. package/src/rules/__test__/numeric-condition.spec.ts +84 -0
  46. package/src/rules/__test__/rule-engine.spec.ts +354 -0
  47. package/src/rules/__test__/rule-evaluation.spec.ts +140 -0
  48. package/src/rules/__test__/string-condition.spec.ts +41 -0
  49. package/src/rules/condition.ts +191 -0
  50. package/src/rules/fact.ts +18 -0
  51. package/src/rules/rule-engine.ts +46 -0
  52. package/src/rules/rule.ts +40 -0
  53. package/src/services/DMedia-manager.spec.ts +27 -0
  54. package/src/services/DMedia-manager.ts +182 -0
  55. package/src/services/resource-provider.ts +33 -0
  56. package/src/services/sequence-manager.spec.ts +168 -0
  57. package/src/services/sequence-manager.ts +132 -0
  58. package/src/state/Dstate.spec.ts +7 -0
  59. package/src/state/Dstate.ts +105 -0
  60. package/src/state/boolean-property.ts +69 -0
  61. package/src/state/state-service.spec.ts +307 -0
  62. package/src/state/state-service.ts +251 -0
  63. package/src/state/state-testing-helpers.ts +59 -0
  64. package/src/utils/DUtil.ts +109 -0
  65. package/tsconfig.json +4 -3
@@ -0,0 +1,543 @@
1
+ declare namespace DCss {
2
+ interface Px {
3
+ readonly _unit: "px";
4
+ readonly value: number;
5
+ }
6
+ type LengthString = `${number}px` | `${number}%`;
7
+ interface Percent {
8
+ readonly _unit: "percent";
9
+ readonly value: number;
10
+ }
11
+ type LengthUnit = Px | Percent;
12
+ /**
13
+ * Will scale to 3% of baseScale
14
+ * @param unit
15
+ * @param scale
16
+ */
17
+ const toString: (unit: Readonly<LengthUnit>, scale: number) => LengthString;
18
+ const isLengthUnit: (unit?: LengthUnit) => unit is LengthUnit;
19
+ }
20
+
21
+ interface DStyle {
22
+ opacity: number;
23
+ backgroundColor: string;
24
+ visibility: "visible" | "hidden";
25
+ cursor: "pointer" | "help" | "copy" | "wait" | "not-allowed" | "context-menu" | "move" | "grabbing" | "grab" | "zoom-in" | "zoom-out" | "none" | "auto" | "default";
26
+ h: number;
27
+ w: number;
28
+ x: number;
29
+ y: number;
30
+ borderStyle: "solid" | "none" | "dotted" | "dashed";
31
+ borderRadius: DCss.Px | DCss.Percent;
32
+ borderWidth: DCss.Px;
33
+ borderColor: string;
34
+ margin: DCss.Px | DCss.Percent;
35
+ padding: DCss.Px | DCss.Percent;
36
+ transform: string;
37
+ translate: string;
38
+ fontSize: DCss.Px;
39
+ textColor: string;
40
+ fontWeight: 100 | 200 | 300 | 400 | 500 | 600 | 700 | 800 | 900;
41
+ textAlign: "right" | "left" | "center";
42
+ letterSpacing: DCss.Px;
43
+ }
44
+ declare namespace DStyle {
45
+ const normalize: <T extends HTMLElement>(el: T) => T;
46
+ const applyStyles: <T extends HTMLElement>(el: T, style: Partial<DStyle>, scale: number) => T;
47
+ }
48
+
49
+ interface AnimationDto {
50
+ readonly keyframes: Keyframe[];
51
+ readonly options: {
52
+ duration: number;
53
+ startIn?: number;
54
+ };
55
+ }
56
+
57
+ type Fact = Fact.Numeric | Fact.String;
58
+ declare namespace Fact {
59
+ interface Numeric {
60
+ readonly kind: "numeric-fact";
61
+ readonly value: number;
62
+ readonly label: string;
63
+ readonly referenceId: string;
64
+ readonly referenceLabel: string;
65
+ }
66
+ interface String {
67
+ readonly kind: "string-fact";
68
+ readonly label: string;
69
+ readonly value: string;
70
+ readonly referenceId: string;
71
+ readonly referenceLabel: string;
72
+ }
73
+ }
74
+
75
+ type Condition = Condition.String | Condition.Numeric | Condition.Complex;
76
+ declare namespace Condition {
77
+ type StringOperator = "eq" | "not-eq" | "longer-then" | "shorter-then";
78
+ type NumericOperator = "eq" | "not-eq" | "greater-then" | "less-then" | "greater-then-inclusive" | "less-then-inclusive";
79
+ interface Numeric {
80
+ readonly referenceId: string;
81
+ readonly referenceLabel: string;
82
+ readonly valueLabel: string;
83
+ readonly kind: "numeric-condition";
84
+ readonly operator: NumericOperator;
85
+ readonly value: number;
86
+ }
87
+ interface String {
88
+ readonly referenceId: string;
89
+ readonly referenceLabel: string;
90
+ readonly valueLabel: string;
91
+ readonly kind: "string-condition";
92
+ readonly operator: StringOperator;
93
+ readonly value: string;
94
+ }
95
+ interface Complex {
96
+ readonly kind: "complex-condition";
97
+ readonly name: string;
98
+ readonly all: ReadonlyArray<Condition.Simple>;
99
+ readonly some: ReadonlyArray<Condition.Simple>;
100
+ }
101
+ type Simple = Condition.String | Condition.Numeric;
102
+ /**
103
+ * An empty condition will evaluate to false,
104
+ * @param condition: Condition.Any
105
+ * @param facts
106
+ */
107
+ const evaluate: (condition: Condition, facts: ReadonlyArray<Fact>) => boolean;
108
+ const isEmpty: (complex: Complex) => boolean;
109
+ const getAllSimpleConditions: (condition: Condition | Array<Condition>) => ReadonlyArray<Condition.Simple>;
110
+ }
111
+
112
+ type DTimestamp = number & {
113
+ __timestamp__: true;
114
+ };
115
+ declare namespace DTimestamp {
116
+ const now: () => DTimestamp;
117
+ type Diff = number & {
118
+ __diff__: true;
119
+ };
120
+ const addMills: (t: DTimestamp, ms: number) => DTimestamp;
121
+ const diff: (t1: DTimestamp, t2: DTimestamp) => Diff;
122
+ const diffNow: (t: DTimestamp) => Diff;
123
+ }
124
+
125
+ interface AnsweredQuestion {
126
+ readonly timestamp: DTimestamp;
127
+ readonly fact: Fact;
128
+ }
129
+ declare namespace AnsweredQuestion {
130
+ const eq: (a: AnsweredQuestion, b: AnsweredQuestion) => boolean;
131
+ }
132
+
133
+ type EventProducer = "DVideo" | "DUser" | "DAudio" | "DImage" | "MediaManager" | "DPage" | "Window" | "HOST" | "RuleEngine" | "Engine" | "STATE-SERVICE";
134
+ interface Ev<K extends EventKind, P extends EventProducer, T> {
135
+ readonly kind: K;
136
+ readonly timestamp: DTimestamp;
137
+ readonly producer: P;
138
+ readonly producerId: string;
139
+ readonly data: T;
140
+ }
141
+ type EventKind = `${Uppercase<string>}_EVENT`;
142
+ type QueryChangedEvent = Ev<"STATE_QUERY_RESULT_CHANGED_EVENT", "STATE-SERVICE", DState.StateQueryResult>;
143
+ type AudioPlayEvent = Ev<"AUDIO_PLAY_EVENT", "DAudio", {}>;
144
+ type DAudioEvent = AudioPlayEvent | Ev<"AUDIO_PAUSED_EVENT", "DAudio", {}> | Ev<"AUDIO_ENDED_EVENT", "DAudio", {
145
+ url: string;
146
+ }> | Ev<"AUDIO_ERROR_EVENT", "DAudio", {
147
+ error: unknown;
148
+ }> | Ev<"AUDIO_METADATA_LOADED_EVENT", "DAudio", {}> | Ev<"AUDIO_LOAD_EVENT", "DAudio", {}> | Ev<"AUDIO_CAN_PLAY_THROUGH_EVENT", "DAudio", {}> | Ev<"AUDIO_DURATION_CHANGE_EVENT", "DAudio", {
149
+ duration: number;
150
+ isInfinity: boolean;
151
+ }> | Ev<"AUDIO_PROGRESS_EVENT", "DAudio", {}>;
152
+ type DVideoEvent = Ev<"VIDEO_PLAY_EVENT", "DVideo", {}> | Ev<"VIDEO_PAUSED_EVENT", "DVideo", {}> | Ev<"VIDEO_ERROR_EVENT", "DVideo", {
153
+ error: unknown;
154
+ }> | Ev<"VIDEO_EVENT", "DVideo", {
155
+ error: unknown;
156
+ }> | Ev<"VIDEO_LOADED_METADATA_EVENT", "DVideo", {
157
+ duration: number;
158
+ isInfinity: boolean;
159
+ }> | Ev<"VIDEO_DURATION_CHANGE_EVENT", "DVideo", {
160
+ duration: number;
161
+ isInfinity: boolean;
162
+ }> | Ev<"VIDEO_PROGRESS_EVENT", "DVideo", {
163
+ duration: number;
164
+ progress: number;
165
+ }> | Ev<"VIDEO_ENDED_EVENT", "DVideo", {}>;
166
+ type DImageEvent = Ev<"IMAGE_LOADED_EVENT", "DImage", {
167
+ naturalHeight: number;
168
+ naturalWidth: number;
169
+ loadTime: DTimestamp.Diff;
170
+ height: number;
171
+ width: number;
172
+ }> | Ev<"IMAGE_ERROR_EVENT", "DImage", {
173
+ error: unknown;
174
+ }>;
175
+ type DPageEvents = Ev<"PAGE_ENTER_EVENT", "DPage", {
176
+ pageId: string;
177
+ }> | Ev<"PAGE_COMPLETED_EVENT", "DPage", {
178
+ pageId: string;
179
+ answers: AnsweredQuestion[];
180
+ }>;
181
+ type DWindowEvents = Ev<"WINDOW_VISIBILITY_CHANGE_EVENT", "Window", {}> | Ev<"WINDOW_ONLINE_STATUS_CHANGE_EVENT", "Window", {}>;
182
+ type DEvent = DImageEvent | DAudioEvent | DVideoEvent | DPageEvents | DWindowEvents | QueryChangedEvent | Ev<"USER_CLICKED_EVENT", "DUser", {
183
+ elementId: string;
184
+ }> | Ev<"RULE_MATCH_EVENT", "Window", {
185
+ ruleId: string;
186
+ }> | Ev<"ENGINE_SCHEMA_LOADED_EVENT", "Engine", {
187
+ pageCount: number;
188
+ hostHeight: number;
189
+ hostWidth: number;
190
+ scale: number;
191
+ }> | Ev<"HOST_SCALE_CHANGED_EVENT", "HOST", {
192
+ scale: number;
193
+ }>;
194
+
195
+ declare namespace DState {
196
+ interface PropDefinition<TypeName, Type extends string | number> {
197
+ readonly _type: TypeName;
198
+ readonly propName: string;
199
+ readonly propDescription: string;
200
+ readonly initialValue?: Type;
201
+ readonly options?: ReadonlyArray<PropValue<Type>>;
202
+ }
203
+ export type NumericProp = PropDefinition<"number", number>;
204
+ export type StringProp = PropDefinition<"string", string>;
205
+ export interface fromEventHandler {
206
+ readonly onEvent: DEvent["kind"];
207
+ readonly thenExecute: ReadonlyArray<StateCommand>;
208
+ }
209
+ export interface PropValue<T> {
210
+ readonly value: T;
211
+ readonly valueLabel: string;
212
+ }
213
+ export type Prop = NumericProp | StringProp;
214
+ export interface SetStringMutation {
215
+ readonly kind: "set-string";
216
+ readonly propName: string;
217
+ readonly value: string;
218
+ }
219
+ export interface IncrementNumberMutation {
220
+ readonly kind: "increment-number";
221
+ readonly propName: string;
222
+ readonly stepSize: number;
223
+ readonly ifNotExistThenSetTo: number;
224
+ }
225
+ export interface DecrementNumberMutation {
226
+ readonly kind: "decrement-number";
227
+ readonly propName: string;
228
+ readonly stepSize: number;
229
+ readonly ifNotExistThenSetTo: number;
230
+ }
231
+ export interface SetNumberMutation {
232
+ readonly kind: "set-number";
233
+ readonly propName: string;
234
+ readonly value: number;
235
+ }
236
+ export type NumberMutations = IncrementNumberMutation | DecrementNumberMutation | SetNumberMutation;
237
+ export type StateMutation = SetStringMutation | NumberMutations;
238
+ export const isNumberMutation: (mutations: StateMutation) => mutations is NumberMutations;
239
+ export const isStringMutation: (mutation: StateMutation) => mutation is SetStringMutation;
240
+ export interface StateQuery {
241
+ readonly name: string;
242
+ readonly condition: Condition;
243
+ }
244
+ export interface StateQueryResult {
245
+ readonly queryName: string;
246
+ readonly prev: boolean;
247
+ readonly curr: boolean;
248
+ }
249
+ export const numericPropToFact: (prop: NumericProp, value: number) => Fact.Numeric;
250
+ export const stringPropToFact: (prop: StringProp, value: string) => Fact.String;
251
+ export {};
252
+ }
253
+
254
+ type CommandTarget = "VIDEO" | "AUDIO" | "ELEMENT" | "PAGE_QUE" | "ENGINE" | "STATE";
255
+ type CommandKind = `${Uppercase<CommandTarget>}_${Uppercase<string>}_COMMAND`;
256
+ type StateCommand = CommandDto<"STATE_MUTATE_COMMAND", "STATE", {
257
+ mutation: DState.StateMutation;
258
+ }>;
259
+ type NavigationCommand = CommandDto<"PAGE_QUE_NEXT_PAGE_COMMAND", "PAGE_QUE", {}> | CommandDto<"PAGE_QUE_GO_TO_SEQUENCE_COMMAND", "PAGE_QUE", {
260
+ sequenceId: string;
261
+ }> | CommandDto<"PAGE_QUE_GO_TO_PAGE_COMMAND", "PAGE_QUE", {
262
+ pageId: string;
263
+ }>;
264
+ type EngineCommand = CommandDto<"ENGINE_LEAVE_PAGE_COMMAND", "ENGINE", {
265
+ readonly pageId: string;
266
+ readonly factsCollected: ReadonlyArray<Fact>;
267
+ }>;
268
+ interface CommandDto<K extends CommandKind, T extends CommandTarget, P> {
269
+ readonly kind: K;
270
+ readonly target: T;
271
+ readonly targetId: T | Omit<string, T>;
272
+ readonly payload: P;
273
+ }
274
+ type VideoCommand = CommandDto<"VIDEO_PLAY_COMMAND", "VIDEO", {
275
+ volume?: number;
276
+ }> | CommandDto<"VIDEO_SET_VOLUME_COMMAND", "VIDEO", {
277
+ volume: number;
278
+ }> | CommandDto<"VIDEO_JUMP_TO_COMMAND", "VIDEO", {
279
+ volume?: number;
280
+ ms: number;
281
+ }> | CommandDto<"VIDEO_PAUSE_COMMAND", "VIDEO", {}>;
282
+ type AudioCommand = CommandDto<"AUDIO_PAUSE_COMMAND", "AUDIO", {}> | CommandDto<"AUDIO_PLAY_COMMAND", "AUDIO", {
283
+ volume?: number;
284
+ startAt?: number;
285
+ }> | CommandDto<"AUDIO_SET_VOLUME_COMMAND", "AUDIO", {
286
+ volume: number;
287
+ }>;
288
+ type ElementCommand = CommandDto<"ELEMENT_ANIMATE_COMMAND", "ELEMENT", AnimationDto> | CommandDto<"ELEMENT_DISABLE_CLICK_COMMAND", "ELEMENT", {}> | CommandDto<"ELEMENT_ENABLE_CLICK_COMMAND", "ELEMENT", {}> | CommandDto<"ELEMENT_STYLE_COMMAND", "ELEMENT", {
289
+ changes: Partial<DStyle>;
290
+ clickIsAllowed?: boolean;
291
+ }>;
292
+ type PageQueCommand = CommandDto<"PAGE_QUE_EXCLUDE_BY_TAG_COMMAND", "PAGE_QUE", {
293
+ tagIds: string[];
294
+ }> | CommandDto<"PAGE_QUE_EXCLUDE_BY_PAGE_ID_COMMAND", "PAGE_QUE", {
295
+ pageIds: Array<string>;
296
+ }> | CommandDto<"PAGE_QUE_JUMP_TO_PAGE_COMMAND", "PAGE_QUE", {
297
+ readonly pageId: string;
298
+ }>;
299
+ type DCommand = StateCommand | NavigationCommand | VideoCommand | AudioCommand | ElementCommand | EngineCommand | PageQueCommand;
300
+
301
+ /**
302
+ * Autoplay video by Id.
303
+ */
304
+ interface AutoPlayVideo {
305
+ readonly kind: "autoplay-video";
306
+ readonly muted?: boolean;
307
+ readonly startAt?: number;
308
+ readonly videoId: string;
309
+ }
310
+ /**
311
+ * Add a pause between auto-play elements.
312
+ * TODO Not implemented
313
+ */
314
+ interface AutoPlayPause {
315
+ readonly kind: "autoplay-pause";
316
+ readonly duration: number;
317
+ }
318
+ interface AutoPlayAudio {
319
+ readonly kind: "autoplay-audio";
320
+ readonly audioId: string;
321
+ readonly startAt?: number;
322
+ }
323
+ type AutoPlayElement = AutoPlayVideo | AutoPlayAudio | AutoPlayPause;
324
+ interface DAutoPlaySequence {
325
+ readonly id: string;
326
+ readonly blockUserInput: boolean;
327
+ readonly items: Array<AutoPlayAudio | AutoPlayVideo | AutoPlayPause>;
328
+ readonly startCommands: ReadonlyArray<DCommand>;
329
+ readonly endCommands: ReadonlyArray<DCommand>;
330
+ }
331
+
332
+ interface QueryChangedHandler {
333
+ readonly queryName: string;
334
+ readonly whenTrue: ReadonlyArray<ElementCommand>;
335
+ readonly whenFalse: ReadonlyArray<ElementCommand>;
336
+ }
337
+ interface DEventHandler<E extends DEvent = DEvent> {
338
+ readonly onEvent: E["kind"];
339
+ readonly when?: {
340
+ producerId?: string;
341
+ condition?: Condition;
342
+ };
343
+ readonly thenExecute: ReadonlyArray<DCommand>;
344
+ }
345
+ declare namespace DEventHandler {
346
+ type LookUp = Map<DEventHandler["onEvent"], Array<DEventHandler>>;
347
+ const createLookUp: (handlers?: ReadonlyArray<DEventHandler>) => LookUp;
348
+ }
349
+
350
+ type DElementDto = DTextDto | DImgDto | DDivDto;
351
+ interface DStateListener {
352
+ readonly onStateChange?: ReadonlyArray<QueryChangedHandler>;
353
+ }
354
+ interface DElementBaseDto extends DStateListener {
355
+ readonly id: string;
356
+ readonly style: Partial<DStyle>;
357
+ readonly eventHandlers?: ReadonlyArray<DEventHandler>;
358
+ readonly onClick?: ReadonlyArray<DCommand>;
359
+ }
360
+ interface DTextDto extends DElementBaseDto {
361
+ readonly _tag: "p";
362
+ readonly text: string;
363
+ }
364
+ interface DDivDto extends DElementBaseDto {
365
+ readonly _tag: "div";
366
+ readonly children: Array<DTextDto | DImgDto>;
367
+ }
368
+ interface DImgDto extends DElementBaseDto {
369
+ readonly _tag: "img";
370
+ readonly url: string;
371
+ }
372
+ interface DVideoDto extends DElementBaseDto {
373
+ readonly _tag: "video";
374
+ readonly url: string;
375
+ }
376
+ interface DAudioDto {
377
+ readonly id: string;
378
+ readonly _tag: "audio";
379
+ readonly url: string;
380
+ }
381
+
382
+ interface Rule<OnSuccessAction, OnFailureAction> {
383
+ readonly id: string;
384
+ readonly description: string;
385
+ readonly all: ReadonlyArray<Condition>;
386
+ readonly some: ReadonlyArray<Condition>;
387
+ readonly onSuccess: ReadonlyArray<OnSuccessAction>;
388
+ readonly onFailure: ReadonlyArray<OnFailureAction>;
389
+ }
390
+ declare namespace Rule {
391
+ /**
392
+ * Validates that the rule is valid.
393
+ * @param rule
394
+ */
395
+ const isEmpty: (rule: Rule<any, any>) => boolean;
396
+ const solve: (rule: Rule<any, any>, facts: ReadonlyArray<Fact>) => boolean;
397
+ }
398
+
399
+ type PageQueRules = Rule<PageQueCommand, never>;
400
+ interface PageDto {
401
+ readonly id: string;
402
+ readonly elements: Array<DElementDto>;
403
+ readonly tags?: string[];
404
+ readonly mainVideoId?: string;
405
+ readonly backgroundColor?: string;
406
+ readonly video?: Array<DVideoDto>;
407
+ readonly audio?: Array<DAudioDto>;
408
+ readonly autoPlaySequence?: DAutoPlaySequence;
409
+ }
410
+ interface PageSequenceDto {
411
+ readonly id: string;
412
+ readonly rules: Array<PageQueRules>;
413
+ readonly pages: Array<PageDto>;
414
+ }
415
+ interface SchemaDto {
416
+ readonly id: string;
417
+ readonly prefix: string;
418
+ readonly baseHeight: number;
419
+ readonly baseWidth: number;
420
+ readonly backgroundColor: string;
421
+ readonly pages: PageDto[];
422
+ readonly rules: Array<PageQueRules>;
423
+ readonly stateProps?: ReadonlyArray<DState.Prop>;
424
+ readonly stateQueries?: ReadonlyArray<DState.StateQuery>;
425
+ readonly stateFromEvent: ReadonlyArray<DState.fromEventHandler>;
426
+ readonly pageSequences?: Array<PageSequenceDto>;
427
+ readonly predefinedFacts?: ReadonlyArray<Fact>;
428
+ }
429
+ declare namespace SchemaDto {
430
+ const getResources: (schema: SchemaDto) => {
431
+ videoList: ReadonlyArray<DVideoDto>;
432
+ audioList: ReadonlyArray<DAudioDto>;
433
+ imageList: ReadonlyArray<DImgDto>;
434
+ };
435
+ }
436
+
437
+ interface SchemaResult {
438
+ readonly eventLog: ReadonlyArray<DEvent>;
439
+ readonly commandLog: ReadonlyArray<DCommand>;
440
+ readonly answers: ReadonlyArray<any>;
441
+ }
442
+ interface ISchemaEngine {
443
+ onComplete(handler: (result: SchemaResult) => void): void;
444
+ onCommandOrEvent(item: DEvent | DCommand): void;
445
+ setSchema(schema: SchemaDto): void;
446
+ onFatalError(handler: (error: {
447
+ message: string;
448
+ }) => void): void;
449
+ }
450
+ declare class SchemaEngine implements ISchemaEngine {
451
+ private readonly height;
452
+ private readonly width;
453
+ private readonly schema;
454
+ private readonly TAG;
455
+ private readonly commandBus;
456
+ private readonly eventBus;
457
+ private readonly mediaManager;
458
+ private readonly scale;
459
+ private readonly hostElement;
460
+ private readonly uiContainer;
461
+ private readonly mediaContainer;
462
+ private readonly resourceProvider;
463
+ private readonly stateService;
464
+ private readonly globalEventToStateHandlers;
465
+ private player;
466
+ private currentPage;
467
+ private readonly subs;
468
+ constructor(hostEl: HTMLDivElement, height: number, width: number, schema: SchemaDto);
469
+ private hookUpListeners;
470
+ private styleSelf;
471
+ private nextPage;
472
+ destroy(): void;
473
+ onComplete(handler: (result: SchemaResult) => void): void;
474
+ onFatalError(handler: (error: {
475
+ message: string;
476
+ }) => void): void;
477
+ onCommandOrEvent(_event_or_command: DEvent | DCommand): void;
478
+ setSchema(schema: SchemaDto): void;
479
+ }
480
+
481
+ interface SolveResult<S, F> {
482
+ matching: ReadonlyArray<Match<S, F>>;
483
+ errors: ReadonlyArray<RuleEngineError>;
484
+ }
485
+ interface Match<S, F> {
486
+ readonly matchingRuleId: string;
487
+ readonly ruleDescription: string;
488
+ readonly actionList: ReadonlyArray<S> | ReadonlyArray<F>;
489
+ }
490
+ interface RuleEngineError {
491
+ readonly kind?: string;
492
+ readonly message: string;
493
+ }
494
+ declare class RuleEngine<S, F> {
495
+ constructor();
496
+ solveAll(rules: Rule<S, F>[], facts: Fact[]): SolveResult<S, F>;
497
+ solve(rule: Rule<S, F>, facts: Fact[]): boolean;
498
+ }
499
+
500
+ declare class BooleanStateProperty<PropName extends string> {
501
+ private readonly initialValue;
502
+ readonly propName: PropName;
503
+ private static readonly TRUE;
504
+ private static readonly FALSE;
505
+ readonly propDefinition: DState.NumericProp;
506
+ getIsTrueCondition(): Condition.Numeric;
507
+ getIsFalseCondition(): Condition.Numeric;
508
+ getSetTrueCommand(): StateCommand;
509
+ getSetFalseCommand(): StateCommand;
510
+ constructor(propName: PropName, initialValue: boolean, description: string);
511
+ }
512
+
513
+ type RandomObjectId = string & {
514
+ randomObjectId: true;
515
+ };
516
+ declare namespace DUtil {
517
+ const randomString: (length: number) => string;
518
+ const randomObjectId: () => RandomObjectId;
519
+ const deleteProp: <Obj, Key extends keyof Obj>(obj: Obj, key: Key) => Omit<Obj, Key>;
520
+ const isInRange: (min: number, max: number) => (value: number) => boolean;
521
+ const isInfinity: (number: number) => boolean;
522
+ type NonEmptyArray<T> = [T, ...T[]];
523
+ const isNonEmptyArray: <T>(array: T[]) => array is NonEmptyArray<T>;
524
+ const neverCheck: (args: never) => void;
525
+ const isString: (str: unknown) => str is string;
526
+ const hasKey: <T extends string>(obj: unknown, key: T) => obj is Record<T, unknown>;
527
+ const isRecord: (obj: unknown) => obj is Record<string, unknown>;
528
+ const isBool: (obj: boolean) => obj is boolean;
529
+ const isTrue: (bool: boolean) => bool is true;
530
+ const isFalse: (bool: boolean) => bool is false;
531
+ const isDefined: (obj: unknown) => boolean;
532
+ const hasKind: (obj: unknown) => obj is {
533
+ readonly kind: string;
534
+ };
535
+ const hasValue: (obj: unknown) => obj is {
536
+ value: unknown;
537
+ };
538
+ const isNumber: (value?: number) => value is number;
539
+ const maxFn: (upperLimit: number) => (value: number) => number;
540
+ const minFn: (lowerLimit: number) => (value: number) => number;
541
+ }
542
+
543
+ export { AnimationDto, AudioCommand, AudioPlayEvent, AutoPlayAudio, AutoPlayElement, AutoPlayPause, AutoPlayVideo, BooleanStateProperty, Condition, DAudioDto, DAudioEvent, DAutoPlaySequence, DCommand, DCss, DDivDto, DElementBaseDto, DElementDto, DEvent, DEventHandler, DImageEvent, DImgDto, DPageEvents, DState, DStyle, DTextDto, DUtil, DVideoDto, DVideoEvent, DWindowEvents, ElementCommand, EngineCommand, Fact, Match, NavigationCommand, PageDto, PageQueCommand, PageQueRules, PageSequenceDto, QueryChangedEvent, QueryChangedHandler, RandomObjectId, Rule, RuleEngine, RuleEngineError, SchemaDto, SchemaEngine, SolveResult, StateCommand, VideoCommand };