add all frontend files

This commit is contained in:
2026-01-17 15:16:36 -05:00
parent ff16ae7858
commit e40287e4aa
25704 changed files with 1935289 additions and 0 deletions

View File

@@ -0,0 +1,4 @@
import type { CSSObject } from '..';
export interface Transformer {
visit?: (cssObj: CSSObject) => CSSObject;
}

View File

@@ -0,0 +1,5 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});

View File

@@ -0,0 +1,12 @@
import type { Transformer } from './interface';
/**
* Convert css logical properties to legacy properties.
* Such as: `margin-block-start` to `margin-top`.
* Transform list:
* - inset
* - margin
* - padding
* - border
*/
declare const transform: Transformer;
export default transform;

View File

@@ -0,0 +1,156 @@
"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
function splitValues(value) {
if (typeof value === 'number') {
return [[value], false];
}
var rawStyle = String(value).trim();
var importantCells = rawStyle.match(/(.*)(!important)/);
var splitStyle = (importantCells ? importantCells[1] : rawStyle).trim().split(/\s+/);
// Combine styles split in brackets, like `calc(1px + 2px)`
var temp = [];
var brackets = 0;
return [splitStyle.reduce(function (list, item) {
if (item.includes('(') || item.includes(')')) {
var left = item.split('(').length - 1;
var right = item.split(')').length - 1;
brackets += left - right;
}
if (brackets >= 0) temp.push(item);
if (brackets === 0) {
list.push(temp.join(' '));
temp = [];
}
return list;
}, []), !!importantCells];
}
function noSplit(list) {
list.notSplit = true;
return list;
}
var keyMap = {
// Inset
inset: ['top', 'right', 'bottom', 'left'],
insetBlock: ['top', 'bottom'],
insetBlockStart: ['top'],
insetBlockEnd: ['bottom'],
insetInline: ['left', 'right'],
insetInlineStart: ['left'],
insetInlineEnd: ['right'],
// Margin
marginBlock: ['marginTop', 'marginBottom'],
marginBlockStart: ['marginTop'],
marginBlockEnd: ['marginBottom'],
marginInline: ['marginLeft', 'marginRight'],
marginInlineStart: ['marginLeft'],
marginInlineEnd: ['marginRight'],
// Padding
paddingBlock: ['paddingTop', 'paddingBottom'],
paddingBlockStart: ['paddingTop'],
paddingBlockEnd: ['paddingBottom'],
paddingInline: ['paddingLeft', 'paddingRight'],
paddingInlineStart: ['paddingLeft'],
paddingInlineEnd: ['paddingRight'],
// Border
borderBlock: noSplit(['borderTop', 'borderBottom']),
borderBlockStart: noSplit(['borderTop']),
borderBlockEnd: noSplit(['borderBottom']),
borderInline: noSplit(['borderLeft', 'borderRight']),
borderInlineStart: noSplit(['borderLeft']),
borderInlineEnd: noSplit(['borderRight']),
// Border width
borderBlockWidth: ['borderTopWidth', 'borderBottomWidth'],
borderBlockStartWidth: ['borderTopWidth'],
borderBlockEndWidth: ['borderBottomWidth'],
borderInlineWidth: ['borderLeftWidth', 'borderRightWidth'],
borderInlineStartWidth: ['borderLeftWidth'],
borderInlineEndWidth: ['borderRightWidth'],
// Border style
borderBlockStyle: ['borderTopStyle', 'borderBottomStyle'],
borderBlockStartStyle: ['borderTopStyle'],
borderBlockEndStyle: ['borderBottomStyle'],
borderInlineStyle: ['borderLeftStyle', 'borderRightStyle'],
borderInlineStartStyle: ['borderLeftStyle'],
borderInlineEndStyle: ['borderRightStyle'],
// Border color
borderBlockColor: ['borderTopColor', 'borderBottomColor'],
borderBlockStartColor: ['borderTopColor'],
borderBlockEndColor: ['borderBottomColor'],
borderInlineColor: ['borderLeftColor', 'borderRightColor'],
borderInlineStartColor: ['borderLeftColor'],
borderInlineEndColor: ['borderRightColor'],
// Border radius
borderStartStartRadius: ['borderTopLeftRadius'],
borderStartEndRadius: ['borderTopRightRadius'],
borderEndStartRadius: ['borderBottomLeftRadius'],
borderEndEndRadius: ['borderBottomRightRadius']
};
function wrapImportantAndSkipCheck(value, important) {
var parsedValue = value;
if (important) {
parsedValue = "".concat(parsedValue, " !important");
}
return {
_skip_check_: true,
value: parsedValue
};
}
/**
* Convert css logical properties to legacy properties.
* Such as: `margin-block-start` to `margin-top`.
* Transform list:
* - inset
* - margin
* - padding
* - border
*/
var transform = {
visit: function visit(cssObj) {
var clone = {};
Object.keys(cssObj).forEach(function (key) {
var value = cssObj[key];
var matchValue = keyMap[key];
if (matchValue && (typeof value === 'number' || typeof value === 'string')) {
var _splitValues = splitValues(value),
_splitValues2 = (0, _slicedToArray2.default)(_splitValues, 2),
_values = _splitValues2[0],
_important = _splitValues2[1];
if (matchValue.length && matchValue.notSplit) {
// not split means always give same value like border
matchValue.forEach(function (matchKey) {
clone[matchKey] = wrapImportantAndSkipCheck(value, _important);
});
} else if (matchValue.length === 1) {
// Handle like `marginBlockStart` => `marginTop`
clone[matchValue[0]] = wrapImportantAndSkipCheck(_values[0], _important);
} else if (matchValue.length === 2) {
// Handle like `marginBlock` => `marginTop` & `marginBottom`
matchValue.forEach(function (matchKey, index) {
var _values$index;
clone[matchKey] = wrapImportantAndSkipCheck((_values$index = _values[index]) !== null && _values$index !== void 0 ? _values$index : _values[0], _important);
});
} else if (matchValue.length === 4) {
// Handle like `inset` => `top` & `right` & `bottom` & `left`
matchValue.forEach(function (matchKey, index) {
var _ref, _values$index2;
clone[matchKey] = wrapImportantAndSkipCheck((_ref = (_values$index2 = _values[index]) !== null && _values$index2 !== void 0 ? _values$index2 : _values[index - 2]) !== null && _ref !== void 0 ? _ref : _values[0], _important);
});
} else {
clone[key] = value;
}
} else {
clone[key] = value;
}
});
return clone;
}
};
var _default = exports.default = transform;

