@thednp/shorty 2.0.6 → 2.0.7

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thednp/shorty",
3
- "version": "2.0.6",
3
+ "version": "2.0.7",
4
4
  "description": "TypeScript shorties for the web",
5
5
  "source": "./src/index.ts",
6
6
  "main": "./dist/shorty.js",
@@ -33,14 +33,14 @@
33
33
  "homepage": "https://github.com/thednp/shorty",
34
34
  "devDependencies": {
35
35
  "@types/node": "^20.17.1",
36
- "@vitest/browser": "^2.1.3",
37
- "@vitest/coverage-istanbul": "^2.1.3",
38
- "@vitest/ui": "^2.1.3",
39
- "dts-bundle-generator": "^9.5.1",
36
+ "@vitest/browser": "^2.1.4",
37
+ "@vitest/coverage-istanbul": "^2.1.4",
38
+ "@vitest/ui": "^2.1.4",
40
39
  "playwright": "^1.48.2",
41
40
  "typescript": "^5.6.3",
42
41
  "vite": "^5.4.10",
43
- "vitest": "^2.1.3"
42
+ "vite-plugin-dts": "^4.3.0",
43
+ "vitest": "^2.1.4"
44
44
  },
45
45
  "engines": {
46
46
  "node": ">=16",
@@ -57,7 +57,6 @@
57
57
  "lint:ts": "deno lint src",
58
58
  "fix:ts": "deno lint src --fix",
59
59
  "check:ts": "tsc -noEmit",
60
- "build": "vite build && pnpm dts",
61
- "dts": "dts-bundle-generator --config ./dts.config.ts"
60
+ "build": "vite build"
62
61
  }
63
62
  }
@@ -1,16 +1,15 @@
1
- import type { NavigatorUABrand } from "../interface/navigatorUA";
2
- import userAgentData from "../strings/userAgentData";
3
- import userAgent from "../strings/userAgent";
4
-
5
- const appleBrands = /(iPhone|iPod|iPad)/;
1
+ import type { NavigatorUA } from "../interface/navigatorUA";
6
2
 
7
3
  /**
8
- * A global `boolean` for Apple browsers.
4
+ * A global `boolean` getter for Apple browsers.
9
5
  */
10
- const isApple: boolean = userAgentData
11
- ? userAgentData.brands.some((x: NavigatorUABrand) =>
6
+ const isApple = () => {
7
+ const appleBrands = /(iPhone|iPod|iPad)/;
8
+ return (navigator as NavigatorUA)?.userAgentData?.brands.some((x) =>
12
9
  appleBrands.test(x.brand)
13
- )
14
- : /* istanbul ignore next @preserve */ appleBrands.test(userAgent);
15
-
10
+ ) || /* istanbul ignore next @preserve */
11
+ appleBrands.test(
12
+ navigator?.userAgent,
13
+ ) || false;
14
+ };
16
15
  export default isApple;
@@ -1,11 +1,9 @@
1
- import userAgent from "../strings/userAgent";
2
-
3
1
  /**
4
2
  * A global boolean for Gecko browsers. When writing this file,
5
3
  * Gecko was not supporting `userAgentData`.
6
4
  */
7
- const isFirefox = userAgent
8
- ? userAgent.includes("Firefox")
9
- : /* istanbul ignore next @preserve */ false;
5
+ const isFirefox = () =>
6
+ navigator?.userAgent?.includes("Firefox") ||
7
+ /* istanbul ignore next @preserve */ false;
10
8
 
11
9
  export default isFirefox;
@@ -1,19 +1,14 @@
1
- import userAgentData from "../strings/userAgentData";
2
- import userAgent from "../strings/userAgent";
3
-
4
- const mobileBrands = /iPhone|iPad|iPod|Android/i;
5
- let isMobileCheck = false;
6
-
7
- // istanbul ignore else @preserve
8
- if (userAgentData) {
9
- isMobileCheck = userAgentData.brands.some((x) => mobileBrands.test(x.brand));
10
- } else {
11
- isMobileCheck = mobileBrands.test(userAgent);
12
- }
1
+ import type { NavigatorUA } from "../interface/navigatorUA";
13
2
 
