@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
@@ -1,611 +1,722 @@
1
- import { css as P, LitElement as H, html as g } from "lit";
2
- import { query as D, property as u, state as M, customElement as U } from "lit/decorators.js";
3
- import { createElement as h, Pipette as S, Shuffle as C, Image as j, Link as R, ArrowUpToLine as G } from "lucide";
4
- import { defaultSettings as m, Direction as _, urlRegex as z, CopyFormat as A } from "../color-palette-utils.js";
5
- import { Combination as b, generateColors as L } from "../../../utils/generateUtils.js";
6
- import y from "colorsea";
7
- import { parseUrl as B, copyToClipboard as F } from "../../../utils/basicUtils.js";
8
- import { CanvasImage as E } from "../../canvas/canvas-image.js";
9
- import { ref as f, createRef as $ } from "lit/directives/ref.js";
10
- import { EventEmitter as W } from "../../../utils/EventEmitter.js";
11
- import { ColorPalette as q } from "../color-palette.js";
12
- var X = Object.defineProperty, Y = Object.getOwnPropertyDescriptor, s = (t, i, n, a) => {
13
- for (var r = a > 1 ? void 0 : a ? Y(i, n) : i, l = t.length - 1, p; l >= 0; l--)
14
- (p = t[l]) && (r = (a ? p(i, n, r) : p(r)) || r);
15
- return a && r && X(i, n, r), r;
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;
16
6
  };
