hyperclayjs 1.22.1 → 1.23.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/README.md +3 -3
- package/package.json +1 -1
- package/src/core/optionVisibility.js +25 -49
- package/src/hyperclay.js +1 -1
package/README.md
CHANGED
|
@@ -60,7 +60,7 @@ import 'hyperclayjs/presets/standard.js';
|
|
|
60
60
|
| autosave | 1.4KB | Auto-save on DOM changes |
|
|
61
61
|
| edit-mode | 1.8KB | Toggle edit mode on hyperclay on/off |
|
|
62
62
|
| edit-mode-helpers | 8.3KB | Admin-only functionality: [edit-mode-input], [edit-mode-resource], [edit-mode-onclick] |
|
|
63
|
-
| option-visibility | 7.
|
|
63
|
+
| option-visibility | 7.1KB | Dynamic show/hide based on ancestor state with option:attribute="value" |
|
|
64
64
|
| persist | 2.4KB | Persist input/select/textarea values to the DOM with [persist] attribute |
|
|
65
65
|
| save-core | 8.9KB | Basic save function only - hyperclay.savePage() |
|
|
66
66
|
| save-system | 13.4KB | CMD+S, [trigger-save] button, savestatus attribute |
|
|
@@ -138,12 +138,12 @@ Essential features for basic editing
|
|
|
138
138
|
|
|
139
139
|
**Modules:** `save-core`, `snapshot`, `save-system`, `edit-mode-helpers`, `toast`, `save-toast`, `export-to-window`, `view-mode-excludes-edit-modules`
|
|
140
140
|
|
|
141
|
-
### Standard (~
|
|
141
|
+
### Standard (~80.8KB)
|
|
142
142
|
Standard feature set for most use cases
|
|
143
143
|
|
|
144
144
|
**Modules:** `save-core`, `snapshot`, `save-system`, `unsaved-warning`, `edit-mode-helpers`, `persist`, `option-visibility`, `event-attrs`, `dom-helpers`, `toast`, `save-toast`, `export-to-window`, `view-mode-excludes-edit-modules`
|
|
145
145
|
|
|
146
|
-
### Everything (~
|
|
146
|
+
### Everything (~217.9KB)
|
|
147
147
|
All available features
|
|
148
148
|
|
|
149
149
|
Includes all available modules across all categories.
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Option Visibility
|
|
2
|
+
* Option Visibility
|
|
3
3
|
*
|
|
4
4
|
* Shows/hides elements based on `option:` and `option-not:` attributes.
|
|
5
5
|
*
|
|
@@ -23,19 +23,19 @@
|
|
|
23
23
|
* </div>
|
|
24
24
|
*
|
|
25
25
|
* HOW IT WORKS:
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
26
|
+
* Uses a single conditional-hide rule per pattern. Elements get `display: none !important`
|
|
27
|
+
* ONLY when they are NOT inside a matching ancestor scope. When the ancestor condition
|
|
28
|
+
* IS met, the hide rule doesn't match, so the author's original display value
|
|
29
|
+
* (flex, grid, block, etc.) applies naturally — no recovery needed.
|
|
30
30
|
*
|
|
31
31
|
* BROWSER SUPPORT:
|
|
32
|
-
* Requires
|
|
32
|
+
* Requires `:is()` and `:not()` with selector lists (~96% of browsers, 2021+).
|
|
33
33
|
* Falls back gracefully - elements remain visible if unsupported.
|
|
34
34
|
*
|
|
35
35
|
* TRADEOFFS:
|
|
36
36
|
* - Pro: Pure CSS after generation, zero JS overhead for toggling
|
|
37
|
-
* - Pro:
|
|
38
|
-
* -
|
|
37
|
+
* - Pro: No @layer or revert-layer — works with any author CSS (layered or unlayered)
|
|
38
|
+
* - Pro: One rule per pattern instead of two
|
|
39
39
|
* - Con: Pipe character `|` cannot be used as a literal value (reserved as OR delimiter)
|
|
40
40
|
*/
|
|
41
41
|
|
|
@@ -78,16 +78,7 @@ const optionVisibility = {
|
|
|
78
78
|
_unsubscribe: null,
|
|
79
79
|
|
|
80
80
|
log(...args) {
|
|
81
|
-
if (this.debug) console.log('[OptionVisibility
|
|
82
|
-
},
|
|
83
|
-
|
|
84
|
-
/**
|
|
85
|
-
* Check if browser supports the layer approach
|
|
86
|
-
*/
|
|
87
|
-
isSupported() {
|
|
88
|
-
return typeof CSS !== 'undefined'
|
|
89
|
-
&& typeof CSS.supports === 'function'
|
|
90
|
-
&& CSS.supports('display', 'revert-layer');
|
|
81
|
+
if (this.debug) console.log('[OptionVisibility]', ...args);
|
|
91
82
|
},
|
|
92
83
|
|
|
93
84
|
/**
|
|
@@ -126,61 +117,51 @@ const optionVisibility = {
|
|
|
126
117
|
},
|
|
127
118
|
|
|
128
119
|
/**
|
|
129
|
-
* Generate CSS rules
|
|
120
|
+
* Generate CSS rules for conditional hiding.
|
|
121
|
+
*
|
|
122
|
+
* Each pattern produces a single rule that hides the element ONLY when
|
|
123
|
+
* it's NOT inside a matching ancestor scope. When the condition IS met,
|
|
124
|
+
* the rule doesn't match, so the author's original display value applies.
|
|
130
125
|
*/
|
|
131
126
|
generateCSS(patterns) {
|
|
132
127
|
if (!patterns.length) return '';
|
|
133
128
|
|
|
134
|
-
|
|
129
|
+
return patterns.map(({ name, rawValue, values, negated }) => {
|
|
135
130
|
const safeName = CSS.escape(name);
|
|
136
131
|
const safeRawValue = CSS.escape(rawValue);
|
|
137
132
|
const prefix = negated ? 'option-not' : 'option';
|
|
138
133
|
const attrSelector = `[${prefix}\\:${safeName}="${safeRawValue}"]`;
|
|
139
134
|
|
|
140
|
-
|
|
141
|
-
const hideRule = `${attrSelector}{display:none!important}`;
|
|
142
|
-
|
|
143
|
-
// Show rule depends on type
|
|
144
|
-
let showRule;
|
|
135
|
+
let scopeSelectors;
|
|
145
136
|
if (negated) {
|
|
146
|
-
// option-not:
|
|
147
|
-
// Uses :not(sel1, sel2) selector list syntax
|
|
137
|
+
// option-not: active when ancestor has attr but NOT any of the values
|
|
148
138
|
const notList = values.map(v => `[${safeName}="${CSS.escape(v)}"]`).join(',');
|
|
149
|
-
|
|
139
|
+
const scope = `[${safeName}]:not(${notList})`;
|
|
140
|
+
scopeSelectors = `${scope},${scope} *`;
|
|
150
141
|
} else {
|
|
151
|
-
// option:
|
|
152
|
-
const
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
showRule = `${showSelectors}{display:revert-layer!important}`;
|
|
142
|
+
// option: active when ancestor has ANY of the values
|
|
143
|
+
const self = values.map(v => `[${safeName}="${CSS.escape(v)}"]`);
|
|
144
|
+
const desc = values.map(v => `[${safeName}="${CSS.escape(v)}"] *`);
|
|
145
|
+
scopeSelectors = [...self, ...desc].join(',');
|
|
156
146
|
}
|
|
157
147
|
|
|
158
|
-
return
|
|
148
|
+
return `${attrSelector}:not(:is(${scopeSelectors})){display:none!important}`;
|
|
159
149
|
}).join('');
|
|
160
|
-
|
|
161
|
-
return `@layer ${STYLE_NAME}{${rules}}`;
|
|
162
150
|
},
|
|
163
151
|
|
|
164
152
|
/**
|
|
165
153
|
* Update the style element with current rules
|
|
166
154
|
*/
|
|
167
155
|
update() {
|
|
168
|
-
if (!this.isSupported()) {
|
|
169
|
-
this.log('Browser lacks revert-layer support, skipping');
|
|
170
|
-
return;
|
|
171
|
-
}
|
|
172
|
-
|
|
173
156
|
try {
|
|
174
157
|
const attributes = this.findOptionAttributes();
|
|
175
158
|
const css = this.generateCSS(attributes);
|
|
176
|
-
// mutations-ignore: This style tag is regenerated on load. Without this,
|
|
177
|
-
// the mutation observer would detect it as a change, delaying the settled signal.
|
|
178
159
|
insertStyles(STYLE_NAME, css, (style) => {
|
|
179
160
|
style.setAttribute('mutations-ignore', '');
|
|
180
161
|
});
|
|
181
162
|
this.log(`Generated ${attributes.length} rules`);
|
|
182
163
|
} catch (error) {
|
|
183
|
-
console.error('[OptionVisibility
|
|
164
|
+
console.error('[OptionVisibility] Error generating rules:', error);
|
|
184
165
|
}
|
|
185
166
|
},
|
|
186
167
|
|
|
@@ -194,11 +175,6 @@ const optionVisibility = {
|
|
|
194
175
|
|
|
195
176
|
this._started = true;
|
|
196
177
|
|
|
197
|
-
if (!this.isSupported()) {
|
|
198
|
-
console.warn('[OptionVisibility:Layer] Browser lacks revert-layer support. Elements will remain visible.');
|
|
199
|
-
return;
|
|
200
|
-
}
|
|
201
|
-
|
|
202
178
|
this.update();
|
|
203
179
|
|
|
204
180
|
// selectorFilter only triggers on option:/option-not: attribute changes (new patterns).
|
package/src/hyperclay.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* DO NOT EDIT THIS FILE DIRECTLY — it is generated from build/hyperclay.template.js
|
|
3
3
|
*
|
|
4
|
-
* HyperclayJS v1.
|
|
4
|
+
* HyperclayJS v1.23.0 - Minimal Browser-Native Loader
|
|
5
5
|
*
|
|
6
6
|
* Modules auto-init when imported (no separate init call needed).
|
|
7
7
|
* Include `export-to-window` feature to export to window.hyperclay.
|