View File

@@ -0,0 +1,20 @@
import type { Transformer } from './interface';
interface Options {
/**
* The root font size.
* @default 16
*/
rootValue?: number;
/**
* The decimal numbers to allow the REM units to grow to.
* @default 5
*/
precision?: number;
/**
* Whether to allow px to be converted in media queries.
* @default false
*/
mediaQuery?: boolean;
}
declare const transform: (options?: Options) => Transformer;
export default transform;

View File

@@ -0,0 +1,68 @@
"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
var _unitless = _interopRequireDefault(require("@emotion/unitless"));
/**
* respect https://github.com/cuth/postcss-pxtorem
*/
// @ts-ignore
var pxRegex = /url\([^)]+\)|var\([^)]+\)|(\d*\.?\d+)px/g;
function toFixed(number, precision) {
var multiplier = Math.pow(10, precision + 1),
wholeNumber = Math.floor(number * multiplier);
return Math.round(wholeNumber / 10) * 10 / multiplier;
}
var transform = function transform() {
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var _options$rootValue = options.rootValue,
rootValue = _options$rootValue === void 0 ? 16 : _options$rootValue,
_options$precision = options.precision,
precision = _options$precision === void 0 ? 5 : _options$precision,
_options$mediaQuery = options.mediaQuery,
mediaQuery = _options$mediaQuery === void 0 ? false : _options$mediaQuery;
var pxReplace = function pxReplace(m, $1) {
if (!$1) return m;
var pixels = parseFloat($1);
// covenant: pixels <= 1, not transform to rem @zombieJ
if (pixels <= 1) return m;
var fixedVal = toFixed(pixels / rootValue, precision);
return "".concat(fixedVal, "rem");
};
var visit = function visit(cssObj) {
var clone = (0, _objectSpread2.default)({}, cssObj);
Object.entries(cssObj).forEach(function (_ref) {
var _ref2 = (0, _slicedToArray2.default)(_ref, 2),
key = _ref2[0],
value = _ref2[1];
if (typeof value === 'string' && value.includes('px')) {
var newValue = value.replace(pxRegex, pxReplace);
clone[key] = newValue;
}
// no unit
if (!_unitless.default[key] && typeof value === 'number' && value !== 0) {
clone[key] = "".concat(value, "px").replace(pxRegex, pxReplace);
}
// Media queries
var mergedKey = key.trim();
if (mergedKey.startsWith('@') && mergedKey.includes('px') && mediaQuery) {
var newKey = key.replace(pxRegex, pxReplace);
clone[newKey] = clone[key];
delete clone[key];
}
});
return clone;
};
return {
visit: visit
};
};
var _default = exports.default = transform;