@luminescent/ui 0.1.2 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -324,218 +324,6 @@ const CardHeader = /* @__PURE__ */ componentQrl(/* @__PURE__ */ inlinedQrl((prop
324
324
  }, 3, "OW_6"), 1, "OW_7")
325
325
  ], 1, "OW_8");
326
326
  }, "CardHeader_component_2xQZ6Uv7R4A"));
327
- var insertCss$1 = { exports: {} };
328
- var containers = [];
329
- var styleElements = [];
330
- var usage = "insert-css: You need to provide a CSS string. Usage: insertCss(cssString[, options]).";
331
- function insertCss(css, options) {
332
- options = options || {};
333
- if (css === void 0) {
334
- throw new Error(usage);
335
- }
336
- var position = options.prepend === true ? "prepend" : "append";
337
- var container = options.container !== void 0 ? options.container : document.querySelector("head");
338
- var containerId = containers.indexOf(container);
339
- if (containerId === -1) {
340
- containerId = containers.push(container) - 1;
341
- styleElements[containerId] = {};
342
- }
343
- var styleElement;
344
- if (styleElements[containerId] !== void 0 && styleElements[containerId][position] !== void 0) {
345
- styleElement = styleElements[containerId][position];
346
- } else {
347
- styleElement = styleElements[containerId][position] = createStyleElement();
348
- if (position === "prepend") {
349
- container.insertBefore(styleElement, container.childNodes[0]);
350
- } else {
351
- container.appendChild(styleElement);
352
- }
353
- }
354
- if (css.charCodeAt(0) === 65279) {
355
- css = css.substr(1, css.length);
356
- }
357
- if (styleElement.styleSheet) {
358
- styleElement.styleSheet.cssText += css;
359
- } else {
360
- styleElement.textContent += css;
361
- }
362
- return styleElement;
363
- }
364
- function createStyleElement() {
365
- var styleElement = document.createElement("style");
366
- styleElement.setAttribute("type", "text/css");
367
- return styleElement;
368
- }
369
- insertCss$1.exports = insertCss;
370
- var insertCss_2 = insertCss$1.exports.insertCss = insertCss;
371
- function e(t, e2) {
372
- for (var i2 = 0; i2 < e2.length; i2++) {
373
- var o2 = e2[i2];
374
- o2.enumerable = o2.enumerable || false, o2.configurable = true, "value" in o2 && (o2.writable = true), Object.defineProperty(t, o2.key, o2);
375
- }
376
- }
377
- function i(t, i2, o2) {
378
- return i2 && e(t.prototype, i2), o2 && e(t, o2), t;
379
- }
380
- function o(t) {
381
- return "number" == typeof t && !isNaN(t);
382
- }
383
- function s(t, e2, i2) {
384
- return Math.min(Math.max(t, e2), i2);
385
- }
386
- function n(t) {
387
- if (0 === t.type.indexOf("touch")) {
388
- var e2 = t.touches[0];
389
- return { x: e2.clientX, y: e2.clientY };
390
- }
391
- return { x: t.clientX, y: t.clientY };
392
- }
393
- function r(t) {
394
- return 1 == t.length ? "0" + t : "" + t;
395
- }
396
- var h = function() {
397
- function t(t2) {
398
- this._rgba = { r: 0, g: 0, b: 0, a: 1 }, this._hsva = { h: 0, s: 0, v: 0, a: 1 }, this.fromHex(t2);
399
- }
400
- var e2 = t.prototype;
401
- return e2.fromHex = function(t2) {
402
- t2 || (t2 = 0), o(t2) ? (this._hexNumber = t2, this._hexString = function(t3) {
403
- return "#" + ("00000" + (0 | t3).toString(16)).substr(-6).toUpperCase();
404
- }(this._hexNumber)) : (this._hexString = t2.toUpperCase(), this._hexNumber = u(this._hexString));
405
- var e3 = function(t3) {
406
- return { r: (t3 >> 16 & 255) / 255, g: (t3 >> 8 & 255) / 255, b: (255 & t3) / 255 };
407
- }(this._hexNumber), i2 = e3.g, s2 = e3.b;
408
- this._rgba.r = e3.r, this._rgba.g = i2, this._rgba.b = s2;
409
- var n2 = function(t3) {
410
- var e4, i3 = t3.r, o2 = t3.g, s3 = t3.b, n3 = Math.max(i3, o2, s3), r3 = Math.min(i3, o2, s3), h3 = n3 - r3, u2 = 0 === n3 ? 0 : h3 / n3, a2 = n3;
411
- if (n3 == r3)
412
- e4 = 0;
413
- else {
414
- switch (n3) {
415
- case i3:
416
- e4 = (o2 - s3) / h3 + (o2 < s3 ? 6 : 0);
417
- break;
418
- case o2:
419
- e4 = (s3 - i3) / h3 + 2;
420
- break;
421
- case s3:
422
- e4 = (i3 - o2) / h3 + 4;
423
- }
424
- e4 /= 6;
425
- }
426
- return { h: e4, s: u2, v: a2 };
427
- }(this._rgba), r2 = n2.s, h2 = n2.v;
428
- this._hsva.h = n2.h, this._hsva.s = r2, this._hsva.v = h2, this._updateBrightness();
429
- }, e2.fromHsv = function(t2) {
430
- var e3 = t2.s, i2 = t2.v;
431
- this._hsva.h = t2.h, this._hsva.s = e3, this._hsva.v = i2;
432
- var o2 = function(t3) {
433
- var e4 = t3.h, i3 = t3.s, o3 = t3.v;
434
- e4 *= 6;
435
- var s3 = Math.floor(e4), n3 = e4 - s3, r2 = o3 * (1 - i3), h2 = o3 * (1 - n3 * i3), u2 = o3 * (1 - (1 - n3) * i3), a2 = s3 % 6;
436
- return { r: [o3, h2, r2, r2, u2, o3][a2], g: [u2, o3, o3, h2, r2, r2][a2], b: [r2, r2, u2, o3, o3, h2][a2] };
437
- }(this._hsva), s2 = o2.g, n2 = o2.b;
438
- this._rgba.r = o2.r, this._rgba.g = s2, this._rgba.b = n2, this._hexString = function(t3) {
439
- var e4 = t3.g, i3 = t3.b;
440
- return ["#", r(Math.round(255 * t3.r).toString(16)), r(Math.round(255 * e4).toString(16)), r(Math.round(255 * i3).toString(16))].join("").toUpperCase();
441
- }(this._rgba), this._hexNumber = u(this._hexString), this._updateBrightness();
442
- }, e2._updateBrightness = function() {
443
- var t2 = this._rgba;
444
- this._brightness = (299 * t2.r + 587 * t2.g + 114 * t2.b) / 1e3, this._isDark = this._brightness < 0.5, this._isLight = !this._isDark;
445
- }, i(t, [{ key: "rgb", get: function() {
446
- return this._rgba;
447
- } }, { key: "hsv", get: function() {
448
- return this._hsva;
449
- } }, { key: "hex", get: function() {
450
- return this._hexNumber;
451
- } }, { key: "hexString", get: function() {
452
- return this._hexString;
453
- } }, { key: "brightness", get: function() {
454
- return this._brightness;
455
- } }, { key: "isDark", get: function() {
456
- return this._isDark;
457
- } }, { key: "isLight", get: function() {
458
- return this._isLight;
459
- } }]), t;
460
- }();
461
- function u(t) {
462
- return parseInt(t.replace("#", ""), 16);
463
- }
464
- var a = function() {
465
- function t(t2) {
466
- var e3 = this;
467
- void 0 === t2 && (t2 = {}), this._widthUnits = "px", this._heightUnits = "px", this._huePosition = 0, this._hueHeight = 0, this._maxHue = 0, this._inputIsNumber = false, this._saturationWidth = 0, this._isChoosing = false, this._callbacks = [], this.width = 0, this.height = 0, this.hue = 0, this.position = { x: 0, y: 0 }, this.color = new h(0), this.backgroundColor = new h(0), this.hueColor = new h(0), this._onSaturationMouseDown = function(t3) {
468
- var i2 = e3.$saturation.getBoundingClientRect(), o2 = n(t3), s2 = o2.x, r2 = o2.y;
469
- e3._isChoosing = true, e3._moveSelectorTo(s2 - i2.left, r2 - i2.top), e3._updateColorFromPosition(), e3._window.addEventListener("mouseup", e3._onSaturationMouseUp), e3._window.addEventListener("touchend", e3._onSaturationMouseUp), e3._window.addEventListener("mousemove", e3._onSaturationMouseMove), e3._window.addEventListener("touchmove", e3._onSaturationMouseMove), t3.preventDefault();
470
- }, this._onSaturationMouseMove = function(t3) {
471
- var i2 = e3.$saturation.getBoundingClientRect(), o2 = n(t3);
472
- e3._moveSelectorTo(o2.x - i2.left, o2.y - i2.top), e3._updateColorFromPosition();
473
- }, this._onSaturationMouseUp = function() {
474
- e3._isChoosing = false, e3._window.removeEventListener("mouseup", e3._onSaturationMouseUp), e3._window.removeEventListener("touchend", e3._onSaturationMouseUp), e3._window.removeEventListener("mousemove", e3._onSaturationMouseMove), e3._window.removeEventListener("touchmove", e3._onSaturationMouseMove);
475
- }, this._onHueMouseDown = function(t3) {
476
- var i2 = e3.$hue.getBoundingClientRect(), o2 = n(t3).y;
477
- e3._isChoosing = true, e3._moveHueTo(o2 - i2.top), e3._updateHueFromPosition(), e3._window.addEventListener("mouseup", e3._onHueMouseUp), e3._window.addEventListener("touchend", e3._onHueMouseUp), e3._window.addEventListener("mousemove", e3._onHueMouseMove), e3._window.addEventListener("touchmove", e3._onHueMouseMove), t3.preventDefault();
478
- }, this._onHueMouseMove = function(t3) {
479
- var i2 = e3.$hue.getBoundingClientRect(), o2 = n(t3);
480
- e3._moveHueTo(o2.y - i2.top), e3._updateHueFromPosition();
481
- }, this._onHueMouseUp = function() {
482
- e3._isChoosing = false, e3._window.removeEventListener("mouseup", e3._onHueMouseUp), e3._window.removeEventListener("touchend", e3._onHueMouseUp), e3._window.removeEventListener("mousemove", e3._onHueMouseMove), e3._window.removeEventListener("touchmove", e3._onHueMouseMove);
483
- }, this._window = t2.window || window, this._document = this._window.document, this.$el = this._document.createElement("div"), this.$el.className = "Scp", this.$el.innerHTML = '\n <div class="Scp-saturation">\n <div class="Scp-brightness"></div>\n <div class="Scp-sbSelector"></div>\n </div>\n <div class="Scp-hue">\n <div class="Scp-hSelector"></div>\n </div>\n ', this.$saturation = this.$el.querySelector(".Scp-saturation"), this.$hue = this.$el.querySelector(".Scp-hue"), this.$sbSelector = this.$el.querySelector(".Scp-sbSelector"), this.$hSelector = this.$el.querySelector(".Scp-hSelector"), this.$saturation.addEventListener("mousedown", this._onSaturationMouseDown), this.$saturation.addEventListener("touchstart", this._onSaturationMouseDown), this.$hue.addEventListener("mousedown", this._onHueMouseDown), this.$hue.addEventListener("touchstart", this._onHueMouseDown), t2.el && this.appendTo(t2.el), t2.background && this.setBackgroundColor(t2.background), t2.widthUnits && (this._widthUnits = t2.widthUnits), t2.heightUnits && (this._heightUnits = t2.heightUnits), this.setSize(t2.width || 175, t2.height || 150), this.setColor(t2.color);
484
- }
485
- var e2 = t.prototype;
486
- return e2.appendTo = function(t2) {
487
- return "string" == typeof t2 ? document.querySelector(t2).appendChild(this.$el) : t2.appendChild(this.$el), this;
488
- }, e2.remove = function() {
489
- this._callbacks = [], this._onSaturationMouseUp(), this._onHueMouseUp(), this.$saturation.removeEventListener("mousedown", this._onSaturationMouseDown), this.$saturation.removeEventListener("touchstart", this._onSaturationMouseDown), this.$hue.removeEventListener("mousedown", this._onHueMouseDown), this.$hue.removeEventListener("touchstart", this._onHueMouseDown), this.$el.parentNode && this.$el.parentNode.removeChild(this.$el);
490
- }, e2.setColor = function(t2) {
491
- this._inputIsNumber = o(t2), this.color.fromHex(t2);
492
- var e3 = this.color.hsv, i2 = e3.h, s2 = e3.s, n2 = e3.v;
493
- return isNaN(i2) || (this.hue = i2), this._moveSelectorTo(this._saturationWidth * s2, (1 - n2) * this._hueHeight), this._moveHueTo((1 - this.hue) * this._hueHeight), this._updateHue(), this;
494
- }, e2.setSize = function(t2, e3) {
495
- return this.width = t2, this.height = e3, this.$el.style.width = this.width + this._widthUnits, this.$el.style.height = this.height + this._heightUnits, this._saturationWidth = this.width - 25, this.$saturation.style.width = this._saturationWidth + "px", this._hueHeight = this.height, this._maxHue = this._hueHeight - 2, this;
496
- }, e2.setBackgroundColor = function(t2) {
497
- return this.backgroundColor.fromHex(t2), this.$el.style.padding = "5px", this.$el.style.background = this.backgroundColor.hexString, this;
498
- }, e2.setNoBackground = function() {
499
- return this.$el.style.padding = "0px", this.$el.style.background = "none", this;
500
- }, e2.onChange = function(t2) {
501
- return this._callbacks.indexOf(t2) < 0 && (this._callbacks.push(t2), t2(this.getHexString())), this;
502
- }, e2.getColor = function() {
503
- return this._inputIsNumber ? this.getHexNumber() : this.getHexString();
504
- }, e2.getHexString = function() {
505
- return this.color.hexString.toUpperCase();
506
- }, e2.getHexNumber = function() {
507
- return this.color.hex;
508
- }, e2.getRGB = function() {
509
- return this.color.rgb;
510
- }, e2.getHSV = function() {
511
- return this.color.hsv;
512
- }, e2.isDark = function() {
513
- return this.color.isDark;
514
- }, e2.isLight = function() {
515
- return this.color.isLight;
516
- }, e2._moveSelectorTo = function(t2, e3) {
517
- this.position.x = s(t2, 0, this._saturationWidth), this.position.y = s(e3, 0, this._hueHeight), this.$sbSelector.style.transform = "translate(" + this.position.x + "px, " + this.position.y + "px)";
518
- }, e2._updateColorFromPosition = function() {
519
- this.color.fromHsv({ h: this.hue, s: this.position.x / this._saturationWidth, v: 1 - this.position.y / this._hueHeight }), this._updateColor();
520
- }, e2._moveHueTo = function(t2) {
521
- this._huePosition = s(t2, 0, this._maxHue), this.$hSelector.style.transform = "translateY(" + this._huePosition + "px)";
522
- }, e2._updateHueFromPosition = function() {
523
- var t2 = this.getHSV();
524
- this.hue = 1 - this._huePosition / this._maxHue, this.color.fromHsv({ h: this.hue, s: t2.s, v: t2.v }), this._updateHue();
525
- }, e2._updateHue = function() {
526
- this.hueColor.fromHsv({ h: this.hue, s: 1, v: 1 }), this.$saturation.style.background = "linear-gradient(to right, #fff, " + this.hueColor.hexString + ")", this._updateColor();
527
- }, e2._updateColor = function() {
528
- this.$sbSelector.style.background = this.getHexString(), this.$sbSelector.style.borderColor = this.isDark() ? "#fff" : "#000", this._triggerChange();
529
- }, e2._triggerChange = function() {
530
- var t2 = this;
531
- this._callbacks.forEach(function(e3) {
532
- return e3(t2.getHexString());
533
- });
534
- }, i(t, [{ key: "isChoosing", get: function() {
535
- return this._isChoosing;
536
- } }]), t;
537
- }();
538
- insertCss_2(".Scp{-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;position:relative}.Scp-saturation{position:relative;height:100%;background:linear-gradient(90deg,#fff,red);float:left;margin-right:5px}.Scp-brightness{width:100%;height:100%;background:linear-gradient(hsla(0,0%,100%,0),#000)}.Scp-sbSelector{border:2px solid #fff;position:absolute;width:14px;height:14px;background:#fff;border-radius:10px;top:-7px;left:-7px;box-sizing:border-box;z-index:10}.Scp-hue{width:20px;height:100%;position:relative;float:left;background:linear-gradient(red,#f0f 17%,#00f 34%,#0ff 50%,#0f0 67%,#ff0 84%,red)}.Scp-hSelector{position:absolute;background:#fff;border-bottom:1px solid #000;right:-3px;width:10px;height:2px}");
539
327
  const TextInput = /* @__PURE__ */ componentQrl(/* @__PURE__ */ inlinedQrl((props) => {
540
328
  return /* @__PURE__ */ _jsxQ("div", null, {
541
329
  class: "flex flex-col"
@@ -563,10 +351,511 @@ const TextInputRaw = /* @__PURE__ */ componentQrl(/* @__PURE__ */ inlinedQrl((pr
563
351
  }
564
352
  }, null, 0, "dC_2");
565
353
  }, "TextInputRaw_component_ssloWlmBB4w"));
354
+ const clamp = (value, min, max) => Math.min(Math.max(value, min), max);
355
+ function getMousePosition(e) {
356
+ if (e instanceof TouchEvent) {
357
+ const touch = e.touches[0];
358
+ return {
359
+ x: touch.clientX,
360
+ y: touch.clientY
361
+ };
362
+ }
363
+ const mouse = e;
364
+ return {
365
+ x: mouse.clientX,
366
+ y: mouse.clientY
367
+ };
368
+ }
369
+ const pad2 = (c) => c.length == 1 ? "0" + c : "" + c;
370
+ class Color {
371
+ constructor(color) {
372
+ this._rgba = {
373
+ r: 0,
374
+ g: 0,
375
+ b: 0,
376
+ a: 1
377
+ };
378
+ this._hsva = {
379
+ h: 0,
380
+ s: 0,
381
+ v: 0,
382
+ a: 1
383
+ };
384
+ this.fromHex(color);
385
+ }
386
+ fromHex(color = 0) {
387
+ if (typeof color === "number") {
388
+ this._hexNumber = color;
389
+ this._hexString = numberToHexString(this._hexNumber);
390
+ } else {
391
+ this._hexString = color.toUpperCase();
392
+ this._hexNumber = hexStringToNumber(this._hexString);
393
+ }
394
+ const { r, g, b } = hexNumberToRgb(this._hexNumber);
395
+ this._rgba.r = r;
396
+ this._rgba.g = g;
397
+ this._rgba.b = b;
398
+ const { h, s, v } = rgbToHsv(this._rgba);
399
+ this._hsva.h = h;
400
+ this._hsva.s = s;
401
+ this._hsva.v = v;
402
+ this._updateBrightness();
403
+ }
404
+ fromHsv(color) {
405
+ const { h, s, v } = color;
406
+ this._hsva.h = h;
407
+ this._hsva.s = s;
408
+ this._hsva.v = v;
409
+ const { r, g, b } = hsvToRgb(this._hsva);
410
+ this._rgba.r = r;
411
+ this._rgba.g = g;
412
+ this._rgba.b = b;
413
+ this._hexString = rgbToHex(this._rgba);
414
+ this._hexNumber = hexStringToNumber(this._hexString);
415
+ this._updateBrightness();
416
+ }
417
+ _updateBrightness() {
418
+ const { r, g, b } = this._rgba;
419
+ this._brightness = (r * 299 + g * 587 + b * 114) / 1e3;
420
+ this._isDark = this._brightness < 0.5;
421
+ this._isLight = !this._isDark;
422
+ }
423
+ get rgb() {
424
+ return this._rgba;
425
+ }
426
+ get hsv() {
427
+ return this._hsva;
428
+ }
429
+ get hex() {
430
+ return this._hexNumber;
431
+ }
432
+ get hexString() {
433
+ return this._hexString;
434
+ }
435
+ get brightness() {
436
+ return this._brightness;
437
+ }
438
+ get isDark() {
439
+ return this._isDark;
440
+ }
441
+ get isLight() {
442
+ return this._isLight;
443
+ }
444
+ }
445
+ function hexNumberToRgb(color) {
446
+ const r = (color >> 16 & 255) / 255;
447
+ const g = (color >> 8 & 255) / 255;
448
+ const b = (color & 255) / 255;
449
+ return {
450
+ r,
451
+ g,
452
+ b
453
+ };
454
+ }
455
+ function rgbToHex(color) {
456
+ const { r, g, b } = color;
457
+ const hex = [
458
+ "#",
459
+ pad2(Math.round(r * 255).toString(16)),
460
+ pad2(Math.round(g * 255).toString(16)),
461
+ pad2(Math.round(b * 255).toString(16))
462
+ ];
463
+ return hex.join("").toUpperCase();
464
+ }
465
+ const numberToHexString = (color) => "#" + ("00000" + (color | 0).toString(16)).substr(-6).toUpperCase();
466
+ const hexStringToNumber = (color) => parseInt(color.replace("#", ""), 16);
467
+ function hsvToRgb(color) {
468
+ let { h } = color;
469
+ const { s, v } = color;
470
+ h *= 6;
471
+ const i = Math.floor(h);
472
+ const f = h - i;
473
+ const p = v * (1 - s);
474
+ const q = v * (1 - f * s);
475
+ const t = v * (1 - (1 - f) * s);
476
+ const mod = i % 6;
477
+ const r = [
478
+ v,
479
+ q,
480
+ p,
481
+ p,
482
+ t,
483
+ v
484
+ ][mod];
485
+ const g = [
486
+ t,
487
+ v,
488
+ v,
489
+ q,
490
+ p,
491
+ p
492
+ ][mod];
493
+ const b = [
494
+ p,
495
+ p,
496
+ t,
497
+ v,
498
+ v,
499
+ q
500
+ ][mod];
501
+ return {
502
+ r,
503
+ g,
504
+ b
505
+ };
506
+ }
507
+ function rgbToHsv(color) {
508
+ const { r, g, b } = color;
509
+ const max = Math.max(r, g, b);
510
+ const min = Math.min(r, g, b);
511
+ const d = max - min;
512
+ const s = max === 0 ? 0 : d / max;
513
+ const v = max;
514
+ let h = 0;
515
+ if (max != min) {
516
+ switch (max) {
517
+ case r:
518
+ h = (g - b) / d + (g < b ? 6 : 0);
519
+ break;
520
+ case g:
521
+ h = (b - r) / d + 2;
522
+ break;
523
+ case b:
524
+ h = (r - g) / d + 4;
525
+ break;
526
+ }
527
+ h /= 6;
528
+ }
529
+ return {
530
+ h,
531
+ s,
532
+ v
533
+ };
534
+ }
535
+ class ColorPicker {
536
+ constructor(options = {}) {
537
+ this._widthUnits = "px";
538
+ this._heightUnits = "px";
539
+ this._huePosition = 0;
540
+ this._hueHeight = 0;
541
+ this._maxHue = 0;
542
+ this._inputIsNumber = false;
543
+ this._saturationWidth = 0;
544
+ this._isChoosing = false;
545
+ this._callbacks = [];
546
+ this.width = 0;
547
+ this.height = 0;
548
+ this.hue = 0;
549
+ this.position = {
550
+ x: 0,
551
+ y: 0
552
+ };
553
+ this.color = new Color(0);
554
+ this.backgroundColor = new Color(0);
555
+ this.hueColor = new Color(0);
556
+ this._onSaturationMouseDown = (e) => {
557
+ const sbOffset = this.$saturation.getBoundingClientRect();
558
+ const { x, y } = getMousePosition(e);
559
+ this._isChoosing = true;
560
+ this._moveSelectorTo(x - sbOffset.left, y - sbOffset.top);
561
+ this._updateColorFromPosition();
562
+ this._window.addEventListener("mouseup", this._onSaturationMouseUp);
563
+ this._window.addEventListener("touchend", this._onSaturationMouseUp);
564
+ this._window.addEventListener("mousemove", this._onSaturationMouseMove);
565
+ this._window.addEventListener("touchmove", this._onSaturationMouseMove);
566
+ e.preventDefault();
567
+ };
568
+ this._onSaturationMouseMove = (e) => {
569
+ const sbOffset = this.$saturation.getBoundingClientRect();
570
+ const { x, y } = getMousePosition(e);
571
+ this._moveSelectorTo(x - sbOffset.left, y - sbOffset.top);
572
+ this._updateColorFromPosition();
573
+ };
574
+ this._onSaturationMouseUp = () => {
575
+ this._isChoosing = false;
576
+ this._window.removeEventListener("mouseup", this._onSaturationMouseUp);
577
+ this._window.removeEventListener("touchend", this._onSaturationMouseUp);
578
+ this._window.removeEventListener("mousemove", this._onSaturationMouseMove);
579
+ this._window.removeEventListener("touchmove", this._onSaturationMouseMove);
580
+ };
581
+ this._onHueMouseDown = (e) => {
582
+ const hOffset = this.$hue.getBoundingClientRect();
583
+ const { y } = getMousePosition(e);
584
+ this._isChoosing = true;
585
+ this._moveHueTo(y - hOffset.top);
586
+ this._updateHueFromPosition();
587
+ this._window.addEventListener("mouseup", this._onHueMouseUp);
588
+ this._window.addEventListener("touchend", this._onHueMouseUp);
589
+ this._window.addEventListener("mousemove", this._onHueMouseMove);
590
+ this._window.addEventListener("touchmove", this._onHueMouseMove);
591
+ e.preventDefault();
592
+ };
593
+ this._onHueMouseMove = (e) => {
594
+ const hOffset = this.$hue.getBoundingClientRect();
595
+ const { y } = getMousePosition(e);
596
+ this._moveHueTo(y - hOffset.top);
597
+ this._updateHueFromPosition();
598
+ };
599
+ this._onHueMouseUp = () => {
600
+ this._isChoosing = false;
601
+ this._window.removeEventListener("mouseup", this._onHueMouseUp);
602
+ this._window.removeEventListener("touchend", this._onHueMouseUp);
603
+ this._window.removeEventListener("mousemove", this._onHueMouseMove);
604
+ this._window.removeEventListener("touchmove", this._onHueMouseMove);
605
+ };
606
+ this._window = options.window || window;
607
+ this._document = this._window.document;
608
+ this.$el = this._document.createElement("div");
609
+ this.$el.className = "color-picker";
610
+ this.$el.innerHTML = `
611
+ <div class="color-picker-saturation">
612
+ <div class="color-picker-brightness"></div>
613
+ <div class="color-picker-sbSelector"></div>
614
+ </div>
615
+ <div class="color-picker-hue">
616
+ <div class="color-picker-hSelector"></div>
617
+ </div>
618
+ `;
619
+ this.$saturation = this.$el.querySelector(".color-picker-saturation");
620
+ this.$hue = this.$el.querySelector(".color-picker-hue");
621
+ this.$sbSelector = this.$el.querySelector(".color-picker-sbSelector");
622
+ this.$hSelector = this.$el.querySelector(".color-picker-hSelector");
623
+ this.$saturation.addEventListener("mousedown", this._onSaturationMouseDown);
624
+ this.$saturation.addEventListener("touchstart", this._onSaturationMouseDown);
625
+ this.$hue.addEventListener("mousedown", this._onHueMouseDown);
626
+ this.$hue.addEventListener("touchstart", this._onHueMouseDown);
627
+ if (options.el)
628
+ this.appendTo(options.el);
629
+ if (options.background)
630
+ this.setBackgroundColor(options.background);
631
+ if (options.widthUnits)
632
+ this._widthUnits = options.widthUnits;
633
+ if (options.heightUnits)
634
+ this._heightUnits = options.heightUnits;
635
+ if (options.colors) {
636
+ this.$colors = this._document.createElement("div");
637
+ this.$colors.className = "color-picker-colors";
638
+ this.$el.appendChild(this.$colors);
639
+ this.$colors.innerHTML = options.colors.map((color) => `<div class="color-picker-color" style="background: ${color}"></div>`).join("");
640
+ }
641
+ this.setSize(options.width || 175, options.height || 150);
642
+ this.setColor(options.color);
643
+ }
644
+ /**
645
+ * Add the ColorPicker instance to a DOM element.
646
+ * @param {HTMLElement} el
647
+ * @return {ColorPicker} Returns itself for chaining purpose
648
+ */
649
+ appendTo(el) {
650
+ if (typeof el === "string")
651
+ document.querySelector(el).appendChild(this.$el);
652
+ else
653
+ el.appendChild(this.$el);
654
+ return this;
655
+ }
656
+ /**
657
+ * Removes picker from its parent and kill all listeners.
658
+ * Call this method for proper destroy.
659
+ */
660
+ remove() {
661
+ this._callbacks = [];
662
+ this._onSaturationMouseUp();
663
+ this._onHueMouseUp();
664
+ this.$saturation.removeEventListener("mousedown", this._onSaturationMouseDown);
665
+ this.$saturation.removeEventListener("touchstart", this._onSaturationMouseDown);
666
+ this.$hue.removeEventListener("mousedown", this._onHueMouseDown);
667
+ this.$hue.removeEventListener("touchstart", this._onHueMouseDown);
668
+ if (this.$el.parentNode)
669
+ this.$el.parentNode.removeChild(this.$el);
670
+ }
671
+ /**
672
+ * Manually set the current color of the picker. This is the method
673
+ * used on instantiation to convert `color` option to actual color for
674
+ * the picker. Param can be a hexadecimal number or an hex String.
675
+ * @param {String|Number} color hex color desired
676
+ * @return {ColorPicker} Returns itself for chaining purpose
677
+ */
678
+ setColor(color) {
679
+ this._inputIsNumber = !isNaN(Number(color));
680
+ this.color.fromHex(color);
681
+ const { h, s, v } = this.color.hsv;
682
+ if (!isNaN(h))
683
+ this.hue = h;
684
+ this._moveSelectorTo(this._saturationWidth * s, (1 - v) * this._hueHeight);
685
+ this._moveHueTo((1 - this.hue) * this._hueHeight);
686
+ this._updateHue();
687
+ return this;
688
+ }
689
+ /**
690
+ * Set size of the color picker for a given width and height. Note that
691
+ * a padding of 5px will be added if you chose to use the background option
692
+ * of the constructor.
693
+ * @param {Number} width
694
+ * @param {Number} height
695
+ * @return {ColorPicker} Returns itself for chaining purpose
696
+ */
697
+ setSize(width, height) {
698
+ this.width = width;
699
+ this.height = height;
700
+ this.$el.style.width = this.width + this._widthUnits;
701
+ this.$el.style.height = this.height + this._heightUnits;
702
+ this._saturationWidth = this.width - 25;
703
+ this.$saturation.style.width = this._saturationWidth + "px";
704
+ this._hueHeight = this.height;
705
+ this._maxHue = this._hueHeight - 2;
706
+ return this;
707
+ }
708
+ /**
709
+ * Set the background color of the picker. It also adds a 5px padding
710
+ * for design purpose.
711
+ * @param {String|Number} color hex color desired for background
712
+ * @return {ColorPicker} Returns itself for chaining purpose
713
+ */
714
+ setBackgroundColor(color) {
715
+ this.backgroundColor.fromHex(color);
716
+ this.$el.style.padding = "5px";
717
+ this.$el.style.background = this.backgroundColor.hexString;
718
+ return this;
719
+ }
720
+ /**
721
+ * Removes background of the picker if previously set. It's no use
722
+ * calling this method if you didn't set the background option on start
723
+ * or if you didn't call setBackgroundColor previously.
724
+ */
725
+ setNoBackground() {
726
+ this.$el.style.padding = "0px";
727
+ this.$el.style.background = "none";
728
+ return this;
729
+ }
730
+ /**
731
+ * Registers callback to the update event of the picker.
732
+ * picker inherits from [component/emitter](https://github.com/component/emitter)
733
+ * so you could do the same thing by calling `colorPicker.on('update');`
734
+ * @param {Function} callback
735
+ * @return {ColorPicker} Returns itself for chaining purpose
736
+ */
737
+ onChange(callback) {
738
+ if (this._callbacks.indexOf(callback) < 0) {
739
+ this._callbacks.push(callback);
740
+ callback(this.getHexString());
741
+ }
742
+ return this;
743
+ }
744
+ /**
745
+ * Is true when mouse is down and user is currently choosing a color.
746
+ */
747
+ get isChoosing() {
748
+ return this._isChoosing;
749
+ }
750
+ /* =============================================================================
751
+ Color getters
752
+ ============================================================================= */
753
+ /**
754
+ * Main color getter, will return a formatted color string depending on input
755
+ * or a number depending on the last setColor call.
756
+ * @return {Number|String}
757
+ */
758
+ getColor() {
759
+ if (this._inputIsNumber)
760
+ return this.getHexNumber();
761
+ return this.getHexString();
762
+ }
763
+ /**
764
+ * Returns color as css hex string (ex: '#FF0000').
765
+ * @return {String}
766
+ */
767
+ getHexString() {
768
+ return this.color.hexString.toUpperCase();
769
+ }
770
+ /**
771
+ * Returns color as number (ex: 0xFF0000).
772
+ * @return {Number}
773
+ */
774
+ getHexNumber() {
775
+ return this.color.hex;
776
+ }
777
+ /**
778
+ * Returns color as {r: 1, g: 0, b: 0} object.
779
+ * @return {Object}
780
+ */
781
+ getRGB() {
782
+ return this.color.rgb;
783
+ }
784
+ /**
785
+ * Returns color as {h: 100, s: 1, v: 1} object.
786
+ * @return {Object}
787
+ */
788
+ getHSV() {
789
+ return this.color.hsv;
790
+ }
791
+ /**
792
+ * Returns true if color is perceived as dark
793
+ * @return {Boolean}
794
+ */
795
+ isDark() {
796
+ return this.color.isDark;
797
+ }
798
+ /**
799
+ * Returns true if color is perceived as light
800
+ * @return {Boolean}
801
+ */
802
+ isLight() {
803
+ return this.color.isLight;
804
+ }
805
+ /* =============================================================================
806
+ Private methods
807
+ ============================================================================= */
808
+ _moveSelectorTo(x, y) {
809
+ this.position.x = clamp(x, 0, this._saturationWidth);
810
+ this.position.y = clamp(y, 0, this._hueHeight);
811
+ this.$sbSelector.style.transform = `translate(${this.position.x}px, ${this.position.y}px)`;
812
+ }
813
+ _updateColorFromPosition() {
814
+ this.color.fromHsv({
815
+ h: this.hue,
816
+ s: this.position.x / this._saturationWidth,
817
+ v: 1 - this.position.y / this._hueHeight
818
+ });
819
+ this._updateColor();
820
+ }
821
+ _moveHueTo(y) {
822
+ this._huePosition = clamp(y, 0, this._maxHue);
823
+ this.$hSelector.style.transform = `translateY(${this._huePosition}px)`;
824
+ }
825
+ _updateHueFromPosition() {
826
+ const hsvColor = this.getHSV();
827
+ this.hue = 1 - this._huePosition / this._maxHue;
828
+ this.color.fromHsv({
829
+ h: this.hue,
830
+ s: hsvColor.s,
831
+ v: hsvColor.v
832
+ });
833
+ this._updateHue();
834
+ }
835
+ _updateHue() {
836
+ this.hueColor.fromHsv({
837
+ h: this.hue,
838
+ s: 1,
839
+ v: 1
840
+ });
841
+ this.$hSelector.style.background = this.hueColor.hexString;
842
+ this.$saturation.style.background = `linear-gradient(to right, #fff, ${this.hueColor.hexString})`;
843
+ this._updateColor();
844
+ }
845
+ _updateColor() {
846
+ this.$sbSelector.style.background = this.getHexString();
847
+ this.$sbSelector.style.borderColor = this.isDark() ? "#fff" : "#000";
848
+ this._triggerChange();
849
+ }
850
+ _triggerChange() {
851
+ this._callbacks.forEach((callback) => callback(this.getHexString()));
852
+ }
853
+ }
566
854
  const ColorInput = /* @__PURE__ */ componentQrl(/* @__PURE__ */ inlinedQrl((props) => {
567
855
  const props1 = _restProps(props, [
568
856
  "onInput$",
569
- "value"
857
+ "value",
858
+ "presetColors"
570
859
  ]);
571
860
  const store = useStore({
572
861
  value: (props.value ?? "#FFFFFF") || "#FFFFFF"
@@ -595,10 +884,10 @@ const ColorInput = /* @__PURE__ */ componentQrl(/* @__PURE__ */ inlinedQrl((prop
595
884
  if (!pickerDiv.children.length) {
596
885
  if (isServer)
597
886
  return;
598
- const picker = new a({
887
+ const picker = new ColorPicker({
599
888
  el: pickerDiv,
600
889
  color: store2.value,
601
- background: "#1D1D1D",
890
+ colors: props2.presetColors,
602
891
  width: 150,
603
892
  height: 150
604
893
  });
@@ -853,10 +1142,10 @@ const OutputFieldRaw = /* @__PURE__ */ componentQrl(/* @__PURE__ */ inlinedQrl((
853
1142
  alertsStore
854
1143
  ])
855
1144
  }, null, 0, null),
856
- alertsStore.alerts.map((alert, i2) => /* @__PURE__ */ _jsxQ("p", {
1145
+ alertsStore.alerts.map((alert, i) => /* @__PURE__ */ _jsxQ("p", {
857
1146
  class: _wrapSignal(alert, "class"),
858
1147
  dangerouslySetInnerHTML: _wrapSignal(alert, "text")
859
- }, null, null, 3, `output-alert${i2}`))
1148
+ }, null, null, 3, `output-alert${i}`))
860
1149
  ]
861
1150
  }, 1, "ze_2");
862
1151
  }, "OutputFieldRaw_component_OxiM0W3AR0o"));