mirror of
https://github.com/R0m1k3/Loki.git
synced 2026-10-21 05:58:13 +02:00
Jauge de contexte, espace disque sur partage agrégé, panneau Fichiers
Trois défauts sans rapport entre eux, tous visibles à l'écran. Jauge de contexte bloquée à « 0 / N (0 %) » : le comptage exact vient de usage.prompt_tokens (include_usage), qu'un llama-server récent a cessé de renvoyer. On note désormais si l'usage est arrivé ; sinon la fin de tour publie l'estimation qui pilote déjà la compaction — approximative, mais jamais absente. Et la souscription envoie la valeur courante juste après le rattrapage : une page rechargée affichait zéro sur une discussion pourtant pleine, faute d'événement ctx_used dans la fenêtre rejouée. Espace disque : « il ne reste que 11,9 Go » sur un partage Unraid qui en a des centaines. /mnt/user est servi par shfs, un FUSE qui agrège plusieurs disques — statfs y renvoie l'espace d'un seul, et ce chiffre REFUSAIT l'installation du modèle. Les systèmes de fichiers qui approximent (FUSE, overlay, NFS, CIFS, Ceph, Gluster) sont reconnus par leur magie : leur chiffre reste affiché, précédé d'un « ~ », mais ne bloque plus rien. Panneau Fichiers : le panneau entier défilait, emportant vers le haut l'en-tête, le fil d'Ariane et le pied (occupation disque, bouton .zip) dès qu'il y avait quelques fichiers. Seule la liste défile maintenant ; le pied reste en bas et l'état vide se centre. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
895ff92ed8
commit
b405adea6c
5118 files changed
+1264007
-23
No files matched your search
+22
@@ -0,0 +1,22 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2020 Menglin "Mark" Xu <mark@remarkablemark.org>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the
|
||||
"Software"), to deal in the Software without restriction, including
|
||||
without limitation the rights to use, copy, modify, merge, publish,
|
||||
distribute, sublicense, and/or sell copies of the Software, and to
|
||||
permit persons to whom the Software is furnished to do so, subject to
|
||||
the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
+271
@@ -0,0 +1,271 @@
|
||||
# style-to-js
|
||||
|
||||
[](https://nodei.co/npm/style-to-js/)
|
||||
|
||||
[](https://www.npmjs.com/package/style-to-js)
|
||||
[](https://bundlephobia.com/package/style-to-js)
|
||||
[](https://github.com/remarkablemark/style-to-js/actions/workflows/build.yml)
|
||||
[](https://codecov.io/gh/remarkablemark/style-to-js)
|
||||
[](https://www.npmjs.com/package/style-to-js)
|
||||
|
||||
Parses CSS inline style to JavaScript object (camelCased):
|
||||
|
||||
```
|
||||
StyleToJS(string)
|
||||
```
|
||||
|
||||
## Example
|
||||
|
||||
```js
|
||||
import parse from 'style-to-js';
|
||||
|
||||
parse('background-color: #BADA55;');
|
||||
```
|
||||
|
||||
Output:
|
||||
|
||||
```json
|
||||
{ "backgroundColor": "#BADA55" }
|
||||
```
|
||||
|
||||
[JSFiddle](https://jsfiddle.net/remarkablemark/04nob1y7/) | [Examples](https://github.com/remarkablemark/style-to-js/tree/master/examples)
|
||||
|
||||
## Install
|
||||
|
||||
[NPM](https://www.npmjs.com/package/style-to-js):
|
||||
|
||||
```sh
|
||||
npm install style-to-js --save
|
||||
```
|
||||
|
||||
[Yarn](https://yarnpkg.com/package/style-to-js):
|
||||
|
||||
```sh
|
||||
yarn add style-to-js
|
||||
```
|
||||
|
||||
[CDN](https://unpkg.com/style-to-js/):
|
||||
|
||||
```html
|
||||
<script src="https://unpkg.com/style-to-js@latest/umd/style-to-js.min.js"></script>
|
||||
<script>
|
||||
window.StyleToJS(/* string */);
|
||||
</script>
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
### Import
|
||||
|
||||
Import with ES Modules:
|
||||
|
||||
```js
|
||||
import parse from 'style-to-js';
|
||||
```
|
||||
|
||||
Require with CommonJS:
|
||||
|
||||
```js
|
||||
const parse = require('style-to-js');
|
||||
```
|
||||
|
||||
### Parse style
|
||||
|
||||
Parse single declaration:
|
||||
|
||||
```js
|
||||
parse('line-height: 42');
|
||||
```
|
||||
|
||||
Output:
|
||||
|
||||
```json
|
||||
{ "lineHeight": "42" }
|
||||
```
|
||||
|
||||
> [!NOTE]
|
||||
> Notice that the CSS property is camelCased.
|
||||
|
||||
Parse multiple declarations:
|
||||
|
||||
```js
|
||||
parse(`
|
||||
border-color: #ACE;
|
||||
z-index: 1337;
|
||||
`);
|
||||
```
|
||||
|
||||
Output:
|
||||
|
||||
```json
|
||||
{
|
||||
"borderColor": "#ACE",
|
||||
"zIndex": "1337"
|
||||
}
|
||||
```
|
||||
|
||||
### Vendor prefix
|
||||
|
||||
Parse [vendor prefix](https://developer.mozilla.org/en-US/docs/Glossary/Vendor_Prefix):
|
||||
|
||||
```js
|
||||
parse(`
|
||||
-webkit-transition: all 4s ease;
|
||||
-moz-transition: all 4s ease;
|
||||
-ms-transition: all 4s ease;
|
||||
-o-transition: all 4s ease;
|
||||
-khtml-transition: all 4s ease;
|
||||
`);
|
||||
```
|
||||
|
||||
Output:
|
||||
|
||||
```json
|
||||
{
|
||||
"webkitTransition": "all 4s ease",
|
||||
"mozTransition": "all 4s ease",
|
||||
"msTransition": "all 4s ease",
|
||||
"oTransition": "all 4s ease",
|
||||
"khtmlTransition": "all 4s ease"
|
||||
}
|
||||
```
|
||||
|
||||
### Custom property
|
||||
|
||||
Parse [custom property](https://developer.mozilla.org/en-US/docs/Web/CSS/--*):
|
||||
|
||||
```js
|
||||
parse('--custom-property: #f00');
|
||||
```
|
||||
|
||||
Output:
|
||||
|
||||
```json
|
||||
{ "--custom-property": "#f00" }
|
||||
```
|
||||
|
||||
### Unknown declaration
|
||||
|
||||
This library does not validate declarations, so unknown declarations can be parsed:
|
||||
|
||||
```js
|
||||
parse('the-answer: 42;');
|
||||
```
|
||||
|
||||
Output:
|
||||
|
||||
```json
|
||||
{ "theAnswer": "42" }
|
||||
```
|
||||
|
||||
### Invalid declaration
|
||||
|
||||
Declarations with missing value are removed:
|
||||
|
||||
```js
|
||||
parse(`
|
||||
margin-top: ;
|
||||
margin-right: 1em;
|
||||
`);
|
||||
```
|
||||
|
||||
Output:
|
||||
|
||||
```json
|
||||
{ "marginRight": "1em" }
|
||||
```
|
||||
|
||||
Other invalid declarations or arguments:
|
||||
|
||||
```js
|
||||
parse(); // {}
|
||||
parse(null); // {}
|
||||
parse(1); // {}
|
||||
parse(true); // {}
|
||||
parse('top:'); // {}
|
||||
parse(':12px'); // {}
|
||||
parse(':'); // {}
|
||||
parse(';'); // {}
|
||||
```
|
||||
|
||||
The following values will throw an error:
|
||||
|
||||
```js
|
||||
parse('top'); // Uncaught Error: property missing ':'
|
||||
parse('/*'); // Uncaught Error: End of comment missing
|
||||
```
|
||||
|
||||
### Options
|
||||
|
||||
#### reactCompat
|
||||
|
||||
When option `reactCompat` is true, the [vendor prefix](https://developer.mozilla.org/en-US/docs/Glossary/Vendor_Prefix) will be capitalized:
|
||||
|
||||
```js
|
||||
parse(
|
||||
`
|
||||
-webkit-transition: all 4s ease;
|
||||
-moz-transition: all 4s ease;
|
||||
-ms-transition: all 4s ease;
|
||||
-o-transition: all 4s ease;
|
||||
-khtml-transition: all 4s ease;
|
||||
`,
|
||||
{ reactCompat: true },
|
||||
);
|
||||
```
|
||||
|
||||
Output:
|
||||
|
||||
```json
|
||||
{
|
||||
"WebkitTransition": "all 4s ease",
|
||||
"MozTransition": "all 4s ease",
|
||||
"msTransition": "all 4s ease",
|
||||
"OTransition": "all 4s ease",
|
||||
"KhtmlTransition": "all 4s ease"
|
||||
}
|
||||
```
|
||||
|
||||
This removes the React warning:
|
||||
|
||||
```
|
||||
Warning: Unsupported vendor-prefixed style property %s. Did you mean %s?%s", "oTransition", "OTransition"
|
||||
```
|
||||
|
||||
## Testing
|
||||
|
||||
Run tests with coverage:
|
||||
|
||||
```sh
|
||||
npm test
|
||||
```
|
||||
|
||||
Run tests in watch mode:
|
||||
|
||||
```sh
|
||||
npm run test:watch
|
||||
```
|
||||
|
||||
Lint files:
|
||||
|
||||
```sh
|
||||
npm run lint
|
||||
```
|
||||
|
||||
Fix lint errors:
|
||||
|
||||
```sh
|
||||
npm run lint:fix
|
||||
```
|
||||
|
||||
## Release
|
||||
|
||||
Release and publish are automated by [Release Please](https://github.com/googleapis/release-please).
|
||||
|
||||
## Special Thanks
|
||||
|
||||
- [style-to-object](https://github.com/remarkablemark/style-to-object)
|
||||
|
||||
## License
|
||||
|
||||
[MIT](https://github.com/remarkablemark/style-to-js/blob/master/LICENSE)
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
import { CamelCaseOptions } from './utilities';
|
||||
type StyleObject = Record<string, string>;
|
||||
interface StyleToJSOptions extends CamelCaseOptions {
|
||||
}
|
||||
/**
|
||||
* Parses CSS inline style to JavaScript object (camelCased).
|
||||
*/
|
||||
declare function StyleToJS(style: string, options?: StyleToJSOptions): StyleObject;
|
||||
declare namespace StyleToJS {
|
||||
var _a: typeof StyleToJS;
|
||||
export { _a as default };
|
||||
}
|
||||
export = StyleToJS;
|
||||
//# sourceMappingURL=index.d.ts.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAa,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAE1D,KAAK,WAAW,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AAE1C,UAAU,gBAAiB,SAAQ,gBAAgB;CAAG;AAEtD;;GAEG;AACH,iBAAS,SAAS,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,gBAAgB,GAAG,WAAW,CAezE;kBAfQ,SAAS;;;;AAmBlB,SAAS,SAAS,CAAC"}
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
var style_to_object_1 = __importDefault(require("style-to-object"));
|
||||
var utilities_1 = require("./utilities");
|
||||
/**
|
||||
* Parses CSS inline style to JavaScript object (camelCased).
|
||||
*/
|
||||
function StyleToJS(style, options) {
|
||||
var output = {};
|
||||
if (!style || typeof style !== 'string') {
|
||||
return output;
|
||||
}
|
||||
(0, style_to_object_1.default)(style, function (property, value) {
|
||||
// skip CSS comment
|
||||
if (property && value) {
|
||||
output[(0, utilities_1.camelCase)(property, options)] = value;
|
||||
}
|
||||
});
|
||||
return output;
|
||||
}
|
||||
StyleToJS.default = StyleToJS;
|
||||
module.exports = StyleToJS;
|
||||
//# sourceMappingURL=index.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;AAAA,oEAA4C;AAE5C,yCAA0D;AAM1D;;GAEG;AACH,SAAS,SAAS,CAAC,KAAa,EAAE,OAA0B;IAC1D,IAAM,MAAM,GAAgB,EAAE,CAAC;IAE/B,IAAI,CAAC,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QACxC,OAAO,MAAM,CAAC;IAChB,CAAC;IAED,IAAA,yBAAa,EAAC,KAAK,EAAE,UAAC,QAAQ,EAAE,KAAK;QACnC,mBAAmB;QACnB,IAAI,QAAQ,IAAI,KAAK,EAAE,CAAC;YACtB,MAAM,CAAC,IAAA,qBAAS,EAAC,QAAQ,EAAE,OAAO,CAAC,CAAC,GAAG,KAAK,CAAC;QAC/C,CAAC;IACH,CAAC,CAAC,CAAC;IAEH,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,SAAS,CAAC,OAAO,GAAG,SAAS,CAAC;AAE9B,iBAAS,SAAS,CAAC"}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
/**
|
||||
* CamelCase options.
|
||||
*/
|
||||
export interface CamelCaseOptions {
|
||||
reactCompat?: boolean;
|
||||
}
|
||||
/**
|
||||
* CamelCases a CSS property.
|
||||
*/
|
||||
export declare const camelCase: (property: string, options?: CamelCaseOptions) => string;
|
||||
//# sourceMappingURL=utilities.d.ts.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"utilities.d.ts","sourceRoot":"","sources":["../src/utilities.ts"],"names":[],"mappings":"AAyBA;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB;AAED;;GAEG;AACH,eAAO,MAAM,SAAS,GAAI,UAAU,MAAM,EAAE,UAAS,gBAAqB,WAgBzE,CAAC"}
|
||||
+47
@@ -0,0 +1,47 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.camelCase = void 0;
|
||||
var CUSTOM_PROPERTY_REGEX = /^--[a-zA-Z0-9_-]+$/;
|
||||
var HYPHEN_REGEX = /-([a-z])/g;
|
||||
var NO_HYPHEN_REGEX = /^[^-]+$/;
|
||||
var VENDOR_PREFIX_REGEX = /^-(webkit|moz|ms|o|khtml)-/;
|
||||
var MS_VENDOR_PREFIX_REGEX = /^-(ms)-/;
|
||||
/**
|
||||
* Checks whether to skip camelCase.
|
||||
*/
|
||||
var skipCamelCase = function (property) {
|
||||
return !property ||
|
||||
NO_HYPHEN_REGEX.test(property) ||
|
||||
CUSTOM_PROPERTY_REGEX.test(property);
|
||||
};
|
||||
/**
|
||||
* Replacer that capitalizes first character.
|
||||
*/
|
||||
var capitalize = function (match, character) {
|
||||
return character.toUpperCase();
|
||||
};
|
||||
/**
|
||||
* Replacer that removes beginning hyphen of vendor prefix property.
|
||||
*/
|
||||
var trimHyphen = function (match, prefix) { return "".concat(prefix, "-"); };
|
||||
/**
|
||||
* CamelCases a CSS property.
|
||||
*/
|
||||
var camelCase = function (property, options) {
|
||||
if (options === void 0) { options = {}; }
|
||||
if (skipCamelCase(property)) {
|
||||
return property;
|
||||
}
|
||||
property = property.toLowerCase();
|
||||
if (options.reactCompat) {
|
||||
// `-ms` vendor prefix should not be capitalized
|
||||
property = property.replace(MS_VENDOR_PREFIX_REGEX, trimHyphen);
|
||||
}
|
||||
else {
|
||||
// for non-React, remove first hyphen so vendor prefix is not capitalized
|
||||
property = property.replace(VENDOR_PREFIX_REGEX, trimHyphen);
|
||||
}
|
||||
return property.replace(HYPHEN_REGEX, capitalize);
|
||||
};
|
||||
exports.camelCase = camelCase;
|
||||
//# sourceMappingURL=utilities.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"utilities.js","sourceRoot":"","sources":["../src/utilities.ts"],"names":[],"mappings":";;;AAAA,IAAM,qBAAqB,GAAG,oBAAoB,CAAC;AACnD,IAAM,YAAY,GAAG,WAAW,CAAC;AACjC,IAAM,eAAe,GAAG,SAAS,CAAC;AAClC,IAAM,mBAAmB,GAAG,4BAA4B,CAAC;AACzD,IAAM,sBAAsB,GAAG,SAAS,CAAC;AAEzC;;GAEG;AACH,IAAM,aAAa,GAAG,UAAC,QAAgB;IACrC,OAAA,CAAC,QAAQ;QACT,eAAe,CAAC,IAAI,CAAC,QAAQ,CAAC;QAC9B,qBAAqB,CAAC,IAAI,CAAC,QAAQ,CAAC;AAFpC,CAEoC,CAAC;AAEvC;;GAEG;AACH,IAAM,UAAU,GAAG,UAAC,KAAa,EAAE,SAAiB;IAClD,OAAA,SAAS,CAAC,WAAW,EAAE;AAAvB,CAAuB,CAAC;AAE1B;;GAEG;AACH,IAAM,UAAU,GAAG,UAAC,KAAa,EAAE,MAAc,IAAK,OAAA,UAAG,MAAM,MAAG,EAAZ,CAAY,CAAC;AASnE;;GAEG;AACI,IAAM,SAAS,GAAG,UAAC,QAAgB,EAAE,OAA8B;IAA9B,wBAAA,EAAA,YAA8B;IACxE,IAAI,aAAa,CAAC,QAAQ,CAAC,EAAE,CAAC;QAC5B,OAAO,QAAQ,CAAC;IAClB,CAAC;IAED,QAAQ,GAAG,QAAQ,CAAC,WAAW,EAAE,CAAC;IAElC,IAAI,OAAO,CAAC,WAAW,EAAE,CAAC;QACxB,gDAAgD;QAChD,QAAQ,GAAG,QAAQ,CAAC,OAAO,CAAC,sBAAsB,EAAE,UAAU,CAAC,CAAC;IAClE,CAAC;SAAM,CAAC;QACN,yEAAyE;QACzE,QAAQ,GAAG,QAAQ,CAAC,OAAO,CAAC,mBAAmB,EAAE,UAAU,CAAC,CAAC;IAC/D,CAAC;IAED,OAAO,QAAQ,CAAC,OAAO,CAAC,YAAY,EAAE,UAAU,CAAC,CAAC;AACpD,CAAC,CAAC;AAhBW,QAAA,SAAS,aAgBpB"}
|
||||
+70
@@ -0,0 +1,70 @@
|
||||
{
|
||||
"name": "style-to-js",
|
||||
"version": "1.1.21",
|
||||
"description": "Parses CSS inline style to JavaScript object (camelCased).",
|
||||
"author": "Mark <mark@remarkablemark.org>",
|
||||
"main": "cjs/index.js",
|
||||
"scripts": {
|
||||
"build": "npm run build:cjs && npm run build:umd",
|
||||
"build:cjs": "tsc --declaration --outDir cjs",
|
||||
"build:umd": "rollup --config --failAfterWarnings",
|
||||
"clean": "rm -rf cjs umd",
|
||||
"lint": "eslint .",
|
||||
"lint:tsc": "tsc --noEmit",
|
||||
"lint:fix": "npm run lint -- --fix",
|
||||
"prepare": "husky",
|
||||
"prepublishOnly": "npm run lint && npm run lint:tsc && npm run test:ci && npm run clean && npm run build",
|
||||
"test": "jest",
|
||||
"test:ci": "CI=true jest --ci --colors --coverage",
|
||||
"test:watch": "jest --watch"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/remarkablemark/style-to-js.git"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/remarkablemark/style-to-js/issues"
|
||||
},
|
||||
"keywords": [
|
||||
"style-to-js",
|
||||
"css",
|
||||
"style",
|
||||
"javascript",
|
||||
"object",
|
||||
"pojo"
|
||||
],
|
||||
"dependencies": {
|
||||
"style-to-object": "1.0.14"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@commitlint/cli": "20.1.0",
|
||||
"@commitlint/config-conventional": "20.0.0",
|
||||
"@eslint/compat": "2.0.0",
|
||||
"@eslint/eslintrc": "3.3.1",
|
||||
"@eslint/js": "9.39.1",
|
||||
"@rollup/plugin-commonjs": "29.0.0",
|
||||
"@rollup/plugin-node-resolve": "16.0.3",
|
||||
"@rollup/plugin-terser": "0.4.4",
|
||||
"@types/jest": "30.0.0",
|
||||
"@typescript-eslint/eslint-plugin": "8.46.4",
|
||||
"@typescript-eslint/parser": "8.46.4",
|
||||
"eslint": "9.39.1",
|
||||
"eslint-plugin-prettier": "5.5.4",
|
||||
"eslint-plugin-simple-import-sort": "12.1.1",
|
||||
"globals": "16.5.0",
|
||||
"husky": "9.1.7",
|
||||
"jest": "30.2.0",
|
||||
"lint-staged": "16.2.6",
|
||||
"prettier": "3.6.2",
|
||||
"rollup": "4.53.2",
|
||||
"ts-jest": "29.4.5",
|
||||
"ts-node": "10.9.2",
|
||||
"typescript": "5.9.3"
|
||||
},
|
||||
"files": [
|
||||
"cjs/",
|
||||
"src/",
|
||||
"umd/"
|
||||
],
|
||||
"license": "MIT"
|
||||
}
|
||||
+129
@@ -0,0 +1,129 @@
|
||||
import styleToJS = require('.');
|
||||
|
||||
it('exposes itself as default', () => {
|
||||
expect(styleToJS).toBe(styleToJS.default);
|
||||
});
|
||||
|
||||
it('parses empty style to object', () => {
|
||||
expect(styleToJS('')).toEqual({});
|
||||
});
|
||||
|
||||
it('does not parse CSS comment', () => {
|
||||
expect(styleToJS('/* comment */')).toEqual({});
|
||||
});
|
||||
|
||||
// invalid argument
|
||||
it.each([undefined, null, 0, 1, true, false, {}, [], () => {}, new Date()])(
|
||||
'parses "%s" to empty object',
|
||||
(text) => {
|
||||
expect(styleToJS(text as string)).toEqual({});
|
||||
},
|
||||
);
|
||||
|
||||
it.each(['top:', ':12px', ':', ';'])('parses "%s" to empty object', (text) => {
|
||||
expect(styleToJS(text)).toEqual({});
|
||||
});
|
||||
|
||||
it('parses common styles to object', () => {
|
||||
const style = `
|
||||
color: #f00;
|
||||
font-size: 42px;
|
||||
z-index: -1;
|
||||
`;
|
||||
expect(styleToJS(style)).toMatchInlineSnapshot(`
|
||||
{
|
||||
"color": "#f00",
|
||||
"fontSize": "42px",
|
||||
"zIndex": "-1",
|
||||
}
|
||||
`);
|
||||
});
|
||||
|
||||
it('parses style with vendor prefix to object', () => {
|
||||
const style = `
|
||||
display: -ms-grid;
|
||||
display: grid;
|
||||
-webkit-transition: all .5s;
|
||||
-o-transition: all .5s;
|
||||
transition: all .5s;
|
||||
-webkit-user-select: none;
|
||||
-moz-user-select: none;
|
||||
-ms-user-select: none;
|
||||
user-select: none;
|
||||
background: -webkit-gradient(linear, left top, left bottom, from(white), to(black));
|
||||
background: -o-linear-gradient(top, white, black);
|
||||
background: linear-gradient(to bottom, white, black);
|
||||
`;
|
||||
expect(styleToJS(style)).toMatchInlineSnapshot(`
|
||||
{
|
||||
"background": "linear-gradient(to bottom, white, black)",
|
||||
"display": "grid",
|
||||
"mozUserSelect": "none",
|
||||
"msUserSelect": "none",
|
||||
"oTransition": "all .5s",
|
||||
"transition": "all .5s",
|
||||
"userSelect": "none",
|
||||
"webkitTransition": "all .5s",
|
||||
"webkitUserSelect": "none",
|
||||
}
|
||||
`);
|
||||
});
|
||||
|
||||
it('parses background style to object', () => {
|
||||
const style =
|
||||
'background: url(data:image/png; base64,ivborw0kggoaaaansaaaabgdbtueaalgpc/xhbqaaaafzmuexurczmzpf399fx1+bm5mzy9avzxbesmgces5/p8/t9furvcrmu73jwlzosgsiizurcjo/ad+eqjjb4hv8bft+idpqocx1wjosbfhh2xssxeiyn3uli/6mnree07uiwjev8u8czwyuqdlkpg1bkb4nnm+veanfhqn1k4+gpt6ugqcvu2h2ovuif)';
|
||||
expect(styleToJS(style)).toMatchInlineSnapshot(`
|
||||
{
|
||||
"background": "url(data:image/png; base64,ivborw0kggoaaaansaaaabgdbtueaalgpc/xhbqaaaafzmuexurczmzpf399fx1+bm5mzy9avzxbesmgces5/p8/t9furvcrmu73jwlzosgsiizurcjo/ad+eqjjb4hv8bft+idpqocx1wjosbfhh2xssxeiyn3uli/6mnree07uiwjev8u8czwyuqdlkpg1bkb4nnm+veanfhqn1k4+gpt6ugqcvu2h2ovuif)",
|
||||
}
|
||||
`);
|
||||
});
|
||||
|
||||
it('parses style with no spaces to object', () => {
|
||||
const style =
|
||||
'border-bottom-left-radius:1em;border-right-style:solid;Z-Index:-1;-moz-border-radius-bottomleft:20px';
|
||||
expect(styleToJS(style)).toMatchInlineSnapshot(`
|
||||
{
|
||||
"borderBottomLeftRadius": "1em",
|
||||
"borderRightStyle": "solid",
|
||||
"mozBorderRadiusBottomleft": "20px",
|
||||
"zIndex": "-1",
|
||||
}
|
||||
`);
|
||||
});
|
||||
|
||||
describe('when option reactCompat is true', () => {
|
||||
const options = { reactCompat: true };
|
||||
|
||||
it('capitalizes vendor prefixes', () => {
|
||||
const style = `
|
||||
-khtml-user-select: none;
|
||||
-moz-user-select: -moz-none;
|
||||
-o-user-select: none;
|
||||
-webkit-user-select: none;
|
||||
user-select: none;
|
||||
`;
|
||||
expect(styleToJS(style, options)).toMatchInlineSnapshot(`
|
||||
{
|
||||
"KhtmlUserSelect": "none",
|
||||
"MozUserSelect": "-moz-none",
|
||||
"OUserSelect": "none",
|
||||
"WebkitUserSelect": "none",
|
||||
"userSelect": "none",
|
||||
}
|
||||
`);
|
||||
});
|
||||
|
||||
it('does not capitalize ms prefixes', () => {
|
||||
const style = `
|
||||
-ms-transform: none;
|
||||
-ms-user-select: none;
|
||||
`;
|
||||
expect(styleToJS(style, options)).toMatchInlineSnapshot(`
|
||||
{
|
||||
"msTransform": "none",
|
||||
"msUserSelect": "none",
|
||||
}
|
||||
`);
|
||||
});
|
||||
});
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
import StyleToObject from 'style-to-object';
|
||||
|
||||
import { camelCase, CamelCaseOptions } from './utilities';
|
||||
|
||||
type StyleObject = Record<string, string>;
|
||||
|
||||
interface StyleToJSOptions extends CamelCaseOptions {}
|
||||
|
||||
/**
|
||||
* Parses CSS inline style to JavaScript object (camelCased).
|
||||
*/
|
||||
function StyleToJS(style: string, options?: StyleToJSOptions): StyleObject {
|
||||
const output: StyleObject = {};
|
||||
|
||||
if (!style || typeof style !== 'string') {
|
||||
return output;
|
||||
}
|
||||
|
||||
StyleToObject(style, (property, value) => {
|
||||
// skip CSS comment
|
||||
if (property && value) {
|
||||
output[camelCase(property, options)] = value;
|
||||
}
|
||||
});
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
StyleToJS.default = StyleToJS;
|
||||
|
||||
export = StyleToJS;
|
||||
+62
@@ -0,0 +1,62 @@
|
||||
import { camelCase } from './utilities';
|
||||
|
||||
describe('camelCase', () => {
|
||||
it('returns "" for empty string', () => {
|
||||
expect(camelCase('')).toBe('');
|
||||
});
|
||||
|
||||
// no hyphen
|
||||
it.each([
|
||||
['foo', 'foo'],
|
||||
['fooBar', 'fooBar'],
|
||||
])('does not transform "%s"', (property, expected) => {
|
||||
expect(camelCase(property)).toBe(expected);
|
||||
});
|
||||
|
||||
// custom property
|
||||
it.each([
|
||||
['--fooBar', '--fooBar'],
|
||||
['--foo-bar', '--foo-bar'],
|
||||
['--foo-100', '--foo-100'],
|
||||
['--test_ing', '--test_ing'],
|
||||
])('does not transform custom property "%s"', (property, expected) => {
|
||||
expect(camelCase(property)).toBe(expected);
|
||||
});
|
||||
|
||||
// vendor prefix
|
||||
it.each([
|
||||
['-khtml-transition', 'khtmlTransition'],
|
||||
['-moz-user-select', 'mozUserSelect'],
|
||||
['-ms-transform', 'msTransform'],
|
||||
['-ms-user-select', 'msUserSelect'],
|
||||
['-o-transition', 'oTransition'],
|
||||
['-webkit-transition', 'webkitTransition'],
|
||||
['-webkit-user-select', 'webkitUserSelect'],
|
||||
])('transforms vendor prefix "%s" to "%s"', (property, expected) => {
|
||||
expect(camelCase(property)).toBe(expected);
|
||||
});
|
||||
|
||||
it.each([
|
||||
['foo-bar', 'fooBar'],
|
||||
['foo-bar-baz', 'fooBarBaz'],
|
||||
['CAMEL-CASE', 'camelCase'],
|
||||
])('transforms "%s" to "%s"', (property, expected) => {
|
||||
expect(camelCase(property)).toBe(expected);
|
||||
});
|
||||
|
||||
describe('option reactCompat is true', () => {
|
||||
const options = { reactCompat: true };
|
||||
|
||||
it.each([
|
||||
['-khtml-transition', 'KhtmlTransition'],
|
||||
['-o-transition', 'OTransition'],
|
||||
['-moz-user-select', 'MozUserSelect'],
|
||||
['-ms-transform', 'msTransform'],
|
||||
['-ms-user-select', 'msUserSelect'],
|
||||
['-webkit-transition', 'WebkitTransition'],
|
||||
['-webkit-user-select', 'WebkitUserSelect'],
|
||||
])('capitalizes vendor prefix "%s" to "%s"', (property, expected) => {
|
||||
expect(camelCase(property, options)).toBe(expected);
|
||||
});
|
||||
});
|
||||
});
|
||||
+52
@@ -0,0 +1,52 @@
|
||||
const CUSTOM_PROPERTY_REGEX = /^--[a-zA-Z0-9_-]+$/;
|
||||
const HYPHEN_REGEX = /-([a-z])/g;
|
||||
const NO_HYPHEN_REGEX = /^[^-]+$/;
|
||||
const VENDOR_PREFIX_REGEX = /^-(webkit|moz|ms|o|khtml)-/;
|
||||
const MS_VENDOR_PREFIX_REGEX = /^-(ms)-/;
|
||||
|
||||
/**
|
||||
* Checks whether to skip camelCase.
|
||||
*/
|
||||
const skipCamelCase = (property: string) =>
|
||||
!property ||
|
||||
NO_HYPHEN_REGEX.test(property) ||
|
||||
CUSTOM_PROPERTY_REGEX.test(property);
|
||||
|
||||
/**
|
||||
* Replacer that capitalizes first character.
|
||||
*/
|
||||
const capitalize = (match: string, character: string) =>
|
||||
character.toUpperCase();
|
||||
|
||||
/**
|
||||
* Replacer that removes beginning hyphen of vendor prefix property.
|
||||
*/
|
||||
const trimHyphen = (match: string, prefix: string) => `${prefix}-`;
|
||||
|
||||
/**
|
||||
* CamelCase options.
|
||||
*/
|
||||
export interface CamelCaseOptions {
|
||||
reactCompat?: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
* CamelCases a CSS property.
|
||||
*/
|
||||
export const camelCase = (property: string, options: CamelCaseOptions = {}) => {
|
||||
if (skipCamelCase(property)) {
|
||||
return property;
|
||||
}
|
||||
|
||||
property = property.toLowerCase();
|
||||
|
||||
if (options.reactCompat) {
|
||||
// `-ms` vendor prefix should not be capitalized
|
||||
property = property.replace(MS_VENDOR_PREFIX_REGEX, trimHyphen);
|
||||
} else {
|
||||
// for non-React, remove first hyphen so vendor prefix is not capitalized
|
||||
property = property.replace(VENDOR_PREFIX_REGEX, trimHyphen);
|
||||
}
|
||||
|
||||
return property.replace(HYPHEN_REGEX, capitalize);
|
||||
};
|
||||
+429
@@ -0,0 +1,429 @@
|
||||
(function (global, factory) {
|
||||
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
|
||||
typeof define === 'function' && define.amd ? define(factory) :
|
||||
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.StyleToJS = factory());
|
||||
})(this, (function () { 'use strict';
|
||||
|
||||
function getDefaultExportFromCjs (x) {
|
||||
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
|
||||
}
|
||||
|
||||
var cjs$2 = {};
|
||||
|
||||
var cjs$1;
|
||||
var hasRequiredCjs$2;
|
||||
|
||||
function requireCjs$2 () {
|
||||
if (hasRequiredCjs$2) return cjs$1;
|
||||
hasRequiredCjs$2 = 1;
|
||||
|
||||
// http://www.w3.org/TR/CSS21/grammar.html
|
||||
// https://github.com/visionmedia/css-parse/pull/49#issuecomment-30088027
|
||||
var COMMENT_REGEX = /\/\*[^*]*\*+([^/*][^*]*\*+)*\//g;
|
||||
|
||||
var NEWLINE_REGEX = /\n/g;
|
||||
var WHITESPACE_REGEX = /^\s*/;
|
||||
|
||||
// declaration
|
||||
var PROPERTY_REGEX = /^(\*?[-#/*\\\w]+(\[[0-9a-z_-]+\])?)\s*/;
|
||||
var COLON_REGEX = /^:\s*/;
|
||||
var VALUE_REGEX = /^((?:'(?:\\'|.)*?'|"(?:\\"|.)*?"|\([^)]*?\)|[^};])+)/;
|
||||
var SEMICOLON_REGEX = /^[;\s]*/;
|
||||
|
||||
// https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String/Trim#Polyfill
|
||||
var TRIM_REGEX = /^\s+|\s+$/g;
|
||||
|
||||
// strings
|
||||
var NEWLINE = '\n';
|
||||
var FORWARD_SLASH = '/';
|
||||
var ASTERISK = '*';
|
||||
var EMPTY_STRING = '';
|
||||
|
||||
// types
|
||||
var TYPE_COMMENT = 'comment';
|
||||
var TYPE_DECLARATION = 'declaration';
|
||||
|
||||
/**
|
||||
* @param {String} style
|
||||
* @param {Object} [options]
|
||||
* @return {Object[]}
|
||||
* @throws {TypeError}
|
||||
* @throws {Error}
|
||||
*/
|
||||
function index (style, options) {
|
||||
if (typeof style !== 'string') {
|
||||
throw new TypeError('First argument must be a string');
|
||||
}
|
||||
|
||||
if (!style) return [];
|
||||
|
||||
options = options || {};
|
||||
|
||||
/**
|
||||
* Positional.
|
||||
*/
|
||||
var lineno = 1;
|
||||
var column = 1;
|
||||
|
||||
/**
|
||||
* Update lineno and column based on `str`.
|
||||
*
|
||||
* @param {String} str
|
||||
*/
|
||||
function updatePosition(str) {
|
||||
var lines = str.match(NEWLINE_REGEX);
|
||||
if (lines) lineno += lines.length;
|
||||
var i = str.lastIndexOf(NEWLINE);
|
||||
column = ~i ? str.length - i : column + str.length;
|
||||
}
|
||||
|
||||
/**
|
||||
* Mark position and patch `node.position`.
|
||||
*
|
||||
* @return {Function}
|
||||
*/
|
||||
function position() {
|
||||
var start = { line: lineno, column: column };
|
||||
return function (node) {
|
||||
node.position = new Position(start);
|
||||
whitespace();
|
||||
return node;
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Store position information for a node.
|
||||
*
|
||||
* @constructor
|
||||
* @property {Object} start
|
||||
* @property {Object} end
|
||||
* @property {undefined|String} source
|
||||
*/
|
||||
function Position(start) {
|
||||
this.start = start;
|
||||
this.end = { line: lineno, column: column };
|
||||
this.source = options.source;
|
||||
}
|
||||
|
||||
/**
|
||||
* Non-enumerable source string.
|
||||
*/
|
||||
Position.prototype.content = style;
|
||||
|
||||
/**
|
||||
* Error `msg`.
|
||||
*
|
||||
* @param {String} msg
|
||||
* @throws {Error}
|
||||
*/
|
||||
function error(msg) {
|
||||
var err = new Error(
|
||||
options.source + ':' + lineno + ':' + column + ': ' + msg
|
||||
);
|
||||
err.reason = msg;
|
||||
err.filename = options.source;
|
||||
err.line = lineno;
|
||||
err.column = column;
|
||||
err.source = style;
|
||||
|
||||
if (options.silent) ; else {
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Match `re` and return captures.
|
||||
*
|
||||
* @param {RegExp} re
|
||||
* @return {undefined|Array}
|
||||
*/
|
||||
function match(re) {
|
||||
var m = re.exec(style);
|
||||
if (!m) return;
|
||||
var str = m[0];
|
||||
updatePosition(str);
|
||||
style = style.slice(str.length);
|
||||
return m;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse whitespace.
|
||||
*/
|
||||
function whitespace() {
|
||||
match(WHITESPACE_REGEX);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse comments.
|
||||
*
|
||||
* @param {Object[]} [rules]
|
||||
* @return {Object[]}
|
||||
*/
|
||||
function comments(rules) {
|
||||
var c;
|
||||
rules = rules || [];
|
||||
while ((c = comment())) {
|
||||
if (c !== false) {
|
||||
rules.push(c);
|
||||
}
|
||||
}
|
||||
return rules;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse comment.
|
||||
*
|
||||
* @return {Object}
|
||||
* @throws {Error}
|
||||
*/
|
||||
function comment() {
|
||||
var pos = position();
|
||||
if (FORWARD_SLASH != style.charAt(0) || ASTERISK != style.charAt(1)) return;
|
||||
|
||||
var i = 2;
|
||||
while (
|
||||
EMPTY_STRING != style.charAt(i) &&
|
||||
(ASTERISK != style.charAt(i) || FORWARD_SLASH != style.charAt(i + 1))
|
||||
) {
|
||||
++i;
|
||||
}
|
||||
i += 2;
|
||||
|
||||
if (EMPTY_STRING === style.charAt(i - 1)) {
|
||||
return error('End of comment missing');
|
||||
}
|
||||
|
||||
var str = style.slice(2, i - 2);
|
||||
column += 2;
|
||||
updatePosition(str);
|
||||
style = style.slice(i);
|
||||
column += 2;
|
||||
|
||||
return pos({
|
||||
type: TYPE_COMMENT,
|
||||
comment: str
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse declaration.
|
||||
*
|
||||
* @return {Object}
|
||||
* @throws {Error}
|
||||
*/
|
||||
function declaration() {
|
||||
var pos = position();
|
||||
|
||||
// prop
|
||||
var prop = match(PROPERTY_REGEX);
|
||||
if (!prop) return;
|
||||
comment();
|
||||
|
||||
// :
|
||||
if (!match(COLON_REGEX)) return error("property missing ':'");
|
||||
|
||||
// val
|
||||
var val = match(VALUE_REGEX);
|
||||
|
||||
var ret = pos({
|
||||
type: TYPE_DECLARATION,
|
||||
property: trim(prop[0].replace(COMMENT_REGEX, EMPTY_STRING)),
|
||||
value: val
|
||||
? trim(val[0].replace(COMMENT_REGEX, EMPTY_STRING))
|
||||
: EMPTY_STRING
|
||||
});
|
||||
|
||||
// ;
|
||||
match(SEMICOLON_REGEX);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse declarations.
|
||||
*
|
||||
* @return {Object[]}
|
||||
*/
|
||||
function declarations() {
|
||||
var decls = [];
|
||||
|
||||
comments(decls);
|
||||
|
||||
// declarations
|
||||
var decl;
|
||||
while ((decl = declaration())) {
|
||||
if (decl !== false) {
|
||||
decls.push(decl);
|
||||
comments(decls);
|
||||
}
|
||||
}
|
||||
|
||||
return decls;
|
||||
}
|
||||
|
||||
whitespace();
|
||||
return declarations();
|
||||
}
|
||||
|
||||
/**
|
||||
* Trim `str`.
|
||||
*
|
||||
* @param {String} str
|
||||
* @return {String}
|
||||
*/
|
||||
function trim(str) {
|
||||
return str ? str.replace(TRIM_REGEX, EMPTY_STRING) : EMPTY_STRING;
|
||||
}
|
||||
|
||||
cjs$1 = index;
|
||||
|
||||
return cjs$1;
|
||||
}
|
||||
|
||||
var hasRequiredCjs$1;
|
||||
|
||||
function requireCjs$1 () {
|
||||
if (hasRequiredCjs$1) return cjs$2;
|
||||
hasRequiredCjs$1 = 1;
|
||||
var __importDefault = (cjs$2 && cjs$2.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(cjs$2, "__esModule", { value: true });
|
||||
cjs$2.default = StyleToObject;
|
||||
const inline_style_parser_1 = __importDefault(requireCjs$2());
|
||||
/**
|
||||
* Parses inline style to object.
|
||||
*
|
||||
* @param style - Inline style.
|
||||
* @param iterator - Iterator.
|
||||
* @returns - Style object or null.
|
||||
*
|
||||
* @example Parsing inline style to object:
|
||||
*
|
||||
* ```js
|
||||
* import parse from 'style-to-object';
|
||||
* parse('line-height: 42;'); // { 'line-height': '42' }
|
||||
* ```
|
||||
*/
|
||||
function StyleToObject(style, iterator) {
|
||||
let styleObject = null;
|
||||
if (!style || typeof style !== 'string') {
|
||||
return styleObject;
|
||||
}
|
||||
const declarations = (0, inline_style_parser_1.default)(style);
|
||||
const hasIterator = typeof iterator === 'function';
|
||||
declarations.forEach((declaration) => {
|
||||
if (declaration.type !== 'declaration') {
|
||||
return;
|
||||
}
|
||||
const { property, value } = declaration;
|
||||
if (hasIterator) {
|
||||
iterator(property, value, declaration);
|
||||
}
|
||||
else if (value) {
|
||||
styleObject = styleObject || {};
|
||||
styleObject[property] = value;
|
||||
}
|
||||
});
|
||||
return styleObject;
|
||||
}
|
||||
|
||||
return cjs$2;
|
||||
}
|
||||
|
||||
var utilities = {};
|
||||
|
||||
var hasRequiredUtilities;
|
||||
|
||||
function requireUtilities () {
|
||||
if (hasRequiredUtilities) return utilities;
|
||||
hasRequiredUtilities = 1;
|
||||
Object.defineProperty(utilities, "__esModule", { value: true });
|
||||
utilities.camelCase = void 0;
|
||||
var CUSTOM_PROPERTY_REGEX = /^--[a-zA-Z0-9_-]+$/;
|
||||
var HYPHEN_REGEX = /-([a-z])/g;
|
||||
var NO_HYPHEN_REGEX = /^[^-]+$/;
|
||||
var VENDOR_PREFIX_REGEX = /^-(webkit|moz|ms|o|khtml)-/;
|
||||
var MS_VENDOR_PREFIX_REGEX = /^-(ms)-/;
|
||||
/**
|
||||
* Checks whether to skip camelCase.
|
||||
*/
|
||||
var skipCamelCase = function (property) {
|
||||
return !property ||
|
||||
NO_HYPHEN_REGEX.test(property) ||
|
||||
CUSTOM_PROPERTY_REGEX.test(property);
|
||||
};
|
||||
/**
|
||||
* Replacer that capitalizes first character.
|
||||
*/
|
||||
var capitalize = function (match, character) {
|
||||
return character.toUpperCase();
|
||||
};
|
||||
/**
|
||||
* Replacer that removes beginning hyphen of vendor prefix property.
|
||||
*/
|
||||
var trimHyphen = function (match, prefix) { return "".concat(prefix, "-"); };
|
||||
/**
|
||||
* CamelCases a CSS property.
|
||||
*/
|
||||
var camelCase = function (property, options) {
|
||||
if (options === void 0) { options = {}; }
|
||||
if (skipCamelCase(property)) {
|
||||
return property;
|
||||
}
|
||||
property = property.toLowerCase();
|
||||
if (options.reactCompat) {
|
||||
// `-ms` vendor prefix should not be capitalized
|
||||
property = property.replace(MS_VENDOR_PREFIX_REGEX, trimHyphen);
|
||||
}
|
||||
else {
|
||||
// for non-React, remove first hyphen so vendor prefix is not capitalized
|
||||
property = property.replace(VENDOR_PREFIX_REGEX, trimHyphen);
|
||||
}
|
||||
return property.replace(HYPHEN_REGEX, capitalize);
|
||||
};
|
||||
utilities.camelCase = camelCase;
|
||||
|
||||
return utilities;
|
||||
}
|
||||
|
||||
var cjs;
|
||||
var hasRequiredCjs;
|
||||
|
||||
function requireCjs () {
|
||||
if (hasRequiredCjs) return cjs;
|
||||
hasRequiredCjs = 1;
|
||||
var __importDefault = (cjs && cjs.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
var style_to_object_1 = __importDefault(requireCjs$1());
|
||||
var utilities_1 = requireUtilities();
|
||||
/**
|
||||
* Parses CSS inline style to JavaScript object (camelCased).
|
||||
*/
|
||||
function StyleToJS(style, options) {
|
||||
var output = {};
|
||||
if (!style || typeof style !== 'string') {
|
||||
return output;
|
||||
}
|
||||
(0, style_to_object_1.default)(style, function (property, value) {
|
||||
// skip CSS comment
|
||||
if (property && value) {
|
||||
output[(0, utilities_1.camelCase)(property, options)] = value;
|
||||
}
|
||||
});
|
||||
return output;
|
||||
}
|
||||
StyleToJS.default = StyleToJS;
|
||||
cjs = StyleToJS;
|
||||
|
||||
return cjs;
|
||||
}
|
||||
|
||||
var cjsExports = requireCjs();
|
||||
var index = /*@__PURE__*/getDefaultExportFromCjs(cjsExports);
|
||||
|
||||
return index;
|
||||
|
||||
}));
|
||||
//# sourceMappingURL=style-to-js.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"style-to-js.js","sources":["../node_modules/inline-style-parser/cjs/index.js","../node_modules/style-to-object/cjs/index.js","../cjs/utilities.js","../cjs/index.js","../cjs/index.js?commonjs-entry"],"sourcesContent":["'use strict';\n\n// http://www.w3.org/TR/CSS21/grammar.html\n// https://github.com/visionmedia/css-parse/pull/49#issuecomment-30088027\nvar COMMENT_REGEX = /\\/\\*[^*]*\\*+([^/*][^*]*\\*+)*\\//g;\n\nvar NEWLINE_REGEX = /\\n/g;\nvar WHITESPACE_REGEX = /^\\s*/;\n\n// declaration\nvar PROPERTY_REGEX = /^(\\*?[-#/*\\\\\\w]+(\\[[0-9a-z_-]+\\])?)\\s*/;\nvar COLON_REGEX = /^:\\s*/;\nvar VALUE_REGEX = /^((?:'(?:\\\\'|.)*?'|\"(?:\\\\\"|.)*?\"|\\([^)]*?\\)|[^};])+)/;\nvar SEMICOLON_REGEX = /^[;\\s]*/;\n\n// https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String/Trim#Polyfill\nvar TRIM_REGEX = /^\\s+|\\s+$/g;\n\n// strings\nvar NEWLINE = '\\n';\nvar FORWARD_SLASH = '/';\nvar ASTERISK = '*';\nvar EMPTY_STRING = '';\n\n// types\nvar TYPE_COMMENT = 'comment';\nvar TYPE_DECLARATION = 'declaration';\n\n/**\n * @param {String} style\n * @param {Object} [options]\n * @return {Object[]}\n * @throws {TypeError}\n * @throws {Error}\n */\nfunction index (style, options) {\n if (typeof style !== 'string') {\n throw new TypeError('First argument must be a string');\n }\n\n if (!style) return [];\n\n options = options || {};\n\n /**\n * Positional.\n */\n var lineno = 1;\n var column = 1;\n\n /**\n * Update lineno and column based on `str`.\n *\n * @param {String} str\n */\n function updatePosition(str) {\n var lines = str.match(NEWLINE_REGEX);\n if (lines) lineno += lines.length;\n var i = str.lastIndexOf(NEWLINE);\n column = ~i ? str.length - i : column + str.length;\n }\n\n /**\n * Mark position and patch `node.position`.\n *\n * @return {Function}\n */\n function position() {\n var start = { line: lineno, column: column };\n return function (node) {\n node.position = new Position(start);\n whitespace();\n return node;\n };\n }\n\n /**\n * Store position information for a node.\n *\n * @constructor\n * @property {Object} start\n * @property {Object} end\n * @property {undefined|String} source\n */\n function Position(start) {\n this.start = start;\n this.end = { line: lineno, column: column };\n this.source = options.source;\n }\n\n /**\n * Non-enumerable source string.\n */\n Position.prototype.content = style;\n\n /**\n * Error `msg`.\n *\n * @param {String} msg\n * @throws {Error}\n */\n function error(msg) {\n var err = new Error(\n options.source + ':' + lineno + ':' + column + ': ' + msg\n );\n err.reason = msg;\n err.filename = options.source;\n err.line = lineno;\n err.column = column;\n err.source = style;\n\n if (options.silent) ; else {\n throw err;\n }\n }\n\n /**\n * Match `re` and return captures.\n *\n * @param {RegExp} re\n * @return {undefined|Array}\n */\n function match(re) {\n var m = re.exec(style);\n if (!m) return;\n var str = m[0];\n updatePosition(str);\n style = style.slice(str.length);\n return m;\n }\n\n /**\n * Parse whitespace.\n */\n function whitespace() {\n match(WHITESPACE_REGEX);\n }\n\n /**\n * Parse comments.\n *\n * @param {Object[]} [rules]\n * @return {Object[]}\n */\n function comments(rules) {\n var c;\n rules = rules || [];\n while ((c = comment())) {\n if (c !== false) {\n rules.push(c);\n }\n }\n return rules;\n }\n\n /**\n * Parse comment.\n *\n * @return {Object}\n * @throws {Error}\n */\n function comment() {\n var pos = position();\n if (FORWARD_SLASH != style.charAt(0) || ASTERISK != style.charAt(1)) return;\n\n var i = 2;\n while (\n EMPTY_STRING != style.charAt(i) &&\n (ASTERISK != style.charAt(i) || FORWARD_SLASH != style.charAt(i + 1))\n ) {\n ++i;\n }\n i += 2;\n\n if (EMPTY_STRING === style.charAt(i - 1)) {\n return error('End of comment missing');\n }\n\n var str = style.slice(2, i - 2);\n column += 2;\n updatePosition(str);\n style = style.slice(i);\n column += 2;\n\n return pos({\n type: TYPE_COMMENT,\n comment: str\n });\n }\n\n /**\n * Parse declaration.\n *\n * @return {Object}\n * @throws {Error}\n */\n function declaration() {\n var pos = position();\n\n // prop\n var prop = match(PROPERTY_REGEX);\n if (!prop) return;\n comment();\n\n // :\n if (!match(COLON_REGEX)) return error(\"property missing ':'\");\n\n // val\n var val = match(VALUE_REGEX);\n\n var ret = pos({\n type: TYPE_DECLARATION,\n property: trim(prop[0].replace(COMMENT_REGEX, EMPTY_STRING)),\n value: val\n ? trim(val[0].replace(COMMENT_REGEX, EMPTY_STRING))\n : EMPTY_STRING\n });\n\n // ;\n match(SEMICOLON_REGEX);\n\n return ret;\n }Line truncated
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).StyleToJS=t()}(this,(function(){"use strict";function e(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var t,r,n,o={};function u(){if(n)return o;n=1;var e=o&&o.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(o,"__esModule",{value:!0}),o.default=function(e,t){let r=null;if(!e||"string"!=typeof e)return r;const n=(0,u.default)(e),o="function"==typeof t;return n.forEach((e=>{if("declaration"!==e.type)return;const{property:n,value:u}=e;o?t(n,u,e):u&&(r=r||{},r[n]=u)})),r};const u=e(function(){if(r)return t;r=1;var e=/\/\*[^*]*\*+([^/*][^*]*\*+)*\//g,n=/\n/g,o=/^\s*/,u=/^(\*?[-#/*\\\w]+(\[[0-9a-z_-]+\])?)\s*/,i=/^:\s*/,a=/^((?:'(?:\\'|.)*?'|"(?:\\"|.)*?"|\([^)]*?\)|[^};])+)/,c=/^[;\s]*/,f=/^\s+|\s+$/g,l="";function s(e){return e?e.replace(f,l):l}return t=function(t,r){if("string"!=typeof t)throw new TypeError("First argument must be a string");if(!t)return[];r=r||{};var f=1,p=1;function d(e){var t=e.match(n);t&&(f+=t.length);var r=e.lastIndexOf("\n");p=~r?e.length-r:p+e.length}function m(){var e={line:f,column:p};return function(t){return t.position=new v(e),g(),t}}function v(e){this.start=e,this.end={line:f,column:p},this.source=r.source}function h(e){var n=new Error(r.source+":"+f+":"+p+": "+e);if(n.reason=e,n.filename=r.source,n.line=f,n.column=p,n.source=t,!r.silent)throw n}function y(e){var r=e.exec(t);if(r){var n=r[0];return d(n),t=t.slice(n.length),r}}function g(){y(o)}function _(e){var t;for(e=e||[];t=w();)!1!==t&&e.push(t);return e}function w(){var e=m();if("/"==t.charAt(0)&&"*"==t.charAt(1)){for(var r=2;l!=t.charAt(r)&&("*"!=t.charAt(r)||"/"!=t.charAt(r+1));)++r;if(r+=2,l===t.charAt(r-1))return h("End of comment missing");var n=t.slice(2,r-2);return p+=2,d(n),t=t.slice(r),p+=2,e({type:"comment",comment:n})}}function b(){var t=m(),r=y(u);if(r){if(w(),!y(i))return h("property missing ':'");var n=y(a),o=t({type:"declaration",property:s(r[0].replace(e,l)),value:n?s(n[0].replace(e,l)):l});return y(c),o}}return v.prototype.content=t,g(),function(){var e,t=[];for(_(t);e=b();)!1!==e&&(t.push(e),_(t));return t}()}}());return o}var i,a,c,f={};function l(){if(i)return f;i=1,Object.defineProperty(f,"__esModule",{value:!0}),f.camelCase=void 0;var e=/^--[a-zA-Z0-9_-]+$/,t=/-([a-z])/g,r=/^[^-]+$/,n=/^-(webkit|moz|ms|o|khtml)-/,o=/^-(ms)-/,u=function(e,t){return t.toUpperCase()},a=function(e,t){return"".concat(t,"-")};return f.camelCase=function(i,c){return void 0===c&&(c={}),function(t){return!t||r.test(t)||e.test(t)}(i)?i:(i=i.toLowerCase(),(i=c.reactCompat?i.replace(o,a):i.replace(n,a)).replace(t,u))},f}return e(function(){if(c)return a;c=1;var e=(a&&a.__importDefault||function(e){return e&&e.__esModule?e:{default:e}})(u()),t=l();function r(r,n){var o={};return r&&"string"==typeof r?((0,e.default)(r,(function(e,r){e&&r&&(o[(0,t.camelCase)(e,n)]=r)})),o):o}return r.default=r,a=r}())}));
|
||||
//# sourceMappingURL=style-to-js.min.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"style-to-js.min.js","sources":["../node_modules/style-to-object/cjs/index.js","../node_modules/inline-style-parser/cjs/index.js","../cjs/utilities.js","../cjs/index.js?commonjs-entry","../cjs/index.js"],"sourcesContent":["\"use strict\";\nvar __importDefault = (this && this.__importDefault) || function (mod) {\n return (mod && mod.__esModule) ? mod : { \"default\": mod };\n};\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.default = StyleToObject;\nconst inline_style_parser_1 = __importDefault(require(\"inline-style-parser\"));\n/**\n * Parses inline style to object.\n *\n * @param style - Inline style.\n * @param iterator - Iterator.\n * @returns - Style object or null.\n *\n * @example Parsing inline style to object:\n *\n * ```js\n * import parse from 'style-to-object';\n * parse('line-height: 42;'); // { 'line-height': '42' }\n * ```\n */\nfunction StyleToObject(style, iterator) {\n let styleObject = null;\n if (!style || typeof style !== 'string') {\n return styleObject;\n }\n const declarations = (0, inline_style_parser_1.default)(style);\n const hasIterator = typeof iterator === 'function';\n declarations.forEach((declaration) => {\n if (declaration.type !== 'declaration') {\n return;\n }\n const { property, value } = declaration;\n if (hasIterator) {\n iterator(property, value, declaration);\n }\n else if (value) {\n styleObject = styleObject || {};\n styleObject[property] = value;\n }\n });\n return styleObject;\n}\n//# sourceMappingURL=index.js.map","'use strict';\n\n// http://www.w3.org/TR/CSS21/grammar.html\n// https://github.com/visionmedia/css-parse/pull/49#issuecomment-30088027\nvar COMMENT_REGEX = /\\/\\*[^*]*\\*+([^/*][^*]*\\*+)*\\//g;\n\nvar NEWLINE_REGEX = /\\n/g;\nvar WHITESPACE_REGEX = /^\\s*/;\n\n// declaration\nvar PROPERTY_REGEX = /^(\\*?[-#/*\\\\\\w]+(\\[[0-9a-z_-]+\\])?)\\s*/;\nvar COLON_REGEX = /^:\\s*/;\nvar VALUE_REGEX = /^((?:'(?:\\\\'|.)*?'|\"(?:\\\\\"|.)*?\"|\\([^)]*?\\)|[^};])+)/;\nvar SEMICOLON_REGEX = /^[;\\s]*/;\n\n// https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String/Trim#Polyfill\nvar TRIM_REGEX = /^\\s+|\\s+$/g;\n\n// strings\nvar NEWLINE = '\\n';\nvar FORWARD_SLASH = '/';\nvar ASTERISK = '*';\nvar EMPTY_STRING = '';\n\n// types\nvar TYPE_COMMENT = 'comment';\nvar TYPE_DECLARATION = 'declaration';\n\n/**\n * @param {String} style\n * @param {Object} [options]\n * @return {Object[]}\n * @throws {TypeError}\n * @throws {Error}\n */\nfunction index (style, options) {\n if (typeof style !== 'string') {\n throw new TypeError('First argument must be a string');\n }\n\n if (!style) return [];\n\n options = options || {};\n\n /**\n * Positional.\n */\n var lineno = 1;\n var column = 1;\n\n /**\n * Update lineno and column based on `str`.\n *\n * @param {String} str\n */\n function updatePosition(str) {\n var lines = str.match(NEWLINE_REGEX);\n if (lines) lineno += lines.length;\n var i = str.lastIndexOf(NEWLINE);\n column = ~i ? str.length - i : column + str.length;\n }\n\n /**\n * Mark position and patch `node.position`.\n *\n * @return {Function}\n */\n function position() {\n var start = { line: lineno, column: column };\n return function (node) {\n node.position = new Position(start);\n whitespace();\n return node;\n };\n }\n\n /**\n * Store position information for a node.\n *\n * @constructor\n * @property {Object} start\n * @property {Object} end\n * @property {undefined|String} source\n */\n function Position(start) {\n this.start = start;\n this.end = { line: lineno, column: column };\n this.source = options.source;\n }\n\n /**\n * Non-enumerable source string.\n */\n Position.prototype.content = style;\n\n /**\n * Error `msg`.\n *\n * @param {String} msg\n * @throws {Error}\n */\n function error(msg) {\n var err = new Error(\n options.source + ':' + lineno + ':' + column + ': ' + msg\n );\n err.reason = msg;\n err.filename = options.source;\n err.line = lineno;\n err.column = column;\n err.source = style;\n\n if (options.silent) ; else {\n throw err;\n }\n }\n\n /**\n * Match `re` and return captures.\n *\n * @param {RegExp} re\n * @return {undefined|Array}\n */\n function match(re) {\n var m = re.exec(style);\n if (!m) return;\n var str = m[0];\n updatePosition(str);\n style = style.slice(str.length);\n return m;\n }\n\n /**\n * Parse whitespace.\n */\n function whitespace() {\n match(WHITESPACE_REGEX);\n }\n\n /**\n * Parse comments.\n *\n * @param {Object[]} [rules]\n * @return {Object[]}\n */\n function comments(rules) {\n var c;\n rules = rules || [];\n while ((c = comment())) {\n if (c !== false) {\n rules.push(c);\n }\n }\n Line truncated
|
||||
Reference in new issue
Block a user