JavaScript 代码片段:_export_sfc、makeMap、normalizeStyle 等函数
javascript/n'use strict';/nconst _export_sfc = (sfc, props) => {/n const target = sfc.__vccOpts || sfc;/n for (const [key, val] of props) {/n target[key] = val;/n }/n return target;/n};/nfunction makeMap(str, expectsLowerCase) {/n const map = /* @__PURE__ */ Object.create(null);/n const list = str.split(',');/n for (let i = 0; i < list.length; i++) {/n map[list[i]] = true;/n }/n return expectsLowerCase ? (val) => !!map[val.toLowerCase()] : (val) => !!map[val];/n}/nfunction normalizeStyle(value) {/n if (isArray(value)) {/n const res = {};/n for (let i = 0; i < value.length; i++) {/n const item = value[i];/n const normalized = isString(item) ? parseStringStyle(item) : normalizeStyle(item);/n if (normalized) {/n for (const key in normalized) {/n res[key] = normalized[key];/n }/n }/n }/n return res;/n } else if (isString(value)) {/n return value;/n } else if (isObject(value)) {/n return value;/n }/n}/nconst listDelimiterRE = /;(?![^(]*/))/g;/nconst propertyDelimiterRE = /:([^]+)/;/nconst styleCommentRE = ////*.*?/*///gs;/nfunction parseStringStyle(cssText) {/n const ret = {};/n cssText.replace(styleCommentRE, '').split(listDelimiterRE).forEach((item) => {/n if (item) {/n const tmp = item.split(propertyDelimiterRE);/n tmp.length > 1 && (ret[tmp[0].trim()] = tmp[1].trim());/n }/n });/n return ret;/n}/nfunction normalizeClass(value) {/n let res = '';/n if (isString(value)) {/n res = value;/n } else if (isArray(value)) {/n for (let i = 0; i < value.length; i++) {/n const normalized = normalizeClass(value[i]);/n if (normalized) {/n res += normalized + ' ';/n }/n }/n } else if (isObject(value)) {/n for (const name in value) {/n if (value[name]) {/n res += name + ' ';/n }/n }/n }/n return res.trim();/n}/nconst toDisplayString = (val) => {/n return isString(val) ? val : val == null ? '' : isArray(val) || isObject(val) && (val.toString === objectToString || !isFunction(val.toString)) ? JSON.stringify(val, replacer, 2) : String(val);/n};/nconst replacer = (_key, val) => {/n if (val && val.__v_isRef) {/n return replacer(_key, val.value);/n } else if (isMap(val)) {/n return {/n [`Map(${val.size})`]: [...val.entries()].reduce((entries, [key, val2]) => {/n entries[`${key} =>`] = val2;/n return entries;/n }, {})/n };/n } else if (isSet(val)) {/n return {/n [`Set(${val.size})`]: [...val.values()]/n };/n } else if (isObject(val) && !isArray(val) && !isPlainObject(val)) {/n return String(val);/n }/n return val;/n};/nconst EMPTY_OBJ = Object.freeze({});/nconst EMPTY_ARR = Object.freeze([]);/nconst NOOP = () => {};/nconst NO = () => false;/nconst onRE = /^on[^a-z]/;/nconst isOn = (key) => onRE.test(key);/nconst isModelListener = (key) => key.startsWith('onUpdate:');/nconst extend = Object.assign;/nconst remove = (arr, el) => {/n const i = arr.indexOf(el);/n if (i > -1) {/n arr.splice(i, 1);/n }/n};/nconst hasOwnProperty$1 = Object.prototype.hasOwnProperty;/nconst hasOwn = (val, key) => hasOwnProperty$1.call(val, key);/nconst isArray = Array.isArray;/nconst isMap = (val) => toTypeString(val) === '[object Map]';/nconst isSet = (val) => toTypeString(val) === '[object Set]';/nconst isFunction = (val) => typeof val === 'function';/nconst isString = (val) => typeof val === 'string';/nconst isSymbol = (val) => typeof val === 'symbol';/nconst isObject = (val) => val !== null && typeof val === 'object';/nconst isPromise = (val) => {/n return isObject(val) && isFunction(val.then) && isFunction(val.catch);/n};/nconst objectToString = Object.prototype.toString;/nconst toTypeString = (value) => objectToString.call(value);/nconst toRawType = (value) => {/n return toTypeString(value).slice(8, -1);/n};/nconst isPlainObject = (val) => toTypeString(val) === '[object Object]';/nconst isIntegerKey = (key) => isString(key) && key !== 'NaN' && key[0] !== '-' && '' + parseInt(key, 10) === key;/nconst isReservedProp = /* @__PURE__ */ makeMap(/n // the leading comma is intentional so empty string '' is also included/n ',key,ref,ref_for,ref_key,onVnodeBeforeMount,onVnodeMounted,onVnodeBeforeUpdate,onVnodeUpdated,onVnodeBeforeUnmount,onVnodeUnmounted'/n);/nconst isBuiltInDirective = /* @__PURE__ */ makeMap('bind,cloak,else-if,else,for,html,if,model,on,once,pre,show,slot,text,memo');/nconst cacheStringFunction = (fn) => {/n const cache = /* @__PURE__ */ Object.create(null);/n return (str) => {/n const hit = cache[str];/n return hit || (cache[str] = fn(str));/n };/n};/nconst camelizeRE = /-(/w)/g;/nconst camelize = cacheStringFunction((str) => {/n return str.replace(camelizeRE, (_, c) => c ? c.toUpperCase() : '');/n});/nconst hyphenateRE = //B([A-Z])/g;/nconst hyphenate = cacheStringFunction((str) => str.replace(hyphenateRE, '-$1').toLowerCase());/nconst capitalize = cacheStringFunction((str) => str.charAt(0).toUpperCase() + str.slice(1));/nconst toHandlerKey = cacheStringFunction((str) => str ? `on${capitalize(str)}` : ``);/nconst hasChanged = (value, oldValue) => !Object.is(value, oldValue);/nconst invokeArrayFns$1 = (fns, arg) => {/n for (let i = 0; i < fns.length; i++) {/n fns[i](arg);/n }/n};/nconst def = (obj, key, value) => {/n Object.defineProperty(obj, key, {/n configurable: true,/n enumerable: false,/n value/n });/n};/nconst looseToNumber = (val) => {/n const n2 = parseFloat(val);/n return isNaN(n2) ? val : n2;/n};/n
原文地址: https://www.cveoy.top/t/topic/lRSl 著作权归作者所有。请勿转载和采集!