@marko/runtime-tags 0.1.19 → 0.1.21

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/debug/dom.js CHANGED
@@ -25,7 +25,6 @@ __export(dom_exports, {
25
25
  attrTags: () => attrTags,
26
26
  attrs: () => attrs,
27
27
  attrsEvents: () => attrsEvents,
28
- changeHandler: () => changeHandler,
29
28
  childClosures: () => childClosures,
30
29
  classAttr: () => classAttr,
31
30
  closure: () => closure,
@@ -42,6 +41,8 @@ __export(dom_exports, {
42
41
  controllable_input_value_effect: () => controllable_input_value_effect,
43
42
  controllable_select_value: () => controllable_select_value,
44
43
  controllable_select_value_effect: () => controllable_select_value_effect,
44
+ controllable_textarea_value: () => controllable_input_value,
45
+ controllable_textarea_value_effect: () => controllable_input_value_effect,
45
46
  createRenderer: () => createRenderer,
46
47
  createRendererWithOwner: () => createRendererWithOwner,
47
48
  createScope: () => createScope,
@@ -50,6 +51,7 @@ __export(dom_exports, {
50
51
  dynamicClosure: () => dynamicClosure,
51
52
  dynamicSubscribers: () => dynamicSubscribers,
52
53
  dynamicTagAttrs: () => dynamicTagAttrs,
54
+ effect: () => effect,
53
55
  forIn: () => forIn,
54
56
  forOf: () => forOf,
55
57
  forTo: () => forTo,
@@ -59,7 +61,6 @@ __export(dom_exports, {
59
61
  inConditionalScope: () => inConditionalScope,
60
62
  inLoopScope: () => inLoopScope,
61
63
  init: () => init,
62
- initValue: () => initValue,
63
64
  intersection: () => intersection,
64
65
  intersections: () => intersections,
65
66
  lifecycle: () => lifecycle,
@@ -70,18 +71,14 @@ __export(dom_exports, {
70
71
  nodeRef: () => nodeRef,
71
72
  on: () => on,
72
73
  partialAttrs: () => partialAttrs,
73
- prepare: () => prepare,
74
74
  props: () => props,
75
- queueControllableSource: () => queueControllableSource,
76
- queueEffect: () => queueEffect,
77
- queueSource: () => queueSource,
78
75
  register: () => register,
79
76
  registerBoundSignal: () => registerBoundSignal,
80
77
  registerSubscriber: () => registerSubscriber,
81
78
  resetAbortSignal: () => resetAbortSignal,
82
79
  run: () => run,
83
- runEffects: () => runEffects,
84
80
  setTagVar: () => setTagVar,
81
+ state: () => state,
85
82
  styleAttr: () => styleAttr,
86
83
  tagVarSignal: () => tagVarSignal,
87
84
  value: () => value
@@ -134,6 +131,51 @@ function forTo(to, from, step, cb) {
134
131
  }
135
132
  }
136
133
 
134
+ // src/dom/schedule.ts
135
+ var task;
136
+ var port2 = /* @__PURE__ */ (() => {
137
+ const { port1, port2: port22 } = new MessageChannel();
138
+ port1.onmessage = () => {
139
+ isScheduled = false;
140
+ if (true) {
141
+ task.run(run);
142
+ task = void 0;
143
+ } else {
144
+ run();
145
+ }
146
+ };
147
+ return port22;
148
+ })();
149
+ var isScheduled;
150
+ function schedule() {
151
+ if (!isScheduled) {
152
+ if (true) {
153
+ task = console.createTask?.("queue") || {
154
+ run(fn) {
155
+ fn();
156
+ }
157
+ };
158
+ }
159
+ isScheduled = true;
160
+ queueMicrotask(flushAndWaitFrame);
161
+ }
162
+ }
163
+ function flushAndWaitFrame() {
164
+ if (true) {
165
+ task.run(run);
166
+ } else {
167
+ run();
168
+ }
169
+ requestAnimationFrame(triggerMacroTask);
170
+ }
171
+ function triggerMacroTask() {
172
+ port2.postMessage(0);
173
+ }
174
+
175
+ // src/common/meta.ts
176
+ var DEFAULT_RUNTIME_ID = "M";
177
+ var DEFAULT_RENDER_ID = "_";
178
+
137
179
  // src/dom/scope.ts
138
180
  var debugID = 0;
139
181
  function createScope($global) {
@@ -163,12 +205,7 @@ function destroyScope(scope) {
163
205
  return scope;
164
206
  }
165
207
  function _destroyScope(scope) {
166
- const cleanup = scope.___cleanup;
167
- if (cleanup) {
168
- for (const instance of cleanup) {
169
- _destroyScope(instance);
170
- }
171
- }
208
+ scope.___cleanup?.forEach(_destroyScope);
172
209
  const controllers = scope.___abortControllers;
173
210
  if (controllers) {
174
211
  for (const ctrl of controllers.values()) {
@@ -204,90 +241,547 @@ function insertBefore(scope, parent, nextSibling) {
204
241
  }
205
242
  }
206
243
 
207
- // src/dom/abort-signal.ts
208
- function resetAbortSignal(scope, id) {
209
- const controllers = scope.___abortControllers;
210
- if (controllers) {
211
- const ctrl = controllers.get(id);
212
- if (ctrl) {
213
- ctrl.abort();
214
- controllers.delete(id);
215
- }
244
+ // src/dom/resume.ts
245
+ var registeredValues = {};
246
+ var Render = class {
247
+ ___scopeStack = [];
248
+ ___scopeLookup = {};
249
+ ___serializeContext = {
250
+ _: registeredValues
251
+ };
252
+ constructor(renders, runtimeId, renderId) {
253
+ this.___renders = renders;
254
+ this.___runtimeId = runtimeId;
255
+ this.___renderId = renderId;
256
+ this.___data = renders[renderId];
257
+ this.___resume();
216
258
  }
217
- }
218
- function getAbortSignal(scope, id) {
219
- const controllers = scope.___abortControllers ||= /* @__PURE__ */ new Map();
220
- let controller = controllers.get(id);
221
- if (!controller) {
222
- onDestroy(scope);
223
- controllers.set(id, controller = new AbortController());
259
+ w() {
260
+ this.___data.w();
261
+ this.___resume();
224
262
  }
225
- return controller.signal;
226
- }
227
-
228
- // src/common/compat-meta.ts
229
- var prefix = true ? "$compat_" : "$C_";
230
- var RENDERER_REGISTER_ID = prefix + (true ? "renderer" : "r");
231
- var SET_SCOPE_REGISTER_ID = prefix + (true ? "setScope" : "s");
232
-
233
- // src/common/helpers.ts
234
- function classValue(value2) {
235
- return toDelimitedString(value2, " ", stringifyClassObject);
236
- }
237
- function stringifyClassObject(name, value2) {
238
- return value2 ? name : "";
239
- }
240
- function styleValue(value2) {
241
- return toDelimitedString(value2, ";", stringifyStyleObject);
242
- }
243
- var NON_DIMENSIONAL = /^(--|ta|or|li|z)|n-c|i(do|nk|m|t)|w$|we/;
244
- function stringifyStyleObject(name, value2) {
245
- return value2 || value2 === 0 ? `${name}:${typeof value2 === "number" && value2 && !NON_DIMENSIONAL.test(name) ? value2 + "px" : value2}` : "";
246
- }
247
- function toDelimitedString(val, delimiter, stringify) {
248
- switch (typeof val) {
249
- case "string":
250
- return val;
251
- case "object":
252
- if (val !== null) {
253
- let result = "";
254
- let curDelimiter = "";
255
- if (Array.isArray(val)) {
256
- for (const v of val) {
257
- const part = toDelimitedString(v, delimiter, stringify);
258
- if (part !== "") {
259
- result += curDelimiter + part;
260
- curDelimiter = delimiter;
263
+ ___resume() {
264
+ const data2 = this.___data;
265
+ const serializeContext = this.___serializeContext;
266
+ const scopeLookup = this.___scopeLookup;
267
+ const visits = data2.v;
268
+ const cleanupOwners = /* @__PURE__ */ new Map();
269
+ if (visits.length) {
270
+ const commentPrefix = data2.i;
271
+ const commentPrefixLen = commentPrefix.length;
272
+ const cleanupMarkers = /* @__PURE__ */ new Map();
273
+ data2.v = [];
274
+ const sectionEnd = (visit, scopeId = this.___currentScopeId, curNode = visit) => {
275
+ const scope = scopeLookup[scopeId] ||= {};
276
+ let endNode = curNode;
277
+ while ((endNode = endNode.previousSibling).nodeType === 8) ;
278
+ scope.___endNode = endNode;
279
+ const startNode = scope.___startNode ||= endNode;
280
+ let len = cleanupMarkers.size;
281
+ for (const [markerScopeId, markerNode] of cleanupMarkers) {
282
+ if (!len--) break;
283
+ if (markerScopeId !== scopeId && startNode.compareDocumentPosition(markerNode) & 4 && curNode.compareDocumentPosition(markerNode) & 2) {
284
+ cleanupOwners.set("" + markerScopeId, scopeId);
285
+ cleanupMarkers.delete(markerScopeId);
286
+ }
287
+ }
288
+ cleanupMarkers.set(scopeId, visit);
289
+ return scope;
290
+ };
291
+ for (const visit of visits) {
292
+ const commentText = visit.data;
293
+ const token = commentText[commentPrefixLen];
294
+ const scopeId = parseInt(commentText.slice(commentPrefixLen + 1));
295
+ const scope = scopeLookup[scopeId] ||= {};
296
+ const dataIndex = commentText.indexOf(" ") + 1;
297
+ const data3 = dataIndex ? commentText.slice(dataIndex) : "";
298
+ if (token === "*" /* Node */) {
299
+ scope[data3] = visit.previousSibling;
300
+ } else if (token === "$" /* Cleanup */) {
301
+ cleanupMarkers.set(scopeId, visit);
302
+ } else if (token === "[" /* SectionStart */) {
303
+ if (this.___currentScopeId) {
304
+ if (data3) {
305
+ sectionEnd(visit);
261
306
  }
307
+ this.___scopeStack.push(this.___currentScopeId);
262
308
  }
263
- } else {
264
- for (const name in val) {
265
- const v = val[name];
266
- const part = stringify(name, v);
267
- if (part !== "") {
268
- result += curDelimiter + part;
269
- curDelimiter = delimiter;
309
+ this.___currentScopeId = scopeId;
310
+ scope.___startNode = visit;
311
+ } else if (token === "]" /* SectionEnd */) {
312
+ scope[data3] = visit;
313
+ if (scopeId < this.___currentScopeId) {
314
+ const currParent = visit.parentNode;
315
+ const startNode = sectionEnd(visit).___startNode;
316
+ if (currParent && currParent !== startNode.parentNode) {
317
+ currParent.prepend(startNode);
270
318
  }
319
+ this.___currentScopeId = this.___scopeStack.pop();
320
+ }
321
+ } else if (token === "|" /* SectionSingleNodesEnd */) {
322
+ scope[true ? data3.slice(0, data3.indexOf(" ")) : parseInt(data3)] = visit;
323
+ const childScopeIds = JSON.parse(
324
+ "[" + data3.slice(data3.indexOf(" ") + 1) + "]"
325
+ );
326
+ let curNode = visit;
327
+ for (let i = childScopeIds.length - 1; i >= 0; i--) {
328
+ curNode = sectionEnd(visit, childScopeIds[i], curNode).___endNode;
271
329
  }
272
330
  }
273
- return result;
274
331
  }
332
+ }
333
+ const resumes = data2.r;
334
+ if (resumes) {
335
+ data2.r = [];
336
+ const len = resumes.length;
337
+ let i = 0;
338
+ try {
339
+ isResuming = true;
340
+ while (i < len) {
341
+ const resumeData = resumes[i++];
342
+ if (typeof resumeData === "function") {
343
+ const scopes = resumeData(serializeContext);
344
+ let { $global } = scopeLookup;
345
+ if (!$global) {
346
+ scopeLookup.$global = $global = scopes.$ || {};
347
+ $global.runtimeId = this.___runtimeId;
348
+ $global.renderId = this.___renderId;
349
+ }
350
+ for (const scopeId in scopes) {
351
+ if (scopeId !== "$") {
352
+ const scope = scopes[scopeId];
353
+ const prevScope = scopeLookup[scopeId];
354
+ scope.$global = $global;
355
+ if (prevScope !== scope) {
356
+ scopeLookup[scopeId] = Object.assign(
357
+ scope,
358
+ prevScope
359
+ );
360
+ }
361
+ const cleanupOwnerId = cleanupOwners.get(scopeId);
362
+ if (cleanupOwnerId) {
363
+ scope.___cleanupOwner = scopes[cleanupOwnerId];
364
+ onDestroy(scope);
365
+ }
366
+ }
367
+ }
368
+ } else if (i === len || typeof resumes[i] !== "string") {
369
+ delete this.___renders[this.___renderId];
370
+ } else {
371
+ registeredValues[resumes[i++]](
372
+ scopeLookup[resumeData]
373
+ );
374
+ }
375
+ }
376
+ } finally {
377
+ isResuming = false;
378
+ }
379
+ }
275
380
  }
276
- return "";
381
+ };
382
+ var isResuming = false;
383
+ function register(id, obj) {
384
+ registeredValues[id] = obj;
385
+ return obj;
277
386
  }
278
- function normalizeDynamicRenderer(value2) {
279
- if (value2) return value2.renderBody || value2.default || value2;
387
+ function registerBoundSignal(id, signal) {
388
+ registeredValues[id] = (scope) => (valueOrOp) => signal(scope, valueOrOp);
389
+ return signal;
280
390
  }
281
-
282
- // src/dom/reconcile.ts
283
- var WRONG_POS = 2147483647;
284
- function reconcile(parent, oldScopes, newScopes, afterReference) {
285
- let oldStart = 0;
286
- let newStart = 0;
287
- let oldEnd = oldScopes.length - 1;
288
- let newEnd = newScopes.length - 1;
289
- let oldStartScope = oldScopes[oldStart];
290
- let newStartScope = newScopes[newStart];
391
+ function getRegisteredWithScope(id, scope) {
392
+ const val = registeredValues[id];
393
+ return scope ? val(scope) : val;
394
+ }
395
+ function init(runtimeId = DEFAULT_RUNTIME_ID) {
396
+ if (true) {
397
+ if (!runtimeId.match(/^[_$a-z][_$a-z0-9]*$/i)) {
398
+ throw new Error(
399
+ `Invalid runtimeId: "${runtimeId}". The runtimeId must be a valid JavaScript identifier.`
400
+ );
401
+ }
402
+ }
403
+ const resumeRender = (renderId) => resumeRender[renderId] = renders[renderId] = new Render(renders, runtimeId, renderId);
404
+ let renders;
405
+ if (window[runtimeId]) {
406
+ setRenders(window[runtimeId]);
407
+ } else {
408
+ Object.defineProperty(window, runtimeId, {
409
+ configurable: true,
410
+ set: setRenders
411
+ });
412
+ }
413
+ function setRenders(v) {
414
+ if (true) {
415
+ if (renders) {
416
+ throw new Error(
417
+ "Marko tried to initialize multiple times. It could be that there are multiple instances of Marko running on the page."
418
+ );
419
+ }
420
+ }
421
+ renders = v;
422
+ for (const renderId in v) {
423
+ resumeRender(renderId);
424
+ }
425
+ Object.defineProperty(window, runtimeId, {
426
+ configurable: true,
427
+ value: resumeRender
428
+ });
429
+ }
430
+ }
431
+ function registerSubscriber(id, signal) {
432
+ register(id, signal.___subscribe);
433
+ return signal;
434
+ }
435
+ function nodeRef(id, key) {
436
+ return register(id, (scope) => () => scope[key]);
437
+ }
438
+
439
+ // src/dom/signals.ts
440
+ var MARK = true ? Symbol("mark") : {};
441
+ var CLEAN = true ? Symbol("clean") : {};
442
+ var DIRTY = true ? Symbol("dirty") : {};
443
+ function state(valueAccessor, fn, getIntersection) {
444
+ const valueSignal = value(valueAccessor, fn, getIntersection);
445
+ const markAccessor = valueAccessor + "#" /* Mark */;
446
+ return (scope, valueOrOp, valueChange) => {
447
+ if (rendering) {
448
+ const valueIsOp = valueOrOp === MARK || valueOrOp === CLEAN || valueOrOp === DIRTY;
449
+ valueSignal(
450
+ scope,
451
+ valueIsOp || valueChange || scope[markAccessor] === void 0 ? valueOrOp : CLEAN
452
+ );
453
+ } else if (valueChange) {
454
+ valueChange(valueOrOp);
455
+ } else {
456
+ queueSource(scope, valueSignal, valueOrOp);
457
+ }
458
+ return valueOrOp;
459
+ };
460
+ }
461
+ function value(valueAccessor, fn, getIntersection) {
462
+ const markAccessor = valueAccessor + "#" /* Mark */;
463
+ let intersection2 = getIntersection && ((scope, op) => (intersection2 = getIntersection())(scope, op));
464
+ return (scope, valueOrOp) => {
465
+ if (valueOrOp === MARK) {
466
+ if ((scope[markAccessor] = (scope[markAccessor] ?? 0) + 1) === 1) {
467
+ intersection2?.(scope, MARK);
468
+ }
469
+ } else if (valueOrOp !== DIRTY) {
470
+ const existing = scope[markAccessor] !== void 0;
471
+ if ((scope[markAccessor] ||= 1) === 1) {
472
+ if (valueOrOp === CLEAN || existing && scope[valueAccessor] === valueOrOp) {
473
+ intersection2?.(scope, CLEAN);
474
+ } else {
475
+ scope[valueAccessor] = valueOrOp;
476
+ fn && fn(scope, valueOrOp);
477
+ intersection2?.(scope, DIRTY);
478
+ }
479
+ }
480
+ scope[markAccessor]--;
481
+ }
482
+ };
483
+ }
484
+ var accessorId = 0;
485
+ function intersection(count, fn, getIntersection) {
486
+ const dirtyAccessor = "?" /* Dynamic */ + accessorId++;
487
+ const markAccessor = dirtyAccessor + "#" /* Mark */;
488
+ let intersection2 = getIntersection && ((scope, op) => (intersection2 = getIntersection())(scope, op));
489
+ return (scope, op) => {
490
+ if (op === MARK) {
491
+ if ((scope[markAccessor] = (scope[markAccessor] ?? 0) + 1) === 1) {
492
+ intersection2?.(scope, MARK);
493
+ }
494
+ } else if (scope[markAccessor] === void 0) {
495
+ scope[markAccessor] = count - 1;
496
+ scope[dirtyAccessor] = true;
497
+ } else if (--scope[markAccessor] === 0) {
498
+ if (op === DIRTY || scope[dirtyAccessor]) {
499
+ scope[dirtyAccessor] = false;
500
+ fn(scope, 0);
501
+ intersection2?.(scope, DIRTY);
502
+ } else {
503
+ intersection2?.(scope, CLEAN);
504
+ }
505
+ } else {
506
+ scope[dirtyAccessor] ||= op === DIRTY;
507
+ }
508
+ };
509
+ }
510
+ var defaultGetOwnerScope = (scope) => scope._;
511
+ function closure(ownerValueAccessor, fn, getOwnerScope = defaultGetOwnerScope, getIntersection) {
512
+ const dirtyAccessor = "?" /* Dynamic */ + accessorId++;
513
+ const markAccessor = dirtyAccessor + 1;
514
+ const getOwnerValueAccessor = typeof ownerValueAccessor === "function" ? ownerValueAccessor : () => ownerValueAccessor;
515
+ let intersection2 = getIntersection && ((scope, op) => (intersection2 = getIntersection())(scope, op));
516
+ return (scope, op) => {
517
+ if (op === MARK) {
518
+ if ((scope[markAccessor] = (scope[markAccessor] ?? 0) + 1) === 1) {
519
+ intersection2?.(scope, MARK);
520
+ }
521
+ } else {
522
+ let ownerScope, ownerValueAccessor2;
523
+ if (scope[markAccessor] === void 0) {
524
+ ownerScope = getOwnerScope(scope);
525
+ ownerValueAccessor2 = getOwnerValueAccessor(scope);
526
+ const ownerMark = ownerScope[ownerValueAccessor2 + "#" /* Mark */];
527
+ const ownerHasRun = ownerMark === void 0 ? !ownerScope.___client : ownerMark === 0;
528
+ scope[markAccessor] = ownerHasRun ? 1 : 2;
529
+ op = DIRTY;
530
+ }
531
+ if (--scope[markAccessor] === 0) {
532
+ if (op === DIRTY || scope[dirtyAccessor]) {
533
+ scope[dirtyAccessor] = false;
534
+ ownerScope ||= getOwnerScope(scope);
535
+ ownerValueAccessor2 ||= getOwnerValueAccessor(scope);
536
+ fn && fn(scope, ownerScope[ownerValueAccessor2]);
537
+ intersection2?.(scope, DIRTY);
538
+ } else {
539
+ intersection2?.(scope, CLEAN);
540
+ }
541
+ } else {
542
+ scope[dirtyAccessor] ||= op === DIRTY;
543
+ }
544
+ }
545
+ };
546
+ }
547
+ function dynamicClosure(ownerValueAccessor, fn, getOwnerScope = defaultGetOwnerScope, getIntersection) {
548
+ const getOwnerValueAccessor = typeof ownerValueAccessor === "function" ? ownerValueAccessor : () => ownerValueAccessor;
549
+ const signalFn = closure(
550
+ getOwnerValueAccessor,
551
+ fn,
552
+ getOwnerScope,
553
+ getIntersection
554
+ );
555
+ const subscribeFns = /* @__PURE__ */ new WeakMap();
556
+ signalFn.___subscribe = (scope) => {
557
+ const subscribeFn = (value2) => signalFn(scope, value2);
558
+ const ownerScope = getOwnerScope(scope);
559
+ const providerSubscriptionsAccessor = getOwnerValueAccessor(scope) + "*" /* Subscribers */;
560
+ subscribeFns.set(scope, subscribeFn);
561
+ (ownerScope[providerSubscriptionsAccessor] ||= /* @__PURE__ */ new Set()).add(subscribeFn);
562
+ };
563
+ signalFn.___unsubscribe = (scope) => {
564
+ const ownerScope = getOwnerScope(scope);
565
+ const providerSubscriptionsAccessor = getOwnerValueAccessor(scope) + "*" /* Subscribers */;
566
+ ownerScope[providerSubscriptionsAccessor]?.delete(subscribeFns.get(scope));
567
+ subscribeFns.delete(scope);
568
+ };
569
+ return signalFn;
570
+ }
571
+ function childClosures(closureSignals, childAccessor) {
572
+ const signal = (scope, op) => {
573
+ const childScope = scope[childAccessor];
574
+ for (const closureSignal of closureSignals) {
575
+ closureSignal(childScope, op);
576
+ }
577
+ };
578
+ signal.___subscribe = (scope) => {
579
+ const childScope = scope[childAccessor];
580
+ for (const closureSignal of closureSignals) {
581
+ closureSignal.___subscribe?.(childScope);
582
+ }
583
+ };
584
+ signal.___unsubscribe = (scope) => {
585
+ const childScope = scope[childAccessor];
586
+ for (const closureSignal of closureSignals) {
587
+ closureSignal.___unsubscribe?.(childScope);
588
+ }
589
+ };
590
+ return signal;
591
+ }
592
+ function dynamicSubscribers(valueAccessor) {
593
+ const subscribersAccessor = valueAccessor + "*" /* Subscribers */;
594
+ return (scope, op) => {
595
+ const subscribers = scope[subscribersAccessor];
596
+ if (subscribers) {
597
+ for (const subscriber of subscribers) {
598
+ subscriber(op);
599
+ }
600
+ }
601
+ };
602
+ }
603
+ function setTagVar(scope, childAccessor, tagVarSignal2) {
604
+ scope[childAccessor]["/" /* TagVariable */] = (valueOrOp) => tagVarSignal2(scope, valueOrOp);
605
+ }
606
+ var tagVarSignal = (scope, valueOrOp) => scope["/" /* TagVariable */]?.(valueOrOp);
607
+ var renderBodyClosures = (renderBody, childScope, op) => {
608
+ const signals = renderBody?.___closureSignals;
609
+ if (signals) {
610
+ for (const signal of signals) {
611
+ signal(childScope, op);
612
+ }
613
+ }
614
+ };
615
+ var tagIdsByGlobal = /* @__PURE__ */ new WeakMap();
616
+ function nextTagId({ $global }) {
617
+ const id = tagIdsByGlobal.get($global) || 0;
618
+ tagIdsByGlobal.set($global, id + 1);
619
+ return "c" + $global.runtimeId + $global.renderId + id.toString(36);
620
+ }
621
+ function inChild(childAccessor, signal) {
622
+ return (scope, valueOrOp) => {
623
+ signal(scope[childAccessor], valueOrOp);
624
+ };
625
+ }
626
+ function intersections(signals) {
627
+ return (scope, op) => {
628
+ for (const signal of signals) {
629
+ signal(scope, op);
630
+ }
631
+ };
632
+ }
633
+ function effect(id, fn) {
634
+ register(id, fn);
635
+ return (scope) => {
636
+ queueEffect(scope, fn);
637
+ };
638
+ }
639
+
640
+ // src/dom/queue.ts
641
+ var pendingSignals = [];
642
+ var pendingEffects = [];
643
+ var rendering = false;
644
+ function queueSource(scope, signal, value2) {
645
+ schedule();
646
+ rendering = true;
647
+ signal(scope, MARK);
648
+ rendering = false;
649
+ pendingSignals.push(scope, signal, value2);
650
+ return value2;
651
+ }
652
+ function queueEffect(scope, fn) {
653
+ pendingEffects.push(scope, fn);
654
+ }
655
+ function run() {
656
+ const signals = pendingSignals;
657
+ const effects = pendingEffects;
658
+ try {
659
+ rendering = true;
660
+ pendingSignals = [];
661
+ runSignals(signals);
662
+ } finally {
663
+ rendering = false;
664
+ }
665
+ pendingEffects = [];
666
+ runEffects(effects);
667
+ }
668
+ function prepareEffects(fn) {
669
+ const prevSignals = pendingSignals;
670
+ const prevEffects = pendingEffects;
671
+ const preparedEffects = pendingEffects = [];
672
+ const preparedSignals = pendingSignals = [];
673
+ try {
674
+ rendering = true;
675
+ fn();
676
+ pendingSignals = prevSignals;
677
+ runSignals(preparedSignals);
678
+ } finally {
679
+ rendering = false;
680
+ pendingSignals = prevSignals;
681
+ pendingEffects = prevEffects;
682
+ }
683
+ return preparedEffects;
684
+ }
685
+ function runEffects(effects = pendingEffects) {
686
+ for (let i = 0; i < effects.length; i += 2 /* Total */) {
687
+ const scope = effects[i];
688
+ const fn = effects[i + 1];
689
+ fn(scope);
690
+ }
691
+ }
692
+ function runSignals(signals) {
693
+ for (let i = 0; i < signals.length; i += 3 /* Total */) {
694
+ const scope = signals[i + 0 /* Scope */];
695
+ const signal = signals[i + 1 /* Signal */];
696
+ const value2 = signals[i + 2 /* Value */];
697
+ signal(scope, value2);
698
+ }
699
+ }
700
+
701
+ // src/dom/abort-signal.ts
702
+ function resetAbortSignal(scope, id) {
703
+ const controllers = scope.___abortControllers;
704
+ if (controllers) {
705
+ const ctrl = controllers.get(id);
706
+ if (ctrl) {
707
+ queueEffect(null, () => ctrl.abort());
708
+ controllers.delete(id);
709
+ }
710
+ }
711
+ }
712
+ function getAbortSignal(scope, id) {
713
+ const controllers = scope.___abortControllers ||= /* @__PURE__ */ new Map();
714
+ let controller = controllers.get(id);
715
+ if (!controller) {
716
+ onDestroy(scope);
717
+ controllers.set(id, controller = new AbortController());
718
+ }
719
+ return controller.signal;
720
+ }
721
+
722
+ // src/common/compat-meta.ts
723
+ var prefix = true ? "$compat_" : "$C_";
724
+ var RENDERER_REGISTER_ID = prefix + (true ? "renderer" : "r");
725
+ var SET_SCOPE_REGISTER_ID = prefix + (true ? "setScope" : "s");
726
+
727
+ // src/common/helpers.ts
728
+ function classValue(value2) {
729
+ return toDelimitedString(value2, " ", stringifyClassObject);
730
+ }
731
+ function stringifyClassObject(name, value2) {
732
+ return value2 ? name : "";
733
+ }
734
+ function styleValue(value2) {
735
+ return toDelimitedString(value2, ";", stringifyStyleObject);
736
+ }
737
+ var NON_DIMENSIONAL = /^(--|ta|or|li|z)|n-c|i(do|nk|m|t)|w$|we/;
738
+ function stringifyStyleObject(name, value2) {
739
+ return value2 || value2 === 0 ? `${name}:${typeof value2 === "number" && value2 && !NON_DIMENSIONAL.test(name) ? value2 + "px" : value2}` : "";
740
+ }
741
+ function toDelimitedString(val, delimiter, stringify) {
742
+ switch (typeof val) {
743
+ case "string":
744
+ return val;
745
+ case "object":
746
+ if (val !== null) {
747
+ let result = "";
748
+ let curDelimiter = "";
749
+ if (Array.isArray(val)) {
750
+ for (const v of val) {
751
+ const part = toDelimitedString(v, delimiter, stringify);
752
+ if (part !== "") {
753
+ result += curDelimiter + part;
754
+ curDelimiter = delimiter;
755
+ }
756
+ }
757
+ } else {
758
+ for (const name in val) {
759
+ const v = val[name];
760
+ const part = stringify(name, v);
761
+ if (part !== "") {
762
+ result += curDelimiter + part;
763
+ curDelimiter = delimiter;
764
+ }
765
+ }
766
+ }
767
+ return result;
768
+ }
769
+ }
770
+ return "";
771
+ }
772
+ function normalizeDynamicRenderer(value2) {
773
+ if (value2) return value2.renderBody || value2.default || value2;
774
+ }
775
+
776
+ // src/dom/reconcile.ts
777
+ var WRONG_POS = 2147483647;
778
+ function reconcile(parent, oldScopes, newScopes, afterReference) {
779
+ let oldStart = 0;
780
+ let newStart = 0;
781
+ let oldEnd = oldScopes.length - 1;
782
+ let newEnd = newScopes.length - 1;
783
+ let oldStartScope = oldScopes[oldStart];
784
+ let newStartScope = newScopes[newStart];
291
785
  let oldEndScope = oldScopes[oldEnd];
292
786
  let newEndScope = newScopes[newEnd];
293
787
  let i;
@@ -339,478 +833,150 @@ function reconcile(parent, oldScopes, newScopes, afterReference) {
339
833
  let pos = 0;
340
834
  let synced = 0;
341
835
  const keyIndex = /* @__PURE__ */ new Map();
342
- for (j = newStart; j <= newEnd; ++j) {
343
- keyIndex.set(newScopes[j], j);
344
- }
345
- for (i = oldStart; i <= oldEnd && synced < newLength; ++i) {
346
- oldScope = oldScopes[i];
347
- j = keyIndex.get(oldScope);
348
- if (j !== void 0) {
349
- pos = pos > j ? WRONG_POS : j;
350
- ++synced;
351
- newScope = newScopes[j];
352
- sources[j - newStart] = i;
353
- aNullable[i] = null;
354
- }
355
- }
356
- if (oldLength === oldScopes.length && synced === 0) {
357
- for (; newStart < newLength; ++newStart) {
358
- insertBefore(newScopes[newStart], parent, afterReference);
359
- }
360
- for (; oldStart < oldLength; ++oldStart) {
361
- removeAndDestroyScope(oldScopes[oldStart]);
362
- }
363
- } else {
364
- i = oldLength - synced;
365
- while (i > 0) {
366
- oldScope = aNullable[oldStart++];
367
- if (oldScope !== null) {
368
- removeAndDestroyScope(oldScope);
369
- i--;
370
- }
371
- }
372
- if (pos === WRONG_POS) {
373
- const seq = longestIncreasingSubsequence(sources);
374
- j = seq.length - 1;
375
- k = newScopes.length;
376
- for (i = newLength - 1; i >= 0; --i) {
377
- if (sources[i] === -1) {
378
- pos = i + newStart;
379
- newScope = newScopes[pos++];
380
- nextSibling = pos < k ? newScopes[pos].___startNode : afterReference;
381
- insertBefore(newScope, parent, nextSibling);
382
- } else {
383
- if (j < 0 || i !== seq[j]) {
384
- pos = i + newStart;
385
- newScope = newScopes[pos++];
386
- nextSibling = pos < k ? newScopes[pos].___startNode : afterReference;
387
- insertBefore(newScope, parent, nextSibling);
388
- } else {
389
- --j;
390
- }
391
- }
392
- }
393
- } else if (synced !== newLength) {
394
- k = newScopes.length;
395
- for (i = newLength - 1; i >= 0; --i) {
396
- if (sources[i] === -1) {
397
- pos = i + newStart;
398
- newScope = newScopes[pos++];
399
- nextSibling = pos < k ? newScopes[pos].___startNode : afterReference;
400
- insertBefore(newScope, parent, nextSibling);
401
- }
402
- }
403
- }
404
- }
405
- }
406
- }
407
- function longestIncreasingSubsequence(a) {
408
- const p = a.slice();
409
- const result = [];
410
- result.push(0);
411
- let u;
412
- let v;
413
- for (let i = 0, il = a.length; i < il; ++i) {
414
- if (a[i] === -1) {
415
- continue;
416
- }
417
- const j = result[result.length - 1];
418
- if (a[j] < a[i]) {
419
- p[i] = j;
420
- result.push(i);
421
- continue;
422
- }
423
- u = 0;
424
- v = result.length - 1;
425
- while (u < v) {
426
- const c = (u + v) / 2 | 0;
427
- if (a[result[c]] < a[i]) {
428
- u = c + 1;
429
- } else {
430
- v = c;
431
- }
432
- }
433
- if (a[i] < a[result[u]]) {
434
- if (u > 0) {
435
- p[i] = result[u - 1];
436
- }
437
- result[u] = i;
438
- }
439
- }
440
- u = result.length;
441
- v = result[u - 1];
442
- while (u-- > 0) {
443
- result[u] = v;
444
- v = p[v];
445
- }
446
- return result;
447
- }
448
-
449
- // src/dom/event.ts
450
- var elementHandlersByEvent = /* @__PURE__ */ new Map();
451
- var defaultDelegator = createDelegator();
452
- function on(element, type, handler) {
453
- let handlersByElement = elementHandlersByEvent.get(type);
454
- if (!handlersByElement) {
455
- elementHandlersByEvent.set(type, handlersByElement = /* @__PURE__ */ new WeakMap());
456
- }
457
- if (!handlersByElement.has(element)) {
458
- defaultDelegator(element, type, handleDelegated);
459
- }
460
- handlersByElement.set(element, handler || void 0);
461
- }
462
- function createDelegator() {
463
- const delegatedEventsByRoot = /* @__PURE__ */ new WeakMap();
464
- return function ensureDelegated(node, type, handler) {
465
- const root = node.getRootNode();
466
- let delegatedEvents = delegatedEventsByRoot.get(root);
467
- if (!delegatedEvents) {
468
- delegatedEventsByRoot.set(root, delegatedEvents = /* @__PURE__ */ new Set());
469
- }
470
- if (!delegatedEvents.has(type)) {
471
- delegatedEvents.add(type);
472
- root.addEventListener(type, handler, true);
473
- }
474
- };
475
- }
476
- function handleDelegated(ev) {
477
- let target = ev.target;
478
- if (target) {
479
- const handlersByElement = elementHandlersByEvent.get(ev.type);
480
- handlersByElement.get(target)?.(ev, target);
481
- if (ev.bubbles) {
482
- while ((target = target.parentElement) && !ev.cancelBubble) {
483
- handlersByElement.get(target)?.(ev, target);
484
- }
485
- }
486
- }
487
- }
488
-
489
- // src/dom/schedule.ts
490
- var task;
491
- var port2 = /* @__PURE__ */ (() => {
492
- const { port1, port2: port22 } = new MessageChannel();
493
- port1.onmessage = () => {
494
- isScheduled = false;
495
- if (true) {
496
- task.run(run);
497
- task = void 0;
498
- } else {
499
- run();
500
- }
501
- };
502
- return port22;
503
- })();
504
- var isScheduled;
505
- function schedule() {
506
- if (!isScheduled) {
507
- if (true) {
508
- task = console.createTask?.("queue") || {
509
- run(fn) {
510
- fn();
511
- }
512
- };
513
- }
514
- isScheduled = true;
515
- queueMicrotask(flushAndWaitFrame);
516
- }
517
- }
518
- function flushAndWaitFrame() {
519
- if (true) {
520
- task.run(run);
521
- } else {
522
- run();
523
- }
524
- requestAnimationFrame(triggerMacroTask);
525
- }
526
- function triggerMacroTask() {
527
- port2.postMessage(0);
528
- }
529
-
530
- // src/dom/signals.ts
531
- var MARK = true ? Symbol("mark") : {};
532
- var CLEAN = true ? Symbol("clean") : {};
533
- var DIRTY = true ? Symbol("dirty") : {};
534
- function initValue(valueAccessor, valueSignal) {
535
- const markAccessor = valueAccessor + "#" /* Mark */;
536
- return (scope, valueOrOp) => {
537
- if (valueOrOp !== MARK && scope[markAccessor] === void 0) {
538
- valueSignal(scope, valueOrOp);
539
- }
540
- };
541
- }
542
- function changeHandler(valueAccessor, fn) {
543
- const markAccessor = valueAccessor + "#" /* Mark */;
544
- return (scope, valueOrOp) => {
545
- if (true) {
546
- if (valueOrOp !== MARK && valueOrOp !== CLEAN && valueOrOp !== DIRTY) {
547
- if (valueOrOp != null && typeof valueOrOp !== "function") {
548
- throw new Error(
549
- `Invalid value ${valueOrOp} for change handler '${valueAccessor}'`
550
- );
551
- } else if (scope[markAccessor] !== void 0) {
552
- const prevValue = scope[valueAccessor];
553
- if (prevValue && !valueOrOp) {
554
- throw new Error(
555
- `Change handler '${valueAccessor}' cannot change from a function to ${valueOrOp}`
556
- );
557
- } else if (!prevValue && valueOrOp) {
558
- throw new Error(
559
- `Change handler '${valueAccessor}' cannot change from a nullish to a function`
560
- );
561
- }
562
- }
563
- }
564
- }
565
- fn(scope, valueOrOp);
566
- };
567
- }
568
- function value(valueAccessor, fn, getIntersection) {
569
- const markAccessor = valueAccessor + "#" /* Mark */;
570
- let intersection2 = getIntersection && ((scope, op) => (intersection2 = getIntersection())(scope, op));
571
- return (scope, valueOrOp) => {
572
- if (valueOrOp === MARK) {
573
- if ((scope[markAccessor] = (scope[markAccessor] ?? 0) + 1) === 1) {
574
- intersection2?.(scope, MARK);
575
- }
576
- } else if (valueOrOp !== DIRTY) {
577
- const existing = scope[markAccessor] !== void 0;
578
- if ((scope[markAccessor] ||= 1) === 1) {
579
- if (valueOrOp === CLEAN || existing && scope[valueAccessor] === valueOrOp) {
580
- intersection2?.(scope, CLEAN);
581
- } else {
582
- scope[valueAccessor] = valueOrOp;
583
- fn?.(scope, valueOrOp);
584
- intersection2?.(scope, DIRTY);
585
- }
586
- }
587
- scope[markAccessor]--;
836
+ for (j = newStart; j <= newEnd; ++j) {
837
+ keyIndex.set(newScopes[j], j);
588
838
  }
589
- };
590
- }
591
- var accessorId = 0;
592
- function intersection(count, fn, getIntersection) {
593
- const dirtyAccessor = "?" /* Dynamic */ + accessorId++;
594
- const markAccessor = dirtyAccessor + "#" /* Mark */;
595
- let intersection2 = getIntersection && ((scope, op) => (intersection2 = getIntersection())(scope, op));
596
- return (scope, op) => {
597
- if (op === MARK) {
598
- if ((scope[markAccessor] = (scope[markAccessor] ?? 0) + 1) === 1) {
599
- intersection2?.(scope, MARK);
600
- }
601
- } else if (scope[markAccessor] === void 0) {
602
- scope[markAccessor] = count - 1;
603
- scope[dirtyAccessor] = true;
604
- } else if (--scope[markAccessor] === 0) {
605
- if (op === DIRTY || scope[dirtyAccessor]) {
606
- scope[dirtyAccessor] = false;
607
- fn(scope, 0);
608
- intersection2?.(scope, DIRTY);
609
- } else {
610
- intersection2?.(scope, CLEAN);
839
+ for (i = oldStart; i <= oldEnd && synced < newLength; ++i) {
840
+ oldScope = oldScopes[i];
841
+ j = keyIndex.get(oldScope);
842
+ if (j !== void 0) {
843
+ pos = pos > j ? WRONG_POS : j;
844
+ ++synced;
845
+ newScope = newScopes[j];
846
+ sources[j - newStart] = i;
847
+ aNullable[i] = null;
611
848
  }
612
- } else {
613
- scope[dirtyAccessor] ||= op === DIRTY;
614
849
  }
615
- };
616
- }
617
- var defaultGetOwnerScope = (scope) => scope._;
618
- function closure(ownerValueAccessor, fn, getOwnerScope = defaultGetOwnerScope, getIntersection) {
619
- const dirtyAccessor = "?" /* Dynamic */ + accessorId++;
620
- const markAccessor = dirtyAccessor + 1;
621
- const getOwnerValueAccessor = typeof ownerValueAccessor === "function" ? ownerValueAccessor : () => ownerValueAccessor;
622
- let intersection2 = getIntersection && ((scope, op) => (intersection2 = getIntersection())(scope, op));
623
- return (scope, op) => {
624
- if (op === MARK) {
625
- if ((scope[markAccessor] = (scope[markAccessor] ?? 0) + 1) === 1) {
626
- intersection2?.(scope, MARK);
850
+ if (oldLength === oldScopes.length && synced === 0) {
851
+ for (; newStart < newLength; ++newStart) {
852
+ insertBefore(newScopes[newStart], parent, afterReference);
853
+ }
854
+ for (; oldStart < oldLength; ++oldStart) {
855
+ removeAndDestroyScope(oldScopes[oldStart]);
627
856
  }
628
857
  } else {
629
- let ownerScope, ownerValueAccessor2;
630
- if (scope[markAccessor] === void 0) {
631
- ownerScope = getOwnerScope(scope);
632
- ownerValueAccessor2 = getOwnerValueAccessor(scope);
633
- const ownerMark = ownerScope[ownerValueAccessor2 + "#" /* Mark */];
634
- const ownerHasRun = ownerMark === void 0 ? !ownerScope.___client : ownerMark === 0;
635
- scope[markAccessor] = ownerHasRun ? 1 : 2;
636
- op = DIRTY;
858
+ i = oldLength - synced;
859
+ while (i > 0) {
860
+ oldScope = aNullable[oldStart++];
861
+ if (oldScope !== null) {
862
+ removeAndDestroyScope(oldScope);
863
+ i--;
864
+ }
637
865
  }
638
- if (--scope[markAccessor] === 0) {
639
- if (op === DIRTY || scope[dirtyAccessor]) {
640
- scope[dirtyAccessor] = false;
641
- ownerScope ||= getOwnerScope(scope);
642
- ownerValueAccessor2 ||= getOwnerValueAccessor(scope);
643
- fn?.(scope, ownerScope[ownerValueAccessor2]);
644
- intersection2?.(scope, DIRTY);
645
- } else {
646
- intersection2?.(scope, CLEAN);
866
+ if (pos === WRONG_POS) {
867
+ const seq = longestIncreasingSubsequence(sources);
868
+ j = seq.length - 1;
869
+ k = newScopes.length;
870
+ for (i = newLength - 1; i >= 0; --i) {
871
+ if (sources[i] === -1) {
872
+ pos = i + newStart;
873
+ newScope = newScopes[pos++];
874
+ nextSibling = pos < k ? newScopes[pos].___startNode : afterReference;
875
+ insertBefore(newScope, parent, nextSibling);
876
+ } else {
877
+ if (j < 0 || i !== seq[j]) {
878
+ pos = i + newStart;
879
+ newScope = newScopes[pos++];
880
+ nextSibling = pos < k ? newScopes[pos].___startNode : afterReference;
881
+ insertBefore(newScope, parent, nextSibling);
882
+ } else {
883
+ --j;
884
+ }
885
+ }
886
+ }
887
+ } else if (synced !== newLength) {
888
+ k = newScopes.length;
889
+ for (i = newLength - 1; i >= 0; --i) {
890
+ if (sources[i] === -1) {
891
+ pos = i + newStart;
892
+ newScope = newScopes[pos++];
893
+ nextSibling = pos < k ? newScopes[pos].___startNode : afterReference;
894
+ insertBefore(newScope, parent, nextSibling);
895
+ }
647
896
  }
648
- } else {
649
- scope[dirtyAccessor] ||= op === DIRTY;
650
897
  }
651
898
  }
652
- };
653
- }
654
- function dynamicClosure(ownerValueAccessor, fn, getOwnerScope = defaultGetOwnerScope, getIntersection) {
655
- const getOwnerValueAccessor = typeof ownerValueAccessor === "function" ? ownerValueAccessor : () => ownerValueAccessor;
656
- const signalFn = closure(
657
- getOwnerValueAccessor,
658
- fn,
659
- getOwnerScope,
660
- getIntersection
661
- );
662
- const subscribeFns = /* @__PURE__ */ new WeakMap();
663
- signalFn.___subscribe = (scope) => {
664
- const subscribeFn = (value2) => signalFn(scope, value2);
665
- const ownerScope = getOwnerScope(scope);
666
- const providerSubscriptionsAccessor = getOwnerValueAccessor(scope) + "*" /* Subscribers */;
667
- subscribeFns.set(scope, subscribeFn);
668
- (ownerScope[providerSubscriptionsAccessor] ||= /* @__PURE__ */ new Set()).add(subscribeFn);
669
- };
670
- signalFn.___unsubscribe = (scope) => {
671
- const ownerScope = getOwnerScope(scope);
672
- const providerSubscriptionsAccessor = getOwnerValueAccessor(scope) + "*" /* Subscribers */;
673
- ownerScope[providerSubscriptionsAccessor]?.delete(subscribeFns.get(scope));
674
- subscribeFns.delete(scope);
675
- };
676
- return signalFn;
899
+ }
677
900
  }
678
- function childClosures(closureSignals, childAccessor) {
679
- const signal = (scope, op) => {
680
- const childScope = scope[childAccessor];
681
- for (const closureSignal of closureSignals) {
682
- closureSignal(childScope, op);
683
- }
684
- };
685
- signal.___subscribe = (scope) => {
686
- const childScope = scope[childAccessor];
687
- for (const closureSignal of closureSignals) {
688
- closureSignal.___subscribe?.(childScope);
901
+ function longestIncreasingSubsequence(a) {
902
+ const p = a.slice();
903
+ const result = [];
904
+ result.push(0);
905
+ let u;
906
+ let v;
907
+ for (let i = 0, il = a.length; i < il; ++i) {
908
+ if (a[i] === -1) {
909
+ continue;
689
910
  }
690
- };
691
- signal.___unsubscribe = (scope) => {
692
- const childScope = scope[childAccessor];
693
- for (const closureSignal of closureSignals) {
694
- closureSignal.___unsubscribe?.(childScope);
911
+ const j = result[result.length - 1];
912
+ if (a[j] < a[i]) {
913
+ p[i] = j;
914
+ result.push(i);
915
+ continue;
695
916
  }
696
- };
697
- return signal;
698
- }
699
- function dynamicSubscribers(valueAccessor) {
700
- const subscribersAccessor = valueAccessor + "*" /* Subscribers */;
701
- return (scope, op) => {
702
- const subscribers = scope[subscribersAccessor];
703
- if (subscribers) {
704
- for (const subscriber of subscribers) {
705
- subscriber(op);
917
+ u = 0;
918
+ v = result.length - 1;
919
+ while (u < v) {
920
+ const c = (u + v) / 2 | 0;
921
+ if (a[result[c]] < a[i]) {
922
+ u = c + 1;
923
+ } else {
924
+ v = c;
706
925
  }
707
926
  }
708
- };
709
- }
710
- function setTagVar(scope, childAccessor, tagVarSignal2) {
711
- scope[childAccessor]["/" /* TagVariable */] = (valueOrOp) => tagVarSignal2(scope, valueOrOp);
712
- }
713
- var tagVarSignal = (scope, valueOrOp) => scope["/" /* TagVariable */]?.(valueOrOp);
714
- var renderBodyClosures = (renderBody, childScope, op) => {
715
- const signals = renderBody?.___closureSignals;
716
- if (signals) {
717
- for (const signal of signals) {
718
- signal(childScope, op);
719
- }
720
- }
721
- };
722
- var tagIdsByGlobal = /* @__PURE__ */ new WeakMap();
723
- function nextTagId({ $global }) {
724
- const id = tagIdsByGlobal.get($global) || 0;
725
- tagIdsByGlobal.set($global, id + 1);
726
- return "c" + $global.runtimeId + $global.renderId + id.toString(36);
727
- }
728
- function inChild(childAccessor, signal) {
729
- return (scope, valueOrOp) => {
730
- signal(scope[childAccessor], valueOrOp);
731
- };
732
- }
733
- function intersections(signals) {
734
- return (scope, op) => {
735
- for (const signal of signals) {
736
- signal(scope, op);
927
+ if (a[i] < a[result[u]]) {
928
+ if (u > 0) {
929
+ p[i] = result[u - 1];
930
+ }
931
+ result[u] = i;
737
932
  }
738
- };
739
- }
740
-
741
- // src/dom/queue.ts
742
- var currentBatch = [];
743
- var currentEffects = [];
744
- function queueControllableSource(scope, signal, changeHandler2, value2) {
745
- if (changeHandler2) {
746
- changeHandler2(value2);
747
- return value2;
748
- }
749
- return queueSource(scope, signal, value2);
750
- }
751
- function queueSource(scope, signal, value2) {
752
- schedule();
753
- signal(scope, MARK);
754
- currentBatch.push(scope, signal, value2);
755
- return value2;
756
- }
757
- function queueEffect(scope, fn) {
758
- currentEffects.push(scope, fn);
759
- }
760
- function run() {
761
- try {
762
- runBatch();
763
- } finally {
764
- currentBatch = [];
765
- }
766
- try {
767
- runEffects();
768
- } finally {
769
- currentEffects = [];
770
933
  }
771
- }
772
- function runSync(fn, v) {
773
- const prevBatch = currentBatch;
774
- const prevEffects = currentEffects;
775
- currentBatch = [];
776
- currentEffects = [];
777
- try {
778
- fn(v);
779
- runBatch();
780
- currentBatch = prevBatch;
781
- runEffects();
782
- } finally {
783
- currentBatch = prevBatch;
784
- currentEffects = prevEffects;
934
+ u = result.length;
935
+ v = result[u - 1];
936
+ while (u-- > 0) {
937
+ result[u] = v;
938
+ v = p[v];
785
939
  }
940
+ return result;
786
941
  }
787
- function prepare(fn) {
788
- const prevBatch = currentBatch;
789
- const prevEffects = currentEffects;
790
- const preparedEffects = currentEffects = [];
791
- currentBatch = [];
792
- try {
793
- fn();
794
- runBatch();
795
- } finally {
796
- currentBatch = prevBatch;
797
- currentEffects = prevEffects;
942
+
943
+ // src/dom/event.ts
944
+ var elementHandlersByEvent = /* @__PURE__ */ new Map();
945
+ var defaultDelegator = createDelegator();
946
+ function on(element, type, handler) {
947
+ let handlersByElement = elementHandlersByEvent.get(type);
948
+ if (!handlersByElement) {
949
+ elementHandlersByEvent.set(type, handlersByElement = /* @__PURE__ */ new WeakMap());
798
950
  }
799
- return preparedEffects;
800
- }
801
- function runEffects(effects = currentEffects) {
802
- for (let i = 0; i < effects.length; i += 2 /* Total */) {
803
- const scope = effects[i];
804
- const fn = effects[i + 1];
805
- fn(scope);
951
+ if (!handlersByElement.has(element)) {
952
+ defaultDelegator(element, type, handleDelegated);
806
953
  }
954
+ handlersByElement.set(element, handler || void 0);
807
955
  }
808
- function runBatch() {
809
- for (let i = 0; i < currentBatch.length; i += 3 /* Total */) {
810
- const scope = currentBatch[i + 0 /* Scope */];
811
- const signal = currentBatch[i + 1 /* Signal */];
812
- const value2 = currentBatch[i + 2 /* Value */];
813
- signal(scope, value2);
956
+ function createDelegator() {
957
+ const delegatedEventsByRoot = /* @__PURE__ */ new WeakMap();
958
+ return function ensureDelegated(node, type, handler) {
959
+ const root = node.getRootNode();
960
+ let delegatedEvents = delegatedEventsByRoot.get(root);
961
+ if (!delegatedEvents) {
962
+ delegatedEventsByRoot.set(root, delegatedEvents = /* @__PURE__ */ new Set());
963
+ }
964
+ if (!delegatedEvents.has(type)) {
965
+ delegatedEvents.add(type);
966
+ root.addEventListener(type, handler, true);
967
+ }
968
+ };
969
+ }
970
+ function handleDelegated(ev) {
971
+ let target = ev.target;
972
+ if (target) {
973
+ const handlersByElement = elementHandlersByEvent.get(ev.type);
974
+ handlersByElement.get(target)?.(ev, target);
975
+ if (ev.bubbles) {
976
+ while ((target = target.parentElement) && !ev.cancelBubble) {
977
+ handlersByElement.get(target)?.(ev, target);
978
+ }
979
+ }
814
980
  }
815
981
  }
816
982
 
@@ -841,205 +1007,6 @@ function stripSpacesAndPunctuation(str) {
841
1007
  return str.replace(/[^\p{L}\p{N}]/gu, "");
842
1008
  }
843
1009
 
844
- // src/common/meta.ts
845
- var DEFAULT_RUNTIME_ID = "M";
846
- var DEFAULT_RENDER_ID = "_";
847
-
848
- // src/dom/resume.ts
849
- var registeredValues = {};
850
- var Render = class {
851
- ___scopeStack = [];
852
- ___scopeLookup = {};
853
- ___serializeContext = {
854
- _: registeredValues
855
- };
856
- constructor(renders, runtimeId, renderId) {
857
- this.___renders = renders;
858
- this.___runtimeId = runtimeId;
859
- this.___renderId = renderId;
860
- this.___data = renders[renderId];
861
- this.___resume();
862
- }
863
- w() {
864
- this.___data.w();
865
- this.___resume();
866
- }
867
- ___resume() {
868
- const data2 = this.___data;
869
- const serializeContext = this.___serializeContext;
870
- const scopeLookup = this.___scopeLookup;
871
- const visits = data2.v;
872
- const cleanupOwners = /* @__PURE__ */ new Map();
873
- if (visits.length) {
874
- const commentPrefix = data2.i;
875
- const commentPrefixLen = commentPrefix.length;
876
- const cleanupMarkers = /* @__PURE__ */ new Map();
877
- data2.v = [];
878
- const sectionEnd = (visit, scopeId = this.___currentScopeId, curNode = visit) => {
879
- const scope = scopeLookup[scopeId] ||= {};
880
- let endNode = curNode;
881
- while ((endNode = endNode.previousSibling).nodeType === 8) ;
882
- scope.___endNode = endNode;
883
- const startNode = scope.___startNode ||= endNode;
884
- let len = cleanupMarkers.size;
885
- for (const [markerScopeId, markerNode] of cleanupMarkers) {
886
- if (!len--) break;
887
- if (markerScopeId !== scopeId && startNode.compareDocumentPosition(markerNode) & 4 && curNode.compareDocumentPosition(markerNode) & 2) {
888
- cleanupOwners.set("" + markerScopeId, scopeId);
889
- cleanupMarkers.delete(markerScopeId);
890
- }
891
- }
892
- cleanupMarkers.set(scopeId, visit);
893
- return scope;
894
- };
895
- for (const visit of visits) {
896
- const commentText = visit.data;
897
- const token = commentText[commentPrefixLen];
898
- const scopeId = parseInt(commentText.slice(commentPrefixLen + 1));
899
- const scope = scopeLookup[scopeId] ||= {};
900
- const dataIndex = commentText.indexOf(" ") + 1;
901
- const data3 = dataIndex ? commentText.slice(dataIndex) : "";
902
- if (token === "*" /* Node */) {
903
- scope[data3] = visit.previousSibling;
904
- } else if (token === "$" /* Cleanup */) {
905
- cleanupMarkers.set(scopeId, visit);
906
- } else if (token === "[" /* SectionStart */) {
907
- if (this.___currentScopeId) {
908
- if (data3) {
909
- sectionEnd(visit);
910
- }
911
- this.___scopeStack.push(this.___currentScopeId);
912
- }
913
- this.___currentScopeId = scopeId;
914
- scope.___startNode = visit;
915
- } else if (token === "]" /* SectionEnd */) {
916
- scope[data3] = visit;
917
- if (scopeId < this.___currentScopeId) {
918
- const currParent = visit.parentNode;
919
- const startNode = sectionEnd(visit).___startNode;
920
- if (currParent && currParent !== startNode.parentNode) {
921
- currParent.prepend(startNode);
922
- }
923
- this.___currentScopeId = this.___scopeStack.pop();
924
- }
925
- } else if (token === "|" /* SectionSingleNodesEnd */) {
926
- scope[true ? data3.slice(0, data3.indexOf(" ")) : parseInt(data3)] = visit;
927
- const childScopeIds = JSON.parse(
928
- "[" + data3.slice(data3.indexOf(" ") + 1) + "]"
929
- );
930
- let curNode = visit;
931
- for (let i = childScopeIds.length - 1; i >= 0; i--) {
932
- curNode = sectionEnd(visit, childScopeIds[i], curNode).___endNode;
933
- }
934
- }
935
- }
936
- }
937
- const resumes = data2.r;
938
- if (resumes) {
939
- data2.r = [];
940
- const len = resumes.length;
941
- let i = 0;
942
- try {
943
- isResuming = true;
944
- while (i < len) {
945
- const resumeData = resumes[i++];
946
- if (typeof resumeData === "function") {
947
- const scopes = resumeData(serializeContext);
948
- let { $global } = scopeLookup;
949
- if (!$global) {
950
- scopeLookup.$global = $global = scopes.$ || {};
951
- $global.runtimeId = this.___runtimeId;
952
- $global.renderId = this.___renderId;
953
- }
954
- for (const scopeId in scopes) {
955
- if (scopeId !== "$") {
956
- const scope = scopes[scopeId];
957
- const prevScope = scopeLookup[scopeId];
958
- scope.$global = $global;
959
- if (prevScope !== scope) {
960
- scopeLookup[scopeId] = Object.assign(
961
- scope,
962
- prevScope
963
- );
964
- }
965
- const cleanupOwnerId = cleanupOwners.get(scopeId);
966
- if (cleanupOwnerId) {
967
- scope.___cleanupOwner = scopes[cleanupOwnerId];
968
- onDestroy(scope);
969
- }
970
- }
971
- }
972
- } else if (i === len || typeof resumes[i] !== "string") {
973
- delete this.___renders[this.___renderId];
974
- } else {
975
- registeredValues[resumes[i++]](
976
- scopeLookup[resumeData]
977
- );
978
- }
979
- }
980
- } finally {
981
- isResuming = false;
982
- }
983
- }
984
- }
985
- };
986
- var isResuming = false;
987
- function register(id, obj) {
988
- registeredValues[id] = obj;
989
- return obj;
990
- }
991
- function registerBoundSignal(id, signal) {
992
- registeredValues[id] = (scope) => (valueOrOp) => signal(scope, valueOrOp);
993
- return signal;
994
- }
995
- function getRegisteredWithScope(id, scope) {
996
- const val = registeredValues[id];
997
- return scope ? val(scope) : val;
998
- }
999
- function init(runtimeId = DEFAULT_RUNTIME_ID) {
1000
- if (true) {
1001
- if (!runtimeId.match(/^[_$a-z][_$a-z0-9]*$/i)) {
1002
- throw new Error(
1003
- `Invalid runtimeId: "${runtimeId}". The runtimeId must be a valid JavaScript identifier.`
1004
- );
1005
- }
1006
- }
1007
- const resumeRender = (renderId) => resumeRender[renderId] = renders[renderId] = new Render(renders, runtimeId, renderId);
1008
- let renders;
1009
- if (window[runtimeId]) {
1010
- setRenders(window[runtimeId]);
1011
- } else {
1012
- Object.defineProperty(window, runtimeId, {
1013
- configurable: true,
1014
- set: setRenders
1015
- });
1016
- }
1017
- function setRenders(v) {
1018
- if (true) {
1019
- if (renders) {
1020
- throw new Error(
1021
- "Marko tried to initialize multiple times. It could be that there are multiple instances of Marko running on the page."
1022
- );
1023
- }
1024
- }
1025
- renders = v;
1026
- for (const renderId in v) {
1027
- resumeRender(renderId);
1028
- }
1029
- Object.defineProperty(window, runtimeId, {
1030
- configurable: true,
1031
- value: resumeRender
1032
- });
1033
- }
1034
- }
1035
- function registerSubscriber(id, signal) {
1036
- register(id, signal.___subscribe);
1037
- return signal;
1038
- }
1039
- function nodeRef(id, key) {
1040
- return register(id, (scope) => () => scope[key]);
1041
- }
1042
-
1043
1010
  // src/dom/controllable.ts
1044
1011
  function controllable_input_checked(scope, nodeAccessor, checked, checkedChange) {
1045
1012
  setCheckboxValue(
@@ -1056,7 +1023,8 @@ function controllable_input_checked_effect(scope, nodeAccessor) {
1056
1023
  const checkedChange = scope[nodeAccessor + ";" /* ControlledHandler */];
1057
1024
  if (checkedChange) {
1058
1025
  scope[nodeAccessor + "=" /* ControlledType */] = 6 /* Pending */;
1059
- runSync(checkedChange, el.checked);
1026
+ checkedChange(el.checked);
1027
+ run();
1060
1028
  if (scope[nodeAccessor + "=" /* ControlledType */] === 6 /* Pending */) {
1061
1029
  el.checked = !el.checked;
1062
1030
  }
@@ -1081,10 +1049,10 @@ function controllable_input_checkedValue_effect(scope, nodeAccessor) {
1081
1049
  if (checkedValueChange) {
1082
1050
  const oldValue = scope[nodeAccessor + ":" /* ControlledValue */];
1083
1051
  scope[nodeAccessor + "=" /* ControlledType */] = 6 /* Pending */;
1084
- runSync(
1085
- checkedValueChange,
1052
+ checkedValueChange(
1086
1053
  Array.isArray(oldValue) ? updateList(oldValue, el.value, el.checked) : el.checked ? el.value : void 0
1087
1054
  );
1055
+ run();
1088
1056
  if (scope[nodeAccessor + "=" /* ControlledType */] === 6 /* Pending */) {
1089
1057
  el.checked = !el.checked;
1090
1058
  }
@@ -1118,7 +1086,8 @@ function controllable_input_value_effect(scope, nodeAccessor) {
1118
1086
  if (valueChange) {
1119
1087
  scope[nodeAccessor + "=" /* ControlledType */] = 6 /* Pending */;
1120
1088
  if (ev) inputType = ev.inputType;
1121
- runSync(valueChange, el.value);
1089
+ valueChange(el.value);
1090
+ run();
1122
1091
  if (scope[nodeAccessor + "=" /* ControlledType */] === 6 /* Pending */) {
1123
1092
  setValueAndUpdateSelection(
1124
1093
  el,
@@ -1149,10 +1118,10 @@ function controllable_select_value_effect(scope, nodeAccessor) {
1149
1118
  const valueChange = scope[nodeAccessor + ";" /* ControlledHandler */];
1150
1119
  if (valueChange) {
1151
1120
  scope[nodeAccessor + "=" /* ControlledType */] = 6 /* Pending */;
1152
- runSync(
1153
- valueChange,
1121
+ valueChange(
1154
1122
  Array.isArray(scope[nodeAccessor + ":" /* ControlledValue */]) ? Array.from(el.selectedOptions, toValueProp) : el.value
1155
1123
  );
1124
+ run();
1156
1125
  if (scope[nodeAccessor + "=" /* ControlledType */] === 6 /* Pending */) {
1157
1126
  setSelectOptions(
1158
1127
  el,
@@ -1205,7 +1174,8 @@ function controllable_detailsOrDialog_open_effect(scope, nodeAccessor) {
1205
1174
  const openChange = scope[nodeAccessor + ";" /* ControlledHandler */];
1206
1175
  if (openChange) {
1207
1176
  scope[nodeAccessor + "=" /* ControlledType */] = 6 /* Pending */;
1208
- runSync(openChange, el.open);
1177
+ openChange(el.open);
1178
+ run();
1209
1179
  if (scope[nodeAccessor + "=" /* ControlledType */] === 6 /* Pending */) {
1210
1180
  el.open = !el.open;
1211
1181
  }
@@ -1289,12 +1259,7 @@ function hasSelectChanged(el) {
1289
1259
  }
1290
1260
  }
1291
1261
  function hasFormElementChanged(el) {
1292
- switch (el.tagName) {
1293
- case "INPUT":
1294
- return hasValueChanged(el) || hasCheckboxChanged(el);
1295
- case "SELECT":
1296
- return hasSelectChanged(el);
1297
- }
1262
+ return el.options ? hasSelectChanged(el) : hasValueChanged(el) || hasCheckboxChanged(el);
1298
1263
  }
1299
1264
  function normalizeStrProp(value2) {
1300
1265
  return normalizeAttrValue(value2) || "";
@@ -1378,14 +1343,14 @@ function attrsInternal(scope, nodeAccessor, nextAttrs) {
1378
1343
  let skip;
1379
1344
  switch (el.tagName) {
1380
1345
  case "INPUT":
1381
- if (nextAttrs.checkedChange) {
1346
+ if ("checked" in nextAttrs || "checkedChange" in nextAttrs) {
1382
1347
  controllable_input_checked(
1383
1348
  scope,
1384
1349
  nodeAccessor,
1385
1350
  nextAttrs.checked,
1386
1351
  nextAttrs.checkedChange
1387
1352
  );
1388
- } else if (nextAttrs.checkedValue || nextAttrs.checkedValueChange) {
1353
+ } else if ("checkedValue" in nextAttrs || "checkedValueChange" in nextAttrs) {
1389
1354
  controllable_input_checkedValue(
1390
1355
  scope,
1391
1356
  nodeAccessor,
@@ -1393,7 +1358,7 @@ function attrsInternal(scope, nodeAccessor, nextAttrs) {
1393
1358
  nextAttrs.checkedValueChange,
1394
1359
  nextAttrs.value
1395
1360
  );
1396
- } else if (nextAttrs.valueChange) {
1361
+ } else if ("value" in nextAttrs || "valueChange" in nextAttrs) {
1397
1362
  controllable_input_value(
1398
1363
  scope,
1399
1364
  nodeAccessor,
@@ -1406,7 +1371,7 @@ function attrsInternal(scope, nodeAccessor, nextAttrs) {
1406
1371
  skip = /^(?:value|checked(?:Value)?)(?:Change)?$/;
1407
1372
  break;
1408
1373
  case "SELECT":
1409
- if (nextAttrs.value || nextAttrs.valueChange) {
1374
+ if ("value" in nextAttrs || "valueChange" in nextAttrs) {
1410
1375
  controllable_select_value(
1411
1376
  scope,
1412
1377
  nodeAccessor,
@@ -1416,9 +1381,20 @@ function attrsInternal(scope, nodeAccessor, nextAttrs) {
1416
1381
  skip = /^value(?:Change)?$/;
1417
1382
  }
1418
1383
  break;
1384
+ case "TEXTAREA":
1385
+ if ("value" in nextAttrs || "valueChange" in nextAttrs) {
1386
+ controllable_input_value(
1387
+ scope,
1388
+ nodeAccessor,
1389
+ nextAttrs.value,
1390
+ nextAttrs.valueChange
1391
+ );
1392
+ skip = /^value(?:Change)?$/;
1393
+ }
1394
+ break;
1419
1395
  case "DETAILS":
1420
1396
  case "DIALOG":
1421
- if (nextAttrs.openChange) {
1397
+ if ("open" in nextAttrs || "openChange" in nextAttrs) {
1422
1398
  controllable_detailsOrDialog_open(
1423
1399
  scope,
1424
1400
  nodeAccessor,
@@ -1655,6 +1631,11 @@ function dynamicTagAttrs(nodeAccessor, getRenderBody, inputIsArgs) {
1655
1631
  const renderBody = getRenderBody?.(scope);
1656
1632
  if (typeof renderer === "string") {
1657
1633
  const nodeAccessor2 = true ? `#${renderer}/0` : 0;
1634
+ if (renderer === "textarea" && renderBody) {
1635
+ throw new Error(
1636
+ "A dynamic tag rendering a `<textarea>` cannot have a `renderBody` and must use the `value` attribute instead."
1637
+ );
1638
+ }
1658
1639
  setConditionalRendererOnlyChild(childScope, nodeAccessor2, renderBody);
1659
1640
  attrs(childScope, nodeAccessor2, attrsOrOp());
1660
1641
  } else if (renderer.___args) {
@@ -1671,7 +1652,7 @@ function dynamicTagAttrs(nodeAccessor, getRenderBody, inputIsArgs) {
1671
1652
  }
1672
1653
  };
1673
1654
  }
1674
- function createRendererWithOwner(template, rawWalks, setup, getClosureSignals, hasUserEffects = 0, getArgs) {
1655
+ function createRendererWithOwner(template, rawWalks, setup, getClosureSignals, getArgs) {
1675
1656
  let args;
1676
1657
  let closureSignals;
1677
1658
  const id = true ? Symbol("Marko Renderer") : {};
@@ -1684,7 +1665,6 @@ function createRendererWithOwner(template, rawWalks, setup, getClosureSignals, h
1684
1665
  ___setup: setup,
1685
1666
  ___clone: _clone,
1686
1667
  ___owner: owner,
1687
- ___hasUserEffects: hasUserEffects,
1688
1668
  ___sourceNode: void 0,
1689
1669
  get ___args() {
1690
1670
  return args ||= getArgs?.();
@@ -1695,13 +1675,12 @@ function createRendererWithOwner(template, rawWalks, setup, getClosureSignals, h
1695
1675
  };
1696
1676
  };
1697
1677
  }
1698
- function createRenderer(template, walks, setup, getClosureSignals, hasUserEffects, getArgs) {
1678
+ function createRenderer(template, walks, setup, getClosureSignals, getArgs) {
1699
1679
  return createRendererWithOwner(
1700
1680
  template,
1701
1681
  walks,
1702
1682
  setup,
1703
1683
  getClosureSignals,
1704
- hasUserEffects,
1705
1684
  getArgs
1706
1685
  )();
1707
1686
  }
@@ -1729,7 +1708,7 @@ var conditional = function conditional2(nodeAccessor, fn, getIntersection) {
1729
1708
  if (isDifferentRenderer(normalizedRenderer, currentRenderer)) {
1730
1709
  currentRenderer = scope[rendererAccessor] = normalizedRenderer;
1731
1710
  setConditionalRenderer(scope, nodeAccessor, normalizedRenderer);
1732
- fn?.(scope);
1711
+ fn && fn(scope);
1733
1712
  op = DIRTY;
1734
1713
  } else {
1735
1714
  op = CLEAN;
@@ -1790,7 +1769,7 @@ var conditionalOnlyChild = function conditional3(nodeAccessor, fn, getIntersecti
1790
1769
  nodeAccessor,
1791
1770
  normalizedRenderer
1792
1771
  );
1793
- fn?.(scope);
1772
+ fn && fn(scope);
1794
1773
  op = DIRTY;
1795
1774
  } else {
1796
1775
  op = CLEAN;
@@ -1903,11 +1882,7 @@ function loop(nodeAccessor, renderer, forEach) {
1903
1882
  newArray = emptyMarkerArray;
1904
1883
  getEmptyScope(referenceNode);
1905
1884
  } else {
1906
- if (renderer.___hasUserEffects) {
1907
- for (let i = 0; i < oldArray.length; i++) {
1908
- destroyScope(oldArray[i]);
1909
- }
1910
- }
1885
+ oldArray.forEach(destroyScope);
1911
1886
  referenceNode.textContent = "";
1912
1887
  newMap = emptyMap;
1913
1888
  newArray = emptyArray;
@@ -2000,7 +1975,6 @@ var compat = {
2000
1975
  void 0,
2001
1976
  setup,
2002
1977
  void 0,
2003
- 1,
2004
1978
  args && (() => args)
2005
1979
  );
2006
1980
  renderer.___clone = clone;
@@ -2017,7 +1991,7 @@ var compat = {
2017
1991
  }
2018
1992
  const args = renderer.___args || noop;
2019
1993
  let existing = false;
2020
- component.effects = prepare(() => {
1994
+ component.effects = prepareEffects(() => {
2021
1995
  if (!scope) {
2022
1996
  scope = component.scope = createScopeWithRenderer(renderer, out.global);
2023
1997
  const closures = renderer.___closureSignals;
@@ -2041,7 +2015,8 @@ function noop() {
2041
2015
  }
2042
2016
 
2043
2017
  // src/dom/template.ts
2044
- var createTemplate = (renderer, templateId) => {
2018
+ var createTemplate = (templateId, ...rendererArgs) => {
2019
+ const renderer = createRenderer(...rendererArgs);
2045
2020
  renderer.mount = mount;
2046
2021
  renderer._ = renderer;
2047
2022
  if (true) {
@@ -2070,7 +2045,7 @@ function mount(input = {}, reference, position) {
2070
2045
  };
2071
2046
  }
2072
2047
  const args = this.___args;
2073
- const effects = prepare(() => {
2048
+ const effects = prepareEffects(() => {
2074
2049
  scope = createScope($global);
2075
2050
  dom = initRenderer(this, scope);
2076
2051
  if (args) {
@@ -2095,10 +2070,12 @@ function mount(input = {}, reference, position) {
2095
2070
  return {
2096
2071
  update: (newInput) => {
2097
2072
  if (args) {
2098
- runSync(() => {
2099
- args(scope, MARK);
2100
- args(scope, [newInput]);
2101
- });
2073
+ runEffects(
2074
+ prepareEffects(() => {
2075
+ args(scope, MARK);
2076
+ args(scope, [newInput]);
2077
+ })
2078
+ );
2102
2079
  }
2103
2080
  },
2104
2081
  destroy: () => {