UNPKG

@sanity/color-input

Version:
115 lines (114 loc) 3.04 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: !0 }); var sanity = require("sanity"), jsxRuntime = require("react/jsx-runtime"), react = require("react"); const ColorInput = react.lazy(() => Promise.resolve().then(function() { return require("./_chunks-cjs/ColorInput.js"); })), round = (val = 1) => Math.round(val * 100), colorTypeName = "color", color = sanity.defineType({ name: colorTypeName, type: "object", title: "Color", components: { input: ColorInput }, fields: [ { title: "Hex", name: "hex", type: "string" }, { title: "Alpha", name: "alpha", type: "number" }, { title: "Hue Saturation Lightness", name: "hsl", type: "hslaColor" }, { title: "Hue Saturation Value", name: "hsv", type: "hsvaColor" }, { title: "Red Green Blue (rgb)", name: "rgb", type: "rgbaColor" } ], preview: { select: { title: "hex", alpha: "alpha", hex: "hex", hsl: "hsl" }, prepare({ title, hex, hsl, alpha }) { let subtitle = hex || "No color set"; return hsl && (subtitle = `H:${round(hsl.h)} S:${round(hsl.s)} L:${round(hsl.l)} A:${round(alpha)}`), { title, subtitle, media: () => /* @__PURE__ */ jsxRuntime.jsx( "div", { style: { backgroundColor: hex ?? "#000", opacity: alpha ?? 1, position: "absolute", height: "100%", width: "100%", top: "0", left: "0" } } ) }; } } }), hslaColor = sanity.defineType({ title: "Hue Saturation Lightness", name: "hslaColor", type: "object", fields: [ { name: "h", type: "number", title: "Hue" }, { name: "s", type: "number", title: "Saturation" }, { name: "l", type: "number", title: "Lightness" }, { name: "a", type: "number", title: "Alpha" } ] }), hsvaColor = sanity.defineType({ title: "Hue Saturation Value", name: "hsvaColor", type: "object", fields: [ { name: "h", type: "number", title: "Hue" }, { name: "s", type: "number", title: "Saturation" }, { name: "v", type: "number", title: "Value" }, { name: "a", type: "number", title: "Alpha" } ] }), rgbaColor = sanity.defineType({ title: "Red Green Blue (rgb)", name: "rgbaColor", type: "object", fields: [ { name: "r", type: "number", title: "Red" }, { name: "g", type: "number", title: "Green" }, { name: "b", type: "number", title: "Blue" }, { name: "a", type: "number", title: "Alpha" } ] }), colorInput = sanity.definePlugin({ name: "@sanity/color-input", schema: { types: [hslaColor, hsvaColor, rgbaColor, color] } }); exports.ColorInput = ColorInput; exports.color = color; exports.colorInput = colorInput; exports.hslaColor = hslaColor; exports.hsvaColor = hsvaColor; exports.rgbaColor = rgbaColor; //# sourceMappingURL=index.js.map