@media-quest/engine 0.0.38 → 0.0.40
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/public-api.d.ts +3 -21
- package/dist/public-api.js +14 -28
- package/dist/public-api.js.map +1 -1
- package/package.json +26 -26
- package/src/Delement/DButton.ts +25 -25
- package/src/Delement/DElement.dto.ts +6 -6
- package/src/Delement/DElement.ts +190 -190
- package/src/Delement/DImg.ts +48 -48
- package/src/Delement/DStyle.ts +376 -391
- package/src/Delement/DText.ts +23 -23
- package/src/Delement/Ddiv.ts +44 -44
- package/src/Delement/button-click-action.ts +42 -42
- package/src/Delement/css.spec.ts +40 -40
- package/src/Delement/css.ts +56 -56
- package/src/Delement/element-factory.ts +49 -49
- package/src/engine/SchemaEngine.ts +155 -160
- package/src/engine/SchemaResult.ts +10 -12
- package/src/engine/dplayer.spec.ts +91 -92
- package/src/engine/dplayer.ts +104 -106
- package/src/engine/history-que.spec.ts +67 -69
- package/src/engine/history-que.ts +17 -21
- package/src/engine/next-que.spec.ts +121 -122
- package/src/engine/next-que.ts +101 -101
- package/src/events/mq-events.ts +63 -76
- package/src/page/Page.ts +190 -181
- package/src/page/page-result.ts +11 -12
- package/src/page/task-manager.ts +263 -263
- package/src/page/task-state.ts +65 -65
- package/src/public-api.ts +25 -26
- package/tsconfig.json +19 -19
package/src/Delement/DText.ts
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
import { DElement, DElementBaseDto } from "./DElement";
|
|
2
|
-
import { ScaleService } from "../engine/scale";
|
|
3
|
-
import { ButtonClickAction } from "./button-click-action";
|
|
4
|
-
|
|
5
|
-
export interface DTextDto extends DElementBaseDto {
|
|
6
|
-
readonly _tag: "p";
|
|
7
|
-
readonly innerText: string;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export class DText extends DElement<HTMLParagraphElement> {
|
|
11
|
-
constructor(dto: DTextDto, scale: ScaleService) {
|
|
12
|
-
super(document.createElement("p"), dto, scale);
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
registerClickHandler(clickHandler: (action: ButtonClickAction) => void) {
|
|
16
|
-
this.el.onclick = () => {
|
|
17
|
-
const onClick = this.dto.onClick;
|
|
18
|
-
if (onClick) {
|
|
19
|
-
clickHandler(onClick);
|
|
20
|
-
}
|
|
21
|
-
};
|
|
22
|
-
}
|
|
23
|
-
}
|
|
1
|
+
import { DElement, DElementBaseDto } from "./DElement";
|
|
2
|
+
import { ScaleService } from "../engine/scale";
|
|
3
|
+
import { ButtonClickAction } from "./button-click-action";
|
|
4
|
+
|
|
5
|
+
export interface DTextDto extends DElementBaseDto {
|
|
6
|
+
readonly _tag: "p";
|
|
7
|
+
readonly innerText: string;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export class DText extends DElement<HTMLParagraphElement> {
|
|
11
|
+
constructor(dto: DTextDto, scale: ScaleService) {
|
|
12
|
+
super(document.createElement("p"), dto, scale);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
registerClickHandler(clickHandler: (action: ButtonClickAction) => void) {
|
|
16
|
+
this.el.onclick = () => {
|
|
17
|
+
const onClick = this.dto.onClick;
|
|
18
|
+
if (onClick) {
|
|
19
|
+
clickHandler(onClick);
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
}
|
package/src/Delement/Ddiv.ts
CHANGED
|
@@ -1,44 +1,44 @@
|
|
|
1
|
-
import { DElement, DElementBaseDto } from "./DElement";
|
|
2
|
-
import { DText, DTextDto } from "./DText";
|
|
3
|
-
import { DImg, DImgDto } from "./DImg";
|
|
4
|
-
import { ScaleService } from "../engine/scale";
|
|
5
|
-
import { DButton, DButtonDto } from "./DButton";
|
|
6
|
-
import { ButtonClickAction } from "./button-click-action";
|
|
7
|
-
|
|
8
|
-
export interface DDivDto extends DElementBaseDto {
|
|
9
|
-
readonly _tag: "div";
|
|
10
|
-
readonly children: Array<DTextDto | DImgDto | DButtonDto>;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export class DDiv extends DElement<HTMLDivElement> {
|
|
14
|
-
private readonly TAG = "[ DDiv ]: ";
|
|
15
|
-
protected readonly defaultStyle = { x: 22, y: 4 };
|
|
16
|
-
private children: Array<DText | DImg | DButton> = [];
|
|
17
|
-
|
|
18
|
-
registerClickHandler(clickHandler: (action: ButtonClickAction) => void) {
|
|
19
|
-
this.el.onclick = () => {
|
|
20
|
-
const action = this.dto.onClick;
|
|
21
|
-
if (action) {
|
|
22
|
-
clickHandler(action);
|
|
23
|
-
}
|
|
24
|
-
};
|
|
25
|
-
this.children.forEach((child) => {
|
|
26
|
-
child.registerClickHandler(clickHandler);
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
constructor(dto: DDivDto, scale: ScaleService, children: Array<DText | DImg | DButton>) {
|
|
31
|
-
const d = document.createElement("div");
|
|
32
|
-
super(d, dto, scale);
|
|
33
|
-
this.children = children;
|
|
34
|
-
|
|
35
|
-
this.children.forEach((child) => {
|
|
36
|
-
child.appendYourself(this.el);
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
protected whenConstructed() {
|
|
40
|
-
this.children.forEach((child) => {
|
|
41
|
-
console.log(child);
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
}
|
|
1
|
+
import { DElement, DElementBaseDto } from "./DElement";
|
|
2
|
+
import { DText, DTextDto } from "./DText";
|
|
3
|
+
import { DImg, DImgDto } from "./DImg";
|
|
4
|
+
import { ScaleService } from "../engine/scale";
|
|
5
|
+
import { DButton, DButtonDto } from "./DButton";
|
|
6
|
+
import { ButtonClickAction } from "./button-click-action";
|
|
7
|
+
|
|
8
|
+
export interface DDivDto extends DElementBaseDto {
|
|
9
|
+
readonly _tag: "div";
|
|
10
|
+
readonly children: Array<DTextDto | DImgDto | DButtonDto>;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export class DDiv extends DElement<HTMLDivElement> {
|
|
14
|
+
private readonly TAG = "[ DDiv ]: ";
|
|
15
|
+
protected readonly defaultStyle = { x: 22, y: 4 };
|
|
16
|
+
private children: Array<DText | DImg | DButton> = [];
|
|
17
|
+
|
|
18
|
+
registerClickHandler(clickHandler: (action: ButtonClickAction) => void) {
|
|
19
|
+
this.el.onclick = () => {
|
|
20
|
+
const action = this.dto.onClick;
|
|
21
|
+
if (action) {
|
|
22
|
+
clickHandler(action);
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
this.children.forEach((child) => {
|
|
26
|
+
child.registerClickHandler(clickHandler);
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
constructor(dto: DDivDto, scale: ScaleService, children: Array<DText | DImg | DButton>) {
|
|
31
|
+
const d = document.createElement("div");
|
|
32
|
+
super(d, dto, scale);
|
|
33
|
+
this.children = children;
|
|
34
|
+
|
|
35
|
+
this.children.forEach((child) => {
|
|
36
|
+
child.appendYourself(this.el);
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
protected whenConstructed() {
|
|
40
|
+
this.children.forEach((child) => {
|
|
41
|
+
console.log(child);
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -1,42 +1,42 @@
|
|
|
1
|
-
import { PlayAudioTask, PlayVideoTask } from "../page/task";
|
|
2
|
-
import { Fact } from "../rules/fact";
|
|
3
|
-
|
|
4
|
-
export type ButtonClickAction =
|
|
5
|
-
| { kind: "play-audio"; task: PlayAudioTask; vibrateMs?: number }
|
|
6
|
-
| { kind: "pause-audio"; vibrateMs?: number }
|
|
7
|
-
| { kind: "play-video"; task: PlayVideoTask; vibrateMs?: number }
|
|
8
|
-
| { kind: "mute-video"; vibrateMs?: number }
|
|
9
|
-
| { kind: "un-mute-video"; vibrateMs?: number }
|
|
10
|
-
| { kind: "pause-video"; vibrateMs?: number }
|
|
11
|
-
| { kind: "submit-fact"; fact: Fact; vibrateMs?: number }
|
|
12
|
-
| { kind: "next-page"; vibrateMs?: number }
|
|
13
|
-
| { kind: "submit-form"; vibrateMs?: number };
|
|
14
|
-
|
|
15
|
-
// export type ButtonClickAction = _ButtonClickAction & ;
|
|
16
|
-
export const ButtonClickAction = {
|
|
17
|
-
describe: (a: ButtonClickAction): string => {
|
|
18
|
-
switch (a.kind) {
|
|
19
|
-
case "next-page":
|
|
20
|
-
return "go to next page";
|
|
21
|
-
case "play-video":
|
|
22
|
-
return "VideoId = " + a.task.videoId;
|
|
23
|
-
case "play-audio":
|
|
24
|
-
return "AudioId = " + a.task.audioId;
|
|
25
|
-
case "pause-video":
|
|
26
|
-
return "";
|
|
27
|
-
case "pause-audio":
|
|
28
|
-
return "";
|
|
29
|
-
case "submit-fact":
|
|
30
|
-
return a.fact.label + " = " + a.fact.value;
|
|
31
|
-
case "submit-form":
|
|
32
|
-
return "";
|
|
33
|
-
case "mute-video":
|
|
34
|
-
return "mute-video";
|
|
35
|
-
case "un-mute-video":
|
|
36
|
-
return "un-mute-video";
|
|
37
|
-
default:
|
|
38
|
-
const _exhaustiveCheck: never = a;
|
|
39
|
-
return "";
|
|
40
|
-
}
|
|
41
|
-
},
|
|
42
|
-
};
|
|
1
|
+
import { PlayAudioTask, PlayVideoTask } from "../page/task";
|
|
2
|
+
import { Fact } from "../rules/fact";
|
|
3
|
+
|
|
4
|
+
export type ButtonClickAction =
|
|
5
|
+
| { kind: "play-audio"; task: PlayAudioTask; vibrateMs?: number }
|
|
6
|
+
| { kind: "pause-audio"; vibrateMs?: number }
|
|
7
|
+
| { kind: "play-video"; task: PlayVideoTask; vibrateMs?: number }
|
|
8
|
+
| { kind: "mute-video"; vibrateMs?: number }
|
|
9
|
+
| { kind: "un-mute-video"; vibrateMs?: number }
|
|
10
|
+
| { kind: "pause-video"; vibrateMs?: number }
|
|
11
|
+
| { kind: "submit-fact"; fact: Fact; vibrateMs?: number }
|
|
12
|
+
| { kind: "next-page"; vibrateMs?: number }
|
|
13
|
+
| { kind: "submit-form"; vibrateMs?: number };
|
|
14
|
+
|
|
15
|
+
// export type ButtonClickAction = _ButtonClickAction & ;
|
|
16
|
+
export const ButtonClickAction = {
|
|
17
|
+
describe: (a: ButtonClickAction): string => {
|
|
18
|
+
switch (a.kind) {
|
|
19
|
+
case "next-page":
|
|
20
|
+
return "go to next page";
|
|
21
|
+
case "play-video":
|
|
22
|
+
return "VideoId = " + a.task.videoId;
|
|
23
|
+
case "play-audio":
|
|
24
|
+
return "AudioId = " + a.task.audioId;
|
|
25
|
+
case "pause-video":
|
|
26
|
+
return "";
|
|
27
|
+
case "pause-audio":
|
|
28
|
+
return "";
|
|
29
|
+
case "submit-fact":
|
|
30
|
+
return a.fact.label + " = " + a.fact.value;
|
|
31
|
+
case "submit-form":
|
|
32
|
+
return "";
|
|
33
|
+
case "mute-video":
|
|
34
|
+
return "mute-video";
|
|
35
|
+
case "un-mute-video":
|
|
36
|
+
return "un-mute-video";
|
|
37
|
+
default:
|
|
38
|
+
const _exhaustiveCheck: never = a;
|
|
39
|
+
return "";
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
};
|
package/src/Delement/css.spec.ts
CHANGED
|
@@ -1,40 +1,40 @@
|
|
|
1
|
-
import { DCss } from "./css";
|
|
2
|
-
import LengthUnit = DCss.LengthUnit;
|
|
3
|
-
import { DStyle } from "./DStyle";
|
|
4
|
-
describe("Css utils testing", () => {
|
|
5
|
-
test("Clamp and round of px-units", () => {
|
|
6
|
-
const px1300: DCss.Px = { _unit: "px", value: 1300 };
|
|
7
|
-
const px555: DCss.Px = { _unit: "px", value: 555 };
|
|
8
|
-
const px123: DCss.Px = { _unit: "px", value: 123 };
|
|
9
|
-
const px10: DCss.Px = { _unit: "px", value: 10 };
|
|
10
|
-
const px3: DCss.Px = { _unit: "px", value: 3 };
|
|
11
|
-
const px0: DCss.Px = { _unit: "px", value: 0 };
|
|
12
|
-
const px1: DCss.Px = { _unit: "px", value: 1 };
|
|
13
|
-
const scale026 = DCss.toString;
|
|
14
|
-
// const scale001 = DCss.toStringCreator(0.01);
|
|
15
|
-
|
|
16
|
-
expect(DCss.toString(px1300, 0.26)).toBe("338px");
|
|
17
|
-
expect(DCss.toString(px10, 0.26)).toBe("3px");
|
|
18
|
-
expect(DCss.toString(px1, 0.26)).toBe("1px");
|
|
19
|
-
expect(DCss.toString(px3, 0.26)).toBe("1px");
|
|
20
|
-
expect(DCss.toString(px0, 0.26)).toBe("0px");
|
|
21
|
-
expect(DCss.toString(px0, 0.26)).toBe("0px");
|
|
22
|
-
expect(DCss.toString(px555, 0.26)).toBe("144px");
|
|
23
|
-
expect(DCss.toString(px123, 0.01)).toBe("4px");
|
|
24
|
-
expect(DCss.toString(px1300, 0.01)).toBe("39px");
|
|
25
|
-
expect(DCss.isLengthUnit()).toBe(false);
|
|
26
|
-
expect(DCss.isLengthUnit({} as LengthUnit)).toBe(false);
|
|
27
|
-
expect(DCss.isLengthUnit(px123)).toBe(true);
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
test("Normalize div: ", () => {
|
|
31
|
-
const div = document.createElement("div");
|
|
32
|
-
const normalized = DStyle.normalize(div);
|
|
33
|
-
expect(normalized.style.padding).toBe("0px");
|
|
34
|
-
expect(normalized.style.boxSizing).toBe("border-box");
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
test("Can validate Length-units ", () => {
|
|
38
|
-
expect(DCss.isLengthUnit(0)).toBe(true);
|
|
39
|
-
});
|
|
40
|
-
});
|
|
1
|
+
import { DCss } from "./css";
|
|
2
|
+
import LengthUnit = DCss.LengthUnit;
|
|
3
|
+
import { DStyle } from "./DStyle";
|
|
4
|
+
describe("Css utils testing", () => {
|
|
5
|
+
test("Clamp and round of px-units", () => {
|
|
6
|
+
const px1300: DCss.Px = { _unit: "px", value: 1300 };
|
|
7
|
+
const px555: DCss.Px = { _unit: "px", value: 555 };
|
|
8
|
+
const px123: DCss.Px = { _unit: "px", value: 123 };
|
|
9
|
+
const px10: DCss.Px = { _unit: "px", value: 10 };
|
|
10
|
+
const px3: DCss.Px = { _unit: "px", value: 3 };
|
|
11
|
+
const px0: DCss.Px = { _unit: "px", value: 0 };
|
|
12
|
+
const px1: DCss.Px = { _unit: "px", value: 1 };
|
|
13
|
+
const scale026 = DCss.toString;
|
|
14
|
+
// const scale001 = DCss.toStringCreator(0.01);
|
|
15
|
+
|
|
16
|
+
expect(DCss.toString(px1300, 0.26)).toBe("338px");
|
|
17
|
+
expect(DCss.toString(px10, 0.26)).toBe("3px");
|
|
18
|
+
expect(DCss.toString(px1, 0.26)).toBe("1px");
|
|
19
|
+
expect(DCss.toString(px3, 0.26)).toBe("1px");
|
|
20
|
+
expect(DCss.toString(px0, 0.26)).toBe("0px");
|
|
21
|
+
expect(DCss.toString(px0, 0.26)).toBe("0px");
|
|
22
|
+
expect(DCss.toString(px555, 0.26)).toBe("144px");
|
|
23
|
+
expect(DCss.toString(px123, 0.01)).toBe("4px");
|
|
24
|
+
expect(DCss.toString(px1300, 0.01)).toBe("39px");
|
|
25
|
+
expect(DCss.isLengthUnit()).toBe(false);
|
|
26
|
+
expect(DCss.isLengthUnit({} as LengthUnit)).toBe(false);
|
|
27
|
+
expect(DCss.isLengthUnit(px123)).toBe(true);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
test("Normalize div: ", () => {
|
|
31
|
+
const div = document.createElement("div");
|
|
32
|
+
const normalized = DStyle.normalize(div);
|
|
33
|
+
expect(normalized.style.padding).toBe("0px");
|
|
34
|
+
expect(normalized.style.boxSizing).toBe("border-box");
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
test("Can validate Length-units ", () => {
|
|
38
|
+
expect(DCss.isLengthUnit(0)).toBe(true);
|
|
39
|
+
});
|
|
40
|
+
});
|
package/src/Delement/css.ts
CHANGED
|
@@ -1,56 +1,56 @@
|
|
|
1
|
-
import { DUtil } from "../utils/DUtil";
|
|
2
|
-
|
|
3
|
-
export namespace DCss {
|
|
4
|
-
export interface Px {
|
|
5
|
-
readonly _unit: "px";
|
|
6
|
-
readonly value: number;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export type LengthString = `${number}px` | `${number}%`;
|
|
10
|
-
export interface Percent {
|
|
11
|
-
readonly _unit: "percent";
|
|
12
|
-
readonly value: number;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export type LengthUnit = Px | Percent | number;
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Will scale to 3% of baseScale
|
|
19
|
-
* @param unit
|
|
20
|
-
* @param scale
|
|
21
|
-
*/
|
|
22
|
-
export const toString = (unit: Readonly<LengthUnit>, scale: number): LengthString => {
|
|
23
|
-
const _mapped: Percent | Px =
|
|
24
|
-
typeof unit === "number" ? { _unit: "percent", value: unit } : unit;
|
|
25
|
-
return _toString(_mapped, scale);
|
|
26
|
-
};
|
|
27
|
-
const _toString = (unit: Readonly<Percent | Px>, scale: number): LengthString => {
|
|
28
|
-
const clampedScale = Math.max(scale, 0.03);
|
|
29
|
-
if (unit._unit === "px") {
|
|
30
|
-
if (unit.value < 0.1) {
|
|
31
|
-
return "0px";
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
const rounded = Math.round(unit.value * clampedScale);
|
|
35
|
-
const clamped = Math.max(rounded, 1);
|
|
36
|
-
return (clamped + "px") as LengthString;
|
|
37
|
-
}
|
|
38
|
-
return (unit.value + "%") as LengthString;
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
export const isLengthUnit = (unit?: LengthUnit): unit is LengthUnit => {
|
|
42
|
-
if (typeof unit === "number") {
|
|
43
|
-
return true;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
if (!unit) {
|
|
47
|
-
return false;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
const unitKey: keyof DCss.Px = "_unit";
|
|
51
|
-
const valueKey: keyof DCss.Px = "value";
|
|
52
|
-
const hasUnitKey = DUtil.hasKey(unit, unitKey);
|
|
53
|
-
const hasValueKey = DUtil.hasKey(unit, valueKey);
|
|
54
|
-
return hasUnitKey && hasValueKey;
|
|
55
|
-
};
|
|
56
|
-
}
|
|
1
|
+
import { DUtil } from "../utils/DUtil";
|
|
2
|
+
|
|
3
|
+
export namespace DCss {
|
|
4
|
+
export interface Px {
|
|
5
|
+
readonly _unit: "px";
|
|
6
|
+
readonly value: number;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export type LengthString = `${number}px` | `${number}%`;
|
|
10
|
+
export interface Percent {
|
|
11
|
+
readonly _unit: "percent";
|
|
12
|
+
readonly value: number;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export type LengthUnit = Px | Percent | number;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Will scale to 3% of baseScale
|
|
19
|
+
* @param unit
|
|
20
|
+
* @param scale
|
|
21
|
+
*/
|
|
22
|
+
export const toString = (unit: Readonly<LengthUnit>, scale: number): LengthString => {
|
|
23
|
+
const _mapped: Percent | Px =
|
|
24
|
+
typeof unit === "number" ? { _unit: "percent", value: unit } : unit;
|
|
25
|
+
return _toString(_mapped, scale);
|
|
26
|
+
};
|
|
27
|
+
const _toString = (unit: Readonly<Percent | Px>, scale: number): LengthString => {
|
|
28
|
+
const clampedScale = Math.max(scale, 0.03);
|
|
29
|
+
if (unit._unit === "px") {
|
|
30
|
+
if (unit.value < 0.1) {
|
|
31
|
+
return "0px";
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const rounded = Math.round(unit.value * clampedScale);
|
|
35
|
+
const clamped = Math.max(rounded, 1);
|
|
36
|
+
return (clamped + "px") as LengthString;
|
|
37
|
+
}
|
|
38
|
+
return (unit.value + "%") as LengthString;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
export const isLengthUnit = (unit?: LengthUnit): unit is LengthUnit => {
|
|
42
|
+
if (typeof unit === "number") {
|
|
43
|
+
return true;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (!unit) {
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const unitKey: keyof DCss.Px = "_unit";
|
|
51
|
+
const valueKey: keyof DCss.Px = "value";
|
|
52
|
+
const hasUnitKey = DUtil.hasKey(unit, unitKey);
|
|
53
|
+
const hasValueKey = DUtil.hasKey(unit, valueKey);
|
|
54
|
+
return hasUnitKey && hasValueKey;
|
|
55
|
+
};
|
|
56
|
+
}
|
|
@@ -1,49 +1,49 @@
|
|
|
1
|
-
import { DElement } from "./DElement";
|
|
2
|
-
import { DDiv, DDivDto } from "./Ddiv";
|
|
3
|
-
import { DImg } from "./DImg";
|
|
4
|
-
import { DText } from "./DText";
|
|
5
|
-
import { ScaleService } from "../engine/scale";
|
|
6
|
-
import { DElementDto } from "./DElement.dto";
|
|
7
|
-
import { DButton } from "./DButton";
|
|
8
|
-
|
|
9
|
-
export const createDElement = (dto: DElementDto, scale: ScaleService): DElement<any> => {
|
|
10
|
-
switch (dto._tag) {
|
|
11
|
-
case "div":
|
|
12
|
-
const childEls = createChildrenForDiv(dto, scale);
|
|
13
|
-
return new DDiv(dto, scale, childEls);
|
|
14
|
-
case "img":
|
|
15
|
-
return new DImg(dto, scale);
|
|
16
|
-
case "p":
|
|
17
|
-
return new DText(dto, scale);
|
|
18
|
-
case "button":
|
|
19
|
-
return new DButton(dto, scale);
|
|
20
|
-
default:
|
|
21
|
-
const check: never = dto;
|
|
22
|
-
throw new Error("Unknown dto given to the createDElement function.");
|
|
23
|
-
// TODO LOGGING or create any HTML-ELEMENT??
|
|
24
|
-
}
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
const createChildrenForDiv = (dto: DDivDto, scale: ScaleService): DDiv["children"] => {
|
|
28
|
-
const childDto = dto.children;
|
|
29
|
-
const childEls: Array<DImg | DText | DButton> = [];
|
|
30
|
-
childDto.forEach((dto) => {
|
|
31
|
-
switch (dto._tag) {
|
|
32
|
-
case "p":
|
|
33
|
-
const newText = new DText(dto, scale);
|
|
34
|
-
childEls.push(newText);
|
|
35
|
-
break;
|
|
36
|
-
case "img":
|
|
37
|
-
const newImage = new DImg(dto, scale);
|
|
38
|
-
childEls.push(newImage);
|
|
39
|
-
break;
|
|
40
|
-
case "button":
|
|
41
|
-
const newButton = new DButton(dto, scale);
|
|
42
|
-
childEls.push(newButton);
|
|
43
|
-
break;
|
|
44
|
-
default:
|
|
45
|
-
const check: never = dto;
|
|
46
|
-
}
|
|
47
|
-
});
|
|
48
|
-
return childEls;
|
|
49
|
-
};
|
|
1
|
+
import { DElement } from "./DElement";
|
|
2
|
+
import { DDiv, DDivDto } from "./Ddiv";
|
|
3
|
+
import { DImg } from "./DImg";
|
|
4
|
+
import { DText } from "./DText";
|
|
5
|
+
import { ScaleService } from "../engine/scale";
|
|
6
|
+
import { DElementDto } from "./DElement.dto";
|
|
7
|
+
import { DButton } from "./DButton";
|
|
8
|
+
|
|
9
|
+
export const createDElement = (dto: DElementDto, scale: ScaleService): DElement<any> => {
|
|
10
|
+
switch (dto._tag) {
|
|
11
|
+
case "div":
|
|
12
|
+
const childEls = createChildrenForDiv(dto, scale);
|
|
13
|
+
return new DDiv(dto, scale, childEls);
|
|
14
|
+
case "img":
|
|
15
|
+
return new DImg(dto, scale);
|
|
16
|
+
case "p":
|
|
17
|
+
return new DText(dto, scale);
|
|
18
|
+
case "button":
|
|
19
|
+
return new DButton(dto, scale);
|
|
20
|
+
default:
|
|
21
|
+
const check: never = dto;
|
|
22
|
+
throw new Error("Unknown dto given to the createDElement function.");
|
|
23
|
+
// TODO LOGGING or create any HTML-ELEMENT??
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
const createChildrenForDiv = (dto: DDivDto, scale: ScaleService): DDiv["children"] => {
|
|
28
|
+
const childDto = dto.children;
|
|
29
|
+
const childEls: Array<DImg | DText | DButton> = [];
|
|
30
|
+
childDto.forEach((dto) => {
|
|
31
|
+
switch (dto._tag) {
|
|
32
|
+
case "p":
|
|
33
|
+
const newText = new DText(dto, scale);
|
|
34
|
+
childEls.push(newText);
|
|
35
|
+
break;
|
|
36
|
+
case "img":
|
|
37
|
+
const newImage = new DImg(dto, scale);
|
|
38
|
+
childEls.push(newImage);
|
|
39
|
+
break;
|
|
40
|
+
case "button":
|
|
41
|
+
const newButton = new DButton(dto, scale);
|
|
42
|
+
childEls.push(newButton);
|
|
43
|
+
break;
|
|
44
|
+
default:
|
|
45
|
+
const check: never = dto;
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
return childEls;
|
|
49
|
+
};
|