@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.
Files changed (307) hide show
  1. package/dist/cli/index.cjs +31 -8
  2. package/dist/cli/index.cjs.map +1 -1
  3. package/dist/cli/index.js +30 -8
  4. package/dist/cli/index.js.map +1 -1
  5. package/package.json +2 -1
  6. package/src/bundler/bundle-schema.ts +146 -0
  7. package/src/bundler/index.ts +151 -0
  8. package/src/bundler/schema-dependency-resolver.ts +299 -0
  9. package/src/bundler/selective-bundler.test.ts +94 -0
  10. package/src/bundler/selective-bundler.ts +159 -0
  11. package/src/bundler/types.ts +93 -0
  12. package/src/bundler/utils.ts +74 -0
  13. package/src/cli/commands/bundle.integration.test.ts +153 -0
  14. package/src/cli/commands/bundle.test.ts +57 -0
  15. package/src/cli/commands/bundle.ts +237 -0
  16. package/src/cli/commands/list.ts +109 -0
  17. package/src/cli/config-schema.ts +36 -0
  18. package/src/cli/index.ts +50 -0
  19. package/src/cli/output-generator.ts +63 -0
  20. package/src/downloader/index.ts +248 -0
  21. package/src/downloader/types.ts +48 -0
  22. package/src/index.ts +8 -0
  23. package/src/schemas/functions/adjust_chroma/adjust-chroma.tokenscript +27 -0
  24. package/src/schemas/functions/adjust_chroma/schema.json +48 -0
  25. package/src/schemas/functions/adjust_chroma/unit.test.ts +76 -0
  26. package/src/schemas/functions/adjust_hue/adjust-hue.tokenscript +32 -0
  27. package/src/schemas/functions/adjust_hue/schema.json +48 -0
  28. package/src/schemas/functions/adjust_hue/unit.test.ts +68 -0
  29. package/src/schemas/functions/adjust_lightness/adjust-lightness.tokenscript +31 -0
  30. package/src/schemas/functions/adjust_lightness/schema.json +48 -0
  31. package/src/schemas/functions/adjust_lightness/unit.test.ts +88 -0
  32. package/src/schemas/functions/adjust_to_contrast/adjust-to-contrast.tokenscript +131 -0
  33. package/src/schemas/functions/adjust_to_contrast/schema.json +56 -0
  34. package/src/schemas/functions/adjust_to_contrast/unit.test.ts +81 -0
  35. package/src/schemas/functions/alpha_blend/alpha-blend.tokenscript +46 -0
  36. package/src/schemas/functions/alpha_blend/schema.json +28 -0
  37. package/src/schemas/functions/alpha_blend/unit.test.ts +135 -0
  38. package/src/schemas/functions/alpha_scale/alpha-scale.tokenscript +38 -0
  39. package/src/schemas/functions/alpha_scale/schema.json +24 -0
  40. package/src/schemas/functions/alpha_scale/unit.test.ts +50 -0
  41. package/src/schemas/functions/analogous/analogous.tokenscript +47 -0
  42. package/src/schemas/functions/analogous/schema.json +28 -0
  43. package/src/schemas/functions/analogous/unit.test.ts +64 -0
  44. package/src/schemas/functions/apca_contrast/apca-contrast.tokenscript +129 -0
  45. package/src/schemas/functions/apca_contrast/schema.json +24 -0
  46. package/src/schemas/functions/apca_contrast/unit.test.ts +259 -0
  47. package/src/schemas/functions/are_similar/are-similar.tokenscript +24 -0
  48. package/src/schemas/functions/are_similar/schema.json +57 -0
  49. package/src/schemas/functions/are_similar/unit.test.ts +57 -0
  50. package/src/schemas/functions/auto_text_color/auto-text-color.tokenscript +41 -0
  51. package/src/schemas/functions/auto_text_color/schema.json +53 -0
  52. package/src/schemas/functions/auto_text_color/unit.test.ts +122 -0
  53. package/src/schemas/functions/best_contrast/best-contrast.tokenscript +66 -0
  54. package/src/schemas/functions/best_contrast/schema.json +24 -0
  55. package/src/schemas/functions/best_contrast/unit.test.ts +64 -0
  56. package/src/schemas/functions/chroma/chroma.tokenscript +12 -0
  57. package/src/schemas/functions/chroma/schema.json +44 -0
  58. package/src/schemas/functions/chroma/unit.test.ts +86 -0
  59. package/src/schemas/functions/clamp_chroma/clamp-chroma.tokenscript +21 -0
  60. package/src/schemas/functions/clamp_chroma/schema.json +52 -0
  61. package/src/schemas/functions/clamp_chroma/unit.test.ts +60 -0
  62. package/src/schemas/functions/clamp_lightness/clamp-lightness.tokenscript +21 -0
  63. package/src/schemas/functions/clamp_lightness/schema.json +52 -0
  64. package/src/schemas/functions/clamp_lightness/unit.test.ts +76 -0
  65. package/src/schemas/functions/clamp_to_gamut/clamp-to-gamut.tokenscript +41 -0
  66. package/src/schemas/functions/clamp_to_gamut/schema.json +20 -0
  67. package/src/schemas/functions/clamp_to_gamut/unit.test.ts +167 -0
  68. package/src/schemas/functions/complement/complement.tokenscript +21 -0
  69. package/src/schemas/functions/complement/schema.json +20 -0
  70. package/src/schemas/functions/complement/unit.test.ts +81 -0
  71. package/src/schemas/functions/contrast_ratio/contrast-ratio.tokenscript +36 -0
  72. package/src/schemas/functions/contrast_ratio/schema.json +24 -0
  73. package/src/schemas/functions/contrast_ratio/unit.test.ts +91 -0
  74. package/src/schemas/functions/cooler/cooler.tokenscript +45 -0
  75. package/src/schemas/functions/cooler/schema.json +43 -0
  76. package/src/schemas/functions/cooler/unit.test.ts +69 -0
  77. package/src/schemas/functions/darken/darken.tokenscript +37 -0
  78. package/src/schemas/functions/darken/schema.json +24 -0
  79. package/src/schemas/functions/darken/unit.test.ts +105 -0
  80. package/src/schemas/functions/delta_e_2000/delta-e-2000.tokenscript +184 -0
  81. package/src/schemas/functions/delta_e_2000/schema.json +36 -0
  82. package/src/schemas/functions/delta_e_2000/unit.test.ts +243 -0
  83. package/src/schemas/functions/delta_e_76/delta-e-76.tokenscript +45 -0
  84. package/src/schemas/functions/delta_e_76/schema.json +24 -0
  85. package/src/schemas/functions/delta_e_76/unit.test.ts +123 -0
  86. package/src/schemas/functions/delta_e_ok/delta-e-ok.tokenscript +43 -0
  87. package/src/schemas/functions/delta_e_ok/schema.json +24 -0
  88. package/src/schemas/functions/delta_e_ok/unit.test.ts +235 -0
  89. package/src/schemas/functions/desaturate/desaturate.tokenscript +32 -0
  90. package/src/schemas/functions/desaturate/schema.json +24 -0
  91. package/src/schemas/functions/desaturate/unit.test.ts +54 -0
  92. package/src/schemas/functions/distributed/distributed.tokenscript +54 -0
  93. package/src/schemas/functions/distributed/schema.json +32 -0
  94. package/src/schemas/functions/distributed/unit.test.ts +58 -0
  95. package/src/schemas/functions/diverging/diverging.tokenscript +58 -0
  96. package/src/schemas/functions/diverging/schema.json +32 -0
  97. package/src/schemas/functions/diverging/unit.test.ts +70 -0
  98. package/src/schemas/functions/grayscale/grayscale.tokenscript +17 -0
  99. package/src/schemas/functions/grayscale/schema.json +20 -0
  100. package/src/schemas/functions/grayscale/unit.test.ts +79 -0
  101. package/src/schemas/functions/harmonize/harmonize.tokenscript +61 -0
  102. package/src/schemas/functions/harmonize/schema.json +52 -0
  103. package/src/schemas/functions/harmonize/unit.test.ts +56 -0
  104. package/src/schemas/functions/hue/hue.tokenscript +12 -0
  105. package/src/schemas/functions/hue/schema.json +44 -0
  106. package/src/schemas/functions/hue/unit.test.ts +75 -0
  107. package/src/schemas/functions/hue_difference/hue-difference.tokenscript +42 -0
  108. package/src/schemas/functions/hue_difference/schema.json +24 -0
  109. package/src/schemas/functions/hue_difference/unit.test.ts +125 -0
  110. package/src/schemas/functions/in_gamut/in-gamut.tokenscript +51 -0
  111. package/src/schemas/functions/in_gamut/schema.json +24 -0
  112. package/src/schemas/functions/in_gamut/unit.test.ts +178 -0
  113. package/src/schemas/functions/interpolate/interpolate.tokenscript +61 -0
  114. package/src/schemas/functions/interpolate/schema.json +52 -0
  115. package/src/schemas/functions/interpolate/unit.test.ts +96 -0
  116. package/src/schemas/functions/invert/invert-initializer.tokenscript +29 -0
  117. package/src/schemas/functions/invert/schema.json +20 -0
  118. package/src/schemas/functions/invert/unit.test.ts +216 -0
  119. package/src/schemas/functions/is_cool/is-cool.tokenscript +41 -0
  120. package/src/schemas/functions/is_cool/schema.json +20 -0
  121. package/src/schemas/functions/is_cool/unit.test.ts +189 -0
  122. package/src/schemas/functions/is_dark/is-dark.tokenscript +16 -0
  123. package/src/schemas/functions/is_dark/schema.json +24 -0
  124. package/src/schemas/functions/is_dark/unit.test.ts +87 -0
  125. package/src/schemas/functions/is_light/is-light.tokenscript +16 -0
  126. package/src/schemas/functions/is_light/schema.json +24 -0
  127. package/src/schemas/functions/is_light/unit.test.ts +86 -0
  128. package/src/schemas/functions/is_neutral/is-neutral.tokenscript +16 -0
  129. package/src/schemas/functions/is_neutral/schema.json +53 -0
  130. package/src/schemas/functions/is_neutral/unit.test.ts +85 -0
  131. package/src/schemas/functions/is_warm/is-warm.tokenscript +62 -0
  132. package/src/schemas/functions/is_warm/schema.json +20 -0
  133. package/src/schemas/functions/is_warm/unit.test.ts +161 -0
  134. package/src/schemas/functions/lighten/lighten.tokenscript +37 -0
  135. package/src/schemas/functions/lighten/schema.json +24 -0
  136. package/src/schemas/functions/lighten/unit.test.ts +109 -0
  137. package/src/schemas/functions/lightness/lightness.tokenscript +12 -0
  138. package/src/schemas/functions/lightness/schema.json +49 -0
  139. package/src/schemas/functions/lightness/unit.test.ts +99 -0
  140. package/src/schemas/functions/luminance/luminance.tokenscript +16 -0
  141. package/src/schemas/functions/luminance/schema.json +20 -0
  142. package/src/schemas/functions/luminance/unit.test.ts +105 -0
  143. package/src/schemas/functions/meets_contrast/meets-contrast.tokenscript +49 -0
  144. package/src/schemas/functions/meets_contrast/schema.json +28 -0
  145. package/src/schemas/functions/meets_contrast/unit.test.ts +170 -0
  146. package/src/schemas/functions/mix/mix.tokenscript +47 -0
  147. package/src/schemas/functions/mix/schema.json +28 -0
  148. package/src/schemas/functions/mix/unit.test.ts +95 -0
  149. package/src/schemas/functions/monochromatic/monochromatic.tokenscript +72 -0
  150. package/src/schemas/functions/monochromatic/schema.json +24 -0
  151. package/src/schemas/functions/monochromatic/unit.test.ts +91 -0
  152. package/src/schemas/functions/muted/muted.tokenscript +25 -0
  153. package/src/schemas/functions/muted/schema.json +48 -0
  154. package/src/schemas/functions/muted/unit.test.ts +100 -0
  155. package/src/schemas/functions/neutral_variant/neutral-variant.tokenscript +23 -0
  156. package/src/schemas/functions/neutral_variant/schema.json +48 -0
  157. package/src/schemas/functions/neutral_variant/unit.test.ts +102 -0
  158. package/src/schemas/functions/relative_luminance/relative-luminance.tokenscript +15 -0
  159. package/src/schemas/functions/relative_luminance/schema.json +49 -0
  160. package/src/schemas/functions/relative_luminance/unit.test.ts +104 -0
  161. package/src/schemas/functions/rotate_hue/rotate-hue.tokenscript +20 -0
  162. package/src/schemas/functions/rotate_hue/schema.json +24 -0
  163. package/src/schemas/functions/rotate_hue/unit.test.ts +86 -0
  164. package/src/schemas/functions/saturate/saturate.tokenscript +33 -0
  165. package/src/schemas/functions/saturate/schema.json +24 -0
  166. package/src/schemas/functions/saturate/unit.test.ts +59 -0
  167. package/src/schemas/functions/scale_chroma/scale-chroma.tokenscript +22 -0
  168. package/src/schemas/functions/scale_chroma/schema.json +48 -0
  169. package/src/schemas/functions/scale_chroma/unit.test.ts +79 -0
  170. package/src/schemas/functions/scale_lightness/scale-lightness.tokenscript +23 -0
  171. package/src/schemas/functions/scale_lightness/schema.json +48 -0
  172. package/src/schemas/functions/scale_lightness/unit.test.ts +73 -0
  173. package/src/schemas/functions/sepia/schema.json +48 -0
  174. package/src/schemas/functions/sepia/sepia.tokenscript +54 -0
  175. package/src/schemas/functions/sepia/unit.test.ts +88 -0
  176. package/src/schemas/functions/set_chroma/schema.json +24 -0
  177. package/src/schemas/functions/set_chroma/set-chroma.tokenscript +18 -0
  178. package/src/schemas/functions/set_chroma/unit.test.ts +79 -0
  179. package/src/schemas/functions/set_hue/schema.json +24 -0
  180. package/src/schemas/functions/set_hue/set-hue.tokenscript +18 -0
  181. package/src/schemas/functions/set_hue/unit.test.ts +90 -0
  182. package/src/schemas/functions/set_lightness/schema.json +24 -0
  183. package/src/schemas/functions/set_lightness/set-lightness.tokenscript +18 -0
  184. package/src/schemas/functions/set_lightness/unit.test.ts +80 -0
  185. package/src/schemas/functions/shade_scale/schema.json +24 -0
  186. package/src/schemas/functions/shade_scale/shade-scale.tokenscript +61 -0
  187. package/src/schemas/functions/shade_scale/unit.test.ts +64 -0
  188. package/src/schemas/functions/split_complement/schema.json +24 -0
  189. package/src/schemas/functions/split_complement/split-complement.tokenscript +38 -0
  190. package/src/schemas/functions/split_complement/unit.test.ts +53 -0
  191. package/src/schemas/functions/steps/schema.json +28 -0
  192. package/src/schemas/functions/steps/steps.tokenscript +54 -0
  193. package/src/schemas/functions/steps/unit.test.ts +71 -0
  194. package/src/schemas/functions/tetradic/schema.json +20 -0
  195. package/src/schemas/functions/tetradic/tetradic.tokenscript +40 -0
  196. package/src/schemas/functions/tetradic/unit.test.ts +50 -0
  197. package/src/schemas/functions/tint_scale/schema.json +32 -0
  198. package/src/schemas/functions/tint_scale/tint-scale.tokenscript +71 -0
  199. package/src/schemas/functions/tint_scale/unit.test.ts +64 -0
  200. package/src/schemas/functions/to_gamut/schema.json +48 -0
  201. package/src/schemas/functions/to_gamut/to-gamut.tokenscript +96 -0
  202. package/src/schemas/functions/to_gamut/unit.test.ts +97 -0
  203. package/src/schemas/functions/triadic/schema.json +20 -0
  204. package/src/schemas/functions/triadic/triadic.tokenscript +33 -0
  205. package/src/schemas/functions/triadic/unit.test.ts +64 -0
  206. package/src/schemas/functions/vibrant/schema.json +48 -0
  207. package/src/schemas/functions/vibrant/unit.test.ts +55 -0
  208. package/src/schemas/functions/vibrant/vibrant.tokenscript +29 -0
  209. package/src/schemas/functions/warmer/schema.json +43 -0
  210. package/src/schemas/functions/warmer/unit.test.ts +69 -0
  211. package/src/schemas/functions/warmer/warmer.tokenscript +45 -0
  212. package/src/schemas/functions/wcag_level/schema.json +48 -0
  213. package/src/schemas/functions/wcag_level/unit.test.ts +75 -0
  214. package/src/schemas/functions/wcag_level/wcag-level.tokenscript +50 -0
  215. package/src/schemas/types/css-color/from-hsl-color.tokenscript +16 -0
  216. package/src/schemas/types/css-color/from-hwb-color.tokenscript +16 -0
  217. package/src/schemas/types/css-color/from-lab-color.tokenscript +16 -0
  218. package/src/schemas/types/css-color/from-lch-color.tokenscript +16 -0
  219. package/src/schemas/types/css-color/from-oklab-color.tokenscript +16 -0
  220. package/src/schemas/types/css-color/from-oklch-color.tokenscript +16 -0
  221. package/src/schemas/types/css-color/from-p3-color.tokenscript +16 -0
  222. package/src/schemas/types/css-color/from-rgb-color.tokenscript +15 -0
  223. package/src/schemas/types/css-color/from-srgb-color.tokenscript +16 -0
  224. package/src/schemas/types/css-color/from-srgb-linear-color.tokenscript +16 -0
  225. package/src/schemas/types/css-color/from-xyz-d50-color.tokenscript +16 -0
  226. package/src/schemas/types/css-color/from-xyz-d65-color.tokenscript +16 -0
  227. package/src/schemas/types/css-color/initializer.tokenscript +13 -0
  228. package/src/schemas/types/css-color/schema.json +148 -0
  229. package/src/schemas/types/css-color/unit.test.ts +402 -0
  230. package/src/schemas/types/hex-color/initializer.tokenscript +3 -0
  231. package/src/schemas/types/hex-color/schema.json +24 -0
  232. package/src/schemas/types/hex-color/unit.test.ts +123 -0
  233. package/src/schemas/types/hsl-color/from-srgb.tokenscript +87 -0
  234. package/src/schemas/types/hsl-color/initializer.tokenscript +16 -0
  235. package/src/schemas/types/hsl-color/schema.json +48 -0
  236. package/src/schemas/types/hsl-color/unit.test.ts +201 -0
  237. package/src/schemas/types/hsv-color/from-srgb.tokenscript +80 -0
  238. package/src/schemas/types/hsv-color/initializer.tokenscript +16 -0
  239. package/src/schemas/types/hsv-color/schema.json +48 -0
  240. package/src/schemas/types/hsv-color/unit.test.ts +162 -0
  241. package/src/schemas/types/hwb-color/from-hsv.tokenscript +31 -0
  242. package/src/schemas/types/hwb-color/initializer.tokenscript +16 -0
  243. package/src/schemas/types/hwb-color/schema.json +48 -0
  244. package/src/schemas/types/hwb-color/unit.test.ts +150 -0
  245. package/src/schemas/types/lab-color/from-xyz-d50.tokenscript +78 -0
  246. package/src/schemas/types/lab-color/initializer.tokenscript +16 -0
  247. package/src/schemas/types/lab-color/schema.json +48 -0
  248. package/src/schemas/types/lab-color/unit.test.ts +263 -0
  249. package/src/schemas/types/lch-color/from-lab.tokenscript +44 -0
  250. package/src/schemas/types/lch-color/initializer.tokenscript +16 -0
  251. package/src/schemas/types/lch-color/schema.json +48 -0
  252. package/src/schemas/types/lch-color/unit.test.ts +173 -0
  253. package/src/schemas/types/okhsl-color/from-oklab.tokenscript +410 -0
  254. package/src/schemas/types/okhsl-color/initializer.tokenscript +24 -0
  255. package/src/schemas/types/okhsl-color/schema.json +48 -0
  256. package/src/schemas/types/okhsl-color/unit.test.ts +514 -0
  257. package/src/schemas/types/okhsv-color/from-oklab.tokenscript +286 -0
  258. package/src/schemas/types/okhsv-color/initializer.tokenscript +24 -0
  259. package/src/schemas/types/okhsv-color/schema.json +48 -0
  260. package/src/schemas/types/okhsv-color/unit.test.ts +499 -0
  261. package/src/schemas/types/oklab-color/from-okhsl.tokenscript +195 -0
  262. package/src/schemas/types/oklab-color/from-okhsv.tokenscript +197 -0
  263. package/src/schemas/types/oklab-color/from-oklch.tokenscript +39 -0
  264. package/src/schemas/types/oklab-color/from-xyz-d65.tokenscript +43 -0
  265. package/src/schemas/types/oklab-color/initializer.tokenscript +16 -0
  266. package/src/schemas/types/oklab-color/schema.json +78 -0
  267. package/src/schemas/types/oklab-color/unit.test.ts +345 -0
  268. package/src/schemas/types/oklch-color/from-oklab.tokenscript +45 -0
  269. package/src/schemas/types/oklch-color/initializer.tokenscript +16 -0
  270. package/src/schemas/types/oklch-color/schema.json +48 -0
  271. package/src/schemas/types/oklch-color/unit.test.ts +267 -0
  272. package/src/schemas/types/p3-color/from-p3-linear.tokenscript +59 -0
  273. package/src/schemas/types/p3-color/initializer.tokenscript +16 -0
  274. package/src/schemas/types/p3-color/schema.json +48 -0
  275. package/src/schemas/types/p3-color/unit.test.ts +119 -0
  276. package/src/schemas/types/p3-linear-color/from-xyz-d65.tokenscript +47 -0
  277. package/src/schemas/types/p3-linear-color/initializer.tokenscript +16 -0
  278. package/src/schemas/types/p3-linear-color/schema.json +48 -0
  279. package/src/schemas/types/p3-linear-color/unit.test.ts +82 -0
  280. package/src/schemas/types/rgb-color/from-hex.tokenscript +43 -0
  281. package/src/schemas/types/rgb-color/initializer.tokenscript +16 -0
  282. package/src/schemas/types/rgb-color/schema.json +55 -0
  283. package/src/schemas/types/rgb-color/to-hex.tokenscript +42 -0
  284. package/src/schemas/types/rgb-color/unit.test.ts +302 -0
  285. package/src/schemas/types/srgb-color/from-hsl.tokenscript +106 -0
  286. package/src/schemas/types/srgb-color/from-linear.tokenscript +58 -0
  287. package/src/schemas/types/srgb-color/from-rgb.tokenscript +20 -0
  288. package/src/schemas/types/srgb-color/initializer.tokenscript +16 -0
  289. package/src/schemas/types/srgb-color/schema.json +68 -0
  290. package/src/schemas/types/srgb-color/unit.test.ts +303 -0
  291. package/src/schemas/types/srgb-linear-color/from-srgb.tokenscript +55 -0
  292. package/src/schemas/types/srgb-linear-color/from-xyz-d65.tokenscript +34 -0
  293. package/src/schemas/types/srgb-linear-color/initializer.tokenscript +13 -0
  294. package/src/schemas/types/srgb-linear-color/schema.json +58 -0
  295. package/src/schemas/types/srgb-linear-color/unit.test.ts +291 -0
  296. package/src/schemas/types/xyz-d50-color/from-xyz-d65.tokenscript +36 -0
  297. package/src/schemas/types/xyz-d50-color/initializer.tokenscript +16 -0
  298. package/src/schemas/types/xyz-d50-color/schema.json +48 -0
  299. package/src/schemas/types/xyz-d50-color/unit.test.ts +240 -0
  300. package/src/schemas/types/xyz-d65-color/from-linear-p3.tokenscript +47 -0
  301. package/src/schemas/types/xyz-d65-color/from-linear-srgb.tokenscript +38 -0
  302. package/src/schemas/types/xyz-d65-color/from-oklab.tokenscript +44 -0
  303. package/src/schemas/types/xyz-d65-color/initializer.tokenscript +16 -0
  304. package/src/schemas/types/xyz-d65-color/schema.json +68 -0
  305. package/src/schemas/types/xyz-d65-color/unit.test.ts +319 -0
  306. package/src/utils/schema-uri.ts +192 -0
  307. package/src/utils/type.ts +194 -0
