@vue/runtime-dom 3.5.0-alpha.5 → 3.5.0-beta.2

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,12 +1,24 @@
1
1
  /**
2
- * @vue/runtime-dom v3.5.0-alpha.5
2
+ * @vue/runtime-dom v3.5.0-beta.2
3
3
  * (c) 2018-present Yuxi (Evan) You and Vue contributors
4
4
  * @license MIT
5
5
  **/
6
- import { h, BaseTransition, BaseTransitionPropsValidators, assertNumber, getCurrentInstance, warn, onMounted, watchPostEffect, onUnmounted, Fragment, Static, camelize, callWithAsyncErrorHandling, defineComponent, nextTick, createVNode, useTransitionState, onUpdated, toRaw, getTransitionRawChildren, setTransitionHooks, resolveTransitionHooks, isRuntimeOnly, createRenderer, createHydrationRenderer } from '@vue/runtime-core';
6
+ import { warn, h, BaseTransition, BaseTransitionPropsValidators, assertNumber, getCurrentInstance, onBeforeMount, watchPostEffect, onMounted, onUnmounted, Fragment, Static, camelize, callWithAsyncErrorHandling, defineComponent, nextTick, unref, createVNode, useTransitionState, onUpdated, toRaw, getTransitionRawChildren, setTransitionHooks, resolveTransitionHooks, isRuntimeOnly, createRenderer, createHydrationRenderer } from '@vue/runtime-core';
7
7
  export * from '@vue/runtime-core';
8
- import { extend, isObject, toNumber, isArray, isString, hyphenate, capitalize, includeBooleanAttr, isSymbol, isSpecialBooleanAttr, isFunction, NOOP, isOn, isModelListener, camelize as camelize$1, EMPTY_OBJ, looseToNumber, looseIndexOf, isSet, looseEqual, invokeArrayFns, isHTMLTag, isSVGTag, isMathMLTag } from '@vue/shared';
8
+ import { extend, isObject, toNumber, isArray, isString, hyphenate, capitalize, includeBooleanAttr, isSymbol, isSpecialBooleanAttr, isFunction, NOOP, isOn, isModelListener, isPlainObject, hasOwn, camelize as camelize$1, EMPTY_OBJ, looseToNumber, looseIndexOf, isSet, looseEqual, invokeArrayFns, isHTMLTag, isSVGTag, isMathMLTag } from '@vue/shared';
9
9
 
10
+ let policy = void 0;
11
+ const tt = typeof window !== "undefined" && window.trustedTypes;
12
+ if (tt) {
13
+ try {
14
+ policy = /* @__PURE__ */ tt.createPolicy("vue", {
15
+ createHTML: (val) => val
16
+ });
17
+ } catch (e) {
18
+ !!(process.env.NODE_ENV !== "production") && warn(`Error creating trusted types policy: ${e}`);
19
+ }
20
+ }
21
+ const unsafeToTrustedHTML = policy ? (val) => policy.createHTML(val) : (val) => val;
10
22
  const svgNS = "http://www.w3.org/2000/svg";
11
23
  const mathmlNS = "http://www.w3.org/1998/Math/MathML";
12
24
  const doc = typeof document !== "undefined" ? document : null;
@@ -54,7 +66,9 @@ const nodeOps = {
54
66
  if (start === end || !(start = start.nextSibling)) break;
55
67
  }
