diff --git a/package.json b/package.json index b7c8b0f..88e0e3a 100644 --- a/package.json +++ b/package.json @@ -39,6 +39,8 @@ ], "dependencies": { "color-name": "^1.1.4", + "lodash.get": "^4.4.2", + "lodash.set": "^4.3.2", "tiny-invariant": "^1.2.0" }, "devDependencies": { @@ -48,6 +50,8 @@ "@semantic-release/git": "^10.0.1", "@types/color-name": "^1.1.1", "@types/jest": "^27.4.1", + "@types/lodash.get": "^4.4.7", + "@types/lodash.set": "^4.3.7", "@types/tailwindcss": "^3.0.10", "@typescript-eslint/eslint-plugin": "^5.20.0", "@typescript-eslint/parser": "^5.20.0", diff --git a/src/plugin.ts b/src/plugin.ts index 6778c92..1a51abb 100644 --- a/src/plugin.ts +++ b/src/plugin.ts @@ -1,5 +1,7 @@ /* eslint-disable @typescript-eslint/ban-ts-comment */ import type { Plugin } from "chart.js" +import set from "lodash.set" +import get from "lodash.get" import resolveConfig from "tailwindcss/resolveConfig" import { TailwindConfig } from "tailwindcss/tailwind-config" import invariant from "tiny-invariant" @@ -60,26 +62,23 @@ const twColorsPlugin = ( "pointBackgroundColor", "pointHoverBackgroundColor", "pointHoverBorderColor", + "fill.above", + "fill.below", ] - // Ignoring some typings here since Chart.js's typings - // itself has its own problems (i.e., too broad), - // or maybe I overlooked something? parsableOpts.forEach((parsableOpt) => { const defaultOpt = defaults[parsableOpt] const chartOpt = chart.options[parsableOpt] chart.data.datasets?.forEach((dataset) => { - const datasetOpt = - // @ts-ignore - ts(7053) - dataset[parsableOpt] - - // @ts-ignore - ts(7053) - dataset[parsableOpt] = + set( + dataset, + parsableOpt, parseTailwindColor( - datasetOpt || + get(dataset, parsableOpt) || (chartOpt?.toString().includes("-") ? chartOpt : defaultOpt) ) + ) }) }) }, diff --git a/yarn.lock b/yarn.lock index 68dec67..2d9e30e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1685,6 +1685,25 @@ resolved "https://registry.yarnpkg.com/@types/json5/-/json5-0.0.29.tgz#ee28707ae94e11d2b827bcbe5270bcea7f3e71ee" integrity sha1-7ihweulOEdK4J7y+UnC86n8+ce4= +"@types/lodash.get@^4.4.7": + version "4.4.7" + resolved "https://registry.yarnpkg.com/@types/lodash.get/-/lodash.get-4.4.7.tgz#1ea63d8b94709f6bc9e231f252b31440abe312cf" + integrity sha512-af34Mj+KdDeuzsJBxc/XeTtOx0SZHZNLd+hdrn+PcKGQs0EG2TJTzQAOTCZTgDJCArahlCzLWSy8c2w59JRz7Q== + dependencies: + "@types/lodash" "*" + +"@types/lodash.set@^4.3.7": + version "4.3.7" + resolved "https://registry.yarnpkg.com/@types/lodash.set/-/lodash.set-4.3.7.tgz#784fccea3fbef4d0949d1897a780f592da700942" + integrity sha512-bS5Wkg/nrT82YUfkNYPSccFrNZRL+irl7Yt4iM6OTSQ0VZJED2oUIVm15NkNtUAQ8SRhCe+axqERUV6MJgkeEg== + dependencies: + "@types/lodash" "*" + +"@types/lodash@*": + version "4.14.182" + resolved "https://registry.yarnpkg.com/@types/lodash/-/lodash-4.14.182.tgz#05301a4d5e62963227eaafe0ce04dd77c54ea5c2" + integrity sha512-/THyiqyQAP9AfARo4pF+aCGcyiQ94tX/Is2I7HofNRqoYLgN1PBoOWu2/zTA5zMxzP5EFutMtWtGAFRKUe961Q== + "@types/minimist@^1.2.0": version "1.2.2" resolved "https://registry.yarnpkg.com/@types/minimist/-/minimist-1.2.2.tgz#ee771e2ba4b3dc5b372935d549fd9617bf345b8c" @@ -4873,6 +4892,11 @@ lodash.escaperegexp@^4.1.2: resolved "https://registry.yarnpkg.com/lodash.escaperegexp/-/lodash.escaperegexp-4.1.2.tgz#64762c48618082518ac3df4ccf5d5886dae20347" integrity sha1-ZHYsSGGAglGKw99Mz11YhtriA0c= +lodash.get@^4.4.2: + version "4.4.2" + resolved "https://registry.yarnpkg.com/lodash.get/-/lodash.get-4.4.2.tgz#2d177f652fa31e939b4438d5341499dfa3825e99" + integrity sha1-LRd/ZS+jHpObRDjVNBSZ36OCXpk= + lodash.ismatch@^4.4.0: version "4.4.0" resolved "https://registry.yarnpkg.com/lodash.ismatch/-/lodash.ismatch-4.4.0.tgz#756cb5150ca3ba6f11085a78849645f188f85f37" @@ -4898,6 +4922,11 @@ lodash.merge@^4.6.2: resolved "https://registry.yarnpkg.com/lodash.merge/-/lodash.merge-4.6.2.tgz#558aa53b43b661e1925a0afdfa36a9a1085fe57a" integrity sha512-0KpjqXRVvrYyCsX1swR/XTK0va6VQkQM6MNo7PqW77ByjAhoARA8EfrP1N4+KlKj8YS0ZUCtRT/YUuhyYDujIQ== +lodash.set@^4.3.2: + version "4.3.2" + resolved "https://registry.yarnpkg.com/lodash.set/-/lodash.set-4.3.2.tgz#d8757b1da807dde24816b0d6a84bea1a76230b23" + integrity sha1-2HV7HagH3eJIFrDWqEvqGnYjCyM= + lodash.uniqby@^4.7.0: version "4.7.0" resolved "https://registry.yarnpkg.com/lodash.uniqby/-/lodash.uniqby-4.7.0.tgz#d99c07a669e9e6d24e1362dfe266c67616af1302"