@ktbsh/ui 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/README.md +165 -0
- package/dist/custom-elements.json +1427 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.js +12 -0
- package/dist/react/alert.d.ts +20 -0
- package/dist/react/alert.js +30 -0
- package/dist/react/badge.d.ts +17 -0
- package/dist/react/badge.js +30 -0
- package/dist/react/box.d.ts +22 -0
- package/dist/react/box.js +30 -0
- package/dist/react/breadcrumb.d.ts +17 -0
- package/dist/react/breadcrumb.js +30 -0
- package/dist/react/button.d.ts +20 -0
- package/dist/react/button.js +30 -0
- package/dist/react/checkbox.d.ts +22 -0
- package/dist/react/checkbox.js +30 -0
- package/dist/react/container.d.ts +18 -0
- package/dist/react/container.js +30 -0
- package/dist/react/field.d.ts +20 -0
- package/dist/react/field.js +30 -0
- package/dist/react/heading.d.ts +19 -0
- package/dist/react/heading.js +30 -0
- package/dist/react/input.d.ts +25 -0
- package/dist/react/input.js +30 -0
- package/dist/react/label.d.ts +18 -0
- package/dist/react/label.js +30 -0
- package/dist/react/link.d.ts +21 -0
- package/dist/react/link.js +30 -0
- package/dist/react/modal.d.ts +18 -0
- package/dist/react/modal.js +30 -0
- package/dist/react/nav.d.ts +17 -0
- package/dist/react/nav.js +30 -0
- package/dist/react/pagination.d.ts +19 -0
- package/dist/react/pagination.js +30 -0
- package/dist/react/progress.d.ts +19 -0
- package/dist/react/progress.js +30 -0
- package/dist/react/radio.d.ts +22 -0
- package/dist/react/radio.js +30 -0
- package/dist/react/select.d.ts +22 -0
- package/dist/react/select.js +30 -0
- package/dist/react/skeleton.d.ts +19 -0
- package/dist/react/skeleton.js +30 -0
- package/dist/react/spinner.d.ts +18 -0
- package/dist/react/spinner.js +30 -0
- package/dist/react/stack.d.ts +21 -0
- package/dist/react/stack.js +30 -0
- package/dist/react/switch.d.ts +21 -0
- package/dist/react/switch.js +30 -0
- package/dist/react/tab-panel.d.ts +18 -0
- package/dist/react/tab-panel.js +30 -0
- package/dist/react/tab.d.ts +19 -0
- package/dist/react/tab.js +30 -0
- package/dist/react/tabs.d.ts +17 -0
- package/dist/react/tabs.js +30 -0
- package/dist/react/text.d.ts +19 -0
- package/dist/react/text.js +30 -0
- package/dist/react/textarea.d.ts +24 -0
- package/dist/react/textarea.js +30 -0
- package/dist/react/toast.d.ts +19 -0
- package/dist/react/toast.js +30 -0
- package/dist/themes/dark.css +52 -0
- package/dist/themes/light.css +53 -0
- package/dist/tokens/index.d.ts +7 -0
- package/dist/tokens/index.js +7 -0
- package/dist/tokens/semantic.d.ts +209 -0
- package/dist/tokens/semantic.js +102 -0
- package/dist/types/index.d.ts +15 -0
- package/dist/types/index.js +2 -0
- package/dist/vanilla/alert.d.ts +2 -0
- package/dist/vanilla/alert.js +134 -0
- package/dist/vanilla/alert.src.js +257 -0
- package/dist/vanilla/badge.d.ts +2 -0
- package/dist/vanilla/badge.js +89 -0
- package/dist/vanilla/badge.src.js +212 -0
- package/dist/vanilla/box.d.ts +2 -0
- package/dist/vanilla/box.js +100 -0
- package/dist/vanilla/box.src.js +270 -0
- package/dist/vanilla/breadcrumb.d.ts +2 -0
- package/dist/vanilla/breadcrumb.js +93 -0
- package/dist/vanilla/breadcrumb.src.js +255 -0
- package/dist/vanilla/button.d.ts +2 -0
- package/dist/vanilla/button.js +135 -0
- package/dist/vanilla/button.src.js +260 -0
- package/dist/vanilla/checkbox.d.ts +2 -0
- package/dist/vanilla/checkbox.js +96 -0
- package/dist/vanilla/checkbox.src.js +296 -0
- package/dist/vanilla/container.d.ts +2 -0
- package/dist/vanilla/container.js +79 -0
- package/dist/vanilla/container.src.js +222 -0
- package/dist/vanilla/field.d.ts +2 -0
- package/dist/vanilla/field.js +113 -0
- package/dist/vanilla/field.src.js +278 -0
- package/dist/vanilla/heading.d.ts +2 -0
- package/dist/vanilla/heading.js +75 -0
- package/dist/vanilla/heading.src.js +241 -0
- package/dist/vanilla/input.d.ts +2 -0
- package/dist/vanilla/input.js +121 -0
- package/dist/vanilla/input.src.js +326 -0
- package/dist/vanilla/label.d.ts +2 -0
- package/dist/vanilla/label.js +75 -0
- package/dist/vanilla/label.src.js +232 -0
- package/dist/vanilla/link.d.ts +2 -0
- package/dist/vanilla/link.js +96 -0
- package/dist/vanilla/link.src.js +272 -0
- package/dist/vanilla/modal.d.ts +2 -0
- package/dist/vanilla/modal.js +125 -0
- package/dist/vanilla/modal.src.js +251 -0
- package/dist/vanilla/nav.d.ts +2 -0
- package/dist/vanilla/nav.js +94 -0
- package/dist/vanilla/nav.src.js +214 -0
- package/dist/vanilla/pagination.d.ts +2 -0
- package/dist/vanilla/pagination.js +114 -0
- package/dist/vanilla/pagination.src.js +262 -0
- package/dist/vanilla/progress.d.ts +2 -0
- package/dist/vanilla/progress.js +108 -0
- package/dist/vanilla/progress.src.js +244 -0
- package/dist/vanilla/radio.d.ts +2 -0
- package/dist/vanilla/radio.js +104 -0
- package/dist/vanilla/radio.src.js +326 -0
- package/dist/vanilla/select.d.ts +2 -0
- package/dist/vanilla/select.js +104 -0
- package/dist/vanilla/select.src.js +332 -0
- package/dist/vanilla/skeleton.d.ts +2 -0
- package/dist/vanilla/skeleton.js +99 -0
- package/dist/vanilla/skeleton.src.js +240 -0
- package/dist/vanilla/spinner.d.ts +2 -0
- package/dist/vanilla/spinner.js +108 -0
- package/dist/vanilla/spinner.src.js +222 -0
- package/dist/vanilla/stack.d.ts +2 -0
- package/dist/vanilla/stack.js +83 -0
- package/dist/vanilla/stack.src.js +259 -0
- package/dist/vanilla/switch.d.ts +2 -0
- package/dist/vanilla/switch.js +166 -0
- package/dist/vanilla/switch.src.js +299 -0
- package/dist/vanilla/tab-panel.d.ts +2 -0
- package/dist/vanilla/tab-panel.js +80 -0
- package/dist/vanilla/tab-panel.src.js +227 -0
- package/dist/vanilla/tab.d.ts +2 -0
- package/dist/vanilla/tab.js +99 -0
- package/dist/vanilla/tab.src.js +253 -0
- package/dist/vanilla/tabs.d.ts +2 -0
- package/dist/vanilla/tabs.js +66 -0
- package/dist/vanilla/tabs.src.js +237 -0
- package/dist/vanilla/text.d.ts +2 -0
- package/dist/vanilla/text.js +74 -0
- package/dist/vanilla/text.src.js +232 -0
- package/dist/vanilla/textarea.d.ts +2 -0
- package/dist/vanilla/textarea.js +97 -0
- package/dist/vanilla/textarea.src.js +316 -0
- package/dist/vanilla/toast.d.ts +2 -0
- package/dist/vanilla/toast.js +120 -0
- package/dist/vanilla/toast.src.js +245 -0
- package/package.json +111 -0
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
|
|
2
|
+
import { render, html } from 'uhtml';
|
|
3
|
+
|
|
4
|
+
const sheet = new CSSStyleSheet();
|
|
5
|
+
sheet.replaceSync(":host {\n--kb-color-bg-canvas: #ffffff;\n--kb-color-bg-surface: #f6f8fa;\n--kb-color-bg-subtle: #eef1f4;\n--kb-color-bg-inverse: #1f2328;\n--kb-color-fg-default: #1f2328;\n--kb-color-fg-muted: #656d76;\n--kb-color-fg-subtle: #8c959f;\n--kb-color-fg-on-accent: #ffffff;\n--kb-color-fg-on-inverse: #ffffff;\n--kb-color-border-default: #d0d7de;\n--kb-color-border-muted: #e6ebf0;\n--kb-color-border-focus: #0969da;\n--kb-color-accent-default: #0969da;\n--kb-color-accent-hover: #0860ca;\n--kb-color-accent-subtle: #ddf4ff;\n--kb-color-danger-default: #cf222e;\n--kb-color-danger-subtle: #ffebe9;\n--kb-color-success-default: #1a7f37;\n--kb-color-success-subtle: #dafbe1;\n--kb-color-warning-default: #9a6700;\n--kb-color-warning-subtle: #fff8c5;\n--kb-space-2xs: 2px;\n--kb-space-xs: 4px;\n--kb-space-sm: 8px;\n--kb-space-md: 16px;\n--kb-space-lg: 24px;\n--kb-space-xl: 32px;\n--kb-space-2xl: 48px;\n--kb-radius-sm: 4px;\n--kb-radius-md: 8px;\n--kb-radius-lg: 12px;\n--kb-radius-full: 9999px;\n--kb-font-family-sans: ui-sans-serif, system-ui, -apple-system, \"Segoe UI\", Roboto, \"Helvetica Neue\", Arial, sans-serif;\n--kb-font-size-sm: 0.875rem;\n--kb-font-size-md: 1rem;\n--kb-font-size-lg: 1.125rem;\n--kb-font-size-xl: 1.25rem;\n--kb-font-weight-regular: 400;\n--kb-font-weight-medium: 500;\n--kb-font-weight-semibold: 600;\n--kb-line-height-tight: 1.25;\n--kb-line-height-normal: 1.5;\n--kb-shadow-sm: 0 1px 2px rgba(31, 35, 40, 0.08);\n--kb-shadow-md: 0 4px 12px rgba(31, 35, 40, 0.1);\n--kb-focus-ring: 0 0 0 3px rgba(9, 105, 218, 0.35);\n}\n\n\n :host {\n display: inline-flex;\n font-family: var(--kb-font-family-sans);\n }\n span {\n display: inline-flex;\n align-items: center;\n max-width: 100%;\n padding: var(--kb-space-2xs) var(--kb-space-sm);\n border-radius: var(--kb-radius-full);\n font-size: var(--kb-font-size-sm);\n font-weight: var(--kb-font-weight-medium);\n line-height: var(--kb-line-height-tight);\n white-space: nowrap;\n }\n .neutral {\n background: var(--kb-color-bg-subtle);\n color: var(--kb-color-fg-default);\n }\n .accent {\n background: var(--kb-color-accent-subtle);\n color: var(--kb-color-accent-default);\n }\n .success {\n background: var(--kb-color-success-subtle);\n color: var(--kb-color-success-default);\n }\n .warning {\n background: var(--kb-color-warning-subtle);\n color: var(--kb-color-warning-default);\n }\n .danger {\n background: var(--kb-color-danger-subtle);\n color: var(--kb-color-danger-default);\n }\n ");
|
|
6
|
+
|
|
7
|
+
export class KitbashBadge extends HTMLElement {
|
|
8
|
+
|
|
9
|
+
static get observedAttributes() {
|
|
10
|
+
return ["tone"];
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
static get propTypes() {
|
|
14
|
+
return {"tone":"String"};
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
get tone() {
|
|
19
|
+
return this._props['tone'];
|
|
20
|
+
}
|
|
21
|
+
set tone(val) {
|
|
22
|
+
// External / framework property writes: re-render, do not emit kitbash-change
|
|
23
|
+
// (caller already knows the value they set).
|
|
24
|
+
this._assignProp('tone', val);
|
|
25
|
+
this.update();
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
constructor() {
|
|
30
|
+
super();
|
|
31
|
+
this.attachShadow({ mode: 'open', delegatesFocus: false });
|
|
32
|
+
|
|
33
|
+
this.shadowRoot.adoptedStyleSheets = [sheet];
|
|
34
|
+
|
|
35
|
+
this._defaults = {"tone":"neutral"};
|
|
36
|
+
|
|
37
|
+
this._state = {};
|
|
38
|
+
this._props = { ...this._defaults };
|
|
39
|
+
this._eventHandlers = {};
|
|
40
|
+
this._eventCleanup = [];
|
|
41
|
+
this._renderFn = function({ props, html }) {
|
|
42
|
+
const tone = props.tone === "accent" || props.tone === "success" || props.tone === "warning" || props.tone === "danger" ? props.tone : "neutral";
|
|
43
|
+
return html`
|
|
44
|
+
<span part="badge-root" class=${tone}>
|
|
45
|
+
<slot></slot>
|
|
46
|
+
</span>
|
|
47
|
+
`;
|
|
48
|
+
};
|
|
49
|
+
this._reflecting = false;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
connectedCallback() {
|
|
53
|
+
// Initial attribute values are parsed by attributeChangedCallback before connectedCallback fires
|
|
54
|
+
this.update();
|
|
55
|
+
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
disconnectedCallback() {
|
|
59
|
+
this.cleanupEvents();
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
attributeChangedCallback(name, oldValue, newValue) {
|
|
63
|
+
// Skip when we caused the attribute write ourselves (avoids double update)
|
|
64
|
+
if (this._reflecting) return;
|
|
65
|
+
if (oldValue === newValue) return;
|
|
66
|
+
|
|
67
|
+
const type = this.constructor.propTypes[name];
|
|
68
|
+
|
|
69
|
+
let parsedValue = newValue;
|
|
70
|
+
if (newValue === null || newValue === undefined) {
|
|
71
|
+
parsedValue = this._defaults[name];
|
|
72
|
+
} else if (type === 'Number' && newValue !== '') {
|
|
73
|
+
// Match property coercion: empty string is not Number('') → 0
|
|
74
|
+
parsedValue = Number(newValue);
|
|
75
|
+
} else if (type === 'Boolean') {
|
|
76
|
+
parsedValue = newValue !== null && newValue !== 'false';
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
this._props[name] = parsedValue;
|
|
80
|
+
|
|
81
|
+
this.update();
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** Coerce + reflect a single prop; no re-render (caller decides). */
|
|
85
|
+
_assignProp(key, val) {
|
|
86
|
+
const type = this.constructor.propTypes[key];
|
|
87
|
+
let next = val;
|
|
88
|
+
if (type === 'Boolean') {
|
|
89
|
+
next = val === true || val === '';
|
|
90
|
+
} else if (type === 'Number' && val !== null && val !== undefined && val !== '') {
|
|
91
|
+
next = Number(val);
|
|
92
|
+
}
|
|
93
|
+
this._props[key] = next;
|
|
94
|
+
|
|
95
|
+
// Only reflect primitives — objects/arrays stay as properties (no [object Object] attrs)
|
|
96
|
+
const isPrimitive =
|
|
97
|
+
next === null ||
|
|
98
|
+
next === undefined ||
|
|
99
|
+
typeof next === 'string' ||
|
|
100
|
+
typeof next === 'number' ||
|
|
101
|
+
typeof next === 'boolean';
|
|
102
|
+
|
|
103
|
+
this._reflecting = true;
|
|
104
|
+
try {
|
|
105
|
+
if (type === 'Boolean') {
|
|
106
|
+
if (next) this.setAttribute(key, '');
|
|
107
|
+
else this.removeAttribute(key);
|
|
108
|
+
} else if (!isPrimitive) {
|
|
109
|
+
// property-only; drop stale attribute if any
|
|
110
|
+
this.removeAttribute(key);
|
|
111
|
+
} else if (next === null || next === undefined) {
|
|
112
|
+
this.removeAttribute(key);
|
|
113
|
+
} else {
|
|
114
|
+
this.setAttribute(key, String(next));
|
|
115
|
+
}
|
|
116
|
+
} finally {
|
|
117
|
+
this._reflecting = false;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
_emitChange() {
|
|
123
|
+
// Shallow-copy both bags so listeners cannot mutate internal state/props via event.detail
|
|
124
|
+
this.dispatchEvent(new CustomEvent('kitbash-change', {
|
|
125
|
+
detail: {
|
|
126
|
+
state: { ...this._state },
|
|
127
|
+
props: { ...this._props },
|
|
128
|
+
},
|
|
129
|
+
bubbles: true,
|
|
130
|
+
composed: true
|
|
131
|
+
}));
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Batch props and/or state: one uhtml update, one kitbash-change.
|
|
136
|
+
* Prefer this in event handlers (e.g. controlled inputs).
|
|
137
|
+
*/
|
|
138
|
+
commit(patch) {
|
|
139
|
+
const p = patch || {};
|
|
140
|
+
if (p.props) {
|
|
141
|
+
const allowed = this.constructor.propTypes || {};
|
|
142
|
+
for (const key of Object.keys(p.props)) {
|
|
143
|
+
// Only declared props — ignore typos / stray keys
|
|
144
|
+
if (!Object.prototype.hasOwnProperty.call(allowed, key)) continue;
|
|
145
|
+
this._assignProp(key, p.props[key]);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
if (p.state) {
|
|
149
|
+
this._state = { ...this._state, ...p.state };
|
|
150
|
+
}
|
|
151
|
+
this.update();
|
|
152
|
+
this._emitChange();
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
setState(newState) {
|
|
156
|
+
this.commit({ state: newState });
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
setProps(nextProps) {
|
|
160
|
+
this.commit({ props: nextProps });
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
_handlerCtx() {
|
|
164
|
+
// Snapshots so handlers/render cannot mutate internal bags by accident
|
|
165
|
+
return {
|
|
166
|
+
props: { ...this._props },
|
|
167
|
+
state: { ...this._state },
|
|
168
|
+
setState: this.setState.bind(this),
|
|
169
|
+
setProps: this.setProps.bind(this),
|
|
170
|
+
commit: this.commit.bind(this),
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
cleanupEvents() {
|
|
175
|
+
this._eventCleanup.forEach(cleanup => cleanup());
|
|
176
|
+
this._eventCleanup = [];
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
update() {
|
|
180
|
+
// Run the uhtml DOM diffing render cycle
|
|
181
|
+
render(this.shadowRoot, this._renderFn({
|
|
182
|
+
...this._handlerCtx(),
|
|
183
|
+
html
|
|
184
|
+
}));
|
|
185
|
+
this.cleanupEvents();
|
|
186
|
+
this.bindEvents();
|
|
187
|
+
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
bindEvents() {
|
|
193
|
+
Object.keys(this._eventHandlers).forEach(eventSelector => {
|
|
194
|
+
const parts = eventSelector.split(' ');
|
|
195
|
+
const eventName = parts[0];
|
|
196
|
+
const selector = parts.slice(1).join(' ');
|
|
197
|
+
|
|
198
|
+
const targets = selector ? this.shadowRoot.querySelectorAll(selector) : [this];
|
|
199
|
+
targets.forEach(target => {
|
|
200
|
+
const handler = (e) => {
|
|
201
|
+
this._eventHandlers[eventSelector](e, this._handlerCtx());
|
|
202
|
+
};
|
|
203
|
+
target.addEventListener(eventName, handler);
|
|
204
|
+
this._eventCleanup.push(() => target.removeEventListener(eventName, handler));
|
|
205
|
+
});
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
if (!customElements.get('kitbash-badge')) {
|
|
211
|
+
customElements.define('kitbash-badge', KitbashBadge);
|
|
212
|
+
}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
var p=(_,U,Y,z,J)=>{let W=Y.length,O=U.length,I=W,Q=0,B=0,$=null;while(Q<O||B<I)if(O===Q){let X=I<W?B?z(Y[B-1],-0).nextSibling:z(Y[I],0):J;while(B<I)_.insertBefore(z(Y[B++],1),X)}else if(I===B)while(Q<O){if(!$||!$.has(U[Q]))_.removeChild(z(U[Q],-1));Q++}else if(U[Q]===Y[B])Q++,B++;else if(U[O-1]===Y[I-1])O--,I--;else if(U[Q]===Y[I-1]&&Y[B]===U[O-1]){let X=z(U[--O],-0).nextSibling;_.insertBefore(z(Y[B++],1),z(U[Q++],-0).nextSibling),_.insertBefore(z(Y[--I],1),X),U[O]=Y[I]}else{if(!$){$=new Map;let X=B;while(X<I)$.set(Y[X],X++)}if($.has(U[Q])){let X=$.get(U[Q]);if(B<X&&X<I){let Z=Q,K=1;while(++Z<O&&Z<I&&$.get(U[Z])===X+K)K++;if(K>X-B){let D=z(U[Q],0);while(B<X)_.insertBefore(z(Y[B++],1),D)}else _.replaceChild(z(Y[B++],1),z(U[Q++],-1))}else Q++}else _.removeChild(z(U[Q++],-1))}return Y};var{isArray:E}=Array,{getPrototypeOf:R1,getOwnPropertyDescriptor:D1}=Object;var m="http://www.w3.org/2000/svg",q=[],N=()=>document.createRange(),M=(_,U,Y)=>{return _.set(U,Y),Y},i=(_,U)=>{let Y;do Y=D1(_,U);while(!Y&&(_=R1(_)));return Y},o=(_,U)=>U.reduceRight(M1,_),M1=(_,U)=>_.childNodes[U];var s=1;var r=8;var l=11;var{setPrototypeOf:T1}=Object,n=(_)=>{function U(Y){return T1(Y,new.target.prototype)}return U.prototype=_.prototype,U};var T,V=(_,U,Y)=>{if(!T)T=N();if(Y)T.setStartAfter(_);else T.setStartBefore(_);return T.setEndAfter(U),T.deleteContents(),_};var w=({firstChild:_,lastChild:U},Y)=>V(_,U,Y),t=!1,j=(_,U)=>t&&_.nodeType===l?1/U<0?U?w(_,!0):_.lastChild:U?_.valueOf():_.firstChild:_,a=(_)=>document.createComment(_);class x extends n(DocumentFragment){#U=a("<>");#Y=a("</>");#_=q;constructor(_){super(_);this.replaceChildren(...[this.#U,..._.childNodes,this.#Y]),t=!0}get firstChild(){return this.#U}get lastChild(){return this.#Y}get parentNode(){return this.#U.parentNode}remove(){w(this,!1)}replaceWith(_){w(this,!0).replaceWith(_)}valueOf(){let{parentNode:_}=this;if(_===this){if(this.#_===q)this.#_=[...this.childNodes]}else{if(_){let{firstChild:U,lastChild:Y}=this;this.#_=[U];while(U!==Y)this.#_.push(U=U.nextSibling)}this.replaceChildren(...this.#_)}return this}}var e=(_,U,Y)=>_.setAttribute(U,Y),P=(_,U)=>_.removeAttribute(U),H1=(_,U)=>{for(let Y in U){let z=U[Y],J=Y==="role"?Y:`aria-${Y}`;if(z==null)P(_,J);else e(_,J,z)}return U},C,P1=(_,U,Y)=>{if(Y=Y.slice(1),!C)C=new WeakMap;let z=C.get(_)||M(C,_,{}),J=z[Y];if(J&&J[0])_.removeEventListener(Y,...J);if(J=E(U)?U:[U,!1],z[Y]=J,J[0])_.addEventListener(Y,...J);return U};var G=(_,U)=>{let{t:Y,n:z}=_,J=!1;switch(typeof U){case"object":if(U!==null){(z||Y).replaceWith(_.n=U.valueOf());break}case"undefined":J=!0;default:if(Y.data=J?"":U,z)_.n=null,z.replaceWith(Y);break}return U},F1=(_,U)=>f(_,U,U==null?"class":"className"),A1=(_,U)=>{let{dataset:Y}=_;for(let z in U)if(U[z]==null)delete Y[z];else Y[z]=U[z];return U},k=(_,U,Y)=>_[Y]=U,E1=(_,U,Y)=>k(_,U,Y.slice(1)),f=(_,U,Y)=>U==null?(P(_,Y),U):k(_,U,Y),_1=(_,U)=>(typeof U==="function"?U(_):U.current=_,U),y=(_,U,Y)=>(U==null?P(_,Y):e(_,Y,U),U),N1=(_,U)=>U==null?f(_,U,"style"):k(_.style,U,"cssText"),V1=(_,U,Y)=>(_.toggleAttribute(Y.slice(1),U),U),R=(_,U,Y)=>{let{length:z}=U;if(_.data=`[${z}]`,z)return p(_.parentNode,Y,U,j,_);switch(Y.length){case 1:Y[0].remove();case 0:break;default:V(j(Y[0],0),j(Y.at(-1),-0),!1);break}return q},U1=new Map([["aria",H1],["class",F1],["data",A1],["ref",_1],["style",N1]]),Y1=(_,U,Y)=>{switch(U[0]){case".":return E1;case"?":return V1;case"@":return P1;default:return Y||"ownerSVGElement"in _?U==="ref"?_1:y:U1.get(U)||(U in _?U.startsWith("on")?k:i(_,U)?.set?f:y:y)}},z1=(_,U)=>(_.textContent=U==null?"":U,U);var H=(_,U,Y)=>({a:_,b:U,c:Y}),I1=(_,U)=>({b:_,c:U}),J1=(_,U,Y,z)=>({v:q,u:_,t:U,n:Y,c:z}),L=()=>H(null,null,q);var b=(_)=>(U,Y)=>{let{a:z,b:J,c:W}=_(U,Y),O=document.importNode(z,!0),I=q;if(J!==q){I=[];for(let Q,B,$=0;$<J.length;$++){let{a:X,b:Z,c:K}=J[$],D=X===B?Q:Q=o(O,B=X);I[$]=J1(Z,D,K,Z===R?[]:Z===G?L():null)}}return I1(W?O.firstChild:new x(O),I)};var O1=/^(?:plaintext|script|style|textarea|title|xmp)$/i,Q1=/^(?:area|base|br|col|embed|hr|img|input|keygen|link|menuitem|meta|param|source|track|wbr)$/i;var j1=/<([a-zA-Z0-9]+[a-zA-Z0-9:._-]*)([^>]*?)(\/?)>/g,C1=/([^\s\\>"'=]+)\s*=\s*(['"]?)\x01/g,k1=/[\x01\x02]/g,W1=(_,U,Y)=>{let z=0;return _.join("\x01").trim().replace(j1,(J,W,O,I)=>`<${W}${O.replace(C1,"\x02=$2$1").trimEnd()}${I?Y||Q1.test(W)?" /":`></${W}`:""}>`).replace(k1,(J)=>J==="\x01"?`<!--${U+z++}-->`:U+z++)};var S=document.createElement("template"),g,h,X1=(_,U)=>{if(U){if(!g)g=document.createElementNS(m,"svg"),h=N(),h.selectNodeContents(g);return h.createContextualFragment(_)}S.innerHTML=_;let{content:Y}=S;return S=S.cloneNode(!1),Y};var c=(_)=>{let U=[],Y;while(Y=_.parentNode)U.push(U.indexOf.call(Y.childNodes,_)),_=Y;return U},$1=()=>document.createTextNode(""),S1=(_,U,Y)=>{let z=X1(W1(_,F,Y),Y),{length:J}=_,W=q;if(J>1){let Q=[],B=document.createTreeWalker(z,129),$=0,X=`${F}${$++}`;W=[];while($<J){let Z=B.nextNode();if(Z.nodeType===r){if(Z.data===X){let K=E(U[$-1])?R:G;if(K===G)Q.push(Z);W.push(H(c(Z),K,null)),X=`${F}${$++}`}}else{let K;while(Z.hasAttribute(X)){if(!K)K=c(Z);let D=Z.getAttribute(X);W.push(H(K,Y1(Z,D,Y),D)),P(Z,X),X=`${F}${$++}`}if(!Y&&O1.test(Z.localName)&&Z.textContent.trim()===`<!--${X}-->`)W.push(H(K||c(Z),z1,null)),X=`${F}${$++}`}}for($=0;$<Q.length;$++)Q[$].replaceWith($1())}let{childNodes:O}=z,{length:I}=O;if(I<1)I=1,z.appendChild($1());else if(I===1&&J!==1&&O[0].nodeType!==s)I=0;return M(B1,_,H(z,W,I===1))},B1=new WeakMap,F="isµ",v=(_)=>(U,Y)=>B1.get(U)||S1(U,Y,_);var w1=b(v(!1)),x1=b(v(!0)),u=(_,{s:U,t:Y,v:z})=>{if(_.a!==Y){let{b:J,c:W}=(U?x1:w1)(Y,z);_.a=Y,_.b=J,_.c=W}for(let{c:J}=_,W=0;W<J.length;W++){let O=z[W],I=J[W];switch(I.u){case R:I.v=R(I.t,y1(I.c,O),I.v);break;case G:let Q=O instanceof A?u(I.c||(I.c=L()),O):(I.c=null,O);if(Q!==I.v)I.v=G(I,Q);break;default:if(O!==I.v)I.v=I.u(I.t,O,I.n,I.v);break}}return _.b},y1=(_,U)=>{let Y=0,{length:z}=U;if(z<_.length)_.splice(z);for(;Y<z;Y++){let J=U[Y];if(J instanceof A)U[Y]=u(_[Y]||(_[Y]=L()),J);else _[Y]=null}return U};class A{constructor(_,U,Y){this.s=_,this.t=U,this.v=Y}toDOM(_=L()){return u(_,this)}}var Z1=new WeakMap,d=(_,U)=>{let Y=Z1.get(_)||M(Z1,_,L()),{b:z}=Y;if(z!==(typeof U==="function"?U():U).toDOM(Y))_.replaceChildren(Y.b.valueOf());return _};/*! (c) Andrea Giammarchi - MIT */var K1=(_)=>(U,...Y)=>new A(_,U,Y),q1=K1(!1),C_=K1(!0);var G1=new CSSStyleSheet;G1.replaceSync(`:host {
|
|
2
|
+
--kb-color-bg-canvas: #ffffff;
|
|
3
|
+
--kb-color-bg-surface: #f6f8fa;
|
|
4
|
+
--kb-color-bg-subtle: #eef1f4;
|
|
5
|
+
--kb-color-bg-inverse: #1f2328;
|
|
6
|
+
--kb-color-fg-default: #1f2328;
|
|
7
|
+
--kb-color-fg-muted: #656d76;
|
|
8
|
+
--kb-color-fg-subtle: #8c959f;
|
|
9
|
+
--kb-color-fg-on-accent: #ffffff;
|
|
10
|
+
--kb-color-fg-on-inverse: #ffffff;
|
|
11
|
+
--kb-color-border-default: #d0d7de;
|
|
12
|
+
--kb-color-border-muted: #e6ebf0;
|
|
13
|
+
--kb-color-border-focus: #0969da;
|
|
14
|
+
--kb-color-accent-default: #0969da;
|
|
15
|
+
--kb-color-accent-hover: #0860ca;
|
|
16
|
+
--kb-color-accent-subtle: #ddf4ff;
|
|
17
|
+
--kb-color-danger-default: #cf222e;
|
|
18
|
+
--kb-color-danger-subtle: #ffebe9;
|
|
19
|
+
--kb-color-success-default: #1a7f37;
|
|
20
|
+
--kb-color-success-subtle: #dafbe1;
|
|
21
|
+
--kb-color-warning-default: #9a6700;
|
|
22
|
+
--kb-color-warning-subtle: #fff8c5;
|
|
23
|
+
--kb-space-2xs: 2px;
|
|
24
|
+
--kb-space-xs: 4px;
|
|
25
|
+
--kb-space-sm: 8px;
|
|
26
|
+
--kb-space-md: 16px;
|
|
27
|
+
--kb-space-lg: 24px;
|
|
28
|
+
--kb-space-xl: 32px;
|
|
29
|
+
--kb-space-2xl: 48px;
|
|
30
|
+
--kb-radius-sm: 4px;
|
|
31
|
+
--kb-radius-md: 8px;
|
|
32
|
+
--kb-radius-lg: 12px;
|
|
33
|
+
--kb-radius-full: 9999px;
|
|
34
|
+
--kb-font-family-sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
|
|
35
|
+
--kb-font-size-sm: 0.875rem;
|
|
36
|
+
--kb-font-size-md: 1rem;
|
|
37
|
+
--kb-font-size-lg: 1.125rem;
|
|
38
|
+
--kb-font-size-xl: 1.25rem;
|
|
39
|
+
--kb-font-weight-regular: 400;
|
|
40
|
+
--kb-font-weight-medium: 500;
|
|
41
|
+
--kb-font-weight-semibold: 600;
|
|
42
|
+
--kb-line-height-tight: 1.25;
|
|
43
|
+
--kb-line-height-normal: 1.5;
|
|
44
|
+
--kb-shadow-sm: 0 1px 2px rgba(31, 35, 40, 0.08);
|
|
45
|
+
--kb-shadow-md: 0 4px 12px rgba(31, 35, 40, 0.1);
|
|
46
|
+
--kb-focus-ring: 0 0 0 3px rgba(9, 105, 218, 0.35);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
:host {
|
|
51
|
+
display: block;
|
|
52
|
+
box-sizing: border-box;
|
|
53
|
+
font-family: var(--kb-font-family-sans);
|
|
54
|
+
color: var(--kb-color-fg-default);
|
|
55
|
+
}
|
|
56
|
+
.root {
|
|
57
|
+
box-sizing: border-box;
|
|
58
|
+
display: block;
|
|
59
|
+
width: 100%;
|
|
60
|
+
}
|
|
61
|
+
.p-none { padding: 0; }
|
|
62
|
+
.p-2xs { padding: var(--kb-space-2xs); }
|
|
63
|
+
.p-xs { padding: var(--kb-space-xs); }
|
|
64
|
+
.p-sm { padding: var(--kb-space-sm); }
|
|
65
|
+
.p-md { padding: var(--kb-space-md); }
|
|
66
|
+
.p-lg { padding: var(--kb-space-lg); }
|
|
67
|
+
.p-xl { padding: var(--kb-space-xl); }
|
|
68
|
+
.p-2xl { padding: var(--kb-space-2xl); }
|
|
69
|
+
.px-none { padding-left: 0; padding-right: 0; }
|
|
70
|
+
.px-2xs { padding-left: var(--kb-space-2xs); padding-right: var(--kb-space-2xs); }
|
|
71
|
+
.px-xs { padding-left: var(--kb-space-xs); padding-right: var(--kb-space-xs); }
|
|
72
|
+
.px-sm { padding-left: var(--kb-space-sm); padding-right: var(--kb-space-sm); }
|
|
73
|
+
.px-md { padding-left: var(--kb-space-md); padding-right: var(--kb-space-md); }
|
|
74
|
+
.px-lg { padding-left: var(--kb-space-lg); padding-right: var(--kb-space-lg); }
|
|
75
|
+
.px-xl { padding-left: var(--kb-space-xl); padding-right: var(--kb-space-xl); }
|
|
76
|
+
.px-2xl { padding-left: var(--kb-space-2xl); padding-right: var(--kb-space-2xl); }
|
|
77
|
+
.py-none { padding-top: 0; padding-bottom: 0; }
|
|
78
|
+
.py-2xs { padding-top: var(--kb-space-2xs); padding-bottom: var(--kb-space-2xs); }
|
|
79
|
+
.py-xs { padding-top: var(--kb-space-xs); padding-bottom: var(--kb-space-xs); }
|
|
80
|
+
.py-sm { padding-top: var(--kb-space-sm); padding-bottom: var(--kb-space-sm); }
|
|
81
|
+
.py-md { padding-top: var(--kb-space-md); padding-bottom: var(--kb-space-md); }
|
|
82
|
+
.py-lg { padding-top: var(--kb-space-lg); padding-bottom: var(--kb-space-lg); }
|
|
83
|
+
.py-xl { padding-top: var(--kb-space-xl); padding-bottom: var(--kb-space-xl); }
|
|
84
|
+
.py-2xl { padding-top: var(--kb-space-2xl); padding-bottom: var(--kb-space-2xl); }
|
|
85
|
+
.r-sm { border-radius: var(--kb-radius-sm); }
|
|
86
|
+
.r-md { border-radius: var(--kb-radius-md); }
|
|
87
|
+
.r-lg { border-radius: var(--kb-radius-lg); }
|
|
88
|
+
.r-full { border-radius: var(--kb-radius-full); }
|
|
89
|
+
.r-none { border-radius: 0; }
|
|
90
|
+
.border {
|
|
91
|
+
border: 1px solid var(--kb-color-border-default);
|
|
92
|
+
}
|
|
93
|
+
.surface {
|
|
94
|
+
background: var(--kb-color-bg-surface);
|
|
95
|
+
}
|
|
96
|
+
`);class L1 extends HTMLElement{static get observedAttributes(){return["padding","paddingX","paddingY","radius","border","surface"]}static get propTypes(){return{padding:"String",paddingX:"String",paddingY:"String",radius:"String",border:"Boolean",surface:"Boolean"}}get padding(){return this._props.padding}set padding(_){this._assignProp("padding",_),this.update()}get paddingX(){return this._props.paddingX}set paddingX(_){this._assignProp("paddingX",_),this.update()}get paddingY(){return this._props.paddingY}set paddingY(_){this._assignProp("paddingY",_),this.update()}get radius(){return this._props.radius}set radius(_){this._assignProp("radius",_),this.update()}get border(){return this._props.border}set border(_){this._assignProp("border",_),this.update()}get surface(){return this._props.surface}set surface(_){this._assignProp("surface",_),this.update()}constructor(){super();this.attachShadow({mode:"open",delegatesFocus:!1}),this.shadowRoot.adoptedStyleSheets=[G1],this._defaults={padding:"md",paddingX:"",paddingY:"",radius:"md",border:!1,surface:!1},this._state={},this._props={...this._defaults},this._eventHandlers={},this._eventCleanup=[],this._renderFn=function({props:_,html:U}){let Y=["none","2xs","xs","sm","md","lg","xl","2xl"],z=["none","sm","md","lg","full"],J=typeof _.padding==="string"&&Y.includes(_.padding)?_.padding:"md",W=typeof _.paddingX==="string"&&Y.includes(_.paddingX)?_.paddingX:"",O=typeof _.paddingY==="string"&&Y.includes(_.paddingY)?_.paddingY:"",I=typeof _.radius==="string"&&z.includes(_.radius)?_.radius:"md",Q=["root",`p-${J}`,W?`px-${W}`:"",O?`py-${O}`:"",`r-${I}`,_.border?"border":"",_.surface?"surface":""].filter(Boolean).join(" ");return U`
|
|
97
|
+
<div part="box-root" class=${Q}>
|
|
98
|
+
<slot></slot>
|
|
99
|
+
</div>
|
|
100
|
+
`},this._reflecting=!1}connectedCallback(){this.update()}disconnectedCallback(){this.cleanupEvents()}attributeChangedCallback(_,U,Y){if(this._reflecting)return;if(U===Y)return;let z=this.constructor.propTypes[_],J=Y;if(Y===null||Y===void 0)J=this._defaults[_];else if(z==="Number"&&Y!=="")J=Number(Y);else if(z==="Boolean")J=Y!==null&&Y!=="false";this._props[_]=J,this.update()}_assignProp(_,U){let Y=this.constructor.propTypes[_],z=U;if(Y==="Boolean")z=U===!0||U==="";else if(Y==="Number"&&U!==null&&U!==void 0&&U!=="")z=Number(U);this._props[_]=z;let J=z===null||z===void 0||typeof z==="string"||typeof z==="number"||typeof z==="boolean";this._reflecting=!0;try{if(Y==="Boolean")if(z)this.setAttribute(_,"");else this.removeAttribute(_);else if(!J)this.removeAttribute(_);else if(z===null||z===void 0)this.removeAttribute(_);else this.setAttribute(_,String(z))}finally{this._reflecting=!1}}_emitChange(){this.dispatchEvent(new CustomEvent("kitbash-change",{detail:{state:{...this._state},props:{...this._props}},bubbles:!0,composed:!0}))}commit(_){let U=_||{};if(U.props){let Y=this.constructor.propTypes||{};for(let z of Object.keys(U.props)){if(!Object.prototype.hasOwnProperty.call(Y,z))continue;this._assignProp(z,U.props[z])}}if(U.state)this._state={...this._state,...U.state};this.update(),this._emitChange()}setState(_){this.commit({state:_})}setProps(_){this.commit({props:_})}_handlerCtx(){return{props:{...this._props},state:{...this._state},setState:this.setState.bind(this),setProps:this.setProps.bind(this),commit:this.commit.bind(this)}}cleanupEvents(){this._eventCleanup.forEach((_)=>_()),this._eventCleanup=[]}update(){d(this.shadowRoot,this._renderFn({...this._handlerCtx(),html:q1})),this.cleanupEvents(),this.bindEvents()}bindEvents(){Object.keys(this._eventHandlers).forEach((_)=>{let U=_.split(" "),Y=U[0],z=U.slice(1).join(" ");(z?this.shadowRoot.querySelectorAll(z):[this]).forEach((W)=>{let O=(I)=>{this._eventHandlers[_](I,this._handlerCtx())};W.addEventListener(Y,O),this._eventCleanup.push(()=>W.removeEventListener(Y,O))})})}}if(!customElements.get("kitbash-box"))customElements.define("kitbash-box",L1);export{L1 as KitbashBox};
|
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
|
|
2
|
+
import { render, html } from 'uhtml';
|
|
3
|
+
|
|
4
|
+
const sheet = new CSSStyleSheet();
|
|
5
|
+
sheet.replaceSync(":host {\n--kb-color-bg-canvas: #ffffff;\n--kb-color-bg-surface: #f6f8fa;\n--kb-color-bg-subtle: #eef1f4;\n--kb-color-bg-inverse: #1f2328;\n--kb-color-fg-default: #1f2328;\n--kb-color-fg-muted: #656d76;\n--kb-color-fg-subtle: #8c959f;\n--kb-color-fg-on-accent: #ffffff;\n--kb-color-fg-on-inverse: #ffffff;\n--kb-color-border-default: #d0d7de;\n--kb-color-border-muted: #e6ebf0;\n--kb-color-border-focus: #0969da;\n--kb-color-accent-default: #0969da;\n--kb-color-accent-hover: #0860ca;\n--kb-color-accent-subtle: #ddf4ff;\n--kb-color-danger-default: #cf222e;\n--kb-color-danger-subtle: #ffebe9;\n--kb-color-success-default: #1a7f37;\n--kb-color-success-subtle: #dafbe1;\n--kb-color-warning-default: #9a6700;\n--kb-color-warning-subtle: #fff8c5;\n--kb-space-2xs: 2px;\n--kb-space-xs: 4px;\n--kb-space-sm: 8px;\n--kb-space-md: 16px;\n--kb-space-lg: 24px;\n--kb-space-xl: 32px;\n--kb-space-2xl: 48px;\n--kb-radius-sm: 4px;\n--kb-radius-md: 8px;\n--kb-radius-lg: 12px;\n--kb-radius-full: 9999px;\n--kb-font-family-sans: ui-sans-serif, system-ui, -apple-system, \"Segoe UI\", Roboto, \"Helvetica Neue\", Arial, sans-serif;\n--kb-font-size-sm: 0.875rem;\n--kb-font-size-md: 1rem;\n--kb-font-size-lg: 1.125rem;\n--kb-font-size-xl: 1.25rem;\n--kb-font-weight-regular: 400;\n--kb-font-weight-medium: 500;\n--kb-font-weight-semibold: 600;\n--kb-line-height-tight: 1.25;\n--kb-line-height-normal: 1.5;\n--kb-shadow-sm: 0 1px 2px rgba(31, 35, 40, 0.08);\n--kb-shadow-md: 0 4px 12px rgba(31, 35, 40, 0.1);\n--kb-focus-ring: 0 0 0 3px rgba(9, 105, 218, 0.35);\n}\n\n\n :host {\n display: block;\n box-sizing: border-box;\n font-family: var(--kb-font-family-sans);\n color: var(--kb-color-fg-default);\n }\n .root {\n box-sizing: border-box;\n display: block;\n width: 100%;\n }\n .p-none { padding: 0; }\n .p-2xs { padding: var(--kb-space-2xs); }\n .p-xs { padding: var(--kb-space-xs); }\n .p-sm { padding: var(--kb-space-sm); }\n .p-md { padding: var(--kb-space-md); }\n .p-lg { padding: var(--kb-space-lg); }\n .p-xl { padding: var(--kb-space-xl); }\n .p-2xl { padding: var(--kb-space-2xl); }\n .px-none { padding-left: 0; padding-right: 0; }\n .px-2xs { padding-left: var(--kb-space-2xs); padding-right: var(--kb-space-2xs); }\n .px-xs { padding-left: var(--kb-space-xs); padding-right: var(--kb-space-xs); }\n .px-sm { padding-left: var(--kb-space-sm); padding-right: var(--kb-space-sm); }\n .px-md { padding-left: var(--kb-space-md); padding-right: var(--kb-space-md); }\n .px-lg { padding-left: var(--kb-space-lg); padding-right: var(--kb-space-lg); }\n .px-xl { padding-left: var(--kb-space-xl); padding-right: var(--kb-space-xl); }\n .px-2xl { padding-left: var(--kb-space-2xl); padding-right: var(--kb-space-2xl); }\n .py-none { padding-top: 0; padding-bottom: 0; }\n .py-2xs { padding-top: var(--kb-space-2xs); padding-bottom: var(--kb-space-2xs); }\n .py-xs { padding-top: var(--kb-space-xs); padding-bottom: var(--kb-space-xs); }\n .py-sm { padding-top: var(--kb-space-sm); padding-bottom: var(--kb-space-sm); }\n .py-md { padding-top: var(--kb-space-md); padding-bottom: var(--kb-space-md); }\n .py-lg { padding-top: var(--kb-space-lg); padding-bottom: var(--kb-space-lg); }\n .py-xl { padding-top: var(--kb-space-xl); padding-bottom: var(--kb-space-xl); }\n .py-2xl { padding-top: var(--kb-space-2xl); padding-bottom: var(--kb-space-2xl); }\n .r-sm { border-radius: var(--kb-radius-sm); }\n .r-md { border-radius: var(--kb-radius-md); }\n .r-lg { border-radius: var(--kb-radius-lg); }\n .r-full { border-radius: var(--kb-radius-full); }\n .r-none { border-radius: 0; }\n .border {\n border: 1px solid var(--kb-color-border-default);\n }\n .surface {\n background: var(--kb-color-bg-surface);\n }\n ");
|
|
6
|
+
|
|
7
|
+
export class KitbashBox extends HTMLElement {
|
|
8
|
+
|
|
9
|
+
static get observedAttributes() {
|
|
10
|
+
return ["padding","paddingX","paddingY","radius","border","surface"];
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
static get propTypes() {
|
|
14
|
+
return {"padding":"String","paddingX":"String","paddingY":"String","radius":"String","border":"Boolean","surface":"Boolean"};
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
get padding() {
|
|
19
|
+
return this._props['padding'];
|
|
20
|
+
}
|
|
21
|
+
set padding(val) {
|
|
22
|
+
// External / framework property writes: re-render, do not emit kitbash-change
|
|
23
|
+
// (caller already knows the value they set).
|
|
24
|
+
this._assignProp('padding', val);
|
|
25
|
+
this.update();
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
get paddingX() {
|
|
29
|
+
return this._props['paddingX'];
|
|
30
|
+
}
|
|
31
|
+
set paddingX(val) {
|
|
32
|
+
// External / framework property writes: re-render, do not emit kitbash-change
|
|
33
|
+
// (caller already knows the value they set).
|
|
34
|
+
this._assignProp('paddingX', val);
|
|
35
|
+
this.update();
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
get paddingY() {
|
|
39
|
+
return this._props['paddingY'];
|
|
40
|
+
}
|
|
41
|
+
set paddingY(val) {
|
|
42
|
+
// External / framework property writes: re-render, do not emit kitbash-change
|
|
43
|
+
// (caller already knows the value they set).
|
|
44
|
+
this._assignProp('paddingY', val);
|
|
45
|
+
this.update();
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
get radius() {
|
|
49
|
+
return this._props['radius'];
|
|
50
|
+
}
|
|
51
|
+
set radius(val) {
|
|
52
|
+
// External / framework property writes: re-render, do not emit kitbash-change
|
|
53
|
+
// (caller already knows the value they set).
|
|
54
|
+
this._assignProp('radius', val);
|
|
55
|
+
this.update();
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
get border() {
|
|
59
|
+
return this._props['border'];
|
|
60
|
+
}
|
|
61
|
+
set border(val) {
|
|
62
|
+
// External / framework property writes: re-render, do not emit kitbash-change
|
|
63
|
+
// (caller already knows the value they set).
|
|
64
|
+
this._assignProp('border', val);
|
|
65
|
+
this.update();
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
get surface() {
|
|
69
|
+
return this._props['surface'];
|
|
70
|
+
}
|
|
71
|
+
set surface(val) {
|
|
72
|
+
// External / framework property writes: re-render, do not emit kitbash-change
|
|
73
|
+
// (caller already knows the value they set).
|
|
74
|
+
this._assignProp('surface', val);
|
|
75
|
+
this.update();
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
constructor() {
|
|
80
|
+
super();
|
|
81
|
+
this.attachShadow({ mode: 'open', delegatesFocus: false });
|
|
82
|
+
|
|
83
|
+
this.shadowRoot.adoptedStyleSheets = [sheet];
|
|
84
|
+
|
|
85
|
+
this._defaults = {"padding":"md","paddingX":"","paddingY":"","radius":"md","border":false,"surface":false};
|
|
86
|
+
|
|
87
|
+
this._state = {};
|
|
88
|
+
this._props = { ...this._defaults };
|
|
89
|
+
this._eventHandlers = {};
|
|
90
|
+
this._eventCleanup = [];
|
|
91
|
+
this._renderFn = function({ props, html }) {
|
|
92
|
+
const spaces = ["none", "2xs", "xs", "sm", "md", "lg", "xl", "2xl"], radii = ["none", "sm", "md", "lg", "full"], pad = typeof props.padding === "string" && spaces.includes(props.padding) ? props.padding : "md", px = typeof props.paddingX === "string" && spaces.includes(props.paddingX) ? props.paddingX : "", py = typeof props.paddingY === "string" && spaces.includes(props.paddingY) ? props.paddingY : "", radius = typeof props.radius === "string" && radii.includes(props.radius) ? props.radius : "md", classes = [
|
|
93
|
+
"root",
|
|
94
|
+
`p-${pad}`,
|
|
95
|
+
px ? `px-${px}` : "",
|
|
96
|
+
py ? `py-${py}` : "",
|
|
97
|
+
`r-${radius}`,
|
|
98
|
+
props.border ? "border" : "",
|
|
99
|
+
props.surface ? "surface" : ""
|
|
100
|
+
].filter(Boolean).join(" ");
|
|
101
|
+
return html`
|
|
102
|
+
<div part="box-root" class=${classes}>
|
|
103
|
+
<slot></slot>
|
|
104
|
+
</div>
|
|
105
|
+
`;
|
|
106
|
+
};
|
|
107
|
+
this._reflecting = false;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
connectedCallback() {
|
|
111
|
+
// Initial attribute values are parsed by attributeChangedCallback before connectedCallback fires
|
|
112
|
+
this.update();
|
|
113
|
+
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
disconnectedCallback() {
|
|
117
|
+
this.cleanupEvents();
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
attributeChangedCallback(name, oldValue, newValue) {
|
|
121
|
+
// Skip when we caused the attribute write ourselves (avoids double update)
|
|
122
|
+
if (this._reflecting) return;
|
|
123
|
+
if (oldValue === newValue) return;
|
|
124
|
+
|
|
125
|
+
const type = this.constructor.propTypes[name];
|
|
126
|
+
|
|
127
|
+
let parsedValue = newValue;
|
|
128
|
+
if (newValue === null || newValue === undefined) {
|
|
129
|
+
parsedValue = this._defaults[name];
|
|
130
|
+
} else if (type === 'Number' && newValue !== '') {
|
|
131
|
+
// Match property coercion: empty string is not Number('') → 0
|
|
132
|
+
parsedValue = Number(newValue);
|
|
133
|
+
} else if (type === 'Boolean') {
|
|
134
|
+
parsedValue = newValue !== null && newValue !== 'false';
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
this._props[name] = parsedValue;
|
|
138
|
+
|
|
139
|
+
this.update();
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/** Coerce + reflect a single prop; no re-render (caller decides). */
|
|
143
|
+
_assignProp(key, val) {
|
|
144
|
+
const type = this.constructor.propTypes[key];
|
|
145
|
+
let next = val;
|
|
146
|
+
if (type === 'Boolean') {
|
|
147
|
+
next = val === true || val === '';
|
|
148
|
+
} else if (type === 'Number' && val !== null && val !== undefined && val !== '') {
|
|
149
|
+
next = Number(val);
|
|
150
|
+
}
|
|
151
|
+
this._props[key] = next;
|
|
152
|
+
|
|
153
|
+
// Only reflect primitives — objects/arrays stay as properties (no [object Object] attrs)
|
|
154
|
+
const isPrimitive =
|
|
155
|
+
next === null ||
|
|
156
|
+
next === undefined ||
|
|
157
|
+
typeof next === 'string' ||
|
|
158
|
+
typeof next === 'number' ||
|
|
159
|
+
typeof next === 'boolean';
|
|
160
|
+
|
|
161
|
+
this._reflecting = true;
|
|
162
|
+
try {
|
|
163
|
+
if (type === 'Boolean') {
|
|
164
|
+
if (next) this.setAttribute(key, '');
|
|
165
|
+
else this.removeAttribute(key);
|
|
166
|
+
} else if (!isPrimitive) {
|
|
167
|
+
// property-only; drop stale attribute if any
|
|
168
|
+
this.removeAttribute(key);
|
|
169
|
+
} else if (next === null || next === undefined) {
|
|
170
|
+
this.removeAttribute(key);
|
|
171
|
+
} else {
|
|
172
|
+
this.setAttribute(key, String(next));
|
|
173
|
+
}
|
|
174
|
+
} finally {
|
|
175
|
+
this._reflecting = false;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
_emitChange() {
|
|
181
|
+
// Shallow-copy both bags so listeners cannot mutate internal state/props via event.detail
|
|
182
|
+
this.dispatchEvent(new CustomEvent('kitbash-change', {
|
|
183
|
+
detail: {
|
|
184
|
+
state: { ...this._state },
|
|
185
|
+
props: { ...this._props },
|
|
186
|
+
},
|
|
187
|
+
bubbles: true,
|
|
188
|
+
composed: true
|
|
189
|
+
}));
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* Batch props and/or state: one uhtml update, one kitbash-change.
|
|
194
|
+
* Prefer this in event handlers (e.g. controlled inputs).
|
|
195
|
+
*/
|
|
196
|
+
commit(patch) {
|
|
197
|
+
const p = patch || {};
|
|
198
|
+
if (p.props) {
|
|
199
|
+
const allowed = this.constructor.propTypes || {};
|
|
200
|
+
for (const key of Object.keys(p.props)) {
|
|
201
|
+
// Only declared props — ignore typos / stray keys
|
|
202
|
+
if (!Object.prototype.hasOwnProperty.call(allowed, key)) continue;
|
|
203
|
+
this._assignProp(key, p.props[key]);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
if (p.state) {
|
|
207
|
+
this._state = { ...this._state, ...p.state };
|
|
208
|
+
}
|
|
209
|
+
this.update();
|
|
210
|
+
this._emitChange();
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
setState(newState) {
|
|
214
|
+
this.commit({ state: newState });
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
setProps(nextProps) {
|
|
218
|
+
this.commit({ props: nextProps });
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
_handlerCtx() {
|
|
222
|
+
// Snapshots so handlers/render cannot mutate internal bags by accident
|
|
223
|
+
return {
|
|
224
|
+
props: { ...this._props },
|
|
225
|
+
state: { ...this._state },
|
|
226
|
+
setState: this.setState.bind(this),
|
|
227
|
+
setProps: this.setProps.bind(this),
|
|
228
|
+
commit: this.commit.bind(this),
|
|
229
|
+
};
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
cleanupEvents() {
|
|
233
|
+
this._eventCleanup.forEach(cleanup => cleanup());
|
|
234
|
+
this._eventCleanup = [];
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
update() {
|
|
238
|
+
// Run the uhtml DOM diffing render cycle
|
|
239
|
+
render(this.shadowRoot, this._renderFn({
|
|
240
|
+
...this._handlerCtx(),
|
|
241
|
+
html
|
|
242
|
+
}));
|
|
243
|
+
this.cleanupEvents();
|
|
244
|
+
this.bindEvents();
|
|
245
|
+
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
|
|
249
|
+
|
|
250
|
+
bindEvents() {
|
|
251
|
+
Object.keys(this._eventHandlers).forEach(eventSelector => {
|
|
252
|
+
const parts = eventSelector.split(' ');
|
|
253
|
+
const eventName = parts[0];
|
|
254
|
+
const selector = parts.slice(1).join(' ');
|
|
255
|
+
|
|
256
|
+
const targets = selector ? this.shadowRoot.querySelectorAll(selector) : [this];
|
|
257
|
+
targets.forEach(target => {
|
|
258
|
+
const handler = (e) => {
|
|
259
|
+
this._eventHandlers[eventSelector](e, this._handlerCtx());
|
|
260
|
+
};
|
|
261
|
+
target.addEventListener(eventName, handler);
|
|
262
|
+
this._eventCleanup.push(() => target.removeEventListener(eventName, handler));
|
|
263
|
+
});
|
|
264
|
+
});
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
if (!customElements.get('kitbash-box')) {
|
|
269
|
+
customElements.define('kitbash-box', KitbashBox);
|
|
270
|
+
}
|