frColorPicker

frColorPicker 拾色器专供Font Rendering使用。

目前為 2022-01-14 提交的版本,檢視 最新版本

此腳本不應該直接安裝,它是一個供其他腳本使用的函式庫。欲使用本函式庫,請在腳本 metadata 寫上: // @require https://update.gf.qytechs.cn/scripts/437214/1008472/frColorPicker.js

  1. // ==UserScript==
  2. // @name frColorPicker
  3. // @author F9y4ng
  4. // @version 1.3
  5. // @license GPL-3.0-only
  6. // ==/UserScript==
  7.  
  8. !(function (E) {
  9. function B(a) {
  10. var b = "";
  11. for (a = Number(a - 1) || 8; 0 < a; --a) b += "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"[Math.floor(62 * Math.random())];
  12. return "ABCDEFGHIJKLMNOPQRSTUVWXYZ"[Math.floor(26 * Math.random())].concat(b);
  13. }
  14. var H = B(9),
  15. I = B(8),
  16. J = B(12),
  17. K = B(8),
  18. L = B(7),
  19. M = B(7),
  20. N = B(6),
  21. O = B(6),
  22. P = B(4);
  23. E =
  24. window.trustedTypes && window.trustedTypes.createPolicy
  25. ? window.trustedTypes.createPolicy("standaloneColorizer", {
  26. createHTML: function (a) {
  27. return a;
  28. },
  29. })
  30. : {
  31. createHTML: function (a) {
  32. return a;
  33. },
  34. };
  35. var T = (function () {
  36. var a = {
  37. initialized: !1,
  38. instances: [],
  39. readyQueue: [],
  40. register: function () {
  41. "undefined" !== typeof window && window.document && window.document.addEventListener("DOMContentLoaded", a.pub.init, !1);
  42. },
  43. installBySelector: function (b, d) {
  44. d = d ? a.node(d) : window.document;
  45. if (!d) throw Error("Missing root node");
  46. b = d.querySelectorAll(b);
  47. d = new RegExp("(^|\\s)(" + a.pub.lookupClass + ")(\\s*(\\{[^}]*\\})|\\s|$)", "i");
  48. for (var e = 0; e < b.length; e += 1)
  49. if (!((b[e].frcolorpicker && b[e].frcolorpicker instanceof a.pub) || (void 0 !== b[e].type && "color" == b[e].type.toLowerCase() && a.isColorAttrSupported))) {
  50. var g, h;
  51. if (null !== (g = a.getDataAttr(b[e], "frcolorpicker")) || (b[e].className && (h = b[e].className.match(d)))) {
  52. var l = b[e],
  53. m = "";
  54. null !== g ? (m = g) : h && h[4] && (m = h[4]);
  55. g = null;
  56. if (m.trim())
  57. try {
  58. g = a.parseOptionsStr(m);
  59. } catch (q) {}
  60. try {
  61. new a.pub(l, g);
  62. } catch (q) {}
  63. }
  64. }
  65. },
  66. parseOptionsStr: function (b) {
  67. var d = null;
  68. try {
  69. d = JSON.parse(b);
  70. } catch (e) {
  71. if (a.pub.looseJSON)
  72. try {
  73. d = new Function("var opts = (" + b + '); return typeof opts === "object" ? opts : {};')();
  74. } catch (g) {
  75. throw Error("Could not evaluate frcolorpicker options: " + g);
  76. }
  77. else throw Error("Could not parse frcolorpicker options as JSON: " + e);
  78. }
  79. return d;
  80. },
  81. getInstances: function () {
  82. for (var b = [], d = 0; d < a.instances.length; d += 1) a.instances[d] && a.instances[d].targetElement && b.push(a.instances[d]);
  83. return b;
  84. },
  85. createEl: function (b) {
  86. b = window.document.createElement(b);
  87. a.setData(b, "gui", !0);
  88. return b;
  89. },
  90. node: function (b) {
  91. if (!b) return null;
  92. if ("string" === typeof b) {
  93. var d = null;
  94. try {
  95. d = window.document.querySelector(b);
  96. } catch (e) {
  97. return null;
  98. }
  99. return d;
  100. }
  101. return a.isNode(b) ? b : null;
  102. },
  103. isNode: function (b) {
  104. return "object" === typeof Node ? b instanceof Node : b && "object" === typeof b && "number" === typeof b.nodeType && "string" === typeof b.nodeName;
  105. },
  106. nodeName: function (b) {
  107. return b && b.nodeName ? b.nodeName.toLowerCase() : !1;
  108. },
  109. removeChildren: function (b) {
  110. for (; b.firstChild; ) b.removeChild(b.firstChild);
  111. },
  112. isTextInput: function (b) {
  113. return b && "input" === a.nodeName(b) && "text" === b.type.toLowerCase();
  114. },
  115. isButton: function (b) {
  116. if (!b) return !1;
  117. var d = a.nodeName(b);
  118. return "button" === d || ("input" === d && -1 < ["button", "submit", "reset"].indexOf(b.type.toLowerCase()));
  119. },
  120. isButtonEmpty: function (b) {
  121. switch (a.nodeName(b)) {
  122. case "input":
  123. return !b.value || "" === b.value.trim();
  124. case "button":
  125. return "" === b.textContent.trim();
  126. }
  127. return null;
  128. },
  129. isPassiveEventSupported: (function () {
  130. var b = !1;
  131. try {
  132. var d = Object.defineProperty({}, "passive", {
  133. get: function () {
  134. b = !0;
  135. },
  136. });
  137. window.addEventListener("testPassive", null, d);
  138. window.removeEventListener("testPassive", null, d);
  139. } catch (e) {}
  140. return b;
  141. })(),
  142. isColorAttrSupported: (function () {
  143. var b = window.document.createElement("input");
  144. return b.setAttribute && (b.setAttribute("type", "color"), "color" == b.type.toLowerCase()) ? !0 : !1;
  145. })(),
  146. dataProp: "_data_frcolorpicker",
  147. setData: function () {
  148. var b = arguments[0];
  149. if (3 === arguments.length) {
  150. b = b.hasOwnProperty(a.dataProp) ? b[a.dataProp] : (b[a.dataProp] = {});
  151. var d = arguments[1];
  152. b[d] = arguments[2];
  153. return !0;
  154. }
  155. if (2 === arguments.length && "object" === typeof arguments[1]) {
  156. b = b.hasOwnProperty(a.dataProp) ? b[a.dataProp] : (b[a.dataProp] = {});
  157. var e = arguments[1];
  158. for (d in e) e.hasOwnProperty(d) && (b[d] = e[d]);
  159. return !0;
  160. }
  161. throw Error("Invalid arguments");
  162. },
  163. removeData: function () {
  164. var b = arguments[0];
  165. if (!b.hasOwnProperty(a.dataProp)) return !0;
  166. for (var d = 1; d < arguments.length; d += 1) delete b[a.dataProp][arguments[d]];
  167. return !0;
  168. },
  169. getData: function (b, d, e) {
  170. if (!b.hasOwnProperty(a.dataProp))
  171. if (void 0 !== e) b[a.dataProp] = {};
  172. else return;
  173. b = b[a.dataProp];
  174. b.hasOwnProperty(d) || void 0 === e || (b[d] = e);
  175. return b[d];
  176. },
  177. getDataAttr: function (b, d) {
  178. return b.getAttribute("data-" + d);
  179. },
  180. setDataAttr: function (b, d, e) {
  181. b.setAttribute("data-" + d, e);
  182. },
  183. _attachedGroupEvents: {},
  184. attachGroupEvent: function (b, d, e, g) {
  185. a._attachedGroupEvents.hasOwnProperty(b) || (a._attachedGroupEvents[b] = []);
  186. a._attachedGroupEvents[b].push([d, e, g]);
  187. d.addEventListener(e, g, !1);
  188. },
  189. detachGroupEvents: function (b) {
  190. if (a._attachedGroupEvents.hasOwnProperty(b)) {
  191. for (var d = 0; d < a._attachedGroupEvents[b].length; d += 1) {
  192. var e = a._attachedGroupEvents[b][d];
  193. e[0].removeEventListener(e[1], e[2], !1);
  194. }
  195. delete a._attachedGroupEvents[b];
  196. }
  197. },
  198. preventDefault: function (b) {
  199. b.preventDefault && b.preventDefault();
  200. b.returnValue = !1;
  201. },
  202. captureTarget: function (b) {
  203. b.setCapture && ((a._capturedTarget = b), a._capturedTarget.setCapture());
  204. },
  205. releaseTarget: function () {
  206. a._capturedTarget && (a._capturedTarget.releaseCapture(), (a._capturedTarget = null));
  207. },
  208. triggerEvent: function (b, d, e, g) {
  209. if (b) {
  210. if ("function" === typeof Event)
  211. var h = new Event(d, {
  212. bubbles: e,
  213. cancelable: g,
  214. });
  215. else (h = window.document.createEvent("Event")), h.initEvent(d, e, g);
  216. if (!h) return !1;
  217. a.setData(h, "internal", !0);
  218. b.dispatchEvent(h);
  219. return !0;
  220. }
  221. },
  222. triggerInputEvent: function (b, d, e, g) {
  223. b && a.isTextInput(b) && a.triggerEvent(b, d, e, g);
  224. },
  225. eventKey: function (b) {
  226. var d = {
  227. 9: "Tab",
  228. 13: "Enter",
  229. 27: "Escape",
  230. };
  231. return "string" === typeof b.code ? b.code : void 0 !== b.keyCode && d.hasOwnProperty(b.keyCode) ? d[b.keyCode] : null;
  232. },
  233. strList: function (b) {
  234. return b ? b.replace(/^\s+|\s+$/g, "").split(/\s+/) : [];
  235. },
  236. hasClass: function (b, d) {
  237. return d ? (void 0 !== b.classList ? b.classList.contains(d) : -1 != (" " + b.className.replace(/\s+/g, " ") + " ").indexOf(" " + d + " ")) : !1;
  238. },
  239. addClass: function (b, d) {
  240. d = a.strList(d);
  241. if (void 0 !== b.classList) for (var e = 0; e < d.length; e += 1) b.classList.add(d[e]);
  242. else for (e = 0; e < d.length; e += 1) a.hasClass(b, d[e]) || (b.className += (b.className ? " " : "") + d[e]);
  243. },
  244. removeClass: function (b, d) {
  245. d = a.strList(d);
  246. if (void 0 !== b.classList) for (var e = 0; e < d.length; e += 1) b.classList.remove(d[e]);
  247. else for (e = 0; e < d.length; e += 1) b.className = b.className.replace(new RegExp("^\\s*" + d[e] + "\\s*|\\s*" + d[e] + "\\s*$|\\s+" + d[e] + "(\\s+)", "g"), "$1");
  248. },
  249. getCompStyle: function (b) {
  250. return (b = window.getComputedStyle ? window.getComputedStyle(b) : b.currentStyle) ? b : {};
  251. },
  252. setStyle: function (b, d, e, g) {
  253. e = e ? "important" : "";
  254. var h = null,
  255. l;
  256. for (l in d)
  257. if (d.hasOwnProperty(l)) {
  258. var m = null;
  259. null === d[l]
  260. ? (h || (h = a.getData(b, "origStyle")), h && h.hasOwnProperty(l) && (m = h[l]))
  261. : (g && (h || (h = a.getData(b, "origStyle", {})), h.hasOwnProperty(l) || (h[l] = b.style[l])), (m = d[l]));
  262. null !== m && b.style.setProperty(l, m, e);
  263. }
  264. },
  265. hexColor: function (b, d, e) {
  266. return "#" + (("0" + Math.round(b).toString(16)).substr(-2) + ("0" + Math.round(d).toString(16)).substr(-2) + ("0" + Math.round(e).toString(16)).substr(-2)).toUpperCase();
  267. },
  268. hexaColor: function (b, d, e, g) {
  269. return (
  270. "#" +
  271. (
  272. ("0" + Math.round(b).toString(16)).substr(-2) +
  273. ("0" + Math.round(d).toString(16)).substr(-2) +
  274. ("0" + Math.round(e).toString(16)).substr(-2) +
  275. ("0" + Math.round(255 * g).toString(16)).substr(-2)
  276. ).toUpperCase()
  277. );
  278. },
  279. rgbColor: function (b, d, e) {
  280. return "rgb(" + Math.round(b) + "," + Math.round(d) + "," + Math.round(e) + ")";
  281. },
  282. rgbaColor: function (b, d, e, g) {
  283. return "rgba(" + Math.round(b) + "," + Math.round(d) + "," + Math.round(e) + "," + Math.round(100 * (void 0 === g || null === g ? 1 : g)) / 100 + ")";
  284. },
  285. linearGradient: (function () {
  286. var b = (function () {
  287. for (var d = ["", "-webkit-", "-moz-", "-o-", "-ms-"], e = window.document.createElement("div"), g = 0; g < d.length; g += 1) {
  288. var h = d[g] + "linear-gradient";
  289. e.style.background = h + "(to right, rgba(0,0,0,0), rgba(0,0,0,0))";
  290. if (e.style.background) return h;
  291. }
  292. return "linear-gradient";
  293. })();
  294. return function () {
  295. return b + "(" + Array.prototype.join.call(arguments, ", ") + ")";
  296. };
  297. })(),
  298. setBorderRadius: function (b, d) {
  299. a.setStyle(b, {
  300. "border-radius": d || "0",
  301. });
  302. },
  303. setBoxShadow: function (b, d) {
  304. a.setStyle(b, {
  305. "box-shadow": d || "none",
  306. });
  307. },
  308. getElementPos: function (b, d) {
  309. var e = b.getBoundingClientRect();
  310. b = e.left;
  311. e = e.top;
  312. d || ((d = a.getViewPos()), (b += d[0]), (e += d[1]));
  313. return [b, e];
  314. },
  315. getElementSize: function (b) {
  316. return [b.offsetWidth, b.offsetHeight];
  317. },
  318. getAbsPointerPos: function (b) {
  319. var d = 0,
  320. e = 0;
  321. "undefined" !== typeof b.changedTouches && b.changedTouches.length
  322. ? ((d = b.changedTouches[0].x), (e = b.changedTouches[0].y))
  323. : "number" === typeof b.x && ((d = b.x), (e = b.y));
  324. return {
  325. x: d,
  326. y: e,
  327. };
  328. },
  329. getRelPointerPos: function (b) {
  330. var d = (b.target || b.srcElement).getBoundingClientRect(),
  331. e = 0,
  332. g = 0;
  333. "undefined" !== typeof b.changedTouches && b.changedTouches.length
  334. ? ((e = b.changedTouches[0].x), (g = b.changedTouches[0].y))
  335. : "number" === typeof b.x && ((e = b.x), (g = b.y));
  336. return {
  337. x: e - d.left,
  338. y: g - d.top,
  339. };
  340. },
  341. getViewPos: function () {
  342. var b = window.document.documentElement;
  343. return [(window.pageXOffset || b.scrollLeft) - (b.clientLeft || 0), (window.pageYOffset || b.scrollTop) - (b.clientTop || 0)];
  344. },
  345. getViewSize: function () {
  346. var b = window.document.documentElement;
  347. return [window.innerWidth || b.clientWidth, window.innerHeight || b.clientHeight];
  348. },
  349. RGB_HSV: function (b, d, e) {
  350. b /= 255;
  351. d /= 255;
  352. e /= 255;
  353. var g = Math.min(Math.min(b, d), e),
  354. h = Math.max(Math.max(b, d), e),
  355. l = h - g;
  356. if (0 === l) return [null, 0, 100 * h];
  357. b = b === g ? 3 + (e - d) / l : d === g ? 5 + (b - e) / l : 1 + (d - b) / l;
  358. return [60 * (6 === b ? 0 : b), (l / h) * 100, 100 * h];
  359. },
  360. HSV_RGB: function (b, d, e) {
  361. e = (e / 100) * 255;
  362. if (null === b) return [e, e, e];
  363. b /= 60;
  364. d /= 100;
  365. var g = Math.floor(b),
  366. h = e * (1 - d);
  367. b = e * (1 - d * (g % 2 ? b - g : 1 - (b - g)));
  368. switch (g) {
  369. case 6:
  370. case 0:
  371. return [e, b, h];
  372. case 1:
  373. return [b, e, h];
  374. case 2:
  375. return [h, e, b];
  376. case 3:
  377. return [h, b, e];
  378. case 4:
  379. return [b, h, e];
  380. case 5:
  381. return [e, h, b];
  382. }
  383. },
  384. parseColorString: function (b) {
  385. var d = {
  386. rgba: null,
  387. format: null,
  388. },
  389. e;
  390. if ((e = b.match(/^\W*([0-9A-F]{3,8})\W*$|^currentcolor$/i))) {
  391. if ("currentcolor" === e[0].toLowerCase()) return (d.format = "hexa"), (d.rgba = [255, 255, 255, 255]), d;
  392. if (8 === e[1].length)
  393. (d.format = "hexa"),
  394. (d.rgba = [parseInt(e[1].substr(0, 2), 16), parseInt(e[1].substr(2, 2), 16), parseInt(e[1].substr(4, 2), 16), parseInt(e[1].substr(6, 2), 16) / 255]);
  395. else if (6 === e[1].length) (d.format = "hex"), (d.rgba = [parseInt(e[1].substr(0, 2), 16), parseInt(e[1].substr(2, 2), 16), parseInt(e[1].substr(4, 2), 16), null]);
  396. else if (3 === e[1].length)
  397. (d.format = "hex"),
  398. (d.rgba = [parseInt(e[1].charAt(0) + e[1].charAt(0), 16), parseInt(e[1].charAt(1) + e[1].charAt(1), 16), parseInt(e[1].charAt(2) + e[1].charAt(2), 16), null]);
  399. else return !1;
  400. return d;
  401. }
  402. if ((e = b.match(/^\W*rgba?\(([^)]*)\)\W*$/i))) {
  403. b = e[1].split(",");
  404. e = /^\s*(\d+|\d*\.\d+|\d+\.\d*)\s*$/;
  405. var g, h, l, m;
  406. if (3 <= b.length && (g = b[0].match(e)) && (h = b[1].match(e)) && (l = b[2].match(e)))
  407. return (
  408. (d.format = "rgb"),
  409. (d.rgba = [parseFloat(g[1]) || 0, parseFloat(h[1]) || 0, parseFloat(l[1]) || 0, null]),
  410. 4 <= b.length && (m = b[3].match(e)) && ((d.format = "rgba"), (d.rgba[3] = parseFloat(m[1]) || 0)),
  411. d
  412. );
  413. }
  414. return !1;
  415. },
  416. parsePaletteValue: function (b) {
  417. var d = [];
  418. "string" === typeof b
  419. ? b.replace(/#[0-9A-F]{3}([0-9A-F]{3})?|rgba?\(([^)]*)\)/gi, function (h) {
  420. d.push(h);
  421. })
  422. : Array.isArray(b) && (d = b);
  423. b = [];
  424. for (var e = 0; e < d.length; e++) {
  425. var g = a.parseColorString(d[e]);
  426. g && b.push(g);
  427. }
  428. return b;
  429. },
  430. containsTranparentColor: function (b) {
  431. for (var d = 0; d < b.length; d++) {
  432. var e = b[d].rgba[3];
  433. if (null !== e && 1 > e) return !0;
  434. }
  435. return !1;
  436. },
  437. isAlphaFormat: function (b) {
  438. switch (b.toLowerCase()) {
  439. case "hexa":
  440. case "rgba":
  441. return !0;
  442. }
  443. return !1;
  444. },
  445. scaleCanvasForHighDPR: function (b) {
  446. var d = window.devicePixelRatio || 1;
  447. b.width *= d;
  448. b.height *= d;
  449. b.getContext("2d").scale(d, d);
  450. },
  451. genColorPreviewCanvas: function (b, d, e, g) {
  452. var h = Math.round(a.pub.previewSeparator.length),
  453. l = a.pub.chessboardSize,
  454. m = a.pub.chessboardColor1,
  455. q = a.pub.chessboardColor2;
  456. e = e ? e : 2 * l;
  457. var v = 2 * l,
  458. r = a.createEl("canvas"),
  459. y = r.getContext("2d");
  460. r.width = e;
  461. r.height = v;
  462. g && a.scaleCanvasForHighDPR(r);
  463. y.fillStyle = m;
  464. y.fillRect(0, 0, e, v);
  465. y.fillStyle = q;
  466. for (g = 0; g < e; g += 2 * l) y.fillRect(g, 0, l, l), y.fillRect(g + l, l, l, l);
  467. b && ((y.fillStyle = b), y.fillRect(0, 0, e, v));
  468. b = null;
  469. switch (d) {
  470. case "left":
  471. b = 0;
  472. y.clearRect(0, 0, h / 2, v);
  473. break;
  474. case "right":
  475. (b = e - h), y.clearRect(e - h / 2, 0, h / 2, v);
  476. }
  477. if (null !== b)
  478. for (y.lineWidth = 1, d = 0; d < a.pub.previewSeparator.length; d += 1)
  479. y.beginPath(), (y.strokeStyle = a.pub.previewSeparator[d]), y.moveTo(0.5 + b + d, 0), y.lineTo(0.5 + b + d, v), y.stroke();
  480. return {
  481. canvas: r,
  482. width: e,
  483. height: v,
  484. };
  485. },
  486. genColorPreviewGradient: function (b, d, e) {
  487. return a.linearGradient.apply(
  488. this,
  489. d && e
  490. ? [
  491. "to " +
  492. {
  493. left: "right",
  494. right: "left",
  495. }[d],
  496. b + " 0%",
  497. b + " " + e + "px",
  498. "rgba(0,0,0,0) " + (e + 1) + "px",
  499. "rgba(0,0,0,0) 100%",
  500. ]
  501. : ["to right", b + " 0%", b + " 100%"]
  502. );
  503. },
  504. redrawPosition: function () {
  505. if (a.picker && a.picker.owner) {
  506. var b = a.picker.owner;
  507. if (b.fixed) {
  508. var d = a.getElementPos(b.targetElement, !0);
  509. var e = [0, 0];
  510. } else (d = a.getElementPos(b.targetElement)), (e = a.getViewPos());
  511. var g = a.getElementSize(b.targetElement),
  512. h = a.getViewSize(),
  513. l = a.getPickerDims(b);
  514. l = [l.borderW, l.borderH];
  515. switch (b.position.toLowerCase()) {
  516. case "left":
  517. var m = 1;
  518. var q = 0;
  519. var v = -1;
  520. break;
  521. case "right":
  522. m = 1;
  523. q = 0;
  524. v = 1;
  525. break;
  526. case "top":
  527. m = 0;
  528. q = 1;
  529. v = -1;
  530. break;
  531. default:
  532. (m = 0), (v = q = 1);
  533. }
  534. var r = (g[q] + l[q]) / 2;
  535. e = b.smartPosition
  536. ? [
  537. -e[m] + d[m] + l[m] > h[m] ? (-e[m] + d[m] + g[m] / 2 > h[m] / 2 && 0 <= d[m] + g[m] - l[m] ? d[m] + g[m] - l[m] : d[m]) : d[m],
  538. -e[q] + d[q] + g[q] + l[q] - r + r * v > h[q]
  539. ? -e[q] + d[q] + g[q] / 2 > h[q] / 2 && 0 <= d[q] + g[q] - r - r * v
  540. ? d[q] + g[q] - r - r * v - 4
  541. : d[q] + g[q] - r + r * v + 4
  542. : 0 <= d[q] + g[q] - r + r * v
  543. ? d[q] + g[q] - r + r * v - 4
  544. : d[q] + g[q] - r - r * v + 4,
  545. ]
  546. : [d[m], d[q] + g[q] - r + r * v];
  547. a._drawPosition(b, e[m], e[q], b.fixed ? "fixed" : "absolute", (e[0] + l[0] > d[0] || e[0] < d[0] + g[0]) && e[1] + l[1] < d[1] + g[1]);
  548. }
  549. },
  550. _drawPosition: function (b, d, e, g, h) {
  551. h = h ? 0 : b.shadowBlur;
  552. var l = "CSS1Compat" === (document.compatMode || "") ? document.documentElement : document.body,
  553. m = window.getComputedStyle(document.body, null).getPropertyValue("transform");
  554. ((m = m && "none" !== m ? Number(m.split(",")[3]) || 1 : 1), 1 !== m)
  555. ? ((a.picker.wrap.style.left = (d - l.getBoundingClientRect().left) / m + "px"), (a.picker.wrap.style.top = (e - l.getBoundingClientRect().top) / m + "px"))
  556. : ((a.picker.wrap.style.left = d + "px"), (a.picker.wrap.style.top = e + "px"));
  557. a.picker.wrap.style.position = g;
  558. a.setBoxShadow(a.picker.boxS, b.shadow ? new a.BoxShadow(0, h, b.shadowBlur, 0, b.shadowColor) : null);
  559. },
  560. getPickerDims: function (b) {
  561. var d = 2 * b.controlBorderWidth + b.width,
  562. e = 2 * b.controlBorderWidth + b.height,
  563. g = 2 * b.controlBorderWidth + 2 * a.getControlPadding(b) + b.sliderSize;
  564. a.getSliderChannel(b) && (d += g);
  565. b.hasAlphaChannel() && (d += g);
  566. g = a.getPaletteDims(b, d);
  567. g.height && (e += g.height + b.padding);
  568. b.closeButton && (e += 2 * b.controlBorderWidth + b.padding + b.buttonHeight);
  569. var h = d + 2 * b.padding,
  570. l = e + 2 * b.padding;
  571. return {
  572. contentW: d,
  573. contentH: e,
  574. paddedW: h,
  575. paddedH: l,
  576. borderW: h + 2 * b.borderWidth,
  577. borderH: l + 2 * b.borderWidth,
  578. palette: g,
  579. };
  580. },
  581. getPaletteDims: function (b, d) {
  582. var e = 0,
  583. g = 0,
  584. h = 0,
  585. l = 0,
  586. m = 0,
  587. q = b._palette ? b._palette.length : 0;
  588. q &&
  589. ((e = b.paletteCols),
  590. (g = 0 < e ? Math.ceil(q / e) : 0),
  591. (h = Math.max(1, Math.floor((d - (e - 1) * b.paletteSpacing) / e))),
  592. (l = b.paletteHeight ? Math.min(b.paletteHeight, h) : h));
  593. g && (m = g * l + (g - 1) * b.paletteSpacing);
  594. return {
  595. cols: e,
  596. rows: g,
  597. cellW: h,
  598. cellH: l,
  599. width: d,
  600. height: m,
  601. };
  602. },
  603. getControlPadding: function (b) {
  604. return Math.max(b.padding / 2, 2 * b.pointerBorderWidth + b.pointerThickness - b.controlBorderWidth);
  605. },
  606. getPadYChannel: function (b) {
  607. switch (b.mode.charAt(1).toLowerCase()) {
  608. case "v":
  609. return "v";
  610. }
  611. return "s";
  612. },
  613. getSliderChannel: function (b) {
  614. if (2 < b.mode.length)
  615. switch (b.mode.charAt(2).toLowerCase()) {
  616. case "s":
  617. return "s";
  618. case "v":
  619. return "v";
  620. }
  621. return null;
  622. },
  623. triggerCallback: function (b, d) {
  624. if (b[d]) {
  625. var e = null;
  626. if ("string" === typeof b[d])
  627. try {
  628. e = new Function(b[d]);
  629. } catch (g) {
  630. console.error(g);
  631. }
  632. else e = b[d];
  633. e && e.call(b);
  634. }
  635. },
  636. triggerGlobal: function (b) {
  637. for (var d = a.getInstances(), e = 0; e < d.length; e += 1) d[e].trigger(b);
  638. },
  639. _pointerMoveEvent: {
  640. mouse: "mousemove",
  641. touch: "touchmove",
  642. },
  643. _pointerEndEvent: {
  644. mouse: "mouseup",
  645. touch: "touchend",
  646. },
  647. _pointerOrigin: null,
  648. _capturedTarget: null,
  649. onDocumentKeyUp: function (b) {
  650. -1 !== ["Tab", "Escape"].indexOf(a.eventKey(b)) && a.picker && a.picker.owner && a.picker.owner.tryHide();
  651. },
  652. onWindowResize: function (b) {
  653. a.redrawPosition();
  654. },
  655. onWindowScroll: function (b) {
  656. a.redrawPosition();
  657. },
  658. onParentScroll: function (b) {
  659. a.picker && a.picker.owner && a.picker.owner.tryHide();
  660. },
  661. onDocumentMouseDown: function (b) {
  662. var d = b.target || b.srcElement;
  663. if (d.frcolorpicker && d.frcolorpicker instanceof a.pub)
  664. d.frcolorpicker.showOnClick && !d.disabled && (a.picker && a.picker.owner ? a.picker.owner.tryHide() : d.frcolorpicker.show());
  665. else if (a.getData(d, "gui")) {
  666. if (a.getData(d, "control")) a.onControlPointerStart(b, d, a.getData(d, "control"), "mouse");
  667. } else a.picker && a.picker.owner && a.picker.owner.tryHide();
  668. },
  669. onPickerTouchStart: function (b) {
  670. var d = b.target || b.srcElement;
  671. if (a.getData(d, "control")) a.onControlPointerStart(b, d, a.getData(d, "control"), "touch");
  672. },
  673. onControlPointerStart: function (b, d, e, g) {
  674. var h = a.getData(d, "instance");
  675. a.preventDefault(b);
  676. a.captureTarget(d);
  677. var l = function (q, v) {
  678. a.attachGroupEvent("drag", q, a._pointerMoveEvent[g], a.onDocumentPointerMove(b, d, e, g, v));
  679. a.attachGroupEvent("drag", q, a._pointerEndEvent[g], a.onDocumentPointerEnd(b, d, e, g));
  680. };
  681. l(window.document, [0, 0]);
  682. if (window.parent && window.frameElement) {
  683. var m = window.frameElement.getBoundingClientRect();
  684. l(window.parent.window.document, [-m.left, -m.top]);
  685. }
  686. l = a.getAbsPointerPos(b);
  687. m = a.getRelPointerPos(b);
  688. a._pointerOrigin = {
  689. x: l.x - m.x,
  690. y: l.y - m.y,
  691. };
  692. switch (e) {
  693. case "pad":
  694. "v" === a.getSliderChannel(h) && 0 === h.channels.v && h.fromHSVA(null, null, 100, null);
  695. a.setPad(h, b, 0, 0);
  696. break;
  697. case "sld":
  698. a.setSld(h, b, 0);
  699. break;
  700. case "asld":
  701. a.setASld(h, b, 0);
  702. }
  703. h.trigger("input");
  704. },
  705. onDocumentPointerMove: function (b, d, e, g, h) {
  706. return function (l) {
  707. var m = a.getData(d, "instance");
  708. switch (e) {
  709. case "pad":
  710. a.setPad(m, l, h[0], h[1]);
  711. break;
  712. case "sld":
  713. a.setSld(m, l, h[1]);
  714. break;
  715. case "asld":
  716. a.setASld(m, l, h[1]);
  717. }
  718. m.trigger("input");
  719. };
  720. },
  721. onDocumentPointerEnd: function (b, d, e, g) {
  722. return function (h) {
  723. h = a.getData(d, "instance");
  724. a.detachGroupEvents("drag");
  725. a.releaseTarget();
  726. h.trigger("input");
  727. h.trigger("change");
  728. };
  729. },
  730. onPaletteSampleClick: function (b) {
  731. var d = b.currentTarget;
  732. b = a.getData(d, "instance");
  733. d = a.getData(d, "color");
  734. "any" === b.format.toLowerCase() && (b._setFormat(d.format), a.isAlphaFormat(b.getFormat()) || (d.rgba[3] = 1));
  735. null === d.rgba[3] && (!0 === b.paletteSetsAlpha || ("auto" === b.paletteSetsAlpha && b._paletteHasTransparency)) && (d.rgba[3] = 1);
  736. b.fromRGBA.apply(b, d.rgba);
  737. b.trigger("input");
  738. b.trigger("change");
  739. b.hideOnPaletteClick && b.hide();
  740. },
  741. setPad: function (b, d, e, g) {
  742. d = a.getAbsPointerPos(d);
  743. e = (360 / (b.width - 1)) * (e + d.x - a._pointerOrigin.x - b.padding - b.controlBorderWidth);
  744. g = 100 - (100 / (b.height - 1)) * (g + d.y - a._pointerOrigin.y - b.padding - b.controlBorderWidth);
  745. switch (a.getPadYChannel(b)) {
  746. case "s":
  747. b.fromHSVA(e, g, null, null);
  748. break;
  749. case "v":
  750. b.fromHSVA(e, null, g, null);
  751. }
  752. },
  753. setSld: function (b, d, e) {
  754. d = a.getAbsPointerPos(d);
  755. e = 100 - (100 / (b.height - 1)) * (e + d.y - a._pointerOrigin.y - b.padding - b.controlBorderWidth);
  756. switch (a.getSliderChannel(b)) {
  757. case "s":
  758. b.fromHSVA(null, e, null, null);
  759. break;
  760. case "v":
  761. b.fromHSVA(null, null, e, null);
  762. }
  763. },
  764. setASld: function (b, d, e) {
  765. d = a.getAbsPointerPos(d);
  766. e = 1 - (1 / (b.height - 1)) * (e + d.y - a._pointerOrigin.y - b.padding - b.controlBorderWidth);
  767. 1 > e && ((d = b.getFormat()), "any" !== b.format.toLowerCase() || a.isAlphaFormat(d) || b._setFormat("hex" === d ? "hexa" : "rgba"));
  768. b.fromHSVA(null, null, null, e);
  769. },
  770. createPadCanvas: function () {
  771. var b = {
  772. elm: null,
  773. draw: null,
  774. },
  775. d = a.createEl("canvas"),
  776. e = d.getContext("2d");
  777. b.elm = d;
  778. b.draw = function (g, h, l) {
  779. d.width = g;
  780. d.height = h;
  781. e.clearRect(0, 0, d.width, d.height);
  782. g = e.createLinearGradient(0, 0, d.width, 0);
  783. g.addColorStop(0, "#F00");
  784. g.addColorStop(1 / 6, "#FF0");
  785. g.addColorStop(2 / 6, "#0F0");
  786. g.addColorStop(0.5, "#0FF");
  787. g.addColorStop(4 / 6, "#00F");
  788. g.addColorStop(5 / 6, "#F0F");
  789. g.addColorStop(1, "#F00");
  790. e.fillStyle = g;
  791. e.fillRect(0, 0, d.width, d.height);
  792. g = e.createLinearGradient(0, 0, 0, d.height);
  793. switch (l.toLowerCase()) {
  794. case "s":
  795. g.addColorStop(0, "rgba(255,255,255,0)");
  796. g.addColorStop(1, "rgba(255,255,255,1)");
  797. break;
  798. case "v":
  799. g.addColorStop(0, "rgba(0,0,0,0)"), g.addColorStop(1, "rgba(0,0,0,1)");
  800. }
  801. e.fillStyle = g;
  802. e.fillRect(0, 0, d.width, d.height);
  803. };
  804. return b;
  805. },
  806. createSliderGradient: function () {
  807. var b = {
  808. elm: null,
  809. draw: null,
  810. },
  811. d = a.createEl("canvas"),
  812. e = d.getContext("2d");
  813. b.elm = d;
  814. b.draw = function (g, h, l, m) {
  815. d.width = g;
  816. d.height = h;
  817. e.clearRect(0, 0, d.width, d.height);
  818. g = e.createLinearGradient(0, 0, 0, d.height);
  819. g.addColorStop(0, l);
  820. g.addColorStop(1, m);
  821. e.fillStyle = g;
  822. e.fillRect(0, 0, d.width, d.height);
  823. };
  824. return b;
  825. },
  826. createASliderGradient: function () {
  827. var b = {
  828. elm: null,
  829. draw: null,
  830. },
  831. d = a.createEl("canvas"),
  832. e = d.getContext("2d");
  833. b.elm = d;
  834. b.draw = function (g, h, l) {
  835. d.width = g;
  836. d.height = h;
  837. e.clearRect(0, 0, d.width, d.height);
  838. g = d.width / 2;
  839. h = a.pub.chessboardColor2;
  840. e.fillStyle = a.pub.chessboardColor1;
  841. e.fillRect(0, 0, d.width, d.height);
  842. if (0 < g) for (var m = 0; m < d.height; m += 2 * g) (e.fillStyle = h), e.fillRect(0, m, g, g), e.fillRect(g, m + g, g, g);
  843. g = e.createLinearGradient(0, 0, 0, d.height);
  844. g.addColorStop(0, l);
  845. g.addColorStop(1, "rgba(0,0,0,0)");
  846. e.fillStyle = g;
  847. e.fillRect(0, 0, d.width, d.height);
  848. };
  849. return b;
  850. },
  851. BoxShadow: (function () {
  852. var b = function (d, e, g, h, l, m) {
  853. this.hShadow = d;
  854. this.vShadow = e;
  855. this.blur = g;
  856. this.spread = h;
  857. this.color = l;
  858. this.inset = !!m;
  859. };
  860. b.prototype.toString = function () {
  861. var d = [Math.round(this.hShadow) + "px", Math.round(this.vShadow) + "px", Math.round(this.blur) + "px", Math.round(this.spread) + "px", this.color];
  862. this.inset && d.push("inset");
  863. return d.join(" ");
  864. };
  865. return b;
  866. })(),
  867. flags: {
  868. leaveValue: 1,
  869. leaveAlpha: 2,
  870. leavePreview: 4,
  871. },
  872. enumOpts: {
  873. format: "auto any hex hexa rgb rgba".split(" "),
  874. previewPosition: ["left", "right"],
  875. mode: ["hsv", "hvs", "hs", "hv"],
  876. position: ["left", "right", "top", "bottom"],
  877. alphaChannel: ["auto", !0, !1],
  878. paletteSetsAlpha: ["auto", !0, !1],
  879. },
  880. deprecatedOpts: {
  881. styleElement: "previewElement",
  882. onFineChange: "onInput",
  883. overwriteImportant: "forceStyle",
  884. closable: "closeButton",
  885. insetWidth: "controlBorderWidth",
  886. insetColor: "controlBorderColor",
  887. refine: null,
  888. },
  889. pub: function (b, d) {
  890. function e(c, k) {
  891. if ("string" !== typeof c) throw Error("Invalid value for option name: " + c);
  892. if (a.enumOpts.hasOwnProperty(c) && ("string" === typeof k && (k = k.toLowerCase()), -1 === a.enumOpts[c].indexOf(k)))
  893. throw Error("Option '" + c + "' has invalid value: " + k);
  894. if (a.deprecatedOpts.hasOwnProperty(c)) {
  895. var p = a.deprecatedOpts[c];
  896. if (p) c = p;
  897. else throw Error("Option '" + c + "' is DEPRECATED");
  898. }
  899. p = "set__" + c;
  900. if ("function" === typeof f[p]) return f[p](k), !0;
  901. if (c in f) return (f[c] = k), !0;
  902. throw Error("Unrecognized configuration option: " + c);
  903. }
  904. function g() {
  905. f._processParentElementsInDOM();
  906. a.picker ||
  907. ((a.picker = {
  908. owner: null,
  909. wrap: a.createEl("fr-colorpicker"),
  910. box: a.createEl("div"),
  911. boxS: a.createEl("div"),
  912. boxB: a.createEl("div"),
  913. pad: a.createEl("div"),
  914. padB: a.createEl("div"),
  915. padM: a.createEl("div"),
  916. padCanvas: a.createPadCanvas(),
  917. cross: a.createEl("div"),
  918. crossBY: a.createEl("div"),
  919. crossBX: a.createEl("div"),
  920. crossLY: a.createEl("div"),
  921. crossLX: a.createEl("div"),
  922. sld: a.createEl("div"),
  923. sldB: a.createEl("div"),
  924. sldM: a.createEl("div"),
  925. sldGrad: a.createSliderGradient(),
  926. sldPtrS: a.createEl("div"),
  927. sldPtrIB: a.createEl("div"),
  928. sldPtrMB: a.createEl("div"),
  929. sldPtrOB: a.createEl("div"),
  930. asld: a.createEl("div"),
  931. asldB: a.createEl("div"),
  932. asldM: a.createEl("div"),
  933. asldGrad: a.createASliderGradient(),
  934. asldPtrS: a.createEl("div"),
  935. asldPtrIB: a.createEl("div"),
  936. asldPtrMB: a.createEl("div"),
  937. asldPtrOB: a.createEl("div"),
  938. pal: a.createEl("div"),
  939. btn: a.createEl("div"),
  940. btnT: a.createEl("span"),
  941. }),
  942. a.picker.pad.appendChild(a.picker.padCanvas.elm),
  943. a.picker.padB.appendChild(a.picker.pad),
  944. a.picker.cross.appendChild(a.picker.crossBY),
  945. a.picker.cross.appendChild(a.picker.crossBX),
  946. a.picker.cross.appendChild(a.picker.crossLY),
  947. a.picker.cross.appendChild(a.picker.crossLX),
  948. a.picker.padB.appendChild(a.picker.cross),
  949. a.picker.box.appendChild(a.picker.padB),
  950. a.picker.box.appendChild(a.picker.padM),
  951. a.picker.sld.appendChild(a.picker.sldGrad.elm),
  952. a.picker.sldB.appendChild(a.picker.sld),
  953. a.picker.sldB.appendChild(a.picker.sldPtrOB),
  954. a.picker.sldPtrOB.appendChild(a.picker.sldPtrMB),
  955. a.picker.sldPtrMB.appendChild(a.picker.sldPtrIB),
  956. a.picker.sldPtrIB.appendChild(a.picker.sldPtrS),
  957. a.picker.box.appendChild(a.picker.sldB),
  958. a.picker.box.appendChild(a.picker.sldM),
  959. a.picker.asld.appendChild(a.picker.asldGrad.elm),
  960. a.picker.asldB.appendChild(a.picker.asld),
  961. a.picker.asldB.appendChild(a.picker.asldPtrOB),
  962. a.picker.asldPtrOB.appendChild(a.picker.asldPtrMB),
  963. a.picker.asldPtrMB.appendChild(a.picker.asldPtrIB),
  964. a.picker.asldPtrIB.appendChild(a.picker.asldPtrS),
  965. a.picker.box.appendChild(a.picker.asldB),
  966. a.picker.box.appendChild(a.picker.asldM),
  967. a.picker.box.appendChild(a.picker.pal),
  968. a.picker.btn.appendChild(a.picker.btnT),
  969. a.picker.box.appendChild(a.picker.btn),
  970. a.picker.boxB.appendChild(a.picker.box),
  971. a.picker.wrap.appendChild(a.picker.boxS),
  972. a.picker.wrap.appendChild(a.picker.boxB),
  973. a.picker.wrap.addEventListener(
  974. "touchstart",
  975. a.onPickerTouchStart,
  976. a.isPassiveEventSupported
  977. ? {
  978. passive: !1,
  979. }
  980. : !1
  981. ));
  982. var c = a.picker,
  983. k = !!a.getSliderChannel(f),
  984. p = f.hasAlphaChannel(),
  985. n = a.getPickerDims(f),
  986. t = 2 * f.pointerBorderWidth + f.pointerThickness + 2 * f.crossSize,
  987. w = a.getControlPadding(f),
  988. z = Math.min(f.borderRadius, Math.round(f.padding * Math.PI)),
  989. u = window.getComputedStyle(document.body, null).getPropertyValue("transform");
  990. u = u && "none" !== u ? Number(u.split(",")[3]) : 0;
  991. var x = Number(window.getComputedStyle(document.body, null).getPropertyValue("zoom")) || 1;
  992. c.wrap.className = J;
  993. c.wrap.style.clear = "both";
  994. c.wrap.style.width = n.borderW + "px";
  995. c.wrap.style.height = n.borderH + "px";
  996. c.wrap.style.zIndex = f.zIndex;
  997. u && 1 !== u
  998. ? ((c.wrap.style.transformOrigin = "left top 0px"), (c.wrap.style.transform = "scale(" + 1 / u + ")"))
  999. : ((c.wrap.style.transformOrigin = null), (c.wrap.style.transform = null));
  1000. c.wrap.style.zoom = x && 1 !== x ? 1 / x : null;
  1001. c.box.className = K;
  1002. c.box.style.width = n.paddedW + "px";
  1003. c.box.style.height = n.paddedH + "px";
  1004. c.box.style.position = "relative";
  1005. c.boxS.className = L;
  1006. c.boxS.style.position = "absolute";
  1007. c.boxS.style.left = "0";
  1008. c.boxS.style.top = "0";
  1009. c.boxS.style.width = "100%";
  1010. c.boxS.style.height = "100%";
  1011. a.setBorderRadius(c.boxS, z + "px");
  1012. c.boxB.className = M;
  1013. c.boxB.style.position = "relative";
  1014. c.boxB.style.border = f.borderWidth + "px solid";
  1015. c.boxB.style.borderColor = f.borderColor;
  1016. c.boxB.style.background = f.backgroundColor;
  1017. a.setBorderRadius(c.boxB, z + "px");
  1018. c.padM.style.background = "rgba(255,0,0,.2)";
  1019. c.sldM.style.background = "rgba(0,255,0,.2)";
  1020. c.asldM.style.background = "rgba(0,0,255,.2)";
  1021. c.padM.style.opacity = c.sldM.style.opacity = c.asldM.style.opacity = "0";
  1022. c.pad.style.position = "relative";
  1023. c.pad.style.width = f.width + "px";
  1024. c.pad.style.height = f.height + "px";
  1025. c.padCanvas.draw(f.width, f.height, a.getPadYChannel(f));
  1026. c.padB.style.position = "absolute";
  1027. c.padB.style.left = f.padding + "px";
  1028. c.padB.style.top = f.padding + "px";
  1029. c.padB.style.border = f.controlBorderWidth + "px solid";
  1030. c.padB.style.borderColor = f.controlBorderColor;
  1031. c.padM.style.position = "absolute";
  1032. c.padM.style.left = "0px";
  1033. c.padM.style.top = "0px";
  1034. c.padM.style.width = f.padding + 2 * f.controlBorderWidth + f.width + w + "px";
  1035. c.padM.style.height = 2 * f.controlBorderWidth + 2 * f.padding + f.height + "px";
  1036. c.padM.style.cursor = "crosshair";
  1037. a.setData(c.padM, {
  1038. instance: f,
  1039. control: "pad",
  1040. });
  1041. c.cross.style.position = "absolute";
  1042. c.cross.style.left = c.cross.style.top = "0";
  1043. c.cross.style.width = c.cross.style.height = t + "px";
  1044. c.crossBY.style.position = c.crossBX.style.position = "absolute";
  1045. c.crossBY.style.background = c.crossBX.style.background = f.pointerBorderColor;
  1046. c.crossBY.style.width = c.crossBX.style.height = 2 * f.pointerBorderWidth + f.pointerThickness + "px";
  1047. c.crossBY.style.height = c.crossBX.style.width = t + "px";
  1048. c.crossBY.style.left = c.crossBX.style.top = Math.floor(t / 2) - Math.floor(f.pointerThickness / 2) - f.pointerBorderWidth + "px";
  1049. c.crossBY.style.top = c.crossBX.style.left = "0";
  1050. c.crossLY.style.position = c.crossLX.style.position = "absolute";
  1051. c.crossLY.style.background = c.crossLX.style.background = f.pointerColor;
  1052. c.crossLY.style.height = c.crossLX.style.width = t - 2 * f.pointerBorderWidth + "px";
  1053. c.crossLY.style.width = c.crossLX.style.height = f.pointerThickness + "px";
  1054. c.crossLY.style.left = c.crossLX.style.top = Math.floor(t / 2) - Math.floor(f.pointerThickness / 2) + "px";
  1055. c.crossLY.style.top = c.crossLX.style.left = f.pointerBorderWidth + "px";
  1056. c.sld.style.overflow = "hidden";
  1057. c.sld.style.width = f.sliderSize + "px";
  1058. c.sld.style.height = f.height + "px";
  1059. c.sldGrad.draw(f.sliderSize, f.height, "#000", "#000");
  1060. c.sldB.style.display = k ? "block" : "none";
  1061. c.sldB.style.position = "absolute";
  1062. c.sldB.style.left = f.padding + f.width + 2 * f.controlBorderWidth + 2 * w + "px";
  1063. c.sldB.style.top = f.padding + "px";
  1064. c.sldB.style.border = f.controlBorderWidth + "px solid";
  1065. c.sldB.style.borderColor = f.controlBorderColor;
  1066. c.sldM.style.display = k ? "block" : "none";
  1067. c.sldM.style.position = "absolute";
  1068. c.sldM.style.left = f.padding + f.width + 2 * f.controlBorderWidth + w + "px";
  1069. c.sldM.style.top = "0px";
  1070. c.sldM.style.width = f.sliderSize + 2 * w + 2 * f.controlBorderWidth + (p ? 0 : Math.max(0, f.padding - w)) + "px";
  1071. c.sldM.style.height = 2 * f.controlBorderWidth + 2 * f.padding + f.height + "px";
  1072. c.sldM.style.cursor = "default";
  1073. a.setData(c.sldM, {
  1074. instance: f,
  1075. control: "sld",
  1076. });
  1077. c.sldPtrIB.style.border = c.sldPtrOB.style.border = f.pointerBorderWidth + "px solid " + f.pointerBorderColor;
  1078. c.sldPtrOB.style.position = "absolute";
  1079. c.sldPtrOB.style.left = -(2 * f.pointerBorderWidth + f.pointerThickness) + "px";
  1080. c.sldPtrOB.style.top = "0";
  1081. c.sldPtrMB.style.border = f.pointerThickness + "px solid " + f.pointerColor;
  1082. c.sldPtrS.style.width = f.sliderSize + "px";
  1083. c.sldPtrS.style.height = a.pub.sliderInnerSpace + "px";
  1084. c.asld.style.overflow = "hidden";
  1085. c.asld.style.width = f.sliderSize + "px";
  1086. c.asld.style.height = f.height + "px";
  1087. c.asldGrad.draw(f.sliderSize, f.height, "#000");
  1088. c.asldB.style.display = p ? "block" : "none";
  1089. c.asldB.style.position = "absolute";
  1090. c.asldB.style.left = f.padding + f.width + 2 * f.controlBorderWidth + w + (k ? f.sliderSize + 3 * w + 2 * f.controlBorderWidth : 0) + "px";
  1091. c.asldB.style.top = f.padding + "px";
  1092. c.asldB.style.border = f.controlBorderWidth + "px solid";
  1093. c.asldB.style.borderColor = f.controlBorderColor;
  1094. c.asldM.style.display = p ? "block" : "none";
  1095. c.asldM.style.position = "absolute";
  1096. c.asldM.style.left = f.padding + f.width + 2 * f.controlBorderWidth + w + (k ? f.sliderSize + 2 * w + 2 * f.controlBorderWidth : 0) + "px";
  1097. c.asldM.style.top = "0px";
  1098. c.asldM.style.width = f.sliderSize + 2 * w + 2 * f.controlBorderWidth + Math.max(0, f.padding - w) + "px";
  1099. c.asldM.style.height = 2 * f.controlBorderWidth + 2 * f.padding + f.height + "px";
  1100. c.asldM.style.cursor = "default";
  1101. a.setData(c.asldM, {
  1102. instance: f,
  1103. control: "asld",
  1104. });
  1105. c.asldPtrIB.style.border = c.asldPtrOB.style.border = f.pointerBorderWidth + "px solid " + f.pointerBorderColor;
  1106. c.asldPtrOB.style.position = "absolute";
  1107. c.asldPtrOB.style.left = -(2 * f.pointerBorderWidth + f.pointerThickness) + "px";
  1108. c.asldPtrOB.style.top = "0";
  1109. c.asldPtrMB.style.border = f.pointerThickness + "px solid " + f.pointerColor;
  1110. c.asldPtrS.style.width = f.sliderSize + "px";
  1111. c.asldPtrS.style.height = a.pub.sliderInnerSpace + "px";
  1112. c.pal.className = N;
  1113. c.pal.style.display = n.palette.rows ? "block" : "none";
  1114. c.pal.style.position = "absolute";
  1115. c.pal.style.left = f.padding + "px";
  1116. c.pal.style.top = 2 * f.controlBorderWidth + 2 * f.padding + f.height + "px";
  1117. c.pal.innerText = "";
  1118. k = a.genColorPreviewCanvas("rgba(0,0,0,0)");
  1119. for (t = p = 0; t < n.palette.rows; t++)
  1120. for (w = 0; w < n.palette.cols && p < f._palette.length; w++, p++)
  1121. (z = f._palette[p]),
  1122. (x = a.rgbaColor.apply(null, z.rgba)),
  1123. (u = a.createEl("div")),
  1124. (u.style.width = n.palette.cellW - 2 * f.controlBorderWidth + "px"),
  1125. (u.style.height = n.palette.cellH - 2 * f.controlBorderWidth + "px"),
  1126. (u.style.backgroundColor = x),
  1127. (x = a.createEl("div")),
  1128. (x.className = O),
  1129. (x.style.display = "block"),
  1130. (x.style.position = "absolute"),
  1131. (x.style.left = (1 >= n.palette.cols ? 0 : Math.round(((n.contentW - n.palette.cellW) / (n.palette.cols - 1)) * 10 * w) / 10) + "px"),
  1132. (x.style.top = t * (n.palette.cellH + f.paletteSpacing) + "px"),
  1133. (x.style.border = f.controlBorderWidth + "px solid"),
  1134. (x.style.borderColor = f.controlBorderColor),
  1135. (x.style.cursor = "pointer"),
  1136. null !== z.rgba[3] &&
  1137. 1 > z.rgba[3] &&
  1138. ((x.style.backgroundImage = "url('" + k.canvas.toDataURL() + "')"), (x.style.backgroundRepeat = "repeat"), (x.style.backgroundPosition = "center center")),
  1139. a.setData(x, {
  1140. instance: f,
  1141. control: "palette-sample",
  1142. color: z,
  1143. }),
  1144. x.addEventListener("click", a.onPaletteSampleClick, !1),
  1145. x.appendChild(u),
  1146. c.pal.appendChild(x);
  1147. c.btn.className = P;
  1148. c.btn.style.display = f.closeButton ? "block" : "none";
  1149. c.btn.style.position = "absolute";
  1150. c.btn.style.left = f.padding + "px";
  1151. c.btn.style.bottom = f.padding + "px";
  1152. c.btn.style.padding = "0 15px";
  1153. c.btn.style.maxWidth = n.contentW - 2 * f.controlBorderWidth - 30 + "px";
  1154. c.btn.style.overflow = "hidden";
  1155. c.btn.style.height = f.buttonHeight + "px";
  1156. c.btn.style.whiteSpace = "nowrap";
  1157. c.btn.style.border = f.controlBorderWidth + "px solid";
  1158. (function () {
  1159. var D = f.controlBorderColor.split(/\s+/);
  1160. c.btn.style.borderColor = 2 > D.length ? D[0] : D[1] + " " + D[0] + " " + D[0] + " " + D[1];
  1161. })();
  1162. c.btn.style.color = f.buttonColor;
  1163. c.btn.style.font = "12px sans-serif";
  1164. c.btn.style.textAlign = "center";
  1165. c.btn.style.cursor = "pointer";
  1166. c.btn.onmousedown = function () {
  1167. f.hide();
  1168. };
  1169. c.btnT.style.lineHeight = f.buttonHeight + "px";
  1170. c.btnT.innerText = "";
  1171. c.btnT.appendChild(window.document.createTextNode(f.closeText));
  1172. h();
  1173. l();
  1174. m();
  1175. a.picker.owner && a.picker.owner !== f && a.removeClass(a.picker.owner.targetElement, a.pub.activeClassName);
  1176. a.picker.owner = f;
  1177. f.container === window.document.body ? a.redrawPosition() : a._drawPosition(f, 0, 0, "relative", !1);
  1178. c.wrap.parentNode !== f.container && f.container.appendChild(c.wrap);
  1179. a.addClass(f.targetElement, a.pub.activeClassName);
  1180. }
  1181. function h() {
  1182. var c = a.getPadYChannel(f);
  1183. c = Math.round((1 - f.channels[c] / 100) * (f.height - 1));
  1184. var k = -Math.floor((2 * f.pointerBorderWidth + f.pointerThickness + 2 * f.crossSize) / 2);
  1185. a.picker.cross.style.left = Math.round((f.channels.h / 360) * (f.width - 1)) + k + "px";
  1186. a.picker.cross.style.top = c + k + "px";
  1187. switch (a.getSliderChannel(f)) {
  1188. case "s":
  1189. k = a.HSV_RGB(f.channels.h, 100, f.channels.v);
  1190. c = a.HSV_RGB(f.channels.h, 0, f.channels.v);
  1191. k = "rgb(" + Math.round(k[0]) + "," + Math.round(k[1]) + "," + Math.round(k[2]) + ")";
  1192. a.picker.sldGrad.draw(f.sliderSize, f.height, k, "rgb(" + Math.round(c[0]) + "," + Math.round(c[1]) + "," + Math.round(c[2]) + ")");
  1193. break;
  1194. case "v":
  1195. (c = a.HSV_RGB(f.channels.h, f.channels.s, 100)),
  1196. (k = "rgb(" + Math.round(c[0]) + "," + Math.round(c[1]) + "," + Math.round(c[2]) + ")"),
  1197. a.picker.sldGrad.draw(f.sliderSize, f.height, k, "#000");
  1198. }
  1199. a.picker.asldGrad.draw(f.sliderSize, f.height, f.toHEXString());
  1200. }
  1201. function l() {
  1202. var c = a.getSliderChannel(f);
  1203. c &&
  1204. (a.picker.sldPtrOB.style.top =
  1205. Math.round((1 - f.channels[c] / 100) * (f.height - 1)) - (2 * f.pointerBorderWidth + f.pointerThickness) - Math.floor(a.pub.sliderInnerSpace / 2) + "px");
  1206. a.picker.asldGrad.draw(f.sliderSize, f.height, f.toHEXString());
  1207. }
  1208. function m() {
  1209. a.picker.asldPtrOB.style.top =
  1210. Math.round((1 - f.channels.a) * (f.height - 1)) - (2 * f.pointerBorderWidth + f.pointerThickness) - Math.floor(a.pub.sliderInnerSpace / 2) + "px";
  1211. }
  1212. function q() {
  1213. return a.picker && a.picker.owner === f;
  1214. }
  1215. function v(c) {
  1216. "Enter" === a.eventKey(c) && (f.valueElement && f.processValueInput(f.valueElement.value), f.tryHide());
  1217. }
  1218. function r(c) {
  1219. "Enter" === a.eventKey(c) && (f.alphaElement && f.processAlphaInput(f.alphaElement.value), f.tryHide());
  1220. }
  1221. function y(c) {
  1222. a.getData(c, "internal") ||
  1223. ((c = f.valueElement.value),
  1224. f.processValueInput(f.valueElement.value),
  1225. a.triggerCallback(f, "onChange"),
  1226. f.valueElement.value !== c && a.triggerInputEvent(f.valueElement, "change", !0, !0));
  1227. }
  1228. function Q(c) {
  1229. a.getData(c, "internal") ||
  1230. ((c = f.alphaElement.value),
  1231. f.processAlphaInput(f.alphaElement.value),
  1232. a.triggerCallback(f, "onChange"),
  1233. a.triggerInputEvent(f.valueElement, "change", !0, !0),
  1234. f.alphaElement.value !== c && a.triggerInputEvent(f.alphaElement, "change", !0, !0));
  1235. }
  1236. function R(c) {
  1237. a.getData(c, "internal") || (f.valueElement && f.fromString(f.valueElement.value, a.flags.leaveValue), a.triggerCallback(f, "onInput"));
  1238. }
  1239. function S(c) {
  1240. a.getData(c, "internal") ||
  1241. (f.alphaElement && f.fromHSVA(null, null, null, parseFloat(f.alphaElement.value), a.flags.leaveAlpha),
  1242. a.triggerCallback(f, "onInput"),
  1243. a.triggerInputEvent(f.valueElement, "input", !0, !0));
  1244. }
  1245. var f = this;
  1246. d || (d = {});
  1247. this.channels = {
  1248. r: 255,
  1249. g: 255,
  1250. b: 255,
  1251. h: 0,
  1252. s: 0,
  1253. v: 100,
  1254. a: 1,
  1255. };
  1256. this.format = "auto";
  1257. this.alpha = this.value = void 0;
  1258. this.random = !1;
  1259. this.previewElement = this.alphaElement = this.valueElement = this.onInput = this.onChange = void 0;
  1260. this.previewPosition = "left";
  1261. this.previewSize = 32;
  1262. this.previewPadding = 8;
  1263. this.forceStyle = this.uppercase = this.hash = this.required = !0;
  1264. this.width = 181;
  1265. this.height = 101;
  1266. this.mode = "HSV";
  1267. this.alphaChannel = "auto";
  1268. this.position = "bottom";
  1269. this.hideOnLeave = this.showOnClick = this.smartPosition = !0;
  1270. this.palette = [];
  1271. this.paletteCols = 10;
  1272. this.paletteSetsAlpha = "auto";
  1273. this.paletteHeight = 16;
  1274. this.paletteSpacing = 4;
  1275. this.hideOnPaletteClick = !1;
  1276. this.sliderSize = 16;
  1277. this.crossSize = 8;
  1278. this.closeButton = !1;
  1279. this.closeText = "Close";
  1280. this.buttonColor = "rgba(0,0,0,1)";
  1281. this.buttonHeight = 18;
  1282. this.padding = 12;
  1283. this.backgroundColor = "rgba(255,255,255,1)";
  1284. this.borderWidth = 1;
  1285. this.borderColor = "rgba(187,187,187,1)";
  1286. this.borderRadius = 8;
  1287. this.controlBorderWidth = 1;
  1288. this.controlBorderColor = "rgba(187,187,187,1)";
  1289. this.shadow = !0;
  1290. this.shadowBlur = 15;
  1291. this.shadowColor = "rgba(0,0,0,0.2)";
  1292. this.pointerColor = "rgba(76,76,76,1)";
  1293. this.pointerBorderWidth = 1;
  1294. this.pointerBorderColor = "rgba(255,255,255,1)";
  1295. this.pointerThickness = 2;
  1296. this.zIndex = 999999;
  1297. this.container = void 0;
  1298. this.minS = 0;
  1299. this.maxS = 100;
  1300. this.minV = 0;
  1301. this.maxV = 100;
  1302. this.minA = 0;
  1303. this.maxA = 1;
  1304. this.option = function () {
  1305. if (!arguments.length) throw Error("No option specified");
  1306. if (1 === arguments.length && "string" === typeof arguments[0]) {
  1307. try {
  1308. var c = arguments[0];
  1309. if ("string" !== typeof c) throw Error("Invalid value for option name: " + c);
  1310. if (a.deprecatedOpts.hasOwnProperty(c)) {
  1311. var k = a.deprecatedOpts[c];
  1312. if (k) c = k;
  1313. else throw Error("Option '" + c + "' is DEPRECATED");
  1314. }
  1315. var p = "get__" + c;
  1316. if ("function" === typeof f[p]) var n = f[p](value);
  1317. else if (c in f) n = f[c];
  1318. else throw Error("Unrecognized configuration option: " + c);
  1319. return n;
  1320. } catch (t) {}
  1321. return !1;
  1322. }
  1323. if (2 <= arguments.length && "string" === typeof arguments[0]) {
  1324. try {
  1325. if (!e(arguments[0], arguments[1])) return !1;
  1326. } catch (t) {
  1327. return !1;
  1328. }
  1329. this.redraw();
  1330. this.exposeColor();
  1331. return !0;
  1332. }
  1333. if (1 === arguments.length && "object" === typeof arguments[0]) {
  1334. n = arguments[0];
  1335. c = !0;
  1336. for (p in n)
  1337. if (n.hasOwnProperty(p))
  1338. try {
  1339. e(p, n[p]) || (c = !1);
  1340. } catch (t) {
  1341. c = !1;
  1342. }
  1343. this.redraw();
  1344. this.exposeColor();
  1345. return c;
  1346. }
  1347. throw Error("Invalid arguments");
  1348. };
  1349. this.channel = function (c, k) {
  1350. if ("string" !== typeof c) throw Error("Invalid value for channel name: " + c);
  1351. if (void 0 === k) return this.channels.hasOwnProperty(c.toLowerCase()) ? this.channels[c.toLowerCase()] : !1;
  1352. switch (c.toLowerCase()) {
  1353. case "r":
  1354. c = this.fromRGBA(k, null, null, null);
  1355. break;
  1356. case "g":
  1357. c = this.fromRGBA(null, k, null, null);
  1358. break;
  1359. case "b":
  1360. c = this.fromRGBA(null, null, k, null);
  1361. break;
  1362. case "h":
  1363. c = this.fromHSVA(k, null, null, null);
  1364. break;
  1365. case "s":
  1366. c = this.fromHSVA(null, k, null, null);
  1367. break;
  1368. case "v":
  1369. c = this.fromHSVA(null, null, k, null);
  1370. break;
  1371. case "a":
  1372. c = this.fromHSVA(null, null, null, k);
  1373. break;
  1374. default:
  1375. return !1;
  1376. }
  1377. return c ? (this.redraw(), !0) : !1;
  1378. };
  1379. this.trigger = function (c) {
  1380. c = a.strList(c);
  1381. for (var k = 0; k < c.length; k += 1) {
  1382. var p = c[k].toLowerCase(),
  1383. n = null;
  1384. switch (p) {
  1385. case "input":
  1386. n = "onInput";
  1387. break;
  1388. case "change":
  1389. n = "onChange";
  1390. }
  1391. n && a.triggerCallback(this, n);
  1392. a.triggerInputEvent(this.valueElement, p, !0, !0);
  1393. }
  1394. };
  1395. this.fromHSVA = function (c, k, p, n, t) {
  1396. void 0 === c && (c = null);
  1397. void 0 === k && (k = null);
  1398. void 0 === p && (p = null);
  1399. void 0 === n && (n = null);
  1400. if (null !== c) {
  1401. if (isNaN(c)) return !1;
  1402. this.channels.h = Math.max(0, Math.min(360, c));
  1403. }
  1404. if (null !== k) {
  1405. if (isNaN(k)) return !1;
  1406. this.channels.s = Math.max(0, Math.min(100, this.maxS, k), this.minS);
  1407. }
  1408. if (null !== p) {
  1409. if (isNaN(p)) return !1;
  1410. this.channels.v = Math.max(0, Math.min(100, this.maxV, p), this.minV);
  1411. }
  1412. if (null !== n) {
  1413. if (isNaN(n)) return !1;
  1414. this.channels.a = this.hasAlphaChannel() ? Math.max(0, Math.min(1, this.maxA, n), this.minA) : 1;
  1415. }
  1416. c = a.HSV_RGB(this.channels.h, this.channels.s, this.channels.v);
  1417. this.channels.r = c[0];
  1418. this.channels.g = c[1];
  1419. this.channels.b = c[2];
  1420. this.exposeColor(t);
  1421. return !0;
  1422. };
  1423. this.fromRGBA = function (c, k, p, n, t) {
  1424. void 0 === c && (c = null);
  1425. void 0 === k && (k = null);
  1426. void 0 === p && (p = null);
  1427. void 0 === n && (n = null);
  1428. if (null !== c) {
  1429. if (isNaN(c)) return !1;
  1430. c = Math.max(0, Math.min(255, c));
  1431. }
  1432. if (null !== k) {
  1433. if (isNaN(k)) return !1;
  1434. k = Math.max(0, Math.min(255, k));
  1435. }
  1436. if (null !== p) {
  1437. if (isNaN(p)) return !1;
  1438. p = Math.max(0, Math.min(255, p));
  1439. }
  1440. if (null !== n) {
  1441. if (isNaN(n)) return !1;
  1442. this.channels.a = this.hasAlphaChannel() ? Math.max(0, Math.min(1, this.maxA, n), this.minA) : 1;
  1443. }
  1444. c = a.RGB_HSV(null === c ? this.channels.r : c, null === k ? this.channels.g : k, null === p ? this.channels.b : p);
  1445. null !== c[0] && (this.channels.h = Math.max(0, Math.min(360, c[0])));
  1446. 0 !== c[2] && (this.channels.s = Math.max(0, this.minS, Math.min(100, this.maxS, c[1])));
  1447. this.channels.v = Math.max(0, this.minV, Math.min(100, this.maxV, c[2]));
  1448. c = a.HSV_RGB(this.channels.h, this.channels.s, this.channels.v);
  1449. this.channels.r = c[0];
  1450. this.channels.g = c[1];
  1451. this.channels.b = c[2];
  1452. this.exposeColor(t);
  1453. return !0;
  1454. };
  1455. this.fromHSV = function (c, k, p, n) {
  1456. return this.fromHSVA(c, k, p, null, n);
  1457. };
  1458. this.fromRGB = function (c, k, p, n) {
  1459. return this.fromRGBA(c, k, p, null, n);
  1460. };
  1461. this.fromString = function (c, k) {
  1462. if (!this.required && "" === c.trim()) return this.setPreviewElementBg(null), this.setValueElementValue(""), !0;
  1463. c = a.parseColorString(c);
  1464. if (!c) return !1;
  1465. "any" === this.format.toLowerCase() && (this._setFormat(c.format), a.isAlphaFormat(this.getFormat()) || (c.rgba[3] = 1));
  1466. this.fromRGBA(c.rgba[0], c.rgba[1], c.rgba[2], c.rgba[3], k);
  1467. return !0;
  1468. };
  1469. this.randomize = function (c, k, p, n, t, w, z, u) {
  1470. void 0 === c && (c = 0);
  1471. void 0 === k && (k = 100);
  1472. void 0 === p && (p = 0);
  1473. void 0 === n && (n = 100);
  1474. void 0 === t && (t = 0);
  1475. void 0 === w && (w = 359);
  1476. void 0 === z && (z = 1);
  1477. void 0 === u && (u = 1);
  1478. this.fromHSVA(
  1479. t + Math.floor(Math.random() * (w - t + 1)),
  1480. p + Math.floor(Math.random() * (n - p + 1)),
  1481. c + Math.floor(Math.random() * (k - c + 1)),
  1482. (100 * z + Math.floor(Math.random() * (100 * (u - z) + 1))) / 100
  1483. );
  1484. };
  1485. this.toString = function (c) {
  1486. void 0 === c && (c = this.getFormat());
  1487. switch (c.toLowerCase()) {
  1488. case "hex":
  1489. return this.toHEXString();
  1490. case "hexa":
  1491. return this.toHEXAString();
  1492. case "rgb":
  1493. return this.toRGBString();
  1494. case "rgba":
  1495. return this.toRGBAString();
  1496. }
  1497. return !1;
  1498. };
  1499. this.toHEXString = function () {
  1500. return a.hexColor(this.channels.r, this.channels.g, this.channels.b);
  1501. };
  1502. this.toHEXAString = function () {
  1503. return a.hexaColor(this.channels.r, this.channels.g, this.channels.b, this.channels.a);
  1504. };
  1505. this.toRGBString = function () {
  1506. return a.rgbColor(this.channels.r, this.channels.g, this.channels.b);
  1507. };
  1508. this.toRGBAString = function () {
  1509. return a.rgbaColor(this.channels.r, this.channels.g, this.channels.b, this.channels.a);
  1510. };
  1511. this.toGrayscale = function () {
  1512. return 0.213 * this.channels.r + 0.715 * this.channels.g + 0.072 * this.channels.b;
  1513. };
  1514. this.toCanvas = function () {
  1515. return a.genColorPreviewCanvas(this.toRGBAString()).canvas;
  1516. };
  1517. this.toDataURL = function () {
  1518. return this.toCanvas().toDataURL();
  1519. };
  1520. this.toBackground = function () {
  1521. return a.pub.background(this.toRGBAString());
  1522. };
  1523. this.isLight = function () {
  1524. return 127.5 < this.toGrayscale();
  1525. };
  1526. this.hide = function () {
  1527. q() &&
  1528. (a.removeClass(f.targetElement, a.pub.activeClassName),
  1529. a.picker.wrap && a.picker.wrap.parentNode && a.picker.wrap.parentNode.removeChild(a.picker.wrap),
  1530. delete a.picker.owner);
  1531. };
  1532. this.show = function () {
  1533. g();
  1534. };
  1535. this.redraw = function () {
  1536. q() && g();
  1537. };
  1538. this.getFormat = function () {
  1539. return this._currentFormat;
  1540. };
  1541. this._setFormat = function (c) {
  1542. this._currentFormat = c.toLowerCase();
  1543. };
  1544. this.hasAlphaChannel = function () {
  1545. return "auto" === this.alphaChannel
  1546. ? "any" === this.format.toLowerCase() || a.isAlphaFormat(this.getFormat()) || void 0 !== this.alpha || void 0 !== this.alphaElement
  1547. : this.alphaChannel;
  1548. };
  1549. this.processValueInput = function (c) {
  1550. this.fromString(c) || this.exposeColor();
  1551. };
  1552. this.processAlphaInput = function (c) {
  1553. this.fromHSVA(null, null, null, parseFloat(c)) || this.exposeColor();
  1554. };
  1555. this.exposeColor = function (c) {
  1556. var k = this.toString(),
  1557. p = this.getFormat();
  1558. a.setDataAttr(this.targetElement, "current-color", k);
  1559. if (!(c & a.flags.leaveValue) && this.valueElement) {
  1560. if ("hex" === p || "hexa" === p) this.uppercase || (k = k.toLowerCase()), this.hash || (k = k.replace(/^#/, ""));
  1561. this.setValueElementValue(k);
  1562. }
  1563. c & a.flags.leaveAlpha || !this.alphaElement || this.setAlphaElementValue(Math.round(100 * this.channels.a) / 100);
  1564. c & a.flags.leavePreview ||
  1565. !this.previewElement ||
  1566. (a.isTextInput(this.previewElement) || (a.isButton(this.previewElement) && a.isButtonEmpty(this.previewElement)), this.setPreviewElementBg(this.toRGBAString()));
  1567. q() && (h(), l(), m());
  1568. };
  1569. this.setPreviewElementBg = function (c) {
  1570. if (this.previewElement) {
  1571. var k = null,
  1572. p = null;
  1573. if (a.isTextInput(this.previewElement) || (a.isButton(this.previewElement) && !a.isButtonEmpty(this.previewElement)))
  1574. (k = this.previewPosition), (p = this.previewSize);
  1575. var n = [];
  1576. c
  1577. ? (n.push({
  1578. image: a.genColorPreviewGradient(c, k, p ? p - a.pub.previewSeparator.length : null),
  1579. position: "left top",
  1580. size: "auto",
  1581. repeat: k ? "repeat-y" : "repeat",
  1582. origin: "padding-box",
  1583. }),
  1584. (c = a.genColorPreviewCanvas(
  1585. "rgba(0,0,0,0)",
  1586. k
  1587. ? {
  1588. left: "right",
  1589. right: "left",
  1590. }[k]
  1591. : null,
  1592. p,
  1593. !0
  1594. )),
  1595. n.push({
  1596. image: "url('" + c.canvas.toDataURL() + "')",
  1597. position: (k || "left") + " top",
  1598. size: c.width + "px " + c.height + "px",
  1599. repeat: k ? "repeat-y" : "repeat",
  1600. origin: "padding-box",
  1601. }))
  1602. : n.push({
  1603. image: "none",
  1604. position: "left top",
  1605. size: "auto",
  1606. repeat: "no-repeat",
  1607. origin: "padding-box",
  1608. });
  1609. c = [];
  1610. p = [];
  1611. for (var t = [], w = [], z = [], u = 0; u < n.length; u += 1) c.push(n[u].image), p.push(n[u].position), t.push(n[u].size), w.push(n[u].repeat), z.push(n[u].origin);
  1612. n = {
  1613. "background-image": c.join(", "),
  1614. "background-position": p.join(", "),
  1615. "background-size": t.join(", "),
  1616. "background-repeat": w.join(", "),
  1617. "background-origin": z.join(", "),
  1618. };
  1619. a.setStyle(this.previewElement, n, this.forceStyle);
  1620. n = {
  1621. left: null,
  1622. right: null,
  1623. };
  1624. k && (n[k] = this.previewSize + this.previewPadding + "px");
  1625. n = {
  1626. "padding-left": n.left,
  1627. "padding-right": n.right,
  1628. };
  1629. a.setStyle(this.previewElement, n, this.forceStyle, !0);
  1630. }
  1631. };
  1632. this.setValueElementValue = function (c) {
  1633. this.valueElement && ("input" === a.nodeName(this.valueElement) ? (this.valueElement.value = c) : (this.valueElement.innerHTML = E.createHTML(c)));
  1634. };
  1635. this.setAlphaElementValue = function (c) {
  1636. this.alphaElement && ("input" === a.nodeName(this.alphaElement) ? (this.alphaElement.value = c) : (this.alphaElement.innerHTML = E.createHTML(c)));
  1637. };
  1638. this._processParentElementsInDOM = function () {
  1639. if (!this._parentElementsProcessed) {
  1640. this._parentElementsProcessed = !0;
  1641. var c = this.targetElement;
  1642. do {
  1643. var k = a.getCompStyle(c);
  1644. k.position && "fixed" === k.position.toLowerCase() && (this.fixed = !0);
  1645. c === this.targetElement || a.getData(c, "hasScrollListener") || (c.addEventListener("scroll", a.onParentScroll, !1), a.setData(c, "hasScrollListener", !0));
  1646. } while ((c = c.parentNode) && "body" !== a.nodeName(c));
  1647. }
  1648. };
  1649. this.tryHide = function () {
  1650. this.hideOnLeave && this.hide();
  1651. };
  1652. this.set__palette = function (c) {
  1653. this.palette = c;
  1654. this._palette = a.parsePaletteValue(c);
  1655. this._paletteHasTransparency = a.containsTranparentColor(this._palette);
  1656. };
  1657. if (a.pub.options)
  1658. for (var A in a.pub.options)
  1659. if (a.pub.options.hasOwnProperty(A))
  1660. try {
  1661. e(A, a.pub.options[A]);
  1662. } catch (c) {}
  1663. var C = [];
  1664. d.preset && ("string" === typeof d.preset ? (C = d.preset.split(/\s+/)) : Array.isArray(d.preset) && (C = d.preset.slice()));
  1665. -1 === C.indexOf("default") && C.push("default");
  1666. for (var G = C.length - 1; 0 <= G; --G) {
  1667. var F = C[G];
  1668. if (F && a.pub.presets.hasOwnProperty(F))
  1669. for (A in a.pub.presets[F])
  1670. if (a.pub.presets[F].hasOwnProperty(A))
  1671. try {
  1672. e(A, a.pub.presets[F][A]);
  1673. } catch (c) {}
  1674. }
  1675. C = ["preset"];
  1676. for (A in d)
  1677. if (d.hasOwnProperty(A) && -1 === C.indexOf(A))
  1678. try {
  1679. e(A, d[A]);
  1680. } catch (c) {}
  1681. this.container = void 0 === this.container ? window.document.body : a.node(this.container);
  1682. if (!this.container) throw Error("No container element");
  1683. this.targetElement = a.node(b);
  1684. if (!this.targetElement) {
  1685. if ("string" === typeof b && /^[a-zA-Z][\w:.-]*$/.test(b)) throw Error("Need CSS selector.");
  1686. throw Error("No target element");
  1687. }
  1688. if (this.targetElement.frcolorpicker && this.targetElement.frcolorpicker instanceof a.pub) throw Error("Redundant element");
  1689. this.targetElement.frcolorpicker = this;
  1690. a.addClass(this.targetElement, a.pub.className);
  1691. a.instances.push(this);
  1692. a.isButton(this.targetElement) &&
  1693. ("button" !== this.targetElement.type.toLowerCase() && (this.targetElement.type = "button"),
  1694. a.isButtonEmpty(this.targetElement) &&
  1695. (a.removeChildren(this.targetElement),
  1696. this.targetElement.appendChild(window.document.createTextNode("\u00a0")),
  1697. (b = a.getCompStyle(this.targetElement)),
  1698. (parseFloat(b["min-width"]) || 0) < this.previewSize &&
  1699. a.setStyle(
  1700. this.targetElement,
  1701. {
  1702. "min-width": this.previewSize + "px",
  1703. },
  1704. this.forceStyle
  1705. )));
  1706. void 0 === this.valueElement
  1707. ? a.isTextInput(this.targetElement) && (this.valueElement = this.targetElement)
  1708. : null !== this.valueElement && (this.valueElement = a.node(this.valueElement));
  1709. this.alphaElement && (this.alphaElement = a.node(this.alphaElement));
  1710. void 0 === this.previewElement ? (this.previewElement = this.targetElement) : null !== this.previewElement && (this.previewElement = a.node(this.previewElement));
  1711. this.valueElement &&
  1712. a.isTextInput(this.valueElement) &&
  1713. ((b = this.valueElement.oninput),
  1714. (this.valueElement.oninput = null),
  1715. this.valueElement.addEventListener("keydown", v, !1),
  1716. this.valueElement.addEventListener("change", y, !1),
  1717. this.valueElement.addEventListener("input", R, !1),
  1718. b && this.valueElement.addEventListener("input", b, !1),
  1719. this.valueElement.setAttribute("autocomplete", "off"),
  1720. this.valueElement.setAttribute("autocorrect", "off"),
  1721. this.valueElement.setAttribute("autocapitalize", "off"),
  1722. this.valueElement.setAttribute("spellcheck", !1));
  1723. this.alphaElement &&
  1724. a.isTextInput(this.alphaElement) &&
  1725. (this.alphaElement.addEventListener("keydown", r, !1),
  1726. this.alphaElement.addEventListener("change", Q, !1),
  1727. this.alphaElement.addEventListener("input", S, !1),
  1728. this.alphaElement.setAttribute("autocomplete", "off"),
  1729. this.alphaElement.setAttribute("autocorrect", "off"),
  1730. this.alphaElement.setAttribute("autocapitalize", "off"),
  1731. this.alphaElement.setAttribute("spellcheck", !1));
  1732. b = "FFFFFF";
  1733. void 0 !== this.value ? (b = this.value) : this.valueElement && void 0 !== this.valueElement.value && (b = this.valueElement.value);
  1734. d = void 0;
  1735. void 0 !== this.alpha ? (d = "" + this.alpha) : this.alphaElement && void 0 !== this.alphaElement.value && (d = this.alphaElement.value);
  1736. this._currentFormat = null;
  1737. -1 < ["auto", "any"].indexOf(this.format.toLowerCase())
  1738. ? (this._currentFormat = (A = a.parseColorString(b)) ? A.format : "hex")
  1739. : (this._currentFormat = this.format.toLowerCase());
  1740. this.processValueInput(b);
  1741. void 0 !== d && this.processAlphaInput(d);
  1742. this.random && this.randomize.apply(this, Array.isArray(this.random) ? this.random : []);
  1743. },
  1744. };
  1745. a.pub.className = H;
  1746. a.pub.activeClassName = I;
  1747. a.pub.looseJSON = !0;
  1748. a.pub.presets = {};
  1749. a.pub.presets["default"] = {};
  1750. a.pub.sliderInnerSpace = 3;
  1751. a.pub.chessboardSize = 8;
  1752. a.pub.chessboardColor1 = "#666666";
  1753. a.pub.chessboardColor2 = "#999999";
  1754. a.pub.previewSeparator = [];
  1755. a.pub.init = function () {
  1756. if (!a.initialized)
  1757. for (
  1758. window.document.addEventListener("mousedown", a.onDocumentMouseDown, !1),
  1759. window.document.addEventListener("keyup", a.onDocumentKeyUp, !1),
  1760. window.addEventListener("resize", a.onWindowResize, !1),
  1761. window.addEventListener("scroll", a.onWindowScroll, !1),
  1762. a.pub.install(),
  1763. a.initialized = !0;
  1764. a.readyQueue.length;
  1765.  
  1766. )
  1767. a.readyQueue.shift()();
  1768. };
  1769. a.pub.install = function (b) {
  1770. var d = !0;
  1771. try {
  1772. a.installBySelector("[data-frcolorpicker]", b);
  1773. } catch (e) {
  1774. d = !1;
  1775. }
  1776. if (a.pub.lookupClass)
  1777. try {
  1778. a.installBySelector("input." + a.pub.lookupClass + ", button." + a.pub.lookupClass, b);
  1779. } catch (e) {}
  1780. return d;
  1781. };
  1782. a.pub.ready = function (b) {
  1783. if ("function" !== typeof b) return !1;
  1784. a.initialized ? b() : a.readyQueue.push(b);
  1785. return !0;
  1786. };
  1787. a.pub.trigger = function (b) {
  1788. var d = function () {
  1789. a.triggerGlobal(b);
  1790. };
  1791. a.initialized ? d() : a.pub.ready(d);
  1792. };
  1793. a.pub.hide = function () {
  1794. a.picker && a.picker.owner && a.picker.owner.hide();
  1795. };
  1796. a.pub.chessboard = function (b) {
  1797. b || (b = "rgba(0,0,0,0)");
  1798. return a.genColorPreviewCanvas(b).canvas.toDataURL();
  1799. };
  1800. a.pub.background = function (b) {
  1801. var d = [];
  1802. d.push(a.genColorPreviewGradient(b));
  1803. b = a.genColorPreviewCanvas();
  1804. d.push(["url('" + b.canvas.toDataURL() + "')", "left top repeat"].join(" "));
  1805. return d.join(", ");
  1806. };
  1807. a.pub.options = {};
  1808. a.pub.lookupClass = H;
  1809. a.pub.installByClassName = function () {
  1810. return !1;
  1811. };
  1812. a.register();
  1813. return a.pub;
  1814. })();
  1815. "undefined" === typeof window.FRColorPicker && (window.FRColorPicker = window.frColorPicker = T);
  1816. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址