'use strict';
const _export_sfc = (sfc, props) => {
  const target = sfc.__vccOpts || sfc;
  for (const [key, val] of props) {
    target[key] = val;
  }
  return target;
};
function makeMap(str, expectsLowerCase) {
  const map = /* @__PURE__ */ Object.create(null);
  const list = str.split(',');
  for (let i = 0; i < list.length; i++) {
    map[list[i]] = true;
  }
  return expectsLowerCase ? (val) => !!map[val.toLowerCase()] : (val) => !!map[val];
}
function normalizeStyle(value) {
  if (isArray(value)) {
    const res = {};
    for (let i = 0; i < value.length; i++) {
      const item = value[i];
      const normalized = isString(item) ? parseStringStyle(item) : normalizeStyle(item);
      if (normalized) {
        for (const key in normalized) {
          res[key] = normalized[key];
        }
      }
    }
    return res;
  } else if (isString(value)) {
    return value;
  } else if (isObject(value)) {
    return value;
  }
}
const listDelimiterRE = /;(?![^(]*))/g;
const propertyDelimiterRE = /:([^]+)/;
const styleCommentRE = /\*.*?\*\//gs;
function parseStringStyle(cssText) {
  const ret = {};
  cssText.replace(styleCommentRE, '').split(listDelimiterRE).forEach((item) => {
    if (item) {
      const tmp = item.split(propertyDelimiterRE);
      tmp.length > 1 && (ret[tmp[0].trim()] = tmp[1].trim());
    }
  });
  return ret;
}
function normalizeClass(value) {
  let res = '';
  if (isString(value)) {
    res = value;
  } else if (isArray(value)) {
    for (let i = 0; i < value.length; i++) {
      const normalized = normalizeClass(value[i]);
      if (normalized) {
        res += normalized + ' ';
      }
    }
  } else if (isObject(value)) {
    for (const name in value) {
      if (value[name]) {
        res += name + ' ';
      }
    }
  }
  return res.trim();
}
const toDisplayString = (val) => {
  return isString(val) ? val : val == null ? '' : isArray(val) || isObject(val) && (val.toString === objectToString || !isFunction(val.toString)) ? JSON.stringify(val, replacer, 2) : String(val);
};
const replacer = (_key, val) => {
  if (val && val.__v_isRef) {
    return replacer(_key, val.value);
  } else if (isMap(val)) {
    return {
      [`Map(${val.size})`]: [...val.entries()].reduce((entries, [key, val2]) => {
        entries[`${key} =>`] = val2;
        return entries;
      }, {})
    };
  } else if (isSet(val)) {
    return {
      [`Set(${val.size})`]: [...val.values()]
    };
  } else if (isObject(val) && !isArray(val) && !isPlainObject(val)) {
    return String(val);
  }
  return val;
};
const EMPTY_OBJ = Object.freeze({});
const EMPTY_ARR = Object.freeze([]);
const NOOP = () => {};
const NO = () => false;
const onRE = /^on[^a-z]/;
const isOn = (key) => onRE.test(key);
const isModelListener = (key) => key.startsWith('onUpdate:');
const extend = Object.assign;
const remove = (arr, el) => {
  const i = arr.indexOf(el);
  if (i > -1) {
    arr.splice(i, 1);
  }
};

This code provides utility functions that are commonly used in Vue.js component development. Here's a breakdown:

_export_sfc: This function merges props with a Vue component's options object, a common practice for extending components with additional properties.
makeMap: Creates a function to determine if a value exists in a given string (with optional case-insensitivity). This is useful for validating inputs or creating custom filters. normalizeStyle: This function takes a variety of input formats for styles (arrays, strings, objects) and standardizes them into a simple object structure. This makes it easier to manage styles across your component. parseStringStyle: This function parses a string containing CSS styles into a plain JavaScript object, enabling manipulation and easy integration with your component's style logic.
normalizeClass: This function takes various representations of classes (strings, arrays, objects) and outputs a formatted string of classes, simplifying class management in your templates.
toDisplayString: This function converts various JavaScript data types into a string representation, suitable for display in templates. It handles special cases like Refs, Maps, and Sets, ensuring correct output.
replacer: This function acts as a helper for toDisplayString and handles specific data types during string conversion. It aims to provide human-readable representations of data like Refs, Maps, and Sets.

This code snippet highlights the importance of utility functions in simplifying code and improving the maintainability of Vue.js components. It demonstrates how to work with various data formats and ensures consistent handling of styling and classes.


原文地址: https://www.cveoy.top/t/topic/lRRU 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录