@rozie-ui/dialog-angular 0.0.0-stage → 0.2.4

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/src/Dialog.ts ADDED
@@ -0,0 +1,414 @@
1
+ import { Component, ContentChild, DestroyRef, ElementRef, Renderer2, TemplateRef, ViewEncapsulation, afterRenderEffect, computed, contentChildren, effect, forwardRef, inject, input, output, signal, untracked, viewChild } from '@angular/core';
2
+ import { NgTemplateOutlet } from '@angular/common';
3
+ import { NG_VALUE_ACCESSOR } from '@angular/forms';
4
+ import { RozieSlot, createRozieAttrApplier, createRozieHostAttrsReader, rozieAttr as __rozieAttr, rozieDisplay as __rozieDisplay, rozieModel } from '@rozie/runtime-angular';
5
+
6
+ import { applyScrollLock as applySharedScrollLock } from './internal/scrollLock';
7
+
8
+ // ---- native reconcile ---------------------------------------------------
9
+ // The <dialog> element, cached by sync() so $onUnmount can reach it without
10
+ // reading $refs during teardown.
11
+
12
+ /** Why the dialog closed: a scrim click, the Escape key, or a programmatic `hide()`. */
13
+ export type DialogCloseReason = 'backdrop' | 'escape' | 'programmatic';
14
+ /** The `close` event payload. */
15
+ export interface DialogClosePayload {
16
+ reason: DialogCloseReason;
17
+ }
18
+
19
+ interface DefaultCtx {}
20
+
21
+ @Component({
22
+ selector: 'rozie-dialog',
23
+ standalone: true,
24
+ imports: [NgTemplateOutlet],
25
+ template: `
26
+
27
+ <dialog class="rozie-dialog" [attr.aria-label]="rozieAttr(ariaLabel())" [attr.aria-labelledby]="rozieAttr(ariaLabelledby())" #rozieSpread_0 (cancel)="onCancel($event)" (close)="onNativeClose()" (pointerdown)="onPointerDown($event)" (click)="onClick($event)" #rozieListenersTarget_1>
28
+
29
+ <div class="rozie-dialog-panel" #panelEl>
30
+ <ng-container *ngTemplateOutlet="(defaultTpl ?? __rozieFillMap()['defaultSlot'] ?? templates()?.['defaultSlot'])" />
31
+ </div>
32
+ </dialog>
33
+
34
+ `,
35
+ styles: [`
36
+ :host(rozie-dialog) { display: contents; }
37
+ @media (prefers-reduced-motion: no-preference) {
38
+ .rozie-dialog {
39
+ transition: opacity var(--rozie-dialog-transition, var(--rdg-transition, 0.15s ease)), transform var(--rozie-dialog-transition, var(--rdg-transition, 0.15s ease)), overlay 0.15s ease allow-discrete, display 0.15s ease allow-discrete;
40
+ opacity: 1;
41
+ transform: translateY(0) scale(1);
42
+ }
43
+ .rozie-dialog:not([open]) {
44
+ opacity: 0;
45
+ transform: translateY(0.5rem) scale(0.98);
46
+ }
47
+ @starting-style {
48
+ .rozie-dialog[open] {
49
+ opacity: 0;
50
+ transform: translateY(0.5rem) scale(0.98);
51
+ }
52
+ }
53
+ .rozie-dialog::backdrop {
54
+ transition: opacity var(--rozie-dialog-transition, var(--rdg-transition, 0.15s ease)), overlay 0.15s ease allow-discrete, display 0.15s ease allow-discrete;
55
+ opacity: 1;
56
+ }
57
+ .rozie-dialog:not([open])::backdrop {
58
+ opacity: 0;
59
+ }
60
+ @starting-style {
61
+ .rozie-dialog[open]::backdrop {
62
+ opacity: 0;
63
+ }
64
+ }
65
+ }
66
+ .rozie-dialog {
67
+ margin: auto; /* centers in the top layer */
68
+ padding: 0;
69
+ width: var(--rozie-dialog-width, var(--rdg-width, auto));
70
+ max-width: var(--rozie-dialog-max-width, var(--rdg-max-width, min(32rem, calc(100vw - 2rem))));
71
+ max-height: var(--rozie-dialog-max-height, var(--rdg-max-height, calc(100vh - 2rem)));
72
+ border: var(--rozie-dialog-border, var(--rdg-border, none));
73
+ border-radius: var(--rozie-dialog-radius, var(--rdg-radius, 0.75rem));
74
+ background: var(--rozie-dialog-bg, var(--rdg-bg, #fff));
75
+ color: var(--rozie-dialog-color, var(--rdg-color, inherit));
76
+ box-shadow: var(--rozie-dialog-shadow, var(--rdg-shadow, 0 10px 38px rgba(0, 0, 0, 0.35), 0 0 1px rgba(0, 0, 0, 0.25)));
77
+ overflow: auto;
78
+ }
79
+ .rozie-dialog::backdrop {
80
+ background: var(--rozie-dialog-backdrop-bg, var(--rdg-backdrop-bg, rgba(0, 0, 0, 0.5)));
81
+ backdrop-filter: var(--rozie-dialog-backdrop-filter, var(--rdg-backdrop-filter, none));
82
+ }
83
+ .rozie-dialog-panel {
84
+ padding: var(--rozie-dialog-padding, var(--rdg-padding, 1.5rem));
85
+ font: var(--rozie-dialog-font, inherit);
86
+ }
87
+ `],
88
+ providers: [
89
+ {
90
+ provide: NG_VALUE_ACCESSOR,
91
+ useExisting: forwardRef(() => Dialog),
92
+ multi: true,
93
+ },
94
+ ],
95
+ host: { '(focusout)': '__rozieCvaOnTouched()' },
96
+ })
97
+ export class Dialog {
98
+ /**
99
+ * Whether the dialog is shown (two-way `r-model`). The sole `model: true` prop — two-way bind it (`r-model:open` / `v-model:open` / `bind:open` / `[(open)]`) and Dialog reconciles the native `<dialog>` to it via `showModal()` / `close()`. Every close path (backdrop, Escape, programmatic `hide()`) writes `open = false` and emits `close`.
100
+ * @example
101
+ * <rozie-dialog [(open)]="confirmOpen" ariaLabelledby="confirm-title" />
102
+ */
103
+ readonly __rozieModelIn_open = input<boolean | undefined>(undefined, { alias: 'open' });
104
+ openChange = output<boolean>();
105
+ open = rozieModel<boolean, import('@angular/core').ModelSignal<boolean>>(this.__rozieModelIn_open, this.openChange, false, { signal, computed, untracked });
106
+ /**
107
+ * Opt **out** of backdrop-click-to-dismiss. By default a click on the scrim (the `<dialog>` element itself, outside the content panel) closes the dialog with `reason: 'backdrop'`; set this to require an explicit action.
108
+ */
109
+ disableBackdropClose = input<boolean>(false);
110
+ /**
111
+ * Opt **out** of Escape-to-dismiss. By default the native `cancel` event (Esc) closes with `reason: 'escape'`; the component `preventDefault()`s it so the close always flows through the `open` model. Set this to keep the dialog open on Escape (e.g. a required confirmation).
112
+ */
113
+ disableEscapeClose = input<boolean>(false);
114
+ /**
115
+ * Opt **out** of locking `<html>` scroll while the dialog is open. By default `document.documentElement` `overflow` is set to `hidden` for the duration the dialog is shown; set this to leave background scrolling enabled.
116
+ */
117
+ disableScrollLock = input<boolean>(false);
118
+ /**
119
+ * What to focus when the dialog opens: a CSS selector matched inside the dialog content, or an Element. By default the native `showModal()` choice applies: the first element with `autofocus`, otherwise the first focusable element. Use it to start on a specific field (e.g. `initialFocus="input[name=title]"`) without waiting for the dialog to mount. A selector that matches nothing, or an element that is not focusable, leaves the native choice in place.
120
+ * @example
121
+ * <rozie-dialog [(open)]="renameOpen" initialFocus="#label-name" />
122
+ */
123
+ initialFocus = input<(string | Element) | null>(null);
124
+ /**
125
+ * Accessible name for the dialog (`aria-label`) when there is no visible title to point at. Prefer `ariaLabelledby` when a visible heading exists.
126
+ */
127
+ ariaLabel = input<(string) | null>(null);
128
+ /**
129
+ * The `id` of the element that titles the dialog (`aria-labelledby`) — preferred over `ariaLabel` when a visible heading exists inside the dialog. On the Lit element the dialog lives in a shadow root while the heading is slotted light DOM, so the attribute alone cannot reach it; Dialog hands the browser the element directly (`ariaLabelledByElements`) where that is supported (Chrome/Edge 135+, Safari 16.4+) — elsewhere, use `ariaLabel` on Lit.
130
+ */
131
+ ariaLabelledby = input<(string) | null>(null);
132
+ panelEl = viewChild<ElementRef<HTMLDivElement>>('panelEl');
133
+ close = output<DialogClosePayload>();
134
+ @ContentChild('defaultSlot', { read: TemplateRef }) defaultTpl?: TemplateRef<DefaultCtx>;
135
+ templates = input<Record<string, TemplateRef<unknown>> | undefined>(undefined);
136
+ __rozieFills = contentChildren(RozieSlot, { descendants: true });
137
+ __rozieFillMap = computed(() => {
138
+ const map = Object.create(null) as Record<string, TemplateRef<unknown>>;
139
+ for (const f of this.__rozieFills()) {
140
+ const k = f.rozieSlot();
141
+ if (k == null) continue;
142
+ if (k === '__proto__' || k === 'constructor' || k === 'prototype') continue;
143
+ map[k === '' ? 'defaultSlot' : k] = f.templateRef;
144
+ }
145
+ return map;
146
+ });
147
+ private __rozieWatchInitial_0 = true;
148
+
149
+ constructor() {
150
+ inject(DestroyRef).onDestroy(() => {
151
+ this.setScrollLock(false);
152
+ this.pressStartedInside = false;
153
+ const el = this.dialogEl;
154
+ const back = this.returnFocusTo;
155
+ this.dialogEl = null;
156
+ this.returnFocusTo = null;
157
+ if (!el || !el.open) return;
158
+ if (el.isConnected) el.close();
159
+ if (!back) return;
160
+ setTimeout(() => {
161
+ // Lost: on <body>, or stranded on a shadow host whose root holds no focus
162
+ // and which is not focusable itself (the dialog's removed subtree was
163
+ // inside it).
164
+ const active = this.deepActiveElement();
165
+ const lost = !active || active === document.body || !!active.shadowRoot && active.tabIndex < 0;
166
+ if (back.isConnected && lost) back.focus();
167
+ }, 0);
168
+ });
169
+ effect(() => { const __watchVal = (() => this.open())(); untracked(() => { if (this.__rozieWatchInitial_0) { this.__rozieWatchInitial_0 = false; return; } ((isOpen: any) => {
170
+ this.sync(isOpen);
171
+ })(__watchVal); }); });
172
+ }
173
+
174
+ ngAfterViewInit() {
175
+ this.sync(this.open());
176
+ }
177
+
178
+ dialogEl: HTMLDialogElement | null = null;
179
+ // Whether THIS instance currently holds one count of the shared scroll lock.
180
+ holdsLock = false;
181
+ // The element focused when the dialog opened, for the unmount-while-open
182
+ // focus return (a normal close gets the native return from close()).
183
+ returnFocusTo: HTMLElement | null = null;
184
+ // Whether the press that is about to produce a `click` began INSIDE the panel.
185
+ // A press that starts on content (selecting text, a drag) and is released over
186
+ // the scrim yields a `click` whose target is the common ancestor, the <dialog>
187
+ // itself; without this it would be mistaken for a backdrop click.
188
+ pressStartedInside = false;
189
+ // Lock/unlock <html> scroll for this instance. The actual lock/unlock is
190
+ // REF-COUNTED (./internal/scrollLock) across every Dialog instance sharing this
191
+ // leaf's module, because a naive per-instance toggle unlocks scrolling the
192
+ // moment ANY dialog closes, even while an OUTER dialog is still open. This
193
+ // wrapper releases only a count this instance took: a dialog that mounts closed
194
+ // (or closes twice) must not release a count another open dialog holds. The
195
+ // opt-out is read when locking only, so toggling it while open still releases.
196
+ setScrollLock = (lock: any) => {
197
+ if (lock === this.holdsLock) return;
198
+ if (lock && this.disableScrollLock()) return;
199
+ this.holdsLock = lock;
200
+ applySharedScrollLock(lock);
201
+ };
202
+ // The element that really has focus. `document.activeElement` stops at the
203
+ // outermost shadow host (on Lit the trigger lives inside a component's shadow
204
+ // root, so it reports that component), so walk each shadowRoot.activeElement.
205
+ deepActiveElement = () => {
206
+ let active: any = typeof document === 'undefined' ? null : document.activeElement;
207
+ while (active && active.shadowRoot && active.shadowRoot.activeElement) active = active.shadowRoot.activeElement;
208
+ return active;
209
+ };
210
+ // Focus `initialFocus` after showModal() has made its native choice. A selector
211
+ // is matched inside the panel and, on Lit, inside the light-DOM content
212
+ // assigned to the panel's <slot> (which panel.querySelector cannot see).
213
+ focusInitial = (panel: any) => {
214
+ const target: any = this.initialFocus();
215
+ if (!target) return;
216
+ let node: any = null;
217
+ if (typeof target === 'string') {
218
+ node = panel.querySelector(target);
219
+ const slot: any = node ? null : panel.querySelector('slot');
220
+ const assigned: any[] = slot && typeof slot.assignedElements === 'function' ? slot.assignedElements({
221
+ flatten: true
222
+ }) : [];
223
+ for (let i = 0; !node && i < assigned.length; i++) {
224
+ node = assigned[i].matches(target) ? assigned[i] : assigned[i].querySelector(target);
225
+ }
226
+ } else {
227
+ node = target;
228
+ }
229
+ if (node && typeof node.focus === 'function') node.focus();
230
+ };
231
+ // `aria-labelledby` is an IDREF, and an IDREF never crosses a shadow-root
232
+ // boundary. Where the <dialog> lives inside an element's shadow root (the Lit
233
+ // target) the heading it names is slotted LIGHT DOM, so the attribute resolves to
234
+ // nothing and the dialog has no accessible name. Element reflection can point
235
+ // across the boundary (to an element in an ancestor tree), so when the id is not
236
+ // reachable from the dialog's own root, hand the browser the element directly.
237
+ // A no-op outside a shadow root, and where the browser lacks the property.
238
+ bridgeLabelledBy = (el: any) => {
239
+ const id = this.ariaLabelledby();
240
+ const root: any = el.getRootNode();
241
+ if (!id || !root || !root.host || typeof root.getElementById !== 'function') return;
242
+ if (root.getElementById(id) || !('ariaLabelledByElements' in el)) return;
243
+ const outer: any = root.host.getRootNode();
244
+ const heading = outer && typeof outer.getElementById === 'function' ? outer.getElementById(id) : null;
245
+ if (heading) el.ariaLabelledByElements = [heading];
246
+ };
247
+ // Reconcile the native <dialog> to the desired open state. Guarded on the
248
+ // native `el.open` flag (showModal throws if already open; close is a no-op when
249
+ // closed). Reads $refs in a post-mount callback (ROZ123-safe).
250
+ //
251
+ // The ref lives on the inner panel <div> (which the emitter types as
252
+ // HTMLDivElement), and we reach the <dialog> via `panel.parentElement` cast to
253
+ // HTMLDialogElement. This sidesteps an emitter gap: the per-target ref-type map
254
+ // has no `dialog` case, so a ref placed directly on <dialog> would be typed the
255
+ // generic HTMLElement (no `.open`/`.showModal()`/`.close()`), failing strict
256
+ // leaf typecheck. Fixing it here keeps the change source-only (no emitter edit).
257
+ sync = (isOpen: any) => {
258
+ const panel = this.panelEl()?.nativeElement;
259
+ const el = (panel && panel.parentElement) as HTMLDialogElement | null;
260
+ if (!el) return;
261
+ this.dialogEl = el;
262
+ if (isOpen) {
263
+ if (!el.open) {
264
+ const active = this.deepActiveElement();
265
+ this.returnFocusTo = active instanceof HTMLElement ? active : null;
266
+ this.bridgeLabelledBy(el);
267
+ el.showModal();
268
+ this.focusInitial(panel);
269
+ }
270
+ this.setScrollLock(true);
271
+ } else {
272
+ if (el.open) el.close();
273
+ this.returnFocusTo = null;
274
+ this.setScrollLock(false);
275
+ }
276
+ };
277
+ // ---- close funnel (single $emit site) ----------------------------------
278
+ closeWith = (reason: any) => {
279
+ this.open.set(false), this.__rozieCvaOnChange(false);
280
+ this.close.emit({
281
+ reason
282
+ });
283
+ };
284
+ // ---- handlers ----------------------------------------------------------
285
+ // Native Esc fires `cancel` on the <dialog>. preventDefault so WE drive the
286
+ // close through the model (keeping `open` in sync); honor the opt-out.
287
+ onCancel = (e: any) => {
288
+ if (e) e.preventDefault();
289
+ if (this.disableEscapeClose()) return;
290
+ this.closeWith('escape');
291
+ };
292
+ // Remember whether a press began on the panel's content (anywhere but the
293
+ // <dialog> box itself), so the `click` that follows can tell a real scrim click
294
+ // from the end of a drag that merely finished over the scrim.
295
+ onPointerDown = (e: any) => {
296
+ const panel = this.panelEl()?.nativeElement;
297
+ const el = panel && panel.parentElement;
298
+ this.pressStartedInside = !!(e && el && e.target !== el);
299
+ };
300
+ // A click whose target IS the <dialog> element (not its panel/children) is a
301
+ // backdrop click — the ::backdrop is part of the dialog box. We compare the
302
+ // real `e.target` (reliable even under Solid's event delegation) to the dialog
303
+ // element resolved via the panel ref's parent. A click whose press started
304
+ // inside the panel is not one (see `pressStartedInside`).
305
+ onClick = (e: any) => {
306
+ const startedInside = this.pressStartedInside;
307
+ this.pressStartedInside = false;
308
+ if (this.disableBackdropClose() || startedInside) return;
309
+ const panel = this.panelEl()?.nativeElement;
310
+ const el = panel && panel.parentElement;
311
+ if (e && el && e.target === el) this.closeWith('backdrop');
312
+ };
313
+ // The native `close` event: fired by `el.close()` from our own reconcile (by then
314
+ // the model is already false, and the dialog may even have been re-opened), but
315
+ // also by closes WE did not drive — a `<form method="dialog">` submit, a stray
316
+ // `dialog.close()`. For those the model is still true over a closed dialog and
317
+ // would stay stuck (writing `open = true` again changes nothing), so fold them
318
+ // into the close funnel. Not during teardown: $onUnmount closes the dialog
319
+ // itself after clearing `dialogEl`.
320
+ onNativeClose = () => {
321
+ const el = this.dialogEl;
322
+ if (!el || el.open || !this.open()) return;
323
+ this.closeWith('programmatic');
324
+ };
325
+ // ---- lifecycle ---------------------------------------------------------
326
+ // ---- imperative handle -------------------------------------------------
327
+ // show()/hide() — named to avoid the `open` model + `@close` event collisions.
328
+ // hide() on a dialog that is not open is a no-op: there is nothing to dismiss, so
329
+ // it must not emit a `close` for a dismissal that never happened.
330
+ show: () => void = () => {
331
+ this.open.set(true), this.__rozieCvaOnChange(true);
332
+ };
333
+ hide: () => void = () => {
334
+ if (!this.open()) return;
335
+ this.closeWith('programmatic');
336
+ };
337
+
338
+ private __rozieCvaOnChange: (v: boolean) => void = () => {};
339
+ private __rozieCvaOnTouchedFn: () => void = () => {};
340
+ protected __rozieCvaDisabled = signal(false);
341
+
342
+ writeValue(v: boolean | null): void {
343
+ this.open.set(v ?? false);
344
+ }
345
+ registerOnChange(fn: (v: boolean) => void): void {
346
+ this.__rozieCvaOnChange = fn;
347
+ }
348
+ registerOnTouched(fn: () => void): void {
349
+ this.__rozieCvaOnTouchedFn = fn;
350
+ }
351
+ setDisabledState(isDisabled: boolean): void {
352
+ this.__rozieCvaDisabled.set(isDisabled);
353
+ }
354
+ __rozieCvaOnTouched(): void {
355
+ this.__rozieCvaOnTouchedFn();
356
+ }
357
+
358
+ static ngTemplateContextGuard(
359
+ _dir: Dialog,
360
+ _ctx: unknown,
361
+ ): _ctx is DefaultCtx {
362
+ return true;
363
+ }
364
+
365
+ private __rozieDestroyRef = inject(DestroyRef);
366
+
367
+ private rozieSpread_0 = viewChild<ElementRef>('rozieSpread_0');
368
+
369
+ private __rozieApplyAttrs = createRozieAttrApplier(inject(Renderer2));
370
+
371
+ private __rozieGetHostAttrs = createRozieHostAttrsReader(inject(ElementRef));
372
+
373
+ private __rozieSpread_0_effect = afterRenderEffect(() => {
374
+ const el = this.rozieSpread_0()?.nativeElement;
375
+ if (!el) return;
376
+ this.__rozieApplyAttrs(el, this.__rozieGetHostAttrs());
377
+ });
378
+
379
+ private rozieListenersTarget_1 = viewChild<ElementRef>('rozieListenersTarget_1');
380
+
381
+ private __rozieListenersRenderer = inject(Renderer2);
382
+
383
+ private __rozieListenersDisposers_1: Array<() => void> = [];
384
+
385
+ private __rozieListenersDestroyRegistered_1 = false;
386
+
387
+ private __rozieListenersEffect_1 = effect(() => {
388
+ const el = this.rozieListenersTarget_1()?.nativeElement;
389
+ if (!el) return;
390
+ for (const off of this.__rozieListenersDisposers_1) off();
391
+ this.__rozieListenersDisposers_1 = [];
392
+ const obj: Record<string, unknown> = {};
393
+ for (const [k, v] of Object.entries(obj)) {
394
+ if (k === '__proto__' || k === 'constructor' || k === 'prototype') continue;
395
+ if (typeof v !== 'function') continue;
396
+ const norm = k.startsWith('on') ? k.slice(2).toLowerCase() : k;
397
+ const dispose = this.__rozieListenersRenderer.listen(el, norm, v as EventListener);
398
+ this.__rozieListenersDisposers_1.push(dispose);
399
+ }
400
+ if (!this.__rozieListenersDestroyRegistered_1) {
401
+ this.__rozieListenersDestroyRegistered_1 = true;
402
+ this.__rozieDestroyRef.onDestroy(() => {
403
+ for (const off of this.__rozieListenersDisposers_1) off();
404
+ this.__rozieListenersDisposers_1 = [];
405
+ });
406
+ }
407
+ });
408
+
409
+ rozieDisplay(v: unknown): string { return __rozieDisplay(v); }
410
+
411
+ rozieAttr(v: unknown): string | null { return __rozieAttr(v); }
412
+ }
413
+
414
+ export default Dialog;
package/src/index.ts ADDED
@@ -0,0 +1 @@
1
+ export * from './Dialog';
@@ -0,0 +1,48 @@
1
+ // scrollLock.ts — a REF-COUNTED `<html>` scroll lock, shared by every `Dialog`
2
+ // instance compiled from this leaf's module (module-scope state — a plain
3
+ // per-instance toggle would unlock scrolling the moment ANY dialog closes,
4
+ // even while an OUTER dialog is still open — nested/stacked dialogs).
5
+ //
6
+ // The lock only actually applies on the 0 -> 1 transition and only actually
7
+ // releases on the 1 -> 0 transition. The ORIGINAL inline `overflow` value
8
+ // (captured on that first lock, not a hardcoded `''`) is restored when the
9
+ // count drops back to zero, so a page that already set its own inline
10
+ // `overflow` isn't clobbered by the second (or third...) dialog to close.
11
+ //
12
+ // Vendored (byte-identical) into every `@rozie-ui/dialog-*` leaf's
13
+ // `src/internal/` by `scripts/codegen.mjs`, unit-tested once here — the same
14
+ // "branchy, non-reactive helper -> src/internal" convention as the resizable
15
+ // family's `resizeMath.ts`.
16
+ let lockCount = 0;
17
+ let previousOverflow: string | null = null;
18
+
19
+ export function applyScrollLock(lock: boolean): void {
20
+ if (typeof document === 'undefined') return;
21
+ const root = document.documentElement;
22
+ if (!root) return;
23
+
24
+ if (lock) {
25
+ if (lockCount === 0) {
26
+ previousOverflow = root.style.overflow;
27
+ root.style.overflow = 'hidden';
28
+ }
29
+ lockCount += 1;
30
+ return;
31
+ }
32
+
33
+ // Guard against an unbalanced release (a lock() that was never applied,
34
+ // e.g. because `disableScrollLock` was toggled mid-flight) — never let the
35
+ // count go negative, which would require two extra locks to re-lock.
36
+ if (lockCount === 0) return;
37
+ lockCount -= 1;
38
+ if (lockCount === 0) {
39
+ root.style.overflow = previousOverflow ?? '';
40
+ previousOverflow = null;
41
+ }
42
+ }
43
+
44
+ /** Test-only: reset the module-level counter between test cases. */
45
+ export function _resetScrollLockForTests(): void {
46
+ lockCount = 0;
47
+ previousOverflow = null;
48
+ }
@@ -0,0 +1,58 @@
1
+ /*
2
+ * @rozie-ui/dialog — base token reference.
3
+ *
4
+ * Every COSMETIC value the dialog box + scrim render is a `--rozie-dialog-*`
5
+ * custom property. The component ships with inline `var(token, fallback)`
6
+ * defaults, so importing this file is OPTIONAL — it simply makes the full token
7
+ * surface explicit in one place so you can copy/override exactly what you need.
8
+ *
9
+ * The STRUCTURAL behaviour — top-layer rendering, the native `::backdrop`
10
+ * pseudo-element, UA centering, the focus trap, Esc-to-dismiss, and focus
11
+ * restoration — all come from the native `<dialog>` + `showModal()` and are NOT
12
+ * tokenized. Only the values below flow through tokens.
13
+ *
14
+ * Override any token at any ancestor scope (`:root`, `.dark`, a wrapper, or the
15
+ * `.rozie-dialog` element). See themes/shadcn.css, themes/material.css and
16
+ * themes/bootstrap.css for design-system bridges.
17
+ *
18
+ * WHERE THE DEFAULTS SIT. This file declares no public token that could shadow yours. Each
19
+ * default is the FALLBACK of a private wiring line on the document root, under `:where(:root)`
20
+ * (zero specificity): `--rdg-x: var(--rozie-dialog-x, <default>)`. The component reads every token
21
+ * public-first, `var(--rozie-dialog-x, var(--rdg-x, <inline default>))`, so a value set on ANY
22
+ * ancestor (`:root`, `.dark`, a wrapper) or on the component itself wins by plain inheritance,
23
+ * in any import order, on all six targets (Lit included: custom properties inherit into its
24
+ * shadow root). A value an element declares for itself always beats one it would inherit,
25
+ * which is why nothing on the way to the component may declare a public token.
26
+ * The lines that say `inherit` / `initial` stay plain declarations: at the root such a value
27
+ * is "unset", so the component's own fallback applies, and it never shadows an ancestor.
28
+ * A design-system bridge (themes/shadcn.css, material.css, bootstrap.css) re-declares only the
29
+ * wiring of the tokens it maps, with the design system's variable as the fallback, on the
30
+ * component (`.rozie-dialog` and the Lit host `rozie-dialog`) — so that variable is resolved AT the
31
+ * component and follows the nearest theme scope — and on `:root`, the copy a Lit component
32
+ * nested in another shadow root (out of reach of every document selector) inherits. The
33
+ * `--rdg-*` names are internal: not a stable API.
34
+ */
35
+ :where(:root) {
36
+ /* box geometry */
37
+ --rdg-width: var(--rozie-dialog-width, auto);
38
+ --rdg-max-width: var(--rozie-dialog-max-width, min(32rem, calc(100vw - 2rem)));
39
+ --rdg-max-height: var(--rozie-dialog-max-height, calc(100vh - 2rem));
40
+
41
+ /* box chrome */
42
+ --rdg-border: var(--rozie-dialog-border, none);
43
+ --rdg-radius: var(--rozie-dialog-radius, 0.75rem);
44
+ --rdg-bg: var(--rozie-dialog-bg, #fff);
45
+ --rozie-dialog-color: inherit;
46
+ --rdg-shadow: var(--rozie-dialog-shadow, 0 10px 38px rgba(0, 0, 0, 0.35), 0 0 1px rgba(0, 0, 0, 0.25));
47
+
48
+ /* scrim (the native ::backdrop) */
49
+ --rdg-backdrop-bg: var(--rozie-dialog-backdrop-bg, rgba(0, 0, 0, 0.5));
50
+ --rdg-backdrop-filter: var(--rozie-dialog-backdrop-filter, none);
51
+
52
+ /* content panel */
53
+ --rdg-padding: var(--rozie-dialog-padding, 1.5rem);
54
+ --rozie-dialog-font: inherit;
55
+
56
+ /* enter/leave transition duration */
57
+ --rdg-transition: var(--rozie-dialog-transition, 0.15s ease);
58
+ }
@@ -0,0 +1,37 @@
1
+ /*
2
+ * @rozie-ui/dialog — Bootstrap 5 bridge.
3
+ *
4
+ * Maps the dialog tokens onto Bootstrap's `--bs-*` CSS variables (Bootstrap
5
+ * 5.2+). Reading them live means the dialog follows `data-bs-theme="dark"` and
6
+ * any custom build automatically. Falls back to Bootstrap's default light
7
+ * palette when the vars are absent.
8
+ *
9
+ * import '@rozie-ui/dialog-angular/themes/bootstrap.css';
10
+ *
11
+ * Bootstrap modals use a 0.5rem radius, a 1px border, and a 0.5-opacity black
12
+ * backdrop (`$modal-backdrop-bg` / `$modal-backdrop-opacity`).
13
+ *
14
+ * HOW IT MAPS. This bridge declares no public token: it re-declares the private wiring of
15
+ * each token it maps, with the design system's variable as the fallback
16
+ * (`--rdg-x: var(--rozie-dialog-x, <design-system variable>)`). The component reads every token
17
+ * public-first, so on all six targets:
18
+ * - a public `--rozie-dialog-*` token set on any ancestor (or on the component) wins;
19
+ * - otherwise the design system's variable applies, resolved AT the component (`.rozie-dialog`
20
+ * and the Lit host `rozie-dialog`), so a `.dark` / `data-bs-theme` wrapper narrower than
21
+ * <html> is followed;
22
+ * - a Lit component nested in another shadow root, which no document selector reaches,
23
+ * inherits the `:root` copy instead: there the design system's variables are read at
24
+ * the document root.
25
+ * This rule outranks base.css's `:where(:root)` wiring, so import order does not matter.
26
+ */
27
+ :root,
28
+ .rozie-dialog,
29
+ rozie-dialog {
30
+ --rdg-bg: var(--rozie-dialog-bg, var(--bs-body-bg, #fff));
31
+ --rdg-color: var(--rozie-dialog-color, var(--bs-body-color, #212529));
32
+ --rdg-border: var(--rozie-dialog-border, 1px solid var(--bs-border-color-translucent, rgba(0, 0, 0, 0.175)));
33
+ --rdg-radius: var(--rozie-dialog-radius, var(--bs-border-radius-lg, 0.5rem));
34
+
35
+ --rdg-backdrop-bg: var(--rozie-dialog-backdrop-bg, rgba(0, 0, 0, 0.5));
36
+ --rdg-shadow: var(--rozie-dialog-shadow, 0 0.5rem 1rem rgba(0, 0, 0, 0.15));
37
+ }
@@ -0,0 +1,37 @@
1
+ /*
2
+ * @rozie-ui/dialog — Material Design 3 bridge.
3
+ *
4
+ * Maps the dialog tokens onto the MD3 system color roles (`--md-sys-color-*`)
5
+ * emitted by material-web / @material/material-color-utilities theme builders.
6
+ * Falls back to the baseline M3 light palette when those vars are absent, so it
7
+ * renders correctly even without a generated theme.
8
+ *
9
+ * import '@rozie-ui/dialog-angular/themes/material.css';
10
+ *
11
+ * M3 dialogs are heavily rounded (28dp), use the surface-container-high color,
12
+ * and a scrim at ~32% of the scrim color role.
13
+ *
14
+ * HOW IT MAPS. This bridge declares no public token: it re-declares the private wiring of
15
+ * each token it maps, with the design system's variable as the fallback
16
+ * (`--rdg-x: var(--rozie-dialog-x, <design-system variable>)`). The component reads every token
17
+ * public-first, so on all six targets:
18
+ * - a public `--rozie-dialog-*` token set on any ancestor (or on the component) wins;
19
+ * - otherwise the design system's variable applies, resolved AT the component (`.rozie-dialog`
20
+ * and the Lit host `rozie-dialog`), so a `.dark` / `data-bs-theme` wrapper narrower than
21
+ * <html> is followed;
22
+ * - a Lit component nested in another shadow root, which no document selector reaches,
23
+ * inherits the `:root` copy instead: there the design system's variables are read at
24
+ * the document root.
25
+ * This rule outranks base.css's `:where(:root)` wiring, so import order does not matter.
26
+ */
27
+ :root,
28
+ .rozie-dialog,
29
+ rozie-dialog {
30
+ --rdg-bg: var(--rozie-dialog-bg, var(--md-sys-color-surface-container-high, #ece6f0));
31
+ --rdg-color: var(--rozie-dialog-color, var(--md-sys-color-on-surface, #1d1b20));
32
+ --rdg-border: var(--rozie-dialog-border, none);
33
+ --rdg-radius: var(--rozie-dialog-radius, 1.75rem);
34
+
35
+ --rdg-backdrop-bg: var(--rozie-dialog-backdrop-bg, color-mix(in srgb, var(--md-sys-color-scrim, #000) 32%, transparent));
36
+ --rdg-shadow: var(--rozie-dialog-shadow, 0 8px 12px 6px rgba(0, 0, 0, 0.15), 0 4px 4px rgba(0, 0, 0, 0.3));
37
+ }
@@ -0,0 +1,38 @@
1
+ /*
2
+ * @rozie-ui/dialog — shadcn/ui (Radix) bridge.
3
+ *
4
+ * Maps the dialog tokens onto the shadcn/ui CSS variables defined on `:root`
5
+ * / `.dark` (the classic HSL-channel convention: `--background: 0 0% 100%`
6
+ * consumed as `hsl(var(--background))`). Because it reads those vars live, the
7
+ * dialog automatically follows light/dark theme switches.
8
+ *
9
+ * import '@rozie-ui/dialog-angular/themes/shadcn.css';
10
+ *
11
+ * If your shadcn setup predates the `hsl()`-wrapping convention (Tailwind v4 /
12
+ * oklch tokens emit pre-formed colors), drop the `hsl(...)` wrappers below.
13
+ *
14
+ * HOW IT MAPS. This bridge declares no public token: it re-declares the private wiring of
15
+ * each token it maps, with the design system's variable as the fallback
16
+ * (`--rdg-x: var(--rozie-dialog-x, <design-system variable>)`). The component reads every token
17
+ * public-first, so on all six targets:
18
+ * - a public `--rozie-dialog-*` token set on any ancestor (or on the component) wins;
19
+ * - otherwise the design system's variable applies, resolved AT the component (`.rozie-dialog`
20
+ * and the Lit host `rozie-dialog`), so a `.dark` / `data-bs-theme` wrapper narrower than
21
+ * <html> is followed;
22
+ * - a Lit component nested in another shadow root, which no document selector reaches,
23
+ * inherits the `:root` copy instead: there the design system's variables are read at
24
+ * the document root.
25
+ * This rule outranks base.css's `:where(:root)` wiring, so import order does not matter.
26
+ */
27
+ :root,
28
+ .rozie-dialog,
29
+ rozie-dialog {
30
+ --rdg-bg: var(--rozie-dialog-bg, hsl(var(--background, 0 0% 100%)));
31
+ --rdg-color: var(--rozie-dialog-color, hsl(var(--foreground, 222.2 84% 4.9%)));
32
+ --rdg-border: var(--rozie-dialog-border, 1px solid hsl(var(--border, 214.3 31.8% 91.4%)));
33
+ --rdg-radius: var(--rozie-dialog-radius, var(--radius, 0.5rem));
34
+
35
+ /* shadcn dialogs use a soft, low scrim */
36
+ --rdg-backdrop-bg: var(--rozie-dialog-backdrop-bg, hsl(var(--background, 0 0% 0%) / 0.8));
37
+ --rdg-shadow: var(--rozie-dialog-shadow, 0 10px 38px hsl(var(--foreground, 222.2 84% 4.9%) / 0.18));
38
+ }