@devtime-ltd/ui-bench 0.0.0-stage → 0.1.0
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/LICENSE +21 -0
- package/README.md +247 -2
- package/dist/cjs/UiBench.js +67 -0
- package/dist/cjs/UiBench.native.js +77 -0
- package/dist/cjs/core/controller.js +147 -0
- package/dist/cjs/core/entry.js +35 -0
- package/dist/cjs/core/fixtures.js +102 -0
- package/dist/cjs/core/fragment.js +107 -0
- package/dist/cjs/core/inputs.js +83 -0
- package/dist/cjs/core/prefs.js +76 -0
- package/dist/cjs/core/props.js +16 -0
- package/dist/cjs/core/stage.js +129 -0
- package/dist/cjs/core/viewports.js +49 -0
- package/dist/cjs/dom/ControlBar.js +34 -0
- package/dist/cjs/dom/FixturePicker.js +105 -0
- package/dist/cjs/dom/Frame.js +171 -0
- package/dist/cjs/dom/InputsPanel.js +47 -0
- package/dist/cjs/dom/Landing.js +32 -0
- package/dist/cjs/dom/hashUrl.js +35 -0
- package/dist/cjs/dom/styles.js +261 -0
- package/dist/cjs/index.js +44 -0
- package/dist/cjs/native/Box.js +47 -0
- package/dist/cjs/native/ControlBar.js +50 -0
- package/dist/cjs/native/FixturePicker.js +65 -0
- package/dist/cjs/native/InputsPanel.js +67 -0
- package/dist/cjs/native/Landing.js +42 -0
- package/dist/cjs/native/Triangle.js +43 -0
- package/dist/cjs/native/theme.js +49 -0
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/testing/index.js +59 -0
- package/dist/esm/UiBench.d.ts +2 -0
- package/dist/esm/UiBench.js +41 -0
- package/dist/esm/UiBench.js.map +1 -0
- package/dist/esm/UiBench.native.d.ts +2 -0
- package/dist/esm/UiBench.native.js +51 -0
- package/dist/esm/UiBench.native.js.map +1 -0
- package/dist/esm/core/controller.d.ts +43 -0
- package/dist/esm/core/controller.js +122 -0
- package/dist/esm/core/controller.js.map +1 -0
- package/dist/esm/core/entry.d.ts +8 -0
- package/dist/esm/core/entry.js +10 -0
- package/dist/esm/core/entry.js.map +1 -0
- package/dist/esm/core/fixtures.d.ts +27 -0
- package/dist/esm/core/fixtures.js +71 -0
- package/dist/esm/core/fixtures.js.map +1 -0
- package/dist/esm/core/fragment.d.ts +14 -0
- package/dist/esm/core/fragment.js +85 -0
- package/dist/esm/core/fragment.js.map +1 -0
- package/dist/esm/core/inputs.d.ts +30 -0
- package/dist/esm/core/inputs.js +52 -0
- package/dist/esm/core/inputs.js.map +1 -0
- package/dist/esm/core/prefs.d.ts +18 -0
- package/dist/esm/core/prefs.js +47 -0
- package/dist/esm/core/prefs.js.map +1 -0
- package/dist/esm/core/props.d.ts +23 -0
- package/dist/esm/core/props.js +2 -0
- package/dist/esm/core/props.js.map +1 -0
- package/dist/esm/core/stage.d.ts +50 -0
- package/dist/esm/core/stage.js +98 -0
- package/dist/esm/core/stage.js.map +1 -0
- package/dist/esm/core/viewports.d.ts +10 -0
- package/dist/esm/core/viewports.js +15 -0
- package/dist/esm/core/viewports.js.map +1 -0
- package/dist/esm/dom/ControlBar.d.ts +4 -0
- package/dist/esm/dom/ControlBar.js +8 -0
- package/dist/esm/dom/ControlBar.js.map +1 -0
- package/dist/esm/dom/FixturePicker.d.ts +6 -0
- package/dist/esm/dom/FixturePicker.js +82 -0
- package/dist/esm/dom/FixturePicker.js.map +1 -0
- package/dist/esm/dom/Frame.d.ts +9 -0
- package/dist/esm/dom/Frame.js +151 -0
- package/dist/esm/dom/Frame.js.map +1 -0
- package/dist/esm/dom/InputsPanel.d.ts +7 -0
- package/dist/esm/dom/InputsPanel.js +21 -0
- package/dist/esm/dom/InputsPanel.js.map +1 -0
- package/dist/esm/dom/Landing.d.ts +6 -0
- package/dist/esm/dom/Landing.js +6 -0
- package/dist/esm/dom/Landing.js.map +1 -0
- package/dist/esm/dom/hashUrl.d.ts +2 -0
- package/dist/esm/dom/hashUrl.js +9 -0
- package/dist/esm/dom/hashUrl.js.map +1 -0
- package/dist/esm/dom/styles.d.ts +1 -0
- package/dist/esm/dom/styles.js +235 -0
- package/dist/esm/dom/styles.js.map +1 -0
- package/dist/esm/index.d.ts +8 -0
- package/dist/esm/index.js +6 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/native/Box.d.ts +10 -0
- package/dist/esm/native/Box.js +21 -0
- package/dist/esm/native/Box.js.map +1 -0
- package/dist/esm/native/ControlBar.d.ts +5 -0
- package/dist/esm/native/ControlBar.js +24 -0
- package/dist/esm/native/ControlBar.js.map +1 -0
- package/dist/esm/native/FixturePicker.d.ts +6 -0
- package/dist/esm/native/FixturePicker.js +39 -0
- package/dist/esm/native/FixturePicker.js.map +1 -0
- package/dist/esm/native/InputsPanel.d.ts +7 -0
- package/dist/esm/native/InputsPanel.js +41 -0
- package/dist/esm/native/InputsPanel.js.map +1 -0
- package/dist/esm/native/Landing.d.ts +8 -0
- package/dist/esm/native/Landing.js +20 -0
- package/dist/esm/native/Landing.js.map +1 -0
- package/dist/esm/native/Triangle.d.ts +4 -0
- package/dist/esm/native/Triangle.js +17 -0
- package/dist/esm/native/Triangle.js.map +1 -0
- package/dist/esm/native/theme.d.ts +18 -0
- package/dist/esm/native/theme.js +19 -0
- package/dist/esm/native/theme.js.map +1 -0
- package/dist/esm/testing/index.d.ts +21 -0
- package/dist/esm/testing/index.js +33 -0
- package/dist/esm/testing/index.js.map +1 -0
- package/package.json +84 -4
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var fixtures_exports = {};
|
|
20
|
+
__export(fixtures_exports, {
|
|
21
|
+
fromRequireContext: () => fromRequireContext,
|
|
22
|
+
groupByFile: () => groupByFile,
|
|
23
|
+
loadFixtures: () => loadFixtures,
|
|
24
|
+
searchFixtures: () => searchFixtures
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(fixtures_exports);
|
|
27
|
+
const FIXTURE_SUFFIX = /\.fixture\.[cm]?[jt]sx?$/;
|
|
28
|
+
function fromRequireContext(context) {
|
|
29
|
+
const modules = {};
|
|
30
|
+
for (const key of context.keys())
|
|
31
|
+
modules[key] = context(key);
|
|
32
|
+
return modules;
|
|
33
|
+
}
|
|
34
|
+
function loadFixtures(modules) {
|
|
35
|
+
const paths = Object.keys(modules).sort();
|
|
36
|
+
const prefix = commonDirectory(paths);
|
|
37
|
+
const fixtures = [];
|
|
38
|
+
for (const path of paths) {
|
|
39
|
+
const module2 = modules[path];
|
|
40
|
+
const file = path.slice(prefix.length).replace(FIXTURE_SUFFIX, "");
|
|
41
|
+
const exported = module2?.default;
|
|
42
|
+
const shared = {
|
|
43
|
+
file,
|
|
44
|
+
seed: module2?.seed,
|
|
45
|
+
inputs: module2?.inputs ?? {},
|
|
46
|
+
viewport: module2?.viewport,
|
|
47
|
+
layout: module2?.layout ?? "padded"
|
|
48
|
+
};
|
|
49
|
+
if (isComponent(exported)) {
|
|
50
|
+
fixtures.push({ ...shared, id: file, name: "default", label: file, Component: exported });
|
|
51
|
+
continue;
|
|
52
|
+
}
|
|
53
|
+
if (!exported || typeof exported !== "object") {
|
|
54
|
+
console.warn(`ui-bench: ${path} has no default export of a component or an object of components.`);
|
|
55
|
+
continue;
|
|
56
|
+
}
|
|
57
|
+
for (const [name, Component] of Object.entries(exported)) {
|
|
58
|
+
if (!isComponent(Component))
|
|
59
|
+
continue;
|
|
60
|
+
fixtures.push({ ...shared, id: `${file}/${name}`, name, label: `${file} / ${name}`, Component });
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return fixtures;
|
|
64
|
+
}
|
|
65
|
+
function groupByFile(fixtures) {
|
|
66
|
+
const byFile = /* @__PURE__ */ new Map();
|
|
67
|
+
for (const fixture of fixtures) {
|
|
68
|
+
byFile.set(fixture.file, [...byFile.get(fixture.file) ?? [], fixture]);
|
|
69
|
+
}
|
|
70
|
+
return [...byFile.entries()];
|
|
71
|
+
}
|
|
72
|
+
function searchFixtures(fixtures, query) {
|
|
73
|
+
const terms = query.toLowerCase().split(/\s+/).filter(Boolean);
|
|
74
|
+
if (terms.length === 0)
|
|
75
|
+
return fixtures;
|
|
76
|
+
return fixtures.filter((fixture) => {
|
|
77
|
+
const label = fixture.label.toLowerCase();
|
|
78
|
+
return terms.every((term) => label.includes(term));
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
function commonDirectory(paths) {
|
|
82
|
+
const [first, ...rest] = paths.map((path) => path.slice(0, path.lastIndexOf("/") + 1));
|
|
83
|
+
if (first === void 0)
|
|
84
|
+
return "";
|
|
85
|
+
let prefix = first;
|
|
86
|
+
for (const directory of rest) {
|
|
87
|
+
while (!directory.startsWith(prefix)) {
|
|
88
|
+
prefix = prefix.slice(0, prefix.lastIndexOf("/", prefix.length - 2) + 1);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
return prefix;
|
|
92
|
+
}
|
|
93
|
+
function isComponent(value) {
|
|
94
|
+
return typeof value === "function" || typeof value === "object" && value !== null && "$$typeof" in value;
|
|
95
|
+
}
|
|
96
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
97
|
+
0 && (module.exports = {
|
|
98
|
+
fromRequireContext,
|
|
99
|
+
groupByFile,
|
|
100
|
+
loadFixtures,
|
|
101
|
+
searchFixtures
|
|
102
|
+
});
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var fragment_exports = {};
|
|
20
|
+
__export(fragment_exports, {
|
|
21
|
+
EMPTY_URL_STATE: () => EMPTY_URL_STATE,
|
|
22
|
+
formatFragment: () => formatFragment,
|
|
23
|
+
parseFragment: () => parseFragment
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(fragment_exports);
|
|
26
|
+
var import_inputs = require("./inputs");
|
|
27
|
+
const EMPTY_URL_STATE = {
|
|
28
|
+
fixture: null,
|
|
29
|
+
inputs: null,
|
|
30
|
+
viewport: null,
|
|
31
|
+
theme: null,
|
|
32
|
+
chrome: true,
|
|
33
|
+
rest: []
|
|
34
|
+
};
|
|
35
|
+
function parseFragment(fragment) {
|
|
36
|
+
const state = { ...EMPTY_URL_STATE, rest: [] };
|
|
37
|
+
for (const pair of fragment.replace(/^#/, "").split("&")) {
|
|
38
|
+
if (pair === "")
|
|
39
|
+
continue;
|
|
40
|
+
const split = pair.indexOf("=");
|
|
41
|
+
const key = split === -1 ? pair : pair.slice(0, split);
|
|
42
|
+
const value = split === -1 ? null : decode(pair.slice(split + 1));
|
|
43
|
+
if (value === null) {
|
|
44
|
+
state.rest.push(pair);
|
|
45
|
+
} else if (key === "fixture") {
|
|
46
|
+
state.fixture = value || null;
|
|
47
|
+
} else if (key === "inputs") {
|
|
48
|
+
state.inputs = parseInputs(value);
|
|
49
|
+
} else if (key === "viewport") {
|
|
50
|
+
state.viewport = value || null;
|
|
51
|
+
} else if (key === "theme") {
|
|
52
|
+
state.theme = value === "light" || value === "dark" ? value : null;
|
|
53
|
+
} else if (key === "chrome") {
|
|
54
|
+
state.chrome = value !== "0";
|
|
55
|
+
} else {
|
|
56
|
+
state.rest.push(pair);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return state;
|
|
60
|
+
}
|
|
61
|
+
function formatFragment(state) {
|
|
62
|
+
const pairs = [];
|
|
63
|
+
if (state.fixture)
|
|
64
|
+
pairs.push(`fixture=${encode(state.fixture)}`);
|
|
65
|
+
if (state.inputs)
|
|
66
|
+
pairs.push(`inputs=${encode(JSON.stringify(state.inputs))}`);
|
|
67
|
+
if (state.viewport)
|
|
68
|
+
pairs.push(`viewport=${encode(state.viewport)}`);
|
|
69
|
+
if (state.theme)
|
|
70
|
+
pairs.push(`theme=${state.theme}`);
|
|
71
|
+
if (!state.chrome)
|
|
72
|
+
pairs.push("chrome=0");
|
|
73
|
+
return [...pairs, ...state.rest].join("&");
|
|
74
|
+
}
|
|
75
|
+
function parseInputs(value) {
|
|
76
|
+
try {
|
|
77
|
+
const parsed = JSON.parse(value);
|
|
78
|
+
return (0, import_inputs.isPlainObject)(parsed) ? parsed : null;
|
|
79
|
+
} catch {
|
|
80
|
+
return null;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
function decode(value) {
|
|
84
|
+
try {
|
|
85
|
+
return decodeURIComponent(value);
|
|
86
|
+
} catch {
|
|
87
|
+
return null;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
const READABLE = {
|
|
91
|
+
"%2F": "/",
|
|
92
|
+
"%3A": ":",
|
|
93
|
+
"%2C": ",",
|
|
94
|
+
"%7B": "{",
|
|
95
|
+
"%7D": "}",
|
|
96
|
+
"%5B": "[",
|
|
97
|
+
"%5D": "]"
|
|
98
|
+
};
|
|
99
|
+
function encode(value) {
|
|
100
|
+
return encodeURIComponent(value).replace(/%(?:2F|3A|2C|7B|7D|5B|5D)/g, (escaped) => READABLE[escaped] ?? escaped);
|
|
101
|
+
}
|
|
102
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
103
|
+
0 && (module.exports = {
|
|
104
|
+
EMPTY_URL_STATE,
|
|
105
|
+
formatFragment,
|
|
106
|
+
parseFragment
|
|
107
|
+
});
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var inputs_exports = {};
|
|
20
|
+
__export(inputs_exports, {
|
|
21
|
+
changedInputs: () => changedInputs,
|
|
22
|
+
defaultInputs: () => defaultInputs,
|
|
23
|
+
formatRawInputs: () => formatRawInputs,
|
|
24
|
+
isInputOptions: () => isInputOptions,
|
|
25
|
+
isPlainObject: () => isPlainObject,
|
|
26
|
+
mergeInputs: () => mergeInputs,
|
|
27
|
+
parseRawInputs: () => parseRawInputs
|
|
28
|
+
});
|
|
29
|
+
module.exports = __toCommonJS(inputs_exports);
|
|
30
|
+
function isInputOptions(value) {
|
|
31
|
+
return isPlainObject(value) && Array.isArray(value.options);
|
|
32
|
+
}
|
|
33
|
+
function defaultInputs(declarations) {
|
|
34
|
+
const values = {};
|
|
35
|
+
for (const [key, declared] of Object.entries(declarations)) {
|
|
36
|
+
values[key] = isInputOptions(declared) ? "default" in declared ? declared.default : declared.options[0] : declared;
|
|
37
|
+
}
|
|
38
|
+
return values;
|
|
39
|
+
}
|
|
40
|
+
function mergeInputs(defaults, overrides) {
|
|
41
|
+
return { ...defaults, ...overrides };
|
|
42
|
+
}
|
|
43
|
+
function changedInputs(defaults, values) {
|
|
44
|
+
const changed = {};
|
|
45
|
+
for (const [key, value] of Object.entries(values)) {
|
|
46
|
+
if (!(key in defaults) || JSON.stringify(defaults[key]) !== JSON.stringify(value))
|
|
47
|
+
changed[key] = value;
|
|
48
|
+
}
|
|
49
|
+
return Object.keys(changed).length > 0 ? changed : null;
|
|
50
|
+
}
|
|
51
|
+
function formatRawInputs(values) {
|
|
52
|
+
return JSON.stringify(values, null, 2);
|
|
53
|
+
}
|
|
54
|
+
function parseRawInputs(text) {
|
|
55
|
+
if (text.trim() === "")
|
|
56
|
+
return { ok: true, values: {} };
|
|
57
|
+
let parsed;
|
|
58
|
+
try {
|
|
59
|
+
parsed = JSON.parse(text);
|
|
60
|
+
} catch (error) {
|
|
61
|
+
try {
|
|
62
|
+
parsed = JSON.parse(text.replace(/[“”]/g, '"').replace(/[‘’]/g, "'"));
|
|
63
|
+
} catch {
|
|
64
|
+
return { ok: false, message: error instanceof Error ? error.message : String(error) };
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
if (!isPlainObject(parsed))
|
|
68
|
+
return { ok: false, message: "Inputs have to be a JSON object." };
|
|
69
|
+
return { ok: true, values: parsed };
|
|
70
|
+
}
|
|
71
|
+
function isPlainObject(value) {
|
|
72
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
73
|
+
}
|
|
74
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
75
|
+
0 && (module.exports = {
|
|
76
|
+
changedInputs,
|
|
77
|
+
defaultInputs,
|
|
78
|
+
formatRawInputs,
|
|
79
|
+
isInputOptions,
|
|
80
|
+
isPlainObject,
|
|
81
|
+
mergeInputs,
|
|
82
|
+
parseRawInputs
|
|
83
|
+
});
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var prefs_exports = {};
|
|
20
|
+
__export(prefs_exports, {
|
|
21
|
+
DEFAULT_PREFS: () => DEFAULT_PREFS,
|
|
22
|
+
memoryStorage: () => memoryStorage,
|
|
23
|
+
readPrefs: () => readPrefs,
|
|
24
|
+
writePrefs: () => writePrefs
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(prefs_exports);
|
|
27
|
+
const DEFAULT_PREFS = {
|
|
28
|
+
edge: "bottom",
|
|
29
|
+
minimised: false,
|
|
30
|
+
mode: "light",
|
|
31
|
+
inputsOpen: false,
|
|
32
|
+
selected: null
|
|
33
|
+
};
|
|
34
|
+
const KEY = "ui-bench:prefs";
|
|
35
|
+
function memoryStorage() {
|
|
36
|
+
const values = /* @__PURE__ */ new Map();
|
|
37
|
+
return {
|
|
38
|
+
getItem: (key) => values.get(key) ?? null,
|
|
39
|
+
setItem: (key, value) => void values.set(key, value)
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
function readPrefs(storage) {
|
|
43
|
+
let stored;
|
|
44
|
+
try {
|
|
45
|
+
stored = storage.getItem(KEY);
|
|
46
|
+
} catch {
|
|
47
|
+
return DEFAULT_PREFS;
|
|
48
|
+
}
|
|
49
|
+
if (stored !== null && typeof stored === "object")
|
|
50
|
+
return stored.then(parsePrefs, () => DEFAULT_PREFS);
|
|
51
|
+
return parsePrefs(stored);
|
|
52
|
+
}
|
|
53
|
+
function writePrefs(storage, prefs) {
|
|
54
|
+
try {
|
|
55
|
+
void Promise.resolve(storage.setItem(KEY, JSON.stringify(prefs))).catch(() => {
|
|
56
|
+
});
|
|
57
|
+
} catch {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
function parsePrefs(raw) {
|
|
62
|
+
if (!raw)
|
|
63
|
+
return DEFAULT_PREFS;
|
|
64
|
+
try {
|
|
65
|
+
return { ...DEFAULT_PREFS, ...JSON.parse(raw) };
|
|
66
|
+
} catch {
|
|
67
|
+
return DEFAULT_PREFS;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
71
|
+
0 && (module.exports = {
|
|
72
|
+
DEFAULT_PREFS,
|
|
73
|
+
memoryStorage,
|
|
74
|
+
readPrefs,
|
|
75
|
+
writePrefs
|
|
76
|
+
});
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
+
var props_exports = {};
|
|
16
|
+
module.exports = __toCommonJS(props_exports);
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var stage_exports = {};
|
|
20
|
+
__export(stage_exports, {
|
|
21
|
+
StageBody: () => StageBody,
|
|
22
|
+
createHarnessSession: () => createHarnessSession,
|
|
23
|
+
useHarness: () => useHarness,
|
|
24
|
+
useInputs: () => useInputs,
|
|
25
|
+
useSeeded: () => useSeeded,
|
|
26
|
+
useStage: () => useStage
|
|
27
|
+
});
|
|
28
|
+
module.exports = __toCommonJS(stage_exports);
|
|
29
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
30
|
+
var import_react = require("react");
|
|
31
|
+
const StageContext = (0, import_react.createContext)(null);
|
|
32
|
+
const UNSEEDED = { hasHarness: false, harness: void 0, seeded: void 0 };
|
|
33
|
+
function useSeeded() {
|
|
34
|
+
return (0, import_react.useContext)(StageContext)?.seeded;
|
|
35
|
+
}
|
|
36
|
+
function useHarness() {
|
|
37
|
+
const stage = (0, import_react.useContext)(StageContext);
|
|
38
|
+
if (!stage?.hasHarness) {
|
|
39
|
+
throw new Error("This fixture needs the harness: export a seed from its fixture module, and pass a harness to the bench.");
|
|
40
|
+
}
|
|
41
|
+
return stage.harness;
|
|
42
|
+
}
|
|
43
|
+
function useInputs() {
|
|
44
|
+
return (0, import_react.useContext)(StageContext)?.inputs ?? {};
|
|
45
|
+
}
|
|
46
|
+
function createHarnessSession(getHarness) {
|
|
47
|
+
let opened = null;
|
|
48
|
+
const open = (harness) => {
|
|
49
|
+
opened ??= Promise.resolve(harness.open()).catch((error) => {
|
|
50
|
+
opened = null;
|
|
51
|
+
throw error;
|
|
52
|
+
});
|
|
53
|
+
return opened;
|
|
54
|
+
};
|
|
55
|
+
return {
|
|
56
|
+
async prepare(fixture) {
|
|
57
|
+
if (!fixture.seed)
|
|
58
|
+
return UNSEEDED;
|
|
59
|
+
const harness = getHarness();
|
|
60
|
+
if (!harness)
|
|
61
|
+
return { hasHarness: false, harness: void 0, seeded: await fixture.seed(void 0) };
|
|
62
|
+
const instance = await open(harness);
|
|
63
|
+
await harness.reset?.(instance);
|
|
64
|
+
return { hasHarness: true, harness: instance, seeded: await fixture.seed(instance) };
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
let seedQueue = Promise.resolve();
|
|
69
|
+
function useStage(fixture, run, harness) {
|
|
70
|
+
const harnessRef = (0, import_react.useRef)(harness);
|
|
71
|
+
harnessRef.current = harness;
|
|
72
|
+
const session = (0, import_react.useMemo)(() => createHarnessSession(() => harnessRef.current), []);
|
|
73
|
+
const key = fixture ? `${fixture.id}#${run}` : null;
|
|
74
|
+
const [settled, setSettled] = (0, import_react.useState)(null);
|
|
75
|
+
(0, import_react.useEffect)(() => {
|
|
76
|
+
if (!fixture?.seed || key === null)
|
|
77
|
+
return;
|
|
78
|
+
let alive = true;
|
|
79
|
+
seedQueue = seedQueue.then(async () => {
|
|
80
|
+
if (!alive)
|
|
81
|
+
return;
|
|
82
|
+
try {
|
|
83
|
+
const prepared = await session.prepare(fixture);
|
|
84
|
+
if (alive)
|
|
85
|
+
setSettled({ key, prepared });
|
|
86
|
+
} catch (error) {
|
|
87
|
+
if (alive)
|
|
88
|
+
setSettled({ key, message: String(error) });
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
return () => {
|
|
92
|
+
alive = false;
|
|
93
|
+
};
|
|
94
|
+
}, [fixture, key, session]);
|
|
95
|
+
if (!fixture || key === null)
|
|
96
|
+
return { kind: "empty" };
|
|
97
|
+
if (!fixture.seed)
|
|
98
|
+
return { kind: "ready", fixture, key, prepared: UNSEEDED };
|
|
99
|
+
if (settled?.key !== key)
|
|
100
|
+
return { kind: "loading", fixture };
|
|
101
|
+
if ("message" in settled)
|
|
102
|
+
return { kind: "failed", fixture, message: settled.message };
|
|
103
|
+
return { kind: "ready", fixture, key, prepared: settled.prepared };
|
|
104
|
+
}
|
|
105
|
+
function StageBody({ stage, inputs, mode, wrapper: Wrapper = Passthrough, renderLoading, renderError }) {
|
|
106
|
+
const context = (0, import_react.useMemo)(() => stage.kind === "ready" ? { ...stage.prepared, inputs } : null, [stage, inputs]);
|
|
107
|
+
return (0, import_jsx_runtime.jsx)(FixtureBoundary, { renderError, children: (0, import_jsx_runtime.jsx)(Wrapper, { mode, children: stage.kind === "loading" ? renderLoading() : stage.kind === "failed" ? renderError(stage.message) : (0, import_jsx_runtime.jsx)(StageContext.Provider, { value: context, children: (0, import_jsx_runtime.jsx)(FixtureBoundary, { renderError, children: (0, import_jsx_runtime.jsx)(stage.fixture.Component, { ...inputs }) }, stage.key) }) }) });
|
|
108
|
+
}
|
|
109
|
+
function Passthrough({ children }) {
|
|
110
|
+
return (0, import_jsx_runtime.jsx)(import_react.Fragment, { children });
|
|
111
|
+
}
|
|
112
|
+
class FixtureBoundary extends import_react.Component {
|
|
113
|
+
state = { message: null };
|
|
114
|
+
static getDerivedStateFromError(error) {
|
|
115
|
+
return { message: String(error) };
|
|
116
|
+
}
|
|
117
|
+
render() {
|
|
118
|
+
return this.state.message !== null ? this.props.renderError(this.state.message) : this.props.children;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
122
|
+
0 && (module.exports = {
|
|
123
|
+
StageBody,
|
|
124
|
+
createHarnessSession,
|
|
125
|
+
useHarness,
|
|
126
|
+
useInputs,
|
|
127
|
+
useSeeded,
|
|
128
|
+
useStage
|
|
129
|
+
});
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var viewports_exports = {};
|
|
20
|
+
__export(viewports_exports, {
|
|
21
|
+
DEFAULT_VIEWPORTS: () => DEFAULT_VIEWPORTS,
|
|
22
|
+
FULL_VIEWPORT: () => FULL_VIEWPORT,
|
|
23
|
+
RESPONSIVE_VIEWPORT: () => RESPONSIVE_VIEWPORT,
|
|
24
|
+
formatViewportSize: () => formatViewportSize,
|
|
25
|
+
parseViewportSize: () => parseViewportSize
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(viewports_exports);
|
|
28
|
+
const FULL_VIEWPORT = "full";
|
|
29
|
+
const RESPONSIVE_VIEWPORT = "responsive";
|
|
30
|
+
const DEFAULT_VIEWPORTS = {
|
|
31
|
+
phone: { width: 390, height: 844 },
|
|
32
|
+
tablet: { width: 820, height: 1180 },
|
|
33
|
+
laptop: { width: 1280, height: 800 }
|
|
34
|
+
};
|
|
35
|
+
function parseViewportSize(value) {
|
|
36
|
+
const match = /^(\d+)x(\d+)$/.exec(value);
|
|
37
|
+
return match ? { width: Number(match[1]), height: Number(match[2]) } : null;
|
|
38
|
+
}
|
|
39
|
+
function formatViewportSize(size) {
|
|
40
|
+
return `${size.width}x${size.height}`;
|
|
41
|
+
}
|
|
42
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
43
|
+
0 && (module.exports = {
|
|
44
|
+
DEFAULT_VIEWPORTS,
|
|
45
|
+
FULL_VIEWPORT,
|
|
46
|
+
RESPONSIVE_VIEWPORT,
|
|
47
|
+
formatViewportSize,
|
|
48
|
+
parseViewportSize
|
|
49
|
+
});
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var ControlBar_exports = {};
|
|
20
|
+
__export(ControlBar_exports, {
|
|
21
|
+
ControlBar: () => ControlBar
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(ControlBar_exports);
|
|
24
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
25
|
+
var import_viewports = require("../core/viewports");
|
|
26
|
+
var import_FixturePicker = require("./FixturePicker");
|
|
27
|
+
function ControlBar({ bench }) {
|
|
28
|
+
const { prefs, updatePrefs, mode } = bench;
|
|
29
|
+
return (0, import_jsx_runtime.jsxs)("div", { className: "uib-bar", "data-testid": "control-bar", children: [(0, import_jsx_runtime.jsxs)("span", { className: "uib-mark", children: ["UI", (0, import_jsx_runtime.jsx)("span", { className: "uib-mark-rest", children: " Bench" })] }), (0, import_jsx_runtime.jsx)(import_FixturePicker.FixturePicker, { fixtures: bench.fixtures, selected: bench.selected, onSelect: bench.select }), (0, import_jsx_runtime.jsx)("span", { className: "uib-spacer" }), (0, import_jsx_runtime.jsxs)("span", { className: "uib-select", children: [(0, import_jsx_runtime.jsxs)("select", { className: "uib-box", value: bench.viewport, "aria-label": "Viewport", "data-testid": "viewport", onChange: (event) => bench.setViewport(event.target.value), children: [(0, import_jsx_runtime.jsx)("option", { value: import_viewports.FULL_VIEWPORT, children: "full" }), (0, import_jsx_runtime.jsx)("option", { value: import_viewports.RESPONSIVE_VIEWPORT, children: "responsive" }), Object.entries(bench.viewports).map(([name, size]) => (0, import_jsx_runtime.jsxs)("option", { value: name, children: [name, " ", size.width, "\xD7", size.height] }, name))] }), (0, import_jsx_runtime.jsx)("span", { className: "uib-tri" })] }), (0, import_jsx_runtime.jsx)("button", { type: "button", className: "uib-box", "aria-pressed": prefs.inputsOpen, "data-testid": "toggle-inputs", onClick: () => updatePrefs({ inputsOpen: !prefs.inputsOpen }), children: "inputs" }), bench.canReseed ? (0, import_jsx_runtime.jsx)("button", { type: "button", className: "uib-box", "aria-label": "Reseed the fixture", "data-testid": "reseed", onClick: bench.reseed, children: "reseed" }) : null, (0, import_jsx_runtime.jsx)("button", { type: "button", className: "uib-box", "aria-label": mode === "light" ? "Switch to dark theme" : "Switch to light theme", "data-testid": "toggle-theme", onClick: bench.toggleTheme, children: mode === "light" ? "dark" : "light" }), (0, import_jsx_runtime.jsx)("button", { type: "button", className: "uib-box", "aria-label": prefs.edge === "bottom" ? "Move control bar to top" : "Move control bar to bottom", "data-testid": "bar-flip", onClick: () => updatePrefs({ edge: prefs.edge === "bottom" ? "top" : "bottom" }), children: (0, import_jsx_runtime.jsx)("span", { className: "uib-tri" }) }), (0, import_jsx_runtime.jsx)("button", { type: "button", className: "uib-box uib-box-accent", "aria-label": "Minimise control bar", "data-testid": "bar-minimise", onClick: () => updatePrefs({ minimised: true }), children: "\u2212" })] });
|
|
30
|
+
}
|
|
31
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
32
|
+
0 && (module.exports = {
|
|
33
|
+
ControlBar
|
|
34
|
+
});
|