From f9a62a14fd3b6606d80b54e017d4d44fb64fb93c Mon Sep 17 00:00:00 2001 From: wzc520pyfm <1528857653@qq.com> Date: Sun, 31 Mar 2024 23:33:07 +0800 Subject: [PATCH] feat: no longer fully export plug-ins to provide better ts types --- README.md | 10 +++++----- package.json | 6 +----- src/plugin/index.ts | 6 ------ test/index.test.ts | 7 ++++--- test/plugin/get-luminance.test.ts | 2 +- test/plugin/input-named.test.ts | 2 +- test/plugin/readablecolor.test.ts | 2 +- test/plugin/theme-colors.test.ts | 2 +- 8 files changed, 14 insertions(+), 23 deletions(-) delete mode 100644 src/plugin/index.ts diff --git a/README.md b/README.md index 543d82f..6c5f43e 100644 --- a/README.md +++ b/README.md @@ -127,8 +127,8 @@ export default (option, ohcolorClass, ohcolorFactory) => { Support input w3cx11 color. ```ts -import { mycolor } from 'ohcolor' -import { inputNamed } from 'ohcolor/plugin' +import mycolor from 'ohcolor' +import inputNamed from 'ohcolor/plugin/inputNamed' mycolor.extend(inputNamed) mycolor("yellow").rgba() // [255, 255, 0, 1] @@ -140,7 +140,7 @@ Returns a number (float) representing the luminance of a color. ```ts import { mycolor } from 'ohcolor' -import { getLuminance } from 'ohcolor/plugin' +import { getLuminance } from 'ohcolor/plugin/getLuminance' mycolor.extend(getLuminance) mycolor("#ffff00").getLuminance() // 0.9278 @@ -152,7 +152,7 @@ Generate color shades for themes. ```ts import { mycolor } from 'ohcolor' -import { themeColors } from 'ohcolor/plugin' +import { themeColors } from 'ohcolor/plugin/themeColors' mycolor.extend(themeColors) mycolor("#ffff00").themeColors() @@ -182,7 +182,7 @@ Get black or white for best contrast depending on the luminosity. ```ts import { mycolor } from 'ohcolor' -import { readableColor } from 'ohcolor/plugin' +import { readableColor } from 'ohcolor/plugin/readableColor' mycolor.extend(readableColor) mycolor("#ffff00").readableColor() // #000 diff --git a/package.json b/package.json index be8aca6..46ff5e7 100644 --- a/package.json +++ b/package.json @@ -20,10 +20,6 @@ "types": "./dist/index.d.ts", "import": "./dist/index.mjs" }, - "./plugin": { - "types": "./dist/plugin/index.d.ts", - "import": "./dist/plugin/index.mjs" - }, "./plugin/*": { "types": "./dist/plugin/*/index.d.ts", "import": "./dist/plugin/*/index.mjs" @@ -59,4 +55,4 @@ "vitest": "^1.3.0" }, "packageManager": "pnpm@8.12.1" -} \ No newline at end of file +} diff --git a/src/plugin/index.ts b/src/plugin/index.ts deleted file mode 100644 index f463376..0000000 --- a/src/plugin/index.ts +++ /dev/null @@ -1,6 +0,0 @@ -export { inputHex } from "./inputHex"; -export { outputHex } from "./outputHex"; -export { inputNamed } from "./inputNamed"; -export { getLuminance } from "./getLuminance"; -export { themeColors } from "./themeColors"; -export { readableColor } from "./readableColor"; diff --git a/test/index.test.ts b/test/index.test.ts index 40ca131..aa683e6 100644 --- a/test/index.test.ts +++ b/test/index.test.ts @@ -43,9 +43,10 @@ describe("mycolor", () => { expect(mycolor(255, 165, 0, 1).format("unknown")).toEqual([255, 165, 0, 1]); }); it("allows multiple plugins to be installed", async () => { - const { inputHex, getLuminance, readableColor } = await import( - "../src/plugin" - ); + const { inputHex } = await import("../src/plugin/inputHex"); + const { getLuminance } = await import("../src/plugin/getLuminance"); + const { readableColor } = await import("../src/plugin/readableColor"); + mycolor.extend(inputHex); mycolor.extend(getLuminance); mycolor.extend(readableColor); diff --git a/test/plugin/get-luminance.test.ts b/test/plugin/get-luminance.test.ts index 89914da..e9a5d1e 100644 --- a/test/plugin/get-luminance.test.ts +++ b/test/plugin/get-luminance.test.ts @@ -1,6 +1,6 @@ import { expect, it, describe } from "vitest"; import { mycolor } from "../../src"; -import { getLuminance } from "../../src/plugin"; +import { getLuminance } from "../../src/plugin/getLuminance"; describe("mycolor plugin: getLuminance", () => { it("should get luminance", () => { diff --git a/test/plugin/input-named.test.ts b/test/plugin/input-named.test.ts index 811f27b..5e0f028 100644 --- a/test/plugin/input-named.test.ts +++ b/test/plugin/input-named.test.ts @@ -1,6 +1,6 @@ import { expect, it, describe } from "vitest"; import { mycolor } from "../../src"; -import { inputNamed } from "../../src/plugin"; +import { inputNamed } from "../../src/plugin/inputNamed"; describe("mycolor plugin: inputNamed", () => { mycolor.extend(inputNamed); diff --git a/test/plugin/readablecolor.test.ts b/test/plugin/readablecolor.test.ts index 0a9dc2c..30818fd 100644 --- a/test/plugin/readablecolor.test.ts +++ b/test/plugin/readablecolor.test.ts @@ -1,5 +1,5 @@ import { expect, it, describe } from "vitest"; -import { readableColor } from "../../src/plugin"; +import { readableColor } from "../../src/plugin/readableColor"; import { mycolor } from "../../src/index"; describe("mycolor plugin: readableColor", () => { diff --git a/test/plugin/theme-colors.test.ts b/test/plugin/theme-colors.test.ts index 2019ea2..afb2f6e 100644 --- a/test/plugin/theme-colors.test.ts +++ b/test/plugin/theme-colors.test.ts @@ -1,6 +1,6 @@ import { expect, it, describe } from "vitest"; import { mycolor } from "../../src"; -import { themeColors } from "../../src/plugin"; +import { themeColors } from "../../src/plugin/themeColors"; describe("mycolor plugin: themeColors", () => { const fixture = {