14
3
  /**
15
4
  * A global `boolean` for mobile detection.
16
5
  */
17
- const isMobile = isMobileCheck;
18
-
6
+ const isMobile = () => {
7
+ const mobileBrands = /iPhone|iPad|iPod|Android/i;
8
+
9
+ return (navigator as NavigatorUA)?.userAgentData?.brands.some((x) =>
10
+ mobileBrands.test(x.brand)
11
+ ) ||
12
+ mobileBrands.test(navigator?.userAgent) || false;
13
+ };
19
14
  export default isMobile;
@@ -1,10 +1,7 @@
1
- import documentHead from "../blocks/documentHead";
2
-
3
1
  /**
4
2
  * A global `boolean` for CSS3 3D transform support.
5
3
  */
6
- const support3DTransform = ["webkitPerspective", "perspective"].some((p) =>
7
- p in documentHead.style
8
- );
4
+ const support3DTransform = () =>
5
+ ["webkitPerspective", "perspective"].some((p) => p in document.head.style);
9
6
 
10
7
  export default support3DTransform;
@@ -1,10 +1,7 @@
1
- import documentHead from "../blocks/documentHead";
2
-
3
1
  /**
4
2
  * A global `boolean` for CSS3 animation support.
5
3
  */
6
- const supportAnimation = ["webkitAnimation", "animation"].some((p) =>
7
- p in documentHead.style
8
- );
4
+ const supportAnimation = () =>
5
+ ["webkitAnimation", "animation"].some((p) => p in document.head.style);
9
6
 
10
7
  export default supportAnimation;
@@ -1,6 +1,6 @@
1
- import DOMContentLoadedEvent from "../strings/DOMContentLoadedEvent";
2
- import one from "../event/one";
3
1
  import noop from "../misc/noop";
2
+ import one from "../event/one";
3
+ import DOMContentLoadedEvent from "../strings/DOMContentLoadedEvent";
4
4
 
5
5
  /**
6
6
  * A global `boolean` for passive events support,
@@ -8,7 +8,7 @@ import noop from "../misc/noop";
8
8
  *
9
9
  * @see https://github.com/WICG/EventListenerOptions/blob/gh-pages/explainer.md#feature-detection
10
10
  */
