@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,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Unit tests for the scale_lightness function
|
|
3
|
+
* Scales a color's lightness by a factor
|
|
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("scale_lightness function", () => {
|
|
11
|
+
describe("Schema Definition", () => {
|
|
12
|
+
it("should have correct schema structure", async () => {
|
|
13
|
+
const schema = (await getBundledSchema(
|
|
14
|
+
"scale_lightness",
|
|
15
|
+
"function",
|
|
16
|
+
)) as FunctionSpecification;
|
|
17
|
+
|
|
18
|
+
expect(schema.name).toBe("scale_lightness");
|
|
19
|
+
expect(schema.type).toBe("function");
|
|
20
|
+
});
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
describe("Function Execution", () => {
|
|
24
|
+
it("should increase lightness with factor > 1", async () => {
|
|
25
|
+
const result = await executeWithSchema(
|
|
26
|
+
"scale_lightness",
|
|
27
|
+
"function",
|
|
28
|
+
`
|
|
29
|
+
variable gray: Color.SRGB;
|
|
30
|
+
gray.r = 0.5; gray.g = 0.5; gray.b = 0.5;
|
|
31
|
+
scale_lightness(gray, 1.2).to.srgb()
|
|
32
|
+
`,
|
|
33
|
+
);
|
|
34
|
+
|
|
35
|
+
expect(result).toBeDefined();
|
|
36
|
+
const r = (result as any).value?.r?.value ?? (result as any).value?.r;
|
|
37
|
+
expect(r).toBeGreaterThan(0.5);
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it("should decrease lightness with factor < 1", async () => {
|
|
41
|
+
const result = await executeWithSchema(
|
|
42
|
+
"scale_lightness",
|
|
43
|
+
"function",
|
|
44
|
+
`
|
|
45
|
+
variable white: Color.SRGB;
|
|
46
|
+
white.r = 1; white.g = 1; white.b = 1;
|
|
47
|
+
scale_lightness(white, 0.5).to.srgb()
|
|
48
|
+
`,
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
expect(result).toBeDefined();
|
|
52
|
+
const r = (result as any).value?.r?.value ?? (result as any).value?.r;
|
|
53
|
+
expect(r).toBeLessThan(0.9);
|
|
54
|
+
expect(r).toBeGreaterThan(0.3);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it("should clamp to 0 with factor 0", async () => {
|
|
58
|
+
const result = await executeWithSchema(
|
|
59
|
+
"scale_lightness",
|
|
60
|
+
"function",
|
|
61
|
+
`
|
|
62
|
+
variable gray: Color.SRGB;
|
|
63
|
+
gray.r = 0.5; gray.g = 0.5; gray.b = 0.5;
|
|
64
|
+
scale_lightness(gray, 0).to.srgb()
|
|
65
|
+
`,
|
|
66
|
+
);
|
|
67
|
+
|
|
68
|
+
expect(result).toBeDefined();
|
|
69
|
+
const r = (result as any).value?.r?.value ?? (result as any).value?.r;
|
|
70
|
+
expect(r).toBeCloseTo(0, 1);
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
});
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "sepia",
|
|
3
|
+
"type": "function",
|
|
4
|
+
"description": "Applies a sepia tone to a color, simulating the warm brownish tint of aged photographs. Uses the standard sepia matrix transformation. Amount parameter controls intensity from 0 (no effect) to 1 (full sepia).",
|
|
5
|
+
"keyword": "sepia",
|
|
6
|
+
"requirements": ["/api/v1/core/srgb-color/0/"],
|
|
7
|
+
"schema": {
|
|
8
|
+
"type": "object",
|
|
9
|
+
"properties": {
|
|
10
|
+
"input": {
|
|
11
|
+
"type": "array",
|
|
12
|
+
"items": [
|
|
13
|
+
{
|
|
14
|
+
"description": "Color to transform",
|
|
15
|
+
"type": "color"
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
"description": "Sepia intensity (0-1), default 1",
|
|
19
|
+
"type": "number"
|
|
20
|
+
}
|
|
21
|
+
],
|
|
22
|
+
"minItems": 1,
|
|
23
|
+
"maxItems": 2
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
"required": ["input"]
|
|
27
|
+
},
|
|
28
|
+
"returns": {
|
|
29
|
+
"type": "color",
|
|
30
|
+
"description": "Color with sepia tone applied"
|
|
31
|
+
},
|
|
32
|
+
"script": {
|
|
33
|
+
"type": "https://schema.tokenscript.dev.gcp.tokens.studio/api/v1/core/tokenscript/0/",
|
|
34
|
+
"script": "./sepia.tokenscript"
|
|
35
|
+
},
|
|
36
|
+
"examples": [
|
|
37
|
+
{
|
|
38
|
+
"description": "Full sepia",
|
|
39
|
+
"input": ["#808080", 1],
|
|
40
|
+
"output": "Warm brownish gray"
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
"description": "Partial sepia",
|
|
44
|
+
"input": ["#808080", 0.5],
|
|
45
|
+
"output": "Subtly warm gray"
|
|
46
|
+
}
|
|
47
|
+
]
|
|
48
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
// sepia: Apply sepia tone transformation
|
|
2
|
+
// Reference: CSS Filter Effects Module Level 1
|
|
3
|
+
// Reference: https://www.w3.org/TR/filter-effects-1/#sepiaEquivalent
|
|
4
|
+
//
|
|
5
|
+
// Uses the standard sepia matrix transformation as defined in CSS.
|
|
6
|
+
// The amount parameter controls intensity (0 = no effect, 1 = full sepia).
|
|
7
|
+
//
|
|
8
|
+
// Matrix coefficients:
|
|
9
|
+
// R' = 0.393R + 0.769G + 0.189B
|
|
10
|
+
// G' = 0.349R + 0.686G + 0.168B
|
|
11
|
+
// B' = 0.272R + 0.534G + 0.131B
|
|
12
|
+
|
|
13
|
+
variable input: List = {input};
|
|
14
|
+
variable color: Color.SRGB = input.get(0).to.srgb();
|
|
15
|
+
variable amount: Number = 1;
|
|
16
|
+
|
|
17
|
+
if (input.length() > 1) [
|
|
18
|
+
amount = input.get(1);
|
|
19
|
+
];
|
|
20
|
+
|
|
21
|
+
// Clamp amount
|
|
22
|
+
if (amount < 0) [ amount = 0; ];
|
|
23
|
+
if (amount > 1) [ amount = 1; ];
|
|
24
|
+
|
|
25
|
+
variable r: Number = color.r;
|
|
26
|
+
variable g: Number = color.g;
|
|
27
|
+
variable b: Number = color.b;
|
|
28
|
+
|
|
29
|
+
// Standard sepia matrix transformation (CSS filter spec)
|
|
30
|
+
// R' = 0.393R + 0.769G + 0.189B
|
|
31
|
+
// G' = 0.349R + 0.686G + 0.168B
|
|
32
|
+
// B' = 0.272R + 0.534G + 0.131B
|
|
33
|
+
variable sepia_r: Number = (r * 0.393) + (g * 0.769) + (b * 0.189);
|
|
34
|
+
variable sepia_g: Number = (r * 0.349) + (g * 0.686) + (b * 0.168);
|
|
35
|
+
variable sepia_b: Number = (r * 0.272) + (g * 0.534) + (b * 0.131);
|
|
36
|
+
|
|
37
|
+
// Clamp sepia values to valid range
|
|
38
|
+
if (sepia_r > 1) [ sepia_r = 1; ];
|
|
39
|
+
if (sepia_g > 1) [ sepia_g = 1; ];
|
|
40
|
+
if (sepia_b > 1) [ sepia_b = 1; ];
|
|
41
|
+
|
|
42
|
+
// Interpolate between original and sepia based on amount
|
|
43
|
+
variable new_r: Number = r + (sepia_r - r) * amount;
|
|
44
|
+
variable new_g: Number = g + (sepia_g - g) * amount;
|
|
45
|
+
variable new_b: Number = b + (sepia_b - b) * amount;
|
|
46
|
+
|
|
47
|
+
// Create result
|
|
48
|
+
variable result: Color.SRGB;
|
|
49
|
+
result.r = new_r;
|
|
50
|
+
result.g = new_g;
|
|
51
|
+
result.b = new_b;
|
|
52
|
+
|
|
53
|
+
return result;
|
|
54
|
+
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Unit tests for the sepia function
|
|
3
|
+
* Applies sepia tone transformation
|
|
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("sepia function", () => {
|
|
11
|
+
describe("Schema Definition", () => {
|
|
12
|
+
it("should have correct schema structure", async () => {
|
|
13
|
+
const schema = (await getBundledSchema("sepia", "function")) as FunctionSpecification;
|
|
14
|
+
|
|
15
|
+
expect(schema.name).toBe("sepia");
|
|
16
|
+
expect(schema.type).toBe("function");
|
|
17
|
+
});
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
describe("Function Execution", () => {
|
|
21
|
+
it("should apply full sepia tone to gray", async () => {
|
|
22
|
+
const result = await executeWithSchema(
|
|
23
|
+
"sepia",
|
|
24
|
+
"function",
|
|
25
|
+
`
|
|
26
|
+
variable gray: Color.SRGB;
|
|
27
|
+
gray.r = 0.5; gray.g = 0.5; gray.b = 0.5;
|
|
28
|
+
sepia(gray, 1)
|
|
29
|
+
`,
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
expect(result).toBeDefined();
|
|
33
|
+
// Sepia should have more red than blue
|
|
34
|
+
const r = (result as any).value?.r?.value ?? (result as any).value?.r;
|
|
35
|
+
const b = (result as any).value?.b?.value ?? (result as any).value?.b;
|
|
36
|
+
expect(r).toBeGreaterThan(b);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it("should apply partial sepia with amount 0.5", async () => {
|
|
40
|
+
const result = await executeWithSchema(
|
|
41
|
+
"sepia",
|
|
42
|
+
"function",
|
|
43
|
+
`
|
|
44
|
+
variable gray: Color.SRGB;
|
|
45
|
+
gray.r = 0.5; gray.g = 0.5; gray.b = 0.5;
|
|
46
|
+
sepia(gray, 0.5)
|
|
47
|
+
`,
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
expect(result).toBeDefined();
|
|
51
|
+
// Partial sepia still has warm tint
|
|
52
|
+
const r = (result as any).value?.r?.value ?? (result as any).value?.r;
|
|
53
|
+
const b = (result as any).value?.b?.value ?? (result as any).value?.b;
|
|
54
|
+
expect(r).toBeGreaterThan(b);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it("should return original color with amount 0", async () => {
|
|
58
|
+
const result = await executeWithSchema(
|
|
59
|
+
"sepia",
|
|
60
|
+
"function",
|
|
61
|
+
`
|
|
62
|
+
variable blue: Color.SRGB;
|
|
63
|
+
blue.r = 0; blue.g = 0; blue.b = 1;
|
|
64
|
+
sepia(blue, 0)
|
|
65
|
+
`,
|
|
66
|
+
);
|
|
67
|
+
|
|
68
|
+
expect(result).toBeDefined();
|
|
69
|
+
// Should be unchanged
|
|
70
|
+
const b = (result as any).value?.b?.value ?? (result as any).value?.b;
|
|
71
|
+
expect(b).toBeCloseTo(1, 1);
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
it("should use default amount if not provided", async () => {
|
|
75
|
+
const result = await executeWithSchema(
|
|
76
|
+
"sepia",
|
|
77
|
+
"function",
|
|
78
|
+
`
|
|
79
|
+
variable gray: Color.SRGB;
|
|
80
|
+
gray.r = 0.5; gray.g = 0.5; gray.b = 0.5;
|
|
81
|
+
sepia(gray)
|
|
82
|
+
`,
|
|
83
|
+
);
|
|
84
|
+
|
|
85
|
+
expect(result).toBeDefined();
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
});
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "Set Chroma",
|
|
3
|
+
"type": "function",
|
|
4
|
+
"description": "Sets a color's chroma (saturation) to a specific value in OKLCH space. Preserves hue and lightness.",
|
|
5
|
+
"keyword": "set_chroma",
|
|
6
|
+
"input": {
|
|
7
|
+
"type": "object",
|
|
8
|
+
"properties": {
|
|
9
|
+
"color": {
|
|
10
|
+
"type": "color",
|
|
11
|
+
"description": "The color to modify"
|
|
12
|
+
},
|
|
13
|
+
"chroma": {
|
|
14
|
+
"type": "number",
|
|
15
|
+
"description": "Target chroma (0-0.4 typical for sRGB)"
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
"script": {
|
|
20
|
+
"type": "/api/v1/core/tokenscript/0/",
|
|
21
|
+
"script": "./set-chroma.tokenscript"
|
|
22
|
+
},
|
|
23
|
+
"requirements": ["/api/v1/core/oklch-color/0/", "/api/v1/core/srgb-color/0/"]
|
|
24
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// Set a color's chroma to a specific value
|
|
2
|
+
// Preserves hue and lightness
|
|
3
|
+
|
|
4
|
+
variable input: List = {input};
|
|
5
|
+
variable color: Color.OKLCH = input.get(0).to.oklch();
|
|
6
|
+
variable target_c: Number = input.get(1);
|
|
7
|
+
|
|
8
|
+
// Clamp to valid range (0 to ~0.4 for sRGB gamut)
|
|
9
|
+
if (target_c < 0) [ target_c = 0; ];
|
|
10
|
+
if (target_c > 0.4) [ target_c = 0.4; ];
|
|
11
|
+
|
|
12
|
+
variable result: Color.OKLCH;
|
|
13
|
+
result.l = color.l;
|
|
14
|
+
result.c = target_c;
|
|
15
|
+
result.h = color.h;
|
|
16
|
+
|
|
17
|
+
return result;
|
|
18
|
+
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Unit tests for the Set Chroma function
|
|
3
|
+
* Sets a color's chroma (saturation) to a specific value in OKLCH
|
|
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("Set Chroma Function", () => {
|
|
11
|
+
describe("Schema Definition", () => {
|
|
12
|
+
it("should have correct schema structure", async () => {
|
|
13
|
+
const schema = (await getBundledSchema("set_chroma", "function")) as FunctionSpecification;
|
|
14
|
+
|
|
15
|
+
expect(schema.name).toBe("Set Chroma");
|
|
16
|
+
expect(schema.type).toBe("function");
|
|
17
|
+
expect(schema.keyword).toBe("set_chroma");
|
|
18
|
+
});
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
describe("Function Execution", () => {
|
|
22
|
+
it("should set chroma to 0 (grayscale)", async () => {
|
|
23
|
+
const result = await executeWithSchema(
|
|
24
|
+
"set_chroma",
|
|
25
|
+
"function",
|
|
26
|
+
`
|
|
27
|
+
variable red: Color.SRGB;
|
|
28
|
+
red.r = 0.9; red.g = 0.2; red.b = 0.2;
|
|
29
|
+
set_chroma(red, 0).to.srgb()
|
|
30
|
+
`,
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
expect(result?.constructor.name).toBe("ColorSymbol");
|
|
34
|
+
const r = (result as any).value.r.value;
|
|
35
|
+
const g = (result as any).value.g.value;
|
|
36
|
+
const b = (result as any).value.b.value;
|
|
37
|
+
// Should be gray (all channels similar)
|
|
38
|
+
expect(Math.abs(r - g)).toBeLessThan(0.1);
|
|
39
|
+
expect(Math.abs(g - b)).toBeLessThan(0.1);
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it("should increase chroma for muted color", async () => {
|
|
43
|
+
const result = await executeWithSchema(
|
|
44
|
+
"set_chroma",
|
|
45
|
+
"function",
|
|
46
|
+
`
|
|
47
|
+
variable muted: Color.SRGB;
|
|
48
|
+
muted.r = 0.5; muted.g = 0.45; muted.b = 0.48;
|
|
49
|
+
set_chroma(muted, 0.15).to.srgb()
|
|
50
|
+
`,
|
|
51
|
+
);
|
|
52
|
+
|
|
53
|
+
expect(result?.constructor.name).toBe("ColorSymbol");
|
|
54
|
+
const r = (result as any).value.r.value;
|
|
55
|
+
const g = (result as any).value.g.value;
|
|
56
|
+
// Should be more saturated (more spread between channels)
|
|
57
|
+
expect(Math.abs(r - g)).toBeGreaterThan(0);
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it("should preserve lightness", async () => {
|
|
61
|
+
const result = await executeWithSchema(
|
|
62
|
+
"set_chroma",
|
|
63
|
+
"function",
|
|
64
|
+
`
|
|
65
|
+
variable bright: Color.SRGB;
|
|
66
|
+
bright.r = 0.9; bright.g = 0.85; bright.b = 0.5;
|
|
67
|
+
set_chroma(bright, 0.1).to.srgb()
|
|
68
|
+
`,
|
|
69
|
+
);
|
|
70
|
+
|
|
71
|
+
expect(result?.constructor.name).toBe("ColorSymbol");
|
|
72
|
+
// Should still be relatively bright
|
|
73
|
+
const r = (result as any).value.r.value;
|
|
74
|
+
const g = (result as any).value.g.value;
|
|
75
|
+
const b = (result as any).value.b.value;
|
|
76
|
+
expect((r + g + b) / 3).toBeGreaterThan(0.5);
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
});
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "Set Hue",
|
|
3
|
+
"type": "function",
|
|
4
|
+
"description": "Sets a color's hue to a specific angle in OKLCH space. Preserves lightness and chroma.",
|
|
5
|
+
"keyword": "set_hue",
|
|
6
|
+
"input": {
|
|
7
|
+
"type": "object",
|
|
8
|
+
"properties": {
|
|
9
|
+
"color": {
|
|
10
|
+
"type": "color",
|
|
11
|
+
"description": "The color to modify"
|
|
12
|
+
},
|
|
13
|
+
"hue": {
|
|
14
|
+
"type": "number",
|
|
15
|
+
"description": "Target hue angle (0-360)"
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
"script": {
|
|
20
|
+
"type": "/api/v1/core/tokenscript/0/",
|
|
21
|
+
"script": "./set-hue.tokenscript"
|
|
22
|
+
},
|
|
23
|
+
"requirements": ["/api/v1/core/oklch-color/0/", "/api/v1/core/srgb-color/0/"]
|
|
24
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// Set a color's hue to a specific angle
|
|
2
|
+
// Preserves lightness and chroma
|
|
3
|
+
|
|
4
|
+
variable input: List = {input};
|
|
5
|
+
variable color: Color.OKLCH = input.get(0).to.oklch();
|
|
6
|
+
variable target_h: Number = input.get(1);
|
|
7
|
+
|
|
8
|
+
// Normalize to 0-360
|
|
9
|
+
while (target_h >= 360) [ target_h = target_h - 360; ];
|
|
10
|
+
while (target_h < 0) [ target_h = target_h + 360; ];
|
|
11
|
+
|
|
12
|
+
variable result: Color.OKLCH;
|
|
13
|
+
result.l = color.l;
|
|
14
|
+
result.c = color.c;
|
|
15
|
+
result.h = target_h;
|
|
16
|
+
|
|
17
|
+
return result;
|
|
18
|
+
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Unit tests for the Set Hue function
|
|
3
|
+
* Sets a color's hue to a specific angle in OKLCH
|
|
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("Set Hue Function", () => {
|
|
11
|
+
describe("Schema Definition", () => {
|
|
12
|
+
it("should have correct schema structure", async () => {
|
|
13
|
+
const schema = (await getBundledSchema("set_hue", "function")) as FunctionSpecification;
|
|
14
|
+
|
|
15
|
+
expect(schema.name).toBe("Set Hue");
|
|
16
|
+
expect(schema.type).toBe("function");
|
|
17
|
+
expect(schema.keyword).toBe("set_hue");
|
|
18
|
+
});
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
describe("Function Execution", () => {
|
|
22
|
+
it("should set hue to 0 (red)", async () => {
|
|
23
|
+
const result = await executeWithSchema(
|
|
24
|
+
"set_hue",
|
|
25
|
+
"function",
|
|
26
|
+
`
|
|
27
|
+
variable blue: Color.SRGB;
|
|
28
|
+
blue.r = 0.2; blue.g = 0.3; blue.b = 0.9;
|
|
29
|
+
set_hue(blue, 30).to.srgb()
|
|
30
|
+
`,
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
expect(result?.constructor.name).toBe("ColorSymbol");
|
|
34
|
+
// At hue ~30° should be more orange/red-ish
|
|
35
|
+
const r = (result as any).value.r.value;
|
|
36
|
+
const b = (result as any).value.b.value;
|
|
37
|
+
expect(r).toBeGreaterThan(b);
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it("should set hue to 120 (green)", async () => {
|
|
41
|
+
const result = await executeWithSchema(
|
|
42
|
+
"set_hue",
|
|
43
|
+
"function",
|
|
44
|
+
`
|
|
45
|
+
variable red: Color.SRGB;
|
|
46
|
+
red.r = 0.9; red.g = 0.2; red.b = 0.2;
|
|
47
|
+
set_hue(red, 140).to.srgb()
|
|
48
|
+
`,
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
expect(result?.constructor.name).toBe("ColorSymbol");
|
|
52
|
+
const r = (result as any).value.r.value;
|
|
53
|
+
const g = (result as any).value.g.value;
|
|
54
|
+
// At hue ~140° should be green-ish
|
|
55
|
+
expect(g).toBeGreaterThan(r);
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it("should set hue to 240 (blue)", async () => {
|
|
59
|
+
const result = await executeWithSchema(
|
|
60
|
+
"set_hue",
|
|
61
|
+
"function",
|
|
62
|
+
`
|
|
63
|
+
variable green: Color.SRGB;
|
|
64
|
+
green.r = 0.2; green.g = 0.8; green.b = 0.3;
|
|
65
|
+
set_hue(green, 260).to.srgb()
|
|
66
|
+
`,
|
|
67
|
+
);
|
|
68
|
+
|
|
69
|
+
expect(result?.constructor.name).toBe("ColorSymbol");
|
|
70
|
+
const g = (result as any).value.g.value;
|
|
71
|
+
const b = (result as any).value.b.value;
|
|
72
|
+
// At hue ~260° should be blue-ish
|
|
73
|
+
expect(b).toBeGreaterThan(g);
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
it("should preserve lightness and chroma", async () => {
|
|
77
|
+
const result = await executeWithSchema(
|
|
78
|
+
"set_hue",
|
|
79
|
+
"function",
|
|
80
|
+
`
|
|
81
|
+
variable color: Color.SRGB;
|
|
82
|
+
color.r = 0.7; color.g = 0.3; color.b = 0.5;
|
|
83
|
+
set_hue(color, 180).to.srgb()
|
|
84
|
+
`,
|
|
85
|
+
);
|
|
86
|
+
|
|
87
|
+
expect(result?.constructor.name).toBe("ColorSymbol");
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
});
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "Set Lightness",
|
|
3
|
+
"type": "function",
|
|
4
|
+
"description": "Sets a color's lightness to a specific value in OKLCH space. Preserves hue and chroma.",
|
|
5
|
+
"keyword": "set_lightness",
|
|
6
|
+
"input": {
|
|
7
|
+
"type": "object",
|
|
8
|
+
"properties": {
|
|
9
|
+
"color": {
|
|
10
|
+
"type": "color",
|
|
11
|
+
"description": "The color to modify"
|
|
12
|
+
},
|
|
13
|
+
"lightness": {
|
|
14
|
+
"type": "number",
|
|
15
|
+
"description": "Target lightness (0-1)"
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
"script": {
|
|
20
|
+
"type": "/api/v1/core/tokenscript/0/",
|
|
21
|
+
"script": "./set-lightness.tokenscript"
|
|
22
|
+
},
|
|
23
|
+
"requirements": ["/api/v1/core/oklch-color/0/", "/api/v1/core/srgb-color/0/"]
|
|
24
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// Set a color's lightness to a specific value
|
|
2
|
+
// Preserves hue and chroma
|
|
3
|
+
|
|
4
|
+
variable input: List = {input};
|
|
5
|
+
variable color: Color.OKLCH = input.get(0).to.oklch();
|
|
6
|
+
variable target_l: Number = input.get(1);
|
|
7
|
+
|
|
8
|
+
// Clamp to valid range
|
|
9
|
+
if (target_l < 0) [ target_l = 0; ];
|
|
10
|
+
if (target_l > 1) [ target_l = 1; ];
|
|
11
|
+
|
|
12
|
+
variable result: Color.OKLCH;
|
|
13
|
+
result.l = target_l;
|
|
14
|
+
result.c = color.c;
|
|
15
|
+
result.h = color.h;
|
|
16
|
+
|
|
17
|
+
return result;
|
|
18
|
+
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Unit tests for the Set Lightness function
|
|
3
|
+
* Sets a color's lightness to a specific value in OKLCH
|
|
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("Set Lightness Function", () => {
|
|
11
|
+
describe("Schema Definition", () => {
|
|
12
|
+
it("should have correct schema structure", async () => {
|
|
13
|
+
const schema = (await getBundledSchema("set_lightness", "function")) as FunctionSpecification;
|
|
14
|
+
|
|
15
|
+
expect(schema.name).toBe("Set Lightness");
|
|
16
|
+
expect(schema.type).toBe("function");
|
|
17
|
+
expect(schema.keyword).toBe("set_lightness");
|
|
18
|
+
});
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
describe("Function Execution", () => {
|
|
22
|
+
it("should set lightness to 0 (black)", async () => {
|
|
23
|
+
const result = await executeWithSchema(
|
|
24
|
+
"set_lightness",
|
|
25
|
+
"function",
|
|
26
|
+
`
|
|
27
|
+
variable color: Color.SRGB;
|
|
28
|
+
color.r = 0.8; color.g = 0.3; color.b = 0.5;
|
|
29
|
+
set_lightness(color, 0).to.srgb()
|
|
30
|
+
`,
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
expect(result?.constructor.name).toBe("ColorSymbol");
|
|
34
|
+
const r = (result as any).value.r.value;
|
|
35
|
+
const g = (result as any).value.g.value;
|
|
36
|
+
const b = (result as any).value.b.value;
|
|
37
|
+
// Should be very dark
|
|
38
|
+
expect(r + g + b).toBeLessThan(0.1);
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it("should set lightness to 1 (white)", async () => {
|
|
42
|
+
const result = await executeWithSchema(
|
|
43
|
+
"set_lightness",
|
|
44
|
+
"function",
|
|
45
|
+
`
|
|
46
|
+
variable color: Color.SRGB;
|
|
47
|
+
color.r = 0.2; color.g = 0.5; color.b = 0.3;
|
|
48
|
+
set_lightness(color, 1).to.srgb()
|
|
49
|
+
`,
|
|
50
|
+
);
|
|
51
|
+
|
|
52
|
+
expect(result?.constructor.name).toBe("ColorSymbol");
|
|
53
|
+
const r = (result as any).value.r.value;
|
|
54
|
+
const g = (result as any).value.g.value;
|
|
55
|
+
const b = (result as any).value.b.value;
|
|
56
|
+
// Should be very bright
|
|
57
|
+
expect(r + g + b).toBeGreaterThan(2.5);
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it("should preserve hue", async () => {
|
|
61
|
+
const result = await executeWithSchema(
|
|
62
|
+
"set_lightness",
|
|
63
|
+
"function",
|
|
64
|
+
`
|
|
65
|
+
variable red: Color.SRGB;
|
|
66
|
+
red.r = 0.9; red.g = 0.1; red.b = 0.1;
|
|
67
|
+
set_lightness(red, 0.7).to.srgb()
|
|
68
|
+
`,
|
|
69
|
+
);
|
|
70
|
+
|
|
71
|
+
expect(result?.constructor.name).toBe("ColorSymbol");
|
|
72
|
+
const r = (result as any).value.r.value;
|
|
73
|
+
const g = (result as any).value.g.value;
|
|
74
|
+
const b = (result as any).value.b.value;
|
|
75
|
+
// Should still be red-ish
|
|
76
|
+
expect(r).toBeGreaterThan(g);
|
|
77
|
+
expect(r).toBeGreaterThan(b);
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
});
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "Shade Scale",
|
|
3
|
+
"type": "function",
|
|
4
|
+
"description": "Generates a Tailwind/Material-style shade scale from 50 (lightest) to 900 (darkest). The input color becomes the 500 (middle) value. Perfect for design system color tokens.",
|
|
5
|
+
"keyword": "shade_scale",
|
|
6
|
+
"input": {
|
|
7
|
+
"type": "object",
|
|
8
|
+
"properties": {
|
|
9
|
+
"color": {
|
|
10
|
+
"type": "color",
|
|
11
|
+
"description": "Base color (becomes the 500 shade)"
|
|
12
|
+
},
|
|
13
|
+
"count": {
|
|
14
|
+
"type": "number",
|
|
15
|
+
"description": "Number of shades. Default is 10 (50-900)"
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
"script": {
|
|
20
|
+
"type": "/api/v1/core/tokenscript/0/",
|
|
21
|
+
"script": "./shade-scale.tokenscript"
|
|
22
|
+
},
|
|
23
|
+
"requirements": ["/api/v1/core/oklch-color/0/", "/api/v1/core/srgb-color/0/"]
|
|
24
|
+
}
|