@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,11 +1,11 @@
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
  **/
6
- import { warn, BaseTransitionPropsValidators, h, BaseTransition, assertNumber, getCurrentInstance, onBeforeUpdate, queuePostFlushCb, onMounted, watch, onUnmounted, Fragment, Static, camelize, callWithAsyncErrorHandling, defineComponent, nextTick, unref, createVNode, useTransitionState, onUpdated, toRaw, getTransitionRawChildren, setTransitionHooks, resolveTransitionHooks, Text, createRenderer, createHydrationRenderer, isRuntimeOnly } from '@vue/runtime-core';
6
+ import { warn, BaseTransitionPropsValidators, assertNumber, h, BaseTransition, getCurrentInstance, onBeforeUpdate, queuePostFlushCb, onMounted, watch, onUnmounted, Fragment, Static, camelize, callWithAsyncErrorHandling, defineComponent, nextTick, unref, createVNode, useTransitionState, onUpdated, toRaw, getTransitionRawChildren, setTransitionHooks, resolveTransitionHooks, Text, createRenderer, createHydrationRenderer, isRuntimeOnly } from '@vue/runtime-core';
7
7
  export * from '@vue/runtime-core';
8
- import { extend, isObject, toNumber, isArray, NOOP, normalizeCssVarValue, isString, hyphenate, capitalize, isSpecialBooleanAttr, includeBooleanAttr, isSymbol, canSetValueDirectly, isFunction, isNativeOn, shouldSetAsAttr, isOn, isModelListener, camelize as camelize$1, isPlainObject, hasOwn, EMPTY_OBJ, looseEqual, looseToNumber, looseIndexOf, isSet, invokeArrayFns, isHTMLTag, isSVGTag, isMathMLTag } from '@vue/shared';
8
+ import { extend, isObject, isArray, toNumber, NOOP, normalizeCssVarValue, isString, hyphenate, capitalize, isSpecialBooleanAttr, includeBooleanAttr, isSymbol, canSetValueDirectly, isFunction, isNativeOn, shouldSetAsAttr, isOn, isModelListener, camelize as camelize$1, isPlainObject, hasOwn, EMPTY_OBJ, looseEqual, looseToNumber, looseIndexOf, isSet, invokeArrayFns, isHTMLTag, isSVGTag, isMathMLTag } from '@vue/shared';
9
9
 
10
10
  let policy = void 0;
11
11
  const tt = typeof window !== "undefined" && window.trustedTypes;
