@dile/ui 3.21.2 → 3.22.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/components/input/src/DileInput.js +2 -22
- package/components/input/src/DileInputMessage.js +25 -6
- package/components/scroll-reveal/index.js +1 -0
- package/components/scroll-reveal/scroll-reveal.js +5 -0
- package/components/scroll-reveal/src/DileScrollReveal.js +45 -0
- package/components/select/src/DileSelect.js +4 -3
- package/mixins/form/index.js +2 -1
- package/mixins/form/src/DileFieldMessage.js +42 -0
- package/mixins/scroll-reveal/index.js +2 -0
- package/mixins/scroll-reveal/src/DileScrollRevealMixin.js +283 -0
- package/mixins/scroll-reveal/src/reveal-styles.js +32 -0
- package/package.json +2 -2
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { LitElement, html, css } from 'lit';
|
|
2
2
|
import { ifDefined } from 'lit/directives/if-defined.js';
|
|
3
|
-
import { DileEmmitChange } from '../../../mixins/form/index.js';
|
|
3
|
+
import { DileEmmitChange, DileFieldMessage } from '../../../mixins/form/index.js';
|
|
4
4
|
import { labelStyles } from './label-styles.js';
|
|
5
5
|
import { messageStyles } from './message-styles.js';
|
|
6
6
|
|
|
7
|
-
export class DileInput extends DileEmmitChange(LitElement) {
|
|
7
|
+
export class DileInput extends DileFieldMessage(DileEmmitChange(LitElement)) {
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
10
|
* Fired when user press enter key.
|
|
@@ -41,9 +41,6 @@ export class DileInput extends DileEmmitChange(LitElement) {
|
|
|
41
41
|
/** Name for this input field */
|
|
42
42
|
name: { type: String, reflect: true },
|
|
43
43
|
|
|
44
|
-
/** Has error on this input field */
|
|
45
|
-
errored: { type: Boolean },
|
|
46
|
-
|
|
47
44
|
/** Disable the autocomplete of the input field */
|
|
48
45
|
disableAutocomplete: { type: Boolean },
|
|
49
46
|
|
|
@@ -53,9 +50,6 @@ export class DileInput extends DileEmmitChange(LitElement) {
|
|
|
53
50
|
/** Select all content on focus */
|
|
54
51
|
selectOnFocus: { type: Boolean },
|
|
55
52
|
|
|
56
|
-
/** Message Displayed */
|
|
57
|
-
message: { type: String },
|
|
58
|
-
|
|
59
53
|
/** Text placed on the right side of the input */
|
|
60
54
|
labelRight: { type: String },
|
|
61
55
|
|
|
@@ -197,15 +191,6 @@ export class DileInput extends DileEmmitChange(LitElement) {
|
|
|
197
191
|
return !this.label && this.accessibleLabel ? this.accessibleLabel : undefined;
|
|
198
192
|
}
|
|
199
193
|
|
|
200
|
-
get messageTemplate() {
|
|
201
|
-
return html`
|
|
202
|
-
${this.message
|
|
203
|
-
? html`<div class="message ${this.errored ? 'errored-msg' : ''}"><span>${this.message}</span></div>`
|
|
204
|
-
: ''
|
|
205
|
-
}
|
|
206
|
-
`
|
|
207
|
-
}
|
|
208
|
-
|
|
209
194
|
/**
|
|
210
195
|
* Private method to dispatch events on enter key pressed
|
|
211
196
|
*/
|
|
@@ -222,11 +207,6 @@ export class DileInput extends DileEmmitChange(LitElement) {
|
|
|
222
207
|
}
|
|
223
208
|
}
|
|
224
209
|
|
|
225
|
-
clearError() {
|
|
226
|
-
this.errored = false;
|
|
227
|
-
this.message = '';
|
|
228
|
-
}
|
|
229
|
-
|
|
230
210
|
availableType(type) {
|
|
231
211
|
if(this.types.includes(type)) {
|
|
232
212
|
return type;
|
|
@@ -1,12 +1,31 @@
|
|
|
1
|
-
import { html } from 'lit';
|
|
2
|
-
import {
|
|
1
|
+
import { LitElement, html, css } from 'lit';
|
|
2
|
+
import { DileFieldMessage } from '../../../mixins/form/index.js';
|
|
3
|
+
import { messageStyles } from './message-styles.js';
|
|
4
|
+
|
|
5
|
+
export class DileInputMessage extends DileFieldMessage(LitElement) {
|
|
6
|
+
|
|
7
|
+
static get properties() {
|
|
8
|
+
return {
|
|
9
|
+
/** Name used by DileForm to locate this element and show errors on it */
|
|
10
|
+
name: { type: String, reflect: true },
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
static get styles() {
|
|
15
|
+
return [
|
|
16
|
+
messageStyles,
|
|
17
|
+
css`
|
|
18
|
+
:host {
|
|
19
|
+
display: block;
|
|
20
|
+
}
|
|
21
|
+
`
|
|
22
|
+
];
|
|
23
|
+
}
|
|
3
24
|
|
|
4
|
-
export class DileInputMessage extends DileInput {
|
|
5
|
-
|
|
6
25
|
render() {
|
|
7
26
|
return html`
|
|
8
|
-
${this.messageTemplate}
|
|
27
|
+
${this.messageTemplate}
|
|
9
28
|
`
|
|
10
29
|
}
|
|
11
30
|
|
|
12
|
-
}
|
|
31
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { DileScrollReveal } from './src/DileScrollReveal.js';
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { LitElement, css } from "lit";
|
|
2
|
+
import { DileScrollRevealMixin, revealStyles } from "../../../mixins/scroll-reveal/index.js";
|
|
3
|
+
|
|
4
|
+
const FALLBACK_STYLE_ID = 'dile-scroll-reveal-styles';
|
|
5
|
+
|
|
6
|
+
/** Adds the reveal base styles to the page once, however many instances are connected. */
|
|
7
|
+
function adoptRevealStylesInDocument() {
|
|
8
|
+
const sheet = revealStyles.styleSheet;
|
|
9
|
+
if (sheet && Array.isArray(document.adoptedStyleSheets)) {
|
|
10
|
+
if (!document.adoptedStyleSheets.includes(sheet)) {
|
|
11
|
+
document.adoptedStyleSheets = [...document.adoptedStyleSheets, sheet];
|
|
12
|
+
}
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
// Browsers without constructable stylesheets.
|
|
16
|
+
if (!document.getElementById(FALLBACK_STYLE_ID)) {
|
|
17
|
+
const style = document.createElement('style');
|
|
18
|
+
style.id = FALLBACK_STYLE_ID;
|
|
19
|
+
style.textContent = revealStyles.cssText;
|
|
20
|
+
document.head.appendChild(style);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Page-level scroll reveal orchestrator. One instance anywhere in the page reveals every
|
|
26
|
+
* `[data-reveal]` / `[data-reveal-group]` element of the document. It renders nothing.
|
|
27
|
+
*/
|
|
28
|
+
export class DileScrollReveal extends DileScrollRevealMixin(LitElement) {
|
|
29
|
+
static get styles() {
|
|
30
|
+
return css`
|
|
31
|
+
:host {
|
|
32
|
+
display: none;
|
|
33
|
+
}
|
|
34
|
+
`;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
get revealRoot() {
|
|
38
|
+
return document;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
connectedCallback() {
|
|
42
|
+
adoptRevealStylesInDocument();
|
|
43
|
+
super.connectedCallback();
|
|
44
|
+
}
|
|
45
|
+
}
|
|
@@ -188,13 +188,14 @@ export class DileSelect extends DileEmmitChange(LitElement) {
|
|
|
188
188
|
|
|
189
189
|
updated(changedProperties) {
|
|
190
190
|
if(changedProperties.has("value")) {
|
|
191
|
-
|
|
191
|
+
// null/undefined would be stringified and leave the select without a selected option
|
|
192
|
+
this.elselect.value = this.value ?? '';
|
|
192
193
|
if (this.quiet) {
|
|
193
194
|
this.quiet = false;
|
|
194
195
|
} else {
|
|
195
196
|
this.emmitChange();
|
|
196
197
|
}
|
|
197
|
-
this.internals.setFormValue(this.value);
|
|
198
|
+
this.internals.setFormValue(this.value ?? '');
|
|
198
199
|
}
|
|
199
200
|
if(changedProperties.has("disabled")) {
|
|
200
201
|
this.elselect.disabled = this.disabled;
|
|
@@ -256,7 +257,7 @@ export class DileSelect extends DileEmmitChange(LitElement) {
|
|
|
256
257
|
}
|
|
257
258
|
|
|
258
259
|
clear() {
|
|
259
|
-
this.value =
|
|
260
|
+
this.value = '';
|
|
260
261
|
}
|
|
261
262
|
|
|
262
263
|
getOptionByValue(id) {
|
package/mixins/form/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
export { DileForm } from "./src/DileForm.js";
|
|
2
2
|
export { DileFormChangeDetect } from "./src/DileFormChangeDetect.js";
|
|
3
|
-
export { DileEmmitChange } from "./src/DileEmmitChange.js";
|
|
3
|
+
export { DileEmmitChange } from "./src/DileEmmitChange.js";
|
|
4
|
+
export { DileFieldMessage } from "./src/DileFieldMessage.js";
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { html } from 'lit';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
*
|
|
5
|
+
* # DileFieldMessage
|
|
6
|
+
*
|
|
7
|
+
* Mixin to display a feedback / validation message in form components.
|
|
8
|
+
* Provides the `message` and `errored` properties, the `messageTemplate`
|
|
9
|
+
* getter and the `clearError()` method.
|
|
10
|
+
*
|
|
11
|
+
* Components using this mixin should include `messageStyles`
|
|
12
|
+
* (from `@dile/ui/components/input`) in their styles.
|
|
13
|
+
*
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
export const DileFieldMessage = (superclass) => class extends superclass {
|
|
17
|
+
|
|
18
|
+
static get properties() {
|
|
19
|
+
return {
|
|
20
|
+
/** Message Displayed */
|
|
21
|
+
message: { type: String },
|
|
22
|
+
|
|
23
|
+
/** Has error on this field */
|
|
24
|
+
errored: { type: Boolean },
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
get messageTemplate() {
|
|
29
|
+
return html`
|
|
30
|
+
${this.message
|
|
31
|
+
? html`<div class="message ${this.errored ? 'errored-msg' : ''}"><span>${this.message}</span></div>`
|
|
32
|
+
: ''
|
|
33
|
+
}
|
|
34
|
+
`
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
clearError() {
|
|
38
|
+
this.errored = false;
|
|
39
|
+
this.message = '';
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
}
|
|
@@ -0,0 +1,283 @@
|
|
|
1
|
+
const DEFAULT_MEDIA = '(min-width: 1024px)';
|
|
2
|
+
const DEFAULT_OFFSET = 0.15;
|
|
3
|
+
const DEFAULT_STAGGER = 140;
|
|
4
|
+
const DEFAULT_GROUP_STAGGER = 220;
|
|
5
|
+
const REDUCED_MOTION_QUERY = '(prefers-reduced-motion: reduce)';
|
|
6
|
+
|
|
7
|
+
const TARGETS_SELECTOR = '[data-reveal-group], [data-reveal]';
|
|
8
|
+
const STATE_ATTRIBUTE = 'data-reveal-state';
|
|
9
|
+
const PENDING = 'pending';
|
|
10
|
+
const REVEALED = 'revealed';
|
|
11
|
+
const DELAY_PROPERTY = '--dile-reveal-delay';
|
|
12
|
+
|
|
13
|
+
function parseOffset(value, fallback) {
|
|
14
|
+
if (value === null || value === undefined || value === '') return fallback;
|
|
15
|
+
const offset = parseFloat(value);
|
|
16
|
+
return Number.isFinite(offset) && offset >= 0 && offset < 1 ? offset : fallback;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function parseMilliseconds(value, fallback) {
|
|
20
|
+
if (value === null || value === undefined || value === '') return fallback;
|
|
21
|
+
const amount = parseInt(value, 10);
|
|
22
|
+
return Number.isFinite(amount) && amount >= 0 ? amount : fallback;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function byDocumentOrder(a, b) {
|
|
26
|
+
return a.compareDocumentPosition(b) & Node.DOCUMENT_POSITION_FOLLOWING ? -1 : 1;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function isGroup(element) {
|
|
30
|
+
return element.hasAttribute('data-reveal-group');
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Reveals elements progressively while the user scrolls, using IntersectionObserver.
|
|
35
|
+
*
|
|
36
|
+
* Elements inside `revealRoot` are configured with data attributes:
|
|
37
|
+
* - `data-reveal` (`""`, `"from-right"`, `"from-left"` or `"trigger"`)
|
|
38
|
+
* - `data-reveal-group`, `data-reveal-stagger`
|
|
39
|
+
* - `data-reveal-offset`, `data-reveal-media`
|
|
40
|
+
*
|
|
41
|
+
* The mixin sets `data-reveal-state="pending|revealed"` and `--dile-reveal-delay` on the
|
|
42
|
+
* managed elements; `revealStyles` turns those states into the hide/show transition.
|
|
43
|
+
*/
|
|
44
|
+
export const DileScrollRevealMixin = (superclass) => class extends superclass {
|
|
45
|
+
static get properties() {
|
|
46
|
+
return {
|
|
47
|
+
/** Media query that enables the effect. Elements can override it with `data-reveal-media`. */
|
|
48
|
+
media: { type: String },
|
|
49
|
+
/** Fraction of the viewport height, from the bottom, an element must enter before revealing. */
|
|
50
|
+
offset: { type: Number },
|
|
51
|
+
/** Milliseconds between loose elements revealed in the same batch. */
|
|
52
|
+
stagger: { type: Number },
|
|
53
|
+
/** Default milliseconds between the children of a group. */
|
|
54
|
+
groupStagger: { type: Number, attribute: 'group-stagger' },
|
|
55
|
+
/** Watch the root with a MutationObserver to pick up elements added later. */
|
|
56
|
+
watch: { type: Boolean },
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
constructor(...args) {
|
|
61
|
+
super(...args);
|
|
62
|
+
this.media = DEFAULT_MEDIA;
|
|
63
|
+
this.offset = DEFAULT_OFFSET;
|
|
64
|
+
this.stagger = DEFAULT_STAGGER;
|
|
65
|
+
this.groupStagger = DEFAULT_GROUP_STAGGER;
|
|
66
|
+
this.watch = false;
|
|
67
|
+
this._revealStarted = false;
|
|
68
|
+
this._revealObservers = new Map();
|
|
69
|
+
this._revealMediaLists = new Map();
|
|
70
|
+
this._revealMutationObserver = null;
|
|
71
|
+
this._revealMediaChangeHandler = () => this.refreshReveal();
|
|
72
|
+
this._revealDomReadyHandler = () => this._startReveal();
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** Node whose descendants are revealed; the component's render root by default. */
|
|
76
|
+
get revealRoot() {
|
|
77
|
+
return this.renderRoot ?? this;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
connectedCallback() {
|
|
81
|
+
super.connectedCallback?.();
|
|
82
|
+
if (this.hasUpdated) this._startReveal();
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
firstUpdated(changedProperties) {
|
|
86
|
+
super.firstUpdated?.(changedProperties);
|
|
87
|
+
this._startReveal();
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
updated(changedProperties) {
|
|
91
|
+
super.updated?.(changedProperties);
|
|
92
|
+
if (!this._revealStarted) return;
|
|
93
|
+
if (changedProperties.has('watch')) this._updateRevealMutationObserver();
|
|
94
|
+
if (changedProperties.has('media')) this.refreshReveal();
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
disconnectedCallback() {
|
|
98
|
+
super.disconnectedCallback?.();
|
|
99
|
+
this._stopReveal();
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/** Rescans the root: new elements are prepared and elements are re-evaluated against their media queries. */
|
|
103
|
+
refreshReveal() {
|
|
104
|
+
if (!this._revealStarted) return;
|
|
105
|
+
const root = this.revealRoot;
|
|
106
|
+
if (!root) return;
|
|
107
|
+
this._getRevealTargets(root).forEach((target) => this._prepareRevealTarget(target));
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/** Shows every managed element immediately and stops observing. */
|
|
111
|
+
revealAll() {
|
|
112
|
+
const root = this.revealRoot;
|
|
113
|
+
if (root) {
|
|
114
|
+
this._getRevealTargets(root).forEach((target) => this._revealTarget(target, 0, false));
|
|
115
|
+
}
|
|
116
|
+
this._disconnectRevealObservers();
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
_startReveal() {
|
|
120
|
+
if (this._revealStarted || !this.isConnected) return;
|
|
121
|
+
if (document.readyState === 'loading') {
|
|
122
|
+
document.addEventListener('DOMContentLoaded', this._revealDomReadyHandler, { once: true });
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
this._revealStarted = true;
|
|
126
|
+
this._listenRevealMedia(REDUCED_MOTION_QUERY);
|
|
127
|
+
this._updateRevealMutationObserver();
|
|
128
|
+
this.refreshReveal();
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
_stopReveal() {
|
|
132
|
+
document.removeEventListener('DOMContentLoaded', this._revealDomReadyHandler);
|
|
133
|
+
this._revealStarted = false;
|
|
134
|
+
this._disconnectRevealObservers();
|
|
135
|
+
this._revealMutationObserver?.disconnect();
|
|
136
|
+
this._revealMutationObserver = null;
|
|
137
|
+
this._revealMediaLists.forEach((mediaList) => {
|
|
138
|
+
mediaList.removeEventListener?.('change', this._revealMediaChangeHandler);
|
|
139
|
+
});
|
|
140
|
+
this._revealMediaLists.clear();
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
_disconnectRevealObservers() {
|
|
144
|
+
this._revealObservers.forEach((observer) => observer.disconnect());
|
|
145
|
+
this._revealObservers.clear();
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
_updateRevealMutationObserver() {
|
|
149
|
+
if (this.watch && !this._revealMutationObserver && typeof MutationObserver === 'function') {
|
|
150
|
+
const root = this.revealRoot;
|
|
151
|
+
if (!root) return;
|
|
152
|
+
this._revealMutationObserver = new MutationObserver(() => this.refreshReveal());
|
|
153
|
+
this._revealMutationObserver.observe(root, {
|
|
154
|
+
childList: true,
|
|
155
|
+
subtree: true,
|
|
156
|
+
attributes: true,
|
|
157
|
+
attributeFilter: ['data-reveal', 'data-reveal-group'],
|
|
158
|
+
});
|
|
159
|
+
} else if (!this.watch && this._revealMutationObserver) {
|
|
160
|
+
this._revealMutationObserver.disconnect();
|
|
161
|
+
this._revealMutationObserver = null;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/** Groups and loose elements (elements inside a group are driven by their group). */
|
|
166
|
+
_getRevealTargets(root) {
|
|
167
|
+
return [...root.querySelectorAll(TARGETS_SELECTOR)]
|
|
168
|
+
.filter((element) => isGroup(element) || !element.parentElement?.closest('[data-reveal-group]'));
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
_getRevealMembers(target) {
|
|
172
|
+
return isGroup(target) ? [target, ...target.querySelectorAll('[data-reveal]')] : [target];
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
_prepareRevealTarget(target) {
|
|
176
|
+
const state = target.getAttribute(STATE_ATTRIBUTE);
|
|
177
|
+
if (state === REVEALED) return;
|
|
178
|
+
|
|
179
|
+
if (!this._isRevealEnabledFor(target)) {
|
|
180
|
+
if (state === PENDING) {
|
|
181
|
+
this._unobserveRevealTarget(target);
|
|
182
|
+
this._getRevealMembers(target).forEach((member) => member.removeAttribute(STATE_ATTRIBUTE));
|
|
183
|
+
}
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
if (state === PENDING) {
|
|
188
|
+
// Elements added to a pending group later on wait for the group too.
|
|
189
|
+
this._getRevealMembers(target)
|
|
190
|
+
.filter((member) => !member.hasAttribute(STATE_ATTRIBUTE))
|
|
191
|
+
.forEach((member) => member.setAttribute(STATE_ATTRIBUTE, PENDING));
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
// Already past its offset line (e.g. arriving through an anchor): shown before hiding anything.
|
|
196
|
+
if (this._isPastRevealLine(target)) {
|
|
197
|
+
this._revealTarget(target, 0, false);
|
|
198
|
+
return;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
this._getRevealMembers(target).forEach((member) => member.setAttribute(STATE_ATTRIBUTE, PENDING));
|
|
202
|
+
this._observeRevealTarget(target);
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
_isRevealEnabledFor(target) {
|
|
206
|
+
if (typeof IntersectionObserver !== 'function') return false;
|
|
207
|
+
if (this._revealMediaMatches(REDUCED_MOTION_QUERY)) return false;
|
|
208
|
+
const query = target.getAttribute('data-reveal-media') || this.media || DEFAULT_MEDIA;
|
|
209
|
+
return this._revealMediaMatches(query);
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
_revealMediaMatches(query) {
|
|
213
|
+
const mediaList = this._listenRevealMedia(query);
|
|
214
|
+
return mediaList ? mediaList.matches : query !== REDUCED_MOTION_QUERY;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
_listenRevealMedia(query) {
|
|
218
|
+
if (typeof matchMedia !== 'function') return null;
|
|
219
|
+
let mediaList = this._revealMediaLists.get(query);
|
|
220
|
+
if (!mediaList) {
|
|
221
|
+
mediaList = matchMedia(query);
|
|
222
|
+
mediaList.addEventListener?.('change', this._revealMediaChangeHandler);
|
|
223
|
+
this._revealMediaLists.set(query, mediaList);
|
|
224
|
+
}
|
|
225
|
+
return mediaList;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
_getRevealOffset(target) {
|
|
229
|
+
return parseOffset(target.getAttribute('data-reveal-offset'), parseOffset(this.offset, DEFAULT_OFFSET));
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
_isPastRevealLine(target) {
|
|
233
|
+
const rect = target.getBoundingClientRect();
|
|
234
|
+
const viewportHeight = window.innerHeight || document.documentElement.clientHeight;
|
|
235
|
+
return rect.top < viewportHeight * (1 - this._getRevealOffset(target)) && rect.bottom > 0;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
_observeRevealTarget(target) {
|
|
239
|
+
const offset = this._getRevealOffset(target);
|
|
240
|
+
let observer = this._revealObservers.get(offset);
|
|
241
|
+
if (!observer) {
|
|
242
|
+
observer = new IntersectionObserver((entries) => this._onRevealIntersection(entries, observer), {
|
|
243
|
+
rootMargin: `0px 0px -${offset * 100}% 0px`,
|
|
244
|
+
});
|
|
245
|
+
this._revealObservers.set(offset, observer);
|
|
246
|
+
}
|
|
247
|
+
observer.observe(target);
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
_unobserveRevealTarget(target) {
|
|
251
|
+
this._revealObservers.forEach((observer) => observer.unobserve(target));
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
_onRevealIntersection(entries, observer) {
|
|
255
|
+
const stagger = parseMilliseconds(this.stagger, DEFAULT_STAGGER);
|
|
256
|
+
entries
|
|
257
|
+
.filter((entry) => entry.isIntersecting)
|
|
258
|
+
.map((entry) => entry.target)
|
|
259
|
+
.sort(byDocumentOrder)
|
|
260
|
+
.forEach((target, index) => {
|
|
261
|
+
observer.unobserve(target);
|
|
262
|
+
this._revealTarget(target, index * stagger);
|
|
263
|
+
});
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
_revealTarget(target, delay = 0, animate = true) {
|
|
267
|
+
this._setRevealed(target, animate ? delay : 0);
|
|
268
|
+
if (!isGroup(target)) return;
|
|
269
|
+
// Group children are revealed one after another in time, in document order.
|
|
270
|
+
const step = parseMilliseconds(
|
|
271
|
+
target.getAttribute('data-reveal-stagger'),
|
|
272
|
+
parseMilliseconds(this.groupStagger, DEFAULT_GROUP_STAGGER),
|
|
273
|
+
);
|
|
274
|
+
target.querySelectorAll('[data-reveal]').forEach((member, index) => {
|
|
275
|
+
this._setRevealed(member, animate ? delay + index * step : 0);
|
|
276
|
+
});
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
_setRevealed(element, delay) {
|
|
280
|
+
element.style.setProperty(DELAY_PROPERTY, `${delay}ms`);
|
|
281
|
+
element.setAttribute(STATE_ATTRIBUTE, REVEALED);
|
|
282
|
+
}
|
|
283
|
+
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { css } from 'lit';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Base hide/show styles for the elements managed by DileScrollRevealMixin.
|
|
5
|
+
*
|
|
6
|
+
* They only act on elements that have a `data-reveal-state` attribute, which the mixin sets
|
|
7
|
+
* when the effect is enabled. Without JavaScript, or when the effect is disabled, no state is
|
|
8
|
+
* set and the elements are simply visible. `data-reveal="trigger"` elements are never hidden.
|
|
9
|
+
* The transition lives in the revealed state, so pending elements are hidden instantly and
|
|
10
|
+
* only the pending -> revealed change is animated.
|
|
11
|
+
*/
|
|
12
|
+
export const revealStyles = css`
|
|
13
|
+
[data-reveal][data-reveal-state="revealed"]:not([data-reveal="trigger"]) {
|
|
14
|
+
transition:
|
|
15
|
+
opacity var(--dile-reveal-duration, 0.7s) ease var(--dile-reveal-delay, 0ms),
|
|
16
|
+
transform var(--dile-reveal-duration, 0.7s) var(--dile-reveal-easing, cubic-bezier(0.22, 1, 0.36, 1)) var(--dile-reveal-delay, 0ms);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
[data-reveal][data-reveal-state="pending"]:not([data-reveal="trigger"]) {
|
|
20
|
+
opacity: 0;
|
|
21
|
+
transform: translateY(var(--dile-reveal-distance, 1.75rem));
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/* Same specificity as the base pending rule (3 attribute selectors) so the direction wins. */
|
|
25
|
+
[data-reveal][data-reveal="from-right"][data-reveal-state="pending"] {
|
|
26
|
+
transform: translateX(var(--dile-reveal-distance-x, 2.5rem));
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
[data-reveal][data-reveal="from-left"][data-reveal-state="pending"] {
|
|
30
|
+
transform: translateX(calc(-1 * var(--dile-reveal-distance-x, 2.5rem)));
|
|
31
|
+
}
|
|
32
|
+
`;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dile/ui",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.22.0",
|
|
4
4
|
"description": "UI Core components from dile-components.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -28,5 +28,5 @@
|
|
|
28
28
|
"publishConfig": {
|
|
29
29
|
"access": "public"
|
|
30
30
|
},
|
|
31
|
-
"gitHead": "
|
|
31
|
+
"gitHead": "707eaedea1d20e5e5bb081d9a05fab7acc1d698c"
|
|
32
32
|
}
|