@thednp/shorty 2.0.4 → 2.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -3
- package/dist/shorty.cjs +17 -1
- package/dist/shorty.cjs.map +1 -1
- package/dist/shorty.d.ts +18 -6
- package/dist/shorty.js +17 -1
- package/dist/shorty.js.map +1 -1
- package/dist/shorty.mjs +418 -384
- package/dist/shorty.mjs.map +1 -1
- package/dts.config.ts +1 -7
- package/package.json +12 -14
- package/src/boolean/isMobile.ts +1 -1
- package/src/boolean/supportPassive.ts +1 -1
- package/src/get/getRectRelativeToOffsetParent.ts +1 -1
- package/src/index.ts +6 -0
- package/src/misc/createCustomEvent.ts +2 -2
- package/src/misc/data.ts +2 -5
- package/src/misc/emulateAnimationEnd.ts +4 -4
- package/src/misc/emulateTransitionEnd.ts +3 -3
- package/src/misc/focusTrap.ts +64 -0
- package/src/misc/normalizeOptions.ts +2 -2
- package/src/misc/timer.ts +3 -3
- package/src/selectors/getCustomElements.ts +1 -2
- package/src/selectors/getElementById.ts +2 -2
- package/src/selectors/getElementsByClassName.ts +2 -7
- package/src/selectors/getElementsByTagName.ts +2 -5
- package/src/selectors/querySelector.ts +6 -3
- package/src/selectors/querySelectorAll.ts +4 -1
- package/src/strings/focusableSelector.ts +4 -0
- package/test/fixtures/getExampleDom.ts +12 -8
- package/test/is.test.ts +15 -11
- package/test/misc.test.ts +65 -17
- package/{vite.config.ts → vite.config.mts} +3 -8
- /package/{vitest.config-ui.ts → vitest.config-ui.mts} +0 -0
- /package/{vitest.config.ts → vitest.config.mts} +0 -0
package/test/misc.test.ts
CHANGED
|
@@ -6,13 +6,16 @@ import "./fixtures/style.css";
|
|
|
6
6
|
describe('Shorty Library Tests - MISC', () => {
|
|
7
7
|
const wrapper = document.createElement('div');
|
|
8
8
|
document.body.append(wrapper);
|
|
9
|
+
|
|
9
10
|
afterEach(async () => {
|
|
10
11
|
wrapper.innerHTML = '';
|
|
11
12
|
});
|
|
12
13
|
|
|
13
|
-
it('Test misc folder - emulateTransitionEnd - no transition', () => {
|
|
14
|
+
it('Test misc folder - emulateTransitionEnd - no transition', async () => {
|
|
15
|
+
vi.useFakeTimers();
|
|
14
16
|
const container = getExampleDOM();
|
|
15
17
|
wrapper.append(container);
|
|
18
|
+
await vi.waitFor(() => container.querySelector('.alert'), 200);
|
|
16
19
|
|
|
17
20
|
const {
|
|
18
21
|
dispatchEvent,
|
|
@@ -57,16 +60,18 @@ describe('Shorty Library Tests - MISC', () => {
|
|
|
57
60
|
dispatchEvent(el, alertHideEvent);
|
|
58
61
|
emulateTransitionEnd(el, function () {
|
|
59
62
|
addClass(el, 'show');
|
|
63
|
+
vi.advanceTimersByTime(350);
|
|
60
64
|
});
|
|
61
65
|
});
|
|
62
66
|
|
|
63
67
|
btn.click();
|
|
64
68
|
});
|
|
65
69
|
|
|
66
|
-
it('Test misc folder - emulateTransitionEnd - default', () => {
|
|
70
|
+
it('Test misc folder - emulateTransitionEnd - default', async () => {
|
|
67
71
|
vi.useFakeTimers();
|
|
68
72
|
const container = getExampleDOM();
|
|
69
73
|
wrapper.append(container);
|
|
74
|
+
await vi.waitFor(() => container.querySelector('.alert'), 200);
|
|
70
75
|
|
|
71
76
|
const {
|
|
72
77
|
dispatchEvent,
|
|
@@ -79,7 +84,7 @@ describe('Shorty Library Tests - MISC', () => {
|
|
|
79
84
|
one,
|
|
80
85
|
focus,
|
|
81
86
|
} = SHORTY;
|
|
82
|
-
|
|
87
|
+
|
|
83
88
|
const el = querySelector('.alert', container) as HTMLElement;
|
|
84
89
|
const btn = querySelector('.btn-close', el) as HTMLButtonElement;
|
|
85
90
|
const alertHideEvent = createCustomEvent('hide-alert', { relatedTarget: null });
|
|
@@ -99,62 +104,105 @@ describe('Shorty Library Tests - MISC', () => {
|
|
|
99
104
|
addClass(el, 'show');
|
|
100
105
|
focus(btn, { preventScroll: false });
|
|
101
106
|
console.log('transitionend triggered');
|
|
107
|
+
vi.advanceTimersByTime(350);
|
|
102
108
|
});
|
|
103
|
-
vi.advanceTimersByTime(350);
|
|
104
109
|
});
|
|
105
110
|
|
|
106
|
-
btn
|
|
111
|
+
btn.click();
|
|
112
|
+
});
|
|
107
113
|
|
|
114
|
+
it("Can use focus trap", async () => {
|
|
115
|
+
const container = getExampleDOM();
|
|
116
|
+
const { focus, toggleFocusTrap, focusableSelector } = SHORTY;
|
|
117
|
+
wrapper.append(container);
|
|
118
|
+
await vi.waitFor(() => container.querySelector('.alert'), 200);
|
|
119
|
+
const element = container.querySelector<HTMLElement>('.alert')!;
|
|
120
|
+
const firstFocusable = element.querySelector<SHORTY.FocusableElement>(focusableSelector)!;
|
|
121
|
+
const table = container.querySelector<HTMLElement>('table')!;
|
|
122
|
+
const doc = element.ownerDocument!;
|
|
123
|
+
|
|
124
|
+
focus(firstFocusable);
|
|
125
|
+
toggleFocusTrap(element);
|
|
126
|
+
element.dispatchEvent(new KeyboardEvent('keydown', { bubbles: true, code: 'Tab', key: 'Tab', shiftKey: true }));
|
|
127
|
+
element.dispatchEvent(new KeyboardEvent('keydown', { bubbles: true, code: 'Tab', key: 'Tab', shiftKey: true }));
|
|
128
|
+
element.dispatchEvent(new KeyboardEvent('keydown', { bubbles: true, code: 'Tab', key: 'Tab', shiftKey: true }));
|
|
129
|
+
element.dispatchEvent(new KeyboardEvent('keydown', { bubbles: true, code: 'Tab', key: 'Tab', shiftKey: true }));
|
|
130
|
+
element.dispatchEvent(new KeyboardEvent('keydown', { bubbles: true, code: 'Tab', key: 'Tab', shiftKey: true }));
|
|
131
|
+
element.dispatchEvent(new KeyboardEvent('keydown', { bubbles: true, code: 'Tab', key: 'Tab', }));
|
|
132
|
+
element.dispatchEvent(new KeyboardEvent('keydown', { bubbles: true, code: 'Tab', key: 'Tab', }));
|
|
133
|
+
element.dispatchEvent(new KeyboardEvent('keydown', { bubbles: true, code: 'Tab', key: 'Tab', }));
|
|
134
|
+
element.dispatchEvent(new KeyboardEvent('keydown', { bubbles: true, code: 'Tab', key: 'Tab', }));
|
|
135
|
+
element.dispatchEvent(new KeyboardEvent('keydown', { bubbles: true, code: 'Tab', key: 'Tab', }));
|
|
136
|
+
|
|
137
|
+
await vi.waitFor(() => {
|
|
138
|
+
expect(element).to.contain(doc.activeElement);
|
|
139
|
+
}, 50)
|
|
140
|
+
toggleFocusTrap(element);
|
|
141
|
+
|
|
142
|
+
toggleFocusTrap(table);
|
|
143
|
+
table.dispatchEvent(new KeyboardEvent('keydown', { bubbles: true, code: 'Tab', shiftKey: true }));
|
|
144
|
+
table.dispatchEvent(new KeyboardEvent('keydown', { bubbles: true, code: 'Tab' }));
|
|
145
|
+
|
|
146
|
+
await vi.waitFor(() => {
|
|
147
|
+
expect(element).to.contain(doc.activeElement);
|
|
148
|
+
}, 50)
|
|
149
|
+
toggleFocusTrap(table);
|
|
108
150
|
});
|
|
109
151
|
|
|
110
152
|
it('Test misc folder - emulateAnimationEnd - default', async () => {
|
|
111
153
|
vi.useFakeTimers();
|
|
112
154
|
const container = getExampleDOM();
|
|
113
155
|
wrapper.append(container);
|
|
114
|
-
|
|
115
156
|
const { emulateAnimationEnd, getElementStyle, querySelector, addClass } = SHORTY;
|
|
157
|
+
await vi.waitFor(() => container.querySelector('.alert'), 200);
|
|
116
158
|
|
|
117
159
|
const el = querySelector('.alert') as HTMLElement;
|
|
118
160
|
|
|
119
161
|
addClass(el, 'animate-test');
|
|
120
162
|
emulateAnimationEnd(el, () => {
|
|
121
163
|
console.log('animationend fired - default');
|
|
164
|
+
vi.advanceTimersByTime(350);
|
|
165
|
+
});
|
|
166
|
+
await vi.waitFor(() => {
|
|
122
167
|
expect(getElementStyle(el, 'animationName'), 'animationName').to.equal('animate-test');
|
|
123
168
|
expect(getElementStyle(el, 'animationDuration'), 'animationDuration').to.equal('0.3s');
|
|
124
169
|
expect(getElementStyle(el, 'animationDelay'), 'animationDelay').to.equal('0s');
|
|
125
|
-
})
|
|
126
|
-
vi.advanceTimersByTime(350);
|
|
127
|
-
|
|
170
|
+
}, 351)
|
|
128
171
|
});
|
|
129
172
|
|
|
130
|
-
|
|
173
|
+
|
|
174
|
+
it('Test misc folder - emulateAnimationEnd - no duration', async () => {
|
|
175
|
+
vi.useFakeTimers();
|
|
131
176
|
const container = getExampleDOM();
|
|
132
177
|
wrapper.append(container);
|
|
178
|
+
await vi.waitFor(() => container.querySelector('.alert'), 200);
|
|
133
179
|
|
|
134
180
|
const { emulateAnimationEnd, setElementStyle, getElementStyle, querySelector, addClass } =
|
|
135
181
|
SHORTY;
|
|
136
182
|
|
|
137
183
|
const el = querySelector('.alert', container)!;
|
|
138
|
-
setElementStyle(el, { animationDuration: '0.1s' });
|
|
184
|
+
// setElementStyle(el, { animationDuration: '0.1s' });
|
|
185
|
+
setElementStyle(el, { animationDuration: '0s' });
|
|
139
186
|
|
|
140
187
|
addClass(el, 'animate-test');
|
|
141
188
|
|
|
142
|
-
|
|
143
189
|
emulateAnimationEnd(el, () => {
|
|
144
|
-
// await vi.waitUntil(() => {
|
|
145
190
|
console.log('animationend fired no duration');
|
|
191
|
+
vi.advanceTimersByTime(150);
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
await vi.waitFor(() => {
|
|
146
195
|
expect(getElementStyle(el, 'animationName'), 'animationName').to.equal('animate-test');
|
|
147
196
|
expect(getElementStyle(el, 'animationDuration'), 'animationDuration').to.equal('0s');
|
|
148
197
|
expect(getElementStyle(el, 'animationDelay'), 'animationDelay').to.equal('0s');
|
|
149
|
-
|
|
150
|
-
// }, { timeout: 150 })
|
|
151
|
-
});
|
|
198
|
+
}, 50)
|
|
152
199
|
|
|
153
200
|
});
|
|
154
201
|
|
|
155
|
-
it('Test misc folder - everything else', () => {
|
|
202
|
+
it('Test misc folder - everything else', async () => {
|
|
156
203
|
const container = getExampleDOM();
|
|
157
204
|
wrapper.append(container);
|
|
205
|
+
await vi.waitFor(() => container.querySelector('.alert'), 200);
|
|
158
206
|
|
|
159
207
|
const {
|
|
160
208
|
ArrayFrom,
|
|
@@ -1,17 +1,12 @@
|
|
|
1
1
|
import { resolve } from 'path';
|
|
2
2
|
import { defineConfig } from 'vite';
|
|
3
|
-
import { name } from './package.json';
|
|
4
|
-
|
|
5
|
-
const getPackageName = () => {
|
|
6
|
-
return name.includes('@') ? name.split('/')[1] : name;
|
|
7
|
-
};
|
|
8
3
|
|
|
9
4
|
const NAME = 'SHORTY';
|
|
10
5
|
|
|
11
6
|
const fileName = {
|
|
12
|
-
es:
|
|
13
|
-
cjs:
|
|
14
|
-
iife:
|
|
7
|
+
es: `shorty.mjs`,
|
|
8
|
+
cjs: `shorty.cjs`,
|
|
9
|
+
iife: `shorty.js`,
|
|
15
10
|
};
|
|
16
11
|
|
|
17
12
|
export default defineConfig({
|
|
File without changes
|
|
File without changes
|