@vue/runtime-dom 3.6.0-alpha.1 → 3.6.0-alpha.3

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.
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @vue/runtime-dom v3.6.0-alpha.1
2
+ * @vue/runtime-dom v3.6.0-alpha.3
3
3
  * (c) 2018-present Yuxi (Evan) You and Vue contributors
4
4
  * @license MIT
5
5
  **/
@@ -217,11 +217,11 @@ function resolveTransitionProps(rawProps) {
217
217
  const resolve = () => finishLeave(el, done);
218
218
  addTransitionClass(el, leaveFromClass);
219
219
  if (!el._enterCancelled) {
220
- forceReflow();
220
+ forceReflow(el);
221
221
  addTransitionClass(el, leaveActiveClass);
222
222
  } else {
223
223
  addTransitionClass(el, leaveActiveClass);
224
- forceReflow();
224
+ forceReflow(el);
225
225
  }
226
226
  nextFrame(() => {
227
227
  if (!el._isLeaving) {
@@ -347,7 +347,7 @@ function getTransitionInfo(el, expectedType) {
347
347
  type = timeout > 0 ? transitionTimeout > animationTimeout ? TRANSITION : ANIMATION : null;
348
348
  propCount = type ? type === TRANSITION ? transitionDurations.length : animationDurations.length : 0;
349
349
  }
350
- const hasTransform = type === TRANSITION && /\b(transform|all)(,|$)/.test(
350
+ const hasTransform = type === TRANSITION && /\b(?:transform|all)(?:,|$)/.test(
351
351
  getStyleProperties(`${TRANSITION}Property`).toString()
352
352
  );
353
353
  return {
@@ -367,8 +367,9 @@ function toMs(s) {
367
367
  if (s === "auto") return 0;
368
368
  return Number(s.slice(0, -1).replace(",", ".")) * 1e3;
369
369
  }
370
- function forceReflow() {
371
- return document.body.offsetHeight;
370
+ function forceReflow(el) {
371
+ const targetDocument = el ? el.ownerDocument : document;
372
+ return targetDocument.body.offsetHeight;
372
373
  }
373
374
 
374
375
  function patchClass(el, value, isSVG) {
@@ -388,6 +389,8 @@ function patchClass(el, value, isSVG) {
388
389
  const vShowOriginalDisplay = Symbol("_vod");
389
390
  const vShowHidden = Symbol("_vsh");
390
391
  const vShow = {
392
+ // used for prop mismatch check during hydration
393
+ name: "show",
391
394
  beforeMount(el, { value }, { transition }) {
392
395
  el[vShowOriginalDisplay] = el.style.display === "none" ? "" : el.style.display;
393
396
  if (transition && value) {
@@ -421,9 +424,6 @@ const vShow = {
421
424
  setDisplay(el, value);
422
425
  }
423
426
  };
424
- {
425
- vShow.name = "show";
426
- }
427
427
  function setDisplay(el, value) {
428
428
  el.style.display = value ? el[vShowOriginalDisplay] : "none";
429
429
  el[vShowHidden] = !value;
@@ -441,7 +441,7 @@ function useCssVars(getter) {
441
441
  return;
442
442
  }
443
443
 
444
- const displayRE = /(^|;)\s*display\s*:/;
444
+ const displayRE = /(?:^|;)\s*display\s*:/;
445
445
  function patchStyle(el, prev, next) {
446
446
  const style = el.style;
447
447
  const isCssString = shared.isString(next);
@@ -746,11 +746,10 @@ function shouldSetAsProp(el, key, value, isSVG) {
746
746
  }
747
747
 
748
748
  const REMOVAL = {};
749
- /*! #__NO_SIDE_EFFECTS__ */
750
749
  // @__NO_SIDE_EFFECTS__
751
750
  function defineCustomElement(options, extraOptions, _createApp) {
752
- const Comp = runtimeCore.defineComponent(options, extraOptions);
753
- if (shared.isPlainObject(Comp)) shared.extend(Comp, extraOptions);
751
+ let Comp = runtimeCore.defineComponent(options, extraOptions);
752
+ if (shared.isPlainObject(Comp)) Comp = shared.extend({}, Comp, extraOptions);
754
753
  class VueCustomElement extends VueElement {
755
754
  constructor(initialProps) {
756
755
  super(Comp, initialProps, _createApp);
@@ -759,10 +758,9 @@ function defineCustomElement(options, extraOptions, _createApp) {
759
758
  VueCustomElement.def = Comp;
760
759
  return VueCustomElement;
761
760
  }
762
- /*! #__NO_SIDE_EFFECTS__ */
763
- const defineSSRCustomElement = /* @__NO_SIDE_EFFECTS__ */ (options, extraOptions) => {
761
+ const defineSSRCustomElement = (/* @__NO_SIDE_EFFECTS__ */ (options, extraOptions) => {
764
762
  return /* @__PURE__ */ defineCustomElement(options, extraOptions, createSSRApp);
765
- };
763
+ });
766
764
  const BaseClass = typeof HTMLElement !== "undefined" ? HTMLElement : class {
767
765
  };
768
766
  class VueElement extends BaseClass {
@@ -786,6 +784,8 @@ class VueElement extends BaseClass {
786
784
  this._nonce = this._def.nonce;
787
785
  this._connected = false;
788
786
  this._resolved = false;
787
+ this._patching = false;
788
+ this._dirty = false;
789
789
  this._numberProps = null;
790
790
  this._styleChildren = /* @__PURE__ */ new WeakSet();
791
791
  this._ob = null;
@@ -798,7 +798,11 @@ class VueElement extends BaseClass {
798
798
  );
799
799
  }
800
800
  if (_def.shadowRoot !== false) {
801
- this.attachShadow({ mode: "open" });
801
+ this.attachShadow(
802
+ shared.extend({}, _def.shadowRootOptions, {
803
+ mode: "open"
804
+ })
805
+ );
802
806
  this._root = this.shadowRoot;
803
807
  } else {
804
808
  this._root = this;
@@ -858,9 +862,18 @@ class VueElement extends BaseClass {
858
862
  this._app && this._app.unmount();
859
863
  if (this._instance) this._instance.ce = void 0;
860
864
  this._app = this._instance = null;
865
+ if (this._teleportTargets) {
866
+ this._teleportTargets.clear();
867
+ this._teleportTargets = void 0;
868
+ }
861
869
  }
862
870
  });
863
871
  }
872
+ _processMutations(mutations) {
873
+ for (const m of mutations) {
874
+ this._setAttr(m.attributeName);
875
+ }
876
+ }
864
877
  /**
865
878
  * resolve inner component definition (handle possible async component)
866
879
  */
@@ -871,11 +884,7 @@ class VueElement extends BaseClass {
871
884
  for (let i = 0; i < this.attributes.length; i++) {
872
885
  this._setAttr(this.attributes[i].name);
873
886
  }
874
- this._ob = new MutationObserver((mutations) => {
875
- for (const m of mutations) {
876
- this._setAttr(m.attributeName);
877
- }
878
- });
887
+ this._ob = new MutationObserver(this._processMutations.bind(this));
879
888
  this._ob.observe(this, { attributes: true });
880
889
  const resolve = (def, isAsync = false) => {
881
890
  this._resolved = true;
@@ -952,7 +961,7 @@ class VueElement extends BaseClass {
952
961
  return this._getProp(key);
953
962
  },
954
963
  set(val) {
955
- this._setProp(key, val, true, true);
964
+ this._setProp(key, val, true, !this._patching);
956
965
  }
957
966
  });
958
967
  }
@@ -978,6 +987,7 @@ class VueElement extends BaseClass {
978
987
  */
979
988
  _setProp(key, val, shouldReflect = true, shouldUpdate = false) {
980
989
  if (val !== this._props[key]) {
990
+ this._dirty = true;
981
991
  if (val === REMOVAL) {
982
992
  delete this._props[key];
983
993
  } else {
@@ -991,7 +1001,10 @@ class VueElement extends BaseClass {
991
1001
  }
992
1002
  if (shouldReflect) {
993
1003
  const ob = this._ob;
994
- ob && ob.disconnect();
1004
+ if (ob) {
1005
+ this._processMutations(ob.takeRecords());
1006
+ ob.disconnect();
1007
+ }
995
1008
  if (val === true) {
996
1009
  this.setAttribute(shared.hyphenate(key), "");
997
1010
  } else if (typeof val === "string" || typeof val === "number") {
@@ -1095,7 +1108,7 @@ class VueElement extends BaseClass {
1095
1108
  * Only called when shadowRoot is false
1096
1109
  */
1097
1110
  _renderSlots() {
1098
- const outlets = (this._teleportTarget || this).querySelectorAll("slot");
1111
+ const outlets = this._getSlots();
1099
1112
  const scopeId = this._instance.type.__scopeId;
1100
1113
  for (let i = 0; i < outlets.length; i++) {
1101
1114
  const o = outlets[i];
@@ -1121,12 +1134,45 @@ class VueElement extends BaseClass {
1121
1134
  parent.removeChild(o);
1122
1135
  }
1123
1136
  }
1137
+ /**
1138
+ * @internal
1139
+ */
1140
+ _getSlots() {
1141
+ const roots = [this];
1142
+ if (this._teleportTargets) {
1143
+ roots.push(...this._teleportTargets);
1144
+ }
1145
+ const slots = /* @__PURE__ */ new Set();
1146
+ for (const root of roots) {
1147
+ const found = root.querySelectorAll("slot");
1148
+ for (let i = 0; i < found.length; i++) {
1149
+ slots.add(found[i]);
1150
+ }
1151
+ }
1152
+ return Array.from(slots);
1153
+ }
1124
1154
  /**
1125
1155
  * @internal
1126
1156
  */
1127
1157
  _injectChildStyle(comp) {
1128
1158
  this._applyStyles(comp.styles, comp);
1129
1159
  }
1160
+ /**
1161
+ * @internal
1162
+ */
1163
+ _beginPatch() {
1164
+ this._patching = true;
1165
+ this._dirty = false;
1166
+ }
1167
+ /**
1168
+ * @internal
1169
+ */
1170
+ _endPatch() {
1171
+ this._patching = false;
1172
+ if (this._dirty && this._instance) {
1173
+ this._update();
1174
+ }
1175
+ }
1130
1176
  /**
1131
1177
  * @internal
1132
1178
  */
@@ -1219,26 +1265,13 @@ const TransitionGroupImpl = /* @__PURE__ */ decorate({
1219
1265
  prevChildren = [];
1220
1266
  return;
1221
1267
  }
1222
- prevChildren.forEach(callPendingCbs);
1268
+ prevChildren.forEach((vnode) => callPendingCbs(vnode.el));
1223
1269
  prevChildren.forEach(recordPosition);
1224
1270
  const movedChildren = prevChildren.filter(applyTranslation);
1225
- forceReflow();
1271
+ forceReflow(instance.vnode.el);
1226
1272
  movedChildren.forEach((c) => {
1227
1273
  const el = c.el;
1228
- const style = el.style;
1229
- addTransitionClass(el, moveClass);
1230
- style.transform = style.webkitTransform = style.transitionDuration = "";
1231
- const cb = el[moveCbKey] = (e) => {
1232
- if (e && e.target !== el) {
1233
- return;
1234
- }
1235
- if (!e || /transform$/.test(e.propertyName)) {
1236
- el.removeEventListener("transitionend", cb);
1237
- el[moveCbKey] = null;
1238
- removeTransitionClass(el, moveClass);
1239
- }
1240
- };
1241
- el.addEventListener("transitionend", cb);
1274
+ handleMovedChildren(el, moveClass);
1242
1275
  });
1243
1276
  prevChildren = [];
1244
1277
  });
@@ -1261,10 +1294,10 @@ const TransitionGroupImpl = /* @__PURE__ */ decorate({
1261
1294
  instance
1262
1295
  )
1263
1296
  );
1264
- positionMap.set(
1265
- child,
1266
- child.el.getBoundingClientRect()
1267
- );
1297
+ positionMap.set(child, {
1298
+ left: child.el.offsetLeft,
1299
+ top: child.el.offsetTop
1300
+ });
1268
1301
  }
1269
1302
  }
1270
1303
  }
@@ -1285,8 +1318,7 @@ const TransitionGroupImpl = /* @__PURE__ */ decorate({
1285
1318
  }
1286
1319
  });
1287
1320
  const TransitionGroup = TransitionGroupImpl;
1288
- function callPendingCbs(c) {
1289
- const el = c.el;
1321
+ function callPendingCbs(el) {
1290
1322
  if (el[moveCbKey]) {
1291
1323
  el[moveCbKey]();
1292
1324
  }
@@ -1295,19 +1327,30 @@ function callPendingCbs(c) {
1295
1327
  }
1296
1328
  }
1297
1329
  function recordPosition(c) {
1298
- newPositionMap.set(c, c.el.getBoundingClientRect());
1330
+ newPositionMap.set(c, {
1331
+ left: c.el.offsetLeft,
1332
+ top: c.el.offsetTop
1333
+ });
1299
1334
  }
1300
1335
  function applyTranslation(c) {
1301
- const oldPos = positionMap.get(c);
1302
- const newPos = newPositionMap.get(c);
1336
+ if (baseApplyTranslation(
1337
+ positionMap.get(c),
1338
+ newPositionMap.get(c),
1339
+ c.el
1340
+ )) {
1341
+ return c;
1342
+ }
1343
+ }
1344
+ function baseApplyTranslation(oldPos, newPos, el) {
1303
1345
  const dx = oldPos.left - newPos.left;
1304
1346
  const dy = oldPos.top - newPos.top;
1305
1347
  if (dx || dy) {
1306
- const s = c.el.style;
1348
+ const s = el.style;
1307
1349
  s.transform = s.webkitTransform = `translate(${dx}px,${dy}px)`;
1308
1350
  s.transitionDuration = "0s";
1309
- return c;
1351
+ return true;
1310
1352
  }
1353
+ return false;
1311
1354
  }
1312
1355
  function hasCSSTransform(el, root, moveClass) {
1313
1356
  const clone = el.cloneNode();
@@ -1325,6 +1368,22 @@ function hasCSSTransform(el, root, moveClass) {
1325
1368
  container.removeChild(clone);
1326
1369
  return hasTransform;
1327
1370
  }
1371
+ const handleMovedChildren = (el, moveClass) => {
1372
+ const style = el.style;
1373
+ addTransitionClass(el, moveClass);
1374
+ style.transform = style.webkitTransform = style.transitionDuration = "";
1375
+ const cb = el[moveCbKey] = (e) => {
1376
+ if (e && e.target !== el) {
1377
+ return;
1378
+ }
1379
+ if (!e || e.propertyName.endsWith("transform")) {
1380
+ el.removeEventListener("transitionend", cb);
1381
+ el[moveCbKey] = null;
1382
+ removeTransitionClass(el, moveClass);
1383
+ }
1384
+ };
1385
+ el.addEventListener("transitionend", cb);
1386
+ };
1328
1387
 
1329
1388
  const getModelAssigner = (vnode) => {
1330
1389
  const fn = vnode.props["onUpdate:modelValue"] || false;
@@ -1360,21 +1419,21 @@ const vModelText = {
1360
1419
  vModelTextUpdate(el, oldValue, value, trim, number, lazy);
1361
1420
  }
1362
1421
  };
1422
+ function castValue(value, trim, number) {
1423
+ if (trim) value = value.trim();
1424
+ if (number) value = shared.looseToNumber(value);
1425
+ return value;
1426
+ }
1363
1427
  const vModelTextInit = (el, trim, number, lazy, set) => {
1364
1428
  addEventListener(el, lazy ? "change" : "input", (e) => {
1365
1429
  if (e.target.composing) return;
1366
- let domValue = el.value;
1367
- if (trim) {
1368
- domValue = domValue.trim();
1369
- }
1370
- if (number || el.type === "number") {
1371
- domValue = shared.looseToNumber(domValue);
1372
- }
1373
- (0, el[assignKey])(domValue);
1430
+ (0, el[assignKey])(
1431
+ castValue(el.value, trim, number || el.type === "number")
1432
+ );
1374
1433
  });
1375
- if (trim) {
1434
+ if (trim || number) {
1376
1435
  addEventListener(el, "change", () => {
1377
- el.value = el.value.trim();
1436
+ el.value = castValue(el.value, trim, number || el.type === "number");
1378
1437
  });
1379
1438
  }
1380
1439
  if (!lazy) {
@@ -1657,13 +1716,13 @@ const modifierGuards = {
1657
1716
  const withModifiers = (fn, modifiers) => {
1658
1717
  const cache = fn._withMods || (fn._withMods = {});
1659
1718
  const cacheKey = modifiers.join(".");
1660
- return cache[cacheKey] || (cache[cacheKey] = (event, ...args) => {
1719
+ return cache[cacheKey] || (cache[cacheKey] = ((event, ...args) => {
1661
1720
  for (let i = 0; i < modifiers.length; i++) {
1662
1721
  const guard = modifierGuards[modifiers[i]];
1663
1722
  if (guard && guard(event, modifiers)) return;
1664
1723
  }
1665
1724
  return fn(event, ...args);
1666
- });
1725
+ }));
1667
1726
  };
1668
1727
  const keyNames = {
1669
1728
  esc: "escape",
@@ -1677,7 +1736,7 @@ const keyNames = {
1677
1736
  const withKeys = (fn, modifiers) => {
1678
1737
  const cache = fn._withKeys || (fn._withKeys = {});
1679
1738
  const cacheKey = modifiers.join(".");
1680
- return cache[cacheKey] || (cache[cacheKey] = (event) => {
1739
+ return cache[cacheKey] || (cache[cacheKey] = ((event) => {
1681
1740
  if (!("key" in event)) {
1682
1741
  return;
1683
1742
  }
@@ -1687,7 +1746,7 @@ const withKeys = (fn, modifiers) => {
1687
1746
  )) {
1688
1747
  return fn(event);
1689
1748
  }
1690
- });
1749
+ }));
1691
1750
  };
1692
1751
 
1693
1752
  const rendererOptions = /* @__PURE__ */ shared.extend({ patchProp }, nodeOps);
@@ -1701,13 +1760,13 @@ function ensureHydrationRenderer() {
1701
1760
  enabledHydration = true;
1702
1761
  return renderer;
1703
1762
  }
1704
- const render = (...args) => {
1763
+ const render = ((...args) => {
1705
1764
  ensureRenderer().render(...args);
1706
- };
1707
- const hydrate = (...args) => {
1765
+ });
1766
+ const hydrate = ((...args) => {
1708
1767
  ensureHydrationRenderer().hydrate(...args);
1709
- };
1710
- const createApp = (...args) => {
1768
+ });
1769
+ const createApp = ((...args) => {
1711
1770
  const app = ensureRenderer().createApp(...args);
1712
1771
  {
1713
1772
  injectNativeTagCheck(app);
@@ -1732,8 +1791,8 @@ const createApp = (...args) => {
1732
1791
  return proxy;
1733
1792
  };
1734
1793
  return app;
1735
- };
1736
- const createSSRApp = (...args) => {
1794
+ });
1795
+ const createSSRApp = ((...args) => {
1737
1796
  const app = ensureHydrationRenderer().createApp(...args);
1738
1797
  {
1739
1798
  injectNativeTagCheck(app);
@@ -1747,7 +1806,7 @@ const createSSRApp = (...args) => {
1747
1806
  }
1748
1807
  };
1749
1808
  return app;
1750
- };
1809
+ });
1751
1810
  function resolveRootNamespace(container) {
1752
1811
  if (container instanceof SVGElement) {
1753
1812
  return "svg";