@firsthandjs/dom 0.9.1 → 0.10.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/dist/adapter.d.ts +0 -3
- package/dist/adapter.d.ts.map +1 -1
- package/dist/chunk-467WEPXM.js +1 -0
- package/dist/chunk-MWEKNBIC.js +1 -0
- package/dist/{chunk-6BRSYQCI.js → chunk-YX6HJXS6.js} +1 -1
- package/dist/{dev-chunk-MKONDKMD.js → dev-chunk-HLMVSIC4.js} +97 -74
- package/dist/{dev-chunk-6V32MCOI.js → dev-chunk-KJHYMOKB.js} +1 -1
- package/dist/{dev-chunk-ADHDPKZW.js → dev-chunk-U46CIJCO.js} +221 -311
- package/dist/errors.d.ts +11 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/hydrate.d.ts.map +1 -1
- package/dist/hydrate.dev.js +28 -24
- package/dist/hydrate.js +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.dev.js +3 -3
- package/dist/index.js +1 -1
- package/dist/insert.d.ts +41 -127
- package/dist/insert.d.ts.map +1 -1
- package/dist/internal.d.ts +5 -2
- package/dist/internal.d.ts.map +1 -1
- package/dist/internal.dev.js +121 -11
- package/dist/internal.js +1 -1
- package/dist/list.d.ts.map +1 -1
- package/dist/nodes.d.ts +36 -0
- package/dist/nodes.d.ts.map +1 -0
- package/dist/props.d.ts.map +1 -1
- package/dist/reconcile.d.ts +30 -0
- package/dist/reconcile.d.ts.map +1 -0
- package/dist/store.d.ts +105 -0
- package/dist/store.d.ts.map +1 -0
- package/package.json +2 -2
- package/dist/chunk-E4GAI5XA.js +0 -1
- package/dist/chunk-P4PXTIUD.js +0 -1
|
@@ -33,30 +33,30 @@ function label(value, kind, name) {
|
|
|
33
33
|
return value;
|
|
34
34
|
}
|
|
35
35
|
var QUIET = 20;
|
|
36
|
-
function devRan(
|
|
37
|
-
if (
|
|
38
|
-
|
|
39
|
-
|
|
36
|
+
function devRan(store) {
|
|
37
|
+
if (store.busy === true) {
|
|
38
|
+
store.busy = false;
|
|
39
|
+
store.quiet = 0;
|
|
40
40
|
return;
|
|
41
41
|
}
|
|
42
|
-
const quiet = (
|
|
43
|
-
|
|
42
|
+
const quiet = (store.quiet ?? 0) + 1;
|
|
43
|
+
store.quiet = quiet;
|
|
44
44
|
if (quiet !== QUIET) {
|
|
45
45
|
return;
|
|
46
46
|
}
|
|
47
47
|
devWarnOnce(
|
|
48
|
-
`quiet-run:${
|
|
49
|
-
`<${
|
|
48
|
+
`quiet-run:${store.name}`,
|
|
49
|
+
`<${store.name}> ran ${String(QUIET)} times and wrote nothing.
|
|
50
50
|
Something it reads in a statement changes more often than what it shows. Move that read into the markup, where it is a part of its own, or move the derivation into a computed in the setup.`
|
|
51
51
|
);
|
|
52
52
|
}
|
|
53
|
-
function devHandedNewFunction(
|
|
53
|
+
function devHandedNewFunction(store, value) {
|
|
54
54
|
if (typeof value !== "function") {
|
|
55
55
|
return;
|
|
56
56
|
}
|
|
57
57
|
devWarnOnce(
|
|
58
|
-
`new-function:${
|
|
59
|
-
`<${
|
|
58
|
+
`new-function:${store.name}`,
|
|
59
|
+
`<${store.name}> hands a child a new function on every run, so that child runs again whenever this one does.
|
|
60
60
|
If the handler does not depend on the run, define it in the setup.`
|
|
61
61
|
);
|
|
62
62
|
}
|
|
@@ -91,17 +91,152 @@ function next(node) {
|
|
|
91
91
|
return claimer === null ? sibling : claimer.step(sibling);
|
|
92
92
|
}
|
|
93
93
|
|
|
94
|
+
// packages/dom/src/reconcile.ts
|
|
95
|
+
function reconcile(parent, marker, a, b) {
|
|
96
|
+
let aStart = 0;
|
|
97
|
+
let bStart = 0;
|
|
98
|
+
let aEnd = a.length - 1;
|
|
99
|
+
let bEnd = b.length - 1;
|
|
100
|
+
while (aStart <= aEnd && bStart <= bEnd && a[aStart] === b[bStart]) {
|
|
101
|
+
aStart++;
|
|
102
|
+
bStart++;
|
|
103
|
+
}
|
|
104
|
+
while (aStart <= aEnd && bStart <= bEnd && a[aEnd] === b[bEnd]) {
|
|
105
|
+
aEnd--;
|
|
106
|
+
bEnd--;
|
|
107
|
+
}
|
|
108
|
+
const after = bEnd + 1 < b.length ? b[bEnd + 1] : marker;
|
|
109
|
+
if (aStart > aEnd) {
|
|
110
|
+
for (let i = bStart; i <= bEnd; i++) {
|
|
111
|
+
parent.insertBefore(b[i], after);
|
|
112
|
+
}
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
if (bStart > bEnd) {
|
|
116
|
+
for (let i = aStart; i <= aEnd; i++) {
|
|
117
|
+
parent.removeChild(a[i]);
|
|
118
|
+
}
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
reorder(parent, b, after, { a, aStart, aEnd, bStart, bEnd });
|
|
122
|
+
}
|
|
123
|
+
function reorder(parent, b, after, middle) {
|
|
124
|
+
const count = middle.bEnd - middle.bStart + 1;
|
|
125
|
+
const sources = sourcesOf(parent, b, middle);
|
|
126
|
+
const keep = longestIncreasing(sources);
|
|
127
|
+
let k = keep.length - 1;
|
|
128
|
+
let anchor = after;
|
|
129
|
+
for (let j = count - 1; j >= 0; j--) {
|
|
130
|
+
const node = b[middle.bStart + j];
|
|
131
|
+
if (k >= 0 && keep[k] === j) {
|
|
132
|
+
k--;
|
|
133
|
+
} else {
|
|
134
|
+
parent.insertBefore(node, anchor);
|
|
135
|
+
}
|
|
136
|
+
anchor = node;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
function sourcesOf(parent, b, middle) {
|
|
140
|
+
const { a, aStart, aEnd, bStart, bEnd } = middle;
|
|
141
|
+
const oldIndex = /* @__PURE__ */ new Map();
|
|
142
|
+
for (let i = aStart; i <= aEnd; i++) {
|
|
143
|
+
oldIndex.set(a[i], i);
|
|
144
|
+
}
|
|
145
|
+
const count = bEnd - bStart + 1;
|
|
146
|
+
const sources = new Int32Array(count).fill(-1);
|
|
147
|
+
for (let j = 0; j < count; j++) {
|
|
148
|
+
const node = b[bStart + j];
|
|
149
|
+
const found = oldIndex.get(node);
|
|
150
|
+
if (found !== void 0) {
|
|
151
|
+
sources[j] = found;
|
|
152
|
+
oldIndex.delete(node);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
for (const node of oldIndex.keys()) {
|
|
156
|
+
parent.removeChild(node);
|
|
157
|
+
}
|
|
158
|
+
return sources;
|
|
159
|
+
}
|
|
160
|
+
function longestIncreasing(sources) {
|
|
161
|
+
const length = sources.length;
|
|
162
|
+
const predecessor = new Int32Array(length).fill(-1);
|
|
163
|
+
const tails = [];
|
|
164
|
+
for (let i = 0; i < length; i++) {
|
|
165
|
+
const value = sources[i];
|
|
166
|
+
if (value === -1) {
|
|
167
|
+
continue;
|
|
168
|
+
}
|
|
169
|
+
let low = 0;
|
|
170
|
+
let high = tails.length;
|
|
171
|
+
while (low < high) {
|
|
172
|
+
const mid = low + high >> 1;
|
|
173
|
+
if (sources[tails[mid]] < value) {
|
|
174
|
+
low = mid + 1;
|
|
175
|
+
} else {
|
|
176
|
+
high = mid;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
if (low > 0) {
|
|
180
|
+
predecessor[i] = tails[low - 1];
|
|
181
|
+
}
|
|
182
|
+
tails[low] = i;
|
|
183
|
+
}
|
|
184
|
+
const result = [];
|
|
185
|
+
let cursor = tails.length > 0 ? tails[tails.length - 1] : -1;
|
|
186
|
+
while (cursor !== -1) {
|
|
187
|
+
result.push(cursor);
|
|
188
|
+
cursor = predecessor[cursor];
|
|
189
|
+
}
|
|
190
|
+
return result.reverse();
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
// packages/dom/src/insert.ts
|
|
194
|
+
import { bind, getOwner, onCleanup, runWithOwner } from "@firsthandjs/core";
|
|
195
|
+
|
|
196
|
+
// packages/dom/src/nodes.ts
|
|
197
|
+
var TEXT_NODE = 3;
|
|
198
|
+
function isNode(value) {
|
|
199
|
+
return typeof value.nodeType === "number";
|
|
200
|
+
}
|
|
201
|
+
function detach(node) {
|
|
202
|
+
const owner = node.parentNode;
|
|
203
|
+
if (owner !== null) {
|
|
204
|
+
owner.removeChild(node);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
function clearIn(parent, marker, current) {
|
|
208
|
+
if (marker === null && Array.isArray(current) && current.length > 1 && parent.childNodes.length === current.length) {
|
|
209
|
+
parent.textContent = "";
|
|
210
|
+
return null;
|
|
211
|
+
}
|
|
212
|
+
return clear(current);
|
|
213
|
+
}
|
|
214
|
+
function clear(current) {
|
|
215
|
+
if (current !== null) {
|
|
216
|
+
if (Array.isArray(current)) {
|
|
217
|
+
for (let i = 0; i < current.length; i++) {
|
|
218
|
+
detach(current[i]);
|
|
219
|
+
}
|
|
220
|
+
} else {
|
|
221
|
+
detach(current);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
return null;
|
|
225
|
+
}
|
|
226
|
+
function single(parent, marker, current, node) {
|
|
227
|
+
if (current === node) {
|
|
228
|
+
return node;
|
|
229
|
+
}
|
|
230
|
+
if (current !== null && !Array.isArray(current)) {
|
|
231
|
+
parent.replaceChild(node, current);
|
|
232
|
+
return node;
|
|
233
|
+
}
|
|
234
|
+
clear(current);
|
|
235
|
+
parent.insertBefore(node, marker);
|
|
236
|
+
return node;
|
|
237
|
+
}
|
|
238
|
+
|
|
94
239
|
// packages/dom/src/insert.ts
|
|
95
|
-
import {
|
|
96
|
-
bind,
|
|
97
|
-
createOwner,
|
|
98
|
-
signal,
|
|
99
|
-
disposeOwner,
|
|
100
|
-
getOwner,
|
|
101
|
-
onCleanup,
|
|
102
|
-
runWithOwner,
|
|
103
|
-
setOwner
|
|
104
|
-
} from "@firsthandjs/core";
|
|
105
240
|
var discarding = 0;
|
|
106
241
|
function discard(body) {
|
|
107
242
|
discarding++;
|
|
@@ -111,10 +246,6 @@ function discard(body) {
|
|
|
111
246
|
discarding--;
|
|
112
247
|
}
|
|
113
248
|
}
|
|
114
|
-
var TEXT_NODE = 3;
|
|
115
|
-
function isNode(value) {
|
|
116
|
-
return typeof value.nodeType === "number";
|
|
117
|
-
}
|
|
118
249
|
var PART = /* @__PURE__ */ Symbol("firsthand.part");
|
|
119
250
|
var FLAT = /* @__PURE__ */ Symbol("firsthand.flat");
|
|
120
251
|
var PENDING = /* @__PURE__ */ Symbol("firsthand.pending");
|
|
@@ -125,115 +256,15 @@ function part(thunk) {
|
|
|
125
256
|
function isDynamicChild(value) {
|
|
126
257
|
return PART in value;
|
|
127
258
|
}
|
|
128
|
-
function
|
|
129
|
-
return { slots: [], owner: getOwner(), generation: 0, name };
|
|
130
|
-
}
|
|
131
|
-
function wrote(store2) {
|
|
132
|
-
store2.busy = true;
|
|
133
|
-
}
|
|
134
|
-
function site(store2, index) {
|
|
135
|
-
const existing = store2.slots[index];
|
|
136
|
-
if (existing !== void 0) {
|
|
137
|
-
existing.seen = store2.generation;
|
|
138
|
-
return existing;
|
|
139
|
-
}
|
|
140
|
-
const slot = { seen: store2.generation };
|
|
141
|
-
store2.slots[index] = slot;
|
|
142
|
-
return slot;
|
|
143
|
-
}
|
|
144
|
-
function open(store2, slot) {
|
|
145
|
-
const owner = createOwner(store2.owner);
|
|
146
|
-
slot.owner = owner;
|
|
147
|
-
return setOwner(owner);
|
|
148
|
-
}
|
|
149
|
-
function close(previous) {
|
|
150
|
-
setOwner(previous);
|
|
151
|
-
}
|
|
152
|
-
function ran(store2, value) {
|
|
153
|
-
devRan(store2);
|
|
154
|
-
const generation = store2.generation;
|
|
155
|
-
const slots = store2.slots;
|
|
156
|
-
for (let i = 0; i < slots.length; i++) {
|
|
157
|
-
const slot = slots[i];
|
|
158
|
-
if (slot === void 0 || slot.seen === generation) {
|
|
159
|
-
continue;
|
|
160
|
-
}
|
|
161
|
-
if (slot.owner !== void 0) {
|
|
162
|
-
disposeOwner(slot.owner);
|
|
163
|
-
}
|
|
164
|
-
slots[i] = void 0;
|
|
165
|
-
}
|
|
166
|
-
store2.generation = generation + 1;
|
|
167
|
-
return value;
|
|
168
|
-
}
|
|
169
|
-
function cell(store2, index, value) {
|
|
170
|
-
const slot = site(store2, index);
|
|
171
|
-
const existing = slot.cell;
|
|
172
|
-
if (existing === void 0) {
|
|
173
|
-
const made = signal(value);
|
|
174
|
-
slot.cell = made;
|
|
175
|
-
return made;
|
|
176
|
-
}
|
|
177
|
-
if (existing.peek() !== value) {
|
|
178
|
-
devHandedNewFunction(store2, value);
|
|
179
|
-
wrote(store2);
|
|
180
|
-
existing.value = value;
|
|
181
|
-
}
|
|
182
|
-
return existing;
|
|
183
|
-
}
|
|
184
|
-
function writeChild(store2, index, parent, marker, value) {
|
|
185
|
-
const slot = site(store2, index);
|
|
186
|
-
if (slot.node === void 0 && hydration.current !== null) {
|
|
187
|
-
const claimed = hydration.current.claim(parent, marker);
|
|
188
|
-
if (claimed !== null) {
|
|
189
|
-
if (typeof value === "object" && value !== null && isDynamicChild(value)) {
|
|
190
|
-
slot.last = value;
|
|
191
|
-
hydration.current.keep(slot, parent, value.anchor, claimed);
|
|
192
|
-
runWithOwner(value.owner, () => {
|
|
193
|
-
insert(parent, value.thunk, value.anchor);
|
|
194
|
-
});
|
|
195
|
-
return;
|
|
196
|
-
}
|
|
197
|
-
slot.node = claimed.nodes;
|
|
198
|
-
slot.text = claimed.text;
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
const type = typeof value;
|
|
202
|
-
if (type === "string" || type === "number") {
|
|
203
|
-
const text = String(value);
|
|
204
|
-
if (text === slot.text) {
|
|
205
|
-
return;
|
|
206
|
-
}
|
|
207
|
-
wrote(store2);
|
|
208
|
-
slot.text = text;
|
|
209
|
-
slot.node = applyChild(parent, marker, slot.node ?? null, text);
|
|
210
|
-
return;
|
|
211
|
-
}
|
|
212
|
-
slot.text = void 0;
|
|
213
|
-
if (value === slot.last) {
|
|
214
|
-
return;
|
|
215
|
-
}
|
|
216
|
-
wrote(store2);
|
|
217
|
-
slot.last = value;
|
|
218
|
-
slot.node = applyChild(parent, marker, slot.node ?? null, value);
|
|
219
|
-
}
|
|
220
|
-
function insert(parent, value, marker = null, seed, report) {
|
|
259
|
+
function insert(parent, value, marker = null, options) {
|
|
221
260
|
if (typeof value !== "function") {
|
|
222
261
|
applyChild(parent, marker, null, value);
|
|
223
262
|
return;
|
|
224
263
|
}
|
|
225
|
-
|
|
226
|
-
let
|
|
227
|
-
|
|
264
|
+
const claimed = claimFor(parent, marker, options?.seed);
|
|
265
|
+
let current = claimed === null ? null : claimed.nodes;
|
|
266
|
+
let written = claimed?.text;
|
|
228
267
|
let adopting = claimed !== null;
|
|
229
|
-
if (claimed !== null) {
|
|
230
|
-
current = claimed.nodes;
|
|
231
|
-
written = claimed.text;
|
|
232
|
-
}
|
|
233
|
-
const body = () => {
|
|
234
|
-
run();
|
|
235
|
-
report?.(nodesOf(current, marker));
|
|
236
|
-
};
|
|
237
268
|
const run = () => {
|
|
238
269
|
const next2 = value();
|
|
239
270
|
const type = typeof next2;
|
|
@@ -247,24 +278,20 @@ function insert(parent, value, marker = null, seed, report) {
|
|
|
247
278
|
}
|
|
248
279
|
written = void 0;
|
|
249
280
|
if (type === "function") {
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
insert(parent, next2, marker, claimed);
|
|
253
|
-
return;
|
|
254
|
-
}
|
|
255
|
-
current = clear(current);
|
|
256
|
-
insert(parent, next2, marker, null);
|
|
281
|
+
current = adopting ? null : clear(current);
|
|
282
|
+
insert(parent, next2, marker, { seed: adopting ? claimed : null });
|
|
257
283
|
return;
|
|
258
284
|
}
|
|
259
285
|
current = applyChild(parent, marker, current, next2);
|
|
260
286
|
};
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
287
|
+
const report = options?.report;
|
|
288
|
+
bindIn(
|
|
289
|
+
claimed,
|
|
290
|
+
report === void 0 ? run : () => {
|
|
291
|
+
run();
|
|
292
|
+
report(nodesOf(current, marker));
|
|
293
|
+
}
|
|
294
|
+
);
|
|
268
295
|
adopting = false;
|
|
269
296
|
onCleanup(() => {
|
|
270
297
|
current = discarding > 0 ? null : clear(current);
|
|
@@ -275,6 +302,21 @@ function nodesOf(current, anchor) {
|
|
|
275
302
|
nodes.push(anchor);
|
|
276
303
|
return nodes;
|
|
277
304
|
}
|
|
305
|
+
function claimFor(parent, marker, seed) {
|
|
306
|
+
if (seed !== void 0) {
|
|
307
|
+
return seed;
|
|
308
|
+
}
|
|
309
|
+
return hydration.current === null ? null : hydration.current.claim(parent, marker);
|
|
310
|
+
}
|
|
311
|
+
function bindIn(claimed, body) {
|
|
312
|
+
if (claimed === null) {
|
|
313
|
+
bind(body);
|
|
314
|
+
return;
|
|
315
|
+
}
|
|
316
|
+
hydration.current.within(claimed.region, () => {
|
|
317
|
+
bind(body);
|
|
318
|
+
});
|
|
319
|
+
}
|
|
278
320
|
function applyChild(parent, marker, current, value) {
|
|
279
321
|
const type = typeof value;
|
|
280
322
|
if (value == null || type === "boolean") {
|
|
@@ -290,43 +332,17 @@ function applyChild(parent, marker, current, value) {
|
|
|
290
332
|
}
|
|
291
333
|
return single(parent, marker, current, document.createTextNode(text));
|
|
292
334
|
}
|
|
293
|
-
|
|
335
|
+
return applyOther(parent, marker, current, value);
|
|
336
|
+
}
|
|
337
|
+
function applyOther(parent, marker, current, value) {
|
|
338
|
+
if (typeof value === "function") {
|
|
294
339
|
return applyChild(parent, marker, current, value());
|
|
295
340
|
}
|
|
296
341
|
if (Array.isArray(value)) {
|
|
297
|
-
|
|
298
|
-
const rows = value;
|
|
299
|
-
if (rows.length === 0) {
|
|
300
|
-
return clearIn(parent, marker, current);
|
|
301
|
-
}
|
|
302
|
-
reconcile(
|
|
303
|
-
parent,
|
|
304
|
-
marker,
|
|
305
|
-
current === null ? [] : Array.isArray(current) ? current : [current],
|
|
306
|
-
rows
|
|
307
|
-
);
|
|
308
|
-
value[PENDING]?.(parent);
|
|
309
|
-
return rows;
|
|
310
|
-
}
|
|
311
|
-
const next2 = [];
|
|
312
|
-
const dynamic = [];
|
|
313
|
-
flatten(value, next2, dynamic);
|
|
314
|
-
if (next2.length === 0) {
|
|
315
|
-
return clearIn(parent, marker, current);
|
|
316
|
-
}
|
|
317
|
-
reconcile(
|
|
318
|
-
parent,
|
|
319
|
-
marker,
|
|
320
|
-
current === null ? [] : Array.isArray(current) ? current : [current],
|
|
321
|
-
next2
|
|
322
|
-
);
|
|
323
|
-
for (let i = 0; i < dynamic.length; i++) {
|
|
324
|
-
bindPart(dynamic[i], parent);
|
|
325
|
-
}
|
|
326
|
-
return next2;
|
|
342
|
+
return applyArray(parent, marker, current, value);
|
|
327
343
|
}
|
|
328
344
|
if (isDynamicChild(value)) {
|
|
329
|
-
return
|
|
345
|
+
return applyArray(parent, marker, current, [value]);
|
|
330
346
|
}
|
|
331
347
|
if (isNode(value)) {
|
|
332
348
|
return single(parent, marker, current, value);
|
|
@@ -334,13 +350,38 @@ function applyChild(parent, marker, current, value) {
|
|
|
334
350
|
devWarnRenderedObject(value);
|
|
335
351
|
return applyChild(parent, marker, current, String(value));
|
|
336
352
|
}
|
|
353
|
+
function asList(current) {
|
|
354
|
+
return current === null ? [] : Array.isArray(current) ? current : [current];
|
|
355
|
+
}
|
|
356
|
+
function applyArray(parent, marker, current, value) {
|
|
357
|
+
if (FLAT in value) {
|
|
358
|
+
const rows = value;
|
|
359
|
+
if (rows.length === 0) {
|
|
360
|
+
return clearIn(parent, marker, current);
|
|
361
|
+
}
|
|
362
|
+
reconcile(parent, marker, asList(current), rows);
|
|
363
|
+
value[PENDING]?.(parent);
|
|
364
|
+
return rows;
|
|
365
|
+
}
|
|
366
|
+
const next2 = [];
|
|
367
|
+
const dynamic = [];
|
|
368
|
+
flatten(value, next2, dynamic);
|
|
369
|
+
if (next2.length === 0) {
|
|
370
|
+
return clearIn(parent, marker, current);
|
|
371
|
+
}
|
|
372
|
+
reconcile(parent, marker, asList(current), next2);
|
|
373
|
+
for (let i = 0; i < dynamic.length; i++) {
|
|
374
|
+
bindPart(dynamic[i], parent);
|
|
375
|
+
}
|
|
376
|
+
return next2;
|
|
377
|
+
}
|
|
337
378
|
function bindPart(child, parent, report) {
|
|
338
379
|
if (mounted.has(child)) {
|
|
339
380
|
return;
|
|
340
381
|
}
|
|
341
382
|
mounted.add(child);
|
|
342
383
|
runWithOwner(child.owner ?? getOwner(), () => {
|
|
343
|
-
insert(parent, child.thunk, child.anchor, void 0
|
|
384
|
+
insert(parent, child.thunk, child.anchor, report === void 0 ? void 0 : { report });
|
|
344
385
|
onCleanup(() => {
|
|
345
386
|
mounted.delete(child);
|
|
346
387
|
});
|
|
@@ -369,131 +410,6 @@ function flatten(value, out, dynamic) {
|
|
|
369
410
|
}
|
|
370
411
|
}
|
|
371
412
|
}
|
|
372
|
-
function detach(node) {
|
|
373
|
-
const owner = node.parentNode;
|
|
374
|
-
if (owner !== null) {
|
|
375
|
-
owner.removeChild(node);
|
|
376
|
-
}
|
|
377
|
-
}
|
|
378
|
-
function clearIn(parent, marker, current) {
|
|
379
|
-
if (marker === null && Array.isArray(current) && current.length > 1 && parent.childNodes.length === current.length) {
|
|
380
|
-
parent.textContent = "";
|
|
381
|
-
return null;
|
|
382
|
-
}
|
|
383
|
-
return clear(current);
|
|
384
|
-
}
|
|
385
|
-
function clear(current) {
|
|
386
|
-
if (current !== null) {
|
|
387
|
-
if (Array.isArray(current)) {
|
|
388
|
-
for (let i = 0; i < current.length; i++) {
|
|
389
|
-
detach(current[i]);
|
|
390
|
-
}
|
|
391
|
-
} else {
|
|
392
|
-
detach(current);
|
|
393
|
-
}
|
|
394
|
-
}
|
|
395
|
-
return null;
|
|
396
|
-
}
|
|
397
|
-
function single(parent, marker, current, node) {
|
|
398
|
-
if (current === node) {
|
|
399
|
-
return node;
|
|
400
|
-
}
|
|
401
|
-
if (current !== null && !Array.isArray(current)) {
|
|
402
|
-
parent.replaceChild(node, current);
|
|
403
|
-
return node;
|
|
404
|
-
}
|
|
405
|
-
clear(current);
|
|
406
|
-
parent.insertBefore(node, marker);
|
|
407
|
-
return node;
|
|
408
|
-
}
|
|
409
|
-
function reconcile(parent, marker, a, b) {
|
|
410
|
-
let aStart = 0;
|
|
411
|
-
let bStart = 0;
|
|
412
|
-
let aEnd = a.length - 1;
|
|
413
|
-
let bEnd = b.length - 1;
|
|
414
|
-
while (aStart <= aEnd && bStart <= bEnd && a[aStart] === b[bStart]) {
|
|
415
|
-
aStart++;
|
|
416
|
-
bStart++;
|
|
417
|
-
}
|
|
418
|
-
while (aStart <= aEnd && bStart <= bEnd && a[aEnd] === b[bEnd]) {
|
|
419
|
-
aEnd--;
|
|
420
|
-
bEnd--;
|
|
421
|
-
}
|
|
422
|
-
const after = bEnd + 1 < b.length ? b[bEnd + 1] : marker;
|
|
423
|
-
if (aStart > aEnd) {
|
|
424
|
-
for (let i = bStart; i <= bEnd; i++) {
|
|
425
|
-
parent.insertBefore(b[i], after);
|
|
426
|
-
}
|
|
427
|
-
return;
|
|
428
|
-
}
|
|
429
|
-
if (bStart > bEnd) {
|
|
430
|
-
for (let i = aStart; i <= aEnd; i++) {
|
|
431
|
-
parent.removeChild(a[i]);
|
|
432
|
-
}
|
|
433
|
-
return;
|
|
434
|
-
}
|
|
435
|
-
const oldIndex = /* @__PURE__ */ new Map();
|
|
436
|
-
for (let i = aStart; i <= aEnd; i++) {
|
|
437
|
-
oldIndex.set(a[i], i);
|
|
438
|
-
}
|
|
439
|
-
const middle = bEnd - bStart + 1;
|
|
440
|
-
const sources = new Int32Array(middle).fill(-1);
|
|
441
|
-
for (let j = 0; j < middle; j++) {
|
|
442
|
-
const node = b[bStart + j];
|
|
443
|
-
const found = oldIndex.get(node);
|
|
444
|
-
if (found !== void 0) {
|
|
445
|
-
sources[j] = found;
|
|
446
|
-
oldIndex.delete(node);
|
|
447
|
-
}
|
|
448
|
-
}
|
|
449
|
-
for (const node of oldIndex.keys()) {
|
|
450
|
-
parent.removeChild(node);
|
|
451
|
-
}
|
|
452
|
-
const keep = longestIncreasing(sources);
|
|
453
|
-
let k = keep.length - 1;
|
|
454
|
-
let anchor = after;
|
|
455
|
-
for (let j = middle - 1; j >= 0; j--) {
|
|
456
|
-
const node = b[bStart + j];
|
|
457
|
-
if (k >= 0 && keep[k] === j) {
|
|
458
|
-
k--;
|
|
459
|
-
} else {
|
|
460
|
-
parent.insertBefore(node, anchor);
|
|
461
|
-
}
|
|
462
|
-
anchor = node;
|
|
463
|
-
}
|
|
464
|
-
}
|
|
465
|
-
function longestIncreasing(sources) {
|
|
466
|
-
const length = sources.length;
|
|
467
|
-
const predecessor = new Int32Array(length).fill(-1);
|
|
468
|
-
const tails = [];
|
|
469
|
-
for (let i = 0; i < length; i++) {
|
|
470
|
-
const value = sources[i];
|
|
471
|
-
if (value === -1) {
|
|
472
|
-
continue;
|
|
473
|
-
}
|
|
474
|
-
let low = 0;
|
|
475
|
-
let high = tails.length;
|
|
476
|
-
while (low < high) {
|
|
477
|
-
const mid = low + high >> 1;
|
|
478
|
-
if (sources[tails[mid]] < value) {
|
|
479
|
-
low = mid + 1;
|
|
480
|
-
} else {
|
|
481
|
-
high = mid;
|
|
482
|
-
}
|
|
483
|
-
}
|
|
484
|
-
if (low > 0) {
|
|
485
|
-
predecessor[i] = tails[low - 1];
|
|
486
|
-
}
|
|
487
|
-
tails[low] = i;
|
|
488
|
-
}
|
|
489
|
-
const result = [];
|
|
490
|
-
let cursor = tails.length > 0 ? tails[tails.length - 1] : -1;
|
|
491
|
-
while (cursor !== -1) {
|
|
492
|
-
result.push(cursor);
|
|
493
|
-
cursor = predecessor[cursor];
|
|
494
|
-
}
|
|
495
|
-
return result.reverse();
|
|
496
|
-
}
|
|
497
413
|
|
|
498
414
|
export {
|
|
499
415
|
devWarn,
|
|
@@ -501,25 +417,19 @@ export {
|
|
|
501
417
|
devPart,
|
|
502
418
|
devComponent,
|
|
503
419
|
label,
|
|
420
|
+
devRan,
|
|
421
|
+
devHandedNewFunction,
|
|
504
422
|
devHydrationMismatch,
|
|
505
423
|
hydration,
|
|
506
424
|
first,
|
|
507
425
|
next,
|
|
426
|
+
reconcile,
|
|
508
427
|
discard,
|
|
509
428
|
FLAT,
|
|
510
429
|
PENDING,
|
|
511
430
|
part,
|
|
512
431
|
isDynamicChild,
|
|
513
|
-
store,
|
|
514
|
-
wrote,
|
|
515
|
-
site,
|
|
516
|
-
open,
|
|
517
|
-
close,
|
|
518
|
-
ran,
|
|
519
|
-
cell,
|
|
520
|
-
writeChild,
|
|
521
432
|
insert,
|
|
522
433
|
applyChild,
|
|
523
|
-
bindPart
|
|
524
|
-
reconcile
|
|
434
|
+
bindPart
|
|
525
435
|
};
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What `@firsthandjs/dom` throws.
|
|
3
|
+
*
|
|
4
|
+
* Its own file so that the adapter is about resolving a foreign element type
|
|
5
|
+
* and nothing else. Prefixed like every other error in this project, so that
|
|
6
|
+
* `instanceof` cannot be confused by a `ComponentError` from somewhere else.
|
|
7
|
+
*/
|
|
8
|
+
export declare class FirsthandComponentError extends Error {
|
|
9
|
+
constructor(name: string);
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,qBAAa,uBAAwB,SAAQ,KAAK;gBACpC,IAAI,EAAE,MAAM;CAQzB"}
|
package/dist/hydrate.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hydrate.d.ts","sourceRoot":"","sources":["../src/hydrate.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAa,KAAK,OAAO,EAAe,KAAK,MAAM,EAAE,MAAM,YAAY,CAAC;AAC/E,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AA0B3C;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,OAAO,CAAC,IAAI,EAAE,MAAM,IAAI,EAAE,SAAS,GAAE,UAA0B,GAAG,OAAO,CAIxF;AAED;;;;;;GAMG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAAE,SAAS,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,CAAC,GAAG,CAAC,CAgBhE;AAaD;;;;;;GAMG;AACH,wBAAgB,KAAK,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,GAAG,IAAI,CAW9C;AAED;;;;;;;;GAQG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,GAAG,IAAI,GAAG,OAAO,GAAG,IAAI,
|
|
1
|
+
{"version":3,"file":"hydrate.d.ts","sourceRoot":"","sources":["../src/hydrate.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAa,KAAK,OAAO,EAAe,KAAK,MAAM,EAAE,MAAM,YAAY,CAAC;AAC/E,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AA0B3C;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,OAAO,CAAC,IAAI,EAAE,MAAM,IAAI,EAAE,SAAS,GAAE,UAA0B,GAAG,OAAO,CAIxF;AAED;;;;;;GAMG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAAE,SAAS,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,CAAC,GAAG,CAAC,CAgBhE;AAaD;;;;;;GAMG;AACH,wBAAgB,KAAK,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,GAAG,IAAI,CAW9C;AAED;;;;;;;;GAQG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,GAAG,IAAI,GAAG,OAAO,GAAG,IAAI,CAe7E;AA+DD;;;;;;;;;GASG;AACH,wBAAgB,KAAK,CAAC,MAAM,EAAE,IAAI,GAAG,IAAI,GAAG,IAAI,CAK/C;AAED,uEAAuE;AACvE,wBAAgB,MAAM,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,GAAG,CAAC,CAQ1D"}
|