yxuse 3.0.12 → 3.0.13

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/lib/index.cjs3.js CHANGED
@@ -1 +1 @@
1
- "use strict";var g=Object.defineProperty;var o=(s,e,t)=>e in s?g(s,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):s[e]=t;var a=(s,e,t)=>(o(s,typeof e!="symbol"?e+"":e,t),t);const y=require("./index.cjs6.js"),u=s=>{new BroadcastChannel("YXUSE_BC").postMessage(s)},c=s=>{const e=new BroadcastChannel("YXUSE_BC");e.onmessage=()=>{s()}},b=(s,e,t,r)=>Array.isArray(s)?s.map(n=>({label:n==null?void 0:n[e],value:r?+n[t]:n[t]})):[],l=s=>{const e=[];for(const t in s)isNaN(Number(t))&&e.push({label:t,value:s[t]});return e},h=s=>{if(!s)return!1;let e,t,r;if(s.startsWith("#"))if(s=s.slice(1),s.length===3)e=parseInt(s[0]+s[0],16),t=parseInt(s[1]+s[1],16),r=parseInt(s[2]+s[2],16);else if(s.length===6)e=parseInt(s.slice(0,2),16),t=parseInt(s.slice(2,4),16),r=parseInt(s.slice(4,6),16);else return null;else if(s.startsWith("rgba")){const i=s.match(/(\d+(\.\d+)?)/g);e=parseFloat(i[0]),t=parseFloat(i[1]),r=parseFloat(i[2])}else return null;e/=255,t/=255,r/=255;const n=Math.max(e,t,r),f=Math.min(e,t,r);return(n+f)/2<.5};class S{constructor(){a(this,"subscribers");this.subscribers={}}subscribe(e,t){this.subscribers[e]||(this.subscribers[e]=[]),this.subscribers[e].push(t)}unsubscribe(e,t){const r=this.subscribers[e];if(!t)return this.subscribers[e]=[];if(r){const n=r.indexOf(t);n!==-1&&r.splice(n,1)}}publish(e){const t=this.subscribers[e.type];t&&t.forEach(r=>{r(e.data)})}}const p=new S,d=Object.freeze(Object.defineProperty({__proto__:null,enumToArray:l,getSelectOptions:b,http:y.http,isDarkColor:h,notifyMessageToSystems:u,receiveMessage:c,yxSubscribe:p},Symbol.toStringTag,{value:"Module"}));exports.enumToArray=l;exports.getSelectOptions=b;exports.isDarkColor=h;exports.notifyMessageToSystems=u;exports.receiveMessage=c;exports.utils2=d;exports.yxSubscribe=p;
1
+ "use strict";var _=Object.defineProperty;var T=(t,s,e)=>s in t?_(t,s,{enumerable:!0,configurable:!0,writable:!0,value:e}):t[s]=e;var M=(t,s,e)=>(T(t,typeof s!="symbol"?s+"":s,e),e);const v=require("./index.cjs6.js"),y=t=>{new BroadcastChannel("YXUSE_BC").postMessage(t)},S=t=>{const s=new BroadcastChannel("YXUSE_BC");s.onmessage=()=>{t()}},I=(t,s,e,i)=>Array.isArray(t)?t.map(r=>({label:r==null?void 0:r[s],value:i?+r[e]:r[e]})):[],x=t=>{const s=[];for(const e in t)isNaN(Number(e))&&s.push({label:e,value:t[e]});return s},B=t=>{const e=(a=>{let f=0,g=0,m=0,C=1;if(a.startsWith("#"))if(a=a.slice(1),a.length===3)f=parseInt(a[0]+a[0],16),g=parseInt(a[1]+a[1],16),m=parseInt(a[2]+a[2],16);else if(a.length===6)f=parseInt(a.slice(0,2),16),g=parseInt(a.slice(2,4),16),m=parseInt(a.slice(4,6),16);else return null;else if(a.startsWith("rgb")){const h=a.match(/(\d+(\.\d+)?)/g);if(h)f=parseFloat(h[0]),g=parseFloat(h[1]),m=parseFloat(h[2]),h.length>3&&(C=parseFloat(h[3]));else return null}else return null;return[f,g,m,C]})(t);if(!e)return null;const[i,r,l,d]=e,n=i/255,u=r/255,c=l/255,p=Math.max(n,u,c),o=Math.min(n,u,c);return(p+o)/2<.5},F=(t,s,e=100)=>{const i=n=>{let u,c,p,o=1;if(n.startsWith("#"))if(n=n.slice(1),n.length===3)u=parseInt(n[0]+n[0],16),c=parseInt(n[1]+n[1],16),p=parseInt(n[2]+n[2],16);else if(n.length===6)u=parseInt(n.slice(0,2),16),c=parseInt(n.slice(2,4),16),p=parseInt(n.slice(4,6),16);else return null;else if(n.startsWith("rgb")){const b=n.match(/(\d+(\.\d+)?)/g);u=parseFloat(b[0]),c=parseFloat(b[1]),p=parseFloat(b[2]),b.length>3&&(o=parseFloat(b[3]))}else return null;return[u,c,p,o]},r=i(t),l=i(s);if(!r||!l)return!1;const d=Math.sqrt(Math.pow(r[0]-l[0],2)+Math.pow(r[1]-l[1],2)+Math.pow(r[2]-l[2],2)+Math.pow(r[3]-l[3],2));return console.log(d),d<=e};class z{constructor(){M(this,"subscribers");this.subscribers={}}subscribe(s,e){this.subscribers[s]||(this.subscribers[s]=[]),this.subscribers[s].push(e)}unsubscribe(s,e){const i=this.subscribers[s];if(!e)return this.subscribers[s]=[];if(i){const r=i.indexOf(e);r!==-1&&i.splice(r,1)}}publish(s){const e=this.subscribers[s.type];e&&e.forEach(i=>{i(s.data)})}}const w=new z,A=Object.freeze(Object.defineProperty({__proto__:null,areColorsSimilar:F,enumToArray:x,getSelectOptions:I,http:v.http,isDarkColor:B,notifyMessageToSystems:y,receiveMessage:S,yxSubscribe:w},Symbol.toStringTag,{value:"Module"}));exports.areColorsSimilar=F;exports.enumToArray=x;exports.getSelectOptions=I;exports.isDarkColor=B;exports.notifyMessageToSystems=y;exports.receiveMessage=S;exports.utils2=A;exports.yxSubscribe=w;
package/lib/index.es3.js CHANGED
@@ -1,82 +1,112 @@
1
- var b = Object.defineProperty;
2
- var c = (s, e, t) => e in s ? b(s, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : s[e] = t;
3
- var i = (s, e, t) => (c(s, typeof e != "symbol" ? e + "" : e, t), t);
4
- import { h as l } from "./index.es6.js";
5
- const h = (s) => {
6
- new BroadcastChannel("YXUSE_BC").postMessage(s);
7
- }, p = (s) => {
8
- const e = new BroadcastChannel("YXUSE_BC");
9
- e.onmessage = () => {
10
- s();
1
+ var I = Object.defineProperty;
2
+ var y = (t, s, e) => s in t ? I(t, s, { enumerable: !0, configurable: !0, writable: !0, value: e }) : t[s] = e;
3
+ var M = (t, s, e) => (y(t, typeof s != "symbol" ? s + "" : s, e), e);
4
+ import { h as S } from "./index.es6.js";
5
+ const B = (t) => {
6
+ new BroadcastChannel("YXUSE_BC").postMessage(t);
7
+ }, F = (t) => {
8
+ const s = new BroadcastChannel("YXUSE_BC");
9
+ s.onmessage = () => {
10
+ t();
11
11
  };
12
- }, f = (s, e, t, r) => Array.isArray(s) ? s.map((n) => ({
13
- label: n == null ? void 0 : n[e],
14
- value: r ? +n[t] : n[t]
15
- })) : [], g = (s) => {
16
- const e = [];
17
- for (const t in s)
18
- isNaN(Number(t)) && e.push({ label: t, value: s[t] });
19
- return e;
20
- }, o = (s) => {
21
- if (!s)
22
- return !1;
23
- let e, t, r;
24
- if (s.startsWith("#"))
25
- if (s = s.slice(1), s.length === 3)
26
- e = parseInt(s[0] + s[0], 16), t = parseInt(s[1] + s[1], 16), r = parseInt(s[2] + s[2], 16);
27
- else if (s.length === 6)
28
- e = parseInt(s.slice(0, 2), 16), t = parseInt(s.slice(2, 4), 16), r = parseInt(s.slice(4, 6), 16);
29
- else
12
+ }, w = (t, s, e, i) => Array.isArray(t) ? t.map((r) => ({
13
+ label: r == null ? void 0 : r[s],
14
+ value: i ? +r[e] : r[e]
15
+ })) : [], x = (t) => {
16
+ const s = [];
17
+ for (const e in t)
18
+ isNaN(Number(e)) && s.push({ label: e, value: t[e] });
19
+ return s;
20
+ }, _ = (t) => {
21
+ const e = ((a) => {
22
+ let f = 0, g = 0, m = 0, C = 1;
23
+ if (a.startsWith("#"))
24
+ if (a = a.slice(1), a.length === 3)
25
+ f = parseInt(a[0] + a[0], 16), g = parseInt(a[1] + a[1], 16), m = parseInt(a[2] + a[2], 16);
26
+ else if (a.length === 6)
27
+ f = parseInt(a.slice(0, 2), 16), g = parseInt(a.slice(2, 4), 16), m = parseInt(a.slice(4, 6), 16);
28
+ else
29
+ return null;
30
+ else if (a.startsWith("rgb")) {
31
+ const b = a.match(/(\d+(\.\d+)?)/g);
32
+ if (b)
33
+ f = parseFloat(b[0]), g = parseFloat(b[1]), m = parseFloat(b[2]), b.length > 3 && (C = parseFloat(b[3]));
34
+ else
35
+ return null;
36
+ } else
30
37
  return null;
31
- else if (s.startsWith("rgba")) {
32
- const a = s.match(/(\d+(\.\d+)?)/g);
33
- e = parseFloat(a[0]), t = parseFloat(a[1]), r = parseFloat(a[2]);
34
- } else
38
+ return [f, g, m, C];
39
+ })(t);
40
+ if (!e)
35
41
  return null;
36
- e /= 255, t /= 255, r /= 255;
37
- const n = Math.max(e, t, r), u = Math.min(e, t, r);
38
- return (n + u) / 2 < 0.5;
42
+ const [i, r, l, d] = e, n = i / 255, u = r / 255, c = l / 255, p = Math.max(n, u, c), o = Math.min(n, u, c);
43
+ return (p + o) / 2 < 0.5;
44
+ }, z = (t, s, e = 100) => {
45
+ const i = (n) => {
46
+ let u, c, p, o = 1;
47
+ if (n.startsWith("#"))
48
+ if (n = n.slice(1), n.length === 3)
49
+ u = parseInt(n[0] + n[0], 16), c = parseInt(n[1] + n[1], 16), p = parseInt(n[2] + n[2], 16);
50
+ else if (n.length === 6)
51
+ u = parseInt(n.slice(0, 2), 16), c = parseInt(n.slice(2, 4), 16), p = parseInt(n.slice(4, 6), 16);
52
+ else
53
+ return null;
54
+ else if (n.startsWith("rgb")) {
55
+ const h = n.match(/(\d+(\.\d+)?)/g);
56
+ u = parseFloat(h[0]), c = parseFloat(h[1]), p = parseFloat(h[2]), h.length > 3 && (o = parseFloat(h[3]));
57
+ } else
58
+ return null;
59
+ return [u, c, p, o];
60
+ }, r = i(t), l = i(s);
61
+ if (!r || !l)
62
+ return !1;
63
+ const d = Math.sqrt(
64
+ Math.pow(r[0] - l[0], 2) + Math.pow(r[1] - l[1], 2) + Math.pow(r[2] - l[2], 2) + Math.pow(r[3] - l[3], 2)
65
+ );
66
+ return console.log(d), d <= e;
39
67
  };
40
- class y {
68
+ class W {
41
69
  constructor() {
42
- i(this, "subscribers");
70
+ M(this, "subscribers");
43
71
  this.subscribers = {};
44
72
  }
45
- subscribe(e, t) {
46
- this.subscribers[e] || (this.subscribers[e] = []), this.subscribers[e].push(t);
73
+ subscribe(s, e) {
74
+ this.subscribers[s] || (this.subscribers[s] = []), this.subscribers[s].push(e);
47
75
  }
48
- unsubscribe(e, t) {
49
- const r = this.subscribers[e];
50
- if (!t)
51
- return this.subscribers[e] = [];
52
- if (r) {
53
- const n = r.indexOf(t);
54
- n !== -1 && r.splice(n, 1);
76
+ unsubscribe(s, e) {
77
+ const i = this.subscribers[s];
78
+ if (!e)
79
+ return this.subscribers[s] = [];
80
+ if (i) {
81
+ const r = i.indexOf(e);
82
+ r !== -1 && i.splice(r, 1);
55
83
  }
56
84
  }
57
- publish(e) {
58
- const t = this.subscribers[e.type];
59
- t && t.forEach((r) => {
60
- r(e.data);
85
+ publish(s) {
86
+ const e = this.subscribers[s.type];
87
+ e && e.forEach((i) => {
88
+ i(s.data);
61
89
  });
62
90
  }
63
91
  }
64
- const d = new y(), B = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
92
+ const v = new W(), N = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
65
93
  __proto__: null,
66
- enumToArray: g,
67
- getSelectOptions: f,
68
- http: l,
69
- isDarkColor: o,
70
- notifyMessageToSystems: h,
71
- receiveMessage: p,
72
- yxSubscribe: d
94
+ areColorsSimilar: z,
95
+ enumToArray: x,
96
+ getSelectOptions: w,
97
+ http: S,
98
+ isDarkColor: _,
99
+ notifyMessageToSystems: B,
100
+ receiveMessage: F,
101
+ yxSubscribe: v
73
102
  }, Symbol.toStringTag, { value: "Module" }));
74
103
  export {
75
- g as e,
76
- f as g,
77
- o as i,
78
- h as n,
79
- p as r,
80
- B as u,
81
- d as y
104
+ z as a,
105
+ x as e,
106
+ w as g,
107
+ _ as i,
108
+ B as n,
109
+ F as r,
110
+ N as u,
111
+ v as y
82
112
  };
package/lib/utils.cjs.js CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("./index.cjs6.js"),e=require("./index.cjs3.js");require("./vue.runtime.esm-bundler.cjs.js");exports.http=s.http;exports.enumToArray=e.enumToArray;exports.getSelectOptions=e.getSelectOptions;exports.isDarkColor=e.isDarkColor;exports.notifyMessageToSystems=e.notifyMessageToSystems;exports.receiveMessage=e.receiveMessage;exports.yxSubscribe=e.yxSubscribe;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("./index.cjs6.js"),e=require("./index.cjs3.js");require("./vue.runtime.esm-bundler.cjs.js");exports.http=r.http;exports.areColorsSimilar=e.areColorsSimilar;exports.enumToArray=e.enumToArray;exports.getSelectOptions=e.getSelectOptions;exports.isDarkColor=e.isDarkColor;exports.notifyMessageToSystems=e.notifyMessageToSystems;exports.receiveMessage=e.receiveMessage;exports.yxSubscribe=e.yxSubscribe;
package/lib/utils.es.js CHANGED
@@ -1,12 +1,13 @@
1
- import { h as a } from "./index.es6.js";
2
- import { e as t, g as i, i as m, n as p, r as y, y as g } from "./index.es3.js";
1
+ import { h as r } from "./index.es6.js";
2
+ import { a as t, e as i, g as m, i as p, n as y, r as g, y as l } from "./index.es3.js";
3
3
  import "./vue.runtime.esm-bundler.es.js";
4
4
  export {
5
- t as enumToArray,
6
- i as getSelectOptions,
7
- a as http,
8
- m as isDarkColor,
9
- p as notifyMessageToSystems,
10
- y as receiveMessage,
11
- g as yxSubscribe
5
+ t as areColorsSimilar,
6
+ i as enumToArray,
7
+ m as getSelectOptions,
8
+ r as http,
9
+ p as isDarkColor,
10
+ y as notifyMessageToSystems,
11
+ g as receiveMessage,
12
+ l as yxSubscribe
12
13
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "yxuse",
3
- "version": "3.0.12",
3
+ "version": "3.0.13",
4
4
  "private": false,
5
5
  "keywords": [
6
6
  "yx"
@@ -35,4 +35,11 @@ export declare const enumToArray: <T extends Record<string, string | number>>(en
35
35
  * @param color 色值
36
36
  */
37
37
  export declare const isDarkColor: (color: string) => boolean | null;
38
+ /**
39
+ * @description 判断两个色值是否为相近色
40
+ * @param color1 第一个色值
41
+ * @param color2 第二个色值
42
+ * @param threshold 阈值,用于判断两个颜色是否相近
43
+ */
44
+ export declare const areColorsSimilar: (color1: string, color2: string, threshold?: number) => boolean;
38
45
  export {};