shared.esm-bundler.js 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587
  1. /**
  2. * Make a map and return a function for checking if a key
  3. * is in that map.
  4. * IMPORTANT: all calls of this function must be prefixed with
  5. * \/\*#\_\_PURE\_\_\*\/
  6. * So that rollup can tree-shake them if necessary.
  7. */
  8. function makeMap(str, expectsLowerCase) {
  9. const map = Object.create(null);
  10. const list = str.split(',');
  11. for (let i = 0; i < list.length; i++) {
  12. map[list[i]] = true;
  13. }
  14. return expectsLowerCase ? val => !!map[val.toLowerCase()] : val => !!map[val];
  15. }
  16. /**
  17. * dev only flag -> name mapping
  18. */
  19. const PatchFlagNames = {
  20. [1 /* PatchFlags.TEXT */]: `TEXT`,
  21. [2 /* PatchFlags.CLASS */]: `CLASS`,
  22. [4 /* PatchFlags.STYLE */]: `STYLE`,
  23. [8 /* PatchFlags.PROPS */]: `PROPS`,
  24. [16 /* PatchFlags.FULL_PROPS */]: `FULL_PROPS`,
  25. [32 /* PatchFlags.HYDRATE_EVENTS */]: `HYDRATE_EVENTS`,
  26. [64 /* PatchFlags.STABLE_FRAGMENT */]: `STABLE_FRAGMENT`,
  27. [128 /* PatchFlags.KEYED_FRAGMENT */]: `KEYED_FRAGMENT`,
  28. [256 /* PatchFlags.UNKEYED_FRAGMENT */]: `UNKEYED_FRAGMENT`,
  29. [512 /* PatchFlags.NEED_PATCH */]: `NEED_PATCH`,
  30. [1024 /* PatchFlags.DYNAMIC_SLOTS */]: `DYNAMIC_SLOTS`,
  31. [2048 /* PatchFlags.DEV_ROOT_FRAGMENT */]: `DEV_ROOT_FRAGMENT`,
  32. [-1 /* PatchFlags.HOISTED */]: `HOISTED`,
  33. [-2 /* PatchFlags.BAIL */]: `BAIL`
  34. };
  35. /**
  36. * Dev only
  37. */
  38. const slotFlagsText = {
  39. [1 /* SlotFlags.STABLE */]: 'STABLE',
  40. [2 /* SlotFlags.DYNAMIC */]: 'DYNAMIC',
  41. [3 /* SlotFlags.FORWARDED */]: 'FORWARDED'
  42. };
  43. const GLOBALS_WHITE_LISTED = 'Infinity,undefined,NaN,isFinite,isNaN,parseFloat,parseInt,decodeURI,' +
  44. 'decodeURIComponent,encodeURI,encodeURIComponent,Math,Number,Date,Array,' +
  45. 'Object,Boolean,String,RegExp,Map,Set,JSON,Intl,BigInt';
  46. const isGloballyWhitelisted = /*#__PURE__*/ makeMap(GLOBALS_WHITE_LISTED);
  47. const range = 2;
  48. function generateCodeFrame(source, start = 0, end = source.length) {
  49. // Split the content into individual lines but capture the newline sequence
  50. // that separated each line. This is important because the actual sequence is
  51. // needed to properly take into account the full line length for offset
  52. // comparison
  53. let lines = source.split(/(\r?\n)/);
  54. // Separate the lines and newline sequences into separate arrays for easier referencing
  55. const newlineSequences = lines.filter((_, idx) => idx % 2 === 1);
  56. lines = lines.filter((_, idx) => idx % 2 === 0);
  57. let count = 0;
  58. const res = [];
  59. for (let i = 0; i < lines.length; i++) {
  60. count +=
  61. lines[i].length +
  62. ((newlineSequences[i] && newlineSequences[i].length) || 0);
  63. if (count >= start) {
  64. for (let j = i - range; j <= i + range || end > count; j++) {
  65. if (j < 0 || j >= lines.length)
  66. continue;
  67. const line = j + 1;
  68. res.push(`${line}${' '.repeat(Math.max(3 - String(line).length, 0))}| ${lines[j]}`);
  69. const lineLength = lines[j].length;
  70. const newLineSeqLength = (newlineSequences[j] && newlineSequences[j].length) || 0;
  71. if (j === i) {
  72. // push underline
  73. const pad = start - (count - (lineLength + newLineSeqLength));
  74. const length = Math.max(1, end > count ? lineLength - pad : end - start);
  75. res.push(` | ` + ' '.repeat(pad) + '^'.repeat(length));
  76. }
  77. else if (j > i) {
  78. if (end > count) {
  79. const length = Math.max(Math.min(end - count, lineLength), 1);
  80. res.push(` | ` + '^'.repeat(length));
  81. }
  82. count += lineLength + newLineSeqLength;
  83. }
  84. }
  85. break;
  86. }
  87. }
  88. return res.join('\n');
  89. }
  90. function normalizeStyle(value) {
  91. if (isArray(value)) {
  92. const res = {};
  93. for (let i = 0; i < value.length; i++) {
  94. const item = value[i];
  95. const normalized = isString(item)
  96. ? parseStringStyle(item)
  97. : normalizeStyle(item);
  98. if (normalized) {
  99. for (const key in normalized) {
  100. res[key] = normalized[key];
  101. }
  102. }
  103. }
  104. return res;
  105. }
  106. else if (isString(value)) {
  107. return value;
  108. }
  109. else if (isObject(value)) {
  110. return value;
  111. }
  112. }
  113. const listDelimiterRE = /;(?![^(]*\))/g;
  114. const propertyDelimiterRE = /:([^]+)/;
  115. const styleCommentRE = /\/\*.*?\*\//gs;
  116. function parseStringStyle(cssText) {
  117. const ret = {};
  118. cssText
  119. .replace(styleCommentRE, '')
  120. .split(listDelimiterRE)
  121. .forEach(item => {
  122. if (item) {
  123. const tmp = item.split(propertyDelimiterRE);
  124. tmp.length > 1 && (ret[tmp[0].trim()] = tmp[1].trim());
  125. }
  126. });
  127. return ret;
  128. }
  129. function stringifyStyle(styles) {
  130. let ret = '';
  131. if (!styles || isString(styles)) {
  132. return ret;
  133. }
  134. for (const key in styles) {
  135. const value = styles[key];
  136. const normalizedKey = key.startsWith(`--`) ? key : hyphenate(key);
  137. if (isString(value) || typeof value === 'number') {
  138. // only render valid values
  139. ret += `${normalizedKey}:${value};`;
  140. }
  141. }
  142. return ret;
  143. }
  144. function normalizeClass(value) {
  145. let res = '';
  146. if (isString(value)) {
  147. res = value;
  148. }
  149. else if (isArray(value)) {
  150. for (let i = 0; i < value.length; i++) {
  151. const normalized = normalizeClass(value[i]);
  152. if (normalized) {
  153. res += normalized + ' ';
  154. }
  155. }
  156. }
  157. else if (isObject(value)) {
  158. for (const name in value) {
  159. if (value[name]) {
  160. res += name + ' ';
  161. }
  162. }
  163. }
  164. return res.trim();
  165. }
  166. function normalizeProps(props) {
  167. if (!props)
  168. return null;
  169. let { class: klass, style } = props;
  170. if (klass && !isString(klass)) {
  171. props.class = normalizeClass(klass);
  172. }
  173. if (style) {
  174. props.style = normalizeStyle(style);
  175. }
  176. return props;
  177. }
  178. // These tag configs are shared between compiler-dom and runtime-dom, so they
  179. // https://developer.mozilla.org/en-US/docs/Web/HTML/Element
  180. const HTML_TAGS = 'html,body,base,head,link,meta,style,title,address,article,aside,footer,' +
  181. 'header,h1,h2,h3,h4,h5,h6,nav,section,div,dd,dl,dt,figcaption,' +
  182. 'figure,picture,hr,img,li,main,ol,p,pre,ul,a,b,abbr,bdi,bdo,br,cite,code,' +
  183. 'data,dfn,em,i,kbd,mark,q,rp,rt,ruby,s,samp,small,span,strong,sub,sup,' +
  184. 'time,u,var,wbr,area,audio,map,track,video,embed,object,param,source,' +
  185. 'canvas,script,noscript,del,ins,caption,col,colgroup,table,thead,tbody,td,' +
  186. 'th,tr,button,datalist,fieldset,form,input,label,legend,meter,optgroup,' +
  187. 'option,output,progress,select,textarea,details,dialog,menu,' +
  188. 'summary,template,blockquote,iframe,tfoot';
  189. // https://developer.mozilla.org/en-US/docs/Web/SVG/Element
  190. const SVG_TAGS = 'svg,animate,animateMotion,animateTransform,circle,clipPath,color-profile,' +
  191. 'defs,desc,discard,ellipse,feBlend,feColorMatrix,feComponentTransfer,' +
  192. 'feComposite,feConvolveMatrix,feDiffuseLighting,feDisplacementMap,' +
  193. 'feDistanceLight,feDropShadow,feFlood,feFuncA,feFuncB,feFuncG,feFuncR,' +
  194. 'feGaussianBlur,feImage,feMerge,feMergeNode,feMorphology,feOffset,' +
  195. 'fePointLight,feSpecularLighting,feSpotLight,feTile,feTurbulence,filter,' +
  196. 'foreignObject,g,hatch,hatchpath,image,line,linearGradient,marker,mask,' +
  197. 'mesh,meshgradient,meshpatch,meshrow,metadata,mpath,path,pattern,' +
  198. 'polygon,polyline,radialGradient,rect,set,solidcolor,stop,switch,symbol,' +
  199. 'text,textPath,title,tspan,unknown,use,view';
  200. const VOID_TAGS = 'area,base,br,col,embed,hr,img,input,link,meta,param,source,track,wbr';
  201. /**
  202. * Compiler only.
  203. * Do NOT use in runtime code paths unless behind `(process.env.NODE_ENV !== 'production')` flag.
  204. */
  205. const isHTMLTag = /*#__PURE__*/ makeMap(HTML_TAGS);
  206. /**
  207. * Compiler only.
  208. * Do NOT use in runtime code paths unless behind `(process.env.NODE_ENV !== 'production')` flag.
  209. */
  210. const isSVGTag = /*#__PURE__*/ makeMap(SVG_TAGS);
  211. /**
  212. * Compiler only.
  213. * Do NOT use in runtime code paths unless behind `(process.env.NODE_ENV !== 'production')` flag.
  214. */
  215. const isVoidTag = /*#__PURE__*/ makeMap(VOID_TAGS);
  216. /**
  217. * On the client we only need to offer special cases for boolean attributes that
  218. * have different names from their corresponding dom properties:
  219. * - itemscope -> N/A
  220. * - allowfullscreen -> allowFullscreen
  221. * - formnovalidate -> formNoValidate
  222. * - ismap -> isMap
  223. * - nomodule -> noModule
  224. * - novalidate -> noValidate
  225. * - readonly -> readOnly
  226. */
  227. const specialBooleanAttrs = `itemscope,allowfullscreen,formnovalidate,ismap,nomodule,novalidate,readonly`;
  228. const isSpecialBooleanAttr = /*#__PURE__*/ makeMap(specialBooleanAttrs);
  229. /**
  230. * The full list is needed during SSR to produce the correct initial markup.
  231. */
  232. const isBooleanAttr = /*#__PURE__*/ makeMap(specialBooleanAttrs +
  233. `,async,autofocus,autoplay,controls,default,defer,disabled,hidden,` +
  234. `loop,open,required,reversed,scoped,seamless,` +
  235. `checked,muted,multiple,selected`);
  236. /**
  237. * Boolean attributes should be included if the value is truthy or ''.
  238. * e.g. `<select multiple>` compiles to `{ multiple: '' }`
  239. */
  240. function includeBooleanAttr(value) {
  241. return !!value || value === '';
  242. }
  243. const unsafeAttrCharRE = /[>/="'\u0009\u000a\u000c\u0020]/;
  244. const attrValidationCache = {};
  245. function isSSRSafeAttrName(name) {
  246. if (attrValidationCache.hasOwnProperty(name)) {
  247. return attrValidationCache[name];
  248. }
  249. const isUnsafe = unsafeAttrCharRE.test(name);
  250. if (isUnsafe) {
  251. console.error(`unsafe attribute name: ${name}`);
  252. }
  253. return (attrValidationCache[name] = !isUnsafe);
  254. }
  255. const propsToAttrMap = {
  256. acceptCharset: 'accept-charset',
  257. className: 'class',
  258. htmlFor: 'for',
  259. httpEquiv: 'http-equiv'
  260. };
  261. /**
  262. * Known attributes, this is used for stringification of runtime static nodes
  263. * so that we don't stringify bindings that cannot be set from HTML.
  264. * Don't also forget to allow `data-*` and `aria-*`!
  265. * Generated from https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes
  266. */
  267. const isKnownHtmlAttr = /*#__PURE__*/ makeMap(`accept,accept-charset,accesskey,action,align,allow,alt,async,` +
  268. `autocapitalize,autocomplete,autofocus,autoplay,background,bgcolor,` +
  269. `border,buffered,capture,challenge,charset,checked,cite,class,code,` +
  270. `codebase,color,cols,colspan,content,contenteditable,contextmenu,controls,` +
  271. `coords,crossorigin,csp,data,datetime,decoding,default,defer,dir,dirname,` +
  272. `disabled,download,draggable,dropzone,enctype,enterkeyhint,for,form,` +
  273. `formaction,formenctype,formmethod,formnovalidate,formtarget,headers,` +
  274. `height,hidden,high,href,hreflang,http-equiv,icon,id,importance,integrity,` +
  275. `ismap,itemprop,keytype,kind,label,lang,language,loading,list,loop,low,` +
  276. `manifest,max,maxlength,minlength,media,min,multiple,muted,name,novalidate,` +
  277. `open,optimum,pattern,ping,placeholder,poster,preload,radiogroup,readonly,` +
  278. `referrerpolicy,rel,required,reversed,rows,rowspan,sandbox,scope,scoped,` +
  279. `selected,shape,size,sizes,slot,span,spellcheck,src,srcdoc,srclang,srcset,` +
  280. `start,step,style,summary,tabindex,target,title,translate,type,usemap,` +
  281. `value,width,wrap`);
  282. /**
  283. * Generated from https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute
  284. */
  285. const isKnownSvgAttr = /*#__PURE__*/ makeMap(`xmlns,accent-height,accumulate,additive,alignment-baseline,alphabetic,amplitude,` +
  286. `arabic-form,ascent,attributeName,attributeType,azimuth,baseFrequency,` +
  287. `baseline-shift,baseProfile,bbox,begin,bias,by,calcMode,cap-height,class,` +
  288. `clip,clipPathUnits,clip-path,clip-rule,color,color-interpolation,` +
  289. `color-interpolation-filters,color-profile,color-rendering,` +
  290. `contentScriptType,contentStyleType,crossorigin,cursor,cx,cy,d,decelerate,` +
  291. `descent,diffuseConstant,direction,display,divisor,dominant-baseline,dur,dx,` +
  292. `dy,edgeMode,elevation,enable-background,end,exponent,fill,fill-opacity,` +
  293. `fill-rule,filter,filterRes,filterUnits,flood-color,flood-opacity,` +
  294. `font-family,font-size,font-size-adjust,font-stretch,font-style,` +
  295. `font-variant,font-weight,format,from,fr,fx,fy,g1,g2,glyph-name,` +
  296. `glyph-orientation-horizontal,glyph-orientation-vertical,glyphRef,` +
  297. `gradientTransform,gradientUnits,hanging,height,href,hreflang,horiz-adv-x,` +
  298. `horiz-origin-x,id,ideographic,image-rendering,in,in2,intercept,k,k1,k2,k3,` +
  299. `k4,kernelMatrix,kernelUnitLength,kerning,keyPoints,keySplines,keyTimes,` +
  300. `lang,lengthAdjust,letter-spacing,lighting-color,limitingConeAngle,local,` +
  301. `marker-end,marker-mid,marker-start,markerHeight,markerUnits,markerWidth,` +
  302. `mask,maskContentUnits,maskUnits,mathematical,max,media,method,min,mode,` +
  303. `name,numOctaves,offset,opacity,operator,order,orient,orientation,origin,` +
  304. `overflow,overline-position,overline-thickness,panose-1,paint-order,path,` +
  305. `pathLength,patternContentUnits,patternTransform,patternUnits,ping,` +
  306. `pointer-events,points,pointsAtX,pointsAtY,pointsAtZ,preserveAlpha,` +
  307. `preserveAspectRatio,primitiveUnits,r,radius,referrerPolicy,refX,refY,rel,` +
  308. `rendering-intent,repeatCount,repeatDur,requiredExtensions,requiredFeatures,` +
  309. `restart,result,rotate,rx,ry,scale,seed,shape-rendering,slope,spacing,` +
  310. `specularConstant,specularExponent,speed,spreadMethod,startOffset,` +
  311. `stdDeviation,stemh,stemv,stitchTiles,stop-color,stop-opacity,` +
  312. `strikethrough-position,strikethrough-thickness,string,stroke,` +
  313. `stroke-dasharray,stroke-dashoffset,stroke-linecap,stroke-linejoin,` +
  314. `stroke-miterlimit,stroke-opacity,stroke-width,style,surfaceScale,` +
  315. `systemLanguage,tabindex,tableValues,target,targetX,targetY,text-anchor,` +
  316. `text-decoration,text-rendering,textLength,to,transform,transform-origin,` +
  317. `type,u1,u2,underline-position,underline-thickness,unicode,unicode-bidi,` +
  318. `unicode-range,units-per-em,v-alphabetic,v-hanging,v-ideographic,` +
  319. `v-mathematical,values,vector-effect,version,vert-adv-y,vert-origin-x,` +
  320. `vert-origin-y,viewBox,viewTarget,visibility,width,widths,word-spacing,` +
  321. `writing-mode,x,x-height,x1,x2,xChannelSelector,xlink:actuate,xlink:arcrole,` +
  322. `xlink:href,xlink:role,xlink:show,xlink:title,xlink:type,xml:base,xml:lang,` +
  323. `xml:space,y,y1,y2,yChannelSelector,z,zoomAndPan`);
  324. const escapeRE = /["'&<>]/;
  325. function escapeHtml(string) {
  326. const str = '' + string;
  327. const match = escapeRE.exec(str);
  328. if (!match) {
  329. return str;
  330. }
  331. let html = '';
  332. let escaped;
  333. let index;
  334. let lastIndex = 0;
  335. for (index = match.index; index < str.length; index++) {
  336. switch (str.charCodeAt(index)) {
  337. case 34: // "
  338. escaped = '&quot;';
  339. break;
  340. case 38: // &
  341. escaped = '&amp;';
  342. break;
  343. case 39: // '
  344. escaped = '&#39;';
  345. break;
  346. case 60: // <
  347. escaped = '&lt;';
  348. break;
  349. case 62: // >
  350. escaped = '&gt;';
  351. break;
  352. default:
  353. continue;
  354. }
  355. if (lastIndex !== index) {
  356. html += str.slice(lastIndex, index);
  357. }
  358. lastIndex = index + 1;
  359. html += escaped;
  360. }
  361. return lastIndex !== index ? html + str.slice(lastIndex, index) : html;
  362. }
  363. // https://www.w3.org/TR/html52/syntax.html#comments
  364. const commentStripRE = /^-?>|<!--|-->|--!>|<!-$/g;
  365. function escapeHtmlComment(src) {
  366. return src.replace(commentStripRE, '');
  367. }
  368. function looseCompareArrays(a, b) {
  369. if (a.length !== b.length)
  370. return false;
  371. let equal = true;
  372. for (let i = 0; equal && i < a.length; i++) {
  373. equal = looseEqual(a[i], b[i]);
  374. }
  375. return equal;
  376. }
  377. function looseEqual(a, b) {
  378. if (a === b)
  379. return true;
  380. let aValidType = isDate(a);
  381. let bValidType = isDate(b);
  382. if (aValidType || bValidType) {
  383. return aValidType && bValidType ? a.getTime() === b.getTime() : false;
  384. }
  385. aValidType = isSymbol(a);
  386. bValidType = isSymbol(b);
  387. if (aValidType || bValidType) {
  388. return a === b;
  389. }
  390. aValidType = isArray(a);
  391. bValidType = isArray(b);
  392. if (aValidType || bValidType) {
  393. return aValidType && bValidType ? looseCompareArrays(a, b) : false;
  394. }
  395. aValidType = isObject(a);
  396. bValidType = isObject(b);
  397. if (aValidType || bValidType) {
  398. /* istanbul ignore if: this if will probably never be called */
  399. if (!aValidType || !bValidType) {
  400. return false;
  401. }
  402. const aKeysCount = Object.keys(a).length;
  403. const bKeysCount = Object.keys(b).length;
  404. if (aKeysCount !== bKeysCount) {
  405. return false;
  406. }
  407. for (const key in a) {
  408. const aHasKey = a.hasOwnProperty(key);
  409. const bHasKey = b.hasOwnProperty(key);
  410. if ((aHasKey && !bHasKey) ||
  411. (!aHasKey && bHasKey) ||
  412. !looseEqual(a[key], b[key])) {
  413. return false;
  414. }
  415. }
  416. }
  417. return String(a) === String(b);
  418. }
  419. function looseIndexOf(arr, val) {
  420. return arr.findIndex(item => looseEqual(item, val));
  421. }
  422. /**
  423. * For converting {{ interpolation }} values to displayed strings.
  424. * @private
  425. */
  426. const toDisplayString = (val) => {
  427. return isString(val)
  428. ? val
  429. : val == null
  430. ? ''
  431. : isArray(val) ||
  432. (isObject(val) &&
  433. (val.toString === objectToString || !isFunction(val.toString)))
  434. ? JSON.stringify(val, replacer, 2)
  435. : String(val);
  436. };
  437. const replacer = (_key, val) => {
  438. // can't use isRef here since @vue/shared has no deps
  439. if (val && val.__v_isRef) {
  440. return replacer(_key, val.value);
  441. }
  442. else if (isMap(val)) {
  443. return {
  444. [`Map(${val.size})`]: [...val.entries()].reduce((entries, [key, val]) => {
  445. entries[`${key} =>`] = val;
  446. return entries;
  447. }, {})
  448. };
  449. }
  450. else if (isSet(val)) {
  451. return {
  452. [`Set(${val.size})`]: [...val.values()]
  453. };
  454. }
  455. else if (isObject(val) && !isArray(val) && !isPlainObject(val)) {
  456. return String(val);
  457. }
  458. return val;
  459. };
  460. const EMPTY_OBJ = (process.env.NODE_ENV !== 'production')
  461. ? Object.freeze({})
  462. : {};
  463. const EMPTY_ARR = (process.env.NODE_ENV !== 'production') ? Object.freeze([]) : [];
  464. const NOOP = () => { };
  465. /**
  466. * Always return false.
  467. */
  468. const NO = () => false;
  469. const onRE = /^on[^a-z]/;
  470. const isOn = (key) => onRE.test(key);
  471. const isModelListener = (key) => key.startsWith('onUpdate:');
  472. const extend = Object.assign;
  473. const remove = (arr, el) => {
  474. const i = arr.indexOf(el);
  475. if (i > -1) {
  476. arr.splice(i, 1);
  477. }
  478. };
  479. const hasOwnProperty = Object.prototype.hasOwnProperty;
  480. const hasOwn = (val, key) => hasOwnProperty.call(val, key);
  481. const isArray = Array.isArray;
  482. const isMap = (val) => toTypeString(val) === '[object Map]';
  483. const isSet = (val) => toTypeString(val) === '[object Set]';
  484. const isDate = (val) => toTypeString(val) === '[object Date]';
  485. const isFunction = (val) => typeof val === 'function';
  486. const isString = (val) => typeof val === 'string';
  487. const isSymbol = (val) => typeof val === 'symbol';
  488. const isObject = (val) => val !== null && typeof val === 'object';
  489. const isPromise = (val) => {
  490. return isObject(val) && isFunction(val.then) && isFunction(val.catch);
  491. };
  492. const objectToString = Object.prototype.toString;
  493. const toTypeString = (value) => objectToString.call(value);
  494. const toRawType = (value) => {
  495. // extract "RawType" from strings like "[object RawType]"
  496. return toTypeString(value).slice(8, -1);
  497. };
  498. const isPlainObject = (val) => toTypeString(val) === '[object Object]';
  499. const isIntegerKey = (key) => isString(key) &&
  500. key !== 'NaN' &&
  501. key[0] !== '-' &&
  502. '' + parseInt(key, 10) === key;
  503. const isReservedProp = /*#__PURE__*/ makeMap(
  504. // the leading comma is intentional so empty string "" is also included
  505. ',key,ref,ref_for,ref_key,' +
  506. 'onVnodeBeforeMount,onVnodeMounted,' +
  507. 'onVnodeBeforeUpdate,onVnodeUpdated,' +
  508. 'onVnodeBeforeUnmount,onVnodeUnmounted');
  509. const isBuiltInDirective = /*#__PURE__*/ makeMap('bind,cloak,else-if,else,for,html,if,model,on,once,pre,show,slot,text,memo');
  510. const cacheStringFunction = (fn) => {
  511. const cache = Object.create(null);
  512. return ((str) => {
  513. const hit = cache[str];
  514. return hit || (cache[str] = fn(str));
  515. });
  516. };
  517. const camelizeRE = /-(\w)/g;
  518. /**
  519. * @private
  520. */
  521. const camelize = cacheStringFunction((str) => {
  522. return str.replace(camelizeRE, (_, c) => (c ? c.toUpperCase() : ''));
  523. });
  524. const hyphenateRE = /\B([A-Z])/g;
  525. /**
  526. * @private
  527. */
  528. const hyphenate = cacheStringFunction((str) => str.replace(hyphenateRE, '-$1').toLowerCase());
  529. /**
  530. * @private
  531. */
  532. const capitalize = cacheStringFunction((str) => str.charAt(0).toUpperCase() + str.slice(1));
  533. /**
  534. * @private
  535. */
  536. const toHandlerKey = cacheStringFunction((str) => str ? `on${capitalize(str)}` : ``);
  537. // compare whether a value has changed, accounting for NaN.
  538. const hasChanged = (value, oldValue) => !Object.is(value, oldValue);
  539. const invokeArrayFns = (fns, arg) => {
  540. for (let i = 0; i < fns.length; i++) {
  541. fns[i](arg);
  542. }
  543. };
  544. const def = (obj, key, value) => {
  545. Object.defineProperty(obj, key, {
  546. configurable: true,
  547. enumerable: false,
  548. value
  549. });
  550. };
  551. const toNumber = (val) => {
  552. const n = parseFloat(val);
  553. return isNaN(n) ? val : n;
  554. };
  555. let _globalThis;
  556. const getGlobalThis = () => {
  557. return (_globalThis ||
  558. (_globalThis =
  559. typeof globalThis !== 'undefined'
  560. ? globalThis
  561. : typeof self !== 'undefined'
  562. ? self
  563. : typeof window !== 'undefined'
  564. ? window
  565. : typeof global !== 'undefined'
  566. ? global
  567. : {}));
  568. };
  569. const identRE = /^[_$a-zA-Z\xA0-\uFFFF][_$a-zA-Z0-9\xA0-\uFFFF]*$/;
  570. function genPropsAccessExp(name) {
  571. return identRE.test(name)
  572. ? `__props.${name}`
  573. : `__props[${JSON.stringify(name)}]`;
  574. }
  575. export { EMPTY_ARR, EMPTY_OBJ, NO, NOOP, PatchFlagNames, camelize, capitalize, def, escapeHtml, escapeHtmlComment, extend, genPropsAccessExp, generateCodeFrame, getGlobalThis, hasChanged, hasOwn, hyphenate, includeBooleanAttr, invokeArrayFns, isArray, isBooleanAttr, isBuiltInDirective, isDate, isFunction, isGloballyWhitelisted, isHTMLTag, isIntegerKey, isKnownHtmlAttr, isKnownSvgAttr, isMap, isModelListener, isObject, isOn, isPlainObject, isPromise, isReservedProp, isSSRSafeAttrName, isSVGTag, isSet, isSpecialBooleanAttr, isString, isSymbol, isVoidTag, looseEqual, looseIndexOf, makeMap, normalizeClass, normalizeProps, normalizeStyle, objectToString, parseStringStyle, propsToAttrMap, remove, slotFlagsText, stringifyStyle, toDisplayString, toHandlerKey, toNumber, toRawType, toTypeString };