@alegendstale/holly-components 0.2.9 → 0.2.11

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.
Files changed (52) hide show
  1. package/dist/components/absolute-container/absolute-container.js +113 -91
  2. package/dist/components/absolute-container/absolute-container.stories.js +36 -0
  3. package/dist/components/absolute-container/index.js +1 -1
  4. package/dist/components/bottom-sheet/bottom-sheet.js +415 -308
  5. package/dist/components/bottom-sheet/bottom-sheet.stories.js +43 -0
  6. package/dist/components/bottom-sheet/bottom-sheet.test.js +15 -0
  7. package/dist/components/bottom-sheet/index.js +1 -1
  8. package/dist/components/canvas/canvas-base.d.ts +2 -1
  9. package/dist/components/canvas/canvas-base.d.ts.map +1 -1
  10. package/dist/components/canvas/canvas-base.js +56 -44
  11. package/dist/components/canvas/canvas-gradient.js +61 -45
  12. package/dist/components/canvas/canvas-image.js +158 -111
  13. package/dist/components/canvas/index.js +2 -2
  14. package/dist/components/carousel-scroller/carousel-scroller.js +133 -121
  15. package/dist/components/carousel-scroller/carousel-scroller.stories.js +40 -0
  16. package/dist/components/carousel-scroller/index.js +1 -1
  17. package/dist/components/color-palette/color-palette-utils.js +105 -41
  18. package/dist/components/color-palette/color-palette.js +429 -337
  19. package/dist/components/color-palette/component/color-palette-component.js +184 -142
  20. package/dist/components/color-palette/component/color-palette-component.stories.js +74 -0
  21. package/dist/components/color-palette/component/index.js +1 -0
  22. package/dist/components/color-palette/editor/color-palette-editor.js +702 -591
  23. package/dist/components/color-palette/editor/color-palette-editor.stories.js +39 -0
  24. package/dist/components/color-palette/editor/index.js +1 -0
  25. package/dist/components/color-palette/index.js +5 -7
  26. package/dist/components/color-palette/item/color-palette-item-edit.js +114 -87
  27. package/dist/components/color-palette/item/color-palette-item.js +155 -140
  28. package/dist/components/color-palette/item/index.js +2 -0
  29. package/dist/components/color-palette/menu/color-palette-menu.js +241 -217
  30. package/dist/components/color-palette/menu/color-palette-reorder.js +117 -103
  31. package/dist/components/color-palette/menu/index.js +2 -0
  32. package/dist/components/color-palette/storybook/color-palette-invalid.stories.js +90 -0
  33. package/dist/components/color-palette/storybook/color-palette-valid.stories.js +295 -0
  34. package/dist/components/color-palette/storybook/color-palette.stories.js +76 -0
  35. package/dist/components/tool-tip/Tooltip2.js +103 -0
  36. package/dist/components/tool-tip/index.js +1 -1
  37. package/dist/components/tool-tip/tool-tip.d.ts +1 -0
  38. package/dist/components/tool-tip/tool-tip.d.ts.map +1 -1
  39. package/dist/components/tool-tip/tool-tip.js +125 -102
  40. package/dist/components/tool-tip/tool-tip.stories.js +30 -0
  41. package/dist/index.js +6 -14
  42. package/dist/utils/EventEmitter.js +23 -23
  43. package/dist/utils/basicUtils.js +149 -32
  44. package/dist/utils/dragDropUtils.js +121 -0
  45. package/dist/utils/generateUtils.js +73 -39
  46. package/dist/utils/types.d.ts +1 -1
  47. package/dist/utils/types.d.ts.map +1 -1
  48. package/dist/utils/types.js +1 -0
  49. package/package.json +1 -1
  50. package/dist/_virtual/_commonjsHelpers.js +0 -8
  51. package/dist/_virtual/x11.js +0 -4
  52. package/dist/node_modules/colorsea/colors/x11.js +0 -14
