@tokens-studio/tokenscript-schemas 0.0.11 → 0.0.13
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 +31 -8
- package/dist/cli/index.cjs.map +1 -1
- package/dist/cli/index.js +30 -8
- 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 +237 -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
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
import { executeWithSchema, getBundledSchema } from "@tests/helpers/schema-test-utils";
|
|
2
|
+
import { describe, expect, it } from "vitest";
|
|
3
|
+
import type { FunctionSpecification } from "@/bundler/types";
|
|
4
|
+
|
|
5
|
+
describe("Invert Function Schema", () => {
|
|
6
|
+
describe("Schema Definition", () => {
|
|
7
|
+
it("should have correct schema structure", async () => {
|
|
8
|
+
const schema = (await getBundledSchema("invert", "function")) as FunctionSpecification;
|
|
9
|
+
|
|
10
|
+
expect(schema.name).toBe("Invert Color");
|
|
11
|
+
expect(schema.type).toBe("function");
|
|
12
|
+
expect(schema.description).toBe(
|
|
13
|
+
"Inverts a color by inverting each RGB channel (R' = 255 - R, G' = 255 - G, B' = 255 - B).",
|
|
14
|
+
);
|
|
15
|
+
expect(schema.keyword).toBe("invert");
|
|
16
|
+
expect(schema.input).toBeDefined();
|
|
17
|
+
expect(schema.input?.type).toBe("object");
|
|
18
|
+
expect(schema.input?.properties).toHaveProperty("color");
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it("should have script defined", async () => {
|
|
22
|
+
const schema = (await getBundledSchema("invert", "function")) as FunctionSpecification;
|
|
23
|
+
|
|
24
|
+
expect(schema.script).toBeDefined();
|
|
25
|
+
expect(schema.script.script).toBeTruthy();
|
|
26
|
+
expect(schema.script.script).not.toContain("./");
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it("should have requirements", async () => {
|
|
30
|
+
const schema = (await getBundledSchema("invert", "function")) as FunctionSpecification;
|
|
31
|
+
|
|
32
|
+
expect(schema.requirements).toBeDefined();
|
|
33
|
+
expect(schema.requirements).toContain(
|
|
34
|
+
"https://schema.tokenscript.dev.gcp.tokens.studio/api/v1/core/rgb-color/0/",
|
|
35
|
+
);
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
describe("Function Execution", () => {
|
|
40
|
+
it("should invert RGB color", async () => {
|
|
41
|
+
const result = await executeWithSchema(
|
|
42
|
+
"invert",
|
|
43
|
+
"function",
|
|
44
|
+
`
|
|
45
|
+
variable original: Color.Rgb = rgb(255, 128, 64);
|
|
46
|
+
invert(original)
|
|
47
|
+
`,
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
expect(result?.constructor.name).toBe("ColorSymbol");
|
|
51
|
+
expect((result as any).subType).toBe("Rgb");
|
|
52
|
+
expect((result as any).value.r.value).toBe(0);
|
|
53
|
+
expect((result as any).value.g.value).toBe(127);
|
|
54
|
+
expect((result as any).value.b.value).toBe(191);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it("should invert HEX color", async () => {
|
|
58
|
+
const result = await executeWithSchema(
|
|
59
|
+
"invert",
|
|
60
|
+
"function",
|
|
61
|
+
`
|
|
62
|
+
variable original: Color.Hex = #ff8040;
|
|
63
|
+
invert(original)
|
|
64
|
+
`,
|
|
65
|
+
);
|
|
66
|
+
|
|
67
|
+
expect(result?.constructor.name).toBe("ColorSymbol");
|
|
68
|
+
expect((result as any).subType).toBe("Rgb");
|
|
69
|
+
expect((result as any).value.r.value).toBe(0);
|
|
70
|
+
expect((result as any).value.g.value).toBe(127);
|
|
71
|
+
expect((result as any).value.b.value).toBe(191);
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
it("should invert black to white", async () => {
|
|
75
|
+
const result = await executeWithSchema(
|
|
76
|
+
"invert",
|
|
77
|
+
"function",
|
|
78
|
+
`
|
|
79
|
+
variable black: Color.Hex = #000000;
|
|
80
|
+
invert(black)
|
|
81
|
+
`,
|
|
82
|
+
);
|
|
83
|
+
|
|
84
|
+
expect(result?.constructor.name).toBe("ColorSymbol");
|
|
85
|
+
expect((result as any).subType).toBe("Rgb");
|
|
86
|
+
expect((result as any).value.r.value).toBe(255);
|
|
87
|
+
expect((result as any).value.g.value).toBe(255);
|
|
88
|
+
expect((result as any).value.b.value).toBe(255);
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
it("should invert white to black", async () => {
|
|
92
|
+
const result = await executeWithSchema(
|
|
93
|
+
"invert",
|
|
94
|
+
"function",
|
|
95
|
+
`
|
|
96
|
+
variable white: Color.Hex = #ffffff;
|
|
97
|
+
invert(white)
|
|
98
|
+
`,
|
|
99
|
+
);
|
|
100
|
+
|
|
101
|
+
expect(result?.constructor.name).toBe("ColorSymbol");
|
|
102
|
+
expect((result as any).subType).toBe("Rgb");
|
|
103
|
+
expect((result as any).value.r.value).toBe(0);
|
|
104
|
+
expect((result as any).value.g.value).toBe(0);
|
|
105
|
+
expect((result as any).value.b.value).toBe(0);
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
it("should invert gray (127.5 rounds to 128)", async () => {
|
|
109
|
+
const result = await executeWithSchema(
|
|
110
|
+
"invert",
|
|
111
|
+
"function",
|
|
112
|
+
`
|
|
113
|
+
variable gray: Color.Hex = #7f7f7f;
|
|
114
|
+
invert(gray)
|
|
115
|
+
`,
|
|
116
|
+
);
|
|
117
|
+
|
|
118
|
+
expect(result?.constructor.name).toBe("ColorSymbol");
|
|
119
|
+
expect((result as any).subType).toBe("Rgb");
|
|
120
|
+
expect((result as any).value.r.value).toBe(128);
|
|
121
|
+
expect((result as any).value.g.value).toBe(128);
|
|
122
|
+
expect((result as any).value.b.value).toBe(128);
|
|
123
|
+
});
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
describe("Round-trip Inversions", () => {
|
|
127
|
+
it("should return to original color when inverted twice", async () => {
|
|
128
|
+
const result = await executeWithSchema(
|
|
129
|
+
"invert",
|
|
130
|
+
"function",
|
|
131
|
+
`
|
|
132
|
+
variable original: Color.Hex = #3498db;
|
|
133
|
+
variable inverted: Color.Rgb = invert(original);
|
|
134
|
+
variable backToOriginal: Color.Rgb = invert(inverted);
|
|
135
|
+
backToOriginal.to.hex()
|
|
136
|
+
`,
|
|
137
|
+
);
|
|
138
|
+
|
|
139
|
+
expect(result?.constructor.name).toBe("ColorSymbol");
|
|
140
|
+
expect((result as any).subType).toBe("Hex");
|
|
141
|
+
expect(result?.toString()).toBe("#3498db");
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
it("should handle double inversion of RGB color", async () => {
|
|
145
|
+
const result = await executeWithSchema(
|
|
146
|
+
"invert",
|
|
147
|
+
"function",
|
|
148
|
+
`
|
|
149
|
+
variable original: Color.Rgb = rgb(100, 150, 200);
|
|
150
|
+
variable inverted: Color.Rgb = invert(original);
|
|
151
|
+
variable backToOriginal: Color.Rgb = invert(inverted);
|
|
152
|
+
backToOriginal
|
|
153
|
+
`,
|
|
154
|
+
);
|
|
155
|
+
|
|
156
|
+
expect(result?.constructor.name).toBe("ColorSymbol");
|
|
157
|
+
expect((result as any).subType).toBe("Rgb");
|
|
158
|
+
expect((result as any).value.r.value).toBe(100);
|
|
159
|
+
expect((result as any).value.g.value).toBe(150);
|
|
160
|
+
expect((result as any).value.b.value).toBe(200);
|
|
161
|
+
});
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
describe("Edge Cases", () => {
|
|
165
|
+
it("should handle pure red", async () => {
|
|
166
|
+
const result = await executeWithSchema(
|
|
167
|
+
"invert",
|
|
168
|
+
"function",
|
|
169
|
+
`
|
|
170
|
+
variable red: Color.Hex = #ff0000;
|
|
171
|
+
invert(red)
|
|
172
|
+
`,
|
|
173
|
+
);
|
|
174
|
+
|
|
175
|
+
expect(result?.constructor.name).toBe("ColorSymbol");
|
|
176
|
+
expect((result as any).subType).toBe("Rgb");
|
|
177
|
+
expect((result as any).value.r.value).toBe(0);
|
|
178
|
+
expect((result as any).value.g.value).toBe(255);
|
|
179
|
+
expect((result as any).value.b.value).toBe(255);
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
it("should handle pure green", async () => {
|
|
183
|
+
const result = await executeWithSchema(
|
|
184
|
+
"invert",
|
|
185
|
+
"function",
|
|
186
|
+
`
|
|
187
|
+
variable green: Color.Hex = #00ff00;
|
|
188
|
+
invert(green)
|
|
189
|
+
`,
|
|
190
|
+
);
|
|
191
|
+
|
|
192
|
+
expect(result?.constructor.name).toBe("ColorSymbol");
|
|
193
|
+
expect((result as any).subType).toBe("Rgb");
|
|
194
|
+
expect((result as any).value.r.value).toBe(255);
|
|
195
|
+
expect((result as any).value.g.value).toBe(0);
|
|
196
|
+
expect((result as any).value.b.value).toBe(255);
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
it("should handle pure blue", async () => {
|
|
200
|
+
const result = await executeWithSchema(
|
|
201
|
+
"invert",
|
|
202
|
+
"function",
|
|
203
|
+
`
|
|
204
|
+
variable blue: Color.Hex = #0000ff;
|
|
205
|
+
invert(blue)
|
|
206
|
+
`,
|
|
207
|
+
);
|
|
208
|
+
|
|
209
|
+
expect(result?.constructor.name).toBe("ColorSymbol");
|
|
210
|
+
expect((result as any).subType).toBe("Rgb");
|
|
211
|
+
expect((result as any).value.r.value).toBe(255);
|
|
212
|
+
expect((result as any).value.g.value).toBe(255);
|
|
213
|
+
expect((result as any).value.b.value).toBe(0);
|
|
214
|
+
});
|
|
215
|
+
});
|
|
216
|
+
});
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
// Is Cool Color
|
|
2
|
+
// Determines if a color is perceptually cool
|
|
3
|
+
//
|
|
4
|
+
// Cool colors are associated with:
|
|
5
|
+
// - Water, ice, sky
|
|
6
|
+
// - Calm, professional, trustworthy feelings
|
|
7
|
+
// - Receding visual perception (appear further away)
|
|
8
|
+
//
|
|
9
|
+
// OKLCH hue ranges:
|
|
10
|
+
// - Cool: 130-320° (yellow-green through purple)
|
|
11
|
+
// - Includes: green, cyan, blue, purple
|
|
12
|
+
//
|
|
13
|
+
// Achromatic colors (low chroma) are considered cool/neutral
|
|
14
|
+
|
|
15
|
+
variable input: List = {input};
|
|
16
|
+
variable color: Color.OKLCH = input.get(0).to.oklch();
|
|
17
|
+
|
|
18
|
+
// Get hue and chroma
|
|
19
|
+
variable h: Number = color.h;
|
|
20
|
+
variable c: Number = color.c;
|
|
21
|
+
|
|
22
|
+
// Achromatic colors (very low chroma) are considered cool/neutral
|
|
23
|
+
if (c < 0.02) [
|
|
24
|
+
return true;
|
|
25
|
+
];
|
|
26
|
+
|
|
27
|
+
// Normalize hue to 0-360
|
|
28
|
+
if (h < 0) [ h = h + 360; ];
|
|
29
|
+
if (h >= 360) [ h = h - 360; ];
|
|
30
|
+
|
|
31
|
+
// Cool hue range: 130-320° (green through purple)
|
|
32
|
+
variable is_cool: Boolean = false;
|
|
33
|
+
|
|
34
|
+
if (h > 130) [
|
|
35
|
+
if (h < 320) [
|
|
36
|
+
is_cool = true;
|
|
37
|
+
];
|
|
38
|
+
];
|
|
39
|
+
|
|
40
|
+
return is_cool;
|
|
41
|
+
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "Is Cool",
|
|
3
|
+
"type": "function",
|
|
4
|
+
"description": "Checks if a color is perceptually cool. Cool colors have hues in the green-blue-purple range (roughly 130-320° in OKLCH). Returns true for cool colors (green, cyan, blue, purple), false for warm colors. Achromatic colors are considered neutral/cool.",
|
|
5
|
+
"keyword": "is_cool",
|
|
6
|
+
"input": {
|
|
7
|
+
"type": "object",
|
|
8
|
+
"properties": {
|
|
9
|
+
"color": {
|
|
10
|
+
"type": "color",
|
|
11
|
+
"description": "Color to check"
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"script": {
|
|
16
|
+
"type": "/api/v1/core/tokenscript/0/",
|
|
17
|
+
"script": "./is-cool.tokenscript"
|
|
18
|
+
},
|
|
19
|
+
"requirements": ["/api/v1/core/oklch-color/0/"]
|
|
20
|
+
}
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
import { executeWithSchema } from "@tests/helpers/schema-test-utils";
|
|
2
|
+
import { describe, expect, it } from "vitest";
|
|
3
|
+
|
|
4
|
+
describe("Is Cool Function", () => {
|
|
5
|
+
describe("Schema Definition", () => {
|
|
6
|
+
it("should have correct schema structure", async () => {
|
|
7
|
+
const { getBundledSchema } = await import("@tests/helpers/schema-test-utils");
|
|
8
|
+
const schema = await getBundledSchema("is_cool", "function");
|
|
9
|
+
|
|
10
|
+
expect(schema.name).toBe("Is Cool");
|
|
11
|
+
expect(schema.type).toBe("function");
|
|
12
|
+
expect((schema as any).keyword).toBe("is_cool");
|
|
13
|
+
});
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
describe("Cool Colors", () => {
|
|
17
|
+
it("should return true for blue", async () => {
|
|
18
|
+
const result = await executeWithSchema(
|
|
19
|
+
"is_cool",
|
|
20
|
+
"function",
|
|
21
|
+
`
|
|
22
|
+
variable c: Color.SRGB;
|
|
23
|
+
c.r = 0; c.g = 0; c.b = 1;
|
|
24
|
+
is_cool(c)
|
|
25
|
+
`,
|
|
26
|
+
);
|
|
27
|
+
|
|
28
|
+
expect(result.value).toBe(true);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it("should return true for green", async () => {
|
|
32
|
+
const result = await executeWithSchema(
|
|
33
|
+
"is_cool",
|
|
34
|
+
"function",
|
|
35
|
+
`
|
|
36
|
+
variable c: Color.SRGB;
|
|
37
|
+
c.r = 0; c.g = 1; c.b = 0;
|
|
38
|
+
is_cool(c)
|
|
39
|
+
`,
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
expect(result.value).toBe(true);
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it("should return true for cyan", async () => {
|
|
46
|
+
const result = await executeWithSchema(
|
|
47
|
+
"is_cool",
|
|
48
|
+
"function",
|
|
49
|
+
`
|
|
50
|
+
variable c: Color.SRGB;
|
|
51
|
+
c.r = 0; c.g = 1; c.b = 1;
|
|
52
|
+
is_cool(c)
|
|
53
|
+
`,
|
|
54
|
+
);
|
|
55
|
+
|
|
56
|
+
expect(result.value).toBe(true);
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
it("should return true for purple", async () => {
|
|
60
|
+
const result = await executeWithSchema(
|
|
61
|
+
"is_cool",
|
|
62
|
+
"function",
|
|
63
|
+
`
|
|
64
|
+
variable c: Color.SRGB;
|
|
65
|
+
c.r = 0.5; c.g = 0; c.b = 1;
|
|
66
|
+
is_cool(c)
|
|
67
|
+
`,
|
|
68
|
+
);
|
|
69
|
+
|
|
70
|
+
expect(result.value).toBe(true);
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
describe("Warm Colors", () => {
|
|
75
|
+
it("should return false for red", async () => {
|
|
76
|
+
const result = await executeWithSchema(
|
|
77
|
+
"is_cool",
|
|
78
|
+
"function",
|
|
79
|
+
`
|
|
80
|
+
variable c: Color.SRGB;
|
|
81
|
+
c.r = 1; c.g = 0; c.b = 0;
|
|
82
|
+
is_cool(c)
|
|
83
|
+
`,
|
|
84
|
+
);
|
|
85
|
+
|
|
86
|
+
expect(result.value).toBe(false);
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
it("should return false for orange", async () => {
|
|
90
|
+
const result = await executeWithSchema(
|
|
91
|
+
"is_cool",
|
|
92
|
+
"function",
|
|
93
|
+
`
|
|
94
|
+
variable c: Color.SRGB;
|
|
95
|
+
c.r = 1; c.g = 0.5; c.b = 0;
|
|
96
|
+
is_cool(c)
|
|
97
|
+
`,
|
|
98
|
+
);
|
|
99
|
+
|
|
100
|
+
expect(result.value).toBe(false);
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
it("should return false for yellow", async () => {
|
|
104
|
+
const result = await executeWithSchema(
|
|
105
|
+
"is_cool",
|
|
106
|
+
"function",
|
|
107
|
+
`
|
|
108
|
+
variable c: Color.SRGB;
|
|
109
|
+
c.r = 1; c.g = 1; c.b = 0;
|
|
110
|
+
is_cool(c)
|
|
111
|
+
`,
|
|
112
|
+
);
|
|
113
|
+
|
|
114
|
+
expect(result.value).toBe(false);
|
|
115
|
+
});
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
describe("Achromatic Colors", () => {
|
|
119
|
+
it("should return true for white (neutral treated as cool)", async () => {
|
|
120
|
+
const result = await executeWithSchema(
|
|
121
|
+
"is_cool",
|
|
122
|
+
"function",
|
|
123
|
+
`
|
|
124
|
+
variable c: Color.SRGB;
|
|
125
|
+
c.r = 1; c.g = 1; c.b = 1;
|
|
126
|
+
is_cool(c)
|
|
127
|
+
`,
|
|
128
|
+
);
|
|
129
|
+
|
|
130
|
+
expect(result.value).toBe(true);
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
it("should return true for black (neutral treated as cool)", async () => {
|
|
134
|
+
const result = await executeWithSchema(
|
|
135
|
+
"is_cool",
|
|
136
|
+
"function",
|
|
137
|
+
`
|
|
138
|
+
variable c: Color.SRGB;
|
|
139
|
+
c.r = 0; c.g = 0; c.b = 0;
|
|
140
|
+
is_cool(c)
|
|
141
|
+
`,
|
|
142
|
+
);
|
|
143
|
+
|
|
144
|
+
expect(result.value).toBe(true);
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
it("should return true for gray (neutral treated as cool)", async () => {
|
|
148
|
+
const result = await executeWithSchema(
|
|
149
|
+
"is_cool",
|
|
150
|
+
"function",
|
|
151
|
+
`
|
|
152
|
+
variable c: Color.SRGB;
|
|
153
|
+
c.r = 0.5; c.g = 0.5; c.b = 0.5;
|
|
154
|
+
is_cool(c)
|
|
155
|
+
`,
|
|
156
|
+
);
|
|
157
|
+
|
|
158
|
+
expect(result.value).toBe(true);
|
|
159
|
+
});
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
describe("Complementary to is_warm", () => {
|
|
163
|
+
it("is_cool and is_warm should be mutually exclusive for chromatic colors", async () => {
|
|
164
|
+
// Blue is cool, not warm
|
|
165
|
+
const coolResult = await executeWithSchema(
|
|
166
|
+
"is_cool",
|
|
167
|
+
"function",
|
|
168
|
+
`
|
|
169
|
+
variable c: Color.SRGB;
|
|
170
|
+
c.r = 0; c.g = 0; c.b = 1;
|
|
171
|
+
is_cool(c)
|
|
172
|
+
`,
|
|
173
|
+
);
|
|
174
|
+
|
|
175
|
+
const warmResult = await executeWithSchema(
|
|
176
|
+
"is_warm",
|
|
177
|
+
"function",
|
|
178
|
+
`
|
|
179
|
+
variable c: Color.SRGB;
|
|
180
|
+
c.r = 0; c.g = 0; c.b = 1;
|
|
181
|
+
is_warm(c)
|
|
182
|
+
`,
|
|
183
|
+
);
|
|
184
|
+
|
|
185
|
+
expect(coolResult.value).toBe(true);
|
|
186
|
+
expect(warmResult.value).toBe(false);
|
|
187
|
+
});
|
|
188
|
+
});
|
|
189
|
+
});
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// Check if a color is perceptually dark
|
|
2
|
+
// Uses OKLCH lightness for accurate perception matching
|
|
3
|
+
//
|
|
4
|
+
// Returns: true if L <= threshold, false otherwise
|
|
5
|
+
// Default threshold: 0.6 (slightly above middle)
|
|
6
|
+
|
|
7
|
+
variable input: List = {input};
|
|
8
|
+
variable color: Color.OKLCH = input.get(0).to.oklch();
|
|
9
|
+
|
|
10
|
+
variable threshold: Number = 0.6;
|
|
11
|
+
if (input.length() > 1) [
|
|
12
|
+
threshold = input.get(1);
|
|
13
|
+
];
|
|
14
|
+
|
|
15
|
+
return color.l <= threshold;
|
|
16
|
+
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "Is Dark",
|
|
3
|
+
"type": "function",
|
|
4
|
+
"description": "Returns true if a color is perceptually dark (lightness <= threshold). Uses OKLCH lightness for perceptual accuracy. Default threshold is 0.6.",
|
|
5
|
+
"keyword": "is_dark",
|
|
6
|
+
"input": {
|
|
7
|
+
"type": "object",
|
|
8
|
+
"properties": {
|
|
9
|
+
"color": {
|
|
10
|
+
"type": "color",
|
|
11
|
+
"description": "The color to check"
|
|
12
|
+
},
|
|
13
|
+
"threshold": {
|
|
14
|
+
"type": "number",
|
|
15
|
+
"description": "Lightness threshold (0-1). Default is 0.6"
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
"script": {
|
|
20
|
+
"type": "/api/v1/core/tokenscript/0/",
|
|
21
|
+
"script": "./is-dark.tokenscript"
|
|
22
|
+
},
|
|
23
|
+
"requirements": ["/api/v1/core/oklch-color/0/"]
|
|
24
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Unit tests for the Is Dark function
|
|
3
|
+
* Checks if a color is perceptually dark
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { executeWithSchema, getBundledSchema } from "@tests/helpers/schema-test-utils";
|
|
7
|
+
import { describe, expect, it } from "vitest";
|
|
8
|
+
import type { FunctionSpecification } from "@/bundler/types";
|
|
9
|
+
|
|
10
|
+
describe("Is Dark Function", () => {
|
|
11
|
+
describe("Schema Definition", () => {
|
|
12
|
+
it("should have correct schema structure", async () => {
|
|
13
|
+
const schema = (await getBundledSchema("is_dark", "function")) as FunctionSpecification;
|
|
14
|
+
|
|
15
|
+
expect(schema.name).toBe("Is Dark");
|
|
16
|
+
expect(schema.type).toBe("function");
|
|
17
|
+
expect(schema.keyword).toBe("is_dark");
|
|
18
|
+
});
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
describe("Function Execution", () => {
|
|
22
|
+
it("should return true for black", async () => {
|
|
23
|
+
const result = await executeWithSchema(
|
|
24
|
+
"is_dark",
|
|
25
|
+
"function",
|
|
26
|
+
`
|
|
27
|
+
variable black: Color.SRGB;
|
|
28
|
+
black.r = 0; black.g = 0; black.b = 0;
|
|
29
|
+
is_dark(black)
|
|
30
|
+
`,
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
expect(result).toBeDefined();
|
|
34
|
+
const isDark = (result as any).value ?? result;
|
|
35
|
+
expect(isDark).toBe(true);
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it("should return false for white", async () => {
|
|
39
|
+
const result = await executeWithSchema(
|
|
40
|
+
"is_dark",
|
|
41
|
+
"function",
|
|
42
|
+
`
|
|
43
|
+
variable white: Color.SRGB;
|
|
44
|
+
white.r = 1; white.g = 1; white.b = 1;
|
|
45
|
+
is_dark(white)
|
|
46
|
+
`,
|
|
47
|
+
);
|
|
48
|
+
|
|
49
|
+
expect(result).toBeDefined();
|
|
50
|
+
const isDark = (result as any).value ?? result;
|
|
51
|
+
expect(isDark).toBe(false);
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it("should return true for dark navy", async () => {
|
|
55
|
+
const result = await executeWithSchema(
|
|
56
|
+
"is_dark",
|
|
57
|
+
"function",
|
|
58
|
+
`
|
|
59
|
+
variable navy: Color.SRGB;
|
|
60
|
+
navy.r = 0.05; navy.g = 0.05; navy.b = 0.2;
|
|
61
|
+
is_dark(navy)
|
|
62
|
+
`,
|
|
63
|
+
);
|
|
64
|
+
|
|
65
|
+
expect(result).toBeDefined();
|
|
66
|
+
const isDark = (result as any).value ?? result;
|
|
67
|
+
expect(isDark).toBe(true);
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it("should be opposite of is_light", async () => {
|
|
71
|
+
const result = await executeWithSchema(
|
|
72
|
+
"is_dark",
|
|
73
|
+
"function",
|
|
74
|
+
`
|
|
75
|
+
variable gray: Color.SRGB;
|
|
76
|
+
gray.r = 0.3; gray.g = 0.3; gray.b = 0.3;
|
|
77
|
+
is_dark(gray)
|
|
78
|
+
`,
|
|
79
|
+
);
|
|
80
|
+
|
|
81
|
+
expect(result).toBeDefined();
|
|
82
|
+
// Dark gray should be dark
|
|
83
|
+
const isDark = (result as any).value ?? result;
|
|
84
|
+
expect(isDark).toBe(true);
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
});
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// Check if a color is perceptually light
|
|
2
|
+
// Uses OKLCH lightness for accurate perception matching
|
|
3
|
+
//
|
|
4
|
+
// Returns: true if L > threshold, false otherwise
|
|
5
|
+
// Default threshold: 0.6 (slightly above middle)
|
|
6
|
+
|
|
7
|
+
variable input: List = {input};
|
|
8
|
+
variable color: Color.OKLCH = input.get(0).to.oklch();
|
|
9
|
+
|
|
10
|
+
variable threshold: Number = 0.6;
|
|
11
|
+
if (input.length() > 1) [
|
|
12
|
+
threshold = input.get(1);
|
|
13
|
+
];
|
|
14
|
+
|
|
15
|
+
return color.l > threshold;
|
|
16
|
+
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "Is Light",
|
|
3
|
+
"type": "function",
|
|
4
|
+
"description": "Returns true if a color is perceptually light (lightness > threshold). Uses OKLCH lightness for perceptual accuracy. Default threshold is 0.6.",
|
|
5
|
+
"keyword": "is_light",
|
|
6
|
+
"input": {
|
|
7
|
+
"type": "object",
|
|
8
|
+
"properties": {
|
|
9
|
+
"color": {
|
|
10
|
+
"type": "color",
|
|
11
|
+
"description": "The color to check"
|
|
12
|
+
},
|
|
13
|
+
"threshold": {
|
|
14
|
+
"type": "number",
|
|
15
|
+
"description": "Lightness threshold (0-1). Default is 0.6"
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
"script": {
|
|
20
|
+
"type": "/api/v1/core/tokenscript/0/",
|
|
21
|
+
"script": "./is-light.tokenscript"
|
|
22
|
+
},
|
|
23
|
+
"requirements": ["/api/v1/core/oklch-color/0/"]
|
|
24
|
+
}
|