@oneplatformdev/ui 0.1.99-beta.302 → 0.1.99-beta.305
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/ColorInput/ColorInput.d.ts +10 -0
- package/ColorInput/ColorInput.d.ts.map +1 -0
- package/ColorInput/ColorInput.js +103 -0
- package/ColorInput/ColorInput.js.map +1 -0
- package/ColorInput/ColorInput.stories.js +78 -0
- package/ColorInput/ColorInput.stories.js.map +1 -0
- package/ColorInput/ColorInput.types.d.ts +46 -0
- package/ColorInput/ColorInput.types.d.ts.map +1 -0
- package/ColorInput/ColorInput.types.js +2 -0
- package/ColorInput/ColorInput.types.js.map +1 -0
- package/ColorInput/ColorPicker.d.ts +28 -0
- package/ColorInput/ColorPicker.d.ts.map +1 -0
- package/ColorInput/ColorPicker.js +322 -0
- package/ColorInput/ColorPicker.js.map +1 -0
- package/ColorInput/color.utils.d.ts +42 -0
- package/ColorInput/color.utils.d.ts.map +1 -0
- package/ColorInput/color.utils.js +129 -0
- package/ColorInput/color.utils.js.map +1 -0
- package/ColorInput/index.d.ts +6 -0
- package/ColorInput/index.d.ts.map +1 -0
- package/ColorInput/index.js +25 -0
- package/ColorInput/index.js.map +1 -0
- package/ColorInput/useSavedColors.d.ts +13 -0
- package/ColorInput/useSavedColors.d.ts.map +1 -0
- package/ColorInput/useSavedColors.js +53 -0
- package/ColorInput/useSavedColors.js.map +1 -0
- package/Combobox/ComboboxRenderContent.d.ts.map +1 -1
- package/Combobox/ComboboxRenderContent.js +38 -35
- package/Combobox/ComboboxRenderContent.js.map +1 -1
- package/Combobox/ComboboxRenderTrigger.js +8 -8
- package/FormColorInput/FormColorInput.d.ts +7 -0
- package/FormColorInput/FormColorInput.d.ts.map +1 -0
- package/FormColorInput/FormColorInput.js +38 -0
- package/FormColorInput/FormColorInput.js.map +1 -0
- package/FormColorInput/FormColorInput.stories.js +95 -0
- package/FormColorInput/FormColorInput.stories.js.map +1 -0
- package/FormColorInput/FormColorInput.types.d.ts +6 -0
- package/FormColorInput/FormColorInput.types.d.ts.map +1 -0
- package/FormColorInput/FormColorInput.types.js +2 -0
- package/FormColorInput/FormColorInput.types.js.map +1 -0
- package/FormColorInput/index.d.ts +3 -0
- package/FormColorInput/index.d.ts.map +1 -0
- package/FormColorInput/index.js +5 -0
- package/FormColorInput/index.js.map +1 -0
- package/FormCombobox/FormCombobox.stories.js.map +1 -1
- package/index.d.ts +2 -0
- package/index.d.ts.map +1 -1
- package/index.js +366 -342
- package/index.js.map +1 -1
- package/package.json +4 -4
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ColorPicker.js","sources":["../../src/ColorInput/ColorPicker.tsx"],"sourcesContent":["import React, { useCallback, useEffect, useRef, useState } from 'react';\r\n\r\nimport { cn } from '@oneplatformdev/utils';\r\n\r\nimport {\r\n clamp,\r\n COLOR_FORMAT_LABELS,\r\n COLOR_FORMATS,\r\n ColorFormat,\r\n formatColor,\r\n FORMAT_HAS_ALPHA,\r\n HSVA,\r\n hsvaToRgba,\r\n parseColor,\r\n parseColorInFormat,\r\n rgbaToHsva,\r\n} from './color.utils';\r\n\r\n/** Compact, styled dropdown for the color format (Hex / RGB / RGBA / …). */\r\nconst FormatSelect = ({\r\n value,\r\n options,\r\n onChange,\r\n}: {\r\n value: ColorFormat;\r\n options: ColorFormat[];\r\n onChange: (next: ColorFormat) => void;\r\n}) => {\r\n const [open, setOpen] = useState(false);\r\n const ref = useRef<HTMLDivElement>(null);\r\n\r\n useEffect(() => {\r\n if (!open) return;\r\n const onDown = (e: MouseEvent) => {\r\n if (ref.current && !ref.current.contains(e.target as Node)) setOpen(false);\r\n };\r\n window.addEventListener('mousedown', onDown);\r\n return () => window.removeEventListener('mousedown', onDown);\r\n }, [open]);\r\n\r\n return (\r\n <div ref={ref} className=\"relative w-[74px] shrink-0\">\r\n <button\r\n type=\"button\"\r\n onClick={() => setOpen((o) => !o)}\r\n aria-haspopup=\"listbox\"\r\n aria-expanded={open}\r\n className={cn(\r\n 'flex h-7 w-full cursor-pointer items-center justify-between rounded border bg-white pl-2 pr-1.5 text-sm text-[#374151] shadow-[0px_1px_2px_rgba(31,41,55,0.08)] transition-colors',\r\n open ? 'border-[#9368FF]' : 'border-[#E5E7EB] hover:border-[#D1D5DB]',\r\n )}\r\n >\r\n <span>{COLOR_FORMAT_LABELS[value]}</span>\r\n <svg className=\"size-3 text-[#9CA3AF]\" viewBox=\"0 0 12 12\" fill=\"none\">\r\n <path d=\"M3.5 5 6 2.5 8.5 5\" stroke=\"currentColor\" strokeWidth=\"1.2\" strokeLinecap=\"round\" strokeLinejoin=\"round\" />\r\n <path d=\"M3.5 7 6 9.5 8.5 7\" stroke=\"currentColor\" strokeWidth=\"1.2\" strokeLinecap=\"round\" strokeLinejoin=\"round\" />\r\n </svg>\r\n </button>\r\n\r\n {open && (\r\n <ul\r\n role=\"listbox\"\r\n className=\"absolute left-0 top-[calc(100%+4px)] z-20 w-full overflow-hidden rounded border border-[#E5E7EB] bg-white py-1 shadow-[0px_10px_15px_rgba(31,41,55,0.1),0px_4px_6px_rgba(31,41,55,0.05)]\"\r\n >\r\n {options.map((f) => (\r\n <li key={f}>\r\n <button\r\n type=\"button\"\r\n role=\"option\"\r\n aria-selected={f === value}\r\n onClick={() => {\r\n onChange(f);\r\n setOpen(false);\r\n }}\r\n className={cn(\r\n 'flex w-full cursor-pointer items-center px-2 py-1 text-left text-sm hover:bg-[#F3F4F6]',\r\n f === value ? 'font-medium text-[#9368FF]' : 'text-[#374151]',\r\n )}\r\n >\r\n {COLOR_FORMAT_LABELS[f]}\r\n </button>\r\n </li>\r\n ))}\r\n </ul>\r\n )}\r\n </div>\r\n );\r\n};\r\n\r\nexport interface ColorPickerProps {\r\n value: string;\r\n onChange: (hex: string) => void;\r\n withAlpha?: boolean;\r\n /** Saved-colors palette. Empty by default. */\r\n savedColors?: string[];\r\n /** Renders the \"+ Add\" action; called with the current color. */\r\n onAddSavedColor?: (hex: string) => void;\r\n /** When provided, each saved swatch gets a hover \"×\" to remove it. */\r\n onRemoveSavedColor?: (hex: string) => void;\r\n /** Label before the palette (i18n). Default \"Saved colors:\". */\r\n savedColorsLabel?: string;\r\n /** Label of the add action (i18n). Default \"+ Add\". */\r\n addLabel?: string;\r\n /** Accessible label for a swatch's remove button (i18n). Default \"Remove color\". */\r\n removeColorLabel?: string;\r\n /**\r\n * Color formats offered in the format dropdown. Defaults to all of them\r\n * (`['hex', 'rgb', 'rgba', 'hsl', 'hsb']`). Pass a subset to restrict input,\r\n * e.g. `formats={['hex']}` to only allow hex. With a single format the\r\n * dropdown is hidden.\r\n */\r\n formats?: ColorFormat[];\r\n className?: string;\r\n}\r\n\r\n/** Returns a 0..1 ratio of pointer position inside an element along an axis. */\r\nconst ratioFromPointer = (\r\n el: HTMLElement,\r\n clientX: number,\r\n clientY: number,\r\n axis: 'x' | 'y' | 'both',\r\n): { x: number; y: number } => {\r\n const rect = el.getBoundingClientRect();\r\n const x = clamp((clientX - rect.left) / rect.width, 0, 1);\r\n const y = clamp((clientY - rect.top) / rect.height, 0, 1);\r\n return {\r\n x: axis === 'y' ? 0 : x,\r\n y: axis === 'x' ? 0 : y,\r\n };\r\n};\r\n\r\nconst useDrag = (\r\n onMove: (clientX: number, clientY: number, el: HTMLElement) => void,\r\n) => {\r\n const ref = useRef<HTMLDivElement>(null);\r\n\r\n const start = useCallback(\r\n (e: React.PointerEvent) => {\r\n const el = ref.current;\r\n if (!el) return;\r\n e.preventDefault();\r\n onMove(e.clientX, e.clientY, el);\r\n\r\n const handleMove = (ev: PointerEvent) =>\r\n onMove(ev.clientX, ev.clientY, el);\r\n const handleUp = () => {\r\n window.removeEventListener('pointermove', handleMove);\r\n window.removeEventListener('pointerup', handleUp);\r\n };\r\n window.addEventListener('pointermove', handleMove);\r\n window.addEventListener('pointerup', handleUp);\r\n },\r\n [onMove],\r\n );\r\n\r\n return { ref, start };\r\n};\r\n\r\nexport const ColorPicker = ({\r\n value,\r\n onChange,\r\n withAlpha = false,\r\n savedColors = [],\r\n onAddSavedColor,\r\n onRemoveSavedColor,\r\n savedColorsLabel = 'Saved colors:',\r\n addLabel = '+ Add',\r\n removeColorLabel = 'Remove color',\r\n formats = COLOR_FORMATS,\r\n className,\r\n}: ColorPickerProps) => {\r\n const availableFormats = formats.length ? formats : COLOR_FORMATS;\r\n const [format, setFormat] = useState<ColorFormat>(availableFormats[0]);\r\n\r\n // Keep the active format within the allowed set if `formats` changes.\r\n useEffect(() => {\r\n if (!availableFormats.includes(format)) setFormat(availableFormats[0]);\r\n }, [availableFormats, format]);\r\n\r\n const [hsva, setHsva] = useState<HSVA>(() => {\r\n const rgba = parseColor(value);\r\n return rgba ? rgbaToHsva(rgba) : { h: 0, s: 0, v: 0, a: 1 };\r\n });\r\n\r\n // Local text buffer so partially-typed values (e.g. \"255, 20\") don't get\r\n // snapped back by the controlled value while the user is mid-edit.\r\n const [fieldText, setFieldText] = useState<string | null>(null);\r\n\r\n // Alpha only makes sense for formats that can encode it: hex (#RRGGBBAA) and\r\n // rgba. rgb/hsl/hsb have no alpha channel, so the transparency slider is\r\n // hidden there. `withAlpha` can still force it on explicitly.\r\n const formatSupportsAlpha = format === 'hex' || format === 'rgba';\r\n const alphaEnabled = withAlpha || formatSupportsAlpha;\r\n\r\n // Sync from external value, but keep internal hue when only it differs\r\n // (prevents the hue jumping when saturation/value reach extremes).\r\n useEffect(() => {\r\n const rgba = parseColor(value);\r\n if (!rgba) return;\r\n const next = rgbaToHsva(rgba);\r\n setHsva((prev) =>\r\n formatColor(hsvaToRgba(prev), 'hex', alphaEnabled).toLowerCase() ===\r\n value.trim().toLowerCase()\r\n ? prev\r\n : next,\r\n );\r\n }, [value, alphaEnabled]);\r\n\r\n const emit = useCallback(\r\n (next: HSVA) => {\r\n setHsva(next);\r\n onChange(formatColor(hsvaToRgba(next), 'hex', alphaEnabled));\r\n },\r\n [onChange, alphaEnabled],\r\n );\r\n\r\n const saturation = useDrag((x, y, el) => {\r\n const { x: rx, y: ry } = ratioFromPointer(el, x, y, 'both');\r\n emit({ ...hsva, s: rx, v: 1 - ry });\r\n });\r\n const hue = useDrag((x, _y, el) => {\r\n const { x: rx } = ratioFromPointer(el, x, 0, 'x');\r\n emit({ ...hsva, h: rx * 360 });\r\n });\r\n const alpha = useDrag((x, _y, el) => {\r\n const { x: rx } = ratioFromPointer(el, x, 0, 'x');\r\n emit({ ...hsva, a: rx });\r\n });\r\n\r\n const hueColor = formatColor(hsvaToRgba({ h: hsva.h, s: 1, v: 1, a: 1 }), 'hex');\r\n const solidColor = formatColor(hsvaToRgba({ ...hsva, a: 1 }), 'hex');\r\n // The actual color with its alpha applied — used for the palette opacity and\r\n // for what \"+ Add\" saves (so a semi-transparent color is stored as #rrggbbaa).\r\n const currentColor = formatColor(hsvaToRgba(hsva), 'hex', alphaEnabled);\r\n const paletteOpacity = alphaEnabled ? hsva.a : 1;\r\n // The saved swatch matching the current color — the trash button targets it.\r\n const selectedSavedColor = savedColors.find(\r\n (c) => c.toLowerCase() === currentColor.toLowerCase(),\r\n );\r\n // The value field shows alpha inline only for formats that encode it (RGBA).\r\n // For hex/rgb/hsl/hsb the alpha lives in the separate `%` field instead.\r\n const fieldValue =\r\n fieldText ??\r\n formatColor(hsvaToRgba(hsva), format, FORMAT_HAS_ALPHA[format]).replace(\r\n format === 'hex' ? /^#/ : /^$/,\r\n '',\r\n );\r\n\r\n const showFormatSelect = availableFormats.length > 1;\r\n\r\n return (\r\n <div className={cn('flex w-[232px] flex-col gap-4', className)}>\r\n {/* Saturation / Value area — checker shows through as alpha drops. */}\r\n <div\r\n ref={saturation.ref}\r\n onPointerDown={saturation.start}\r\n className=\"relative h-[152px] w-full cursor-crosshair touch-none overflow-hidden rounded\"\r\n style={{\r\n backgroundImage:\r\n 'repeating-conic-gradient(#ccc 0% 25%, #fff 0% 50%)',\r\n backgroundSize: '16px 16px',\r\n }}\r\n >\r\n <div\r\n className=\"pointer-events-none absolute inset-0\"\r\n style={{\r\n opacity: paletteOpacity,\r\n backgroundColor: hueColor,\r\n backgroundImage:\r\n 'linear-gradient(to top, #000 0%, transparent 100%), linear-gradient(to right, #fff 0%, transparent 100%)',\r\n }}\r\n />\r\n <span\r\n className=\"pointer-events-none absolute size-4 -translate-x-1/2 -translate-y-1/2 rounded-full border-2 border-white shadow-[0px_2px_4px_rgba(31,41,55,0.2)]\"\r\n style={{\r\n left: `calc(8px + ${hsva.s} * (100% - 16px))`,\r\n top: `calc(8px + ${1 - hsva.v} * (100% - 16px))`,\r\n // actual color incl. alpha, so the dot matches the square\r\n backgroundColor: currentColor,\r\n }}\r\n />\r\n </div>\r\n\r\n {/* Hue slider */}\r\n <div\r\n ref={hue.ref}\r\n onPointerDown={hue.start}\r\n className=\"relative h-2 w-full cursor-pointer touch-none rounded-full\"\r\n style={{\r\n backgroundImage:\r\n 'linear-gradient(90deg, #FF0000 0%, #FF8A00 12%, #FFE600 25%, #14FF00 39%, #00A3FF 50%, #0500FF 62%, #AD00FF 73%, #FF00C7 85%, #FF0000 100%)',\r\n }}\r\n >\r\n <span\r\n className=\"pointer-events-none absolute top-1/2 size-4 -translate-y-1/2 rounded-full border-2 border-white shadow-[0px_2px_4px_rgba(31,41,55,0.2)]\"\r\n style={{\r\n left: `calc(${hsva.h / 360} * (100% - 16px))`,\r\n backgroundColor: hueColor,\r\n }}\r\n />\r\n </div>\r\n\r\n {/* Alpha (transparency) slider */}\r\n {alphaEnabled && (\r\n <div\r\n ref={alpha.ref}\r\n onPointerDown={alpha.start}\r\n className=\"relative h-2 w-full cursor-pointer touch-none rounded-full\"\r\n style={{\r\n backgroundImage: `linear-gradient(90deg, transparent 0%, ${solidColor} 100%), repeating-conic-gradient(#ccc 0% 25%, #fff 0% 50%)`,\r\n backgroundSize: '100% 100%, 6px 6px',\r\n }}\r\n >\r\n <span\r\n className=\"pointer-events-none absolute top-1/2 size-4 -translate-y-1/2 rounded-full border-2 border-white shadow-[0px_2px_4px_rgba(31,41,55,0.2)]\"\r\n style={{\r\n left: `calc(${hsva.a} * (100% - 16px))`,\r\n backgroundColor: solidColor,\r\n }}\r\n />\r\n </div>\r\n )}\r\n\r\n {/* Fields: format select + value + optional alpha % */}\r\n <div className=\"flex items-start gap-2\">\r\n {showFormatSelect && (\r\n <FormatSelect\r\n value={format}\r\n options={availableFormats}\r\n onChange={(next) => {\r\n setFieldText(null);\r\n setFormat(next);\r\n }}\r\n />\r\n )}\r\n\r\n <div className=\"flex h-7 flex-1 items-center gap-1 rounded border border-[#E5E7EB] bg-white px-1.5 shadow-[0px_1px_2px_rgba(31,41,55,0.08)]\">\r\n {format === 'hex' && <span className=\"text-sm text-[#9CA3AF]\">#</span>}\r\n <input\r\n value={fieldValue}\r\n onChange={(e) => {\r\n setFieldText(e.target.value);\r\n const rgba = parseColorInFormat(e.target.value, format);\r\n if (rgba) emit(rgbaToHsva(rgba));\r\n }}\r\n onBlur={() => setFieldText(null)}\r\n className=\"w-full min-w-0 bg-transparent text-sm text-[#374151] outline-none\"\r\n aria-label={`${COLOR_FORMAT_LABELS[format]} value`}\r\n />\r\n </div>\r\n\r\n {/*\r\n The separate % field is only for hex (its value is short, so 3 boxes\r\n fit). RGBA carries alpha in its value field; rgb/hsl/hsb control alpha\r\n via the slider — keeping their (long) value field from being squeezed.\r\n */}\r\n {alphaEnabled && format === 'hex' && (\r\n <div className=\"flex h-7 w-[56px] shrink-0 items-center rounded border border-[#E5E7EB] bg-white px-1.5 shadow-[0px_1px_2px_rgba(31,41,55,0.08)]\">\r\n <input\r\n value={`${Math.round(hsva.a * 100)}%`}\r\n onChange={(e) => {\r\n const num = parseInt(e.target.value.replace(/[^0-9]/g, ''), 10);\r\n if (!Number.isNaN(num)) emit({ ...hsva, a: clamp(num, 0, 100) / 100 });\r\n }}\r\n className=\"w-full bg-transparent text-sm text-[#374151] outline-none\"\r\n aria-label=\"Alpha percent\"\r\n />\r\n </div>\r\n )}\r\n </div>\r\n\r\n {/* Saved colors */}\r\n {(Boolean(onAddSavedColor) || savedColors.length > 0) && (\r\n <>\r\n <div className=\"flex items-center justify-between\">\r\n <span className=\"text-xs font-medium text-[#374151]\">\r\n {savedColorsLabel}\r\n </span>\r\n <div className=\"flex items-center gap-2\">\r\n {/* Remove the currently selected swatch (avoids per-dot crosses). */}\r\n {Boolean(onRemoveSavedColor) && selectedSavedColor && (\r\n <button\r\n type=\"button\"\r\n aria-label={removeColorLabel}\r\n title={removeColorLabel}\r\n className=\"flex cursor-pointer items-center text-[#6B7280] hover:text-[#EF4444]\"\r\n onClick={() => onRemoveSavedColor?.(selectedSavedColor)}\r\n >\r\n <svg viewBox=\"0 0 16 16\" className=\"size-3.5\" fill=\"none\">\r\n <path\r\n d=\"M2.5 4h11M6.5 4V2.8c0-.4.3-.8.8-.8h1.4c.5 0 .8.4.8.8V4M4 4l.6 8.3c0 .6.5 1 1 1h4.8c.5 0 1-.4 1-1L12 4M6.5 6.8v4M9.5 6.8v4\"\r\n stroke=\"currentColor\"\r\n strokeWidth=\"1.1\"\r\n strokeLinecap=\"round\"\r\n strokeLinejoin=\"round\"\r\n />\r\n </svg>\r\n </button>\r\n )}\r\n {Boolean(onAddSavedColor) && (\r\n <button\r\n type=\"button\"\r\n className=\"text-xs font-medium text-[#6B7280] hover:text-[#374151]\"\r\n onClick={() => onAddSavedColor?.(currentColor)}\r\n >\r\n {addLabel}\r\n </button>\r\n )}\r\n </div>\r\n </div>\r\n {savedColors.length > 0 && (\r\n <div className=\"grid grid-cols-7 gap-2\">\r\n {savedColors.map((color) => (\r\n <div key={color} className=\"relative size-6\">\r\n {/* checker so semi-transparent swatches read correctly */}\r\n <span\r\n className=\"absolute inset-0 rounded-full\"\r\n style={{\r\n backgroundImage:\r\n 'repeating-conic-gradient(#ccc 0% 25%, #fff 0% 50%)',\r\n backgroundSize: '8px 8px',\r\n }}\r\n />\r\n <button\r\n type=\"button\"\r\n title={color}\r\n onClick={() => {\r\n const rgba = parseColor(color);\r\n if (rgba) emit(rgbaToHsva(rgba));\r\n }}\r\n className={cn(\r\n 'absolute inset-0 cursor-pointer rounded-full',\r\n currentColor.toLowerCase() === color.toLowerCase() &&\r\n 'border-2 border-white shadow-[0px_0px_0px_2px_rgba(0,0,0,0.25)]',\r\n )}\r\n style={{ backgroundColor: color }}\r\n />\r\n </div>\r\n ))}\r\n </div>\r\n )}\r\n </>\r\n )}\r\n </div>\r\n );\r\n};\r\n"],"names":["FormatSelect","value","options","onChange","open","setOpen","useState","ref","useRef","useEffect","onDown","e","jsxs","o","cn","jsx","COLOR_FORMAT_LABELS","f","ratioFromPointer","el","clientX","clientY","axis","rect","x","clamp","y","useDrag","onMove","start","useCallback","handleMove","ev","handleUp","ColorPicker","withAlpha","savedColors","onAddSavedColor","onRemoveSavedColor","savedColorsLabel","addLabel","removeColorLabel","formats","COLOR_FORMATS","className","availableFormats","format","setFormat","hsva","setHsva","rgba","parseColor","rgbaToHsva","fieldText","setFieldText","alphaEnabled","next","prev","formatColor","hsvaToRgba","emit","saturation","rx","ry","hue","_y","alpha","hueColor","solidColor","currentColor","paletteOpacity","selectedSavedColor","c","fieldValue","FORMAT_HAS_ALPHA","showFormatSelect","parseColorInFormat","num","Fragment","color"],"mappings":";;;;AAmBA,MAAMA,KAAe,CAAC;AAAA,EACpB,OAAAC;AAAA,EACA,SAAAC;AAAA,EACA,UAAAC;AACF,MAIM;AACJ,QAAM,CAACC,GAAMC,CAAO,IAAIC,EAAS,EAAK,GAChCC,IAAMC,EAAuB,IAAI;AAEvC,SAAAC,EAAU,MAAM;AACd,QAAI,CAACL,EAAM;AACX,UAAMM,IAAS,CAACC,MAAkB;AAChC,MAAIJ,EAAI,WAAW,CAACA,EAAI,QAAQ,SAASI,EAAE,MAAc,KAAGN,EAAQ,EAAK;AAAA,IAC3E;AACA,kBAAO,iBAAiB,aAAaK,CAAM,GACpC,MAAM,OAAO,oBAAoB,aAAaA,CAAM;AAAA,EAC7D,GAAG,CAACN,CAAI,CAAC,GAGP,gBAAAQ,EAAC,OAAA,EAAI,KAAAL,GAAU,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,UAAC;AAAA,UAAA;AAAA,YACC,MAAK;AAAA,YACL,OAAOgE;AAAA,YACP,SAAS,MAAM;AACb,oBAAM7B,IAAOC,EAAW4B,CAAK;AAC7B,cAAI7B,KAAMU,EAAKR,EAAWF,CAAI,CAAC;AAAA,YACjC;AAAA,YACA,WAAWpC;AAAA,cACT;AAAA,cACAuD,EAAa,YAAA,MAAkBU,EAAM,iBACnC;AAAA,YAAA;AAAA,YAEJ,OAAO,EAAE,iBAAiBA,EAAA;AAAA,UAAM;AAAA,QAAA;AAAA,MAClC,EAAA,GAvBQA,CAwBV,CACD,EAAA,CACH;AAAA,IAAA,EAAA,CAEJ;AAAA,EAAA,GAEJ;AAEJ;"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
export interface RGBA {
|
|
2
|
+
r: number;
|
|
3
|
+
g: number;
|
|
4
|
+
b: number;
|
|
5
|
+
a: number;
|
|
6
|
+
}
|
|
7
|
+
export interface HSVA {
|
|
8
|
+
h: number;
|
|
9
|
+
s: number;
|
|
10
|
+
v: number;
|
|
11
|
+
a: number;
|
|
12
|
+
}
|
|
13
|
+
export declare const clamp: (value: number, min: number, max: number) => number;
|
|
14
|
+
/** Parses #rgb / #rrggbb / #rrggbbaa (with or without leading #) into RGBA. */
|
|
15
|
+
export declare const parseColor: (input: string) => RGBA | null;
|
|
16
|
+
export declare const isValidColor: (input: string) => boolean;
|
|
17
|
+
/** Formats RGBA to a hex string. Includes the alpha byte only when withAlpha and a<1. */
|
|
18
|
+
export declare const rgbaToHex: (rgba: RGBA, withAlpha?: boolean) => string;
|
|
19
|
+
export declare const rgbaToHsva: ({ r, g, b, a }: RGBA) => HSVA;
|
|
20
|
+
export declare const hsvaToRgba: ({ h, s, v, a }: HSVA) => RGBA;
|
|
21
|
+
/** Color string formats the picker can read/emit. */
|
|
22
|
+
export type ColorFormat = 'hex' | 'rgb' | 'rgba' | 'hsl' | 'hsb';
|
|
23
|
+
/** All formats, in the order they appear in the format dropdown. */
|
|
24
|
+
export declare const COLOR_FORMATS: ColorFormat[];
|
|
25
|
+
export declare const COLOR_FORMAT_LABELS: Record<ColorFormat, string>;
|
|
26
|
+
/** Formats that carry an alpha channel — these enable the transparency slider. */
|
|
27
|
+
export declare const FORMAT_HAS_ALPHA: Record<ColorFormat, boolean>;
|
|
28
|
+
export interface HSLA {
|
|
29
|
+
h: number;
|
|
30
|
+
s: number;
|
|
31
|
+
l: number;
|
|
32
|
+
a: number;
|
|
33
|
+
}
|
|
34
|
+
export declare const rgbaToHsla: ({ r, g, b, a }: RGBA) => HSLA;
|
|
35
|
+
export declare const hslaToRgba: ({ h, s, l, a }: HSLA) => RGBA;
|
|
36
|
+
/** Renders an RGBA value as a string in the requested format. */
|
|
37
|
+
export declare const formatColor: (rgba: RGBA, format: ColorFormat, withAlpha?: boolean) => string;
|
|
38
|
+
/** Parses a string written in the given format back into RGBA. */
|
|
39
|
+
export declare const parseColorInFormat: (input: string, format: ColorFormat) => RGBA | null;
|
|
40
|
+
/** Default saved-colors palette mirroring the Figma design. */
|
|
41
|
+
export declare const DEFAULT_SAVED_COLORS: string[];
|
|
42
|
+
//# sourceMappingURL=color.utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"color.utils.d.ts","sourceRoot":"","sources":["../../src/ColorInput/color.utils.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,IAAI;IACnB,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;CACX;AAED,MAAM,WAAW,IAAI;IACnB,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;CACX;AAED,eAAO,MAAM,KAAK,GAAI,OAAO,MAAM,EAAE,KAAK,MAAM,EAAE,KAAK,MAAM,KAAG,MAC3B,CAAC;AAKtC,+EA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B,EAAE,MAAM,EAexC,CAAC"}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
const u = (t, n, e) => Math.min(e, Math.max(n, t)), b = (t) => u(Math.round(t), 0, 255).toString(16).padStart(2, "0"), m = (t) => {
|
|
2
|
+
if (!t) return null;
|
|
3
|
+
let n = t.trim().replace(/^#/, "");
|
|
4
|
+
return /^[0-9a-f]{3}$/i.test(n) && (n = n.split("").map((e) => e + e).join("")), /^[0-9a-f]{6}$/i.test(n) ? {
|
|
5
|
+
r: parseInt(n.slice(0, 2), 16),
|
|
6
|
+
g: parseInt(n.slice(2, 4), 16),
|
|
7
|
+
b: parseInt(n.slice(4, 6), 16),
|
|
8
|
+
a: 1
|
|
9
|
+
} : /^[0-9a-f]{8}$/i.test(n) ? {
|
|
10
|
+
r: parseInt(n.slice(0, 2), 16),
|
|
11
|
+
g: parseInt(n.slice(2, 4), 16),
|
|
12
|
+
b: parseInt(n.slice(4, 6), 16),
|
|
13
|
+
a: parseInt(n.slice(6, 8), 16) / 255
|
|
14
|
+
} : null;
|
|
15
|
+
}, E = (t) => m(t) !== null, x = (t, n = !1) => {
|
|
16
|
+
const e = `#${b(t.r)}${b(t.g)}${b(t.b)}`;
|
|
17
|
+
return n && t.a < 1 ? `${e}${b(t.a * 255)}` : e;
|
|
18
|
+
}, g = ({ r: t, g: n, b: e, a: h }) => {
|
|
19
|
+
const s = t / 255, r = n / 255, c = e / 255, l = Math.max(s, r, c), a = Math.min(s, r, c), o = l - a;
|
|
20
|
+
let i = 0;
|
|
21
|
+
o !== 0 && (l === s ? i = (r - c) / o % 6 : l === r ? i = (c - s) / o + 2 : i = (s - r) / o + 4, i *= 60, i < 0 && (i += 360));
|
|
22
|
+
const $ = l === 0 ? 0 : o / l;
|
|
23
|
+
return { h: i, s: $, v: l, a: h };
|
|
24
|
+
}, F = ({ h: t, s: n, v: e, a: h }) => {
|
|
25
|
+
const s = e * n, r = s * (1 - Math.abs(t / 60 % 2 - 1)), c = e - s;
|
|
26
|
+
let l = 0, a = 0, o = 0;
|
|
27
|
+
return t < 60 ? [l, a, o] = [s, r, 0] : t < 120 ? [l, a, o] = [r, s, 0] : t < 180 ? [l, a, o] = [0, s, r] : t < 240 ? [l, a, o] = [0, r, s] : t < 300 ? [l, a, o] = [r, 0, s] : [l, a, o] = [s, 0, r], {
|
|
28
|
+
r: Math.round((l + c) * 255),
|
|
29
|
+
g: Math.round((a + c) * 255),
|
|
30
|
+
b: Math.round((o + c) * 255),
|
|
31
|
+
a: h
|
|
32
|
+
};
|
|
33
|
+
}, R = ["hex", "rgb", "rgba", "hsl", "hsb"], H = {
|
|
34
|
+
hex: "Hex",
|
|
35
|
+
rgb: "RGB",
|
|
36
|
+
rgba: "RGBA",
|
|
37
|
+
hsl: "HSL",
|
|
38
|
+
hsb: "HSB"
|
|
39
|
+
}, O = {
|
|
40
|
+
hex: !1,
|
|
41
|
+
rgb: !1,
|
|
42
|
+
rgba: !0,
|
|
43
|
+
hsl: !1,
|
|
44
|
+
hsb: !1
|
|
45
|
+
}, p = ({ r: t, g: n, b: e, a: h }) => {
|
|
46
|
+
const s = t / 255, r = n / 255, c = e / 255, l = Math.max(s, r, c), a = Math.min(s, r, c), o = l - a;
|
|
47
|
+
let i = 0;
|
|
48
|
+
o !== 0 && (l === s ? i = (r - c) / o % 6 : l === r ? i = (c - s) / o + 2 : i = (s - r) / o + 4, i *= 60, i < 0 && (i += 360));
|
|
49
|
+
const $ = (l + a) / 2, d = o === 0 ? 0 : o / (1 - Math.abs(2 * $ - 1));
|
|
50
|
+
return { h: i, s: d, l: $, a: h };
|
|
51
|
+
}, C = ({ h: t, s: n, l: e, a: h }) => {
|
|
52
|
+
const s = (1 - Math.abs(2 * e - 1)) * n, r = s * (1 - Math.abs(t / 60 % 2 - 1)), c = e - s / 2;
|
|
53
|
+
let l = 0, a = 0, o = 0;
|
|
54
|
+
return t < 60 ? [l, a, o] = [s, r, 0] : t < 120 ? [l, a, o] = [r, s, 0] : t < 180 ? [l, a, o] = [0, s, r] : t < 240 ? [l, a, o] = [0, r, s] : t < 300 ? [l, a, o] = [r, 0, s] : [l, a, o] = [s, 0, r], {
|
|
55
|
+
r: Math.round((l + c) * 255),
|
|
56
|
+
g: Math.round((a + c) * 255),
|
|
57
|
+
b: Math.round((o + c) * 255),
|
|
58
|
+
a: h
|
|
59
|
+
};
|
|
60
|
+
}, f = (t) => Math.round(t), M = (t) => `${Math.round(t * 100)}%`, S = (t, n, e = !1) => {
|
|
61
|
+
switch (n) {
|
|
62
|
+
case "rgba":
|
|
63
|
+
return `${f(t.r)}, ${f(t.g)}, ${f(t.b)}, ${Number(t.a.toFixed(2))}`;
|
|
64
|
+
case "rgb":
|
|
65
|
+
return e && t.a < 1 ? `${f(t.r)}, ${f(t.g)}, ${f(t.b)}, ${Number(t.a.toFixed(2))}` : `${f(t.r)}, ${f(t.g)}, ${f(t.b)}`;
|
|
66
|
+
case "hsl": {
|
|
67
|
+
const { h, s, l: r } = p(t);
|
|
68
|
+
return `${f(h)}, ${M(s)}, ${M(r)}`;
|
|
69
|
+
}
|
|
70
|
+
case "hsb": {
|
|
71
|
+
const { h, s, v: r } = g(t);
|
|
72
|
+
return `${f(h)}, ${M(s)}, ${M(r)}`;
|
|
73
|
+
}
|
|
74
|
+
case "hex":
|
|
75
|
+
default:
|
|
76
|
+
return x(t, e).toUpperCase();
|
|
77
|
+
}
|
|
78
|
+
}, A = (t) => (t.match(/-?\d*\.?\d+/g) || []).map(Number), T = (t, n) => {
|
|
79
|
+
if (n === "hex") return m(t);
|
|
80
|
+
const e = A(t);
|
|
81
|
+
return n === "rgb" || n === "rgba" ? e.length < 3 ? null : {
|
|
82
|
+
r: u(e[0], 0, 255),
|
|
83
|
+
g: u(e[1], 0, 255),
|
|
84
|
+
b: u(e[2], 0, 255),
|
|
85
|
+
a: e.length > 3 ? u(e[3], 0, 1) : 1
|
|
86
|
+
} : n === "hsl" ? e.length < 3 ? null : C({
|
|
87
|
+
h: u(e[0], 0, 360),
|
|
88
|
+
s: u(e[1], 0, 100) / 100,
|
|
89
|
+
l: u(e[2], 0, 100) / 100,
|
|
90
|
+
a: e.length > 3 ? u(e[3], 0, 1) : 1
|
|
91
|
+
}) : e.length < 3 ? null : F({
|
|
92
|
+
h: u(e[0], 0, 360),
|
|
93
|
+
s: u(e[1], 0, 100) / 100,
|
|
94
|
+
v: u(e[2], 0, 100) / 100,
|
|
95
|
+
a: e.length > 3 ? u(e[3], 0, 1) : 1
|
|
96
|
+
});
|
|
97
|
+
}, B = [
|
|
98
|
+
"#EF4444",
|
|
99
|
+
"#F97316",
|
|
100
|
+
"#FACC15",
|
|
101
|
+
"#4ADE80",
|
|
102
|
+
"#2DD4BF",
|
|
103
|
+
"#3B82F6",
|
|
104
|
+
"#6366F1",
|
|
105
|
+
"#EC4899",
|
|
106
|
+
"#F43F5E",
|
|
107
|
+
"#D946EF",
|
|
108
|
+
"#8B5CF6",
|
|
109
|
+
"#0EA5E9",
|
|
110
|
+
"#10B981",
|
|
111
|
+
"#84CC16"
|
|
112
|
+
];
|
|
113
|
+
export {
|
|
114
|
+
R as COLOR_FORMATS,
|
|
115
|
+
H as COLOR_FORMAT_LABELS,
|
|
116
|
+
B as DEFAULT_SAVED_COLORS,
|
|
117
|
+
O as FORMAT_HAS_ALPHA,
|
|
118
|
+
u as clamp,
|
|
119
|
+
S as formatColor,
|
|
120
|
+
C as hslaToRgba,
|
|
121
|
+
F as hsvaToRgba,
|
|
122
|
+
E as isValidColor,
|
|
123
|
+
m as parseColor,
|
|
124
|
+
T as parseColorInFormat,
|
|
125
|
+
x as rgbaToHex,
|
|
126
|
+
p as rgbaToHsla,
|
|
127
|
+
g as rgbaToHsva
|
|
128
|
+
};
|
|
129
|
+
//# sourceMappingURL=color.utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"color.utils.js","sources":["../../src/ColorInput/color.utils.ts"],"sourcesContent":["export interface RGBA {\r\n r: number; // 0..255\r\n g: number; // 0..255\r\n b: number; // 0..255\r\n a: number; // 0..1\r\n}\r\n\r\nexport interface HSVA {\r\n h: number; // 0..360\r\n s: number; // 0..1\r\n v: number; // 0..1\r\n a: number; // 0..1\r\n}\r\n\r\nexport const clamp = (value: number, min: number, max: number): number =>\r\n Math.min(max, Math.max(min, value));\r\n\r\nconst toHex2 = (value: number): string =>\r\n clamp(Math.round(value), 0, 255).toString(16).padStart(2, '0');\r\n\r\n/** Parses #rgb / #rrggbb / #rrggbbaa (with or without leading #) into RGBA. */\r\nexport const parseColor = (input: string): RGBA | null => {\r\n if (!input) return null;\r\n let hex = input.trim().replace(/^#/, '');\r\n\r\n if (/^[0-9a-f]{3}$/i.test(hex)) {\r\n hex = hex\r\n .split('')\r\n .map((c) => c + c)\r\n .join('');\r\n }\r\n\r\n if (/^[0-9a-f]{6}$/i.test(hex)) {\r\n return {\r\n r: parseInt(hex.slice(0, 2), 16),\r\n g: parseInt(hex.slice(2, 4), 16),\r\n b: parseInt(hex.slice(4, 6), 16),\r\n a: 1,\r\n };\r\n }\r\n\r\n if (/^[0-9a-f]{8}$/i.test(hex)) {\r\n return {\r\n r: parseInt(hex.slice(0, 2), 16),\r\n g: parseInt(hex.slice(2, 4), 16),\r\n b: parseInt(hex.slice(4, 6), 16),\r\n a: parseInt(hex.slice(6, 8), 16) / 255,\r\n };\r\n }\r\n\r\n return null;\r\n};\r\n\r\nexport const isValidColor = (input: string): boolean => parseColor(input) !== null;\r\n\r\n/** Formats RGBA to a hex string. Includes the alpha byte only when withAlpha and a<1. */\r\nexport const rgbaToHex = (rgba: RGBA, withAlpha = false): string => {\r\n const base = `#${toHex2(rgba.r)}${toHex2(rgba.g)}${toHex2(rgba.b)}`;\r\n if (withAlpha && rgba.a < 1) return `${base}${toHex2(rgba.a * 255)}`;\r\n return base;\r\n};\r\n\r\nexport const rgbaToHsva = ({ r, g, b, a }: RGBA): HSVA => {\r\n const rn = r / 255;\r\n const gn = g / 255;\r\n const bn = b / 255;\r\n const max = Math.max(rn, gn, bn);\r\n const min = Math.min(rn, gn, bn);\r\n const d = max - min;\r\n\r\n let h = 0;\r\n if (d !== 0) {\r\n if (max === rn) h = ((gn - bn) / d) % 6;\r\n else if (max === gn) h = (bn - rn) / d + 2;\r\n else h = (rn - gn) / d + 4;\r\n h *= 60;\r\n if (h < 0) h += 360;\r\n }\r\n\r\n const s = max === 0 ? 0 : d / max;\r\n return { h, s, v: max, a };\r\n};\r\n\r\nexport const hsvaToRgba = ({ h, s, v, a }: HSVA): RGBA => {\r\n const c = v * s;\r\n const x = c * (1 - Math.abs(((h / 60) % 2) - 1));\r\n const m = v - c;\r\n\r\n let rn = 0;\r\n let gn = 0;\r\n let bn = 0;\r\n if (h < 60) [rn, gn, bn] = [c, x, 0];\r\n else if (h < 120) [rn, gn, bn] = [x, c, 0];\r\n else if (h < 180) [rn, gn, bn] = [0, c, x];\r\n else if (h < 240) [rn, gn, bn] = [0, x, c];\r\n else if (h < 300) [rn, gn, bn] = [x, 0, c];\r\n else [rn, gn, bn] = [c, 0, x];\r\n\r\n return {\r\n r: Math.round((rn + m) * 255),\r\n g: Math.round((gn + m) * 255),\r\n b: Math.round((bn + m) * 255),\r\n a,\r\n };\r\n};\r\n\r\n/** Color string formats the picker can read/emit. */\r\nexport type ColorFormat = 'hex' | 'rgb' | 'rgba' | 'hsl' | 'hsb';\r\n\r\n/** All formats, in the order they appear in the format dropdown. */\r\nexport const COLOR_FORMATS: ColorFormat[] = ['hex', 'rgb', 'rgba', 'hsl', 'hsb'];\r\n\r\nexport const COLOR_FORMAT_LABELS: Record<ColorFormat, string> = {\r\n hex: 'Hex',\r\n rgb: 'RGB',\r\n rgba: 'RGBA',\r\n hsl: 'HSL',\r\n hsb: 'HSB',\r\n};\r\n\r\n/** Formats that carry an alpha channel — these enable the transparency slider. */\r\nexport const FORMAT_HAS_ALPHA: Record<ColorFormat, boolean> = {\r\n hex: false,\r\n rgb: false,\r\n rgba: true,\r\n hsl: false,\r\n hsb: false,\r\n};\r\n\r\nexport interface HSLA {\r\n h: number; // 0..360\r\n s: number; // 0..1\r\n l: number; // 0..1\r\n a: number; // 0..1\r\n}\r\n\r\nexport const rgbaToHsla = ({ r, g, b, a }: RGBA): HSLA => {\r\n const rn = r / 255;\r\n const gn = g / 255;\r\n const bn = b / 255;\r\n const max = Math.max(rn, gn, bn);\r\n const min = Math.min(rn, gn, bn);\r\n const d = max - min;\r\n\r\n let h = 0;\r\n if (d !== 0) {\r\n if (max === rn) h = ((gn - bn) / d) % 6;\r\n else if (max === gn) h = (bn - rn) / d + 2;\r\n else h = (rn - gn) / d + 4;\r\n h *= 60;\r\n if (h < 0) h += 360;\r\n }\r\n\r\n const l = (max + min) / 2;\r\n const s = d === 0 ? 0 : d / (1 - Math.abs(2 * l - 1));\r\n return { h, s, l, a };\r\n};\r\n\r\nexport const hslaToRgba = ({ h, s, l, a }: HSLA): RGBA => {\r\n const c = (1 - Math.abs(2 * l - 1)) * s;\r\n const x = c * (1 - Math.abs(((h / 60) % 2) - 1));\r\n const m = l - c / 2;\r\n\r\n let rn = 0;\r\n let gn = 0;\r\n let bn = 0;\r\n if (h < 60) [rn, gn, bn] = [c, x, 0];\r\n else if (h < 120) [rn, gn, bn] = [x, c, 0];\r\n else if (h < 180) [rn, gn, bn] = [0, c, x];\r\n else if (h < 240) [rn, gn, bn] = [0, x, c];\r\n else if (h < 300) [rn, gn, bn] = [x, 0, c];\r\n else [rn, gn, bn] = [c, 0, x];\r\n\r\n return {\r\n r: Math.round((rn + m) * 255),\r\n g: Math.round((gn + m) * 255),\r\n b: Math.round((bn + m) * 255),\r\n a,\r\n };\r\n};\r\n\r\nconst round = (n: number) => Math.round(n);\r\nconst pct = (n: number) => `${Math.round(n * 100)}%`;\r\n\r\n/** Renders an RGBA value as a string in the requested format. */\r\nexport const formatColor = (\r\n rgba: RGBA,\r\n format: ColorFormat,\r\n withAlpha = false,\r\n): string => {\r\n switch (format) {\r\n case 'rgba':\r\n return `${round(rgba.r)}, ${round(rgba.g)}, ${round(rgba.b)}, ${Number(rgba.a.toFixed(2))}`;\r\n case 'rgb':\r\n return withAlpha && rgba.a < 1\r\n ? `${round(rgba.r)}, ${round(rgba.g)}, ${round(rgba.b)}, ${Number(rgba.a.toFixed(2))}`\r\n : `${round(rgba.r)}, ${round(rgba.g)}, ${round(rgba.b)}`;\r\n case 'hsl': {\r\n const { h, s, l } = rgbaToHsla(rgba);\r\n return `${round(h)}, ${pct(s)}, ${pct(l)}`;\r\n }\r\n case 'hsb': {\r\n const { h, s, v } = rgbaToHsva(rgba);\r\n return `${round(h)}, ${pct(s)}, ${pct(v)}`;\r\n }\r\n case 'hex':\r\n default:\r\n return rgbaToHex(rgba, withAlpha).toUpperCase();\r\n }\r\n};\r\n\r\nconst numbers = (input: string): number[] =>\r\n (input.match(/-?\\d*\\.?\\d+/g) || []).map(Number);\r\n\r\n/** Parses a string written in the given format back into RGBA. */\r\nexport const parseColorInFormat = (\r\n input: string,\r\n format: ColorFormat,\r\n): RGBA | null => {\r\n if (format === 'hex') return parseColor(input);\r\n\r\n const n = numbers(input);\r\n if (format === 'rgb' || format === 'rgba') {\r\n if (n.length < 3) return null;\r\n return {\r\n r: clamp(n[0], 0, 255),\r\n g: clamp(n[1], 0, 255),\r\n b: clamp(n[2], 0, 255),\r\n a: n.length > 3 ? clamp(n[3], 0, 1) : 1,\r\n };\r\n }\r\n if (format === 'hsl') {\r\n if (n.length < 3) return null;\r\n return hslaToRgba({\r\n h: clamp(n[0], 0, 360),\r\n s: clamp(n[1], 0, 100) / 100,\r\n l: clamp(n[2], 0, 100) / 100,\r\n a: n.length > 3 ? clamp(n[3], 0, 1) : 1,\r\n });\r\n }\r\n // hsb\r\n if (n.length < 3) return null;\r\n return hsvaToRgba({\r\n h: clamp(n[0], 0, 360),\r\n s: clamp(n[1], 0, 100) / 100,\r\n v: clamp(n[2], 0, 100) / 100,\r\n a: n.length > 3 ? clamp(n[3], 0, 1) : 1,\r\n });\r\n};\r\n\r\n/** Default saved-colors palette mirroring the Figma design. */\r\nexport const DEFAULT_SAVED_COLORS: string[] = [\r\n '#EF4444',\r\n '#F97316',\r\n '#FACC15',\r\n '#4ADE80',\r\n '#2DD4BF',\r\n '#3B82F6',\r\n '#6366F1',\r\n '#EC4899',\r\n '#F43F5E',\r\n '#D946EF',\r\n '#8B5CF6',\r\n '#0EA5E9',\r\n '#10B981',\r\n '#84CC16',\r\n];\r\n"],"names":["clamp","value","min","max","toHex2","parseColor","input","hex","c","isValidColor","rgbaToHex","rgba","withAlpha","base","rgbaToHsva","r","g","b","a","rn","gn","bn","d","h","s","hsvaToRgba","v","x","m","COLOR_FORMATS","COLOR_FORMAT_LABELS","FORMAT_HAS_ALPHA","rgbaToHsla","l","hslaToRgba","round","n","pct","formatColor","format","numbers","parseColorInFormat","DEFAULT_SAVED_COLORS"],"mappings":"AAcO,MAAMA,IAAQ,CAACC,GAAeC,GAAaC,MAChD,KAAK,IAAIA,GAAK,KAAK,IAAID,GAAKD,CAAK,CAAC,GAE9BG,IAAS,CAACH,MACdD,EAAM,KAAK,MAAMC,CAAK,GAAG,GAAG,GAAG,EAAE,SAAS,EAAE,EAAE,SAAS,GAAG,GAAG,GAGlDI,IAAa,CAACC,MAA+B;AACxD,MAAI,CAACA,EAAO,QAAO;AACnB,MAAIC,IAAMD,EAAM,KAAA,EAAO,QAAQ,MAAM,EAAE;AASvC,SAPI,iBAAiB,KAAKC,CAAG,MAC3BA,IAAMA,EACH,MAAM,EAAE,EACR,IAAI,CAACC,MAAMA,IAAIA,CAAC,EAChB,KAAK,EAAE,IAGR,iBAAiB,KAAKD,CAAG,IACpB;AAAA,IACL,GAAG,SAASA,EAAI,MAAM,GAAG,CAAC,GAAG,EAAE;AAAA,IAC/B,GAAG,SAASA,EAAI,MAAM,GAAG,CAAC,GAAG,EAAE;AAAA,IAC/B,GAAG,SAASA,EAAI,MAAM,GAAG,CAAC,GAAG,EAAE;AAAA,IAC/B,GAAG;AAAA,EAAA,IAIH,iBAAiB,KAAKA,CAAG,IACpB;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CAAC,GAAG,GAAG,GAAG,IAAI;AAAA,IACzB,GAAGpC,EAAMoC,EAAE,CAAC,GAAG,GAAG,GAAG,IAAI;AAAA,IACzB,GAAGA,EAAE,SAAS,IAAIpC,EAAMoC,EAAE,CAAC,GAAG,GAAG,CAAC,IAAI;AAAA,EAAA,CACvC;AACH,GAGaM,IAAiC;AAAA,EAC5C;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/ColorInput/index.tsx"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,eAAe,CAAC;AAC9B,cAAc,kBAAkB,CAAC;AACjC,mBAAmB,oBAAoB,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { ColorInput as a } from "./ColorInput.js";
|
|
2
|
+
import { ColorPicker as O } from "./ColorPicker.js";
|
|
3
|
+
import { COLOR_FORMATS as C, COLOR_FORMAT_LABELS as T, DEFAULT_SAVED_COLORS as _, FORMAT_HAS_ALPHA as e, clamp as R, formatColor as s, hslaToRgba as L, hsvaToRgba as S, isValidColor as p, parseColor as m, parseColorInFormat as t, rgbaToHex as E, rgbaToHsla as F, rgbaToHsva as b } from "./color.utils.js";
|
|
4
|
+
import { DEFAULT_SAVED_COLORS_STORAGE_KEY as g, useSavedColors as x } from "./useSavedColors.js";
|
|
5
|
+
export {
|
|
6
|
+
C as COLOR_FORMATS,
|
|
7
|
+
T as COLOR_FORMAT_LABELS,
|
|
8
|
+
a as ColorInput,
|
|
9
|
+
O as ColorPicker,
|
|
10
|
+
_ as DEFAULT_SAVED_COLORS,
|
|
11
|
+
g as DEFAULT_SAVED_COLORS_STORAGE_KEY,
|
|
12
|
+
e as FORMAT_HAS_ALPHA,
|
|
13
|
+
R as clamp,
|
|
14
|
+
s as formatColor,
|
|
15
|
+
L as hslaToRgba,
|
|
16
|
+
S as hsvaToRgba,
|
|
17
|
+
p as isValidColor,
|
|
18
|
+
m as parseColor,
|
|
19
|
+
t as parseColorInFormat,
|
|
20
|
+
E as rgbaToHex,
|
|
21
|
+
F as rgbaToHsla,
|
|
22
|
+
b as rgbaToHsva,
|
|
23
|
+
x as useSavedColors
|
|
24
|
+
};
|
|
25
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export declare const DEFAULT_SAVED_COLORS_STORAGE_KEY = "op-color-input-saved-colors";
|
|
2
|
+
/**
|
|
3
|
+
* Saved-colors palette persisted to localStorage (empty by default). Used by
|
|
4
|
+
* `ColorInput` when the consumer doesn't pass a controlled
|
|
5
|
+
* `savedColors`/`onAddSavedColor` pair.
|
|
6
|
+
*/
|
|
7
|
+
export declare const useSavedColors: (storageKey?: string) => {
|
|
8
|
+
savedColors: string[];
|
|
9
|
+
addColor: (hex: string) => void;
|
|
10
|
+
removeColor: (hex: string) => void;
|
|
11
|
+
setSavedColors: (next: string[]) => void;
|
|
12
|
+
};
|
|
13
|
+
//# sourceMappingURL=useSavedColors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useSavedColors.d.ts","sourceRoot":"","sources":["../../src/ColorInput/useSavedColors.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,gCAAgC,gCAAgC,CAAC;AAuB9E;;;;GAIG;AACH,eAAO,MAAM,cAAc,GACzB,aAAY,MAAyC;;oBAiB7C,MAAM;uBAaN,MAAM;2BArBL,MAAM,EAAE;CAiClB,CAAC"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { useState as C, useEffect as S, useCallback as i } from "react";
|
|
2
|
+
const m = "op-color-input-saved-colors", d = (o) => {
|
|
3
|
+
if (typeof window > "u") return [];
|
|
4
|
+
try {
|
|
5
|
+
const e = window.localStorage.getItem(o);
|
|
6
|
+
if (!e) return [];
|
|
7
|
+
const t = JSON.parse(e);
|
|
8
|
+
return Array.isArray(t) ? t : [];
|
|
9
|
+
} catch {
|
|
10
|
+
return [];
|
|
11
|
+
}
|
|
12
|
+
}, a = (o, e) => {
|
|
13
|
+
if (!(typeof window > "u"))
|
|
14
|
+
try {
|
|
15
|
+
window.localStorage.setItem(o, JSON.stringify(e));
|
|
16
|
+
} catch {
|
|
17
|
+
}
|
|
18
|
+
}, L = (o = m) => {
|
|
19
|
+
const [e, t] = C(() => d(o));
|
|
20
|
+
S(() => {
|
|
21
|
+
t(d(o));
|
|
22
|
+
}, [o]);
|
|
23
|
+
const u = i(
|
|
24
|
+
(r) => {
|
|
25
|
+
t(r), a(o, r);
|
|
26
|
+
},
|
|
27
|
+
[o]
|
|
28
|
+
), w = i(
|
|
29
|
+
(r) => {
|
|
30
|
+
t((n) => {
|
|
31
|
+
const c = r.toLowerCase();
|
|
32
|
+
if (n.some((l) => l.toLowerCase() === c)) return n;
|
|
33
|
+
const s = [...n, r];
|
|
34
|
+
return a(o, s), s;
|
|
35
|
+
});
|
|
36
|
+
},
|
|
37
|
+
[o]
|
|
38
|
+
), f = i(
|
|
39
|
+
(r) => {
|
|
40
|
+
t((n) => {
|
|
41
|
+
const c = r.toLowerCase(), s = n.filter((l) => l.toLowerCase() !== c);
|
|
42
|
+
return a(o, s), s;
|
|
43
|
+
});
|
|
44
|
+
},
|
|
45
|
+
[o]
|
|
46
|
+
);
|
|
47
|
+
return { savedColors: e, addColor: w, removeColor: f, setSavedColors: u };
|
|
48
|
+
};
|
|
49
|
+
export {
|
|
50
|
+
m as DEFAULT_SAVED_COLORS_STORAGE_KEY,
|
|
51
|
+
L as useSavedColors
|
|
52
|
+
};
|
|
53
|
+
//# sourceMappingURL=useSavedColors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useSavedColors.js","sources":["../../src/ColorInput/useSavedColors.ts"],"sourcesContent":["import { useCallback, useEffect, useState } from 'react';\n\nexport const DEFAULT_SAVED_COLORS_STORAGE_KEY = 'op-color-input-saved-colors';\n\nconst read = (key: string): string[] => {\n if (typeof window === 'undefined') return [];\n try {\n const raw = window.localStorage.getItem(key);\n if (!raw) return [];\n const parsed = JSON.parse(raw);\n return Array.isArray(parsed) ? parsed : [];\n } catch {\n return [];\n }\n};\n\nconst write = (key: string, next: string[]) => {\n if (typeof window === 'undefined') return;\n try {\n window.localStorage.setItem(key, JSON.stringify(next));\n } catch {\n /* ignore quota / privacy-mode failures */\n }\n};\n\n/**\n * Saved-colors palette persisted to localStorage (empty by default). Used by\n * `ColorInput` when the consumer doesn't pass a controlled\n * `savedColors`/`onAddSavedColor` pair.\n */\nexport const useSavedColors = (\n storageKey: string = DEFAULT_SAVED_COLORS_STORAGE_KEY,\n) => {\n const [colors, setColors] = useState<string[]>(() => read(storageKey));\n\n useEffect(() => {\n setColors(read(storageKey));\n }, [storageKey]);\n\n const setSavedColors = useCallback(\n (next: string[]) => {\n setColors(next);\n write(storageKey, next);\n },\n [storageKey],\n );\n\n const addColor = useCallback(\n (hex: string) => {\n setColors((prev) => {\n const lower = hex.toLowerCase();\n if (prev.some((c) => c.toLowerCase() === lower)) return prev;\n const next = [...prev, hex];\n write(storageKey, next);\n return next;\n });\n },\n [storageKey],\n );\n\n const removeColor = useCallback(\n (hex: string) => {\n setColors((prev) => {\n const lower = hex.toLowerCase();\n const next = prev.filter((c) => c.toLowerCase() !== lower);\n write(storageKey, next);\n return next;\n });\n },\n [storageKey],\n );\n\n return { savedColors: colors, addColor, removeColor, setSavedColors };\n};\n"],"names":["DEFAULT_SAVED_COLORS_STORAGE_KEY","read","key","raw","parsed","write","next","useSavedColors","storageKey","colors","setColors","useState","useEffect","setSavedColors","useCallback","addColor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platformdev/utils";
|
|
3
3
|
import { ComboboxRenderOptions as G } from "./ComboboxRenderOptions.js";
|
|
4
4
|
import { useRef as H, useEffect as J } from "react";
|
|
5
5
|
import { useInView as T } from "react-intersection-observer";
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
6
|
+
import { Command as _, CommandInput as q, CommandList as z, CommandGroup as B, CommandEmpty as w, CommandItem as K } from "../Command/Command.js";
|
|
7
|
+
import { LoadingMask as Q } from "../LoadingMask/LoadingMask.js";
|
|
8
|
+
import { PopoverContent as U } from "../Popover/Popover.js";
|
|
9
9
|
import { Skeleton as W } from "../Skeleton/Skeleton.js";
|
|
10
|
-
const X = (t) => /* @__PURE__ */ e("div", { className: "flex w-full flex-col gap-0", children: Array.from({ length: t.length || 2 }).map((c,
|
|
10
|
+
const X = (t) => /* @__PURE__ */ e("div", { className: "flex w-full flex-col gap-0", children: Array.from({ length: t.length || 2 }).map((c, m) => /* @__PURE__ */ e(
|
|
11
11
|
"div",
|
|
12
12
|
{
|
|
13
13
|
className: "flex items-center min-h-10 w-full px-4",
|
|
14
14
|
children: /* @__PURE__ */ e("div", { className: s("flex items-center w-full", t.className), children: /* @__PURE__ */ e(W, { className: "h-4 w-full" }) })
|
|
15
15
|
},
|
|
16
|
-
|
|
16
|
+
m
|
|
17
17
|
)) }), ae = (t) => {
|
|
18
18
|
const {
|
|
19
19
|
open: c,
|
|
20
|
-
type:
|
|
20
|
+
type: m,
|
|
21
21
|
search: u,
|
|
22
|
-
onSearch:
|
|
23
|
-
hasNext:
|
|
24
|
-
loading:
|
|
22
|
+
onSearch: y,
|
|
23
|
+
hasNext: C,
|
|
24
|
+
loading: n,
|
|
25
25
|
loadingMore: A,
|
|
26
|
-
isEmptyList:
|
|
26
|
+
isEmptyList: d,
|
|
27
27
|
onSelect: L,
|
|
28
28
|
options: x = [],
|
|
29
29
|
callbackStateParams: o,
|
|
30
30
|
value: S,
|
|
31
31
|
searchLabel: F = "Type to search...",
|
|
32
32
|
emptyLabel: N = "No options",
|
|
33
|
-
emptyAction:
|
|
33
|
+
emptyAction: l,
|
|
34
34
|
commandInputAction: p,
|
|
35
|
-
listHeadAction:
|
|
35
|
+
listHeadAction: r,
|
|
36
36
|
listFooterAction: a,
|
|
37
37
|
slotProps: f = {},
|
|
38
38
|
defaultNodeDisabled: I,
|
|
39
39
|
defaultNodeMatched: M,
|
|
40
40
|
defaultNodeMuted: R,
|
|
41
|
-
defaultNodeInteractive:
|
|
42
|
-
forcePointerSelect:
|
|
41
|
+
defaultNodeInteractive: P,
|
|
42
|
+
forcePointerSelect: k,
|
|
43
43
|
popoverContainer: E,
|
|
44
44
|
renderList: h,
|
|
45
45
|
onLoadMore: V
|
|
@@ -51,43 +51,46 @@ const X = (t) => /* @__PURE__ */ e("div", { className: "flex w-full flex-col gap
|
|
|
51
51
|
return J(() => {
|
|
52
52
|
c && g && V?.();
|
|
53
53
|
}, [g, c]), /* @__PURE__ */ e(
|
|
54
|
-
|
|
54
|
+
U,
|
|
55
55
|
{
|
|
56
56
|
className: s(
|
|
57
|
-
"w-(--radix-popper-anchor-width) max-w-none p-2"
|
|
57
|
+
"w-(--radix-popper-anchor-width) max-w-none p-2",
|
|
58
|
+
"flex flex-col",
|
|
59
|
+
"max-h-(--radix-popover-content-available-height)"
|
|
58
60
|
),
|
|
59
61
|
align: "start",
|
|
62
|
+
collisionPadding: 8,
|
|
60
63
|
container: E,
|
|
61
|
-
children: /* @__PURE__ */ i(
|
|
64
|
+
children: /* @__PURE__ */ i(_, { shouldFilter: !1, className: "flex min-h-0 flex-1 flex-col", children: [
|
|
62
65
|
/* @__PURE__ */ e(
|
|
63
|
-
|
|
66
|
+
q,
|
|
64
67
|
{
|
|
65
68
|
placeholder: F,
|
|
66
69
|
value: u,
|
|
67
|
-
onValueChange:
|
|
70
|
+
onValueChange: y
|
|
68
71
|
}
|
|
69
72
|
),
|
|
70
73
|
typeof p == "function" ? p(o) : p,
|
|
71
|
-
/* @__PURE__ */ e(
|
|
72
|
-
|
|
74
|
+
/* @__PURE__ */ e(z, { ref: b, className: "min-h-0 flex-1", children: /* @__PURE__ */ i(
|
|
75
|
+
B,
|
|
73
76
|
{
|
|
74
77
|
className: s(
|
|
75
78
|
!x.length && "p-0 shadow-none",
|
|
76
79
|
"px-0 py-2"
|
|
77
80
|
),
|
|
78
81
|
children: [
|
|
79
|
-
|
|
80
|
-
!
|
|
82
|
+
n && /* @__PURE__ */ e("div", { className: "pt-2 pb-0", children: /* @__PURE__ */ e(Q, {}) }),
|
|
83
|
+
!n && d && /* @__PURE__ */ e(v, { children: l ? /* @__PURE__ */ i(w, { className: "flex flex-col gap-3 py-5 px-3 items-center", children: [
|
|
81
84
|
/* @__PURE__ */ e("span", { children: N }),
|
|
82
|
-
typeof
|
|
83
|
-
] }) : /* @__PURE__ */ e(
|
|
84
|
-
!
|
|
85
|
-
|
|
86
|
-
|
|
85
|
+
typeof l == "function" ? l(o) : l
|
|
86
|
+
] }) : /* @__PURE__ */ e(w, { children: N }) }),
|
|
87
|
+
!n && !d && /* @__PURE__ */ i(v, { children: [
|
|
88
|
+
r && /* @__PURE__ */ e(
|
|
89
|
+
K,
|
|
87
90
|
{
|
|
88
91
|
asChild: !0,
|
|
89
92
|
className: "w-full",
|
|
90
|
-
children: typeof
|
|
93
|
+
children: typeof r == "function" ? r(o) : r
|
|
91
94
|
},
|
|
92
95
|
"combobox-list-head-action"
|
|
93
96
|
),
|
|
@@ -95,7 +98,7 @@ const X = (t) => /* @__PURE__ */ e("div", { className: "flex w-full flex-col gap
|
|
|
95
98
|
!h && /* @__PURE__ */ e(
|
|
96
99
|
G,
|
|
97
100
|
{
|
|
98
|
-
type:
|
|
101
|
+
type: m,
|
|
99
102
|
search: u,
|
|
100
103
|
value: S,
|
|
101
104
|
options: x,
|
|
@@ -103,17 +106,17 @@ const X = (t) => /* @__PURE__ */ e("div", { className: "flex w-full flex-col gap
|
|
|
103
106
|
defaultNodeDisabled: I,
|
|
104
107
|
defaultNodeMatched: M,
|
|
105
108
|
defaultNodeMuted: R,
|
|
106
|
-
defaultNodeInteractive:
|
|
107
|
-
forcePointerSelect:
|
|
109
|
+
defaultNodeInteractive: P,
|
|
110
|
+
forcePointerSelect: k
|
|
108
111
|
}
|
|
109
112
|
),
|
|
110
|
-
|
|
113
|
+
C && /* @__PURE__ */ e("div", { ref: j, className: "h-px w-full" }),
|
|
111
114
|
A && /* @__PURE__ */ e(X, {})
|
|
112
115
|
] })
|
|
113
116
|
]
|
|
114
117
|
}
|
|
115
118
|
) }),
|
|
116
|
-
!
|
|
119
|
+
!n && a && !d && /* @__PURE__ */ e(
|
|
117
120
|
"div",
|
|
118
121
|
{
|
|
119
122
|
"data-slot": "command-footer-wrapper",
|