@luminescent/ui 0.1.3 → 0.2.1

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