ngwr 16.8.0 → 16.9.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/descriptions/styles/_index.scss +91 -0
- package/fesm2022/ngwr-anchor.mjs +48 -10
- package/fesm2022/ngwr-anchor.mjs.map +1 -1
- package/fesm2022/ngwr-carousel.mjs +3 -2
- package/fesm2022/ngwr-carousel.mjs.map +1 -1
- package/fesm2022/ngwr-compare.mjs +4 -0
- package/fesm2022/ngwr-compare.mjs.map +1 -1
- package/fesm2022/ngwr-cookie.mjs +6 -3
- package/fesm2022/ngwr-cookie.mjs.map +1 -1
- package/fesm2022/ngwr-date-stamp-testing.mjs +3 -0
- package/fesm2022/ngwr-date-stamp-testing.mjs.map +1 -1
- package/fesm2022/ngwr-date-stamp.mjs +81 -4
- package/fesm2022/ngwr-date-stamp.mjs.map +1 -1
- package/fesm2022/ngwr-date.mjs +16 -2
- package/fesm2022/ngwr-date.mjs.map +1 -1
- package/fesm2022/ngwr-density.mjs +4 -3
- package/fesm2022/ngwr-density.mjs.map +1 -1
- package/fesm2022/ngwr-descriptions.mjs +77 -20
- package/fesm2022/ngwr-descriptions.mjs.map +1 -1
- package/fesm2022/ngwr-directives.mjs +12 -0
- package/fesm2022/ngwr-directives.mjs.map +1 -1
- package/fesm2022/ngwr-editor.mjs +1 -0
- package/fesm2022/ngwr-editor.mjs.map +1 -1
- package/fesm2022/ngwr-file-upload.mjs +2 -3
- package/fesm2022/ngwr-file-upload.mjs.map +1 -1
- package/fesm2022/ngwr-form.mjs.map +1 -1
- package/fesm2022/ngwr-hotkey.mjs +10 -5
- package/fesm2022/ngwr-hotkey.mjs.map +1 -1
- package/fesm2022/ngwr-i18n-ar.mjs +9 -3
- package/fesm2022/ngwr-i18n-ar.mjs.map +1 -1
- package/fesm2022/ngwr-i18n-cs.mjs +9 -3
- package/fesm2022/ngwr-i18n-cs.mjs.map +1 -1
- package/fesm2022/ngwr-i18n-de.mjs +9 -3
- package/fesm2022/ngwr-i18n-de.mjs.map +1 -1
- package/fesm2022/ngwr-i18n-en.mjs +9 -3
- package/fesm2022/ngwr-i18n-en.mjs.map +1 -1
- package/fesm2022/ngwr-i18n-es.mjs +9 -3
- package/fesm2022/ngwr-i18n-es.mjs.map +1 -1
- package/fesm2022/ngwr-i18n-fr.mjs +9 -3
- package/fesm2022/ngwr-i18n-fr.mjs.map +1 -1
- package/fesm2022/ngwr-i18n-he.mjs +9 -3
- package/fesm2022/ngwr-i18n-he.mjs.map +1 -1
- package/fesm2022/ngwr-i18n-hi.mjs +9 -3
- package/fesm2022/ngwr-i18n-hi.mjs.map +1 -1
- package/fesm2022/ngwr-i18n-id.mjs +9 -3
- package/fesm2022/ngwr-i18n-id.mjs.map +1 -1
- package/fesm2022/ngwr-i18n-it.mjs +9 -3
- package/fesm2022/ngwr-i18n-it.mjs.map +1 -1
- package/fesm2022/ngwr-i18n-ja.mjs +9 -3
- package/fesm2022/ngwr-i18n-ja.mjs.map +1 -1
- package/fesm2022/ngwr-i18n-kk.mjs +9 -3
- package/fesm2022/ngwr-i18n-kk.mjs.map +1 -1
- package/fesm2022/ngwr-i18n-ko.mjs +9 -3
- package/fesm2022/ngwr-i18n-ko.mjs.map +1 -1
- package/fesm2022/ngwr-i18n-nl.mjs +9 -3
- package/fesm2022/ngwr-i18n-nl.mjs.map +1 -1
- package/fesm2022/ngwr-i18n-pl.mjs +9 -3
- package/fesm2022/ngwr-i18n-pl.mjs.map +1 -1
- package/fesm2022/ngwr-i18n-pt.mjs +9 -3
- package/fesm2022/ngwr-i18n-pt.mjs.map +1 -1
- package/fesm2022/ngwr-i18n-ru.mjs +9 -3
- package/fesm2022/ngwr-i18n-ru.mjs.map +1 -1
- package/fesm2022/ngwr-i18n-sv.mjs +9 -3
- package/fesm2022/ngwr-i18n-sv.mjs.map +1 -1
- package/fesm2022/ngwr-i18n-tr.mjs +9 -3
- package/fesm2022/ngwr-i18n-tr.mjs.map +1 -1
- package/fesm2022/ngwr-i18n-uk.mjs +9 -3
- package/fesm2022/ngwr-i18n-uk.mjs.map +1 -1
- package/fesm2022/ngwr-i18n-vi.mjs +9 -3
- package/fesm2022/ngwr-i18n-vi.mjs.map +1 -1
- package/fesm2022/ngwr-i18n-zh-tw.mjs +9 -3
- package/fesm2022/ngwr-i18n-zh-tw.mjs.map +1 -1
- package/fesm2022/ngwr-i18n-zh.mjs +9 -3
- package/fesm2022/ngwr-i18n-zh.mjs.map +1 -1
- package/fesm2022/ngwr-i18n.mjs +7 -6
- package/fesm2022/ngwr-i18n.mjs.map +1 -1
- package/fesm2022/ngwr-image-cropper-testing.mjs +33 -0
- package/fesm2022/ngwr-image-cropper-testing.mjs.map +1 -1
- package/fesm2022/ngwr-image-cropper.mjs +536 -30
- package/fesm2022/ngwr-image-cropper.mjs.map +1 -1
- package/fesm2022/ngwr-knob.mjs +5 -0
- package/fesm2022/ngwr-knob.mjs.map +1 -1
- package/fesm2022/ngwr-mention.mjs +2 -0
- package/fesm2022/ngwr-mention.mjs.map +1 -1
- package/fesm2022/ngwr-meta.mjs +43 -8
- package/fesm2022/ngwr-meta.mjs.map +1 -1
- package/fesm2022/ngwr-pagination.mjs +1 -1
- package/fesm2022/ngwr-pagination.mjs.map +1 -1
- package/fesm2022/ngwr-pipes.mjs +160 -8
- package/fesm2022/ngwr-pipes.mjs.map +1 -1
- package/fesm2022/ngwr-qr.mjs +65 -7
- package/fesm2022/ngwr-qr.mjs.map +1 -1
- package/fesm2022/ngwr-schema-form.mjs +2 -2
- package/fesm2022/ngwr-schema-form.mjs.map +1 -1
- package/fesm2022/ngwr-scroll.mjs +1 -2
- package/fesm2022/ngwr-scroll.mjs.map +1 -1
- package/fesm2022/ngwr-speed-dial.mjs +30 -1
- package/fesm2022/ngwr-speed-dial.mjs.map +1 -1
- package/fesm2022/ngwr-statistic.mjs +1 -1
- package/fesm2022/ngwr-stepper-testing.mjs +7 -1
- package/fesm2022/ngwr-stepper-testing.mjs.map +1 -1
- package/fesm2022/ngwr-stepper.mjs +55 -4
- package/fesm2022/ngwr-stepper.mjs.map +1 -1
- package/fesm2022/ngwr-timeline.mjs +4 -0
- package/fesm2022/ngwr-timeline.mjs.map +1 -1
- package/fesm2022/ngwr-toolbar.mjs +171 -16
- package/fesm2022/ngwr-toolbar.mjs.map +1 -1
- package/fesm2022/ngwr-transfer.mjs +3 -2
- package/fesm2022/ngwr-transfer.mjs.map +1 -1
- package/fesm2022/ngwr-tree.mjs +1 -1
- package/fesm2022/ngwr-utils.mjs +46 -8
- package/fesm2022/ngwr-utils.mjs.map +1 -1
- package/fesm2022/ngwr-version.mjs +1 -1
- package/fesm2022/ngwr-version.mjs.map +1 -1
- package/fesm2022/ngwr-virtual-scroll.mjs +2 -2
- package/fesm2022/ngwr-virtual-scroll.mjs.map +1 -1
- package/i18n/ar.json +9 -3
- package/i18n/cs.json +9 -3
- package/i18n/de.json +9 -3
- package/i18n/en.json +9 -3
- package/i18n/es.json +9 -3
- package/i18n/fr.json +9 -3
- package/i18n/he.json +9 -3
- package/i18n/hi.json +9 -3
- package/i18n/id.json +9 -3
- package/i18n/it.json +9 -3
- package/i18n/ja.json +9 -3
- package/i18n/kk.json +9 -3
- package/i18n/ko.json +9 -3
- package/i18n/nl.json +9 -3
- package/i18n/pl.json +9 -3
- package/i18n/pt.json +9 -3
- package/i18n/ru.json +9 -3
- package/i18n/sv.json +9 -3
- package/i18n/tr.json +9 -3
- package/i18n/uk.json +9 -3
- package/i18n/vi.json +9 -3
- package/i18n/zh-TW.json +9 -3
- package/i18n/zh.json +9 -3
- package/image-cropper/styles/_index.scss +30 -1
- package/llms-full.txt +5 -5
- package/package.json +1 -1
- package/schematics/use/symbol-map.json +1 -0
- package/skills/ngwr/SKILL.md +2 -2
- package/stepper/styles/_index.scss +33 -0
- package/types/ngwr-anchor.d.ts +14 -1
- package/types/ngwr-date-stamp-testing.d.ts +2 -0
- package/types/ngwr-date-stamp.d.ts +41 -2
- package/types/ngwr-date.d.ts +3 -1
- package/types/ngwr-descriptions.d.ts +33 -5
- package/types/ngwr-directives.d.ts +1 -0
- package/types/ngwr-form.d.ts +4 -0
- package/types/ngwr-hotkey.d.ts +2 -0
- package/types/ngwr-image-cropper-testing.d.ts +33 -1
- package/types/ngwr-image-cropper.d.ts +214 -6
- package/types/ngwr-meta.d.ts +13 -1
- package/types/ngwr-pipes.d.ts +125 -1
- package/types/ngwr-qr.d.ts +17 -0
- package/types/ngwr-speed-dial.d.ts +10 -0
- package/types/ngwr-stepper-testing.d.ts +10 -0
- package/types/ngwr-stepper.d.ts +47 -1
- package/types/ngwr-toolbar.d.ts +27 -0
- package/types/ngwr-transfer.d.ts +2 -0
- package/types/ngwr-utils.d.ts +61 -2
- package/types/ngwr-version.d.ts +1 -1
|
@@ -21,6 +21,9 @@
|
|
|
21
21
|
--wr-descriptions-label-letter-spacing: var(--wr-tracking-wide);
|
|
22
22
|
--wr-descriptions-value-font-size: var(--wr-text-sm);
|
|
23
23
|
--wr-descriptions-value-line-height: var(--wr-leading-normal);
|
|
24
|
+
// Written by an item with a `span`. Reset here so a list nested in an item's
|
|
25
|
+
// value does not inherit the span of the item around it.
|
|
26
|
+
--wr-descriptions-span: initial;
|
|
24
27
|
|
|
25
28
|
display: block;
|
|
26
29
|
font-family: var(--wr-descriptions-font-family);
|
|
@@ -142,6 +145,66 @@
|
|
|
142
145
|
background: var(--wr-color-fill);
|
|
143
146
|
border-inline-end: 1px solid var(--wr-descriptions-border);
|
|
144
147
|
}
|
|
148
|
+
|
|
149
|
+
// Columns. The list is a grid of equal tracks and every item is one cell,
|
|
150
|
+
// `span` wide. Each selector list below names the inline variants too, to
|
|
151
|
+
// outweigh the two-track grid those rules give the list. Child combinators
|
|
152
|
+
// keep a list nested in a cell out of the grid.
|
|
153
|
+
&--columns {
|
|
154
|
+
--wr-descriptions-list-column-gap: var(--wr-space-lg);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
&--columns > &__list,
|
|
158
|
+
&--columns#{&}--inline > &__list,
|
|
159
|
+
&--columns#{&}--bordered#{&}--inline > &__list {
|
|
160
|
+
display: grid;
|
|
161
|
+
grid-template-columns: repeat(var(--wr-descriptions-columns), minmax(0, 1fr));
|
|
162
|
+
align-items: stretch;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
&--columns > &__list > &__row {
|
|
166
|
+
grid-column: span var(--wr-descriptions-span, 1);
|
|
167
|
+
min-width: 0;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
// Inline: the item is a cell again rather than `display: contents`, with the
|
|
171
|
+
// label and value tracks of the one-column inline list inside it.
|
|
172
|
+
&--columns#{&}--inline > &__list > &__row,
|
|
173
|
+
&--columns#{&}--bordered#{&}--inline > &__list > &__row {
|
|
174
|
+
display: grid;
|
|
175
|
+
grid-template-columns: minmax(8rem, max-content) minmax(0, 1fr);
|
|
176
|
+
gap: 0 var(--wr-descriptions-list-column-gap);
|
|
177
|
+
align-items: baseline;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
// Bordered: the rules are each cell's outline, drawn in a 1px gap. Two
|
|
181
|
+
// neighbours share the gap, the list clips the outer edge under its own
|
|
182
|
+
// border, and a row a span leaves short keeps the rules of the cells around
|
|
183
|
+
// the empty track. A border could not: it would need to know its column.
|
|
184
|
+
&--columns#{&}--bordered > &__list,
|
|
185
|
+
&--columns#{&}--bordered#{&}--inline > &__list {
|
|
186
|
+
gap: 1px;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
&--columns#{&}--bordered > &__list > &__row {
|
|
190
|
+
outline: 1px solid var(--wr-descriptions-border);
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
&--columns#{&}--bordered > &__list > &__row + &__row,
|
|
194
|
+
&--columns#{&}--bordered#{&}--inline > &__list > &__row + &__row {
|
|
195
|
+
border-top: 0;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
&--columns#{&}--bordered#{&}--inline > &__list > &__row {
|
|
199
|
+
gap: 0;
|
|
200
|
+
padding: 0;
|
|
201
|
+
align-items: stretch;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
&--columns#{&}--bordered#{&}--inline > &__list > &__row > &__label,
|
|
205
|
+
&--columns#{&}--bordered#{&}--inline > &__list > &__row > &__value {
|
|
206
|
+
border-top: 0;
|
|
207
|
+
}
|
|
145
208
|
}
|
|
146
209
|
|
|
147
210
|
// When the descriptions box itself is narrow (not the viewport), inline modes
|
|
@@ -197,4 +260,32 @@
|
|
|
197
260
|
background: transparent;
|
|
198
261
|
border-inline-end: 0;
|
|
199
262
|
}
|
|
263
|
+
|
|
264
|
+
// A `columns` grid drops to one track, and a span with it, or the item
|
|
265
|
+
// would ask for tracks the list no longer has and push the box wide.
|
|
266
|
+
.wr-descriptions--columns > .wr-descriptions__list,
|
|
267
|
+
.wr-descriptions--columns.wr-descriptions--inline > .wr-descriptions__list,
|
|
268
|
+
.wr-descriptions--columns.wr-descriptions--bordered.wr-descriptions--inline > .wr-descriptions__list {
|
|
269
|
+
grid-template-columns: minmax(0, 1fr);
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
.wr-descriptions--columns > .wr-descriptions__list > .wr-descriptions__row {
|
|
273
|
+
grid-column: auto;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
.wr-descriptions--columns.wr-descriptions--inline > .wr-descriptions__list > .wr-descriptions__row,
|
|
277
|
+
.wr-descriptions--columns.wr-descriptions--bordered.wr-descriptions--inline
|
|
278
|
+
> .wr-descriptions__list
|
|
279
|
+
> .wr-descriptions__row {
|
|
280
|
+
display: flex;
|
|
281
|
+
flex-direction: column;
|
|
282
|
+
gap: var(--wr-descriptions-row-gap);
|
|
283
|
+
align-items: stretch;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
.wr-descriptions--columns.wr-descriptions--bordered.wr-descriptions--inline
|
|
287
|
+
> .wr-descriptions__list
|
|
288
|
+
> .wr-descriptions__row {
|
|
289
|
+
padding: var(--wr-descriptions-row-padding-y) var(--wr-descriptions-row-padding-x);
|
|
290
|
+
}
|
|
200
291
|
}
|
package/fesm2022/ngwr-anchor.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as i0 from "@angular/core";
|
|
2
|
-
import { Component, DestroyRef, NgZone, ViewEncapsulation, afterNextRender, computed, inject, input, signal } from "@angular/core";
|
|
2
|
+
import { Component, DestroyRef, Injector, NgZone, ViewEncapsulation, afterNextRender, computed, effect, inject, input, signal } from "@angular/core";
|
|
3
3
|
import { coerceNumberProperty } from "@angular/cdk/coercion";
|
|
4
4
|
import { DOCUMENT as DOCUMENT$1 } from "@angular/common";
|
|
5
5
|
import { wrCheckStyles } from "ngwr/utils";
|
|
@@ -12,6 +12,9 @@ import { WrScroll } from "ngwr/scroll";
|
|
|
12
12
|
* Use of this source code is governed by an MIT-style license that can be
|
|
13
13
|
* found in the LICENSE file at https://github.com/thekhegay/ngwr/blob/main/LICENSE
|
|
14
14
|
*/
|
|
15
|
+
function paddingTop(box) {
|
|
16
|
+
return box.getBoundingClientRect().top + box.clientTop;
|
|
17
|
+
}
|
|
15
18
|
var WrAnchor = class WrAnchor {
|
|
16
19
|
links = input([], ...ngDevMode ? [{ debugName: "links" }] : /* istanbul ignore next */ []);
|
|
17
20
|
ariaLabel = input(null, ...ngDevMode ? [{ debugName: "ariaLabel" }] : /* istanbul ignore next */ []);
|
|
@@ -24,6 +27,7 @@ var WrAnchor = class WrAnchor {
|
|
|
24
27
|
...ngDevMode ? { debugName: "hitArea" } : /* istanbul ignore next */ {},
|
|
25
28
|
transform: (v) => Math.max(0, coerceNumberProperty(v, 80))
|
|
26
29
|
});
|
|
30
|
+
container = input(null, ...ngDevMode ? [{ debugName: "container" }] : /* istanbul ignore next */ []);
|
|
27
31
|
activeId = signal(null, ...ngDevMode ? [{ debugName: "activeId" }] : /* istanbul ignore next */ []);
|
|
28
32
|
flatIds = computed(() => {
|
|
29
33
|
const out = [];
|
|
@@ -37,6 +41,7 @@ var WrAnchor = class WrAnchor {
|
|
|
37
41
|
platform = inject(WrPlatform);
|
|
38
42
|
doc = inject(DOCUMENT$1);
|
|
39
43
|
zone = inject(NgZone);
|
|
44
|
+
injector = inject(Injector);
|
|
40
45
|
destroyRef = inject(DestroyRef);
|
|
41
46
|
pinned = null;
|
|
42
47
|
lastY = 0;
|
|
@@ -44,7 +49,9 @@ var WrAnchor = class WrAnchor {
|
|
|
44
49
|
if (typeof ngDevMode === "undefined" || ngDevMode) wrCheckStyles("anchor");
|
|
45
50
|
if (!this.platform.isBrowser) return;
|
|
46
51
|
const measure = () => {
|
|
47
|
-
const
|
|
52
|
+
const box = this.container();
|
|
53
|
+
const y = box ? box.scrollTop : window.scrollY;
|
|
54
|
+
if (this.pinned && !this.flatIds().includes(this.pinned.id)) this.pinned = null;
|
|
48
55
|
const pin = this.pinned;
|
|
49
56
|
if (pin) {
|
|
50
57
|
const distance = Math.abs(pin.y - y);
|
|
@@ -56,7 +63,7 @@ var WrAnchor = class WrAnchor {
|
|
|
56
63
|
this.pinned = null;
|
|
57
64
|
}
|
|
58
65
|
this.lastY = y;
|
|
59
|
-
const cursor = this.offset() + this.hitArea();
|
|
66
|
+
const cursor = (box ? paddingTop(box) : 0) + this.offset() + this.hitArea();
|
|
60
67
|
let active = null;
|
|
61
68
|
for (const id of this.flatIds()) {
|
|
62
69
|
const el = document.getElementById(id);
|
|
@@ -74,12 +81,23 @@ var WrAnchor = class WrAnchor {
|
|
|
74
81
|
measure();
|
|
75
82
|
});
|
|
76
83
|
};
|
|
77
|
-
|
|
84
|
+
effect((onCleanup) => {
|
|
85
|
+
const source = this.container() ?? window;
|
|
86
|
+
this.pinned = null;
|
|
87
|
+
this.zone.runOutsideAngular(() => source.addEventListener("scroll", handler, { passive: true }));
|
|
88
|
+
onCleanup(() => source.removeEventListener("scroll", handler));
|
|
89
|
+
});
|
|
78
90
|
this.destroyRef.onDestroy(() => {
|
|
79
|
-
window.removeEventListener("scroll", handler);
|
|
80
91
|
if (frame) cancelAnimationFrame(frame);
|
|
81
92
|
});
|
|
82
93
|
afterNextRender(() => measure());
|
|
94
|
+
effect(() => {
|
|
95
|
+
this.container();
|
|
96
|
+
this.flatIds();
|
|
97
|
+
this.offset();
|
|
98
|
+
this.hitArea();
|
|
99
|
+
afterNextRender(() => measure(), { injector: this.injector });
|
|
100
|
+
});
|
|
83
101
|
}
|
|
84
102
|
hrefFor(id) {
|
|
85
103
|
const location = this.doc.location;
|
|
@@ -88,18 +106,23 @@ var WrAnchor = class WrAnchor {
|
|
|
88
106
|
onClick(id, event) {
|
|
89
107
|
if (event.button !== 0 || event.ctrlKey || event.metaKey || event.shiftKey || event.altKey) return;
|
|
90
108
|
event.preventDefault();
|
|
109
|
+
const box = this.container();
|
|
91
110
|
const target = document.getElementById(id);
|
|
92
111
|
if (target) {
|
|
93
|
-
const root = document.documentElement;
|
|
112
|
+
const root = box ?? document.documentElement;
|
|
94
113
|
const max = Math.max(0, root.scrollHeight - root.clientHeight);
|
|
95
|
-
const
|
|
114
|
+
const from = box ? box.scrollTop : window.scrollY;
|
|
115
|
+
const top = target.getBoundingClientRect().top - (box ? paddingTop(box) : 0);
|
|
96
116
|
this.pinned = {
|
|
97
117
|
id,
|
|
98
|
-
y: Math.min(max, Math.max(0,
|
|
118
|
+
y: Math.min(max, Math.max(0, top + from - this.offset()))
|
|
99
119
|
};
|
|
100
|
-
this.lastY =
|
|
120
|
+
this.lastY = from;
|
|
101
121
|
}
|
|
102
|
-
this.scroll.to(`#${id}`, {
|
|
122
|
+
this.scroll.to(`#${id}`, {
|
|
123
|
+
offset: this.offset(),
|
|
124
|
+
...box ? { container: box } : {}
|
|
125
|
+
});
|
|
103
126
|
this.activeId.set(id);
|
|
104
127
|
}
|
|
105
128
|
static ɵfac = i0.ɵɵngDeclareFactory({
|
|
@@ -144,6 +167,13 @@ var WrAnchor = class WrAnchor {
|
|
|
144
167
|
isSignal: true,
|
|
145
168
|
isRequired: false,
|
|
146
169
|
transformFunction: null
|
|
170
|
+
},
|
|
171
|
+
container: {
|
|
172
|
+
classPropertyName: "container",
|
|
173
|
+
publicName: "container",
|
|
174
|
+
isSignal: true,
|
|
175
|
+
isRequired: false,
|
|
176
|
+
transformFunction: null
|
|
147
177
|
}
|
|
148
178
|
},
|
|
149
179
|
host: {
|
|
@@ -207,6 +237,14 @@ i0.ɵɵngDeclareClassMetadata({
|
|
|
207
237
|
alias: "hitArea",
|
|
208
238
|
required: false
|
|
209
239
|
}]
|
|
240
|
+
}],
|
|
241
|
+
container: [{
|
|
242
|
+
type: i0.Input,
|
|
243
|
+
args: [{
|
|
244
|
+
isSignal: true,
|
|
245
|
+
alias: "container",
|
|
246
|
+
required: false
|
|
247
|
+
}]
|
|
210
248
|
}]
|
|
211
249
|
}
|
|
212
250
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ngwr-anchor.mjs","names":["DOCUMENT"],"sources":["../../../projects/lib/anchor/anchor.ts","../../../projects/lib/anchor/anchor.html"],"sourcesContent":["/**\n * @license\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://github.com/thekhegay/ngwr/blob/main/LICENSE\n */\n\nimport { coerceNumberProperty } from '@angular/cdk/coercion';\nimport { DOCUMENT } from '@angular/common';\nimport {\n Component,\n DestroyRef,\n NgZone,\n ViewEncapsulation,\n afterNextRender,\n computed,\n inject,\n input,\n signal,\n} from '@angular/core';\n\nimport { useI18nText } from 'ngwr/i18n';\nimport { WrPlatform } from 'ngwr/platform';\nimport { WrScroll } from 'ngwr/scroll';\nimport { wrCheckStyles } from 'ngwr/utils';\n\nimport type { WrAnchorLink } from './types';\n\n/**\n * Scroll-spy in-page navigation. Renders a list of links to elements on\n * the page; clicking a link smooth-scrolls (via {@link WrScroll}),\n * and the closest visible heading auto-highlights as the user scrolls.\n *\n * @example\n * ```html\n * <wr-anchor\n * [links]=\"[\n * { id: 'intro', label: 'Introduction' },\n * { id: 'usage', label: 'Usage', children: [\n * { id: 'basic', label: 'Basic' },\n * { id: 'advanced', label: 'Advanced' },\n * ]}\n * ]\"\n * [offset]=\"80\"\n * />\n * ```\n *\n * @see https://ngwr.dev/reference/components/anchor\n */\n@Component({\n selector: 'wr-anchor',\n templateUrl: './anchor.html',\n encapsulation: ViewEncapsulation.None,\n host: { class: 'wr-anchor', role: 'navigation', '[attr.aria-label]': 'resolvedAriaLabel()' },\n})\nexport class WrAnchor {\n /**\n * The entries, in DOCUMENT ORDER — the scroll spy walks them top to bottom\n * and stops at the first target below the cursor line, so a list in any other\n * order highlights the wrong entry.\n */\n readonly links = input<readonly WrAnchorLink[]>([]);\n\n /**\n * Accessible name for the navigation landmark. Falls back to `anchor.label`,\n * then `'Table of contents'` — it used to be that English string, hard-coded\n * on the host, in a landmark a screen reader reads out on every page.\n */\n readonly ariaLabel = input<string | null>(null);\n\n protected readonly resolvedAriaLabel = useI18nText(this.ariaLabel, 'anchor.label', 'Table of contents');\n\n /** Pixel offset subtracted on scroll — for sticky headers. @default 0 */\n readonly offset = input(0, { transform: (v: unknown): number => Math.max(0, coerceNumberProperty(v, 0)) });\n\n /** Highlight an item when its target's top is within this many px of the offset line. @default 80 */\n readonly hitArea = input(80, { transform: (v: unknown): number => Math.max(0, coerceNumberProperty(v, 80)) });\n\n protected readonly activeId = signal<string | null>(null);\n\n /**\n * Flat list of the ids the template RENDERS — top level plus one level of\n * children, which is the nesting `WrAnchorLink` documents. It used to recurse\n * all the way down, so a third level was spied on and drawn nowhere: scrolling\n * through a grandchild made it active, no rendered link matched the id, and\n * the highlight vanished for that whole region rather than resting on its\n * parent.\n */\n protected readonly flatIds = computed<readonly string[]>(() => {\n const out: string[] = [];\n for (const item of this.links()) {\n out.push(item.id);\n for (const child of item.children ?? []) out.push(child.id);\n }\n return out;\n });\n\n private readonly scroll = inject(WrScroll);\n private readonly platform = inject(WrPlatform);\n private readonly doc = inject(DOCUMENT);\n private readonly zone = inject(NgZone);\n private readonly destroyRef = inject(DestroyRef);\n\n /**\n * The entry a click asked for, and the scroll position that click sends the\n * page to. A target near the end of the page can never reach the cursor line —\n * the page runs out of scroll first — so the spy took the highlight straight\n * back from the entry just clicked and handed it to the one above. While the\n * page is still travelling toward that position, or parked on it, the clicked\n * entry stays lit; the first scroll AWAY from it is the reader's own, and the\n * spy takes over again.\n */\n private pinned: { readonly id: string; readonly y: number } | null = null;\n private lastY = 0;\n\n constructor() {\n if (typeof ngDevMode === 'undefined' || ngDevMode) wrCheckStyles('anchor');\n if (!this.platform.isBrowser) return;\n const measure = (): void => {\n const y = window.scrollY;\n const pin = this.pinned;\n if (pin) {\n const distance = Math.abs(pin.y - y);\n if (distance <= 1 || distance < Math.abs(pin.y - this.lastY)) {\n this.lastY = y;\n if (pin.id !== this.activeId()) this.zone.run(() => this.activeId.set(pin.id));\n return;\n }\n this.pinned = null;\n }\n this.lastY = y;\n const cursor = this.offset() + this.hitArea();\n let active: string | null = null;\n for (const id of this.flatIds()) {\n const el = document.getElementById(id);\n if (!el) continue;\n const top = el.getBoundingClientRect().top;\n if (top <= cursor) active = id;\n else break;\n }\n if (active !== this.activeId()) this.zone.run(() => this.activeId.set(active));\n };\n let frame = 0;\n const handler = (): void => {\n if (frame) return;\n frame = requestAnimationFrame(() => {\n frame = 0;\n measure();\n });\n };\n this.zone.runOutsideAngular(() => window.addEventListener('scroll', handler, { passive: true }));\n this.destroyRef.onDestroy(() => {\n window.removeEventListener('scroll', handler);\n if (frame) cancelAnimationFrame(frame);\n });\n // The first pass has to wait for a render: the targets are elsewhere on the\n // page and are usually rendered AFTER this list, so a constructor-time pass\n // found nothing by `getElementById` and left the page with no highlight at\n // all until the reader happened to scroll.\n afterNextRender(() => measure());\n }\n\n /** Carries the current path, so a `<base href>` cannot send copy link or a new tab to the site root. */\n protected hrefFor(id: string): string {\n const location = this.doc.location;\n return `${location?.pathname ?? ''}${location?.search ?? ''}#${id}`;\n }\n\n protected onClick(id: string, event: MouseEvent): void {\n if (event.button !== 0 || event.ctrlKey || event.metaKey || event.shiftKey || event.altKey) return;\n event.preventDefault();\n const target = document.getElementById(id);\n if (target) {\n // Where `WrScroll` sends the page, clamped the way the browser clamps it.\n const root = document.documentElement;\n const max = Math.max(0, root.scrollHeight - root.clientHeight);\n const y = target.getBoundingClientRect().top + window.scrollY - this.offset();\n this.pinned = { id, y: Math.min(max, Math.max(0, y)) };\n this.lastY = window.scrollY;\n }\n this.scroll.to(`#${id}`, { offset: this.offset() });\n this.activeId.set(id);\n }\n}\n\nexport type { WrAnchorLink } from './types';\n","<ul class=\"wr-anchor__list\">\n @for (link of links(); track link.id) {\n <li class=\"wr-anchor__item\">\n <a\n class=\"wr-anchor__link\"\n [class.wr-anchor__link--active]=\"activeId() === link.id\"\n [attr.aria-current]=\"activeId() === link.id ? 'location' : null\"\n [href]=\"hrefFor(link.id)\"\n (click)=\"onClick(link.id, $event)\"\n >\n {{ link.label }}\n </a>\n @if (link.children?.length) {\n <ul class=\"wr-anchor__list wr-anchor__list--nested\">\n @for (child of link.children; track child.id) {\n <li class=\"wr-anchor__item\">\n <a\n class=\"wr-anchor__link\"\n [class.wr-anchor__link--active]=\"activeId() === child.id\"\n [attr.aria-current]=\"activeId() === child.id ? 'location' : null\"\n [href]=\"hrefFor(child.id)\"\n (click)=\"onClick(child.id, $event)\"\n >\n {{ child.label }}\n </a>\n </li>\n }\n </ul>\n }\n </li>\n }\n</ul>\n"],"mappings":";;;;;;;;;;;;;;AAuDA,IAAa,WAAb,MAAa,SAAQ;CAMV,QAAQ,MAA+B,CAAA,GAAG,GAAA,YAAA,CAAA,EAAA,WAAA,QAAA,CAAA,+BAAA,CAAA,CAAA;CAO1C,YAAY,MAAqB,MAAK,GAAA,YAAA,CAAA,EAAA,WAAA,YAAA,CAAA,+BAAA,CAAA,CAAA;CAE5B,oBAAoB,YAAY,KAAK,WAAW,gBAAgB,mBAAmB;CAG7F,SAAS,MAAM,GAAC;EAAA,GAAA,YAAA,EAAA,WAAA,SAAA,+BAAA,CAAA;EAAI,YAAY,MAAuB,KAAK,IAAI,GAAG,qBAAqB,GA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AAE,QAAQ,KAAK,OAAM,EAAE,CAAE;EAClD,KAAK,SAAS,IAAI,EAAE;CACtB;CA/HW,OAAA,OAAA,GAAA,mBAAA;EAAA,YAAA;EAAA,SAAA;EAAA,UAAA;EAAA,MAAA;EAAQ,MAAA,CAAA;EAAA,QAAA,GAAA,gBAAA;CAAA,CAAA;CAAR,OAAA,OAAA,GAAA,qBAAA;EAAA,YAAA;EAAA,SAAA;EAAA,MAAA;EAAQ,cAAA;EAAA,UAAA;EAAA,QAAA;GAAA,OAAA;IAAA,mBAAA;IAAA,YAAA;IAAA,UAAA;IAAA,YAAA;IAAA,mBAAA;GAAA;GAAA,WAAA;IAAA,mBAAA;IAAA,YAAA;IAAA,UAAA;IAAA,YAAA;IAAA,mBAAA;GAAA;GAAA,QAAA;IAAA,mBAAA;IAAA,YAAA;IAAA,UAAA;IAAA,YAAA;IAAA,mBAAA;GAAA;GAAA,SAAA;IAAA,mBAAA;IAAA,YAAA;IAAA,UAAA;IAAA,YAAA;IAAA,mBAAA;GAAA;EAAA;EAAA,MAAA;GAAA,YAAA,EAAA,QAAA,aAAA;GAAA,YAAA,EAAA,mBAAA,sBAAA;GAAA,gBAAA;EAAA;EAAA,UAAA;EAAA,UCvDrB;EAgCA,eAAA,GAAA,kBAAA;CAAA,CAAA;;ADuBa,GAAA,yBAAA;CAAA,YAAA;CAAA,SAAA;CAAA,UAAA;CAAA,MAAA;CAAQ,YAAA,CAAA;EANpB,MAAA;EACW,MAAA,CAAA;GAAA,UAAA;GAAW,eAEN,kBAAkB;GAAI,MAC/B;IAAE,OAAO;IAAa,MAAM;IAAc,qBAAqB;GAAqB;GAAE,UAAA;EAAA,CAAA"}
|
|
1
|
+
{"version":3,"file":"ngwr-anchor.mjs","names":["DOCUMENT"],"sources":["../../../projects/lib/anchor/anchor.ts","../../../projects/lib/anchor/anchor.html"],"sourcesContent":["/**\n * @license\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://github.com/thekhegay/ngwr/blob/main/LICENSE\n */\n\nimport { coerceNumberProperty } from '@angular/cdk/coercion';\nimport { DOCUMENT } from '@angular/common';\nimport {\n Component,\n DestroyRef,\n NgZone,\n ViewEncapsulation,\n afterNextRender,\n Injector,\n computed,\n effect,\n inject,\n input,\n signal,\n} from '@angular/core';\n\nimport { useI18nText } from 'ngwr/i18n';\nimport { WrPlatform } from 'ngwr/platform';\nimport { WrScroll } from 'ngwr/scroll';\nimport { wrCheckStyles } from 'ngwr/utils';\n\nimport type { WrAnchorLink } from './types';\n\n/** The viewport top of a container's padding edge, where its scrolling starts. */\nfunction paddingTop(box: HTMLElement): number {\n return box.getBoundingClientRect().top + box.clientTop;\n}\n\n/**\n * Scroll-spy in-page navigation. Renders a list of links to elements on\n * the page; clicking a link smooth-scrolls (via {@link WrScroll}),\n * and the closest visible heading auto-highlights as the user scrolls.\n * Follows the window, or the element passed as `container`.\n *\n * @example\n * ```html\n * <wr-anchor\n * [links]=\"[\n * { id: 'intro', label: 'Introduction' },\n * { id: 'usage', label: 'Usage', children: [\n * { id: 'basic', label: 'Basic' },\n * { id: 'advanced', label: 'Advanced' },\n * ]}\n * ]\"\n * [offset]=\"80\"\n * />\n * ```\n *\n * @see https://ngwr.dev/reference/components/anchor\n */\n@Component({\n selector: 'wr-anchor',\n templateUrl: './anchor.html',\n encapsulation: ViewEncapsulation.None,\n host: { class: 'wr-anchor', role: 'navigation', '[attr.aria-label]': 'resolvedAriaLabel()' },\n})\nexport class WrAnchor {\n /**\n * The entries, in DOCUMENT ORDER — the scroll spy walks them top to bottom\n * and stops at the first target below the cursor line, so a list in any other\n * order highlights the wrong entry.\n */\n readonly links = input<readonly WrAnchorLink[]>([]);\n\n /**\n * Accessible name for the navigation landmark. Falls back to `anchor.label`,\n * then `'Table of contents'` — it used to be that English string, hard-coded\n * on the host, in a landmark a screen reader reads out on every page.\n */\n readonly ariaLabel = input<string | null>(null);\n\n protected readonly resolvedAriaLabel = useI18nText(this.ariaLabel, 'anchor.label', 'Table of contents');\n\n /** Pixel offset subtracted on scroll — for sticky headers. @default 0 */\n readonly offset = input(0, { transform: (v: unknown): number => Math.max(0, coerceNumberProperty(v, 0)) });\n\n /** Highlight an item when its target's top is within this many px of the offset line. @default 80 */\n readonly hitArea = input(80, { transform: (v: unknown): number => Math.max(0, coerceNumberProperty(v, 80)) });\n\n /**\n * The element whose scroll the links follow, for targets inside a pane with\n * its own scroll: a docs panel, a dialog body, a drawer. A click scrolls it\n * and leaves the page alone. `null` follows the window. @default null\n */\n readonly container = input<HTMLElement | null>(null);\n\n protected readonly activeId = signal<string | null>(null);\n\n /**\n * Flat list of the ids the template RENDERS — top level plus one level of\n * children, which is the nesting `WrAnchorLink` documents. It used to recurse\n * all the way down, so a third level was spied on and drawn nowhere: scrolling\n * through a grandchild made it active, no rendered link matched the id, and\n * the highlight vanished for that whole region rather than resting on its\n * parent.\n */\n protected readonly flatIds = computed<readonly string[]>(() => {\n const out: string[] = [];\n for (const item of this.links()) {\n out.push(item.id);\n for (const child of item.children ?? []) out.push(child.id);\n }\n return out;\n });\n\n private readonly scroll = inject(WrScroll);\n private readonly platform = inject(WrPlatform);\n private readonly doc = inject(DOCUMENT);\n private readonly zone = inject(NgZone);\n private readonly injector = inject(Injector);\n private readonly destroyRef = inject(DestroyRef);\n\n /**\n * The entry a click asked for, and the scroll position that click sends the\n * page (or the `container`) to. A target near the end of the page can never reach the cursor line —\n * the page runs out of scroll first — so the spy took the highlight straight\n * back from the entry just clicked and handed it to the one above. While the\n * page is still travelling toward that position, or parked on it, the clicked\n * entry stays lit; the first scroll AWAY from it is the reader's own, and the\n * spy takes over again.\n */\n private pinned: { readonly id: string; readonly y: number } | null = null;\n private lastY = 0;\n\n constructor() {\n if (typeof ngDevMode === 'undefined' || ngDevMode) wrCheckStyles('anchor');\n if (!this.platform.isBrowser) return;\n const measure = (): void => {\n const box = this.container();\n const y = box ? box.scrollTop : window.scrollY;\n if (this.pinned && !this.flatIds().includes(this.pinned.id)) this.pinned = null;\n const pin = this.pinned;\n if (pin) {\n const distance = Math.abs(pin.y - y);\n if (distance <= 1 || distance < Math.abs(pin.y - this.lastY)) {\n this.lastY = y;\n if (pin.id !== this.activeId()) this.zone.run(() => this.activeId.set(pin.id));\n return;\n }\n this.pinned = null;\n }\n this.lastY = y;\n // Measured from the container's padding edge, the way `WrScroll` lands a click.\n const cursor = (box ? paddingTop(box) : 0) + this.offset() + this.hitArea();\n let active: string | null = null;\n for (const id of this.flatIds()) {\n const el = document.getElementById(id);\n if (!el) continue;\n const top = el.getBoundingClientRect().top;\n if (top <= cursor) active = id;\n else break;\n }\n if (active !== this.activeId()) this.zone.run(() => this.activeId.set(active));\n };\n let frame = 0;\n const handler = (): void => {\n if (frame) return;\n frame = requestAnimationFrame(() => {\n frame = 0;\n measure();\n });\n };\n effect(onCleanup => {\n const source: HTMLElement | Window = this.container() ?? window;\n // A pin is a position in the scroll box it was taken in.\n this.pinned = null;\n this.zone.runOutsideAngular(() => source.addEventListener('scroll', handler, { passive: true }));\n onCleanup(() => source.removeEventListener('scroll', handler));\n });\n this.destroyRef.onDestroy(() => {\n if (frame) cancelAnimationFrame(frame);\n });\n // The first pass has to wait for a render: the targets are elsewhere on the\n // page and are usually rendered AFTER this list, so a constructor-time pass\n // found nothing by `getElementById` and left the page with no highlight at\n // all until the reader happened to scroll.\n afterNextRender(() => measure());\n // The entries, the cursor line, its height or the scroll container changing at\n // rest moves the answer with no scroll to ask for it.\n effect(() => {\n this.container();\n this.flatIds();\n this.offset();\n this.hitArea();\n afterNextRender(() => measure(), { injector: this.injector });\n });\n }\n\n /** Carries the current path, so a `<base href>` cannot send copy link or a new tab to the site root. */\n protected hrefFor(id: string): string {\n const location = this.doc.location;\n return `${location?.pathname ?? ''}${location?.search ?? ''}#${id}`;\n }\n\n protected onClick(id: string, event: MouseEvent): void {\n if (event.button !== 0 || event.ctrlKey || event.metaKey || event.shiftKey || event.altKey) return;\n event.preventDefault();\n const box = this.container();\n const target = document.getElementById(id);\n if (target) {\n // Where `WrScroll` sends the page or the container, clamped the way the browser clamps it.\n const root = box ?? document.documentElement;\n const max = Math.max(0, root.scrollHeight - root.clientHeight);\n const from = box ? box.scrollTop : window.scrollY;\n const top = target.getBoundingClientRect().top - (box ? paddingTop(box) : 0);\n this.pinned = { id, y: Math.min(max, Math.max(0, top + from - this.offset())) };\n this.lastY = from;\n }\n this.scroll.to(`#${id}`, { offset: this.offset(), ...(box ? { container: box } : {}) });\n this.activeId.set(id);\n }\n}\n\nexport type { WrAnchorLink } from './types';\n","<ul class=\"wr-anchor__list\">\n @for (link of links(); track link.id) {\n <li class=\"wr-anchor__item\">\n <a\n class=\"wr-anchor__link\"\n [class.wr-anchor__link--active]=\"activeId() === link.id\"\n [attr.aria-current]=\"activeId() === link.id ? 'location' : null\"\n [href]=\"hrefFor(link.id)\"\n (click)=\"onClick(link.id, $event)\"\n >\n {{ link.label }}\n </a>\n @if (link.children?.length) {\n <ul class=\"wr-anchor__list wr-anchor__list--nested\">\n @for (child of link.children; track child.id) {\n <li class=\"wr-anchor__item\">\n <a\n class=\"wr-anchor__link\"\n [class.wr-anchor__link--active]=\"activeId() === child.id\"\n [attr.aria-current]=\"activeId() === child.id ? 'location' : null\"\n [href]=\"hrefFor(child.id)\"\n (click)=\"onClick(child.id, $event)\"\n >\n {{ child.label }}\n </a>\n </li>\n }\n </ul>\n }\n </li>\n }\n</ul>\n"],"mappings":";;;;;;;;;;;;;;AA+BA,SAAS,WAAW,KAAgB;CAClC,OAAO,IAAI,sBAAqB,CAAE,CAAC,MAAM,IAAI;AAC/C;AA8BA,IAAa,WAAb,MAAa,SAAQ;CAMV,QAAQ,MAA+B,CAAA,GAAG,GAAA,YAAA,CAAA,EAAA,WAAA,QAAA,CAAA,+BAAA,CAAA,CAAA;CAO1C,YAAY,MAAqB,MAAK,GAAA,YAAA,CAAA,EAAA,WAAA,YAAA,CAAA,+BAAA,CAAA,CAAA;CAE5B,oBAAoB,YAAY,KAAK,WAAW,gBAAgB,mBAAmB;C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AAA,YAAA;IAAA,UAAA;IAAA,YAAA;IAAA,mBAAA;GAAA;GAAA,QAAA;IAAA,mBAAA;IAAA,YAAA;IAAA,UAAA;IAAA,YAAA;IAAA,mBAAA;GAAA;GAAA,SAAA;IAAA,mBAAA;IAAA,YAAA;IAAA,UAAA;IAAA,YAAA;IAAA,mBAAA;GAAA;GAAA,WAAA;IAAA,mBAAA;IAAA,YAAA;IAAA,UAAA;IAAA,YAAA;IAAA,mBAAA;GAAA;EAAA;EAAA,MAAA;GAAA,YAAA,EAAA,QAAA,aAAA;GAAA,YAAA,EAAA,mBAAA,sBAAA;GAAA,gBAAA;EAAA;EAAA,UAAA;EAAA,UC/DrB;EAgCA,eAAA,GAAA,kBAAA;CAAA,CAAA;;AD+Ba,GAAA,yBAAA;CAAA,YAAA;CAAA,SAAA;CAAA,UAAA;CAAA,MAAA;CAAQ,YAAA,CAAA;EANpB,MAAA;EACW,MAAA,CAAA;GAAA,UAAA;GAAW,eAEN,kBAAkB;GAAI,MAC/B;IAAE,OAAO;IAAa,MAAM;IAAc,qBAAqB;GAAqB;GAAE,UAAA;EAAA,CAAA"}
|
|
@@ -191,8 +191,9 @@ var WrCarousel = class WrCarousel {
|
|
|
191
191
|
effect(() => {
|
|
192
192
|
const max = this.count() - 1;
|
|
193
193
|
if (max < 0) return;
|
|
194
|
-
const
|
|
195
|
-
|
|
194
|
+
const current = this.active();
|
|
195
|
+
const clamped = Number.isFinite(current) ? Math.min(Math.max(0, Math.floor(current)), max) : 0;
|
|
196
|
+
if (clamped !== current) this.active.set(clamped);
|
|
196
197
|
});
|
|
197
198
|
this.destroyRef.onDestroy(() => {
|
|
198
199
|
if (this.timer) clearInterval(this.timer);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ngwr-carousel.mjs","names":[],"sources":["../../../projects/lib/carousel/tokens/carousel.token.ts","../../../projects/lib/carousel/carousel-slide.ts","../../../projects/lib/carousel/carousel.ts","../../../projects/lib/carousel/carousel.html"],"sourcesContent":["/**\n * @license\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://github.com/thekhegay/ngwr/blob/main/LICENSE\n */\n\nimport { InjectionToken } from '@angular/core';\n\nimport type { WrCarouselContext } from '../types';\n\n/** Token a `<wr-carousel-slide>` injects to find its parent `<wr-carousel>`. */\nexport const WR_CAROUSEL = new InjectionToken<WrCarouselContext>('WR_CAROUSEL');\n","/**\n * @license\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://github.com/thekhegay/ngwr/blob/main/LICENSE\n */\n\nimport { Component, ViewEncapsulation, computed, inject, input } from '@angular/core';\n\nimport { useI18nText } from 'ngwr/i18n';\nimport { wrCheckStyles } from 'ngwr/utils';\n\nimport { WR_CAROUSEL } from './tokens';\n\n/**\n * One slide in a {@link WrCarousel}. Holds whatever content you\n * project — image, card, video, anything.\n *\n * **An off-screen slide is `inert`.** Only one slide is visible, but the track\n * merely translates the others out of view: without this they stay in the tab\n * order and in the accessibility tree, so a keyboard user tabs into a link they\n * cannot see and a screen reader announces every slide as if they were all on\n * screen. `inert` takes the whole subtree out of both at once, which is why it\n * is preferred here over `tabindex=\"-1\"` (which reaches only the host) — the\n * same answer `wr-collapse` uses.\n *\n * `aria-hidden` rides along: it states the intent for anything reading the attribute\n * rather than honouring `inert`.\n */\n@Component({\n selector: 'wr-carousel-slide',\n template: '<ng-content />',\n encapsulation: ViewEncapsulation.None,\n host: {\n class: 'wr-carousel-slide',\n role: 'group',\n '[attr.aria-roledescription]': 'resolvedRoledescription()',\n '[attr.inert]': 'offScreen() ? \"\" : null',\n '[attr.aria-hidden]': 'offScreen() ? \"true\" : null',\n },\n})\nexport class WrCarouselSlide {\n constructor() {\n if (typeof ngDevMode === 'undefined' || ngDevMode) wrCheckStyles('carousel');\n }\n\n private readonly carousel = inject(WR_CAROUSEL, { optional: true });\n\n /**\n * Word a screen reader speaks IN PLACE OF the `group` role. Falls back to\n * `carousel.slideRoledescription`, then `'slide'`.\n */\n readonly roledescription = input<string | null>(null);\n\n // Spoken verbatim, and only the off-screen slides are `inert` — so the visible\n // one announced an English \"slide\" inside an otherwise localized carousel.\n protected readonly resolvedRoledescription = useI18nText(\n this.roledescription,\n 'carousel.slideRoledescription',\n 'slide'\n );\n\n /**\n * Whether this slide is one of the ones translated out of view.\n *\n * `false` while the index is `-1`: content children resolve after the first\n * render, and a slide that hid itself in that window would make the carousel\n * open with everything inert. `false` too when there is no parent — the\n * component is exported, so it can be used on its own.\n */\n protected readonly offScreen = computed(() => {\n if (!this.carousel) return false;\n const index = this.carousel.indexOf(this);\n return index >= 0 && index !== this.carousel.active();\n });\n}\n","/**\n * @license\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://github.com/thekhegay/ngwr/blob/main/LICENSE\n */\n\nimport { Directionality } from '@angular/cdk/bidi';\nimport { coerceBooleanProperty, coerceNumberProperty } from '@angular/cdk/coercion';\nimport { isPlatformBrowser } from '@angular/common';\nimport {\n Component,\n DestroyRef,\n PLATFORM_ID,\n ViewEncapsulation,\n computed,\n contentChildren,\n forwardRef,\n effect,\n inject,\n input,\n model,\n signal,\n} from '@angular/core';\n\nimport { useI18nFormatter, useI18nText } from 'ngwr/i18n';\nimport { WrPlatform } from 'ngwr/platform';\nimport { wrCheckStyles } from 'ngwr/utils';\n\nimport { WrCarouselSlide } from './carousel-slide';\nimport { WR_CAROUSEL } from './tokens';\nimport type { WrCarouselContext } from './types';\n\n/**\n * How far a touch travels before the carousel decides whether it is a swipe or a\n * scroll — the usual touch slop, so a finger's first wobble decides nothing.\n */\nconst SWIPE_SLOP = 10;\n\n/**\n * Slide carousel. Project `<wr-carousel-slide>` children — the carousel\n * snaps between them with prev/next buttons and optional dots / autoplay.\n *\n * @example\n * ```html\n * <wr-carousel [(active)]=\"i\" autoplay>\n * <wr-carousel-slide><img src=\"a.jpg\" /></wr-carousel-slide>\n * <wr-carousel-slide><img src=\"b.jpg\" /></wr-carousel-slide>\n * <wr-carousel-slide><img src=\"c.jpg\" /></wr-carousel-slide>\n * </wr-carousel>\n * ```\n *\n * @see https://ngwr.dev/reference/components/carousel\n */\n@Component({\n selector: 'wr-carousel',\n templateUrl: './carousel.html',\n encapsulation: ViewEncapsulation.None,\n // On the HOST, not the viewport: the arrows and dots are the viewport's siblings, so\n // viewport-scoped listeners let a slide change under a cursor aiming at an arrow.\n // `focusin` / `focusout` are the keyboard half — WCAG 2.2.2 wants a way to stop\n // moving content, and hovering is not one for someone who never uses a mouse.\n host: {\n class: 'wr-carousel',\n '(mouseenter)': 'onHoverIn()',\n '(mouseleave)': 'onHoverOut()',\n '(focusin)': 'onFocusIn()',\n '(focusout)': 'onFocusOut()',\n },\n providers: [\n {\n provide: WR_CAROUSEL,\n // eslint-disable-next-line @angular-eslint/no-forward-ref\n useExisting: forwardRef(() => WrCarousel),\n },\n ],\n})\nexport class WrCarousel implements WrCarouselContext {\n /** Accessible name of the previous-slide button. Falls back to `carousel.prev`. */\n readonly prevLabel = input<string | null>(null);\n\n /** Accessible name of the next-slide button. Falls back to `carousel.next`. */\n readonly nextLabel = input<string | null>(null);\n\n /** Accessible name of the dot group. Falls back to `carousel.pagination`. */\n readonly paginationLabel = input<string | null>(null);\n\n protected readonly resolvedPrevLabel = useI18nText(this.prevLabel, 'carousel.prev', 'Previous slide');\n protected readonly resolvedNextLabel = useI18nText(this.nextLabel, 'carousel.next', 'Next slide');\n protected readonly resolvedPaginationLabel = useI18nText(\n this.paginationLabel,\n 'carousel.pagination',\n 'Carousel pagination'\n );\n\n /** Accessible name of the carousel itself. Falls back to `carousel.label`. */\n readonly ariaLabel = input<string | null>(null);\n\n protected readonly resolvedAriaLabel = useI18nText(this.ariaLabel, 'carousel.label', 'Carousel');\n\n /**\n * Word a screen reader speaks IN PLACE OF the `group` role. Falls back to\n * `carousel.roledescription`, then `'carousel'`.\n */\n readonly roledescription = input<string | null>(null);\n\n // Routed for the same reason the name above is: `aria-roledescription` is spoken\n // verbatim, so a static English \"carousel\" made the viewport announce\n // \"Карусель, carousel\" with the localized arrows right beside it.\n protected readonly resolvedRoledescription = useI18nText(\n this.roledescription,\n 'carousel.roledescription',\n 'carousel'\n );\n\n // The three labels above route through the catalog; this one was a hard-coded\n // English template, so a localized app got two languages in one pagination strip.\n protected readonly slideLabel = useI18nFormatter('carousel.goToSlide', 'Go to slide {{index}}');\n\n /** Name of the autoplay button while the slides advance. Falls back to `marquee.pause`, \"Pause\" in English. */\n readonly pauseLabel = input<string | null>(null);\n\n /** Name of the autoplay button while the slides stand. Falls back to `marquee.play`, \"Play\" in English. */\n readonly playLabel = input<string | null>(null);\n\n // The marquee's pair: the same two words on the same kind of button.\n protected readonly resolvedPauseLabel = useI18nText(this.pauseLabel, 'marquee.pause', 'Pause');\n protected readonly resolvedPlayLabel = useI18nText(this.playLabel, 'marquee.play', 'Play');\n\n private readonly positionText = useI18nFormatter('carousel.position', 'Slide {{current}} of {{total}}');\n\n /** Active slide index. Two-way bindable. @default 0 */\n readonly active = model(0);\n\n /** Show prev / next arrow buttons. @default true */\n readonly showArrows = input(true, { transform: coerceBooleanProperty });\n\n /** Show dot indicators below the slides. @default true */\n readonly showDots = input(true, { transform: coerceBooleanProperty });\n\n /**\n * Auto-advance slides. Held while the pointer or keyboard focus is inside the\n * carousel and during a swipe. While the reader prefers reduced motion it does\n * not start until they press play. Turn on `pauseButton` to let readers stop\n * it. @default false\n */\n readonly autoplay = input(false, { transform: coerceBooleanProperty });\n\n /**\n * Draw a pause / play button while `autoplay` is on. WCAG 2.2.2 asks for a way\n * to pause moving content, so turn it on with autoplay. @default false\n */\n readonly pauseButton = input(false, { transform: coerceBooleanProperty });\n\n /** Autoplay interval (ms). @default 4000 */\n readonly intervalMs = input(4000, {\n transform: (v: unknown): number => Math.max(500, coerceNumberProperty(v, 4000)),\n });\n\n /** Wrap around at the ends. @default true */\n readonly loop = input(true, { transform: coerceBooleanProperty });\n\n protected readonly slides = contentChildren(WrCarouselSlide);\n protected readonly count = computed(() => this.slides().length);\n\n /**\n * Whether an arrow has nowhere to go: only without `loop`, at the matching end.\n * The arrows used to stay enabled there and do nothing — announced, focusable\n * and clickable controls with no effect. Native `disabled`, the way\n * `wr-pagination` stops its own previous / next at the ends.\n */\n protected readonly atStart = computed(() => !this.loop() && this.active() <= 0);\n protected readonly atEnd = computed(() => !this.loop() && this.active() >= this.count() - 1);\n\n /**\n * Where a slide sits in projection order — {@link WrCarouselContext}.\n *\n * Public only because the child injects the parent through `WR_CAROUSEL`;\n * reading `slides()` here is what makes the child's `computed()` re-run when a\n * slide is added or removed.\n */\n indexOf(slide: object): number {\n return this.slides().indexOf(slide as WrCarouselSlide);\n }\n\n /** Live horizontal drag offset (px) during a touch swipe. */\n protected readonly dragX = signal(0);\n protected readonly dragging = signal(false);\n\n private readonly dir = inject(Directionality, { optional: true });\n\n /**\n * Reading direction of the track. `Directionality` is root-provided, so this\n * always resolves — `optional` only guards a consumer who has deliberately\n * torn the provider out. It reads the document once at construction; a\n * subtree that overrides the direction does it with the CDK's `Dir`\n * directive, which writes `valueSignal`, so `trackStyle` re-renders instead\n * of leaving the track parked on the old side.\n */\n private readonly isRtl = computed(() => this.dir?.valueSignal() === 'rtl');\n\n /** CSS transform for the track — the per-slide offset plus any live drag. */\n protected readonly trackStyle = computed(() => {\n // `translateX` is PHYSICAL while the slides are laid out on the inline axis:\n // under `dir=\"rtl\"` the flex track runs right-to-left, so slide 1 sits to the\n // LEFT of slide 0 and reaching it means moving the track the other way. Left\n // unsigned, every RTL carousel translated itself off into blank space.\n const base = (this.isRtl() ? 1 : -1) * this.active() * 100;\n // The drag stays physical on purpose: it is the finger's own displacement,\n // and the track follows the finger in both directions.\n const drag = this.dragX();\n return drag === 0 ? `translateX(${base}%)` : `translateX(calc(${base}% + ${drag}px))`;\n });\n\n private timer: ReturnType<typeof setInterval> | null = null;\n\n // Three sources hold the pause and they release independently, so they get a\n // flag each rather than one shared boolean — the same `hovered` / `focusWithin`\n // pair `WrToastHost` keeps. With one flag whichever source released LAST won:\n // moving the pointer off the carousel while focus was still on a link inside it\n // restarted the slides under the focused element, and a `touchend` released a\n // pause it had never taken. Flags, not a counter: `mouseenter`/`mouseleave` and\n // `focusin`/`focusout` each pair exactly once per source, so a count would only\n // add a way to drift out of step.\n private readonly hovered = signal(false);\n private readonly focusWithin = signal(false);\n private readonly paused = computed(() => this.hovered() || this.focusWithin() || this.dragging());\n\n /**\n * Autoplay is motion the reader did not start, which is exactly what\n * `prefers-reduced-motion` asks a page to drop: the stylesheet already switches\n * slides in place under it, and a panel that still changed every four seconds\n * was the half that stylesheet cannot reach. A signal, so the preference is\n * followed while the page is open, until the reader presses the button: a\n * press is an explicit answer and outranks the preference.\n */\n private readonly reducedMotion = inject(WrPlatform).prefersReducedMotion;\n\n /** What the reader last asked of the pause button, `null` until it is pressed. */\n private readonly asked = signal<'play' | 'pause' | null>(null);\n\n /** Whether autoplay is switched on, holds aside: what the button's name and glyph follow. */\n protected readonly playing = computed(() => {\n const asked = this.asked();\n return this.autoplay() && (asked === null ? !this.reducedMotion() : asked === 'play');\n });\n\n /** The slides are advancing on their own right now. */\n protected readonly rotating = computed(() => this.isBrowser && this.playing() && !this.paused() && this.count() > 1);\n\n /**\n * Text of the live region: the position after a move the reader made. Empty\n * after an autoplay tick, so the same position can be said again later.\n */\n protected readonly announcement = signal('');\n\n private readonly destroyRef = inject(DestroyRef);\n private readonly isBrowser = isPlatformBrowser(inject(PLATFORM_ID));\n\n constructor() {\n if (typeof ngDevMode === 'undefined' || ngDevMode) wrCheckStyles('carousel');\n effect(() => {\n if (this.timer) clearInterval(this.timer);\n this.timer = null;\n // `isBrowser` first: without it the prerender ran the timer too, doing work\n // nobody will ever see on a slide index that then gets serialized.\n if (!this.rotating()) return;\n const interval = this.intervalMs();\n this.timer = setInterval(() => {\n this.move(this.active() + 1);\n this.announcement.set('');\n }, interval);\n });\n\n // `active` is a plain `model`, so `[(active)]` and a shrinking slide list both\n // write into it unchecked — a filtered list left it pointing past the end,\n // translating the track into blank space with no dot lit.\n effect(() => {\n const max = this.count() - 1;\n if (max < 0) return;\n const clamped = Math.min(Math.max(0, this.active()), max);\n if (clamped !== this.active()) this.active.set(clamped);\n });\n\n this.destroyRef.onDestroy(() => {\n if (this.timer) clearInterval(this.timer);\n });\n }\n\n protected onHoverIn(): void {\n this.hovered.set(true);\n }\n\n protected onHoverOut(): void {\n this.hovered.set(false);\n }\n\n protected onFocusIn(): void {\n this.focusWithin.set(true);\n }\n\n protected onFocusOut(): void {\n this.focusWithin.set(false);\n }\n\n /**\n * The pause button. Play also lets go of the hover and focus holds in force:\n * the press came from inside the carousel, so they would keep the slides still\n * after the reader asked for them to move. Each hold comes back with the next\n * `focusin` or `mouseenter`.\n */\n protected toggleAutoplay(): void {\n if (this.playing()) {\n this.asked.set('pause');\n return;\n }\n this.asked.set('play');\n this.hovered.set(false);\n this.focusWithin.set(false);\n }\n\n // Imperative\n\n /** Show a slide, and announce its position: an autoplay tick is the only silent move. */\n goTo(index: number): void {\n const before = this.active();\n this.move(index);\n const current = this.active();\n if (current !== before) this.announcement.set(this.positionText({ current: current + 1, total: this.count() }));\n }\n\n private move(index: number): void {\n const max = this.count() - 1;\n if (max < 0) return;\n if (this.loop()) {\n const next = ((index % this.count()) + this.count()) % this.count();\n this.active.set(next);\n } else {\n this.active.set(Math.min(Math.max(0, index), max));\n }\n }\n\n next(): void {\n this.goTo(this.active() + 1);\n }\n\n prev(): void {\n this.goTo(this.active() - 1);\n }\n\n // Swipe navigation — the track follows the finger; releasing past ~20% of the\n // viewport advances a slide, otherwise snaps back. Which way that is follows\n // the reading direction: dragging toward the inline start (left in LTR, right\n // in RTL) pulls the next slide into view.\n\n private swipeStartX = 0;\n private swipeStartY = 0;\n\n /**\n * Which way the finger is going, decided once it has moved {@link SWIPE_SLOP}\n * px: `'x'` is a swipe, `'y'` a page scroll that happened to start on a slide.\n * Without the lock every vertical scroll that drifted sideways dragged the\n * track along and, past 20% of the width, changed the slide under it.\n */\n private swipeAxis: 'x' | 'y' | null = null;\n\n protected onSwipeStart(event: TouchEvent): void {\n const touch = event.touches[0];\n if (!touch) return;\n this.swipeStartX = touch.clientX;\n this.swipeStartY = touch.clientY;\n this.swipeAxis = null;\n this.dragging.set(true); // holds autoplay on its own — `paused` reads it\n }\n\n protected onSwipeMove(event: TouchEvent): void {\n if (!this.dragging()) return;\n const touch = event.touches[0];\n if (!touch) return;\n const dx = touch.clientX - this.swipeStartX;\n const dy = touch.clientY - this.swipeStartY;\n if (this.swipeAxis === null) {\n if (Math.abs(dx) < SWIPE_SLOP && Math.abs(dy) < SWIPE_SLOP) return;\n this.swipeAxis = Math.abs(dx) > Math.abs(dy) ? 'x' : 'y';\n }\n if (this.swipeAxis === 'x') this.dragX.set(dx);\n }\n\n /** The browser took the touch over (a scroll, a system gesture): drop the drag, never navigate. */\n protected onSwipeCancel(): void {\n if (!this.dragging()) return;\n this.dragging.set(false);\n this.swipeAxis = null;\n this.dragX.set(0);\n }\n\n protected onSwipeEnd(event: TouchEvent, viewport: HTMLElement): void {\n if (!this.dragging()) return;\n this.dragging.set(false);\n const dx = this.swipeAxis === 'x' ? this.dragX() : 0;\n this.swipeAxis = null;\n this.dragX.set(0);\n const threshold = (viewport.offsetWidth || 0) * 0.2;\n // `dx` is a physical delta. The next slide sits to the physical RIGHT in LTR\n // and to the LEFT in RTL, so the drag that pulls it into view — and with it\n // the sign that advances — turns around with the direction. The buttons keep\n // their semantics either way; only the gesture is physical.\n const advance = this.isRtl() ? dx >= threshold : dx <= -threshold;\n const retreat = this.isRtl() ? dx <= -threshold : dx >= threshold;\n if (advance) this.next();\n else if (retreat) this.prev();\n }\n}\n","<!--\n First in the DOM, so it is the first tab stop of the carousel: the way to stop\n the slides comes before the slides. Named for what a press does next.\n-->\n@if (autoplay() && pauseButton() && count() > 1) {\n <button\n type=\"button\"\n class=\"wr-carousel__toggle\"\n [attr.aria-label]=\"playing() ? resolvedPauseLabel() : resolvedPlayLabel()\"\n (click)=\"toggleAutoplay()\"\n >\n @if (playing()) {\n <svg width=\"14\" height=\"14\" viewBox=\"0 0 24 24\" fill=\"currentColor\" aria-hidden=\"true\">\n <rect x=\"5\" y=\"4\" width=\"5\" height=\"16\" rx=\"1\" />\n <rect x=\"14\" y=\"4\" width=\"5\" height=\"16\" rx=\"1\" />\n </svg>\n } @else {\n <svg width=\"14\" height=\"14\" viewBox=\"0 0 24 24\" fill=\"currentColor\" aria-hidden=\"true\">\n <path d=\"M6 4.5a1 1 0 0 1 1.52-.86l12 7.5a1 1 0 0 1 0 1.72l-12 7.5A1 1 0 0 1 6 19.5z\" />\n </svg>\n }\n </button>\n}\n\n<div\n #viewport\n class=\"wr-carousel__viewport\"\n role=\"group\"\n [attr.aria-roledescription]=\"resolvedRoledescription()\"\n [attr.aria-label]=\"resolvedAriaLabel()\"\n (touchstart)=\"onSwipeStart($event)\"\n (touchmove)=\"onSwipeMove($event)\"\n (touchend)=\"onSwipeEnd($event, viewport)\"\n (touchcancel)=\"onSwipeCancel()\"\n>\n <div class=\"wr-carousel__track\" [style.transform]=\"trackStyle()\" [style.transition]=\"dragging() ? 'none' : null\">\n <ng-content />\n </div>\n</div>\n\n@if (showArrows() && count() > 1) {\n <button\n type=\"button\"\n class=\"wr-carousel__nav wr-carousel__nav--prev\"\n [attr.aria-label]=\"resolvedPrevLabel()\"\n [disabled]=\"atStart()\"\n (click)=\"prev()\"\n >\n <svg width=\"14\" height=\"14\" viewBox=\"0 0 14 14\" aria-hidden=\"true\">\n <path d=\"M9 2 L4 7 L9 12\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" />\n </svg>\n </button>\n <button\n type=\"button\"\n class=\"wr-carousel__nav wr-carousel__nav--next\"\n [attr.aria-label]=\"resolvedNextLabel()\"\n [disabled]=\"atEnd()\"\n (click)=\"next()\"\n >\n <svg width=\"14\" height=\"14\" viewBox=\"0 0 14 14\" aria-hidden=\"true\">\n <path d=\"M5 2 L10 7 L5 12\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" />\n </svg>\n </button>\n}\n\n@if (showDots() && count() > 1) {\n <div class=\"wr-carousel__dots\" role=\"group\" [attr.aria-label]=\"resolvedPaginationLabel()\">\n @for (slide of slides(); track $index) {\n <button\n type=\"button\"\n class=\"wr-carousel__dot\"\n [class.wr-carousel__dot--active]=\"$index === active()\"\n [attr.aria-current]=\"$index === active() ? 'true' : null\"\n [attr.aria-label]=\"slideLabel({ index: $index + 1 })\"\n (click)=\"goTo($index)\"\n ></button>\n }\n </div>\n}\n\n<!--\n One live region for the whole carousel, in the DOM before its text changes.\n Off while the slides advance on their own, as the WAI-ARIA carousel pattern has it.\n-->\n<div class=\"wr-carousel__live\" aria-atomic=\"true\" [attr.aria-live]=\"rotating() ? 'off' : 'polite'\">\n {{ announcement() }}\n</div>\n"],"mappings":";;;;;;;;;;;;;;AAYA,MAAa,cAAc,IAAI,eAAkC,aAAa;;;;;;;AC6B9E,IAAa,kBAAb,MAAa,gBAAe;CAC1B,cAAA;EACE,IAAI,OAAO,cAAc,eAAe,WAAW,cAAc,UAAU;CAC7E;CAEiB,WAAW,OAAO,aAAa,EAAE,UAAU,KAAI,CAAE;CAMzD,kBAAkB,MAAqB,MAAK,GAAA,YAAA,CAAA,EAAA,WAAA,kBAAA,CAAA,+BAAA,CAAA,CAAA;CAIlC,0BAA0B,YAC3C,KAAK,iBACL,iCACA,OAAO;CAWU,YAAY,eAAc;EAC3C,IAAI,CAAC,KAAK,UAAU,OAAO;EAC3B,MAAM,QAAQ,KAAK,SAAS,QAAQ,IAAI;EACxC,OAAO,SAAS,KAAK,UAAU,KAAK,SAAS,OAAM;CACrD,GAAE,GAAA,YAAA,CAAA,EAAA,WAAA,YAAA,CAAA,+BAAA,CAAA,CAAA;CAjCS,OAAA,OAAA,GAAA,mBAAA;EAAA,YAAA;EAAA,SAAA;EAAA,UAAA;EAAA,MAAA;EAAe,MAAA,CAAA;EAAA,QAAA,GAAA,gBAAA;CAAA,CAAA;CAAf,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A,GAAA;GAAA,MAAA,CAAA;IAAA,UAAA;IAAA,OAAA;IAAA,UAAA;GAAA,CAAA;EAAA,CAAA;EAAA,QAAA,CAAA;GAAA,MAAA,GAAA;GAAA,MAAA,CAAA,GAAA,iBAAA,eAAe,GAAA,EAAA,UAAA,KAAA,CAAA;EAAA,CAAA;CAAA;AAAA,CAAA"}
|
|
1
|
+
{"version":3,"file":"ngwr-carousel.mjs","names":[],"sources":["../../../projects/lib/carousel/tokens/carousel.token.ts","../../../projects/lib/carousel/carousel-slide.ts","../../../projects/lib/carousel/carousel.ts","../../../projects/lib/carousel/carousel.html"],"sourcesContent":["/**\n * @license\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://github.com/thekhegay/ngwr/blob/main/LICENSE\n */\n\nimport { InjectionToken } from '@angular/core';\n\nimport type { WrCarouselContext } from '../types';\n\n/** Token a `<wr-carousel-slide>` injects to find its parent `<wr-carousel>`. */\nexport const WR_CAROUSEL = new InjectionToken<WrCarouselContext>('WR_CAROUSEL');\n","/**\n * @license\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://github.com/thekhegay/ngwr/blob/main/LICENSE\n */\n\nimport { Component, ViewEncapsulation, computed, inject, input } from '@angular/core';\n\nimport { useI18nText } from 'ngwr/i18n';\nimport { wrCheckStyles } from 'ngwr/utils';\n\nimport { WR_CAROUSEL } from './tokens';\n\n/**\n * One slide in a {@link WrCarousel}. Holds whatever content you\n * project — image, card, video, anything.\n *\n * **An off-screen slide is `inert`.** Only one slide is visible, but the track\n * merely translates the others out of view: without this they stay in the tab\n * order and in the accessibility tree, so a keyboard user tabs into a link they\n * cannot see and a screen reader announces every slide as if they were all on\n * screen. `inert` takes the whole subtree out of both at once, which is why it\n * is preferred here over `tabindex=\"-1\"` (which reaches only the host) — the\n * same answer `wr-collapse` uses.\n *\n * `aria-hidden` rides along: it states the intent for anything reading the attribute\n * rather than honouring `inert`.\n */\n@Component({\n selector: 'wr-carousel-slide',\n template: '<ng-content />',\n encapsulation: ViewEncapsulation.None,\n host: {\n class: 'wr-carousel-slide',\n role: 'group',\n '[attr.aria-roledescription]': 'resolvedRoledescription()',\n '[attr.inert]': 'offScreen() ? \"\" : null',\n '[attr.aria-hidden]': 'offScreen() ? \"true\" : null',\n },\n})\nexport class WrCarouselSlide {\n constructor() {\n if (typeof ngDevMode === 'undefined' || ngDevMode) wrCheckStyles('carousel');\n }\n\n private readonly carousel = inject(WR_CAROUSEL, { optional: true });\n\n /**\n * Word a screen reader speaks IN PLACE OF the `group` role. Falls back to\n * `carousel.slideRoledescription`, then `'slide'`.\n */\n readonly roledescription = input<string | null>(null);\n\n // Spoken verbatim, and only the off-screen slides are `inert` — so the visible\n // one announced an English \"slide\" inside an otherwise localized carousel.\n protected readonly resolvedRoledescription = useI18nText(\n this.roledescription,\n 'carousel.slideRoledescription',\n 'slide'\n );\n\n /**\n * Whether this slide is one of the ones translated out of view.\n *\n * `false` while the index is `-1`: content children resolve after the first\n * render, and a slide that hid itself in that window would make the carousel\n * open with everything inert. `false` too when there is no parent — the\n * component is exported, so it can be used on its own.\n */\n protected readonly offScreen = computed(() => {\n if (!this.carousel) return false;\n const index = this.carousel.indexOf(this);\n return index >= 0 && index !== this.carousel.active();\n });\n}\n","/**\n * @license\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://github.com/thekhegay/ngwr/blob/main/LICENSE\n */\n\nimport { Directionality } from '@angular/cdk/bidi';\nimport { coerceBooleanProperty, coerceNumberProperty } from '@angular/cdk/coercion';\nimport { isPlatformBrowser } from '@angular/common';\nimport {\n Component,\n DestroyRef,\n PLATFORM_ID,\n ViewEncapsulation,\n computed,\n contentChildren,\n forwardRef,\n effect,\n inject,\n input,\n model,\n signal,\n} from '@angular/core';\n\nimport { useI18nFormatter, useI18nText } from 'ngwr/i18n';\nimport { WrPlatform } from 'ngwr/platform';\nimport { wrCheckStyles } from 'ngwr/utils';\n\nimport { WrCarouselSlide } from './carousel-slide';\nimport { WR_CAROUSEL } from './tokens';\nimport type { WrCarouselContext } from './types';\n\n/**\n * How far a touch travels before the carousel decides whether it is a swipe or a\n * scroll — the usual touch slop, so a finger's first wobble decides nothing.\n */\nconst SWIPE_SLOP = 10;\n\n/**\n * Slide carousel. Project `<wr-carousel-slide>` children — the carousel\n * snaps between them with prev/next buttons and optional dots / autoplay.\n *\n * @example\n * ```html\n * <wr-carousel [(active)]=\"i\" autoplay>\n * <wr-carousel-slide><img src=\"a.jpg\" /></wr-carousel-slide>\n * <wr-carousel-slide><img src=\"b.jpg\" /></wr-carousel-slide>\n * <wr-carousel-slide><img src=\"c.jpg\" /></wr-carousel-slide>\n * </wr-carousel>\n * ```\n *\n * @see https://ngwr.dev/reference/components/carousel\n */\n@Component({\n selector: 'wr-carousel',\n templateUrl: './carousel.html',\n encapsulation: ViewEncapsulation.None,\n // On the HOST, not the viewport: the arrows and dots are the viewport's siblings, so\n // viewport-scoped listeners let a slide change under a cursor aiming at an arrow.\n // `focusin` / `focusout` are the keyboard half — WCAG 2.2.2 wants a way to stop\n // moving content, and hovering is not one for someone who never uses a mouse.\n host: {\n class: 'wr-carousel',\n '(mouseenter)': 'onHoverIn()',\n '(mouseleave)': 'onHoverOut()',\n '(focusin)': 'onFocusIn()',\n '(focusout)': 'onFocusOut()',\n },\n providers: [\n {\n provide: WR_CAROUSEL,\n // eslint-disable-next-line @angular-eslint/no-forward-ref\n useExisting: forwardRef(() => WrCarousel),\n },\n ],\n})\nexport class WrCarousel implements WrCarouselContext {\n /** Accessible name of the previous-slide button. Falls back to `carousel.prev`. */\n readonly prevLabel = input<string | null>(null);\n\n /** Accessible name of the next-slide button. Falls back to `carousel.next`. */\n readonly nextLabel = input<string | null>(null);\n\n /** Accessible name of the dot group. Falls back to `carousel.pagination`. */\n readonly paginationLabel = input<string | null>(null);\n\n protected readonly resolvedPrevLabel = useI18nText(this.prevLabel, 'carousel.prev', 'Previous slide');\n protected readonly resolvedNextLabel = useI18nText(this.nextLabel, 'carousel.next', 'Next slide');\n protected readonly resolvedPaginationLabel = useI18nText(\n this.paginationLabel,\n 'carousel.pagination',\n 'Carousel pagination'\n );\n\n /** Accessible name of the carousel itself. Falls back to `carousel.label`. */\n readonly ariaLabel = input<string | null>(null);\n\n protected readonly resolvedAriaLabel = useI18nText(this.ariaLabel, 'carousel.label', 'Carousel');\n\n /**\n * Word a screen reader speaks IN PLACE OF the `group` role. Falls back to\n * `carousel.roledescription`, then `'carousel'`.\n */\n readonly roledescription = input<string | null>(null);\n\n // Routed for the same reason the name above is: `aria-roledescription` is spoken\n // verbatim, so a static English \"carousel\" made the viewport announce\n // \"Карусель, carousel\" with the localized arrows right beside it.\n protected readonly resolvedRoledescription = useI18nText(\n this.roledescription,\n 'carousel.roledescription',\n 'carousel'\n );\n\n // The three labels above route through the catalog; this one was a hard-coded\n // English template, so a localized app got two languages in one pagination strip.\n protected readonly slideLabel = useI18nFormatter('carousel.goToSlide', 'Go to slide {{index}}');\n\n /** Name of the autoplay button while the slides advance. Falls back to `marquee.pause`, \"Pause\" in English. */\n readonly pauseLabel = input<string | null>(null);\n\n /** Name of the autoplay button while the slides stand. Falls back to `marquee.play`, \"Play\" in English. */\n readonly playLabel = input<string | null>(null);\n\n // The marquee's pair: the same two words on the same kind of button.\n protected readonly resolvedPauseLabel = useI18nText(this.pauseLabel, 'marquee.pause', 'Pause');\n protected readonly resolvedPlayLabel = useI18nText(this.playLabel, 'marquee.play', 'Play');\n\n private readonly positionText = useI18nFormatter('carousel.position', 'Slide {{current}} of {{total}}');\n\n /** Active slide index. Two-way bindable. @default 0 */\n readonly active = model(0);\n\n /** Show prev / next arrow buttons. @default true */\n readonly showArrows = input(true, { transform: coerceBooleanProperty });\n\n /** Show dot indicators below the slides. @default true */\n readonly showDots = input(true, { transform: coerceBooleanProperty });\n\n /**\n * Auto-advance slides. Held while the pointer or keyboard focus is inside the\n * carousel and during a swipe. While the reader prefers reduced motion it does\n * not start until they press play. Turn on `pauseButton` to let readers stop\n * it. @default false\n */\n readonly autoplay = input(false, { transform: coerceBooleanProperty });\n\n /**\n * Draw a pause / play button while `autoplay` is on. WCAG 2.2.2 asks for a way\n * to pause moving content, so turn it on with autoplay. @default false\n */\n readonly pauseButton = input(false, { transform: coerceBooleanProperty });\n\n /** Autoplay interval (ms). @default 4000 */\n readonly intervalMs = input(4000, {\n transform: (v: unknown): number => Math.max(500, coerceNumberProperty(v, 4000)),\n });\n\n /** Wrap around at the ends. @default true */\n readonly loop = input(true, { transform: coerceBooleanProperty });\n\n protected readonly slides = contentChildren(WrCarouselSlide);\n protected readonly count = computed(() => this.slides().length);\n\n /**\n * Whether an arrow has nowhere to go: only without `loop`, at the matching end.\n * The arrows used to stay enabled there and do nothing — announced, focusable\n * and clickable controls with no effect. Native `disabled`, the way\n * `wr-pagination` stops its own previous / next at the ends.\n */\n protected readonly atStart = computed(() => !this.loop() && this.active() <= 0);\n protected readonly atEnd = computed(() => !this.loop() && this.active() >= this.count() - 1);\n\n /**\n * Where a slide sits in projection order — {@link WrCarouselContext}.\n *\n * Public only because the child injects the parent through `WR_CAROUSEL`;\n * reading `slides()` here is what makes the child's `computed()` re-run when a\n * slide is added or removed.\n */\n indexOf(slide: object): number {\n return this.slides().indexOf(slide as WrCarouselSlide);\n }\n\n /** Live horizontal drag offset (px) during a touch swipe. */\n protected readonly dragX = signal(0);\n protected readonly dragging = signal(false);\n\n private readonly dir = inject(Directionality, { optional: true });\n\n /**\n * Reading direction of the track. `Directionality` is root-provided, so this\n * always resolves — `optional` only guards a consumer who has deliberately\n * torn the provider out. It reads the document once at construction; a\n * subtree that overrides the direction does it with the CDK's `Dir`\n * directive, which writes `valueSignal`, so `trackStyle` re-renders instead\n * of leaving the track parked on the old side.\n */\n private readonly isRtl = computed(() => this.dir?.valueSignal() === 'rtl');\n\n /** CSS transform for the track — the per-slide offset plus any live drag. */\n protected readonly trackStyle = computed(() => {\n // `translateX` is PHYSICAL while the slides are laid out on the inline axis:\n // under `dir=\"rtl\"` the flex track runs right-to-left, so slide 1 sits to the\n // LEFT of slide 0 and reaching it means moving the track the other way. Left\n // unsigned, every RTL carousel translated itself off into blank space.\n const base = (this.isRtl() ? 1 : -1) * this.active() * 100;\n // The drag stays physical on purpose: it is the finger's own displacement,\n // and the track follows the finger in both directions.\n const drag = this.dragX();\n return drag === 0 ? `translateX(${base}%)` : `translateX(calc(${base}% + ${drag}px))`;\n });\n\n private timer: ReturnType<typeof setInterval> | null = null;\n\n // Three sources hold the pause and they release independently, so they get a\n // flag each rather than one shared boolean — the same `hovered` / `focusWithin`\n // pair `WrToastHost` keeps. With one flag whichever source released LAST won:\n // moving the pointer off the carousel while focus was still on a link inside it\n // restarted the slides under the focused element, and a `touchend` released a\n // pause it had never taken. Flags, not a counter: `mouseenter`/`mouseleave` and\n // `focusin`/`focusout` each pair exactly once per source, so a count would only\n // add a way to drift out of step.\n private readonly hovered = signal(false);\n private readonly focusWithin = signal(false);\n private readonly paused = computed(() => this.hovered() || this.focusWithin() || this.dragging());\n\n /**\n * Autoplay is motion the reader did not start, which is exactly what\n * `prefers-reduced-motion` asks a page to drop: the stylesheet already switches\n * slides in place under it, and a panel that still changed every four seconds\n * was the half that stylesheet cannot reach. A signal, so the preference is\n * followed while the page is open, until the reader presses the button: a\n * press is an explicit answer and outranks the preference.\n */\n private readonly reducedMotion = inject(WrPlatform).prefersReducedMotion;\n\n /** What the reader last asked of the pause button, `null` until it is pressed. */\n private readonly asked = signal<'play' | 'pause' | null>(null);\n\n /** Whether autoplay is switched on, holds aside: what the button's name and glyph follow. */\n protected readonly playing = computed(() => {\n const asked = this.asked();\n return this.autoplay() && (asked === null ? !this.reducedMotion() : asked === 'play');\n });\n\n /** The slides are advancing on their own right now. */\n protected readonly rotating = computed(() => this.isBrowser && this.playing() && !this.paused() && this.count() > 1);\n\n /**\n * Text of the live region: the position after a move the reader made. Empty\n * after an autoplay tick, so the same position can be said again later.\n */\n protected readonly announcement = signal('');\n\n private readonly destroyRef = inject(DestroyRef);\n private readonly isBrowser = isPlatformBrowser(inject(PLATFORM_ID));\n\n constructor() {\n if (typeof ngDevMode === 'undefined' || ngDevMode) wrCheckStyles('carousel');\n effect(() => {\n if (this.timer) clearInterval(this.timer);\n this.timer = null;\n // `isBrowser` first: without it the prerender ran the timer too, doing work\n // nobody will ever see on a slide index that then gets serialized.\n if (!this.rotating()) return;\n const interval = this.intervalMs();\n this.timer = setInterval(() => {\n this.move(this.active() + 1);\n this.announcement.set('');\n }, interval);\n });\n\n // `active` is a plain `model`, so `[(active)]` and a shrinking slide list both\n // write into it unchecked — a filtered list left it pointing past the end,\n // translating the track into blank space with no dot lit.\n effect(() => {\n const max = this.count() - 1;\n if (max < 0) return;\n const current = this.active();\n // NaN and a fraction from the host are repaired here: `Math.min` and `Math.max` keep NaN.\n const clamped = Number.isFinite(current) ? Math.min(Math.max(0, Math.floor(current)), max) : 0;\n if (clamped !== current) this.active.set(clamped);\n });\n\n this.destroyRef.onDestroy(() => {\n if (this.timer) clearInterval(this.timer);\n });\n }\n\n protected onHoverIn(): void {\n this.hovered.set(true);\n }\n\n protected onHoverOut(): void {\n this.hovered.set(false);\n }\n\n protected onFocusIn(): void {\n this.focusWithin.set(true);\n }\n\n protected onFocusOut(): void {\n this.focusWithin.set(false);\n }\n\n /**\n * The pause button. Play also lets go of the hover and focus holds in force:\n * the press came from inside the carousel, so they would keep the slides still\n * after the reader asked for them to move. Each hold comes back with the next\n * `focusin` or `mouseenter`.\n */\n protected toggleAutoplay(): void {\n if (this.playing()) {\n this.asked.set('pause');\n return;\n }\n this.asked.set('play');\n this.hovered.set(false);\n this.focusWithin.set(false);\n }\n\n // Imperative\n\n /** Show a slide, and announce its position: an autoplay tick is the only silent move. */\n goTo(index: number): void {\n const before = this.active();\n this.move(index);\n const current = this.active();\n if (current !== before) this.announcement.set(this.positionText({ current: current + 1, total: this.count() }));\n }\n\n private move(index: number): void {\n const max = this.count() - 1;\n if (max < 0) return;\n if (this.loop()) {\n const next = ((index % this.count()) + this.count()) % this.count();\n this.active.set(next);\n } else {\n this.active.set(Math.min(Math.max(0, index), max));\n }\n }\n\n next(): void {\n this.goTo(this.active() + 1);\n }\n\n prev(): void {\n this.goTo(this.active() - 1);\n }\n\n // Swipe navigation — the track follows the finger; releasing past ~20% of the\n // viewport advances a slide, otherwise snaps back. Which way that is follows\n // the reading direction: dragging toward the inline start (left in LTR, right\n // in RTL) pulls the next slide into view.\n\n private swipeStartX = 0;\n private swipeStartY = 0;\n\n /**\n * Which way the finger is going, decided once it has moved {@link SWIPE_SLOP}\n * px: `'x'` is a swipe, `'y'` a page scroll that happened to start on a slide.\n * Without the lock every vertical scroll that drifted sideways dragged the\n * track along and, past 20% of the width, changed the slide under it.\n */\n private swipeAxis: 'x' | 'y' | null = null;\n\n protected onSwipeStart(event: TouchEvent): void {\n const touch = event.touches[0];\n if (!touch) return;\n this.swipeStartX = touch.clientX;\n this.swipeStartY = touch.clientY;\n this.swipeAxis = null;\n this.dragging.set(true); // holds autoplay on its own — `paused` reads it\n }\n\n protected onSwipeMove(event: TouchEvent): void {\n if (!this.dragging()) return;\n const touch = event.touches[0];\n if (!touch) return;\n const dx = touch.clientX - this.swipeStartX;\n const dy = touch.clientY - this.swipeStartY;\n if (this.swipeAxis === null) {\n if (Math.abs(dx) < SWIPE_SLOP && Math.abs(dy) < SWIPE_SLOP) return;\n this.swipeAxis = Math.abs(dx) > Math.abs(dy) ? 'x' : 'y';\n }\n if (this.swipeAxis === 'x') this.dragX.set(dx);\n }\n\n /** The browser took the touch over (a scroll, a system gesture): drop the drag, never navigate. */\n protected onSwipeCancel(): void {\n if (!this.dragging()) return;\n this.dragging.set(false);\n this.swipeAxis = null;\n this.dragX.set(0);\n }\n\n protected onSwipeEnd(event: TouchEvent, viewport: HTMLElement): void {\n if (!this.dragging()) return;\n this.dragging.set(false);\n const dx = this.swipeAxis === 'x' ? this.dragX() : 0;\n this.swipeAxis = null;\n this.dragX.set(0);\n const threshold = (viewport.offsetWidth || 0) * 0.2;\n // `dx` is a physical delta. The next slide sits to the physical RIGHT in LTR\n // and to the LEFT in RTL, so the drag that pulls it into view — and with it\n // the sign that advances — turns around with the direction. The buttons keep\n // their semantics either way; only the gesture is physical.\n const advance = this.isRtl() ? dx >= threshold : dx <= -threshold;\n const retreat = this.isRtl() ? dx <= -threshold : dx >= threshold;\n if (advance) this.next();\n else if (retreat) this.prev();\n }\n}\n","<!--\n First in the DOM, so it is the first tab stop of the carousel: the way to stop\n the slides comes before the slides. Named for what a press does next.\n-->\n@if (autoplay() && pauseButton() && count() > 1) {\n <button\n type=\"button\"\n class=\"wr-carousel__toggle\"\n [attr.aria-label]=\"playing() ? resolvedPauseLabel() : resolvedPlayLabel()\"\n (click)=\"toggleAutoplay()\"\n >\n @if (playing()) {\n <svg width=\"14\" height=\"14\" viewBox=\"0 0 24 24\" fill=\"currentColor\" aria-hidden=\"true\">\n <rect x=\"5\" y=\"4\" width=\"5\" height=\"16\" rx=\"1\" />\n <rect x=\"14\" y=\"4\" width=\"5\" height=\"16\" rx=\"1\" />\n </svg>\n } @else {\n <svg width=\"14\" height=\"14\" viewBox=\"0 0 24 24\" fill=\"currentColor\" aria-hidden=\"true\">\n <path d=\"M6 4.5a1 1 0 0 1 1.52-.86l12 7.5a1 1 0 0 1 0 1.72l-12 7.5A1 1 0 0 1 6 19.5z\" />\n </svg>\n }\n </button>\n}\n\n<div\n #viewport\n class=\"wr-carousel__viewport\"\n role=\"group\"\n [attr.aria-roledescription]=\"resolvedRoledescription()\"\n [attr.aria-label]=\"resolvedAriaLabel()\"\n (touchstart)=\"onSwipeStart($event)\"\n (touchmove)=\"onSwipeMove($event)\"\n (touchend)=\"onSwipeEnd($event, viewport)\"\n (touchcancel)=\"onSwipeCancel()\"\n>\n <div class=\"wr-carousel__track\" [style.transform]=\"trackStyle()\" [style.transition]=\"dragging() ? 'none' : null\">\n <ng-content />\n </div>\n</div>\n\n@if (showArrows() && count() > 1) {\n <button\n type=\"button\"\n class=\"wr-carousel__nav wr-carousel__nav--prev\"\n [attr.aria-label]=\"resolvedPrevLabel()\"\n [disabled]=\"atStart()\"\n (click)=\"prev()\"\n >\n <svg width=\"14\" height=\"14\" viewBox=\"0 0 14 14\" aria-hidden=\"true\">\n <path d=\"M9 2 L4 7 L9 12\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" />\n </svg>\n </button>\n <button\n type=\"button\"\n class=\"wr-carousel__nav wr-carousel__nav--next\"\n [attr.aria-label]=\"resolvedNextLabel()\"\n [disabled]=\"atEnd()\"\n (click)=\"next()\"\n >\n <svg width=\"14\" height=\"14\" viewBox=\"0 0 14 14\" aria-hidden=\"true\">\n <path d=\"M5 2 L10 7 L5 12\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" />\n </svg>\n </button>\n}\n\n@if (showDots() && count() > 1) {\n <div class=\"wr-carousel__dots\" role=\"group\" [attr.aria-label]=\"resolvedPaginationLabel()\">\n @for (slide of slides(); track $index) {\n <button\n type=\"button\"\n class=\"wr-carousel__dot\"\n [class.wr-carousel__dot--active]=\"$index === active()\"\n [attr.aria-current]=\"$index === active() ? 'true' : null\"\n [attr.aria-label]=\"slideLabel({ index: $index + 1 })\"\n (click)=\"goTo($index)\"\n ></button>\n }\n </div>\n}\n\n<!--\n One live region for the whole carousel, in the DOM before its text changes.\n Off while the slides advance on their own, as the WAI-ARIA carousel pattern has it.\n-->\n<div class=\"wr-carousel__live\" aria-atomic=\"true\" [attr.aria-live]=\"rotating() ? 'off' : 'polite'\">\n {{ announcement() }}\n</div>\n"],"mappings":";;;;;;;;;;;;;;AAYA,MAAa,cAAc,IAAI,eAAkC,aAAa;;;;;;;AC6B9E,IAAa,kBAAb,MAAa,gBAAe;CAC1B,cAAA;EACE,IAAI,OAAO,cAAc,eAAe,WAAW,cAAc,UAAU;CAC7E;CAEiB,WAAW,OAAO,aAAa,EAAE,UAAU,KAAI,CAAE;CAMzD,kBAAkB,MAAqB,MAAK,GAAA,YAAA,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AA,UAAA;GAAA,CAAA;EAAA,CAAA;EAAA,UAAA,CAAA;GAAA,MAAA,GAAA;GAAA,MAAA,CAAA;IAAA,UAAA;IAAA,OAAA;IAAA,UAAA;GAAA,CAAA;EAAA,CAAA;EAAA,UAAA,CAAA;GAAA,MAAA,GAAA;GAAA,MAAA,CAAA;IAAA,UAAA;IAAA,OAAA;IAAA,UAAA;GAAA,CAAA;EAAA,CAAA;EAAA,aAAA,CAAA;GAAA,MAAA,GAAA;GAAA,MAAA,CAAA;IAAA,UAAA;IAAA,OAAA;IAAA,UAAA;GAAA,CAAA;EAAA,CAAA;EAAA,YAAA,CAAA;GAAA,MAAA,GAAA;GAAA,MAAA,CAAA;IAAA,UAAA;IAAA,OAAA;IAAA,UAAA;GAAA,CAAA;EAAA,CAAA;EAAA,MAAA,CAAA;GAAA,MAAA,GAAA;GAAA,MAAA,CAAA;IAAA,UAAA;IAAA,OAAA;IAAA,UAAA;GAAA,CAAA;EAAA,CAAA;EAAA,QAAA,CAAA;GAAA,MAAA,GAAA;GAAA,MAAA,CAAA,GAAA,iBAAA,eAAe,GAAA,EAAA,UAAA,KAAA,CAAA;EAAA,CAAA;CAAA;AAAA,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ngwr-compare.mjs","names":[],"sources":["../../../projects/lib/compare/compare.ts","../../../projects/lib/compare/compare.html"],"sourcesContent":["/**\n * @license\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://github.com/thekhegay/ngwr/blob/main/LICENSE\n */\n\nimport { Directionality } from '@angular/cdk/bidi';\nimport { coerceBooleanProperty, coerceNumberProperty } from '@angular/cdk/coercion';\nimport {\n Component,\n ElementRef,\n ViewEncapsulation,\n computed,\n effect,\n inject,\n input,\n model,\n signal,\n} from '@angular/core';\nimport { takeUntilDestroyed } from '@angular/core/rxjs-interop';\n\nimport { useI18nText } from 'ngwr/i18n';\nimport { wrClamp, wrCheckStyles } from 'ngwr/utils';\n\n/**\n * Before/after comparison slider. Works with any content — project two\n * pieces of markup with `wrCompareBefore` and `wrCompareAfter` attributes;\n * the component stacks them in the same cell and clips the \"after\" side\n * with a draggable divider.\n *\n * @example\n * ```html\n * <wr-compare [(position)]=\"pos\">\n * <img wrCompareBefore src=\"before.jpg\" alt=\"\" />\n * <img wrCompareAfter src=\"after.jpg\" alt=\"\" />\n * </wr-compare>\n *\n * <wr-compare orientation=\"vertical\">\n * <pre wrCompareBefore>{{ oldCode }}</pre>\n * <pre wrCompareAfter>{{ newCode }}</pre>\n * </wr-compare>\n * ```\n *\n * Under `dir=\"rtl\"` the horizontal wipe MIRRORS: \"before\" occupies the inline-start\n * side, which is the right. Before/after is an ordinal pair — the two ends of a\n * progression — and ordinal progressions follow reading order, the same reason a\n * progress bar fills from the right in Arabic. The LTR habit of putting \"before\" on\n * the left IS reading order, so mirroring preserves that intent rather than breaking\n * it. Nothing is flipped pixel-wise: both layers are the images the consumer passed,\n * unscaled and unmirrored — only the side each is revealed on changes.\n *\n * Pinning the physical arrangement inside an RTL page takes the CDK's `Dir` directive\n * (`[dir]`, from `@angular/cdk/bidi`) on a wrapper, because that is what provides a\n * scoped `Directionality`. A bare `dir=\"ltr\"` attribute does NOT do it: the ambient\n * `Directionality` reads `<html>` / `<body>` once at startup and never looks at the\n * element, and this component's horizontal wipe is painted entirely from TypeScript,\n * so the attribute would change nothing at all while looking like an opt-out.\n *\n * @see https://ngwr.dev/reference/components/compare\n */\n@Component({\n selector: 'wr-compare',\n templateUrl: './compare.html',\n encapsulation: ViewEncapsulation.None,\n host: { class: 'wr-compare', '[class]': 'classes()' },\n})\nexport class WrCompare {\n /** Divider position as a percentage (0–100). Two-way bindable. @default 50 */\n readonly position = model(50);\n\n /** Accessible name of the divider. Falls back to `compare.label`. */\n readonly ariaLabel = input<string | null>(null);\n\n protected readonly resolvedAriaLabel = useI18nText(this.ariaLabel, 'compare.label', 'Comparison divider');\n\n /**\n * Divider direction:\n * - `'horizontal'` — divider line is vertical, drags left/right.\n * - `'vertical'` — divider line is horizontal, drags up/down.\n * @default 'horizontal'\n */\n readonly orientation = input<'horizontal' | 'vertical'>('horizontal');\n\n /** Show the round drag handle on the divider. @default true */\n readonly showHandle = input(true, { transform: coerceBooleanProperty });\n\n /** Disable interaction (divider stays put). @default false */\n readonly disabled = input(false, { transform: coerceBooleanProperty });\n\n /** Lowest position the divider may reach, in percent. @default 0 */\n readonly minPosition = input(0, { transform: (v: unknown): number => coerceNumberProperty(v, 0) });\n\n /** Highest position the divider may reach, in percent. @default 100 */\n readonly maxPosition = input(100, { transform: (v: unknown): number => coerceNumberProperty(v, 100) });\n\n private readonly host = inject<ElementRef<HTMLElement>>(ElementRef);\n // Optional on purpose: `Directionality` is root-provided, so a consumer never has to\n // supply it — and a bare `TestBed` does not either.\n private readonly dir = inject(Directionality, { optional: true });\n\n /**\n * Reading direction as a signal, because unlike the splitter this component PAINTS\n * from it: the clip and the divider offset are both direction-derived, and\n * `Directionality.value` is an ordinary read. A `dir` flip at runtime would otherwise\n * leave the wipe on the side the page no longer uses until some unrelated position\n * change happened to recompute it.\n */\n private readonly rtl = signal(this.dir?.value === 'rtl');\n\n private dragging = false;\n\n /** Where the divider was when the live drag began — see `onPointerCancel`. */\n private dragStart = 0;\n\n /**\n * `aria-valuenow`, in whole percent. A drag sets `position` to wherever the\n * pointer fell, and a reader announced all of it: `29.99999788072374`.\n */\n protected readonly valueNow = computed(() =>\n wrClamp(Math.round(this.position()), this.minPosition(), this.maxPosition())\n );\n\n constructor() {\n if (typeof ngDevMode === 'undefined' || ngDevMode) wrCheckStyles('compare');\n this.dir?.change.pipe(takeUntilDestroyed()).subscribe(value => this.rtl.set(value === 'rtl'));\n\n // `position` is a `model`, so `[(position)]` and a restored layout write into it\n // directly while only the handlers clamped — an out-of-range write reached the DOM\n // as `aria-valuenow=\"150\"` against a `valuemax` of 100.\n effect(() => {\n const clamped = wrClamp(this.position(), this.minPosition(), this.maxPosition());\n if (clamped !== this.position()) this.position.set(clamped);\n });\n }\n\n protected readonly classes = computed(() => {\n const parts = [`wr-compare--${this.orientation()}`];\n if (this.disabled()) parts.push('wr-compare--disabled');\n return parts.join(' ');\n });\n\n /**\n * Clip path applied to the \"after\" layer so the divider reveals it.\n *\n * `inset()` takes PHYSICAL edges and has no logical form, so the mirroring is done\n * here rather than in CSS: `position` counts from the inline-start edge, and under\n * RTL that edge is the right one, so the after layer is clipped from the right by\n * the same percentage.\n */\n protected readonly clipPath = computed(() => {\n const p = wrClamp(this.position(), 0, 100);\n if (this.orientation() === 'horizontal') {\n // Show from `p%` to the inline-end edge.\n return this.rtl() ? `inset(0 ${p}% 0 0)` : `inset(0 0 0 ${p}%)`;\n }\n // Block axis: `dir` does not touch it.\n return `inset(${p}% 0 0 0)`;\n });\n\n /**\n * Physical `left` percentage of the divider. Deliberately physical: it pairs with the\n * `translateX(-50%)` that centres the 2px line on its own position, and the two have\n * to agree on which edge they count from. `position` is logical, so RTL flips it here.\n */\n protected readonly dividerLeft = computed(() => (this.rtl() ? 100 - this.position() : this.position()));\n\n // Pointer handlers\n\n protected onPointerDown(event: PointerEvent): void {\n if (this.disabled()) return;\n // Any pointerdown used to start a drag, so the right button moved the divider; the\n // same guard keeps a second finger out of a drag already in progress.\n if (event.button !== 0 || !event.isPrimary) return;\n event.preventDefault();\n this.dragging = true;\n this.dragStart = this.position();\n const surface = event.currentTarget as HTMLElement;\n surface.setPointerCapture(event.pointerId);\n // `preventDefault` above also suppresses the click's default focus, so the arrows\n // did nothing after a mouse drag until the divider was found again with Tab.\n surface.focus();\n // A touch may still turn out to be a scroll along the other axis, which the\n // browser takes over with `pointercancel`, so it moves the divider from its first\n // move (or a tap's lift) rather than jumping it to where the finger came down.\n if (event.pointerType !== 'touch') this.updateFromPointer(event);\n }\n\n protected onPointerMove(event: PointerEvent): void {\n if (!this.dragging) return;\n this.updateFromPointer(event);\n }\n\n protected onPointerUp(event: PointerEvent): void {\n if (!this.dragging) return;\n // A tap: the touch that never moved still sets the position where it lifted.\n if (event.pointerType === 'touch') this.updateFromPointer(event);\n this.dragging = false;\n (event.currentTarget as HTMLElement).releasePointerCapture(event.pointerId);\n }\n\n /**\n * The browser took the gesture over — a scroll along the axis `touch-action` leaves\n * to the page — so the drag never happened, and the divider goes back to where it\n * was rather than keeping whatever the first moves of a swipe said.\n */\n protected onPointerCancel(event: PointerEvent): void {\n if (!this.dragging) return;\n this.dragging = false;\n this.position.set(this.dragStart);\n const surface = event.currentTarget as HTMLElement;\n if (surface.hasPointerCapture(event.pointerId)) surface.releasePointerCapture(event.pointerId);\n }\n\n protected onKeydown(event: KeyboardEvent): void {\n if (this.disabled()) return;\n const step = event.shiftKey ? 10 : 1;\n // Steps count from the whole percent a reader was told, so a key after a drag\n // lands on a round number instead of carrying the drag's fraction along.\n const from = this.valueNow();\n let next: number | null = null;\n if (this.orientation() === 'horizontal') {\n // Arrows follow the VISUAL axis (WAI-ARIA APG). Under `dir=\"rtl\"` the \"before\"\n // side grows from the right, so the visual right is the low end of this slider's\n // range and ArrowRight has to decrease the value.\n const inline = this.rtl() ? -step : step;\n if (event.key === 'ArrowLeft') next = from - inline;\n else if (event.key === 'ArrowRight') next = from + inline;\n } else {\n // Block axis: unaffected by `dir`.\n if (event.key === 'ArrowUp') next = from - step;\n else if (event.key === 'ArrowDown') next = from + step;\n }\n // Home/End are semantic — first/last, not left/right — so they never mirror.\n if (event.key === 'Home') next = this.minPosition();\n else if (event.key === 'End') next = this.maxPosition();\n if (next === null) return;\n event.preventDefault();\n this.position.set(wrClamp(next, this.minPosition(), this.maxPosition()));\n }\n\n private updateFromPointer(event: PointerEvent): void {\n const rect = this.host.nativeElement.getBoundingClientRect();\n const horizontal = this.orientation() === 'horizontal';\n const extent = horizontal ? rect.width : rect.height;\n // A host that has not been laid out — hidden, detached, or a pane the browser has\n // throttled — measures 0, and dividing by it puts `Infinity` or `NaN` straight into\n // `aria-valuenow`. There is no meaningful position to compute, so keep the current one.\n if (extent <= 0) return;\n const raw = horizontal\n ? this.inlineFraction(event.clientX, rect) * 100\n : ((event.clientY - rect.top) / extent) * 100;\n this.position.set(wrClamp(raw, this.minPosition(), this.maxPosition()));\n }\n\n /**\n * Fraction of the host measured from the INLINE-START edge — the left edge in LTR, the\n * right edge in RTL, which is the side \"before\" is revealed from. Taken from\n * `rect.left` in both, a drag under `dir=\"rtl\"` read 0 at the visual maximum and moved\n * the divider opposite the pointer.\n */\n private inlineFraction(clientX: number, rect: DOMRect): number {\n return this.rtl() ? (rect.right - clientX) / rect.width : (clientX - rect.left) / rect.width;\n }\n}\n","<div\n class=\"wr-compare__surface\"\n role=\"slider\"\n [attr.aria-label]=\"resolvedAriaLabel()\"\n [attr.aria-orientation]=\"orientation()\"\n [attr.aria-valuemin]=\"minPosition()\"\n [attr.aria-valuemax]=\"maxPosition()\"\n [attr.aria-valuenow]=\"valueNow()\"\n [attr.aria-disabled]=\"disabled() || null\"\n [attr.tabindex]=\"disabled() ? -1 : 0\"\n (pointerdown)=\"onPointerDown($event)\"\n (pointermove)=\"onPointerMove($event)\"\n (pointerup)=\"onPointerUp($event)\"\n (pointercancel)=\"onPointerCancel($event)\"\n (keydown)=\"onKeydown($event)\"\n>\n <div class=\"wr-compare__layers\">\n <div class=\"wr-compare__layer wr-compare__layer--before\">\n <ng-content select=\"[wrCompareBefore]\" />\n </div>\n <div class=\"wr-compare__layer wr-compare__layer--after\" [style.clip-path]=\"clipPath()\">\n <ng-content select=\"[wrCompareAfter]\" />\n </div>\n </div>\n\n <div\n class=\"wr-compare__divider\"\n [style.left.%]=\"orientation() === 'horizontal' ? dividerLeft() : null\"\n [style.top.%]=\"orientation() === 'vertical' ? position() : null\"\n aria-hidden=\"true\"\n >\n @if (showHandle()) {\n <span class=\"wr-compare__handle\">\n @if (orientation() === 'horizontal') {\n <svg width=\"16\" height=\"16\" viewBox=\"0 0 16 16\" aria-hidden=\"true\">\n <path\n d=\"M5 4 L1 8 L5 12 M11 4 L15 8 L11 12\"\n fill=\"none\"\n stroke=\"currentColor\"\n stroke-width=\"1.5\"\n stroke-linecap=\"round\"\n stroke-linejoin=\"round\"\n />\n </svg>\n } @else {\n <svg width=\"16\" height=\"16\" viewBox=\"0 0 16 16\" aria-hidden=\"true\">\n <path\n d=\"M4 5 L8 1 L12 5 M4 11 L8 15 L12 11\"\n fill=\"none\"\n stroke=\"currentColor\"\n stroke-width=\"1.5\"\n stroke-linecap=\"round\"\n stroke-linejoin=\"round\"\n />\n </svg>\n }\n </span>\n }\n </div>\n</div>\n"],"mappings":";;;;;;;;;;;;;AAmEA,IAAa,YAAb,MAAa,UAAS;CAEX,WAAW,MAAM,IAAG,GAAA,YAAA,CAAA,EAAA,WAAA,WAAA,CAAA,+BAAA,CAAA,CAAA;CAGpB,YAAY,MAAqB,MAAK,GAAA,YAAA,CAAA,EAAA,WAAA,YAAA,CAAA,+BAAA,CAAA,CAAA;CAE5B,oBAAoB,YAAY,KAAK,WAAW,iBAAiB,oBAAoB;CAQ/F,cAAc,MAAiC,cAAa,GAAA,YAAA,CAAA,EAAA,WAAA,cAAA,CAAA,+BAAA,CAAA,CAAA;CAG5D,aAAa,MAAM,MAAI;EAAA,GAAA,YAAA,EAAA,WAAA,aAAA,+BAAA,CAAA;EAAI,WAAW;CAAqB,CAAA;CAG3D,WAAW,MAAM,OAAK;EAAA,GAAA,YAAA,EAAA,WAAA,WAAA,+BAAA,CAAA;EAAI,WAAW;CAAqB,CAAA;CAG1D,cAAc,MAAM,GAAC;EAAA,GAAA,YAAA,EAAA,WAAA,cAAA,+BAAA,CAAA;EAAI,YAAY,MAAuB,qBAAqB,GAAG,CAAC;CAAC,CAAA;CAGtF,cAAc,MAAM,KAAG;EAAA,GAAA,YAAA,EAAA,WAAA,cAAA,+BAAA,CAAA;EAAI,YAAY,MAAuB,qBAAqB,GAAG,GAAG;CAAC,CAAA;CAElF,OAAO,OAAgC,UAAU;CAGjD,MAAM,OAAO,gBAAgB,EAAE,UAAU,KAAI,CAAE;CAS/C,MAAM,OAAO,KAAK,KAA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;IAAA,mBAAA;IAAA,YAAA;IAAA,UAAA;IAAA,YAAA;IAAA,mBAAA;GAAA;GAAA,aAAA;IAAA,mBAAA;IAAA,YAAA;IAAA,UAAA;IAAA,YAAA;IAAA,mBAAA;GAAA;GAAA,aAAA;IAAA,mBAAA;IAAA,YAAA;IAAA,UAAA;IAAA,YAAA;IAAA,mBAAA;GAAA;EAAA;EAAA,SAAA,EAAA,UAAA,iBAAA;EAAA,MAAA;GAAA,YAAA,EAAA,SAAA,YAAA;GAAA,gBAAA;EAAA;EAAA,UAAA;EAAA,UCnEtB;EA4DA,eAAA,GAAA,kBAAA;CAAA,CAAA;;ADOa,GAAA,yBAAA;CAAA,YAAA;CAAA,SAAA;CAAA,UAAA;CAAA,MAAA;CAAS,YAAA,CAAA;EANrB,MAAA;EACW,MAAA,CAAA;GAAA,UAAA;GAAY,eAEP,kBAAkB;GAAI,MAC/B;IAAE,OAAO;IAAc,WAAW;GAAW;GAAE,UAAA;EAAA,CAAA"}
|
|
1
|
+
{"version":3,"file":"ngwr-compare.mjs","names":[],"sources":["../../../projects/lib/compare/compare.ts","../../../projects/lib/compare/compare.html"],"sourcesContent":["/**\n * @license\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://github.com/thekhegay/ngwr/blob/main/LICENSE\n */\n\nimport { Directionality } from '@angular/cdk/bidi';\nimport { coerceBooleanProperty, coerceNumberProperty } from '@angular/cdk/coercion';\nimport {\n Component,\n ElementRef,\n ViewEncapsulation,\n computed,\n effect,\n inject,\n input,\n model,\n signal,\n} from '@angular/core';\nimport { takeUntilDestroyed } from '@angular/core/rxjs-interop';\n\nimport { useI18nText } from 'ngwr/i18n';\nimport { wrClamp, wrCheckStyles } from 'ngwr/utils';\n\n/**\n * Before/after comparison slider. Works with any content — project two\n * pieces of markup with `wrCompareBefore` and `wrCompareAfter` attributes;\n * the component stacks them in the same cell and clips the \"after\" side\n * with a draggable divider.\n *\n * @example\n * ```html\n * <wr-compare [(position)]=\"pos\">\n * <img wrCompareBefore src=\"before.jpg\" alt=\"\" />\n * <img wrCompareAfter src=\"after.jpg\" alt=\"\" />\n * </wr-compare>\n *\n * <wr-compare orientation=\"vertical\">\n * <pre wrCompareBefore>{{ oldCode }}</pre>\n * <pre wrCompareAfter>{{ newCode }}</pre>\n * </wr-compare>\n * ```\n *\n * Under `dir=\"rtl\"` the horizontal wipe MIRRORS: \"before\" occupies the inline-start\n * side, which is the right. Before/after is an ordinal pair — the two ends of a\n * progression — and ordinal progressions follow reading order, the same reason a\n * progress bar fills from the right in Arabic. The LTR habit of putting \"before\" on\n * the left IS reading order, so mirroring preserves that intent rather than breaking\n * it. Nothing is flipped pixel-wise: both layers are the images the consumer passed,\n * unscaled and unmirrored — only the side each is revealed on changes.\n *\n * Pinning the physical arrangement inside an RTL page takes the CDK's `Dir` directive\n * (`[dir]`, from `@angular/cdk/bidi`) on a wrapper, because that is what provides a\n * scoped `Directionality`. A bare `dir=\"ltr\"` attribute does NOT do it: the ambient\n * `Directionality` reads `<html>` / `<body>` once at startup and never looks at the\n * element, and this component's horizontal wipe is painted entirely from TypeScript,\n * so the attribute would change nothing at all while looking like an opt-out.\n *\n * @see https://ngwr.dev/reference/components/compare\n */\n@Component({\n selector: 'wr-compare',\n templateUrl: './compare.html',\n encapsulation: ViewEncapsulation.None,\n host: { class: 'wr-compare', '[class]': 'classes()' },\n})\nexport class WrCompare {\n /** Divider position as a percentage (0–100). Two-way bindable. @default 50 */\n readonly position = model(50);\n\n /** Accessible name of the divider. Falls back to `compare.label`. */\n readonly ariaLabel = input<string | null>(null);\n\n protected readonly resolvedAriaLabel = useI18nText(this.ariaLabel, 'compare.label', 'Comparison divider');\n\n /**\n * Divider direction:\n * - `'horizontal'` — divider line is vertical, drags left/right.\n * - `'vertical'` — divider line is horizontal, drags up/down.\n * @default 'horizontal'\n */\n readonly orientation = input<'horizontal' | 'vertical'>('horizontal');\n\n /** Show the round drag handle on the divider. @default true */\n readonly showHandle = input(true, { transform: coerceBooleanProperty });\n\n /** Disable interaction (divider stays put). @default false */\n readonly disabled = input(false, { transform: coerceBooleanProperty });\n\n /** Lowest position the divider may reach, in percent. @default 0 */\n readonly minPosition = input(0, { transform: (v: unknown): number => coerceNumberProperty(v, 0) });\n\n /** Highest position the divider may reach, in percent. @default 100 */\n readonly maxPosition = input(100, { transform: (v: unknown): number => coerceNumberProperty(v, 100) });\n\n private readonly host = inject<ElementRef<HTMLElement>>(ElementRef);\n // Optional on purpose: `Directionality` is root-provided, so a consumer never has to\n // supply it — and a bare `TestBed` does not either.\n private readonly dir = inject(Directionality, { optional: true });\n\n /**\n * Reading direction as a signal, because unlike the splitter this component PAINTS\n * from it: the clip and the divider offset are both direction-derived, and\n * `Directionality.value` is an ordinary read. A `dir` flip at runtime would otherwise\n * leave the wipe on the side the page no longer uses until some unrelated position\n * change happened to recompute it.\n */\n private readonly rtl = signal(this.dir?.value === 'rtl');\n\n private dragging = false;\n\n /** Where the divider was when the live drag began — see `onPointerCancel`. */\n private dragStart = 0;\n\n /**\n * `aria-valuenow`, in whole percent. A drag sets `position` to wherever the\n * pointer fell, and a reader announced all of it: `29.99999788072374`.\n */\n protected readonly valueNow = computed(() =>\n wrClamp(Math.round(this.position()), this.minPosition(), this.maxPosition())\n );\n\n constructor() {\n if (typeof ngDevMode === 'undefined' || ngDevMode) wrCheckStyles('compare');\n this.dir?.change.pipe(takeUntilDestroyed()).subscribe(value => this.rtl.set(value === 'rtl'));\n\n // `position` is a `model`, so `[(position)]` and a restored layout write into it\n // directly while only the handlers clamped — an out-of-range write reached the DOM\n // as `aria-valuenow=\"150\"` against a `valuemax` of 100.\n effect(() => {\n const clamped = wrClamp(this.position(), this.minPosition(), this.maxPosition());\n if (clamped !== this.position()) this.position.set(clamped);\n });\n }\n\n protected readonly classes = computed(() => {\n const parts = [`wr-compare--${this.orientation()}`];\n if (this.disabled()) parts.push('wr-compare--disabled');\n return parts.join(' ');\n });\n\n /**\n * Clip path applied to the \"after\" layer so the divider reveals it.\n *\n * `inset()` takes PHYSICAL edges and has no logical form, so the mirroring is done\n * here rather than in CSS: `position` counts from the inline-start edge, and under\n * RTL that edge is the right one, so the after layer is clipped from the right by\n * the same percentage.\n */\n protected readonly clipPath = computed(() => {\n const p = wrClamp(this.position(), 0, 100);\n if (this.orientation() === 'horizontal') {\n // Show from `p%` to the inline-end edge.\n return this.rtl() ? `inset(0 ${p}% 0 0)` : `inset(0 0 0 ${p}%)`;\n }\n // Block axis: `dir` does not touch it.\n return `inset(${p}% 0 0 0)`;\n });\n\n /**\n * Physical `left` percentage of the divider. Deliberately physical: it pairs with the\n * `translateX(-50%)` that centres the 2px line on its own position, and the two have\n * to agree on which edge they count from. `position` is logical, so RTL flips it here.\n */\n protected readonly dividerLeft = computed(() => (this.rtl() ? 100 - this.position() : this.position()));\n\n // Pointer handlers\n\n protected onPointerDown(event: PointerEvent): void {\n if (this.disabled()) return;\n // Any pointerdown used to start a drag, so the right button moved the divider; the\n // same guard keeps a second finger out of a drag already in progress.\n if (event.button !== 0 || !event.isPrimary) return;\n event.preventDefault();\n this.dragging = true;\n this.dragStart = this.position();\n const surface = event.currentTarget as HTMLElement;\n surface.setPointerCapture(event.pointerId);\n // `preventDefault` above also suppresses the click's default focus, so the arrows\n // did nothing after a mouse drag until the divider was found again with Tab.\n surface.focus();\n // A touch may still turn out to be a scroll along the other axis, which the\n // browser takes over with `pointercancel`, so it moves the divider from its first\n // move (or a tap's lift) rather than jumping it to where the finger came down.\n if (event.pointerType !== 'touch') this.updateFromPointer(event);\n }\n\n protected onPointerMove(event: PointerEvent): void {\n if (!this.dragging) return;\n // Turned disabled mid-drag: the gesture is over.\n if (this.disabled()) {\n this.dragging = false;\n return;\n }\n this.updateFromPointer(event);\n }\n\n protected onPointerUp(event: PointerEvent): void {\n if (!this.dragging) return;\n // A tap: the touch that never moved still sets the position where it lifted.\n if (event.pointerType === 'touch') this.updateFromPointer(event);\n this.dragging = false;\n (event.currentTarget as HTMLElement).releasePointerCapture(event.pointerId);\n }\n\n /**\n * The browser took the gesture over — a scroll along the axis `touch-action` leaves\n * to the page — so the drag never happened, and the divider goes back to where it\n * was rather than keeping whatever the first moves of a swipe said.\n */\n protected onPointerCancel(event: PointerEvent): void {\n if (!this.dragging) return;\n this.dragging = false;\n this.position.set(this.dragStart);\n const surface = event.currentTarget as HTMLElement;\n if (surface.hasPointerCapture(event.pointerId)) surface.releasePointerCapture(event.pointerId);\n }\n\n protected onKeydown(event: KeyboardEvent): void {\n if (this.disabled()) return;\n const step = event.shiftKey ? 10 : 1;\n // Steps count from the whole percent a reader was told, so a key after a drag\n // lands on a round number instead of carrying the drag's fraction along.\n const from = this.valueNow();\n let next: number | null = null;\n if (this.orientation() === 'horizontal') {\n // Arrows follow the VISUAL axis (WAI-ARIA APG). Under `dir=\"rtl\"` the \"before\"\n // side grows from the right, so the visual right is the low end of this slider's\n // range and ArrowRight has to decrease the value.\n const inline = this.rtl() ? -step : step;\n if (event.key === 'ArrowLeft') next = from - inline;\n else if (event.key === 'ArrowRight') next = from + inline;\n } else {\n // Block axis: unaffected by `dir`.\n if (event.key === 'ArrowUp') next = from - step;\n else if (event.key === 'ArrowDown') next = from + step;\n }\n // Home/End are semantic — first/last, not left/right — so they never mirror.\n if (event.key === 'Home') next = this.minPosition();\n else if (event.key === 'End') next = this.maxPosition();\n if (next === null) return;\n event.preventDefault();\n this.position.set(wrClamp(next, this.minPosition(), this.maxPosition()));\n }\n\n private updateFromPointer(event: PointerEvent): void {\n const rect = this.host.nativeElement.getBoundingClientRect();\n const horizontal = this.orientation() === 'horizontal';\n const extent = horizontal ? rect.width : rect.height;\n // A host that has not been laid out — hidden, detached, or a pane the browser has\n // throttled — measures 0, and dividing by it puts `Infinity` or `NaN` straight into\n // `aria-valuenow`. There is no meaningful position to compute, so keep the current one.\n if (extent <= 0) return;\n const raw = horizontal\n ? this.inlineFraction(event.clientX, rect) * 100\n : ((event.clientY - rect.top) / extent) * 100;\n this.position.set(wrClamp(raw, this.minPosition(), this.maxPosition()));\n }\n\n /**\n * Fraction of the host measured from the INLINE-START edge — the left edge in LTR, the\n * right edge in RTL, which is the side \"before\" is revealed from. Taken from\n * `rect.left` in both, a drag under `dir=\"rtl\"` read 0 at the visual maximum and moved\n * the divider opposite the pointer.\n */\n private inlineFraction(clientX: number, rect: DOMRect): number {\n return this.rtl() ? (rect.right - clientX) / rect.width : (clientX - rect.left) / rect.width;\n }\n}\n","<div\n class=\"wr-compare__surface\"\n role=\"slider\"\n [attr.aria-label]=\"resolvedAriaLabel()\"\n [attr.aria-orientation]=\"orientation()\"\n [attr.aria-valuemin]=\"minPosition()\"\n [attr.aria-valuemax]=\"maxPosition()\"\n [attr.aria-valuenow]=\"valueNow()\"\n [attr.aria-disabled]=\"disabled() || null\"\n [attr.tabindex]=\"disabled() ? -1 : 0\"\n (pointerdown)=\"onPointerDown($event)\"\n (pointermove)=\"onPointerMove($event)\"\n (pointerup)=\"onPointerUp($event)\"\n (pointercancel)=\"onPointerCancel($event)\"\n (keydown)=\"onKeydown($event)\"\n>\n <div class=\"wr-compare__layers\">\n <div class=\"wr-compare__layer wr-compare__layer--before\">\n <ng-content select=\"[wrCompareBefore]\" />\n </div>\n <div class=\"wr-compare__layer wr-compare__layer--after\" [style.clip-path]=\"clipPath()\">\n <ng-content select=\"[wrCompareAfter]\" />\n </div>\n </div>\n\n <div\n class=\"wr-compare__divider\"\n [style.left.%]=\"orientation() === 'horizontal' ? dividerLeft() : null\"\n [style.top.%]=\"orientation() === 'vertical' ? position() : null\"\n aria-hidden=\"true\"\n >\n @if (showHandle()) {\n <span class=\"wr-compare__handle\">\n @if (orientation() === 'horizontal') {\n <svg width=\"16\" height=\"16\" viewBox=\"0 0 16 16\" aria-hidden=\"true\">\n <path\n d=\"M5 4 L1 8 L5 12 M11 4 L15 8 L11 12\"\n fill=\"none\"\n stroke=\"currentColor\"\n stroke-width=\"1.5\"\n stroke-linecap=\"round\"\n stroke-linejoin=\"round\"\n />\n </svg>\n } @else {\n <svg width=\"16\" height=\"16\" viewBox=\"0 0 16 16\" aria-hidden=\"true\">\n <path\n d=\"M4 5 L8 1 L12 5 M4 11 L8 15 L12 11\"\n fill=\"none\"\n stroke=\"currentColor\"\n stroke-width=\"1.5\"\n stroke-linecap=\"round\"\n stroke-linejoin=\"round\"\n />\n </svg>\n }\n </span>\n }\n </div>\n</div>\n"],"mappings":";;;;;;;;;;;;;AAmEA,IAAa,YAAb,MAAa,UAAS;CAEX,WAAW,MAAM,IAAG,GAAA,YAAA,CAAA,EAAA,WAAA,WAAA,CAAA,+BAAA,CAAA,CAAA;CAGpB,YAAY,MAAqB,MAAK,GAAA,YAAA,CAAA,EAAA,WAAA,YAAA,CAAA,+BAAA,CAAA,CAAA;CAE5B,oBAAoB,YAAY,KAAK,WAAW,iBAAiB,oBAAoB;CAQ/F,cAAc,MAAiC,cAAa,GAAA,YAAA,CAAA,EAAA,WAAA,cAAA,CAAA,+BAAA,CAAA,CAAA;CAG5D,aAAa,MAAM,MAAI;EAAA,GAAA,YAAA,EAAA,WAAA,aAAA,+BAAA,CAAA;EAAI,WAAW;CAAqB,CAAA;CAG3D,WAAW,MAAM,OAAK;EAAA,GAAA,YAAA,EAAA,WAAA,WAAA,+BAAA,CAAA;EAAI,WAAW;CAAqB,CAAA;CAG1D,cAAc,MAAM,GAAC;EAAA,GAAA,YAAA,EAAA,WAAA,cAAA,+BAAA,CAAA;EAAI,YAAY,MAAuB,qBAAqB,GAAG,CAAC;CAAC,CAAA;CAGtF,cAAc,MAAM,KAAG;EAAA,GAAA,YAAA,EAAA,WAAA,cAAA,+BAAA,CAAA;EAAI,YAAY,MAAuB,qBAAqB,GAAG,GAAG;CAAC,CAAA;CAElF,OAAO,OAAgC,UAAU;CAGjD,MAAM,OAAO,gBAAgB,EAAE,UAAU,KAAI,CAAE;CAS/C,MAAM,OAAO,KAAK,KAAK,UAAU,OAAM,GAAA,YAAA,CAAA,EAAA,WAAA,MAAA,CAAA,+BAAA,CAAA,CAAA;CAEhD,WAAW;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AAA,UAAA;IAAA,YAAA;IAAA,mBAAA;GAAA;GAAA,aAAA;IAAA,mBAAA;IAAA,YAAA;IAAA,UAAA;IAAA,YAAA;IAAA,mBAAA;GAAA;GAAA,aAAA;IAAA,mBAAA;IAAA,YAAA;IAAA,UAAA;IAAA,YAAA;IAAA,mBAAA;GAAA;EAAA;EAAA,SAAA,EAAA,UAAA,iBAAA;EAAA,MAAA;GAAA,YAAA,EAAA,SAAA,YAAA;GAAA,gBAAA;EAAA;EAAA,UAAA;EAAA,UCnEtB;EA4DA,eAAA,GAAA,kBAAA;CAAA,CAAA;;ADOa,GAAA,yBAAA;CAAA,YAAA;CAAA,SAAA;CAAA,UAAA;CAAA,MAAA;CAAS,YAAA,CAAA;EANrB,MAAA;EACW,MAAA,CAAA;GAAA,UAAA;GAAY,eAEP,kBAAkB;GAAI,MAC/B;IAAE,OAAO;IAAc,WAAW;GAAW;GAAE,UAAA;EAAA,CAAA"}
|
package/fesm2022/ngwr-cookie.mjs
CHANGED
|
@@ -47,9 +47,12 @@ var WrCookie = class WrCookie {
|
|
|
47
47
|
if (opts.expires instanceof Date) parts.push(`expires=${opts.expires.toUTCString()}`);
|
|
48
48
|
else parts.push(`max-age=${Math.max(0, Math.floor(opts.expires))}`);
|
|
49
49
|
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
50
|
+
const lowerKey = key.toLowerCase();
|
|
51
|
+
const host = lowerKey.startsWith("__host-");
|
|
52
|
+
const prefixed = host || lowerKey.startsWith("__secure-");
|
|
53
|
+
parts.push(`path=${host ? "/" : opts.path}`);
|
|
54
|
+
if (opts.domain && !host) parts.push(`domain=${opts.domain}`);
|
|
55
|
+
if (opts.secure || prefixed || opts.sameSite === "None") parts.push("secure");
|
|
53
56
|
parts.push(`samesite=${opts.sameSite}`);
|
|
54
57
|
try {
|
|
55
58
|
this.doc.cookie = parts.join("; ");
|