Software: Apache/2.4.41 (Ubuntu). PHP/8.0.30 uname -a: Linux apirnd 5.4.0-204-generic #224-Ubuntu SMP Thu Dec 5 13:38:28 UTC 2024 x86_64 uid=33(www-data) gid=33(www-data) groups=33(www-data) Safe-mode: OFF (not secure) /var/www/html/wincloud_gateway/node_modules/jss-plugin-default-unit/src/ drwxr-xr-x | |
| Viewing file: Select action/file-type: // @flow
import type {Plugin} from 'jss'
import defaultUnits, {px} from './defaultUnits'
export type Options = {[key: string]: string | ((val: number) => string)}
/**
* Clones the object and adds a camel cased property version.
*/
function addCamelCasedVersion(obj) {
const regExp = /(-[a-z])/g
const replace = str => str[1].toUpperCase()
const newObj = {}
for (const key in obj) {
newObj[key] = obj[key]
newObj[key.replace(regExp, replace)] = obj[key]
}
return newObj
}
const units = addCamelCasedVersion(defaultUnits)
/**
* Recursive deep style passing function
*/
function iterate(prop: string, value: any, options: Options) {
if (value == null) return value
if (Array.isArray(value)) {
for (let i = 0; i < value.length; i++) {
value[i] = iterate(prop, value[i], options)
}
} else if (typeof value === 'object') {
if (prop === 'fallbacks') {
for (const innerProp in value) {
value[innerProp] = iterate(innerProp, value[innerProp], options)
}
} else {
for (const innerProp in value) {
value[innerProp] = iterate(`${prop}-${innerProp}`, value[innerProp], options)
}
}
// eslint-disable-next-line no-restricted-globals
} else if (typeof value === 'number' && isNaN(value) === false) {
const unit = options[prop] || units[prop]
// Add the unit if available, except for the special case of 0px.
if (unit && !(value === 0 && unit === px)) {
return typeof unit === 'function' ? unit(value).toString() : `${value}${unit}`
}
return value.toString()
}
return value
}
/**
* Add unit to numeric values.
*/
export default function defaultUnit(options: Options = {}): Plugin {
const camelCasedOptions = addCamelCasedVersion(options)
function onProcessStyle(style, rule) {
if (rule.type !== 'style') return style
for (const prop in style) {
style[prop] = iterate(prop, style[prop], camelCasedOptions)
}
return style
}
function onChangeValue(value, prop) {
return iterate(prop, value, camelCasedOptions)
}
return {onProcessStyle, onChangeValue}
}
|
:: Command execute :: | |
--[ c99shell v. 2.5 [PHP 8 Update] [24.05.2025] | Generation time: 0.0045 ]-- |