runtime-dom.cjs.js 58 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', { value: true });
  3. var runtimeCore = require('@vue/runtime-core');
  4. var shared = require('@vue/shared');
  5. const svgNS = 'http://www.w3.org/2000/svg';
  6. const doc = (typeof document !== 'undefined' ? document : null);
  7. const staticTemplateCache = new Map();
  8. const nodeOps = {
  9. insert: (child, parent, anchor) => {
  10. parent.insertBefore(child, anchor || null);
  11. },
  12. remove: child => {
  13. const parent = child.parentNode;
  14. if (parent) {
  15. parent.removeChild(child);
  16. }
  17. },
  18. createElement: (tag, isSVG, is, props) => {
  19. const el = isSVG
  20. ? doc.createElementNS(svgNS, tag)
  21. : doc.createElement(tag, is ? { is } : undefined);
  22. if (tag === 'select' && props && props.multiple != null) {
  23. el.setAttribute('multiple', props.multiple);
  24. }
  25. return el;
  26. },
  27. createText: text => doc.createTextNode(text),
  28. createComment: text => doc.createComment(text),
  29. setText: (node, text) => {
  30. node.nodeValue = text;
  31. },
  32. setElementText: (el, text) => {
  33. el.textContent = text;
  34. },
  35. parentNode: node => node.parentNode,
  36. nextSibling: node => node.nextSibling,
  37. querySelector: selector => doc.querySelector(selector),
  38. setScopeId(el, id) {
  39. el.setAttribute(id, '');
  40. },
  41. cloneNode(el) {
  42. const cloned = el.cloneNode(true);
  43. // #3072
  44. // - in `patchDOMProp`, we store the actual value in the `el._value` property.
  45. // - normally, elements using `:value` bindings will not be hoisted, but if
  46. // the bound value is a constant, e.g. `:value="true"` - they do get
  47. // hoisted.
  48. // - in production, hoisted nodes are cloned when subsequent inserts, but
  49. // cloneNode() does not copy the custom property we attached.
  50. // - This may need to account for other custom DOM properties we attach to
  51. // elements in addition to `_value` in the future.
  52. if (`_value` in el) {
  53. cloned._value = el._value;
  54. }
  55. return cloned;
  56. },
  57. // __UNSAFE__
  58. // Reason: innerHTML.
  59. // Static content here can only come from compiled templates.
  60. // As long as the user only uses trusted templates, this is safe.
  61. insertStaticContent(content, parent, anchor, isSVG) {
  62. // <parent> before | first ... last | anchor </parent>
  63. const before = anchor ? anchor.previousSibling : parent.lastChild;
  64. let template = staticTemplateCache.get(content);
  65. if (!template) {
  66. const t = doc.createElement('template');
  67. t.innerHTML = isSVG ? `<svg>${content}</svg>` : content;
  68. template = t.content;
  69. if (isSVG) {
  70. // remove outer svg wrapper
  71. const wrapper = template.firstChild;
  72. while (wrapper.firstChild) {
  73. template.appendChild(wrapper.firstChild);
  74. }
  75. template.removeChild(wrapper);
  76. }
  77. staticTemplateCache.set(content, template);
  78. }
  79. parent.insertBefore(template.cloneNode(true), anchor);
  80. return [
  81. // first
  82. before ? before.nextSibling : parent.firstChild,
  83. // last
  84. anchor ? anchor.previousSibling : parent.lastChild
  85. ];
  86. }
  87. };
  88. // compiler should normalize class + :class bindings on the same element
  89. // into a single binding ['staticClass', dynamic]
  90. function patchClass(el, value, isSVG) {
  91. // directly setting className should be faster than setAttribute in theory
  92. // if this is an element during a transition, take the temporary transition
  93. // classes into account.
  94. const transitionClasses = el._vtc;
  95. if (transitionClasses) {
  96. value = (value ? [value, ...transitionClasses] : [...transitionClasses]).join(' ');
  97. }
  98. if (value == null) {
  99. el.removeAttribute('class');
  100. }
  101. else if (isSVG) {
  102. el.setAttribute('class', value);
  103. }
  104. else {
  105. el.className = value;
  106. }
  107. }
  108. function patchStyle(el, prev, next) {
  109. const style = el.style;
  110. const isCssString = shared.isString(next);
  111. if (next && !isCssString) {
  112. for (const key in next) {
  113. setStyle(style, key, next[key]);
  114. }
  115. if (prev && !shared.isString(prev)) {
  116. for (const key in prev) {
  117. if (next[key] == null) {
  118. setStyle(style, key, '');
  119. }
  120. }
  121. }
  122. }
  123. else {
  124. const currentDisplay = style.display;
  125. if (isCssString) {
  126. if (prev !== next) {
  127. style.cssText = next;
  128. }
  129. }
  130. else if (prev) {
  131. el.removeAttribute('style');
  132. }
  133. // indicates that the `display` of the element is controlled by `v-show`,
  134. // so we always keep the current `display` value regardless of the `style`
  135. // value, thus handing over control to `v-show`.
  136. if ('_vod' in el) {
  137. style.display = currentDisplay;
  138. }
  139. }
  140. }
  141. const importantRE = /\s*!important$/;
  142. function setStyle(style, name, val) {
  143. if (shared.isArray(val)) {
  144. val.forEach(v => setStyle(style, name, v));
  145. }
  146. else {
  147. if (name.startsWith('--')) {
  148. // custom property definition
  149. style.setProperty(name, val);
  150. }
  151. else {
  152. const prefixed = autoPrefix(style, name);
  153. if (importantRE.test(val)) {
  154. // !important
  155. style.setProperty(shared.hyphenate(prefixed), val.replace(importantRE, ''), 'important');
  156. }
  157. else {
  158. style[prefixed] = val;
  159. }
  160. }
  161. }
  162. }
  163. const prefixes = ['Webkit', 'Moz', 'ms'];
  164. const prefixCache = {};
  165. function autoPrefix(style, rawName) {
  166. const cached = prefixCache[rawName];
  167. if (cached) {
  168. return cached;
  169. }
  170. let name = runtimeCore.camelize(rawName);
  171. if (name !== 'filter' && name in style) {
  172. return (prefixCache[rawName] = name);
  173. }
  174. name = shared.capitalize(name);
  175. for (let i = 0; i < prefixes.length; i++) {
  176. const prefixed = prefixes[i] + name;
  177. if (prefixed in style) {
  178. return (prefixCache[rawName] = prefixed);
  179. }
  180. }
  181. return rawName;
  182. }
  183. const xlinkNS = 'http://www.w3.org/1999/xlink';
  184. function patchAttr(el, key, value, isSVG, instance) {
  185. if (isSVG && key.startsWith('xlink:')) {
  186. if (value == null) {
  187. el.removeAttributeNS(xlinkNS, key.slice(6, key.length));
  188. }
  189. else {
  190. el.setAttributeNS(xlinkNS, key, value);
  191. }
  192. }
  193. else {
  194. // note we are only checking boolean attributes that don't have a
  195. // corresponding dom prop of the same name here.
  196. const isBoolean = shared.isSpecialBooleanAttr(key);
  197. if (value == null || (isBoolean && !shared.includeBooleanAttr(value))) {
  198. el.removeAttribute(key);
  199. }
  200. else {
  201. el.setAttribute(key, isBoolean ? '' : value);
  202. }
  203. }
  204. }
  205. // __UNSAFE__
  206. // functions. The user is responsible for using them with only trusted content.
  207. function patchDOMProp(el, key, value,
  208. // the following args are passed only due to potential innerHTML/textContent
  209. // overriding existing VNodes, in which case the old tree must be properly
  210. // unmounted.
  211. prevChildren, parentComponent, parentSuspense, unmountChildren) {
  212. if (key === 'innerHTML' || key === 'textContent') {
  213. if (prevChildren) {
  214. unmountChildren(prevChildren, parentComponent, parentSuspense);
  215. }
  216. el[key] = value == null ? '' : value;
  217. return;
  218. }
  219. if (key === 'value' &&
  220. el.tagName !== 'PROGRESS' &&
  221. // custom elements may use _value internally
  222. !el.tagName.includes('-')) {
  223. // store value as _value as well since
  224. // non-string values will be stringified.
  225. el._value = value;
  226. const newValue = value == null ? '' : value;
  227. if (el.value !== newValue ||
  228. // #4956: always set for OPTION elements because its value falls back to
  229. // textContent if no value attribute is present. And setting .value for
  230. // OPTION has no side effect
  231. el.tagName === 'OPTION') {
  232. el.value = newValue;
  233. }
  234. if (value == null) {
  235. el.removeAttribute(key);
  236. }
  237. return;
  238. }
  239. if (value === '' || value == null) {
  240. const type = typeof el[key];
  241. if (type === 'boolean') {
  242. // e.g. <select multiple> compiles to { multiple: '' }
  243. el[key] = shared.includeBooleanAttr(value);
  244. return;
  245. }
  246. else if (value == null && type === 'string') {
  247. // e.g. <div :id="null">
  248. el[key] = '';
  249. el.removeAttribute(key);
  250. return;
  251. }
  252. else if (type === 'number') {
  253. // e.g. <img :width="null">
  254. // the value of some IDL attr must be greater than 0, e.g. input.size = 0 -> error
  255. try {
  256. el[key] = 0;
  257. }
  258. catch (_a) { }
  259. el.removeAttribute(key);
  260. return;
  261. }
  262. }
  263. // some properties perform value validation and throw
  264. try {
  265. el[key] = value;
  266. }
  267. catch (e) {
  268. {
  269. runtimeCore.warn(`Failed setting prop "${key}" on <${el.tagName.toLowerCase()}>: ` +
  270. `value ${value} is invalid.`, e);
  271. }
  272. }
  273. }
  274. // Async edge case fix requires storing an event listener's attach timestamp.
  275. let _getNow = Date.now;
  276. let skipTimestampCheck = false;
  277. if (typeof window !== 'undefined') {
  278. // Determine what event timestamp the browser is using. Annoyingly, the
  279. // timestamp can either be hi-res (relative to page load) or low-res
  280. // (relative to UNIX epoch), so in order to compare time we have to use the
  281. // same timestamp type when saving the flush timestamp.
  282. if (_getNow() > document.createEvent('Event').timeStamp) {
  283. // if the low-res timestamp which is bigger than the event timestamp
  284. // (which is evaluated AFTER) it means the event is using a hi-res timestamp,
  285. // and we need to use the hi-res version for event listeners as well.
  286. _getNow = () => performance.now();
  287. }
  288. // #3485: Firefox <= 53 has incorrect Event.timeStamp implementation
  289. // and does not fire microtasks in between event propagation, so safe to exclude.
  290. const ffMatch = navigator.userAgent.match(/firefox\/(\d+)/i);
  291. skipTimestampCheck = !!(ffMatch && Number(ffMatch[1]) <= 53);
  292. }
  293. // To avoid the overhead of repeatedly calling performance.now(), we cache
  294. // and use the same timestamp for all event listeners attached in the same tick.
  295. let cachedNow = 0;
  296. const p = Promise.resolve();
  297. const reset = () => {
  298. cachedNow = 0;
  299. };
  300. const getNow = () => cachedNow || (p.then(reset), (cachedNow = _getNow()));
  301. function addEventListener(el, event, handler, options) {
  302. el.addEventListener(event, handler, options);
  303. }
  304. function removeEventListener(el, event, handler, options) {
  305. el.removeEventListener(event, handler, options);
  306. }
  307. function patchEvent(el, rawName, prevValue, nextValue, instance = null) {
  308. // vei = vue event invokers
  309. const invokers = el._vei || (el._vei = {});
  310. const existingInvoker = invokers[rawName];
  311. if (nextValue && existingInvoker) {
  312. // patch
  313. existingInvoker.value = nextValue;
  314. }
  315. else {
  316. const [name, options] = parseName(rawName);
  317. if (nextValue) {
  318. // add
  319. const invoker = (invokers[rawName] = createInvoker(nextValue, instance));
  320. addEventListener(el, name, invoker, options);
  321. }
  322. else if (existingInvoker) {
  323. // remove
  324. removeEventListener(el, name, existingInvoker, options);
  325. invokers[rawName] = undefined;
  326. }
  327. }
  328. }
  329. const optionsModifierRE = /(?:Once|Passive|Capture)$/;
  330. function parseName(name) {
  331. let options;
  332. if (optionsModifierRE.test(name)) {
  333. options = {};
  334. let m;
  335. while ((m = name.match(optionsModifierRE))) {
  336. name = name.slice(0, name.length - m[0].length);
  337. options[m[0].toLowerCase()] = true;
  338. }
  339. }
  340. return [shared.hyphenate(name.slice(2)), options];
  341. }
  342. function createInvoker(initialValue, instance) {
  343. const invoker = (e) => {
  344. // async edge case #6566: inner click event triggers patch, event handler
  345. // attached to outer element during patch, and triggered again. This
  346. // happens because browsers fire microtask ticks between event propagation.
  347. // the solution is simple: we save the timestamp when a handler is attached,
  348. // and the handler would only fire if the event passed to it was fired
  349. // AFTER it was attached.
  350. const timeStamp = e.timeStamp || _getNow();
  351. if (skipTimestampCheck || timeStamp >= invoker.attached - 1) {
  352. runtimeCore.callWithAsyncErrorHandling(patchStopImmediatePropagation(e, invoker.value), instance, 5 /* NATIVE_EVENT_HANDLER */, [e]);
  353. }
  354. };
  355. invoker.value = initialValue;
  356. invoker.attached = getNow();
  357. return invoker;
  358. }
  359. function patchStopImmediatePropagation(e, value) {
  360. if (shared.isArray(value)) {
  361. const originalStop = e.stopImmediatePropagation;
  362. e.stopImmediatePropagation = () => {
  363. originalStop.call(e);
  364. e._stopped = true;
  365. };
  366. return value.map(fn => (e) => !e._stopped && fn(e));
  367. }
  368. else {
  369. return value;
  370. }
  371. }
  372. const nativeOnRE = /^on[a-z]/;
  373. const patchProp = (el, key, prevValue, nextValue, isSVG = false, prevChildren, parentComponent, parentSuspense, unmountChildren) => {
  374. if (key === 'class') {
  375. patchClass(el, nextValue, isSVG);
  376. }
  377. else if (key === 'style') {
  378. patchStyle(el, prevValue, nextValue);
  379. }
  380. else if (shared.isOn(key)) {
  381. // ignore v-model listeners
  382. if (!shared.isModelListener(key)) {
  383. patchEvent(el, key, prevValue, nextValue, parentComponent);
  384. }
  385. }
  386. else if (key[0] === '.'
  387. ? ((key = key.slice(1)), true)
  388. : key[0] === '^'
  389. ? ((key = key.slice(1)), false)
  390. : shouldSetAsProp(el, key, nextValue, isSVG)) {
  391. patchDOMProp(el, key, nextValue, prevChildren, parentComponent, parentSuspense, unmountChildren);
  392. }
  393. else {
  394. // special case for <input v-model type="checkbox"> with
  395. // :true-value & :false-value
  396. // store value as dom properties since non-string values will be
  397. // stringified.
  398. if (key === 'true-value') {
  399. el._trueValue = nextValue;
  400. }
  401. else if (key === 'false-value') {
  402. el._falseValue = nextValue;
  403. }
  404. patchAttr(el, key, nextValue, isSVG);
  405. }
  406. };
  407. function shouldSetAsProp(el, key, value, isSVG) {
  408. if (isSVG) {
  409. // most keys must be set as attribute on svg elements to work
  410. // ...except innerHTML & textContent
  411. if (key === 'innerHTML' || key === 'textContent') {
  412. return true;
  413. }
  414. // or native onclick with function values
  415. if (key in el && nativeOnRE.test(key) && shared.isFunction(value)) {
  416. return true;
  417. }
  418. return false;
  419. }
  420. // spellcheck and draggable are numerated attrs, however their
  421. // corresponding DOM properties are actually booleans - this leads to
  422. // setting it with a string "false" value leading it to be coerced to
  423. // `true`, so we need to always treat them as attributes.
  424. // Note that `contentEditable` doesn't have this problem: its DOM
  425. // property is also enumerated string values.
  426. if (key === 'spellcheck' || key === 'draggable') {
  427. return false;
  428. }
  429. // #1787, #2840 form property on form elements is readonly and must be set as
  430. // attribute.
  431. if (key === 'form') {
  432. return false;
  433. }
  434. // #1526 <input list> must be set as attribute
  435. if (key === 'list' && el.tagName === 'INPUT') {
  436. return false;
  437. }
  438. // #2766 <textarea type> must be set as attribute
  439. if (key === 'type' && el.tagName === 'TEXTAREA') {
  440. return false;
  441. }
  442. // native onclick with string value, must be set as attribute
  443. if (nativeOnRE.test(key) && shared.isString(value)) {
  444. return false;
  445. }
  446. return key in el;
  447. }
  448. function defineCustomElement(options, hydate) {
  449. const Comp = runtimeCore.defineComponent(options);
  450. class VueCustomElement extends VueElement {
  451. constructor(initialProps) {
  452. super(Comp, initialProps, hydate);
  453. }
  454. }
  455. VueCustomElement.def = Comp;
  456. return VueCustomElement;
  457. }
  458. const defineSSRCustomElement = ((options) => {
  459. // @ts-ignore
  460. return defineCustomElement(options, hydrate);
  461. });
  462. const BaseClass = (typeof HTMLElement !== 'undefined' ? HTMLElement : class {
  463. });
  464. class VueElement extends BaseClass {
  465. constructor(_def, _props = {}, hydrate) {
  466. super();
  467. this._def = _def;
  468. this._props = _props;
  469. /**
  470. * @internal
  471. */
  472. this._instance = null;
  473. this._connected = false;
  474. this._resolved = false;
  475. this._numberProps = null;
  476. if (this.shadowRoot && hydrate) {
  477. hydrate(this._createVNode(), this.shadowRoot);
  478. }
  479. else {
  480. if (this.shadowRoot) {
  481. runtimeCore.warn(`Custom element has pre-rendered declarative shadow root but is not ` +
  482. `defined as hydratable. Use \`defineSSRCustomElement\`.`);
  483. }
  484. this.attachShadow({ mode: 'open' });
  485. }
  486. }
  487. connectedCallback() {
  488. this._connected = true;
  489. if (!this._instance) {
  490. this._resolveDef();
  491. }
  492. }
  493. disconnectedCallback() {
  494. this._connected = false;
  495. runtimeCore.nextTick(() => {
  496. if (!this._connected) {
  497. render(null, this.shadowRoot);
  498. this._instance = null;
  499. }
  500. });
  501. }
  502. /**
  503. * resolve inner component definition (handle possible async component)
  504. */
  505. _resolveDef() {
  506. if (this._resolved) {
  507. return;
  508. }
  509. this._resolved = true;
  510. // set initial attrs
  511. for (let i = 0; i < this.attributes.length; i++) {
  512. this._setAttr(this.attributes[i].name);
  513. }
  514. // watch future attr changes
  515. new MutationObserver(mutations => {
  516. for (const m of mutations) {
  517. this._setAttr(m.attributeName);
  518. }
  519. }).observe(this, { attributes: true });
  520. const resolve = (def) => {
  521. const { props, styles } = def;
  522. const hasOptions = !shared.isArray(props);
  523. const rawKeys = props ? (hasOptions ? Object.keys(props) : props) : [];
  524. // cast Number-type props set before resolve
  525. let numberProps;
  526. if (hasOptions) {
  527. for (const key in this._props) {
  528. const opt = props[key];
  529. if (opt === Number || (opt && opt.type === Number)) {
  530. this._props[key] = shared.toNumber(this._props[key]);
  531. (numberProps || (numberProps = Object.create(null)))[key] = true;
  532. }
  533. }
  534. }
  535. this._numberProps = numberProps;
  536. // check if there are props set pre-upgrade or connect
  537. for (const key of Object.keys(this)) {
  538. if (key[0] !== '_') {
  539. this._setProp(key, this[key], true, false);
  540. }
  541. }
  542. // defining getter/setters on prototype
  543. for (const key of rawKeys.map(shared.camelize)) {
  544. Object.defineProperty(this, key, {
  545. get() {
  546. return this._getProp(key);
  547. },
  548. set(val) {
  549. this._setProp(key, val);
  550. }
  551. });
  552. }
  553. // apply CSS
  554. this._applyStyles(styles);
  555. // initial render
  556. this._update();
  557. };
  558. const asyncDef = this._def.__asyncLoader;
  559. if (asyncDef) {
  560. asyncDef().then(resolve);
  561. }
  562. else {
  563. resolve(this._def);
  564. }
  565. }
  566. _setAttr(key) {
  567. let value = this.getAttribute(key);
  568. if (this._numberProps && this._numberProps[key]) {
  569. value = shared.toNumber(value);
  570. }
  571. this._setProp(shared.camelize(key), value, false);
  572. }
  573. /**
  574. * @internal
  575. */
  576. _getProp(key) {
  577. return this._props[key];
  578. }
  579. /**
  580. * @internal
  581. */
  582. _setProp(key, val, shouldReflect = true, shouldUpdate = true) {
  583. if (val !== this._props[key]) {
  584. this._props[key] = val;
  585. if (shouldUpdate && this._instance) {
  586. this._update();
  587. }
  588. // reflect
  589. if (shouldReflect) {
  590. if (val === true) {
  591. this.setAttribute(shared.hyphenate(key), '');
  592. }
  593. else if (typeof val === 'string' || typeof val === 'number') {
  594. this.setAttribute(shared.hyphenate(key), val + '');
  595. }
  596. else if (!val) {
  597. this.removeAttribute(shared.hyphenate(key));
  598. }
  599. }
  600. }
  601. }
  602. _update() {
  603. render(this._createVNode(), this.shadowRoot);
  604. }
  605. _createVNode() {
  606. const vnode = runtimeCore.createVNode(this._def, shared.extend({}, this._props));
  607. if (!this._instance) {
  608. vnode.ce = instance => {
  609. this._instance = instance;
  610. instance.isCE = true;
  611. // HMR
  612. {
  613. instance.ceReload = newStyles => {
  614. // always reset styles
  615. if (this._styles) {
  616. this._styles.forEach(s => this.shadowRoot.removeChild(s));
  617. this._styles.length = 0;
  618. }
  619. this._applyStyles(newStyles);
  620. // if this is an async component, ceReload is called from the inner
  621. // component so no need to reload the async wrapper
  622. if (!this._def.__asyncLoader) {
  623. // reload
  624. this._instance = null;
  625. this._update();
  626. }
  627. };
  628. }
  629. // intercept emit
  630. instance.emit = (event, ...args) => {
  631. this.dispatchEvent(new CustomEvent(event, {
  632. detail: args
  633. }));
  634. };
  635. // locate nearest Vue custom element parent for provide/inject
  636. let parent = this;
  637. while ((parent =
  638. parent && (parent.parentNode || parent.host))) {
  639. if (parent instanceof VueElement) {
  640. instance.parent = parent._instance;
  641. break;
  642. }
  643. }
  644. };
  645. }
  646. return vnode;
  647. }
  648. _applyStyles(styles) {
  649. if (styles) {
  650. styles.forEach(css => {
  651. const s = document.createElement('style');
  652. s.textContent = css;
  653. this.shadowRoot.appendChild(s);
  654. // record for HMR
  655. {
  656. (this._styles || (this._styles = [])).push(s);
  657. }
  658. });
  659. }
  660. }
  661. }
  662. function useCssModule(name = '$style') {
  663. /* istanbul ignore else */
  664. {
  665. const instance = runtimeCore.getCurrentInstance();
  666. if (!instance) {
  667. runtimeCore.warn(`useCssModule must be called inside setup()`);
  668. return shared.EMPTY_OBJ;
  669. }
  670. const modules = instance.type.__cssModules;
  671. if (!modules) {
  672. runtimeCore.warn(`Current instance does not have CSS modules injected.`);
  673. return shared.EMPTY_OBJ;
  674. }
  675. const mod = modules[name];
  676. if (!mod) {
  677. runtimeCore.warn(`Current instance does not have CSS module named "${name}".`);
  678. return shared.EMPTY_OBJ;
  679. }
  680. return mod;
  681. }
  682. }
  683. /**
  684. * Runtime helper for SFC's CSS variable injection feature.
  685. * @private
  686. */
  687. function useCssVars(getter) {
  688. return;
  689. }
  690. const TRANSITION = 'transition';
  691. const ANIMATION = 'animation';
  692. // DOM Transition is a higher-order-component based on the platform-agnostic
  693. // base Transition component, with DOM-specific logic.
  694. const Transition = (props, { slots }) => runtimeCore.h(runtimeCore.BaseTransition, resolveTransitionProps(props), slots);
  695. Transition.displayName = 'Transition';
  696. const DOMTransitionPropsValidators = {
  697. name: String,
  698. type: String,
  699. css: {
  700. type: Boolean,
  701. default: true
  702. },
  703. duration: [String, Number, Object],
  704. enterFromClass: String,
  705. enterActiveClass: String,
  706. enterToClass: String,
  707. appearFromClass: String,
  708. appearActiveClass: String,
  709. appearToClass: String,
  710. leaveFromClass: String,
  711. leaveActiveClass: String,
  712. leaveToClass: String
  713. };
  714. const TransitionPropsValidators = (Transition.props =
  715. /*#__PURE__*/ shared.extend({}, runtimeCore.BaseTransition.props, DOMTransitionPropsValidators));
  716. /**
  717. * #3227 Incoming hooks may be merged into arrays when wrapping Transition
  718. * with custom HOCs.
  719. */
  720. const callHook = (hook, args = []) => {
  721. if (shared.isArray(hook)) {
  722. hook.forEach(h => h(...args));
  723. }
  724. else if (hook) {
  725. hook(...args);
  726. }
  727. };
  728. /**
  729. * Check if a hook expects a callback (2nd arg), which means the user
  730. * intends to explicitly control the end of the transition.
  731. */
  732. const hasExplicitCallback = (hook) => {
  733. return hook
  734. ? shared.isArray(hook)
  735. ? hook.some(h => h.length > 1)
  736. : hook.length > 1
  737. : false;
  738. };
  739. function resolveTransitionProps(rawProps) {
  740. const baseProps = {};
  741. for (const key in rawProps) {
  742. if (!(key in DOMTransitionPropsValidators)) {
  743. baseProps[key] = rawProps[key];
  744. }
  745. }
  746. if (rawProps.css === false) {
  747. return baseProps;
  748. }
  749. const { name = 'v', type, duration, enterFromClass = `${name}-enter-from`, enterActiveClass = `${name}-enter-active`, enterToClass = `${name}-enter-to`, appearFromClass = enterFromClass, appearActiveClass = enterActiveClass, appearToClass = enterToClass, leaveFromClass = `${name}-leave-from`, leaveActiveClass = `${name}-leave-active`, leaveToClass = `${name}-leave-to` } = rawProps;
  750. const durations = normalizeDuration(duration);
  751. const enterDuration = durations && durations[0];
  752. const leaveDuration = durations && durations[1];
  753. const { onBeforeEnter, onEnter, onEnterCancelled, onLeave, onLeaveCancelled, onBeforeAppear = onBeforeEnter, onAppear = onEnter, onAppearCancelled = onEnterCancelled } = baseProps;
  754. const finishEnter = (el, isAppear, done) => {
  755. removeTransitionClass(el, isAppear ? appearToClass : enterToClass);
  756. removeTransitionClass(el, isAppear ? appearActiveClass : enterActiveClass);
  757. done && done();
  758. };
  759. const finishLeave = (el, done) => {
  760. removeTransitionClass(el, leaveToClass);
  761. removeTransitionClass(el, leaveActiveClass);
  762. done && done();
  763. };
  764. const makeEnterHook = (isAppear) => {
  765. return (el, done) => {
  766. const hook = isAppear ? onAppear : onEnter;
  767. const resolve = () => finishEnter(el, isAppear, done);
  768. callHook(hook, [el, resolve]);
  769. nextFrame(() => {
  770. removeTransitionClass(el, isAppear ? appearFromClass : enterFromClass);
  771. addTransitionClass(el, isAppear ? appearToClass : enterToClass);
  772. if (!hasExplicitCallback(hook)) {
  773. whenTransitionEnds(el, type, enterDuration, resolve);
  774. }
  775. });
  776. };
  777. };
  778. return shared.extend(baseProps, {
  779. onBeforeEnter(el) {
  780. callHook(onBeforeEnter, [el]);
  781. addTransitionClass(el, enterFromClass);
  782. addTransitionClass(el, enterActiveClass);
  783. },
  784. onBeforeAppear(el) {
  785. callHook(onBeforeAppear, [el]);
  786. addTransitionClass(el, appearFromClass);
  787. addTransitionClass(el, appearActiveClass);
  788. },
  789. onEnter: makeEnterHook(false),
  790. onAppear: makeEnterHook(true),
  791. onLeave(el, done) {
  792. const resolve = () => finishLeave(el, done);
  793. addTransitionClass(el, leaveFromClass);
  794. // force reflow so *-leave-from classes immediately take effect (#2593)
  795. forceReflow();
  796. addTransitionClass(el, leaveActiveClass);
  797. nextFrame(() => {
  798. removeTransitionClass(el, leaveFromClass);
  799. addTransitionClass(el, leaveToClass);
  800. if (!hasExplicitCallback(onLeave)) {
  801. whenTransitionEnds(el, type, leaveDuration, resolve);
  802. }
  803. });
  804. callHook(onLeave, [el, resolve]);
  805. },
  806. onEnterCancelled(el) {
  807. finishEnter(el, false);
  808. callHook(onEnterCancelled, [el]);
  809. },
  810. onAppearCancelled(el) {
  811. finishEnter(el, true);
  812. callHook(onAppearCancelled, [el]);
  813. },
  814. onLeaveCancelled(el) {
  815. finishLeave(el);
  816. callHook(onLeaveCancelled, [el]);
  817. }
  818. });
  819. }
  820. function normalizeDuration(duration) {
  821. if (duration == null) {
  822. return null;
  823. }
  824. else if (shared.isObject(duration)) {
  825. return [NumberOf(duration.enter), NumberOf(duration.leave)];
  826. }
  827. else {
  828. const n = NumberOf(duration);
  829. return [n, n];
  830. }
  831. }
  832. function NumberOf(val) {
  833. const res = shared.toNumber(val);
  834. validateDuration(res);
  835. return res;
  836. }
  837. function validateDuration(val) {
  838. if (typeof val !== 'number') {
  839. runtimeCore.warn(`<transition> explicit duration is not a valid number - ` +
  840. `got ${JSON.stringify(val)}.`);
  841. }
  842. else if (isNaN(val)) {
  843. runtimeCore.warn(`<transition> explicit duration is NaN - ` +
  844. 'the duration expression might be incorrect.');
  845. }
  846. }
  847. function addTransitionClass(el, cls) {
  848. cls.split(/\s+/).forEach(c => c && el.classList.add(c));
  849. (el._vtc ||
  850. (el._vtc = new Set())).add(cls);
  851. }
  852. function removeTransitionClass(el, cls) {
  853. cls.split(/\s+/).forEach(c => c && el.classList.remove(c));
  854. const { _vtc } = el;
  855. if (_vtc) {
  856. _vtc.delete(cls);
  857. if (!_vtc.size) {
  858. el._vtc = undefined;
  859. }
  860. }
  861. }
  862. function nextFrame(cb) {
  863. requestAnimationFrame(() => {
  864. requestAnimationFrame(cb);
  865. });
  866. }
  867. let endId = 0;
  868. function whenTransitionEnds(el, expectedType, explicitTimeout, resolve) {
  869. const id = (el._endId = ++endId);
  870. const resolveIfNotStale = () => {
  871. if (id === el._endId) {
  872. resolve();
  873. }
  874. };
  875. if (explicitTimeout) {
  876. return setTimeout(resolveIfNotStale, explicitTimeout);
  877. }
  878. const { type, timeout, propCount } = getTransitionInfo(el, expectedType);
  879. if (!type) {
  880. return resolve();
  881. }
  882. const endEvent = type + 'end';
  883. let ended = 0;
  884. const end = () => {
  885. el.removeEventListener(endEvent, onEnd);
  886. resolveIfNotStale();
  887. };
  888. const onEnd = (e) => {
  889. if (e.target === el && ++ended >= propCount) {
  890. end();
  891. }
  892. };
  893. setTimeout(() => {
  894. if (ended < propCount) {
  895. end();
  896. }
  897. }, timeout + 1);
  898. el.addEventListener(endEvent, onEnd);
  899. }
  900. function getTransitionInfo(el, expectedType) {
  901. const styles = window.getComputedStyle(el);
  902. // JSDOM may return undefined for transition properties
  903. const getStyleProperties = (key) => (styles[key] || '').split(', ');
  904. const transitionDelays = getStyleProperties(TRANSITION + 'Delay');
  905. const transitionDurations = getStyleProperties(TRANSITION + 'Duration');
  906. const transitionTimeout = getTimeout(transitionDelays, transitionDurations);
  907. const animationDelays = getStyleProperties(ANIMATION + 'Delay');
  908. const animationDurations = getStyleProperties(ANIMATION + 'Duration');
  909. const animationTimeout = getTimeout(animationDelays, animationDurations);
  910. let type = null;
  911. let timeout = 0;
  912. let propCount = 0;
  913. /* istanbul ignore if */
  914. if (expectedType === TRANSITION) {
  915. if (transitionTimeout > 0) {
  916. type = TRANSITION;
  917. timeout = transitionTimeout;
  918. propCount = transitionDurations.length;
  919. }
  920. }
  921. else if (expectedType === ANIMATION) {
  922. if (animationTimeout > 0) {
  923. type = ANIMATION;
  924. timeout = animationTimeout;
  925. propCount = animationDurations.length;
  926. }
  927. }
  928. else {
  929. timeout = Math.max(transitionTimeout, animationTimeout);
  930. type =
  931. timeout > 0
  932. ? transitionTimeout > animationTimeout
  933. ? TRANSITION
  934. : ANIMATION
  935. : null;
  936. propCount = type
  937. ? type === TRANSITION
  938. ? transitionDurations.length
  939. : animationDurations.length
  940. : 0;
  941. }
  942. const hasTransform = type === TRANSITION &&
  943. /\b(transform|all)(,|$)/.test(styles[TRANSITION + 'Property']);
  944. return {
  945. type,
  946. timeout,
  947. propCount,
  948. hasTransform
  949. };
  950. }
  951. function getTimeout(delays, durations) {
  952. while (delays.length < durations.length) {
  953. delays = delays.concat(delays);
  954. }
  955. return Math.max(...durations.map((d, i) => toMs(d) + toMs(delays[i])));
  956. }
  957. // Old versions of Chromium (below 61.0.3163.100) formats floating pointer
  958. // numbers in a locale-dependent way, using a comma instead of a dot.
  959. // If comma is not replaced with a dot, the input will be rounded down
  960. // (i.e. acting as a floor function) causing unexpected behaviors
  961. function toMs(s) {
  962. return Number(s.slice(0, -1).replace(',', '.')) * 1000;
  963. }
  964. // synchronously force layout to put elements into a certain state
  965. function forceReflow() {
  966. return document.body.offsetHeight;
  967. }
  968. const positionMap = new WeakMap();
  969. const newPositionMap = new WeakMap();
  970. const TransitionGroupImpl = {
  971. name: 'TransitionGroup',
  972. props: /*#__PURE__*/ shared.extend({}, TransitionPropsValidators, {
  973. tag: String,
  974. moveClass: String
  975. }),
  976. setup(props, { slots }) {
  977. const instance = runtimeCore.getCurrentInstance();
  978. const state = runtimeCore.useTransitionState();
  979. let prevChildren;
  980. let children;
  981. runtimeCore.onUpdated(() => {
  982. // children is guaranteed to exist after initial render
  983. if (!prevChildren.length) {
  984. return;
  985. }
  986. const moveClass = props.moveClass || `${props.name || 'v'}-move`;
  987. if (!hasCSSTransform(prevChildren[0].el, instance.vnode.el, moveClass)) {
  988. return;
  989. }
  990. // we divide the work into three loops to avoid mixing DOM reads and writes
  991. // in each iteration - which helps prevent layout thrashing.
  992. prevChildren.forEach(callPendingCbs);
  993. prevChildren.forEach(recordPosition);
  994. const movedChildren = prevChildren.filter(applyTranslation);
  995. // force reflow to put everything in position
  996. forceReflow();
  997. movedChildren.forEach(c => {
  998. const el = c.el;
  999. const style = el.style;
  1000. addTransitionClass(el, moveClass);
  1001. style.transform = style.webkitTransform = style.transitionDuration = '';
  1002. const cb = (el._moveCb = (e) => {
  1003. if (e && e.target !== el) {
  1004. return;
  1005. }
  1006. if (!e || /transform$/.test(e.propertyName)) {
  1007. el.removeEventListener('transitionend', cb);
  1008. el._moveCb = null;
  1009. removeTransitionClass(el, moveClass);
  1010. }
  1011. });
  1012. el.addEventListener('transitionend', cb);
  1013. });
  1014. });
  1015. return () => {
  1016. const rawProps = runtimeCore.toRaw(props);
  1017. const cssTransitionProps = resolveTransitionProps(rawProps);
  1018. let tag = rawProps.tag || runtimeCore.Fragment;
  1019. prevChildren = children;
  1020. children = slots.default ? runtimeCore.getTransitionRawChildren(slots.default()) : [];
  1021. for (let i = 0; i < children.length; i++) {
  1022. const child = children[i];
  1023. if (child.key != null) {
  1024. runtimeCore.setTransitionHooks(child, runtimeCore.resolveTransitionHooks(child, cssTransitionProps, state, instance));
  1025. }
  1026. else {
  1027. runtimeCore.warn(`<TransitionGroup> children must be keyed.`);
  1028. }
  1029. }
  1030. if (prevChildren) {
  1031. for (let i = 0; i < prevChildren.length; i++) {
  1032. const child = prevChildren[i];
  1033. runtimeCore.setTransitionHooks(child, runtimeCore.resolveTransitionHooks(child, cssTransitionProps, state, instance));
  1034. positionMap.set(child, child.el.getBoundingClientRect());
  1035. }
  1036. }
  1037. return runtimeCore.createVNode(tag, null, children);
  1038. };
  1039. }
  1040. };
  1041. const TransitionGroup = TransitionGroupImpl;
  1042. function callPendingCbs(c) {
  1043. const el = c.el;
  1044. if (el._moveCb) {
  1045. el._moveCb();
  1046. }
  1047. if (el._enterCb) {
  1048. el._enterCb();
  1049. }
  1050. }
  1051. function recordPosition(c) {
  1052. newPositionMap.set(c, c.el.getBoundingClientRect());
  1053. }
  1054. function applyTranslation(c) {
  1055. const oldPos = positionMap.get(c);
  1056. const newPos = newPositionMap.get(c);
  1057. const dx = oldPos.left - newPos.left;
  1058. const dy = oldPos.top - newPos.top;
  1059. if (dx || dy) {
  1060. const s = c.el.style;
  1061. s.transform = s.webkitTransform = `translate(${dx}px,${dy}px)`;
  1062. s.transitionDuration = '0s';
  1063. return c;
  1064. }
  1065. }
  1066. function hasCSSTransform(el, root, moveClass) {
  1067. // Detect whether an element with the move class applied has
  1068. // CSS transitions. Since the element may be inside an entering
  1069. // transition at this very moment, we make a clone of it and remove
  1070. // all other transition classes applied to ensure only the move class
  1071. // is applied.
  1072. const clone = el.cloneNode();
  1073. if (el._vtc) {
  1074. el._vtc.forEach(cls => {
  1075. cls.split(/\s+/).forEach(c => c && clone.classList.remove(c));
  1076. });
  1077. }
  1078. moveClass.split(/\s+/).forEach(c => c && clone.classList.add(c));
  1079. clone.style.display = 'none';
  1080. const container = (root.nodeType === 1 ? root : root.parentNode);
  1081. container.appendChild(clone);
  1082. const { hasTransform } = getTransitionInfo(clone);
  1083. container.removeChild(clone);
  1084. return hasTransform;
  1085. }
  1086. const getModelAssigner = (vnode) => {
  1087. const fn = vnode.props['onUpdate:modelValue'];
  1088. return shared.isArray(fn) ? value => shared.invokeArrayFns(fn, value) : fn;
  1089. };
  1090. function onCompositionStart(e) {
  1091. e.target.composing = true;
  1092. }
  1093. function onCompositionEnd(e) {
  1094. const target = e.target;
  1095. if (target.composing) {
  1096. target.composing = false;
  1097. trigger(target, 'input');
  1098. }
  1099. }
  1100. function trigger(el, type) {
  1101. const e = document.createEvent('HTMLEvents');
  1102. e.initEvent(type, true, true);
  1103. el.dispatchEvent(e);
  1104. }
  1105. // We are exporting the v-model runtime directly as vnode hooks so that it can
  1106. // be tree-shaken in case v-model is never used.
  1107. const vModelText = {
  1108. created(el, { modifiers: { lazy, trim, number } }, vnode) {
  1109. el._assign = getModelAssigner(vnode);
  1110. const castToNumber = number || (vnode.props && vnode.props.type === 'number');
  1111. addEventListener(el, lazy ? 'change' : 'input', e => {
  1112. if (e.target.composing)
  1113. return;
  1114. let domValue = el.value;
  1115. if (trim) {
  1116. domValue = domValue.trim();
  1117. }
  1118. else if (castToNumber) {
  1119. domValue = shared.toNumber(domValue);
  1120. }
  1121. el._assign(domValue);
  1122. });
  1123. if (trim) {
  1124. addEventListener(el, 'change', () => {
  1125. el.value = el.value.trim();
  1126. });
  1127. }
  1128. if (!lazy) {
  1129. addEventListener(el, 'compositionstart', onCompositionStart);
  1130. addEventListener(el, 'compositionend', onCompositionEnd);
  1131. // Safari < 10.2 & UIWebView doesn't fire compositionend when
  1132. // switching focus before confirming composition choice
  1133. // this also fixes the issue where some browsers e.g. iOS Chrome
  1134. // fires "change" instead of "input" on autocomplete.
  1135. addEventListener(el, 'change', onCompositionEnd);
  1136. }
  1137. },
  1138. // set value on mounted so it's after min/max for type="range"
  1139. mounted(el, { value }) {
  1140. el.value = value == null ? '' : value;
  1141. },
  1142. beforeUpdate(el, { value, modifiers: { lazy, trim, number } }, vnode) {
  1143. el._assign = getModelAssigner(vnode);
  1144. // avoid clearing unresolved text. #2302
  1145. if (el.composing)
  1146. return;
  1147. if (document.activeElement === el) {
  1148. if (lazy) {
  1149. return;
  1150. }
  1151. if (trim && el.value.trim() === value) {
  1152. return;
  1153. }
  1154. if ((number || el.type === 'number') && shared.toNumber(el.value) === value) {
  1155. return;
  1156. }
  1157. }
  1158. const newValue = value == null ? '' : value;
  1159. if (el.value !== newValue) {
  1160. el.value = newValue;
  1161. }
  1162. }
  1163. };
  1164. const vModelCheckbox = {
  1165. // #4096 array checkboxes need to be deep traversed
  1166. deep: true,
  1167. created(el, _, vnode) {
  1168. el._assign = getModelAssigner(vnode);
  1169. addEventListener(el, 'change', () => {
  1170. const modelValue = el._modelValue;
  1171. const elementValue = getValue(el);
  1172. const checked = el.checked;
  1173. const assign = el._assign;
  1174. if (shared.isArray(modelValue)) {
  1175. const index = shared.looseIndexOf(modelValue, elementValue);
  1176. const found = index !== -1;
  1177. if (checked && !found) {
  1178. assign(modelValue.concat(elementValue));
  1179. }
  1180. else if (!checked && found) {
  1181. const filtered = [...modelValue];
  1182. filtered.splice(index, 1);
  1183. assign(filtered);
  1184. }
  1185. }
  1186. else if (shared.isSet(modelValue)) {
  1187. const cloned = new Set(modelValue);
  1188. if (checked) {
  1189. cloned.add(elementValue);
  1190. }
  1191. else {
  1192. cloned.delete(elementValue);
  1193. }
  1194. assign(cloned);
  1195. }
  1196. else {
  1197. assign(getCheckboxValue(el, checked));
  1198. }
  1199. });
  1200. },
  1201. // set initial checked on mount to wait for true-value/false-value
  1202. mounted: setChecked,
  1203. beforeUpdate(el, binding, vnode) {
  1204. el._assign = getModelAssigner(vnode);
  1205. setChecked(el, binding, vnode);
  1206. }
  1207. };
  1208. function setChecked(el, { value, oldValue }, vnode) {
  1209. el._modelValue = value;
  1210. if (shared.isArray(value)) {
  1211. el.checked = shared.looseIndexOf(value, vnode.props.value) > -1;
  1212. }
  1213. else if (shared.isSet(value)) {
  1214. el.checked = value.has(vnode.props.value);
  1215. }
  1216. else if (value !== oldValue) {
  1217. el.checked = shared.looseEqual(value, getCheckboxValue(el, true));
  1218. }
  1219. }
  1220. const vModelRadio = {
  1221. created(el, { value }, vnode) {
  1222. el.checked = shared.looseEqual(value, vnode.props.value);
  1223. el._assign = getModelAssigner(vnode);
  1224. addEventListener(el, 'change', () => {
  1225. el._assign(getValue(el));
  1226. });
  1227. },
  1228. beforeUpdate(el, { value, oldValue }, vnode) {
  1229. el._assign = getModelAssigner(vnode);
  1230. if (value !== oldValue) {
  1231. el.checked = shared.looseEqual(value, vnode.props.value);
  1232. }
  1233. }
  1234. };
  1235. const vModelSelect = {
  1236. // <select multiple> value need to be deep traversed
  1237. deep: true,
  1238. created(el, { value, modifiers: { number } }, vnode) {
  1239. const isSetModel = shared.isSet(value);
  1240. addEventListener(el, 'change', () => {
  1241. const selectedVal = Array.prototype.filter
  1242. .call(el.options, (o) => o.selected)
  1243. .map((o) => number ? shared.toNumber(getValue(o)) : getValue(o));
  1244. el._assign(el.multiple
  1245. ? isSetModel
  1246. ? new Set(selectedVal)
  1247. : selectedVal
  1248. : selectedVal[0]);
  1249. });
  1250. el._assign = getModelAssigner(vnode);
  1251. },
  1252. // set value in mounted & updated because <select> relies on its children
  1253. // <option>s.
  1254. mounted(el, { value }) {
  1255. setSelected(el, value);
  1256. },
  1257. beforeUpdate(el, _binding, vnode) {
  1258. el._assign = getModelAssigner(vnode);
  1259. },
  1260. updated(el, { value }) {
  1261. setSelected(el, value);
  1262. }
  1263. };
  1264. function setSelected(el, value) {
  1265. const isMultiple = el.multiple;
  1266. if (isMultiple && !shared.isArray(value) && !shared.isSet(value)) {
  1267. runtimeCore.warn(`<select multiple v-model> expects an Array or Set value for its binding, ` +
  1268. `but got ${Object.prototype.toString.call(value).slice(8, -1)}.`);
  1269. return;
  1270. }
  1271. for (let i = 0, l = el.options.length; i < l; i++) {
  1272. const option = el.options[i];
  1273. const optionValue = getValue(option);
  1274. if (isMultiple) {
  1275. if (shared.isArray(value)) {
  1276. option.selected = shared.looseIndexOf(value, optionValue) > -1;
  1277. }
  1278. else {
  1279. option.selected = value.has(optionValue);
  1280. }
  1281. }
  1282. else {
  1283. if (shared.looseEqual(getValue(option), value)) {
  1284. if (el.selectedIndex !== i)
  1285. el.selectedIndex = i;
  1286. return;
  1287. }
  1288. }
  1289. }
  1290. if (!isMultiple && el.selectedIndex !== -1) {
  1291. el.selectedIndex = -1;
  1292. }
  1293. }
  1294. // retrieve raw value set via :value bindings
  1295. function getValue(el) {
  1296. return '_value' in el ? el._value : el.value;
  1297. }
  1298. // retrieve raw value for true-value and false-value set via :true-value or :false-value bindings
  1299. function getCheckboxValue(el, checked) {
  1300. const key = checked ? '_trueValue' : '_falseValue';
  1301. return key in el ? el[key] : checked;
  1302. }
  1303. const vModelDynamic = {
  1304. created(el, binding, vnode) {
  1305. callModelHook(el, binding, vnode, null, 'created');
  1306. },
  1307. mounted(el, binding, vnode) {
  1308. callModelHook(el, binding, vnode, null, 'mounted');
  1309. },
  1310. beforeUpdate(el, binding, vnode, prevVNode) {
  1311. callModelHook(el, binding, vnode, prevVNode, 'beforeUpdate');
  1312. },
  1313. updated(el, binding, vnode, prevVNode) {
  1314. callModelHook(el, binding, vnode, prevVNode, 'updated');
  1315. }
  1316. };
  1317. function callModelHook(el, binding, vnode, prevVNode, hook) {
  1318. let modelToUse;
  1319. switch (el.tagName) {
  1320. case 'SELECT':
  1321. modelToUse = vModelSelect;
  1322. break;
  1323. case 'TEXTAREA':
  1324. modelToUse = vModelText;
  1325. break;
  1326. default:
  1327. switch (vnode.props && vnode.props.type) {
  1328. case 'checkbox':
  1329. modelToUse = vModelCheckbox;
  1330. break;
  1331. case 'radio':
  1332. modelToUse = vModelRadio;
  1333. break;
  1334. default:
  1335. modelToUse = vModelText;
  1336. }
  1337. }
  1338. const fn = modelToUse[hook];
  1339. fn && fn(el, binding, vnode, prevVNode);
  1340. }
  1341. // SSR vnode transforms, only used when user includes client-oriented render
  1342. // function in SSR
  1343. function initVModelForSSR() {
  1344. vModelText.getSSRProps = ({ value }) => ({ value });
  1345. vModelRadio.getSSRProps = ({ value }, vnode) => {
  1346. if (vnode.props && shared.looseEqual(vnode.props.value, value)) {
  1347. return { checked: true };
  1348. }
  1349. };
  1350. vModelCheckbox.getSSRProps = ({ value }, vnode) => {
  1351. if (shared.isArray(value)) {
  1352. if (vnode.props && shared.looseIndexOf(value, vnode.props.value) > -1) {
  1353. return { checked: true };
  1354. }
  1355. }
  1356. else if (shared.isSet(value)) {
  1357. if (vnode.props && value.has(vnode.props.value)) {
  1358. return { checked: true };
  1359. }
  1360. }
  1361. else if (value) {
  1362. return { checked: true };
  1363. }
  1364. };
  1365. }
  1366. const systemModifiers = ['ctrl', 'shift', 'alt', 'meta'];
  1367. const modifierGuards = {
  1368. stop: e => e.stopPropagation(),
  1369. prevent: e => e.preventDefault(),
  1370. self: e => e.target !== e.currentTarget,
  1371. ctrl: e => !e.ctrlKey,
  1372. shift: e => !e.shiftKey,
  1373. alt: e => !e.altKey,
  1374. meta: e => !e.metaKey,
  1375. left: e => 'button' in e && e.button !== 0,
  1376. middle: e => 'button' in e && e.button !== 1,
  1377. right: e => 'button' in e && e.button !== 2,
  1378. exact: (e, modifiers) => systemModifiers.some(m => e[`${m}Key`] && !modifiers.includes(m))
  1379. };
  1380. /**
  1381. * @private
  1382. */
  1383. const withModifiers = (fn, modifiers) => {
  1384. return (event, ...args) => {
  1385. for (let i = 0; i < modifiers.length; i++) {
  1386. const guard = modifierGuards[modifiers[i]];
  1387. if (guard && guard(event, modifiers))
  1388. return;
  1389. }
  1390. return fn(event, ...args);
  1391. };
  1392. };
  1393. // Kept for 2.x compat.
  1394. // Note: IE11 compat for `spacebar` and `del` is removed for now.
  1395. const keyNames = {
  1396. esc: 'escape',
  1397. space: ' ',
  1398. up: 'arrow-up',
  1399. left: 'arrow-left',
  1400. right: 'arrow-right',
  1401. down: 'arrow-down',
  1402. delete: 'backspace'
  1403. };
  1404. /**
  1405. * @private
  1406. */
  1407. const withKeys = (fn, modifiers) => {
  1408. return (event) => {
  1409. if (!('key' in event)) {
  1410. return;
  1411. }
  1412. const eventKey = shared.hyphenate(event.key);
  1413. if (modifiers.some(k => k === eventKey || keyNames[k] === eventKey)) {
  1414. return fn(event);
  1415. }
  1416. };
  1417. };
  1418. const vShow = {
  1419. beforeMount(el, { value }, { transition }) {
  1420. el._vod = el.style.display === 'none' ? '' : el.style.display;
  1421. if (transition && value) {
  1422. transition.beforeEnter(el);
  1423. }
  1424. else {
  1425. setDisplay(el, value);
  1426. }
  1427. },
  1428. mounted(el, { value }, { transition }) {
  1429. if (transition && value) {
  1430. transition.enter(el);
  1431. }
  1432. },
  1433. updated(el, { value, oldValue }, { transition }) {
  1434. if (!value === !oldValue)
  1435. return;
  1436. if (transition) {
  1437. if (value) {
  1438. transition.beforeEnter(el);
  1439. setDisplay(el, true);
  1440. transition.enter(el);
  1441. }
  1442. else {
  1443. transition.leave(el, () => {
  1444. setDisplay(el, false);
  1445. });
  1446. }
  1447. }
  1448. else {
  1449. setDisplay(el, value);
  1450. }
  1451. },
  1452. beforeUnmount(el, { value }) {
  1453. setDisplay(el, value);
  1454. }
  1455. };
  1456. function setDisplay(el, value) {
  1457. el.style.display = value ? el._vod : 'none';
  1458. }
  1459. // SSR vnode transforms, only used when user includes client-oriented render
  1460. // function in SSR
  1461. function initVShowForSSR() {
  1462. vShow.getSSRProps = ({ value }) => {
  1463. if (!value) {
  1464. return { style: { display: 'none' } };
  1465. }
  1466. };
  1467. }
  1468. const rendererOptions = shared.extend({ patchProp }, nodeOps);
  1469. // lazy create the renderer - this makes core renderer logic tree-shakable
  1470. // in case the user only imports reactivity utilities from Vue.
  1471. let renderer;
  1472. let enabledHydration = false;
  1473. function ensureRenderer() {
  1474. return (renderer ||
  1475. (renderer = runtimeCore.createRenderer(rendererOptions)));
  1476. }
  1477. function ensureHydrationRenderer() {
  1478. renderer = enabledHydration
  1479. ? renderer
  1480. : runtimeCore.createHydrationRenderer(rendererOptions);
  1481. enabledHydration = true;
  1482. return renderer;
  1483. }
  1484. // use explicit type casts here to avoid import() calls in rolled-up d.ts
  1485. const render = ((...args) => {
  1486. ensureRenderer().render(...args);
  1487. });
  1488. const hydrate = ((...args) => {
  1489. ensureHydrationRenderer().hydrate(...args);
  1490. });
  1491. const createApp = ((...args) => {
  1492. const app = ensureRenderer().createApp(...args);
  1493. {
  1494. injectNativeTagCheck(app);
  1495. injectCompilerOptionsCheck(app);
  1496. }
  1497. const { mount } = app;
  1498. app.mount = (containerOrSelector) => {
  1499. const container = normalizeContainer(containerOrSelector);
  1500. if (!container)
  1501. return;
  1502. const component = app._component;
  1503. if (!shared.isFunction(component) && !component.render && !component.template) {
  1504. // __UNSAFE__
  1505. // Reason: potential execution of JS expressions in in-DOM template.
  1506. // The user must make sure the in-DOM template is trusted. If it's
  1507. // rendered by the server, the template should not contain any user data.
  1508. component.template = container.innerHTML;
  1509. }
  1510. // clear content before mounting
  1511. container.innerHTML = '';
  1512. const proxy = mount(container, false, container instanceof SVGElement);
  1513. if (container instanceof Element) {
  1514. container.removeAttribute('v-cloak');
  1515. container.setAttribute('data-v-app', '');
  1516. }
  1517. return proxy;
  1518. };
  1519. return app;
  1520. });
  1521. const createSSRApp = ((...args) => {
  1522. const app = ensureHydrationRenderer().createApp(...args);
  1523. {
  1524. injectNativeTagCheck(app);
  1525. injectCompilerOptionsCheck(app);
  1526. }
  1527. const { mount } = app;
  1528. app.mount = (containerOrSelector) => {
  1529. const container = normalizeContainer(containerOrSelector);
  1530. if (container) {
  1531. return mount(container, true, container instanceof SVGElement);
  1532. }
  1533. };
  1534. return app;
  1535. });
  1536. function injectNativeTagCheck(app) {
  1537. // Inject `isNativeTag`
  1538. // this is used for component name validation (dev only)
  1539. Object.defineProperty(app.config, 'isNativeTag', {
  1540. value: (tag) => shared.isHTMLTag(tag) || shared.isSVGTag(tag),
  1541. writable: false
  1542. });
  1543. }
  1544. // dev only
  1545. function injectCompilerOptionsCheck(app) {
  1546. if (runtimeCore.isRuntimeOnly()) {
  1547. const isCustomElement = app.config.isCustomElement;
  1548. Object.defineProperty(app.config, 'isCustomElement', {
  1549. get() {
  1550. return isCustomElement;
  1551. },
  1552. set() {
  1553. runtimeCore.warn(`The \`isCustomElement\` config option is deprecated. Use ` +
  1554. `\`compilerOptions.isCustomElement\` instead.`);
  1555. }
  1556. });
  1557. const compilerOptions = app.config.compilerOptions;
  1558. const msg = `The \`compilerOptions\` config option is only respected when using ` +
  1559. `a build of Vue.js that includes the runtime compiler (aka "full build"). ` +
  1560. `Since you are using the runtime-only build, \`compilerOptions\` ` +
  1561. `must be passed to \`@vue/compiler-dom\` in the build setup instead.\n` +
  1562. `- For vue-loader: pass it via vue-loader's \`compilerOptions\` loader option.\n` +
  1563. `- For vue-cli: see https://cli.vuejs.org/guide/webpack.html#modifying-options-of-a-loader\n` +
  1564. `- For vite: pass it via @vitejs/plugin-vue options. See https://github.com/vitejs/vite/tree/main/packages/plugin-vue#example-for-passing-options-to-vuecompiler-dom`;
  1565. Object.defineProperty(app.config, 'compilerOptions', {
  1566. get() {
  1567. runtimeCore.warn(msg);
  1568. return compilerOptions;
  1569. },
  1570. set() {
  1571. runtimeCore.warn(msg);
  1572. }
  1573. });
  1574. }
  1575. }
  1576. function normalizeContainer(container) {
  1577. if (shared.isString(container)) {
  1578. const res = document.querySelector(container);
  1579. if (!res) {
  1580. runtimeCore.warn(`Failed to mount app: mount target selector "${container}" returned null.`);
  1581. }
  1582. return res;
  1583. }
  1584. if (window.ShadowRoot &&
  1585. container instanceof window.ShadowRoot &&
  1586. container.mode === 'closed') {
  1587. runtimeCore.warn(`mounting on a ShadowRoot with \`{mode: "closed"}\` may lead to unpredictable bugs`);
  1588. }
  1589. return container;
  1590. }
  1591. let ssrDirectiveInitialized = false;
  1592. /**
  1593. * @internal
  1594. */
  1595. const initDirectivesForSSR = () => {
  1596. if (!ssrDirectiveInitialized) {
  1597. ssrDirectiveInitialized = true;
  1598. initVModelForSSR();
  1599. initVShowForSSR();
  1600. }
  1601. }
  1602. ;
  1603. Object.keys(runtimeCore).forEach(function (k) {
  1604. if (k !== 'default') exports[k] = runtimeCore[k];
  1605. });
  1606. exports.Transition = Transition;
  1607. exports.TransitionGroup = TransitionGroup;
  1608. exports.VueElement = VueElement;
  1609. exports.createApp = createApp;
  1610. exports.createSSRApp = createSSRApp;
  1611. exports.defineCustomElement = defineCustomElement;
  1612. exports.defineSSRCustomElement = defineSSRCustomElement;
  1613. exports.hydrate = hydrate;
  1614. exports.initDirectivesForSSR = initDirectivesForSSR;
  1615. exports.render = render;
  1616. exports.useCssModule = useCssModule;
  1617. exports.useCssVars = useCssVars;
  1618. exports.vModelCheckbox = vModelCheckbox;
  1619. exports.vModelDynamic = vModelDynamic;
  1620. exports.vModelRadio = vModelRadio;
  1621. exports.vModelSelect = vModelSelect;
  1622. exports.vModelText = vModelText;
  1623. exports.vShow = vShow;
  1624. exports.withKeys = withKeys;
  1625. exports.withModifiers = withModifiers;