runtime-dom.cjs.prod.js 53 KB

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