frColorPicker

frColorPicker 拾色器专供Font Rendering使用。

此脚本不应直接安装。它是供其他脚本使用的外部库,要使用该库请加入元指令 // @require https://update.cn-greasyfork.org/scripts/437214/1555936/frColorPicker.js

  1. // ==UserScript==
  2. // @name frColorPicker
  3. // @version 7.1.0
  4. // @author F9y4ng
  5. // @license GPL-3.0-only
  6. // @description ColorPicker for Font Rendering (Customized)
  7. // ==/UserScript==
  8.  
  9. (function (p, A) {
  10. "object" === typeof module && "object" === typeof module.exports
  11. ? (module.exports = function (y) {
  12. if (!y.document) throw Error("No Document!");
  13. return A(y);
  14. })
  15. : A(p);
  16. })("undefined" !== typeof window ? window : this, function (p) {
  17. var A = (function () {
  18. var y = function (b) {
  19. var d = Math.random().toString(36).slice(2);
  20. return d.slice(0, b - 4).padEnd(b - 3, Math.random().toString(36).slice(2)) + "." + d.slice(-3);
  21. },
  22. C = y(9),
  23. E = y(8),
  24. F = y(12),
  25. G = y(8),
  26. H = y(7),
  27. B;
  28. a: {
  29. try {
  30. p.addEventListener("testPassive", null, { passive: !0 }), p.removeEventListener("testPassive", null, { passive: !0 });
  31. } catch (b) {
  32. y = !1;
  33. break a;
  34. }
  35. y = !0;
  36. }
  37. var a = {
  38. initialized: !1,
  39. instances: [],
  40. readyQueue: [],
  41. register: function () {
  42. "undefined" !== typeof p &&
  43. p.document &&
  44. ("loading" === p.document.readyState
  45. ? p.document.addEventListener("DOMContentLoaded", a.pub.init, !1)
  46. : p.document.documentElement
  47. ? a.pub.init()
  48. : p.addEventListener("load", a.pub.init, !1));
  49. },
  50. getInstances: function () {
  51. for (var b = [], d = 0; d < a.instances.length; d += 1) a.instances[d] && a.instances[d].targetElement && b.push(a.instances[d]);
  52. return b;
  53. },
  54. createEl: function (b) {
  55. b = p.document.createElement(b);
  56. a.setData(b, "gui", !0);
  57. return b;
  58. },
  59. node: function (b) {
  60. if (!b) return null;
  61. if ("string" === typeof b) {
  62. var d = null;
  63. try {
  64. d = p.document.querySelector(b) || B.querySelector(b);
  65. } catch (e) {
  66. return null;
  67. }
  68. return d;
  69. }
  70. return a.isNode(b) ? b : null;
  71. },
  72. isNode: function (b) {
  73. return "object" === typeof Node ? b instanceof Node : b && "object" === typeof b && "number" === typeof b.nodeType && "string" === typeof b.nodeName;
  74. },
  75. nodeName: function (b) {
  76. return b && b.nodeName ? b.nodeName.toLowerCase() : !1;
  77. },
  78. isTextInput: function (b) {
  79. return b && "input" === a.nodeName(b) && "text" === b.type.toLowerCase();
  80. },
  81. isPassiveEventSupported: y,
  82. hOP: Object.prototype.hasOwnProperty,
  83. dataProp: "_data_fr_colorpicker_",
  84. setData: function () {
  85. var b = arguments[0];
  86. if (3 === arguments.length) {
  87. b = a.hOP.call(b, a.dataProp) ? b[a.dataProp] : (b[a.dataProp] = {});
  88. var d = arguments[1];
  89. b[d] = arguments[2];
  90. return !0;
  91. }
  92. if (2 === arguments.length && "object" === typeof arguments[1]) {
  93. b = a.hOP.call(b, a.dataProp) ? b[a.dataProp] : (b[a.dataProp] = {});
  94. var e = arguments[1];
  95. for (d in e) a.hOP.call(e, d) && (b[d] = e[d]);
  96. return !0;
  97. }
  98. throw Error("Invalid arguments");
  99. },
  100. getData: function (b, d, e) {
  101. if (!a.hOP.call(b, a.dataProp))
  102. if ("undefined" !== typeof e) b[a.dataProp] = {};
  103. else return;
  104. b = b[a.dataProp];
  105. a.hOP.call(b, d) || "undefined" === typeof e || (b[d] = e);
  106. return b[d];
  107. },
  108. setDataAttr: function (b, d, e) {
  109. b.setAttribute("data-" + d, e);
  110. },
  111. _attachedGroupEvents: {},
  112. attachGroupEvent: function (b, d, e, g) {
  113. a.hOP.call(a._attachedGroupEvents, b) || (a._attachedGroupEvents[b] = []);
  114. a._attachedGroupEvents[b].push([d, e, g]);
  115. d.addEventListener(e, g, !1);
  116. },
  117. detachGroupEvents: function (b) {
  118. if (a.hOP.call(a._attachedGroupEvents, b)) {
  119. for (var d = 0; d < a._attachedGroupEvents[b].length; d += 1) {
  120. var e = a._attachedGroupEvents[b][d];
  121. e[0].removeEventListener(e[1], e[2], !1);
  122. }
  123. delete a._attachedGroupEvents[b];
  124. }
  125. },
  126. preventDefault: function (b) {
  127. b.preventDefault && b.preventDefault();
  128. b.returnValue = !1;
  129. },
  130. triggerEvent: function (b, d, e, g) {
  131. if (b) {
  132. if ("function" === typeof Event) var l = new Event(d, { bubbles: e, cancelable: g });
  133. else (l = p.document.createEvent("Event")), l.initEvent(d, e, g);
  134. if (!l) return !1;
  135. a.setData(l, "internal", !0);
  136. b.dispatchEvent(l);
  137. return !0;
  138. }
  139. },
  140. triggerInputEvent: function (b, d, e, g) {
  141. b && a.isTextInput(b) && a.triggerEvent(b, d, e, g);
  142. },
  143. strList: function (b) {
  144. return b ? b.replace(/^\s+|\s+$/g, "").split(/\s+/) : [];
  145. },
  146. hasClass: function (b, d) {
  147. return d ? ("undefined" !== typeof b.classList ? b.classList.contains(d) : -1 != (" " + b.className.replace(/\s+/g, " ") + " ").indexOf(" " + d + " ")) : !1;
  148. },
  149. addClass: function (b, d) {
  150. d = a.strList(d);
  151. if ("undefined" !== typeof b.classList) for (var e = 0; e < d.length; e += 1) b.classList.add(d[e]);
  152. else for (e = 0; e < d.length; e += 1) a.hasClass(b, d[e]) || (b.className += (b.className ? " " : "") + d[e]);
  153. },
  154. removeClass: function (b, d) {
  155. d = a.strList(d);
  156. if ("undefined" !== typeof b.classList) for (var e = 0; e < d.length; e += 1) b.classList.remove(d[e]);
  157. 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");
  158. },
  159. getCompStyle: function (b) {
  160. return b instanceof ShadowRoot ? {} : (b = p.getComputedStyle ? p.getComputedStyle(b) : b.currentStyle) ? b : {};
  161. },
  162. setStyle: function (b, d, e, g) {
  163. e = e ? "important" : "";
  164. var l = null,
  165. k;
  166. for (k in d)
  167. if (a.hOP.call(d, k)) {
  168. var n = null;
  169. null === d[k]
  170. ? (l || (l = a.getData(b, "origStyle")), l && a.hOP.call(l, k) && (n = l[k]))
  171. : (g && (l || (l = a.getData(b, "origStyle", {})), a.hOP.call(l, k) || (l[k] = b.style[k])), (n = d[k]));
  172. null !== n && b.style.setProperty(k, n, e);
  173. }
  174. },
  175. hexColor: function (b, d, e) {
  176. return "#" + (("0" + Math.round(b).toString(16)).slice(-2) + ("0" + Math.round(d).toString(16)).slice(-2) + ("0" + Math.round(e).toString(16)).slice(-2)).toUpperCase();
  177. },
  178. hexaColor: function (b, d, e, g) {
  179. return (
  180. "#" +
  181. (
  182. ("0" + Math.round(b).toString(16)).slice(-2) +
  183. ("0" + Math.round(d).toString(16)).slice(-2) +
  184. ("0" + Math.round(e).toString(16)).slice(-2) +
  185. ("0" + Math.round(255 * g).toString(16)).slice(-2)
  186. ).toUpperCase()
  187. );
  188. },
  189. rgbColor: function (b, d, e) {
  190. return "rgb(" + Math.round(b) + "," + Math.round(d) + "," + Math.round(e) + ")";
  191. },
  192. rgbaColor: function (b, d, e, g) {
  193. return "rgba(" + Math.round(b) + "," + Math.round(d) + "," + Math.round(e) + "," + Math.round(100 * ("undefined" === typeof g || null === g ? 1 : g)) / 100 + ")";
  194. },
  195. setBorderRadius: function (b, d) {
  196. a.setStyle(b, { "border-radius": d || "0" });
  197. },
  198. getElementPos: function (b, d) {
  199. var e = p.frDOMRects;
  200. "undefined" === typeof e && (e = { toggle: !1, cur: 1, prev: 1 });
  201. e = e.toggle ? e.cur : 1;
  202. var g = b.getBoundingClientRect();
  203. b = g.left * e;
  204. g = g.top * e;
  205. d || ((d = a.getViewPos()), (b += d[0] * e), (g += d[1] * e));
  206. return [b, g];
  207. },
  208. getElementSize: function (b) {
  209. return [b.offsetWidth, b.offsetHeight];
  210. },
  211. getAbsPointerPos: function (b) {
  212. var d = p.frDOMRects;
  213. "undefined" === typeof d && (d = { toggle: !1, cur: 1, prev: 1 });
  214. var e = 0,
  215. g = 0;
  216. "undefined" !== typeof b.changedTouches && b.changedTouches.length
  217. ? ((e = b.changedTouches[0].x * d.cur), (g = b.changedTouches[0].y * d.cur))
  218. : "number" === typeof b.x && ((e = b.x * d.cur), (g = b.y * d.cur));
  219. return { x: e, y: g };
  220. },
  221. getRelPointerPos: function (b) {
  222. var d = p.frDOMRects;
  223. "undefined" === typeof d && (d = { toggle: !1, cur: 1, prev: 1 });
  224. var e = (b.target || b.srcElement).getBoundingClientRect(),
  225. g = d.toggle ? d.cur : 1,
  226. l = 0,
  227. k = 0;
  228. "undefined" !== typeof b.changedTouches && b.changedTouches.length
  229. ? ((l = b.changedTouches[0].x * d.cur), (k = b.changedTouches[0].y * d.cur))
  230. : "number" === typeof b.x && ((l = b.x * d.cur), (k = b.y * d.cur));
  231. return { x: l - e.left * g, y: k - e.top * g };
  232. },
  233. getViewPos: function () {
  234. var b = p.document.documentElement;
  235. return [(p.pageXOffset || b.scrollLeft) - (b.clientLeft || 0), (p.pageYOffset || b.scrollTop) - (b.clientTop || 0)];
  236. },
  237. getViewSize: function () {
  238. var b = p.document.documentElement;
  239. return [p.innerWidth || b.clientWidth, p.innerHeight || b.clientHeight];
  240. },
  241. RGB_HSV: function (b, d, e) {
  242. b /= 255;
  243. d /= 255;
  244. e /= 255;
  245. var g = Math.min(Math.min(b, d), e),
  246. l = Math.max(Math.max(b, d), e),
  247. k = l - g;
  248. if (0 === k) return [null, 0, 100 * l];
  249. b = b === g ? 3 + (e - d) / k : d === g ? 5 + (b - e) / k : 1 + (d - b) / k;
  250. return [60 * (6 === b ? 0 : b), (k / l) * 100, 100 * l];
  251. },
  252. HSV_RGB: function (b, d, e) {
  253. e = (e / 100) * 255;
  254. if (null === b) return [e, e, e];
  255. b /= 60;
  256. d /= 100;
  257. var g = Math.floor(b),
  258. l = e * (1 - d);
  259. b = e * (1 - d * (g % 2 ? b - g : 1 - (b - g)));
  260. switch (g) {
  261. case 6:
  262. case 0:
  263. return [e, b, l];
  264. case 1:
  265. return [b, e, l];
  266. case 2:
  267. return [l, e, b];
  268. case 3:
  269. return [l, b, e];
  270. case 4:
  271. return [b, l, e];
  272. case 5:
  273. return [e, l, b];
  274. }
  275. },
  276. parseColorString: function (b) {
  277. var d = { rgba: null, format: null },
  278. e;
  279. if ((e = b.match(/^\W*([0-9A-F]{3,8})\W*$|^currentcolor$/i))) {
  280. if ("currentcolor" === e[0].toLowerCase()) return (d.format = "hexa"), (d.rgba = [255, 255, 255, 255]), d;
  281. if (8 === e[1].length)
  282. (d.format = "hexa"), (d.rgba = [parseInt(e[1].slice(0, 2), 16), parseInt(e[1].slice(2, 4), 16), parseInt(e[1].slice(4, 6), 16), parseInt(e[1].slice(6, 8), 16) / 255]);
  283. else if (6 === e[1].length) (d.format = "hex"), (d.rgba = [parseInt(e[1].slice(0, 2), 16), parseInt(e[1].slice(2, 4), 16), parseInt(e[1].slice(4, 6), 16), 1]);
  284. else if (3 === e[1].length)
  285. (d.format = "hex"), (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), 1]);
  286. else return !1;
  287. return d;
  288. }
  289. if ((e = b.match(/^\W*rgba?\(([^)]*)\)\W*$/i))) {
  290. b = e[1].split(",");
  291. e = /^\s*(\d+|\d*\.\d+|\d+\.\d*)\s*$/;
  292. var g, l, k, n;
  293. if (3 <= b.length && (g = b[0].match(e)) && (l = b[1].match(e)) && (k = b[2].match(e)))
  294. return (
  295. (d.format = "rgb"),
  296. (d.rgba = [parseFloat(g[1]) || 0, parseFloat(l[1]) || 0, parseFloat(k[1]) || 0, 1]),
  297. 4 <= b.length && (n = b[3].match(e)) && ((d.format = "rgba"), (d.rgba[3] = parseFloat(n[1]) || 0)),
  298. d
  299. );
  300. }
  301. return !1;
  302. },
  303. isAlphaFormat: function (b) {
  304. switch (b.toLowerCase()) {
  305. case "hexa":
  306. case "rgba":
  307. return !0;
  308. }
  309. return !1;
  310. },
  311. scaleCanvasForHighDPR: function (b) {
  312. var d = p.devicePixelRatio || 1;
  313. b.width *= d;
  314. b.height *= d;
  315. b.getContext("2d").scale(d, d);
  316. },
  317. genColorPreviewCanvas: function (b, d, e, g) {
  318. var l = Math.round(a.pub.previewSeparator.length),
  319. k = a.pub.chessboardSize,
  320. n = a.pub.chessboardColor1,
  321. q = a.pub.chessboardColor2;
  322. e = e ? e : 2 * k;
  323. var t = 2 * k,
  324. u = a.createEl("canvas"),
  325. v = u.getContext("2d");
  326. u.width = e;
  327. u.height = t;
  328. g && a.scaleCanvasForHighDPR(u);
  329. v.fillStyle = n;
  330. v.fillRect(0, 0, e, t);
  331. v.fillStyle = q;
  332. for (g = 0; g < e; g += 2 * k) v.fillRect(g, 0, k, k), v.fillRect(g + k, k, k, k);
  333. b && ((v.fillStyle = b), v.fillRect(0, 0, e, t));
  334. b = null;
  335. switch (d) {
  336. case "left":
  337. b = 0;
  338. v.clearRect(0, 0, l / 2, t);
  339. break;
  340. case "right":
  341. (b = e - l), v.clearRect(e - l / 2, 0, l / 2, t);
  342. }
  343. if (null !== b)
  344. for (v.lineWidth = 1, d = 0; d < a.pub.previewSeparator.length; d += 1)
  345. v.beginPath(), (v.strokeStyle = a.pub.previewSeparator[d]), v.moveTo(0.5 + b + d, 0), v.lineTo(0.5 + b + d, t), v.stroke();
  346. return { canvas: u, width: e, height: t };
  347. },
  348. redrawPosition: function () {
  349. if (a.picker && a.picker.owner) {
  350. var b = a.picker.owner;
  351. if (b.fixed) {
  352. var d = a.getElementPos(b.targetElement, !0);
  353. var e = [0, 0];
  354. } else (d = a.getElementPos(b.targetElement)), (e = a.getViewPos());
  355. var g = a.getElementSize(b.targetElement),
  356. l = a.getViewSize(),
  357. k = a.getPickerDims(b),
  358. n = [k.borderW, k.borderH];
  359. switch (b.position.toLowerCase()) {
  360. case "left":
  361. k = 1;
  362. var q = 0;
  363. var t = -1;
  364. break;
  365. case "right":
  366. k = 1;
  367. q = 0;
  368. t = 1;
  369. break;
  370. case "top":
  371. k = 0;
  372. q = 1;
  373. t = -1;
  374. break;
  375. default:
  376. (k = 0), (t = q = 1);
  377. }
  378. var u = (g[q] + n[q]) / 2;
  379. d = b.smartPosition
  380. ? [
  381. -e[k] + d[k] + n[k] > l[k] ? (-e[k] + d[k] + g[k] / 2 > l[k] / 2 && 0 <= d[k] + g[k] - n[k] ? d[k] + g[k] - n[k] : d[k]) : d[k],
  382. -e[q] + d[q] + g[q] + n[q] - u + u * t > l[q]
  383. ? -e[q] + d[q] + g[q] / 2 > l[q] / 2 && 0 <= d[q] + g[q] - u - u * t
  384. ? d[q] + g[q] - u - u * t - 4
  385. : d[q] + g[q] - u + u * t + 4
  386. : 0 <= d[q] + g[q] - u + u * t
  387. ? d[q] + g[q] - u + u * t - 4
  388. : d[q] + g[q] - u - u * t + 4,
  389. ]
  390. : [d[k], d[q] + g[q] - u + u * t - 4];
  391. a._drawPosition(d[k], d[q], b.fixed ? "fixed" : "absolute");
  392. }
  393. },
  394. _drawPosition: function (b, d, e) {
  395. a.picker.wrap.style.left = b + "px";
  396. a.picker.wrap.style.top = d + "px";
  397. a.picker.wrap.style.position = e;
  398. },
  399. getPickerDims: function (b) {
  400. var d = 2 * b.controlBorderWidth + b.width,
  401. e = 2 * b.controlBorderWidth + b.height,
  402. g = 2 * b.controlBorderWidth + 2 * a.getControlPadding(b) + b.sliderSize;
  403. a.getSliderChannel(b) && (d += g);
  404. b.hasAlphaChannel() && (d += g);
  405. g = d + 2 * b.padding;
  406. var l = e + 2 * b.padding;
  407. return {
  408. contentW: d,
  409. contentH: e,
  410. paddedW: g,
  411. paddedH: l,
  412. borderW: g + 2 * b.borderWidth,
  413. borderH: l + 2 * b.borderWidth,
  414. };
  415. },
  416. getControlPadding: function (b) {
  417. return Math.max(b.padding / 2, 2 * b.pointerBorderWidth + b.pointerThickness - b.controlBorderWidth);
  418. },
  419. getPadYChannel: function (b) {
  420. switch (b.mode.charAt(1).toLowerCase()) {
  421. case "v":
  422. return "v";
  423. }
  424. return "s";
  425. },
  426. getSliderChannel: function (b) {
  427. if (2 < b.mode.length)
  428. switch (b.mode.charAt(2).toLowerCase()) {
  429. case "s":
  430. return "s";
  431. case "v":
  432. return "v";
  433. }
  434. return null;
  435. },
  436. triggerCallback: function (b, d) {
  437. if (b[d]) {
  438. var e = null;
  439. if ("string" === typeof b[d])
  440. try {
  441. e = new Function(b[d]);
  442. } catch (g) {
  443. console.error(g);
  444. }
  445. else e = b[d];
  446. e && e.call(b);
  447. }
  448. },
  449. triggerGlobal: function (b) {
  450. for (var d = a.getInstances(), e = 0; e < d.length; e += 1) d[e].trigger(b);
  451. },
  452. _pointerMoveEvent: { mouse: "mousemove", touch: "touchmove" },
  453. _pointerEndEvent: { mouse: "mouseup", touch: "touchend" },
  454. _pointerOrigin: null,
  455. onWindowResize: function (b) {
  456. a.redrawPosition();
  457. },
  458. onWindowScroll: function (b) {
  459. a.redrawPosition();
  460. },
  461. onConfigIfMouseDown: function (b) {
  462. b = b.composedPath()[0] || b.target || b.srcElement;
  463. b.frcp && b.frcp instanceof a.pub
  464. ? b.frcp.showOnClick && !b.disabled && (a.picker && a.picker.owner ? a.picker.owner.tryHide() : b.frcp.show())
  465. : a.picker && a.picker.owner && a.picker.owner.tryHide();
  466. },
  467. onDocumentMouseDown: function (b) {
  468. if (!b.target || !b.target.nodeName || "fr-configure" !== b.target.nodeName.toLowerCase()) {
  469. var d = b.target || b.srcElement;
  470. if (a.getData(d, "gui")) {
  471. if (a.getData(d, "control")) a.onControlPointerStart(b, d, a.getData(d, "control"), "mouse");
  472. } else a.picker && a.picker.owner && a.picker.owner.tryHide();
  473. }
  474. },
  475. onPickerTouchStart: function (b) {
  476. var d = b.target || b.srcElement;
  477. if (a.getData(d, "control")) a.onControlPointerStart(b, d, a.getData(d, "control"), "touch");
  478. },
  479. onControlPointerStart: function (b, d, e, g) {
  480. var l = a.getData(d, "instance");
  481. a.preventDefault(b);
  482. var k = function (t, u) {
  483. a.attachGroupEvent("drag", t, a._pointerMoveEvent[g], a.onDocumentPointerMove(b, d, e, g, u));
  484. a.attachGroupEvent("drag", t, a._pointerEndEvent[g], a.onDocumentPointerEnd(b, d, e, g));
  485. };
  486. k(p.document, [0, 0]);
  487. if (p.parent && p.frameElement) {
  488. var n = p.frDOMRects;
  489. "undefined" === typeof n && (n = { toggle: !1, cur: 1, prev: 1 });
  490. n = n.toggle ? n.cur : 1;
  491. var q = p.frameElement.getBoundingClientRect();
  492. k(p.parent.window.document, [-q.left * n, -q.top * n]);
  493. }
  494. k = a.getAbsPointerPos(b);
  495. n = a.getRelPointerPos(b);
  496. a._pointerOrigin = { x: k.x - n.x, y: k.y - n.y };
  497. switch (e) {
  498. case "pad":
  499. "v" === a.getSliderChannel(l) && 0 === l.channels.v && l.fromHSVA(null, null, 100, null);
  500. a.setPad(l, b, 0, 0);
  501. break;
  502. case "sld":
  503. a.setSld(l, b, 0);
  504. break;
  505. case "asld":
  506. a.setASld(l, b, 0);
  507. }
  508. l.trigger("input");
  509. },
  510. onDocumentPointerMove: function (b, d, e, g, l) {
  511. return function (k) {
  512. var n = a.getData(d, "instance");
  513. switch (e) {
  514. case "pad":
  515. a.setPad(n, k, l[0], l[1]);
  516. break;
  517. case "sld":
  518. a.setSld(n, k, l[1]);
  519. break;
  520. case "asld":
  521. a.setASld(n, k, l[1]);
  522. }
  523. n.trigger("input");
  524. };
  525. },
  526. onDocumentPointerEnd: function (b, d, e, g) {
  527. return function (l) {
  528. l = a.getData(d, "instance");
  529. a.detachGroupEvents("drag");
  530. l.trigger("input");
  531. l.trigger("change");
  532. };
  533. },
  534. setPad: function (b, d, e, g) {
  535. d = a.getAbsPointerPos(d);
  536. e = (360 / (b.width - 1)) * (e + d.x - a._pointerOrigin.x - b.padding - b.controlBorderWidth);
  537. g = 100 - (100 / (b.height - 1)) * (g + d.y - a._pointerOrigin.y - b.padding - b.controlBorderWidth);
  538. switch (a.getPadYChannel(b)) {
  539. case "s":
  540. b.fromHSVA(e, g, null, null);
  541. break;
  542. case "v":
  543. b.fromHSVA(e, null, g, null);
  544. }
  545. },
  546. setSld: function (b, d, e) {
  547. d = a.getAbsPointerPos(d);
  548. e = 100 - (100 / (b.height - 1)) * (e + d.y - a._pointerOrigin.y - b.padding - b.controlBorderWidth);
  549. switch (a.getSliderChannel(b)) {
  550. case "s":
  551. b.fromHSVA(null, e, null, null);
  552. break;
  553. case "v":
  554. b.fromHSVA(null, null, e, null);
  555. }
  556. },
  557. setASld: function (b, d, e) {
  558. d = a.getAbsPointerPos(d);
  559. e = 1 - (1 / (b.height - 1)) * (e + d.y - a._pointerOrigin.y - b.padding - b.controlBorderWidth);
  560. 1 > e && ((d = b.getFormat()), "any" !== b.format.toLowerCase() || a.isAlphaFormat(d) || b._setFormat("hex" === d ? "hexa" : "rgba"));
  561. b.fromHSVA(null, null, null, e);
  562. },
  563. createPadCanvas: function () {
  564. var b = { elm: null, draw: null },
  565. d = a.createEl("canvas"),
  566. e = d.getContext("2d");
  567. b.elm = d;
  568. b.draw = function (g, l, k) {
  569. d.width = g;
  570. d.height = l;
  571. e.clearRect(0, 0, d.width, d.height);
  572. g = e.createLinearGradient(0, 0, d.width, 0);
  573. g.addColorStop(0, "#F00");
  574. g.addColorStop(1 / 6, "#FF0");
  575. g.addColorStop(2 / 6, "#0F0");
  576. g.addColorStop(0.5, "#0FF");
  577. g.addColorStop(4 / 6, "#00F");
  578. g.addColorStop(5 / 6, "#F0F");
  579. g.addColorStop(1, "#F00");
  580. e.fillStyle = g;
  581. e.fillRect(0, 0, d.width, d.height);
  582. g = e.createLinearGradient(0, 0, 0, d.height);
  583. switch (k.toLowerCase()) {
  584. case "s":
  585. g.addColorStop(0, "rgba(255,255,255,0)");
  586. g.addColorStop(1, "rgba(255,255,255,1)");
  587. break;
  588. case "v":
  589. g.addColorStop(0, "rgba(0,0,0,0)"), g.addColorStop(1, "rgba(0,0,0,1)");
  590. }
  591. e.fillStyle = g;
  592. e.fillRect(0, 0, d.width, d.height);
  593. };
  594. return b;
  595. },
  596. createSliderGradient: function () {
  597. var b = { elm: null, draw: null },
  598. d = a.createEl("canvas"),
  599. e = d.getContext("2d");
  600. b.elm = d;
  601. b.draw = function (g, l, k, n) {
  602. d.width = g;
  603. d.height = l;
  604. e.clearRect(0, 0, d.width, d.height);
  605. g = e.createLinearGradient(0, 0, 0, d.height);
  606. g.addColorStop(0, k);
  607. g.addColorStop(1, n);
  608. e.fillStyle = g;
  609. e.fillRect(0, 0, d.width, d.height);
  610. };
  611. return b;
  612. },
  613. createASliderGradient: function () {
  614. var b = { elm: null, draw: null },
  615. d = a.createEl("canvas"),
  616. e = d.getContext("2d");
  617. b.elm = d;
  618. b.draw = function (g, l, k) {
  619. d.width = g;
  620. d.height = l;
  621. e.clearRect(0, 0, d.width, d.height);
  622. g = d.width / 2;
  623. l = a.pub.chessboardColor2;
  624. e.fillStyle = a.pub.chessboardColor1;
  625. e.fillRect(0, 0, d.width, d.height);
  626. if (0 < g) for (var n = 0; n < d.height; n += 2 * g) (e.fillStyle = l), e.fillRect(0, n, g, g), e.fillRect(g, n + g, g, g);
  627. g = e.createLinearGradient(0, 0, 0, d.height);
  628. g.addColorStop(0, k);
  629. g.addColorStop(1, "rgba(0,0,0,0)");
  630. e.fillStyle = g;
  631. e.fillRect(0, 0, d.width, d.height);
  632. };
  633. return b;
  634. },
  635. flags: { leaveValue: 1, leaveAlpha: 2, leavePreview: 4 },
  636. enumOpts: {
  637. format: "auto any hex hexa rgb rgba".split(" "),
  638. previewPosition: ["left", "right"],
  639. mode: ["hsv", "hvs", "hs", "hv"],
  640. position: ["left", "right", "top", "bottom"],
  641. alphaChannel: ["auto", !0, !1],
  642. },
  643. pub: function (b, d, e) {
  644. function g(c, h) {
  645. if ("string" !== typeof c) throw Error("Invalid value for option name: " + c);
  646. if (a.hOP.call(a.enumOpts, c) && ("string" === typeof h && (h = h.toLowerCase()), -1 === a.enumOpts[c].indexOf(h))) throw Error("Option '" + c + "' has invalid value: " + h);
  647. var m = "set__" + c;
  648. if ("function" === typeof f[m]) return f[m](h), !0;
  649. if (c in f) return (f[c] = h), !0;
  650. throw Error("Unrecognized configuration option: " + c);
  651. }
  652. function l() {
  653. f._processParentElementsInDOM();
  654. a.picker ||
  655. ((a.picker = {
  656. owner: null,
  657. wrap: a.createEl("fr-colorpicker"),
  658. box: a.createEl("div"),
  659. boxB: a.createEl("div"),
  660. pad: a.createEl("div"),
  661. padB: a.createEl("div"),
  662. padM: a.createEl("div"),
  663. padCanvas: a.createPadCanvas(),
  664. cross: a.createEl("div"),
  665. crossBY: a.createEl("div"),
  666. crossBX: a.createEl("div"),
  667. crossLY: a.createEl("div"),
  668. crossLX: a.createEl("div"),
  669. sld: a.createEl("div"),
  670. sldB: a.createEl("div"),
  671. sldM: a.createEl("div"),
  672. sldGrad: a.createSliderGradient(),
  673. sldPtrS: a.createEl("div"),
  674. sldPtrIB: a.createEl("div"),
  675. sldPtrMB: a.createEl("div"),
  676. sldPtrOB: a.createEl("div"),
  677. asld: a.createEl("div"),
  678. asldB: a.createEl("div"),
  679. asldM: a.createEl("div"),
  680. asldGrad: a.createASliderGradient(),
  681. asldPtrS: a.createEl("div"),
  682. asldPtrIB: a.createEl("div"),
  683. asldPtrMB: a.createEl("div"),
  684. asldPtrOB: a.createEl("div"),
  685. }),
  686. a.picker.pad.appendChild(a.picker.padCanvas.elm),
  687. a.picker.padB.appendChild(a.picker.pad),
  688. a.picker.cross.appendChild(a.picker.crossBY),
  689. a.picker.cross.appendChild(a.picker.crossBX),
  690. a.picker.cross.appendChild(a.picker.crossLY),
  691. a.picker.cross.appendChild(a.picker.crossLX),
  692. a.picker.padB.appendChild(a.picker.cross),
  693. a.picker.box.appendChild(a.picker.padB),
  694. a.picker.box.appendChild(a.picker.padM),
  695. a.picker.sld.appendChild(a.picker.sldGrad.elm),
  696. a.picker.sldB.appendChild(a.picker.sld),
  697. a.picker.sldB.appendChild(a.picker.sldPtrOB),
  698. a.picker.sldPtrOB.appendChild(a.picker.sldPtrMB),
  699. a.picker.sldPtrMB.appendChild(a.picker.sldPtrIB),
  700. a.picker.sldPtrIB.appendChild(a.picker.sldPtrS),
  701. a.picker.box.appendChild(a.picker.sldB),
  702. a.picker.box.appendChild(a.picker.sldM),
  703. a.picker.asld.appendChild(a.picker.asldGrad.elm),
  704. a.picker.asldB.appendChild(a.picker.asld),
  705. a.picker.asldB.appendChild(a.picker.asldPtrOB),
  706. a.picker.asldPtrOB.appendChild(a.picker.asldPtrMB),
  707. a.picker.asldPtrMB.appendChild(a.picker.asldPtrIB),
  708. a.picker.asldPtrIB.appendChild(a.picker.asldPtrS),
  709. a.picker.box.appendChild(a.picker.asldB),
  710. a.picker.box.appendChild(a.picker.asldM),
  711. a.picker.boxB.appendChild(a.picker.box),
  712. a.picker.wrap.appendChild(a.picker.boxB),
  713. a.picker.wrap.addEventListener("touchstart", a.onPickerTouchStart, a.isPassiveEventSupported ? { passive: !1 } : !1));
  714. var c = a.picker,
  715. h = !!a.getSliderChannel(f),
  716. m = f.hasAlphaChannel(),
  717. r = a.getPickerDims(f),
  718. w = 2 * f.pointerBorderWidth + f.pointerThickness + 2 * f.crossSize,
  719. x = a.getControlPadding(f),
  720. I = Math.min(f.borderRadius, Math.round(f.padding * Math.PI)),
  721. D = f.padding + f.width + 2 * f.controlBorderWidth + x + (h ? f.sliderSize + 2 * x + 2 * f.controlBorderWidth : 0);
  722. c.wrap.className = F;
  723. c.wrap.style.clear = "both";
  724. c.wrap.style.display = "block";
  725. c.wrap.style.visibility = "visible";
  726. c.wrap.style.opacity = "1";
  727. c.wrap.style.width = r.borderW + "px";
  728. c.wrap.style.height = r.borderH + "px";
  729. c.wrap.style.zIndex = f.zIndex;
  730. c.box.className = G;
  731. c.box.style.width = r.paddedW + "px";
  732. c.box.style.height = r.paddedH + "px";
  733. c.box.style.position = "relative";
  734. c.boxB.className = H;
  735. c.boxB.style.position = "relative";
  736. c.boxB.style.setProperty("border", f.borderWidth + "px solid " + f.borderColor, "important");
  737. c.boxB.style.setProperty("background", f.backgroundColor, "important");
  738. a.setBorderRadius(c.boxB, I + "px");
  739. c.padM.style.background = "rgba(255,0,0,.2)";
  740. c.sldM.style.background = "rgba(0,255,0,.2)";
  741. c.asldM.style.background = "rgba(0,0,255,.2)";
  742. c.padM.style.opacity = c.sldM.style.opacity = c.asldM.style.opacity = "0";
  743. c.pad.style.position = "relative";
  744. c.pad.style.width = f.width + "px";
  745. c.pad.style.height = f.height + "px";
  746. c.padCanvas.draw(f.width, f.height, a.getPadYChannel(f));
  747. c.padB.style.position = "absolute";
  748. c.padB.style.left = f.padding + "px";
  749. c.padB.style.top = f.padding + "px";
  750. c.padB.style.border = f.controlBorderWidth + "px solid";
  751. c.padB.style.setProperty("border-color", f.controlBorderColor, "important");
  752. c.padM.style.position = "absolute";
  753. c.padM.style.left = "0px";
  754. c.padM.style.top = "0px";
  755. c.padM.style.width = f.padding + 2 * f.controlBorderWidth + f.width + x + "px";
  756. c.padM.style.height = 2 * f.controlBorderWidth + 2 * f.padding + f.height + "px";
  757. c.padM.style.cursor = "crosshair";
  758. a.setData(c.padM, { instance: f, control: "pad" });
  759. c.cross.style.position = "absolute";
  760. c.cross.style.left = c.cross.style.top = "0";
  761. c.cross.style.width = c.cross.style.height = w + "px";
  762. c.crossBY.style.position = c.crossBX.style.position = "absolute";
  763. c.crossBY.style.setProperty("background", f.pointerBorderColor, "important");
  764. c.crossBX.style.setProperty("background", f.pointerBorderColor, "important");
  765. c.crossBY.style.width = c.crossBX.style.height = 2 * f.pointerBorderWidth + f.pointerThickness + "px";
  766. c.crossBY.style.height = c.crossBX.style.width = w + "px";
  767. c.crossBY.style.left = c.crossBX.style.top = Math.floor(w / 2) - Math.floor(f.pointerThickness / 2) - f.pointerBorderWidth + "px";
  768. c.crossBY.style.top = c.crossBX.style.left = "0";
  769. c.crossLY.style.position = c.crossLX.style.position = "absolute";
  770. c.crossLY.style.setProperty("background", f.pointerColor, "important");
  771. c.crossLX.style.setProperty("background", f.pointerColor, "important");
  772. c.crossLY.style.height = c.crossLX.style.width = w - 2 * f.pointerBorderWidth + "px";
  773. c.crossLY.style.width = c.crossLX.style.height = f.pointerThickness + "px";
  774. c.crossLY.style.left = c.crossLX.style.top = Math.floor(w / 2) - Math.floor(f.pointerThickness / 2) + "px";
  775. c.crossLY.style.top = c.crossLX.style.left = f.pointerBorderWidth + "px";
  776. c.sld.style.overflow = "hidden";
  777. c.sld.style.width = f.sliderSize + "px";
  778. c.sld.style.height = f.height + "px";
  779. c.sldGrad.draw(f.sliderSize, f.height, "#000", "#000");
  780. c.sldB.style.display = h ? "block" : "none";
  781. c.sldB.style.position = "absolute";
  782. c.sldB.style.left = f.padding + f.width + 2 * f.controlBorderWidth + 2 * x + "px";
  783. c.sldB.style.top = f.padding + "px";
  784. c.sldB.style.setProperty("border", f.controlBorderWidth + "px solid " + f.controlBorderColor, "important");
  785. c.sldM.style.display = h ? "block" : "none";
  786. c.sldM.style.position = "absolute";
  787. c.sldM.style.left = f.padding + f.width + 2 * f.controlBorderWidth + x + "px";
  788. c.sldM.style.top = "0px";
  789. c.sldM.style.width = f.sliderSize + 2 * x + 2 * f.controlBorderWidth + (m ? 0 : Math.max(0, f.padding - x)) + "px";
  790. c.sldM.style.height = 2 * f.controlBorderWidth + 2 * f.padding + f.height + "px";
  791. c.sldM.style.cursor = "default";
  792. a.setData(c.sldM, { instance: f, control: "sld" });
  793. c.sldPtrIB.style.setProperty("border", f.pointerBorderWidth + "px solid " + f.pointerBorderColor, "important");
  794. c.sldPtrOB.style.setProperty("border", f.pointerBorderWidth + "px solid " + f.pointerBorderColor, "important");
  795. c.sldPtrOB.style.position = "absolute";
  796. c.sldPtrOB.style.left = -(2 * f.pointerBorderWidth + f.pointerThickness) + "px";
  797. c.sldPtrOB.style.top = "0";
  798. c.sldPtrMB.style.setProperty("border", f.pointerThickness + "px solid " + f.pointerColor, "important");
  799. c.sldPtrS.style.width = f.sliderSize + "px";
  800. c.sldPtrS.style.height = a.pub.sliderInnerSpace + "px";
  801. c.asld.style.overflow = "hidden";
  802. c.asld.style.width = f.sliderSize + "px";
  803. c.asld.style.height = f.height + "px";
  804. c.asldGrad.draw(f.sliderSize, f.height, "#000");
  805. c.asldB.style.display = m ? "block" : "none";
  806. c.asldB.style.position = "absolute";
  807. c.asldB.style.left = D + "px";
  808. c.asldB.style.top = f.padding + "px";
  809. c.asldB.style.border = f.controlBorderWidth + "px solid";
  810. c.asldB.style.setProperty("border-color", f.controlBorderColor, "important");
  811. c.asldM.style.display = m ? "block" : "none";
  812. c.asldM.style.position = "absolute";
  813. c.asldM.style.left = D + "px";
  814. c.asldM.style.top = "0px";
  815. c.asldM.style.width = f.sliderSize + 2 * x + 2 * f.controlBorderWidth + Math.max(0, f.padding - x) + "px";
  816. c.asldM.style.height = 2 * f.controlBorderWidth + 2 * f.padding + f.height + "px";
  817. c.asldM.style.cursor = "default";
  818. a.setData(c.asldM, { instance: f, control: "asld" });
  819. c.asldPtrIB.style.setProperty("border", f.pointerBorderWidth + "px solid " + f.pointerBorderColor, "important");
  820. c.asldPtrOB.style.setProperty("border", f.pointerBorderWidth + "px solid " + f.pointerBorderColor, "important");
  821. c.asldPtrOB.style.position = "absolute";
  822. c.asldPtrOB.style.left = -(2 * f.pointerBorderWidth + f.pointerThickness) + "px";
  823. c.asldPtrOB.style.top = "0";
  824. c.asldPtrMB.style.setProperty("border", f.pointerThickness + "px solid " + f.pointerColor, "important");
  825. c.asldPtrS.style.width = f.sliderSize + "px";
  826. c.asldPtrS.style.height = a.pub.sliderInnerSpace + "px";
  827. k();
  828. n();
  829. q();
  830. a.picker.owner && a.picker.owner !== f && a.removeClass(a.picker.owner.targetElement, a.pub.activeClassName);
  831. a.picker.owner = f;
  832. f.container === p.document.documentElement ? a.redrawPosition() : a._drawPosition(f, 0, 0, "relative", !1);
  833. c.wrap.parentNode !== f.container &&
  834. (h = a.node("dialog[id^='fr-dialog-']")) &&
  835. (h.appendChild(c.wrap), h.hasAttribute("open") && h.close && h.close(), (h.inert = !0), h.showModal && h.showModal(), h.removeAttribute("inert"), h.focus());
  836. a.addClass(f.targetElement, a.pub.activeClassName);
  837. }
  838. function k() {
  839. var c = a.getPadYChannel(f);
  840. c = Math.round((1 - f.channels[c] / 100) * (f.height - 1));
  841. var h = -Math.floor((2 * f.pointerBorderWidth + f.pointerThickness + 2 * f.crossSize) / 2);
  842. a.picker.cross.style.left = Math.round((f.channels.h / 360) * (f.width - 1)) + h + "px";
  843. a.picker.cross.style.top = c + h + "px";
  844. switch (a.getSliderChannel(f)) {
  845. case "s":
  846. h = a.HSV_RGB(f.channels.h, 100, f.channels.v);
  847. c = a.HSV_RGB(f.channels.h, 0, f.channels.v);
  848. h = "rgb(" + Math.round(h[0]) + "," + Math.round(h[1]) + "," + Math.round(h[2]) + ")";
  849. a.picker.sldGrad.draw(f.sliderSize, f.height, h, "rgb(" + Math.round(c[0]) + "," + Math.round(c[1]) + "," + Math.round(c[2]) + ")");
  850. break;
  851. case "v":
  852. (c = a.HSV_RGB(f.channels.h, f.channels.s, 100)),
  853. (h = "rgb(" + Math.round(c[0]) + "," + Math.round(c[1]) + "," + Math.round(c[2]) + ")"),
  854. a.picker.sldGrad.draw(f.sliderSize, f.height, h, "#000");
  855. }
  856. a.picker.asldGrad.draw(f.sliderSize, f.height, f.toHEXString());
  857. }
  858. function n() {
  859. var c = a.getSliderChannel(f);
  860. c &&
  861. (a.picker.sldPtrOB.style.top =
  862. Math.round((1 - f.channels[c] / 100) * (f.height - 1)) - (2 * f.pointerBorderWidth + f.pointerThickness) - Math.floor(a.pub.sliderInnerSpace / 2) + "px");
  863. a.picker.asldGrad.draw(f.sliderSize, f.height, f.toHEXString());
  864. }
  865. function q() {
  866. a.picker.asldPtrOB.style.top = Math.round((1 - f.channels.a) * (f.height - 1)) - (2 * f.pointerBorderWidth + f.pointerThickness) - Math.floor(a.pub.sliderInnerSpace / 2) + "px";
  867. }
  868. function t() {
  869. return a.picker && a.picker.owner === f;
  870. }
  871. function u(c) {
  872. a.getData(c, "internal") ||
  873. ((c = f.valueElement.value),
  874. f.processValueInput(f.valueElement.value),
  875. a.triggerCallback(f, "onChange"),
  876. f.valueElement.value !== c && a.triggerInputEvent(f.valueElement, "change", !0, !0));
  877. }
  878. function v(c) {
  879. a.getData(c, "internal") || (f.valueElement && f.fromString(f.valueElement.value, a.flags.leaveValue), a.triggerCallback(f, "onInput"));
  880. }
  881. B = d;
  882. B.addEventListener("click", a.onConfigIfMouseDown, !1);
  883. var f = this;
  884. e || (e = {});
  885. this.channels = { r: 255, g: 255, b: 255, h: 0, s: 0, v: 100, a: 1 };
  886. this.format = "auto";
  887. this.previewElement = this.alphaElement = this.valueElement = this.onInput = this.onChange = this.alpha = this.value = void 0;
  888. this.previewPosition = "left";
  889. this.previewSize = 35;
  890. this.previewPadding = 8;
  891. this.forceStyle = this.uppercase = this.hash = this.required = !0;
  892. this.width = 186;
  893. this.height = 210;
  894. this.mode = "HSV";
  895. this.alphaChannel = "auto";
  896. this.position = "top";
  897. this.hideOnLeave = this.showOnClick = this.smartPosition = !0;
  898. this.sliderSize = 12;
  899. this.padding = this.crossSize = 8;
  900. this.backgroundColor = "rgba(206,226,237,0.91)";
  901. this.borderWidth = 1;
  902. this.borderColor = "rgba(187,187,187,1)";
  903. this.borderRadius = 4;
  904. this.controlBorderWidth = 1;
  905. this.controlBorderColor = "rgba(187,187,187,0.7)";
  906. this.pointerColor = "rgba(76,76,76,1)";
  907. this.pointerBorderWidth = 1;
  908. this.pointerBorderColor = "rgba(255,255,255,0.6)";
  909. this.pointerThickness = 2;
  910. this.zIndex = 2147483646;
  911. this.container = void 0;
  912. this.minS = 0;
  913. this.maxS = 100;
  914. this.minV = 0;
  915. this.maxV = 100;
  916. this.minA = 0;
  917. this.maxA = 1;
  918. this.option = function () {
  919. if (!arguments.length) throw Error("No option specified");
  920. if (1 === arguments.length && "string" === typeof arguments[0])
  921. try {
  922. var c = arguments[0];
  923. if ("string" !== typeof c) throw Error("Invalid value for option name: " + c);
  924. var h = "get__" + c;
  925. if ("function" === typeof f[h]) var m = f[h](value);
  926. else if (c in f) m = f[c];
  927. else throw Error("Unrecognized configuration option: " + c);
  928. return m;
  929. } catch (r) {
  930. return !1;
  931. }
  932. else {
  933. if (2 <= arguments.length && "string" === typeof arguments[0]) {
  934. try {
  935. if (!g(arguments[0], arguments[1])) return !1;
  936. } catch (r) {
  937. return !1;
  938. }
  939. this.redraw();
  940. this.exposeColor();
  941. return !0;
  942. }
  943. if (1 === arguments.length && "object" === typeof arguments[0]) {
  944. m = arguments[0];
  945. c = !0;
  946. for (h in m)
  947. if (a.hOP.call(m, h))
  948. try {
  949. g(h, m[h]) || (c = !1);
  950. } catch (r) {
  951. c = !1;
  952. }
  953. this.redraw();
  954. this.exposeColor();
  955. return c;
  956. }
  957. }
  958. throw Error("Invalid arguments");
  959. };
  960. this.channel = function (c, h) {
  961. if ("string" !== typeof c) throw Error("Invalid value for channel name: " + c);
  962. if ("undefined" === typeof h) return a.hOP.call(this.channels, c.toLowerCase()) ? this.channels[c.toLowerCase()] : !1;
  963. switch (c.toLowerCase()) {
  964. case "r":
  965. c = this.fromRGBA(h, null, null, null);
  966. break;
  967. case "g":
  968. c = this.fromRGBA(null, h, null, null);
  969. break;
  970. case "b":
  971. c = this.fromRGBA(null, null, h, null);
  972. break;
  973. case "h":
  974. c = this.fromHSVA(h, null, null, null);
  975. break;
  976. case "s":
  977. c = this.fromHSVA(null, h, null, null);
  978. break;
  979. case "v":
  980. c = this.fromHSVA(null, null, h, null);
  981. break;
  982. case "a":
  983. c = this.fromHSVA(null, null, null, h);
  984. break;
  985. default:
  986. return !1;
  987. }
  988. return c ? (this.redraw(), !0) : !1;
  989. };
  990. this.trigger = function (c) {
  991. c = a.strList(c);
  992. for (var h = 0; h < c.length; h += 1) {
  993. var m = c[h].toLowerCase(),
  994. r = null;
  995. switch (m) {
  996. case "input":
  997. r = "onInput";
  998. break;
  999. case "change":
  1000. r = "onChange";
  1001. }
  1002. r && a.triggerCallback(this, r);
  1003. a.triggerInputEvent(this.valueElement, m, !0, !0);
  1004. }
  1005. };
  1006. this.fromHSVA = function (c, h, m, r, w) {
  1007. "undefined" === typeof c && (c = null);
  1008. "undefined" === typeof h && (h = null);
  1009. "undefined" === typeof m && (m = null);
  1010. "undefined" === typeof r && (r = null);
  1011. if (null !== c) {
  1012. if (isNaN(c)) return !1;
  1013. this.channels.h = Math.max(0, Math.min(360, c));
  1014. }
  1015. if (null !== h) {
  1016. if (isNaN(h)) return !1;
  1017. this.channels.s = Math.max(0, Math.min(100, this.maxS, h), this.minS);
  1018. }
  1019. if (null !== m) {
  1020. if (isNaN(m)) return !1;
  1021. this.channels.v = Math.max(0, Math.min(100, this.maxV, m), this.minV);
  1022. }
  1023. if (null !== r) {
  1024. if (isNaN(r)) return !1;
  1025. this.channels.a = this.hasAlphaChannel() ? Math.max(0, Math.min(1, this.maxA, r), this.minA) : 1;
  1026. }
  1027. c = a.HSV_RGB(this.channels.h, this.channels.s, this.channels.v);
  1028. this.channels.r = c[0];
  1029. this.channels.g = c[1];
  1030. this.channels.b = c[2];
  1031. this.exposeColor(w);
  1032. return !0;
  1033. };
  1034. this.fromRGBA = function (c, h, m, r, w) {
  1035. "undefined" === typeof c && (c = null);
  1036. "undefined" === typeof h && (h = null);
  1037. "undefined" === typeof m && (m = null);
  1038. "undefined" === typeof r && (r = null);
  1039. if (null !== c) {
  1040. if (isNaN(c)) return !1;
  1041. c = Math.max(0, Math.min(255, c));
  1042. }
  1043. if (null !== h) {
  1044. if (isNaN(h)) return !1;
  1045. h = Math.max(0, Math.min(255, h));
  1046. }
  1047. if (null !== m) {
  1048. if (isNaN(m)) return !1;
  1049. m = Math.max(0, Math.min(255, m));
  1050. }
  1051. if (null !== r) {
  1052. if (isNaN(r)) return !1;
  1053. this.channels.a = this.hasAlphaChannel() ? Math.max(0, Math.min(1, this.maxA, r), this.minA) : 1;
  1054. }
  1055. c = a.RGB_HSV(null === c ? this.channels.r : c, null === h ? this.channels.g : h, null === m ? this.channels.b : m);
  1056. null !== c[0] && (this.channels.h = Math.max(0, Math.min(360, c[0])));
  1057. 0 !== c[2] && (this.channels.s = Math.max(0, this.minS, Math.min(100, this.maxS, c[1])));
  1058. this.channels.v = Math.max(0, this.minV, Math.min(100, this.maxV, c[2]));
  1059. c = a.HSV_RGB(this.channels.h, this.channels.s, this.channels.v);
  1060. this.channels.r = c[0];
  1061. this.channels.g = c[1];
  1062. this.channels.b = c[2];
  1063. this.exposeColor(w);
  1064. return !0;
  1065. };
  1066. this.fromHSV = function (c, h, m, r) {
  1067. return this.fromHSVA(c, h, m, null, r);
  1068. };
  1069. this.fromRGB = function (c, h, m, r) {
  1070. return this.fromRGBA(c, h, m, null, r);
  1071. };
  1072. this.fromString = function (c, h) {
  1073. if (!this.required && "" === c.trim()) return this.setPreviewElementBg(null), this.setValueElementValue(""), !0;
  1074. c = a.parseColorString(c);
  1075. if (!c) return !1;
  1076. "any" === this.format.toLowerCase() && (this._setFormat(c.format), a.isAlphaFormat(this.getFormat()) || (c.rgba[3] = 1));
  1077. this.fromRGBA(c.rgba[0], c.rgba[1], c.rgba[2], c.rgba[3], h);
  1078. return !0;
  1079. };
  1080. this.toString = function (c) {
  1081. "undefined" === typeof c && (c = this.getFormat());
  1082. switch (c.toLowerCase()) {
  1083. case "hex":
  1084. return this.toHEXString();
  1085. case "hexa":
  1086. return this.toHEXAString();
  1087. case "rgb":
  1088. return this.toRGBString();
  1089. case "rgba":
  1090. return this.toRGBAString();
  1091. }
  1092. return !1;
  1093. };
  1094. this.toHEXString = function () {
  1095. return a.hexColor(this.channels.r, this.channels.g, this.channels.b);
  1096. };
  1097. this.toHEXAString = function () {
  1098. return a.hexaColor(this.channels.r, this.channels.g, this.channels.b, this.channels.a);
  1099. };
  1100. this.toRGBString = function () {
  1101. return a.rgbColor(this.channels.r, this.channels.g, this.channels.b);
  1102. };
  1103. this.toRGBAString = function () {
  1104. return a.rgbaColor(this.channels.r, this.channels.g, this.channels.b, this.channels.a);
  1105. };
  1106. this.hide = function () {
  1107. t() &&
  1108. (a.removeClass(f.targetElement, a.pub.activeClassName), a.picker.wrap && a.picker.wrap.parentNode && a.picker.wrap.parentNode.removeChild(a.picker.wrap), delete a.picker.owner);
  1109. };
  1110. this.show = function () {
  1111. l();
  1112. };
  1113. this.redraw = function () {
  1114. t() && l();
  1115. };
  1116. this.getFormat = function () {
  1117. return this._currentFormat;
  1118. };
  1119. this._setFormat = function (c) {
  1120. this._currentFormat = c.toLowerCase();
  1121. };
  1122. this.hasAlphaChannel = function () {
  1123. return "auto" === this.alphaChannel
  1124. ? "any" === this.format.toLowerCase() || a.isAlphaFormat(this.getFormat()) || "undefined" !== typeof this.alpha || "undefined" !== typeof this.alphaElement
  1125. : this.alphaChannel;
  1126. };
  1127. this.processValueInput = function (c) {
  1128. this.fromString(c) || this.exposeColor();
  1129. };
  1130. this.processAlphaInput = function (c) {
  1131. this.fromHSVA(null, null, null, parseFloat(c)) || this.exposeColor();
  1132. };
  1133. this.exposeColor = function (c) {
  1134. var h = this.toString(),
  1135. m = this.getFormat();
  1136. a.setDataAttr(this.targetElement, "current-color", h);
  1137. if (!(c & a.flags.leaveValue) && this.valueElement) {
  1138. if ("hex" === m || "hexa" === m) this.uppercase || (h = h.toLowerCase()), this.hash || (h = h.replace(/^#/, ""));
  1139. this.setValueElementValue(h);
  1140. }
  1141. c & a.flags.leaveAlpha || !this.alphaElement || this.setAlphaElementValue(Math.round(100 * this.channels.a) / 100);
  1142. c & a.flags.leavePreview || !this.previewElement || this.setPreviewElementBg(this.toRGBAString());
  1143. t() && (k(), n(), q());
  1144. };
  1145. this.setPreviewElementBg = function (c) {
  1146. if (this.previewElement) {
  1147. var h = null,
  1148. m = null;
  1149. a.isTextInput(this.previewElement) && ((h = this.previewPosition), (m = this.previewSize));
  1150. var r = [];
  1151. r.push({ size: "auto" });
  1152. if (c) {
  1153. var w = a.genColorPreviewCanvas("rgba(0,0,0,0)", h ? { left: "right", right: "left" }[h] : null, m, !0);
  1154. r.push({ size: w.width + "px " + w.height + "px" });
  1155. }
  1156. w = [];
  1157. for (var x = 0; x < r.length; x += 1) w.push(r[x].size);
  1158. c = {
  1159. "--fr-input-color": c,
  1160. "--fr-input-color-edge": m + "px",
  1161. "--fr-input-color-edge2": m + 1 + "px",
  1162. "--fr-input-gb-size": w.join(", "),
  1163. };
  1164. a.setStyle(this.previewElement, c, !this.forceStyle);
  1165. c = { left: null, right: null };
  1166. h && (c[h] = this.previewSize + this.previewPadding + "px");
  1167. c = { "--fr-input-padding-left": c.left };
  1168. a.setStyle(this.previewElement, c, !this.forceStyle, !0);
  1169. }
  1170. };
  1171. this.setValueElementValue = function (c) {
  1172. this.valueElement && ("input" === a.nodeName(this.valueElement) ? (this.valueElement.value = c) : (this.valueElement.textContent = c));
  1173. };
  1174. this._processParentElementsInDOM = function () {
  1175. if (!this._parentElementsProcessed) {
  1176. this._parentElementsProcessed = !0;
  1177. var c = this.targetElement;
  1178. do {
  1179. var h = a.getCompStyle(c);
  1180. c instanceof ShadowRoot && (this.fixed = !0);
  1181. h.position && "fixed" === h.position.toLowerCase() && (this.fixed = !0);
  1182. } while ((c = c.parentNode) && "body" !== a.nodeName(c));
  1183. }
  1184. };
  1185. this.tryHide = function () {
  1186. this.hideOnLeave && this.hide();
  1187. };
  1188. if (a.pub.options)
  1189. for (var z in a.pub.options)
  1190. if (a.hOP.call(a.pub.options, z))
  1191. try {
  1192. g(z, a.pub.options[z]);
  1193. } catch (c) {
  1194. console.error(c);
  1195. }
  1196. for (z in e)
  1197. if (a.hOP.call(e, z) && -1 === ["preset"].indexOf(z))
  1198. try {
  1199. g(z, e[z]);
  1200. } catch (c) {
  1201. console.error(c);
  1202. }
  1203. this.container = "undefined" === typeof this.container ? p.document.documentElement : a.node(this.container);
  1204. if (!this.container) throw Error("No container element");
  1205. this.targetElement = a.node(b);
  1206. if (!this.targetElement) throw Error("No target element");
  1207. if (this.targetElement.frcp && this.targetElement.frcp instanceof a.pub) throw Error("Redundant Fr-Color-picker");
  1208. this.targetElement.frcp = this;
  1209. a.addClass(this.targetElement, a.pub.className);
  1210. a.instances.push(this);
  1211. "undefined" === typeof this.valueElement
  1212. ? a.isTextInput(this.targetElement) && (this.valueElement = this.targetElement)
  1213. : null !== this.valueElement && (this.valueElement = a.node(this.valueElement));
  1214. "undefined" === typeof this.previewElement ? (this.previewElement = this.targetElement) : null !== this.previewElement && (this.previewElement = a.node(this.previewElement));
  1215. this.valueElement &&
  1216. a.isTextInput(this.valueElement) &&
  1217. ((b = this.valueElement.oninput),
  1218. (this.valueElement.oninput = null),
  1219. this.valueElement.addEventListener("change", u, !1),
  1220. this.valueElement.addEventListener("input", v, !1),
  1221. b && this.valueElement.addEventListener("input", b, !1),
  1222. this.valueElement.setAttribute("autocomplete", "off"),
  1223. this.valueElement.setAttribute("autocorrect", "off"),
  1224. this.valueElement.setAttribute("autocapitalize", "off"),
  1225. this.valueElement.setAttribute("spellcheck", !1));
  1226. b = "FFFFFF";
  1227. "undefined" !== typeof this.value ? (b = this.value) : this.valueElement && "undefined" !== typeof this.valueElement.value && (b = this.valueElement.value);
  1228. d = void 0;
  1229. "undefined" !== typeof this.alpha && (d = "" + this.alpha);
  1230. this._currentFormat = null;
  1231. -1 < ["auto", "any"].indexOf(this.format.toLowerCase()) ? (this._currentFormat = (e = a.parseColorString(b)) ? e.format : "hex") : (this._currentFormat = this.format.toLowerCase());
  1232. this.processValueInput(b);
  1233. "undefined" !== typeof d && this.processAlphaInput(d);
  1234. },
  1235. };
  1236. a.pub.className = C;
  1237. a.pub.activeClassName = E;
  1238. a.pub.looseJSON = !0;
  1239. a.pub.sliderInnerSpace = 3;
  1240. a.pub.chessboardSize = 8;
  1241. a.pub.chessboardColor1 = "#666666";
  1242. a.pub.chessboardColor2 = "#999999";
  1243. a.pub.previewSeparator = [];
  1244. a.pub.init = function () {
  1245. if (!a.initialized) {
  1246. p.document.addEventListener("mousedown", a.onDocumentMouseDown, !1);
  1247. p.addEventListener("resize", a.onWindowResize, !1);
  1248. p.addEventListener("scroll", a.onWindowScroll, !1);
  1249. a.initialized = !0;
  1250. for (var b; (b = a.readyQueue.shift()); ) b();
  1251. }
  1252. };
  1253. a.pub.ready = function (b) {
  1254. if ("function" !== typeof b) return !1;
  1255. a.initialized ? b() : a.readyQueue.push(b);
  1256. return !0;
  1257. };
  1258. a.pub.trigger = function (b) {
  1259. var d = function () {
  1260. a.triggerGlobal(b);
  1261. };
  1262. a.initialized ? d() : a.pub.ready(d);
  1263. };
  1264. a.pub.hide = function () {
  1265. a.picker && a.picker.owner && a.picker.owner.hide();
  1266. };
  1267. a.pub.options = {};
  1268. a.pub.lookupClass = C;
  1269. a.pub.installByClassName = function () {
  1270. return !1;
  1271. };
  1272. a.register();
  1273. return a.pub;
  1274. })();
  1275. "undefined" === typeof p.FRColorPicker && (p.FRColorPicker = A);
  1276. return A;
  1277. });