From 1cae3345ba223edeb2a828847fae11918391462c Mon Sep 17 00:00:00 2001 From: "asamuzaK (Kazz)" Date: Sat, 16 Nov 2024 10:56:02 +0900 Subject: [PATCH 1/6] Add css-color --- lib/parsers.js | 12 +- package-lock.json | 404 +++++++++++++++++++++++----------------------- package.json | 1 + test/parsers.js | 37 +++++ 4 files changed, 252 insertions(+), 202 deletions(-) diff --git a/lib/parsers.js b/lib/parsers.js index 887bd51..bacd50e 100644 --- a/lib/parsers.js +++ b/lib/parsers.js @@ -4,6 +4,7 @@ ********************************************************************/ 'use strict'; +const { resolve } = require('@asamuzakjp/css-color'); const namedColors = require('./named_colors.json'); const { hslToRgb } = require('./utils/colorSpace'); @@ -323,7 +324,7 @@ exports.parseColor = function parseColor(val) { return 'rgb(' + red + ', ' + green + ', ' + blue + ')'; } - res = colorRegEx2.exec(val); + res = val.includes(',') && colorRegEx2.exec(val); if (res) { parts = res[1].split(/\s*,\s*/); if (parts.length !== 3) { @@ -346,7 +347,7 @@ exports.parseColor = function parseColor(val) { return 'rgb(' + red + ', ' + green + ', ' + blue + ')'; } - res = colorRegEx3.exec(val); + res = val.includes(',') && colorRegEx3.exec(val); if (res) { parts = res[1].split(/\s*,\s*/); if (parts.length !== 4) { @@ -402,6 +403,13 @@ exports.parseColor = function parseColor(val) { if (type === exports.TYPES.COLOR) { return val; } + + res = resolve(val, { + format: 'specifiedValue', + }); + if (res) { + return res; + } return undefined; }; diff --git a/package-lock.json b/package-lock.json index f18d9a6..a6bb36b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,6 +9,7 @@ "version": "4.1.0", "license": "MIT", "dependencies": { + "@asamuzakjp/css-color": "^2.2.1", "rrweb-cssom": "^0.7.1" }, "devDependencies": { @@ -28,6 +29,16 @@ "node": ">=18" } }, + "node_modules/@asamuzakjp/css-color": { + "version": "2.2.1", + "resolved": "https://registry.npmjs.org/@asamuzakjp/css-color/-/css-color-2.2.1.tgz", + "integrity": "sha512-4/RoWIs1GTq3Bm7Xyh1cjRC1h+nyMqoB23Twr5vnbyNqWx5FTbBq7Pb70IovyL6vZbi8vlsoyx03bIBl0U61FA==", + "license": "MIT", + "dependencies": { + "@csstools/css-calc": "^2.1.0", + "lru-cache": "^11.0.2" + } + }, "node_modules/@babel/code-frame": { "version": "7.24.7", "resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.24.7.tgz", @@ -169,6 +180,72 @@ "node": ">=6.9.0" } }, + "node_modules/@csstools/css-calc": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/@csstools/css-calc/-/css-calc-2.1.0.tgz", + "integrity": "sha512-X69PmFOrjTZfN5ijxtI8hZ9kRADFSLrmmQ6hgDJ272Il049WGKpDY64KhrFm/7rbWve0z81QepawzjkKlqkNGw==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/csstools" + }, + { + "type": "opencollective", + "url": "https://opencollective.com/csstools" + } + ], + "license": "MIT", + "engines": { + "node": ">=18" + }, + "peerDependencies": { + "@csstools/css-parser-algorithms": "^3.0.4", + "@csstools/css-tokenizer": "^3.0.3" + } + }, + "node_modules/@csstools/css-parser-algorithms": { + "version": "3.0.4", + "resolved": "https://registry.npmjs.org/@csstools/css-parser-algorithms/-/css-parser-algorithms-3.0.4.tgz", + "integrity": "sha512-Up7rBoV77rv29d3uKHUIVubz1BTcgyUK72IvCQAbfbMv584xHcGKCKbWh7i8hPrRJ7qU4Y8IO3IY9m+iTB7P3A==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/csstools" + }, + { + "type": "opencollective", + "url": "https://opencollective.com/csstools" + } + ], + "license": "MIT", + "peer": true, + "engines": { + "node": ">=18" + }, + "peerDependencies": { + "@csstools/css-tokenizer": "^3.0.3" + } + }, + "node_modules/@csstools/css-tokenizer": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/@csstools/css-tokenizer/-/css-tokenizer-3.0.3.tgz", + "integrity": "sha512-UJnjoFsmxfKUdNYdWgOB0mWUypuLvAfQPH1+pyvRJs6euowbFkFC6P13w1l8mJyi3vxYMxc9kld5jZEGRQs6bw==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/csstools" + }, + { + "type": "opencollective", + "url": "https://opencollective.com/csstools" + } + ], + "license": "MIT", + "peer": true, + "engines": { + "node": ">=18" + } + }, "node_modules/@eslint-community/eslint-utils": { "version": "4.4.0", "resolved": "https://registry.npmjs.org/@eslint-community/eslint-utils/-/eslint-utils-4.4.0.tgz", @@ -199,9 +276,9 @@ } }, "node_modules/@eslint-community/regexpp": { - "version": "4.11.0", - "resolved": "https://registry.npmjs.org/@eslint-community/regexpp/-/regexpp-4.11.0.tgz", - "integrity": "sha512-G/M/tIiMrTAxEWRfLfQJMmGNX28IxBg4PBz8XqQhqUHLFI6TL2htpIB1iQCj144V5ee/JaKyT9/WZ0MGZWfA7A==", + "version": "4.12.1", + "resolved": "https://registry.npmjs.org/@eslint-community/regexpp/-/regexpp-4.12.1.tgz", + "integrity": "sha512-CCZCDJuduB9OUkFkY2IgppNZMi2lBQgD2qzwXkEia16cge2pijY/aXi96CJMquDMn3nJdlPV1A5KrJEXwfLNzQ==", "dev": true, "license": "MIT", "engines": { @@ -209,9 +286,9 @@ } }, "node_modules/@eslint/config-array": { - "version": "0.18.0", - "resolved": "https://registry.npmjs.org/@eslint/config-array/-/config-array-0.18.0.tgz", - "integrity": "sha512-fTxvnS1sRMu3+JjXwJG0j/i4RT9u4qJ+lqS/yCGap4lH4zZGzQ7tu+xZqQmcMZq5OBZDL4QRxQzRjkWcGt8IVw==", + "version": "0.19.0", + "resolved": "https://registry.npmjs.org/@eslint/config-array/-/config-array-0.19.0.tgz", + "integrity": "sha512-zdHg2FPIFNKPdcHWtiNT+jEFCHYVplAXRDlQDyqy0zGx/q2parwh7brGJSiTxRk/TSMkbM//zt/f5CHgyTyaSQ==", "dev": true, "license": "Apache-2.0", "dependencies": { @@ -223,10 +300,20 @@ "node": "^18.18.0 || ^20.9.0 || >=21.1.0" } }, + "node_modules/@eslint/core": { + "version": "0.9.0", + "resolved": "https://registry.npmjs.org/@eslint/core/-/core-0.9.0.tgz", + "integrity": "sha512-7ATR9F0e4W85D/0w7cU0SNj7qkAexMG+bAHEZOjo9akvGuhHE2m7umzWzfnpa0XAg5Kxc1BWmtPMV67jJ+9VUg==", + "dev": true, + "license": "Apache-2.0", + "engines": { + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" + } + }, "node_modules/@eslint/eslintrc": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/@eslint/eslintrc/-/eslintrc-3.1.0.tgz", - "integrity": "sha512-4Bfj15dVJdoy3RfZmmo86RK1Fwzn6SstsvK9JS+BaVKqC6QQQQyXekNaC+g+LKNgkQ+2VhGAzm6hO40AhMR3zQ==", + "version": "3.2.0", + "resolved": "https://registry.npmjs.org/@eslint/eslintrc/-/eslintrc-3.2.0.tgz", + "integrity": "sha512-grOjVNN8P3hjJn/eIETF1wwd12DdnwFDoyceUJLYYdkpbwq3nLi+4fqrTAONx7XDALqlL220wC/RHSC/QTI/0w==", "dev": true, "license": "MIT", "dependencies": { @@ -261,9 +348,9 @@ } }, "node_modules/@eslint/js": { - "version": "9.10.0", - "resolved": "https://registry.npmjs.org/@eslint/js/-/js-9.10.0.tgz", - "integrity": "sha512-fuXtbiP5GWIn8Fz+LWoOMVf/Jxm+aajZYkhi6CuEm4SxymFM+eUWzbO9qXT+L0iCkL5+KGYMCSGxo686H19S1g==", + "version": "9.15.0", + "resolved": "https://registry.npmjs.org/@eslint/js/-/js-9.15.0.tgz", + "integrity": "sha512-tMTqrY+EzbXmKJR5ToI8lxu7jaN5EdmrBFJpQk5JmSlyLsx6o4t27r883K5xsLuCYCpfKBCGswMSWXsM+jB7lg==", "dev": true, "license": "MIT", "engines": { @@ -281,9 +368,9 @@ } }, "node_modules/@eslint/plugin-kit": { - "version": "0.1.0", - "resolved": "https://registry.npmjs.org/@eslint/plugin-kit/-/plugin-kit-0.1.0.tgz", - "integrity": "sha512-autAXT203ixhqei9xt+qkYOvY8l6LAFIdT2UXc/RPNeUVfqRF1BV94GTJyVPFKT8nFM6MyVJhjLj9E8JWvf5zQ==", + "version": "0.2.3", + "resolved": "https://registry.npmjs.org/@eslint/plugin-kit/-/plugin-kit-0.2.3.tgz", + "integrity": "sha512-2b/g5hRmpbb1o4GnTZax9N9m0FXzz9OV42ZzI4rDDMDuHUqigAiQCEWChBWCY4ztAGVRjoWT19v0yMmc5/L5kA==", "dev": true, "license": "Apache-2.0", "dependencies": { @@ -293,6 +380,44 @@ "node": "^18.18.0 || ^20.9.0 || >=21.1.0" } }, + "node_modules/@humanfs/core": { + "version": "0.19.1", + "resolved": "https://registry.npmjs.org/@humanfs/core/-/core-0.19.1.tgz", + "integrity": "sha512-5DyQ4+1JEUzejeK1JGICcideyfUbGixgS9jNgex5nqkW+cY7WZhxBigmieN5Qnw9ZosSNVC9KQKyb+GUaGyKUA==", + "dev": true, + "license": "Apache-2.0", + "engines": { + "node": ">=18.18.0" + } + }, + "node_modules/@humanfs/node": { + "version": "0.16.6", + "resolved": "https://registry.npmjs.org/@humanfs/node/-/node-0.16.6.tgz", + "integrity": "sha512-YuI2ZHQL78Q5HbhDiBA1X4LmYdXCKCMQIfw0pw7piHJwyREFebJUvrQN4cMssyES6x+vfUbx1CIpaQUKYdQZOw==", + "dev": true, + "license": "Apache-2.0", + "dependencies": { + "@humanfs/core": "^0.19.1", + "@humanwhocodes/retry": "^0.3.0" + }, + "engines": { + "node": ">=18.18.0" + } + }, + "node_modules/@humanfs/node/node_modules/@humanwhocodes/retry": { + "version": "0.3.1", + "resolved": "https://registry.npmjs.org/@humanwhocodes/retry/-/retry-0.3.1.tgz", + "integrity": "sha512-JBxkERygn7Bv/GbN5Rv8Ul6LVknS+5Bp6RgDC/O8gEBU/yeH5Ui5C/OlWrTb6qct7LjjfT6Re2NxB0ln0yYybA==", + "dev": true, + "license": "Apache-2.0", + "engines": { + "node": ">=18.18" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/nzakas" + } + }, "node_modules/@humanwhocodes/module-importer": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/@humanwhocodes/module-importer/-/module-importer-1.0.1.tgz", @@ -308,9 +433,9 @@ } }, "node_modules/@humanwhocodes/retry": { - "version": "0.3.0", - "resolved": "https://registry.npmjs.org/@humanwhocodes/retry/-/retry-0.3.0.tgz", - "integrity": "sha512-d2CGZR2o7fS6sWB7DG/3a95bGKQyHMACZ5aW8qGkkqQpUoZV6C0X7Pc7l4ZNMZkfNBf4VWNe9E1jRsf0G146Ew==", + "version": "0.4.1", + "resolved": "https://registry.npmjs.org/@humanwhocodes/retry/-/retry-0.4.1.tgz", + "integrity": "sha512-c7hNEllBlenFTHBky65mhq8WD2kbN9Q6gk0bTk8lSBvc554jpXSkST1iePudpt7+A/AQvuHs9EMqjHDXMY1lrA==", "dev": true, "license": "Apache-2.0", "engines": { @@ -374,44 +499,6 @@ "@jridgewell/sourcemap-codec": "^1.4.14" } }, - "node_modules/@nodelib/fs.scandir": { - "version": "2.1.5", - "resolved": "https://registry.npmjs.org/@nodelib/fs.scandir/-/fs.scandir-2.1.5.tgz", - "integrity": "sha512-vq24Bq3ym5HEQm2NKCr3yXDwjc7vTsEThRDnkp2DK9p1uqLR+DHurm/NOTo0KG7HYHU7eppKZj3MyqYuMBf62g==", - "dev": true, - "license": "MIT", - "dependencies": { - "@nodelib/fs.stat": "2.0.5", - "run-parallel": "^1.1.9" - }, - "engines": { - "node": ">= 8" - } - }, - "node_modules/@nodelib/fs.stat": { - "version": "2.0.5", - "resolved": "https://registry.npmjs.org/@nodelib/fs.stat/-/fs.stat-2.0.5.tgz", - "integrity": "sha512-RkhPPp2zrqDAQA/2jNhnztcPAlv64XdhIp7a7454A5ovI7Bukxgt7MX7udwAu3zg1DcpPU0rz3VV1SeaqvY4+A==", - "dev": true, - "license": "MIT", - "engines": { - "node": ">= 8" - } - }, - "node_modules/@nodelib/fs.walk": { - "version": "1.2.8", - "resolved": "https://registry.npmjs.org/@nodelib/fs.walk/-/fs.walk-1.2.8.tgz", - "integrity": "sha512-oGB+UxlgWcgQkgwo8GcEGwemoTFt3FIO9ababBmaGwXIoBKZ+GTy0pP185beGg7Llih/NSHSV2XAs1lnznocSg==", - "dev": true, - "license": "MIT", - "dependencies": { - "@nodelib/fs.scandir": "2.1.5", - "fastq": "^1.6.0" - }, - "engines": { - "node": ">= 8" - } - }, "node_modules/@pkgr/core": { "version": "0.1.1", "resolved": "https://registry.npmjs.org/@pkgr/core/-/core-0.1.1.tgz", @@ -425,10 +512,24 @@ "url": "https://opencollective.com/unts" } }, + "node_modules/@types/estree": { + "version": "1.0.6", + "resolved": "https://registry.npmjs.org/@types/estree/-/estree-1.0.6.tgz", + "integrity": "sha512-AYnb1nQyY49te+VRAVgmzfcgjYS91mY5P0TKUDCLEM+gNnA+3T6rWITXRLYCpahpqSQbN5cE+gHpnPyXjHWxcw==", + "dev": true, + "license": "MIT" + }, + "node_modules/@types/json-schema": { + "version": "7.0.15", + "resolved": "https://registry.npmjs.org/@types/json-schema/-/json-schema-7.0.15.tgz", + "integrity": "sha512-5+fP8P8MFNC+AyZCDxrB2pkZFPGzqQWUzpSeuuVLvm8VMcorNYavBqoFcxK8bQz4Qsbn4oUEEem4wDLfcysGHA==", + "dev": true, + "license": "MIT" + }, "node_modules/acorn": { - "version": "8.12.1", - "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.12.1.tgz", - "integrity": "sha512-tcpGyI9zbizT9JbV6oYE477V6mTlXvvi0T0G3SNIYE2apm/G5huBa1+K89VGeovbg+jycCrfhl3ADxErOuO6Jg==", + "version": "8.14.0", + "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.14.0.tgz", + "integrity": "sha512-cl669nCJTZBsL97OF4kUQm5g5hC2uihk0NxY3WENAC0TYdILVkAyHymAntgxGkl7K+t0cXIrH5siy5S4XkFycA==", "dev": true, "license": "MIT", "bin": { @@ -465,16 +566,6 @@ "url": "https://github.com/sponsors/epoberezkin" } }, - "node_modules/ansi-regex": { - "version": "5.0.1", - "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz", - "integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==", - "dev": true, - "license": "MIT", - "engines": { - "node": ">=8" - } - }, "node_modules/ansi-styles": { "version": "3.2.1", "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-3.2.1.tgz", @@ -639,9 +730,9 @@ "license": "MIT" }, "node_modules/cross-spawn": { - "version": "7.0.3", - "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.3.tgz", - "integrity": "sha512-iRDPJKUPVEND7dHPO8rkbOnPpyDygcDFtWjpeWNCgy8WP2rXcxXL8TskReQl6OrB2G7+UJrags1q15Fudc7G6w==", + "version": "7.0.6", + "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.6.tgz", + "integrity": "sha512-uV2QOWP2nWzsy2aMp8aRibhi9dlzF5Hgh5SHaB9OiTGEyDTiJJyx0uy51QXdyWbtAHNua4XJzUKca3OzKUd3vA==", "dev": true, "license": "MIT", "dependencies": { @@ -919,29 +1010,32 @@ } }, "node_modules/eslint": { - "version": "9.10.0", - "resolved": "https://registry.npmjs.org/eslint/-/eslint-9.10.0.tgz", - "integrity": "sha512-Y4D0IgtBZfOcOUAIQTSXBKoNGfY0REGqHJG6+Q81vNippW5YlKjHFj4soMxamKK1NXHUWuBZTLdU3Km+L/pcHw==", + "version": "9.15.0", + "resolved": "https://registry.npmjs.org/eslint/-/eslint-9.15.0.tgz", + "integrity": "sha512-7CrWySmIibCgT1Os28lUU6upBshZ+GxybLOrmRzi08kS8MBuO8QA7pXEgYgY5W8vK3e74xv0lpjo9DbaGU9Rkw==", "dev": true, "license": "MIT", "dependencies": { "@eslint-community/eslint-utils": "^4.2.0", - "@eslint-community/regexpp": "^4.11.0", - "@eslint/config-array": "^0.18.0", - "@eslint/eslintrc": "^3.1.0", - "@eslint/js": "9.10.0", - "@eslint/plugin-kit": "^0.1.0", + "@eslint-community/regexpp": "^4.12.1", + "@eslint/config-array": "^0.19.0", + "@eslint/core": "^0.9.0", + "@eslint/eslintrc": "^3.2.0", + "@eslint/js": "9.15.0", + "@eslint/plugin-kit": "^0.2.3", + "@humanfs/node": "^0.16.6", "@humanwhocodes/module-importer": "^1.0.1", - "@humanwhocodes/retry": "^0.3.0", - "@nodelib/fs.walk": "^1.2.8", + "@humanwhocodes/retry": "^0.4.1", + "@types/estree": "^1.0.6", + "@types/json-schema": "^7.0.15", "ajv": "^6.12.4", "chalk": "^4.0.0", - "cross-spawn": "^7.0.2", + "cross-spawn": "^7.0.5", "debug": "^4.3.2", "escape-string-regexp": "^4.0.0", - "eslint-scope": "^8.0.2", - "eslint-visitor-keys": "^4.0.0", - "espree": "^10.1.0", + "eslint-scope": "^8.2.0", + "eslint-visitor-keys": "^4.2.0", + "espree": "^10.3.0", "esquery": "^1.5.0", "esutils": "^2.0.2", "fast-deep-equal": "^3.1.3", @@ -951,14 +1045,11 @@ "ignore": "^5.2.0", "imurmurhash": "^0.1.4", "is-glob": "^4.0.0", - "is-path-inside": "^3.0.3", "json-stable-stringify-without-jsonify": "^1.0.1", "lodash.merge": "^4.6.2", "minimatch": "^3.1.2", "natural-compare": "^1.4.0", - "optionator": "^0.9.3", - "strip-ansi": "^6.0.1", - "text-table": "^0.2.0" + "optionator": "^0.9.3" }, "bin": { "eslint": "bin/eslint.js" @@ -1023,9 +1114,9 @@ } }, "node_modules/eslint-scope": { - "version": "8.0.2", - "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-8.0.2.tgz", - "integrity": "sha512-6E4xmrTw5wtxnLA5wYL3WDfhZ/1bUBGOXV0zQvVRDOtrR8D0p6W7fs3JweNYhwRYeGvd/1CKX2se0/2s7Q/nJA==", + "version": "8.2.0", + "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-8.2.0.tgz", + "integrity": "sha512-PHlWUfG6lvPc3yvP5A4PNyBL1W8fkDUccmI21JUu/+GKZBoH/W5u6usENXUrWFRsyoW5ACUjFGgAFQp5gUlb/A==", "dev": true, "license": "BSD-2-Clause", "dependencies": { @@ -1040,9 +1131,9 @@ } }, "node_modules/eslint-visitor-keys": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-4.0.0.tgz", - "integrity": "sha512-OtIRv/2GyiF6o/d8K7MYKKbXrOUBIK6SfkIRM4Z0dY3w+LiQ0vy3F57m0Z71bjbyeiWFiHJ8brqnmE6H6/jEuw==", + "version": "4.2.0", + "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-4.2.0.tgz", + "integrity": "sha512-UyLnSehNt62FFhSwjZlHmeokpRK59rcz29j+F1/aDgbkbRTk7wIc9XzdoasMUbRNKDM0qQt/+BJ4BrpFeABemw==", "dev": true, "license": "Apache-2.0", "engines": { @@ -1142,15 +1233,15 @@ } }, "node_modules/espree": { - "version": "10.1.0", - "resolved": "https://registry.npmjs.org/espree/-/espree-10.1.0.tgz", - "integrity": "sha512-M1M6CpiE6ffoigIOWYO9UDP8TMUw9kqb21tf+08IgDYjCsOvCuDt4jQcZmoYxx+w7zlKw9/N0KXfto+I8/FrXA==", + "version": "10.3.0", + "resolved": "https://registry.npmjs.org/espree/-/espree-10.3.0.tgz", + "integrity": "sha512-0QYC8b24HWY8zjRnDTL6RiHfDbAWn63qb4LMj1Z4b076A4une81+z03Kg7l7mn/48PUTqoLptSXez8oknU8Clg==", "dev": true, "license": "BSD-2-Clause", "dependencies": { - "acorn": "^8.12.0", + "acorn": "^8.14.0", "acorn-jsx": "^5.3.2", - "eslint-visitor-keys": "^4.0.0" + "eslint-visitor-keys": "^4.2.0" }, "engines": { "node": "^18.18.0 || ^20.9.0 || >=21.1.0" @@ -1233,16 +1324,6 @@ "dev": true, "license": "MIT" }, - "node_modules/fastq": { - "version": "1.17.1", - "resolved": "https://registry.npmjs.org/fastq/-/fastq-1.17.1.tgz", - "integrity": "sha512-sRVD3lWVIXWg6By68ZN7vho9a1pQcN/WBFaAAsDDFzlJjvoGx0P8z7V1t72grFJfJhu3YPZBuu25f7Kaw2jN1w==", - "dev": true, - "license": "ISC", - "dependencies": { - "reusify": "^1.0.4" - } - }, "node_modules/file-entry-cache": { "version": "8.0.0", "resolved": "https://registry.npmjs.org/file-entry-cache/-/file-entry-cache-8.0.0.tgz", @@ -1758,16 +1839,6 @@ "url": "https://github.com/sponsors/ljharb" } }, - "node_modules/is-path-inside": { - "version": "3.0.3", - "resolved": "https://registry.npmjs.org/is-path-inside/-/is-path-inside-3.0.3.tgz", - "integrity": "sha512-Fd4gABb+ycGAmKou8eMftCupSir5lRxqf4aD/vd0cD2qc4HL07OjCeuHMr8Ro4CoMaeCKDB0/ECBOVWjTwUvPQ==", - "dev": true, - "license": "MIT", - "engines": { - "node": ">=8" - } - }, "node_modules/is-regex": { "version": "1.1.4", "resolved": "https://registry.npmjs.org/is-regex/-/is-regex-1.1.4.tgz", @@ -2000,6 +2071,15 @@ "dev": true, "license": "MIT" }, + "node_modules/lru-cache": { + "version": "11.0.2", + "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-11.0.2.tgz", + "integrity": "sha512-123qHRfJBmo2jXDbo/a5YOQrJoHF/GNQTLzQ5+IdK5pWpceK17yRc6ozlWd25FxvGKQbIUs91fDFkXmDHTKcyA==", + "license": "ISC", + "engines": { + "node": "20 || >=22" + } + }, "node_modules/memorystream": { "version": "0.3.1", "resolved": "https://registry.npmjs.org/memorystream/-/memorystream-0.3.1.tgz", @@ -2083,9 +2163,9 @@ } }, "node_modules/npm-run-all/node_modules/cross-spawn": { - "version": "6.0.5", - "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-6.0.5.tgz", - "integrity": "sha512-eTVLrBSt7fjbDygz805pMnstIs2VTBNkRm0qxZd+M7A5XDdxVRWO5MxGBXZhjY4cqLYLdtrGqRf8mBPmzwSpWQ==", + "version": "6.0.6", + "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-6.0.6.tgz", + "integrity": "sha512-VqCUuhcd1iB+dsv8gxPttb5iZh/D0iubSP21g36KXdEuf6I5JiioesUVjpCdHV9MZRUfVFlvwtIUyPfxo5trtw==", "dev": true, "license": "MIT", "dependencies": { @@ -2393,27 +2473,6 @@ "node": ">=6" } }, - "node_modules/queue-microtask": { - "version": "1.2.3", - "resolved": "https://registry.npmjs.org/queue-microtask/-/queue-microtask-1.2.3.tgz", - "integrity": "sha512-NuaNSa6flKT5JaSYQzJok04JzTL1CA6aGhv5rfLW3PgqA+M2ChpZQnAC8h8i4ZFkBS8X5RqkDBHA7r4hej3K9A==", - "dev": true, - "funding": [ - { - "type": "github", - "url": "https://github.com/sponsors/feross" - }, - { - "type": "patreon", - "url": "https://www.patreon.com/feross" - }, - { - "type": "consulting", - "url": "https://feross.org/support" - } - ], - "license": "MIT" - }, "node_modules/read-pkg": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/read-pkg/-/read-pkg-3.0.0.tgz", @@ -2476,47 +2535,12 @@ "node": ">=4" } }, - "node_modules/reusify": { - "version": "1.0.4", - "resolved": "https://registry.npmjs.org/reusify/-/reusify-1.0.4.tgz", - "integrity": "sha512-U9nH88a3fc/ekCF1l0/UP1IosiuIjyTh7hBvXVMHYgVcfGvt897Xguj2UOLDeI5BG2m7/uwyaLVT6fbtCwTyzw==", - "dev": true, - "license": "MIT", - "engines": { - "iojs": ">=1.0.0", - "node": ">=0.10.0" - } - }, "node_modules/rrweb-cssom": { "version": "0.7.1", "resolved": "https://registry.npmjs.org/rrweb-cssom/-/rrweb-cssom-0.7.1.tgz", "integrity": "sha512-TrEMa7JGdVm0UThDJSx7ddw5nVm3UJS9o9CCIZ72B1vSyEZoziDqBYP3XIoi/12lKrJR8rE3jeFHMok2F/Mnsg==", "license": "MIT" }, - "node_modules/run-parallel": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/run-parallel/-/run-parallel-1.2.0.tgz", - "integrity": "sha512-5l4VyZR86LZ/lDxZTR6jqL8AFE2S0IFLMP26AbjsLVADxHdhB/c0GUsH+y39UfCi3dzz8OlQuPmnaJOMoDHQBA==", - "dev": true, - "funding": [ - { - "type": "github", - "url": "https://github.com/sponsors/feross" - }, - { - "type": "patreon", - "url": "https://www.patreon.com/feross" - }, - { - "type": "consulting", - "url": "https://feross.org/support" - } - ], - "license": "MIT", - "dependencies": { - "queue-microtask": "^1.2.2" - } - }, "node_modules/safe-array-concat": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/safe-array-concat/-/safe-array-concat-1.1.2.tgz", @@ -2757,19 +2781,6 @@ "url": "https://github.com/sponsors/ljharb" } }, - "node_modules/strip-ansi": { - "version": "6.0.1", - "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz", - "integrity": "sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==", - "dev": true, - "license": "MIT", - "dependencies": { - "ansi-regex": "^5.0.1" - }, - "engines": { - "node": ">=8" - } - }, "node_modules/strip-bom": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/strip-bom/-/strip-bom-3.0.0.tgz", @@ -2836,13 +2847,6 @@ "url": "https://opencollective.com/unts" } }, - "node_modules/text-table": { - "version": "0.2.0", - "resolved": "https://registry.npmjs.org/text-table/-/text-table-0.2.0.tgz", - "integrity": "sha512-N+8UisAXDGk8PFXP4HAzVR9nbfmVJ3zYLAWiTIoqC5v5isinhr+r5uaO8+7r3BMfuNIufIsA7RdpVgacC2cSpw==", - "dev": true, - "license": "MIT" - }, "node_modules/to-fast-properties": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/to-fast-properties/-/to-fast-properties-2.0.0.tgz", diff --git a/package.json b/package.json index 41617d7..f7dcd65 100644 --- a/package.json +++ b/package.json @@ -37,6 +37,7 @@ ], "main": "./lib/CSSStyleDeclaration.js", "dependencies": { + "@asamuzakjp/css-color": "^2.2.1", "rrweb-cssom": "^0.7.1" }, "devDependencies": { diff --git a/test/parsers.js b/test/parsers.js index a0b3ff9..af1c791 100644 --- a/test/parsers.js +++ b/test/parsers.js @@ -114,15 +114,52 @@ describe('parseColor', () => { it('should convert not zero hsl with non zero hue 120 to rgb(0, 255, 0)', () => { let input = 'hsl(120, 100%, 50%)'; let output = parsers.parseColor(input); + assert.strictEqual(output, 'rgb(0, 255, 0)'); }); it('should convert not zero hsl with non zero hue 240 to rgb(0, 0, 255)', () => { let input = 'hsl(240, 100%, 50%)'; let output = parsers.parseColor(input); + assert.strictEqual(output, 'rgb(0, 0, 255)'); }); + it('should convert modern rgb to rgb values', () => { + let input = 'rgb(128 0 128 / 1)'; + let output = parsers.parseColor(input); + + assert.strictEqual(output, 'rgb(128, 0, 128)'); + }); + + it('should convert modern rgba to rgba values', () => { + let input = 'rgba(127.5 0 127.5 / .5)'; + let output = parsers.parseColor(input); + + assert.strictEqual(output, 'rgba(128, 0, 128, 0.5)'); + }); + + it('should normalize lab values', () => { + let input = 'lab(46.2775% -47.5621 48.5837 / 1.0)'; // green + let output = parsers.parseColor(input); + + assert.strictEqual(output, 'lab(46.2775 -47.5621 48.5837)'); + }); + + it('should normalize color function values', () => { + let input = 'color(srgb 0 .5 0 / 1.0)'; + let output = parsers.parseColor(input); + + assert.strictEqual(output, 'color(srgb 0 0.5 0)'); + }); + + it('should normalize color-mix values', () => { + let input = 'color-mix(in srgb, rgb(255 0 0), #0000ff)'; + let output = parsers.parseColor(input); + + assert.strictEqual(output, 'color-mix(in srgb, rgb(255, 0, 0), rgb(0, 0, 255))'); + }); + it.todo('Add more tests'); }); describe('parseAngle', () => { From d5754f7ecfe5af147ac45b257566f5711685e645 Mon Sep 17 00:00:00 2001 From: "asamuzaK (Kazz)" Date: Sat, 7 Dec 2024 16:44:51 +0900 Subject: [PATCH 2/6] Update package --- package-lock.json | 10 +++++----- package.json | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/package-lock.json b/package-lock.json index a6bb36b..898b882 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,7 +9,7 @@ "version": "4.1.0", "license": "MIT", "dependencies": { - "@asamuzakjp/css-color": "^2.2.1", + "@asamuzakjp/css-color": "^2.3.0", "rrweb-cssom": "^0.7.1" }, "devDependencies": { @@ -30,12 +30,13 @@ } }, "node_modules/@asamuzakjp/css-color": { - "version": "2.2.1", - "resolved": "https://registry.npmjs.org/@asamuzakjp/css-color/-/css-color-2.2.1.tgz", - "integrity": "sha512-4/RoWIs1GTq3Bm7Xyh1cjRC1h+nyMqoB23Twr5vnbyNqWx5FTbBq7Pb70IovyL6vZbi8vlsoyx03bIBl0U61FA==", + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/@asamuzakjp/css-color/-/css-color-2.3.0.tgz", + "integrity": "sha512-vDI1tl26mhkepjjDW6th+vM8p6kEqUsdQy+GwYkAWIS7Uo85nV9Zf8FZLb4RGzWjKeys3KOHEyUwRd20TxdXBw==", "license": "MIT", "dependencies": { "@csstools/css-calc": "^2.1.0", + "@csstools/css-tokenizer": "^3.0.3", "lru-cache": "^11.0.2" } }, @@ -241,7 +242,6 @@ } ], "license": "MIT", - "peer": true, "engines": { "node": ">=18" } diff --git a/package.json b/package.json index f7dcd65..4c21398 100644 --- a/package.json +++ b/package.json @@ -37,7 +37,7 @@ ], "main": "./lib/CSSStyleDeclaration.js", "dependencies": { - "@asamuzakjp/css-color": "^2.2.1", + "@asamuzakjp/css-color": "^2.3.0", "rrweb-cssom": "^0.7.1" }, "devDependencies": { From 7d7da4647a0cbca93e6af3e4f0c3be19a36722ac Mon Sep 17 00:00:00 2001 From: "asamuzaK (Kazz)" Date: Sat, 7 Dec 2024 16:45:07 +0900 Subject: [PATCH 3/6] Add test --- test/parsers.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/test/parsers.js b/test/parsers.js index af1c791..2b73fcb 100644 --- a/test/parsers.js +++ b/test/parsers.js @@ -132,6 +132,13 @@ describe('parseColor', () => { assert.strictEqual(output, 'rgb(128, 0, 128)'); }); + it('should convert modern rgb with none values to rgb values', () => { + let input = 'rgb(128 0 none)'; + let output = parsers.parseColor(input); + + assert.strictEqual(output, 'rgb(128, 0, 0)'); + }); + it('should convert modern rgba to rgba values', () => { let input = 'rgba(127.5 0 127.5 / .5)'; let output = parsers.parseColor(input); From aff8b07bccdd59d34bf5216e55cec682cba12961 Mon Sep 17 00:00:00 2001 From: "asamuzaK (Kazz)" Date: Sat, 14 Dec 2024 10:26:24 +0900 Subject: [PATCH 4/6] Update css-color --- package-lock.json | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package-lock.json b/package-lock.json index 898b882..806c391 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,7 +9,7 @@ "version": "4.1.0", "license": "MIT", "dependencies": { - "@asamuzakjp/css-color": "^2.3.0", + "@asamuzakjp/css-color": "^2.5.0", "rrweb-cssom": "^0.7.1" }, "devDependencies": { @@ -30,9 +30,9 @@ } }, "node_modules/@asamuzakjp/css-color": { - "version": "2.3.0", - "resolved": "https://registry.npmjs.org/@asamuzakjp/css-color/-/css-color-2.3.0.tgz", - "integrity": "sha512-vDI1tl26mhkepjjDW6th+vM8p6kEqUsdQy+GwYkAWIS7Uo85nV9Zf8FZLb4RGzWjKeys3KOHEyUwRd20TxdXBw==", + "version": "2.5.0", + "resolved": "https://registry.npmjs.org/@asamuzakjp/css-color/-/css-color-2.5.0.tgz", + "integrity": "sha512-LuUSDuz8MPTAPOb9Zvd6b/D2nUyG7NZaI8OGZhu45xgQTqLQOC29HLfadPMrs5C7JY784WRtLMvLmQhTpIY0Pw==", "license": "MIT", "dependencies": { "@csstools/css-calc": "^2.1.0", diff --git a/package.json b/package.json index 4c21398..0f8e70c 100644 --- a/package.json +++ b/package.json @@ -37,7 +37,7 @@ ], "main": "./lib/CSSStyleDeclaration.js", "dependencies": { - "@asamuzakjp/css-color": "^2.3.0", + "@asamuzakjp/css-color": "^2.5.0", "rrweb-cssom": "^0.7.1" }, "devDependencies": { From 515afa4e786dcec971f5c080f3cd3d125b702d91 Mon Sep 17 00:00:00 2001 From: "asamuzaK (Kazz)" Date: Sat, 14 Dec 2024 10:37:39 +0900 Subject: [PATCH 5/6] Update valueType(), parseColor() --- lib/parsers.js | 169 ++---------------------------------- lib/utils/colorSpace.js | 19 ---- test/CSSStyleDeclaration.js | 12 ++- test/parsers.js | 11 ++- 4 files changed, 23 insertions(+), 188 deletions(-) delete mode 100644 lib/utils/colorSpace.js diff --git a/lib/parsers.js b/lib/parsers.js index bacd50e..3478658 100644 --- a/lib/parsers.js +++ b/lib/parsers.js @@ -4,9 +4,7 @@ ********************************************************************/ 'use strict'; -const { resolve } = require('@asamuzakjp/css-color'); -const namedColors = require('./named_colors.json'); -const { hslToRgb } = require('./utils/colorSpace'); +const { isColor, resolve } = require('@asamuzakjp/css-color'); exports.TYPES = { INTEGER: 1, @@ -29,12 +27,7 @@ var lengthRegEx = /^(0|[-+]?[0-9]*\.?[0-9]+(in|cm|em|mm|pt|pc|px|ex|rem|vh|vw|ch var percentRegEx = /^[-+]?[0-9]*\.?[0-9]+%$/; var urlRegEx = /^url\(\s*([^)]*)\s*\)$/; var stringRegEx = /^("[^"]*"|'[^']*')$/; -var colorRegEx1 = /^#([0-9a-fA-F]{3,4}){1,2}$/; -var colorRegEx2 = /^rgb\(([^)]*)\)$/; -var colorRegEx3 = /^rgba\(([^)]*)\)$/; var calcRegEx = /^calc\(([^)]*)\)$/; -var colorRegEx4 = - /^hsla?\(\s*(-?\d+|-?\d*.\d+)\s*,\s*(-?\d+|-?\d*.\d+)%\s*,\s*(-?\d+|-?\d*.\d+)%\s*(,\s*(-?\d+|-?\d*.\d+)\s*)?\)/; var angleRegEx = /^([-+]?[0-9]*\.?[0-9]+)(deg|grad|rad)$/; // This will return one of the above types based on the passed in string @@ -74,54 +67,11 @@ exports.valueType = function valueType(val) { if (angleRegEx.test(val)) { return exports.TYPES.ANGLE; } - if (colorRegEx1.test(val)) { + if (isColor(val)) { return exports.TYPES.COLOR; } - var res = colorRegEx2.exec(val); - var parts; - if (res !== null) { - parts = res[1].split(/\s*,\s*/); - if (parts.length !== 3) { - return undefined; - } - if ( - parts.every(percentRegEx.test.bind(percentRegEx)) || - parts.every(integerRegEx.test.bind(integerRegEx)) - ) { - return exports.TYPES.COLOR; - } - return undefined; - } - res = colorRegEx3.exec(val); - if (res !== null) { - parts = res[1].split(/\s*,\s*/); - if (parts.length !== 4) { - return undefined; - } - if ( - parts.slice(0, 3).every(percentRegEx.test.bind(percentRegEx)) || - parts.slice(0, 3).every(integerRegEx.test.bind(integerRegEx)) - ) { - if (numberRegEx.test(parts[3])) { - return exports.TYPES.COLOR; - } - } - return undefined; - } - - if (colorRegEx4.test(val)) { - return exports.TYPES.COLOR; - } - - // could still be a color, one of the standard keyword colors - val = val.toLowerCase(); - - if (namedColors.includes(val)) { - return exports.TYPES.COLOR; - } - - switch (val) { + switch (val.toLowerCase()) { // the following are deprecated in CSS3 case 'activeborder': case 'activecaption': @@ -292,119 +242,10 @@ exports.parseColor = function parseColor(val) { if (type === exports.TYPES.NULL_OR_EMPTY_STR) { return val; } - var red, - green, - blue, - hue, - saturation, - lightness, - alpha = 1; - var parts; - var res = colorRegEx1.exec(val); - // is it #aaa, #ababab, #aaaa, #abababaa - if (res) { - var defaultHex = val.substr(1); - var hex = val.substr(1); - if (hex.length === 3 || hex.length === 4) { - hex = hex[0] + hex[0] + hex[1] + hex[1] + hex[2] + hex[2]; - - if (defaultHex.length === 4) { - hex = hex + defaultHex[3] + defaultHex[3]; - } - } - red = parseInt(hex.substr(0, 2), 16); - green = parseInt(hex.substr(2, 2), 16); - blue = parseInt(hex.substr(4, 2), 16); - if (hex.length === 8) { - var hexAlpha = hex.substr(6, 2); - var hexAlphaToRgbaAlpha = Number((parseInt(hexAlpha, 16) / 255).toFixed(3)); - - return 'rgba(' + red + ', ' + green + ', ' + blue + ', ' + hexAlphaToRgbaAlpha + ')'; - } - return 'rgb(' + red + ', ' + green + ', ' + blue + ')'; - } - - res = val.includes(',') && colorRegEx2.exec(val); - if (res) { - parts = res[1].split(/\s*,\s*/); - if (parts.length !== 3) { - return undefined; - } - if (parts.every(percentRegEx.test.bind(percentRegEx))) { - red = Math.floor((parseFloat(parts[0].slice(0, -1)) * 255) / 100); - green = Math.floor((parseFloat(parts[1].slice(0, -1)) * 255) / 100); - blue = Math.floor((parseFloat(parts[2].slice(0, -1)) * 255) / 100); - } else if (parts.every(integerRegEx.test.bind(integerRegEx))) { - red = parseInt(parts[0], 10); - green = parseInt(parts[1], 10); - blue = parseInt(parts[2], 10); - } else { - return undefined; - } - red = Math.min(255, Math.max(0, red)); - green = Math.min(255, Math.max(0, green)); - blue = Math.min(255, Math.max(0, blue)); - return 'rgb(' + red + ', ' + green + ', ' + blue + ')'; - } - - res = val.includes(',') && colorRegEx3.exec(val); - if (res) { - parts = res[1].split(/\s*,\s*/); - if (parts.length !== 4) { - return undefined; - } - if (parts.slice(0, 3).every(percentRegEx.test.bind(percentRegEx))) { - red = Math.floor((parseFloat(parts[0].slice(0, -1)) * 255) / 100); - green = Math.floor((parseFloat(parts[1].slice(0, -1)) * 255) / 100); - blue = Math.floor((parseFloat(parts[2].slice(0, -1)) * 255) / 100); - alpha = parseFloat(parts[3]); - } else if (parts.slice(0, 3).every(integerRegEx.test.bind(integerRegEx))) { - red = parseInt(parts[0], 10); - green = parseInt(parts[1], 10); - blue = parseInt(parts[2], 10); - alpha = parseFloat(parts[3]); - } else { - return undefined; - } - if (isNaN(alpha)) { - alpha = 1; - } - red = Math.min(255, Math.max(0, red)); - green = Math.min(255, Math.max(0, green)); - blue = Math.min(255, Math.max(0, blue)); - alpha = Math.min(1, Math.max(0, alpha)); - if (alpha === 1) { - return 'rgb(' + red + ', ' + green + ', ' + blue + ')'; - } - return 'rgba(' + red + ', ' + green + ', ' + blue + ', ' + alpha + ')'; - } - - res = colorRegEx4.exec(val); - if (res) { - const [, _hue, _saturation, _lightness, _alphaString = ''] = res; - const _alpha = parseFloat(_alphaString.replace(',', '').trim()); - if (!_hue || !_saturation || !_lightness) { - return undefined; - } - hue = parseFloat(_hue); - saturation = parseInt(_saturation, 10); - lightness = parseInt(_lightness, 10); - if (_alpha && numberRegEx.test(_alpha)) { - alpha = parseFloat(_alpha); - } - - const [r, g, b] = hslToRgb(hue, saturation / 100, lightness / 100); - if (!_alphaString || alpha === 1) { - return 'rgb(' + r + ', ' + g + ', ' + b + ')'; - } - return 'rgba(' + r + ', ' + g + ', ' + b + ', ' + alpha + ')'; - } - - if (type === exports.TYPES.COLOR) { + if (/^[a-z]+$/i.test(val) && type === exports.TYPES.COLOR) { return val; } - - res = resolve(val, { + var res = resolve(val, { format: 'specifiedValue', }); if (res) { diff --git a/lib/utils/colorSpace.js b/lib/utils/colorSpace.js deleted file mode 100644 index 83be60a..0000000 --- a/lib/utils/colorSpace.js +++ /dev/null @@ -1,19 +0,0 @@ -'use strict'; - -const MAX_HUE = 360; -const COLOR_NB = 12; -const MAX_RGB_VALUE = 255; - -// https://www.w3.org/TR/css-color-4/#hsl-to-rgb -exports.hslToRgb = (hue, sat, light) => { - hue = hue % MAX_HUE; - if (hue < 0) { - hue += MAX_HUE; - } - function f(n) { - const k = (n + hue / (MAX_HUE / COLOR_NB)) % COLOR_NB; - const a = sat * Math.min(light, 1 - light); - return light - a * Math.max(-1, Math.min(k - 3, 9 - k, 1)); - } - return [f(0), f(8), f(4)].map((value) => Math.round(value * MAX_RGB_VALUE)); -}; diff --git a/test/CSSStyleDeclaration.js b/test/CSSStyleDeclaration.js index b2f20a2..62f35d0 100644 --- a/test/CSSStyleDeclaration.js +++ b/test/CSSStyleDeclaration.js @@ -183,9 +183,9 @@ describe('CSSStyleDeclaration', () => { style.color = 'rgba(0,0,0,0)'; assert.strictEqual(style.color, 'rgba(0, 0, 0, 0)'); style.color = 'rgba(5%, 10%, 20%, 0.4)'; - assert.strictEqual(style.color, 'rgba(12, 25, 51, 0.4)'); + assert.strictEqual(style.color, 'rgba(13, 26, 51, 0.4)'); style.color = 'rgb(33%, 34%, 33%)'; - assert.strictEqual(style.color, 'rgb(84, 86, 84)'); + assert.strictEqual(style.color, 'rgb(84, 87, 84)'); style.color = 'rgba(300, 200, 100, 1.5)'; assert.strictEqual(style.color, 'rgb(255, 200, 100)'); style.color = 'hsla(0, 1%, 2%, 0.5)'; @@ -199,13 +199,19 @@ describe('CSSStyleDeclaration', () => { style.color = 'currentcolor'; assert.strictEqual(style.color, 'currentcolor'); style.color = '#ffffffff'; - assert.strictEqual(style.color, 'rgba(255, 255, 255, 1)'); + assert.strictEqual(style.color, 'rgb(255, 255, 255)'); style.color = '#fffa'; assert.strictEqual(style.color, 'rgba(255, 255, 255, 0.667)'); style.color = '#ffffff66'; assert.strictEqual(style.color, 'rgba(255, 255, 255, 0.4)'); }); + it('invalid hex color value', () => { + var style = new CSSStyleDeclaration(); + style.color = '#1234567'; + assert.strictEqual(style.color, ''); + }); + it('short hand properties with embedded spaces', () => { var style = new CSSStyleDeclaration(); style.background = 'rgb(0, 0, 0) url(/something/somewhere.jpg)'; diff --git a/test/parsers.js b/test/parsers.js index 2b73fcb..4f0fa97 100644 --- a/test/parsers.js +++ b/test/parsers.js @@ -161,10 +161,17 @@ describe('parseColor', () => { }); it('should normalize color-mix values', () => { - let input = 'color-mix(in srgb, rgb(255 0 0), #0000ff)'; + let input = 'color-mix(in srgb, rgb(255 0 0), #0000ff 40%)'; let output = parsers.parseColor(input); - assert.strictEqual(output, 'color-mix(in srgb, rgb(255, 0, 0), rgb(0, 0, 255))'); + assert.strictEqual(output, 'color-mix(in srgb, rgb(255, 0, 0) 60%, rgb(0, 0, 255))'); + }); + + it('should not remove comments, trim or lower case letters if var() is used', () => { + let input = 'var( --custom-Color /* comment */)'; + let output = parsers.parseColor(input); + + assert.strictEqual(output, 'var( --custom-Color /* comment */)'); }); it.todo('Add more tests'); From bfd84fc23e5a44ad64ef39cac44130c5e6931107 Mon Sep 17 00:00:00 2001 From: "asamuzaK (Kazz)" Date: Tue, 17 Dec 2024 21:11:13 +0900 Subject: [PATCH 6/6] Update package-lock.json --- package-lock.json | 45 ++++++++++++++++++++++++--------------------- 1 file changed, 24 insertions(+), 21 deletions(-) diff --git a/package-lock.json b/package-lock.json index 806c391..454e249 100644 --- a/package-lock.json +++ b/package-lock.json @@ -286,13 +286,13 @@ } }, "node_modules/@eslint/config-array": { - "version": "0.19.0", - "resolved": "https://registry.npmjs.org/@eslint/config-array/-/config-array-0.19.0.tgz", - "integrity": "sha512-zdHg2FPIFNKPdcHWtiNT+jEFCHYVplAXRDlQDyqy0zGx/q2parwh7brGJSiTxRk/TSMkbM//zt/f5CHgyTyaSQ==", + "version": "0.19.1", + "resolved": "https://registry.npmjs.org/@eslint/config-array/-/config-array-0.19.1.tgz", + "integrity": "sha512-fo6Mtm5mWyKjA/Chy1BYTdn5mGJoDNjC7C64ug20ADsRDGrA85bN3uK3MaKbeRkRuuIEAR5N33Jr1pbm411/PA==", "dev": true, "license": "Apache-2.0", "dependencies": { - "@eslint/object-schema": "^2.1.4", + "@eslint/object-schema": "^2.1.5", "debug": "^4.3.1", "minimatch": "^3.1.2" }, @@ -301,11 +301,14 @@ } }, "node_modules/@eslint/core": { - "version": "0.9.0", - "resolved": "https://registry.npmjs.org/@eslint/core/-/core-0.9.0.tgz", - "integrity": "sha512-7ATR9F0e4W85D/0w7cU0SNj7qkAexMG+bAHEZOjo9akvGuhHE2m7umzWzfnpa0XAg5Kxc1BWmtPMV67jJ+9VUg==", + "version": "0.9.1", + "resolved": "https://registry.npmjs.org/@eslint/core/-/core-0.9.1.tgz", + "integrity": "sha512-GuUdqkyyzQI5RMIWkHhvTWLCyLo1jNK3vzkSyaExH5kHPDHcuL2VOpHjmMY+y3+NC69qAKToBqldTBgYeLSr9Q==", "dev": true, "license": "Apache-2.0", + "dependencies": { + "@types/json-schema": "^7.0.15" + }, "engines": { "node": "^18.18.0 || ^20.9.0 || >=21.1.0" } @@ -348,9 +351,9 @@ } }, "node_modules/@eslint/js": { - "version": "9.15.0", - "resolved": "https://registry.npmjs.org/@eslint/js/-/js-9.15.0.tgz", - "integrity": "sha512-tMTqrY+EzbXmKJR5ToI8lxu7jaN5EdmrBFJpQk5JmSlyLsx6o4t27r883K5xsLuCYCpfKBCGswMSWXsM+jB7lg==", + "version": "9.17.0", + "resolved": "https://registry.npmjs.org/@eslint/js/-/js-9.17.0.tgz", + "integrity": "sha512-Sxc4hqcs1kTu0iID3kcZDW3JHq2a77HO9P8CP6YEA/FpH3Ll8UXE2r/86Rz9YJLKme39S9vU5OWNjC6Xl0Cr3w==", "dev": true, "license": "MIT", "engines": { @@ -358,9 +361,9 @@ } }, "node_modules/@eslint/object-schema": { - "version": "2.1.4", - "resolved": "https://registry.npmjs.org/@eslint/object-schema/-/object-schema-2.1.4.tgz", - "integrity": "sha512-BsWiH1yFGjXXS2yvrf5LyuoSIIbPrGUWob917o+BTKuZ7qJdxX8aJLRxs1fS9n6r7vESrq1OUqb68dANcFXuQQ==", + "version": "2.1.5", + "resolved": "https://registry.npmjs.org/@eslint/object-schema/-/object-schema-2.1.5.tgz", + "integrity": "sha512-o0bhxnL89h5Bae5T318nFoFzGy+YE5i/gGkoPAgkmTVdRKTiv3p8JHevPiPaMwoloKfEiiaHlawCqaZMqRm+XQ==", "dev": true, "license": "Apache-2.0", "engines": { @@ -368,9 +371,9 @@ } }, "node_modules/@eslint/plugin-kit": { - "version": "0.2.3", - "resolved": "https://registry.npmjs.org/@eslint/plugin-kit/-/plugin-kit-0.2.3.tgz", - "integrity": "sha512-2b/g5hRmpbb1o4GnTZax9N9m0FXzz9OV42ZzI4rDDMDuHUqigAiQCEWChBWCY4ztAGVRjoWT19v0yMmc5/L5kA==", + "version": "0.2.4", + "resolved": "https://registry.npmjs.org/@eslint/plugin-kit/-/plugin-kit-0.2.4.tgz", + "integrity": "sha512-zSkKow6H5Kdm0ZUQUB2kV5JIXqoG0+uH5YADhaEHswm664N9Db8dXSi0nMJpacpMf+MyyglF1vnZohpEg5yUtg==", "dev": true, "license": "Apache-2.0", "dependencies": { @@ -1010,9 +1013,9 @@ } }, "node_modules/eslint": { - "version": "9.15.0", - "resolved": "https://registry.npmjs.org/eslint/-/eslint-9.15.0.tgz", - "integrity": "sha512-7CrWySmIibCgT1Os28lUU6upBshZ+GxybLOrmRzi08kS8MBuO8QA7pXEgYgY5W8vK3e74xv0lpjo9DbaGU9Rkw==", + "version": "9.17.0", + "resolved": "https://registry.npmjs.org/eslint/-/eslint-9.17.0.tgz", + "integrity": "sha512-evtlNcpJg+cZLcnVKwsai8fExnqjGPicK7gnUtlNuzu+Fv9bI0aLpND5T44VLQtoMEnI57LoXO9XAkIXwohKrA==", "dev": true, "license": "MIT", "dependencies": { @@ -1021,7 +1024,7 @@ "@eslint/config-array": "^0.19.0", "@eslint/core": "^0.9.0", "@eslint/eslintrc": "^3.2.0", - "@eslint/js": "9.15.0", + "@eslint/js": "9.17.0", "@eslint/plugin-kit": "^0.2.3", "@humanfs/node": "^0.16.6", "@humanwhocodes/module-importer": "^1.0.1", @@ -1030,7 +1033,7 @@ "@types/json-schema": "^7.0.15", "ajv": "^6.12.4", "chalk": "^4.0.0", - "cross-spawn": "^7.0.5", + "cross-spawn": "^7.0.6", "debug": "^4.3.2", "escape-string-regexp": "^4.0.0", "eslint-scope": "^8.2.0",