@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,197 @@
|
|
|
1
|
+
// OKHSV to OKLab Conversion
|
|
2
|
+
// Reference: Björn Ottosson - "A perceptual color picker: OKHSL and OKHSV"
|
|
3
|
+
// URL: https://bottosson.github.io/posts/colorpicker/
|
|
4
|
+
// Reference: https://github.com/color-js/color.js/blob/main/src/spaces/okhsv.js
|
|
5
|
+
//
|
|
6
|
+
// Converts OKHSV back to OKLab using:
|
|
7
|
+
// 1. Cusp finding to determine gamut boundary at this hue
|
|
8
|
+
// 2. V and S denormalization to get L and C
|
|
9
|
+
//
|
|
10
|
+
// Input: Color.OKHSV with h (0-360), s (0-1), v (0-1)
|
|
11
|
+
// Output: Color.OKLab with l (0-1), a, b coordinates
|
|
12
|
+
|
|
13
|
+
variable h: Number = input.h;
|
|
14
|
+
variable s: Number = input.s;
|
|
15
|
+
variable v: Number = input.v;
|
|
16
|
+
|
|
17
|
+
// Native constants
|
|
18
|
+
variable pi_val: Number = pi();
|
|
19
|
+
|
|
20
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
21
|
+
// Step 1: Handle edge cases
|
|
22
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
23
|
+
variable lab_l: Number = v;
|
|
24
|
+
variable lab_a: Number = 0;
|
|
25
|
+
variable lab_b: Number = 0;
|
|
26
|
+
|
|
27
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
28
|
+
// Step 2: Compute hue direction
|
|
29
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
30
|
+
variable h_rad: Number = h * pi_val / 180;
|
|
31
|
+
variable a_: Number = cos(h_rad);
|
|
32
|
+
variable b_: Number = sin(h_rad);
|
|
33
|
+
|
|
34
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
35
|
+
// Pre-compute LMS coefficients (used in steps 3 and 4)
|
|
36
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
37
|
+
variable kl: Number = 0.3963377774 * a_ + 0.2158037573 * b_;
|
|
38
|
+
variable km: Number = -0.1055613458 * a_ - 0.0638541728 * b_;
|
|
39
|
+
variable ks: Number = -0.0894841775 * a_ - 1.2914855480 * b_;
|
|
40
|
+
|
|
41
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
42
|
+
// Step 3: Find maximum saturation at this hue
|
|
43
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
44
|
+
variable s_max: Number = 0;
|
|
45
|
+
|
|
46
|
+
// Variables for LMS intermediate calculations (reused in step 4)
|
|
47
|
+
variable l_lms: Number = 0;
|
|
48
|
+
variable m_lms: Number = 0;
|
|
49
|
+
variable s_lms: Number = 0;
|
|
50
|
+
|
|
51
|
+
if (s >= 0.0001 && v >= 0.0001) [
|
|
52
|
+
variable k0: Number = 0;
|
|
53
|
+
variable k1_coef: Number = 0;
|
|
54
|
+
variable k2_coef: Number = 0;
|
|
55
|
+
variable k3_coef: Number = 0;
|
|
56
|
+
variable k4_coef: Number = 0;
|
|
57
|
+
variable wl: Number = 0;
|
|
58
|
+
variable wm: Number = 0;
|
|
59
|
+
variable ws: Number = 0;
|
|
60
|
+
|
|
61
|
+
variable test_r: Number = -1.88170328 * a_ - 0.80936493 * b_;
|
|
62
|
+
variable test_g: Number = 1.81444104 * a_ - 1.19445276 * b_;
|
|
63
|
+
|
|
64
|
+
if (test_r > 1) [
|
|
65
|
+
k0 = 1.19086277;
|
|
66
|
+
k1_coef = 1.76576728;
|
|
67
|
+
k2_coef = 0.59662641;
|
|
68
|
+
k3_coef = 0.75515197;
|
|
69
|
+
k4_coef = 0.56771245;
|
|
70
|
+
wl = 4.0767416621;
|
|
71
|
+
wm = -3.3077115913;
|
|
72
|
+
ws = 0.2309699292;
|
|
73
|
+
] else [
|
|
74
|
+
if (test_g > 1) [
|
|
75
|
+
k0 = 0.73956515;
|
|
76
|
+
k1_coef = -0.45954404;
|
|
77
|
+
k2_coef = 0.08285427;
|
|
78
|
+
k3_coef = 0.12541073;
|
|
79
|
+
k4_coef = -0.14503204;
|
|
80
|
+
wl = -1.2684380046;
|
|
81
|
+
wm = 2.6097574011;
|
|
82
|
+
ws = -0.3413193965;
|
|
83
|
+
] else [
|
|
84
|
+
k0 = 1.35733652;
|
|
85
|
+
k1_coef = -0.00915799;
|
|
86
|
+
k2_coef = -1.15130210;
|
|
87
|
+
k3_coef = -0.50559606;
|
|
88
|
+
k4_coef = 0.00692167;
|
|
89
|
+
wl = -0.0041960863;
|
|
90
|
+
wm = -0.7034186147;
|
|
91
|
+
ws = 1.7076147010;
|
|
92
|
+
];
|
|
93
|
+
];
|
|
94
|
+
|
|
95
|
+
s_max = k0 + k1_coef * a_ + k2_coef * b_ + k3_coef * a_ * a_ + k4_coef * a_ * b_;
|
|
96
|
+
|
|
97
|
+
// Halley's method refinement
|
|
98
|
+
variable l_temp: Number = 1 + s_max * kl;
|
|
99
|
+
variable m_temp: Number = 1 + s_max * km;
|
|
100
|
+
variable s_temp: Number = 1 + s_max * ks;
|
|
101
|
+
|
|
102
|
+
variable l_cubed: Number = l_temp * l_temp * l_temp;
|
|
103
|
+
variable m_cubed: Number = m_temp * m_temp * m_temp;
|
|
104
|
+
variable s_cubed: Number = s_temp * s_temp * s_temp;
|
|
105
|
+
|
|
106
|
+
variable l_ds: Number = 3 * kl * l_temp * l_temp;
|
|
107
|
+
variable m_ds: Number = 3 * km * m_temp * m_temp;
|
|
108
|
+
variable s_ds: Number = 3 * ks * s_temp * s_temp;
|
|
109
|
+
|
|
110
|
+
variable l_ds2: Number = 6 * kl * kl * l_temp;
|
|
111
|
+
variable m_ds2: Number = 6 * km * km * m_temp;
|
|
112
|
+
variable s_ds2: Number = 6 * ks * ks * s_temp;
|
|
113
|
+
|
|
114
|
+
variable f: Number = wl * l_cubed + wm * m_cubed + ws * s_cubed;
|
|
115
|
+
variable f1: Number = wl * l_ds + wm * m_ds + ws * s_ds;
|
|
116
|
+
variable f2: Number = wl * l_ds2 + wm * m_ds2 + ws * s_ds2;
|
|
117
|
+
|
|
118
|
+
variable denom: Number = f1 * f1 - 0.5 * f * f2;
|
|
119
|
+
if (abs(denom) > 0.000001) [
|
|
120
|
+
s_max = s_max - f * f1 / denom;
|
|
121
|
+
];
|
|
122
|
+
];
|
|
123
|
+
|
|
124
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
125
|
+
// Step 4: Find cusp
|
|
126
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
127
|
+
variable l_cusp: Number = 1;
|
|
128
|
+
variable c_cusp: Number = 0;
|
|
129
|
+
|
|
130
|
+
if (s >= 0.0001 && v >= 0.0001 && s_max > 0) [
|
|
131
|
+
// Recompute LMS values with refined s_max (kl, km, ks already computed)
|
|
132
|
+
variable l_cusp_temp: Number = 1 + s_max * kl;
|
|
133
|
+
variable m_cusp_temp: Number = 1 + s_max * km;
|
|
134
|
+
variable s_cusp_temp: Number = 1 + s_max * ks;
|
|
135
|
+
|
|
136
|
+
l_lms = l_cusp_temp * l_cusp_temp * l_cusp_temp;
|
|
137
|
+
m_lms = m_cusp_temp * m_cusp_temp * m_cusp_temp;
|
|
138
|
+
s_lms = s_cusp_temp * s_cusp_temp * s_cusp_temp;
|
|
139
|
+
|
|
140
|
+
variable r_lin: Number = 4.0767416621 * l_lms - 3.3077115913 * m_lms + 0.2309699292 * s_lms;
|
|
141
|
+
variable g_lin: Number = -1.2684380046 * l_lms + 2.6097574011 * m_lms - 0.3413193965 * s_lms;
|
|
142
|
+
variable b_lin: Number = -0.0041960863 * l_lms - 0.7034186147 * m_lms + 1.7076147010 * s_lms;
|
|
143
|
+
|
|
144
|
+
variable max_rgb: Number = r_lin;
|
|
145
|
+
if (g_lin > max_rgb) [ max_rgb = g_lin; ];
|
|
146
|
+
if (b_lin > max_rgb) [ max_rgb = b_lin; ];
|
|
147
|
+
|
|
148
|
+
if (max_rgb > 0) [
|
|
149
|
+
l_cusp = pow(1 / max_rgb, 0.3333333333333333);
|
|
150
|
+
c_cusp = l_cusp * s_max;
|
|
151
|
+
];
|
|
152
|
+
];
|
|
153
|
+
|
|
154
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
155
|
+
// Step 5: Compute L and C from V and S
|
|
156
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
157
|
+
variable c: Number = 0;
|
|
158
|
+
|
|
159
|
+
if (s >= 0.0001 && v >= 0.0001 && l_cusp > 0.0001 && c_cusp > 0.0001) [
|
|
160
|
+
variable s_t_cusp: Number = c_cusp / l_cusp;
|
|
161
|
+
variable t_t_cusp: Number = c_cusp / (1 - l_cusp + 0.0001);
|
|
162
|
+
|
|
163
|
+
// Compute max chroma at this V
|
|
164
|
+
variable c_max_at_v: Number = 0;
|
|
165
|
+
|
|
166
|
+
if (v <= l_cusp) [
|
|
167
|
+
c_max_at_v = v * s_t_cusp;
|
|
168
|
+
] else [
|
|
169
|
+
c_max_at_v = (1 - v) * t_t_cusp;
|
|
170
|
+
];
|
|
171
|
+
|
|
172
|
+
// Compute actual chroma
|
|
173
|
+
c = s * c_max_at_v;
|
|
174
|
+
|
|
175
|
+
// Compute L from V and C
|
|
176
|
+
// Reverse of: V = L + C / s_t_cusp
|
|
177
|
+
lab_l = v - c / (s_t_cusp + 0.0001);
|
|
178
|
+
if (lab_l < 0) [ lab_l = 0; ];
|
|
179
|
+
if (lab_l > 1) [ lab_l = 1; ];
|
|
180
|
+
];
|
|
181
|
+
|
|
182
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
183
|
+
// Step 6: Convert polar to cartesian
|
|
184
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
185
|
+
if (s >= 0.0001 && v >= 0.0001) [
|
|
186
|
+
lab_a = c * a_;
|
|
187
|
+
lab_b = c * b_;
|
|
188
|
+
];
|
|
189
|
+
|
|
190
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
191
|
+
// Output
|
|
192
|
+
// ═══════════════════════════════════════════════════════════════════════════
|
|
193
|
+
variable output: Color.OKLab;
|
|
194
|
+
output.l = lab_l;
|
|
195
|
+
output.a = lab_a;
|
|
196
|
+
output.b = lab_b;
|
|
197
|
+
output
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// OKLCH to OKLab Conversion
|
|
2
|
+
// Converts polar (C, H) back to cartesian (a, b) coordinates
|
|
3
|
+
// Reference: Björn Ottosson's OKLab specification
|
|
4
|
+
//
|
|
5
|
+
// Algorithm:
|
|
6
|
+
// L stays the same (lightness)
|
|
7
|
+
// a = C * cos(H * π/180)
|
|
8
|
+
// b = C * sin(H * π/180)
|
|
9
|
+
//
|
|
10
|
+
// Input: Color.OKLCH with l, c, h coordinates
|
|
11
|
+
// Output: Color.OKLab with l, a, b coordinates
|
|
12
|
+
|
|
13
|
+
// Get input OKLCH values
|
|
14
|
+
variable l: Number = {input}.l;
|
|
15
|
+
variable c: Number = {input}.c;
|
|
16
|
+
variable h: Number = {input}.h;
|
|
17
|
+
|
|
18
|
+
// Constants
|
|
19
|
+
variable pi: Number = pi();
|
|
20
|
+
variable deg_to_rad: Number = pi / 180;
|
|
21
|
+
|
|
22
|
+
// Convert hue to radians
|
|
23
|
+
variable h_rad: Number = h * deg_to_rad;
|
|
24
|
+
|
|
25
|
+
// Convert polar to cartesian
|
|
26
|
+
variable a: Number = c * cos(h_rad);
|
|
27
|
+
variable b: Number = c * sin(h_rad);
|
|
28
|
+
|
|
29
|
+
// Create output
|
|
30
|
+
variable output: Color.OKLab;
|
|
31
|
+
output.l = l;
|
|
32
|
+
output.a = a;
|
|
33
|
+
output.b = b;
|
|
34
|
+
|
|
35
|
+
return output;
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
// XYZ-D65 to OKLab Conversion
|
|
2
|
+
// Uses ColorJS-compatible matrices (recalculated for consistent D65 white)
|
|
3
|
+
// Reference: https://github.com/color-js/color.js/blob/main/src/spaces/oklab.js
|
|
4
|
+
//
|
|
5
|
+
// Algorithm:
|
|
6
|
+
// 1. XYZ-D65 → LMS (M1 matrix)
|
|
7
|
+
// 2. LMS → LMS' (cube root transformation)
|
|
8
|
+
// 3. LMS' → OKLab (M2 matrix)
|
|
9
|
+
//
|
|
10
|
+
// Input: Color.XYZD65 with x, y, z tristimulus
|
|
11
|
+
// Output: Color.OKLab with l, a, b coordinates
|
|
12
|
+
|
|
13
|
+
// Get input XYZ-D65 values
|
|
14
|
+
variable x: Number = {input}.x;
|
|
15
|
+
variable y: Number = {input}.y;
|
|
16
|
+
variable z: Number = {input}.z;
|
|
17
|
+
|
|
18
|
+
// Step 1: XYZ-D65 → LMS cone response
|
|
19
|
+
// ColorJS XYZtoLMS_M matrix (recalculated for consistent reference white)
|
|
20
|
+
variable lms_l: Number = x * 0.8190224379967030 + y * 0.3619062600528904 + z * -0.1288737815209879;
|
|
21
|
+
variable lms_m: Number = x * 0.0329836539323885 + y * 0.9292868615863434 + z * 0.0361446663506424;
|
|
22
|
+
variable lms_s: Number = x * 0.0481771893596242 + y * 0.2642395317527308 + z * 0.6335478284694309;
|
|
23
|
+
|
|
24
|
+
// Step 2: Apply cube root (γ = 1/3)
|
|
25
|
+
// Note: Using pow with 1/3 exponent (cbrt equivalent for positive values)
|
|
26
|
+
variable cube_root_exp: Number = 0.3333333333333333;
|
|
27
|
+
variable lms_l_prime: Number = pow(lms_l, cube_root_exp);
|
|
28
|
+
variable lms_m_prime: Number = pow(lms_m, cube_root_exp);
|
|
29
|
+
variable lms_s_prime: Number = pow(lms_s, cube_root_exp);
|
|
30
|
+
|
|
31
|
+
// Step 3: LMS' → OKLab
|
|
32
|
+
// ColorJS LMStoLab_M matrix
|
|
33
|
+
variable oklab_l: Number = lms_l_prime * 0.2104542683093140 + lms_m_prime * 0.7936177747023054 + lms_s_prime * -0.0040720430116193;
|
|
34
|
+
variable oklab_a: Number = lms_l_prime * 1.9779985324311684 + lms_m_prime * -2.4285922420485799 + lms_s_prime * 0.4505937096174110;
|
|
35
|
+
variable oklab_b: Number = lms_l_prime * 0.0259040424655478 + lms_m_prime * 0.7827717124575296 + lms_s_prime * -0.8086757549230774;
|
|
36
|
+
|
|
37
|
+
// Create output
|
|
38
|
+
variable output: Color.OKLab;
|
|
39
|
+
output.l = oklab_l;
|
|
40
|
+
output.a = oklab_a;
|
|
41
|
+
output.b = oklab_b;
|
|
42
|
+
|
|
43
|
+
return output;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// OKLab Color Initializer
|
|
2
|
+
// Creates an OKLab color from L, a, b values
|
|
3
|
+
// Input: List of [l, a, b] values
|
|
4
|
+
|
|
5
|
+
variable lab_values: List = {input};
|
|
6
|
+
variable output: Color.OKLab;
|
|
7
|
+
|
|
8
|
+
output.l = lab_values.get(0);
|
|
9
|
+
output.a = lab_values.get(1);
|
|
10
|
+
output.b = lab_values.get(2);
|
|
11
|
+
|
|
12
|
+
return output;
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "OKLab",
|
|
3
|
+
"type": "color",
|
|
4
|
+
"description": "OKLab perceptually uniform color space by Björn Ottosson. L is lightness (0-1), a is green-red axis, b is blue-yellow axis.",
|
|
5
|
+
"schema": {
|
|
6
|
+
"type": "object",
|
|
7
|
+
"properties": {
|
|
8
|
+
"l": {
|
|
9
|
+
"type": "number",
|
|
10
|
+
"description": "Lightness (0-1)"
|
|
11
|
+
},
|
|
12
|
+
"a": {
|
|
13
|
+
"type": "number",
|
|
14
|
+
"description": "Green-red axis (typically -0.4 to 0.4)"
|
|
15
|
+
},
|
|
16
|
+
"b": {
|
|
17
|
+
"type": "number",
|
|
18
|
+
"description": "Blue-yellow axis (typically -0.4 to 0.4)"
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"required": ["l", "a", "b"],
|
|
22
|
+
"order": ["l", "a", "b"],
|
|
23
|
+
"additionalProperties": false
|
|
24
|
+
},
|
|
25
|
+
"initializers": [
|
|
26
|
+
{
|
|
27
|
+
"title": "OKLab Color Initializer",
|
|
28
|
+
"keyword": "oklab",
|
|
29
|
+
"description": "Creates an OKLab color from L, a, b 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/xyz-d65-color/0/",
|
|
39
|
+
"target": "$self",
|
|
40
|
+
"description": "Converts XYZ-D65 to OKLab using Björn Ottosson's algorithm",
|
|
41
|
+
"lossless": true,
|
|
42
|
+
"script": {
|
|
43
|
+
"type": "/api/v1/core/tokenscript/0/",
|
|
44
|
+
"script": "./from-xyz-d65.tokenscript"
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
"source": "/api/v1/core/oklch-color/0/",
|
|
49
|
+
"target": "$self",
|
|
50
|
+
"description": "Converts OKLCH to OKLab (polar to cartesian)",
|
|
51
|
+
"lossless": true,
|
|
52
|
+
"script": {
|
|
53
|
+
"type": "/api/v1/core/tokenscript/0/",
|
|
54
|
+
"script": "./from-oklch.tokenscript"
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
"source": "/api/v1/core/okhsl-color/0/",
|
|
59
|
+
"target": "$self",
|
|
60
|
+
"description": "Converts OKHSL to OKLab",
|
|
61
|
+
"lossless": true,
|
|
62
|
+
"script": {
|
|
63
|
+
"type": "/api/v1/core/tokenscript/0/",
|
|
64
|
+
"script": "./from-okhsl.tokenscript"
|
|
65
|
+
}
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
"source": "/api/v1/core/okhsv-color/0/",
|
|
69
|
+
"target": "$self",
|
|
70
|
+
"description": "Converts OKHSV to OKLab",
|
|
71
|
+
"lossless": true,
|
|
72
|
+
"script": {
|
|
73
|
+
"type": "/api/v1/core/tokenscript/0/",
|
|
74
|
+
"script": "./from-okhsv.tokenscript"
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
]
|
|
78
|
+
}
|