treeloom 2.0.0 → 2.1.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.
@@ -8438,6 +8438,104 @@ var treeloomRenderOnly = (() => {
8438
8438
  }
8439
8439
  });
8440
8440
 
8441
+ // dist/diff/appliedSnapshot.js
8442
+ var require_appliedSnapshot = __commonJS({
8443
+ "dist/diff/appliedSnapshot.js"(exports) {
8444
+ "use strict";
8445
+ init_process();
8446
+ require_es_array_includes();
8447
+ var __importDefault = function(mod) {
8448
+ return mod && mod.__esModule ? mod : {
8449
+ "default": mod
8450
+ };
8451
+ };
8452
+ Object.defineProperty(exports, "__esModule", {
8453
+ value: true
8454
+ });
8455
+ exports.changesFromApplied = exports.forgetApplied = exports.recordApplied = void 0;
8456
+ var si_funciona_1 = __importDefault(require_main());
8457
+ var createChangeList_1 = __importDefault(require_createChangeList());
8458
+ var LIVE_PROPERTIES = ["value", "checked", "selected", "indeterminate"];
8459
+ var snapshots = /* @__PURE__ */ new WeakMap();
8460
+ var canSnapshot = (domItem) => typeof domItem.attributes.style === "undefined" || si_funciona_1.default.isObject(domItem.attributes.style);
8461
+ var classNames = (className) => typeof className === "string" ? className.split(/\s+/).filter(Boolean) : [];
8462
+ var describe = (domItem) => {
8463
+ const snapshot = {
8464
+ attributes: {},
8465
+ classes: [],
8466
+ style: {}
8467
+ };
8468
+ for (const name in domItem.attributes) {
8469
+ const value = domItem.attributes[name];
8470
+ if (name === "className") {
8471
+ snapshot.classes = classNames(value);
8472
+ continue;
8473
+ }
8474
+ if (name === "style") {
8475
+ for (const property in value) {
8476
+ snapshot.style[si_funciona_1.default.kabobCase(property)] = value[property];
8477
+ }
8478
+ continue;
8479
+ }
8480
+ snapshot.attributes[si_funciona_1.default.kabobCase(name)] = value;
8481
+ }
8482
+ return snapshot;
8483
+ };
8484
+ var recordApplied = (domItem) => {
8485
+ if (!domItem.element || domItem.nodeValue !== null || !canSnapshot(domItem)) {
8486
+ return;
8487
+ }
8488
+ snapshots.set(domItem.element, describe(domItem));
8489
+ };
8490
+ exports.recordApplied = recordApplied;
8491
+ var forgetApplied = (element) => {
8492
+ if (element) {
8493
+ snapshots.delete(element);
8494
+ }
8495
+ };
8496
+ exports.forgetApplied = forgetApplied;
8497
+ var changesFromApplied = (domItem, propertyName) => {
8498
+ const previous = domItem.element ? snapshots.get(domItem.element) : void 0;
8499
+ if (!previous || domItem.nodeValue !== null || !canSnapshot(domItem)) {
8500
+ return void 0;
8501
+ }
8502
+ const next = describe(domItem);
8503
+ const changes = (0, createChangeList_1.default)();
8504
+ const element = domItem.element;
8505
+ for (const key in next.attributes) {
8506
+ const live = LIVE_PROPERTIES.includes(key) && key in element;
8507
+ const current = live ? element[key] : previous.attributes[key];
8508
+ const differs = live && typeof current === "string" ? String(next.attributes[key] ?? "") !== current : next.attributes[key] !== current;
8509
+ if (differs) {
8510
+ changes.added[propertyName(key)] = next.attributes[key];
8511
+ }
8512
+ }
8513
+ previous.classes.forEach((name, index) => {
8514
+ if (!next.classes.includes(name)) {
8515
+ changes.removed[`class.${index}`] = name;
8516
+ }
8517
+ });
8518
+ next.classes.forEach((name, index) => {
8519
+ if (!previous.classes.includes(name)) {
8520
+ changes.added[`class.${index}`] = name;
8521
+ }
8522
+ });
8523
+ for (const property in previous.style) {
8524
+ if (!(property in next.style)) {
8525
+ changes.removed[`style.${property}`] = previous.style[property];
8526
+ }
8527
+ }
8528
+ for (const property in next.style) {
8529
+ if (next.style[property] !== previous.style[property]) {
8530
+ changes.added[`style.${property}`] = next.style[property];
8531
+ }
8532
+ }
8533
+ return changes;
8534
+ };
8535
+ exports.changesFromApplied = changesFromApplied;
8536
+ }
8537
+ });
8538
+
8441
8539
  // dist/sync/updateDomItem.js