@@ -0,0 +1,103 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ import { html, css, LitElement } from 'lit';
8
+ import { customElement, property } from 'lit/decorators.js';
9
+ const enterEvents = ['pointerenter', 'focus'];
10
+ const leaveEvents = ['pointerleave', 'blur', 'keydown', 'click'];
11
+ let SimpleTooltip = class SimpleTooltip extends LitElement {
12
+ static lazy(target, callback) {
13
+ const createTooltip = () => {
14
+ const tooltip = document.createElement('simple-tooltip');
15
+ callback(tooltip);
16
+ target.parentNode.insertBefore(tooltip, target.nextSibling);
17
+ tooltip.show();
18
+ enterEvents.forEach((eventName) => target.removeEventListener(eventName, createTooltip));
19
+ };
20
+ enterEvents.forEach((eventName) => target.addEventListener(eventName, createTooltip));
21
+ }
22
+ get target() {
23
+ return this._target;
24
+ }
25
+ set target(target) {
26
+ if (this.target) {
27
+ // Remove events from current target
28
+ enterEvents.forEach(name => this.target.removeEventListener(name, this.show));
29
+ leaveEvents.forEach(name => this.target.removeEventListener(name, this.hide));
30
+ }
31
+ if (target) {
32
+ // Add events to new target
33
+ enterEvents.forEach(name => target.addEventListener(name, this.show));
34
+ leaveEvents.forEach(name => target.addEventListener(name, this.hide));
35
+ }
36
+ this._target = target;
37
+ }
38
+ constructor() {
39
+ super();
40
+ this.offset = 4;
41
+ this.showing = false;
42
+ // Tooltip target
43
+ this._target = null;
44
+ this.addEventListener('transitionend', this.finishHide);
45
+ }
46
+ connectedCallback() {
47
+ super.connectedCallback();
48
+ this.hide();
49
+ // Set target to previous element as backup
50
+ this.target ??= this.previousElementSibling;
51
+ }
52
+ render() {
53
+ return html `<slot></slot>`;
54
+ }
55
+ show() {
56
+ this.style.cssText = '';
57
+ // Position tooltip near target
58
+ const { x, y, height } = this.target.getBoundingClientRect();
59
+ this.style.left = `${x}px`;
60
+ this.style.top = `${y + height + this.offset}px`;
61
+ this.showing = true;
62
+ }
63
+ hide() {
64
+ this.showing = false;
65
+ }
66
+ finishHide() {
67
+ if (!this.showing) {
68
+ this.style.display = 'none';
69
+ }
70
+ }
71
+ };
72
+ SimpleTooltip.styles = css `
73
+ :host {
74
+ display: inline-block;
75
+ position: fixed;
76
+ padding: 4px;
77
+ border: 1px solid darkgray;
78
+ border-radius: 4px;
79
+ background: #ccc;
80
+ pointer-events: none;
81
+
82
+ //Animation
83
+ opacity: 0;
84
+ transform: scale(0.75);
85
+ transition: opacity, transform;
86
+ transition-duration: .33s;
87
+ }
88
+
89
+ :host([showing]) {
90
+ opacity: 1;
91
+ transform: scale(1);
92
+ }
93
+ `;
94
+ __decorate([
95
+ property({ type: Number })
96
+ ], SimpleTooltip.prototype, "offset", void 0);
97
+ __decorate([
98
+ property({ type: Boolean, reflect: true })
99
+ ], SimpleTooltip.prototype, "showing", void 0);
100
+ SimpleTooltip = __decorate([
101
+ customElement('simple-tooltip')
102
+ ], SimpleTooltip);
103
+ export { SimpleTooltip };
@@ -1 +1 @@
1
- import "./tool-tip.js";
1
+ import './tool-tip';
@@ -1,4 +1,5 @@
1
1
  import { LitElement } from "lit";
