@10x-media/fields 0.1.0-beta.0
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/CHANGELOG.md +12 -0
- package/LICENSE +21 -0
- package/README.md +62 -0
- package/dist/exports/client.d.ts +7 -0
- package/dist/exports/client.js +8 -0
- package/dist/exports/color-utils.d.ts +9 -0
- package/dist/exports/color-utils.js +7 -0
- package/dist/exports/color.d.ts +6 -0
- package/dist/exports/color.js +5 -0
- package/dist/exports/encrypted.d.ts +12 -0
- package/dist/exports/encrypted.js +10 -0
- package/dist/exports/i18n.d.ts +3 -0
- package/dist/exports/i18n.js +3 -0
- package/dist/exports/icon-adapters/lucide.d.ts +5 -0
- package/dist/exports/icon-adapters/lucide.js +4 -0
- package/dist/exports/icon-adapters/radix.d.ts +5 -0
- package/dist/exports/icon-adapters/radix.js +4 -0
- package/dist/exports/icon-adapters/tabler.d.ts +5 -0
- package/dist/exports/icon-adapters/tabler.js +4 -0
- package/dist/exports/icon-codegen.d.ts +4 -0
- package/dist/exports/icon-codegen.js +2 -0
- package/dist/exports/icon-react.d.ts +4 -0
- package/dist/exports/icon-react.js +3 -0
- package/dist/exports/icon.d.ts +8 -0
- package/dist/exports/icon.js +7 -0
- package/dist/exports/rsc.d.ts +10 -0
- package/dist/exports/rsc.js +9 -0
- package/dist/exports/types.d.ts +4 -0
- package/dist/exports/types.js +1 -0
- package/dist/fields/color/client/ColorField.d.ts +13 -0
- package/dist/fields/color/client/ColorField.js +321 -0
- package/dist/fields/color/client/ColorField.js.map +1 -0
- package/dist/fields/color/client/ColorPickerPanel.d.ts +29 -0
- package/dist/fields/color/client/ColorPickerPanel.js +233 -0
- package/dist/fields/color/client/ColorPickerPanel.js.map +1 -0
- package/dist/fields/color/client/colorField.css +411 -0
- package/dist/fields/color/client/icons.js +38 -0
- package/dist/fields/color/client/icons.js.map +1 -0
- package/dist/fields/color/colorField.d.ts +20 -0
- package/dist/fields/color/colorField.js +102 -0
- package/dist/fields/color/colorField.js.map +1 -0
- package/dist/fields/color/commitValue.js +29 -0
- package/dist/fields/color/commitValue.js.map +1 -0
- package/dist/fields/color/engine/contrast.d.ts +10 -0
- package/dist/fields/color/engine/contrast.js +25 -0
- package/dist/fields/color/engine/contrast.js.map +1 -0
- package/dist/fields/color/engine/convert.d.ts +28 -0
- package/dist/fields/color/engine/convert.js +232 -0
- package/dist/fields/color/engine/convert.js.map +1 -0
- package/dist/fields/color/engine/format.d.ts +15 -0
- package/dist/fields/color/engine/format.js +53 -0
- package/dist/fields/color/engine/format.js.map +1 -0
- package/dist/fields/color/engine/index.d.ts +8 -0
- package/dist/fields/color/engine/namedColors.d.ts +9 -0
- package/dist/fields/color/engine/namedColors.js +159 -0
- package/dist/fields/color/engine/namedColors.js.map +1 -0
- package/dist/fields/color/engine/parse.d.ts +12 -0
- package/dist/fields/color/engine/parse.js +151 -0
- package/dist/fields/color/engine/parse.js.map +1 -0
- package/dist/fields/color/engine/salvage.d.ts +13 -0
- package/dist/fields/color/engine/salvage.js +75 -0
- package/dist/fields/color/engine/salvage.js.map +1 -0
- package/dist/fields/color/engine/types.d.ts +34 -0
- package/dist/fields/color/options.d.ts +55 -0
- package/dist/fields/color/options.js +8 -0
- package/dist/fields/color/options.js.map +1 -0
- package/dist/fields/color/presetChip.js +27 -0
- package/dist/fields/color/presetChip.js.map +1 -0
- package/dist/fields/color/presetsFromDoc.d.ts +27 -0
- package/dist/fields/color/presetsFromDoc.js +74 -0
- package/dist/fields/color/presetsFromDoc.js.map +1 -0
- package/dist/fields/color/resolveFormat.js +16 -0
- package/dist/fields/color/resolveFormat.js.map +1 -0
- package/dist/fields/color/resolvePresets.d.ts +29 -0
- package/dist/fields/color/resolvePresets.js +39 -0
- package/dist/fields/color/resolvePresets.js.map +1 -0
- package/dist/fields/color/server/ColorCell.d.ts +6 -0
- package/dist/fields/color/server/ColorCell.js +34 -0
- package/dist/fields/color/server/ColorCell.js.map +1 -0
- package/dist/fields/color/server/ColorFieldServer.d.ts +18 -0
- package/dist/fields/color/server/ColorFieldServer.js +69 -0
- package/dist/fields/color/server/ColorFieldServer.js.map +1 -0
- package/dist/fields/color/server/colorCell.css +32 -0
- package/dist/fields/encrypted/boot.d.ts +14 -0
- package/dist/fields/encrypted/boot.js +22 -0
- package/dist/fields/encrypted/boot.js.map +1 -0
- package/dist/fields/encrypted/components/EncryptedInput.js +89 -0
- package/dist/fields/encrypted/components/EncryptedInput.js.map +1 -0
- package/dist/fields/encrypted/components/EncryptedTextarea.js +86 -0
- package/dist/fields/encrypted/components/EncryptedTextarea.js.map +1 -0
- package/dist/fields/encrypted/components/EyeToggle.js +51 -0
- package/dist/fields/encrypted/components/EyeToggle.js.map +1 -0
- package/dist/fields/encrypted/components/MaskDots.js +20 -0
- package/dist/fields/encrypted/components/MaskDots.js.map +1 -0
- package/dist/fields/encrypted/components/ProtectedCell.d.ts +19 -0
- package/dist/fields/encrypted/components/ProtectedCell.js +44 -0
- package/dist/fields/encrypted/components/ProtectedCell.js.map +1 -0
- package/dist/fields/encrypted/components/ProtectedField.css +180 -0
- package/dist/fields/encrypted/components/ProtectedField.d.ts +30 -0
- package/dist/fields/encrypted/components/ProtectedField.js +95 -0
- package/dist/fields/encrypted/components/ProtectedField.js.map +1 -0
- package/dist/fields/encrypted/components/ProtectedRichText.d.ts +21 -0
- package/dist/fields/encrypted/components/ProtectedRichText.js +35 -0
- package/dist/fields/encrypted/components/ProtectedRichText.js.map +1 -0
- package/dist/fields/encrypted/components/RichTextRevealGate.d.ts +24 -0
- package/dist/fields/encrypted/components/RichTextRevealGate.js +87 -0
- package/dist/fields/encrypted/components/RichTextRevealGate.js.map +1 -0
- package/dist/fields/encrypted/components/StructuralField.js +64 -0
- package/dist/fields/encrypted/components/StructuralField.js.map +1 -0
- package/dist/fields/encrypted/components/facsimiles.js +219 -0
- package/dist/fields/encrypted/components/facsimiles.js.map +1 -0
- package/dist/fields/encrypted/components/placement.js +21 -0
- package/dist/fields/encrypted/components/placement.js.map +1 -0
- package/dist/fields/encrypted/crypto/aad.js +29 -0
- package/dist/fields/encrypted/crypto/aad.js.map +1 -0
- package/dist/fields/encrypted/crypto/bidx.js +26 -0
- package/dist/fields/encrypted/crypto/bidx.js.map +1 -0
- package/dist/fields/encrypted/crypto/keys.d.ts +31 -0
- package/dist/fields/encrypted/crypto/keys.js +113 -0
- package/dist/fields/encrypted/crypto/keys.js.map +1 -0
- package/dist/fields/encrypted/crypto/wire.d.ts +23 -0
- package/dist/fields/encrypted/crypto/wire.js +135 -0
- package/dist/fields/encrypted/crypto/wire.js.map +1 -0
- package/dist/fields/encrypted/encryptedField.d.ts +15 -0
- package/dist/fields/encrypted/encryptedField.js +187 -0
- package/dist/fields/encrypted/encryptedField.js.map +1 -0
- package/dist/fields/encrypted/hooks.d.ts +21 -0
- package/dist/fields/encrypted/hooks.js +326 -0
- package/dist/fields/encrypted/hooks.js.map +1 -0
- package/dist/fields/encrypted/maskDots.js +16 -0
- package/dist/fields/encrypted/maskDots.js.map +1 -0
- package/dist/fields/encrypted/plaintextStash.js +57 -0
- package/dist/fields/encrypted/plaintextStash.js.map +1 -0
- package/dist/fields/encrypted/queryRewrite.d.ts +12 -0
- package/dist/fields/encrypted/queryRewrite.js +134 -0
- package/dist/fields/encrypted/queryRewrite.js.map +1 -0
- package/dist/fields/encrypted/scan.js +36 -0
- package/dist/fields/encrypted/scan.js.map +1 -0
- package/dist/fields/encrypted/types.d.ts +35 -0
- package/dist/fields/encrypted/types.js +12 -0
- package/dist/fields/encrypted/types.js.map +1 -0
- package/dist/fields/encrypted/typescriptSchema.js +41 -0
- package/dist/fields/encrypted/typescriptSchema.js.map +1 -0
- package/dist/fields/encrypted/utils/decryptAllData.d.ts +17 -0
- package/dist/fields/encrypted/utils/decryptAllData.js +98 -0
- package/dist/fields/encrypted/utils/decryptAllData.js.map +1 -0
- package/dist/fields/encrypted/utils/encryptExistingData.d.ts +14 -0
- package/dist/fields/encrypted/utils/encryptExistingData.js +72 -0
- package/dist/fields/encrypted/utils/encryptExistingData.js.map +1 -0
- package/dist/fields/encrypted/utils/pageThrough.js +42 -0
- package/dist/fields/encrypted/utils/pageThrough.js.map +1 -0
- package/dist/fields/encrypted/utils/rotateEncryptedFields.d.ts +27 -0
- package/dist/fields/encrypted/utils/rotateEncryptedFields.js +92 -0
- package/dist/fields/encrypted/utils/rotateEncryptedFields.js.map +1 -0
- package/dist/fields/encrypted/validators.js +111 -0
- package/dist/fields/encrypted/validators.js.map +1 -0
- package/dist/fields/icon/adapters/lucide/adapter.d.ts +8 -0
- package/dist/fields/icon/adapters/lucide/adapter.js +15 -0
- package/dist/fields/icon/adapters/lucide/adapter.js.map +1 -0
- package/dist/fields/icon/adapters/lucide/client.d.ts +10 -0
- package/dist/fields/icon/adapters/lucide/client.js +41 -0
- package/dist/fields/icon/adapters/lucide/client.js.map +1 -0
- package/dist/fields/icon/adapters/lucide/generated/manifest.js +23338 -0
- package/dist/fields/icon/adapters/lucide/generated/manifest.js.map +1 -0
- package/dist/fields/icon/adapters/lucide/generated/nodes.js +14296 -0
- package/dist/fields/icon/adapters/lucide/generated/nodes.js.map +1 -0
- package/dist/fields/icon/adapters/lucide/renderer.d.ts +7 -0
- package/dist/fields/icon/adapters/lucide/renderer.js +13 -0
- package/dist/fields/icon/adapters/lucide/renderer.js.map +1 -0
- package/dist/fields/icon/adapters/radix/adapter.d.ts +8 -0
- package/dist/fields/icon/adapters/radix/adapter.js +14 -0
- package/dist/fields/icon/adapters/radix/adapter.js.map +1 -0
- package/dist/fields/icon/adapters/radix/client.d.ts +8 -0
- package/dist/fields/icon/adapters/radix/client.js +20 -0
- package/dist/fields/icon/adapters/radix/client.js.map +1 -0
- package/dist/fields/icon/adapters/radix/generated/imports.js +324 -0
- package/dist/fields/icon/adapters/radix/generated/imports.js.map +1 -0
- package/dist/fields/icon/adapters/radix/generated/manifest.js +1805 -0
- package/dist/fields/icon/adapters/radix/generated/manifest.js.map +1 -0
- package/dist/fields/icon/adapters/radix/renderer.d.ts +7 -0
- package/dist/fields/icon/adapters/radix/renderer.js +23 -0
- package/dist/fields/icon/adapters/radix/renderer.js.map +1 -0
- package/dist/fields/icon/adapters/tabler/adapter.d.ts +8 -0
- package/dist/fields/icon/adapters/tabler/adapter.js +15 -0
- package/dist/fields/icon/adapters/tabler/adapter.js.map +1 -0
- package/dist/fields/icon/adapters/tabler/client.d.ts +9 -0
- package/dist/fields/icon/adapters/tabler/client.js +18 -0
- package/dist/fields/icon/adapters/tabler/client.js.map +1 -0
- package/dist/fields/icon/adapters/tabler/generated/imports.js +4942 -0
- package/dist/fields/icon/adapters/tabler/generated/imports.js.map +1 -0
- package/dist/fields/icon/adapters/tabler/generated/manifest.js +61269 -0
- package/dist/fields/icon/adapters/tabler/generated/manifest.js.map +1 -0
- package/dist/fields/icon/adapters/tabler/generated/nodes.js +26749 -0
- package/dist/fields/icon/adapters/tabler/generated/nodes.js.map +1 -0
- package/dist/fields/icon/adapters/tabler/renderer.d.ts +7 -0
- package/dist/fields/icon/adapters/tabler/renderer.js +13 -0
- package/dist/fields/icon/adapters/tabler/renderer.js.map +1 -0
- package/dist/fields/icon/client/DrawerGlyph.js +32 -0
- package/dist/fields/icon/client/DrawerGlyph.js.map +1 -0
- package/dist/fields/icon/client/IconDrawerContent.js +294 -0
- package/dist/fields/icon/client/IconDrawerContent.js.map +1 -0
- package/dist/fields/icon/client/IconFieldClient.d.ts +19 -0
- package/dist/fields/icon/client/IconFieldClient.js +245 -0
- package/dist/fields/icon/client/IconFieldClient.js.map +1 -0
- package/dist/fields/icon/client/IconLibrarySelect.d.ts +14 -0
- package/dist/fields/icon/client/IconLibrarySelect.js +36 -0
- package/dist/fields/icon/client/IconLibrarySelect.js.map +1 -0
- package/dist/fields/icon/client/availableLibraries.js +25 -0
- package/dist/fields/icon/client/availableLibraries.js.map +1 -0
- package/dist/fields/icon/client/generatedAdapter.js +88 -0
- package/dist/fields/icon/client/generatedAdapter.js.map +1 -0
- package/dist/fields/icon/client/icon-field.css +524 -0
- package/dist/fields/icon/client/useRecentIcons.js +32 -0
- package/dist/fields/icon/client/useRecentIcons.js.map +1 -0
- package/dist/fields/icon/codegen/emit.js +81 -0
- package/dist/fields/icon/codegen/emit.js.map +1 -0
- package/dist/fields/icon/codegen/generate.d.ts +10 -0
- package/dist/fields/icon/codegen/generate.js +59 -0
- package/dist/fields/icon/codegen/generate.js.map +1 -0
- package/dist/fields/icon/codegen/sources/lucide.js +52 -0
- package/dist/fields/icon/codegen/sources/lucide.js.map +1 -0
- package/dist/fields/icon/codegen/sources/radix.js +33 -0
- package/dist/fields/icon/codegen/sources/radix.js.map +1 -0
- package/dist/fields/icon/codegen/sources/tabler.js +31 -0
- package/dist/fields/icon/codegen/sources/tabler.js.map +1 -0
- package/dist/fields/icon/codegen/types.d.ts +36 -0
- package/dist/fields/icon/defineIconAdapter.d.ts +8 -0
- package/dist/fields/icon/defineIconAdapter.js +10 -0
- package/dist/fields/icon/defineIconAdapter.js.map +1 -0
- package/dist/fields/icon/plugin.js +55 -0
- package/dist/fields/icon/plugin.js.map +1 -0
- package/dist/fields/icon/react/createIcon.d.ts +15 -0
- package/dist/fields/icon/react/createIcon.js +47 -0
- package/dist/fields/icon/react/createIcon.js.map +1 -0
- package/dist/fields/icon/react/createRscIcon.d.ts +12 -0
- package/dist/fields/icon/react/createRscIcon.js +27 -0
- package/dist/fields/icon/react/createRscIcon.js.map +1 -0
- package/dist/fields/icon/react/types.d.ts +24 -0
- package/dist/fields/icon/rsc/IconCell.d.ts +14 -0
- package/dist/fields/icon/rsc/IconCell.js +32 -0
- package/dist/fields/icon/rsc/IconCell.js.map +1 -0
- package/dist/fields/icon/rsc/IconFieldServer.d.ts +24 -0
- package/dist/fields/icon/rsc/IconFieldServer.js +74 -0
- package/dist/fields/icon/rsc/IconFieldServer.js.map +1 -0
- package/dist/fields/icon/rsc/IconLibrarySelectServer.d.ts +13 -0
- package/dist/fields/icon/rsc/IconLibrarySelectServer.js +24 -0
- package/dist/fields/icon/rsc/IconLibrarySelectServer.js.map +1 -0
- package/dist/fields/icon/rsc/resolveStaticLabel.js +16 -0
- package/dist/fields/icon/rsc/resolveStaticLabel.js.map +1 -0
- package/dist/fields/icon/server/availability.d.ts +32 -0
- package/dist/fields/icon/server/availability.js +58 -0
- package/dist/fields/icon/server/availability.js.map +1 -0
- package/dist/fields/icon/server/iconField.d.ts +32 -0
- package/dist/fields/icon/server/iconField.js +48 -0
- package/dist/fields/icon/server/iconField.js.map +1 -0
- package/dist/fields/icon/server/iconLibraryField.d.ts +23 -0
- package/dist/fields/icon/server/iconLibraryField.js +50 -0
- package/dist/fields/icon/server/iconLibraryField.js.map +1 -0
- package/dist/fields/icon/server/libraryOptions.d.ts +12 -0
- package/dist/fields/icon/server/libraryOptions.js +13 -0
- package/dist/fields/icon/server/libraryOptions.js.map +1 -0
- package/dist/fields/icon/server/manifestCache.js +17 -0
- package/dist/fields/icon/server/manifestCache.js.map +1 -0
- package/dist/fields/icon/server/validate.js +37 -0
- package/dist/fields/icon/server/validate.js.map +1 -0
- package/dist/fields/icon/shared/adapterComponents.d.ts +23 -0
- package/dist/fields/icon/shared/formatIconLabel.js +16 -0
- package/dist/fields/icon/shared/formatIconLabel.js.map +1 -0
- package/dist/fields/icon/shared/search.js +58 -0
- package/dist/fields/icon/shared/search.js.map +1 -0
- package/dist/fields/icon/shared/value.d.ts +16 -0
- package/dist/fields/icon/shared/value.js +27 -0
- package/dist/fields/icon/shared/value.js.map +1 -0
- package/dist/index.d.ts +39 -0
- package/dist/index.js +41 -0
- package/dist/index.js.map +1 -0
- package/dist/plugin/registerTranslations.js +19 -0
- package/dist/plugin/registerTranslations.js.map +1 -0
- package/dist/plugin/registry.d.ts +9 -0
- package/dist/plugin/registry.js +14 -0
- package/dist/plugin/registry.js.map +1 -0
- package/dist/translations/de.js +49 -0
- package/dist/translations/de.js.map +1 -0
- package/dist/translations/en.js +49 -0
- package/dist/translations/en.js.map +1 -0
- package/dist/translations/index.d.ts +15 -0
- package/dist/translations/index.js +30 -0
- package/dist/translations/index.js.map +1 -0
- package/dist/translations/keys.d.ts +48 -0
- package/dist/translations/keys.js +48 -0
- package/dist/translations/keys.js.map +1 -0
- package/dist/translations/server.js +13 -0
- package/dist/translations/server.js.map +1 -0
- package/dist/translations/useTranslation.js +12 -0
- package/dist/translations/useTranslation.js.map +1 -0
- package/dist/types.d.ts +105 -0
- package/dist/utils/memoForRequest.js +25 -0
- package/dist/utils/memoForRequest.js.map +1 -0
- package/package.json +196 -0
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { Hsl, Hsv, OklchColor, ParsedColor, RgbColor } from "./types.js";
|
|
2
|
+
|
|
3
|
+
//#region src/fields/color/engine/convert.d.ts
|
|
4
|
+
declare const rgbToOklch: (color: RgbColor) => OklchColor;
|
|
5
|
+
declare const isInSrgbGamut: (color: RgbColor) => boolean;
|
|
6
|
+
/**
|
|
7
|
+
* OKLCH to sRGB with CSS-style gamut mapping: chroma is reduced at constant
|
|
8
|
+
* lightness and hue via binary search until the color fits, then clipped for
|
|
9
|
+
* numeric noise. Never a naive per-channel clamp.
|
|
10
|
+
*/
|
|
11
|
+
declare const oklchToRgb: (color: OklchColor) => RgbColor;
|
|
12
|
+
declare const toRgb: (color: ParsedColor) => RgbColor;
|
|
13
|
+
declare const toOklch: (color: ParsedColor) => OklchColor;
|
|
14
|
+
declare const hslToRgb: ({
|
|
15
|
+
h,
|
|
16
|
+
l,
|
|
17
|
+
s
|
|
18
|
+
}: Hsl, alpha?: number) => RgbColor;
|
|
19
|
+
declare const rgbToHsl: (color: RgbColor) => Hsl;
|
|
20
|
+
declare const rgbToHsv: (color: RgbColor) => Hsv;
|
|
21
|
+
declare const hsvToRgb: ({
|
|
22
|
+
h,
|
|
23
|
+
s,
|
|
24
|
+
v
|
|
25
|
+
}: Hsv, alpha?: number) => RgbColor;
|
|
26
|
+
//#endregion
|
|
27
|
+
export { hslToRgb, hsvToRgb, isInSrgbGamut, oklchToRgb, rgbToHsl, rgbToHsv, rgbToOklch, toOklch, toRgb };
|
|
28
|
+
//# sourceMappingURL=convert.d.ts.map
|
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
//#region src/fields/color/engine/convert.ts
|
|
2
|
+
const srgbToLinear = (channel) => channel <= .04045 ? channel / 12.92 : ((channel + .055) / 1.055) ** 2.4;
|
|
3
|
+
const linearToSrgb = (channel) => channel <= .0031308 ? channel * 12.92 : 1.055 * channel ** (1 / 2.4) - .055;
|
|
4
|
+
/** Standard CSS Color 4 / Ottosson OKLab matrices. */
|
|
5
|
+
const rgbToOklab = (color) => {
|
|
6
|
+
const r = srgbToLinear(color.r);
|
|
7
|
+
const g = srgbToLinear(color.g);
|
|
8
|
+
const b = srgbToLinear(color.b);
|
|
9
|
+
const l = Math.cbrt(.4122214708 * r + .5363325363 * g + .0514459929 * b);
|
|
10
|
+
const m = Math.cbrt(.2119034982 * r + .6806995451 * g + .1073969566 * b);
|
|
11
|
+
const s = Math.cbrt(.0883024619 * r + .2817188376 * g + .6299787005 * b);
|
|
12
|
+
return {
|
|
13
|
+
l: .2104542553 * l + .793617785 * m - .0040720468 * s,
|
|
14
|
+
a: 1.9779984951 * l - 2.428592205 * m + .4505937099 * s,
|
|
15
|
+
b: .0259040371 * l + .7827717662 * m - .808675766 * s
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
const oklabToRgb = (lab, alpha = 1) => {
|
|
19
|
+
const l = (lab.l + .3963377774 * lab.a + .2158037573 * lab.b) ** 3;
|
|
20
|
+
const m = (lab.l - .1055613458 * lab.a - .0638541728 * lab.b) ** 3;
|
|
21
|
+
const s = (lab.l - .0894841775 * lab.a - 1.291485548 * lab.b) ** 3;
|
|
22
|
+
return {
|
|
23
|
+
mode: "rgb",
|
|
24
|
+
r: linearToSrgb(4.0767416621 * l - 3.3077115913 * m + .2309699292 * s),
|
|
25
|
+
g: linearToSrgb(-1.2684380046 * l + 2.6097574011 * m - .3413193965 * s),
|
|
26
|
+
b: linearToSrgb(-.0041960863 * l - .7034186147 * m + 1.707614701 * s),
|
|
27
|
+
alpha
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
const rgbToOklch = (color) => {
|
|
31
|
+
const lab = rgbToOklab(color);
|
|
32
|
+
const c = Math.hypot(lab.a, lab.b);
|
|
33
|
+
let h = Math.atan2(lab.b, lab.a) * 180 / Math.PI;
|
|
34
|
+
if (h < 0) h += 360;
|
|
35
|
+
if (c < 1e-6) h = 0;
|
|
36
|
+
return {
|
|
37
|
+
mode: "oklch",
|
|
38
|
+
l: lab.l,
|
|
39
|
+
c,
|
|
40
|
+
h,
|
|
41
|
+
alpha: color.alpha
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
/** Direct OKLCH to sRGB conversion; channels may fall outside [0, 1]. */
|
|
45
|
+
const oklchToRgbUnmapped = (color) => {
|
|
46
|
+
const rad = color.h * Math.PI / 180;
|
|
47
|
+
return oklabToRgb({
|
|
48
|
+
l: color.l,
|
|
49
|
+
a: color.c * Math.cos(rad),
|
|
50
|
+
b: color.c * Math.sin(rad)
|
|
51
|
+
}, color.alpha);
|
|
52
|
+
};
|
|
53
|
+
const isInSrgbGamut = (color) => [
|
|
54
|
+
color.r,
|
|
55
|
+
color.g,
|
|
56
|
+
color.b
|
|
57
|
+
].every((v) => v >= -1e-5 && v <= 1.00001);
|
|
58
|
+
const clip = (value) => Math.min(1, Math.max(0, value));
|
|
59
|
+
const clipToSrgb = (color) => ({
|
|
60
|
+
...color,
|
|
61
|
+
r: clip(color.r),
|
|
62
|
+
g: clip(color.g),
|
|
63
|
+
b: clip(color.b)
|
|
64
|
+
});
|
|
65
|
+
/**
|
|
66
|
+
* OKLCH to sRGB with CSS-style gamut mapping: chroma is reduced at constant
|
|
67
|
+
* lightness and hue via binary search until the color fits, then clipped for
|
|
68
|
+
* numeric noise. Never a naive per-channel clamp.
|
|
69
|
+
*/
|
|
70
|
+
const oklchToRgb = (color) => {
|
|
71
|
+
const direct = oklchToRgbUnmapped(color);
|
|
72
|
+
if (isInSrgbGamut(direct)) return clipToSrgb(direct);
|
|
73
|
+
if (color.l <= 0) return {
|
|
74
|
+
mode: "rgb",
|
|
75
|
+
r: 0,
|
|
76
|
+
g: 0,
|
|
77
|
+
b: 0,
|
|
78
|
+
alpha: color.alpha
|
|
79
|
+
};
|
|
80
|
+
if (color.l >= 1) return {
|
|
81
|
+
mode: "rgb",
|
|
82
|
+
r: 1,
|
|
83
|
+
g: 1,
|
|
84
|
+
b: 1,
|
|
85
|
+
alpha: color.alpha
|
|
86
|
+
};
|
|
87
|
+
let lo = 0;
|
|
88
|
+
let hi = color.c;
|
|
89
|
+
for (let i = 0; i < 24; i += 1) {
|
|
90
|
+
const mid = (lo + hi) / 2;
|
|
91
|
+
if (isInSrgbGamut(oklchToRgbUnmapped({
|
|
92
|
+
...color,
|
|
93
|
+
c: mid
|
|
94
|
+
}))) lo = mid;
|
|
95
|
+
else hi = mid;
|
|
96
|
+
}
|
|
97
|
+
return clipToSrgb(oklchToRgbUnmapped({
|
|
98
|
+
...color,
|
|
99
|
+
c: lo
|
|
100
|
+
}));
|
|
101
|
+
};
|
|
102
|
+
const toRgb = (color) => color.mode === "rgb" ? color : oklchToRgb(color);
|
|
103
|
+
const toOklch = (color) => color.mode === "oklch" ? color : rgbToOklch(color);
|
|
104
|
+
const hslToRgb = ({ h, l, s }, alpha = 1) => {
|
|
105
|
+
const c = (1 - Math.abs(2 * l - 1)) * s;
|
|
106
|
+
const hp = (h % 360 + 360) % 360 / 60;
|
|
107
|
+
const x = c * (1 - Math.abs(hp % 2 - 1));
|
|
108
|
+
let r = 0;
|
|
109
|
+
let g = 0;
|
|
110
|
+
let b = 0;
|
|
111
|
+
if (hp < 1) [r, g, b] = [
|
|
112
|
+
c,
|
|
113
|
+
x,
|
|
114
|
+
0
|
|
115
|
+
];
|
|
116
|
+
else if (hp < 2) [r, g, b] = [
|
|
117
|
+
x,
|
|
118
|
+
c,
|
|
119
|
+
0
|
|
120
|
+
];
|
|
121
|
+
else if (hp < 3) [r, g, b] = [
|
|
122
|
+
0,
|
|
123
|
+
c,
|
|
124
|
+
x
|
|
125
|
+
];
|
|
126
|
+
else if (hp < 4) [r, g, b] = [
|
|
127
|
+
0,
|
|
128
|
+
x,
|
|
129
|
+
c
|
|
130
|
+
];
|
|
131
|
+
else if (hp < 5) [r, g, b] = [
|
|
132
|
+
x,
|
|
133
|
+
0,
|
|
134
|
+
c
|
|
135
|
+
];
|
|
136
|
+
else [r, g, b] = [
|
|
137
|
+
c,
|
|
138
|
+
0,
|
|
139
|
+
x
|
|
140
|
+
];
|
|
141
|
+
const m = l - c / 2;
|
|
142
|
+
return {
|
|
143
|
+
mode: "rgb",
|
|
144
|
+
r: r + m,
|
|
145
|
+
g: g + m,
|
|
146
|
+
b: b + m,
|
|
147
|
+
alpha
|
|
148
|
+
};
|
|
149
|
+
};
|
|
150
|
+
const rgbToHsl = (color) => {
|
|
151
|
+
const { b, g, r } = color;
|
|
152
|
+
const max = Math.max(r, g, b);
|
|
153
|
+
const min = Math.min(r, g, b);
|
|
154
|
+
const d = max - min;
|
|
155
|
+
const l = (max + min) / 2;
|
|
156
|
+
const s = d === 0 ? 0 : d / (1 - Math.abs(2 * l - 1));
|
|
157
|
+
let h = 0;
|
|
158
|
+
if (d !== 0) if (max === r) h = 60 * ((g - b) / d % 6);
|
|
159
|
+
else if (max === g) h = 60 * ((b - r) / d + 2);
|
|
160
|
+
else h = 60 * ((r - g) / d + 4);
|
|
161
|
+
if (h < 0) h += 360;
|
|
162
|
+
return {
|
|
163
|
+
h,
|
|
164
|
+
s,
|
|
165
|
+
l
|
|
166
|
+
};
|
|
167
|
+
};
|
|
168
|
+
const rgbToHsv = (color) => {
|
|
169
|
+
const { b, g, r } = color;
|
|
170
|
+
const max = Math.max(r, g, b);
|
|
171
|
+
const d = max - Math.min(r, g, b);
|
|
172
|
+
let h = 0;
|
|
173
|
+
if (d !== 0) if (max === r) h = 60 * ((g - b) / d % 6);
|
|
174
|
+
else if (max === g) h = 60 * ((b - r) / d + 2);
|
|
175
|
+
else h = 60 * ((r - g) / d + 4);
|
|
176
|
+
if (h < 0) h += 360;
|
|
177
|
+
return {
|
|
178
|
+
h,
|
|
179
|
+
s: max === 0 ? 0 : d / max,
|
|
180
|
+
v: max
|
|
181
|
+
};
|
|
182
|
+
};
|
|
183
|
+
const hsvToRgb = ({ h, s, v }, alpha = 1) => {
|
|
184
|
+
const c = v * s;
|
|
185
|
+
const hp = (h % 360 + 360) % 360 / 60;
|
|
186
|
+
const x = c * (1 - Math.abs(hp % 2 - 1));
|
|
187
|
+
let r = 0;
|
|
188
|
+
let g = 0;
|
|
189
|
+
let b = 0;
|
|
190
|
+
if (hp < 1) [r, g, b] = [
|
|
191
|
+
c,
|
|
192
|
+
x,
|
|
193
|
+
0
|
|
194
|
+
];
|
|
195
|
+
else if (hp < 2) [r, g, b] = [
|
|
196
|
+
x,
|
|
197
|
+
c,
|
|
198
|
+
0
|
|
199
|
+
];
|
|
200
|
+
else if (hp < 3) [r, g, b] = [
|
|
201
|
+
0,
|
|
202
|
+
c,
|
|
203
|
+
x
|
|
204
|
+
];
|
|
205
|
+
else if (hp < 4) [r, g, b] = [
|
|
206
|
+
0,
|
|
207
|
+
x,
|
|
208
|
+
c
|
|
209
|
+
];
|
|
210
|
+
else if (hp < 5) [r, g, b] = [
|
|
211
|
+
x,
|
|
212
|
+
0,
|
|
213
|
+
c
|
|
214
|
+
];
|
|
215
|
+
else [r, g, b] = [
|
|
216
|
+
c,
|
|
217
|
+
0,
|
|
218
|
+
x
|
|
219
|
+
];
|
|
220
|
+
const m = v - c;
|
|
221
|
+
return {
|
|
222
|
+
mode: "rgb",
|
|
223
|
+
r: r + m,
|
|
224
|
+
g: g + m,
|
|
225
|
+
b: b + m,
|
|
226
|
+
alpha
|
|
227
|
+
};
|
|
228
|
+
};
|
|
229
|
+
//#endregion
|
|
230
|
+
export { hslToRgb, hsvToRgb, isInSrgbGamut, oklchToRgb, rgbToHsl, rgbToHsv, rgbToOklch, srgbToLinear, toOklch, toRgb };
|
|
231
|
+
|
|
232
|
+
//# sourceMappingURL=convert.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"convert.js","names":[],"sources":["../../../../src/fields/color/engine/convert.ts"],"sourcesContent":["import type { Hsl, Hsv, Oklab, OklchColor, ParsedColor, RgbColor } from './types'\n\nexport const srgbToLinear = (channel: number): number =>\n\tchannel <= 0.04045 ? channel / 12.92 : ((channel + 0.055) / 1.055) ** 2.4\n\nexport const linearToSrgb = (channel: number): number =>\n\tchannel <= 0.0031308 ? channel * 12.92 : 1.055 * channel ** (1 / 2.4) - 0.055\n\n/** Standard CSS Color 4 / Ottosson OKLab matrices. */\nexport const rgbToOklab = (color: RgbColor): Oklab => {\n\tconst r = srgbToLinear(color.r)\n\tconst g = srgbToLinear(color.g)\n\tconst b = srgbToLinear(color.b)\n\tconst l = Math.cbrt(0.4122214708 * r + 0.5363325363 * g + 0.0514459929 * b)\n\tconst m = Math.cbrt(0.2119034982 * r + 0.6806995451 * g + 0.1073969566 * b)\n\tconst s = Math.cbrt(0.0883024619 * r + 0.2817188376 * g + 0.6299787005 * b)\n\treturn {\n\t\tl: 0.2104542553 * l + 0.793617785 * m - 0.0040720468 * s,\n\t\ta: 1.9779984951 * l - 2.428592205 * m + 0.4505937099 * s,\n\t\tb: 0.0259040371 * l + 0.7827717662 * m - 0.808675766 * s,\n\t}\n}\n\nexport const oklabToRgb = (lab: Oklab, alpha = 1): RgbColor => {\n\tconst l = (lab.l + 0.3963377774 * lab.a + 0.2158037573 * lab.b) ** 3\n\tconst m = (lab.l - 0.1055613458 * lab.a - 0.0638541728 * lab.b) ** 3\n\tconst s = (lab.l - 0.0894841775 * lab.a - 1.291485548 * lab.b) ** 3\n\treturn {\n\t\tmode: 'rgb',\n\t\tr: linearToSrgb(4.0767416621 * l - 3.3077115913 * m + 0.2309699292 * s),\n\t\tg: linearToSrgb(-1.2684380046 * l + 2.6097574011 * m - 0.3413193965 * s),\n\t\tb: linearToSrgb(-0.0041960863 * l - 0.7034186147 * m + 1.707614701 * s),\n\t\talpha,\n\t}\n}\n\nexport const rgbToOklch = (color: RgbColor): OklchColor => {\n\tconst lab = rgbToOklab(color)\n\tconst c = Math.hypot(lab.a, lab.b)\n\tlet h = (Math.atan2(lab.b, lab.a) * 180) / Math.PI\n\tif (h < 0) h += 360\n\t// Hue is meaningless at zero chroma; pin it so formatting is stable\n\tif (c < 1e-6) h = 0\n\treturn { mode: 'oklch', l: lab.l, c, h, alpha: color.alpha }\n}\n\n/** Direct OKLCH to sRGB conversion; channels may fall outside [0, 1]. */\nexport const oklchToRgbUnmapped = (color: OklchColor): RgbColor => {\n\tconst rad = (color.h * Math.PI) / 180\n\treturn oklabToRgb(\n\t\t{ l: color.l, a: color.c * Math.cos(rad), b: color.c * Math.sin(rad) },\n\t\tcolor.alpha\n\t)\n}\n\nconst GAMUT_EPSILON = 1e-5\n\nexport const isInSrgbGamut = (color: RgbColor): boolean =>\n\t[color.r, color.g, color.b].every((v) => v >= -GAMUT_EPSILON && v <= 1 + GAMUT_EPSILON)\n\nconst clip = (value: number): number => Math.min(1, Math.max(0, value))\n\nexport const clipToSrgb = (color: RgbColor): RgbColor => ({\n\t...color,\n\tr: clip(color.r),\n\tg: clip(color.g),\n\tb: clip(color.b),\n})\n\n/**\n * OKLCH to sRGB with CSS-style gamut mapping: chroma is reduced at constant\n * lightness and hue via binary search until the color fits, then clipped for\n * numeric noise. Never a naive per-channel clamp.\n */\nexport const oklchToRgb = (color: OklchColor): RgbColor => {\n\tconst direct = oklchToRgbUnmapped(color)\n\tif (isInSrgbGamut(direct)) return clipToSrgb(direct)\n\tif (color.l <= 0) return { mode: 'rgb', r: 0, g: 0, b: 0, alpha: color.alpha }\n\tif (color.l >= 1) return { mode: 'rgb', r: 1, g: 1, b: 1, alpha: color.alpha }\n\tlet lo = 0\n\tlet hi = color.c\n\tfor (let i = 0; i < 24; i += 1) {\n\t\tconst mid = (lo + hi) / 2\n\t\tif (isInSrgbGamut(oklchToRgbUnmapped({ ...color, c: mid }))) lo = mid\n\t\telse hi = mid\n\t}\n\treturn clipToSrgb(oklchToRgbUnmapped({ ...color, c: lo }))\n}\n\nexport const toRgb = (color: ParsedColor): RgbColor =>\n\tcolor.mode === 'rgb' ? color : oklchToRgb(color)\n\nexport const toOklch = (color: ParsedColor): OklchColor =>\n\tcolor.mode === 'oklch' ? color : rgbToOklch(color)\n\nexport const hslToRgb = ({ h, l, s }: Hsl, alpha = 1): RgbColor => {\n\tconst c = (1 - Math.abs(2 * l - 1)) * s\n\tconst hp = (((h % 360) + 360) % 360) / 60\n\tconst x = c * (1 - Math.abs((hp % 2) - 1))\n\tlet r = 0\n\tlet g = 0\n\tlet b = 0\n\tif (hp < 1) [r, g, b] = [c, x, 0]\n\telse if (hp < 2) [r, g, b] = [x, c, 0]\n\telse if (hp < 3) [r, g, b] = [0, c, x]\n\telse if (hp < 4) [r, g, b] = [0, x, c]\n\telse if (hp < 5) [r, g, b] = [x, 0, c]\n\telse [r, g, b] = [c, 0, x]\n\tconst m = l - c / 2\n\treturn { mode: 'rgb', r: r + m, g: g + m, b: b + m, alpha }\n}\n\nexport const rgbToHsl = (color: RgbColor): Hsl => {\n\tconst { b, g, r } = color\n\tconst max = Math.max(r, g, b)\n\tconst min = Math.min(r, g, b)\n\tconst d = max - min\n\tconst l = (max + min) / 2\n\tconst s = d === 0 ? 0 : d / (1 - Math.abs(2 * l - 1))\n\tlet h = 0\n\tif (d !== 0) {\n\t\tif (max === r) h = 60 * (((g - b) / d) % 6)\n\t\telse if (max === g) h = 60 * ((b - r) / d + 2)\n\t\telse h = 60 * ((r - g) / d + 4)\n\t}\n\tif (h < 0) h += 360\n\treturn { h, s, l }\n}\n\nexport const rgbToHsv = (color: RgbColor): Hsv => {\n\tconst { b, g, r } = color\n\tconst max = Math.max(r, g, b)\n\tconst min = Math.min(r, g, b)\n\tconst d = max - min\n\tlet h = 0\n\tif (d !== 0) {\n\t\tif (max === r) h = 60 * (((g - b) / d) % 6)\n\t\telse if (max === g) h = 60 * ((b - r) / d + 2)\n\t\telse h = 60 * ((r - g) / d + 4)\n\t}\n\tif (h < 0) h += 360\n\treturn { h, s: max === 0 ? 0 : d / max, v: max }\n}\n\nexport const hsvToRgb = ({ h, s, v }: Hsv, alpha = 1): RgbColor => {\n\tconst c = v * s\n\tconst hp = (((h % 360) + 360) % 360) / 60\n\tconst x = c * (1 - Math.abs((hp % 2) - 1))\n\tlet r = 0\n\tlet g = 0\n\tlet b = 0\n\tif (hp < 1) [r, g, b] = [c, x, 0]\n\telse if (hp < 2) [r, g, b] = [x, c, 0]\n\telse if (hp < 3) [r, g, b] = [0, c, x]\n\telse if (hp < 4) [r, g, b] = [0, x, c]\n\telse if (hp < 5) [r, g, b] = [x, 0, c]\n\telse [r, g, b] = [c, 0, x]\n\tconst m = v - c\n\treturn { mode: 'rgb', r: r + m, g: g + m, b: b + m, alpha }\n}\n"],"mappings":";AAEA,MAAa,gBAAgB,YAC5B,WAAW,SAAU,UAAU,UAAU,UAAU,QAAS,UAAU;AAEvE,MAAa,gBAAgB,YAC5B,WAAW,WAAY,UAAU,QAAQ,QAAQ,YAAY,IAAI,OAAO;;AAGzE,MAAa,cAAc,UAA2B;CACrD,MAAM,IAAI,aAAa,MAAM,CAAC;CAC9B,MAAM,IAAI,aAAa,MAAM,CAAC;CAC9B,MAAM,IAAI,aAAa,MAAM,CAAC;CAC9B,MAAM,IAAI,KAAK,KAAK,cAAe,IAAI,cAAe,IAAI,cAAe,CAAC;CAC1E,MAAM,IAAI,KAAK,KAAK,cAAe,IAAI,cAAe,IAAI,cAAe,CAAC;CAC1E,MAAM,IAAI,KAAK,KAAK,cAAe,IAAI,cAAe,IAAI,cAAe,CAAC;CAC1E,OAAO;EACN,GAAG,cAAe,IAAI,aAAc,IAAI,cAAe;EACvD,GAAG,eAAe,IAAI,cAAc,IAAI,cAAe;EACvD,GAAG,cAAe,IAAI,cAAe,IAAI,aAAc;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C,IAAI,QAAQ,GAAG,IAAI,OAAO,IAAI,KAAK,IAAI;MACvC,IAAI,OAAO,IAAI,KAAK,IAAI;CAE9B,IAAI,IAAI,GAAG,KAAK;CAChB,OAAO;EAAE;EAAG,GAAG,QAAQ,IAAI,IAAI,IAAI;EAAK,GAAG;CAAI;AAChD;AAEA,MAAa,YAAY,EAAE,GAAG,GAAG,KAAU,QAAQ,MAAgB;CAClE,MAAM,IAAI,IAAI;CACd,MAAM,MAAQ,IAAI,MAAO,OAAO,MAAO;CACvC,MAAM,IAAI,KAAK,IAAI,KAAK,IAAK,KAAK,IAAK,CAAC;CACxC,IAAI,IAAI;CACR,IAAI,IAAI;CACR,IAAI,IAAI;CACR,IAAI,KAAK,GAAG,CAAC,GAAG,GAAG,KAAK;EAAC;EAAG;EAAG;CAAC;MAC3B,IAAI,KAAK,GAAG,CAAC,GAAG,GAAG,KAAK;EAAC;EAAG;EAAG;CAAC;MAChC,IAAI,KAAK,GAAG,CAAC,GAAG,GAAG,KAAK;EAAC;EAAG;EAAG;CAAC;MAChC,IAAI,KAAK,GAAG,CAAC,GAAG,GAAG,KAAK;EAAC;EAAG;EAAG;CAAC;MAChC,IAAI,KAAK,GAAG,CAAC,GAAG,GAAG,KAAK;EAAC;EAAG;EAAG;CAAC;MAChC,CAAC,GAAG,GAAG,KAAK;EAAC;EAAG;EAAG;CAAC;CACzB,MAAM,IAAI,IAAI;CACd,OAAO;EAAE,MAAM;EAAO,GAAG,IAAI;EAAG,GAAG,IAAI;EAAG,GAAG,IAAI;EAAG;CAAM;AAC3D"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ColorFormat } from "../../../types.js";
|
|
2
|
+
import { FormatColorOptions, ParsedColor } from "./types.js";
|
|
3
|
+
|
|
4
|
+
//#region src/fields/color/engine/format.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* Formats a parsed color as modern CSS syntax in the requested format.
|
|
7
|
+
* Alpha is emitted only when below 1 (hex becomes 8-digit); `{ alpha: false }`
|
|
8
|
+
* strips it entirely. OKLCH input emitted as an sRGB format is gamut-mapped.
|
|
9
|
+
*/
|
|
10
|
+
declare const formatColor: (color: ParsedColor, format: ColorFormat, options?: FormatColorOptions) => string;
|
|
11
|
+
/** parseColor + formatColor in one step. Returns null when the input does not parse. */
|
|
12
|
+
declare const convertColor: (input: string, format: ColorFormat, options?: FormatColorOptions) => null | string;
|
|
13
|
+
//#endregion
|
|
14
|
+
export { convertColor, formatColor };
|
|
15
|
+
//# sourceMappingURL=format.d.ts.map
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { rgbToHsl, toOklch, toRgb } from "./convert.js";
|
|
2
|
+
import { parseColor } from "./parse.js";
|
|
3
|
+
//#region src/fields/color/engine/format.ts
|
|
4
|
+
const trimNumber = (value, decimals) => {
|
|
5
|
+
const fixed = (Math.abs(value) < 1e-9 ? 0 : value).toFixed(decimals);
|
|
6
|
+
if (!fixed.includes(".")) return fixed;
|
|
7
|
+
return fixed.replace(/0+$/, "").replace(/\.$/, "");
|
|
8
|
+
};
|
|
9
|
+
/** Rounds to the emitted precision first so hues in [360 - half-step, 360) wrap to 0, not '360'. */
|
|
10
|
+
const wrapHue = (value, decimals) => Number(value.toFixed(decimals)) % 360;
|
|
11
|
+
const clamp01 = (value) => Math.min(1, Math.max(0, value));
|
|
12
|
+
const channel255 = (value) => Math.round(clamp01(value) * 255);
|
|
13
|
+
const hexPair = (value) => channel255(value).toString(16).padStart(2, "0");
|
|
14
|
+
/**
|
|
15
|
+
* Formats a parsed color as modern CSS syntax in the requested format.
|
|
16
|
+
* Alpha is emitted only when below 1 (hex becomes 8-digit); `{ alpha: false }`
|
|
17
|
+
* strips it entirely. OKLCH input emitted as an sRGB format is gamut-mapped.
|
|
18
|
+
*/
|
|
19
|
+
const formatColor = (color, format, options = {}) => {
|
|
20
|
+
const rawAlpha = options.alpha === false ? 1 : color.alpha;
|
|
21
|
+
const alpha = Number.isFinite(rawAlpha) ? clamp01(rawAlpha) : 1;
|
|
22
|
+
const alphaText = trimNumber(alpha, 3);
|
|
23
|
+
const suffix = alphaText === "1" ? "" : ` / ${alphaText}`;
|
|
24
|
+
switch (format) {
|
|
25
|
+
case "hex": {
|
|
26
|
+
const rgb = toRgb(color);
|
|
27
|
+
const base = `#${hexPair(rgb.r)}${hexPair(rgb.g)}${hexPair(rgb.b)}`;
|
|
28
|
+
const alphaPair = hexPair(alpha);
|
|
29
|
+
return alphaPair === "ff" ? base : `${base}${alphaPair}`;
|
|
30
|
+
}
|
|
31
|
+
case "hsl": {
|
|
32
|
+
const hsl = rgbToHsl(toRgb(color));
|
|
33
|
+
return `hsl(${trimNumber(wrapHue(hsl.h, 1), 1)} ${trimNumber(hsl.s * 100, 1)}% ${trimNumber(hsl.l * 100, 1)}%${suffix})`;
|
|
34
|
+
}
|
|
35
|
+
case "oklch": {
|
|
36
|
+
const oklch = toOklch(color);
|
|
37
|
+
return `oklch(${trimNumber(oklch.l, 4)} ${trimNumber(oklch.c, 4)} ${trimNumber(wrapHue(oklch.h, 2), 2)}${suffix})`;
|
|
38
|
+
}
|
|
39
|
+
case "rgb": {
|
|
40
|
+
const rgb = toRgb(color);
|
|
41
|
+
return `rgb(${channel255(rgb.r)} ${channel255(rgb.g)} ${channel255(rgb.b)}${suffix})`;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
/** parseColor + formatColor in one step. Returns null when the input does not parse. */
|
|
46
|
+
const convertColor = (input, format, options) => {
|
|
47
|
+
const parsed = parseColor(input);
|
|
48
|
+
return parsed ? formatColor(parsed, format, options) : null;
|
|
49
|
+
};
|
|
50
|
+
//#endregion
|
|
51
|
+
export { convertColor, formatColor };
|
|
52
|
+
|
|
53
|
+
//# sourceMappingURL=format.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"format.js","names":[],"sources":["../../../../src/fields/color/engine/format.ts"],"sourcesContent":["import { rgbToHsl, toOklch, toRgb } from './convert'\nimport { parseColor } from './parse'\nimport type { ColorFormat, FormatColorOptions, ParsedColor } from './types'\n\nconst trimNumber = (value: number, decimals: number): string => {\n\tconst fixed = (Math.abs(value) < 1e-9 ? 0 : value).toFixed(decimals)\n\tif (!fixed.includes('.')) return fixed\n\treturn fixed.replace(/0+$/, '').replace(/\\.$/, '')\n}\n\n/** Rounds to the emitted precision first so hues in [360 - half-step, 360) wrap to 0, not '360'. */\nconst wrapHue = (value: number, decimals: number): number => Number(value.toFixed(decimals)) % 360\n\nconst clamp01 = (value: number): number => Math.min(1, Math.max(0, value))\n\nconst channel255 = (value: number): number => Math.round(clamp01(value) * 255)\n\nconst hexPair = (value: number): string => channel255(value).toString(16).padStart(2, '0')\n\n/**\n * Formats a parsed color as modern CSS syntax in the requested format.\n * Alpha is emitted only when below 1 (hex becomes 8-digit); `{ alpha: false }`\n * strips it entirely. OKLCH input emitted as an sRGB format is gamut-mapped.\n */\nexport const formatColor = (\n\tcolor: ParsedColor,\n\tformat: ColorFormat,\n\toptions: FormatColorOptions = {}\n): string => {\n\tconst rawAlpha = options.alpha === false ? 1 : color.alpha\n\tconst alpha = Number.isFinite(rawAlpha) ? clamp01(rawAlpha) : 1\n\tconst alphaText = trimNumber(alpha, 3)\n\tconst suffix = alphaText === '1' ? '' : ` / ${alphaText}`\n\tswitch (format) {\n\t\tcase 'hex': {\n\t\t\tconst rgb = toRgb(color)\n\t\t\tconst base = `#${hexPair(rgb.r)}${hexPair(rgb.g)}${hexPair(rgb.b)}`\n\t\t\tconst alphaPair = hexPair(alpha)\n\t\t\treturn alphaPair === 'ff' ? base : `${base}${alphaPair}`\n\t\t}\n\t\tcase 'hsl': {\n\t\t\tconst hsl = rgbToHsl(toRgb(color))\n\t\t\treturn `hsl(${trimNumber(wrapHue(hsl.h, 1), 1)} ${trimNumber(hsl.s * 100, 1)}% ${trimNumber(hsl.l * 100, 1)}%${suffix})`\n\t\t}\n\t\tcase 'oklch': {\n\t\t\tconst oklch = toOklch(color)\n\t\t\treturn `oklch(${trimNumber(oklch.l, 4)} ${trimNumber(oklch.c, 4)} ${trimNumber(wrapHue(oklch.h, 2), 2)}${suffix})`\n\t\t}\n\t\tcase 'rgb': {\n\t\t\tconst rgb = toRgb(color)\n\t\t\treturn `rgb(${channel255(rgb.r)} ${channel255(rgb.g)} ${channel255(rgb.b)}${suffix})`\n\t\t}\n\t}\n}\n\n/** parseColor + formatColor in one step. Returns null when the input does not parse. */\nexport const convertColor = (\n\tinput: string,\n\tformat: ColorFormat,\n\toptions?: FormatColorOptions\n): null | string => {\n\tconst parsed = parseColor(input)\n\treturn parsed ? formatColor(parsed, format, options) : null\n}\n"],"mappings":";;;AAIA,MAAM,cAAc,OAAe,aAA6B;CAC/D,MAAM,SAAS,KAAK,IAAI,KAAK,IAAI,OAAO,IAAI,OAAO,QAAQ,QAAQ;CACnE,IAAI,CAAC,MAAM,SAAS,GAAG,GAAG,OAAO;CACjC,OAAO,MAAM,QAAQ,OAAO,EAAE,EAAE,QAAQ,OAAO,EAAE;AAClD;;AAGA,MAAM,WAAW,OAAe,aAA6B,OAAO,MAAM,QAAQ,QAAQ,CAAC,IAAI;AAE/F,MAAM,WAAW,UAA0B,KAAK,IAAI,GAAG,KAAK,IAAI,GAAG,KAAK,CAAC;AAEzE,MAAM,cAAc,UAA0B,KAAK,MAAM,QAAQ,KAAK,IAAI,GAAG;AAE7E,MAAM,WAAW,UAA0B,WAAW,KAAK,EAAE,SAAS,EAAE,EAAE,SAAS,GAAG,GAAG;;;;;;AAOzF,MAAa,eACZ,OACA,QACA,UAA8B,CAAC,MACnB;CACZ,MAAM,WAAW,QAAQ,UAAU,QAAQ,IAAI,MAAM;CACrD,MAAM,QAAQ,OAAO,SAAS,QAAQ,IAAI,QAAQ,QAAQ,IAAI;CAC9D,MAAM,YAAY,WAAW,OAAO,CAAC;CACrC,MAAM,SAAS,cAAc,MAAM,KAAK,MAAM;CAC9C,QAAQ,QAAR;EACC,KAAK,OAAO;GACX,MAAM,MAAM,MAAM,KAAK;GACvB,MAAM,OAAO,IAAI,QAAQ,IAAI,CAAC,IAAI,QAAQ,IAAI,CAAC,IAAI,QAAQ,IAAI,CAAC;GAChE,MAAM,YAAY,QAAQ,KAAK;GAC/B,OAAO,cAAc,OAAO,OAAO,GAAG,OAAO;EAC9C;EACA,KAAK,OAAO;GACX,MAAM,MAAM,SAAS,MAAM,KAAK,CAAC;GACjC,OAAO,OAAO,WAAW,QAAQ,IAAI,GAAG,CAAC,GAAG,CAAC,EAAE,GAAG,WAAW,IAAI,IAAI,KAAK,CAAC,EAAE,IAAI,WAAW,IAAI,IAAI,KAAK,CAAC,EAAE,GAAG,OAAO;EACvH;EACA,KAAK,SAAS;GACb,MAAM,QAAQ,QAAQ,KAAK;GAC3B,OAAO,SAAS,WAAW,MAAM,GAAG,CAAC,EAAE,GAAG,WAAW,MAAM,GAAG,CAAC,EAAE,GAAG,WAAW,QAAQ,MAAM,GAAG,CAAC,GAAG,CAAC,IAAI,OAAO;EACjH;EACA,KAAK,OAAO;GACX,MAAM,MAAM,MAAM,KAAK;GACvB,OAAO,OAAO,WAAW,IAAI,CAAC,EAAE,GAAG,WAAW,IAAI,CAAC,EAAE,GAAG,WAAW,IAAI,CAAC,IAAI,OAAO;EACpF;CACD;AACD;;AAGA,MAAa,gBACZ,OACA,QACA,YACmB;CACnB,MAAM,SAAS,WAAW,KAAK;CAC/B,OAAO,SAAS,YAAY,QAAQ,QAAQ,OAAO,IAAI;AACxD"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ColorFormat } from "../../../types.js";
|
|
2
|
+
import { FormatColorOptions, Hsl, Hsv, OklchColor, ParsedColor, RgbColor } from "./types.js";
|
|
3
|
+
import { contrastRatio, relativeLuminance } from "./contrast.js";
|
|
4
|
+
import { hslToRgb, hsvToRgb, isInSrgbGamut, oklchToRgb, rgbToHsl, rgbToHsv, rgbToOklch, toOklch, toRgb } from "./convert.js";
|
|
5
|
+
import { convertColor, formatColor } from "./format.js";
|
|
6
|
+
import { namedColors } from "./namedColors.js";
|
|
7
|
+
import { parseColor } from "./parse.js";
|
|
8
|
+
import { salvageColor } from "./salvage.js";
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
//#region src/fields/color/engine/namedColors.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* The 148 CSS Color 4 named colors (X11 set plus rebeccapurple), lowercased.
|
|
4
|
+
* `transparent` is handled by the parser, not this table.
|
|
5
|
+
*/
|
|
6
|
+
declare const namedColors: Record<string, string>;
|
|
7
|
+
//#endregion
|
|
8
|
+
export { namedColors };
|
|
9
|
+
//# sourceMappingURL=namedColors.d.ts.map
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
//#region src/fields/color/engine/namedColors.ts
|
|
2
|
+
/**
|
|
3
|
+
* The 148 CSS Color 4 named colors (X11 set plus rebeccapurple), lowercased.
|
|
4
|
+
* `transparent` is handled by the parser, not this table.
|
|
5
|
+
*/
|
|
6
|
+
const namedColors = {
|
|
7
|
+
aliceblue: "#f0f8ff",
|
|
8
|
+
antiquewhite: "#faebd7",
|
|
9
|
+
aqua: "#00ffff",
|
|
10
|
+
aquamarine: "#7fffd4",
|
|
11
|
+
azure: "#f0ffff",
|
|
12
|
+
beige: "#f5f5dc",
|
|
13
|
+
bisque: "#ffe4c4",
|
|
14
|
+
black: "#000000",
|
|
15
|
+
blanchedalmond: "#ffebcd",
|
|
16
|
+
blue: "#0000ff",
|
|
17
|
+
blueviolet: "#8a2be2",
|
|
18
|
+
brown: "#a52a2a",
|
|
19
|
+
burlywood: "#deb887",
|
|
20
|
+
cadetblue: "#5f9ea0",
|
|
21
|
+
chartreuse: "#7fff00",
|
|
22
|
+
chocolate: "#d2691e",
|
|
23
|
+
coral: "#ff7f50",
|
|
24
|
+
cornflowerblue: "#6495ed",
|
|
25
|
+
cornsilk: "#fff8dc",
|
|
26
|
+
crimson: "#dc143c",
|
|
27
|
+
cyan: "#00ffff",
|
|
28
|
+
darkblue: "#00008b",
|
|
29
|
+
darkcyan: "#008b8b",
|
|
30
|
+
darkgoldenrod: "#b8860b",
|
|
31
|
+
darkgray: "#a9a9a9",
|
|
32
|
+
darkgreen: "#006400",
|
|
33
|
+
darkgrey: "#a9a9a9",
|
|
34
|
+
darkkhaki: "#bdb76b",
|
|
35
|
+
darkmagenta: "#8b008b",
|
|
36
|
+
darkolivegreen: "#556b2f",
|
|
37
|
+
darkorange: "#ff8c00",
|
|
38
|
+
darkorchid: "#9932cc",
|
|
39
|
+
darkred: "#8b0000",
|
|
40
|
+
darksalmon: "#e9967a",
|
|
41
|
+
darkseagreen: "#8fbc8f",
|
|
42
|
+
darkslateblue: "#483d8b",
|
|
43
|
+
darkslategray: "#2f4f4f",
|
|
44
|
+
darkslategrey: "#2f4f4f",
|
|
45
|
+
darkturquoise: "#00ced1",
|
|
46
|
+
darkviolet: "#9400d3",
|
|
47
|
+
deeppink: "#ff1493",
|
|
48
|
+
deepskyblue: "#00bfff",
|
|
49
|
+
dimgray: "#696969",
|
|
50
|
+
dimgrey: "#696969",
|
|
51
|
+
dodgerblue: "#1e90ff",
|
|
52
|
+
firebrick: "#b22222",
|
|
53
|
+
floralwhite: "#fffaf0",
|
|
54
|
+
forestgreen: "#228b22",
|
|
55
|
+
fuchsia: "#ff00ff",
|
|
56
|
+
gainsboro: "#dcdcdc",
|
|
57
|
+
ghostwhite: "#f8f8ff",
|
|
58
|
+
gold: "#ffd700",
|
|
59
|
+
goldenrod: "#daa520",
|
|
60
|
+
gray: "#808080",
|
|
61
|
+
green: "#008000",
|
|
62
|
+
greenyellow: "#adff2f",
|
|
63
|
+
grey: "#808080",
|
|
64
|
+
honeydew: "#f0fff0",
|
|
65
|
+
hotpink: "#ff69b4",
|
|
66
|
+
indianred: "#cd5c5c",
|
|
67
|
+
indigo: "#4b0082",
|
|
68
|
+
ivory: "#fffff0",
|
|
69
|
+
khaki: "#f0e68c",
|
|
70
|
+
lavender: "#e6e6fa",
|
|
71
|
+
lavenderblush: "#fff0f5",
|
|
72
|
+
lawngreen: "#7cfc00",
|
|
73
|
+
lemonchiffon: "#fffacd",
|
|
74
|
+
lightblue: "#add8e6",
|
|
75
|
+
lightcoral: "#f08080",
|
|
76
|
+
lightcyan: "#e0ffff",
|
|
77
|
+
lightgoldenrodyellow: "#fafad2",
|
|
78
|
+
lightgray: "#d3d3d3",
|
|
79
|
+
lightgreen: "#90ee90",
|
|
80
|
+
lightgrey: "#d3d3d3",
|
|
81
|
+
lightpink: "#ffb6c1",
|
|
82
|
+
lightsalmon: "#ffa07a",
|
|
83
|
+
lightseagreen: "#20b2aa",
|
|
84
|
+
lightskyblue: "#87cefa",
|
|
85
|
+
lightslategray: "#778899",
|
|
86
|
+
lightslategrey: "#778899",
|
|
87
|
+
lightsteelblue: "#b0c4de",
|
|
88
|
+
lightyellow: "#ffffe0",
|
|
89
|
+
lime: "#00ff00",
|
|
90
|
+
limegreen: "#32cd32",
|
|
91
|
+
linen: "#faf0e6",
|
|
92
|
+
magenta: "#ff00ff",
|
|
93
|
+
maroon: "#800000",
|
|
94
|
+
mediumaquamarine: "#66cdaa",
|
|
95
|
+
mediumblue: "#0000cd",
|
|
96
|
+
mediumorchid: "#ba55d3",
|
|
97
|
+
mediumpurple: "#9370db",
|
|
98
|
+
mediumseagreen: "#3cb371",
|
|
99
|
+
mediumslateblue: "#7b68ee",
|
|
100
|
+
mediumspringgreen: "#00fa9a",
|
|
101
|
+
mediumturquoise: "#48d1cc",
|
|
102
|
+
mediumvioletred: "#c71585",
|
|
103
|
+
midnightblue: "#191970",
|
|
104
|
+
mintcream: "#f5fffa",
|
|
105
|
+
mistyrose: "#ffe4e1",
|
|
106
|
+
moccasin: "#ffe4b5",
|
|
107
|
+
navajowhite: "#ffdead",
|
|
108
|
+
navy: "#000080",
|
|
109
|
+
oldlace: "#fdf5e6",
|
|
110
|
+
olive: "#808000",
|
|
111
|
+
olivedrab: "#6b8e23",
|
|
112
|
+
orange: "#ffa500",
|
|
113
|
+
orangered: "#ff4500",
|
|
114
|
+
orchid: "#da70d6",
|
|
115
|
+
palegoldenrod: "#eee8aa",
|
|
116
|
+
palegreen: "#98fb98",
|
|
117
|
+
paleturquoise: "#afeeee",
|
|
118
|
+
palevioletred: "#db7093",
|
|
119
|
+
papayawhip: "#ffefd5",
|
|
120
|
+
peachpuff: "#ffdab9",
|
|
121
|
+
peru: "#cd853f",
|
|
122
|
+
pink: "#ffc0cb",
|
|
123
|
+
plum: "#dda0dd",
|
|
124
|
+
powderblue: "#b0e0e6",
|
|
125
|
+
purple: "#800080",
|
|
126
|
+
rebeccapurple: "#663399",
|
|
127
|
+
red: "#ff0000",
|
|
128
|
+
rosybrown: "#bc8f8f",
|
|
129
|
+
royalblue: "#4169e1",
|
|
130
|
+
saddlebrown: "#8b4513",
|
|
131
|
+
salmon: "#fa8072",
|
|
132
|
+
sandybrown: "#f4a460",
|
|
133
|
+
seagreen: "#2e8b57",
|
|
134
|
+
seashell: "#fff5ee",
|
|
135
|
+
sienna: "#a0522d",
|
|
136
|
+
silver: "#c0c0c0",
|
|
137
|
+
skyblue: "#87ceeb",
|
|
138
|
+
slateblue: "#6a5acd",
|
|
139
|
+
slategray: "#708090",
|
|
140
|
+
slategrey: "#708090",
|
|
141
|
+
snow: "#fffafa",
|
|
142
|
+
springgreen: "#00ff7f",
|
|
143
|
+
steelblue: "#4682b4",
|
|
144
|
+
tan: "#d2b48c",
|
|
145
|
+
teal: "#008080",
|
|
146
|
+
thistle: "#d8bfd8",
|
|
147
|
+
tomato: "#ff6347",
|
|
148
|
+
turquoise: "#40e0d0",
|
|
149
|
+
violet: "#ee82ee",
|
|
150
|
+
wheat: "#f5deb3",
|
|
151
|
+
white: "#ffffff",
|
|
152
|
+
whitesmoke: "#f5f5f5",
|
|
153
|
+
yellow: "#ffff00",
|
|
154
|
+
yellowgreen: "#9acd32"
|
|
155
|
+
};
|
|
156
|
+
//#endregion
|
|
157
|
+
export { namedColors };
|
|
158
|
+
|
|
159
|
+
//# sourceMappingURL=namedColors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"namedColors.js","names":[],"sources":["../../../../src/fields/color/engine/namedColors.ts"],"sourcesContent":["/**\n * The 148 CSS Color 4 named colors (X11 set plus rebeccapurple), lowercased.\n * `transparent` is handled by the parser, not this table.\n */\nexport const namedColors: Record<string, string> = {\n\taliceblue: '#f0f8ff',\n\tantiquewhite: '#faebd7',\n\taqua: '#00ffff',\n\taquamarine: '#7fffd4',\n\tazure: '#f0ffff',\n\tbeige: '#f5f5dc',\n\tbisque: '#ffe4c4',\n\tblack: '#000000',\n\tblanchedalmond: '#ffebcd',\n\tblue: '#0000ff',\n\tblueviolet: '#8a2be2',\n\tbrown: '#a52a2a',\n\tburlywood: '#deb887',\n\tcadetblue: '#5f9ea0',\n\tchartreuse: '#7fff00',\n\tchocolate: '#d2691e',\n\tcoral: '#ff7f50',\n\tcornflowerblue: '#6495ed',\n\tcornsilk: '#fff8dc',\n\tcrimson: '#dc143c',\n\tcyan: '#00ffff',\n\tdarkblue: '#00008b',\n\tdarkcyan: '#008b8b',\n\tdarkgoldenrod: '#b8860b',\n\tdarkgray: '#a9a9a9',\n\tdarkgreen: '#006400',\n\tdarkgrey: '#a9a9a9',\n\tdarkkhaki: '#bdb76b',\n\tdarkmagenta: '#8b008b',\n\tdarkolivegreen: '#556b2f',\n\tdarkorange: '#ff8c00',\n\tdarkorchid: '#9932cc',\n\tdarkred: '#8b0000',\n\tdarksalmon: '#e9967a',\n\tdarkseagreen: '#8fbc8f',\n\tdarkslateblue: '#483d8b',\n\tdarkslategray: '#2f4f4f',\n\tdarkslategrey: '#2f4f4f',\n\tdarkturquoise: '#00ced1',\n\tdarkviolet: '#9400d3',\n\tdeeppink: '#ff1493',\n\tdeepskyblue: '#00bfff',\n\tdimgray: '#696969',\n\tdimgrey: '#696969',\n\tdodgerblue: '#1e90ff',\n\tfirebrick: '#b22222',\n\tfloralwhite: '#fffaf0',\n\tforestgreen: '#228b22',\n\tfuchsia: '#ff00ff',\n\tgainsboro: '#dcdcdc',\n\tghostwhite: '#f8f8ff',\n\tgold: '#ffd700',\n\tgoldenrod: '#daa520',\n\tgray: '#808080',\n\tgreen: '#008000',\n\tgreenyellow: '#adff2f',\n\tgrey: '#808080',\n\thoneydew: '#f0fff0',\n\thotpink: '#ff69b4',\n\tindianred: '#cd5c5c',\n\tindigo: '#4b0082',\n\tivory: '#fffff0',\n\tkhaki: '#f0e68c',\n\tlavender: '#e6e6fa',\n\tlavenderblush: '#fff0f5',\n\tlawngreen: '#7cfc00',\n\tlemonchiffon: '#fffacd',\n\tlightblue: '#add8e6',\n\tlightcoral: '#f08080',\n\tlightcyan: '#e0ffff',\n\tlightgoldenrodyellow: '#fafad2',\n\tlightgray: '#d3d3d3',\n\tlightgreen: '#90ee90',\n\tlightgrey: '#d3d3d3',\n\tlightpink: '#ffb6c1',\n\tlightsalmon: '#ffa07a',\n\tlightseagreen: '#20b2aa',\n\tlightskyblue: '#87cefa',\n\tlightslategray: '#778899',\n\tlightslategrey: '#778899',\n\tlightsteelblue: '#b0c4de',\n\tlightyellow: '#ffffe0',\n\tlime: '#00ff00',\n\tlimegreen: '#32cd32',\n\tlinen: '#faf0e6',\n\tmagenta: '#ff00ff',\n\tmaroon: '#800000',\n\tmediumaquamarine: '#66cdaa',\n\tmediumblue: '#0000cd',\n\tmediumorchid: '#ba55d3',\n\tmediumpurple: '#9370db',\n\tmediumseagreen: '#3cb371',\n\tmediumslateblue: '#7b68ee',\n\tmediumspringgreen: '#00fa9a',\n\tmediumturquoise: '#48d1cc',\n\tmediumvioletred: '#c71585',\n\tmidnightblue: '#191970',\n\tmintcream: '#f5fffa',\n\tmistyrose: '#ffe4e1',\n\tmoccasin: '#ffe4b5',\n\tnavajowhite: '#ffdead',\n\tnavy: '#000080',\n\toldlace: '#fdf5e6',\n\tolive: '#808000',\n\tolivedrab: '#6b8e23',\n\torange: '#ffa500',\n\torangered: '#ff4500',\n\torchid: '#da70d6',\n\tpalegoldenrod: '#eee8aa',\n\tpalegreen: '#98fb98',\n\tpaleturquoise: '#afeeee',\n\tpalevioletred: '#db7093',\n\tpapayawhip: '#ffefd5',\n\tpeachpuff: '#ffdab9',\n\tperu: '#cd853f',\n\tpink: '#ffc0cb',\n\tplum: '#dda0dd',\n\tpowderblue: '#b0e0e6',\n\tpurple: '#800080',\n\trebeccapurple: '#663399',\n\tred: '#ff0000',\n\trosybrown: '#bc8f8f',\n\troyalblue: '#4169e1',\n\tsaddlebrown: '#8b4513',\n\tsalmon: '#fa8072',\n\tsandybrown: '#f4a460',\n\tseagreen: '#2e8b57',\n\tseashell: '#fff5ee',\n\tsienna: '#a0522d',\n\tsilver: '#c0c0c0',\n\tskyblue: '#87ceeb',\n\tslateblue: '#6a5acd',\n\tslategray: '#708090',\n\tslategrey: '#708090',\n\tsnow: '#fffafa',\n\tspringgreen: '#00ff7f',\n\tsteelblue: '#4682b4',\n\ttan: '#d2b48c',\n\tteal: '#008080',\n\tthistle: '#d8bfd8',\n\ttomato: '#ff6347',\n\tturquoise: '#40e0d0',\n\tviolet: '#ee82ee',\n\twheat: '#f5deb3',\n\twhite: '#ffffff',\n\twhitesmoke: '#f5f5f5',\n\tyellow: '#ffff00',\n\tyellowgreen: '#9acd32',\n}\n"],"mappings":";;;;;AAIA,MAAa,cAAsC;CAClD,WAAW;CACX,cAAc;CACd,MAAM;CACN,YAAY;CACZ,OAAO;CACP,OAAO;CACP,QAAQ;CACR,OAAO;CACP,gBAAgB;CAChB,MAAM;CACN,YAAY;CACZ,OAAO;CACP,WAAW;CACX,WAAW;CACX,YAAY;CACZ,WAAW;CACX,OAAO;CACP,gBAAgB;CAChB,UAAU;CACV,SAAS;CACT,MAAM;CACN,UAAU;CACV,UAAU;CACV,eAAe;CACf,UAAU;CACV,WAAW;CACX,UAAU;CACV,WAAW;CACX,aAAa;CACb,gBAAgB;CAChB,YAAY;CACZ,YAAY;CACZ,SAAS;CACT,YAAY;CACZ,cAAc;CACd,eAAe;CACf,eAAe;CACf,eAAe;CACf,eA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;CACR,aAAa;AACd"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ParsedColor } from "./types.js";
|
|
2
|
+
|
|
3
|
+
//#region src/fields/color/engine/parse.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Parses a CSS color string: hex 3/4/6/8, rgb()/rgba() (legacy and modern syntax),
|
|
6
|
+
* hsl()/hsla(), oklch(), the 148 named colors, and `transparent`.
|
|
7
|
+
* Returns null for anything unparseable. Frontend-safe, zero dependencies.
|
|
8
|
+
*/
|
|
9
|
+
declare const parseColor: (input: string) => null | ParsedColor;
|
|
10
|
+
//#endregion
|
|
11
|
+
export { parseColor };
|
|
12
|
+
//# sourceMappingURL=parse.d.ts.map
|