stimeo-ui 0.16.0 → 0.17.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +31 -0
- data/README.md +8 -1
- data/dist/cable/index.js +363 -436
- data/dist/controllers/accordion_controller.js +166 -55
- data/dist/controllers/alert_dialog_controller.js +862 -221
- data/dist/controllers/announcer_controller.js +135 -198
- data/dist/controllers/aspect_ratio_controller.js +0 -10
- data/dist/controllers/auto_submit_controller.js +271 -127
- data/dist/controllers/avatar_controller.js +171 -105
- data/dist/controllers/breadcrumb_controller.js +0 -130
- data/dist/controllers/bulk_select_controller.js +262 -52
- data/dist/controllers/calendar_controller.js +175 -209
- data/dist/controllers/carousel_controller.js +461 -399
- data/dist/controllers/character_counter_controller.js +246 -156
- data/dist/controllers/checkbox_controller.js +32 -74
- data/dist/controllers/clipboard_controller.js +168 -147
- data/dist/controllers/collapsible_controller.js +301 -120
- data/dist/controllers/color_picker_controller.js +149 -139
- data/dist/controllers/combobox_controller.js +360 -133
- data/dist/controllers/command_palette_controller.js +970 -358
- data/dist/controllers/conditional_fields_controller.js +166 -124
- data/dist/controllers/confirm_controller.js +939 -248
- data/dist/controllers/context_menu_controller.js +256 -128
- data/dist/controllers/count_up_controller.js +73 -21
- data/dist/controllers/countdown_controller.js +183 -148
- data/dist/controllers/currency_input_controller.js +134 -158
- data/dist/controllers/data_grid_controller.js +114 -186
- data/dist/controllers/date_range_picker_controller.js +288 -206
- data/dist/controllers/dialog_controller.js +858 -223
- data/dist/controllers/direct_upload_controller.js +73 -153
- data/dist/controllers/dirty_form_controller.js +14 -48
- data/dist/controllers/dismissible_controller.js +175 -21
- data/dist/controllers/drawer_controller.js +933 -341
- data/dist/controllers/dropdown_controller.js +312 -82
- data/dist/controllers/editable_controller.js +158 -68
- data/dist/controllers/empty_state_controller.js +67 -53
- data/dist/controllers/file_dropzone_controller.js +311 -207
- data/dist/controllers/filter_controller.js +67 -39
- data/dist/controllers/flash_controller.js +172 -314
- data/dist/controllers/focus_controller.js +654 -240
- data/dist/controllers/form_field_controller.js +147 -132
- data/dist/controllers/form_validation_controller.js +13 -86
- data/dist/controllers/frame_loading_controller.js +264 -213
- data/dist/controllers/highlight_controller.js +107 -75
- data/dist/controllers/hover_card_controller.js +309 -118
- data/dist/controllers/idle_controller.js +267 -101
- data/dist/controllers/input_mask_controller.js +71 -72
- data/dist/controllers/intersection_controller.js +147 -106
- data/dist/controllers/lazy_frame_controller.js +9 -65
- data/dist/controllers/listbox_controller.js +306 -204
- data/dist/controllers/local_time_controller.js +54 -64
- data/dist/controllers/masonry_controller.js +70 -93
- data/dist/controllers/menu_controller.js +214 -156
- data/dist/controllers/menubar_controller.js +170 -329
- data/dist/controllers/meter_controller.js +151 -67
- data/dist/controllers/multi_select_controller.js +593 -358
- data/dist/controllers/navigation_menu_controller.js +124 -232
- data/dist/controllers/nested_form_controller.js +352 -182
- data/dist/controllers/network_status_controller.js +242 -54
- data/dist/controllers/number_input_controller.js +320 -263
- data/dist/controllers/optimistic_controller.js +16 -76
- data/dist/controllers/otp_controller.js +198 -193
- data/dist/controllers/overflow_indicator_controller.js +116 -113
- data/dist/controllers/overflow_menu_controller.js +343 -283
- data/dist/controllers/pagination_controller.js +295 -119
- data/dist/controllers/password_reveal_controller.js +389 -121
- data/dist/controllers/password_strength_controller.js +99 -153
- data/dist/controllers/persist_controller.js +237 -103
- data/dist/controllers/pointer_drag_controller.js +185 -165
- data/dist/controllers/popover_controller.js +236 -97
- data/dist/controllers/portal_controller.js +209 -76
- data/dist/controllers/preview_guard_controller.js +232 -116
- data/dist/controllers/progress_controller.js +125 -56
- data/dist/controllers/radio_group_controller.js +117 -137
- data/dist/controllers/range_slider_controller.js +192 -105
- data/dist/controllers/rating_controller.js +418 -207
- data/dist/controllers/read_more_controller.js +134 -63
- data/dist/controllers/reading_progress_controller.js +147 -135
- data/dist/controllers/relative_time_controller.js +145 -110
- data/dist/controllers/{reset_before_cache_controller.js → reset_on_restore_controller.js} +97 -38
- data/dist/controllers/resizable_controller.js +255 -139
- data/dist/controllers/roving_controller.js +39 -84
- data/dist/controllers/scroll_area_controller.js +428 -225
- data/dist/controllers/scroll_restore_controller.js +0 -53
- data/dist/controllers/scroll_visibility_controller.js +395 -145
- data/dist/controllers/scrollspy_controller.js +181 -242
- data/dist/controllers/separator_controller.js +267 -140
- data/dist/controllers/sidebar_controller.js +1023 -386
- data/dist/controllers/skeleton_controller.js +248 -97
- data/dist/controllers/slider_controller.js +159 -79
- data/dist/controllers/smart_sticky_header_controller.js +162 -63
- data/dist/controllers/sortable_controller.js +0 -112
- data/dist/controllers/spinner_controller.js +277 -169
- data/dist/controllers/step_indicator_controller.js +99 -46
- data/dist/controllers/stepper_controller.js +114 -73
- data/dist/controllers/stick_to_bottom_controller.js +262 -138
- data/dist/controllers/sticky_observer_controller.js +214 -49
- data/dist/controllers/submit_once_controller.js +294 -205
- data/dist/controllers/switch_controller.js +33 -60
- data/dist/controllers/tabs_controller.js +35 -29
- data/dist/controllers/tags_input_controller.js +136 -145
- data/dist/controllers/textarea_autosize_controller.js +71 -58
- data/dist/controllers/theme_controller.js +130 -112
- data/dist/controllers/time_picker_controller.js +146 -80
- data/dist/controllers/toast_controller.js +186 -297
- data/dist/controllers/toggle_group_controller.js +95 -136
- data/dist/controllers/toolbar_controller.js +68 -98
- data/dist/controllers/tooltip_controller.js +158 -124
- data/dist/controllers/transition_controller.js +123 -119
- data/dist/controllers/tree_view_controller.js +150 -345
- data/dist/index.js +6370 -9346
- data/dist/positioning/index.js +148 -47
- data/lib/stimeo/ui/version.rb +1 -1
- metadata +3 -3
|
@@ -1,44 +1,7 @@
|
|
|
1
1
|
import { Controller } from '@hotwired/stimulus';
|
|
2
2
|
|
|
3
|
-
// src/controllers/reading_progress_controller.ts
|
|
4
|
-
|
|
5
|
-
// src/utils/before_cache_reset.ts
|
|
6
|
-
var BeforeCacheReset = class _BeforeCacheReset {
|
|
7
|
-
/** Every subscribed instance, iterated by the one shared document listener. */
|
|
8
|
-
static #subscribers = /* @__PURE__ */ new Set();
|
|
9
|
-
/** The shared listener; installed while at least one instance is subscribed. */
|
|
10
|
-
static #onBeforeCache = () => {
|
|
11
|
-
for (const subscriber of _BeforeCacheReset.#subscribers) subscriber.#rewind();
|
|
12
|
-
};
|
|
13
|
-
#rewind;
|
|
14
|
-
/** @param rewind - the pass that returns this controller's state to its initial form. */
|
|
15
|
-
constructor(rewind) {
|
|
16
|
-
this.#rewind = rewind;
|
|
17
|
-
}
|
|
18
|
-
/** Subscribes to `turbo:before-cache`; call from `connect()`. Idempotent. */
|
|
19
|
-
activate() {
|
|
20
|
-
const first = _BeforeCacheReset.#subscribers.size === 0;
|
|
21
|
-
_BeforeCacheReset.#subscribers.add(this);
|
|
22
|
-
if (first) {
|
|
23
|
-
document.addEventListener("turbo:before-cache", _BeforeCacheReset.#onBeforeCache);
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
/** Unsubscribes; call from `disconnect()`. Safe when never subscribed. */
|
|
27
|
-
deactivate() {
|
|
28
|
-
_BeforeCacheReset.#subscribers.delete(this);
|
|
29
|
-
if (_BeforeCacheReset.#subscribers.size > 0) return;
|
|
30
|
-
document.removeEventListener("turbo:before-cache", _BeforeCacheReset.#onBeforeCache);
|
|
31
|
-
}
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
// src/utils/frame_coalescer.ts
|
|
35
3
|
var FrameCoalescer = class {
|
|
36
4
|
#frame = null;
|
|
37
|
-
/**
|
|
38
|
-
* Runs `run` on the next frame, unless a frame is already pending — the first
|
|
39
|
-
* request of a burst wins and the rest are dropped. The pending frame is
|
|
40
|
-
* released before `run`, so `run` may request the next one.
|
|
41
|
-
*/
|
|
42
5
|
schedule(run) {
|
|
43
6
|
if (this.#frame !== null) return;
|
|
44
7
|
this.#frame = requestAnimationFrame(() => {
|
|
@@ -46,14 +9,6 @@ var FrameCoalescer = class {
|
|
|
46
9
|
run();
|
|
47
10
|
});
|
|
48
11
|
}
|
|
49
|
-
/**
|
|
50
|
-
* Drops the pending frame, and reaches the platform only when there is one.
|
|
51
|
-
*
|
|
52
|
-
* There is no handle value that stands for "nothing pending":
|
|
53
|
-
* `cancelAnimationFrame` takes an `unsigned long`, so a negative placeholder
|
|
54
|
-
* arrives as a large positive number that the same allocator can hand out, and
|
|
55
|
-
* an idle cancel would then drop a frame belonging to someone else.
|
|
56
|
-
*/
|
|
57
12
|
cancel() {
|
|
58
13
|
if (this.#frame === null) return;
|
|
59
14
|
cancelAnimationFrame(this.#frame);
|
|
@@ -61,18 +16,15 @@ var FrameCoalescer = class {
|
|
|
61
16
|
}
|
|
62
17
|
};
|
|
63
18
|
|
|
64
|
-
// src/utils/layout_observer.ts
|
|
65
19
|
var LayoutObserver = class {
|
|
66
20
|
#callback;
|
|
67
21
|
#resizeObserverFactory;
|
|
68
22
|
#resizeObserver = null;
|
|
69
23
|
#observingViewport = false;
|
|
70
24
|
#loadContainer = null;
|
|
71
|
-
/** Stable bound handler so add/removeEventListener target the same reference. */
|
|
72
25
|
#handleViewportResize = () => {
|
|
73
26
|
this.#callback();
|
|
74
27
|
};
|
|
75
|
-
/** Stable bound handler for the capture-phase `load`; see {@link observeDescendantLoads}. */
|
|
76
28
|
#handleDescendantLoad = () => {
|
|
77
29
|
this.#callback();
|
|
78
30
|
};
|
|
@@ -80,11 +32,6 @@ var LayoutObserver = class {
|
|
|
80
32
|
this.#callback = callback;
|
|
81
33
|
this.#resizeObserverFactory = options.resizeObserverFactory ?? (typeof ResizeObserver === "undefined" ? null : (cb) => new ResizeObserver(cb));
|
|
82
34
|
}
|
|
83
|
-
/**
|
|
84
|
-
* Starts observing an element's size. Repeated calls observe additional
|
|
85
|
-
* elements through the same shared observer. No-ops when no
|
|
86
|
-
* `ResizeObserver` implementation is available.
|
|
87
|
-
*/
|
|
88
35
|
observe(element) {
|
|
89
36
|
if (!this.#resizeObserverFactory) return;
|
|
90
37
|
if (!this.#resizeObserver) {
|
|
@@ -94,47 +41,28 @@ var LayoutObserver = class {
|
|
|
94
41
|
}
|
|
95
42
|
this.#resizeObserver.observe(element);
|
|
96
43
|
}
|
|
97
|
-
/** Stops observing a single element while leaving any others in place. */
|
|
98
44
|
unobserve(element) {
|
|
99
45
|
this.#resizeObserver?.unobserve(element);
|
|
100
46
|
}
|
|
101
|
-
/** Starts observing viewport resizes. Idempotent: the listener is added once. */
|
|
102
47
|
observeViewport() {
|
|
103
48
|
if (this.#observingViewport) return;
|
|
104
49
|
this.#observingViewport = true;
|
|
105
50
|
window.addEventListener("resize", this.#handleViewportResize);
|
|
106
51
|
}
|
|
107
|
-
/** Stops observing viewport resizes without affecting element observation. */
|
|
108
52
|
unobserveViewport() {
|
|
109
53
|
if (!this.#observingViewport) return;
|
|
110
54
|
this.#observingViewport = false;
|
|
111
55
|
window.removeEventListener("resize", this.#handleViewportResize);
|
|
112
56
|
}
|
|
113
|
-
/**
|
|
114
|
-
* Starts reporting a `load` from anywhere inside `container` — an image or a
|
|
115
|
-
* frame settling changes the box it sits in, and it measures as zero high until
|
|
116
|
-
* then. `load` does not bubble, so the subscription is a capture-phase listener
|
|
117
|
-
* on the container itself and nothing the caller spells.
|
|
118
|
-
*
|
|
119
|
-
* **One container at a time.** A further call moves the observation, so a widget
|
|
120
|
-
* whose content element is swapped at runtime releases the element it let go by
|
|
121
|
-
* naming the new one — there is no second place for the release to drift from.
|
|
122
|
-
*/
|
|
123
57
|
observeDescendantLoads(container) {
|
|
124
58
|
this.unobserveDescendantLoads();
|
|
125
59
|
this.#loadContainer = container;
|
|
126
60
|
container.addEventListener("load", this.#handleDescendantLoad, true);
|
|
127
61
|
}
|
|
128
|
-
/** Stops reporting descendant loads without affecting element or viewport observation. */
|
|
129
62
|
unobserveDescendantLoads() {
|
|
130
63
|
this.#loadContainer?.removeEventListener("load", this.#handleDescendantLoad, true);
|
|
131
64
|
this.#loadContainer = null;
|
|
132
65
|
}
|
|
133
|
-
/**
|
|
134
|
-
* Releases every observation: disconnects the {@link ResizeObserver} and removes
|
|
135
|
-
* the viewport and descendant-load listeners. Safe to call multiple times. Call
|
|
136
|
-
* this from a controller's `disconnect()`.
|
|
137
|
-
*/
|
|
138
66
|
disconnect() {
|
|
139
67
|
this.#resizeObserver?.disconnect();
|
|
140
68
|
this.#resizeObserver = null;
|
|
@@ -143,72 +71,171 @@ var LayoutObserver = class {
|
|
|
143
71
|
}
|
|
144
72
|
};
|
|
145
73
|
|
|
146
|
-
|
|
147
|
-
|
|
74
|
+
function sharedRegistry(key, create) {
|
|
75
|
+
const symbol = Symbol.for(key);
|
|
76
|
+
const scope = globalThis;
|
|
77
|
+
const existing = scope[symbol];
|
|
78
|
+
if (existing !== void 0) return existing;
|
|
79
|
+
const registry = create();
|
|
80
|
+
Object.defineProperty(globalThis, symbol, { value: registry });
|
|
81
|
+
return registry;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
var StylePropertyLease = class _StylePropertyLease {
|
|
85
|
+
static #registry = sharedRegistry(
|
|
86
|
+
"stimeo-ui.style-property-lease.registry.v1",
|
|
87
|
+
() => ({ stacks: /* @__PURE__ */ new WeakMap(), names: /* @__PURE__ */ new Map() })
|
|
88
|
+
);
|
|
148
89
|
#property;
|
|
149
|
-
#
|
|
150
|
-
|
|
151
|
-
constructor(property) {
|
|
90
|
+
#record;
|
|
91
|
+
#held = /* @__PURE__ */ new Set();
|
|
92
|
+
constructor(property, owner) {
|
|
152
93
|
this.#property = property;
|
|
94
|
+
this.#record = `data-${owner}-style-${property}-lease`;
|
|
95
|
+
const names = _StylePropertyLease.#registry.names;
|
|
96
|
+
names.set(property, (names.get(property) ?? /* @__PURE__ */ new Set()).add(this.#record));
|
|
153
97
|
}
|
|
154
|
-
/** Writes or removes the leased declaration while preserving its authored value. */
|
|
155
98
|
write(element, value, priority = "") {
|
|
156
|
-
const
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
writtenValue: value,
|
|
165
|
-
writtenPriority: value === null ? "" : priority
|
|
166
|
-
});
|
|
167
|
-
}
|
|
168
|
-
this.#reflect(element, value, priority);
|
|
99
|
+
const stack = this.#stack(element);
|
|
100
|
+
const hold = this.#take(stack) ?? this.#acquire(element, stack);
|
|
101
|
+
this.#held.add(element);
|
|
102
|
+
const shows = !this.#covered(element, stack, hold);
|
|
103
|
+
hold.writtenValue = value;
|
|
104
|
+
hold.writtenPriority = value === null ? "" : priority;
|
|
105
|
+
this.#mark(element, stack);
|
|
106
|
+
if (shows) this.#show(element, value, hold.writtenPriority);
|
|
169
107
|
}
|
|
170
|
-
/** Returns one lease without overwriting a later consumer declaration. */
|
|
171
108
|
return(element) {
|
|
172
|
-
const
|
|
173
|
-
|
|
174
|
-
this.#
|
|
175
|
-
const
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
109
|
+
const held = this.#held.delete(element);
|
|
110
|
+
const known = _StylePropertyLease.#registry.stacks.get(element)?.has(this.#property);
|
|
111
|
+
const stack = held || known || element.hasAttribute(this.#record) ? this.#stack(element) : [];
|
|
112
|
+
const hold = this.#take(stack);
|
|
113
|
+
if (!hold) return;
|
|
114
|
+
const owns = this.#carries(element, hold) && !this.#covered(element, stack, hold);
|
|
115
|
+
const index = stack.indexOf(hold);
|
|
116
|
+
stack.splice(index, 1);
|
|
117
|
+
const above = stack[index];
|
|
118
|
+
if (above) above.linked &&= hold.linked;
|
|
119
|
+
this.#mark(element, stack);
|
|
120
|
+
if (!owns) return;
|
|
121
|
+
const below = hold.linked ? stack[index - 1] : void 0;
|
|
122
|
+
if (below) this.#show(element, below.writtenValue, below.writtenPriority);
|
|
123
|
+
else this.#show(element, hold.originalValue, hold.originalPriority);
|
|
180
124
|
}
|
|
181
|
-
/** Returns every outstanding declaration lease. */
|
|
182
125
|
returnAll() {
|
|
183
|
-
for (const element of Array.from(this.#
|
|
126
|
+
for (const element of Array.from(this.#held)) this.return(element);
|
|
127
|
+
}
|
|
128
|
+
#recorded(element, name) {
|
|
129
|
+
try {
|
|
130
|
+
const parsed = JSON.parse(element.getAttribute(name) ?? "null");
|
|
131
|
+
if (!Array.isArray(parsed)) return null;
|
|
132
|
+
const [originalValue, originalPriority, writtenValue, writtenPriority, ...rest] = parsed;
|
|
133
|
+
if (typeof originalValue !== "string" || typeof originalPriority !== "string") return null;
|
|
134
|
+
if (typeof writtenValue !== "string" && writtenValue !== null) return null;
|
|
135
|
+
if (typeof writtenPriority !== "string") return null;
|
|
136
|
+
const linked = rest[0] !== false;
|
|
137
|
+
const beneath = linked ? rest : rest.slice(1);
|
|
138
|
+
if (!beneath.every((under) => typeof under === "string")) return null;
|
|
139
|
+
return { originalValue, originalPriority, writtenValue, writtenPriority, linked, beneath };
|
|
140
|
+
} catch {
|
|
141
|
+
return null;
|
|
142
|
+
}
|
|
184
143
|
}
|
|
185
|
-
|
|
186
|
-
|
|
144
|
+
#stack(element) {
|
|
145
|
+
const stacks = _StylePropertyLease.#registry.stacks;
|
|
146
|
+
const byProperty = stacks.get(element) ?? /* @__PURE__ */ new Map();
|
|
147
|
+
stacks.set(element, byProperty);
|
|
148
|
+
const stack = byProperty.get(this.#property) ?? this.#seed(element);
|
|
149
|
+
byProperty.set(this.#property, stack);
|
|
150
|
+
return stack;
|
|
151
|
+
}
|
|
152
|
+
#seed(element) {
|
|
153
|
+
const found = [];
|
|
154
|
+
for (const record of _StylePropertyLease.#registry.names.get(this.#property) ?? []) {
|
|
155
|
+
const read = this.#recorded(element, record);
|
|
156
|
+
if (read) found.push({ ...read, record });
|
|
157
|
+
}
|
|
158
|
+
const depth = ({ beneath }) => beneath.filter((name) => found.some((other) => other.record === name)).length;
|
|
159
|
+
return found.sort((one, other) => depth(one) - depth(other)).map((entry, index) => ({
|
|
160
|
+
lease: null,
|
|
161
|
+
record: entry.record,
|
|
162
|
+
writtenValue: entry.writtenValue,
|
|
163
|
+
writtenPriority: entry.writtenPriority,
|
|
164
|
+
originalValue: entry.originalValue,
|
|
165
|
+
originalPriority: entry.originalPriority,
|
|
166
|
+
linked: entry.linked && index > 0
|
|
167
|
+
}));
|
|
168
|
+
}
|
|
169
|
+
#take(stack) {
|
|
170
|
+
const hold = stack.find((held) => held.lease === this) ?? stack.find((held) => held.lease === null && held.record === this.#record);
|
|
171
|
+
if (hold) hold.lease = this;
|
|
172
|
+
return hold;
|
|
173
|
+
}
|
|
174
|
+
#acquire(element, stack) {
|
|
175
|
+
const top = stack.at(-1);
|
|
176
|
+
const over = top && this.#carries(element, top) ? top : void 0;
|
|
187
177
|
const style = element.style;
|
|
188
|
-
const
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
178
|
+
const hold = {
|
|
179
|
+
lease: this,
|
|
180
|
+
record: this.#record,
|
|
181
|
+
writtenValue: null,
|
|
182
|
+
writtenPriority: "",
|
|
183
|
+
originalValue: over ? over.originalValue : style.getPropertyValue(this.#property),
|
|
184
|
+
originalPriority: over ? over.originalPriority : style.getPropertyPriority(this.#property),
|
|
185
|
+
linked: over !== void 0
|
|
186
|
+
};
|
|
187
|
+
stack.push(hold);
|
|
188
|
+
return hold;
|
|
189
|
+
}
|
|
190
|
+
#covered(element, stack, hold) {
|
|
191
|
+
return stack.slice(stack.indexOf(hold) + 1).some((above) => this.#carries(element, above));
|
|
192
|
+
}
|
|
193
|
+
#mark(element, stack) {
|
|
194
|
+
const records = /* @__PURE__ */ new Map([[this.#record, null]]);
|
|
195
|
+
stack.forEach((hold, index) => {
|
|
196
|
+
const names = stack.slice(0, index).map((under) => under.record);
|
|
197
|
+
const beneath = [...new Set(names.reverse())].filter((name) => name !== hold.record);
|
|
198
|
+
const marker = hold.linked || beneath.length === 0 ? [] : [false];
|
|
199
|
+
const { originalValue, originalPriority, writtenValue, writtenPriority } = hold;
|
|
200
|
+
records.set(
|
|
201
|
+
hold.record,
|
|
202
|
+
(writtenValue ?? "") === originalValue && writtenPriority === originalPriority && beneath.length === 0 && index === stack.length - 1 ? null : JSON.stringify([
|
|
203
|
+
originalValue,
|
|
204
|
+
originalPriority,
|
|
205
|
+
writtenValue,
|
|
206
|
+
writtenPriority,
|
|
207
|
+
...marker,
|
|
208
|
+
...beneath
|
|
209
|
+
])
|
|
210
|
+
);
|
|
211
|
+
});
|
|
212
|
+
for (const [name, recorded] of records) {
|
|
213
|
+
if (element.getAttribute(name) === recorded) continue;
|
|
214
|
+
if (recorded === null) element.removeAttribute(name);
|
|
215
|
+
else element.setAttribute(name, recorded);
|
|
192
216
|
}
|
|
193
|
-
|
|
194
|
-
|
|
217
|
+
}
|
|
218
|
+
#carries(element, hold) {
|
|
219
|
+
return this.#holds(element, hold.writtenValue ?? "", hold.writtenPriority);
|
|
220
|
+
}
|
|
221
|
+
#holds(element, value, priority) {
|
|
222
|
+
const style = element.style;
|
|
223
|
+
return style.getPropertyValue(this.#property) === value && style.getPropertyPriority(this.#property) === priority;
|
|
224
|
+
}
|
|
225
|
+
#show(element, value, priority) {
|
|
226
|
+
if (this.#holds(element, value ?? "", priority)) return;
|
|
227
|
+
if (value === null) element.style.removeProperty(this.#property);
|
|
228
|
+
else element.style.setProperty(this.#property, value, priority);
|
|
195
229
|
}
|
|
196
230
|
};
|
|
197
231
|
|
|
198
|
-
// src/controllers/reading_progress_controller.ts
|
|
199
232
|
var PROGRESS_PROPERTY = "--stimeo--reading-progress";
|
|
200
233
|
var ReadingProgressController = class extends Controller {
|
|
201
234
|
static events = ["change", "complete"];
|
|
202
|
-
|
|
203
|
-
#lease = new StylePropertyLease(PROGRESS_PROPERTY);
|
|
204
|
-
/** The article's own box and the viewport: either changes the span. */
|
|
235
|
+
#lease = new StylePropertyLease(PROGRESS_PROPERTY, this.identifier);
|
|
205
236
|
#layout = new LayoutObserver(() => this.#onScroll());
|
|
206
|
-
#beforeCache = new BeforeCacheReset(() => this.#rewindForCache());
|
|
207
|
-
/** Coalesces scroll bursts, and the connect baseline, into one frame. */
|
|
208
237
|
#frames = new FrameCoalescer();
|
|
209
|
-
/** Last published progress, so `change`/`complete` fire only on movement. */
|
|
210
238
|
#progress = -1;
|
|
211
|
-
/** False until the connect frame has run: `complete` needs real reading. */
|
|
212
239
|
#baselined = false;
|
|
213
240
|
#onScroll = () => this.#frames.schedule(() => this.#measure());
|
|
214
241
|
connect() {
|
|
@@ -217,7 +244,6 @@ var ReadingProgressController = class extends Controller {
|
|
|
217
244
|
window.addEventListener("scroll", this.#onScroll, { passive: true, capture: true });
|
|
218
245
|
this.#layout.observe(this.element);
|
|
219
246
|
this.#layout.observeViewport();
|
|
220
|
-
this.#beforeCache.activate();
|
|
221
247
|
this.#measure();
|
|
222
248
|
this.#frames.schedule(() => {
|
|
223
249
|
this.#measure();
|
|
@@ -227,23 +253,10 @@ var ReadingProgressController = class extends Controller {
|
|
|
227
253
|
disconnect() {
|
|
228
254
|
window.removeEventListener("scroll", this.#onScroll, { capture: true });
|
|
229
255
|
this.#layout.disconnect();
|
|
230
|
-
this.#beforeCache.deactivate();
|
|
231
256
|
this.#frames.cancel();
|
|
232
|
-
this.#lease.
|
|
233
|
-
|
|
234
|
-
/**
|
|
235
|
-
* Hands both declarations back before the page is snapshotted, so a restored
|
|
236
|
-
* page starts from the authored DOM rather than from someone else's progress.
|
|
237
|
-
* The baseline goes back with them: a cancelled visit leaves this page on
|
|
238
|
-
* screen, and the next measurement has to publish afresh rather than match a
|
|
239
|
-
* value that has already been handed back.
|
|
240
|
-
*/
|
|
241
|
-
#rewindForCache() {
|
|
242
|
-
this.#frames.cancel();
|
|
243
|
-
this.#lease.returnAll();
|
|
244
|
-
this.#progress = -1;
|
|
257
|
+
this.#lease.return(this.element);
|
|
258
|
+
this.#lease.return(document.documentElement);
|
|
245
259
|
}
|
|
246
|
-
/** Computes and publishes the progress; emits on movement only. */
|
|
247
260
|
#measure() {
|
|
248
261
|
const rect = this.element.getBoundingClientRect();
|
|
249
262
|
if (rect.width === 0 && rect.height === 0) return;
|
|
@@ -262,5 +275,4 @@ var ReadingProgressController = class extends Controller {
|
|
|
262
275
|
};
|
|
263
276
|
|
|
264
277
|
export { ReadingProgressController };
|
|
265
|
-
//# sourceMappingURL=reading_progress_controller.js.map
|
|
266
278
|
//# sourceMappingURL=reading_progress_controller.js.map
|