@jungherz-de/glasskit-elements 1.23.0 → 1.25.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/CHANGELOG.md +32 -1
- package/README.md +18 -4
- package/SKILL.md +13 -3
- package/dist/components/base.js +38 -13
- package/dist/glasskit-elements.esm.js +42 -17
- package/dist/glasskit-elements.js +42 -17
- package/dist/glasskit-elements.min.js +1 -1
- package/package.json +3 -3
- package/src/base.js +38 -13
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jungherz-de/glasskit-elements",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.25.0",
|
|
4
4
|
"description": "Vanilla JavaScript Web Components wrapping the GlassKit CSS glassmorphism library",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://glasskit-elements.jungherz.com",
|
|
@@ -49,10 +49,10 @@
|
|
|
49
49
|
"vanilla-js"
|
|
50
50
|
],
|
|
51
51
|
"peerDependencies": {
|
|
52
|
-
"@jungherz-de/glasskit": ">=1.
|
|
52
|
+
"@jungherz-de/glasskit": ">=1.25.0"
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
|
-
"@jungherz-de/glasskit": "^1.
|
|
55
|
+
"@jungherz-de/glasskit": "^1.25.0",
|
|
56
56
|
"@rollup/plugin-node-resolve": "^15.0.0",
|
|
57
57
|
"@rollup/plugin-terser": "^0.4.0",
|
|
58
58
|
"rollup": "^4.0.0"
|
package/src/base.js
CHANGED
|
@@ -53,16 +53,16 @@ function syncDefaultTokens() {
|
|
|
53
53
|
|
|
54
54
|
injectDefaultTokens();
|
|
55
55
|
|
|
56
|
-
// ── Global Theme &
|
|
57
|
-
// Single MutationObserver that watches data-theme
|
|
58
|
-
// and notifies all GlkElement instances.
|
|
56
|
+
// ── Global Theme, Density & Surface Sync ──
|
|
57
|
+
// Single MutationObserver that watches data-theme, data-density and
|
|
58
|
+
// data-surface on <html> and notifies all GlkElement instances.
|
|
59
59
|
//
|
|
60
|
-
// The density tokens themselves arrive from <html> by
|
|
61
|
-
// other token: GlassKit's [data-density="compact"]
|
|
62
|
-
//
|
|
63
|
-
//
|
|
64
|
-
//
|
|
65
|
-
// there.
|
|
60
|
+
// The density and surface tokens themselves arrive from <html> by
|
|
61
|
+
// inheritance, like every other token: GlassKit's [data-density="compact"]
|
|
62
|
+
// and [data-surface="solid"] presets are part of tokensCss, not of the
|
|
63
|
+
// components sheet. The wrapper mirrors the attributes anyway, as it mirrors
|
|
64
|
+
// data-theme — a rule keyed on one (a component rule, a subclass's
|
|
65
|
+
// hostStyles) can match inside a shadow root only on an element there.
|
|
66
66
|
|
|
67
67
|
const instances = new Set();
|
|
68
68
|
|
|
@@ -75,6 +75,11 @@ function getCurrentDensity() {
|
|
|
75
75
|
return document.documentElement.getAttribute('data-density');
|
|
76
76
|
}
|
|
77
77
|
|
|
78
|
+
/** The surface preset on <html> (since 1.24.0), or null, like the density. */
|
|
79
|
+
function getCurrentSurface() {
|
|
80
|
+
return document.documentElement.getAttribute('data-surface');
|
|
81
|
+
}
|
|
82
|
+
|
|
78
83
|
function syncAllThemes() {
|
|
79
84
|
const theme = getCurrentTheme();
|
|
80
85
|
for (const instance of instances) {
|
|
@@ -89,15 +94,23 @@ function syncAllDensities() {
|
|
|
89
94
|
}
|
|
90
95
|
}
|
|
91
96
|
|
|
97
|
+
function syncAllSurfaces() {
|
|
98
|
+
const surface = getCurrentSurface();
|
|
99
|
+
for (const instance of instances) {
|
|
100
|
+
instance._syncSurface(surface);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
92
104
|
if (typeof window !== 'undefined' && typeof MutationObserver !== 'undefined') {
|
|
93
105
|
const observer = new MutationObserver(records => {
|
|
94
106
|
if (records.some(r => r.attributeName === 'data-theme')) syncAllThemes();
|
|
95
107
|
if (records.some(r => r.attributeName === 'data-density')) syncAllDensities();
|
|
108
|
+
if (records.some(r => r.attributeName === 'data-surface')) syncAllSurfaces();
|
|
96
109
|
if (records.some(r => r.attributeName === DEFAULTS_ATTR)) syncDefaultTokens();
|
|
97
110
|
});
|
|
98
111
|
observer.observe(document.documentElement, {
|
|
99
112
|
attributes: true,
|
|
100
|
-
attributeFilter: ['data-theme', 'data-density', DEFAULTS_ATTR]
|
|
113
|
+
attributeFilter: ['data-theme', 'data-density', 'data-surface', DEFAULTS_ATTR]
|
|
101
114
|
});
|
|
102
115
|
}
|
|
103
116
|
|
|
@@ -235,17 +248,19 @@ export class GlkElement extends HTMLElement {
|
|
|
235
248
|
this._wrapper.className = 'glk-wrapper';
|
|
236
249
|
this._wrapper.setAttribute('data-theme', getCurrentTheme());
|
|
237
250
|
this._syncDensity(getCurrentDensity());
|
|
251
|
+
this._syncSurface(getCurrentSurface());
|
|
238
252
|
this._shadow.appendChild(this._wrapper);
|
|
239
253
|
|
|
240
254
|
this.render();
|
|
241
255
|
if (this.constructor.formAssociated) this._syncDisabled();
|
|
242
256
|
} else {
|
|
243
257
|
// Back in the document. While it was out, the observer did not reach
|
|
244
|
-
// it, so a theme or
|
|
245
|
-
// — the wrapper's data-theme also sets the color-scheme
|
|
246
|
-
// parts inside.
|
|
258
|
+
// it, so a theme, density or surface switched in the meantime is
|
|
259
|
+
// caught up here — the wrapper's data-theme also sets the color-scheme
|
|
260
|
+
// of the native parts inside.
|
|
247
261
|
this._syncTheme(getCurrentTheme());
|
|
248
262
|
this._syncDensity(getCurrentDensity());
|
|
263
|
+
this._syncSurface(getCurrentSurface());
|
|
249
264
|
}
|
|
250
265
|
|
|
251
266
|
// Everything below runs on every connect, not just the first. Moving an
|
|
@@ -315,6 +330,16 @@ export class GlkElement extends HTMLElement {
|
|
|
315
330
|
}
|
|
316
331
|
}
|
|
317
332
|
|
|
333
|
+
/** Mirrors data-surface from <html> (since 1.24.0), like the density. */
|
|
334
|
+
_syncSurface(surface) {
|
|
335
|
+
if (!this._wrapper) return;
|
|
336
|
+
if (surface) {
|
|
337
|
+
this._wrapper.setAttribute('data-surface', surface);
|
|
338
|
+
} else {
|
|
339
|
+
this._wrapper.removeAttribute('data-surface');
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
|
|
318
343
|
/** Subclasses override to build inner DOM inside this._wrapper. */
|
|
319
344
|
render() {}
|
|
320
345
|
|