@aviala-design/color 0.3.0 → 0.4.1
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/README.md +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.mjs +549 -315
- package/dist/linear.d.ts +9 -1
- package/dist/linear.d.ts.map +1 -1
- package/dist/theme-blend.d.ts +300 -26
- package/dist/theme-blend.d.ts.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
<!-- 当前版本: 0.
|
|
1
|
+
<!-- 当前版本: 0.4.1 | 最后同步: 2026/3/8 16:36:55 -->
|
|
2
2
|
# Aviala Design Color
|
|
3
3
|
|
|
4
4
|
  
|
package/dist/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { default as generate } from './generate.js';
|
|
|
2
2
|
import { getRgbStr } from './utils.js';
|
|
3
3
|
import { extractColorFromImage, extractColorFromFile } from './image-color.js';
|
|
4
4
|
import { generateLinear, generateGrayLinear, generateMonochromeLinear, generateLinearHSL } from './linear.js';
|
|
5
|
-
import { rgbToHct, hctToRgb, blendInHct, harmonizeColor, generateThemeVariants, blendUIColors, generateThemePalette, generateControlColors, generateSemanticColors, generateThemeColors, generateInterfaceColorSystem } from './theme-blend.js';
|
|
5
|
+
import { rgbToHct, hctToRgb, blendInHct, harmonizeColor, generateThemeVariants, blendUIColors, generateThemePalette, generateControlColors, generateNeutralColors, generateSemanticColors, generateThemeColors, generateInterfaceColorSystem, colorDifference, adjustTone, adjustChroma, adjustHue, rotateHue, getComplementary, getTriadic, getSplitComplementary, getAnalogous } from './theme-blend.js';
|
|
6
6
|
/**
|
|
7
7
|
* 获取所有预设颜色的色板
|
|
8
8
|
*
|
|
@@ -80,5 +80,5 @@ export const colorList: {
|
|
|
80
80
|
pinkpurple: string;
|
|
81
81
|
magenta: string;
|
|
82
82
|
};
|
|
83
|
-
export { generate, getRgbStr, extractColorFromImage, extractColorFromFile, generateLinear, generateGrayLinear, generateMonochromeLinear, generateLinearHSL, rgbToHct, hctToRgb, blendInHct, harmonizeColor, generateThemeVariants, blendUIColors, generateThemePalette, generateControlColors, generateSemanticColors, generateThemeColors, generateInterfaceColorSystem };
|
|
83
|
+
export { generate, getRgbStr, extractColorFromImage, extractColorFromFile, generateLinear, generateGrayLinear, generateMonochromeLinear, generateLinearHSL, rgbToHct, hctToRgb, blendInHct, harmonizeColor, generateThemeVariants, blendUIColors, generateThemePalette, generateControlColors, generateNeutralColors, generateSemanticColors, generateThemeColors, generateInterfaceColorSystem, colorDifference, adjustTone, adjustChroma, adjustHue, rotateHue, getComplementary, getTriadic, getSplitComplementary, getAnalogous };
|
|
84
84
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.js"],"names":[],"mappings":"AAyEA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,mCAtBa;IAAC,CAAC,GAAG,EAAE,MAAM,GAAG;QAAC,KAAK,EAAE,MAAM,EAAE,CAAC;QAAC,IAAI,EAAE,MAAM,EAAE,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAC,CAAA;CAAC,CA4D/E;AA7GD;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,wBAvBU;IACL,GAAG,EAAE,MAAM,CAAC;IACZ,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,MAAM,CAAA;CAChB,CAuBF;qBAvEmB,eAAe;0BACV,YAAY;sCACsB,kBAAkB;qCAAlB,kBAAkB;+BACkB,aAAa;mCAAb,aAAa;yCAAb,aAAa;kCAAb,aAAa;yBAwBtG,kBAAkB;yBAAlB,kBAAkB;2BAAlB,kBAAkB;+BAAlB,kBAAkB;sCAAlB,kBAAkB;8BAAlB,kBAAkB;qCAAlB,kBAAkB;sCAAlB,kBAAkB;sCAAlB,kBAAkB;uCAAlB,kBAAkB;oCAAlB,kBAAkB;6CAAlB,kBAAkB;gCAAlB,kBAAkB;2BAAlB,kBAAkB;6BAAlB,kBAAkB;0BAAlB,kBAAkB;0BAAlB,kBAAkB;iCAAlB,kBAAkB;2BAAlB,kBAAkB;sCAAlB,kBAAkB;6BAAlB,kBAAkB"}
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(d,w){typeof exports=="object"&&typeof module<"u"?w(exports,require("color")):typeof define=="function"&&define.amd?define(["exports","color"],w):(d=typeof globalThis<"u"?globalThis:d||self,w(d.AvialaColor={},d.Color))})(this,function(d,w){"use strict";function O(t){return w(t).rgb().round().color.join(",")}const G=["hex","rgb","hsl"];function j(t){return!t||!G.includes(t)?"hex":t}function F(t,n){const i=j(n);return i==="hex"?t[i]().toLowerCase():t[i]().round().string()}function D(t,n,i){const r=w(t),o=r.hue(),a=r.saturationv(),e=r.value(),s=(y=>y>=60&&y<=240?2.5:y>=0&&y<60||y>300&&y<=360?1.5:2)(o),l=100,f=9,u=100,h=30;function m(y,p){let x;return o>=60&&o<=240?x=y?o-s*p:o+s*p:x=y?o+s*p:o-s*p,x<0?x+=360:x>=360&&(x-=360),Math.round(x)}function M(y,p){let x;if(y)x=a<=f?a:a-(a-f)/5.5*Math.pow(p,1.05);else{const q=Math.min(l,a+30);x=a+(q-a)/4.2*Math.pow(p,.95)}return Math.max(0,Math.min(100,x))}function b(y,p){return y?Math.min(u,e+(u-e)/5.2*Math.pow(p,.9)):e<=h?e:Math.max(h,e-(e-h)/4.2*Math.pow(p,1.05))}const g=n<6,E=g?6-n:n-6,S=n===6?r:w({h:m(g,E),s:M(g,E),v:b(g,E)});return F(S,i)}function A(t,n,i){const r=w(D(t,10-n+1,"hex")),o=w(t),a=o.hue(),e=o.saturationv();function c(m){if(m<6)return l+(6-m)*u;if(m===6){if(a>=0&&a<50)return e-15;if(a>=50&&a<191)return e-20;if(a>=191&&a<=360)return e-15}return l-f*(m-6)}const l=w({h:o.hue(),s:c(6),v:o.value()}).saturationv(),f=Math.ceil((l-9)/4),u=Math.ceil((100-l)/5),h=w({h:r.hue(),s:c(n),v:r.value()});return F(h,i)}function T(t,n={}){const{dark:i,list:r,index:o=6,format:a="hex"}=n;if(r){const e=[],c=i?A:D;for(let s=1;s<=10;s++)e.push(c(t,s,a));return e}return i?A(t,o,a):D(t,o,a)}async function P(t){try{const n=await V(t),i=N(n);return U(i)}catch(n){throw console.error("提取图片颜色失败:",n),n}}async function V(t){return new Promise((n,i)=>{try{if(typeof document>"u"){i(new Error("图像颜色提取功能仅在浏览器环境中可用"));return}const r=document.createElement("canvas"),o=r.getContext("2d");if(!o){i(new Error("无法获取canvas 2d context"));return}const a=Math.min(t.width,100),e=Math.min(t.height,100),c=Math.min(a/t.width,e/t.height);r.width=t.width*c,r.height=t.height*c,o.drawImage(t,0,0,r.width,r.height);const s=o.getImageData(0,0,r.width,r.height);n(s)}catch(r){i(r)}})}function N(t){const n=t.data,i=new Map;for(let o=0;o<n.length;o+=4){const a=n[o],e=n[o+1],c=n[o+2];if(n[o+3]<128)continue;const l=Math.round(a/16)*16,f=Math.round(e/16)*16,u=Math.round(c/16)*16,h=`${l},${f},${u}`;i.has(h)?i.set(h,i.get(h)+1):i.set(h,1)}const r=[];return i.forEach((o,a)=>{const[e,c,s]=a.split(",").map(Number);r.push({r:e,g:c,b:s,count:o})}),r}function U(t){t.sort((o,a)=>a.count-o.count);const n=t.filter(o=>{const{r:a,g:e,b:c}=o,s=Math.max(a,e,c),l=Math.min(a,e,c),f=s-l,u=s===0?0:f/s,h=s/255;return u>.15&&h>.2&&h<.8}),i=n.length>0?n[0]:t[0];return w({r:i.r,g:i.g,b:i.b}).hex()}function K(t){return new Promise((n,i)=>{if(typeof FileReader>"u"||typeof Image>"u"){i(new Error("文件读取功能仅在浏览器环境中可用"));return}if(!t.type.startsWith("image/")){i(new Error("请选择图片文件"));return}const r=new FileReader;r.onload=async o=>{var a;try{const e=new Image;e.onload=async()=>{try{const s=await P(e);n(s)}catch(s){i(s)}},e.onerror=()=>i(new Error("图片加载失败"));const c=(a=o.target)==null?void 0:a.result;typeof c=="string"?e.src=c:i(new Error("无法读取图片数据"))}catch(e){i(e)}},r.onerror=()=>i(new Error("文件读取失败")),r.readAsDataURL(t)})}function C(t,n,i={}){const{steps:r=10,format:o="hex",includeEnds:a=!0}=i;if(r<2)throw new Error("步数必须至少为2");const e=w(t),c=w(n),s=[],l=a?r:r+2,f=1/(l-1);for(let u=0;u<l;u++){const h=u*f,m=Math.round(e.red()+(c.red()-e.red())*h),M=Math.round(e.green()+(c.green()-e.green())*h),b=Math.round(e.blue()+(c.blue()-e.blue())*h),g=w({r:m,g:M,b});!a&&(u===0||u===l-1)||s.push(F(g,o))}return s}function W(t={}){const{startGray:n="#ffffff",endGray:i="#000000",steps:r=10,format:o="hex"}=t;return C(n,i,{steps:r,format:o,includeEnds:!0})}function z(t,n={}){const{steps:i=10,format:r="hex",lightnessRange:o=80,minLightness:a=null,maxLightness:e=null}=n,c=w(t);let s,l;if(a!==null&&e!==null){if(a>e)throw new Error("minLightness 不能大于 maxLightness");s=Math.max(0,Math.min(100,e)),l=Math.max(0,Math.min(100,a))}else{const h=c.lightness();s=Math.min(95,h+o/2),l=Math.max(5,h-o/2)}const f=w({h:c.hue(),s:c.saturationl(),l:s}),u=w({h:c.hue(),s:c.saturationl(),l});return C(f.hex(),u.hex(),{steps:i,format:r,includeEnds:!0})}function J(t,n,i={}){const{steps:r=10,format:o="hex",includeEnds:a=!0}=i;if(r<2)throw new Error("步数必须至少为2");const e=w(t),c=w(n),s=[],l=a?r:r+2,f=1/(l-1);let u=e.hue()||0,h=c.hue()||0;const m=h-u;Math.abs(m)>180&&(m>0?u+=360:h+=360);const M=e.saturationl(),b=c.saturationl(),g=e.lightness(),E=c.lightness();for(let S=0;S<l;S++){const y=S*f;let p=u+(h-u)*y;const x=M+(b-M)*y,q=g+(E-g)*y;p=p%360,p<0&&(p+=360);const tt=w({h:p,s:x,l:q});!a&&(S===0||S===l-1)||s.push(F(tt,o))}return s}function R(t){if(!t||typeof t!="string")throw new Error("Invalid RGB color: must be a string");let n=t.replace("#","");if(n.length===8&&(n=n.substring(0,6)),!/^[0-9A-Fa-f]{6}$/.test(n))throw new Error("Invalid RGB color format: must be #rrggbb or rrggbb");const i=parseInt(n.slice(0,2),16)/255,r=parseInt(n.slice(2,4),16)/255,o=parseInt(n.slice(4,6),16)/255,a=Math.max(i,r,o),e=Math.min(i,r,o),c=a-e;let s=0;c!==0&&(a===i?s=(r-o)/c%6:a===r?s=(o-i)/c+2:s=(i-r)/c+4),s=Math.round(s*60),s<0&&(s+=360);const l=Math.round((.299*i+.587*r+.114*o)*100),f=(a+e)/2;let u=0;c!==0&&f!==0&&f!==1&&(u=c/(1-Math.abs(2*f-1)));let h=0;return l>0&&l<100&&(h=Math.round(u*Math.min(l,100-l))),{h:s,c:Math.max(0,h),t:Math.max(0,Math.min(100,l))}}function L(t,n={}){if(!t||typeof t!="object"||t.h===void 0||t.c===void 0||t.t===void 0)throw new Error("Invalid HCT color: must be an object with h, c, t properties");const{h:i,c:r,t:o}=t,{maxChroma:a=200}=n,e=(i%360+360)%360,c=Math.max(0,Math.min(a,r)),s=Math.max(0,Math.min(100,o)),l=s/100;let f=0;if(s>0&&s<100&&c>0){const S=Math.min(s,100-s);f=S>0?c/S:0}const u=(1-Math.abs(2*l-1))*Math.min(1,f),h=u*(1-Math.abs(e/60%2-1)),m=l-u/2;let M,b,g;e>=0&&e<60?[M,b,g]=[u,h,0]:e>=60&&e<120?[M,b,g]=[h,u,0]:e>=120&&e<180?[M,b,g]=[0,u,h]:e>=180&&e<240?[M,b,g]=[0,h,u]:e>=240&&e<300?[M,b,g]=[h,0,u]:[M,b,g]=[u,0,h];const E=S=>{const y=Math.max(0,Math.min(1,S+m)),p=Math.round(y*255).toString(16);return p.length===1?"0"+p:p};return`#${E(M)}${E(b)}${E(g)}`}function H(t,n,i=.5){if(!t||!n)throw new Error("Both colors are required for blending");const r=Math.max(0,Math.min(1,i)),o=R(t),a=R(n);let e=o.h,c=a.h,s=c-e;Math.abs(s)>180&&(s>0?e+=360:c+=360,s=c-e);const l=(e+s*r)%360,f=o.c+(a.c-o.c)*r,u=o.t+(a.t-o.t)*r;return L({h:l<0?l+360:l,c:Math.max(0,Math.round(f)),t:Math.max(0,Math.min(100,Math.round(u)))})}function Q(t,n,i=.15){if(!t||!n)throw new Error("Both theme color and target color are required");const r=Math.max(0,Math.min(1,i)),o=R(t),a=R(n);let e=a.h,c=o.h,s=c-e;Math.abs(s)>180&&(s>0?e+=360:c+=360,s=c-e);const l=(e+s*r)%360;return L({h:l<0?l+360:l,c:a.c,t:a.t})}function X(t,n){if(!t)throw new Error("Theme color is required");const i=R(t);let r;if(Array.isArray(n)?r=n:n&&n.tones&&Array.isArray(n.tones)?r=n.tones:r=[10,20,30,40,50,60,70,80,90],!Array.isArray(r)||r.length===0)throw new Error("Tone steps must be a non-empty array");const o=r.filter(a=>typeof a=="number"&&a>=0&&a<=100);if(o.length===0)throw new Error("No valid tone values found (must be numbers between 0-100)");return o.map(a=>L({h:i.h,c:i.c,t:a}))}function k(t,n,i=.2){if(!t)throw new Error("Theme color is required");if(!n||typeof n!="object")throw new Error("UI colors must be an object");const r=Math.max(0,Math.min(1,i)),o={};for(const[a,e]of Object.entries(n))try{o[a]=H(t,e,r)}catch(c){console.warn(`Failed to blend color for key "${a}": ${c.message}`),o[a]=e}return o}function I(t,n={}){if(!t)throw new Error("Theme color is required");const{baseGray:i="#989898",blendRatio:r=.08,isDark:o=!1,steps:a=12,lightnessRange:e=85,minLightness:c=null,maxLightness:s=null}=n,l=Math.max(0,Math.min(1,r)),f=Math.max(2,Math.min(100,Math.round(a))),u=H(i,t,l),h={steps:f,format:"hex"};if(c!==null&&s!==null)h.minLightness=c,h.maxLightness=s;else{const g=Math.max(20,Math.min(95,e));h.lightnessRange=g}const m=z(u,h),M=o?m.reverse():m,b={};return M.forEach((g,E)=>{b[`gray-${E+1}`]=g}),b}function B(t,n={}){if(!t)throw new Error("Theme color is required");const{semanticColors:i={success:"#52c41a",warning:"#faad14",error:"#ff4d4f",info:"#1890ff"},blendRatio:r=0,isDark:o=!1}=n;if(!i||typeof i!="object")throw new Error("Semantic colors must be an object");const a=Math.max(0,Math.min(1,r)),e={};return Object.entries(i).forEach(([c,s])=>{if(!s||typeof s!="string"){console.warn(`Invalid color for semantic color "${c}": ${s}`);return}try{const l={},f=R(s);(o?[90,80,70,60,50,40,30,25,20,15]:[15,25,35,45,55,65,75,85,90,95]).forEach((h,m)=>{const M={h:f.h,c:f.c,t:h},b=H(L(M),t,a);l[`${c}-${m+1}`]=b}),Object.assign(e,l)}catch(l){console.warn(`Failed to generate variants for semantic color "${c}": ${l.message}`)}}),e}function $(t,n={}){if(!t)throw new Error("Theme color is required");const{isDark:i=!1}=n,r=R(t),o={};return(i?[90,80,70,60,50,40,30,25,20,15]:[15,25,35,45,55,65,75,85,90,95]).forEach((e,c)=>{const s={h:r.h,c:r.c,t:e};o[`theme-${c+1}`]=L(s)}),o}function Y(t,n={}){if(!t)throw new Error("Theme color is required");const{baseGray:i="#666666",isDark:r=!1,semanticColors:o,controlBlendRatio:a=.08,semanticBlendRatio:e=.12,controlSteps:c=12,controlLightnessRange:s=85,controlMinLightness:l=null,controlMaxLightness:f=null}=n,u=Math.max(0,Math.min(1,a)),h=Math.max(0,Math.min(1,e)),m={baseGray:i,blendRatio:u,isDark:r,steps:c};return l!==null&&f!==null?(m.minLightness=l,m.maxLightness=f):m.lightnessRange=s,{controls:I(t,m),semantic:B(t,{semanticColors:o,blendRatio:h,isDark:r}),theme:$(t,{isDark:r})}}function Z(t,n={}){if(!t)throw new Error("Theme color is required");const{semanticColors:i={success:"#52c41a",warning:"#faad14",error:"#ff4d4f",info:"#1890ff"},uiColors:r={background:"#ffffff",surface:"#fafafa",border:"#d9d9d9",disabled:"#f5f5f5"},harmonizeRatio:o=.15,blendRatio:a=.12,isDark:e=!1}=n,c=Math.max(0,Math.min(1,o)),s=Math.max(0,Math.min(1,a)),l=$(t,{isDark:e}),f=I(t,{blendRatio:s*.5,isDark:e}),u=B(t,{semanticColors:i,blendRatio:c,isDark:e}),h={};return Object.entries(i).forEach(([M])=>{h[M]={};for(let b=1;b<=10;b++){const g=`${M}-${b}`;u[g]&&(h[M][b]=u[g])}}),{theme:l,controls:f,semantic:h,ui:k(t,r,s)}}const v={red:"#F53F3F",orangered:"#F77234",orange:"#FF7D00",gold:"#F7BA1E",yellow:"#FADC19",lime:"#9FDB1D",green:"#00B42A",cyan:"#14C9C9",blue:"#3491FA",arcoblue:"#165DFF",purple:"#722ED1",pinkpurple:"#D91AD9",magenta:"#F5319D"};function _(){const t={};return Object.keys(v).forEach(n=>{t[n]={},t[n].light=T(v[n],{list:!0}),t[n].dark=T(v[n],{list:!0,dark:!0}),t[n].primary=v[n]}),t.gray={},t.gray.light=["#f7f8fa","#f2f3f5","#e5e6eb","#c9cdd4","#a9aeb8","#86909c","#6b7785","#4e5969","#272e3b","#1d2129"],t.gray.dark=["#17171a","#2e2e30","#484849","#5f5f60","#78787a","#929293","#ababac","#c5c5c5","#dfdfdf","#f6f6f6"],t.gray.primary=t.gray.light[6],t}d.blendInHct=H,d.blendUIColors=k,d.colorList=v,d.extractColorFromFile=K,d.extractColorFromImage=P,d.generate=T,d.generateControlColors=I,d.generateGrayLinear=W,d.generateInterfaceColorSystem=Y,d.generateLinear=C,d.generateLinearHSL=J,d.generateMonochromeLinear=z,d.generateSemanticColors=B,d.generateThemeColors=$,d.generateThemePalette=Z,d.generateThemeVariants=X,d.getPresetColors=_,d.getRgbStr=O,d.harmonizeColor=Q,d.hctToRgb=L,d.rgbToHct=R,Object.defineProperty(d,Symbol.toStringTag,{value:"Module"})});
|
|
1
|
+
(function(d,b){typeof exports=="object"&&typeof module<"u"?b(exports,require("color")):typeof define=="function"&&define.amd?define(["exports","color"],b):(d=typeof globalThis<"u"?globalThis:d||self,b(d.AvialaColor={},d.Color))})(this,function(d,b){"use strict";function J(t){return b(t).rgb().round().color.join(",")}const Q=["hex","rgb","hsl"];function X(t){return!t||!Q.includes(t)?"hex":t}function C(t,e){const r=X(e);return r==="hex"?t[r]().toLowerCase():t[r]().round().string()}function $(t,e,r){const n=b(t),a=n.hue(),o=n.saturationv(),s=n.value(),i=(p=>p>=60&&p<=240?2.5:p>=0&&p<60||p>300&&p<=360?1.5:2)(a),h=100,f=9,u=100,l=30;function m(p,y){let S;return a>=60&&a<=240?S=p?a-i*y:a+i*y:S=p?a+i*y:a-i*y,S<0?S+=360:S>=360&&(S-=360),Math.round(S)}function g(p,y){let S;if(p)S=o<=f?o:o-(o-f)/5.5*Math.pow(y,1.05);else{const H=Math.min(h,o+30);S=o+(H-o)/4.2*Math.pow(y,.95)}return Math.max(0,Math.min(100,S))}function w(p,y){return p?Math.min(u,s+(u-s)/5.2*Math.pow(y,.9)):s<=l?s:Math.max(l,s-(s-l)/4.2*Math.pow(y,1.05))}const M=e<6,L=M?6-e:e-6,x=e===6?n:b({h:m(M,L),s:g(M,L),v:w(M,L)});return C(x,r)}function G(t,e,r){const n=b($(t,10-e+1,"hex")),a=b(t),o=a.hue(),s=a.saturationv();function c(m){if(m<6)return h+(6-m)*u;if(m===6){if(o>=0&&o<50)return s-15;if(o>=50&&o<191)return s-20;if(o>=191&&o<=360)return s-15}return h-f*(m-6)}const h=b({h:a.hue(),s:c(6),v:a.value()}).saturationv(),f=Math.ceil((h-9)/4),u=Math.ceil((100-h)/5),l=b({h:n.hue(),s:c(e),v:n.value()});return C(l,r)}function q(t,e={}){const{dark:r,list:n,index:a=6,format:o="hex"}=e;if(n){const s=[],c=r?G:$;for(let i=1;i<=10;i++)s.push(c(t,i,o));return s}return r?G(t,a,o):$(t,a,o)}async function N(t){try{const e=await Y(t),r=Z(e);return _(r)}catch(e){throw console.error("提取图片颜色失败:",e),e}}async function Y(t){return new Promise((e,r)=>{try{if(typeof document>"u"){r(new Error("图像颜色提取功能仅在浏览器环境中可用"));return}const n=document.createElement("canvas"),a=n.getContext("2d");if(!a){r(new Error("无法获取canvas 2d context"));return}const o=Math.min(t.width,100),s=Math.min(t.height,100),c=Math.min(o/t.width,s/t.height);n.width=t.width*c,n.height=t.height*c,a.drawImage(t,0,0,n.width,n.height);const i=a.getImageData(0,0,n.width,n.height);e(i)}catch(n){r(n)}})}function Z(t){const e=t.data,r=new Map;for(let a=0;a<e.length;a+=4){const o=e[a],s=e[a+1],c=e[a+2];if(e[a+3]<128)continue;const h=Math.round(o/16)*16,f=Math.round(s/16)*16,u=Math.round(c/16)*16,l=`${h},${f},${u}`;r.has(l)?r.set(l,r.get(l)+1):r.set(l,1)}const n=[];return r.forEach((a,o)=>{const[s,c,i]=o.split(",").map(Number);n.push({r:s,g:c,b:i,count:a})}),n}function _(t){t.sort((a,o)=>o.count-a.count);const e=t.filter(a=>{const{r:o,g:s,b:c}=a,i=Math.max(o,s,c),h=Math.min(o,s,c),f=i-h,u=i===0?0:f/i,l=i/255;return u>.15&&l>.2&&l<.8}),r=e.length>0?e[0]:t[0];return b({r:r.r,g:r.g,b:r.b}).hex()}function tt(t){return new Promise((e,r)=>{if(typeof FileReader>"u"||typeof Image>"u"){r(new Error("文件读取功能仅在浏览器环境中可用"));return}if(!t.type.startsWith("image/")){r(new Error("请选择图片文件"));return}const n=new FileReader;n.onload=async a=>{var o;try{const s=new Image;s.onload=async()=>{try{const i=await N(s);e(i)}catch(i){r(i)}},s.onerror=()=>r(new Error("图片加载失败"));const c=(o=a.target)==null?void 0:o.result;typeof c=="string"?s.src=c:r(new Error("无法读取图片数据"))}catch(s){r(s)}},n.onerror=()=>r(new Error("文件读取失败")),n.readAsDataURL(t)})}function P(t,e,r={}){const{steps:n=10,format:a="hex",includeEnds:o=!0}=r;if(n<2)throw new Error("步数必须至少为2");const s=b(t),c=b(e),i=[],h=o?n:n+2,f=1/(h-1);for(let u=0;u<h;u++){const l=u*f,m=Math.round(s.red()+(c.red()-s.red())*l),g=Math.round(s.green()+(c.green()-s.green())*l),w=Math.round(s.blue()+(c.blue()-s.blue())*l),M=b({r:m,g,b:w});!o&&(u===0||u===h-1)||i.push(C(M,a))}return i}function et(t={}){const{startGray:e="#ffffff",endGray:r="#000000",steps:n=10,format:a="hex"}=t;return P(e,r,{steps:n,format:a,includeEnds:!0})}function T(t,e={}){const{steps:r=10,format:n="hex",lightnessRange:a=80,minLightness:o=null,maxLightness:s=null,preserveChroma:c=!1}=e,i=b(t);let h,f;if(o!==null&&s!==null){if(o>s)throw new Error("minLightness 不能大于 maxLightness");h=Math.max(0,Math.min(100,s)),f=Math.max(0,Math.min(100,o))}else{const m=i.lightness();h=Math.min(95,m+a/2),f=Math.max(5,m-a/2)}if(c)return nt(i,h,f,r,n);const u=b({h:i.hue(),s:i.saturationl(),l:h}),l=b({h:i.hue(),s:i.saturationl(),l:f});return P(u.hex(),l.hex(),{steps:r,format:n,includeEnds:!0})}function nt(t,e,r,n,a){const o=t.a(),s=t.b(),c=Math.sqrt(o*o+s*s),i=Math.atan2(s,o),h=[],f=(e-r)/(n-1);for(let u=0;u<n;u++){const l=e-f*u;let m=c;if(l>85){const p=Math.max(0,(100-l)/15);m=c*p}else if(l<15){const p=Math.max(0,l/15);m=c*p}const g=m*Math.cos(i),w=m*Math.sin(i);let M=b.lab(l,g,w),L=M.rgb().array(),x=m;for(;(L[0]<0||L[0]>255||L[1]<0||L[1]>255||L[2]<0||L[2]>255)&&x>0;){x-=1;const p=x*Math.cos(i),y=x*Math.sin(i);M=b.lab(l,p,y),L=M.rgb().array()}h.push(C(M,a))}return h}function rt(t,e,r={}){const{steps:n=10,format:a="hex",includeEnds:o=!0}=r;if(n<2)throw new Error("步数必须至少为2");const s=b(t),c=b(e),i=[],h=o?n:n+2,f=1/(h-1);let u=s.hue()||0,l=c.hue()||0;const m=l-u;Math.abs(m)>180&&(m>0?u+=360:l+=360);const g=s.saturationl(),w=c.saturationl(),M=s.lightness(),L=c.lightness();for(let x=0;x<h;x++){const p=x*f;let y=u+(l-u)*p;const S=g+(w-g)*p,H=M+(L-M)*p;y=y%360,y<0&&(y+=360);const k=b({h:y,s:S,l:H});!o&&(x===0||x===h-1)||i.push(C(k,a))}return i}function R(t){if(!t||typeof t!="string")throw new Error("Invalid RGB color: must be a string");let e;try{e=b(t)}catch{throw new Error("Invalid RGB color format")}const r=e.l(),n=e.a(),a=e.b();let o=Math.atan2(a,n)*(180/Math.PI);o<0&&(o+=360);const s=Math.sqrt(n*n+a*a);return{h:o,c:s,t:r}}function v(t,e={}){if(!t||typeof t!="object"||t.h===void 0||t.c===void 0||t.t===void 0)throw new Error("Invalid HCT color: must be an object with h, c, t properties");const{gamutMapping:r="reduce-chroma"}=e;let{h:n,c:a,t:o}=t;n=(n%360+360)%360,a=Math.max(0,a),o=Math.max(0,Math.min(100,o));const s=n*(Math.PI/180),c=a*Math.cos(s),i=a*Math.sin(s);try{let h=b.lab(o,c,i);if(r==="reduce-chroma"){let g=a,w=h.rgb().array();for(;(w[0]<0||w[0]>255||w[1]<0||w[1]>255||w[2]<0||w[2]>255)&&g>0;){g-=1;const M=g*Math.cos(s),L=g*Math.sin(s);h=b.lab(o,M,L),w=h.rgb().array()}}const f=h.rgb().array(),u=Math.max(0,Math.min(255,Math.round(f[0]))),l=Math.max(0,Math.min(255,Math.round(f[1]))),m=Math.max(0,Math.min(255,Math.round(f[2])));return`#${u.toString(16).padStart(2,"0")}${l.toString(16).padStart(2,"0")}${m.toString(16).padStart(2,"0")}`}catch{return b.lab(o,c,i).hex().toLowerCase()}}function B(t,e,r=.5,n={}){if(!t||!e)throw new Error("Both colors are required for blending");const{mode:a="lab"}=n,o=Math.max(0,Math.min(1,r));return a==="lab"?at(t,e,o):a==="hue-only"?V(t,e,o):ot(t,e,o)}function at(t,e,r){const n=b(t),a=b(e),o=n.l(),s=n.a(),c=n.b(),i=a.l(),h=a.a(),f=a.b(),u=o+(i-o)*r,l=s+(h-s)*r,m=c+(f-c)*r;return b.lab(u,l,m).hex().toLowerCase()}function ot(t,e,r){const n=R(t),a=R(e),o=U(n.h,a.h,r),s=n.c+(a.c-n.c)*r,c=n.t+(a.t-n.t)*r;return v({h:o,c:Math.max(0,s),t:Math.max(0,Math.min(100,c))})}function V(t,e,r){const n=R(t),a=R(e),o=U(n.h,a.h,r);return v({h:o,c:n.c,t:n.t})}function U(t,e,r){let n=e-t;n>180?n-=360:n<-180&&(n+=360);let a=t+n*r;return a<0&&(a+=360),a>=360&&(a-=360),a}function st(t,e){const r=b(t),n=b(e),a=r.l(),o=r.a(),s=r.b(),c=n.l(),i=n.a(),h=n.b();return Math.sqrt(Math.pow(c-a,2)+Math.pow(i-o,2)+Math.pow(h-s,2))}function it(t,e){const r=R(t);return v({h:r.h,c:r.c,t:Math.max(0,Math.min(100,e))})}function ct(t,e){const r=R(t);return v({h:r.h,c:Math.max(0,e),t:r.t})}function lt(t,e){const r=R(t);return v({h:(e%360+360)%360,c:r.c,t:r.t})}function E(t,e){const r=R(t);let n=r.h+e;return n=(n%360+360)%360,v({h:n,c:r.c,t:r.t})}function ht(t){return E(t,180)}function ut(t){return[t,E(t,120),E(t,240)]}function ft(t,e=30){return[t,E(t,180-e),E(t,180+e)]}function mt(t,e=3,r=30){const n=[],a=-r*Math.floor(e/2);for(let o=0;o<e;o++)n.push(E(t,a+r*o));return n}function dt(t,e,r=.15){if(!t||!e)throw new Error("Both theme color and target color are required");const n=Math.max(0,Math.min(1,r));return V(e,t,n)}function gt(t,e){if(!t)throw new Error("Theme color is required");const r=R(t);let n;if(Array.isArray(e)?n=e:e&&e.tones&&Array.isArray(e.tones)?n=e.tones:n=[10,20,30,40,50,60,70,80,90],!Array.isArray(n)||n.length===0)throw new Error("Tone steps must be a non-empty array");const a=n.filter(o=>typeof o=="number"&&o>=0&&o<=100);if(a.length===0)throw new Error("No valid tone values found (must be numbers between 0-100)");return a.map(o=>v({h:r.h,c:r.c,t:o}))}function K(t,e,r=.2){if(!t)throw new Error("Theme color is required");if(!e||typeof e!="object")throw new Error("UI colors must be an object");const n=Math.max(0,Math.min(1,r)),a={};for(const[o,s]of Object.entries(e))try{a[o]=B(t,s,n)}catch(c){console.warn(`Failed to blend color for key "${o}": ${c.message}`),a[o]=s}return a}function j(t,e={}){if(!t)throw new Error("Theme color is required");const{baseGray:r="#989898",blendRatio:n=.08,isDark:a=!1,steps:o=12,lightnessRange:s=85,minLightness:c=null,maxLightness:i=null}=e,h=Math.max(0,Math.min(1,n)),f=Math.max(2,Math.min(100,Math.round(o))),u=B(r,t,h),l={steps:f,format:"hex"};if(c!==null&&i!==null)l.minLightness=c,l.maxLightness=i;else{const M=Math.max(20,Math.min(95,s));l.lightnessRange=M}const m=T(u,l),g=a?m.reverse():m,w={};return g.forEach((M,L)=>{w[`gray-${L+1}`]=M}),w}function W(t,e={}){if(!t)throw new Error("Theme color is required");const{baseGray:r="#f5f5f5",blendRatio:n=.03,steps:a=6,minLightness:o=92,maxLightness:s=100,prefix:c="neutral"}=e,i=Math.max(0,Math.min(1,n)),h=Math.max(2,Math.min(20,Math.round(a))),f=Math.max(80,Math.min(99,o)),u=Math.max(f+1,Math.min(100,s)),l=B(r,t,i),m=T(l,{steps:h,format:"hex",minLightness:f,maxLightness:u}),g={};return m.forEach((w,M)=>{g[`${c}-${M+1}`]=w}),g}function O(t,e={}){if(!t)throw new Error("Theme color is required");const{semanticColors:r={success:"#52c41a",warning:"#faad14",error:"#ff4d4f",info:"#1890ff"},blendRatio:n=0,isDark:a=!1,steps:o=10,lightnessRange:s=80,minLightness:c=8,maxLightness:i=97,preserveChroma:h=!0}=e;if(!r||typeof r!="object")throw new Error("Semantic colors must be an object");const f=Math.max(0,Math.min(1,n)),u=Math.max(2,Math.min(100,Math.round(o))),l={};return Object.entries(r).forEach(([m,g])=>{if(!g||typeof g!="string"){console.warn(`Invalid color for semantic color "${m}": ${g}`);return}try{const w=B(g,t,f),M={steps:u,format:"hex",preserveChroma:h};if(c!==null&&i!==null)M.minLightness=c,M.maxLightness=i;else{const p=Math.max(20,Math.min(95,s));M.lightnessRange=p}const L=T(w,M);(a?L.reverse():L).forEach((p,y)=>{l[`${m}-${y+1}`]=p})}catch(w){console.warn(`Failed to generate variants for semantic color "${m}": ${w.message}`)}}),l}function z(t,e={}){if(!t)throw new Error("Theme color is required");const{isDark:r=!1,steps:n=10,lightnessRange:a=80,minLightness:o=8,maxLightness:s=97,preserveChroma:c=!0}=e,h={steps:Math.max(2,Math.min(100,Math.round(n))),format:"hex",preserveChroma:c};if(o!==null&&s!==null)h.minLightness=o,h.maxLightness=s;else{const m=Math.max(20,Math.min(95,a));h.lightnessRange=m}const f=T(t,h),u=r?f.reverse():f,l={};return u.forEach((m,g)=>{l[`theme-${g+1}`]=m}),l}function Mt(t,e={}){if(!t)throw new Error("Theme color is required");const{baseGray:r="#666666",isDark:n=!1,semanticColors:a,controlBlendRatio:o=.08,semanticBlendRatio:s=.12,controlSteps:c=12,controlLightnessRange:i=85,controlMinLightness:h=null,controlMaxLightness:f=null,semanticSteps:u=10,semanticLightnessRange:l=80,semanticMinLightness:m=null,semanticMaxLightness:g=null,semanticPreserveChroma:w=!0,themeSteps:M=10,themeLightnessRange:L=80,themeMinLightness:x=null,themeMaxLightness:p=null,themePreserveChroma:y=!0,neutralSteps:S=6,neutralMinLightness:H=92,neutralMaxLightness:k=100,neutralBlendRatio:pt=.03}=e,Lt=Math.max(0,Math.min(1,o)),yt=Math.max(0,Math.min(1,s)),D={baseGray:r,blendRatio:Lt,isDark:n,steps:c};h!==null&&f!==null?(D.minLightness=h,D.maxLightness=f):D.lightnessRange=i;const I={semanticColors:a,blendRatio:yt,isDark:n,steps:u,preserveChroma:w};m!==null&&g!==null?(I.minLightness=m,I.maxLightness=g):I.lightnessRange=l;const A={isDark:n,steps:M,preserveChroma:y};return x!==null&&p!==null?(A.minLightness=x,A.maxLightness=p):A.lightnessRange=L,{controls:j(t,D),neutrals:W(t,{blendRatio:pt,steps:S,minLightness:H,maxLightness:k}),semantic:O(t,I),theme:z(t,A)}}function bt(t,e={}){if(!t)throw new Error("Theme color is required");const{semanticColors:r={success:"#52c41a",warning:"#faad14",error:"#ff4d4f",info:"#1890ff"},uiColors:n={background:"#ffffff",surface:"#fafafa",border:"#d9d9d9",disabled:"#f5f5f5"},harmonizeRatio:a=.15,blendRatio:o=.12,isDark:s=!1}=e,c=Math.max(0,Math.min(1,a)),i=Math.max(0,Math.min(1,o)),h=z(t,{isDark:s}),f=j(t,{blendRatio:i*.5,isDark:s}),u=O(t,{semanticColors:r,blendRatio:c,isDark:s}),l={};return Object.entries(r).forEach(([g])=>{l[g]={};for(let w=1;w<=10;w++){const M=`${g}-${w}`;u[M]&&(l[g][w]=u[M])}}),{theme:h,controls:f,semantic:l,ui:K(t,n,i)}}const F={red:"#F53F3F",orangered:"#F77234",orange:"#FF7D00",gold:"#F7BA1E",yellow:"#FADC19",lime:"#9FDB1D",green:"#00B42A",cyan:"#14C9C9",blue:"#3491FA",arcoblue:"#165DFF",purple:"#722ED1",pinkpurple:"#D91AD9",magenta:"#F5319D"};function wt(){const t={};return Object.keys(F).forEach(e=>{t[e]={},t[e].light=q(F[e],{list:!0}),t[e].dark=q(F[e],{list:!0,dark:!0}),t[e].primary=F[e]}),t.gray={},t.gray.light=["#f7f8fa","#f2f3f5","#e5e6eb","#c9cdd4","#a9aeb8","#86909c","#6b7785","#4e5969","#272e3b","#1d2129"],t.gray.dark=["#17171a","#2e2e30","#484849","#5f5f60","#78787a","#929293","#ababac","#c5c5c5","#dfdfdf","#f6f6f6"],t.gray.primary=t.gray.light[6],t}d.adjustChroma=ct,d.adjustHue=lt,d.adjustTone=it,d.blendInHct=B,d.blendUIColors=K,d.colorDifference=st,d.colorList=F,d.extractColorFromFile=tt,d.extractColorFromImage=N,d.generate=q,d.generateControlColors=j,d.generateGrayLinear=et,d.generateInterfaceColorSystem=Mt,d.generateLinear=P,d.generateLinearHSL=rt,d.generateMonochromeLinear=T,d.generateNeutralColors=W,d.generateSemanticColors=O,d.generateThemeColors=z,d.generateThemePalette=bt,d.generateThemeVariants=gt,d.getAnalogous=mt,d.getComplementary=ht,d.getPresetColors=wt,d.getRgbStr=J,d.getSplitComplementary=ft,d.getTriadic=ut,d.harmonizeColor=dt,d.hctToRgb=v,d.rgbToHct=R,d.rotateHue=E,Object.defineProperty(d,Symbol.toStringTag,{value:"Module"})});
|