shared.cjs.js 24 KB

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