@mintplayer/web-components 1.0.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.
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Root of the Bootstrap card family.
3
+ *
4
+ * Light-DOM rendering: this element does NOT use shadow DOM. Bootstrap's
5
+ * `_card.scss` relies on parent-child selectors (`.card > .card-header`,
6
+ * `.card > .list-group + .card-footer`) which cannot pierce shadow roots, so
7
+ * the entire `mp-card*` family stays in light DOM. The compiled card slice
8
+ * is injected into `document.head` exactly once on the first connection of
9
+ * any `<mp-card>` instance.
10
+ *
11
+ * Attributes:
12
+ * - `color` — one of the Bootstrap colour names; maps to `text-bg-<name>`.
13
+ * - `outline` — boolean (presence = true); flips to `border border-<name>`
14
+ * plus a transparent background, instead of the filled variant.
15
+ */
16
+ export declare class MpCardElement extends HTMLElement {
17
+ static get observedAttributes(): string[];
18
+ connectedCallback(): void;
19
+ attributeChangedCallback(name: string, _old: string | null, _next: string | null): void;
20
+ private applyColor;
21
+ }
22
+ /**
23
+ * Inject the compiled Bootstrap-card SCSS into `document.head` exactly once
24
+ * per page. Called from `MpCardElement.connectedCallback()` and also exported
25
+ * for the Angular wrapper (`BsCardComponent`) which doesn't instantiate
26
+ * `<mp-card>` itself but needs the same global cascade.
27
+ */
28
+ export declare function ensureCardStylesInjected(): void;
29
+ declare global {
30
+ interface HTMLElementTagNameMap {
31
+ 'mp-card': MpCardElement;
32
+ }
33
+ }
@@ -0,0 +1,2 @@
1
+ export declare const template: import('lit-html').TemplateResult<1>;
2
+ export declare const styles: import('lit').CSSResult;
@@ -0,0 +1 @@
1
+ export type CardHeaderNavStyle = 'tabs' | 'pills';
@@ -0,0 +1 @@
1
+ export type CardImagePosition = 'top' | 'bottom' | 'overlay';
@@ -0,0 +1,218 @@
1
+ import { LitElement as g, css as m, html as u } from "lit";
2
+ import { property as p, state as h } from "lit/decorators.js";
3
+ import { unsafeHTML as b } from "lit/directives/unsafe-html.js";
4
+ import n from "highlight.js/lib/common";
5
+ var f = Object.defineProperty, a = (r, t, e, s) => {
6
+ for (var o = void 0, l = r.length - 1, d; l >= 0; l--)
7
+ (d = r[l]) && (o = d(t, e, o) || o);
8
+ return o && f(t, e, o), o;
9
+ };
10
+ const c = "mp-code-snippet";
11
+ class i extends g {
12
+ constructor() {
13
+ super(...arguments), this.language = "", this.code = "", this.detectedLanguage = "code", this.highlighted = "", this.toastVisible = !1, this.toastTimer = null;
14
+ }
15
+ static {
16
+ this.styles = m`
17
+ /* Verbatim port of highlight.js's a11y-dark.css — the same theme
18
+ the master branch's ngx-highlightjs setup loads for the Angular
19
+ demo. That theme has only a dark variant; the code-snippet
20
+ intentionally renders dark-on-light-page like in an IDE, so the
21
+ host's own background is fixed (no Bootstrap data-bs-theme
22
+ branch). Tokens not explicitly mapped (e.g. .hljs-attr inside
23
+ .hljs-tag) inherit from their parent, matching production. */
24
+ :host {
25
+ display: block;
26
+ position: relative;
27
+ font-family: var(--bs-font-monospace);
28
+ background: #2b2b2b;
29
+ color: #f8f8f2;
30
+ border: 1px solid var(--bs-border-color);
31
+ border-radius: var(--bs-border-radius);
32
+ overflow: hidden;
33
+ }
34
+
35
+ pre {
36
+ margin: 0;
37
+ padding: 1rem 1rem 1rem 1rem;
38
+ overflow-x: auto;
39
+ white-space: pre;
40
+ tab-size: 2;
41
+ }
42
+
43
+ code {
44
+ display: block;
45
+ font-family: inherit;
46
+ font-size: 0.875rem;
47
+ line-height: 1.5;
48
+ color: inherit;
49
+ }
50
+
51
+ .copy {
52
+ position: absolute;
53
+ top: 0.5rem;
54
+ right: 0.5rem;
55
+ padding: 0.25rem 0.75rem;
56
+ font-size: 0.75rem;
57
+ color: var(--bs-body-color);
58
+ background: var(--bs-body-bg);
59
+ border: 1px solid var(--bs-border-color);
60
+ border-radius: var(--bs-border-radius-sm);
61
+ cursor: pointer;
62
+ opacity: 0.85;
63
+ transition: opacity 120ms ease;
64
+ }
65
+
66
+ .copy:hover,
67
+ .copy:focus-visible {
68
+ opacity: 1;
69
+ }
70
+
71
+ .toast {
72
+ position: absolute;
73
+ bottom: 0.5rem;
74
+ right: 0.5rem;
75
+ padding: 0.25rem 0.75rem;
76
+ font-size: 0.75rem;
77
+ color: var(--bs-body-bg);
78
+ background: var(--bs-success);
79
+ border-radius: var(--bs-border-radius-sm);
80
+ opacity: 0;
81
+ transform: translateY(0.5rem);
82
+ transition: opacity 150ms ease, transform 150ms ease;
83
+ pointer-events: none;
84
+ }
85
+
86
+ .toast.visible {
87
+ opacity: 1;
88
+ transform: translateY(0);
89
+ }
90
+
91
+ .sr-only {
92
+ position: absolute;
93
+ width: 1px;
94
+ height: 1px;
95
+ padding: 0;
96
+ margin: -1px;
97
+ overflow: hidden;
98
+ clip: rect(0, 0, 0, 0);
99
+ white-space: nowrap;
100
+ border: 0;
101
+ }
102
+
103
+ /* Default slot is hidden; content is hoisted into the <code> on each render. */
104
+ slot { display: none; }
105
+
106
+ /* a11y-dark token → colour mapping. Selectors + colours are a 1:1
107
+ port of highlight.js's a11y-dark.css. Tokens not listed here
108
+ (.hljs-attr, .hljs-property, .hljs-operator, .hljs-doctag, etc.)
109
+ intentionally inherit from their nearest mapped ancestor — that's
110
+ the canonical behaviour and matches the master branch's rendering. */
111
+ /* Comment */
112
+ .hljs-comment, .hljs-quote { color: #d4d0ab; }
113
+ /* Red */
114
+ .hljs-variable, .hljs-template-variable, .hljs-tag, .hljs-name,
115
+ .hljs-selector-id, .hljs-selector-class, .hljs-regexp,
116
+ .hljs-deletion { color: #ffa07a; }
117
+ /* Orange */
118
+ .hljs-number, .hljs-built_in, .hljs-literal, .hljs-type,
119
+ .hljs-params, .hljs-meta, .hljs-link { color: #f5ab35; }
120
+ /* Yellow */
121
+ .hljs-attribute { color: #ffd700; }
122
+ /* Green */
123
+ .hljs-string, .hljs-symbol, .hljs-bullet,
124
+ .hljs-addition { color: #abe338; }
125
+ /* Blue */
126
+ .hljs-title, .hljs-section { color: #00e0e0; }
127
+ /* Purple */
128
+ .hljs-keyword, .hljs-selector-tag { color: #dcc6e0; }
129
+ .hljs-emphasis { font-style: italic; }
130
+ .hljs-strong { font-weight: bold; }
131
+ `;
132
+ }
133
+ connectedCallback() {
134
+ super.connectedCallback();
135
+ }
136
+ disconnectedCallback() {
137
+ super.disconnectedCallback(), this.toastTimer !== null && (clearTimeout(this.toastTimer), this.toastTimer = null);
138
+ }
139
+ willUpdate(t) {
140
+ (t.has("code") || t.has("language")) && this.runHighlight();
141
+ }
142
+ runHighlight() {
143
+ const t = this.code ?? "";
144
+ if (!t) {
145
+ this.highlighted = "", this.detectedLanguage = "code";
146
+ return;
147
+ }
148
+ let e;
149
+ if (this.language)
150
+ try {
151
+ e = n.highlight(t, { language: this.language, ignoreIllegals: !0 });
152
+ } catch {
153
+ e = n.highlightAuto(t);
154
+ }
155
+ else
156
+ e = n.highlightAuto(t);
157
+ this.highlighted = e.value;
158
+ const s = e.language ?? "code";
159
+ s !== this.detectedLanguage && (this.detectedLanguage = s, this.dispatchEvent(
160
+ new CustomEvent("language-detected", {
161
+ detail: { language: s },
162
+ bubbles: !0,
163
+ composed: !0
164
+ })
165
+ ));
166
+ }
167
+ async handleCopy() {
168
+ try {
169
+ await navigator.clipboard.writeText(this.code ?? ""), this.showToast();
170
+ } catch (t) {
171
+ console.warn("[mp-code-snippet] clipboard write failed", t);
172
+ }
173
+ }
174
+ showToast() {
175
+ this.toastVisible = !0, this.toastTimer !== null && clearTimeout(this.toastTimer), this.toastTimer = setTimeout(() => {
176
+ this.toastVisible = !1, this.toastTimer = null;
177
+ }, 3e3);
178
+ }
179
+ render() {
180
+ return u`
181
+ <slot @slotchange=${this.onSlotChange}></slot>
182
+ <button
183
+ type="button"
184
+ class="copy"
185
+ part="copy-button"
186
+ @click=${this.handleCopy}
187
+ aria-label="Copy ${this.detectedLanguage} code to clipboard"
188
+ >Copy ${this.detectedLanguage}</button>
189
+ <pre part="pre"><code part="code" class="hljs">${b(this.highlighted)}</code></pre>
190
+ <div class="toast ${this.toastVisible ? "visible" : ""}" part="toast" aria-hidden="${!this.toastVisible}">Copied!</div>
191
+ <div class="sr-only" role="status" aria-live="polite">${this.toastVisible ? "Copied to clipboard" : ""}</div>
192
+ `;
193
+ }
194
+ onSlotChange(t) {
195
+ if (this.code) return;
196
+ const s = t.target.assignedNodes({ flatten: !0 }).map((o) => o.textContent ?? "").join("").trim();
197
+ s && (this.code = s);
198
+ }
199
+ }
200
+ a([
201
+ p({ type: String })
202
+ ], i.prototype, "language");
203
+ a([
204
+ p({ type: String })
205
+ ], i.prototype, "code");
206
+ a([
207
+ h()
208
+ ], i.prototype, "detectedLanguage");
209
+ a([
210
+ h()
211
+ ], i.prototype, "highlighted");
212
+ a([
213
+ h()
214
+ ], i.prototype, "toastVisible");
215
+ typeof customElements < "u" && !customElements.get(c) && customElements.define(c, i);
216
+ export {
217
+ i as MpCodeSnippet
218
+ };
@@ -0,0 +1 @@
1
+ export * from './mp-code-snippet.element';
@@ -0,0 +1,47 @@
1
+ import { LitElement, TemplateResult, PropertyValues } from 'lit';
2
+ /**
3
+ * `<mp-code-snippet>` — code block with syntax highlighting + copy-to-clipboard.
4
+ *
5
+ * Replaces the Angular-only `bs-code-snippet`. All three demo apps
6
+ * (Angular / React / Vue) render their per-page source snippets through
7
+ * this WC for visual consistency.
8
+ *
9
+ * Attributes / properties:
10
+ * - `language` (optional): force a specific highlight.js language. If
11
+ * omitted, the highlighter auto-detects.
12
+ * - `code` (property): the source to render. Setting via attribute also
13
+ * works but the property form is preferred for multi-line content.
14
+ *
15
+ * Events:
16
+ * - `language-detected` — fires after each highlight pass with
17
+ * `detail.language` containing the resolved language id (e.g. `"typescript"`).
18
+ *
19
+ * a11y: the copy button announces success via an `aria-live="polite"`
20
+ * region inside the shadow root.
21
+ *
22
+ * Source content can ALSO be projected via the default slot — useful for
23
+ * static HTML pages where attribute serialization of newlines is awkward.
24
+ * Slot content is read once on first render and on `slotchange`.
25
+ */
26
+ export declare class MpCodeSnippet extends LitElement {
27
+ static styles: import('lit').CSSResult;
28
+ language: string;
29
+ code: string;
30
+ private detectedLanguage;
31
+ private highlighted;
32
+ private toastVisible;
33
+ private toastTimer;
34
+ connectedCallback(): void;
35
+ disconnectedCallback(): void;
36
+ willUpdate(changed: PropertyValues<this>): void;
37
+ private runHighlight;
38
+ private handleCopy;
39
+ private showToast;
40
+ render(): TemplateResult;
41
+ private onSlotChange;
42
+ }
43
+ declare global {
44
+ interface HTMLElementTagNameMap {
45
+ 'mp-code-snippet': MpCodeSnippet;
46
+ }
47
+ }