|
| 1 | +export const LAYOUT_MODES = Object.freeze(["getBoundingClientRect", "getBoundingRectAndElementFromPoint"]); |
| 2 | + |
1 | 3 | export class Params {
|
2 | 4 | viewport = {
|
3 | 5 | width: 800,
|
@@ -27,6 +29,8 @@ export class Params {
|
27 | 29 | // "generate": generate a random seed
|
28 | 30 | // <integer>: use the provided integer as a seed
|
29 | 31 | shuffleSeed = "off";
|
| 32 | + // Choices: "getBoundingClientRect" or "getBoundingRectAndElementFromPoint" |
| 33 | + layoutMode = LAYOUT_MODES[0]; |
30 | 34 | // Measure more workload prepare time.
|
31 | 35 | measurePrepare = false;
|
32 | 36 |
|
@@ -57,8 +61,9 @@ export class Params {
|
57 | 61 | this.useAsyncSteps = this._parseBooleanParam(searchParams, "useAsyncSteps");
|
58 | 62 | this.waitBeforeSync = this._parseIntParam(searchParams, "waitBeforeSync", 0);
|
59 | 63 | this.warmupBeforeSync = this._parseIntParam(searchParams, "warmupBeforeSync", 0);
|
60 |
| - this.measurementMethod = this._parseMeasurementMethod(searchParams); |
| 64 | + this.measurementMethod = this._parseEnumParam(searchParams, "measurementMethod", ["raf"]); |
61 | 65 | this.shuffleSeed = this._parseShuffleSeed(searchParams);
|
| 66 | + this.layoutMode = this._parseEnumParam(searchParams, "layoutMode", LAYOUT_MODES); |
62 | 67 | this.measurePrepare = this._parseBooleanParam(searchParams, "measurePrepare");
|
63 | 68 |
|
64 | 69 | const unused = Array.from(searchParams.keys());
|
@@ -124,14 +129,14 @@ export class Params {
|
124 | 129 | return tags;
|
125 | 130 | }
|
126 | 131 |
|
127 |
| - _parseMeasurementMethod(searchParams) { |
128 |
| - if (!searchParams.has("measurementMethod")) |
129 |
| - return defaultParams.measurementMethod; |
130 |
| - const measurementMethod = searchParams.get("measurementMethod"); |
131 |
| - if (measurementMethod !== "raf") |
132 |
| - throw new Error(`Invalid measurement method: '${measurementMethod}', must be 'raf'.`); |
133 |
| - searchParams.delete("measurementMethod"); |
134 |
| - return measurementMethod; |
| 132 | + _parseEnumParam(searchParams, paramKey, enumArray) { |
| 133 | + if (!searchParams.has(paramKey)) |
| 134 | + return defaultParams[paramKey]; |
| 135 | + const value = searchParams.get(paramKey); |
| 136 | + if (!enumArray.includes(value)) |
| 137 | + throw new Error(`Got invalid ${paramKey}: '${value}', choices are ${enumArray}`); |
| 138 | + searchParams.delete(paramKey); |
| 139 | + return value; |
135 | 140 | }
|
136 | 141 |
|
137 | 142 | _parseShuffleSeed(searchParams) {
|
|
0 commit comments