runtime-dom.cjs.prod.js 53 KB

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