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