@@ -0,0 +1,82 @@
1
+ /**
2
+ * Linear P3 Color Schema Tests
3
+ */
4
+
5
+ import { executeWithSchema, getBundledSchema } from "@tests/helpers/schema-test-utils";
6
+ import Color from "colorjs.io";
7
+ import { describe, expect, it } from "vitest";
8
+ import type { ColorSpecification } from "@/bundler/types";
9
+
10
+ describe("Linear P3 Color Schema", () => {
11
+ describe("Schema Definition", () => {
12
+ it("should have correct schema structure", async () => {
13
+ const schema = (await getBundledSchema("p3-linear-color")) as ColorSpecification;
14
+
15
+ expect(schema.name).toBe("LinearP3");
16
+ expect(schema.type).toBe("color");
17
+ expect(schema.schema?.properties).toHaveProperty("r");
18
+ expect(schema.schema?.properties).toHaveProperty("g");
19
+ expect(schema.schema?.properties).toHaveProperty("b");
20
+ });
21
+ });
22
+
23
+ describe("Conversion from XYZ-D65", () => {
24
+ const testCases = [
25
+ { name: "red", xyz: [0.4124564, 0.2126729, 0.0193339] },
26
+ { name: "green", xyz: [0.3575761, 0.7151522, 0.119192] },
27
+ { name: "blue", xyz: [0.1804375, 0.072175, 0.9505041] },
28
+ { name: "white", xyz: [0.95047, 1.0, 1.08883] },
29
+ { name: "P3 green primary", xyz: [0.2657, 0.6918, 0.0451] },
30
+ ];
31
+
32
+ for (const { name, xyz } of testCases) {
33
+ it(`should convert XYZ-D65 to Linear P3 for ${name}`, async () => {
34
+ const result = await executeWithSchema(
35
+ "p3-linear-color",
36
+ "type",
37
+ `
38
+ variable xyz: Color.XYZD65;
39
+ xyz.x = ${xyz[0]}; xyz.y = ${xyz[1]}; xyz.z = ${xyz[2]};
40
+ xyz.to.linearp3()
41
+ `,
42
+ );
43
+
44
+ // ColorJS reference
45
+ const colorJS = new Color("xyz-d65", xyz as [number, number, number]).to("p3-linear");
46
+
47
+ const tsR = (result as any).value.r.value;
48
+ const tsG = (result as any).value.g.value;
49
+ const tsB = (result as any).value.b.value;
50
+
51
+ expect(tsR).toBeCloseTo(colorJS.coords[0], 8);
52
+ expect(tsG).toBeCloseTo(colorJS.coords[1], 8);
53
+ expect(tsB).toBeCloseTo(colorJS.coords[2], 8);
54
+ });
55
+ }
56
+ });
57
+
58
+ describe("Wide Gamut Colors", () => {
59
+ it("should handle P3 colors outside sRGB gamut", async () => {
60
+ // P3's green primary has negative sRGB values
61
+ const result = await executeWithSchema(
62
+ "p3-linear-color",
63
+ "type",
64
+ `
65
+ variable xyz: Color.XYZD65;
66
+ xyz.x = 0.2657; xyz.y = 0.6918; xyz.z = 0.0451;
67
+ xyz.to.linearp3()
68
+ `,
69
+ );
70
+
71
+ // This should give us approximately (0, 1, 0) in Linear P3
72
+ const tsR = (result as any).value.r.value;
73
+ const tsG = (result as any).value.g.value;
74
+ const tsB = (result as any).value.b.value;
75
+
76
+ // P3 green primary should be close to (0, 1, 0)
77
+ expect(tsG).toBeCloseTo(1, 1);
78
+ expect(Math.abs(tsR)).toBeLessThan(0.1);
79
+ expect(Math.abs(tsB)).toBeLessThan(0.1);
80
+ });
81
+ });
82
+ });
@@ -0,0 +1,43 @@
1
+ // Hex to RGB Conversion
2
+ // Converts hexadecimal color string to RGB (0-255 range)
3
+ //
4
+ // Supports both shorthand (#RGB) and standard (#RRGGBB) formats:
5
+ // #f00 → RGB(255, 0, 0)
6
+ // #ff0000 → RGB(255, 0, 0)
7
+ //
8
+ // Algorithm:
9
+ // 1. Remove '#' prefix and split into characters
10
+ // 2. For shorthand: duplicate each digit (f → ff)
11
+ // 3. Parse hex pairs to decimal values
12
+ //
13
+ // Input: Color.Hex (e.g., #ff5733)
14
+ // Output: Color.Rgb with r, g, b in 0-255 range
15
+
16
+ // Split hex string on '#' and get the color value
17
+ variable color_parts: List = {input}.to_string().split('#');
18
+ variable color: List = color_parts.get(1).split();
19
+ variable length: Number = color.length();
20
+
21
+ // Initialize RGB values
22
+ variable rgb: List = 0, 0, 0;
23
+
24
+ // Handle shorthand (#RGB) vs standard (#RRGGBB) format
25
+ if(length == 3) [
26
+ // Shorthand: duplicate each digit
27
+ rgb.update(0, parse_int(color.get(0).concat(color.get(0)), 16));
28
+ rgb.update(1, parse_int(color.get(1).concat(color.get(1)), 16));
29
+ rgb.update(2, parse_int(color.get(2).concat(color.get(2)), 16));
30
+ ] else [
31
+ // Standard: pair adjacent digits
32
+ rgb.update(0, parse_int(color.get(0).concat(color.get(1)), 16));
33
+ rgb.update(1, parse_int(color.get(2).concat(color.get(3)), 16));
34
+ rgb.update(2, parse_int(color.get(4).concat(color.get(5)), 16));
35
+ ];
36
+
37
+ // Create output color
38
+ variable output: Color.Rgb;
39
+ output.r = rgb.get(0);
40
+ output.g = rgb.get(1);
41
+ output.b = rgb.get(2);
42
+
43
+ return output;
@@ -0,0 +1,16 @@
1
+ // RGB Color Initializer
2
+ // Creates an RGB color from r, g, b values (0-255 range)
3
+ //
4
+ // Usage: rgb(255, 128, 64) → Color.Rgb { r: 255, g: 128, b: 64 }
5
+ //
6
+ // Input: List of 3 numbers [r, g, b]
7
+ // Output: Color.Rgb
8
+
9
+ variable color_parts: List = {input};
10
+
11
+ variable output: Color.Rgb;
12
+ output.r = color_parts.get(0);
13
+ output.g = color_parts.get(1);
14
+ output.b = color_parts.get(2);
15
+
16
+ return output;
@@ -0,0 +1,55 @@
1
+ {
2
+ "name": "Rgb",
3
+ "type": "color",
4
+ "description": "RGB color",
5
+ "schema": {
6
+ "type": "object",
7
+ "properties": {
8
+ "r": {
9
+ "type": "number"
10
+ },
11
+ "g": {
12
+ "type": "number"
13
+ },
14
+ "b": {
15
+ "type": "number"
16
+ }
17
+ },
18
+ "required": ["r", "g", "b"],
19
+ "order": ["r", "g", "b"],
20
+ "additionalProperties": false
21
+ },
22
+ "initializers": [
23
+ {
24
+ "title": "function",
25
+ "keyword": "rgb",
26
+ "description": "Creates an RGB color",
27
+ "script": {
28
+ "type": "/api/v1/core/tokenscript/0/",
29
+ "script": "./initializer.tokenscript"
30
+ }
31
+ }
32
+ ],
33
+ "conversions": [
34
+ {
35
+ "source": "/api/v1/core/hex-color/0/",
36
+ "target": "$self",
37
+ "description": "Converts HEX to RGB",
38
+ "lossless": true,
39
+ "script": {
40
+ "type": "/api/v1/core/tokenscript/0/",
41
+ "script": "./from-hex.tokenscript"
42
+ }
43
+ },
44
+ {
45
+ "source": "$self",
46
+ "target": "/api/v1/core/hex-color/0/",
47
+ "description": "Converts RGB to HEX",
48
+ "lossless": true,
49
+ "script": {
50
+ "type": "/api/v1/core/tokenscript/0/",
51
+ "script": "./to-hex.tokenscript"
52
+ }
53
+ }
54
+ ]
55
+ }
@@ -0,0 +1,42 @@
1
+ // RGB to Hex Conversion
2
+ // Converts RGB (0-255) color to hexadecimal string format
3
+ //
4
+ // Examples:
5
+ // RGB(255, 0, 0) → #ff0000
6
+ // RGB(0, 255, 128) → #00ff80
7
+ //
8
+ // Algorithm:
9
+ // 1. Round each channel to nearest integer
10
+ // 2. Convert to base-16 string
11
+ // 3. Pad single digits with leading zero
12
+ // 4. Concatenate with '#' prefix
13
+ //
14
+ // Input: Color.Rgb with r, g, b in 0-255 range
15
+ // Output: String (hex format #rrggbb)
16
+
17
+ variable rgba: List = {input}.r, {input}.g, {input}.b;
18
+ variable hex: String = "#";
19
+ variable i: Number = 0;
20
+ variable value: Number = 0;
21
+
22
+ // Convert each RGB channel to hex
23
+ while( i < min(rgba.length(), 3)) [
24
+ value = round(rgba.get(i));
25
+ if(value < 16) [
26
+ hex = hex.concat("0").concat(value.to_string(16));
27
+ ] else [
28
+ hex = hex.concat(value.to_string(16));
29
+ ];
30
+ i = i + 1;
31
+ ];
32
+
33
+ if (rgba.length() == 4) [
34
+ value = rgba.get(3) * 255; // Convert alpha to 0-255 range
35
+ if(value < 16) [
36
+ hex = hex.concat("0").concat(value.to_string(16));
37
+ ] else [
38
+ hex = hex.concat(value.to_string(16));
39
+ ];
40
+ ];
41
+
42
+ return hex;
@@ -0,0 +1,302 @@
1
+ import { executeWithSchema, getBundledSchema } from "@tests/helpers/schema-test-utils";
2
+ import { describe, expect, it } from "vitest";
3
+ import type { ColorSpecification } from "@/bundler/types";
4
+
5
+ describe("RGB Color Schema", () => {
6
+ describe("Schema Definition", () => {
7
+ it("should have correct schema structure", async () => {
8
+ const schema = (await getBundledSchema("rgb-color")) as ColorSpecification;
9
+
10
+ expect(schema.name).toBe("Rgb");
11
+ expect(schema.type).toBe("color");
12
+ expect(schema.description).toBe("RGB color");
13
+ expect(schema.schema).toBeDefined();
14
+ expect(schema.schema?.properties).toHaveProperty("r");
15
+ expect(schema.schema?.properties).toHaveProperty("g");
16
+ expect(schema.schema?.properties).toHaveProperty("b");
17
+ expect(schema.schema?.required).toEqual(["r", "g", "b"]);
18
+ });
19
+
20
+ it("should have initializers defined", async () => {
21
+ const schema = (await getBundledSchema("rgb-color")) as ColorSpecification;
22
+
23
+ expect(schema.initializers).toHaveLength(1);
24
+ expect(schema.initializers[0].keyword).toBe("rgb");
25
+ expect(schema.initializers[0].script.script).toBeTruthy();
26
+ expect(schema.initializers[0].script.script).not.toContain("./");
27
+ });
28
+
29
+ it("should have conversions defined", async () => {
30
+ const schema = (await getBundledSchema("rgb-color")) as ColorSpecification;
31
+
32
+ expect(schema.conversions).toHaveLength(2);
33
+
34
+ // Check HEX to RGB conversion
35
+ const hexToRgb = schema.conversions.find(
36
+ (c: { target: string; source: string }) =>
37
+ c.target === "$self" && c.source.includes("hex-color"),
38
+ );
39
+ expect(hexToRgb).toBeDefined();
40
+ expect(hexToRgb?.lossless).toBe(true);
41
+ expect(hexToRgb?.script.script).toBeTruthy();
42
+ expect(hexToRgb?.script.script).not.toContain("./");
43
+
44
+ // Check RGB to HEX conversion
45
+ const rgbToHex = schema.conversions.find(
46
+ (c: { target: string; source: string }) =>
47
+ c.source === "$self" && c.target.includes("hex-color"),
48
+ );
49
+ expect(rgbToHex).toBeDefined();
50
+ expect(rgbToHex?.lossless).toBe(true);
51
+ expect(rgbToHex?.script.script).toBeTruthy();
52
+ expect(rgbToHex?.script.script).not.toContain("./");
53
+ });
54
+ });
55
+
56
+ describe("Initialization", () => {
57
+ it("should initialize RGB color from object", async () => {
58
+ const result = await executeWithSchema(
59
+ "rgb-color",
60
+ "type",
61
+ `
62
+ variable c: Color.Rgb;
63
+ c.r = 255;
64
+ c.g = 128;
65
+ c.b = 64;
66
+ c
67
+ `,
68
+ );
69
+
70
+ expect(result?.constructor.name).toBe("ColorSymbol");
71
+ expect((result as any).subType).toBe("Rgb");
72
+ expect((result as any).value.r.value).toBe(255);
73
+ expect((result as any).value.g.value).toBe(128);
74
+ expect((result as any).value.b.value).toBe(64);
75
+ });
76
+
77
+ it("should access individual color channels", async () => {
78
+ const result = await executeWithSchema(
79
+ "rgb-color",
80
+ "type",
81
+ `
82
+ variable c: Color.Rgb;
83
+ c.r = 200;
84
+ c.g = 150;
85
+ c.b = 100;
86
+ c.r
87
+ `,
88
+ );
89
+
90
+ expect(result?.constructor.name).toBe("NumberSymbol");
91
+ expect(result?.toString()).toBe("200");
92
+ });
93
+ });
94
+
95
+ describe("Conversion from HEX to RGB", () => {
96
+ it("should convert 6-digit HEX to RGB", async () => {
97
+ const result = await executeWithSchema(
98
+ "rgb-color",
99
+ "type",
100
+ `
101
+ variable c: Color.Hex = #ff5733;
102
+ c.to.rgb()
103
+ `,
104
+ );
105
+
106
+ expect(result?.constructor.name).toBe("ColorSymbol");
107
+ expect((result as any).subType).toBe("Rgb");
108
+ expect((result as any).value.r.value).toBe(255);
109
+ expect((result as any).value.g.value).toBe(87);
110
+ expect((result as any).value.b.value).toBe(51);
111
+ });
112
+
113
+ it("should convert 3-digit HEX to RGB", async () => {
114
+ const result = await executeWithSchema(
115
+ "rgb-color",
116
+ "type",
117
+ `
118
+ variable c: Color.Hex = #f53;
119
+ c.to.rgb()
120
+ `,
121
+ );
122
+
123
+ expect(result?.constructor.name).toBe("ColorSymbol");
124
+ expect((result as any).subType).toBe("Rgb");
125
+ expect((result as any).value.r.value).toBe(255);
126
+ expect((result as any).value.g.value).toBe(85);
127
+ expect((result as any).value.b.value).toBe(51);
128
+ });
129
+
130
+ it("should convert black HEX to RGB", async () => {
131
+ const result = await executeWithSchema(
132
+ "rgb-color",
133
+ "type",
134
+ `
135
+ variable c: Color.Hex = #000;
136
+ c.to.rgb()
137
+ `,
138
+ );
139
+
140
+ expect(result?.constructor.name).toBe("ColorSymbol");
141
+ expect((result as any).subType).toBe("Rgb");
142
+ expect((result as any).value.r.value).toBe(0);
143
+ expect((result as any).value.g.value).toBe(0);
144
+ expect((result as any).value.b.value).toBe(0);
145
+ });
146
+
147
+ it("should convert white HEX to RGB", async () => {
148
+ const result = await executeWithSchema(
149
+ "rgb-color",
150
+ "type",
151
+ `
152
+ variable c: Color.Hex = #ffffff;
153
+ c.to.rgb()
154
+ `,
155
+ );
156
+
157
+ expect(result?.constructor.name).toBe("ColorSymbol");
158
+ expect((result as any).subType).toBe("Rgb");
159
+ expect((result as any).value.r.value).toBe(255);
160
+ expect((result as any).value.g.value).toBe(255);
161
+ expect((result as any).value.b.value).toBe(255);
162
+ });
163
+ });
164
+
165
+ describe("Conversion from RGB to HEX", () => {
166
+ it("should convert RGB to HEX", async () => {
167
+ const result = await executeWithSchema(
168
+ "rgb-color",
169
+ "type",
170
+ `
171
+ variable c: Color.Rgb;
172
+ c.r = 255;
173
+ c.g = 87;
174
+ c.b = 51;
175
+ c.to.hex()
176
+ `,
177
+ );
178
+
179
+ expect(result?.constructor.name).toBe("ColorSymbol");
180
+ expect((result as any).subType).toBe("Hex");
181
+ expect(result?.toString()).toBe("#ff5733");
182
+ });
183
+
184
+ it("should convert RGB with low values to HEX", async () => {
185
+ const result = await executeWithSchema(
186
+ "rgb-color",
187
+ "type",
188
+ `
189
+ variable c: Color.Rgb;
190
+ c.r = 10;
191
+ c.g = 5;
192
+ c.b = 0;
193
+ c.to.hex()
194
+ `,
195
+ );
196
+
197
+ expect(result?.constructor.name).toBe("ColorSymbol");
198
+ expect((result as any).subType).toBe("Hex");
199
+ expect(result?.toString()).toBe("#0a0500");
200
+ });
201
+
202
+ it("should convert black RGB to HEX", async () => {
203
+ const result = await executeWithSchema(
204
+ "rgb-color",
205
+ "type",
206
+ `
207
+ variable c: Color.Rgb;
208
+ c.r = 0;
209
+ c.g = 0;
210
+ c.b = 0;
211
+ c.to.hex()
212
+ `,
213
+ );
214
+
215
+ expect(result?.constructor.name).toBe("ColorSymbol");
216
+ expect((result as any).subType).toBe("Hex");
217
+ expect(result?.toString()).toBe("#000000");
218
+ });
219
+
220
+ it("should convert white RGB to HEX", async () => {
221
+ const result = await executeWithSchema(
222
+ "rgb-color",
223
+ "type",
224
+ `
225
+ variable c: Color.Rgb;
226
+ c.r = 255;
227
+ c.g = 255;
228
+ c.b = 255;
229
+ c.to.hex()
230
+ `,
231
+ );
232
+
233
+ expect(result?.constructor.name).toBe("ColorSymbol");
234
+ expect((result as any).subType).toBe("Hex");
235
+ expect(result?.toString()).toBe("#ffffff");
236
+ });
237
+ });
238
+
239
+ describe("Round-trip Conversions", () => {
240
+ it("should maintain color values through HEX -> RGB -> HEX", async () => {
241
+ const result = await executeWithSchema(
242
+ "rgb-color",
243
+ "type",
244
+ `
245
+ variable original: Color.Hex = #3498db;
246
+ variable rgb: Color.Rgb = original.to.rgb();
247
+ variable back: Color.Hex = rgb.to.hex();
248
+ back
249
+ `,
250
+ );
251
+
252
+ expect(result?.constructor.name).toBe("ColorSymbol");
253
+ expect((result as any).subType).toBe("Hex");
254
+ expect(result?.toString()).toBe("#3498db");
255
+ });
256
+
257
+ it("should maintain color values through RGB -> HEX -> RGB", async () => {
258
+ const result = await executeWithSchema(
259
+ "rgb-color",
260
+ "type",
261
+ `
262
+ variable original: Color.Rgb;
263
+ original.r = 52;
264
+ original.g = 152;
265
+ original.b = 219;
266
+
267
+ variable hex: Color.Hex = original.to.hex();
268
+ variable back: Color.Rgb = hex.to.rgb();
269
+ back
270
+ `,
271
+ );
272
+
273
+ expect(result?.constructor.name).toBe("ColorSymbol");
274
+ expect((result as any).subType).toBe("Rgb");
275
+ expect((result as any).value.r.value).toBe(52);
276
+ expect((result as any).value.g.value).toBe(152);
277
+ expect((result as any).value.b.value).toBe(219);
278
+ });
279
+ });
280
+
281
+ describe("Identity Conversions", () => {
282
+ it("should handle RGB to RGB identity conversion", async () => {
283
+ const result = await executeWithSchema(
284
+ "rgb-color",
285
+ "type",
286
+ `
287
+ variable c: Color.Rgb;
288
+ c.r = 100;
289
+ c.g = 150;
290
+ c.b = 200;
291
+ c.to.rgb()
292
+ `,
293
+ );
294
+
295
+ expect(result?.constructor.name).toBe("ColorSymbol");
296
+ expect((result as any).subType).toBe("Rgb");
297
+ expect((result as any).value.r.value).toBe(100);
298
+ expect((result as any).value.g.value).toBe(150);
299
+ expect((result as any).value.b.value).toBe(200);
300
+ });
301
+ });
302
+ });
@@ -0,0 +1,106 @@
1
+ // HSL to sRGB Conversion
2
+ // Reference: https://github.com/color-js/color.js/blob/main/src/spaces/hsl.js
3
+ //
4
+ // Algorithm:
5
+ // 1. If saturation is 0, it's achromatic: R=G=B=L
6
+ // 2. Otherwise use the HSL to RGB formula:
7
+ // - Calculate intermediate values based on L
8
+ // - Use hue to determine RGB components
9
+ //
10
+ // Input: Color.HSL with h (0-360), s (0-1), l (0-1)
11
+ // Output: Color.SRGB with r, g, b in 0-1 range
12
+
13
+ // Get input HSL values
14
+ variable h: Number = {input}.h;
15
+ variable s: Number = {input}.s;
16
+ variable l: Number = {input}.l;
17
+
18
+ // Normalize hue to 0-1 range
19
+ variable hue: Number = h / 360;
20
+
21
+ // Output values
22
+ variable r: Number = l;
23
+ variable g: Number = l;
24
+ variable b: Number = l;
25
+
26
+ // Only calculate if there's saturation (not achromatic)
27
+ if (s > 0) [
28
+ // Calculate intermediate value
29
+ variable q: Number = 0;
30
+ if (l < 0.5) [
31
+ q = l * (1 + s);
32
+ ] else [
33
+ q = l + s - l * s;
34
+ ];
35
+
36
+ variable p: Number = 2 * l - q;
37
+
38
+ // Helper function logic inlined for R (hue + 1/3)
39
+ variable tr: Number = hue + 0.333333333333333;
40
+ if (tr < 0) [ tr = tr + 1; ];
41
+ if (tr > 1) [ tr = tr - 1; ];
42
+
43
+ if (tr < 0.166666666666667) [
44
+ r = p + (q - p) * 6 * tr;
45
+ ] else [
46
+ if (tr < 0.5) [
47
+ r = q;
48
+ ] else [
49
+ if (tr < 0.666666666666667) [
50
+ r = p + (q - p) * (0.666666666666667 - tr) * 6;
51
+ ] else [
52
+ r = p;
53
+ ];
54
+ ];
55
+ ];
56
+
57
+ // Helper function logic inlined for G (hue)
58
+ variable tg: Number = hue;
59
+ if (tg < 0) [ tg = tg + 1; ];
60
+ if (tg > 1) [ tg = tg - 1; ];
61
+
62
+ if (tg < 0.166666666666667) [
63
+ g = p + (q - p) * 6 * tg;
64
+ ] else [
65
+ if (tg < 0.5) [
66
+ g = q;
67
+ ] else [
68
+ if (tg < 0.666666666666667) [
69
+ g = p + (q - p) * (0.666666666666667 - tg) * 6;
70
+ ] else [
71
+ g = p;
72
+ ];
73
+ ];
74
+ ];
75
+
76
+ // Helper function logic inlined for B (hue - 1/3)
77
+ variable tb: Number = hue - 0.333333333333333;
78
+ if (tb < 0) [ tb = tb + 1; ];
79
+ if (tb > 1) [ tb = tb - 1; ];
80
+
81
+ if (tb < 0.166666666666667) [
82
+ b = p + (q - p) * 6 * tb;
83
+ ] else [
84
+ if (tb < 0.5) [
85
+ b = q;
86
+ ] else [
87
+ if (tb < 0.666666666666667) [
88
+ b = p + (q - p) * (0.666666666666667 - tb) * 6;
89
+ ] else [
90
+ b = p;
91
+ ];
92
+ ];
93
+ ];
94
+ ];
95
+
96
+ // Create output
97
+ variable output: Color.SRGB;
98
+ output.r = r;
99
+ output.g = g;
100
+ output.b = b;
101
+
102
+ return output;
103
+
104
+
105
+
106
+