mirror of
https://github.com/XiaoDaiGua-Ray/ray-template.git
synced 2025-04-05 19:42:07 +08:00
2 lines
6.7 KiB
JavaScript
2 lines
6.7 KiB
JavaScript
let R=[];const N=new WeakMap;function S(){R.forEach(n=>n(...N.get(n))),R=[]}function B(n,...t){N.set(n,t),!R.includes(n)&&R.push(n)===1&&requestAnimationFrame(S)}function P(n,t){let{target:r}=n;for(;r;){if(r.dataset&&r.dataset[t]!==void 0)return!0;r=r.parentElement}return!1}function T(n){return n.composedPath()[0]||null}function H(n){if(typeof n=="number")return{"":n.toString()};const t={};return n.split(/ +/).forEach(r=>{if(r==="")return;const[e,i]=r.split(":");i===void 0?t[""]=e:t[e]=i}),t}function _(n,t){var r;if(n==null)return;const e=H(n);if(t===void 0)return e[""];if(typeof t=="string")return(r=e[t])!==null&&r!==void 0?r:e[""];if(Array.isArray(t)){for(let i=t.length-1;i>=0;--i){const u=t[i];if(u in e)return e[u]}return e[""]}else{let i,u=-1;return Object.keys(e).forEach(f=>{const d=Number(f);!Number.isNaN(d)&&t>=d&&d>=u&&(u=d,i=e[f])}),i}}function J(n){return typeof n=="string"?n.endsWith("px")?Number(n.slice(0,n.length-2)):Number(n):n}function Q(n){if(n!=null)return typeof n=="number"?`${n}px`:n.endsWith("px")?n:`${n}px`}function V(n,t){const r=n.trim().split(/\s+/g),e={top:r[0]};switch(r.length){case 1:e.right=r[0],e.bottom=r[0],e.left=r[0];break;case 2:e.right=r[1],e.left=r[1],e.bottom=r[0];break;case 3:e.right=r[1],e.bottom=r[2],e.left=r[1];break;case 4:e.right=r[1],e.bottom=r[2],e.left=r[3];break;default:throw new Error("[seemly/getMargin]:"+n+" is not a valid value.")}return t===void 0?e:e[t]}function X(n,t){const[r,e]=n.split(" ");return{row:r,col:e||r}}const C={black:"#000",silver:"#C0C0C0",gray:"#808080",white:"#FFF",maroon:"#800000",red:"#F00",purple:"#800080",fuchsia:"#F0F",green:"#008000",lime:"#0F0",olive:"#808000",yellow:"#FF0",navy:"#000080",blue:"#00F",teal:"#008080",aqua:"#0FF",transparent:"#0000"};function Y(n,t,r){t/=100,r/=100;const e=t*Math.min(r,1-r)+r;return[n,e?(2-2*r/e)*100:0,e*100]}function Z(n,t,r){t/=100,r/=100;const e=r-r*t/2,i=Math.min(e,1-e);return[n,i?(r-e)/i*100:0,e*100]}function L(n,t,r){t/=100,r/=100;let e=(i,u=(i+n/60)%6)=>r-r*t*Math.max(Math.min(u,4-u,1),0);return[e(5)*255,e(3)*255,e(1)*255]}function O(n,t,r){n/=255,t/=255,r/=255;let e=Math.max(n,t,r),i=e-Math.min(n,t,r),u=i&&(e==n?(t-r)/i:e==t?2+(r-n)/i:4+(n-t)/i);return[60*(u<0?u+6:u),e&&i/e*100,e*100]}function z(n,t,r){n/=255,t/=255,r/=255;let e=Math.max(n,t,r),i=e-Math.min(n,t,r),u=1-Math.abs(e+e-i-1),f=i&&(e==n?(t-r)/i:e==t?2+(r-n)/i:4+(n-t)/i);return[60*(f<0?f+6:f),u?i/u*100:0,(e+e-i)*50]}function K(n,t,r){t/=100,r/=100;let e=t*Math.min(r,1-r),i=(u,f=(u+n/30)%12)=>r-e*Math.max(Math.min(f-3,9-f,1),-1);return[i(0)*255,i(8)*255,i(4)*255]}const h="^\\s*",l="\\s*$",x="\\s*((\\.\\d+)|(\\d+(\\.\\d*)?))%\\s*",c="\\s*((\\.\\d+)|(\\d+(\\.\\d*)?))\\s*",p="([0-9A-Fa-f])",m="([0-9A-Fa-f]{2})",I=new RegExp(`${h}hsl\\s*\\(${c},${x},${x}\\)${l}`),j=new RegExp(`${h}hsv\\s*\\(${c},${x},${x}\\)${l}`),q=new RegExp(`${h}hsla\\s*\\(${c},${x},${x},${c}\\)${l}`),G=new RegExp(`${h}hsva\\s*\\(${c},${x},${x},${c}\\)${l}`),U=new RegExp(`${h}rgb\\s*\\(${c},${c},${c}\\)${l}`),W=new RegExp(`${h}rgba\\s*\\(${c},${c},${c},${c}\\)${l}`),E=new RegExp(`${h}#${p}${p}${p}${l}`),M=new RegExp(`${h}#${m}${m}${m}${l}`),A=new RegExp(`${h}#${p}${p}${p}${p}${l}`),v=new RegExp(`${h}#${m}${m}${m}${m}${l}`);function a(n){return parseInt(n,16)}function tt(n){try{let t;if(t=q.exec(n))return[$(t[1]),o(t[5]),o(t[9]),g(t[13])];if(t=I.exec(n))return[$(t[1]),o(t[5]),o(t[9]),1];throw new Error(`[seemly/hsla]: Invalid color value ${n}.`)}catch(t){throw t}}function nt(n){try{let t;if(t=G.exec(n))return[$(t[1]),o(t[5]),o(t[9]),g(t[13])];if(t=j.exec(n))return[$(t[1]),o(t[5]),o(t[9]),1];throw new Error(`[seemly/hsva]: Invalid color value ${n}.`)}catch(t){throw t}}function w(n){try{let t;if(t=M.exec(n))return[a(t[1]),a(t[2]),a(t[3]),1];if(t=U.exec(n))return[s(t[1]),s(t[5]),s(t[9]),1];if(t=W.exec(n))return[s(t[1]),s(t[5]),s(t[9]),g(t[13])];if(t=E.exec(n))return[a(t[1]+t[1]),a(t[2]+t[2]),a(t[3]+t[3]),1];if(t=v.exec(n))return[a(t[1]),a(t[2]),a(t[3]),g(a(t[4])/255)];if(t=A.exec(n))return[a(t[1]+t[1]),a(t[2]+t[2]),a(t[3]+t[3]),g(a(t[4]+t[4])/255)];if(n in C)return w(C[n]);throw new Error(`[seemly/rgba]: Invalid color value ${n}.`)}catch(t){throw t}}function b(n){return n>1?1:n<0?0:n}function k(n,t,r){return`rgb(${s(n)}, ${s(t)}, ${s(r)})`}function F(n,t,r,e){return`rgba(${s(n)}, ${s(t)}, ${s(r)}, ${b(e)})`}function y(n,t,r,e,i){return s((n*t*(1-e)+r*e)/i)}function et(n,t){Array.isArray(n)||(n=w(n)),Array.isArray(t)||(t=w(t));const r=n[3],e=t[3],i=g(r+e-r*e);return F(y(n[0],r,t[0],e,i),y(n[1],r,t[1],e,i),y(n[2],r,t[2],e,i),i)}function rt(n,t){const[r,e,i,u=1]=Array.isArray(n)?n:w(n);return t.alpha?F(r,e,i,t.alpha):F(r,e,i,u)}function it(n,t){const[r,e,i,u=1]=Array.isArray(n)?n:w(n),{lightness:f=1,alpha:d=1}=t;return D([r*f,e*f,i*f,u*d])}function g(n){const t=Math.round(Number(n)*100)/100;return t>1?1:t<0?0:t}function $(n){const t=Math.round(Number(n));return t>=360||t<0?0:t}function s(n){const t=Math.round(Number(n));return t>255?255:t<0?0:t}function o(n){const t=Math.round(Number(n));return t>100?100:t<0?0:t}function st(n){const[t,r,e]=Array.isArray(n)?n:w(n);return k(t,r,e)}function D(n){const[t,r,e]=n;return 3 in n?`rgba(${s(t)}, ${s(r)}, ${s(e)}, ${g(n[3])})`:`rgba(${s(t)}, ${s(r)}, ${s(e)}, 1)`}function ut(n){return`hsv(${$(n[0])}, ${o(n[1])}%, ${o(n[2])}%)`}function ot(n){const[t,r,e]=n;return 3 in n?`hsva(${$(t)}, ${o(r)}%, ${o(e)}%, ${g(n[3])})`:`hsva(${$(t)}, ${o(r)}%, ${o(e)}%, 1)`}function at(n){return`hsl(${$(n[0])}, ${o(n[1])}%, ${o(n[2])}%)`}function ft(n){const[t,r,e]=n;return 3 in n?`hsla(${$(t)}, ${o(r)}%, ${o(e)}%, ${g(n[3])})`:`hsla(${$(t)}, ${o(r)}%, ${o(e)}%, 1)`}function ct(n){if(typeof n=="string"){let e;if(e=M.exec(n))return`${e[0]}FF`;if(e=v.exec(n))return e[0];if(e=E.exec(n))return`#${e[1]}${e[1]}${e[2]}${e[2]}${e[3]}${e[3]}FF`;if(e=A.exec(n))return`#${e[1]}${e[1]}${e[2]}${e[2]}${e[3]}${e[3]}${e[4]}${e[4]}`;throw new Error(`[seemly/toHexString]: Invalid hex value ${n}.`)}const t=`#${n.slice(0,3).map(e=>s(e).toString(16).toUpperCase().padStart(2,"0")).join("")}`,r=n.length===3?"FF":s(n[3]*255).toString(16).padStart(2,"0").toUpperCase();return t+r}function $t(n){if(typeof n=="string"){let t;if(t=M.exec(n))return t[0];if(t=v.exec(n))return t[0].slice(0,7);if(t=E.exec(n)||A.exec(n))return`#${t[1]}${t[1]}${t[2]}${t[2]}${t[3]}${t[3]}`;throw new Error(`[seemly/toHexString]: Invalid hex value ${n}.`)}return`#${n.slice(0,3).map(t=>s(t).toString(16).toUpperCase().padStart(2,"0")).join("")}`}function ht(n=8){return Math.random().toString(16).slice(2,2+n)}function lt(n,t){const r=[];for(let e=0;e<n;++e)r.push(t);return r}export{lt as A,B,X as C,_ as D,T as a,rt as b,et as c,J as d,ht as e,ft as f,V as g,P as h,z as i,ot as j,O as k,D as l,tt as m,K as n,Y as o,nt as p,L as q,w as r,it as s,ct as t,Z as u,$t as v,at as w,st as x,ut as y,Q as z};
|