@media-quest/builder 0.0.30 → 0.0.32
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 +178 -2
- package/dist/public-api.js +862 -248
- package/dist/public-api.js.map +1 -1
- package/package.json +2 -2
- package/src/Builder-option.ts +62 -64
- package/src/Builder-schema.ts +4 -2
- package/src/public-api.ts +1 -0
- package/src/theme/Default-theme.ts +173 -0
- package/src/theme/IDefault-theme.ts +125 -0
- package/src/theme/ThemeCompiler.ts +10 -0
- package/src/theme/default-theme-compiler.spec.ts +31 -0
- package/src/theme/default-theme-compiler.ts +407 -114
- package/src/theme/icon-urls.ts +29 -29
- package/src/theme/icons.ts +117 -0
- package/src/theme/{theme1.spec.ts → theme-utils.spec.ts} +52 -52
- package/src/theme/theme-utils.ts +56 -57
- package/src/theme/theme2.ts +377 -0
- package/src/theme/AbstractThemeCompiler.ts +0 -7
- package/src/theme/IDefaultTheme.ts +0 -226
|
@@ -1,37 +1,46 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ThemeCompiler } from "./ThemeCompiler";
|
|
2
2
|
import type { BuilderSchemaDto } from "../Builder-schema";
|
|
3
3
|
import { BuilderSchema } from "../Builder-schema";
|
|
4
4
|
import type { BuilderPageDto } from "../page/Builder-page";
|
|
5
|
-
import {
|
|
6
|
-
import { DefaultTheme, type IDefaultTheme } from "./IDefaultTheme";
|
|
5
|
+
import { DefaultTheme } from "./Default-theme";
|
|
7
6
|
import type { BuilderMainImageDto } from "../BuilderMainImageDto";
|
|
8
7
|
import type { BuilderMainVideoDto } from "../BuilderMainVideoDto";
|
|
9
8
|
import {
|
|
10
9
|
ButtonClickAction,
|
|
10
|
+
DButtonDto,
|
|
11
11
|
DDivDto,
|
|
12
|
+
DelayTask,
|
|
12
13
|
DElementDto,
|
|
13
14
|
DImgDto,
|
|
14
15
|
DTextDto,
|
|
15
16
|
PageDto,
|
|
16
|
-
PageComponentDto,
|
|
17
|
-
RuleActionPageQue,
|
|
18
17
|
PlayAudioTask,
|
|
19
18
|
PlayVideoTask,
|
|
19
|
+
PStyle,
|
|
20
20
|
Rule,
|
|
21
|
+
RuleActionPageQue,
|
|
21
22
|
SchemaDto,
|
|
22
|
-
DelayTask,
|
|
23
23
|
} from "@media-quest/engine";
|
|
24
24
|
|
|
25
25
|
import { AudioFile } from "../media-files";
|
|
26
26
|
import { BuilderRule } from "../rulebuilder";
|
|
27
|
+
import { IDefaultTheme } from "./IDefault-theme";
|
|
28
|
+
import { Theme2 } from "./theme2";
|
|
27
29
|
|
|
28
|
-
export class DefaultThemeCompiler
|
|
30
|
+
export class DefaultThemeCompiler implements ThemeCompiler<IDefaultTheme> {
|
|
29
31
|
readonly name = "Ispe default theme.";
|
|
32
|
+
readonly defaultTheme = DefaultTheme;
|
|
33
|
+
readonly theme2 = Theme2;
|
|
34
|
+
currentTheme = Theme2;
|
|
35
|
+
allThemes = [DefaultTheme, Theme2];
|
|
30
36
|
private readonly TAG = "[ DEFAULT_THEME_COMPILER ]: ";
|
|
31
|
-
|
|
32
|
-
|
|
37
|
+
|
|
38
|
+
setTheme(theme: IDefaultTheme) {
|
|
39
|
+
this.currentTheme = theme;
|
|
33
40
|
}
|
|
34
41
|
|
|
42
|
+
constructor() {}
|
|
43
|
+
|
|
35
44
|
private compileRules(source: BuilderSchemaDto): Rule<RuleActionPageQue, never>[] {
|
|
36
45
|
const builderSchema = BuilderSchema.fromJson(source);
|
|
37
46
|
const ruleInput = builderSchema.getRuleInput();
|
|
@@ -48,119 +57,230 @@ export class DefaultThemeCompiler extends AbstractThemeCompiler<IDefaultTheme> {
|
|
|
48
57
|
}
|
|
49
58
|
|
|
50
59
|
compile(source: BuilderSchemaDto): SchemaDto {
|
|
51
|
-
const
|
|
60
|
+
const t = this.currentTheme;
|
|
61
|
+
const themeName = t.name;
|
|
62
|
+
const schema = source.name;
|
|
63
|
+
const tag = schema + "-" + themeName + " compile";
|
|
64
|
+
const TAG = tag.toUpperCase();
|
|
65
|
+
// console.group(TAG);
|
|
66
|
+
const numberOfPages = source.pages.length;
|
|
67
|
+
const pages = source.pages.map((p, index) => {
|
|
68
|
+
return this.compilePage(p, index, numberOfPages, source.prefix);
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
let baseHeight = source.baseHeight;
|
|
72
|
+
let baseWidth = source.baseWidth;
|
|
73
|
+
let backgroundColor = source.backgroundColor;
|
|
74
|
+
if (t.dimensions.baseHeight) {
|
|
75
|
+
baseHeight = t.dimensions.baseHeight;
|
|
76
|
+
}
|
|
77
|
+
if (t.dimensions.baseWidth) {
|
|
78
|
+
baseWidth = t.dimensions.baseWidth;
|
|
79
|
+
}
|
|
80
|
+
if (t.dimensions.baseWidth) {
|
|
81
|
+
baseWidth = t.dimensions.baseWidth;
|
|
82
|
+
}
|
|
83
|
+
if (t.schemaBackgroundColor) {
|
|
84
|
+
backgroundColor = t.schemaBackgroundColor;
|
|
85
|
+
}
|
|
86
|
+
|
|
52
87
|
const rules = this.compileRules(source);
|
|
53
88
|
|
|
54
89
|
const dto: SchemaDto = {
|
|
55
|
-
backgroundColor: source.backgroundColor,
|
|
56
|
-
baseHeight: source.baseHeight,
|
|
57
|
-
baseWidth: source.baseWidth,
|
|
58
90
|
id: source.id,
|
|
91
|
+
backgroundColor,
|
|
92
|
+
baseHeight,
|
|
93
|
+
baseWidth,
|
|
59
94
|
pageSequences: [],
|
|
60
95
|
pages,
|
|
61
96
|
predefinedFacts: [],
|
|
62
97
|
rules,
|
|
63
98
|
};
|
|
99
|
+
// console.groupEnd();
|
|
64
100
|
return dto;
|
|
65
101
|
}
|
|
66
102
|
|
|
67
|
-
private compilePage(
|
|
103
|
+
private compilePage(
|
|
104
|
+
page: BuilderPageDto,
|
|
105
|
+
pageIndex: number,
|
|
106
|
+
totalNumberOfPages: number,
|
|
107
|
+
modulePrefix: string,
|
|
108
|
+
): PageDto {
|
|
109
|
+
const pageNumber = pageIndex + 1;
|
|
68
110
|
const tags = page.tags ?? [];
|
|
69
111
|
const { nextButton, mainText, id, mainMedia, _type, prefix } = page;
|
|
70
|
-
const
|
|
112
|
+
const t = this.currentTheme;
|
|
113
|
+
const hasMainMedia = !!mainMedia;
|
|
114
|
+
const hasMainTextAudio = !!mainText.audioFile;
|
|
115
|
+
|
|
116
|
+
const elements: DElementDto[] = [];
|
|
71
117
|
let initialAudioTasks: Array<PlayAudioTask | DelayTask> = [];
|
|
72
118
|
let initialVideoTaskList: Array<PlayVideoTask | DelayTask> = [];
|
|
73
119
|
const newPage: PageDto = {
|
|
74
120
|
background: "white",
|
|
75
|
-
|
|
76
|
-
staticElements,
|
|
121
|
+
elements,
|
|
77
122
|
id,
|
|
78
123
|
prefix,
|
|
79
124
|
initialTasks: [],
|
|
80
125
|
tags: [...tags],
|
|
81
126
|
};
|
|
127
|
+
const bg = t.pageBackGround;
|
|
128
|
+
if (bg) {
|
|
129
|
+
const pageBackGround: DDivDto = {
|
|
130
|
+
style: bg.style,
|
|
131
|
+
_tag: "div",
|
|
132
|
+
children: [],
|
|
133
|
+
};
|
|
134
|
+
elements.push(pageBackGround);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
const bgArea1 = t.backGroundArea1;
|
|
138
|
+
|
|
139
|
+
if (bgArea1) {
|
|
140
|
+
const backgroundArea1: DDivDto = {
|
|
141
|
+
style: bgArea1.style,
|
|
142
|
+
_tag: "div",
|
|
143
|
+
children: [],
|
|
144
|
+
};
|
|
145
|
+
elements.push(backgroundArea1);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
if (t.progressBar) {
|
|
149
|
+
// console.log("ADDED PROGRESS.");
|
|
150
|
+
const progressInPercent = pageNumber / totalNumberOfPages;
|
|
151
|
+
// const a =
|
|
152
|
+
const baseStyles: PStyle = {
|
|
153
|
+
bottom: t.progressBar.bottom,
|
|
154
|
+
left: t.progressBar.left,
|
|
155
|
+
height: t.progressBar.height,
|
|
156
|
+
width: t.progressBar.width,
|
|
157
|
+
};
|
|
158
|
+
const progressBackGround: DDivDto = {
|
|
159
|
+
style: {
|
|
160
|
+
...baseStyles,
|
|
161
|
+
...t.progressBar.backgroundStyles,
|
|
162
|
+
},
|
|
163
|
+
_tag: "div",
|
|
164
|
+
children: [],
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
const currentProgress = t.progressBar.width * progressInPercent;
|
|
168
|
+
const progressIndicator: DDivDto = {
|
|
169
|
+
style: { ...baseStyles, ...t.progressBar.progressStyles, w: currentProgress },
|
|
170
|
+
_tag: "div",
|
|
171
|
+
children: [],
|
|
172
|
+
};
|
|
173
|
+
const pText = t.progressBar.text;
|
|
174
|
+
|
|
175
|
+
elements.push(progressBackGround);
|
|
176
|
+
elements.push(progressIndicator);
|
|
177
|
+
if (pText) {
|
|
178
|
+
const progressText: DTextDto = {
|
|
179
|
+
_tag: "p",
|
|
180
|
+
innerText: "side " + pageNumber + " av " + totalNumberOfPages,
|
|
181
|
+
style: pText.style,
|
|
182
|
+
};
|
|
183
|
+
elements.push(progressText);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
82
186
|
|
|
83
187
|
if (page.mainText.audioFile) {
|
|
84
188
|
const autoPlay = page.mainText.autoplay;
|
|
85
189
|
const autoPlayDelay = page.mainText.autoplayDelay;
|
|
86
|
-
const res = this.compileMainTextAudio(
|
|
190
|
+
const res = this.compileMainTextAudio(
|
|
191
|
+
page.mainText.audioFile,
|
|
192
|
+
autoPlay,
|
|
193
|
+
autoPlayDelay,
|
|
194
|
+
hasMainMedia,
|
|
195
|
+
);
|
|
196
|
+
// console.log(page.mainText.text);
|
|
87
197
|
initialAudioTasks = [...res.initialTasks];
|
|
88
|
-
newPage.
|
|
198
|
+
newPage.elements.push(...res.components);
|
|
89
199
|
}
|
|
90
200
|
|
|
91
201
|
if (_type === "question") {
|
|
92
202
|
const variableId = modulePrefix + "_" + page.prefix;
|
|
93
|
-
const
|
|
94
|
-
newPage.
|
|
95
|
-
|
|
203
|
+
const qRes = this.compileQuestion(id, page, variableId, hasMainMedia);
|
|
204
|
+
newPage.elements.push(qRes.buttonBar, qRes.question);
|
|
205
|
+
|
|
206
|
+
// newPage.elements.push(question);
|
|
96
207
|
// console.log(question);
|
|
97
208
|
// elements.push(...buttons, question);
|
|
98
209
|
}
|
|
99
210
|
|
|
100
211
|
if (_type === "info-page") {
|
|
101
212
|
const infoText = mainText.text;
|
|
102
|
-
const
|
|
103
|
-
kind: "next-button",
|
|
104
|
-
|
|
213
|
+
const nextButtonBar = this.compileButtonBar([
|
|
214
|
+
this.compileButton(nextButton, { kind: "next-button" }),
|
|
215
|
+
]);
|
|
216
|
+
const infoTextElement = this.compileMainText(infoText, hasMainTextAudio, hasMainMedia);
|
|
105
217
|
|
|
106
|
-
const
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
const infoTextElement: DElementDto = {
|
|
110
|
-
innerText: infoText,
|
|
111
|
-
_tag: "p",
|
|
112
|
-
style: textStyle,
|
|
113
|
-
};
|
|
114
|
-
newPage.staticElements.push(infoTextElement);
|
|
115
|
-
newPage.components.push(nextButtonComponent);
|
|
218
|
+
// const textBase =
|
|
219
|
+
newPage.elements.push(infoTextElement, nextButtonBar);
|
|
220
|
+
// newPage.components.push(nextButtonComponent);
|
|
116
221
|
}
|
|
117
222
|
if (mainMedia && mainMedia.kind === "main-image") {
|
|
118
223
|
const mainImageElement = this.compileImage(mainMedia);
|
|
119
|
-
newPage.
|
|
224
|
+
newPage.elements.push(mainImageElement);
|
|
120
225
|
}
|
|
121
226
|
|
|
122
227
|
if (mainMedia && mainMedia.kind === "main-video") {
|
|
123
228
|
const videoOutput = this.compileVideo(mainMedia);
|
|
229
|
+
// newPage.videoPlayer?.playUrl
|
|
124
230
|
newPage.videoPlayer = videoOutput.videoPlayer;
|
|
125
|
-
newPage.
|
|
231
|
+
newPage.elements.push(...videoOutput.components);
|
|
126
232
|
initialVideoTaskList = [...videoOutput.autoPlayTasks];
|
|
127
233
|
}
|
|
128
234
|
|
|
129
235
|
// ADDING INITIAL TASKS IN CORRECT ORDER
|
|
130
236
|
newPage.initialTasks.push(...initialVideoTaskList);
|
|
131
237
|
newPage.initialTasks.push(...initialAudioTasks);
|
|
132
|
-
const clone = JSON.parse(JSON.stringify(newPage));
|
|
238
|
+
const clone = JSON.parse(JSON.stringify(newPage)) as PageDto;
|
|
133
239
|
return clone;
|
|
134
240
|
}
|
|
135
241
|
|
|
136
242
|
private compileImage(image: BuilderMainImageDto) {
|
|
137
243
|
const img: DImgDto = {
|
|
138
244
|
_tag: "img",
|
|
139
|
-
style: this.
|
|
245
|
+
style: this.currentTheme.image.style,
|
|
140
246
|
url: image.file.downloadUrl,
|
|
141
247
|
};
|
|
142
248
|
return img;
|
|
143
249
|
}
|
|
144
250
|
|
|
251
|
+
private compileMainText(text: string, hasAudio: boolean, hasMainMedia: boolean): DTextDto {
|
|
252
|
+
const t = this.currentTheme;
|
|
253
|
+
const { base, hasMediaNotAudio, notMediaHasAudio, notMediaNotAudio, hasMediaHasAudio } =
|
|
254
|
+
t.mainText;
|
|
255
|
+
let style = base.text;
|
|
256
|
+
if (hasMainMedia && hasAudio) style = { ...style, ...hasMediaHasAudio.text };
|
|
257
|
+
if (!hasMainMedia && hasAudio) style = { ...style, ...notMediaHasAudio.text };
|
|
258
|
+
if (hasMainMedia && !hasAudio) style = { ...style, ...hasMediaNotAudio.text };
|
|
259
|
+
if (!hasMainMedia && !hasAudio) style = { ...style, ...notMediaNotAudio.text };
|
|
260
|
+
// console.log(style.textColor);
|
|
261
|
+
return {
|
|
262
|
+
_tag: "p",
|
|
263
|
+
innerText: text,
|
|
264
|
+
style,
|
|
265
|
+
};
|
|
266
|
+
}
|
|
267
|
+
|
|
145
268
|
private compileMainTextAudio(
|
|
146
269
|
audioFile: AudioFile,
|
|
147
270
|
autoPlay: boolean,
|
|
148
271
|
autoPlayDelay: number,
|
|
272
|
+
hasMainMedia: boolean,
|
|
149
273
|
): {
|
|
150
|
-
components:
|
|
274
|
+
components: DElementDto[];
|
|
151
275
|
initialTasks: Array<PlayAudioTask | DelayTask>;
|
|
152
276
|
} {
|
|
153
|
-
const t = this.
|
|
277
|
+
const t = this.currentTheme.mainText;
|
|
154
278
|
const audioId = audioFile.id;
|
|
155
|
-
const iconUrl =
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
const playMainTextAudio: DImgDto = {
|
|
159
|
-
_tag: "img",
|
|
160
|
-
url: iconUrl,
|
|
161
|
-
style: { ...t.withMedia.audio.css },
|
|
162
|
-
};
|
|
279
|
+
const iconUrl = this.currentTheme.mainText.base.audio.iconUrl;
|
|
280
|
+
const baseIconStyles = t.base.audio;
|
|
281
|
+
const addedStyles = hasMainMedia ? t.hasMediaHasAudio.audio : t.notMediaHasAudio.audio;
|
|
163
282
|
|
|
283
|
+
const audioIconStyle = { ...baseIconStyles.css, ...addedStyles };
|
|
164
284
|
const task: PlayAudioTask = {
|
|
165
285
|
audioId,
|
|
166
286
|
blockAudio: false,
|
|
@@ -172,6 +292,13 @@ export class DefaultThemeCompiler extends AbstractThemeCompiler<IDefaultTheme> {
|
|
|
172
292
|
url: audioFile.downloadUrl,
|
|
173
293
|
};
|
|
174
294
|
|
|
295
|
+
const playMainTextAudio: DImgDto = {
|
|
296
|
+
_tag: "img",
|
|
297
|
+
url: iconUrl,
|
|
298
|
+
style: { ...audioIconStyle },
|
|
299
|
+
onClick: { kind: "play-audio", task },
|
|
300
|
+
};
|
|
301
|
+
|
|
175
302
|
let initialAudioTasks: Array<PlayAudioTask | DelayTask> = [];
|
|
176
303
|
if (autoPlay) {
|
|
177
304
|
const playAudioTask: PlayAudioTask = { ...task, priority: "follow-queue" };
|
|
@@ -190,28 +317,74 @@ export class DefaultThemeCompiler extends AbstractThemeCompiler<IDefaultTheme> {
|
|
|
190
317
|
}
|
|
191
318
|
}
|
|
192
319
|
// const autoplayTask =
|
|
193
|
-
const playBtn: PageComponentDto = {
|
|
194
|
-
el: playMainTextAudio,
|
|
195
|
-
onClick: { kind: "play-audio", task },
|
|
196
|
-
};
|
|
197
320
|
|
|
198
|
-
return { components: [
|
|
321
|
+
return { components: [playMainTextAudio], initialTasks: [...initialAudioTasks] };
|
|
199
322
|
}
|
|
200
323
|
|
|
201
324
|
private compileVideo(video: BuilderMainVideoDto): {
|
|
202
325
|
videoPlayer: PageDto["videoPlayer"];
|
|
203
|
-
components:
|
|
326
|
+
components: DElementDto[];
|
|
204
327
|
autoPlayTasks: Array<PlayVideoTask | DelayTask>;
|
|
205
328
|
} {
|
|
206
|
-
const t = this.
|
|
329
|
+
const t = this.currentTheme.videoPlayer;
|
|
330
|
+
const hasReplayButton = !!t.replayButton;
|
|
331
|
+
|
|
207
332
|
const mode = video.mode;
|
|
208
|
-
const components:
|
|
333
|
+
// const components: DElementDto[] = [];
|
|
209
334
|
|
|
210
335
|
let autoPlayTasks: Array<PlayVideoTask | DelayTask> = [];
|
|
211
336
|
|
|
212
337
|
let autoplayVideoTask: PlayVideoTask | false = false;
|
|
213
338
|
let autoplayDelayTask: DelayTask | false = false;
|
|
214
339
|
|
|
340
|
+
let buttonBar: DDivDto | false = false;
|
|
341
|
+
let playButton: DImgDto | false = false;
|
|
342
|
+
let playButtonText: DTextDto | false = false;
|
|
343
|
+
let replayButton: DImgDto | false = false;
|
|
344
|
+
let replayButtonText: DTextDto | false = false;
|
|
345
|
+
let pauseButton: DImgDto | false = false;
|
|
346
|
+
let pauseButtonText: DTextDto | false = false;
|
|
347
|
+
let unmuteButton: DImgDto | false = false;
|
|
348
|
+
let unmuteButtonText: DTextDto | false = false;
|
|
349
|
+
let muteButton: DImgDto | false = false;
|
|
350
|
+
let muteButtonText: DTextDto | false = false;
|
|
351
|
+
|
|
352
|
+
const showWhenEnded: Partial<DElementDto> = {
|
|
353
|
+
whenVideoEnded: { visibility: "visible" },
|
|
354
|
+
whenVideoEndedAndMuted: { visibility: "visible" },
|
|
355
|
+
whenVideoPlaying: { visibility: "hidden" },
|
|
356
|
+
whenVideoPlayingAndMuted: { visibility: "hidden" },
|
|
357
|
+
whenVideoPaused: { visibility: "hidden" },
|
|
358
|
+
whenVideoPausedAndMuted: { visibility: "hidden" },
|
|
359
|
+
};
|
|
360
|
+
|
|
361
|
+
const showWhenPlayingOrPaused: Partial<DElementDto> = {
|
|
362
|
+
whenVideoEnded: { visibility: "visible" },
|
|
363
|
+
whenVideoEndedAndMuted: { visibility: "visible" },
|
|
364
|
+
whenVideoPlaying: { visibility: "visible" },
|
|
365
|
+
whenVideoPlayingAndMuted: { visibility: "visible" },
|
|
366
|
+
whenVideoPaused: { visibility: "hidden" },
|
|
367
|
+
whenVideoPausedAndMuted: { visibility: "hidden" },
|
|
368
|
+
};
|
|
369
|
+
|
|
370
|
+
const showWhenPlaying: Partial<DElementDto> = {
|
|
371
|
+
whenVideoEnded: { visibility: "hidden" },
|
|
372
|
+
whenVideoEndedAndMuted: { visibility: "hidden" },
|
|
373
|
+
whenVideoPlaying: { visibility: "visible" },
|
|
374
|
+
whenVideoPlayingAndMuted: { visibility: "visible" },
|
|
375
|
+
whenVideoPaused: { visibility: "hidden" },
|
|
376
|
+
whenVideoPausedAndMuted: { visibility: "hidden" },
|
|
377
|
+
};
|
|
378
|
+
|
|
379
|
+
const showWhenPaused: Partial<DElementDto> = {
|
|
380
|
+
whenVideoEnded: { visibility: "hidden" },
|
|
381
|
+
whenVideoEndedAndMuted: { visibility: "hidden" },
|
|
382
|
+
whenVideoPlaying: { visibility: "hidden" },
|
|
383
|
+
whenVideoPlayingAndMuted: { visibility: "hidden" },
|
|
384
|
+
whenVideoPaused: { visibility: "visible" },
|
|
385
|
+
whenVideoPausedAndMuted: { visibility: "visible" },
|
|
386
|
+
};
|
|
387
|
+
|
|
215
388
|
const playButtonTask: PlayVideoTask = {
|
|
216
389
|
kind: "play-video-task",
|
|
217
390
|
url: video.file.downloadUrl,
|
|
@@ -243,60 +416,173 @@ export class DefaultThemeCompiler extends AbstractThemeCompiler<IDefaultTheme> {
|
|
|
243
416
|
|
|
244
417
|
const videoPlayer: PageDto["videoPlayer"] = {
|
|
245
418
|
playUrl: video.file.downloadUrl,
|
|
246
|
-
style:
|
|
419
|
+
style: t.videoElement.css,
|
|
420
|
+
// style: { h: 45, w: 100, x: 0, y: 55 },
|
|
247
421
|
};
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
style: { ...t.
|
|
253
|
-
|
|
422
|
+
|
|
423
|
+
if (t.buttonBar) {
|
|
424
|
+
buttonBar = {
|
|
425
|
+
_tag: "div",
|
|
426
|
+
style: { ...t.buttonBar },
|
|
427
|
+
children: [],
|
|
428
|
+
};
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
playButton = {
|
|
432
|
+
...showWhenPaused,
|
|
433
|
+
_tag: "img",
|
|
434
|
+
url: t.playButton.iconUrl,
|
|
435
|
+
style: { ...t.playButton.css, ...t.playButton.cssEnabled },
|
|
436
|
+
// },
|
|
254
437
|
onClick: { kind: "play-video", task: playButtonTask },
|
|
255
|
-
whenVideoPlay: { visibility: "hidden" },
|
|
256
|
-
whenVideoPaused: { visibility: "visible" },
|
|
257
438
|
};
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
439
|
+
if (t.playButton.text) {
|
|
440
|
+
playButtonText = {
|
|
441
|
+
...showWhenPaused,
|
|
442
|
+
_tag: "p",
|
|
443
|
+
style: t.playButton.text.css,
|
|
444
|
+
innerText: t.playButton.text.text,
|
|
445
|
+
};
|
|
446
|
+
// components.push({
|
|
447
|
+
//
|
|
448
|
+
// });
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
pauseButton = {
|
|
452
|
+
...showWhenPlaying,
|
|
453
|
+
_tag: "img",
|
|
454
|
+
style: {
|
|
455
|
+
...t.pauseButton.css,
|
|
456
|
+
visibility: "hidden",
|
|
457
|
+
...t.pauseButton.cssEnabled,
|
|
267
458
|
},
|
|
459
|
+
url: t.pauseButton.iconUrl,
|
|
268
460
|
onClick: { kind: "pause-video" },
|
|
269
|
-
|
|
270
|
-
|
|
461
|
+
};
|
|
462
|
+
|
|
463
|
+
if (t.pauseButton.text) {
|
|
464
|
+
pauseButtonText = {
|
|
465
|
+
...showWhenPlaying,
|
|
466
|
+
_tag: "p",
|
|
467
|
+
style: t.pauseButton.text.css,
|
|
468
|
+
innerText: t.pauseButton.text.text,
|
|
469
|
+
};
|
|
470
|
+
}
|
|
471
|
+
if (t.unMuteButton) {
|
|
472
|
+
unmuteButton = {
|
|
473
|
+
_tag: "img",
|
|
474
|
+
style: { ...t.unMuteButton.css },
|
|
475
|
+
url: t.unMuteButton.iconUrl,
|
|
476
|
+
onClick: { kind: "un-mute-video" },
|
|
477
|
+
whenVideoPausedAndMuted: { visibility: "visible" },
|
|
478
|
+
whenVideoPaused: { visibility: "hidden" },
|
|
479
|
+
whenVideoPlayingAndMuted: { visibility: "visible" },
|
|
480
|
+
whenVideoPlaying: { visibility: "hidden" },
|
|
481
|
+
whenVideoEnded: { visibility: "hidden" },
|
|
482
|
+
whenVideoEndedAndMuted: { visibility: "hidden" },
|
|
483
|
+
};
|
|
484
|
+
if (t.unMuteButton.text) {
|
|
485
|
+
unmuteButtonText = {
|
|
486
|
+
_tag: "p",
|
|
487
|
+
style: t.unMuteButton.text.css,
|
|
488
|
+
innerText: t.unMuteButton.text.text,
|
|
489
|
+
whenVideoPausedAndMuted: { visibility: "visible" },
|
|
490
|
+
whenVideoPaused: { visibility: "hidden" },
|
|
491
|
+
whenVideoPlayingAndMuted: { visibility: "visible" },
|
|
492
|
+
whenVideoPlaying: { visibility: "hidden" },
|
|
493
|
+
whenVideoEnded: { visibility: "hidden" },
|
|
494
|
+
whenVideoEndedAndMuted: { visibility: "hidden" },
|
|
495
|
+
};
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
if (t.muteButton) {
|
|
499
|
+
muteButton = {
|
|
500
|
+
_tag: "img",
|
|
501
|
+
style: { ...t.muteButton.css },
|
|
502
|
+
url: t.muteButton.iconUrl,
|
|
503
|
+
onClick: { kind: "mute-video" },
|
|
504
|
+
whenVideoPausedAndMuted: { visibility: "hidden" },
|
|
505
|
+
whenVideoPaused: { visibility: "visible" },
|
|
506
|
+
whenVideoPlayingAndMuted: { visibility: "hidden" },
|
|
507
|
+
whenVideoPlaying: { visibility: "visible" },
|
|
508
|
+
whenVideoEnded: { visibility: "hidden" },
|
|
509
|
+
whenVideoEndedAndMuted: { visibility: "hidden" },
|
|
510
|
+
};
|
|
511
|
+
|
|
512
|
+
if (t.muteButton.text) {
|
|
513
|
+
muteButtonText = {
|
|
514
|
+
_tag: "p",
|
|
515
|
+
style: t.muteButton.text.css,
|
|
516
|
+
innerText: t.muteButton.text.text,
|
|
517
|
+
whenVideoPausedAndMuted: { visibility: "hidden" },
|
|
518
|
+
whenVideoPaused: { visibility: "visible" },
|
|
519
|
+
whenVideoPlayingAndMuted: { visibility: "hidden" },
|
|
520
|
+
whenVideoPlaying: { visibility: "visible" },
|
|
521
|
+
whenVideoEnded: { visibility: "hidden" },
|
|
522
|
+
whenVideoEndedAndMuted: { visibility: "hidden" },
|
|
523
|
+
};
|
|
524
|
+
}
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
if (t.replayButton) {
|
|
528
|
+
replayButton = {
|
|
529
|
+
...showWhenEnded,
|
|
530
|
+
_tag: "img",
|
|
531
|
+
style: { ...t.replayButton.css },
|
|
532
|
+
url: t.replayButton.iconUrl,
|
|
533
|
+
onClick: { kind: "play-video", task: playButtonTask },
|
|
534
|
+
};
|
|
535
|
+
if (t.replayButton.text) {
|
|
536
|
+
replayButtonText = {
|
|
537
|
+
...showWhenEnded,
|
|
538
|
+
_tag: "p",
|
|
539
|
+
style: t.replayButton.text.css,
|
|
540
|
+
innerText: t.replayButton.text.text,
|
|
541
|
+
};
|
|
542
|
+
}
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
const componentsSet = new Set<DElementDto>();
|
|
546
|
+
const addComponent = (maybeComponent: DElementDto | false) => {
|
|
547
|
+
if (maybeComponent) {
|
|
548
|
+
componentsSet.add(maybeComponent);
|
|
549
|
+
}
|
|
271
550
|
};
|
|
272
551
|
|
|
273
552
|
if (mode !== "gif-mode") {
|
|
274
|
-
|
|
275
|
-
|
|
553
|
+
addComponent(buttonBar);
|
|
554
|
+
addComponent(unmuteButton);
|
|
555
|
+
addComponent(unmuteButtonText);
|
|
556
|
+
addComponent(muteButton);
|
|
557
|
+
addComponent(muteButtonText);
|
|
558
|
+
addComponent(playButton);
|
|
559
|
+
addComponent(playButtonText);
|
|
560
|
+
addComponent(pauseButton);
|
|
561
|
+
addComponent(pauseButtonText);
|
|
562
|
+
addComponent(replayButton);
|
|
563
|
+
addComponent(replayButtonText);
|
|
276
564
|
}
|
|
277
|
-
|
|
565
|
+
// components = []
|
|
566
|
+
return { videoPlayer, components: [...componentsSet], autoPlayTasks: [...autoPlayTasks] };
|
|
278
567
|
}
|
|
279
568
|
private compileQuestion(
|
|
280
569
|
pageId: string,
|
|
281
570
|
page: BuilderPageDto,
|
|
282
571
|
variableId: string,
|
|
572
|
+
hasMainMedia: boolean,
|
|
283
573
|
): {
|
|
284
574
|
question: DTextDto;
|
|
285
|
-
|
|
575
|
+
buttonBar: DDivDto;
|
|
286
576
|
} {
|
|
287
577
|
// TODO REFACTORE DEFAULT QUESTION TO - (REMOVE USE TEXT1)
|
|
288
578
|
// console.log(page);
|
|
579
|
+
const t = this.currentTheme;
|
|
289
580
|
const q = page.defaultQuestion;
|
|
290
581
|
const text = page.mainText.text;
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
const
|
|
295
|
-
_tag: "p",
|
|
296
|
-
innerText: text,
|
|
297
|
-
style: questionStyle,
|
|
298
|
-
};
|
|
299
|
-
const buttons: PageComponentDto[] = q.options.map((o) => {
|
|
582
|
+
|
|
583
|
+
const questionElement = this.compileMainText(text, !!page.mainText.audioFile, hasMainMedia);
|
|
584
|
+
// initialTasks: Array<PlayAudioTask | DelayTask>;
|
|
585
|
+
const buttons: DButtonDto[] = q.options.map((o) => {
|
|
300
586
|
const btns = this.compileButton(o, {
|
|
301
587
|
kind: "response-button",
|
|
302
588
|
questionId: variableId,
|
|
@@ -304,18 +590,35 @@ export class DefaultThemeCompiler extends AbstractThemeCompiler<IDefaultTheme> {
|
|
|
304
590
|
});
|
|
305
591
|
return btns;
|
|
306
592
|
});
|
|
307
|
-
const
|
|
308
|
-
|
|
309
|
-
|
|
593
|
+
const buttonBar = this.compileButtonBar(buttons);
|
|
594
|
+
return {
|
|
595
|
+
question: questionElement,
|
|
596
|
+
buttonBar,
|
|
597
|
+
};
|
|
310
598
|
}
|
|
311
599
|
|
|
600
|
+
private compileButtonBar(buttons: Array<DButtonDto>): DDivDto {
|
|
601
|
+
const t = this.currentTheme;
|
|
602
|
+
const isSingle = buttons.length < 2;
|
|
603
|
+
const style: PStyle = isSingle
|
|
604
|
+
? { ...t.buttonBar.container.base, ...t.buttonBar.container.whenSingle }
|
|
605
|
+
: { ...t.buttonBar.container.base, ...t.buttonBar.container.whenMany };
|
|
606
|
+
// console.log(t);
|
|
607
|
+
const buttonBar: DDivDto = {
|
|
608
|
+
_tag: "div",
|
|
609
|
+
children: [...buttons],
|
|
610
|
+
style,
|
|
611
|
+
};
|
|
612
|
+
return buttonBar;
|
|
613
|
+
}
|
|
312
614
|
private compileButton(
|
|
313
615
|
buttonDto: BuilderPageDto["nextButton"],
|
|
314
616
|
options:
|
|
315
617
|
| { kind: "response-button"; questionId: string; questionText: string }
|
|
316
618
|
| { kind: "next-button" },
|
|
317
|
-
):
|
|
619
|
+
): DButtonDto {
|
|
318
620
|
const { id, value, label } = buttonDto;
|
|
621
|
+
const t = this.currentTheme;
|
|
319
622
|
const onclickAction: ButtonClickAction =
|
|
320
623
|
options.kind === "response-button"
|
|
321
624
|
? {
|
|
@@ -331,28 +634,18 @@ export class DefaultThemeCompiler extends AbstractThemeCompiler<IDefaultTheme> {
|
|
|
331
634
|
: { kind: "next-page" };
|
|
332
635
|
|
|
333
636
|
const btnStyles =
|
|
334
|
-
value === 9 ?
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
children: [
|
|
338
|
-
{
|
|
339
|
-
_tag: "p",
|
|
340
|
-
innerText: label,
|
|
341
|
-
style: btnStyles.text1,
|
|
342
|
-
},
|
|
343
|
-
],
|
|
344
|
-
style: { ...btnStyles.btn.css, ...btnStyles.btn.cssEnabled },
|
|
345
|
-
};
|
|
346
|
-
|
|
347
|
-
if (options.kind === "next-button") {
|
|
348
|
-
btn.style.x = 50;
|
|
349
|
-
btn.style.y = 8;
|
|
350
|
-
btn.style.transform = "translate(-50%, 0%)";
|
|
637
|
+
value === 9 ? t.buttonBar.responseButtons.dontKnow : t.buttonBar.responseButtons.normal;
|
|
638
|
+
if (t.buttonBar.vibrateMs) {
|
|
639
|
+
onclickAction.vibrateMs = t.buttonBar.vibrateMs;
|
|
351
640
|
}
|
|
352
|
-
|
|
353
|
-
|
|
641
|
+
|
|
642
|
+
const btn: DButtonDto = {
|
|
643
|
+
_tag: "button",
|
|
644
|
+
innerText: label,
|
|
645
|
+
style: { ...btnStyles.btn.css, ...btnStyles.btn.cssEnabled },
|
|
354
646
|
onClick: onclickAction,
|
|
355
647
|
};
|
|
356
|
-
|
|
648
|
+
|
|
649
|
+
return btn;
|
|
357
650
|
}
|
|
358
651
|
}
|