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 | var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
8 | if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
9 | if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
10 | return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
11 | };
|
12 | var _DuoyunCardElement_onOpenMenu;
|
13 | var DuoyunCardElement_1;
|
14 |
|
15 | import { adoptedStyle, customElement, attribute, property, part } from '@mantou/gem/lib/decorators';
|
16 | import { html } from '@mantou/gem/lib/element';
|
17 | import { createCSSSheet, css } from '@mantou/gem/lib/utils';
|
18 | import { theme } from '../lib/theme';
|
19 | import { icons } from '../lib/icons';
|
20 | import { commonHandle } from '../lib/hotkeys';
|
21 | import { focusStyle } from '../lib/styles';
|
22 | import { DuoyunLoadableBaseElement } from './base/loadable';
|
23 | import { ContextMenu } from './menu';
|
24 | import './use';
|
25 | const style = createCSSSheet(css `
|
26 | :host(:where(:not([hidden]))) {
|
27 | display: flex;
|
28 | flex-direction: column;
|
29 | padding: 1em;
|
30 | border: 1px solid ${theme.borderColor};
|
31 | border-radius: ${theme.normalRound};
|
32 | }
|
33 | .preview {
|
34 | display: block;
|
35 | margin: -1em -1em 1em;
|
36 | aspect-ratio: 2 / 1;
|
37 | background: ${theme.hoverBackgroundColor};
|
38 | width: calc(100% + 2em);
|
39 | object-fit: cover;
|
40 | }
|
41 | .avatar {
|
42 | display: block;
|
43 | width: 4em;
|
44 | height: 4em;
|
45 | border: 2px solid ${theme.backgroundColor};
|
46 | background: ${theme.describeColor};
|
47 | border-radius: 4em;
|
48 | margin-block: -4em 1em;
|
49 | object-fit: cover;
|
50 | }
|
51 | .header {
|
52 | display: flex;
|
53 | gap: 0.2em;
|
54 | align-items: baseline;
|
55 | margin-block-end: 1em;
|
56 | }
|
57 | .title {
|
58 | font-size: 1.125em;
|
59 | font-weight: bold;
|
60 | color: ${theme.highlightColor};
|
61 | }
|
62 | .detail {
|
63 | flex-grow: 1;
|
64 | font-size: 0.875em;
|
65 | color: ${theme.describeColor};
|
66 | }
|
67 | .detail:not(.right) {
|
68 | text-transform: uppercase;
|
69 | }
|
70 | .right {
|
71 | flex-grow: 0;
|
72 | white-space: nowrap;
|
73 | }
|
74 | .actions {
|
75 | width: 1.5em;
|
76 | padding: 0.1em;
|
77 | border-radius: ${theme.normalRound};
|
78 | align-self: center;
|
79 | }
|
80 | .actions:where(:hover, [data-active], :state(active)) {
|
81 | background-color: ${theme.hoverBackgroundColor};
|
82 | }
|
83 | slot[name='body']::slotted(*) {
|
84 | hyphens: auto;
|
85 | margin-block-end: 0em !important;
|
86 | }
|
87 | slot[name='footer']::slotted(*) {
|
88 | margin-block-start: 1em;
|
89 | padding-block-start: 1em;
|
90 | border-block-start: 1px solid ${theme.borderColor};
|
91 | border-radius: 0;
|
92 | display: flex;
|
93 | justify-content: flex-end;
|
94 | gap: 1em;
|
95 | }
|
96 | `);
|
97 |
|
98 |
|
99 |
|
100 |
|
101 |
|
102 |
|
103 |
|
104 | let DuoyunCardElement = DuoyunCardElement_1 = class DuoyunCardElement extends DuoyunLoadableBaseElement {
|
105 | constructor() {
|
106 | super({ delegatesFocus: true });
|
107 | _DuoyunCardElement_onOpenMenu.set(this, (evt) => {
|
108 | const target = evt.target;
|
109 | ContextMenu.open(this.actions.map((e) => ({ ...e, handle: () => e.handle(target) })), { activeElement: target });
|
110 | });
|
111 | this.render = () => {
|
112 | return html `
|
113 | ${this.preview
|
114 | ? html `<img
|
115 | part=${DuoyunCardElement_1.preview}
|
116 | alt="preview"
|
117 | class="preview"
|
118 | src=${this.preview}
|
119 | crossorigin=${this.crossorigin}
|
120 | />`
|
121 | : ''}
|
122 | ${this.avatar
|
123 | ? html `<img
|
124 | part=${DuoyunCardElement_1.avatar}
|
125 | alt="avatar"
|
126 | class="avatar"
|
127 | src=${this.avatar}
|
128 | crossorigin=${this.crossorigin}
|
129 | />`
|
130 | : ''}
|
131 | ${this.header
|
132 | ? html `
|
133 | <div class="header">
|
134 | <div class="title">${this.header}</div>
|
135 | <div class="detail">${this.detail}</div>
|
136 | <div class="detail right">${this.detailRight}</div>
|
137 | ${this.actions
|
138 | ? html `
|
139 | <dy-use
|
140 | tabindex="0"
|
141 | role="button"
|
142 | class="actions"
|
143 | @click=${__classPrivateFieldGet(this, _DuoyunCardElement_onOpenMenu, "f")}
|
144 | @keydown=${commonHandle}
|
145 | .element=${icons.more}
|
146 | ></dy-use>
|
147 | `
|
148 | : ''}
|
149 | </div>
|
150 | `
|
151 | : ''}
|
152 | <slot name="body"></slot>
|
153 | <slot></slot>
|
154 | <slot name="footer"></slot>
|
155 | `;
|
156 | };
|
157 | this.internals.role = 'group';
|
158 | }
|
159 | };
|
160 | _DuoyunCardElement_onOpenMenu = new WeakMap();
|
161 | __decorate([
|
162 | attribute
|
163 | ], DuoyunCardElement.prototype, "avatar", void 0);
|
164 | __decorate([
|
165 | attribute
|
166 | ], DuoyunCardElement.prototype, "preview", void 0);
|
167 | __decorate([
|
168 | property
|
169 | ], DuoyunCardElement.prototype, "header", void 0);
|
170 | __decorate([
|
171 | property
|
172 | ], DuoyunCardElement.prototype, "detail", void 0);
|
173 | __decorate([
|
174 | property
|
175 | ], DuoyunCardElement.prototype, "detailRight", void 0);
|
176 | __decorate([
|
177 | property
|
178 | ], DuoyunCardElement.prototype, "actions", void 0);
|
179 | __decorate([
|
180 | attribute
|
181 | ], DuoyunCardElement.prototype, "crossorigin", void 0);
|
182 | __decorate([
|
183 | part
|
184 | ], DuoyunCardElement, "preview", void 0);
|
185 | __decorate([
|
186 | part
|
187 | ], DuoyunCardElement, "avatar", void 0);
|
188 | DuoyunCardElement = DuoyunCardElement_1 = __decorate([
|
189 | customElement('dy-card'),
|
190 | adoptedStyle(style),
|
191 | adoptedStyle(focusStyle)
|
192 | ], DuoyunCardElement);
|
193 | export { DuoyunCardElement };
|
194 |
|
\ | No newline at end of file |