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 |
|
8 | import { adoptedStyle, customElement, attribute, globalemitter, boolattribute, refobject, } from '@mantou/gem/lib/decorators';
|
9 | import { GemElement, html } from '@mantou/gem/lib/element';
|
10 | import { createCSSSheet, css, styleMap } from '@mantou/gem/lib/utils';
|
11 | import { theme } from '../lib/theme';
|
12 | import { commonHandle } from '../lib/hotkeys';
|
13 | import { focusStyle } from '../lib/styles';
|
14 | import './popover';
|
15 | import './color-panel';
|
16 | const style = createCSSSheet(css `
|
17 | :host(:where(:not([hidden]))) {
|
18 | cursor: pointer;
|
19 | display: inline-flex;
|
20 | font-size: 0.875em;
|
21 | width: 4em;
|
22 | overflow: hidden;
|
23 | border-radius: ${theme.normalRound};
|
24 | background: conic-gradient(
|
25 | transparent 0.25turn,
|
26 | #d3cfcf 0.25turn 0.5turn,
|
27 | transparent 0.5turn 0.75turn,
|
28 | #d3cfcf 0.75turn
|
29 | )
|
30 | top left / 1.2em 1.2em repeat;
|
31 | }
|
32 | .picker {
|
33 | width: 100%;
|
34 | height: calc(2.2em + 2px);
|
35 | border-radius: ${theme.normalRound};
|
36 | box-shadow: inset 0 0 0 1px #0002;
|
37 | }
|
38 | `);
|
39 |
|
40 |
|
41 |
|
42 | let DuoyunColorPickElement = class DuoyunColorPickElement extends GemElement {
|
43 | constructor() {
|
44 | super({ delegatesFocus: true });
|
45 | this.render = () => {
|
46 | return html `
|
47 | <dy-popover
|
48 | trigger="click"
|
49 | ref=${this.popoverRef.ref}
|
50 | .content=${html `
|
51 | <dy-color-panel
|
52 | style=${styleMap({ marginBlock: '.6em' })}
|
53 | value=${this.value}
|
54 | ?alpha=${this.alpha}
|
55 | @change=${({ detail }) => this.change(detail)}
|
56 | ></dy-color-panel>
|
57 | `}
|
58 | >
|
59 | <div
|
60 | role="combobox"
|
61 | tabindex="0"
|
62 | @keydown=${commonHandle}
|
63 | class="picker"
|
64 | style=${styleMap({ backgroundColor: this.value })}
|
65 | ></div>
|
66 | </dy-popover>
|
67 | `;
|
68 | };
|
69 | }
|
70 | showPicker() {
|
71 | var _a;
|
72 | (_a = this.popoverRef.element) === null || _a === void 0 ? void 0 : _a.click();
|
73 | }
|
74 | };
|
75 | __decorate([
|
76 | attribute
|
77 | ], DuoyunColorPickElement.prototype, "value", void 0);
|
78 | __decorate([
|
79 | boolattribute
|
80 | ], DuoyunColorPickElement.prototype, "alpha", void 0);
|
81 | __decorate([
|
82 | refobject
|
83 | ], DuoyunColorPickElement.prototype, "popoverRef", void 0);
|
84 | __decorate([
|
85 | globalemitter
|
86 | ], DuoyunColorPickElement.prototype, "change", void 0);
|
87 | DuoyunColorPickElement = __decorate([
|
88 | customElement('dy-color-picker'),
|
89 | adoptedStyle(style),
|
90 | adoptedStyle(focusStyle)
|
91 | ], DuoyunColorPickElement);
|
92 | export { DuoyunColorPickElement };
|
93 |
|
\ | No newline at end of file |