@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/package.json
CHANGED
|
@@ -1,29 +1,29 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@media-quest/builder",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"description": "Builder library for Media-quest schemas",
|
|
5
|
-
"main": "dist/public-api.js",
|
|
6
|
-
"types": "dist/public-api.d.js",
|
|
7
|
-
"license": "MIT",
|
|
8
|
-
"scripts": {
|
|
9
|
-
"clean": "rimraf dist",
|
|
10
|
-
"prepublishOnly": "npm run build",
|
|
11
|
-
"build": "tsup",
|
|
12
|
-
"tsc:check:builder": "tsc --watch --noEmit"
|
|
13
|
-
},
|
|
14
|
-
"tsup": {
|
|
15
|
-
"entry": [
|
|
16
|
-
"src/public-api.ts"
|
|
17
|
-
],
|
|
18
|
-
"splitting": false,
|
|
19
|
-
"sourcemap": true,
|
|
20
|
-
"clean": true,
|
|
21
|
-
"format": [
|
|
22
|
-
"cjs"
|
|
23
|
-
],
|
|
24
|
-
"dts": true
|
|
25
|
-
},
|
|
26
|
-
"peerDependencies": {
|
|
27
|
-
"@media-quest/engine": "0.0.
|
|
28
|
-
}
|
|
29
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@media-quest/builder",
|
|
3
|
+
"version": "0.0.40",
|
|
4
|
+
"description": "Builder library for Media-quest schemas",
|
|
5
|
+
"main": "dist/public-api.js",
|
|
6
|
+
"types": "dist/public-api.d.js",
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"scripts": {
|
|
9
|
+
"clean": "rimraf dist",
|
|
10
|
+
"prepublishOnly": "npm run build",
|
|
11
|
+
"build": "tsup",
|
|
12
|
+
"tsc:check:builder": "tsc --watch --noEmit"
|
|
13
|
+
},
|
|
14
|
+
"tsup": {
|
|
15
|
+
"entry": [
|
|
16
|
+
"src/public-api.ts"
|
|
17
|
+
],
|
|
18
|
+
"splitting": false,
|
|
19
|
+
"sourcemap": true,
|
|
20
|
+
"clean": true,
|
|
21
|
+
"format": [
|
|
22
|
+
"cjs"
|
|
23
|
+
],
|
|
24
|
+
"dts": true
|
|
25
|
+
},
|
|
26
|
+
"peerDependencies": {
|
|
27
|
+
"@media-quest/engine": "0.0.40"
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -1,233 +1,233 @@
|
|
|
1
|
-
const SPLITTER = " ";
|
|
2
|
-
|
|
3
|
-
const maxWordLength = (text: string) => {
|
|
4
|
-
const splitt = text.split(" ");
|
|
5
|
-
return Math.max(...splitt.map((w) => w.length));
|
|
6
|
-
};
|
|
7
|
-
|
|
8
|
-
type Splitted = {
|
|
9
|
-
index: number;
|
|
10
|
-
first: string;
|
|
11
|
-
second: string;
|
|
12
|
-
longest: number;
|
|
13
|
-
lineDiff: number;
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
const allSplits = (text: string): ReadonlyArray<Splitted> => {
|
|
17
|
-
const lines = text.split(SPLITTER);
|
|
18
|
-
const slices: Array<Splitted> = [];
|
|
19
|
-
lines.forEach((line, index, array) => {
|
|
20
|
-
const first = array.slice(0, index).join(SPLITTER);
|
|
21
|
-
const last = array.slice(index).join(SPLITTER);
|
|
22
|
-
const longest = Math.max(first.length, last.length);
|
|
23
|
-
const lineDiff = Math.abs(first.length - last.length);
|
|
24
|
-
const slice: Splitted = {
|
|
25
|
-
first,
|
|
26
|
-
second: last,
|
|
27
|
-
index,
|
|
28
|
-
longest,
|
|
29
|
-
lineDiff,
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
slices.push(slice);
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
return slices;
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
const splitInTwo = (buttonText: string) => {
|
|
39
|
-
const all = allSplits(buttonText);
|
|
40
|
-
let result = { first: "", last: "", longest: 0 };
|
|
41
|
-
all.forEach((slice, index) => {
|
|
42
|
-
if (index === 0) {
|
|
43
|
-
result.first = slice.first;
|
|
44
|
-
result.last = slice.second;
|
|
45
|
-
result.longest = slice.longest;
|
|
46
|
-
} else if (result.longest > slice.longest) {
|
|
47
|
-
result.first = slice.first;
|
|
48
|
-
result.last = slice.second;
|
|
49
|
-
result.longest = slice.longest;
|
|
50
|
-
}
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
return result;
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
type ButtonTextLength = {
|
|
57
|
-
readonly text: string;
|
|
58
|
-
/**
|
|
59
|
-
* Text is on one line.
|
|
60
|
-
*/
|
|
61
|
-
readonly max: number;
|
|
62
|
-
/**
|
|
63
|
-
* Text is on two lines.
|
|
64
|
-
*/
|
|
65
|
-
readonly min: number;
|
|
66
|
-
};
|
|
67
|
-
const checkLength = (buttonText: string): ButtonTextLength => {
|
|
68
|
-
const max = buttonText.length;
|
|
69
|
-
const onTwo = splitInTwo(buttonText);
|
|
70
|
-
const min = onTwo.longest;
|
|
71
|
-
return {
|
|
72
|
-
text: buttonText,
|
|
73
|
-
min,
|
|
74
|
-
max,
|
|
75
|
-
};
|
|
76
|
-
};
|
|
77
|
-
|
|
78
|
-
type ButtonTextSanitized = string & { __sanitized: true };
|
|
79
|
-
export class ButtonTextState {
|
|
80
|
-
private readonly text: string;
|
|
81
|
-
private _isSplit: boolean;
|
|
82
|
-
private readonly twoLineWidth: number;
|
|
83
|
-
private readonly oneLineWidth: number;
|
|
84
|
-
|
|
85
|
-
get width() {
|
|
86
|
-
return this._isSplit ? this.twoLineWidth : this.oneLineWidth;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
get isSplit() {
|
|
90
|
-
return this._isSplit;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
get canSplit() {
|
|
94
|
-
return this.oneLineWidth > this.twoLineWidth;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
get splitDiff() {
|
|
98
|
-
return this.oneLineWidth - this.twoLineWidth;
|
|
99
|
-
}
|
|
100
|
-
// get si
|
|
101
|
-
constructor(text: string) {
|
|
102
|
-
this.text = text;
|
|
103
|
-
this.oneLineWidth = text.length;
|
|
104
|
-
this._isSplit = false;
|
|
105
|
-
this.twoLineWidth = splitInTwo(text).longest;
|
|
106
|
-
}
|
|
107
|
-
tryToSplit() {
|
|
108
|
-
this._isSplit = true;
|
|
109
|
-
}
|
|
110
|
-
unSplit() {
|
|
111
|
-
this._isSplit = false;
|
|
112
|
-
}
|
|
113
|
-
getState() {
|
|
114
|
-
const sanitizedText = this.text as ButtonTextSanitized;
|
|
115
|
-
return { raw: this.text, sanitizedText, isSplit: this._isSplit, width: this.width };
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
type FittedButton = {
|
|
120
|
-
width: number;
|
|
121
|
-
isSingleLine: boolean;
|
|
122
|
-
};
|
|
123
|
-
|
|
124
|
-
type FitAllOptions = {
|
|
125
|
-
oneLine: { min: number; max: number };
|
|
126
|
-
twoLine: { min: number; max: number };
|
|
127
|
-
};
|
|
128
|
-
|
|
129
|
-
type FittedResult = {
|
|
130
|
-
success: boolean;
|
|
131
|
-
isSingleLine: boolean;
|
|
132
|
-
requiredSpace: number;
|
|
133
|
-
twoLineCount: number;
|
|
134
|
-
result: ReadonlyArray<FittedButton>;
|
|
135
|
-
};
|
|
136
|
-
|
|
137
|
-
const sumReducer = (acc: number, number: number) => acc + number;
|
|
138
|
-
|
|
139
|
-
/**
|
|
140
|
-
* Calculates the sum of an array of numbers.
|
|
141
|
-
*
|
|
142
|
-
* @param {number[]} numbers - An array of numbers to calculate the sum for.
|
|
143
|
-
* @returns {number} - The sum of the numbers in the array.
|
|
144
|
-
*/
|
|
145
|
-
const sum = (numbers: number[]): number => {
|
|
146
|
-
return numbers.reduce(sumReducer, 0);
|
|
147
|
-
};
|
|
148
|
-
|
|
149
|
-
export class ButtonBarState {
|
|
150
|
-
private readonly buttons: ReadonlyArray<ButtonTextState>;
|
|
151
|
-
private readonly oneLineMax: number;
|
|
152
|
-
constructor(buttons: ReadonlyArray<string>, options: { oneLineMax: number; twoLineMax: number }) {
|
|
153
|
-
this.buttons = buttons.map((text) => new ButtonTextState(text));
|
|
154
|
-
// this.fitAllOptions = fitAllOptions;
|
|
155
|
-
this.oneLineMax = options.oneLineMax;
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
fitAll() {
|
|
159
|
-
// const result = fitAll(this.buttons, this.fitAllOptions);
|
|
160
|
-
// return result;
|
|
161
|
-
}
|
|
162
|
-
isFitting(): boolean {
|
|
163
|
-
return this.getWidth() <= this.oneLineMax;
|
|
164
|
-
}
|
|
165
|
-
getWidth() {
|
|
166
|
-
return this.buttons.reduce((acc, b) => acc + b.width, 0);
|
|
167
|
-
}
|
|
168
|
-
isOneLine() {
|
|
169
|
-
return this.buttons.every((b) => !b.isSplit);
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
compressOneButton(): boolean {
|
|
173
|
-
let btn: ButtonTextState | false = false;
|
|
174
|
-
let didCompress = false;
|
|
175
|
-
this.buttons.forEach((b) => {
|
|
176
|
-
if (!didCompress && b.canSplit) {
|
|
177
|
-
b.tryToSplit();
|
|
178
|
-
didCompress = true;
|
|
179
|
-
}
|
|
180
|
-
});
|
|
181
|
-
|
|
182
|
-
return didCompress;
|
|
183
|
-
}
|
|
184
|
-
canCompress() {
|
|
185
|
-
return true;
|
|
186
|
-
// return this.buttons.some((b) => b.canSplit);
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
const fitAll = (buttons: string[], options: FitAllOptions): FittedResult => {
|
|
190
|
-
const bar = new ButtonBarState(buttons, {
|
|
191
|
-
oneLineMax: options.oneLine.max,
|
|
192
|
-
twoLineMax: options.twoLine.max,
|
|
193
|
-
});
|
|
194
|
-
|
|
195
|
-
let isSingleLine = true;
|
|
196
|
-
|
|
197
|
-
// isSingleLine = state.every((b) => !b.isSplit);
|
|
198
|
-
// const requiredSpace = state.reduce((acc, b) => acc + b.width, 0);
|
|
199
|
-
|
|
200
|
-
let requiredSpace = 0;
|
|
201
|
-
let twoLineCount = 0;
|
|
202
|
-
if (!isSingleLine) {
|
|
203
|
-
twoLineCount = 1;
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
// const result = textWithLengths.map((text) => {
|
|
207
|
-
// if (text.max <= options.oneLine.max) {
|
|
208
|
-
// requiredSpace+= text.max;
|
|
209
|
-
// return { width: text.max, isSingleLine: true };
|
|
210
|
-
// } else if (text.min <= options.twoLine.max) {
|
|
211
|
-
// twoLineCount++;
|
|
212
|
-
// return { width: text.min, isSingleLine: false };
|
|
213
|
-
// } else {
|
|
214
|
-
// requiredSpace += text.min;
|
|
215
|
-
// return { width: text.min, isSingleLine: false };
|
|
216
|
-
// }
|
|
217
|
-
// });
|
|
218
|
-
return {
|
|
219
|
-
success: true,
|
|
220
|
-
isSingleLine,
|
|
221
|
-
requiredSpace,
|
|
222
|
-
twoLineCount,
|
|
223
|
-
result: [],
|
|
224
|
-
};
|
|
225
|
-
};
|
|
226
|
-
|
|
227
|
-
export const buttonTextUtils = {
|
|
228
|
-
checkLength,
|
|
229
|
-
fitAll,
|
|
230
|
-
splitInTwo,
|
|
231
|
-
allSplits,
|
|
232
|
-
maxWordLength,
|
|
233
|
-
} as const;
|
|
1
|
+
const SPLITTER = " ";
|
|
2
|
+
|
|
3
|
+
const maxWordLength = (text: string) => {
|
|
4
|
+
const splitt = text.split(" ");
|
|
5
|
+
return Math.max(...splitt.map((w) => w.length));
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
type Splitted = {
|
|
9
|
+
index: number;
|
|
10
|
+
first: string;
|
|
11
|
+
second: string;
|
|
12
|
+
longest: number;
|
|
13
|
+
lineDiff: number;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
const allSplits = (text: string): ReadonlyArray<Splitted> => {
|
|
17
|
+
const lines = text.split(SPLITTER);
|
|
18
|
+
const slices: Array<Splitted> = [];
|
|
19
|
+
lines.forEach((line, index, array) => {
|
|
20
|
+
const first = array.slice(0, index).join(SPLITTER);
|
|
21
|
+
const last = array.slice(index).join(SPLITTER);
|
|
22
|
+
const longest = Math.max(first.length, last.length);
|
|
23
|
+
const lineDiff = Math.abs(first.length - last.length);
|
|
24
|
+
const slice: Splitted = {
|
|
25
|
+
first,
|
|
26
|
+
second: last,
|
|
27
|
+
index,
|
|
28
|
+
longest,
|
|
29
|
+
lineDiff,
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
slices.push(slice);
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
return slices;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
const splitInTwo = (buttonText: string) => {
|
|
39
|
+
const all = allSplits(buttonText);
|
|
40
|
+
let result = { first: "", last: "", longest: 0 };
|
|
41
|
+
all.forEach((slice, index) => {
|
|
42
|
+
if (index === 0) {
|
|
43
|
+
result.first = slice.first;
|
|
44
|
+
result.last = slice.second;
|
|
45
|
+
result.longest = slice.longest;
|
|
46
|
+
} else if (result.longest > slice.longest) {
|
|
47
|
+
result.first = slice.first;
|
|
48
|
+
result.last = slice.second;
|
|
49
|
+
result.longest = slice.longest;
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
return result;
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
type ButtonTextLength = {
|
|
57
|
+
readonly text: string;
|
|
58
|
+
/**
|
|
59
|
+
* Text is on one line.
|
|
60
|
+
*/
|
|
61
|
+
readonly max: number;
|
|
62
|
+
/**
|
|
63
|
+
* Text is on two lines.
|
|
64
|
+
*/
|
|
65
|
+
readonly min: number;
|
|
66
|
+
};
|
|
67
|
+
const checkLength = (buttonText: string): ButtonTextLength => {
|
|
68
|
+
const max = buttonText.length;
|
|
69
|
+
const onTwo = splitInTwo(buttonText);
|
|
70
|
+
const min = onTwo.longest;
|
|
71
|
+
return {
|
|
72
|
+
text: buttonText,
|
|
73
|
+
min,
|
|
74
|
+
max,
|
|
75
|
+
};
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
type ButtonTextSanitized = string & { __sanitized: true };
|
|
79
|
+
export class ButtonTextState {
|
|
80
|
+
private readonly text: string;
|
|
81
|
+
private _isSplit: boolean;
|
|
82
|
+
private readonly twoLineWidth: number;
|
|
83
|
+
private readonly oneLineWidth: number;
|
|
84
|
+
|
|
85
|
+
get width() {
|
|
86
|
+
return this._isSplit ? this.twoLineWidth : this.oneLineWidth;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
get isSplit() {
|
|
90
|
+
return this._isSplit;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
get canSplit() {
|
|
94
|
+
return this.oneLineWidth > this.twoLineWidth;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
get splitDiff() {
|
|
98
|
+
return this.oneLineWidth - this.twoLineWidth;
|
|
99
|
+
}
|
|
100
|
+
// get si
|
|
101
|
+
constructor(text: string) {
|
|
102
|
+
this.text = text;
|
|
103
|
+
this.oneLineWidth = text.length;
|
|
104
|
+
this._isSplit = false;
|
|
105
|
+
this.twoLineWidth = splitInTwo(text).longest;
|
|
106
|
+
}
|
|
107
|
+
tryToSplit() {
|
|
108
|
+
this._isSplit = true;
|
|
109
|
+
}
|
|
110
|
+
unSplit() {
|
|
111
|
+
this._isSplit = false;
|
|
112
|
+
}
|
|
113
|
+
getState() {
|
|
114
|
+
const sanitizedText = this.text as ButtonTextSanitized;
|
|
115
|
+
return { raw: this.text, sanitizedText, isSplit: this._isSplit, width: this.width };
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
type FittedButton = {
|
|
120
|
+
width: number;
|
|
121
|
+
isSingleLine: boolean;
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
type FitAllOptions = {
|
|
125
|
+
oneLine: { min: number; max: number };
|
|
126
|
+
twoLine: { min: number; max: number };
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
type FittedResult = {
|
|
130
|
+
success: boolean;
|
|
131
|
+
isSingleLine: boolean;
|
|
132
|
+
requiredSpace: number;
|
|
133
|
+
twoLineCount: number;
|
|
134
|
+
result: ReadonlyArray<FittedButton>;
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
const sumReducer = (acc: number, number: number) => acc + number;
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Calculates the sum of an array of numbers.
|
|
141
|
+
*
|
|
142
|
+
* @param {number[]} numbers - An array of numbers to calculate the sum for.
|
|
143
|
+
* @returns {number} - The sum of the numbers in the array.
|
|
144
|
+
*/
|
|
145
|
+
const sum = (numbers: number[]): number => {
|
|
146
|
+
return numbers.reduce(sumReducer, 0);
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
export class ButtonBarState {
|
|
150
|
+
private readonly buttons: ReadonlyArray<ButtonTextState>;
|
|
151
|
+
private readonly oneLineMax: number;
|
|
152
|
+
constructor(buttons: ReadonlyArray<string>, options: { oneLineMax: number; twoLineMax: number }) {
|
|
153
|
+
this.buttons = buttons.map((text) => new ButtonTextState(text));
|
|
154
|
+
// this.fitAllOptions = fitAllOptions;
|
|
155
|
+
this.oneLineMax = options.oneLineMax;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
fitAll() {
|
|
159
|
+
// const result = fitAll(this.buttons, this.fitAllOptions);
|
|
160
|
+
// return result;
|
|
161
|
+
}
|
|
162
|
+
isFitting(): boolean {
|
|
163
|
+
return this.getWidth() <= this.oneLineMax;
|
|
164
|
+
}
|
|
165
|
+
getWidth() {
|
|
166
|
+
return this.buttons.reduce((acc, b) => acc + b.width, 0);
|
|
167
|
+
}
|
|
168
|
+
isOneLine() {
|
|
169
|
+
return this.buttons.every((b) => !b.isSplit);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
compressOneButton(): boolean {
|
|
173
|
+
let btn: ButtonTextState | false = false;
|
|
174
|
+
let didCompress = false;
|
|
175
|
+
this.buttons.forEach((b) => {
|
|
176
|
+
if (!didCompress && b.canSplit) {
|
|
177
|
+
b.tryToSplit();
|
|
178
|
+
didCompress = true;
|
|
179
|
+
}
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
return didCompress;
|
|
183
|
+
}
|
|
184
|
+
canCompress() {
|
|
185
|
+
return true;
|
|
186
|
+
// return this.buttons.some((b) => b.canSplit);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
const fitAll = (buttons: string[], options: FitAllOptions): FittedResult => {
|
|
190
|
+
const bar = new ButtonBarState(buttons, {
|
|
191
|
+
oneLineMax: options.oneLine.max,
|
|
192
|
+
twoLineMax: options.twoLine.max,
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
let isSingleLine = true;
|
|
196
|
+
|
|
197
|
+
// isSingleLine = state.every((b) => !b.isSplit);
|
|
198
|
+
// const requiredSpace = state.reduce((acc, b) => acc + b.width, 0);
|
|
199
|
+
|
|
200
|
+
let requiredSpace = 0;
|
|
201
|
+
let twoLineCount = 0;
|
|
202
|
+
if (!isSingleLine) {
|
|
203
|
+
twoLineCount = 1;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
// const result = textWithLengths.map((text) => {
|
|
207
|
+
// if (text.max <= options.oneLine.max) {
|
|
208
|
+
// requiredSpace+= text.max;
|
|
209
|
+
// return { width: text.max, isSingleLine: true };
|
|
210
|
+
// } else if (text.min <= options.twoLine.max) {
|
|
211
|
+
// twoLineCount++;
|
|
212
|
+
// return { width: text.min, isSingleLine: false };
|
|
213
|
+
// } else {
|
|
214
|
+
// requiredSpace += text.min;
|
|
215
|
+
// return { width: text.min, isSingleLine: false };
|
|
216
|
+
// }
|
|
217
|
+
// });
|
|
218
|
+
return {
|
|
219
|
+
success: true,
|
|
220
|
+
isSingleLine,
|
|
221
|
+
requiredSpace,
|
|
222
|
+
twoLineCount,
|
|
223
|
+
result: [],
|
|
224
|
+
};
|
|
225
|
+
};
|
|
226
|
+
|
|
227
|
+
export const buttonTextUtils = {
|
|
228
|
+
checkLength,
|
|
229
|
+
fitAll,
|
|
230
|
+
splitInTwo,
|
|
231
|
+
allSplits,
|
|
232
|
+
maxWordLength,
|
|
233
|
+
} as const;
|