@dasl/tile-loader 3.0.0 → 3.2.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 +841 -26
- package/dist/at.d.ts +126 -12
- package/dist/at.d.ts.map +1 -1
- package/dist/at.js +574 -90
- package/dist/at.js.map +1 -1
- package/dist/car.d.ts +21 -2
- package/dist/car.d.ts.map +1 -1
- package/dist/car.js +78 -15
- package/dist/car.js.map +1 -1
- package/dist/content-scheme.d.ts +17 -3
- package/dist/content-scheme.d.ts.map +1 -1
- package/dist/content-scheme.js +32 -6
- package/dist/content-scheme.js.map +1 -1
- package/dist/guard.d.ts +242 -0
- package/dist/guard.d.ts.map +1 -0
- package/dist/guard.js +956 -0
- package/dist/guard.js.map +1 -0
- package/dist/index.d.ts +297 -13
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +917 -78
- package/dist/index.js.map +1 -1
- package/dist/lib/cid.d.ts +25 -0
- package/dist/lib/cid.d.ts.map +1 -0
- package/dist/lib/cid.js +65 -0
- package/dist/lib/cid.js.map +1 -0
- package/dist/lib/defaults.d.ts +8 -0
- package/dist/lib/defaults.d.ts.map +1 -0
- package/dist/lib/defaults.js +14 -0
- package/dist/lib/defaults.js.map +1 -0
- package/dist/lib/destinations.d.ts +25 -0
- package/dist/lib/destinations.d.ts.map +1 -0
- package/dist/lib/destinations.js +94 -0
- package/dist/lib/destinations.js.map +1 -0
- package/dist/lib/drisl.d.ts +10 -0
- package/dist/lib/drisl.d.ts.map +1 -0
- package/dist/lib/drisl.js +169 -0
- package/dist/lib/drisl.js.map +1 -0
- package/dist/lib/errors.d.ts +80 -0
- package/dist/lib/errors.d.ts.map +1 -0
- package/dist/lib/errors.js +44 -0
- package/dist/lib/errors.js.map +1 -0
- package/dist/lib/fetching.d.ts +24 -0
- package/dist/lib/fetching.d.ts.map +1 -0
- package/dist/lib/fetching.js +135 -0
- package/dist/lib/fetching.js.map +1 -0
- package/dist/lib/limits.d.ts +34 -0
- package/dist/lib/limits.d.ts.map +1 -0
- package/dist/lib/limits.js +33 -0
- package/dist/lib/limits.js.map +1 -0
- package/dist/lib/pointer.d.ts +83 -0
- package/dist/lib/pointer.d.ts.map +1 -0
- package/dist/lib/pointer.js +244 -0
- package/dist/lib/pointer.js.map +1 -0
- package/dist/link.d.ts +110 -13
- package/dist/link.d.ts.map +1 -1
- package/dist/link.js +336 -43
- package/dist/link.js.map +1 -1
- package/dist/memory.d.ts +1 -0
- package/dist/memory.d.ts.map +1 -1
- package/dist/memory.js +5 -0
- package/dist/memory.js.map +1 -1
- package/dist/mount.d.ts +54 -0
- package/dist/mount.d.ts.map +1 -0
- package/dist/mount.js +286 -0
- package/dist/mount.js.map +1 -0
- package/dist/size.d.ts +43 -2
- package/dist/size.d.ts.map +1 -1
- package/dist/size.js +296 -15
- package/dist/size.js.map +1 -1
- package/package.json +13 -3
- package/src/at.ts +582 -84
- package/src/car.ts +75 -16
- package/src/content-scheme.ts +38 -7
- package/src/guard.ts +1013 -0
- package/src/index.ts +1011 -80
- package/src/lib/cid.ts +65 -0
- package/src/lib/defaults.ts +12 -0
- package/src/lib/destinations.ts +79 -0
- package/src/lib/drisl.ts +160 -0
- package/src/lib/errors.ts +111 -0
- package/src/lib/fetching.ts +138 -0
- package/src/lib/limits.ts +61 -0
- package/src/lib/pointer.ts +290 -0
- package/src/link.ts +365 -48
- package/src/memory.ts +5 -0
- package/src/mount.ts +356 -0
- package/src/size.ts +304 -16
package/dist/mount.js
ADDED
|
@@ -0,0 +1,286 @@
|
|
|
1
|
+
// Tiles in a list: a feed, a thread, a page of posts. Every running tile is a
|
|
2
|
+
// process or two of the browser's, tens of megabytes each, and the loader
|
|
3
|
+
// runs as many as it is asked to. This module is what asks, for a host with
|
|
4
|
+
// more tiles than it should run at once: a tile is mounted when its place in
|
|
5
|
+
// the page has been in view for a moment, closed when it has been out of
|
|
6
|
+
// view for a while, and no more than a few are live at a time.
|
|
7
|
+
//
|
|
8
|
+
// import { tileMounts } from '@dasl/tile-loader/mount';
|
|
9
|
+
// const mounts = tileMounts({ maxLive: 4 });
|
|
10
|
+
// for (const post of posts) {
|
|
11
|
+
// mounts.watch(post.querySelector('.tile'), () => mothership.loadTile(post.dataset.tile));
|
|
12
|
+
// }
|
|
13
|
+
//
|
|
14
|
+
// Each place is an element of the host's: give it the size the tile will
|
|
15
|
+
// have, so that the page does not move when the tile comes and goes. While
|
|
16
|
+
// its tile is live the frame is its last child and it has the attribute
|
|
17
|
+
// `data-tile-live`, for a style that hides what the place showed before (a
|
|
18
|
+
// card, a screenshot).
|
|
19
|
+
//
|
|
20
|
+
// A tile that is put away is closed (Tile.close()): its frame goes, and the
|
|
21
|
+
// origin it ran on is wiped. Shown again, it starts afresh, on another
|
|
22
|
+
// origin. So this is for tiles whose state the host does not mean to keep.
|
|
23
|
+
//
|
|
24
|
+
// Starting a tile is the costly moment (its runtime spends the browser's
|
|
25
|
+
// WebRTC budget first, where there is one), so tiles are also started a few
|
|
26
|
+
// at a time: a tile counts as starting from when it is mounted until it fires
|
|
27
|
+
// `load`, or for `startLimit` at most. The function that loads a tile gets
|
|
28
|
+
// no longer than that either: one that never answers (the server of a tile's
|
|
29
|
+
// author can see to that) does not keep the other tiles from being mounted.
|
|
30
|
+
// Guesses, all of them, for a host to replace with what suits its pages: see
|
|
31
|
+
// TileMountOptions.
|
|
32
|
+
const MAX_LIVE = 6;
|
|
33
|
+
const MAX_STARTING = 3;
|
|
34
|
+
const MOUNT_AFTER_MS = 300;
|
|
35
|
+
const CLOSE_AFTER_MS = 10000;
|
|
36
|
+
const START_LIMIT_MS = 5000;
|
|
37
|
+
/** The attribute a place has while its tile is live. */
|
|
38
|
+
export const LIVE_ATTRIBUTE = 'data-tile-live';
|
|
39
|
+
/** Mounts tiles in their places as these come into view, a bounded number at a time. */
|
|
40
|
+
export function tileMounts(options = {}) {
|
|
41
|
+
const maxLive = Math.max(1, options.maxLive ?? MAX_LIVE);
|
|
42
|
+
const maxStarting = Math.max(1, options.maxStarting ?? MAX_STARTING);
|
|
43
|
+
const mountAfter = options.mountAfter ?? MOUNT_AFTER_MS;
|
|
44
|
+
const closeAfter = options.closeAfter ?? CLOSE_AFTER_MS;
|
|
45
|
+
const startLimit = options.startLimit ?? START_LIMIT_MS;
|
|
46
|
+
const places = new Map();
|
|
47
|
+
// The places whose tile is due and waits for room, first come first served.
|
|
48
|
+
const waiting = [];
|
|
49
|
+
// Tiles being closed, for stop() to wait on.
|
|
50
|
+
const closing = new Set();
|
|
51
|
+
let live = 0;
|
|
52
|
+
let starting = 0;
|
|
53
|
+
const observer = new IntersectionObserver((entries) => {
|
|
54
|
+
for (const entry of entries) {
|
|
55
|
+
const place = places.get(entry.target);
|
|
56
|
+
if (place)
|
|
57
|
+
seen(place, entry.isIntersecting);
|
|
58
|
+
}
|
|
59
|
+
}, { root: options.root ?? null, rootMargin: options.rootMargin ?? '0px' });
|
|
60
|
+
// A place came into view, or left it.
|
|
61
|
+
function seen(place, inView) {
|
|
62
|
+
if (place.inView === inView)
|
|
63
|
+
return;
|
|
64
|
+
place.inView = inView;
|
|
65
|
+
place.since = Date.now();
|
|
66
|
+
clearTimeout(place.timer);
|
|
67
|
+
place.timer = undefined;
|
|
68
|
+
if (inView) {
|
|
69
|
+
// Back in view before its tile was closed: it stays. Otherwise the
|
|
70
|
+
// tile is due once the place has been looked at for a moment, not
|
|
71
|
+
// scrolled past.
|
|
72
|
+
if (!place.frame && !place.mounting)
|
|
73
|
+
place.timer = setTimeout(() => due(place), mountAfter);
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
// Out of view, it no longer waits for room; and a live tile is on notice.
|
|
77
|
+
drop(place);
|
|
78
|
+
if (place.frame && Number.isFinite(closeAfter))
|
|
79
|
+
place.timer = setTimeout(() => { void putAway(place); }, closeAfter);
|
|
80
|
+
// A tile out of view is one that can make room for those that wait.
|
|
81
|
+
fill();
|
|
82
|
+
}
|
|
83
|
+
function due(place) {
|
|
84
|
+
place.timer = undefined;
|
|
85
|
+
if (!place.watched || !place.inView || place.frame || place.mounting || waiting.includes(place))
|
|
86
|
+
return;
|
|
87
|
+
waiting.push(place);
|
|
88
|
+
fill();
|
|
89
|
+
}
|
|
90
|
+
function drop(place) {
|
|
91
|
+
const at = waiting.indexOf(place);
|
|
92
|
+
if (at >= 0)
|
|
93
|
+
waiting.splice(at, 1);
|
|
94
|
+
}
|
|
95
|
+
// Mounts the tiles that wait, for as long as there is room for them.
|
|
96
|
+
function fill() {
|
|
97
|
+
while (waiting.length && starting < maxStarting) {
|
|
98
|
+
if (live >= maxLive) {
|
|
99
|
+
// Room is made by the live tile that has been out of view longest.
|
|
100
|
+
// None out of view: the ones that wait go on waiting.
|
|
101
|
+
let oldest;
|
|
102
|
+
for (const p of places.values()) {
|
|
103
|
+
if (p.frame && !p.inView && (!oldest || p.since < oldest.since))
|
|
104
|
+
oldest = p;
|
|
105
|
+
}
|
|
106
|
+
if (!oldest)
|
|
107
|
+
return;
|
|
108
|
+
void putAway(oldest);
|
|
109
|
+
continue;
|
|
110
|
+
}
|
|
111
|
+
void mount(waiting.shift());
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
async function mount(place) {
|
|
115
|
+
// The room is taken before the tile is loaded, which can take a while.
|
|
116
|
+
place.mounting = true;
|
|
117
|
+
live++;
|
|
118
|
+
starting++;
|
|
119
|
+
// It counts as starting until it has loaded, or been put away, or for
|
|
120
|
+
// startLimit; and once it no longer does, another can start.
|
|
121
|
+
let counted = true;
|
|
122
|
+
const started = () => {
|
|
123
|
+
if (!counted)
|
|
124
|
+
return false;
|
|
125
|
+
counted = false;
|
|
126
|
+
starting--;
|
|
127
|
+
return true;
|
|
128
|
+
};
|
|
129
|
+
const endStart = () => {
|
|
130
|
+
if (started())
|
|
131
|
+
fill();
|
|
132
|
+
};
|
|
133
|
+
const giveUp = () => {
|
|
134
|
+
place.mounting = false;
|
|
135
|
+
live--;
|
|
136
|
+
endStart();
|
|
137
|
+
};
|
|
138
|
+
let tile = place.tile;
|
|
139
|
+
if (!tile) {
|
|
140
|
+
// Loading the tile is the host's doing (a fetch from the server of the
|
|
141
|
+
// tile's author, say) and may never end. It has as long as a tile has
|
|
142
|
+
// to start: after that its room is given back to the tiles that wait.
|
|
143
|
+
// If the tile comes after all it is kept, and mounted if its place is
|
|
144
|
+
// still being looked at and there is room.
|
|
145
|
+
let held = true;
|
|
146
|
+
const tooLong = setTimeout(() => {
|
|
147
|
+
held = false;
|
|
148
|
+
giveUp();
|
|
149
|
+
}, startLimit);
|
|
150
|
+
tile = await load(place);
|
|
151
|
+
clearTimeout(tooLong);
|
|
152
|
+
if (!held) {
|
|
153
|
+
if (tile)
|
|
154
|
+
due(place);
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
if (!tile)
|
|
158
|
+
return giveUp();
|
|
159
|
+
}
|
|
160
|
+
// Gone from view, or no longer watched, while its tile was loading.
|
|
161
|
+
if (!place.watched || !place.inView)
|
|
162
|
+
return giveUp();
|
|
163
|
+
let frame;
|
|
164
|
+
try {
|
|
165
|
+
frame = (place.item.render ?? ((t) => t.renderContent()))(tile);
|
|
166
|
+
}
|
|
167
|
+
catch (err) {
|
|
168
|
+
console.error('[tiles] A tile could not be rendered for its place in the page:', err);
|
|
169
|
+
return giveUp();
|
|
170
|
+
}
|
|
171
|
+
const mounted = new AbortController();
|
|
172
|
+
const { signal } = mounted;
|
|
173
|
+
tile.addEventListener('load', endStart, { signal });
|
|
174
|
+
// A tile the dock stopped is gone from its frame: closing it wipes its origin.
|
|
175
|
+
tile.addEventListener('stopped', () => { void putAway(place); }, { signal });
|
|
176
|
+
const limit = setTimeout(endStart, startLimit);
|
|
177
|
+
// Put away: putAway() sees to the ones that wait, when it is done.
|
|
178
|
+
signal.addEventListener('abort', () => {
|
|
179
|
+
clearTimeout(limit);
|
|
180
|
+
started();
|
|
181
|
+
});
|
|
182
|
+
place.mounting = false;
|
|
183
|
+
place.frame = frame;
|
|
184
|
+
place.mounted = mounted;
|
|
185
|
+
place.el.append(frame);
|
|
186
|
+
place.el.setAttribute(LIVE_ATTRIBUTE, '');
|
|
187
|
+
try {
|
|
188
|
+
place.unmount = place.item.onMount?.(tile, frame);
|
|
189
|
+
}
|
|
190
|
+
catch (err) {
|
|
191
|
+
console.error('[tiles] onMount threw:', err);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
// Loads a place's tile, with the function the host gave for it. Once: a
|
|
195
|
+
// place that is due again while its tile is still loading waits for the
|
|
196
|
+
// same answer. A tile that could not be loaded is tried again the next
|
|
197
|
+
// time its place is looked at.
|
|
198
|
+
function load(place) {
|
|
199
|
+
place.loading ??= (async () => {
|
|
200
|
+
try {
|
|
201
|
+
const { tile } = place.item;
|
|
202
|
+
place.tile = (typeof tile === 'function' ? await tile() : tile) || undefined;
|
|
203
|
+
}
|
|
204
|
+
catch (err) {
|
|
205
|
+
console.error('[tiles] A tile could not be loaded for its place in the page:', err);
|
|
206
|
+
}
|
|
207
|
+
place.loading = undefined;
|
|
208
|
+
return place.tile;
|
|
209
|
+
})();
|
|
210
|
+
return place.loading;
|
|
211
|
+
}
|
|
212
|
+
// Closes a live tile: its frame goes and its origin is wiped.
|
|
213
|
+
function putAway(place) {
|
|
214
|
+
const { tile, frame } = place;
|
|
215
|
+
if (!tile || !frame)
|
|
216
|
+
return Promise.resolve();
|
|
217
|
+
clearTimeout(place.timer);
|
|
218
|
+
place.timer = undefined;
|
|
219
|
+
place.frame = undefined;
|
|
220
|
+
live--;
|
|
221
|
+
place.mounted?.abort();
|
|
222
|
+
place.mounted = undefined;
|
|
223
|
+
place.el.removeAttribute(LIVE_ATTRIBUTE);
|
|
224
|
+
try {
|
|
225
|
+
if (typeof place.unmount === 'function')
|
|
226
|
+
place.unmount();
|
|
227
|
+
}
|
|
228
|
+
catch (err) {
|
|
229
|
+
console.error('[tiles] What onMount returned threw:', err);
|
|
230
|
+
}
|
|
231
|
+
place.unmount = undefined;
|
|
232
|
+
const closed = tile.close().then((wiped) => { place.item.onClose?.(tile, wiped); }, (err) => { console.error('[tiles] A tile could not be closed:', err); }).finally(() => {
|
|
233
|
+
closing.delete(closed);
|
|
234
|
+
});
|
|
235
|
+
closing.add(closed);
|
|
236
|
+
// A frame that close() left in the document for the runtime to answer
|
|
237
|
+
// from is not shown meanwhile.
|
|
238
|
+
if (frame.isConnected)
|
|
239
|
+
frame.style.display = 'none';
|
|
240
|
+
// Still in view, as a tile the dock stopped is: it is not mounted again
|
|
241
|
+
// until its place has left view and come back.
|
|
242
|
+
fill();
|
|
243
|
+
return closed;
|
|
244
|
+
}
|
|
245
|
+
function unwatch(place) {
|
|
246
|
+
if (!place.watched)
|
|
247
|
+
return Promise.resolve();
|
|
248
|
+
place.watched = false;
|
|
249
|
+
observer.unobserve(place.el);
|
|
250
|
+
places.delete(place.el);
|
|
251
|
+
drop(place);
|
|
252
|
+
clearTimeout(place.timer);
|
|
253
|
+
place.timer = undefined;
|
|
254
|
+
return putAway(place);
|
|
255
|
+
}
|
|
256
|
+
return {
|
|
257
|
+
watch(el, item) {
|
|
258
|
+
const earlier = places.get(el);
|
|
259
|
+
if (earlier)
|
|
260
|
+
void unwatch(earlier);
|
|
261
|
+
const place = {
|
|
262
|
+
el,
|
|
263
|
+
item: typeof item === 'object' && item !== null && 'tile' in item ? item : { tile: item },
|
|
264
|
+
inView: false,
|
|
265
|
+
since: Date.now(),
|
|
266
|
+
watched: true,
|
|
267
|
+
};
|
|
268
|
+
// A tile that is there already is not waited for.
|
|
269
|
+
if (typeof place.item.tile !== 'function')
|
|
270
|
+
place.tile = place.item.tile;
|
|
271
|
+
places.set(el, place);
|
|
272
|
+
observer.observe(el);
|
|
273
|
+
return () => unwatch(place);
|
|
274
|
+
},
|
|
275
|
+
get live() {
|
|
276
|
+
return live;
|
|
277
|
+
},
|
|
278
|
+
async stop() {
|
|
279
|
+
observer.disconnect();
|
|
280
|
+
for (const place of [...places.values()])
|
|
281
|
+
void unwatch(place);
|
|
282
|
+
await Promise.all([...closing]);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AE,KAAK,CAAC,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC;YACxE,MAAM,CAAC,GAAG,CAAC,EAAE,EAAE,KAAK,CAAC,CAAC;YACtB,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;YACrB,OAAO,GAAG,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;QAC9B,CAAC;QACD,IAAI,IAAI;YACN,OAAO,IAAI,CAAC;QACd,CAAC;QACD,KAAK,CAAC,IAAI;YACR,QAAQ,CAAC,UAAU,EAAE,CAAC;YACtB,KAAK,MAAM,KAAK,IAAI,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC;gBAAE,KAAK,OAAO,CAAC,KAAK,CAAC,CAAC;YAC9D,MAAM,OAAO,CAAC,GAAG,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC;QAClC,CAAC;KACF,CAAC;AACJ,CAAC"}
|
package/dist/size.d.ts
CHANGED
|
@@ -3,13 +3,54 @@ import type { Tile } from './index.js';
|
|
|
3
3
|
export type { SizeLimits, TileSize } from '@dasl/tile-lexicon';
|
|
4
4
|
/** The tiles protocol this module speaks. */
|
|
5
5
|
export declare const SIZE_PROTOCOL = "size";
|
|
6
|
+
/**
|
|
7
|
+
* The numbers the gate goes by. All of them are first guesses: each trades a
|
|
8
|
+
* tile that follows its content promptly against a page that holds still
|
|
9
|
+
* under its user.
|
|
10
|
+
*/
|
|
11
|
+
export interface SizeGateOptions {
|
|
12
|
+
/** How far above the edge that moves a pointer still counts as on what moves, in pixels. */
|
|
13
|
+
margin?: number;
|
|
14
|
+
/** The least time between two changes of size, in milliseconds. */
|
|
15
|
+
intervalMs?: number;
|
|
16
|
+
/** How many changes in a row a tile gets. */
|
|
17
|
+
burst?: number;
|
|
18
|
+
/** How long until a tile that has used its changes up gets one back, in milliseconds. */
|
|
19
|
+
refillMs?: number;
|
|
20
|
+
/** How long what a change put where a press may be coming takes no press, in milliseconds. */
|
|
21
|
+
shieldMs?: number;
|
|
22
|
+
/** The same while a mouse rests on it without pressing, in milliseconds. */
|
|
23
|
+
dwellMs?: number;
|
|
24
|
+
/** How long the strip a tile gave up under a finger waits for the tap it is there to take, in milliseconds. */
|
|
25
|
+
stickyMs?: number;
|
|
26
|
+
/** How long until a change that is held is looked at again, should the pointer not say sooner, in milliseconds. */
|
|
27
|
+
retryMs?: number;
|
|
28
|
+
/** How long a page that is not drawing takes to decide, in milliseconds. One that draws decides two frames on. */
|
|
29
|
+
decideMs?: number;
|
|
30
|
+
}
|
|
31
|
+
/** The gate's numbers where a host gives none. */
|
|
32
|
+
export declare const SIZE_GATE: Readonly<Required<SizeGateOptions>>;
|
|
6
33
|
export interface TileSizeOptions {
|
|
7
34
|
/** The context's limits; the floor (SIZE_FLOOR) is under them regardless. */
|
|
8
35
|
limits?: SizeLimits;
|
|
9
|
-
/**
|
|
10
|
-
|
|
36
|
+
/**
|
|
37
|
+
* Size the frame here (the default); or hand each size to the host, to put
|
|
38
|
+
* on a box of its own, when it may be applied (a function: it is called
|
|
39
|
+
* with the size to start at, then with each change); or leave the box, and
|
|
40
|
+
* when it changes, to the host altogether (`false`: nothing is held then).
|
|
41
|
+
*/
|
|
42
|
+
apply?: boolean | ((size: TileSize) => void);
|
|
11
43
|
/** Who sets the width: the context's layout (the default), or the tile, within the limits. */
|
|
12
44
|
width?: 'context' | 'tile';
|
|
45
|
+
/** The gate's numbers, where a host knows better than `SIZE_GATE`. */
|
|
46
|
+
gate?: SizeGateOptions;
|
|
47
|
+
/**
|
|
48
|
+
* What a change of the frame's height moves is taken to be everything
|
|
49
|
+
* below it, the whole width of the window. A host whose layout keeps that
|
|
50
|
+
* to one column names an element as wide as the column here: a pointer
|
|
51
|
+
* beside it then holds nothing up.
|
|
52
|
+
*/
|
|
53
|
+
column?: Element;
|
|
13
54
|
/** Called with each thing the tile asks for and the size the rules give it. */
|
|
14
55
|
onRequest?: (want: Partial<TileSize>, resolved: TileSize) => void;
|
|
15
56
|
/** Called with the tile's size whenever it changes. */
|
package/dist/size.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"size.d.ts","sourceRoot":"","sources":["../src/size.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"size.d.ts","sourceRoot":"","sources":["../src/size.ts"],"names":[],"mappings":"AA6BA,OAAO,KAAK,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC/D,OAAO,KAAK,EAAiB,IAAI,EAAE,MAAM,YAAY,CAAC;AAKtD,YAAY,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAE/D,6CAA6C;AAC7C,eAAO,MAAM,aAAa,SAAS,CAAC;AAWpC;;;;GAIG;AACH,MAAM,WAAW,eAAe;IAC9B,4FAA4F;IAC5F,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,mEAAmE;IACnE,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,6CAA6C;IAC7C,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,yFAAyF;IACzF,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,8FAA8F;IAC9F,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,4EAA4E;IAC5E,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,+GAA+G;IAC/G,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,mHAAmH;IACnH,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,kHAAkH;IAClH,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,kDAAkD;AAClD,eAAO,MAAM,SAAS,EAAE,QAAQ,CAAC,QAAQ,CAAC,eAAe,CAAC,CAUxD,CAAC;AAEH,MAAM,WAAW,eAAe;IAC9B,6EAA6E;IAC7E,MAAM,CAAC,EAAE,UAAU,CAAC;IACpB;;;;;OAKG;IACH,KAAK,CAAC,EAAE,OAAO,GAAG,CAAC,CAAC,IAAI,EAAE,QAAQ,KAAK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