@stacksjs/components 0.2.865 → 0.2.868
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/AppearancePicker-61r20jpp.stx +351 -0
- package/dist/{Button-sebyqeva.stx → Button-pg8mzsq3.stx} +249 -0
- package/dist/Checkbox-52mhrzkz.stx +417 -0
- package/dist/ColorSwatches-ecfxphjy.stx +287 -0
- package/dist/{NumberInput-axcfj9y8.stx → NumberInput-e2afxyh3.stx} +303 -0
- package/dist/{PasswordInput-8m3109tp.stx → PasswordInput-n2ven456.stx} +315 -0
- package/dist/RadioGroup-ps9kn22f.stx +329 -0
- package/dist/RadioGroupOption-6hyy1bvb.stx +246 -0
- package/dist/{SegmentedControl-fr69q4gb.stx → SegmentedControl-7q0t8c9s.stx} +170 -1
- package/dist/{Select-1cnqbcmg.stx → Select-ygzchedx.stx} +266 -0
- package/dist/SettingsGroup-dkae46k5.stx +200 -0
- package/dist/SettingsPane-jbd1gbdt.stx +50 -0
- package/dist/SettingsPaneHeader-f0cvkqs7.stx +188 -0
- package/dist/SettingsRow-4cxbsf1q.stx +424 -0
- package/dist/SettingsSidebarGroup-p2ygv5yy.stx +108 -0
- package/dist/SettingsSidebarItem-x8fsn3w5.stx +228 -0
- package/dist/SettingsWindow-mm490ymt.stx +537 -0
- package/dist/Slider-j59dgw1c.stx +377 -0
- package/dist/Switch-ga9ap8n8.stx +374 -0
- package/dist/{TextInput-tsvfwxmg.stx → TextInput-tyqzz3jy.stx} +325 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +35 -24
- package/dist/preview-frame/preview-frame.js +58 -2
- package/dist/settings/settings.js +757 -0
- package/dist/ui/appearance-picker/AppearancePicker.d.ts +12 -0
- package/dist/ui/appearance-picker/index.d.ts +16 -0
- package/dist/ui/button/Button.d.ts +24 -1
- package/dist/ui/button/index.d.ts +1 -0
- package/dist/ui/checkbox/Checkbox.d.ts +9 -1
- package/dist/ui/checkbox/index.d.ts +1 -0
- package/dist/ui/color-swatches/ColorSwatches.d.ts +26 -0
- package/dist/ui/color-swatches/index.d.ts +18 -0
- package/dist/ui/input/NumberInput.d.ts +11 -1
- package/dist/ui/input/PasswordInput.d.ts +9 -1
- package/dist/ui/input/TextInput.d.ts +12 -1
- package/dist/ui/input/index.d.ts +7 -3
- package/dist/ui/preview-frame/core.d.ts +22 -0
- package/dist/ui/preview-frame/view.d.ts +9 -0
- package/dist/ui/radio-group/RadioGroup.d.ts +14 -2
- package/dist/ui/radio-group/RadioGroupOption.d.ts +6 -1
- package/dist/ui/radio-group/index.d.ts +2 -0
- package/dist/ui/segmented-control/SegmentedControl.d.ts +9 -1
- package/dist/ui/segmented-control/index.d.ts +1 -0
- package/dist/ui/select/Select.d.ts +10 -1
- package/dist/ui/select/index.d.ts +1 -0
- package/dist/ui/settings/SettingsGroup.d.ts +30 -0
- package/dist/ui/settings/SettingsPane.d.ts +19 -0
- package/dist/ui/settings/SettingsPaneHeader.d.ts +20 -0
- package/dist/ui/settings/SettingsRow.d.ts +53 -0
- package/dist/ui/settings/SettingsSidebarGroup.d.ts +11 -0
- package/dist/ui/settings/SettingsSidebarItem.d.ts +22 -0
- package/dist/ui/settings/SettingsWindow.d.ts +22 -0
- package/dist/ui/settings/core.d.ts +146 -0
- package/dist/ui/settings/index.d.ts +73 -0
- package/dist/ui/settings/settings.d.ts +8 -0
- package/dist/ui/settings/view.d.ts +36 -0
- package/dist/ui/slider/Slider.d.ts +24 -0
- package/dist/ui/slider/core.d.ts +33 -0
- package/dist/ui/slider/index.d.ts +20 -0
- package/dist/ui/switch/Switch.d.ts +10 -1
- package/dist/ui/switch/index.d.ts +2 -1
- package/dist/utils/mac-theme.d.ts +24 -0
- package/package.json +8 -3
- package/src/index.ts +6 -0
- package/src/ui/appearance-picker/AppearancePicker.stx +351 -0
- package/src/ui/appearance-picker/README.md +61 -0
- package/src/ui/appearance-picker/index.ts +22 -0
- package/src/ui/button/Button.stx +249 -0
- package/src/ui/button/README.md +21 -0
- package/src/ui/button/index.ts +8 -0
- package/src/ui/checkbox/Checkbox.stx +275 -0
- package/src/ui/checkbox/index.ts +2 -0
- package/src/ui/color-swatches/ColorSwatches.stx +287 -0
- package/src/ui/color-swatches/README.md +66 -0
- package/src/ui/color-swatches/index.ts +25 -0
- package/src/ui/input/NumberInput.stx +303 -0
- package/src/ui/input/PasswordInput.stx +315 -0
- package/src/ui/input/TextInput.stx +325 -0
- package/src/ui/input/index.ts +9 -3
- package/src/ui/preview-frame/README.md +16 -14
- package/src/ui/preview-frame/core.ts +50 -0
- package/src/ui/preview-frame/index.ts +4 -4
- package/src/ui/preview-frame/view.ts +61 -4
- package/src/ui/radio-group/README.md +17 -0
- package/src/ui/radio-group/RadioGroup.stx +184 -6
- package/src/ui/radio-group/RadioGroupOption.stx +178 -2
- package/src/ui/radio-group/index.ts +4 -0
- package/src/ui/segmented-control/SegmentedControl.stx +170 -1
- package/src/ui/segmented-control/index.ts +2 -0
- package/src/ui/select/README.md +12 -0
- package/src/ui/select/Select.stx +266 -0
- package/src/ui/select/index.ts +2 -0
- package/src/ui/settings/README.md +221 -0
- package/src/ui/settings/SettingsGroup.stx +200 -0
- package/src/ui/settings/SettingsPane.stx +50 -0
- package/src/ui/settings/SettingsPaneHeader.stx +188 -0
- package/src/ui/settings/SettingsRow.stx +424 -0
- package/src/ui/settings/SettingsSidebarGroup.stx +108 -0
- package/src/ui/settings/SettingsSidebarItem.stx +228 -0
- package/src/ui/settings/SettingsWindow.stx +537 -0
- package/src/ui/settings/core.ts +359 -0
- package/src/ui/settings/index.ts +111 -0
- package/src/ui/settings/settings.ts +8 -0
- package/src/ui/settings/view.ts +740 -0
- package/src/ui/slider/README.md +91 -0
- package/src/ui/slider/Slider.stx +377 -0
- package/src/ui/slider/core.ts +120 -0
- package/src/ui/slider/index.ts +34 -0
- package/src/ui/switch/README.md +11 -0
- package/src/ui/switch/Switch.stx +217 -0
- package/src/ui/switch/index.ts +4 -1
- package/src/utils/mac-theme.ts +95 -0
- package/dist/Checkbox-80myyzzm.stx +0 -142
- package/dist/RadioGroup-smqcqgds.stx +0 -151
- package/dist/RadioGroupOption-twcw1b2a.stx +0 -70
- package/dist/Switch-s8yf2rvm.stx +0 -157
|
@@ -70,10 +70,29 @@ var HEAD_OPEN = /<head(?:\s[^>]*)?>/i;
|
|
|
70
70
|
var HTML_OPEN = /<html(?:\s[^>]*)?>/i;
|
|
71
71
|
var HAS_BASE = /<base[\s>]/i;
|
|
72
72
|
var HAS_COLOR_SCHEME = /<meta[^>]+name\s*=\s*["']?color-scheme/i;
|
|
73
|
+
var SCHEME_FEATURE = /\(\s*prefers-color-scheme\s*:\s*(light|dark)\s*\)/gi;
|
|
74
|
+
var STYLE_OR_SCRIPT = /(<(style|script)\b[^>]*>)([\s\S]*?)(<\/\2\s*>)/gi;
|
|
75
|
+
var MEDIA_ATTRIBUTE = /(\smedia\s*=\s*)("[^"]*"|'[^']*')/gi;
|
|
76
|
+
var ALWAYS = "(min-width: 0px)";
|
|
77
|
+
var NEVER = "(max-width: 0px)";
|
|
78
|
+
function forceColorScheme(html, scheme) {
|
|
79
|
+
const settle = (text) => text.replace(SCHEME_FEATURE, (_, asked) => asked.toLowerCase() === scheme ? ALWAYS : NEVER);
|
|
80
|
+
const rewritten = html.replace(STYLE_OR_SCRIPT, (_, open, _tag, body, close) => open + settle(body) + close).replace(MEDIA_ATTRIBUTE, (_, name, value) => name + settle(value));
|
|
81
|
+
const rule = `<style data-stx-preview-scheme>:root{color-scheme:${scheme} !important}</style>`;
|
|
82
|
+
if (HEAD_OPEN.test(rewritten))
|
|
83
|
+
return rewritten.replace(HEAD_OPEN, (match) => match + rule);
|
|
84
|
+
if (HTML_OPEN.test(rewritten))
|
|
85
|
+
return rewritten.replace(HTML_OPEN, (match) => `${match}<head>${rule}</head>`);
|
|
86
|
+
return rule + rewritten;
|
|
87
|
+
}
|
|
73
88
|
function escapeHtml(text) {
|
|
74
89
|
return text.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
|
|
75
90
|
}
|
|
76
91
|
function buildDocument(html, options = {}) {
|
|
92
|
+
const built = wrapDocument(html, options);
|
|
93
|
+
return options.forceScheme ? forceColorScheme(built, options.forceScheme) : built;
|
|
94
|
+
}
|
|
95
|
+
function wrapDocument(html, options) {
|
|
77
96
|
const source = html == null ? "" : String(html);
|
|
78
97
|
const base = '<base target="_blank">';
|
|
79
98
|
if (!HAS_DOCUMENT.test(source)) {
|
|
@@ -98,6 +117,29 @@ function stepViewport(name, direction) {
|
|
|
98
117
|
}
|
|
99
118
|
// src/ui/preview-frame/view.ts
|
|
100
119
|
var STAGE_PADDING = 16;
|
|
120
|
+
var PREFERS_DARK = "(prefers-color-scheme: dark)";
|
|
121
|
+
var framesFollow;
|
|
122
|
+
function framePassesColorScheme() {
|
|
123
|
+
if (framesFollow !== undefined)
|
|
124
|
+
return framesFollow;
|
|
125
|
+
try {
|
|
126
|
+
if (typeof matchMedia !== "function" || !document.body)
|
|
127
|
+
return true;
|
|
128
|
+
const systemDark = matchMedia(PREFERS_DARK).matches;
|
|
129
|
+
const probe = document.createElement("iframe");
|
|
130
|
+
probe.setAttribute("aria-hidden", "true");
|
|
131
|
+
probe.tabIndex = -1;
|
|
132
|
+
probe.style.cssText = `position:absolute;width:1px;height:1px;border:0;opacity:0;pointer-events:none;color-scheme:${systemDark ? "light" : "dark"}`;
|
|
133
|
+
document.body.appendChild(probe);
|
|
134
|
+
probe.offsetWidth;
|
|
135
|
+
const seen = probe.contentWindow?.matchMedia?.(PREFERS_DARK).matches;
|
|
136
|
+
probe.remove();
|
|
137
|
+
framesFollow = typeof seen === "boolean" ? seen !== systemDark : true;
|
|
138
|
+
} catch {
|
|
139
|
+
framesFollow = true;
|
|
140
|
+
}
|
|
141
|
+
return framesFollow;
|
|
142
|
+
}
|
|
101
143
|
|
|
102
144
|
class PreviewFrameView {
|
|
103
145
|
root;
|
|
@@ -114,6 +156,7 @@ class PreviewFrameView {
|
|
|
114
156
|
viewport;
|
|
115
157
|
scale = 1;
|
|
116
158
|
frame = null;
|
|
159
|
+
written;
|
|
117
160
|
stage;
|
|
118
161
|
device;
|
|
119
162
|
observer = null;
|
|
@@ -188,7 +231,10 @@ class PreviewFrameView {
|
|
|
188
231
|
if (next === this.scheme)
|
|
189
232
|
return;
|
|
190
233
|
this.scheme = next;
|
|
191
|
-
this.
|
|
234
|
+
if (this.schemeToWrite() !== this.written)
|
|
235
|
+
this.load();
|
|
236
|
+
else
|
|
237
|
+
this.applyScheme();
|
|
192
238
|
this.reflect();
|
|
193
239
|
this.callbacks.onScheme?.(this.getState());
|
|
194
240
|
}
|
|
@@ -232,6 +278,13 @@ class PreviewFrameView {
|
|
|
232
278
|
return "light";
|
|
233
279
|
return typeof matchMedia === "function" && matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light";
|
|
234
280
|
}
|
|
281
|
+
schemeToWrite() {
|
|
282
|
+
if (framePassesColorScheme())
|
|
283
|
+
return;
|
|
284
|
+
if (this.scheme === "auto" && !this.root.closest(".dark, .light"))
|
|
285
|
+
return;
|
|
286
|
+
return this.effectiveScheme();
|
|
287
|
+
}
|
|
235
288
|
load() {
|
|
236
289
|
const frame = document.createElement("iframe");
|
|
237
290
|
frame.setAttribute("sandbox", sandboxValue({ scripts: this.scripts, forms: this.forms }));
|
|
@@ -243,7 +296,8 @@ class PreviewFrameView {
|
|
|
243
296
|
if (frame === this.frame)
|
|
244
297
|
this.callbacks.onLoad?.(this.getState());
|
|
245
298
|
});
|
|
246
|
-
|
|
299
|
+
this.written = this.schemeToWrite();
|
|
300
|
+
frame.srcdoc = buildDocument(this.html, { title: this.title, forceScheme: this.written });
|
|
247
301
|
this.frame?.remove();
|
|
248
302
|
this.frame = frame;
|
|
249
303
|
this.applyScheme();
|
|
@@ -348,6 +402,8 @@ export {
|
|
|
348
402
|
declaresColorScheme,
|
|
349
403
|
describeViewport,
|
|
350
404
|
fitScale,
|
|
405
|
+
forceColorScheme,
|
|
406
|
+
framePassesColorScheme,
|
|
351
407
|
isIsolatingSandbox,
|
|
352
408
|
normalizeScheme,
|
|
353
409
|
resolveViewport,
|