@alegendstale/holly-components 0.2.8 → 0.2.10
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.
- package/dist/components/absolute-container/absolute-container.js +113 -91
- package/dist/components/absolute-container/absolute-container.stories.js +36 -0
- package/dist/components/absolute-container/index.js +1 -1
- package/dist/components/bottom-sheet/bottom-sheet.js +415 -308
- package/dist/components/bottom-sheet/bottom-sheet.stories.js +43 -0
- package/dist/components/bottom-sheet/bottom-sheet.test.js +15 -0
- package/dist/components/bottom-sheet/index.js +1 -1
- package/dist/components/canvas/canvas-base.d.ts +2 -1
- package/dist/components/canvas/canvas-base.d.ts.map +1 -1
- package/dist/components/canvas/canvas-base.js +56 -44
- package/dist/components/canvas/canvas-gradient.d.ts.map +1 -1
- package/dist/components/canvas/canvas-gradient.js +61 -45
- package/dist/components/canvas/canvas-image.js +158 -111
- package/dist/components/canvas/index.js +2 -2
- package/dist/components/carousel-scroller/carousel-scroller.js +133 -121
- package/dist/components/carousel-scroller/carousel-scroller.stories.js +40 -0
- package/dist/components/carousel-scroller/index.js +1 -1
- package/dist/components/color-palette/color-palette-utils.d.ts.map +1 -1
- package/dist/components/color-palette/color-palette-utils.js +105 -40
- package/dist/components/color-palette/color-palette.js +429 -337
- package/dist/components/color-palette/component/color-palette-component.js +184 -142
- package/dist/components/color-palette/component/color-palette-component.stories.js +74 -0
- package/dist/components/color-palette/component/index.js +1 -0
- package/dist/components/color-palette/editor/color-palette-editor.js +702 -591
- package/dist/components/color-palette/editor/color-palette-editor.stories.js +39 -0
- package/dist/components/color-palette/editor/index.js +1 -0
- package/dist/components/color-palette/index.js +5 -7
- package/dist/components/color-palette/item/color-palette-item-edit.js +114 -87
- package/dist/components/color-palette/item/color-palette-item.js +155 -140
- package/dist/components/color-palette/item/index.js +2 -0
- package/dist/components/color-palette/menu/color-palette-menu.js +241 -217
- package/dist/components/color-palette/menu/color-palette-reorder.js +117 -103
- package/dist/components/color-palette/menu/index.js +2 -0
- package/dist/components/color-palette/storybook/color-palette-invalid.stories.js +90 -0
- package/dist/components/color-palette/storybook/color-palette-valid.stories.js +295 -0
- package/dist/components/color-palette/storybook/color-palette.stories.js +76 -0
- package/dist/components/tool-tip/Tooltip2.js +103 -0
- package/dist/components/tool-tip/index.js +1 -1
- package/dist/components/tool-tip/tool-tip.d.ts +1 -0
- package/dist/components/tool-tip/tool-tip.d.ts.map +1 -1
- package/dist/components/tool-tip/tool-tip.js +125 -102
- package/dist/components/tool-tip/tool-tip.stories.js +30 -0
- package/dist/index.js +6 -14
- package/dist/utils/EventEmitter.js +23 -23
- package/dist/utils/basicUtils.d.ts +2 -0
- package/dist/utils/basicUtils.d.ts.map +1 -1
- package/dist/utils/basicUtils.js +149 -23
- package/dist/utils/dragDropUtils.js +121 -0
- package/dist/utils/generateUtils.js +73 -39
- package/dist/utils/types.d.ts +1 -1
- package/dist/utils/types.d.ts.map +1 -1
- package/dist/utils/types.js +1 -0
- package/package.json +2 -3
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { html } from 'lit';
|
|
2
|
+
const meta = {
|
|
3
|
+
title: 'Bottom Sheet',
|
|
4
|
+
tags: ['autodocs'],
|
|
5
|
+
component: 'bottom-sheet',
|
|
6
|
+
};
|
|
7
|
+
export default meta;
|
|
8
|
+
const Template = {
|
|
9
|
+
render: ({ open, nonmodal, snapPoints }) => {
|
|
10
|
+
return html `
|
|
11
|
+
<bottom-sheet ?open=${open} .snapPoints=${snapPoints} ?nonmodal=${nonmodal}>
|
|
12
|
+
<p>
|
|
13
|
+
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque eget dui eros. Nunc vel magna pellentesque, euismod lacus eu, euismod ligula. Nulla porttitor ultrices enim, ac fermentum ligula bibendum nec. Maecenas et volutpat nulla. Donec sit amet dapibus est, ultricies accumsan nunc. Praesent vitae nulla metus. Aenean non posuere lorem, bibendum scelerisque mauris. Praesent arcu dolor, efficitur vel malesuada nec, rhoncus eget eros. Nullam facilisis, diam eu tristique euismod, neque dolor pellentesque purus, id tristique ex quam eget lacus. Pellentesque lacinia consequat ligula. Duis egestas ornare porttitor. Morbi tempus fermentum nulla. Sed eu turpis quis nunc aliquam cursus vitae nec arcu. Nulla nec leo et tellus condimentum commodo mollis in dolor. Vivamus tortor eros, dictum in nulla ac, ultricies posuere ligula. Maecenas elit sem, efficitur et risus sed, placerat imperdiet nisl. Donec nunc ipsum, molestie et elementum a, hendrerit in diam. Vestibulum
|
|
14
|
+
ullamcorper eu dolor id maximus. Donec in nunc vel dolor vehicula mollis. Mauris elementum, massa vitae condimentum efficitur, nisi massa condimentum dolor, at ultricies nulla ante et tortor. Praesent vitae vestibulum urna. Nunc aliquam aliquam elementum. Nullam facilisis ut ligula in ultrices. Vestibulum et risus ut eros gravida malesuada varius euismod dolor. Interdum et malesuada fames ac ante ipsum primis in faucibus. Aenean dui nisl, auctor quis laoreet fringilla, aliquam id risus. Pellentesque sit amet neque finibus, pharetra dolor eu, eleifend ante. Vestibulum condimentum urna urna, ut dignissim nibh posuere in. Proin nec tincidunt enim, vel vehicula nunc. In quis pellentesque urna. Curabitur egestas arcu non arcu ullamcorper, at pellentesque lacus varius. Maecenas ac molestie erat. Integer ornare dui vitae turpis porttitor, nec semper mauris ultrices. Quisque eu arcu ipsum. Morbi sed tristique urna. Pellentesque gravida, nisi elementum ultrices condimentum,
|
|
15
|
+
ipsum nisl faucibus ex, eget imperdiet dolor sem sit amet dui. Aenean dictum nibh nulla, non lacinia arcu molestie tempus. Donec a ex sodales, posuere felis eget, vestibulum odio. Sed lectus sapien, lacinia in orci eu, molestie finibus ex. Pellentesque dictum, dolor nec interdum gravida, sapien velit venenatis libero, eu finibus elit purus et ipsum. Vivamus sed eros libero. Aenean a auctor quam. Vivamus blandit enim tellus, in posuere enim fermentum varius. Donec malesuada orci ac ex dapibus, nec condimentum metus hendrerit. Nam non efficitur sem, ac ornare sapien. In varius libero et malesuada gravida. Suspendisse sollicitudin euismod ante, quis tincidunt quam rhoncus ac. Proin in pulvinar tortor. Nullam condimentum vestibulum dignissim. In hac habitasse platea dictumst. Etiam laoreet volutpat urna, et euismod urna aliquet egestas. Nulla odio tellus, vestibulum sit amet auctor vitae, tristique ut turpis. Cras sed tellus accumsan, pellentesque urna eget,
|
|
16
|
+
sollicitudin felis. In euismod ac arcu vitae suscipit. Curabitur non consequat nibh. In purus nulla, egestas in commodo in, fermentum sit amet massa. Nullam luctus velit vel arcu dictum, vel fermentum dolor convallis. Nulla interdum quam nibh, in egestas turpis vestibulum vel. Nulla placerat sapien sit amet pharetra porttitor.
|
|
17
|
+
</p>
|
|
18
|
+
</bottom-sheet>
|
|
19
|
+
`;
|
|
20
|
+
},
|
|
21
|
+
};
|
|
22
|
+
export const Modal = {
|
|
23
|
+
...Template,
|
|
24
|
+
args: {
|
|
25
|
+
open: false,
|
|
26
|
+
snapPoints: [0, 50, 100],
|
|
27
|
+
},
|
|
28
|
+
};
|
|
29
|
+
export const NonModal = {
|
|
30
|
+
...Template,
|
|
31
|
+
args: {
|
|
32
|
+
open: false,
|
|
33
|
+
nonmodal: true,
|
|
34
|
+
snapPoints: [0, 50, 100],
|
|
35
|
+
},
|
|
36
|
+
};
|
|
37
|
+
export const Thirds = {
|
|
38
|
+
...Template,
|
|
39
|
+
args: {
|
|
40
|
+
open: false,
|
|
41
|
+
snapPoints: [0, 33, 66],
|
|
42
|
+
},
|
|
43
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { $, expect } from '@wdio/globals';
|
|
2
|
+
import './bottom-sheet';
|
|
3
|
+
import { html, render } from 'lit';
|
|
4
|
+
describe('Lit component testing', () => {
|
|
5
|
+
it('should open the sheet', async () => {
|
|
6
|
+
render(html `
|
|
7
|
+
<bottom-sheet></bottom-sheet>,
|
|
8
|
+
`, document.body);
|
|
9
|
+
const sheet = await $('bottom-sheet');
|
|
10
|
+
it('should open sheet', async () => {
|
|
11
|
+
// sheet.showSheet(true);
|
|
12
|
+
await expect($(sheet)).toHaveAttr('open');
|
|
13
|
+
});
|
|
14
|
+
});
|
|
15
|
+
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import
|
|
1
|
+
import './bottom-sheet';
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { EventEmitter } from '../../utils/EventEmitter';
|
|
2
|
+
import { LitElement } from 'lit';
|
|
3
|
+
import { client } from '../../utils/types';
|
|
2
4
|
type EventMap = {
|
|
3
5
|
click: [hex: string];
|
|
4
6
|
move: [e: client];
|
|
5
7
|
};
|
|
6
|
-
import { LitElement } from 'lit';
|
|
7
8
|
export declare class CanvasBase extends LitElement {
|
|
8
9
|
canvas: HTMLCanvasElement;
|
|
9
10
|
protected context: CanvasRenderingContext2D;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"canvas-base.d.ts","sourceRoot":"","sources":["../../../src/components/canvas/canvas-base.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;
|
|
1
|
+
{"version":3,"file":"canvas-base.d.ts","sourceRoot":"","sources":["../../../src/components/canvas/canvas-base.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAExD,OAAO,EAAE,UAAU,EAAa,MAAM,KAAK,CAAC;AAE5C,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAE3C,KAAK,QAAQ,GAAG;IACf,KAAK,EAAE,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;IACrB,IAAI,EAAE,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC;CAClB,CAAC;AAEF,qBACa,UAAW,SAAQ,UAAU;IAEzC,MAAM,EAAG,iBAAiB,CAAC;IAE3B,SAAS,CAAC,OAAO,EAAG,wBAAwB,CAAC;IAEtC,OAAO,EAAE,YAAY,CAAC,QAAQ,CAAC,CAAgC;IAEtE,oBAAoB,IAAI,IAAI;IAK5B,MAAM;IAsBC,YAAY,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM;CAWpD"}
|
|
@@ -1,48 +1,60 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
var C = Object.defineProperty, b = Object.getOwnPropertyDescriptor, v = (i, e, r, a) => {
|
|
7
|
-
for (var t = a > 1 ? void 0 : a ? b(e, r) : e, n = i.length - 1, s; n >= 0; n--)
|
|
8
|
-
(s = i[n]) && (t = (a ? s(e, r, t) : s(t)) || t);
|
|
9
|
-
return a && t && C(e, r, t), t;
|
|
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;
|
|
10
6
|
};
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
7
|
+
import colorsea from 'colorsea';
|
|
8
|
+
import { EventEmitter } from '../../utils/EventEmitter';
|
|
9
|
+
import { ref } from 'lit/directives/ref.js';
|
|
10
|
+
import { LitElement, html } from 'lit';
|
|
11
|
+
import { customElement, query } from 'lit/decorators.js';
|
|
12
|
+
let CanvasBase = class CanvasBase extends LitElement {
|
|
13
|
+
constructor() {
|
|
14
|
+
super(...arguments);
|
|
15
|
+
this.emitter = new EventEmitter();
|
|
16
|
+
}
|
|
17
|
+
disconnectedCallback() {
|
|
18
|
+
super.disconnectedCallback();
|
|
19
|
+
this.emitter.clear();
|
|
20
|
+
}
|
|
21
|
+
render() {
|
|
22
|
+
let canvasRef = (canvas) => {
|
|
23
|
+
if (!(canvas instanceof HTMLCanvasElement))
|
|
24
|
+
return;
|
|
25
|
+
this.context = canvas.getContext('2d', { willReadFrequently: true, alpha: true });
|
|
26
|
+
};
|
|
27
|
+
return html `
|
|
28
|
+
<canvas
|
|
29
|
+
@click=${(e) => this.emitter.emit('click', this.getCanvasHex(e.clientX, e.clientY))}
|
|
22
30
|
@pointermove=${(e) => {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
31
|
+
// Track only the first touch
|
|
32
|
+
if (!e.isPrimary)
|
|
33
|
+
return;
|
|
34
|
+
this.emitter.emit('move', { x: e.clientX, y: e.clientY });
|
|
35
|
+
}}
|
|
36
|
+
${ref(canvasRef)}
|
|
37
|
+
>
|
|
38
|
+
</canvas>
|
|
30
39
|
`;
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
g("canvas-base")
|
|
45
|
-
], c);
|
|
46
|
-
export {
|
|
47
|
-
c as CanvasBase
|
|
40
|
+
}
|
|
41
|
+
// Retrieves the hex from the mouse position
|
|
42
|
+
getCanvasHex(clientX, clientY) {
|
|
43
|
+
const canvasBounds = this.canvas.getBoundingClientRect();
|
|
44
|
+
let x = clientX - canvasBounds.left;
|
|
45
|
+
let y = clientY - canvasBounds.top;
|
|
46
|
+
let [r, g, b, a] = this.context.getImageData(x, y, 1, 1).data;
|
|
47
|
+
// Convert alpha from 0-255 to 0-1
|
|
48
|
+
const alpha = Math.round((a / 255) * 100);
|
|
49
|
+
// Hide alpha value if not an alpha color
|
|
50
|
+
let hex = alpha !== 255 ? colorsea([r, g, b, alpha]).hex() : colorsea([r, g, b]).hex();
|
|
51
|
+
return hex;
|
|
52
|
+
}
|
|
48
53
|
};
|
|
54
|
+
__decorate([
|
|
55
|
+
query('canvas')
|
|
56
|
+
], CanvasBase.prototype, "canvas", void 0);
|
|
57
|
+
CanvasBase = __decorate([
|
|
58
|
+
customElement('canvas-base')
|
|
59
|
+
], CanvasBase);
|
|
60
|
+
export { CanvasBase };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"canvas-gradient.d.ts","sourceRoot":"","sources":["../../../src/components/canvas/canvas-gradient.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,sCAAsC,CAAC;
|
|
1
|
+
{"version":3,"file":"canvas-gradient.d.ts","sourceRoot":"","sources":["../../../src/components/canvas/canvas-gradient.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,sCAAsC,CAAC;AAEjE,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,cAAc,EAAE,MAAM,KAAK,CAAC;AAGrC,qBACa,cAAe,SAAQ,UAAU;IAE7C,MAAM,EAAE,MAAM,EAAE,CAAM;IAGtB,MAAM,EAAE,MAAM,CAAK;IAGnB,KAAK,EAAE,MAAM,CAAK;IAGlB,SAAS,EAAE,SAAS,CAAoB;IAExC,SAAS,CAAC,OAAO,CAAC,kBAAkB,EAAE,cAAc,GAAG,IAAI;IAM3D;;OAEG;IACI,cAAc,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,SAAS;CAyB3F;AAED,OAAO,CAAC,MAAM,CAAC;IACd,UAAU,qBAAqB;QAC9B,iBAAiB,EAAE,cAAc,CAAC;KAClC;CACD"}
|
|
@@ -1,47 +1,63 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
for (var t = i > 1 ? void 0 : i ? v(e, o) : e, s = r.length - 1, a; s >= 0; s--)
|
|
7
|
-
(a = r[s]) && (t = (i ? a(e, o, t) : a(t)) || t);
|
|
8
|
-
return i && t && m(e, o, t), t;
|
|
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;
|
|
9
6
|
};
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
7
|
+
import { Direction } from '../color-palette/color-palette-utils';
|
|
8
|
+
import { customElement, property } from 'lit/decorators.js';
|
|
9
|
+
import { CanvasBase } from './canvas-base';
|
|
10
|
+
import { isColorValid } from '../../utils/basicUtils';
|
|
11
|
+
let CanvasGradient = class CanvasGradient extends CanvasBase {
|
|
12
|
+
constructor() {
|
|
13
|
+
super(...arguments);
|
|
14
|
+
this.colors = [];
|
|
15
|
+
this.height = 0;
|
|
16
|
+
this.width = 0;
|
|
17
|
+
this.direction = Direction.Column;
|
|
18
|
+
}
|
|
19
|
+
updated(_changedProperties) {
|
|
20
|
+
super.updated(_changedProperties);
|
|
21
|
+
this.createGradient(this.colors, this.height, this.width, this.direction);
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Creates a new gradient canvas
|
|
25
|
+
*/
|
|
26
|
+
createGradient(colors, height, width, direction) {
|
|
27
|
+
if (!this.context)
|
|
28
|
+
return;
|
|
29
|
+
this.canvas.height = height;
|
|
30
|
+
this.canvas.width = width;
|
|
31
|
+
let gradient = direction === Direction.Column ? this.context.createLinearGradient(0, 0, width, 0) : this.context.createLinearGradient(0, 0, 0, height);
|
|
32
|
+
let colorStops = [];
|
|
33
|
+
for (const [i, color] of colors.entries()) {
|
|
34
|
+
// Skip non-colors, even with override enabled. This prevents errors, especially dealing with css-variables which cannot be parsed at run-time.
|
|
35
|
+
if (isColorValid(color)) {
|
|
36
|
+
gradient.addColorStop(i / (colors.length - 1), color);
|
|
37
|
+
colorStops.push(color);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
if (colorStops.length <= 1)
|
|
41
|
+
throw new Error('There are not enough valid color stops to create the gradient.');
|
|
42
|
+
this.context.fillStyle = gradient || '#000';
|
|
43
|
+
this.context.fillRect(0, 0, width, height);
|
|
44
|
+
this.canvas.classList.add('gradient');
|
|
45
|
+
this.canvas.style.setProperty('--palette-column-flex-basis', (height / colors.length / 2).toString() + 'px');
|
|
46
|
+
}
|
|
47
47
|
};
|
|
48
|
+
__decorate([
|
|
49
|
+
property({ type: Array })
|
|
50
|
+
], CanvasGradient.prototype, "colors", void 0);
|
|
51
|
+
__decorate([
|
|
52
|
+
property({ type: Number })
|
|
53
|
+
], CanvasGradient.prototype, "height", void 0);
|
|
54
|
+
__decorate([
|
|
55
|
+
property({ type: Number })
|
|
56
|
+
], CanvasGradient.prototype, "width", void 0);
|
|
57
|
+
__decorate([
|
|
58
|
+
property({ type: String })
|
|
59
|
+
], CanvasGradient.prototype, "direction", void 0);
|
|
60
|
+
CanvasGradient = __decorate([
|
|
61
|
+
customElement('canvas-gradient')
|
|
62
|
+
], CanvasGradient);
|
|
63
|
+
export { CanvasGradient };
|
|
@@ -1,117 +1,164 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
for (var t = s > 1 ? void 0 : s ? L(a, i) : a, r = e.length - 1, n; r >= 0; r--)
|
|
7
|
-
(n = e[r]) && (t = (s ? n(a, i, t) : n(t)) || t);
|
|
8
|
-
return s && t && x(a, i, t), t;
|
|
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;
|
|
9
6
|
};
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
7
|
+
import { html, css } from 'lit';
|
|
8
|
+
import { customElement, property, query } from 'lit/decorators.js';
|
|
9
|
+
import quantize from 'quantize';
|
|
10
|
+
import { CanvasBase } from './canvas-base';
|
|
11
|
+
let CanvasImage = class CanvasImage extends CanvasBase {
|
|
12
|
+
constructor() {
|
|
13
|
+
super(...arguments);
|
|
14
|
+
this.imageURL = '';
|
|
15
|
+
this.smoothing = false;
|
|
16
|
+
this.loading = true;
|
|
17
|
+
this.width = 0;
|
|
18
|
+
this.height = 0;
|
|
19
|
+
/**
|
|
20
|
+
* Waits for loading variable to equal true
|
|
21
|
+
*/
|
|
22
|
+
this.waitForLoading = () => new Promise((resolve) => {
|
|
23
|
+
const checkLoading = setInterval(() => {
|
|
24
|
+
if (!this.loading) {
|
|
25
|
+
clearInterval(checkLoading);
|
|
26
|
+
resolve(true);
|
|
27
|
+
}
|
|
28
|
+
}, 100);
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
firstUpdated(_changedProperties) {
|
|
32
|
+
super.firstUpdated(_changedProperties);
|
|
33
|
+
this.canvas.classList.add('image');
|
|
34
|
+
this.context.imageSmoothingEnabled = this.smoothing;
|
|
35
|
+
}
|
|
36
|
+
render() {
|
|
37
|
+
// Allows CORS requests for images from different domains
|
|
38
|
+
return html `
|
|
39
|
+
${super.render()}
|
|
40
|
+
<img
|
|
41
|
+
src=${this.imageURL}
|
|
42
|
+
crossorigin='anonymous'
|
|
43
|
+
@load=${() => this.loading = false}
|
|
44
|
+
>
|
|
29
45
|
`;
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* Updates & loads the canvas image.
|
|
33
|
-
* Attempts to preserve aspect ratio based on width.
|
|
34
|
-
* @param width The canvas width
|
|
35
|
-
* @param height The canvas height
|
|
36
|
-
*/
|
|
37
|
-
updateImage(e, a, i) {
|
|
38
|
-
this.image.src = e, this.waitForLoading().then(() => {
|
|
39
|
-
const s = this.image.naturalHeight / this.image.naturalWidth;
|
|
40
|
-
let t = a, r = t * s;
|
|
41
|
-
r > i && (t = i / s, r = i), this.width = this.canvas.width = t, this.height = this.canvas.height = r, this.context.drawImage(this.image, 0, 0, t, r);
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* Gets the most frequent colors in an image
|
|
46
|
-
* @param numColors Number of colors to return
|
|
47
|
-
* @param quality Artificially reduce number of pixels (higher = less accurate but faster)
|
|
48
|
-
* @returns Most frequent colors
|
|
49
|
-
*/
|
|
50
|
-
async getPalette(e = 7, a = 10) {
|
|
51
|
-
const i = e <= 7 ? e : e + 1;
|
|
52
|
-
await this.waitForLoading();
|
|
53
|
-
const s = await this.createPixelArray(a);
|
|
54
|
-
if (!s) return null;
|
|
55
|
-
const t = y(s, i);
|
|
56
|
-
return t ? t.palette() : [];
|
|
57
|
-
}
|
|
58
|
-
/**
|
|
59
|
-
* Creates an array of pixels from the image
|
|
60
|
-
* Inspired by colorthief
|
|
61
|
-
* @param quality Artificially reduce number of pixels (higher = less accurate but faster)
|
|
62
|
-
* @returns
|
|
63
|
-
*/
|
|
64
|
-
async createPixelArray(e) {
|
|
65
|
-
var t;
|
|
66
|
-
await this.waitForLoading();
|
|
67
|
-
const a = [], i = (t = await this.getImageData()) == null ? void 0 : t.data;
|
|
68
|
-
if (!i) return null;
|
|
69
|
-
const s = this.height * this.width;
|
|
70
|
-
for (let r = 0; r < s; r += e) {
|
|
71
|
-
const n = r * 4, [g, c, l, d] = [i[n + 0], i[n + 1], i[n + 2], i[n + 3]];
|
|
72
|
-
(typeof d > "u" || d >= 125) && (g > 250 && c > 250 && l > 250 || a.push([g, c, l]));
|
|
73
46
|
}
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
47
|
+
/**
|
|
48
|
+
* Updates & loads the canvas image.
|
|
49
|
+
* Attempts to preserve aspect ratio based on width.
|
|
50
|
+
* @param width The canvas width
|
|
51
|
+
* @param height The canvas height
|
|
52
|
+
*/
|
|
53
|
+
updateImage(imageURL, width, height) {
|
|
54
|
+
// Set URL
|
|
55
|
+
this.image.src = imageURL;
|
|
56
|
+
// Wait for image to load before calculating dimensions & drawing image to canvas
|
|
57
|
+
this.waitForLoading().then(() => {
|
|
58
|
+
// Calculate the new height based on the aspect ratio
|
|
59
|
+
const aspectRatio = this.image.naturalHeight / this.image.naturalWidth;
|
|
60
|
+
let newWidth = width;
|
|
61
|
+
let newHeight = newWidth * aspectRatio;
|
|
62
|
+
// Ensure the new height fits within the canvas height
|
|
63
|
+
if (newHeight > height) {
|
|
64
|
+
// Adjust width if height exceeds canvas height
|
|
65
|
+
newWidth = height / aspectRatio;
|
|
66
|
+
newHeight = height;
|
|
67
|
+
}
|
|
68
|
+
this.width = this.canvas.width = newWidth;
|
|
69
|
+
this.height = this.canvas.height = newHeight;
|
|
70
|
+
this.context.drawImage(this.image, 0, 0, newWidth, newHeight);
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Gets the most frequent colors in an image
|
|
75
|
+
* @param numColors Number of colors to return
|
|
76
|
+
* @param quality Artificially reduce number of pixels (higher = less accurate but faster)
|
|
77
|
+
* @returns Most frequent colors
|
|
78
|
+
*/
|
|
79
|
+
async getPalette(numColors = 7, quality = 10) {
|
|
80
|
+
/*
|
|
81
|
+
Quantize has an issue with number of colors which has been addressed here https://github.com/olivierlesnicki/quantize/issues/9
|
|
82
|
+
`nColors` is a simple fix for this.
|
|
83
|
+
*/
|
|
84
|
+
const nColors = numColors <= 7 ? numColors : numColors + 1;
|
|
85
|
+
// Wait for image to load
|
|
86
|
+
await this.waitForLoading();
|
|
87
|
+
// Get an array of pixels
|
|
88
|
+
const pixels = await this.createPixelArray(quality);
|
|
89
|
+
if (!pixels)
|
|
90
|
+
return null;
|
|
91
|
+
// Reduce pixels array to a small number of the most common colors
|
|
92
|
+
const colorMap = quantize(pixels, nColors);
|
|
93
|
+
// Return palette
|
|
94
|
+
return colorMap ? colorMap.palette() : [];
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Creates an array of pixels from the image
|
|
98
|
+
* Inspired by colorthief
|
|
99
|
+
* @param quality Artificially reduce number of pixels (higher = less accurate but faster)
|
|
100
|
+
* @returns
|
|
101
|
+
*/
|
|
102
|
+
async createPixelArray(quality) {
|
|
103
|
+
await this.waitForLoading();
|
|
104
|
+
const pixelArray = [];
|
|
105
|
+
const imageData = (await this.getImageData())?.data;
|
|
106
|
+
if (!imageData)
|
|
107
|
+
return null;
|
|
108
|
+
// Get number of pixels in image
|
|
109
|
+
const pixelCount = this.height * this.width;
|
|
110
|
+
for (let i = 0; i < pixelCount; i += quality) {
|
|
111
|
+
// Offset to correct starting position of each pixel
|
|
112
|
+
const offset = i * 4;
|
|
113
|
+
const [r, g, b, a] = [imageData[offset + 0], imageData[offset + 1], imageData[offset + 2], imageData[offset + 3]];
|
|
114
|
+
// If pixel is mostly opaque and not white
|
|
115
|
+
if (typeof a === 'undefined' || a >= 125) {
|
|
116
|
+
if (!(r > 250 && g > 250 && b > 250)) {
|
|
117
|
+
pixelArray.push([r, g, b]);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
return pixelArray;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Gets the image data from the canvas
|
|
125
|
+
*/
|
|
126
|
+
async getImageData(x = 0, y = 0) {
|
|
127
|
+
try {
|
|
128
|
+
await this.waitForLoading();
|
|
129
|
+
return this.context.getImageData(x, y, this.width, this.height);
|
|
130
|
+
}
|
|
131
|
+
catch (e) {
|
|
132
|
+
throw new Error('Failed to get image data.');
|
|
133
|
+
}
|
|
84
134
|
}
|
|
85
|
-
}
|
|
86
135
|
};
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
:host {
|
|
90
|
-
display: block;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
/* Hide when width hasn't been set */
|
|
94
|
-
canvas:not([width]) {
|
|
95
|
-
display: none;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
img {
|
|
99
|
-
display: none;
|
|
100
|
-
}
|
|
101
|
-
|
|
136
|
+
CanvasImage.styles = [
|
|
137
|
+
css `
|
|
138
|
+
:host {
|
|
139
|
+
display: block;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/* Hide when width hasn't been set */
|
|
143
|
+
canvas:not([width]) {
|
|
144
|
+
display: none;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
img {
|
|
148
|
+
display: none;
|
|
149
|
+
}
|
|
150
|
+
`,
|
|
102
151
|
];
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
],
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
],
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
],
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
],
|
|
115
|
-
export {
|
|
116
|
-
o as CanvasImage
|
|
117
|
-
};
|
|
152
|
+
__decorate([
|
|
153
|
+
query('img')
|
|
154
|
+
], CanvasImage.prototype, "image", void 0);
|
|
155
|
+
__decorate([
|
|
156
|
+
property({ type: String })
|
|
157
|
+
], CanvasImage.prototype, "imageURL", void 0);
|
|
158
|
+
__decorate([
|
|
159
|
+
property({ type: Boolean })
|
|
160
|
+
], CanvasImage.prototype, "smoothing", void 0);
|
|
161
|
+
CanvasImage = __decorate([
|
|
162
|
+
customElement('canvas-image')
|
|
163
|
+
], CanvasImage);
|
|
164
|
+
export { CanvasImage };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import './canvas-gradient';
|
|
2
|
+
import './canvas-image';
|