@micropasts/authority-card 0.0.0-stage → 0.1.0
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/LICENSE +21 -0
- package/README.md +251 -2
- package/dist/authority-card.esm.js +778 -0
- package/dist/authority-card.iife.js +788 -0
- package/package.json +39 -3
- package/src/core.js +316 -0
- package/src/demo.html +189 -0
- package/src/index.js +10 -0
- package/src/shadow.js +281 -0
- package/src/tailwind.js +174 -0
package/src/shadow.js
ADDED
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
import { resolveAuthority, emitSelect, copyTextToClipboard } from './core.js';
|
|
2
|
+
|
|
3
|
+
let globalTemplate = null;
|
|
4
|
+
|
|
5
|
+
export class AuthorityCard extends HTMLElement {
|
|
6
|
+
static get observedAttributes() {
|
|
7
|
+
return ['uri', 'mode', 'listen'];
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
static setTemplate(fn) {
|
|
11
|
+
globalTemplate = fn;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
constructor() {
|
|
15
|
+
super();
|
|
16
|
+
this.attachShadow({ mode: 'open' });
|
|
17
|
+
this._open = false;
|
|
18
|
+
this._data = null;
|
|
19
|
+
this.template = null;
|
|
20
|
+
this._onExternalSelect = this._onExternalSelect.bind(this);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
connectedCallback() {
|
|
24
|
+
this.renderShell();
|
|
25
|
+
this._bindEvents();
|
|
26
|
+
if (this.mode === 'panel' && this.getAttribute('uri')) {
|
|
27
|
+
this.loadAndRender(this.getAttribute('uri'));
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
disconnectedCallback() {
|
|
32
|
+
const eventName = this.getAttribute('listen');
|
|
33
|
+
if (eventName) {
|
|
34
|
+
window.removeEventListener(eventName, this._onExternalSelect);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
attributeChangedCallback(name, oldVal, newVal) {
|
|
39
|
+
if (oldVal === newVal || !this.isConnected) return;
|
|
40
|
+
if (name === 'uri' && this.mode === 'panel' && newVal) {
|
|
41
|
+
this.loadAndRender(newVal);
|
|
42
|
+
}
|
|
43
|
+
if (name === 'mode') {
|
|
44
|
+
this.renderShell();
|
|
45
|
+
this._bindEvents();
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
get mode() {
|
|
50
|
+
return this.getAttribute('mode') || 'popover';
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
_bindEvents() {
|
|
54
|
+
const eventName = this.getAttribute('listen');
|
|
55
|
+
if (eventName) {
|
|
56
|
+
window.addEventListener(eventName, this._onExternalSelect);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
if (this.mode === 'popover') {
|
|
60
|
+
const trigger = this.shadowRoot.querySelector('[part="trigger"]');
|
|
61
|
+
trigger?.addEventListener('mouseenter', () => this.open());
|
|
62
|
+
trigger?.addEventListener('focus', () => this.open());
|
|
63
|
+
trigger?.addEventListener('click', (e) => {
|
|
64
|
+
emitSelect(this, this.getAttribute('uri'), this._data);
|
|
65
|
+
if (this.hasAttribute('prevent-navigation')) e.preventDefault();
|
|
66
|
+
});
|
|
67
|
+
this.addEventListener('mouseleave', () => this.close());
|
|
68
|
+
this.addEventListener('keydown', (e) => {
|
|
69
|
+
if (e.key === 'Escape') this.close();
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
_onExternalSelect(e) {
|
|
75
|
+
const uri = e.detail?.uri;
|
|
76
|
+
if (!uri) return;
|
|
77
|
+
this.setAttribute('uri', uri);
|
|
78
|
+
this.loadAndRender(uri);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
async open() {
|
|
82
|
+
if (this.mode !== 'popover') return;
|
|
83
|
+
this._open = true;
|
|
84
|
+
this._updateCardVisibility();
|
|
85
|
+
const uri = this.getAttribute('uri');
|
|
86
|
+
if (!this._data && uri) {
|
|
87
|
+
await this.loadAndRender(uri);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
close() {
|
|
92
|
+
if (this.mode !== 'popover') return;
|
|
93
|
+
this._open = false;
|
|
94
|
+
this._updateCardVisibility();
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
async loadAndRender(uri) {
|
|
98
|
+
this._renderLoading();
|
|
99
|
+
this._data = await resolveAuthority(uri, this.textContent.trim());
|
|
100
|
+
this._renderCardContent();
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
_updateCardVisibility() {
|
|
104
|
+
const card = this.shadowRoot.querySelector('[part="card"]');
|
|
105
|
+
if (!card) return;
|
|
106
|
+
card.hidden = !this._open;
|
|
107
|
+
if (this._open) {
|
|
108
|
+
const rect = this.getBoundingClientRect();
|
|
109
|
+
const cardWidth = 336;
|
|
110
|
+
if (rect.left + cardWidth > window.innerWidth - 16) {
|
|
111
|
+
card.style.left = 'auto';
|
|
112
|
+
card.style.right = '0';
|
|
113
|
+
} else {
|
|
114
|
+
card.style.left = '0';
|
|
115
|
+
card.style.right = 'auto';
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
_esc(str) {
|
|
121
|
+
return String(str ?? '')
|
|
122
|
+
.replace(/&/g, '&')
|
|
123
|
+
.replace(/</g, '<')
|
|
124
|
+
.replace(/>/g, '>')
|
|
125
|
+
.replace(/"/g, '"');
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
_renderLoading() {
|
|
129
|
+
const card = this.shadowRoot.querySelector('[part="card"]');
|
|
130
|
+
if (card) {
|
|
131
|
+
card.innerHTML = `<div part="loading" class="loading">Resolving authority record…</div>`;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
_renderCardContent() {
|
|
136
|
+
const card = this.shadowRoot.querySelector('[part="card"]');
|
|
137
|
+
if (!card || !this._data) return;
|
|
138
|
+
|
|
139
|
+
const customRenderer = this.template || globalTemplate;
|
|
140
|
+
if (typeof customRenderer === 'function') {
|
|
141
|
+
card.innerHTML = customRenderer(this._data, this._esc.bind(this));
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
const d = this._data;
|
|
146
|
+
const uriToCopy = d?.uri || this.getAttribute('uri') || '';
|
|
147
|
+
|
|
148
|
+
card.innerHTML = `
|
|
149
|
+
<div part="header" class="header">
|
|
150
|
+
<span part="badge" class="badge" style="background:${this._esc(d.badgeColor)}">${this._esc(d.source)}</span>
|
|
151
|
+
<a part="external-link" class="ext" href="${this._esc(uriToCopy)}" target="_blank" rel="noopener">Open ↗</a>
|
|
152
|
+
</div>
|
|
153
|
+
<div part="body" class="body">
|
|
154
|
+
${d.thumb ? `<img part="thumb" class="thumb" src="${this._esc(d.thumb)}" alt="">` : ''}
|
|
155
|
+
<div>
|
|
156
|
+
<div part="title" class="title">${this._esc(d.label)}</div>
|
|
157
|
+
${d.subtitle ? `<div part="subtitle" class="subtitle">${this._esc(d.subtitle)}</div>` : ''}
|
|
158
|
+
</div>
|
|
159
|
+
</div>
|
|
160
|
+
${d.scopeNote ? `<p part="note" class="note">${this._esc(d.scopeNote)}</p>` : ''}
|
|
161
|
+
${
|
|
162
|
+
d.meta?.length
|
|
163
|
+
? `<div part="meta" class="meta">${d.meta
|
|
164
|
+
.map((m) => `<div><span>${this._esc(m.label)}</span><strong>${this._esc(m.value)}</strong></div>`)
|
|
165
|
+
.join('')}</div>`
|
|
166
|
+
: ''
|
|
167
|
+
}
|
|
168
|
+
${d.aliases?.length ? `<div part="aliases" class="aliases">Also: ${d.aliases.map((a) => this._esc(a)).join(' · ')}</div>` : ''}
|
|
169
|
+
<div part="footer" class="footer">
|
|
170
|
+
<code part="uri" class="uri">${this._esc(uriToCopy)}</code>
|
|
171
|
+
<button part="copy-button" type="button" class="copy" data-uri="${this._esc(uriToCopy)}">Copy</button>
|
|
172
|
+
</div>
|
|
173
|
+
`;
|
|
174
|
+
|
|
175
|
+
const copyBtn = card.querySelector('.copy');
|
|
176
|
+
copyBtn?.addEventListener('click', async (e) => {
|
|
177
|
+
e.preventDefault();
|
|
178
|
+
e.stopPropagation();
|
|
179
|
+
const targetUri = e.currentTarget.getAttribute('data-uri') || uriToCopy;
|
|
180
|
+
if (!targetUri) return;
|
|
181
|
+
const copied = await copyTextToClipboard(targetUri);
|
|
182
|
+
if (copied) {
|
|
183
|
+
copyBtn.textContent = 'Copied';
|
|
184
|
+
setTimeout(() => {
|
|
185
|
+
copyBtn.textContent = 'Copy';
|
|
186
|
+
}, 1200);
|
|
187
|
+
}
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
renderShell() {
|
|
192
|
+
const uri = this.getAttribute('uri') || '#';
|
|
193
|
+
const isPanel = this.mode === 'panel';
|
|
194
|
+
|
|
195
|
+
this.shadowRoot.innerHTML = `
|
|
196
|
+
<style>
|
|
197
|
+
:host {
|
|
198
|
+
--ac-bg: #ffffff;
|
|
199
|
+
--ac-fg: #18181b;
|
|
200
|
+
--ac-muted: #71717a;
|
|
201
|
+
--ac-border: #e4e4e7;
|
|
202
|
+
--ac-surface: rgba(127, 127, 127, 0.08);
|
|
203
|
+
--ac-radius: 0.5rem;
|
|
204
|
+
--ac-shadow: 0 12px 28px -4px rgba(0, 0, 0, 0.14);
|
|
205
|
+
--ac-width: 336px;
|
|
206
|
+
--ac-font: system-ui, -apple-system, sans-serif;
|
|
207
|
+
|
|
208
|
+
position: relative;
|
|
209
|
+
display: ${isPanel ? 'block' : 'inline-block'};
|
|
210
|
+
font-family: var(--ac-font);
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
@media (prefers-color-scheme: dark) {
|
|
214
|
+
:host(:not([theme="light"])) {
|
|
215
|
+
--ac-bg: #18181b;
|
|
216
|
+
--ac-fg: #f4f4f5;
|
|
217
|
+
--ac-muted: #a1a1aa;
|
|
218
|
+
--ac-border: #27272a;
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
:host([theme="dark"]) {
|
|
223
|
+
--ac-bg: #18181b;
|
|
224
|
+
--ac-fg: #f4f4f5;
|
|
225
|
+
--ac-muted: #a1a1aa;
|
|
226
|
+
--ac-border: #27272a;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
.trigger {
|
|
230
|
+
color: inherit;
|
|
231
|
+
text-decoration: underline;
|
|
232
|
+
text-decoration-style: dotted;
|
|
233
|
+
text-underline-offset: 3px;
|
|
234
|
+
cursor: pointer;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
.card {
|
|
238
|
+
box-sizing: border-box;
|
|
239
|
+
background: var(--ac-bg);
|
|
240
|
+
color: var(--ac-fg);
|
|
241
|
+
border: 1px solid var(--ac-border);
|
|
242
|
+
border-radius: var(--ac-radius);
|
|
243
|
+
padding: 12px;
|
|
244
|
+
font-size: 13px;
|
|
245
|
+
line-height: 1.45;
|
|
246
|
+
${
|
|
247
|
+
isPanel
|
|
248
|
+
? 'width: 100%;'
|
|
249
|
+
: 'position: absolute; top: calc(100% + 6px); left: 0; z-index: 1000; width: var(--ac-width); box-shadow: var(--ac-shadow);'
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
.header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
|
|
254
|
+
.badge { color: #fff; font-size: 10px; font-weight: 700; padding: 2px 6px; border-radius: 4px; letter-spacing: 0.04em; text-transform: uppercase; }
|
|
255
|
+
.ext { font-size: 11px; color: var(--ac-muted); text-decoration: none; }
|
|
256
|
+
.ext:hover { text-decoration: underline; }
|
|
257
|
+
.body { display: flex; gap: 10px; align-items: flex-start; }
|
|
258
|
+
.thumb { width: 52px; height: 52px; object-fit: cover; border-radius: 4px; flex-shrink: 0; }
|
|
259
|
+
.title { font-weight: 600; font-size: 15px; line-height: 1.25; }
|
|
260
|
+
.subtitle { font-size: 12px; color: var(--ac-muted); margin-top: 2px; }
|
|
261
|
+
.note { margin: 8px 0; font-size: 12.5px; }
|
|
262
|
+
.meta { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 6px; margin: 8px 0; padding: 6px 8px; background: var(--ac-surface); border-radius: 4px; font-size: 11px; }
|
|
263
|
+
.meta span { display: block; color: var(--ac-muted); }
|
|
264
|
+
.aliases { font-size: 11px; color: var(--ac-muted); margin-bottom: 8px; }
|
|
265
|
+
.footer { display: flex; justify-content: space-between; align-items: center; gap: 8px; border-top: 1px solid var(--ac-border); padding-top: 8px; margin-top: 8px; }
|
|
266
|
+
.uri { font-size: 10px; color: var(--ac-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
267
|
+
.copy { font-size: 11px; padding: 2px 8px; border-radius: 4px; border: 1px solid var(--ac-border); background: transparent; color: inherit; cursor: pointer; }
|
|
268
|
+
.copy:hover { background: var(--ac-surface); }
|
|
269
|
+
.loading { color: var(--ac-muted); font-size: 12px; }
|
|
270
|
+
</style>
|
|
271
|
+
${isPanel ? '' : `<a part="trigger" class="trigger" href="${this._esc(uri)}" target="_blank" rel="noopener"><slot></slot></a>`}
|
|
272
|
+
<div part="card" class="card" ${isPanel ? '' : 'role="tooltip" hidden'}>
|
|
273
|
+
${isPanel ? '<div class="loading">Select an entity to inspect its authority record.</div>' : ''}
|
|
274
|
+
</div>
|
|
275
|
+
`;
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
if (!customElements.get('authority-card')) {
|
|
280
|
+
customElements.define('authority-card', AuthorityCard);
|
|
281
|
+
}
|
package/src/tailwind.js
ADDED
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import { resolveAuthority, emitSelect, copyTextToClipboard } from './core.js';
|
|
2
|
+
|
|
3
|
+
export class AuthorityCardTailwind extends HTMLElement {
|
|
4
|
+
static classes = {
|
|
5
|
+
trigger:
|
|
6
|
+
'underline decoration-dotted underline-offset-4 text-sky-700 dark:text-sky-400 hover:text-sky-900 dark:hover:text-sky-300 cursor-pointer font-medium',
|
|
7
|
+
popover:
|
|
8
|
+
'absolute left-0 top-full mt-1.5 z-50 w-80 rounded-lg border border-zinc-200 dark:border-zinc-800 bg-white dark:bg-zinc-900 p-3.5 text-left text-sm text-zinc-900 dark:text-zinc-100 shadow-xl',
|
|
9
|
+
panel:
|
|
10
|
+
'w-full rounded-lg border border-zinc-200 dark:border-zinc-800 bg-white dark:bg-zinc-900 p-4 text-left text-sm text-zinc-900 dark:text-zinc-100',
|
|
11
|
+
badge:
|
|
12
|
+
'inline-flex items-center rounded px-1.5 py-0.5 text-[10px] font-bold uppercase tracking-wider text-white',
|
|
13
|
+
title: 'text-base font-semibold leading-snug text-zinc-900 dark:text-zinc-50',
|
|
14
|
+
subtitle: 'text-xs text-zinc-500 dark:text-zinc-400',
|
|
15
|
+
note: 'mt-2 text-xs leading-relaxed text-zinc-700 dark:text-zinc-300',
|
|
16
|
+
metaBox:
|
|
17
|
+
'mt-2.5 grid grid-cols-2 gap-2 rounded bg-zinc-100 dark:bg-zinc-800/70 p-2 text-xs',
|
|
18
|
+
footer:
|
|
19
|
+
'mt-3 flex items-center justify-between gap-2 border-t border-zinc-200 dark:border-zinc-800 pt-2',
|
|
20
|
+
copyBtn:
|
|
21
|
+
'shrink-0 rounded border border-zinc-300 dark:border-zinc-700 px-2 py-0.5 text-[11px] font-medium hover:bg-zinc-100 dark:hover:bg-zinc-800 transition-colors',
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
constructor() {
|
|
25
|
+
super();
|
|
26
|
+
this._open = false;
|
|
27
|
+
this._data = null;
|
|
28
|
+
this._initialized = false;
|
|
29
|
+
this._onExternalSelect = this._onExternalSelect.bind(this);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
connectedCallback() {
|
|
33
|
+
if (this._initialized) return;
|
|
34
|
+
this._initialized = true;
|
|
35
|
+
|
|
36
|
+
const uri = this.getAttribute('uri') || '#';
|
|
37
|
+
const isPanel = this.getAttribute('mode') === 'panel';
|
|
38
|
+
const labelHtml = this.innerHTML;
|
|
39
|
+
const c = AuthorityCardTailwind.classes;
|
|
40
|
+
|
|
41
|
+
const triggerClasses = `${c.trigger} ${this.getAttribute('trigger-class') || ''}`.trim();
|
|
42
|
+
const cardClasses = `${isPanel ? c.panel : c.popover} ${this.getAttribute('card-class') || ''}`.trim();
|
|
43
|
+
|
|
44
|
+
this.classList.add(isPanel ? 'block' : 'relative', isPanel ? 'w-full' : 'inline-block');
|
|
45
|
+
|
|
46
|
+
this.innerHTML = isPanel
|
|
47
|
+
? `<div data-ac-card class="${cardClasses}"><p class="text-xs text-zinc-500">Select an entity to inspect…</p></div>`
|
|
48
|
+
: `<a data-ac-trigger href="${this._esc(uri)}" target="_blank" rel="noopener" class="${triggerClasses}">${labelHtml}</a>
|
|
49
|
+
<div data-ac-card role="tooltip" hidden class="${cardClasses}"></div>`;
|
|
50
|
+
|
|
51
|
+
const listenEvent = this.getAttribute('listen');
|
|
52
|
+
if (listenEvent) {
|
|
53
|
+
window.addEventListener(listenEvent, this._onExternalSelect);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
if (isPanel) {
|
|
57
|
+
if (this.getAttribute('uri')) this.load(this.getAttribute('uri'));
|
|
58
|
+
} else {
|
|
59
|
+
const trigger = this.querySelector('[data-ac-trigger]');
|
|
60
|
+
trigger.addEventListener('mouseenter', () => this.open());
|
|
61
|
+
trigger.addEventListener('focus', () => this.open());
|
|
62
|
+
trigger.addEventListener('click', (e) => {
|
|
63
|
+
emitSelect(this, this.getAttribute('uri'), this._data);
|
|
64
|
+
if (this.hasAttribute('prevent-navigation')) e.preventDefault();
|
|
65
|
+
});
|
|
66
|
+
this.addEventListener('mouseleave', () => this.close());
|
|
67
|
+
this.addEventListener('keydown', (e) => {
|
|
68
|
+
if (e.key === 'Escape') this.close();
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
disconnectedCallback() {
|
|
74
|
+
const listenEvent = this.getAttribute('listen');
|
|
75
|
+
if (listenEvent) {
|
|
76
|
+
window.removeEventListener(listenEvent, this._onExternalSelect);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
_onExternalSelect(e) {
|
|
81
|
+
if (e.detail?.uri) {
|
|
82
|
+
this.setAttribute('uri', e.detail.uri);
|
|
83
|
+
this.load(e.detail.uri);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
async open() {
|
|
88
|
+
this._open = true;
|
|
89
|
+
const card = this.querySelector('[data-ac-card]');
|
|
90
|
+
if (card) card.hidden = false;
|
|
91
|
+
if (!this._data && this.getAttribute('uri')) {
|
|
92
|
+
await this.load(this.getAttribute('uri'));
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
close() {
|
|
97
|
+
this._open = false;
|
|
98
|
+
const card = this.querySelector('[data-ac-card]');
|
|
99
|
+
if (card) card.hidden = true;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
async load(uri) {
|
|
103
|
+
const card = this.querySelector('[data-ac-card]');
|
|
104
|
+
if (!card) return;
|
|
105
|
+
card.innerHTML = `<div class="text-xs text-zinc-500 animate-pulse">Resolving authority record…</div>`;
|
|
106
|
+
|
|
107
|
+
const fallback = this.querySelector('[data-ac-trigger]')?.textContent?.trim() || '';
|
|
108
|
+
this._data = await resolveAuthority(uri, fallback);
|
|
109
|
+
this._renderData(card, this._data);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
_renderData(card, d) {
|
|
113
|
+
const c = AuthorityCardTailwind.classes;
|
|
114
|
+
const uriToCopy = d?.uri || this.getAttribute('uri') || '';
|
|
115
|
+
|
|
116
|
+
card.innerHTML = `
|
|
117
|
+
<div class="flex items-center justify-between mb-2">
|
|
118
|
+
<span class="${c.badge}" style="background:${this._esc(d.badgeColor)}">${this._esc(d.source)}</span>
|
|
119
|
+
<a href="${this._esc(uriToCopy)}" target="_blank" rel="noopener" class="text-xs text-zinc-500 hover:text-zinc-800 dark:hover:text-zinc-200">Open ↗</a>
|
|
120
|
+
</div>
|
|
121
|
+
<div class="flex items-start gap-3">
|
|
122
|
+
${d.thumb ? `<img src="${this._esc(d.thumb)}" alt="" class="h-12 w-12 shrink-0 rounded object-cover border border-zinc-200 dark:border-zinc-700">` : ''}
|
|
123
|
+
<div class="min-w-0">
|
|
124
|
+
<div class="${c.title}">${this._esc(d.label)}</div>
|
|
125
|
+
${d.subtitle ? `<div class="${c.subtitle}">${this._esc(d.subtitle)}</div>` : ''}
|
|
126
|
+
</div>
|
|
127
|
+
</div>
|
|
128
|
+
${d.scopeNote ? `<p class="${c.note}">${this._esc(d.scopeNote)}</p>` : ''}
|
|
129
|
+
${
|
|
130
|
+
d.meta?.length
|
|
131
|
+
? `<div class="${c.metaBox}">${d.meta
|
|
132
|
+
.map(
|
|
133
|
+
(m) =>
|
|
134
|
+
`<div><span class="block text-[10px] uppercase tracking-wide text-zinc-500">${this._esc(m.label)}</span><strong class="font-medium">${this._esc(m.value)}</strong></div>`
|
|
135
|
+
)
|
|
136
|
+
.join('')}</div>`
|
|
137
|
+
: ''
|
|
138
|
+
}
|
|
139
|
+
${d.aliases?.length ? `<div class="mt-2 text-[11px] text-zinc-500">Also: ${d.aliases.map((a) => this._esc(a)).join(' · ')}</div>` : ''}
|
|
140
|
+
<div class="${c.footer}">
|
|
141
|
+
<code class="truncate text-[10px] text-zinc-500">${this._esc(uriToCopy)}</code>
|
|
142
|
+
<button type="button" data-ac-copy data-uri="${this._esc(uriToCopy)}" class="${c.copyBtn}">Copy</button>
|
|
143
|
+
</div>
|
|
144
|
+
`;
|
|
145
|
+
|
|
146
|
+
const copyBtn = card.querySelector('[data-ac-copy]');
|
|
147
|
+
copyBtn?.addEventListener('click', async (e) => {
|
|
148
|
+
e.preventDefault();
|
|
149
|
+
e.stopPropagation();
|
|
150
|
+
const targetUri = e.currentTarget.getAttribute('data-uri') || uriToCopy;
|
|
151
|
+
if (!targetUri) return;
|
|
152
|
+
const copied = await copyTextToClipboard(targetUri);
|
|
153
|
+
if (copied) {
|
|
154
|
+
const prev = copyBtn.textContent;
|
|
155
|
+
copyBtn.textContent = 'Copied';
|
|
156
|
+
setTimeout(() => {
|
|
157
|
+
copyBtn.textContent = prev;
|
|
158
|
+
}, 1200);
|
|
159
|
+
}
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
_esc(str) {
|
|
164
|
+
return String(str ?? '')
|
|
165
|
+
.replace(/&/g, '&')
|
|
166
|
+
.replace(/</g, '<')
|
|
167
|
+
.replace(/>/g, '>')
|
|
168
|
+
.replace(/"/g, '"');
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
if (!customElements.get('authority-card-tw')) {
|
|
173
|
+
customElements.define('authority-card-tw', AuthorityCardTailwind);
|
|
174
|
+
}
|