11
- const supportPassive = (() => {
11
+ const supportPassive = () => {
12
12
  let result = false;
13
13
  try {
14
14
  const opts = Object.defineProperty({}, "passive", {
@@ -24,6 +24,6 @@ const supportPassive = (() => {
24
24
  }
25
25
 
26
26
  return result;
27
- })();
27
+ };
28
28
 
29
29
  export default supportPassive;
@@ -1,7 +1,8 @@
1
1
  /**
2
2
  * A global `boolean` for touch events support.
3
3
  */
4
- const supportTouch = "ontouchstart" in window ||
4
+ const supportTouch = () =>
5
+ "ontouchstart" in window ||
5
6
  /* istanbul ignore next @preserve */
6
7
  "msMaxTouchPoints" in navigator;
7
8
 
@@ -1,10 +1,7 @@
1
- import documentHead from "../blocks/documentHead";
2
-
3
1
  /**
4
2
  * A global `boolean` for CSS3 transform support.
5
3
  */
6
- const supportTransform = ["webkitTransform", "transform"].some((p) =>
7
- p in documentHead.style
8
- );
4
+ const supportTransform = () =>
5
+ ["webkitTransform", "transform"].some((p) => p in document.head.style);
9
6
 
10
7
  export default supportTransform;
@@ -1,10 +1,7 @@
1
- import documentHead from "../blocks/documentHead";
2
-
3
1
  /**
4
2
  * A global `boolean` for CSS3 transition support.
5
3
  */
6
- const supportTransition = ["webkitTransition", "transition"].some((p) =>
7
- p in documentHead.style
8
- );
4
+ const supportTransition = () =>
5
+ ["webkitTransition", "transition"].some((p) => p in document.head.style);
9
6
 
10
7
  export default supportTransition;
package/src/index.ts CHANGED
@@ -118,7 +118,6 @@ import transitionProperty from "./strings/transitionProperty";
118
118
 
119
119
  import addEventListener from "./strings/addEventListener";
120
120
  import removeEventListener from "./strings/removeEventListener";
121
-
122
121
  import bezierEasings from "./strings/bezierEasings";
123
122
 
124
123
  import offsetHeight from "./strings/offsetHeight";
@@ -257,6 +256,50 @@ import getElementsByTagName from "./selectors/getElementsByTagName";
257
256
  import getElementsByClassName from "./selectors/getElementsByClassName";
258
257
  import matches from "./selectors/matches";
259
258
 
259
+ import type {
260
+ NavigatorUA,
261
+ NavigatorUABrand,
262
+ NavigatorUAData,
263
+ } from "./interface/navigatorUA.d";
264
+ import type { OffsetRect } from "./interface/offsetRect.d";
265
+ import type { OriginalEvent } from "./interface/originalEvent.d";
266
+ import type { BoundingClientRect } from "./interface/boundingClientRect.d";
267
+ import type { CustomElement } from "./interface/customElement.d";
268
+ import type { CSS4Declaration } from "./interface/css4Declaration.d";
269
+ import type {
270
+ AnimationEvent,
271
+ AnimationEventHandler,
272
+ ChangeEvent,
273
+ ChangeEventHandler,
274
+ ClipboardEvent,
275
+ ClipboardEventHandler,
276
+ CompositionEvent,
277
+ CompositionEventHandler,
278
+ DragEvent,
279
+ DragEventHandler,
280
+ FocusEvent,
281
+ FocusEventHandler,
282
+ FormEvent,
283
+ FormEventHandler,
284
+ KeyboardEvent,
285
+ KeyboardEventHandler,
286
+ MouseEvent,
287
+ MouseEventHandler,
288
+ NativeEvent,
289
+ NativeEventHandler,
290
+ PointerEvent,
291
+ PointerEventHandler,
292
+ PossibleEventTarget,
293
+ TouchEvent,
294
+ TouchEventHandler,
295
+ TransitionEvent,
296
+ TransitionEventHandler,
297
+ UIEvent,
298
+ UIEventHandler,
299
+ WheelEvent,
300
+ WheelEventHandler,
301
+ } from "./interface/event.d";
302
+
260
303
  import { version } from "../package.json";
261
304
 
262
305
  export {
@@ -266,6 +309,8 @@ export {
266
309
  animationDelay,
267
310
  animationDuration,
268
311
  animationEndEvent,
312
+ type AnimationEvent,
313
+ type AnimationEventHandler,
269
314
  animationName,
270
315
  ariaChecked,
271
316
  ariaDescribedBy,
@@ -286,12 +331,21 @@ export {
286
331
  beforeunloadEvent,
287
332
  bezierEasings,
288
333
  blurEvent,
334
+ type BoundingClientRect,
335
+ type ChangeEvent,
289
336
  changeEvent,
337
+ type ChangeEventHandler,
338
+ type ClipboardEvent,
339
+ type ClipboardEventHandler,
290
340
  closest,
341
+ type CompositionEvent,
342
+ type CompositionEventHandler,
291
343
  contextmenuEvent,
292
344
  createCustomEvent,
293
345
  createElement,
294
346
  createElementNS,
347
+ type CSS4Declaration,
348
+ type CustomElement,
295
349
  Data,
296
350
  dispatchEvent,
297
351
  distinct,
@@ -302,7 +356,9 @@ export {
302
356
  DOMMouseScrollEvent,
303
357
  dragendEvent,
304
358
  dragenterEvent,
359
+ type DragEvent,
305
360
  dragEvent,
361
+ type DragEventHandler,
306
362
  dragleaveEvent,
307
363
  dragoverEvent,
308
364
  dragstartEvent,
@@ -312,11 +368,17 @@ export {
312
368
  Float32ArrayFrom,
313
369
  Float64ArrayFrom,
314
370
  focus,
371
+ // types
372
+ type FocusableElement,
315
373
  focusableSelector,
374
+ type FocusEvent,
316
375
  focusEvent,
376
+ type FocusEventHandler,
317
377
  focusEvents,
318
378
  focusinEvent,
319
379
  focusoutEvent,
380
+ type FormEvent,
381
+ type FormEventHandler,
320
382
  gesturechangeEvent,
321
383
  gestureendEvent,
322
384
  gesturestartEvent,
@@ -382,6 +444,8 @@ export {
382
444
  keyArrowRight,
383
445
  keyArrowUp,
384
446
  keyBackspace,
447
+ type KeyboardEvent,
448
+ type KeyboardEventHandler,
385
449
  keyboardEventKeys,
386
450
  keyCapsLock,
387
451
  keyControl,
@@ -407,6 +471,8 @@ export {
407
471
  mousedblclickEvent,
408
472
  mousedownEvent,
409
473
  mouseenterEvent,
474
+ type MouseEvent,
475
+ type MouseEventHandler,
410
476
  mousehoverEvent,
411
477
  mouseHoverEvents,
412
478
  mouseinEvent,
@@ -418,7 +484,12 @@ export {
418
484
  mouseupEvent,
419
485
  mousewheelEvent,
420
486
  moveEvent,
487
+ type NativeEvent,
488
+ type NativeEventHandler,
421
489
  nativeEvents,
490
+ type NavigatorUA,
491
+ type NavigatorUABrand,
492
+ type NavigatorUAData,
422
493
  noop,
423
494
  normalizeOptions,
424
495
  normalizeValue,
@@ -430,16 +501,21 @@ export {
430
501
  ObjectValues,
431
502
  off,
432
503
  offsetHeight,
504
+ type OffsetRect,
433
505
  offsetWidth,
434
506
  on,
435
507
  one,
436
508
  orientationchangeEvent,
509
+ type OriginalEvent,
437
510
  passiveHandler,
438
511
  pointercancelEvent,
439
512
  pointerdownEvent,
513
+ type PointerEvent,
514
+ type PointerEventHandler,
440
515
  pointerleaveEvent,
441
516
  pointermoveEvent,
442
517
  pointerupEvent,
518
+ type PossibleEventTarget,
443
519
  querySelector,
444
520
  querySelectorAll,
445
521
  readystatechangeEvent,
@@ -472,6 +548,8 @@ export {
472
548
  toLowerCase,
473
549
  touchcancelEvent,
474
550
  touchendEvent,
551
+ type TouchEvent,
552
+ type TouchEventHandler,
475
553
  touchEvents,
476
554
  touchmoveEvent,
477
555
  touchstartEvent,
@@ -479,55 +557,15 @@ export {
479
557
  transitionDelay,
480
558
  transitionDuration,
481
559
  transitionEndEvent,
560
+ type TransitionEvent,
561
+ type TransitionEventHandler,
482
562
  transitionProperty,
563
+ type UIEvent,
564
+ type UIEventHandler,
483
565
  unloadEvent,
484
566
  userAgent,
485
567
  userAgentData,
486
568
  version,
569
+ type WheelEvent,
570
+ type WheelEventHandler,
487
571
  };
488
-
489
- export * from "./interface/navigatorUA.d";
490
- export * from "./interface/offsetRect.d";
491
-
492
- export type { FocusableElement };
493
- export type { OriginalEvent } from "./interface/originalEvent.d";
494
-
495
- export type { BoundingClientRect } from "./interface/boundingClientRect.d";
496
-
497
- export type { CustomElement } from "./interface/customElement.d";
498
-
499
- export type { CSS4Declaration } from "./interface/css4Declaration.d";
500
-
501
- export type {
502
- AnimationEvent,
503
- AnimationEventHandler,
504
- ChangeEvent,
505
- ChangeEventHandler,
506
- ClipboardEvent,
507
- ClipboardEventHandler,
508
- CompositionEvent,
509
- CompositionEventHandler,
510
- DragEvent,
511
- DragEventHandler,
512
- FocusEvent,
513
- FocusEventHandler,
514
- FormEvent,
515
- FormEventHandler,
516
- KeyboardEvent,
517
- KeyboardEventHandler,
518
- MouseEvent,
519
- MouseEventHandler,
520
- NativeEvent,
521
- NativeEventHandler,
522
- PointerEvent,
523
- PointerEventHandler,
524
- PossibleEventTarget,
525
- TouchEvent,
526
- TouchEventHandler,
527
- TransitionEvent,
528
- TransitionEventHandler,
529
- UIEvent,
530
- UIEventHandler,
531
- WheelEvent,
532
- WheelEventHandler,
533
- } from "./interface/event.d";
@@ -1,9 +1,8 @@
1
1
  import type { NavigatorUA } from "../interface/navigatorUA";
2
2
 
3
- const uaDATA = (navigator as NavigatorUA).userAgentData;
4
-
5
3
  /**
6
4
  * A global namespace for `userAgentData` object.
7
5
  */
8
- const userAgentData: NavigatorUA["userAgentData"] = uaDATA;
6
+ const userAgentData: NavigatorUA["userAgentData"] =
7
+ (navigator as NavigatorUA).userAgentData;
9
8
  export default userAgentData;
@@ -17,14 +17,14 @@ describe('Shorty Library Tests - BOOL', () => {
17
17
  // querySelectorAll, getWindow
18
18
  } = SHORTY;
19
19
 
20
- expect(isApple, 'isApple').to.be.false;
21
- expect(isMobile, 'isMobile').to.be.false;
22
- expect(isFirefox, 'isFirefox').to.be.false;
23
- expect(support3DTransform, 'support3DTransform').to.be.true;
24
- expect(supportAnimation, 'supportAnimation').to.be.true;
25
- expect(supportPassive, 'supportPassive').to.be.true;
26
- expect(supportTouch, 'supportTouch').to.be.false;
27
- expect(supportTransform, 'supportTransform').to.be.true;
28
- expect(supportTransition, 'supportTransition').to.be.true;
20
+ expect(isApple(), 'isApple').to.be.false;
21
+ expect(isMobile(), 'isMobile').to.be.false;
22
+ expect(isFirefox(), 'isFirefox').to.be.false;
23
+ expect(support3DTransform(), 'support3DTransform').to.be.true;
24
+ expect(supportAnimation(), 'supportAnimation').to.be.true;
25
+ expect(supportPassive(), 'supportPassive').to.be.true;
26
+ expect(supportTouch(), 'supportTouch').to.be.false;
27
+ expect(supportTransform(), 'supportTransform').to.be.true;
28
+ expect(supportTransition(), 'supportTransition').to.be.true;
29
29
  });
30
30
  });
package/tsconfig.json CHANGED
@@ -7,9 +7,10 @@
7
7
  "baseUrl": "./",
8
8
  "module": "ESNext",
9
9
  "target": "ESNext",
10
- "moduleResolution": "Node",
10
+ "moduleResolution": "Bundler",
11
11
  "allowJs": true,
12
12
  "forceConsistentCasingInFileNames": true,
13
+ "resolvePackageJsonImports": true,
13
14
  "useDefineForClassFields": true,
14
15
  "strict": true,
15
16
  "sourceMap": true,
package/vite.config.mts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { resolve } from 'path';
2
2
  import { defineConfig } from 'vite';
3
+ import dts from "vite-plugin-dts";
3
4
 
4
5
  const NAME = 'SHORTY';
5
6
 
@@ -11,7 +12,25 @@ const fileName = {
11
12
 
12
13
  export default defineConfig({
13
14
  base: './',
15
+ esbuild: {
16
+ legalComments: 'none',
17
+ minifyIdentifiers: false,
18
+ },
19
+ plugins: [
20
+ dts({
21
+ outDir: 'dist',
22
+ copyDtsFiles: true,
23
+ rollupTypes: true,
24
+ })
25
+ ],
14
26
  build: {
27
+ rollupOptions: {
28
+ preserveEntrySignatures: "strict",
29
+ output: {
30
+ compact: true
31
+ }
32
+ },
33
+ minify: 'esbuild',
15
34
  emptyOutDir: true,
16
35
  outDir: 'dist',
17
36
  target: 'ESNext',
package/dts.config.ts DELETED
@@ -1,16 +0,0 @@
1
- const config = {
2
- entries: [
3
- {
4
- filePath: "./src/index.ts",
5
- outFile: `./dist/shorty.d.ts`,
6
- noCheck: false,
7
- output: {
8
- exportReferencedTypes: false,
9
- umdModuleName: 'SHORTY',
10
- noBanner: true,
11
- }
12
- },
13
- ],
14
- };
15
-
16
- module.exports = config;