17
- let c = class extends H {
18
- constructor() {
19
- super(...arguments), this.colors = [], this.settings = {
20
- height: m.height,
21
- width: m.width,
22
- direction: m.direction,
23
- gradient: m.gradient,
24
- preventHover: m.preventHover,
25
- override: m.override,
26
- aliases: []
27
- }, this.selectedInput = "Color Picker", this.combination = b.Random, this.colorPickerDisabled = !1, this.emitter = new W();
28
- }
29
- disconnectedCallback() {
30
- this.emitter.clear();
31
- }
32
- render() {
33
- const t = () => {
34
- switch (this.selectedInput) {
35
- case "Color Picker":
36
- return this.pickerOption();
37
- case "Generate":
38
- return this.generateOption();
39
- case "Image":
40
- return this.imageOption();
41
- case "URL":
42
- return this.urlOption();
43
- }
44
- }, i = (n) => {
45
- n instanceof q && n.emitter.on("changed", (a, r) => {
46
- this.colors = a, this.settings = r;
47
- });
48
- };
49
- return g`
50
- <div id="color-palette-editor">
51
- <h1>Editor</h1>
52
- <section id='colors'>
53
- <h3>Colors</h3>
54
- <div id="control-container">
55
- <button
56
- title="Color Picker"
57
- @click=${() => this.selectedInput = "Color Picker"}
58
- >
59
- ${h(S)}
60
- </button>
61
- <button
62
- title="Generate"
63
- @click=${() => this.selectedInput = "Generate"}
64
- >
65
- ${h(C)}
66
- </button>
67
- <button
68
- title="Image"
69
- @click=${() => this.selectedInput = "Image"}
70
- >
71
- ${h(j)}
72
- </button>
73
- <button
74
- title="URL"
75
- @click=${() => this.selectedInput = "URL"}
76
- >
77
- ${h(R)}
78
- </button>
79
- </div>
80
- <div id='colors-container'>
81
- ${t()}
82
- </div>
83
- </section>
84
- <section id='preview'>
85
- <color-palette
86
- .colors=${this.colors}
87
- height=${this.settings.height}
88
- width=${this.settings.width}
89
- direction=${this.settings.direction}
90
- ?gradient=${this.settings.gradient}
91
- ?preventHover=${this.settings.preventHover}
92
- ?override=${this.settings.override}
93
- .aliases=${this.settings.aliases}
94
- ?editMode=${!0}
95
- maxWidth=${560}
96
- ${f(i)}
97
- >
98
- </color-palette>
99
- </section>
100
- <section id='settings'>
101
- <h3>Settings</h3>
102
- ${this.renderSettings()}
103
- <button
104
- id='create-btn'
7
+ import { LitElement, html, css } from 'lit';
8
+ import { customElement, property, query, state } from 'lit/decorators.js';
9
+ import { ArrowUpToLine, createElement, Image, Link, Pipette, Shuffle } from 'lucide';
10
+ import { defaultSettings, Direction } from '../color-palette-utils';
11
+ import { Combination, generateColors } from '../../../utils/generateUtils';
12
+ import colorsea from 'colorsea';
13
+ import { copyToClipboard, parseUrl } from '../../../utils/basicUtils';
14
+ import { CopyFormat, urlRegex } from '../color-palette-utils';
15
+ import { CanvasImage } from '../../canvas/canvas-image';
16
+ import { ref, createRef } from 'lit/directives/ref.js';
17
+ import { EventEmitter } from '../../../utils/EventEmitter';
18
+ import { ColorPalette } from '../color-palette';
19
+ var SelectedInput;
20
+ (function (SelectedInput) {
21
+ SelectedInput["Color_Picker"] = "Color Picker";
22
+ SelectedInput["Generate"] = "Generate";
23
+ SelectedInput["Image"] = "Image";
24
+ SelectedInput["URL"] = "URL";
25
+ })(SelectedInput || (SelectedInput = {}));
26
+ let ColorPaletteEditor = class ColorPaletteEditor extends LitElement {
27
+ constructor() {
28
+ super(...arguments);
29
+ this.colors = [];
30
+ this.settings = {
31
+ height: defaultSettings.height,
32
+ width: defaultSettings.width,
33
+ direction: defaultSettings.direction,
34
+ gradient: defaultSettings.gradient,
35
+ preventHover: defaultSettings.preventHover,
36
+ override: defaultSettings.override,
37
+ aliases: []
38
+ };
39
+ this.selectedInput = SelectedInput.Color_Picker;
40
+ this.combination = Combination.Random;
41
+ this.colorPickerDisabled = false;
42
+ this.emitter = new EventEmitter();
43
+ }
44
+ disconnectedCallback() {
45
+ this.emitter.clear();
46
+ }
47
+ render() {
48
+ const chooseControl = () => {
49
+ switch (this.selectedInput) {
50
+ case SelectedInput.Color_Picker:
51
+ return this.pickerOption();
52
+ case SelectedInput.Generate:
53
+ return this.generateOption();
54
+ case SelectedInput.Image:
55
+ return this.imageOption();
56
+ case SelectedInput.URL:
57
+ return this.urlOption();
58
+ }
59
+ };
60
+ const paletteRef = (palette) => {
61
+ if (!(palette instanceof ColorPalette))
62
+ return;
63
+ palette.emitter.on('changed', (colors, settings) => {
64
+ this.colors = colors;
65
+ this.settings = settings;
66
+ });
67
+ };
68
+ return html `
69
+ <div id="color-palette-editor">
70
+ <h1>Editor</h1>
71
+ <section id='colors'>
72
+ <h3>Colors</h3>
73
+ <div id="control-container">
74
+ <button
75
+ title="Color Picker"
76
+ @click=${() => this.selectedInput = SelectedInput.Color_Picker}
77
+ >
78
+ ${createElement(Pipette)}
79
+ </button>
80
+ <button
81
+ title="Generate"
82
+ @click=${() => this.selectedInput = SelectedInput.Generate}
83
+ >
84
+ ${createElement(Shuffle)}
85
+ </button>
86
+ <button
87
+ title="Image"
88
+ @click=${() => this.selectedInput = SelectedInput.Image}
89
+ >
90
+ ${createElement(Image)}
91
+ </button>
92
+ <button
93
+ title="URL"
94
+ @click=${() => this.selectedInput = SelectedInput.URL}
95
+ >
96
+ ${createElement(Link)}
97
+ </button>
98
+ </div>
99
+ <div id='colors-container'>
100
+ ${chooseControl()}
101
+ </div>
102
+ </section>
103
+ <section id='preview'>
104
+ <color-palette
105
+ .colors=${this.colors}
106
+ height=${this.settings.height}
107
+ width=${this.settings.width}
108
+ direction=${this.settings.direction}
109
+ ?gradient=${this.settings.gradient}
110
+ ?preventHover=${this.settings.preventHover}
111
+ ?override=${this.settings.override}
112
+ .aliases=${this.settings.aliases}
113
+ ?editMode=${true}
114
+ maxWidth=${560}
115
+ ${ref(paletteRef)}
116
+ >
117
+ </color-palette>
118
+ </section>
119
+ <section id='settings'>
120
+ <h3>Settings</h3>
121
+ ${this.renderSettings()}
122
+ <button
123
+ id='create-btn'
105
124
  @click=${() => {
106
- try {
107
- this.colors.length === 0 && (this.colors = L(b.Random).colors), this.emitter.emit("submit", this.colors, this.settings);
108
- } catch {
109
- }
110
- }}
111
- >
112
- Create
113
- </button>
114
- </section>
115
- </div>
125
+ try {
126
+ // Generate random colors if none are provided
127
+ if (this.colors.length === 0)
128
+ this.colors = generateColors(Combination.Random).colors;
129
+ this.emitter.emit('submit', this.colors, this.settings);
130
+ }
131
+ catch (e) {
132
+ // new Notice(e);
133
+ }
134
+ }}
135
+ >
136
+ Create
137
+ </button>
138
+ </section>
139
+ </div>
116
140
  `;
117
- }
118
- renderSettings() {
119
- return g`
120
- <setting-item
121
- name='Height'
122
- >
123
- <input
124
- type='number'
125
- value=${this.settings.height}
126
- step=${5}
127
- @input=${(t) => {
128
- t.target instanceof HTMLInputElement && (this.settings = { ...this.settings, height: +t.target.value });
129
- }}
130
- >
131
- </setting-item>
132
- <setting-item
133
- name='Width'
134
- description='Caution - Might cause palette to display incorrectly.'
135
- >
136
- <input
137
- type='number'
138
- value=${this.settings.width}
139
- step=${10}
140
- @input=${(t) => {
141
- t.target instanceof HTMLInputElement && (this.settings = { ...this.settings, width: +t.target.value });
142
- }}
143
- >
144
- </setting-item>
145
- <setting-item
146
- name='Direction'
147
- >
148
- <select
149
- @change=${(t) => {
150
- t.target instanceof HTMLSelectElement && (this.settings = { ...this.settings, direction: t.target.value });
151
- }}
152
- >
153
- ${Object.values(_).map((t) => g`<option ?selected=${this.settings.direction === t}>${t}</option>`)}
154
- </select>
155
- </setting-item>
156
- <setting-item
157
- name='Gradient'
158
- >
159
- <input
160
- type='checkbox'
161
- ?checked=${this.settings.gradient}
162
- @change=${(t) => {
163
- t.target instanceof HTMLInputElement && (this.settings = { ...this.settings, gradient: t.target.checked });
164
- }}
165
- >
166
- </setting-item>
167
- <setting-item
168
- name='Prevent Hover'
169
- description='Toggles whether palettes can be hovered'
170
- >
171
- <input
172
- type='checkbox'
173
- ?checked=${this.settings.preventHover}
174
- @change=${(t) => {
175
- t.target instanceof HTMLInputElement && (this.settings = { ...this.settings, preventHover: t.target.checked });
176
- }}
177
- >
178
- </setting-item>
179
- <setting-item
180
- name='Override'
181
- description='Disables color validation for full control (advanced)'
182
- >
183
- <input
184
- type='checkbox'
185
- ?checked=${this.settings.override}
186
- @change=${(t) => {
187
- t.target instanceof HTMLInputElement && (this.settings = { ...this.settings, override: t.target.checked });
188
- }}
189
- >
190
- </setting-item>
141
+ }
142
+ renderSettings() {
143
+ return html `
144
+ <setting-item
145
+ name='Height'
146
+ >
147
+ <input
148
+ type='number'
149
+ value=${this.settings.height}
150
+ step=${5}
151
+ @input=${(e) => {
152
+ if (!(e.target instanceof HTMLInputElement))
153
+ return;
154
+ this.settings = { ...this.settings, height: +e.target.value };
155
+ }}
156
+ >
157
+ </setting-item>
158
+ <setting-item
159
+ name='Width'
160
+ description='Caution - Might cause palette to display incorrectly.'
161
+ >
162
+ <input
163
+ type='number'
164
+ value=${this.settings.width}
165
+ step=${10}
166
+ @input=${(e) => {
167
+ if (!(e.target instanceof HTMLInputElement))
168
+ return;
169
+ this.settings = { ...this.settings, width: +e.target.value };
170
+ }}
171
+ >
172
+ </setting-item>
173
+ <setting-item
174
+ name='Direction'
175
+ >
176
+ <select
177
+ @change=${(e) => {
178
+ if (!(e.target instanceof HTMLSelectElement))
179
+ return;
180
+ this.settings = { ...this.settings, direction: e.target.value };
181
+ }}
182
+ >
183
+ ${Object.values(Direction).map((val) => {
184
+ return html `<option ?selected=${this.settings.direction === val}>${val}</option>`;
185
+ })}
186
+ </select>
187
+ </setting-item>
188
+ <setting-item
189
+ name='Gradient'
190
+ >
191
+ <input
192
+ type='checkbox'
193
+ ?checked=${this.settings.gradient}
194
+ @change=${(e) => {
195
+ if (!(e.target instanceof HTMLInputElement))
196
+ return;
197
+ this.settings = { ...this.settings, gradient: e.target.checked };
198
+ }}
199
+ >
200
+ </setting-item>
201
+ <setting-item
202
+ name='Prevent Hover'
203
+ description='Toggles whether palettes can be hovered'
204
+ >
205
+ <input
206
+ type='checkbox'
207
+ ?checked=${this.settings.preventHover}
208
+ @change=${(e) => {
209
+ if (!(e.target instanceof HTMLInputElement))
210
+ return;
211
+ this.settings = { ...this.settings, preventHover: e.target.checked };
212
+ }}
213
+ >
214
+ </setting-item>
215
+ <setting-item
216
+ name='Override'
217
+ description='Disables color validation for full control (advanced)'
218
+ >
219
+ <input
220
+ type='checkbox'
221
+ ?checked=${this.settings.override}
222
+ @change=${(e) => {
223
+ if (!(e.target instanceof HTMLInputElement))
224
+ return;
225
+ this.settings = { ...this.settings, override: e.target.checked };
226
+ }}
227
+ >
228
+ </setting-item>
191
229
  `;
192
- }
193
- pickerOption() {
194
- return g`
195
- <setting-item
196
- name='Color Picker'
197
- description='Use handpicked colors'
198
- >
199
- <input
200
- type='color'
201
- @change=${(t) => {
202
- t.target instanceof HTMLInputElement && (this.colors = [...this.colors, t.target.value], this.settings.aliases.push(""));
203
- }}
204
- >
205
- </setting-item>
230
+ }
231
+ pickerOption() {
232
+ return html `
233
+ <setting-item
234
+ name='Color Picker'
235
+ description='Use handpicked colors'
236
+ >
237
+ <input
238
+ type='color'
239
+ @change=${(e) => {
240
+ if (!(e.target instanceof HTMLInputElement))
241
+ return;
242
+ this.colors = [...this.colors, e.target.value];
243
+ this.settings.aliases.push('');
244
+ }}
245
+ >
246
+ </setting-item>
206
247
  `;
207
- }
208
- generateOption() {
209
- return this.colorPickerDisabled = this.combination === b.Random, g`
210
- <setting-item
211
- name='Generate'
212
- description='Generate colors based on color theory'
213
- >
214
- <select
215
- @change=${(t) => {
216
- t.target instanceof HTMLSelectElement && (this.combination = t.target.value, this.colorPickerDisabled = this.combination === b.Random);
217
- }}
218
- >
219
- ${Object.values(b).map((t) => g`<option ?selected=${this.combination === t}>${t}</option>`)}
220
- </select>
221
- <input
222
- type='color'
223
- ?disabled=${this.colorPickerDisabled}
224
- @change=${(t) => {
225
- t.target instanceof HTMLInputElement && (this.baseColor = y(t.target.value));
226
- }}
227
- @contextmenu=${(t) => {
228
- t.preventDefault(), t.target instanceof HTMLInputElement && (t.target.value = y("#000").hex(), this.baseColor = void 0);
229
- }}
230
- >
231
- <button
232
- title='Loads the generated colors'
233
- @click=${(t) => {
234
- const i = L(this.combination, { baseColor: this.baseColor, settings: this.settings });
235
- this.colors = i.colors, i.settings && (this.settings = i.settings);
236
- }}
237
- >
238
- ${h(C)}
239
- </button>
240
- </setting-item>
248
+ }
249
+ generateOption() {
250
+ this.colorPickerDisabled = this.combination === Combination.Random;
251
+ return html `
252
+ <setting-item
253
+ name='Generate'
254
+ description='Generate colors based on color theory'
255
+ >
256
+ <select
257
+ @change=${(e) => {
258
+ if (!(e.target instanceof HTMLSelectElement))
259
+ return;
260
+ this.combination = e.target.value;
261
+ this.colorPickerDisabled = this.combination === Combination.Random;
262
+ }}
263
+ >
264
+ ${Object.values(Combination).map((val) => {
265
+ return html `<option ?selected=${this.combination === val}>${val}</option>`;
266
+ })}
267
+ </select>
268
+ <input
269
+ type='color'
270
+ ?disabled=${this.colorPickerDisabled}
271
+ @change=${(e) => {
272
+ if (!(e.target instanceof HTMLInputElement))
273
+ return;
274
+ this.baseColor = colorsea(e.target.value);
275
+ }}
276
+ @contextmenu=${(e) => {
277
+ e.preventDefault();
278
+ if (!(e.target instanceof HTMLInputElement))
279
+ return;
280
+ e.target.value = colorsea('#000').hex();
281
+ this.baseColor = undefined;
282
+ }}
283
+ >
284
+ <button
285
+ title='Loads the generated colors'
286
+ @click=${(e) => {
287
+ const generated = generateColors(this.combination, { baseColor: this.baseColor, settings: this.settings });
288
+ this.colors = generated.colors;
289
+ if (generated.settings)
290
+ this.settings = generated.settings;
291
+ }}
292
+ >
293
+ ${createElement(Shuffle)}
294
+ </button>
295
+ </setting-item>
241
296
  `;
242
- }
243
- imageOption() {
244
- var w;
245
- let t = "", i = $(), n = $(), a = $(), r = ((w = i.value) == null ? void 0 : w.value) || "", l, p = $(), O = (e) => {
246
- e instanceof E && (l = e, e.emitter.clear(), e.emitter.on("click", async (o) => await F(o.toUpperCase(), A.Raw)), e.emitter.on("move", (o) => {
247
- if (!p.value) return;
248
- let d = p.value;
249
- d.text = e.getCanvasHex(o.x, o.y).toUpperCase(), d.setClampedPosition(o, e.getBoundingClientRect());
250
- }));
251
- };
252
- const T = async () => {
253
- if (!n.value || !l) return;
254
- const e = n.value;
255
- return await l.getPalette(+e.value);
256
- }, k = async () => {
257
- const e = await T();
258
- e && (this.colors = e.map((o) => y(o).hex(0)), this.settings.aliases = []);
259
- }, x = async (e) => {
260
- if (!URL.canParse(e) || !l) return;
261
- l.updateImage(e, this.palette.getBoundingClientRect().width, this.palette.getBoundingClientRect().height), await k();
262
- };
263
- return g`
264
- <setting-item
265
- name='Image'
266
- description='Convert image into palette'
267
- >
268
- <input
269
- type='url'
270
- placeholder='Enter URL or select file'
271
- ${f(i)}
272
- >
273
- <button
274
- title='Right click to clear URL'
297
+ }
298
+ imageOption() {
299
+ let hex = '';
300
+ let urlRef = createRef();
301
+ let sliderRef = createRef();
302
+ let fileRef = createRef();
303
+ let fileUrl = urlRef.value?.value || '';
304
+ let canvasEl;
305
+ let tooltipRef = createRef();
306
+ let canvasRef = (canvas) => {
307
+ if (!(canvas instanceof CanvasImage))
308
+ return;
309
+ canvasEl = canvas;
310
+ canvas.emitter.clear();
311
+ canvas.emitter.on('click', async (color) => await copyToClipboard(color.toUpperCase(), CopyFormat.Raw));
312
+ canvas.emitter.on('move', (pos) => {
313
+ if (!tooltipRef.value)
314
+ return;
315
+ let tooltip = tooltipRef.value;
316
+ // Set tooltip text
317
+ tooltip.text = canvas.getCanvasHex(pos.x, pos.y).toUpperCase();
318
+ // Set tooltip position
319
+ tooltip.setClampedPosition(pos, canvas.getBoundingClientRect());
320
+ });
321
+ };
322
+ const getColors = async () => {
323
+ if (!sliderRef.value || !canvasEl)
324
+ return;
325
+ const sliderInput = sliderRef.value;
326
+ const canvasImage = canvasEl;
327
+ return await canvasImage.getPalette(+sliderInput.value);
328
+ };
329
+ const updateColors = async () => {
330
+ const colors = await getColors();
331
+ if (colors) {
332
+ this.colors = colors.map((color) => colorsea(color).hex(0));
333
+ this.settings.aliases = [];
334
+ }
335
+ };
336
+ const updateImagePreview = async (url) => {
337
+ if (!URL.canParse(url) || !canvasEl)
338
+ return;
339
+ const canvasImage = canvasEl;
340
+ canvasImage.updateImage(url, this.palette.getBoundingClientRect().width, this.palette.getBoundingClientRect().height);
341
+ await updateColors();
342
+ };
343
+ return html `
344
+ <setting-item
345
+ name='Image'
346
+ description='Convert image into palette'
347
+ >
348
+ <input
349
+ type='url'
350
+ placeholder='Enter URL or select file'
351
+ ${ref(urlRef)}
352
+ >
353
+ <button
354
+ title='Right click to clear URL'
275
355
  @click=${async (e) => {
276
- try {
277
- if (!a.value) return;
278
- let o = a.value;
279
- if (r !== "")
280
- if (URL.canParse(r)) await x(r);
281
- else throw new Error("URL provided is not valid.");
282
- else o.click();
283
- } catch {
284
- }
285
- }}
356
+ try {
357
+ if (!fileRef.value)
358
+ return;
359
+ let fileInput = fileRef.value;
360
+ // Check if any text is present, otherwise prompt user to select image
361
+ if (fileUrl !== '') {
362
+ // Check if URL is valid
363
+ if (URL.canParse(fileUrl))
364
+ await updateImagePreview(fileUrl);
365
+ else
366
+ throw new Error('URL provided is not valid.');
367
+ }
368
+ else
369
+ fileInput.click();
370
+ }
371
+ catch (e) {
372
+ // new Notice(e);
373
+ }
374
+ }}
286
375
  @contextmenu=${() => {
287
- if (!i.value) return;
288
- const e = i.value;
289
- e.value = "";
290
- }}
291
- >
292
- ${h(G)}
293
- </button>
294
- <input
295
- type ='file'
296
- accept = 'image/*'
376
+ if (!urlRef.value)
377
+ return;
378
+ const urlInput = urlRef.value;
379
+ urlInput.value = '';
380
+ }}
381
+ >
382
+ ${createElement(ArrowUpToLine)}
383
+ </button>
384
+ <input
385
+ type ='file'
386
+ accept = 'image/*'
297
387
  @change=${(e) => {
298
- var o;
299
- try {
300
- const d = new FileReader(), I = (o = e.target.files) == null ? void 0 : o[0];
301
- I && d.readAsDataURL(I), d.addEventListener("load", async () => {
302
- typeof d.result == "string" && (r = d.result, await x(r));
303
- }), d.addEventListener("error", () => {
304
- throw new Error("Error processing image");
305
- });
306
- } catch {
307
- }
308
- }}
309
- ${f(a)}
310
- >
311
- </setting-item>
312
- <setting-item
313
- name='Count'
314
- description='Set the number of colors to generate from the image'
315
- >
316
- <input
317
- id='range-slider'
318
- type='range'
319
- min='4'
320
- max='12'
321
- value='8'
388
+ try {
389
+ const reader = new FileReader();
390
+ const file = e.target.files?.[0];
391
+ if (file)
392
+ reader.readAsDataURL(file);
393
+ reader.addEventListener('load', async () => {
394
+ if (typeof reader.result === 'string') {
395
+ fileUrl = reader.result;
396
+ await updateImagePreview(fileUrl);
397
+ }
398
+ });
399
+ reader.addEventListener('error', () => {
400
+ throw new Error('Error processing image');
401
+ });
402
+ }
403
+ catch (e) {
404
+ // new Notice(e);
405
+ }
406
+ }}
407
+ ${ref(fileRef)}
408
+ >
409
+ </setting-item>
410
+ <setting-item
411
+ name='Count'
412
+ description='Set the number of colors to generate from the image'
413
+ >
414
+ <input
415
+ id='range-slider'
416
+ type='range'
417
+ min='4'
418
+ max='12'
419
+ value='8'
322
420
  @change=${async () => {
323
- await k();
324
- }}
325
- ${f(n)}
326
- >
327
- </setting-item>
328
- <tool-tip
329
- trigger='hover'
330
- ${f(p)}
331
- >
332
- <canvas-image
421
+ await updateColors();
422
+ }}
423
+ ${ref(sliderRef)}
424
+ >
425
+ </setting-item>
426
+ <tool-tip
427
+ trigger='hover'
428
+ ${ref(tooltipRef)}
429
+ >
430
+ <canvas-image
333
431
  @mousemove=${(e) => {
334
- e.target instanceof E && (t = e.target.getCanvasHex(e.clientX, e.clientY));
335
- }}
432
+ if (!(e.target instanceof CanvasImage))
433
+ return;
434
+ hex = e.target.getCanvasHex(e.clientX, e.clientY);
435
+ }}
336
436
  @click=${(e) => {
337
- t && (this.colors = [...this.colors, t], this.settings.aliases = [...this.settings.aliases, ""]);
338
- }}
339
- ${f(O)}
340
- >
341
- </canvas-image>
342
- </tool-tip>
437
+ if (!hex)
438
+ return;
439
+ this.colors = [...this.colors, hex];
440
+ this.settings.aliases = [...this.settings.aliases, ''];
441
+ }}
442
+ ${ref(canvasRef)}
443
+ >
444
+ </canvas-image>
445
+ </tool-tip>
343
446
  `;
344
- }
345
- urlOption() {
346
- let t;
347
- return g`
348
- <setting-item
349
- name='URL'
350
- description='Only coolors.co & colorhunt.co are currently supported'
351
- >
352
- <input
353
- type='url'
354
- placeholder='Enter URL'
355
- @change=${(i) => {
356
- i.target instanceof HTMLInputElement && (t = i.target);
357
- }}
358
- >
359
- <button
360
- title='Right click to clear URL'
361
- @click=${(i) => {
362
- try {
363
- if (!t.value.match(z)) throw new Error("URL provided is not valid.");
364
- this.colors = B(t.value), this.settings.aliases = [];
365
- } catch {
366
- }
367
- }}
368
- @contextmenu=${(i) => {
369
- i.preventDefault(), t && (t.value = "");
370
- }}
371
- >
372
- ${h(R)}
373
- </button>
374
- </setting-item>
447
+ }
448
+ urlOption() {
449
+ let input;
450
+ return html `
451
+ <setting-item
452
+ name='URL'
453
+ description='Only coolors.co & colorhunt.co are currently supported'
454
+ >
455
+ <input
456
+ type='url'
457
+ placeholder='Enter URL'
458
+ @change=${(e) => {
459
+ if (!(e.target instanceof HTMLInputElement))
460
+ return;
461
+ input = e.target;
462
+ }}
463
+ >
464
+ <button
465
+ title='Right click to clear URL'
466
+ @click=${(e) => {
467
+ try {
468
+ if (!input.value.match(urlRegex))
469
+ throw new Error('URL provided is not valid.');
470
+ this.colors = parseUrl(input.value);
471
+ this.settings.aliases = [];
472
+ }
473
+ catch (e) {
474
+ // new Notice(e)
475
+ }
476
+ }}
477
+ @contextmenu=${(e) => {
478
+ e.preventDefault();
479
+ if (input)
480
+ input.value = '';
481
+ }}
482
+ >
483
+ ${createElement(Link)}
484
+ </button>
485
+ </setting-item>
375
486
  `;
376
- }
487
+ }
377
488
  };