56
68
  } else {
57
- templateContainer.innerHTML = namespace === "svg" ? `<svg>${content}</svg>` : namespace === "mathml" ? `<math>${content}</math>` : content;
69
+ templateContainer.innerHTML = unsafeToTrustedHTML(
70
+ namespace === "svg" ? `<svg>${content}</svg>` : namespace === "mathml" ? `<math>${content}</math>` : content
71
+ );
58
72
  const template = templateContainer.content;
59
73
  if (namespace === "svg" || namespace === "mathml") {
60
74
  const wrapper = template.firstChild;
@@ -424,11 +438,17 @@ function useCssVars(getter) {
424
438
  }
425
439
  const setVars = () => {
426
440
  const vars = getter(instance.proxy);
427
- setVarsOnVNode(instance.subTree, vars);
441
+ if (instance.ce) {
442
+ setVarsOnNode(instance.ce, vars);
443
+ } else {
444
+ setVarsOnVNode(instance.subTree, vars);
445
+ }
428
446
  updateTeleports(vars);
429
447
  };
430
- onMounted(() => {
448
+ onBeforeMount(() => {
431
449
  watchPostEffect(setVars);
450
+ });
451
+ onMounted(() => {
432
452
  const ob = new MutationObserver(setVars);
433
453
  ob.observe(instance.subTree.el.parentNode, { childList: true });
434
454
  onUnmounted(() => ob.disconnect());
@@ -781,16 +801,24 @@ function shouldSetAsProp(el, key, value, isSVG) {
781
801
  if (isNativeOn(key) && isString(value)) {
782
802
  return false;
783
803
  }
784
- return key in el;
804
+ if (key in el) {
805
+ return true;
806
+ }
807
+ if (el._isVueCE && (/[A-Z]/.test(key) || !isString(value))) {
808
+ return true;
809
+ }
810
+ return false;
785
811
  }
786
812
 
813
+ const REMOVAL = {};
787
814
  /*! #__NO_SIDE_EFFECTS__ */
788
815
  // @__NO_SIDE_EFFECTS__
789
- function defineCustomElement(options, extraOptions, hydrate2) {
816
+ function defineCustomElement(options, extraOptions, _createApp) {
790
817
  const Comp = defineComponent(options, extraOptions);
818
+ if (isPlainObject(Comp)) extend(Comp, extraOptions);
791
819
  class VueCustomElement extends VueElement {
792
820
  constructor(initialProps) {
793
- super(Comp, initialProps, hydrate2);
821
+ super(Comp, initialProps, _createApp);
794
822
  }
795
823
  }
796
824
  VueCustomElement.def = Comp;
@@ -798,47 +826,87 @@ function defineCustomElement(options, extraOptions, hydrate2) {
798
826
  }
799
827
  /*! #__NO_SIDE_EFFECTS__ */
800
828
  const defineSSRCustomElement = /* @__NO_SIDE_EFFECTS__ */ (options, extraOptions) => {
801
- return /* @__PURE__ */ defineCustomElement(options, extraOptions, hydrate);
829
+ return /* @__PURE__ */ defineCustomElement(options, extraOptions, createSSRApp);
802
830
  };
803
831
  const BaseClass = typeof HTMLElement !== "undefined" ? HTMLElement : class {
804
832
  };
805
833
  class VueElement extends BaseClass {
806
- constructor(_def, _props = {}, hydrate2) {
834
+ constructor(_def, _props = {}, _createApp = createApp) {
807
835
  super();
808
836
  this._def = _def;
809
837
  this._props = _props;
838
+ this._createApp = _createApp;
839
+ this._isVueCE = true;
810
840
  /**
811
841
  * @internal
812
842
  */
813
843
  this._instance = null;
844
+ /**
845
+ * @internal
846
+ */
847
+ this._app = null;
848
+ /**
849
+ * @internal
850
+ */
851
+ this._nonce = this._def.nonce;
814
852
  this._connected = false;
815
853
  this._resolved = false;
816
854
  this._numberProps = null;
855
+ this._styleChildren = /* @__PURE__ */ new WeakSet();
817
856
  this._ob = null;
818
- if (this.shadowRoot && hydrate2) {
819
- hydrate2(this._createVNode(), this.shadowRoot);
857
+ if (this.shadowRoot && _createApp !== createApp) {
858
+ this._root = this.shadowRoot;
820
859
  } else {
821
860
  if (!!(process.env.NODE_ENV !== "production") && this.shadowRoot) {
822
861
  warn(
823
862
  `Custom element has pre-rendered declarative shadow root but is not defined as hydratable. Use \`defineSSRCustomElement\`.`
824
863
  );
825
864
  }
826
- this.attachShadow({ mode: "open" });
827
- if (!this._def.__asyncLoader) {
828
- this._resolveProps(this._def);
865
+ if (_def.shadowRoot !== false) {
866
+ this.attachShadow({ mode: "open" });
867
+ this._root = this.shadowRoot;
868
+ } else {
869
+ this._root = this;
829
870
  }
830
871
  }
872
+ if (!this._def.__asyncLoader) {
873
+ this._resolveProps(this._def);
874
+ }
831
875
  }
832
876
  connectedCallback() {
877
+ if (!this.shadowRoot) {
878
+ this._parseSlots();
879
+ }
833
880
  this._connected = true;
881
+ let parent = this;
882
+ while (parent = parent && (parent.parentNode || parent.host)) {
883
+ if (parent instanceof VueElement) {
884
+ this._parent = parent;
885
+ break;
886
+ }
887
+ }
834
888
  if (!this._instance) {
835
889
  if (this._resolved) {
890
+ this._setParent();
836
891
  this._update();
837
892
  } else {
838
- this._resolveDef();
893
+ if (parent && parent._pendingResolve) {
894
+ this._pendingResolve = parent._pendingResolve.then(() => {
895
+ this._pendingResolve = void 0;
896
+ this._resolveDef();
897
+ });
898
+ } else {
899
+ this._resolveDef();
900
+ }
839
901
  }
840
902
  }
841
903
  }
904
+ _setParent(parent = this._parent) {
905
+ if (parent) {
906
+ this._instance.parent = parent._instance;
907
+ this._instance.provides = parent._instance.provides;
908
+ }
909
+ }
842
910
  disconnectedCallback() {
843
911
  this._connected = false;
844
912
  nextTick(() => {
@@ -847,8 +915,9 @@ class VueElement extends BaseClass {
847
915
  this._ob.disconnect();
848
916
  this._ob = null;
849
917
  }
850
- render(null, this.shadowRoot);
851
- this._instance = null;
918
+ this._app && this._app.unmount();
919
+ this._instance.ce = void 0;
920
+ this._app = this._instance = null;
852
921
  }
853
922
  });
854
923
  }
@@ -856,7 +925,9 @@ class VueElement extends BaseClass {
856
925
  * resolve inner component definition (handle possible async component)
857
926
  */
858
927
  _resolveDef() {
859
- this._resolved = true;
928
+ if (this._pendingResolve) {
929
+ return;
930
+ }
860
931
  for (let i = 0; i < this.attributes.length; i++) {
861
932
  this._setAttr(this.attributes[i].name);
862
933
  }
@@ -867,6 +938,8 @@ class VueElement extends BaseClass {
867
938
  });
868
939
  this._ob.observe(this, { attributes: true });
869
940
  const resolve = (def, isAsync = false) => {
941
+ this._resolved = true;
942
+ this._pendingResolve = void 0;
870
943
  const { props, styles } = def;
871
944
  let numberProps;
872
945
  if (props && !isArray(props)) {
@@ -884,22 +957,53 @@ class VueElement extends BaseClass {
884
957
  if (isAsync) {
885
958
  this._resolveProps(def);
886
959
  }
887
- this._applyStyles(styles);
888
- this._update();
960
+ if (this.shadowRoot) {
961
+ this._applyStyles(styles);
962
+ } else if (!!(process.env.NODE_ENV !== "production") && styles) {
963
+ warn(
964
+ "Custom element style injection is not supported when using shadowRoot: false"
965
+ );
966
+ }
967
+ this._mount(def);
889
968
  };
890
969
  const asyncDef = this._def.__asyncLoader;
891
970
  if (asyncDef) {
892
- asyncDef().then((def) => resolve(def, true));
971
+ this._pendingResolve = asyncDef().then(
972
+ (def) => resolve(this._def = def, true)
973
+ );
893
974
  } else {
894
975
  resolve(this._def);
895
976
  }
896
977
  }
978
+ _mount(def) {
979
+ if ((!!(process.env.NODE_ENV !== "production") || __VUE_PROD_DEVTOOLS__) && !def.name) {
980
+ def.name = "VueElement";
981
+ }
982
+ this._app = this._createApp(def);
983
+ if (def.configureApp) {
984
+ def.configureApp(this._app);
985
+ }
986
+ this._app._ceVNode = this._createVNode();
987
+ this._app.mount(this._root);
988
+ const exposed = this._instance && this._instance.exposed;
989
+ if (!exposed) return;
990
+ for (const key in exposed) {
991
+ if (!hasOwn(this, key)) {
992
+ Object.defineProperty(this, key, {
993
+ // unwrap ref to be consistent with public instance behavior
994
+ get: () => unref(exposed[key])
995
+ });
996
+ } else if (!!(process.env.NODE_ENV !== "production")) {
997
+ warn(`Exposed property "${key}" already exists on custom element.`);
998
+ }
999
+ }
1000
+ }
897
1001
  _resolveProps(def) {
898
1002
  const { props } = def;
899
1003
  const declaredPropKeys = isArray(props) ? props : Object.keys(props || {});
900
1004
  for (const key of Object.keys(this)) {
901
1005
  if (key[0] !== "_" && declaredPropKeys.includes(key)) {
902
- this._setProp(key, this[key], true, false);
1006
+ this._setProp(key, this[key]);
903
1007
  }
904
1008
  }
905
1009
  for (const key of declaredPropKeys.map(camelize$1)) {
@@ -908,18 +1012,20 @@ class VueElement extends BaseClass {
908
1012
  return this._getProp(key);
909
1013
  },
910
1014
  set(val) {
911
- this._setProp(key, val);
1015
+ this._setProp(key, val, true, true);
912
1016
  }
913
1017
  });
914
1018
  }
915
1019
  }
916
1020
  _setAttr(key) {
917
- let value = this.hasAttribute(key) ? this.getAttribute(key) : void 0;
1021
+ if (key.startsWith("data-v-")) return;
1022
+ const has = this.hasAttribute(key);
1023
+ let value = has ? this.getAttribute(key) : REMOVAL;
918
1024
  const camelKey = camelize$1(key);
919
- if (this._numberProps && this._numberProps[camelKey]) {
1025
+ if (has && this._numberProps && this._numberProps[camelKey]) {
920
1026
  value = toNumber(value);
921
1027
  }
922
- this._setProp(camelKey, value, false);
1028
+ this._setProp(camelKey, value, false, true);
923
1029
  }
924
1030
  /**
925
1031
  * @internal
@@ -930,9 +1036,13 @@ class VueElement extends BaseClass {
930
1036
  /**
931
1037
  * @internal
932
1038
  */
933
- _setProp(key, val, shouldReflect = true, shouldUpdate = true) {
1039
+ _setProp(key, val, shouldReflect = true, shouldUpdate = false) {
934
1040
  if (val !== this._props[key]) {
935
- this._props[key] = val;
1041
+ if (val === REMOVAL) {
1042
+ delete this._props[key];
1043
+ } else {
1044
+ this._props[key] = val;
1045
+ }
936
1046
  if (shouldUpdate && this._instance) {
937
1047
  this._update();
938
1048
  }
@@ -948,18 +1058,23 @@ class VueElement extends BaseClass {
948
1058
  }
949
1059
  }
950
1060
  _update() {
951
- render(this._createVNode(), this.shadowRoot);
1061
+ render(this._createVNode(), this._root);
952
1062
  }
953
1063
  _createVNode() {
954
- const vnode = createVNode(this._def, extend({}, this._props));
1064
+ const baseProps = {};
1065
+ if (!this.shadowRoot) {
1066
+ baseProps.onVnodeMounted = baseProps.onVnodeUpdated = this._renderSlots.bind(this);
1067
+ }
1068
+ const vnode = createVNode(this._def, extend(baseProps, this._props));
955
1069
  if (!this._instance) {
956
1070
  vnode.ce = (instance) => {
957
1071
  this._instance = instance;
1072
+ instance.ce = this;
958
1073
  instance.isCE = true;
959
1074
  if (!!(process.env.NODE_ENV !== "production")) {
960
1075
  instance.ceReload = (newStyles) => {
961
1076
  if (this._styles) {
962
- this._styles.forEach((s) => this.shadowRoot.removeChild(s));
1077
+ this._styles.forEach((s) => this._root.removeChild(s));
963
1078
  this._styles.length = 0;
964
1079
  }
965
1080
  this._applyStyles(newStyles);
@@ -969,9 +1084,10 @@ class VueElement extends BaseClass {
969
1084
  }
970
1085
  const dispatch = (event, args) => {
971
1086
  this.dispatchEvent(
972
- new CustomEvent(event, {
973
- detail: args
974
- })
1087
+ new CustomEvent(
1088
+ event,
1089
+ isPlainObject(args[0]) ? extend({ detail: args }, args[0]) : { detail: args }
1090
+ )
975
1091
  );
976
1092
  };
977
1093
  instance.emit = (event, ...args) => {
@@ -980,31 +1096,127 @@ class VueElement extends BaseClass {
980
1096
  dispatch(hyphenate(event), args);
981
1097
  }
982
1098
  };
983
- let parent = this;
984
- while (parent = parent && (parent.parentNode || parent.host)) {
985
- if (parent instanceof VueElement) {
986
- instance.parent = parent._instance;
987
- instance.provides = parent._instance.provides;
988
- break;
989
- }
990
- }
1099
+ this._setParent();
991
1100
  };
992
1101
  }
993
1102
  return vnode;
994
1103
  }
995
- _applyStyles(styles) {
996
- if (styles) {
997
- styles.forEach((css) => {
998
- const s = document.createElement("style");
999
- s.textContent = css;
1000
- this.shadowRoot.appendChild(s);
1001
- if (!!(process.env.NODE_ENV !== "production")) {
1104
+ _applyStyles(styles, owner) {
1105
+ if (!styles) return;
1106
+ if (owner) {
1107
+ if (owner === this._def || this._styleChildren.has(owner)) {
1108
+ return;
1109
+ }
1110
+ this._styleChildren.add(owner);
1111
+ }
1112
+ const nonce = this._nonce;
1113
+ for (let i = styles.length - 1; i >= 0; i--) {
1114
+ const s = document.createElement("style");
1115
+ if (nonce) s.setAttribute("nonce", nonce);
1116
+ s.textContent = styles[i];
1117
+ this.shadowRoot.prepend(s);
1118
+ if (!!(process.env.NODE_ENV !== "production")) {
1119
+ if (owner) {
1120
+ if (owner.__hmrId) {
1121
+ if (!this._childStyles) this._childStyles = /* @__PURE__ */ new Map();
1122
+ let entry = this._childStyles.get(owner.__hmrId);
1123
+ if (!entry) {
1124
+ this._childStyles.set(owner.__hmrId, entry = []);
1125
+ }
1126
+ entry.push(s);
1127
+ }
1128
+ } else {
1002
1129
  (this._styles || (this._styles = [])).push(s);
1003
1130
  }
1004
- });
1131
+ }
1132
+ }
1133
+ }
1134
+ /**
1135
+ * Only called when shaddowRoot is false
1136
+ */
1137
+ _parseSlots() {
1138
+ const slots = this._slots = {};
1139
+ let n;
1140
+ while (n = this.firstChild) {
1141
+ const slotName = n.nodeType === 1 && n.getAttribute("slot") || "default";
1142
+ (slots[slotName] || (slots[slotName] = [])).push(n);
1143
+ this.removeChild(n);
1144
+ }
1145
+ }
1146
+ /**
1147
+ * Only called when shaddowRoot is false
1148
+ */
1149
+ _renderSlots() {
1150
+ const outlets = this.querySelectorAll("slot");
1151
+ const scopeId = this._instance.type.__scopeId;
1152
+ for (let i = 0; i < outlets.length; i++) {
1153
+ const o = outlets[i];
1154
+ const slotName = o.getAttribute("name") || "default";
1155
+ const content = this._slots[slotName];
1156
+ const parent = o.parentNode;
1157
+ if (content) {
1158
+ for (const n of content) {
1159
+ if (scopeId && n.nodeType === 1) {
1160
+ const id = scopeId + "-s";
1161
+ const walker = document.createTreeWalker(n, 1);
1162
+ n.setAttribute(id, "");
1163
+ let child;
1164
+ while (child = walker.nextNode()) {
1165
+ child.setAttribute(id, "");
1166
+ }
1167
+ }
1168
+ parent.insertBefore(n, o);
1169
+ }
1170
+ } else {
1171
+ while (o.firstChild) parent.insertBefore(o.firstChild, o);
1172
+ }
1173
+ parent.removeChild(o);
1174
+ }
1175
+ }
1176
+ /**
1177
+ * @internal
1178
+ */
1179
+ _injectChildStyle(comp) {
1180
+ this._applyStyles(comp.styles, comp);
1181
+ }
1182
+ /**
1183
+ * @internal
1184
+ */
1185
+ _removeChildStyle(comp) {
1186
+ if (!!(process.env.NODE_ENV !== "production")) {
1187
+ this._styleChildren.delete(comp);
1188
+ if (this._childStyles && comp.__hmrId) {
1189
+ const oldStyles = this._childStyles.get(comp.__hmrId);
1190
+ if (oldStyles) {
1191
+ oldStyles.forEach((s) => this._root.removeChild(s));
1192
+ oldStyles.length = 0;
1193
+ }
1194
+ }
1005
1195
  }
1006
1196
  }
1007
1197
  }
1198
+ function useHost(caller) {
1199
+ const instance = getCurrentInstance();
1200
+ const el = instance && instance.ce;
1201
+ if (el) {
1202
+ return el;
1203
+ } else if (!!(process.env.NODE_ENV !== "production")) {
1204
+ if (!instance) {
1205
+ warn(
1206
+ `${caller || "useHost"} called without an active component instance.`
1207
+ );
1208
+ } else {
1209
+ warn(
1210
+ `${caller || "useHost"} can only be used in components defined via defineCustomElement.`
1211
+ );
1212
+ }
1213
+ }
1214
+ return null;
1215
+ }
1216
+ function useShadowRoot() {
1217
+ const el = !!(process.env.NODE_ENV !== "production") ? useHost("useShadowRoot") : useHost();
1218
+ return el && el.shadowRoot;
1219
+ }
1008
1220
 
1009
1221
  function useCssModule(name = "$style") {
1010
1222
  {
@@ -1518,7 +1730,9 @@ const createApp = (...args) => {
1518
1730
  if (!isFunction(component) && !component.render && !component.template) {
1519
1731
  component.template = container.innerHTML;
1520
1732
  }
1521
- container.innerHTML = "";
1733
+ if (container.nodeType === 1) {
1734
+ container.textContent = "";
1735
+ }
1522
1736
  const proxy = mount(container, false, resolveRootNamespace(container));
1523
1737
  if (container instanceof Element) {
1524
1738
  container.removeAttribute("v-cloak");
@@ -1612,4 +1826,4 @@ const initDirectivesForSSR = () => {
1612
1826
  }
1613
1827
  } ;
1614
1828
 
1615
- export { Transition, TransitionGroup, VueElement, createApp, createSSRApp, defineCustomElement, defineSSRCustomElement, hydrate, initDirectivesForSSR, render, useCssModule, useCssVars, vModelCheckbox, vModelDynamic, vModelRadio, vModelSelect, vModelText, vShow, withKeys, withModifiers };
1829
+ export { Transition, TransitionGroup, VueElement, createApp, createSSRApp, defineCustomElement, defineSSRCustomElement, hydrate, initDirectivesForSSR, render, useCssModule, useCssVars, useHost, useShadowRoot, vModelCheckbox, vModelDynamic, vModelRadio, vModelSelect, vModelText, vShow, withKeys, withModifiers };