@media-quest/builder 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 +82 -99
- package/dist/public-api.js +36 -101
- package/dist/public-api.js.map +1 -1
- package/package.json +29 -29
- package/src/{theme → ARKIV}/button-bar/button-text-utils.ts +233 -233
- package/src/{theme → ARKIV}/button-bar/text-utils.spec.ts +105 -105
- package/src/Builder-option.ts +78 -62
- package/src/Builder-question.ts +98 -98
- package/src/Builder-schema.spec.ts +348 -348
- package/src/Builder-schema.ts +308 -306
- package/src/builder-compiler.ts +14 -20
- package/src/code-book/codebook-variable.ts +27 -27
- package/src/code-book/codebook.ts +89 -89
- package/src/media-files.ts +28 -32
- package/src/page/Builder-page-collection.spec.ts +219 -219
- package/src/page/Builder-page-collection.ts +129 -129
- package/src/page/Builder-page.spec.ts +177 -177
- package/src/page/Builder-page.ts +250 -250
- package/src/primitives/ID.ts +135 -135
- package/src/public-api.ts +29 -30
- package/src/rulebuilder/RuleAction.ts +105 -105
- package/src/schema-config.ts +25 -26
- package/src/sum-score/sum-score-variable-collection.spec.ts +68 -68
- package/src/sum-score/sum-score-variable-collection.ts +101 -101
- package/src/sum-score/sum-score-variable.ts +0 -1
- package/src/sum-score/sum-score.ts +166 -167
- package/src/tag/BuilderTag.ts +45 -45
- package/src/tag/Tag-Collection.ts +53 -53
- package/src/theme/Default-theme.ts +173 -188
- package/src/theme/IDefault-theme.ts +125 -125
- package/src/theme/ThemeCompiler.ts +10 -11
- package/src/theme/default-theme-compiler.spec.ts +31 -31
- package/src/theme/default-theme-compiler.ts +655 -652
- package/src/theme/icon-urls.ts +29 -29
- package/src/theme/icons.ts +117 -117
- package/src/theme/theme-utils.spec.ts +52 -52
- package/src/theme/theme-utils.ts +56 -56
- package/src/theme/theme2.ts +388 -386
- package/tsconfig.json +19 -19
- package/src/Builder-schema-dto.spec.ts +0 -155
- package/src/Builder-schema-dto.ts +0 -86
package/tsconfig.json
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"target": "es2022",
|
|
4
|
-
"module": "commonjs",
|
|
5
|
-
"moduleResolution": "node",
|
|
6
|
-
"declaration": true,
|
|
7
|
-
"strict": true,
|
|
8
|
-
"esModuleInterop": true,
|
|
9
|
-
"skipLibCheck": true,
|
|
10
|
-
"forceConsistentCasingInFileNames": true,
|
|
11
|
-
"rootDir": "./src",
|
|
12
|
-
"stripInternal": true,
|
|
13
|
-
"strictPropertyInitialization": true,
|
|
14
|
-
"strictNullChecks": true,
|
|
15
|
-
"outDir": "./dist"
|
|
16
|
-
},
|
|
17
|
-
"include": ["src/**/*"],
|
|
18
|
-
"exclude": ["node_modules", "dist"]
|
|
19
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "es2022",
|
|
4
|
+
"module": "commonjs",
|
|
5
|
+
"moduleResolution": "node",
|
|
6
|
+
"declaration": true,
|
|
7
|
+
"strict": true,
|
|
8
|
+
"esModuleInterop": true,
|
|
9
|
+
"skipLibCheck": true,
|
|
10
|
+
"forceConsistentCasingInFileNames": true,
|
|
11
|
+
"rootDir": "./src",
|
|
12
|
+
"stripInternal": true,
|
|
13
|
+
"strictPropertyInitialization": true,
|
|
14
|
+
"strictNullChecks": true,
|
|
15
|
+
"outDir": "./dist"
|
|
16
|
+
},
|
|
17
|
+
"include": ["src/**/*"],
|
|
18
|
+
"exclude": ["node_modules", "dist"]
|
|
19
|
+
}
|
|
@@ -1,155 +0,0 @@
|
|
|
1
|
-
import { BuilderSchema } from "./Builder-schema";
|
|
2
|
-
import { OptionID, PageID, QuestionID, SchemaID, SumScoreVariableID } from "./primitives/ID";
|
|
3
|
-
import { SchemaPrefixValue } from "./primitives/schema-prefix";
|
|
4
|
-
import { BuilderSchemaDto } from "./Builder-schema-dto";
|
|
5
|
-
import { PagePrefix } from "./primitives/page-prefix";
|
|
6
|
-
import { BuilderPageDto } from "./page/Builder-page";
|
|
7
|
-
import { Options } from "tsup";
|
|
8
|
-
import { AudioFile, ImageFile, VideoFile } from "./media-files";
|
|
9
|
-
|
|
10
|
-
const SCHEMA_ID = "schema_id" as SchemaID;
|
|
11
|
-
const SCHEMA_PREFIX_A = "schema_prefix_a" as SchemaPrefixValue;
|
|
12
|
-
let s1 = BuilderSchema.create(SCHEMA_ID, "test-name", SCHEMA_PREFIX_A);
|
|
13
|
-
|
|
14
|
-
const createPage = (options: {
|
|
15
|
-
pageNumber: number;
|
|
16
|
-
audioUrl: string;
|
|
17
|
-
mainMedia: { type: "image" | "video"; url: string; id: string };
|
|
18
|
-
}): BuilderPageDto => {
|
|
19
|
-
const { pageNumber, audioUrl, mainMedia } = options;
|
|
20
|
-
|
|
21
|
-
const audioId = "audio" + pageNumber + "_id";
|
|
22
|
-
|
|
23
|
-
let media: BuilderPageDto["mainMedia"] = undefined;
|
|
24
|
-
if (mainMedia.type === "image") {
|
|
25
|
-
media = {
|
|
26
|
-
kind: "main-image",
|
|
27
|
-
file: {
|
|
28
|
-
kind: "image-file",
|
|
29
|
-
id: mainMedia.id,
|
|
30
|
-
downloadUrl: mainMedia.url,
|
|
31
|
-
name: "video",
|
|
32
|
-
size: 1000,
|
|
33
|
-
type: "video",
|
|
34
|
-
originalFileName: "",
|
|
35
|
-
},
|
|
36
|
-
overlay: false,
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
if (mainMedia.type === "video") {
|
|
40
|
-
media = {
|
|
41
|
-
kind: "main-video",
|
|
42
|
-
file: {
|
|
43
|
-
kind: "video-file",
|
|
44
|
-
id: mainMedia.id,
|
|
45
|
-
downloadUrl: mainMedia.url,
|
|
46
|
-
duration: 2,
|
|
47
|
-
name: "video",
|
|
48
|
-
size: 1000,
|
|
49
|
-
type: "video",
|
|
50
|
-
originalFileName: "",
|
|
51
|
-
},
|
|
52
|
-
controls: false,
|
|
53
|
-
volume: 1,
|
|
54
|
-
mode: "optional",
|
|
55
|
-
preDelay: 0,
|
|
56
|
-
};
|
|
57
|
-
}
|
|
58
|
-
return {
|
|
59
|
-
id: ("p" + pageNumber) as PageID,
|
|
60
|
-
_type: "question",
|
|
61
|
-
mainMedia: media,
|
|
62
|
-
prefix: PagePrefix.fromStringOrThrow("p" + pageNumber),
|
|
63
|
-
mainText: {
|
|
64
|
-
text: "test",
|
|
65
|
-
audioFile: {
|
|
66
|
-
kind: "audio-file",
|
|
67
|
-
id: audioId,
|
|
68
|
-
name: audioId + " beskrivelse",
|
|
69
|
-
downloadUrl: audioUrl,
|
|
70
|
-
duration: 2,
|
|
71
|
-
originalFileName: "",
|
|
72
|
-
size: 1000,
|
|
73
|
-
relativePath: "asd",
|
|
74
|
-
},
|
|
75
|
-
autoplay: false,
|
|
76
|
-
autoplayDelay: 0,
|
|
77
|
-
},
|
|
78
|
-
defaultQuestion: {
|
|
79
|
-
id: "q1" as QuestionID,
|
|
80
|
-
_type: "select-one",
|
|
81
|
-
prefix: "1",
|
|
82
|
-
text: "test",
|
|
83
|
-
options: [],
|
|
84
|
-
},
|
|
85
|
-
includedInSumScores: [],
|
|
86
|
-
autoplaySequence: [],
|
|
87
|
-
// id: "p1",
|
|
88
|
-
// _type: "question",
|
|
89
|
-
nextButton: { label: "", id: "ja" as OptionID, value: 1 },
|
|
90
|
-
tags: [],
|
|
91
|
-
};
|
|
92
|
-
};
|
|
93
|
-
describe("BuilderSchemaDto utilities works", () => {
|
|
94
|
-
test("Can override media-urls", () => {
|
|
95
|
-
const page1 = createPage({
|
|
96
|
-
pageNumber: 1,
|
|
97
|
-
audioUrl: "audio1_url",
|
|
98
|
-
mainMedia: { type: "image", url: "image1_url", id: "image1_id" },
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
const page2 = createPage({
|
|
102
|
-
pageNumber: 2,
|
|
103
|
-
audioUrl: "audio2_url",
|
|
104
|
-
mainMedia: { type: "video", url: "video2_url", id: "video2_id" },
|
|
105
|
-
});
|
|
106
|
-
const page3 = createPage({
|
|
107
|
-
pageNumber: 3,
|
|
108
|
-
audioUrl: "audio3_url",
|
|
109
|
-
mainMedia: { type: "video", url: "video3_url", id: "video3_id" },
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
expect(page1.mainMedia?.file.downloadUrl).toBe("image1_url");
|
|
113
|
-
expect(page1.mainText.audioFile && page1.mainText.audioFile.downloadUrl).toBe("audio1_url");
|
|
114
|
-
expect(page2.mainMedia?.file.downloadUrl).toBe("video2_url");
|
|
115
|
-
expect(page2.mainText.audioFile && page2.mainText.audioFile.downloadUrl).toBe("audio2_url");
|
|
116
|
-
expect(page3.mainMedia?.file.downloadUrl).toBe("video3_url");
|
|
117
|
-
expect(page3.mainText.audioFile && page3.mainText.audioFile.downloadUrl).toBe("audio3_url");
|
|
118
|
-
const dto: BuilderSchemaDto = {
|
|
119
|
-
id: SCHEMA_ID,
|
|
120
|
-
prefix: SCHEMA_PREFIX_A,
|
|
121
|
-
mainImage: false,
|
|
122
|
-
backgroundColor: "#FFFFFF",
|
|
123
|
-
name: "test-name",
|
|
124
|
-
pages: [page1, page2, page3],
|
|
125
|
-
baseHeight: 100,
|
|
126
|
-
baseWidth: 100,
|
|
127
|
-
rules: [],
|
|
128
|
-
tags: [],
|
|
129
|
-
};
|
|
130
|
-
|
|
131
|
-
const newDto = BuilderSchemaDto.overrideAllMediaUrls(dto, {
|
|
132
|
-
videoFilesBaseUrl: "base_url/video_folder",
|
|
133
|
-
audioFilesBaseUrl: "base_url/audio_folder",
|
|
134
|
-
imageFilesBaseUrl: "base_url/image_folder",
|
|
135
|
-
});
|
|
136
|
-
|
|
137
|
-
const pages = newDto.pages;
|
|
138
|
-
const page1Media = pages[0].mainMedia;
|
|
139
|
-
const page1Audio = pages[0].mainText.audioFile as AudioFile;
|
|
140
|
-
const page2Media = pages[1].mainMedia;
|
|
141
|
-
const page2Audio = pages[1].mainText.audioFile as AudioFile;
|
|
142
|
-
const page3Media = pages[2].mainMedia;
|
|
143
|
-
const page3Audio = pages[2].mainText.audioFile as AudioFile;
|
|
144
|
-
|
|
145
|
-
expect(page1Media?.file.downloadUrl).toBe("base_url/image_folder/image1_id");
|
|
146
|
-
expect(page1Media?.file.kind).toBe("image-file");
|
|
147
|
-
expect(page1Audio.downloadUrl).toBe("base_url/audio_folder/audio1_id");
|
|
148
|
-
expect(page2Media?.file.downloadUrl).toBe("base_url/video_folder/video2_id");
|
|
149
|
-
expect(page2Media?.file.kind).toBe("video-file");
|
|
150
|
-
expect(page2Audio.downloadUrl).toBe("base_url/audio_folder/audio2_id");
|
|
151
|
-
expect(page3Media?.file.downloadUrl).toBe("base_url/video_folder/video3_id");
|
|
152
|
-
expect(page3Media?.file.kind).toBe("video-file");
|
|
153
|
-
expect(page3Audio.downloadUrl).toBe("base_url/audio_folder/audio3_id");
|
|
154
|
-
});
|
|
155
|
-
});
|
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
import { SchemaID } from "./primitives/ID";
|
|
2
|
-
import { SchemaPrefixValue } from "./primitives/schema-prefix";
|
|
3
|
-
import { AudioFile, ImageFile } from "./media-files";
|
|
4
|
-
import type { BuilderPageDto } from "./page/Builder-page";
|
|
5
|
-
import { CodebookPredefinedVariable } from "./code-book/codebook-variable";
|
|
6
|
-
import { SumScoreVariableDto } from "./sum-score/sum-score-variable";
|
|
7
|
-
import type { BuilderRuleDto } from "./rulebuilder";
|
|
8
|
-
import type { BuilderTagDto } from "./tag/BuilderTag";
|
|
9
|
-
|
|
10
|
-
const setUrl = <T extends { downloadUrl: string }>(dto: T, newUrl: string): T => {
|
|
11
|
-
return { ...dto, downloadUrl: newUrl };
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
export interface BuilderSchemaDto {
|
|
15
|
-
readonly id: SchemaID;
|
|
16
|
-
readonly prefix: SchemaPrefixValue;
|
|
17
|
-
readonly mainImage: ImageFile | false;
|
|
18
|
-
readonly backgroundColor: string;
|
|
19
|
-
readonly name: string;
|
|
20
|
-
readonly pages: ReadonlyArray<BuilderPageDto>;
|
|
21
|
-
readonly baseHeight: number;
|
|
22
|
-
readonly baseWidth: number;
|
|
23
|
-
readonly predefinedVariables?: Array<CodebookPredefinedVariable>;
|
|
24
|
-
readonly sumScoreVariables?: ReadonlyArray<SumScoreVariableDto>;
|
|
25
|
-
readonly rules: ReadonlyArray<BuilderRuleDto>;
|
|
26
|
-
readonly tags: ReadonlyArray<BuilderTagDto>;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
const blockAutoplayVideo = (dto: BuilderPageDto): BuilderPageDto => {
|
|
30
|
-
if (dto.mainMedia && dto.mainMedia.kind === "main-video") {
|
|
31
|
-
dto.mainMedia.mode = "optional";
|
|
32
|
-
}
|
|
33
|
-
return dto;
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
const overrideVideoUrl = (dto: BuilderPageDto, baseUrl: string): BuilderPageDto => {
|
|
37
|
-
const mainMedia = dto.mainMedia;
|
|
38
|
-
if (mainMedia && mainMedia.kind === "main-video") {
|
|
39
|
-
const url = [baseUrl, mainMedia.file.id].join("/");
|
|
40
|
-
const file = { ...mainMedia.file, downloadUrl: url };
|
|
41
|
-
dto.mainMedia = { ...mainMedia, file };
|
|
42
|
-
}
|
|
43
|
-
return dto;
|
|
44
|
-
};
|
|
45
|
-
const overrideImageUrl = (dto: BuilderPageDto, baseUrl: string): BuilderPageDto => {
|
|
46
|
-
const mainMedia = dto.mainMedia;
|
|
47
|
-
if (mainMedia && mainMedia.kind === "main-image") {
|
|
48
|
-
const url = [baseUrl, mainMedia.file.id].join("/");
|
|
49
|
-
const file = { ...mainMedia.file, downloadUrl: url };
|
|
50
|
-
dto.mainMedia = { ...mainMedia, file };
|
|
51
|
-
}
|
|
52
|
-
return dto;
|
|
53
|
-
};
|
|
54
|
-
const overrideAudioUrl = (dto: BuilderPageDto, baseUrl: string): BuilderPageDto => {
|
|
55
|
-
const newAudioFile = { ...dto };
|
|
56
|
-
const audioFile = newAudioFile.mainText.audioFile;
|
|
57
|
-
if (audioFile) {
|
|
58
|
-
const url = [baseUrl, audioFile.id].join("/");
|
|
59
|
-
dto.mainText.audioFile = { ...audioFile, downloadUrl: url };
|
|
60
|
-
}
|
|
61
|
-
return dto;
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
const overrideAllMediaUrls = (
|
|
65
|
-
schema: BuilderSchemaDto,
|
|
66
|
-
options: {
|
|
67
|
-
videoFilesBaseUrl: string;
|
|
68
|
-
audioFilesBaseUrl: string;
|
|
69
|
-
imageFilesBaseUrl: string;
|
|
70
|
-
},
|
|
71
|
-
): BuilderSchemaDto => {
|
|
72
|
-
// const videoFolder = [options.baseUrl, options.videoFileFolder].join("/");
|
|
73
|
-
// const audioFolder = [options.baseUrl, options.audioFileFolder].join("/");
|
|
74
|
-
// const imageFolder = [options.baseUrl, options.imageFileFolder].join("/");
|
|
75
|
-
const pages = schema.pages.map((page) => {
|
|
76
|
-
page = overrideVideoUrl(page, options.videoFilesBaseUrl);
|
|
77
|
-
page = overrideImageUrl(page, options.imageFilesBaseUrl);
|
|
78
|
-
page = overrideAudioUrl(page, options.audioFilesBaseUrl);
|
|
79
|
-
return page;
|
|
80
|
-
});
|
|
81
|
-
return { ...schema, pages };
|
|
82
|
-
};
|
|
83
|
-
export const BuilderSchemaDto = {
|
|
84
|
-
blockAutoplayVideo,
|
|
85
|
-
overrideAllMediaUrls,
|
|
86
|
-
};
|