@@ -214,11 +214,11 @@ function resolveTransitionProps(rawProps) {
214
214
  const resolve = () => finishLeave(el, done);
215
215
  addTransitionClass(el, leaveFromClass);
216
216
  if (!el._enterCancelled) {
217
- forceReflow();
217
+ forceReflow(el);
218
218
  addTransitionClass(el, leaveActiveClass);
219
219
  } else {
220
220
  addTransitionClass(el, leaveActiveClass);
221
- forceReflow();
221
+ forceReflow(el);
222
222
  }
223
223
  nextFrame(() => {
224
224
  if (!el._isLeaving) {
@@ -344,7 +344,7 @@ function getTransitionInfo(el, expectedType) {
344
344
  type = timeout > 0 ? transitionTimeout > animationTimeout ? TRANSITION : ANIMATION : null;
345
345
  propCount = type ? type === TRANSITION ? transitionDurations.length : animationDurations.length : 0;
346
346
  }
347
- const hasTransform = type === TRANSITION && /\b(transform|all)(,|$)/.test(
347
+ const hasTransform = type === TRANSITION && /\b(?:transform|all)(?:,|$)/.test(
348
348
  getStyleProperties(`${TRANSITION}Property`).toString()
349
349
  );
350
350
  return {
@@ -364,8 +364,9 @@ function toMs(s) {
364
364
  if (s === "auto") return 0;
365
365
  return Number(s.slice(0, -1).replace(",", ".")) * 1e3;
366
366
  }
367
- function forceReflow() {
368
- return document.body.offsetHeight;
367
+ function forceReflow(el) {
368
+ const targetDocument = el ? el.ownerDocument : document;
369
+ return targetDocument.body.offsetHeight;
369
370
  }
370
371
 
371
372
  function patchClass(el, value, isSVG) {
@@ -385,6 +386,8 @@ function patchClass(el, value, isSVG) {
385
386
  const vShowOriginalDisplay = Symbol("_vod");
386
387
  const vShowHidden = Symbol("_vsh");
387
388
  const vShow = {
389
+ // used for prop mismatch check during hydration
390
+ name: "show",
388
391
  beforeMount(el, { value }, { transition }) {
389
392
  el[vShowOriginalDisplay] = el.style.display === "none" ? "" : el.style.display;
390
393
  if (transition && value) {
@@ -418,9 +421,6 @@ const vShow = {
418
421
  setDisplay(el, value);
419
422
  }
420
423
  };
421
- if (!!(process.env.NODE_ENV !== "production")) {
422
- vShow.name = "show";
423
- }
424
424
  function setDisplay(el, value) {
425
425
  el.style.display = value ? el[vShowOriginalDisplay] : "none";
426
426
  el[vShowHidden] = !value;
@@ -506,7 +506,7 @@ function setVarsOnNode(el, vars) {
506
506
  }
507
507
  }
508
508
 
509
- const displayRE = /(^|;)\s*display\s*:/;
509
+ const displayRE = /(?:^|;)\s*display\s*:/;
510
510
  function patchStyle(el, prev, next) {
511
511
  const style = el.style;
512
512
  const isCssString = isString(next);
@@ -811,11 +811,10 @@ function shouldSetAsProp(el, key, value, isSVG) {
811
811
  }
812
812
 
813
813
  const REMOVAL = {};
814
- /*! #__NO_SIDE_EFFECTS__ */
815
814
  // @__NO_SIDE_EFFECTS__
816
815
  function defineCustomElement(options, extraOptions, _createApp) {
817
- const Comp = defineComponent(options, extraOptions);
818
- if (isPlainObject(Comp)) extend(Comp, extraOptions);
816
+ let Comp = defineComponent(options, extraOptions);
817
+ if (isPlainObject(Comp)) Comp = extend({}, Comp, extraOptions);
819
818
  class VueCustomElement extends VueElement {
820
819
  constructor(initialProps) {
821
820
  super(Comp, initialProps, _createApp);
@@ -824,10 +823,9 @@ function defineCustomElement(options, extraOptions, _createApp) {
824
823
  VueCustomElement.def = Comp;
825
824
  return VueCustomElement;
826
825
  }
827
- /*! #__NO_SIDE_EFFECTS__ */
828
- const defineSSRCustomElement = /* @__NO_SIDE_EFFECTS__ */ (options, extraOptions) => {
826
+ const defineSSRCustomElement = (/* @__NO_SIDE_EFFECTS__ */ (options, extraOptions) => {
829
827
  return /* @__PURE__ */ defineCustomElement(options, extraOptions, createSSRApp);
830
- };
828
+ });
831
829
  const BaseClass = typeof HTMLElement !== "undefined" ? HTMLElement : class {
832
830
  };
833
831
  class VueElement extends BaseClass {
@@ -851,6 +849,8 @@ class VueElement extends BaseClass {
851
849
  this._nonce = this._def.nonce;
852
850
  this._connected = false;
853
851
  this._resolved = false;
852
+ this._patching = false;
853
+ this._dirty = false;
854
854
  this._numberProps = null;
855
855
  this._styleChildren = /* @__PURE__ */ new WeakSet();
856
856
  this._ob = null;
@@ -863,7 +863,11 @@ class VueElement extends BaseClass {
863
863
  );
864
864
  }
865
865
  if (_def.shadowRoot !== false) {
866
- this.attachShadow({ mode: "open" });
866
+ this.attachShadow(
867
+ extend({}, _def.shadowRootOptions, {
868
+ mode: "open"
869
+ })
870
+ );
867
871
  this._root = this.shadowRoot;
868
872
  } else {
869
873
  this._root = this;
@@ -923,9 +927,18 @@ class VueElement extends BaseClass {
923
927
  this._app && this._app.unmount();
924
928
  if (this._instance) this._instance.ce = void 0;
925
929
  this._app = this._instance = null;
930
+ if (this._teleportTargets) {
931
+ this._teleportTargets.clear();
932
+ this._teleportTargets = void 0;
933
+ }
926
934
  }
927
935
  });
928
936
  }
937
+ _processMutations(mutations) {
938
+ for (const m of mutations) {
939
+ this._setAttr(m.attributeName);
940
+ }
941
+ }
929
942
  /**
930
943
  * resolve inner component definition (handle possible async component)
931
944
  */
@@ -936,11 +949,7 @@ class VueElement extends BaseClass {
936
949
  for (let i = 0; i < this.attributes.length; i++) {
937
950
  this._setAttr(this.attributes[i].name);
938
951
  }
939
- this._ob = new MutationObserver((mutations) => {
940
- for (const m of mutations) {
941
- this._setAttr(m.attributeName);
942
- }
943
- });
952
+ this._ob = new MutationObserver(this._processMutations.bind(this));
944
953
  this._ob.observe(this, { attributes: true });
945
954
  const resolve = (def, isAsync = false) => {
946
955
  this._resolved = true;
@@ -1017,7 +1026,7 @@ class VueElement extends BaseClass {
1017
1026
  return this._getProp(key);
1018
1027
  },
1019
1028
  set(val) {
1020
- this._setProp(key, val, true, true);
1029
+ this._setProp(key, val, true, !this._patching);
1021
1030
  }
1022
1031
  });
1023
1032
  }
@@ -1043,6 +1052,7 @@ class VueElement extends BaseClass {
1043
1052
  */
1044
1053
  _setProp(key, val, shouldReflect = true, shouldUpdate = false) {
1045
1054
  if (val !== this._props[key]) {
1055
+ this._dirty = true;
1046
1056
  if (val === REMOVAL) {
1047
1057
  delete this._props[key];
1048
1058
  } else {
@@ -1056,7 +1066,10 @@ class VueElement extends BaseClass {
1056
1066
  }
1057
1067
  if (shouldReflect) {
1058
1068
  const ob = this._ob;
1059
- ob && ob.disconnect();
1069
+ if (ob) {
1070
+ this._processMutations(ob.takeRecords());
1071
+ ob.disconnect();
1072
+ }
1060
1073
  if (val === true) {
1061
1074
  this.setAttribute(hyphenate(key), "");
1062
1075
  } else if (typeof val === "string" || typeof val === "number") {
@@ -1160,7 +1173,7 @@ class VueElement extends BaseClass {
1160
1173
  * Only called when shadowRoot is false
1161
1174
  */
1162
1175
  _renderSlots() {
1163
- const outlets = (this._teleportTarget || this).querySelectorAll("slot");
1176
+ const outlets = this._getSlots();
1164
1177
  const scopeId = this._instance.type.__scopeId;
1165
1178
  for (let i = 0; i < outlets.length; i++) {
1166
1179
  const o = outlets[i];
@@ -1186,12 +1199,45 @@ class VueElement extends BaseClass {
1186
1199
  parent.removeChild(o);
1187
1200
  }
1188
1201
  }
1202
+ /**
1203
+ * @internal
1204
+ */
1205
+ _getSlots() {
1206
+ const roots = [this];
1207
+ if (this._teleportTargets) {
1208
+ roots.push(...this._teleportTargets);
1209
+ }
1210
+ const slots = /* @__PURE__ */ new Set();
1211
+ for (const root of roots) {
1212
+ const found = root.querySelectorAll("slot");
1213
+ for (let i = 0; i < found.length; i++) {
1214
+ slots.add(found[i]);
1215
+ }
1216
+ }
1217
+ return Array.from(slots);
1218
+ }
1189
1219
  /**
1190
1220
  * @internal
1191
1221
  */
1192
1222
  _injectChildStyle(comp) {
1193
1223
  this._applyStyles(comp.styles, comp);
1194
1224
  }
1225
+ /**
1226
+ * @internal
1227
+ */
1228
+ _beginPatch() {
1229
+ this._patching = true;
1230
+ this._dirty = false;
1231
+ }
1232
+ /**
1233
+ * @internal
1234
+ */
1235
+ _endPatch() {
1236
+ this._patching = false;
1237
+ if (this._dirty && this._instance) {
1238
+ this._update();
1239
+ }
1240
+ }
1195
1241
  /**
1196
1242
  * @internal
1197
1243
  */
@@ -1284,26 +1330,13 @@ const TransitionGroupImpl = /* @__PURE__ */ decorate({
1284
1330
  prevChildren = [];
1285
1331
  return;
1286
1332
  }
1287
- prevChildren.forEach(callPendingCbs);
1333
+ prevChildren.forEach((vnode) => callPendingCbs(vnode.el));
1288
1334
  prevChildren.forEach(recordPosition);
1289
1335
  const movedChildren = prevChildren.filter(applyTranslation);
1290
- forceReflow();
1336
+ forceReflow(instance.vnode.el);
1291
1337
  movedChildren.forEach((c) => {
1292
1338
  const el = c.el;
1293
- const style = el.style;
1294
- addTransitionClass(el, moveClass);
1295
- style.transform = style.webkitTransform = style.transitionDuration = "";
1296
- const cb = el[moveCbKey] = (e) => {
1297
- if (e && e.target !== el) {
1298
- return;
1299
- }
1300
- if (!e || /transform$/.test(e.propertyName)) {
1301
- el.removeEventListener("transitionend", cb);
1302
- el[moveCbKey] = null;
1303
- removeTransitionClass(el, moveClass);
1304
- }
1305
- };
1306
- el.addEventListener("transitionend", cb);
1339
+ handleMovedChildren(el, moveClass);
1307
1340
  });
1308
1341
  prevChildren = [];
1309
1342
  });
@@ -1326,10 +1359,10 @@ const TransitionGroupImpl = /* @__PURE__ */ decorate({
1326
1359
  instance
1327
1360
  )
1328
1361
  );
1329
- positionMap.set(
1330
- child,
1331
- child.el.getBoundingClientRect()
1332
- );
1362
+ positionMap.set(child, {
1363
+ left: child.el.offsetLeft,
1364
+ top: child.el.offsetTop
1365
+ });
1333
1366
  }
1334
1367
  }
1335
1368
  }
@@ -1350,8 +1383,7 @@ const TransitionGroupImpl = /* @__PURE__ */ decorate({
1350
1383
  }
1351
1384
  });
1352
1385
  const TransitionGroup = TransitionGroupImpl;
1353
- function callPendingCbs(c) {
1354
- const el = c.el;
1386
+ function callPendingCbs(el) {
1355
1387
  if (el[moveCbKey]) {
1356
1388
  el[moveCbKey]();
1357
1389
  }
@@ -1360,19 +1392,30 @@ function callPendingCbs(c) {
1360
1392
  }
1361
1393
  }
1362
1394
  function recordPosition(c) {
1363
- newPositionMap.set(c, c.el.getBoundingClientRect());
1395
+ newPositionMap.set(c, {
1396
+ left: c.el.offsetLeft,
1397
+ top: c.el.offsetTop
1398
+ });
1364
1399
  }
1365
1400
  function applyTranslation(c) {
1366
- const oldPos = positionMap.get(c);
1367
- const newPos = newPositionMap.get(c);
1401
+ if (baseApplyTranslation(
1402
+ positionMap.get(c),
1403
+ newPositionMap.get(c),
1404
+ c.el
1405
+ )) {
1406
+ return c;
1407
+ }
1408
+ }
1409
+ function baseApplyTranslation(oldPos, newPos, el) {
1368
1410
  const dx = oldPos.left - newPos.left;
1369
1411
  const dy = oldPos.top - newPos.top;
1370
1412
  if (dx || dy) {
1371
- const s = c.el.style;
1413
+ const s = el.style;
1372
1414
  s.transform = s.webkitTransform = `translate(${dx}px,${dy}px)`;
1373
1415
  s.transitionDuration = "0s";
1374
- return c;
1416
+ return true;
1375
1417
  }
1418
+ return false;
1376
1419
  }
1377
1420
  function hasCSSTransform(el, root, moveClass) {
1378
1421
  const clone = el.cloneNode();
@@ -1390,6 +1433,22 @@ function hasCSSTransform(el, root, moveClass) {
1390
1433
  container.removeChild(clone);
1391
1434
  return hasTransform;
1392
1435
  }
1436
+ const handleMovedChildren = (el, moveClass) => {
1437
+ const style = el.style;
1438
+ addTransitionClass(el, moveClass);
1439
+ style.transform = style.webkitTransform = style.transitionDuration = "";
1440
+ const cb = el[moveCbKey] = (e) => {
1441
+ if (e && e.target !== el) {
1442
+ return;
1443
+ }
1444
+ if (!e || e.propertyName.endsWith("transform")) {
1445
+ el.removeEventListener("transitionend", cb);
1446
+ el[moveCbKey] = null;
1447
+ removeTransitionClass(el, moveClass);
1448
+ }
1449
+ };
1450
+ el.addEventListener("transitionend", cb);
1451
+ };
1393
1452
 
1394
1453
  const getModelAssigner = (vnode) => {
1395
1454
  const fn = vnode.props["onUpdate:modelValue"] || false;
@@ -1425,21 +1484,21 @@ const vModelText = {
1425
1484
  vModelTextUpdate(el, oldValue, value, trim, number, lazy);
1426
1485
  }
1427
1486
  };
1487
+ function castValue(value, trim, number) {
1488
+ if (trim) value = value.trim();
1489
+ if (number) value = looseToNumber(value);
1490
+ return value;
1491
+ }
1428
1492
  const vModelTextInit = (el, trim, number, lazy, set) => {
1429
1493
  addEventListener(el, lazy ? "change" : "input", (e) => {
1430
1494
  if (e.target.composing) return;
1431
- let domValue = el.value;
1432
- if (trim) {
1433
- domValue = domValue.trim();
1434
- }
1435
- if (number || el.type === "number") {
1436
- domValue = looseToNumber(domValue);
1437
- }
1438
- (set || el[assignKey])(domValue);
1495
+ (set || el[assignKey])(
1496
+ castValue(el.value, trim, number || el.type === "number")
1497
+ );
1439
1498
  });
1440
- if (trim) {
1499
+ if (trim || number) {
1441
1500
  addEventListener(el, "change", () => {
1442
- el.value = el.value.trim();
1501
+ el.value = castValue(el.value, trim, number || el.type === "number");
1443
1502
  });
1444
1503
  }
1445
1504
  if (!lazy) {
@@ -1722,13 +1781,13 @@ const modifierGuards = {
1722
1781
  const withModifiers = (fn, modifiers) => {
1723
1782
  const cache = fn._withMods || (fn._withMods = {});
1724
1783
  const cacheKey = modifiers.join(".");
1725
- return cache[cacheKey] || (cache[cacheKey] = (event, ...args) => {
1784
+ return cache[cacheKey] || (cache[cacheKey] = ((event, ...args) => {
1726
1785
  for (let i = 0; i < modifiers.length; i++) {
1727
1786
  const guard = modifierGuards[modifiers[i]];
1728
1787
  if (guard && guard(event, modifiers)) return;
1729
1788
  }
1730
1789
  return fn(event, ...args);
1731
- });
1790
+ }));
1732
1791
  };
1733
1792
  const keyNames = {
1734
1793
  esc: "escape",
@@ -1742,7 +1801,7 @@ const keyNames = {
1742
1801
  const withKeys = (fn, modifiers) => {
1743
1802
  const cache = fn._withKeys || (fn._withKeys = {});
1744
1803
  const cacheKey = modifiers.join(".");
1745
- return cache[cacheKey] || (cache[cacheKey] = (event) => {
1804
+ return cache[cacheKey] || (cache[cacheKey] = ((event) => {
1746
1805
  if (!("key" in event)) {
1747
1806
  return;
1748
1807
  }
@@ -1752,7 +1811,7 @@ const withKeys = (fn, modifiers) => {
1752
1811
  )) {
1753
1812
  return fn(event);
1754
1813
  }
1755
- });
1814
+ }));
1756
1815
  };
1757
1816
 
1758
1817
  const rendererOptions = /* @__PURE__ */ extend({ patchProp }, nodeOps);
@@ -1766,13 +1825,13 @@ function ensureHydrationRenderer() {
1766
1825
  enabledHydration = true;
1767
1826
  return renderer;
1768
1827
  }
1769
- const render = (...args) => {
1828
+ const render = ((...args) => {
1770
1829
  ensureRenderer().render(...args);
1771
- };
1772
- const hydrate = (...args) => {
1830
+ });
1831
+ const hydrate = ((...args) => {
1773
1832
  ensureHydrationRenderer().hydrate(...args);
1774
- };
1775
- const createApp = (...args) => {
1833
+ });
1834
+ const createApp = ((...args) => {
1776
1835
  const app = ensureRenderer().createApp(...args);
1777
1836
  if (!!(process.env.NODE_ENV !== "production")) {
1778
1837
  injectNativeTagCheck(app);
@@ -1797,8 +1856,8 @@ const createApp = (...args) => {
1797
1856
  return proxy;
1798
1857
  };
1799
1858
  return app;
1800
- };
1801
- const createSSRApp = (...args) => {
1859
+ });
1860
+ const createSSRApp = ((...args) => {
1802
1861
  const app = ensureHydrationRenderer().createApp(...args);
1803
1862
  if (!!(process.env.NODE_ENV !== "production")) {
1804
1863
  injectNativeTagCheck(app);
@@ -1812,7 +1871,7 @@ const createSSRApp = (...args) => {
1812
1871
  }
1813
1872
  };
1814
1873
  return app;
1815
- };
1874
+ });
1816
1875
  function resolveRootNamespace(container) {
1817
1876
  if (container instanceof SVGElement) {
1818
1877
  return "svg";
@@ -1882,4 +1941,4 @@ const initDirectivesForSSR = () => {
1882
1941
  }
1883
1942
  } ;
1884
1943
 
1885
- export { Transition, TransitionGroup, VueElement, createApp, createSSRApp, defineCustomElement, defineSSRCustomElement, ensureRenderer, hydrate, initDirectivesForSSR, normalizeContainer, patchStyle, render, shouldSetAsProp, useCssModule, useCssVars, useHost, useShadowRoot, vModelCheckbox, vModelCheckboxInit, vModelCheckboxUpdate, vModelDynamic, getValue as vModelGetValue, vModelRadio, vModelSelect, vModelSelectInit, vModelSetSelected, vModelText, vModelTextInit, vModelTextUpdate, vShow, vShowHidden, vShowOriginalDisplay, withKeys, withModifiers };
1944
+ export { Transition, TransitionGroup, TransitionPropsValidators, VueElement, addTransitionClass, baseApplyTranslation, callPendingCbs, createApp, createSSRApp, defineCustomElement, defineSSRCustomElement, ensureHydrationRenderer, ensureRenderer, forceReflow, handleMovedChildren, hasCSSTransform, hydrate, initDirectivesForSSR, moveCbKey, normalizeContainer, patchStyle, removeTransitionClass, render, resolveTransitionProps, shouldSetAsProp, unsafeToTrustedHTML, useCssModule, useCssVars, useHost, useShadowRoot, vModelCheckbox, vModelCheckboxInit, vModelCheckboxUpdate, vModelDynamic, getValue as vModelGetValue, vModelRadio, vModelSelect, vModelSelectInit, vModelSetSelected, vModelText, vModelTextInit, vModelTextUpdate, vShow, vShowHidden, vShowOriginalDisplay, withKeys, withModifiers };