diff options
author | RaindropsSys <contact@minteck.org> | 2023-04-06 22:18:28 +0200 |
---|---|---|
committer | RaindropsSys <contact@minteck.org> | 2023-04-06 22:18:28 +0200 |
commit | 83354b2b88218090988dd6e526b0a2505b57e0f1 (patch) | |
tree | e3c73c38a122a78bb7e66fbb99056407edd9d4b9 /includes/external/addressbook/node_modules/cheerio/lib/api/css.js | |
parent | 47b8f2299a483024c4a6a8876af825a010954caa (diff) | |
download | pluralconnect-83354b2b88218090988dd6e526b0a2505b57e0f1.tar.gz pluralconnect-83354b2b88218090988dd6e526b0a2505b57e0f1.tar.bz2 pluralconnect-83354b2b88218090988dd6e526b0a2505b57e0f1.zip |
Updated 5 files and added 1110 files (automated)
Diffstat (limited to 'includes/external/addressbook/node_modules/cheerio/lib/api/css.js')
-rw-r--r-- | includes/external/addressbook/node_modules/cheerio/lib/api/css.js | 118 |
1 files changed, 118 insertions, 0 deletions
diff --git a/includes/external/addressbook/node_modules/cheerio/lib/api/css.js b/includes/external/addressbook/node_modules/cheerio/lib/api/css.js new file mode 100644 index 0000000..9389c29 --- /dev/null +++ b/includes/external/addressbook/node_modules/cheerio/lib/api/css.js @@ -0,0 +1,118 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.css = void 0; +var utils_js_1 = require("../utils.js"); +/** + * Set multiple CSS properties for every matched element. + * + * @category CSS + * @param prop - The names of the properties. + * @param val - The new values. + * @returns The instance itself. + * @see {@link https://api.jquery.com/css/} + */ +function css(prop, val) { + if ((prop != null && val != null) || + // When `prop` is a "plain" object + (typeof prop === 'object' && !Array.isArray(prop))) { + return (0, utils_js_1.domEach)(this, function (el, i) { + if ((0, utils_js_1.isTag)(el)) { + // `prop` can't be an array here anymore. + setCss(el, prop, val, i); + } + }); + } + if (this.length === 0) { + return undefined; + } + return getCss(this[0], prop); +} +exports.css = css; +/** + * Set styles of all elements. + * + * @private + * @param el - Element to set style of. + * @param prop - Name of property. + * @param value - Value to set property to. + * @param idx - Optional index within the selection. + */ +function setCss(el, prop, value, idx) { + if (typeof prop === 'string') { + var styles = getCss(el); + var val = typeof value === 'function' ? value.call(el, idx, styles[prop]) : value; + if (val === '') { + delete styles[prop]; + } + else if (val != null) { + styles[prop] = val; + } + el.attribs['style'] = stringify(styles); + } + else if (typeof prop === 'object') { + Object.keys(prop).forEach(function (k, i) { + setCss(el, k, prop[k], i); + }); + } +} +function getCss(el, prop) { + if (!el || !(0, utils_js_1.isTag)(el)) + return; + var styles = parse(el.attribs['style']); + if (typeof prop === 'string') { + return styles[prop]; + } + if (Array.isArray(prop)) { + var newStyles_1 = {}; + prop.forEach(function (item) { + if (styles[item] != null) { + newStyles_1[item] = styles[item]; + } + }); + return newStyles_1; + } + return styles; +} +/** + * Stringify `obj` to styles. + * + * @private + * @category CSS + * @param obj - Object to stringify. + * @returns The serialized styles. + */ +function stringify(obj) { + return Object.keys(obj).reduce(function (str, prop) { return "".concat(str).concat(str ? ' ' : '').concat(prop, ": ").concat(obj[prop], ";"); }, ''); +} +/** + * Parse `styles`. + * + * @private + * @category CSS + * @param styles - Styles to be parsed. + * @returns The parsed styles. + */ +function parse(styles) { + styles = (styles || '').trim(); + if (!styles) + return {}; + var obj = {}; + var key; + for (var _i = 0, _a = styles.split(';'); _i < _a.length; _i++) { + var str = _a[_i]; + var n = str.indexOf(':'); + // If there is no :, or if it is the first/last character, add to the previous item's value + if (n < 1 || n === str.length - 1) { + var trimmed = str.trimEnd(); + if (trimmed.length > 0 && key !== undefined) { + obj[key] += ";".concat(trimmed); + } + } + else { + key = str.slice(0, n).trim(); + obj[key] = str.slice(n + 1).trim(); + } + } + return obj; +} +//# sourceMappingURL=css.js.map
\ No newline at end of file |