2
+ import { client } from "../../utils/types";
2
3
  export type TriggerTypes = 'hover' | 'click' | 'manual';
3
4
  export declare const styles: import("lit").CSSResult;
4
5
  export declare class ToolTip extends LitElement {
@@ -1 +1 @@
1
- {"version":3,"file":"tool-tip.d.ts","sourceRoot":"","sources":["../../../src/components/tool-tip/tool-tip.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,UAAU,EAAE,MAAM,KAAK,CAAC;AAG5C,MAAM,MAAM,YAAY,GACtB,OAAO,GACP,OAAO,GACP,QAAQ,CAAA;AAEV,eAAO,MAAM,MAAM,yBAgDlB,CAAA;AAED,qBACa,OAAQ,SAAQ,UAAU;IACtC,MAAM,CAAC,MAAM,0BAAU;IAGvB,SAAS,CAAC,EAAE,oBAAoB,CAAC;IAGjC,OAAO,UAAS;IAGhB,IAAI,SAAM;IAGV,OAAO,EAAE,YAAY,CAAY;IAEjC,MAAM;IAcN;;OAEG;IACH,aAAa,QAAS;QAAE,CAAC,EAAE,MAAM,CAAC;QAAC,CAAC,EAAE,MAAM,CAAA;KAAE,UAAU,OAAO;;;MAsB7D;IAEK,kBAAkB,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO;IAIpD,WAAW,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,EAAE,MAAM;CAInC;AAED,OAAO,CAAC,MAAM,CAAC;IACd,UAAU,qBAAqB;QAC9B,UAAU,EAAE,OAAO,CAAC;KACpB;CACD"}
1
+ {"version":3,"file":"tool-tip.d.ts","sourceRoot":"","sources":["../../../src/components/tool-tip/tool-tip.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,UAAU,EAAE,MAAM,KAAK,CAAC;AAE5C,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAE3C,MAAM,MAAM,YAAY,GACtB,OAAO,GACP,OAAO,GACP,QAAQ,CAAA;AAEV,eAAO,MAAM,MAAM,yBAgDlB,CAAA;AAED,qBACa,OAAQ,SAAQ,UAAU;IACtC,MAAM,CAAC,MAAM,0BAAU;IAGvB,SAAS,CAAC,EAAE,oBAAoB,CAAC;IAGjC,OAAO,UAAS;IAGhB,IAAI,SAAM;IAGV,OAAO,EAAE,YAAY,CAAY;IAEjC,MAAM;IAcN;;OAEG;IACH,aAAa,QAAS;QAAE,CAAC,EAAE,MAAM,CAAC;QAAC,CAAC,EAAE,MAAM,CAAA;KAAE,UAAU,OAAO;;;MAsB7D;IAEK,kBAAkB,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO;IAIpD,WAAW,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,EAAE,MAAM;CAInC;AAED,OAAO,CAAC,MAAM,CAAC;IACd,UAAU,qBAAqB;QAC9B,UAAU,EAAE,OAAO,CAAC;KACpB;CACD"}
@@ -1,106 +1,129 @@
1
- import { css as h, LitElement as y, html as f } from "lit";
2
- import { query as d, property as a, customElement as c } from "lit/decorators.js";
3
- var g = Object.defineProperty, x = Object.getOwnPropertyDescriptor, n = (i, t, o, l) => {
4
- for (var e = l > 1 ? void 0 : l ? x(t, o) : t, s = i.length - 1, r; s >= 0; s--)
5
- (r = i[s]) && (e = (l ? r(t, o, e) : r(e)) || e);
6
- return l && e && g(t, o, e), e;
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
6
  };
8
- const m = h`
9
- :host {
10
- display: block;
11
- position: relative;
12
- --tooltip-x: 0;
13
- --tooltip-y: 0;
14
- }
15
-
16
- :host([display]:hover) {
17
- & > p {
18
- display: flex;
19
- }
20
- }
21
-
22
- p {
23
- display: none;
24
- align-items: center;
25
- justify-content: center;
26
-
27
- position: absolute;
28
- background: #000000C0;
29
- width: max-content;
30
- min-width: 100px;
31
- height: 40px;
32
- text-align: center;
33
- vertical-align: middle;
34
- font-size: 18px;
35
- font-weight: var(--font-medium);
36
- color: #FAFAFA;
37
- padding: 0;
38
- margin: 0;
39
- transform: translateX(-50%);
40
-
41
- left: var(--tooltip-x);
42
- top: var(--tooltip-y);
43
-
44
- /* Obsidian Styling */
45
-
46
- box-sizing: border-box;
47
- animation: pop-down 200ms forwards ease-in-out;
48
- box-shadow: 0 2px 8px var(--background-modifier-box-shadow);
49
- border-radius: var(--radius-s);
50
- line-height: var(--line-height-tight);
51
- z-index: var(--layer-tooltip);
52
- pointer-events: none;
53
- word-break: normal;
54
- overflow-wrap: anywhere;
55
- }
7
+ import { css, html, LitElement } from "lit";
8
+ import { customElement, property, query } from "lit/decorators.js";
9
+ export const styles = css `
10
+ :host {
11
+ display: block;
12
+ position: relative;
13
+ --tooltip-x: 0;
14
+ --tooltip-y: 0;
15
+ }
16
+
17
+ :host([display]:hover) {
18
+ & > p {
19
+ display: flex;
20
+ }
21
+ }
22
+
23
+ p {
24
+ display: none;
25
+ align-items: center;
26
+ justify-content: center;
27
+
28
+ position: absolute;
29
+ background: #000000C0;
30
+ width: max-content;
31
+ min-width: 100px;
32
+ height: 40px;
33
+ text-align: center;
34
+ vertical-align: middle;
35
+ font-size: 18px;
36
+ font-weight: var(--font-medium);
37
+ color: #FAFAFA;
38
+ padding: 0;
39
+ margin: 0;
40
+ transform: translateX(-50%);
41
+
42
+ left: var(--tooltip-x);
43
+ top: var(--tooltip-y);
44
+
45
+ /* Obsidian Styling */
46
+
47
+ box-sizing: border-box;
48
+ animation: pop-down 200ms forwards ease-in-out;
49
+ box-shadow: 0 2px 8px var(--background-modifier-box-shadow);
50
+ border-radius: var(--radius-s);
51
+ line-height: var(--line-height-tight);
52
+ z-index: var(--layer-tooltip);
53
+ pointer-events: none;
54
+ word-break: normal;
55
+ overflow-wrap: anywhere;
56
+ }
56
57
  `;
57
- let p = class extends y {
58
- constructor() {
59
- super(...arguments), this.display = !1, this.text = "", this.trigger = "manual", this.clampPosition = (i, t) => {
60
- if (!this.contentEl || !t) return { x: 0, y: 0 };
61
- let o = this.contentEl.offsetWidth, l = this.contentEl.offsetHeight, e = i.x - t.left > t.width / 2 ? i.x - t.left - 56 : i.x - t.left + 64, s = o / 2;
62
- e < 0 + s ? e = 0 + s : e + o > t.width + s && (e = t.width - o + s);
63
- let r = i.y - t.top - l / 4;
64
- return r < 0 ? r = 0 : r + l > t.height && (r = t.height - l), { x: e, y: r };
65
- };
66
- }
67
- render() {
68
- return f`
69
- <slot
70
- @pointerover=${() => this.display = this.trigger === "hover" ? !0 : this.display}
71
- @pointerout=${() => this.display = this.trigger === "hover" ? !1 : this.display}
72
- @click=${() => this.trigger === "click" ? this.display = !this.display : null}
73
- >
74
- </slot>
75
- <p id='content'>
76
- ${this.text}
77
- </p>
58
+ let ToolTip = class ToolTip extends LitElement {
59
+ constructor() {
60
+ super(...arguments);
61
+ this.display = false;
62
+ this.text = '';
63
+ this.trigger = 'manual';
64
+ /**
65
+ * Clamps the tooltip position to within the bounds
66
+ */
67
+ this.clampPosition = (pos, bounds) => {
68
+ if (!this.contentEl || !bounds)
69
+ return { x: 0, y: 0 };
70
+ // Get tooltip bounds
71
+ let tooltipWidth = this.contentEl.offsetWidth;
72
+ let tooltipHeight = this.contentEl.offsetHeight;
73
+ // Set tooltip position left or right side of mouse based on whether cursor is halfway
74
+ let leftPosition = pos.x - bounds.left > bounds.width / 2 ? pos.x - bounds.left - 56 : pos.x - bounds.left + 64;
75
+ let halfTooltipWidth = tooltipWidth / 2;
76
+ // Clamp to left edge
77
+ if (leftPosition < 0 + halfTooltipWidth)
78
+ leftPosition = 0 + halfTooltipWidth;
79
+ else if (leftPosition + tooltipWidth > bounds.width + halfTooltipWidth)
80
+ leftPosition = bounds.width - tooltipWidth + halfTooltipWidth;
81
+ // Get cursor position & align tooltip centered to cursor (1/4 tooltip height)
82
+ let topPosition = pos.y - bounds.top - tooltipHeight / 4;
83
+ // Clamp to top edge
84
+ if (topPosition < 0)
85
+ topPosition = 0;
86
+ // Clamp to bottom edge
87
+ else if (topPosition + tooltipHeight > bounds.height)
88
+ topPosition = bounds.height - tooltipHeight;
89
+ return { x: leftPosition, y: topPosition };
90
+ };
91
+ }
92
+ render() {
93
+ return html `
94
+ <slot
95
+ @pointerover=${() => this.display = this.trigger === 'hover' ? true : this.display}
96
+ @pointerout=${() => this.display = this.trigger === 'hover' ? false : this.display}
97
+ @click=${() => this.trigger === 'click' ? this.display = !this.display : null}
98
+ >
99
+ </slot>
100
+ <p id='content'>
101
+ ${this.text}
102
+ </p>
78
103
  `;
79
- }
80
- setClampedPosition({ x: i, y: t }, o) {
81
- this.setPosition(this.clampPosition({ x: i, y: t }, o));
82
- }
83
- setPosition({ x: i, y: t }) {
84
- this.style.setProperty("--tooltip-x", `${i}px`), this.style.setProperty("--tooltip-y", `${t}px`);
85
- }
86
- };
87
- p.styles = m;
88
- n([
89
- d("#content")
90
- ], p.prototype, "contentEl", 2);
91
- n([
92
- a({ type: Boolean, reflect: !0 })
93
- ], p.prototype, "display", 2);
94
- n([
95
- a({ type: String })
96
- ], p.prototype, "text", 2);
97
- n([
98
- a({ type: String })
99
- ], p.prototype, "trigger", 2);
100
- p = n([
101
- c("tool-tip")
102
- ], p);
103
- export {
104
- p as ToolTip,
105
- m as styles
104
+ }
105
+ setClampedPosition({ x, y }, bounds) {
106
+ this.setPosition(this.clampPosition({ x, y }, bounds));
107
+ }
108
+ setPosition({ x, y }) {
109
+ this.style.setProperty('--tooltip-x', `${x}px`);
110
+ this.style.setProperty('--tooltip-y', `${y}px`);
111
+ }
106
112
  };
113
+ ToolTip.styles = styles;
114
+ __decorate([
115
+ query('#content')
116
+ ], ToolTip.prototype, "contentEl", void 0);
117
+ __decorate([
118
+ property({ type: Boolean, reflect: true })
119
+ ], ToolTip.prototype, "display", void 0);
120
+ __decorate([
121
+ property({ type: String })
122
+ ], ToolTip.prototype, "text", void 0);
123
+ __decorate([
124
+ property({ type: String })
125
+ ], ToolTip.prototype, "trigger", void 0);
126
+ ToolTip = __decorate([
127
+ customElement('tool-tip')
128
+ ], ToolTip);
129
+ export { ToolTip };
@@ -0,0 +1,30 @@
1
+ import { html } from 'lit';
2
+ const meta = {
3
+ title: 'Tool Tip',
4
+ tags: ['autodocs'],
5
+ component: 'tool-tip',
6
+ };
7
+ export default meta;
8
+ const Template = {
9
+ render: ({ content, trigger }) => {
10
+ return html `
11
+ <tool-tip content=${content} trigger=${trigger}>
12
+ <button>${trigger} me</button>
13
+ </tool-tip>
14
+ `;
15
+ },
16
+ };
17
+ export const Hover = {
18
+ ...Template,
19
+ args: {
20
+ content: 'hovered tooltip',
21
+ trigger: 'hover'
22
+ }
23
+ };
24
+ export const Click = {
25
+ ...Template,
26
+ args: {
27
+ content: 'clicked tooltip',
28
+ trigger: 'click'
29
+ }
30
+ };
package/dist/index.js CHANGED
@@ -1,14 +1,6 @@
1
- import * as o from "./components/tool-tip/index.js";
2
- import * as r from "./components/bottom-sheet/index.js";
3
- import * as e from "./components/carousel-scroller/index.js";
4
- import * as t from "./components/color-palette/index.js";
5
- import * as a from "./components/canvas/index.js";
6
- import * as s from "./components/absolute-container/index.js";
7
- export {
8
- s as AbsoluteContainer,
9
- r as BottomSheet,
10
- a as Canvas,
11
- e as CarouselScroller,
12
- t as ColorPalette,
13
- o as ToolTip
14
- };
1
+ export * as ToolTip from './components/tool-tip';
2
+ export * as BottomSheet from './components/bottom-sheet';
3
+ export * as CarouselScroller from './components/carousel-scroller';
4
+ export * as ColorPalette from './components/color-palette';
5
+ export * as Canvas from './components/canvas';
6
+ export * as AbsoluteContainer from './components/absolute-container';
@@ -1,24 +1,24 @@
1
- class r {
2
- constructor() {
3
- this.eventListeners = {};
4
- }
5
- on(e, s) {
6
- const t = this.eventListeners[e] ?? /* @__PURE__ */ new Set();
7
- t.add(s), this.eventListeners[e] = t;
8
- }
9
- off(e, s) {
10
- const t = this.eventListeners[e] ?? /* @__PURE__ */ new Set();
11
- t.delete(s), this.eventListeners[e] = t;
12
- }
13
- emit(e, ...s) {
14
- const t = this.eventListeners[e] ?? /* @__PURE__ */ new Set();
15
- for (const n of t)
16
- n(...s);
17
- }
18
- clear() {
19
- this.eventListeners = {};
20
- }
1
+ export class EventEmitter {
2
+ constructor() {
3
+ this.eventListeners = {};
4
+ }
5
+ on(eventName, listener) {
6
+ const listeners = this.eventListeners[eventName] ?? new Set();
7
+ listeners.add(listener);
8
+ this.eventListeners[eventName] = listeners;
9
+ }
10
+ off(eventName, listener) {
11
+ const listeners = this.eventListeners[eventName] ?? new Set();
12
+ listeners.delete(listener);
13
+ this.eventListeners[eventName] = listeners;
14
+ }
15
+ emit(eventName, ...args) {
16
+ const listeners = this.eventListeners[eventName] ?? new Set();
17
+ for (const listener of listeners) {
18
+ listener(...args);
19
+ }
20
+ }
21
+ clear() {
22
+ this.eventListeners = {};
23
+ }
21
24
  }
22
- export {
23
- r as EventEmitter
24
- };
@@ -1,32 +1,149 @@
1
- import r from "colorsea";
2
- import i from "../node_modules/colorsea/colors/x11.js";
3
- import { CopyFormat as n } from "../components/color-palette/color-palette-utils.js";
4
- function f(t) {
5
- var o;
6
- return t.includes("-") ? t.substring(t.lastIndexOf("/") + 1).split("-").map((e) => "#" + e) : ((o = t.substring(t.lastIndexOf("/") + 1).match(/.{1,6}/g)) == null ? void 0 : o.map((e) => "#" + e)) || [];
7
- }
8
- function l(t) {
9
- const o = r(t);
10
- return o.rgb()[0] * 0.299 + o.rgb()[1] * 0.587 + o.rgb()[2] * 0.114 > 186 ? "#000000" : "#ffffff";
11
- }
12
- async function u(t, o) {
13
- let e = t;
14
- o === n.Value && !t.includes("`") && (e.includes("#") ? e = e.split("#")[1] : e.includes("(") && (e = e.split("(")[1].split(")")[0])), await navigator.clipboard.writeText(e);
15
- }
16
- function p(t) {
17
- return Math.max(10, 16 - t);
18
- }
19
- function d(t) {
20
- try {
21
- return r.useNames(i), r(t, void 0, { thowParseError: !0 }), !0;
22
- } catch {
23
- return !1;
24
- }
25
- }
26
- export {
27
- u as copyToClipboard,
28
- p as getAdjustedFontSize,
29
- l as getForegroundColor,
30
- d as isColorValid,
31
- f as parseUrl
32
- };
1
+ import colorsea from "colorsea";
2
+ import x11 from 'colorsea/colors/x11';
3
+ import { CopyFormat, defaultSettings } from "../components/color-palette/color-palette-utils";
4
+ /**
5
+ * Get settings without their default values
6
+ */
7
+ export function getModifiedSettings(settings) {
8
+ let newSettings = {};
9
+ for (const [key, value] of Object.entries(settings)) {
10
+ const defaultVal = defaultSettings[key];
11
+ // Check if setting is a key in defaultSettings
12
+ if (key in defaultSettings) {
13
+ // Check if setting is equal to default & keep setting if not equal
14
+ if (value !== defaultVal)
15
+ newSettings = { ...newSettings, [key]: value };
16
+ }
17
+ // Add all other settings not defined in defaults
18
+ else {
19
+ // Break if empty array
20
+ if (value instanceof Array && value.length === 0)
21
+ break;
22
+ // Add setting
23
+ else
24
+ newSettings = { ...newSettings, [key]: value };
25
+ }
26
+ }
27
+ // Return null if newSettings is empty
28
+ return Object.keys(newSettings).length !== 0 ? newSettings : undefined;
29
+ }
30
+ /**
31
+ * Checks if all settings are set to their default values
32
+ */
33
+ export function areSettingsDefault(settings) {
34
+ for (const [key, value] of Object.entries(settings)) {
35
+ // Ignore settings that don't have a default counterpart
36
+ if (!(key in defaultSettings))
37
+ return true;
38
+ // Check if any settings are not default
39
+ if (value !== defaultSettings[key]) {
40
+ return false;
41
+ }
42
+ }
43
+ return true;
44
+ }
45
+ /**
46
+ * Gets the modified settings as a string
47
+ */
48
+ export function getModifiedSettingsAsString(settings) {
49
+ const moddedSettings = getModifiedSettings(settings);
50
+ if (moddedSettings)
51
+ return JSON.stringify(moddedSettings);
52
+ }
53
+ export function convertStringSettings(settings) {
54
+ return JSON.parse(`{
55
+ "height": ${settings.height},
56
+ "direction": "${settings.direction}",
57
+ "gradient": ${settings.gradient},
58
+ "preventHover": ${settings.preventHover},
59
+ "override": ${settings.override},
60
+ "aliases": ${JSON.stringify(settings.aliases)}
61
+ }`);
62
+ }
63
+ /**
64
+ * Parse input url & extract colors
65
+ * @param url URL from color input
66
+ * @returns Array of colors
67
+ */
68
+ export function parseUrl(url) {
69
+ // Check if url colors contain dashes in-between
70
+ if (url.includes('-')) {
71
+ // Replace dashes with hexes (colorhunt)
72
+ return url.substring(url.lastIndexOf('/') + 1).split('-').map(i => '#' + i);
73
+ }
74
+ // Add hex between URL path colors (coolors)
75
+ else
76
+ return url.substring(url.lastIndexOf('/') + 1).match(/.{1,6}/g)?.map(i => '#' + i) || [];
77
+ }
78
+ /**
79
+ * Converts ColorPalette plugin settings to Palette settings
80
+ */
81
+ export function pluginToPaletteSettings(pluginSettings) {
82
+ return {
83
+ height: pluginSettings.height,
84
+ width: pluginSettings.width,
85
+ direction: pluginSettings.direction,
86
+ gradient: pluginSettings.gradient,
87
+ preventHover: pluginSettings.preventHover,
88
+ override: pluginSettings.override,
89
+ aliases: []
90
+ };
91
+ }
92
+ /**
93
+ * Creates a codeblock palette
94
+ * @param input Either palette input or colors & settings object
95
+ * @returns palette block string
96
+ */
97
+ export function createPaletteBlock(input) {
98
+ if (typeof input === 'string')
99
+ return `\`\`\`palette\n${input}\n\`\`\`\n`;
100
+ else
101
+ return input.settings ? `\`\`\`palette\n${toNString(input.colors)}\n${JSON.stringify(input.settings)}\n\`\`\`\n` : `\`\`\`palette\n${toNString(input.colors)}\n\`\`\`\n`;
102
+ }
103
+ /**
104
+ * Gets the appropriate foreground contrast color
105
+ */
106
+ export function getForegroundColor(color) {
107
+ const csColor = colorsea(color);
108
+ return (csColor.rgb()[0] * 0.299 + csColor.rgb()[1] * 0.587 + csColor.rgb()[2] * 0.114) > 186 ? '#000000' : '#ffffff';
109
+ }
110
+ /**
111
+ * Converts string array to newline separated string
112
+ */
113
+ export function toNString(array) {
114
+ let result = '';
115
+ for (const string of array) {
116
+ result += string + '\n';
117
+ }
118
+ return result.trim();
119
+ }
120
+ export async function copyToClipboard(text, copyFormat) {
121
+ let copiedText = text;
122
+ // Copy only color value if CopyFormat is set to value & when not a codeblock
123
+ if (copyFormat === CopyFormat.Value && !text.includes('`')) {
124
+ if (copiedText.includes('#'))
125
+ copiedText = copiedText.split('#')[1];
126
+ else if (copiedText.includes('('))
127
+ copiedText = copiedText.split('(')[1].split(')')[0];
128
+ }
129
+ // new Notice(`Copied ${copiedText}`);
130
+ await navigator.clipboard.writeText(copiedText);
131
+ }
132
+ /**
133
+ * Calculate font size based on number of colors
134
+ */
135
+ export function getAdjustedFontSize(colorsCount) {
136
+ const minFontSize = 10;
137
+ const baseFontSize = 16;
138
+ return Math.max(minFontSize, baseFontSize - colorsCount);
139
+ }
140
+ export function isColorValid(color) {
141
+ try {
142
+ colorsea.useNames(x11);
143
+ colorsea(color, undefined, { thowParseError: true });
144
+ return true;
145
+ }
146
+ catch (e) {
147
+ return false;
148
+ }
149
+ }