"use strict"; var __create = Object.create; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __getProtoOf = Object.getPrototypeOf; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( // If the importer is in node compatibility mode or this is not an ESM // file that has been converted to a CommonJS file using a Babel- // compatible transform (i.e. "__esModule" has not been set), then set // "default" to the CommonJS "module.exports" for node compatibility. isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod )); var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); // src/index.ts var src_exports = {}; __export(src_exports, { createPalette: () => createPalette, initializeState: () => initializeState }); module.exports = __toCommonJS(src_exports); // src/domain/constants.ts var frameworksList = [ "tailwind", "bootstrap5", "css", "mantine" ]; var saturationRange = { min: 0, max: 1 }; // src/domain/palette.ts var import_chroma_js = __toESM(require("chroma-js"), 1); function hslFromHex(hexCode) { const [hue, sat, lum] = (0, import_chroma_js.default)(hexCode).hsl(); return { hue: Math.round(hue), saturation: sat, luminosity: lum }; } function hexFromHsl(hsl) { return import_chroma_js.default.hsl(hsl.hue, hsl.saturation, hsl.luminosity).hex(); } // src/domain/math.ts function _subtractHues(minuend, subtrahend) { return (minuend - subtrahend + 360) % 360; } function _addHues(augend, addend) { const result = (augend + addend) % 360; return result; } function calculateClockwiseMidpoint(firstHue, secondHue) { const result = _addHues(firstHue, _subtractHues(secondHue, firstHue) / 2); return result; } // src/domain/logic.ts function modifyColorAttribute(originalAttributeValue, minAttributeValue, maxAttributeValue, modFactor) { let newValue; if (modFactor === 0) { newValue = originalAttributeValue; } else if (modFactor < 0) { newValue = originalAttributeValue - (originalAttributeValue - minAttributeValue) * Math.abs(modFactor); } else if (modFactor > 0) { newValue = originalAttributeValue + (maxAttributeValue - originalAttributeValue) * modFactor; } else { throw new Error(`invalid modification factor ${modFactor}`); } return newValue; } function modifyHex(hexCode, minHue, maxHue, modFactor) { const hsl = hslFromHex(hexCode); const newHue = modifyColorAttribute( hsl.hue, minHue, maxHue, modFactor.hueMod ); const newSaturation = modifyColorAttribute( hsl.saturation, saturationRange.min, saturationRange.max, modFactor.satMod ); const newHex = hexFromHsl({ hue: newHue, saturation: newSaturation, luminosity: hsl.luminosity }); return newHex; } function findHueRange(centralHue, previousHue, nextHue) { const min = calculateClockwiseMidpoint(previousHue, centralHue); const max = calculateClockwiseMidpoint(centralHue, nextHue); return { min, max }; } // src/domain/transformations.ts function flatten(palette2) { return palette2.flatMap( (color) => color.shades.map((shade) => ({ colorName: color.colorName, hexCode: shade.hexCode, weight: shade.weight })) ); } function getDistinctWeights(data) { const weights = new Set(data.map((item) => item.weight)); return Array.from(weights); } function addHue(data) { const addedHues = data.map((x) => { const hue = hslFromHex(x.hexCode).hue; return { ...x, hue }; }); return addedHues; } function filterByWeight(data, weight) { const filtered = data.filter((x) => x.weight === weight); return filtered; } function validateAllWeightsAreEqual(data) { const weights = new Set(data.map((x) => x.weight)); if (weights.size > 1) { throw new Error("weights are not equal"); } } function sortByHue(data) { validateAllWeightsAreEqual(data); const sorted = data.sort((a, b) => a.hue - b.hue); return sorted; } function validateIsSortedByHue(data) { data.forEach((item, i) => { if (i > 0 && item.hue < data[i - 1].hue) { throw new Error("array is not sorted by hue ascending"); } }); } function addAdjancentHues(data) { validateIsSortedByHue(data); return data.map((item, index, array) => { const prevIndex = index === 0 ? array.length - 1 : index - 1; const nextIndex = index === array.length - 1 ? 0 : index + 1; return { ...item, prevHue: array[prevIndex].hue, nextHue: array[nextIndex].hue }; }); } function addHueRanges(data) { return data.map((x) => { const hueRange = findHueRange(x.hue, x.prevHue, x.nextHue); return { ...x, minHue: hueRange.min, maxHue: hueRange.max }; }); } function addModifiedHex(data, modFactor) { return data.map((x) => { const modifiedHex = modifyHex(x.hexCode, x.minHue, x.maxHue, modFactor); return { ...x, modifiedHex }; }); } function transformToColorScale(data) { const resultMap = {}; data.forEach((item) => { if (!resultMap[item.colorName]) { resultMap[item.colorName] = []; } resultMap[item.colorName].push({ weight: item.weight, hexCode: item.modifiedHex }); }); return Object.keys(resultMap).map((colorName) => ({ colorName, shades: resultMap[colorName].sort((a, b) => a.weight - b.weight) })); } // src/domain/api.ts var domainModule = { modifyPallete: (palette2, modFactor) => { const flattened = flatten(palette2); const weights = getDistinctWeights(flattened); const withAdjancentHues = weights.flatMap((weight) => { const filteredByWeight = filterByWeight(flattened, weight); const addedHues = addHue(filteredByWeight); const sortedByHue = sortByHue(addedHues); const addedAdjancentHues = addAdjancentHues(sortedByHue); return addedAdjancentHues; }); const withHueRanges = addHueRanges(withAdjancentHues); const withModifiedHex = addModifiedHex(withHueRanges, modFactor); const newPalette = transformToColorScale(withModifiedHex); return newPalette; } }; // src/frameworks/tailwind3/data.ts var palette = [ { colorName: "slate", shades: [ { weight: 50, hexCode: "#f8fafc" }, { weight: 100, hexCode: "#f1f5f9" }, { weight: 200, hexCode: "#e2e8f0" }, { weight: 300, hexCode: "#cbd5e1" }, { weight: 400, hexCode: "#94a3b8" }, { weight: 500, hexCode: "#64748b" }, { weight: 600, hexCode: "#475569" }, { weight: 700, hexCode: "#334155" }, { weight: 800, hexCode: "#1e293b" }, { weight: 900, hexCode: "#0f172a" }, { weight: 950, hexCode: "#020617" } ] }, { colorName: "gray", shades: [ { weight: 50, hexCode: "#f9fafb" }, { weight: 100, hexCode: "#f3f4f6" }, { weight: 200, hexCode: "#e5e7eb" }, { weight: 300, hexCode: "#d1d5db" }, { weight: 400, hexCode: "#9ca3af" }, { weight: 500, hexCode: "#6b7280" }, { weight: 600, hexCode: "#4b5563" }, { weight: 700, hexCode: "#374151" }, { weight: 800, hexCode: "#1f2937" }, { weight: 900, hexCode: "#111827" }, { weight: 950, hexCode: "#030712" } ] }, { colorName: "zinc", shades: [ { weight: 50, hexCode: "#fafafa" }, { weight: 100, hexCode: "#f4f4f5" }, { weight: 200, hexCode: "#e4e4e7" }, { weight: 300, hexCode: "#d4d4d8" }, { weight: 400, hexCode: "#a1a1aa" }, { weight: 500, hexCode: "#71717a" }, { weight: 600, hexCode: "#52525b" }, { weight: 700, hexCode: "#3f3f46" }, { weight: 800, hexCode: "#27272a" }, { weight: 900, hexCode: "#18181b" }, { weight: 950, hexCode: "#09090b" } ] }, { colorName: "neutral", shades: [ { weight: 50, hexCode: "#fafafa" }, { weight: 100, hexCode: "#f5f5f5" }, { weight: 200, hexCode: "#e5e5e5" }, { weight: 300, hexCode: "#d4d4d4" }, { weight: 400, hexCode: "#a3a3a3" }, { weight: 500, hexCode: "#737373" }, { weight: 600, hexCode: "#525252" }, { weight: 700, hexCode: "#404040" }, { weight: 800, hexCode: "#262626" }, { weight: 900, hexCode: "#171717" }, { weight: 950, hexCode: "#0a0a0a" } ] }, { colorName: "stone", shades: [ { weight: 50, hexCode: "#fafaf9" }, { weight: 100, hexCode: "#f5f5f4" }, { weight: 200, hexCode: "#e7e5e4" }, { weight: 300, hexCode: "#d6d3d1" }, { weight: 400, hexCode: "#a8a29e" }, { weight: 500, hexCode: "#78716c" }, { weight: 600, hexCode: "#57534e" }, { weight: 700, hexCode: "#44403c" }, { weight: 800, hexCode: "#292524" }, { weight: 900, hexCode: "#1c1917" }, { weight: 950, hexCode: "#0c0a09" } ] }, { colorName: "red", shades: [ { weight: 50, hexCode: "#fef2f2" }, { weight: 100, hexCode: "#fee2e2" }, { weight: 200, hexCode: "#fecaca" }, { weight: 300, hexCode: "#fca5a5" }, { weight: 400, hexCode: "#f87171" }, { weight: 500, hexCode: "#ef4444" }, { weight: 600, hexCode: "#dc2626" }, { weight: 700, hexCode: "#b91c1c" }, { weight: 800, hexCode: "#991b1b" }, { weight: 900, hexCode: "#7f1d1d" }, { weight: 950, hexCode: "#450a0a" } ] }, { colorName: "orange", shades: [ { weight: 50, hexCode: "#fff7ed" }, { weight: 100, hexCode: "#ffedd5" }, { weight: 200, hexCode: "#fed7aa" }, { weight: 300, hexCode: "#fdba74" }, { weight: 400, hexCode: "#fb923c" }, { weight: 500, hexCode: "#f97316" }, { weight: 600, hexCode: "#ea580c" }, { weight: 700, hexCode: "#c2410c" }, { weight: 800, hexCode: "#9a3412" }, { weight: 900, hexCode: "#7c2d12" }, { weight: 950, hexCode: "#431407" } ] }, { colorName: "amber", shades: [ { weight: 50, hexCode: "#fffbeb" }, { weight: 100, hexCode: "#fef3c7" }, { weight: 200, hexCode: "#fde68a" }, { weight: 300, hexCode: "#fcd34d" }, { weight: 400, hexCode: "#fbbf24" }, { weight: 500, hexCode: "#f59e0b" }, { weight: 600, hexCode: "#d97706" }, { weight: 700, hexCode: "#b45309" }, { weight: 800, hexCode: "#92400e" }, { weight: 900, hexCode: "#78350f" }, { weight: 950, hexCode: "#451a03" } ] }, { colorName: "yellow", shades: [ { weight: 50, hexCode: "#fefce8" }, { weight: 100, hexCode: "#fef9c3" }, { weight: 200, hexCode: "#fef08a" }, { weight: 300, hexCode: "#fde047" }, { weight: 400, hexCode: "#facc15" }, { weight: 500, hexCode: "#eab308" }, { weight: 600, hexCode: "#ca8a04" }, { weight: 700, hexCode: "#a16207" }, { weight: 800, hexCode: "#854d0e" }, { weight: 900, hexCode: "#713f12" }, { weight: 950, hexCode: "#422006" } ] }, { colorName: "lime", shades: [ { weight: 50, hexCode: "#f7fee7" }, { weight: 100, hexCode: "#ecfccb" }, { weight: 200, hexCode: "#d9f99d" }, { weight: 300, hexCode: "#bef264" }, { weight: 400, hexCode: "#a3e635" }, { weight: 500, hexCode: "#84cc16" }, { weight: 600, hexCode: "#65a30d" }, { weight: 700, hexCode: "#4d7c0f" }, { weight: 800, hexCode: "#3f6212" }, { weight: 900, hexCode: "#365314" }, { weight: 950, hexCode: "#1a2e05" } ] }, { colorName: "green", shades: [ { weight: 50, hexCode: "#f0fdf4" }, { weight: 100, hexCode: "#dcfce7" }, { weight: 200, hexCode: "#bbf7d0" }, { weight: 300, hexCode: "#86efac" }, { weight: 400, hexCode: "#4ade80" }, { weight: 500, hexCode: "#22c55e" }, { weight: 600, hexCode: "#16a34a" }, { weight: 700, hexCode: "#15803d" }, { weight: 800, hexCode: "#166534" }, { weight: 900, hexCode: "#14532d" }, { weight: 950, hexCode: "#052e16" } ] }, { colorName: "emerald", shades: [ { weight: 50, hexCode: "#ecfdf5" }, { weight: 100, hexCode: "#d1fae5" }, { weight: 200, hexCode: "#a7f3d0" }, { weight: 300, hexCode: "#6ee7b7" }, { weight: 400, hexCode: "#34d399" }, { weight: 500, hexCode: "#10b981" }, { weight: 600, hexCode: "#059669" }, { weight: 700, hexCode: "#047857" }, { weight: 800, hexCode: "#065f46" }, { weight: 900, hexCode: "#064e3b" }, { weight: 950, hexCode: "#022c22" } ] }, { colorName: "teal", shades: [ { weight: 50, hexCode: "#f0fdfa" }, { weight: 100, hexCode: "#ccfbf1" }, { weight: 200, hexCode: "#99f6e4" }, { weight: 300, hexCode: "#5eead4" }, { weight: 400, hexCode: "#2dd4bf" }, { weight: 500, hexCode: "#14b8a6" }, { weight: 600, hexCode: "#0d9488" }, { weight: 700, hexCode: "#0f766e" }, { weight: 800, hexCode: "#115e59" }, { weight: 900, hexCode: "#134e4a" }, { weight: 950, hexCode: "#042f2e" } ] }, { colorName: "cyan", shades: [ { weight: 50, hexCode: "#ecfeff" }, { weight: 100, hexCode: "#cffafe" }, { weight: 200, hexCode: "#a5f3fc" }, { weight: 300, hexCode: "#67e8f9" }, { weight: 400, hexCode: "#22d3ee" }, { weight: 500, hexCode: "#06b6d4" }, { weight: 600, hexCode: "#0891b2" }, { weight: 700, hexCode: "#0e7490" }, { weight: 800, hexCode: "#155e75" }, { weight: 900, hexCode: "#164e63" }, { weight: 950, hexCode: "#083344" } ] }, { colorName: "sky", shades: [ { weight: 50, hexCode: "#f0f9ff" }, { weight: 100, hexCode: "#e0f2fe" }, { weight: 200, hexCode: "#bae6fd" }, { weight: 300, hexCode: "#7dd3fc" }, { weight: 400, hexCode: "#38bdf8" }, { weight: 500, hexCode: "#0ea5e9" }, { weight: 600, hexCode: "#0284c7" }, { weight: 700, hexCode: "#0369a1" }, { weight: 800, hexCode: "#075985" }, { weight: 900, hexCode: "#0c4a6e" }, { weight: 950, hexCode: "#082f49" } ] }, { colorName: "blue", shades: [ { weight: 50, hexCode: "#eff6ff" }, { weight: 100, hexCode: "#dbeafe" }, { weight: 200, hexCode: "#bfdbfe" }, { weight: 300, hexCode: "#93c5fd" }, { weight: 400, hexCode: "#60a5fa" }, { weight: 500, hexCode: "#3b82f6" }, { weight: 600, hexCode: "#2563eb" }, { weight: 700, hexCode: "#1d4ed8" }, { weight: 800, hexCode: "#1e40af" }, { weight: 900, hexCode: "#1e3a8a" }, { weight: 950, hexCode: "#172554" } ] }, { colorName: "indigo", shades: [ { weight: 50, hexCode: "#eef2ff" }, { weight: 100, hexCode: "#e0e7ff" }, { weight: 200, hexCode: "#c7d2fe" }, { weight: 300, hexCode: "#a5b4fc" }, { weight: 400, hexCode: "#818cf8" }, { weight: 500, hexCode: "#6366f1" }, { weight: 600, hexCode: "#4f46e5" }, { weight: 700, hexCode: "#4338ca" }, { weight: 800, hexCode: "#3730a3" }, { weight: 900, hexCode: "#312e81" }, { weight: 950, hexCode: "#1e1b4b" } ] }, { colorName: "violet", shades: [ { weight: 50, hexCode: "#f5f3ff" }, { weight: 100, hexCode: "#ede9fe" }, { weight: 200, hexCode: "#ddd6fe" }, { weight: 300, hexCode: "#c4b5fd" }, { weight: 400, hexCode: "#a78bfa" }, { weight: 500, hexCode: "#8b5cf6" }, { weight: 600, hexCode: "#7c3aed" }, { weight: 700, hexCode: "#6d28d9" }, { weight: 800, hexCode: "#5b21b6" }, { weight: 900, hexCode: "#4c1d95" }, { weight: 950, hexCode: "#2e1065" } ] }, { colorName: "purple", shades: [ { weight: 50, hexCode: "#faf5ff" }, { weight: 100, hexCode: "#f3e8ff" }, { weight: 200, hexCode: "#e9d5ff" }, { weight: 300, hexCode: "#d8b4fe" }, { weight: 400, hexCode: "#c084fc" }, { weight: 500, hexCode: "#a855f7" }, { weight: 600, hexCode: "#9333ea" }, { weight: 700, hexCode: "#7e22ce" }, { weight: 800, hexCode: "#6b21a8" }, { weight: 900, hexCode: "#581c87" }, { weight: 950, hexCode: "#3b0764" } ] }, { colorName: "fuchsia", shades: [ { weight: 50, hexCode: "#fdf4ff" }, { weight: 100, hexCode: "#fae8ff" }, { weight: 200, hexCode: "#f5d0fe" }, { weight: 300, hexCode: "#f0abfc" }, { weight: 400, hexCode: "#e879f9" }, { weight: 500, hexCode: "#d946ef" }, { weight: 600, hexCode: "#c026d3" }, { weight: 700, hexCode: "#a21caf" }, { weight: 800, hexCode: "#86198f" }, { weight: 900, hexCode: "#701a75" }, { weight: 950, hexCode: "#4a044e" } ] }, { colorName: "pink", shades: [ { weight: 50, hexCode: "#fdf2f8" }, { weight: 100, hexCode: "#fce7f3" }, { weight: 200, hexCode: "#fbcfe8" }, { weight: 300, hexCode: "#f9a8d4" }, { weight: 400, hexCode: "#f472b6" }, { weight: 500, hexCode: "#ec4899" }, { weight: 600, hexCode: "#db2777" }, { weight: 700, hexCode: "#be185d" }, { weight: 800, hexCode: "#9d174d" }, { weight: 900, hexCode: "#831843" }, { weight: 950, hexCode: "#500724" } ] }, { colorName: "rose", shades: [ { weight: 50, hexCode: "#fff1f2" }, { weight: 100, hexCode: "#ffe4e6" }, { weight: 200, hexCode: "#fecdd3" }, { weight: 300, hexCode: "#fda4af" }, { weight: 400, hexCode: "#fb7185" }, { weight: 500, hexCode: "#f43f5e" }, { weight: 600, hexCode: "#e11d48" }, { weight: 700, hexCode: "#be123c" }, { weight: 800, hexCode: "#9f1239" }, { weight: 900, hexCode: "#881337" }, { weight: 950, hexCode: "#4c0519" } ] } ]; // src/frameworks/tailwind3/generator.ts function generateShadeValue(shade) { return `${shade.weight}: '${shade.hexCode}', `; } function generateShadesObject(shades) { const openingBrace = "{\n"; const closingBrace = "},\n"; const indent = " "; const shadeValuesArray = shades.map((x) => indent + generateShadeValue(x)); const shadeValuesString = shadeValuesArray.join(""); return openingBrace + shadeValuesString + closingBrace; } function generateColorObject(color) { const colorKey = `'${color.colorName}'`; const shadesObject = generateShadesObject(color.shades); return `${colorKey}: ${shadesObject}`; } function generateConfigCode(palette2) { const colorObjectsArray = palette2.map((x) => generateColorObject(x)); const colorObjectsString = colorObjectsArray.join(""); return colorObjectsString; } // src/frameworks/api.ts function generateConfigurationCode(framework, palette2) { switch (framework) { case "bootstrap5": throw new Error("not implemented"); case "tailwind": return generateConfigCode(palette2); case "css": throw new Error("not implemented"); case "mantine": throw new Error("not implemented"); default: throw new Error(`framework ${framework} is not implemented`); } } function getOriginalPalette(framework) { switch (framework) { case "bootstrap5": throw new Error("not implemented"); case "tailwind": return palette; case "css": throw new Error("not implemented"); case "mantine": throw new Error("not implemented"); default: throw new Error(`framework ${framework} is not implemented`); } } // src/appService/api.ts function createPalette(input) { const originalPalette = getOriginalPalette(input.framework); const modFactor = { hueMod: input.hueMod, satMod: input.saturationMod }; const newPalette = domainModule.modifyPallete(originalPalette, modFactor); const code = generateConfigurationCode(input.framework, newPalette); const output = { code, palette: newPalette }; return output; } function initializeState() { const initialFramework = "tailwind"; const initialSaturationMod = 0; const initialHueMod = 0; const inputDto = { framework: initialFramework, saturationMod: initialSaturationMod, hueMod: initialHueMod }; const pallete = createPalette(inputDto); const initialDto = { frameworksList: [...frameworksList], saturationMod: initialSaturationMod, hueMod: initialHueMod, code: pallete.code, paletteData: pallete.palette, framework: initialFramework }; return initialDto; } // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { createPalette, initializeState });