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