8442
8540
  var require_updateDomItem = __commonJS({
8443
8541
  "dist/sync/updateDomItem.js"(exports) {
@@ -8453,6 +8551,7 @@ var treeloomRenderOnly = (() => {
8453
8551
  });
8454
8552
  var si_funciona_1 = __importDefault(require_main());
8455
8553
  var elementChanges_1 = __importDefault(require_elementChanges());
8554
+ var appliedSnapshot_1 = require_appliedSnapshot();
8456
8555
  var updateDomItem = (config) => {
8457
8556
  if (!config.element) {
8458
8557
  return config;
@@ -8478,6 +8577,7 @@ var treeloomRenderOnly = (() => {
8478
8577
  }
8479
8578
  si_funciona_1.default.dotSet(config, dotKey, changes.added[dotKey]);
8480
8579
  }
8580
+ (0, appliedSnapshot_1.forgetApplied)(config.element);
8481
8581
  return config;
8482
8582
  };
8483
8583
  exports.default = updateDomItem;
@@ -10064,6 +10164,7 @@ var treeloomRenderOnly = (() => {
10064
10164
  var si_funciona_1 = __importDefault(require_main());
10065
10165
  var elementHasAttribute_1 = __importDefault(require_elementHasAttribute());
10066
10166
  var createChangeList_1 = __importDefault(require_createChangeList());
10167
+ var appliedSnapshot_1 = require_appliedSnapshot();
10067
10168
  var checkAttribute = (element) => (attr, key) => {
10068
10169
  if (typeof attr === "object") {
10069
10170
  const styles = attr;
@@ -10116,6 +10217,16 @@ var treeloomRenderOnly = (() => {
10116
10217
  }
10117
10218
  return changeList;
10118
10219
  }
10220
+ if (!changeList.added.nodeName) {
10221
+ const fromApplied = (0, appliedSnapshot_1.changesFromApplied)(domItem, (kabobKey) => {
10222
+ const name = attributeName(domItem.attributes, kabobKey);
10223
+ const element = domItem.element;
10224
+ return element && name in element && name !== "form" ? name : kabobKey;
10225
+ });
10226
+ if (fromApplied) {
10227
+ return fromApplied;
10228
+ }
10229
+ }
10119
10230
  const domItemAttributes = kabobCaseAttributes(domItem.attributes);
10120
10231
  const diffMap = si_funciona_1.default.mapObject(domItemAttributes, (attr, key) => checkAttribute(domItem.element)(attr, key));
10121
10232
  return si_funciona_1.default.reduceObject(diffMap, (changed, result, key) => {
@@ -10203,31 +10314,24 @@ var treeloomRenderOnly = (() => {
10203
10314
  return domItem;
10204
10315
  }
10205
10316
  const element = domItem.element;
10206
- const previousChildNodes = Array.from(element.childNodes);
10207
- domItem.children.map((child, index) => {
10208
- const existing = previousChildNodes.find((childNode2) => childNode2 === child.element);
10209
- let childNode = existing ?? child.element;
10210
- if (!childNode) {
10211
- childNode = (0, updateElement_1.default)(child).element;
10212
- }
10213
- if (!previousChildNodes[index]) {
10214
- element.appendChild(childNode);
10215
- return childNode;
10216
- }
10217
- if (childNode !== previousChildNodes[index]) {
10218
- element.replaceChild(childNode, previousChildNodes[index]);
10219
- }
10317
+ const childNodes = domItem.children.map((child) => {
10318
+ const childNode = child.element ?? (0, updateElement_1.default)(child).element;
10319
+ child.element = childNode;
10220
10320
  return childNode;
10221
- }).forEach((childNode, index) => {
10222
- domItem.children[index].element = childNode;
10223
10321
  });
10224
- if (element.childNodes.length > domItem.children.length) {
10225
- const maxLength = domItem.children.length;
10226
- let nodeToRemove = element.childNodes[maxLength];
10227
- while (nodeToRemove) {
10228
- element.removeChild(nodeToRemove);
10229
- nodeToRemove = element.childNodes[maxLength];
10322
+ const wanted = new Set(childNodes);
10323
+ Array.from(element.childNodes).forEach((node) => {
10324
+ if (!wanted.has(node)) {
10325
+ element.removeChild(node);
10326
+ }
10327
+ });
10328
+ let following = null;
10329
+ for (let index = childNodes.length - 1; index >= 0; index--) {
10330
+ const childNode = childNodes[index];
10331
+ if (childNode.parentNode !== element || childNode.nextSibling !== following) {
10332
+ element.insertBefore(childNode, following);
10230
10333
  }
10334
+ following = childNode;
10231
10335
  }
10232
10336
  return domItem;
10233
10337
  };
@@ -10252,6 +10356,7 @@ var treeloomRenderOnly = (() => {
10252
10356
  var bindListeners_1 = __importDefault(require_bindListeners());
10253
10357
  var deactivateListeners_1 = __importDefault(require_deactivateListeners());
10254
10358
  var domItemChanges_1 = __importDefault(require_domItemChanges());
10359
+ var appliedSnapshot_1 = require_appliedSnapshot();
10255
10360
  var si_funciona_1 = __importDefault(require_main());
10256
10361
  var generateElement_1 = __importDefault(require_generateElement());
10257
10362
  var updateChildNodes_1 = __importDefault(require_updateChildNodes());
@@ -10319,6 +10424,7 @@ var treeloomRenderOnly = (() => {
10319
10424
  }
10320
10425
  element.style.setProperty(si_funciona_1.default.kabobCase(si_funciona_1.default.strAfter(dotKey, ".")), value);
10321
10426
  }
10427
+ (0, appliedSnapshot_1.recordApplied)(domItem);
10322
10428
  return (0, bindListeners_1.default)(domItem);
10323
10429
  };
10324
10430
  exports.default = updateElement;
@@ -10359,6 +10465,365 @@ var treeloomRenderOnly = (() => {
10359
10465
  }
10360
10466
  });
10361
10467
 
10468
+ // node_modules/core-js/internals/is-array.js
10469
+ var require_is_array = __commonJS({
10470
+ "node_modules/core-js/internals/is-array.js"(exports, module) {
10471
+ "use strict";
10472
+ init_process();
10473
+ var classof = require_classof_raw();
10474
+ module.exports = Array.isArray || function isArray(argument) {
10475
+ return classof(argument) === "Array";
10476
+ };
10477
+ }
10478
+ });
10479
+
10480
+ // node_modules/core-js/internals/is-raw-json.js
10481
+ var require_is_raw_json = __commonJS({
10482
+ "node_modules/core-js/internals/is-raw-json.js"(exports, module) {
10483
+ "use strict";
10484
+ init_process();
10485
+ var isObject = require_is_object();
10486
+ var getInternalState = require_internal_state().get;
10487
+ module.exports = function isRawJSON(O) {
10488
+ if (!isObject(O)) return false;
10489
+ var state = getInternalState(O);
10490
+ return !!state && state.type === "RawJSON";
10491
+ };
10492
+ }
10493
+ });
10494
+
10495
+ // node_modules/core-js/internals/this-number-value.js
10496
+ var require_this_number_value = __commonJS({
10497
+ "node_modules/core-js/internals/this-number-value.js"(exports, module) {
10498
+ "use strict";
10499
+ init_process();
10500
+ var uncurryThis = require_function_uncurry_this();
10501
+ module.exports = uncurryThis(1.1.valueOf);
10502
+ }
10503
+ });
10504
+
10505
+ // node_modules/core-js/internals/to-string-tag-support.js
10506
+ var require_to_string_tag_support = __commonJS({
10507
+ "node_modules/core-js/internals/to-string-tag-support.js"(exports, module) {
10508
+ "use strict";
10509
+ init_process();
10510
+ var wellKnownSymbol = require_well_known_symbol();
10511
+ var TO_STRING_TAG = wellKnownSymbol("toStringTag");
10512
+ var test = {};
10513
+ test[TO_STRING_TAG] = "z";
10514
+ module.exports = String(test) === "[object z]";
10515
+ }
10516
+ });
10517
+
10518
+ // node_modules/core-js/internals/classof.js
10519
+ var require_classof = __commonJS({
10520
+ "node_modules/core-js/internals/classof.js"(exports, module) {
10521
+ "use strict";
10522
+ init_process();
10523
+ var TO_STRING_TAG_SUPPORT = require_to_string_tag_support();
10524
+ var isCallable = require_is_callable();
10525
+ var classofRaw = require_classof_raw();
10526
+ var wellKnownSymbol = require_well_known_symbol();
10527
+ var TO_STRING_TAG = wellKnownSymbol("toStringTag");
10528
+ var $Object = Object;
10529
+ var CORRECT_ARGUMENTS = classofRaw(/* @__PURE__ */ (function() {
10530
+ return arguments;
10531
+ })()) === "Arguments";
10532
+ var tryGet = function(it, key) {
10533
+ try {
10534
+ return it[key];
10535
+ } catch (error) {
10536
+ }
10537
+ };
10538
+ module.exports = TO_STRING_TAG_SUPPORT ? classofRaw : function(it) {
10539
+ var O, tag, result;
10540
+ return it === void 0 ? "Undefined" : it === null ? "Null" : typeof (tag = tryGet(O = $Object(it), TO_STRING_TAG)) == "string" ? tag : CORRECT_ARGUMENTS ? classofRaw(O) : (result = classofRaw(O)) === "Object" && isCallable(O.callee) ? "Arguments" : result;
10541
+ };
10542
+ }
10543
+ });
10544
+
10545
+ // node_modules/core-js/internals/to-string.js
10546
+ var require_to_string = __commonJS({
10547
+ "node_modules/core-js/internals/to-string.js"(exports, module) {
10548
+ "use strict";
10549
+ init_process();
10550
+ var classof = require_classof();
10551
+ var $String = String;
10552
+ module.exports = function(argument) {
10553
+ if (classof(argument) === "Symbol") throw new TypeError("Cannot convert a Symbol value to a string");
10554
+ return $String(argument);
10555
+ };
10556
+ }
10557
+ });
10558
+
10559
+ // node_modules/core-js/internals/parse-json-string.js
10560
+ var require_parse_json_string = __commonJS({
10561
+ "node_modules/core-js/internals/parse-json-string.js"(exports, module) {
10562
+ "use strict";
10563
+ init_process();
10564
+ var uncurryThis = require_function_uncurry_this();
10565
+ var hasOwn = require_has_own_property();
10566
+ var $SyntaxError = SyntaxError;
10567
+ var $parseInt = parseInt;
10568
+ var fromCharCode = String.fromCharCode;
10569
+ var at = uncurryThis("".charAt);
10570
+ var slice = uncurryThis("".slice);
10571
+ var exec = uncurryThis(/./.exec);
10572
+ var codePoints = {
10573
+ '\\"': '"',
10574
+ "\\\\": "\\",
10575
+ "\\/": "/",
10576
+ "\\b": "\b",
10577
+ "\\f": "\f",
10578
+ "\\n": "\n",
10579
+ "\\r": "\r",
10580
+ "\\t": " "
10581
+ };
10582
+ var IS_4_HEX_DIGITS = /^[\da-f]{4}$/i;
10583
+ var IS_C0_CONTROL_CODE = /^[\u0000-\u001F]$/;
10584
+ module.exports = function(source, i) {
10585
+ var unterminated = true;
10586
+ var value = "";
10587
+ while (i < source.length) {
10588
+ var chr = at(source, i);
10589
+ if (chr === "\\") {
10590
+ var twoChars = slice(source, i, i + 2);
10591
+ if (hasOwn(codePoints, twoChars)) {
10592
+ value += codePoints[twoChars];
10593
+ i += 2;
10594
+ } else if (twoChars === "\\u") {
10595
+ i += 2;
10596
+ var fourHexDigits = slice(source, i, i + 4);
10597
+ if (!exec(IS_4_HEX_DIGITS, fourHexDigits)) throw new $SyntaxError("Bad Unicode escape at: " + i);
10598
+ value += fromCharCode($parseInt(fourHexDigits, 16));
10599
+ i += 4;
10600
+ } else throw new $SyntaxError('Unknown escape sequence: "' + twoChars + '"');
10601
+ } else if (chr === '"') {
10602
+ unterminated = false;
10603
+ i++;
10604
+ break;
10605
+ } else {
10606
+ if (exec(IS_C0_CONTROL_CODE, chr)) throw new $SyntaxError("Bad control character in string literal at: " + i);
10607
+ value += chr;
10608
+ i++;
10609
+ }
10610
+ }
10611
+ if (unterminated) throw new $SyntaxError("Unterminated string at: " + i);
10612
+ return { value, end: i };
10613
+ };
10614
+ }
10615
+ });
10616
+
10617
+ // node_modules/core-js/internals/native-raw-json.js
10618
+ var require_native_raw_json = __commonJS({
10619
+ "node_modules/core-js/internals/native-raw-json.js"(exports, module) {
10620
+ "use strict";
10621
+ init_process();
10622
+ var fails = require_fails();
10623
+ module.exports = !fails(function() {
10624
+ var unsafeInt = "9007199254740993";
10625
+ var raw = JSON.rawJSON(unsafeInt);
10626
+ return !JSON.isRawJSON(raw) || JSON.stringify(raw) !== unsafeInt;
10627
+ });
10628
+ }
10629
+ });
10630
+
10631
+ // node_modules/core-js/modules/es.json.stringify.js
10632
+ var require_es_json_stringify = __commonJS({
10633
+ "node_modules/core-js/modules/es.json.stringify.js"() {
10634
+ "use strict";
10635
+ init_process();
10636
+ var $ = require_export();
10637
+ var getBuiltIn = require_get_built_in();
10638
+ var call = require_function_call();
10639
+ var uncurryThis = require_function_uncurry_this();
10640
+ var fails = require_fails();
10641
+ var isArray = require_is_array();
10642
+ var isCallable = require_is_callable();
10643
+ var isObject = require_is_object();
10644
+ var create = require_object_create();
10645
+ var isRawJSON = require_is_raw_json();
10646
+ var isSymbol = require_is_symbol();
10647
+ var classof = require_classof_raw();
10648
+ var thisNumberValue = require_this_number_value();
10649
+ var includes = require_array_includes().includes;
10650
+ var hasOwn = require_has_own_property();
10651
+ var toString = require_to_string();
10652
+ var parseJSONString = require_parse_json_string();
10653
+ var uid = require_uid();
10654
+ var NATIVE_SYMBOL = require_symbol_constructor_detection();
10655
+ var NATIVE_RAW_JSON = require_native_raw_json();
10656
+ var $String = String;
10657
+ var $TypeError = TypeError;
10658
+ var $stringify = getBuiltIn("JSON", "stringify");
10659
+ var $BigInt = getBuiltIn("BigInt");
10660
+ var stringValueOf = uncurryThis("".valueOf);
10661
+ var booleanValueOf = uncurryThis(true.valueOf);
10662
+ var bigIntValueOf = $BigInt && uncurryThis($BigInt.prototype.valueOf);
10663
+ var exec = uncurryThis(/./.exec);
10664
+ var charAt = uncurryThis("".charAt);
10665
+ var charCodeAt = uncurryThis("".charCodeAt);
10666
+ var replace = uncurryThis("".replace);
10667
+ var slice = uncurryThis("".slice);
10668
+ var push = uncurryThis([].push);
10669
+ var pop = uncurryThis([].pop);
10670
+ var numberToString = uncurryThis(1.1.toString);
10671
+ var surrogates = /[\uD800-\uDFFF]/g;
10672
+ var leadingSurrogates = /^[\uD800-\uDBFF]$/;
10673
+ var trailingSurrogates = /^[\uDC00-\uDFFF]$/;
10674
+ var digits = /^\d+$/;
10675
+ var RAW_MARK = uid();
10676
+ var KEY_MARK = uid();
10677
+ var END_MARK = uid();
10678
+ var RAW_MARK_LENGTH = RAW_MARK.length;
10679
+ var KEY_MARK_LENGTH = KEY_MARK.length;
10680
+ var WRONG_SYMBOLS_CONVERSION = !NATIVE_SYMBOL || fails(function() {
10681
+ var symbol = getBuiltIn("Symbol")("stringify detection");
10682
+ return $stringify([symbol]) !== "[null]" || $stringify({ a: symbol }) !== "{}" || $stringify(Object(symbol)) !== "{}";
10683
+ });
10684
+ var ILL_FORMED_UNICODE = fails(function() {
10685
+ return $stringify("\uDF06\uD834") !== '"\\udf06\\ud834"' || $stringify("\uDEAD") !== '"\\udead"';
10686
+ });
10687
+ var isRawJSONValue = NATIVE_RAW_JSON ? getBuiltIn("JSON", "isRawJSON") : isRawJSON;
10688
+ var stringifyWithProperSymbolsConversion = WRONG_SYMBOLS_CONVERSION ? function(it, replacer, space) {
10689
+ return $stringify(it, function(key, value) {
10690
+ var replaced = call(replacer, this, key, value);
10691
+ if (!isSymbol(replaced)) return replaced;
10692
+ }, space);
10693
+ } : $stringify;
10694
+ var fixIllFormedJSON = function(match, offset, string) {
10695
+ var prev = charAt(string, offset - 1);
10696
+ var next = charAt(string, offset + 1);
10697
+ if (exec(leadingSurrogates, match) && !exec(trailingSurrogates, next) || exec(trailingSurrogates, match) && !exec(leadingSurrogates, prev)) {
10698
+ return "\\u" + numberToString(charCodeAt(match, 0), 16);
10699
+ }
10700
+ return match;
10701
+ };
10702
+ var getPropertyList = function(replacer) {
10703
+ if (!isArray(replacer)) return;
10704
+ var rawLength = replacer.length;
10705
+ var propertyList = [];
10706
+ var addedKeys = create(null);
10707
+ for (var i = 0; i < rawLength; i++) {
10708
+ var element = replacer[i];
10709
+ var key;
10710
+ if (typeof element == "string") key = element;
10711
+ else if (typeof element == "number" || classof(element) === "Number" || classof(element) === "String") key = toString(element);
10712
+ else continue;
10713
+ if (!hasOwn(addedKeys, key)) {
10714
+ addedKeys[key] = true;
10715
+ push(propertyList, key);
10716
+ }
10717
+ }
10718
+ return propertyList;
10719
+ };
10720
+ var hasInternalSlot = function(valueOf, it) {
10721
+ try {
10722
+ valueOf(it);
10723
+ return true;
10724
+ } catch (error) {
10725
+ return false;
10726
+ }
10727
+ };
10728
+ var isBoxedPrimitive = function(it) {
10729
+ var kind = classof(it);
10730
+ return kind === "Number" && hasInternalSlot(thisNumberValue, it) || kind === "String" && hasInternalSlot(stringValueOf, it) || kind === "Boolean" && hasInternalSlot(booleanValueOf, it) || !!bigIntValueOf && kind === "BigInt" && hasInternalSlot(bigIntValueOf, it);
10731
+ };
10732
+ var isSerializedAsObject = function(it) {
10733
+ if (!isObject(it) || isCallable(it) || isArray(it)) return false;
10734
+ try {
10735
+ return !isBoxedPrimitive(it);
10736
+ } catch (error) {
10737
+ return true;
10738
+ }
10739
+ };
10740
+ var createElementHolder = function(holder, key) {
10741
+ return {
10742
+ toJSON: function() {
10743
+ var element = holder[key];
10744
+ if (isObject(element) || typeof element == "bigint") {
10745
+ var elementToJSON = element.toJSON;
10746
+ if (isCallable(elementToJSON)) element = call(elementToJSON, element, key);
10747
+ }
10748
+ return element;
10749
+ }
10750
+ };
10751
+ };
10752
+ var getKeyPrefix = function(propertyList) {
10753
+ for (var i = 0, length = propertyList.length; i < length; i++) {
10754
+ if (exec(digits, propertyList[i])) return KEY_MARK;
10755
+ }
10756
+ return "";
10757
+ };
10758
+ var createOrderedObject = function(value, propertyList, keyPrefix) {
10759
+ var ordered = create(null);
10760
+ for (var i = 0, length = propertyList.length; i < length; i++) {
10761
+ var key = propertyList[i];
10762
+ ordered[keyPrefix + key] = createElementHolder(value, key);
10763
+ }
10764
+ ordered[END_MARK] = null;
10765
+ return ordered;
10766
+ };
10767
+ if ($stringify) $({ target: "JSON", stat: true, arity: 3, forced: WRONG_SYMBOLS_CONVERSION || ILL_FORMED_UNICODE || !NATIVE_RAW_JSON }, {
10768
+ stringify: function stringify(text, replacer, space) {
10769
+ var replacerFunction = isCallable(replacer) ? replacer : void 0;
10770
+ var propertyList = replacerFunction ? void 0 : getPropertyList(replacer);
10771
+ var keyPrefix = propertyList && getKeyPrefix(propertyList);
10772
+ var rawStrings = [];
10773
+ var openObjects = [];
10774
+ var parentOrdered = [];
10775
+ var currentOrdered;
10776
+ var marked = false;
10777
+ var root = true;
10778
+ var json = stringifyWithProperSymbolsConversion(text, function(key, value) {
10779
+ key = $String(key);
10780
+ if (propertyList) {
10781
+ if (key === END_MARK) {
10782
+ pop(openObjects);
10783
+ currentOrdered = pop(parentOrdered);
10784
+ return;
10785
+ }
10786
+ if (root) root = false;
10787
+ else if (this !== currentOrdered && !isArray(this) && !includes(propertyList, key)) return;
10788
+ } else if (replacerFunction) value = call(replacerFunction, this, key, value);
10789
+ if (isRawJSONValue(value)) {
10790
+ if (NATIVE_RAW_JSON) return value;
10791
+ marked = true;
10792
+ return RAW_MARK + (push(rawStrings, value.rawJSON) - 1);
10793
+ }
10794
+ if (propertyList && isSerializedAsObject(value)) {
10795
+ if (includes(openObjects, value)) throw new $TypeError("Converting circular structure to JSON");
10796
+ var ordered = createOrderedObject(value, propertyList, keyPrefix);
10797
+ push(openObjects, value);
10798
+ push(parentOrdered, currentOrdered);
10799
+ currentOrdered = ordered;
10800
+ if (keyPrefix) marked = true;
10801
+ return ordered;
10802
+ }
10803
+ return value;
10804
+ }, space);
10805
+ if (typeof json != "string") return json;
10806
+ if (ILL_FORMED_UNICODE) json = replace(json, surrogates, fixIllFormedJSON);
10807
+ if (!marked) return json;
10808
+ var result = "";
10809
+ var length = json.length;
10810
+ for (var i = 0; i < length; i++) {
10811
+ var chr = charAt(json, i);
10812
+ if (chr === '"') {
10813
+ var end = parseJSONString(json, ++i).end - 1;
10814
+ var string = slice(json, i, end);
10815
+ if (slice(string, 0, RAW_MARK_LENGTH) === RAW_MARK) result += rawStrings[slice(string, RAW_MARK_LENGTH)];
10816
+ else if (slice(string, 0, KEY_MARK_LENGTH) === KEY_MARK) result += '"' + slice(string, KEY_MARK_LENGTH) + '"';
10817
+ else result += '"' + string + '"';
10818
+ i = end;
10819
+ } else result += chr;
10820
+ }
10821
+ return result;
10822
+ }
10823
+ });
10824
+ }
10825
+ });
10826
+
10362
10827
  // dist/render/updateElements.js
10363
10828
  var require_updateElements = __commonJS({
10364
10829
  "dist/render/updateElements.js"(exports) {
@@ -10389,6 +10854,124 @@ var treeloomRenderOnly = (() => {
10389
10854
  }
10390
10855
  });
10391
10856
 
10857
+ // dist/render/reconcile.js
10858
+ var require_reconcile = __commonJS({
10859
+ "dist/render/reconcile.js"(exports) {
10860
+ "use strict";
10861
+ init_process();
10862
+ require_es_array_includes();
10863
+ require_es_json_stringify();
10864
+ var __importDefault = function(mod) {
10865
+ return mod && mod.__esModule ? mod : {
10866
+ "default": mod
10867
+ };
10868
+ };
10869
+ Object.defineProperty(exports, "__esModule", {
10870
+ value: true
10871
+ });
10872
+ var removeEventListener_1 = __importDefault(require_removeEventListener());
10873
+ var itemIdIndex_1 = require_itemIdIndex();
10874
+ var updateElements_1 = __importDefault(require_updateElements());
10875
+ var STRUCTURE = /* @__PURE__ */ new Set(["element", "parentItem", "children", "eventListeners", "activeListeners"]);
10876
+ var listenerKey = (listener) => typeof listener.listenerFunc === "string" ? JSON.stringify([listener.listenerFunc, listener.listenerArgs ?? null, listener.listenerOptions ?? null]) : null;
10877
+ var reconcileListeners = (existing, next) => {
10878
+ const nextListeners = next.eventListeners ?? {};
10879
+ existing.eventListeners = existing.eventListeners ?? {};
10880
+ for (const eventName of Object.keys(existing.eventListeners)) {
10881
+ const wanted = (nextListeners[eventName] ?? []).map(listenerKey);
10882
+ for (const listener of [...existing.eventListeners[eventName]]) {
10883
+ const key = listenerKey(listener);
10884
+ if (key !== null && !wanted.includes(key)) {
10885
+ (0, removeEventListener_1.default)(eventName, listener.listenerFunc, listener.listenerArgs, listener.listenerOptions, existing);
10886
+ }
10887
+ }
10888
+ }
10889
+ for (const eventName of Object.keys(nextListeners)) {
10890
+ const have = (existing.eventListeners[eventName] ?? []).map(listenerKey);
10891
+ for (const listener of nextListeners[eventName]) {
10892
+ const key = listenerKey(listener);
10893
+ if (key !== null && !have.includes(key)) {
10894
+ existing.eventListeners[eventName] = existing.eventListeners[eventName] ?? [];
10895
+ existing.eventListeners[eventName].push({
10896
+ ...listener,
10897
+ listenerActive: false,
10898
+ activeResponder: null
10899
+ });
10900
+ }
10901
+ }
10902
+ }
10903
+ };
10904
+ var reconcileData = (existing, next) => {
10905
+ const target = existing;
10906
+ const source = next;
10907
+ for (const key of Object.keys(target)) {
10908
+ if (!STRUCTURE.has(key) && !(key in source) && typeof target[key] !== "function") {
10909
+ delete target[key];
10910
+ }
10911
+ }
10912
+ for (const key of Object.keys(source)) {
10913
+ if (!STRUCTURE.has(key)) {
10914
+ target[key] = source[key];
10915
+ }
10916
+ }
10917
+ };
10918
+ var pairChildren = (existing, next) => {
10919
+ const byId = /* @__PURE__ */ new Map();
10920
+ existing.forEach((child) => {
10921
+ if (typeof child.id === "number") {
10922
+ byId.set(child.id, child);
10923
+ }
10924
+ });
10925
+ const claimed = new Set(next.map((child) => typeof child.id === "number" ? byId.get(child.id) : void 0).filter(Boolean));
10926
+ const taken = /* @__PURE__ */ new Set();
10927
+ return next.map((nextChild, index) => {
10928
+ const sameId = typeof nextChild.id === "number" ? byId.get(nextChild.id) : void 0;
10929
+ const atPosition = existing[index] && !claimed.has(existing[index]) ? existing[index] : void 0;
10930
+ const candidate = sameId ?? atPosition;
10931
+ if (candidate && !taken.has(candidate) && candidate.nodeName === nextChild.nodeName) {
10932
+ taken.add(candidate);
10933
+ return candidate;
10934
+ }
10935
+ return void 0;
10936
+ });
10937
+ };
10938
+ var reconcileItem = (existing, next) => {
10939
+ reconcileData(existing, next);
10940
+ reconcileListeners(existing, next);
10941
+ const previous = existing.children ?? [];
10942
+ const nextChildren = next.children ?? [];
10943
+ const pairs = pairChildren(previous, nextChildren);
10944
+ const kept = new Set(pairs.filter(Boolean));
10945
+ previous.filter((child) => !kept.has(child)).forEach((child) => {
10946
+ ;
10947
+ child.element?.remove?.();
10948
+ });
10949
+ existing.children = nextChildren.map((nextChild, index) => {
10950
+ const child = pairs[index];
10951
+ if (child) {
10952
+ reconcileItem(child, nextChild);
10953
+ return child;
10954
+ }
10955
+ nextChild.parentItem = existing;
10956
+ return nextChild;
10957
+ });
10958
+ existing.children.forEach((child) => {
10959
+ child.parentItem = existing;
10960
+ });
10961
+ };
10962
+ var reconcile = (existing, next) => {
10963
+ if (existing.nodeName.toLowerCase() !== next.nodeName.toLowerCase()) {
10964
+ throw new Error(`reconcile can't turn a ${existing.nodeName} into a ${next.nodeName}: give it a tree of the same node, or reconcile its parent.`);
10965
+ }
10966
+ (0, itemIdIndex_1.unregisterItemIds)(existing);
10967
+ reconcileItem(existing, next);
10968
+ (0, itemIdIndex_1.registerItemIds)(existing);
10969
+ return (0, updateElements_1.default)(existing);
10970
+ };
10971
+ exports.default = reconcile;
10972
+ }
10973
+ });
10974
+
10392
10975
  // dist/render/renderHtml.js
10393
10976
  var require_renderHtml = __commonJS({
10394
10977
  "dist/render/renderHtml.js"(exports) {
@@ -10437,12 +11020,14 @@ var treeloomRenderOnly = (() => {
10437
11020
  value: true
10438
11021
  });
10439
11022
  var generateElement_1 = __importDefault(require_generateElement());
11023
+ var reconcile_1 = __importDefault(require_reconcile());
10440
11024
  var renderHtml_1 = __importDefault(require_renderHtml());
10441
11025
  var updateChildNodes_1 = __importDefault(require_updateChildNodes());
10442
11026
  var updateElement_1 = __importDefault(require_updateElement());
10443
11027
  var updateElements_1 = __importDefault(require_updateElements());
10444
11028
  exports.default = {
10445
11029
  generateElement: generateElement_1.default,
11030
+ reconcile: reconcile_1.default,
10446
11031
  renderHtml: renderHtml_1.default,
10447
11032
  updateChildNodes: updateChildNodes_1.default,
10448
11033
  updateElement: updateElement_1.default,