378
- c.styles = [
379
- P`
380
- :host {
381
- display: block;
382
- contain: content;
383
- width: 560px;
384
- padding: 16px;
385
- background-color: rgb(27, 27, 27);
386
- color: rgba(245, 245, 245, .9);
387
- border-radius: 5px;
388
-
389
- --cta-background: hsl(262, 83%, 69%);
390
- }
391
-
392
- input[type='file'] {
393
- display: none;
394
- }
395
-
396
- :host([selectedInput="Color Picker"]) {
397
- #color-palette-editor #colors {
398
- div:nth-of-type(1) {
399
- button[title="Color Picker"] {
400
- background-color: var(--cta-background);
401
- }
402
- }
403
- div:nth-of-type(2) {
404
- canvas {
405
- max-width: 100%;
406
- max-height: fit-content;
407
- object-fit: cover;
408
- }
409
- }
410
- }
411
- }
412
-
413
- :host([selectedInput="Generate"]) {
414
- #color-palette-editor #colors div {
415
- button[title="Generate"] {
416
- background-color: var(--cta-background);
417
- }
418
- }
419
- }
420
-
421
- :host([selectedInput="Image"]) {
422
- #color-palette-editor #colors div {
423
- button[title="Image"] {
424
- background-color: var(--cta-background);
425
- }
426
- }
427
- }
428
-
429
- :host([selectedInput="URL"]) {
430
- #color-palette-editor #colors div {
431
- button[title="URL"] {
432
- background-color: var(--cta-background);
433
- }
434
- }
435
- }
436
-
437
- #color-palette-editor {
438
- display: flex;
439
- flex-direction: column;
440
- gap: .5rem;
441
-
442
- h1 {
443
- font-size: 2.25rem;
444
- }
445
-
446
- button {
447
- cursor: pointer;
448
- }
449
-
450
- #colors {
451
- div {
452
- input:not([type='color']) {
453
- color: rgb(245, 245, 245);
454
- background-color: rgb(38, 38, 38);
455
- border: none;
456
- border-radius: 5px;
457
- height: fit-content;
458
- width: fit-content;
459
- padding: .5rem;
460
- }
461
-
462
- select {
463
- color: rgb(245, 245, 245);
464
- background-color: rgb(38, 38, 38);
465
- border: none;
466
- border-radius: 5px;
467
- height: fit-content;
468
- width: fit-content;
469
- padding: .5rem;
470
- }
471
-
472
- button {
473
- color: rgb(245, 245, 245);
474
- background-color: rgb(38, 38, 38);
475
- border: none;
476
- border-radius: 5px;
477
- height: fit-content;
478
- width: fit-content;
479
- padding: 4px 12px;
480
- }
481
- }
482
- }
483
-
484
- #settings {
485
- display: flex;
486
- flex-direction: column;
487
-
488
- input {
489
- color: rgb(245, 245, 245);
490
- background-color: rgb(38, 38, 38);
491
- border: none;
492
- border-radius: 5px;
493
- height: fit-content;
494
- width: fit-content;
495
- padding: .5rem;
496
- }
497
-
498
- select {
499
- color: rgb(245, 245, 245);
500
- background-color: rgb(38, 38, 38);
501
- border: none;
502
- border-radius: 5px;
503
- height: fit-content;
504
- width: fit-content;
505
- padding: .5rem;
506
- }
507
-
508
- #create-btn {
509
- background-color: var(--cta-background);
510
- color: white;
511
- border-radius: 5px;
512
- padding: 4px 12px;
513
- user-select: none;
514
- border: none;
515
- width: fit-content;
516
- align-self: flex-end;
517
-
518
- &:hover {
519
- background-color: hsl(calc( 262 - 3), calc( 83% * 1.02), calc( 69% * 1.15));
520
- }
521
- }
522
- }
523
- }
524
- `
489
+ ColorPaletteEditor.styles = [
490
+ css `
491
+ :host {
492
+ display: block;
493
+ contain: content;
494
+ width: 560px;
495
+ padding: 16px;
496
+ background-color: rgb(27, 27, 27);
497
+ color: rgba(245, 245, 245, .9);
498
+ border-radius: 5px;
499
+
500
+ --cta-background: hsl(262, 83%, 69%);
501
+ }
502
+
503
+ input[type='file'] {
504
+ display: none;
505
+ }
506
+
507
+ :host([selectedInput="Color Picker"]) {
508
+ #color-palette-editor #colors {
509
+ div:nth-of-type(1) {
510
+ button[title="Color Picker"] {
511
+ background-color: var(--cta-background);
512
+ }
513
+ }
514
+ div:nth-of-type(2) {
515
+ canvas {
516
+ max-width: 100%;
517
+ max-height: fit-content;
518
+ object-fit: cover;
519
+ }
520
+ }
521
+ }
522
+ }
523
+
524
+ :host([selectedInput="Generate"]) {
525
+ #color-palette-editor #colors div {
526
+ button[title="Generate"] {
527
+ background-color: var(--cta-background);
528
+ }
529
+ }
530
+ }
531
+
532
+ :host([selectedInput="Image"]) {
533
+ #color-palette-editor #colors div {
534
+ button[title="Image"] {
535
+ background-color: var(--cta-background);
536
+ }
537
+ }
538
+ }
539
+
540
+ :host([selectedInput="URL"]) {
541
+ #color-palette-editor #colors div {
542
+ button[title="URL"] {
543
+ background-color: var(--cta-background);
544
+ }
545
+ }
546
+ }
547
+
548
+ #color-palette-editor {
549
+ display: flex;
550
+ flex-direction: column;
551
+ gap: .5rem;
552
+
553
+ h1 {
554
+ font-size: 2.25rem;
555
+ }
556
+
557
+ button {
558
+ cursor: pointer;
559
+ }
560
+
561
+ #colors {
562
+ div {
563
+ input:not([type='color']) {
564
+ color: rgb(245, 245, 245);
565
+ background-color: rgb(38, 38, 38);
566
+ border: none;
567
+ border-radius: 5px;
568
+ height: fit-content;
569
+ width: fit-content;
570
+ padding: .5rem;
571
+ }
572
+
573
+ select {
574
+ color: rgb(245, 245, 245);
575
+ background-color: rgb(38, 38, 38);
576
+ border: none;
577
+ border-radius: 5px;
578
+ height: fit-content;
579
+ width: fit-content;
580
+ padding: .5rem;
581
+ }
582
+
583
+ button {
584
+ color: rgb(245, 245, 245);
585
+ background-color: rgb(38, 38, 38);
586
+ border: none;
587
+ border-radius: 5px;
588
+ height: fit-content;
589
+ width: fit-content;
590
+ padding: 4px 12px;
591
+ }
592
+ }
593
+ }
594
+
595
+ #settings {
596
+ display: flex;
597
+ flex-direction: column;
598
+
599
+ input {
600
+ color: rgb(245, 245, 245);
601
+ background-color: rgb(38, 38, 38);
602
+ border: none;
603
+ border-radius: 5px;
604
+ height: fit-content;
605
+ width: fit-content;
606
+ padding: .5rem;
607
+ }
608
+
609
+ select {
610
+ color: rgb(245, 245, 245);
611
+ background-color: rgb(38, 38, 38);
612
+ border: none;
613
+ border-radius: 5px;
614
+ height: fit-content;
615
+ width: fit-content;
616
+ padding: .5rem;
617
+ }
618
+
619
+ #create-btn {
620
+ background-color: var(--cta-background);
621
+ color: white;
622
+ border-radius: 5px;
623
+ padding: 4px 12px;
624
+ user-select: none;
625
+ border: none;
626
+ width: fit-content;
627
+ align-self: flex-end;
628
+
629
+ &:hover {
630
+ background-color: hsl(calc( 262 - 3), calc( 83% * 1.02), calc( 69% * 1.15));
631
+ }
632
+ }
633
+ }
634
+ }
635
+ `,
525
636
  ];
526
- s([
527
- D("#color-palette-editor")
528
- ], c.prototype, "palette", 2);
529
- s([
530
- u({ type: Array })
531
- ], c.prototype, "colors", 2);
532
- s([
533
- u({ type: Object })
534
- ], c.prototype, "settings", 2);
535
- s([
536
- u({ type: String, reflect: !0 })
537
- ], c.prototype, "selectedInput", 2);
538
- s([
539
- u({ type: String })
540
- ], c.prototype, "combination", 2);
541
- s([
542
- u({ type: Object })
543
- ], c.prototype, "baseColor", 2);
544
- s([
545
- M()
546
- ], c.prototype, "colorPickerDisabled", 2);
547
- c = s([
548
- U("color-palette-editor")
549
- ], c);
550
- let v = class extends H {
551
- constructor() {
552
- super(...arguments), this.name = "", this.description = "";
553
- }
554
- render() {
555
- return g`
556
- <div>
557
- <h3>${this.name}</h3>
558
- <p>${this.description}</p>
559
- </div>
560
- <slot></slot>
637
+ __decorate([
638
+ query('#color-palette-editor')
639
+ ], ColorPaletteEditor.prototype, "palette", void 0);
640
+ __decorate([
641
+ property({ type: Array })
642
+ ], ColorPaletteEditor.prototype, "colors", void 0);
643
+ __decorate([
644
+ property({ type: Object })
645
+ ], ColorPaletteEditor.prototype, "settings", void 0);
646
+ __decorate([
647
+ property({ type: String, reflect: true })
648
+ ], ColorPaletteEditor.prototype, "selectedInput", void 0);
649
+ __decorate([
650
+ property({ type: String })
651
+ ], ColorPaletteEditor.prototype, "combination", void 0);
652
+ __decorate([
653
+ property({ type: Object })
654
+ ], ColorPaletteEditor.prototype, "baseColor", void 0);
655
+ __decorate([
656
+ state()
657
+ ], ColorPaletteEditor.prototype, "colorPickerDisabled", void 0);
658
+ ColorPaletteEditor = __decorate([
659
+ customElement('color-palette-editor')
660
+ ], ColorPaletteEditor);
661
+ export { ColorPaletteEditor };
662
+ let SettingItem = class SettingItem extends LitElement {
663
+ constructor() {
664
+ super(...arguments);
665
+ this.name = '';
666
+ this.description = '';
667
+ }
668
+ render() {
669
+ return html `
670
+ <div>
671
+ <h3>${this.name}</h3>
672
+ <p>${this.description}</p>
673
+ </div>
674
+ <slot></slot>
561
675
  `;
562
- }
676
+ }
563
677
  };
564
- v.styles = [
565
- P`
566
- :host {
567
- display: grid;
568
- grid-template-columns: 1fr 1fr;
569
- padding-block: 2%;
570
- }
571
-
572
- :host(:not([description])) p {
573
- display: none;
574
- }
575
-
576
- h3 {
577
- margin: 0;
578
- font-size: 15px;
579
- }
580
-
581
- p {
582
- margin: 0;
583
- padding-top: 4px;
584
- font-size: 12px;
585
- }
586
-
587
- slot {
588
- display: flex;
589
- justify-self: flex-end;
590
- align-items: center;
591
- gap: 5%;
592
- }
593
-
594
- ::slotted(input[type="color"]) {
595
- border: none;
596
- }
678
+ SettingItem.styles = [
679
+ css `
680
+ :host {
681
+ display: grid;
682
+ grid-template-columns: 1fr 1fr;
683
+ padding-block: 2%;
684
+ }
685
+
686
+ :host(:not([description])) p {
687
+ display: none;
688
+ }
689
+
690
+ h3 {
691
+ margin: 0;
692
+ font-size: 15px;
693
+ }
694
+
695
+ p {
696
+ margin: 0;
697
+ padding-top: 4px;
698
+ font-size: 12px;
699
+ }
700
+
701
+ slot {
702
+ display: flex;
703
+ justify-self: flex-end;
704
+ align-items: center;
705
+ gap: 5%;
706
+ }
707
+
708
+ ::slotted(input[type="color"]) {
709
+ border: none;
710
+ }
597
711
  `
598
712
  ];
599
- s([
600
- u({ type: String })
601
- ], v.prototype, "name", 2);
602
- s([
603
- u({ type: String })
604
- ], v.prototype, "description", 2);
605
- v = s([
606
- U("setting-item")
607
- ], v);
608
- export {
609
- c as ColorPaletteEditor,
610
- v as SettingItem
611
- };
713
+ __decorate([
714
+ property({ type: String })
715
+ ], SettingItem.prototype, "name", void 0);
716
+ __decorate([
717
+ property({ type: String })
718
+ ], SettingItem.prototype, "description", void 0);
719
+ SettingItem = __decorate([
720
+ customElement('setting-item')
721
+ ], SettingItem);
722
+ export { SettingItem };