@wcstack/resize 1.12.1
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.ja.md +189 -0
- package/README.md +189 -0
- package/dist/auto.js +3 -0
- package/dist/auto.min.js +1 -0
- package/dist/index.d.ts +302 -0
- package/dist/index.esm.js +592 -0
- package/dist/index.esm.js.map +1 -0
- package/dist/index.esm.min.js +2 -0
- package/dist/index.esm.min.js.map +1 -0
- package/package.json +71 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,302 @@
|
|
|
1
|
+
interface ITagNames {
|
|
2
|
+
readonly resize: string;
|
|
3
|
+
}
|
|
4
|
+
interface IWritableTagNames {
|
|
5
|
+
resize?: string;
|
|
6
|
+
}
|
|
7
|
+
interface IConfig {
|
|
8
|
+
readonly tagNames: ITagNames;
|
|
9
|
+
}
|
|
10
|
+
interface IWritableConfig {
|
|
11
|
+
tagNames?: IWritableTagNames;
|
|
12
|
+
}
|
|
13
|
+
interface IWcBindableProperty {
|
|
14
|
+
readonly name: string;
|
|
15
|
+
readonly event: string;
|
|
16
|
+
readonly getter?: (event: Event) => any;
|
|
17
|
+
}
|
|
18
|
+
interface IWcBindableInput {
|
|
19
|
+
readonly name: string;
|
|
20
|
+
readonly attribute?: string;
|
|
21
|
+
}
|
|
22
|
+
interface IWcBindableCommand {
|
|
23
|
+
readonly name: string;
|
|
24
|
+
readonly async?: boolean;
|
|
25
|
+
}
|
|
26
|
+
interface IWcBindable {
|
|
27
|
+
readonly protocol: "wc-bindable";
|
|
28
|
+
readonly version: number;
|
|
29
|
+
readonly properties: IWcBindableProperty[];
|
|
30
|
+
readonly inputs?: IWcBindableInput[];
|
|
31
|
+
readonly commands?: IWcBindableCommand[];
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Which box-size CSS-side ResizeObserver reports. Mirrors `ResizeObserverBoxOptions`.
|
|
35
|
+
* `device-pixel-content-box` is Chromium-only; the Core falls back to `content-box`
|
|
36
|
+
* if the runtime rejects it (never-throw).
|
|
37
|
+
*/
|
|
38
|
+
type ResizeBoxOption = "content-box" | "border-box" | "device-pixel-content-box";
|
|
39
|
+
/**
|
|
40
|
+
* Plain snapshot of a `DOMRectReadOnly` (`contentRect`). Unlike the live DOM rect,
|
|
41
|
+
* every field is a plain number so it can flow through data binding and serialize.
|
|
42
|
+
*/
|
|
43
|
+
interface WcsResizeRect {
|
|
44
|
+
x: number;
|
|
45
|
+
y: number;
|
|
46
|
+
width: number;
|
|
47
|
+
height: number;
|
|
48
|
+
top: number;
|
|
49
|
+
right: number;
|
|
50
|
+
bottom: number;
|
|
51
|
+
left: number;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Plain snapshot of a `ResizeObserverSize` (one fragment of `contentBoxSize` /
|
|
55
|
+
* `borderBoxSize` / `devicePixelContentBoxSize`). Logical sizes (inline/block),
|
|
56
|
+
* correct under vertical writing modes.
|
|
57
|
+
*/
|
|
58
|
+
interface WcsResizeBoxSize {
|
|
59
|
+
inlineSize: number;
|
|
60
|
+
blockSize: number;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Payload carried by the `wcs-resize:change` event — a structured-clone-friendly
|
|
64
|
+
* snapshot of `ResizeObserverEntry`, plus the live `target` Element.
|
|
65
|
+
*
|
|
66
|
+
* `width` / `height` are the headline values derived from the box that the `box`
|
|
67
|
+
* option selected (border-box / device-pixel / content-box), falling back to
|
|
68
|
+
* `contentRect` when the matching boxSize fragment is absent. They are rounded to
|
|
69
|
+
* integers when the `round` option is set.
|
|
70
|
+
*
|
|
71
|
+
* `contentBoxSize` / `borderBoxSize` / `devicePixelContentBoxSize` keep the first
|
|
72
|
+
* fragment only (single-element observers never produce multiple fragments here);
|
|
73
|
+
* `null` when the runtime did not report that box.
|
|
74
|
+
*/
|
|
75
|
+
interface WcsResizeEntry {
|
|
76
|
+
width: number;
|
|
77
|
+
height: number;
|
|
78
|
+
contentRect: WcsResizeRect;
|
|
79
|
+
contentBoxSize: WcsResizeBoxSize | null;
|
|
80
|
+
borderBoxSize: WcsResizeBoxSize | null;
|
|
81
|
+
devicePixelContentBoxSize: WcsResizeBoxSize | null;
|
|
82
|
+
/** The observed element. Not serializable — kept for consumers needing the node. */
|
|
83
|
+
target: Element;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Options accepted by `ResizeCore.observe`. `box` mirrors `ResizeObserverOptions`;
|
|
87
|
+
* `round` rounds the headline `width` / `height` to integers to absorb sub-pixel
|
|
88
|
+
* jitter (the nested boxSize fragments stay raw).
|
|
89
|
+
*/
|
|
90
|
+
interface ResizeOptions {
|
|
91
|
+
box?: ResizeBoxOption;
|
|
92
|
+
round?: boolean;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Value types for ResizeCore (headless) — the observable state properties.
|
|
96
|
+
* Use with `bind()` from `@wc-bindable/core` for compile-time type checking.
|
|
97
|
+
*
|
|
98
|
+
* @example
|
|
99
|
+
* ```typescript
|
|
100
|
+
* const core = new ResizeCore();
|
|
101
|
+
* bind(core, (name: keyof WcsResizeCoreValues, value) => { ... });
|
|
102
|
+
* core.observe(document.querySelector("#panel")!);
|
|
103
|
+
* ```
|
|
104
|
+
*/
|
|
105
|
+
interface WcsResizeCoreValues {
|
|
106
|
+
entry: WcsResizeEntry | null;
|
|
107
|
+
width: number;
|
|
108
|
+
height: number;
|
|
109
|
+
observing: boolean;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Value types for the Shell (`<wcs-resize>`) — identical observable surface to the
|
|
113
|
+
* Core, plus the DOM-driven `trigger` command-property.
|
|
114
|
+
*/
|
|
115
|
+
interface WcsResizeValues extends WcsResizeCoreValues {
|
|
116
|
+
trigger: boolean;
|
|
117
|
+
}
|
|
118
|
+
interface WcsResizeInputs {
|
|
119
|
+
/**
|
|
120
|
+
* What to observe. Omitted → the first element child (the element itself renders
|
|
121
|
+
* as `display:contents`). A selector (`"#panel"`, `".card"`) → the matched
|
|
122
|
+
* element (`display:none`). The literal `"self"` → the element itself, which as a
|
|
123
|
+
* `display:block` zero-height box stretches to the parent's available inline size
|
|
124
|
+
* — a container-width probe.
|
|
125
|
+
*/
|
|
126
|
+
target: string;
|
|
127
|
+
/**
|
|
128
|
+
* Which box to report: `content-box` (default), `border-box`,
|
|
129
|
+
* `device-pixel-content-box`. Typed as `string` because the Shell's `box`
|
|
130
|
+
* accessor returns the raw attribute (`""` when unset, and any unrecognized
|
|
131
|
+
* value verbatim); `_parseBox()` falls back to `content-box` at observe time.
|
|
132
|
+
*/
|
|
133
|
+
box: string;
|
|
134
|
+
/** Round the headline `width` / `height` to integers (absorbs sub-pixel jitter). */
|
|
135
|
+
round: boolean;
|
|
136
|
+
/** Disconnect after the first size observation (ResizeObserver always fires once on observe). */
|
|
137
|
+
once: boolean;
|
|
138
|
+
/** Do not auto-observe on connect; observe is driven manually instead. */
|
|
139
|
+
manual: boolean;
|
|
140
|
+
/**
|
|
141
|
+
* Momentary command-property (no mirrored attribute): a `false`→`true` write
|
|
142
|
+
* re-runs `observe()`, then the flag immediately resets to `false`. Unlike the
|
|
143
|
+
* other inputs it does not reflect to an HTML attribute.
|
|
144
|
+
*/
|
|
145
|
+
trigger: boolean;
|
|
146
|
+
}
|
|
147
|
+
interface WcsResizeCoreCommands {
|
|
148
|
+
observe(element: Element, options?: ResizeOptions): void;
|
|
149
|
+
unobserve(element: Element): void;
|
|
150
|
+
disconnect(): void;
|
|
151
|
+
}
|
|
152
|
+
interface WcsResizeCommands {
|
|
153
|
+
/** Re-resolve the target from the DOM and (re)start observing. */
|
|
154
|
+
observe(): void;
|
|
155
|
+
unobserve(): void;
|
|
156
|
+
disconnect(): void;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
declare function bootstrapResize(userConfig?: IWritableConfig): void;
|
|
160
|
+
|
|
161
|
+
declare function getConfig(): IConfig;
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* Headless element-size primitive. A thin, framework-agnostic wrapper around the
|
|
165
|
+
* ResizeObserver API exposed through the wc-bindable protocol.
|
|
166
|
+
*
|
|
167
|
+
* Like IntersectionCore, the thing being observed is a *DOM element* — so
|
|
168
|
+
* `observe()` takes the target node. The Core stays DOM-resolution-agnostic: it
|
|
169
|
+
* observes whatever element it is handed (the Shell resolves the `target` selector
|
|
170
|
+
* before calling). It is a read-only producer — element/layout → state only.
|
|
171
|
+
*
|
|
172
|
+
* Every observer callback is published via the single `wcs-resize:change` event;
|
|
173
|
+
* `width` / `height` are read from it through getters (mirroring how
|
|
174
|
+
* IntersectionCore derives `intersecting` / `ratio` from one event), so an observer
|
|
175
|
+
* binding any of them is notified on every change.
|
|
176
|
+
*
|
|
177
|
+
* `width` / `height` follow the observed `box` (border-box / device-pixel /
|
|
178
|
+
* content-box) and are rounded to integers when `round` is set — `round` absorbs
|
|
179
|
+
* the sub-pixel jitter that would otherwise let a size→layout→size loop oscillate.
|
|
180
|
+
*
|
|
181
|
+
* Single-target by design: the Shell observes exactly one element, so the state
|
|
182
|
+
* reflects that element. Multi-target observation is intentionally out of scope.
|
|
183
|
+
*/
|
|
184
|
+
declare class ResizeCore extends EventTarget {
|
|
185
|
+
static wcBindable: IWcBindable;
|
|
186
|
+
private _target;
|
|
187
|
+
private _observer;
|
|
188
|
+
private _observed;
|
|
189
|
+
private _options;
|
|
190
|
+
private _effectiveBox;
|
|
191
|
+
private _entry;
|
|
192
|
+
private _observing;
|
|
193
|
+
constructor(target?: EventTarget);
|
|
194
|
+
get entry(): WcsResizeEntry | null;
|
|
195
|
+
get width(): number;
|
|
196
|
+
get height(): number;
|
|
197
|
+
get observing(): boolean;
|
|
198
|
+
private _setEntry;
|
|
199
|
+
private _setObserving;
|
|
200
|
+
/**
|
|
201
|
+
* Start observing `element`. Idempotent while already observing the same element
|
|
202
|
+
* with the same options. Changing the element or options tears down the current
|
|
203
|
+
* observer and builds a new one (re-observing also re-delivers the initial size,
|
|
204
|
+
* which is how a `round` toggle re-fires with the new rounding).
|
|
205
|
+
*
|
|
206
|
+
* If ResizeObserver is unavailable (SSR) this is a silent no-op — `observing`
|
|
207
|
+
* stays false. If the requested `box` is unsupported, it retries once with
|
|
208
|
+
* `content-box` before giving up; both giving-up paths leave `observing` false,
|
|
209
|
+
* consistent with the never-throw design of the other @wcstack sensors.
|
|
210
|
+
*/
|
|
211
|
+
observe(element: Element, options?: ResizeOptions): void;
|
|
212
|
+
/**
|
|
213
|
+
* Stop observing `element`. A no-op if it is not the currently observed element.
|
|
214
|
+
* The observer instance is torn down (single-target Core), so a later observe()
|
|
215
|
+
* rebuilds it.
|
|
216
|
+
*/
|
|
217
|
+
unobserve(element: Element): void;
|
|
218
|
+
/** Stop all observation and release the observer. */
|
|
219
|
+
disconnect(): void;
|
|
220
|
+
private _teardownObserver;
|
|
221
|
+
private _createObserver;
|
|
222
|
+
/**
|
|
223
|
+
* Start observing with the requested `box`, retrying once with `content-box` if
|
|
224
|
+
* the runtime rejects the box (e.g. `device-pixel-content-box` on engines that do
|
|
225
|
+
* not support it). Returns the box actually in effect, or `null` if observation
|
|
226
|
+
* could not start at all.
|
|
227
|
+
*/
|
|
228
|
+
private _beginObserve;
|
|
229
|
+
private _onResize;
|
|
230
|
+
private _normalizeEntry;
|
|
231
|
+
/**
|
|
232
|
+
* Pick the headline width/height from the boxSize matching the observed `box`,
|
|
233
|
+
* falling back to `contentRect` when that fragment is absent (older engines only
|
|
234
|
+
* fill contentRect). `inlineSize`/`blockSize` map to width/height (correct for
|
|
235
|
+
* horizontal writing modes). Rounds to integers when `round` is set.
|
|
236
|
+
*/
|
|
237
|
+
private _headlineSize;
|
|
238
|
+
private _firstBoxSize;
|
|
239
|
+
private _normalizeRect;
|
|
240
|
+
private _optionsEqual;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
/**
|
|
244
|
+
* `<wcs-resize>` — declarative ResizeObserver.
|
|
245
|
+
*
|
|
246
|
+
* The `target` attribute is the single knob that decides both *what* is observed
|
|
247
|
+
* and how the element renders (it never injects a layout box unless asked):
|
|
248
|
+
*
|
|
249
|
+
* | `target` | observes | display | use case |
|
|
250
|
+
* |-----------------|-----------------------|-------------|----------------------|
|
|
251
|
+
* | omitted | first element child | `contents` | size a wrapped child |
|
|
252
|
+
* | `"#panel"` / sel| the matched element | `none` | size an existing node|
|
|
253
|
+
* | `"self"` | the element itself | `block` | container-width probe|
|
|
254
|
+
*
|
|
255
|
+
* `display:contents` means wrapping a child injects no box of its own (so a
|
|
256
|
+
* `<wcs-resize><div></wcs-resize>` does not disturb a flex/grid parent); the
|
|
257
|
+
* `target="self"` form takes a `display:block` box that, as a zero-height element,
|
|
258
|
+
* stretches to the parent's available inline size — a container-width probe.
|
|
259
|
+
*
|
|
260
|
+
* Note: a `display:contents` / `display:none` element generates no box, so the
|
|
261
|
+
* observed node must be the child / selector target (which do have boxes), never
|
|
262
|
+
* the `<wcs-resize>` host itself except in the `self` form.
|
|
263
|
+
*/
|
|
264
|
+
declare class WcsResize extends HTMLElement {
|
|
265
|
+
static hasConnectedCallbackPromise: boolean;
|
|
266
|
+
static observedAttributes: string[];
|
|
267
|
+
static wcBindable: IWcBindable;
|
|
268
|
+
private _core;
|
|
269
|
+
private _trigger;
|
|
270
|
+
constructor();
|
|
271
|
+
get target(): string;
|
|
272
|
+
set target(value: string);
|
|
273
|
+
get box(): string;
|
|
274
|
+
set box(value: string);
|
|
275
|
+
get round(): boolean;
|
|
276
|
+
set round(value: boolean);
|
|
277
|
+
get once(): boolean;
|
|
278
|
+
set once(value: boolean);
|
|
279
|
+
get manual(): boolean;
|
|
280
|
+
set manual(value: boolean);
|
|
281
|
+
get entry(): WcsResizeEntry | null;
|
|
282
|
+
get width(): number;
|
|
283
|
+
get height(): number;
|
|
284
|
+
get observing(): boolean;
|
|
285
|
+
get trigger(): boolean;
|
|
286
|
+
set trigger(value: boolean);
|
|
287
|
+
/** Re-resolve the target from the DOM and (re)start observing. */
|
|
288
|
+
observe(): void;
|
|
289
|
+
unobserve(): void;
|
|
290
|
+
disconnect(): void;
|
|
291
|
+
private _resolveTarget;
|
|
292
|
+
private _safeQuery;
|
|
293
|
+
private _parseBox;
|
|
294
|
+
private _options;
|
|
295
|
+
private _onChange;
|
|
296
|
+
connectedCallback(): void;
|
|
297
|
+
disconnectedCallback(): void;
|
|
298
|
+
attributeChangedCallback(_name: string, oldValue: string | null, newValue: string | null): void;
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
export { ResizeCore, WcsResize, bootstrapResize, getConfig };
|
|
302
|
+
export type { IWritableConfig, IWritableTagNames, ResizeBoxOption, ResizeOptions, WcsResizeBoxSize, WcsResizeCommands, WcsResizeCoreCommands, WcsResizeCoreValues, WcsResizeEntry, WcsResizeInputs, WcsResizeRect, WcsResizeValues };
|