@tokens-studio/tokenscript-schemas 0.0.10 → 0.0.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli/index.cjs +30 -4
- package/dist/cli/index.cjs.map +1 -1
- package/dist/cli/index.js +29 -4
- package/dist/cli/index.js.map +1 -1
- package/package.json +2 -1
- package/src/bundler/bundle-schema.ts +146 -0
- package/src/bundler/index.ts +151 -0
- package/src/bundler/schema-dependency-resolver.ts +299 -0
- package/src/bundler/selective-bundler.test.ts +94 -0
- package/src/bundler/selective-bundler.ts +159 -0
- package/src/bundler/types.ts +93 -0
- package/src/bundler/utils.ts +74 -0
- package/src/cli/commands/bundle.integration.test.ts +153 -0
- package/src/cli/commands/bundle.test.ts +57 -0
- package/src/cli/commands/bundle.ts +240 -0
- package/src/cli/commands/list.ts +109 -0
- package/src/cli/config-schema.ts +36 -0
- package/src/cli/index.ts +50 -0
- package/src/cli/output-generator.ts +63 -0
- package/src/downloader/index.ts +248 -0
- package/src/downloader/types.ts +48 -0
- package/src/index.ts +8 -0
- package/src/schemas/functions/adjust_chroma/adjust-chroma.tokenscript +27 -0
- package/src/schemas/functions/adjust_chroma/schema.json +48 -0
- package/src/schemas/functions/adjust_chroma/unit.test.ts +76 -0
- package/src/schemas/functions/adjust_hue/adjust-hue.tokenscript +32 -0
- package/src/schemas/functions/adjust_hue/schema.json +48 -0
- package/src/schemas/functions/adjust_hue/unit.test.ts +68 -0
- package/src/schemas/functions/adjust_lightness/adjust-lightness.tokenscript +31 -0
- package/src/schemas/functions/adjust_lightness/schema.json +48 -0
- package/src/schemas/functions/adjust_lightness/unit.test.ts +88 -0
- package/src/schemas/functions/adjust_to_contrast/adjust-to-contrast.tokenscript +131 -0
- package/src/schemas/functions/adjust_to_contrast/schema.json +56 -0
- package/src/schemas/functions/adjust_to_contrast/unit.test.ts +81 -0
- package/src/schemas/functions/alpha_blend/alpha-blend.tokenscript +46 -0
- package/src/schemas/functions/alpha_blend/schema.json +28 -0
- package/src/schemas/functions/alpha_blend/unit.test.ts +135 -0
- package/src/schemas/functions/alpha_scale/alpha-scale.tokenscript +38 -0
- package/src/schemas/functions/alpha_scale/schema.json +24 -0
- package/src/schemas/functions/alpha_scale/unit.test.ts +50 -0
- package/src/schemas/functions/analogous/analogous.tokenscript +47 -0
- package/src/schemas/functions/analogous/schema.json +28 -0
- package/src/schemas/functions/analogous/unit.test.ts +64 -0
- package/src/schemas/functions/apca_contrast/apca-contrast.tokenscript +129 -0
- package/src/schemas/functions/apca_contrast/schema.json +24 -0
- package/src/schemas/functions/apca_contrast/unit.test.ts +259 -0
- package/src/schemas/functions/are_similar/are-similar.tokenscript +24 -0
- package/src/schemas/functions/are_similar/schema.json +57 -0
- package/src/schemas/functions/are_similar/unit.test.ts +57 -0
- package/src/schemas/functions/auto_text_color/auto-text-color.tokenscript +41 -0
- package/src/schemas/functions/auto_text_color/schema.json +53 -0
- package/src/schemas/functions/auto_text_color/unit.test.ts +122 -0
- package/src/schemas/functions/best_contrast/best-contrast.tokenscript +66 -0
- package/src/schemas/functions/best_contrast/schema.json +24 -0
- package/src/schemas/functions/best_contrast/unit.test.ts +64 -0
- package/src/schemas/functions/chroma/chroma.tokenscript +12 -0
- package/src/schemas/functions/chroma/schema.json +44 -0
- package/src/schemas/functions/chroma/unit.test.ts +86 -0
- package/src/schemas/functions/clamp_chroma/clamp-chroma.tokenscript +21 -0
- package/src/schemas/functions/clamp_chroma/schema.json +52 -0
- package/src/schemas/functions/clamp_chroma/unit.test.ts +60 -0
- package/src/schemas/functions/clamp_lightness/clamp-lightness.tokenscript +21 -0
- package/src/schemas/functions/clamp_lightness/schema.json +52 -0
- package/src/schemas/functions/clamp_lightness/unit.test.ts +76 -0
- package/src/schemas/functions/clamp_to_gamut/clamp-to-gamut.tokenscript +41 -0
- package/src/schemas/functions/clamp_to_gamut/schema.json +20 -0
- package/src/schemas/functions/clamp_to_gamut/unit.test.ts +167 -0
- package/src/schemas/functions/complement/complement.tokenscript +21 -0
- package/src/schemas/functions/complement/schema.json +20 -0
- package/src/schemas/functions/complement/unit.test.ts +81 -0
- package/src/schemas/functions/contrast_ratio/contrast-ratio.tokenscript +36 -0
- package/src/schemas/functions/contrast_ratio/schema.json +24 -0
- package/src/schemas/functions/contrast_ratio/unit.test.ts +91 -0
- package/src/schemas/functions/cooler/cooler.tokenscript +45 -0
- package/src/schemas/functions/cooler/schema.json +43 -0
- package/src/schemas/functions/cooler/unit.test.ts +69 -0
- package/src/schemas/functions/darken/darken.tokenscript +37 -0
- package/src/schemas/functions/darken/schema.json +24 -0
- package/src/schemas/functions/darken/unit.test.ts +105 -0
- package/src/schemas/functions/delta_e_2000/delta-e-2000.tokenscript +184 -0
- package/src/schemas/functions/delta_e_2000/schema.json +36 -0
- package/src/schemas/functions/delta_e_2000/unit.test.ts +243 -0
- package/src/schemas/functions/delta_e_76/delta-e-76.tokenscript +45 -0
- package/src/schemas/functions/delta_e_76/schema.json +24 -0
- package/src/schemas/functions/delta_e_76/unit.test.ts +123 -0
- package/src/schemas/functions/delta_e_ok/delta-e-ok.tokenscript +43 -0
- package/src/schemas/functions/delta_e_ok/schema.json +24 -0
- package/src/schemas/functions/delta_e_ok/unit.test.ts +235 -0
- package/src/schemas/functions/desaturate/desaturate.tokenscript +32 -0
- package/src/schemas/functions/desaturate/schema.json +24 -0
- package/src/schemas/functions/desaturate/unit.test.ts +54 -0
- package/src/schemas/functions/distributed/distributed.tokenscript +54 -0
- package/src/schemas/functions/distributed/schema.json +32 -0
- package/src/schemas/functions/distributed/unit.test.ts +58 -0
- package/src/schemas/functions/diverging/diverging.tokenscript +58 -0
- package/src/schemas/functions/diverging/schema.json +32 -0
- package/src/schemas/functions/diverging/unit.test.ts +70 -0
- package/src/schemas/functions/grayscale/grayscale.tokenscript +17 -0
- package/src/schemas/functions/grayscale/schema.json +20 -0
- package/src/schemas/functions/grayscale/unit.test.ts +79 -0
- package/src/schemas/functions/harmonize/harmonize.tokenscript +61 -0
- package/src/schemas/functions/harmonize/schema.json +52 -0
- package/src/schemas/functions/harmonize/unit.test.ts +56 -0
- package/src/schemas/functions/hue/hue.tokenscript +12 -0
- package/src/schemas/functions/hue/schema.json +44 -0
- package/src/schemas/functions/hue/unit.test.ts +75 -0
- package/src/schemas/functions/hue_difference/hue-difference.tokenscript +42 -0
- package/src/schemas/functions/hue_difference/schema.json +24 -0
- package/src/schemas/functions/hue_difference/unit.test.ts +125 -0
- package/src/schemas/functions/in_gamut/in-gamut.tokenscript +51 -0
- package/src/schemas/functions/in_gamut/schema.json +24 -0
- package/src/schemas/functions/in_gamut/unit.test.ts +178 -0
- package/src/schemas/functions/interpolate/interpolate.tokenscript +61 -0
- package/src/schemas/functions/interpolate/schema.json +52 -0
- package/src/schemas/functions/interpolate/unit.test.ts +96 -0
- package/src/schemas/functions/invert/invert-initializer.tokenscript +29 -0
- package/src/schemas/functions/invert/schema.json +20 -0
- package/src/schemas/functions/invert/unit.test.ts +216 -0
- package/src/schemas/functions/is_cool/is-cool.tokenscript +41 -0
- package/src/schemas/functions/is_cool/schema.json +20 -0
- package/src/schemas/functions/is_cool/unit.test.ts +189 -0
- package/src/schemas/functions/is_dark/is-dark.tokenscript +16 -0
- package/src/schemas/functions/is_dark/schema.json +24 -0
- package/src/schemas/functions/is_dark/unit.test.ts +87 -0
- package/src/schemas/functions/is_light/is-light.tokenscript +16 -0
- package/src/schemas/functions/is_light/schema.json +24 -0
- package/src/schemas/functions/is_light/unit.test.ts +86 -0
- package/src/schemas/functions/is_neutral/is-neutral.tokenscript +16 -0
- package/src/schemas/functions/is_neutral/schema.json +53 -0
- package/src/schemas/functions/is_neutral/unit.test.ts +85 -0
- package/src/schemas/functions/is_warm/is-warm.tokenscript +62 -0
- package/src/schemas/functions/is_warm/schema.json +20 -0
- package/src/schemas/functions/is_warm/unit.test.ts +161 -0
- package/src/schemas/functions/lighten/lighten.tokenscript +37 -0
- package/src/schemas/functions/lighten/schema.json +24 -0
- package/src/schemas/functions/lighten/unit.test.ts +109 -0
- package/src/schemas/functions/lightness/lightness.tokenscript +12 -0
- package/src/schemas/functions/lightness/schema.json +49 -0
- package/src/schemas/functions/lightness/unit.test.ts +99 -0
- package/src/schemas/functions/luminance/luminance.tokenscript +16 -0
- package/src/schemas/functions/luminance/schema.json +20 -0
- package/src/schemas/functions/luminance/unit.test.ts +105 -0
- package/src/schemas/functions/meets_contrast/meets-contrast.tokenscript +49 -0
- package/src/schemas/functions/meets_contrast/schema.json +28 -0
- package/src/schemas/functions/meets_contrast/unit.test.ts +170 -0
- package/src/schemas/functions/mix/mix.tokenscript +47 -0
- package/src/schemas/functions/mix/schema.json +28 -0
- package/src/schemas/functions/mix/unit.test.ts +95 -0
- package/src/schemas/functions/monochromatic/monochromatic.tokenscript +72 -0
- package/src/schemas/functions/monochromatic/schema.json +24 -0
- package/src/schemas/functions/monochromatic/unit.test.ts +91 -0
- package/src/schemas/functions/muted/muted.tokenscript +25 -0
- package/src/schemas/functions/muted/schema.json +48 -0
- package/src/schemas/functions/muted/unit.test.ts +100 -0
- package/src/schemas/functions/neutral_variant/neutral-variant.tokenscript +23 -0
- package/src/schemas/functions/neutral_variant/schema.json +48 -0
- package/src/schemas/functions/neutral_variant/unit.test.ts +102 -0
- package/src/schemas/functions/relative_luminance/relative-luminance.tokenscript +15 -0
- package/src/schemas/functions/relative_luminance/schema.json +49 -0
- package/src/schemas/functions/relative_luminance/unit.test.ts +104 -0
- package/src/schemas/functions/rotate_hue/rotate-hue.tokenscript +20 -0
- package/src/schemas/functions/rotate_hue/schema.json +24 -0
- package/src/schemas/functions/rotate_hue/unit.test.ts +86 -0
- package/src/schemas/functions/saturate/saturate.tokenscript +33 -0
- package/src/schemas/functions/saturate/schema.json +24 -0
- package/src/schemas/functions/saturate/unit.test.ts +59 -0
- package/src/schemas/functions/scale_chroma/scale-chroma.tokenscript +22 -0
- package/src/schemas/functions/scale_chroma/schema.json +48 -0
- package/src/schemas/functions/scale_chroma/unit.test.ts +79 -0
- package/src/schemas/functions/scale_lightness/scale-lightness.tokenscript +23 -0
- package/src/schemas/functions/scale_lightness/schema.json +48 -0
- package/src/schemas/functions/scale_lightness/unit.test.ts +73 -0
- package/src/schemas/functions/sepia/schema.json +48 -0
- package/src/schemas/functions/sepia/sepia.tokenscript +54 -0
- package/src/schemas/functions/sepia/unit.test.ts +88 -0
- package/src/schemas/functions/set_chroma/schema.json +24 -0
- package/src/schemas/functions/set_chroma/set-chroma.tokenscript +18 -0
- package/src/schemas/functions/set_chroma/unit.test.ts +79 -0
- package/src/schemas/functions/set_hue/schema.json +24 -0
- package/src/schemas/functions/set_hue/set-hue.tokenscript +18 -0
- package/src/schemas/functions/set_hue/unit.test.ts +90 -0
- package/src/schemas/functions/set_lightness/schema.json +24 -0
- package/src/schemas/functions/set_lightness/set-lightness.tokenscript +18 -0
- package/src/schemas/functions/set_lightness/unit.test.ts +80 -0
- package/src/schemas/functions/shade_scale/schema.json +24 -0
- package/src/schemas/functions/shade_scale/shade-scale.tokenscript +61 -0
- package/src/schemas/functions/shade_scale/unit.test.ts +64 -0
- package/src/schemas/functions/split_complement/schema.json +24 -0
- package/src/schemas/functions/split_complement/split-complement.tokenscript +38 -0
- package/src/schemas/functions/split_complement/unit.test.ts +53 -0
- package/src/schemas/functions/steps/schema.json +28 -0
- package/src/schemas/functions/steps/steps.tokenscript +54 -0
- package/src/schemas/functions/steps/unit.test.ts +71 -0
- package/src/schemas/functions/tetradic/schema.json +20 -0
- package/src/schemas/functions/tetradic/tetradic.tokenscript +40 -0
- package/src/schemas/functions/tetradic/unit.test.ts +50 -0
- package/src/schemas/functions/tint_scale/schema.json +32 -0
- package/src/schemas/functions/tint_scale/tint-scale.tokenscript +71 -0
- package/src/schemas/functions/tint_scale/unit.test.ts +64 -0
- package/src/schemas/functions/to_gamut/schema.json +48 -0
- package/src/schemas/functions/to_gamut/to-gamut.tokenscript +96 -0
- package/src/schemas/functions/to_gamut/unit.test.ts +97 -0
- package/src/schemas/functions/triadic/schema.json +20 -0
- package/src/schemas/functions/triadic/triadic.tokenscript +33 -0
- package/src/schemas/functions/triadic/unit.test.ts +64 -0
- package/src/schemas/functions/vibrant/schema.json +48 -0
- package/src/schemas/functions/vibrant/unit.test.ts +55 -0
- package/src/schemas/functions/vibrant/vibrant.tokenscript +29 -0
- package/src/schemas/functions/warmer/schema.json +43 -0
- package/src/schemas/functions/warmer/unit.test.ts +69 -0
- package/src/schemas/functions/warmer/warmer.tokenscript +45 -0
- package/src/schemas/functions/wcag_level/schema.json +48 -0
- package/src/schemas/functions/wcag_level/unit.test.ts +75 -0
- package/src/schemas/functions/wcag_level/wcag-level.tokenscript +50 -0
- package/src/schemas/types/css-color/from-hsl-color.tokenscript +16 -0
- package/src/schemas/types/css-color/from-hwb-color.tokenscript +16 -0
- package/src/schemas/types/css-color/from-lab-color.tokenscript +16 -0
- package/src/schemas/types/css-color/from-lch-color.tokenscript +16 -0
- package/src/schemas/types/css-color/from-oklab-color.tokenscript +16 -0
- package/src/schemas/types/css-color/from-oklch-color.tokenscript +16 -0
- package/src/schemas/types/css-color/from-p3-color.tokenscript +16 -0
- package/src/schemas/types/css-color/from-rgb-color.tokenscript +15 -0
- package/src/schemas/types/css-color/from-srgb-color.tokenscript +16 -0
- package/src/schemas/types/css-color/from-srgb-linear-color.tokenscript +16 -0
- package/src/schemas/types/css-color/from-xyz-d50-color.tokenscript +16 -0
- package/src/schemas/types/css-color/from-xyz-d65-color.tokenscript +16 -0
- package/src/schemas/types/css-color/initializer.tokenscript +13 -0
- package/src/schemas/types/css-color/schema.json +148 -0
- package/src/schemas/types/css-color/unit.test.ts +402 -0
- package/src/schemas/types/hex-color/initializer.tokenscript +3 -0
- package/src/schemas/types/hex-color/schema.json +24 -0
- package/src/schemas/types/hex-color/unit.test.ts +123 -0
- package/src/schemas/types/hsl-color/from-srgb.tokenscript +87 -0
- package/src/schemas/types/hsl-color/initializer.tokenscript +16 -0
- package/src/schemas/types/hsl-color/schema.json +48 -0
- package/src/schemas/types/hsl-color/unit.test.ts +201 -0
- package/src/schemas/types/hsv-color/from-srgb.tokenscript +80 -0
- package/src/schemas/types/hsv-color/initializer.tokenscript +16 -0
- package/src/schemas/types/hsv-color/schema.json +48 -0
- package/src/schemas/types/hsv-color/unit.test.ts +162 -0
- package/src/schemas/types/hwb-color/from-hsv.tokenscript +31 -0
- package/src/schemas/types/hwb-color/initializer.tokenscript +16 -0
- package/src/schemas/types/hwb-color/schema.json +48 -0
- package/src/schemas/types/hwb-color/unit.test.ts +150 -0
- package/src/schemas/types/lab-color/from-xyz-d50.tokenscript +78 -0
- package/src/schemas/types/lab-color/initializer.tokenscript +16 -0
- package/src/schemas/types/lab-color/schema.json +48 -0
- package/src/schemas/types/lab-color/unit.test.ts +263 -0
- package/src/schemas/types/lch-color/from-lab.tokenscript +44 -0
- package/src/schemas/types/lch-color/initializer.tokenscript +16 -0
- package/src/schemas/types/lch-color/schema.json +48 -0
- package/src/schemas/types/lch-color/unit.test.ts +173 -0
- package/src/schemas/types/okhsl-color/from-oklab.tokenscript +410 -0
- package/src/schemas/types/okhsl-color/initializer.tokenscript +24 -0
- package/src/schemas/types/okhsl-color/schema.json +48 -0
- package/src/schemas/types/okhsl-color/unit.test.ts +514 -0
- package/src/schemas/types/okhsv-color/from-oklab.tokenscript +286 -0
- package/src/schemas/types/okhsv-color/initializer.tokenscript +24 -0
- package/src/schemas/types/okhsv-color/schema.json +48 -0
- package/src/schemas/types/okhsv-color/unit.test.ts +499 -0
- package/src/schemas/types/oklab-color/from-okhsl.tokenscript +195 -0
- package/src/schemas/types/oklab-color/from-okhsv.tokenscript +197 -0
- package/src/schemas/types/oklab-color/from-oklch.tokenscript +39 -0
- package/src/schemas/types/oklab-color/from-xyz-d65.tokenscript +43 -0
- package/src/schemas/types/oklab-color/initializer.tokenscript +16 -0
- package/src/schemas/types/oklab-color/schema.json +78 -0
- package/src/schemas/types/oklab-color/unit.test.ts +345 -0
- package/src/schemas/types/oklch-color/from-oklab.tokenscript +45 -0
- package/src/schemas/types/oklch-color/initializer.tokenscript +16 -0
- package/src/schemas/types/oklch-color/schema.json +48 -0
- package/src/schemas/types/oklch-color/unit.test.ts +267 -0
- package/src/schemas/types/p3-color/from-p3-linear.tokenscript +59 -0
- package/src/schemas/types/p3-color/initializer.tokenscript +16 -0
- package/src/schemas/types/p3-color/schema.json +48 -0
- package/src/schemas/types/p3-color/unit.test.ts +119 -0
- package/src/schemas/types/p3-linear-color/from-xyz-d65.tokenscript +47 -0
- package/src/schemas/types/p3-linear-color/initializer.tokenscript +16 -0
- package/src/schemas/types/p3-linear-color/schema.json +48 -0
- package/src/schemas/types/p3-linear-color/unit.test.ts +82 -0
- package/src/schemas/types/rgb-color/from-hex.tokenscript +43 -0
- package/src/schemas/types/rgb-color/initializer.tokenscript +16 -0
- package/src/schemas/types/rgb-color/schema.json +55 -0
- package/src/schemas/types/rgb-color/to-hex.tokenscript +42 -0
- package/src/schemas/types/rgb-color/unit.test.ts +302 -0
- package/src/schemas/types/srgb-color/from-hsl.tokenscript +106 -0
- package/src/schemas/types/srgb-color/from-linear.tokenscript +58 -0
- package/src/schemas/types/srgb-color/from-rgb.tokenscript +20 -0
- package/src/schemas/types/srgb-color/initializer.tokenscript +16 -0
- package/src/schemas/types/srgb-color/schema.json +68 -0
- package/src/schemas/types/srgb-color/unit.test.ts +303 -0
- package/src/schemas/types/srgb-linear-color/from-srgb.tokenscript +55 -0
- package/src/schemas/types/srgb-linear-color/from-xyz-d65.tokenscript +34 -0
- package/src/schemas/types/srgb-linear-color/initializer.tokenscript +13 -0
- package/src/schemas/types/srgb-linear-color/schema.json +58 -0
- package/src/schemas/types/srgb-linear-color/unit.test.ts +291 -0
- package/src/schemas/types/xyz-d50-color/from-xyz-d65.tokenscript +36 -0
- package/src/schemas/types/xyz-d50-color/initializer.tokenscript +16 -0
- package/src/schemas/types/xyz-d50-color/schema.json +48 -0
- package/src/schemas/types/xyz-d50-color/unit.test.ts +240 -0
- package/src/schemas/types/xyz-d65-color/from-linear-p3.tokenscript +47 -0
- package/src/schemas/types/xyz-d65-color/from-linear-srgb.tokenscript +38 -0
- package/src/schemas/types/xyz-d65-color/from-oklab.tokenscript +44 -0
- package/src/schemas/types/xyz-d65-color/initializer.tokenscript +16 -0
- package/src/schemas/types/xyz-d65-color/schema.json +68 -0
- package/src/schemas/types/xyz-d65-color/unit.test.ts +319 -0
- package/src/utils/schema-uri.ts +192 -0
- package/src/utils/type.ts +194 -0
- package/dist/cli/index.d.cts +0 -1
- package/dist/cli/index.d.ts +0 -1
- package/dist/index.d.cts +0 -158
- package/dist/index.d.ts +0 -158
|
@@ -0,0 +1,345 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OKLab Color Schema Tests
|
|
3
|
+
*
|
|
4
|
+
* Tests for the OKLab perceptually uniform color space
|
|
5
|
+
* Validates against ColorJS for parity
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { log } from "@tests/helpers/logger";
|
|
9
|
+
import { executeWithSchema, getBundledSchema } from "@tests/helpers/schema-test-utils";
|
|
10
|
+
import Color from "colorjs.io";
|
|
11
|
+
import { describe, expect, it } from "vitest";
|
|
12
|
+
import type { ColorSpecification } from "@/bundler/types";
|
|
13
|
+
|
|
14
|
+
// ColorJS reference tolerance (OKLab is sensitive to precision)
|
|
15
|
+
const TOLERANCE = 1e-7;
|
|
16
|
+
|
|
17
|
+
describe("OKLab Color Schema", () => {
|
|
18
|
+
describe("Schema Definition", () => {
|
|
19
|
+
it("should have correct schema structure", async () => {
|
|
20
|
+
const schema = (await getBundledSchema("oklab-color")) as ColorSpecification;
|
|
21
|
+
|
|
22
|
+
expect(schema.name).toBe("OKLab");
|
|
23
|
+
expect(schema.type).toBe("color");
|
|
24
|
+
expect(schema.schema).toBeDefined();
|
|
25
|
+
expect(schema.schema?.properties).toHaveProperty("l");
|
|
26
|
+
expect(schema.schema?.properties).toHaveProperty("a");
|
|
27
|
+
expect(schema.schema?.properties).toHaveProperty("b");
|
|
28
|
+
expect(schema.schema?.required).toEqual(["l", "a", "b"]);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it("should have oklab initializer", async () => {
|
|
32
|
+
const schema = (await getBundledSchema("oklab-color")) as ColorSpecification;
|
|
33
|
+
|
|
34
|
+
expect(schema.initializers).toHaveLength(1);
|
|
35
|
+
expect(schema.initializers[0].keyword).toBe("oklab");
|
|
36
|
+
expect(schema.initializers[0].script.script).toContain("Color.OKLab");
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it("should have conversion from XYZ-D65", async () => {
|
|
40
|
+
const schema = (await getBundledSchema("oklab-color")) as ColorSpecification;
|
|
41
|
+
|
|
42
|
+
expect(schema.conversions.length).toBeGreaterThanOrEqual(1);
|
|
43
|
+
|
|
44
|
+
const xyzToOklab = schema.conversions.find((c: { source: string }) =>
|
|
45
|
+
c.source.includes("xyz-d65-color"),
|
|
46
|
+
);
|
|
47
|
+
expect(xyzToOklab).toBeDefined();
|
|
48
|
+
expect(xyzToOklab?.lossless).toBe(true);
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
describe("Initialization", () => {
|
|
53
|
+
it("should create OKLab color from values", async () => {
|
|
54
|
+
const result = await executeWithSchema(
|
|
55
|
+
"oklab-color",
|
|
56
|
+
"type",
|
|
57
|
+
`
|
|
58
|
+
variable c: Color.OKLab;
|
|
59
|
+
c.l = 0.7;
|
|
60
|
+
c.a = 0.1;
|
|
61
|
+
c.b = -0.1;
|
|
62
|
+
c
|
|
63
|
+
`,
|
|
64
|
+
);
|
|
65
|
+
|
|
66
|
+
expect(result?.constructor.name).toBe("ColorSymbol");
|
|
67
|
+
expect((result as any).subType).toBe("OKLab");
|
|
68
|
+
expect((result as any).value.l.value).toBeCloseTo(0.7, 10);
|
|
69
|
+
expect((result as any).value.a.value).toBeCloseTo(0.1, 10);
|
|
70
|
+
expect((result as any).value.b.value).toBeCloseTo(-0.1, 10);
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
describe("Conversion from XYZ-D65 to OKLab", () => {
|
|
75
|
+
it("should convert XYZ-D65 white to OKLab", async () => {
|
|
76
|
+
// D65 white point XYZ values
|
|
77
|
+
const result = await executeWithSchema(
|
|
78
|
+
"oklab-color",
|
|
79
|
+
"type",
|
|
80
|
+
`
|
|
81
|
+
variable xyz: Color.XYZD65;
|
|
82
|
+
xyz.x = 0.95047;
|
|
83
|
+
xyz.y = 1.0;
|
|
84
|
+
xyz.z = 1.08883;
|
|
85
|
+
xyz.to.oklab()
|
|
86
|
+
`,
|
|
87
|
+
);
|
|
88
|
+
|
|
89
|
+
// ColorJS reference
|
|
90
|
+
const colorJS = new Color("xyz-d65", [0.95047, 1.0, 1.08883]).to("oklab");
|
|
91
|
+
|
|
92
|
+
log.info(`\n=== D65 WHITE → OKLab ===`);
|
|
93
|
+
log.info(
|
|
94
|
+
`TokenScript: { l: ${(result as any).value.l.value}, a: ${(result as any).value.a.value}, b: ${(result as any).value.b.value} }`,
|
|
95
|
+
);
|
|
96
|
+
log.info(
|
|
97
|
+
`ColorJS: { l: ${colorJS.coords[0]}, a: ${colorJS.coords[1]}, b: ${colorJS.coords[2]} }`,
|
|
98
|
+
);
|
|
99
|
+
|
|
100
|
+
expect((result as any).value.l.value).toBeCloseTo(colorJS.coords[0], 6);
|
|
101
|
+
expect((result as any).value.a.value).toBeCloseTo(colorJS.coords[1], 6);
|
|
102
|
+
expect((result as any).value.b.value).toBeCloseTo(colorJS.coords[2], 6);
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
it("should convert red XYZ-D65 to OKLab", async () => {
|
|
106
|
+
// Red in XYZ-D65
|
|
107
|
+
const colorJSRed = new Color("srgb", [1, 0, 0]);
|
|
108
|
+
const redXYZ = colorJSRed.to("xyz-d65");
|
|
109
|
+
|
|
110
|
+
const result = await executeWithSchema(
|
|
111
|
+
"oklab-color",
|
|
112
|
+
"type",
|
|
113
|
+
`
|
|
114
|
+
variable xyz: Color.XYZD65;
|
|
115
|
+
xyz.x = ${redXYZ.coords[0]};
|
|
116
|
+
xyz.y = ${redXYZ.coords[1]};
|
|
117
|
+
xyz.z = ${redXYZ.coords[2]};
|
|
118
|
+
xyz.to.oklab()
|
|
119
|
+
`,
|
|
120
|
+
);
|
|
121
|
+
|
|
122
|
+
const colorJS = redXYZ.to("oklab");
|
|
123
|
+
|
|
124
|
+
log.info(`\n=== RED XYZ → OKLab ===`);
|
|
125
|
+
log.info(
|
|
126
|
+
`TokenScript: { l: ${(result as any).value.l.value}, a: ${(result as any).value.a.value}, b: ${(result as any).value.b.value} }`,
|
|
127
|
+
);
|
|
128
|
+
log.info(
|
|
129
|
+
`ColorJS: { l: ${colorJS.coords[0]}, a: ${colorJS.coords[1]}, b: ${colorJS.coords[2]} }`,
|
|
130
|
+
);
|
|
131
|
+
|
|
132
|
+
expect((result as any).value.l.value).toBeCloseTo(colorJS.coords[0], 6);
|
|
133
|
+
expect((result as any).value.a.value).toBeCloseTo(colorJS.coords[1], 6);
|
|
134
|
+
expect((result as any).value.b.value).toBeCloseTo(colorJS.coords[2], 6);
|
|
135
|
+
});
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
describe("Full Conversion Chain: sRGB → Linear sRGB → XYZ-D65 → OKLab", () => {
|
|
139
|
+
it("should convert sRGB red through to OKLab", async () => {
|
|
140
|
+
const result = await executeWithSchema(
|
|
141
|
+
"oklab-color",
|
|
142
|
+
"type",
|
|
143
|
+
`
|
|
144
|
+
variable srgb: Color.SRGB;
|
|
145
|
+
srgb.r = 1;
|
|
146
|
+
srgb.g = 0;
|
|
147
|
+
srgb.b = 0;
|
|
148
|
+
|
|
149
|
+
variable linear: Color.LinearSRGB = srgb.to.linearsrgb();
|
|
150
|
+
variable xyz: Color.XYZD65 = linear.to.xyzd65();
|
|
151
|
+
xyz.to.oklab()
|
|
152
|
+
`,
|
|
153
|
+
);
|
|
154
|
+
|
|
155
|
+
// ColorJS reference: sRGB red → OKLab
|
|
156
|
+
const colorJS = new Color("srgb", [1, 0, 0]).to("oklab");
|
|
157
|
+
|
|
158
|
+
log.info(`\n=== sRGB RED → OKLab (full chain) ===`);
|
|
159
|
+
log.info(
|
|
160
|
+
`TokenScript: { l: ${(result as any).value.l.value}, a: ${(result as any).value.a.value}, b: ${(result as any).value.b.value} }`,
|
|
161
|
+
);
|
|
162
|
+
log.info(
|
|
163
|
+
`ColorJS: { l: ${colorJS.coords[0]}, a: ${colorJS.coords[1]}, b: ${colorJS.coords[2]} }`,
|
|
164
|
+
);
|
|
165
|
+
|
|
166
|
+
expect((result as any).value.l.value).toBeCloseTo(colorJS.coords[0], 6);
|
|
167
|
+
expect((result as any).value.a.value).toBeCloseTo(colorJS.coords[1], 6);
|
|
168
|
+
expect((result as any).value.b.value).toBeCloseTo(colorJS.coords[2], 6);
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
it("should convert sRGB green through to OKLab", async () => {
|
|
172
|
+
const result = await executeWithSchema(
|
|
173
|
+
"oklab-color",
|
|
174
|
+
"type",
|
|
175
|
+
`
|
|
176
|
+
variable srgb: Color.SRGB;
|
|
177
|
+
srgb.r = 0;
|
|
178
|
+
srgb.g = 1;
|
|
179
|
+
srgb.b = 0;
|
|
180
|
+
|
|
181
|
+
variable linear: Color.LinearSRGB = srgb.to.linearsrgb();
|
|
182
|
+
variable xyz: Color.XYZD65 = linear.to.xyzd65();
|
|
183
|
+
xyz.to.oklab()
|
|
184
|
+
`,
|
|
185
|
+
);
|
|
186
|
+
|
|
187
|
+
const colorJS = new Color("srgb", [0, 1, 0]).to("oklab");
|
|
188
|
+
|
|
189
|
+
expect((result as any).value.l.value).toBeCloseTo(colorJS.coords[0], 6);
|
|
190
|
+
expect((result as any).value.a.value).toBeCloseTo(colorJS.coords[1], 6);
|
|
191
|
+
expect((result as any).value.b.value).toBeCloseTo(colorJS.coords[2], 6);
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
it("should convert sRGB blue through to OKLab", async () => {
|
|
195
|
+
const result = await executeWithSchema(
|
|
196
|
+
"oklab-color",
|
|
197
|
+
"type",
|
|
198
|
+
`
|
|
199
|
+
variable srgb: Color.SRGB;
|
|
200
|
+
srgb.r = 0;
|
|
201
|
+
srgb.g = 0;
|
|
202
|
+
srgb.b = 1;
|
|
203
|
+
|
|
204
|
+
variable linear: Color.LinearSRGB = srgb.to.linearsrgb();
|
|
205
|
+
variable xyz: Color.XYZD65 = linear.to.xyzd65();
|
|
206
|
+
xyz.to.oklab()
|
|
207
|
+
`,
|
|
208
|
+
);
|
|
209
|
+
|
|
210
|
+
const colorJS = new Color("srgb", [0, 0, 1]).to("oklab");
|
|
211
|
+
|
|
212
|
+
expect((result as any).value.l.value).toBeCloseTo(colorJS.coords[0], 6);
|
|
213
|
+
expect((result as any).value.a.value).toBeCloseTo(colorJS.coords[1], 6);
|
|
214
|
+
expect((result as any).value.b.value).toBeCloseTo(colorJS.coords[2], 6);
|
|
215
|
+
});
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
describe("ColorJS Parity", () => {
|
|
219
|
+
const testCases = [
|
|
220
|
+
{ name: "red", srgb: [1, 0, 0] },
|
|
221
|
+
{ name: "green", srgb: [0, 1, 0] },
|
|
222
|
+
{ name: "blue", srgb: [0, 0, 1] },
|
|
223
|
+
{ name: "white", srgb: [1, 1, 1] },
|
|
224
|
+
{ name: "black", srgb: [0, 0, 0] },
|
|
225
|
+
{ name: "gray-50%", srgb: [0.5, 0.5, 0.5] },
|
|
226
|
+
{ name: "coral", srgb: [1, 0.341, 0.2] },
|
|
227
|
+
{ name: "cyan", srgb: [0, 1, 1] },
|
|
228
|
+
{ name: "magenta", srgb: [1, 0, 1] },
|
|
229
|
+
{ name: "yellow", srgb: [1, 1, 0] },
|
|
230
|
+
];
|
|
231
|
+
|
|
232
|
+
for (const { name, srgb } of testCases) {
|
|
233
|
+
it(`should match ColorJS for ${name}`, async () => {
|
|
234
|
+
const result = await executeWithSchema(
|
|
235
|
+
"oklab-color",
|
|
236
|
+
"type",
|
|
237
|
+
`
|
|
238
|
+
variable srgb: Color.SRGB;
|
|
239
|
+
srgb.r = ${srgb[0]};
|
|
240
|
+
srgb.g = ${srgb[1]};
|
|
241
|
+
srgb.b = ${srgb[2]};
|
|
242
|
+
|
|
243
|
+
variable linear: Color.LinearSRGB = srgb.to.linearsrgb();
|
|
244
|
+
variable xyz: Color.XYZD65 = linear.to.xyzd65();
|
|
245
|
+
xyz.to.oklab()
|
|
246
|
+
`,
|
|
247
|
+
);
|
|
248
|
+
|
|
249
|
+
// ColorJS reference
|
|
250
|
+
const colorJS = new Color("srgb", srgb as [number, number, number]).to("oklab");
|
|
251
|
+
|
|
252
|
+
const tsL = (result as any).value.l.value;
|
|
253
|
+
const tsA = (result as any).value.a.value;
|
|
254
|
+
const tsB = (result as any).value.b.value;
|
|
255
|
+
|
|
256
|
+
const diffL = Math.abs(tsL - colorJS.coords[0]);
|
|
257
|
+
const diffA = Math.abs(tsA - colorJS.coords[1]);
|
|
258
|
+
const diffB = Math.abs(tsB - colorJS.coords[2]);
|
|
259
|
+
const maxDiff = Math.max(diffL, diffA, diffB);
|
|
260
|
+
|
|
261
|
+
log.info(`\n=== ${name.toUpperCase()} ColorJS Parity ===`);
|
|
262
|
+
log.info(`Input sRGB: { r: ${srgb[0]}, g: ${srgb[1]}, b: ${srgb[2]} }`);
|
|
263
|
+
log.info(
|
|
264
|
+
`TokenScript: { l: ${tsL.toFixed(6)}, a: ${tsA.toFixed(6)}, b: ${tsB.toFixed(6)} }`,
|
|
265
|
+
);
|
|
266
|
+
log.info(
|
|
267
|
+
`ColorJS: { l: ${colorJS.coords[0].toFixed(6)}, a: ${colorJS.coords[1].toFixed(6)}, b: ${colorJS.coords[2].toFixed(6)} }`,
|
|
268
|
+
);
|
|
269
|
+
log.info(`Max Diff: ${maxDiff.toExponential(2)}`);
|
|
270
|
+
log.info(`Status: ${maxDiff < TOLERANCE ? "✅ PASS" : "❌ FAIL"}`);
|
|
271
|
+
|
|
272
|
+
expect(maxDiff).toBeLessThan(TOLERANCE);
|
|
273
|
+
});
|
|
274
|
+
}
|
|
275
|
+
});
|
|
276
|
+
|
|
277
|
+
describe("Edge Cases", () => {
|
|
278
|
+
it("should handle black (L=0)", async () => {
|
|
279
|
+
const result = await executeWithSchema(
|
|
280
|
+
"oklab-color",
|
|
281
|
+
"type",
|
|
282
|
+
`
|
|
283
|
+
variable srgb: Color.SRGB;
|
|
284
|
+
srgb.r = 0;
|
|
285
|
+
srgb.g = 0;
|
|
286
|
+
srgb.b = 0;
|
|
287
|
+
|
|
288
|
+
variable linear: Color.LinearSRGB = srgb.to.linearsrgb();
|
|
289
|
+
variable xyz: Color.XYZD65 = linear.to.xyzd65();
|
|
290
|
+
xyz.to.oklab()
|
|
291
|
+
`,
|
|
292
|
+
);
|
|
293
|
+
|
|
294
|
+
// Black should have L=0 and a=b=0
|
|
295
|
+
expect((result as any).value.l.value).toBeCloseTo(0, 6);
|
|
296
|
+
expect((result as any).value.a.value).toBeCloseTo(0, 6);
|
|
297
|
+
expect((result as any).value.b.value).toBeCloseTo(0, 6);
|
|
298
|
+
});
|
|
299
|
+
|
|
300
|
+
it("should handle white (L=1)", async () => {
|
|
301
|
+
const result = await executeWithSchema(
|
|
302
|
+
"oklab-color",
|
|
303
|
+
"type",
|
|
304
|
+
`
|
|
305
|
+
variable srgb: Color.SRGB;
|
|
306
|
+
srgb.r = 1;
|
|
307
|
+
srgb.g = 1;
|
|
308
|
+
srgb.b = 1;
|
|
309
|
+
|
|
310
|
+
variable linear: Color.LinearSRGB = srgb.to.linearsrgb();
|
|
311
|
+
variable xyz: Color.XYZD65 = linear.to.xyzd65();
|
|
312
|
+
xyz.to.oklab()
|
|
313
|
+
`,
|
|
314
|
+
);
|
|
315
|
+
|
|
316
|
+
const colorJS = new Color("srgb", [1, 1, 1]).to("oklab");
|
|
317
|
+
|
|
318
|
+
// White should have L≈1 and a≈b≈0
|
|
319
|
+
expect((result as any).value.l.value).toBeCloseTo(colorJS.coords[0], 6);
|
|
320
|
+
expect(Math.abs((result as any).value.a.value)).toBeLessThan(1e-5);
|
|
321
|
+
expect(Math.abs((result as any).value.b.value)).toBeLessThan(1e-5);
|
|
322
|
+
});
|
|
323
|
+
|
|
324
|
+
it("should handle neutral grays (a=b≈0)", async () => {
|
|
325
|
+
const result = await executeWithSchema(
|
|
326
|
+
"oklab-color",
|
|
327
|
+
"type",
|
|
328
|
+
`
|
|
329
|
+
variable srgb: Color.SRGB;
|
|
330
|
+
srgb.r = 0.5;
|
|
331
|
+
srgb.g = 0.5;
|
|
332
|
+
srgb.b = 0.5;
|
|
333
|
+
|
|
334
|
+
variable linear: Color.LinearSRGB = srgb.to.linearsrgb();
|
|
335
|
+
variable xyz: Color.XYZD65 = linear.to.xyzd65();
|
|
336
|
+
xyz.to.oklab()
|
|
337
|
+
`,
|
|
338
|
+
);
|
|
339
|
+
|
|
340
|
+
// Gray should have a≈0 and b≈0
|
|
341
|
+
expect(Math.abs((result as any).value.a.value)).toBeLessThan(1e-5);
|
|
342
|
+
expect(Math.abs((result as any).value.b.value)).toBeLessThan(1e-5);
|
|
343
|
+
});
|
|
344
|
+
});
|
|
345
|
+
});
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
// OKLab to OKLCH Conversion
|
|
2
|
+
// Converts Cartesian (a, b) to polar (C, H) coordinates
|
|
3
|
+
// Reference: Björn Ottosson's OKLab specification
|
|
4
|
+
//
|
|
5
|
+
// Algorithm:
|
|
6
|
+
// L stays the same (lightness)
|
|
7
|
+
// C = sqrt(a² + b²) (chroma - distance from neutral axis)
|
|
8
|
+
// H = atan2(b, a) * 180/π (hue angle in degrees)
|
|
9
|
+
//
|
|
10
|
+
// Input: Color.OKLab with l, a, b coordinates
|
|
11
|
+
// Output: Color.OKLCH with l, c, h coordinates
|
|
12
|
+
|
|
13
|
+
// Get input OKLab values
|
|
14
|
+
variable l: Number = {input}.l;
|
|
15
|
+
variable a: Number = {input}.a;
|
|
16
|
+
variable b: Number = {input}.b;
|
|
17
|
+
|
|
18
|
+
// Constants
|
|
19
|
+
variable pi: Number = pi();
|
|
20
|
+
variable rad_to_deg: Number = 180 / pi;
|
|
21
|
+
|
|
22
|
+
// Calculate chroma (distance from neutral axis)
|
|
23
|
+
variable c: Number = sqrt(a * a + b * b);
|
|
24
|
+
|
|
25
|
+
// Calculate hue angle using atan2
|
|
26
|
+
// atan2(y, x) returns angle in radians from -π to π
|
|
27
|
+
variable h_rad: Number = atan2(b, a);
|
|
28
|
+
variable h: Number = h_rad * rad_to_deg;
|
|
29
|
+
|
|
30
|
+
// Normalize hue to 0-360 range
|
|
31
|
+
if (h < 0) [
|
|
32
|
+
h = h + 360;
|
|
33
|
+
];
|
|
34
|
+
|
|
35
|
+
// Create output
|
|
36
|
+
variable output: Color.OKLCH;
|
|
37
|
+
output.l = l;
|
|
38
|
+
output.c = c;
|
|
39
|
+
output.h = h;
|
|
40
|
+
|
|
41
|
+
return output;
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// OKLCH Color Initializer
|
|
2
|
+
// Creates an OKLCH color from L, C, H values
|
|
3
|
+
// Input: List of [l, c, h] values
|
|
4
|
+
|
|
5
|
+
variable lch_values: List = {input};
|
|
6
|
+
variable output: Color.OKLCH;
|
|
7
|
+
|
|
8
|
+
output.l = lch_values.get(0);
|
|
9
|
+
output.c = lch_values.get(1);
|
|
10
|
+
output.h = lch_values.get(2);
|
|
11
|
+
|
|
12
|
+
return output;
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "OKLCH",
|
|
3
|
+
"type": "color",
|
|
4
|
+
"description": "OKLCH color space - the polar form of OKLab. L is lightness (0-1), C is chroma, H is hue angle (0-360).",
|
|
5
|
+
"schema": {
|
|
6
|
+
"type": "object",
|
|
7
|
+
"properties": {
|
|
8
|
+
"l": {
|
|
9
|
+
"type": "number",
|
|
10
|
+
"description": "Lightness (0-1)"
|
|
11
|
+
},
|
|
12
|
+
"c": {
|
|
13
|
+
"type": "number",
|
|
14
|
+
"description": "Chroma (0 to ~0.4 for sRGB gamut)"
|
|
15
|
+
},
|
|
16
|
+
"h": {
|
|
17
|
+
"type": "number",
|
|
18
|
+
"description": "Hue angle (0-360 degrees)"
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"required": ["l", "c", "h"],
|
|
22
|
+
"order": ["l", "c", "h"],
|
|
23
|
+
"additionalProperties": false
|
|
24
|
+
},
|
|
25
|
+
"initializers": [
|
|
26
|
+
{
|
|
27
|
+
"title": "OKLCH Color Initializer",
|
|
28
|
+
"keyword": "oklch",
|
|
29
|
+
"description": "Creates an OKLCH color from L, C, H values",
|
|
30
|
+
"script": {
|
|
31
|
+
"type": "/api/v1/core/tokenscript/0/",
|
|
32
|
+
"script": "./initializer.tokenscript"
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
],
|
|
36
|
+
"conversions": [
|
|
37
|
+
{
|
|
38
|
+
"source": "/api/v1/core/oklab-color/0/",
|
|
39
|
+
"target": "$self",
|
|
40
|
+
"description": "Converts OKLab to OKLCH using Cartesian to polar transformation",
|
|
41
|
+
"lossless": true,
|
|
42
|
+
"script": {
|
|
43
|
+
"type": "/api/v1/core/tokenscript/0/",
|
|
44
|
+
"script": "./from-oklab.tokenscript"
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
]
|
|
48
|
+
}
|