mazey 4.10.0 → 4.10.2

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/.dockerignore ADDED
@@ -0,0 +1,35 @@
1
+ # Git
2
+ **/.git
3
+ **/.gitignore
4
+
5
+ # Node.js
6
+ **/node_modules
7
+ **/npm-debug.log
8
+
9
+ # PHP
10
+ **/*.php
11
+
12
+ # Cache & System Files
13
+ **/.DS_Store
14
+ **/Thumbs.db
15
+ **/.vscode
16
+ **/.idea
17
+ **/.cache
18
+ **/tmp
19
+ **/temp
20
+ **/*.code-workspace
21
+
22
+ # Docs
23
+ **/documents/**/*.md
24
+ **/documents/**/*.txt
25
+
26
+ # Cert
27
+ **/cert/**/*.key
28
+ **/cert/**/*.pem
29
+
30
+ # LOG
31
+ **/var-log-web
32
+
33
+ # Archives
34
+ **/*.tar.gz
35
+ **/asset_frozen
package/.gitattributes ADDED
@@ -0,0 +1,5 @@
1
+ *.ts text eol=lf
2
+ *.js text eol=lf
3
+ *.json text eol=lf
4
+ *.yml text eol=lf
5
+ *.yaml text eol=lf
package/AGENTS.md ADDED
@@ -0,0 +1,111 @@
1
+ # AGENTS.md
2
+
3
+ ## Purpose
4
+
5
+ This repository is a browser-focused utility library published as `mazey`. It is not an application or monorepo. The main job here is maintaining a flat public API of frontend helper functions and shipping it in multiple bundle formats.
6
+
7
+ ## Repo Map
8
+
9
+ - `src/`: source of truth for the library
10
+ - `types/`: extra global type declarations bundled into `lib/`
11
+ - `test/`: Jest tests, generally one file per source module
12
+ - `examples/`: demo page and TS entry used by the local dev server
13
+ - `scripts/`: Rollup, Webpack, release, and docs helpers
14
+ - `images/`: documentation assets
15
+ - `.github/`: CI/workflows
16
+
17
+ ## Main Entry Points
18
+
19
+ - Library source entry: `src/index.ts`
20
+ - Published package outputs:
21
+ - `lib/index.cjs.js`
22
+ - `lib/index.esm.js`
23
+ - `lib/mazey.min.js`
24
+ - `lib/index.d.ts`
25
+ - Dev/demo entry: `examples/index.ts`
26
+
27
+ `src/index.ts` is intentionally simple: it re-exports all feature modules so consumers import from `"mazey"` and get a flat API.
28
+
29
+ ## Source Modules
30
+
31
+ - `src/util.ts`: shared utility layer; many other modules depend on this
32
+ - `src/typing.d.ts`: shared internal/public types
33
+ - `src/url.ts`: URL parsing, query helpers, URL transforms, script query inspection
34
+ - `src/dom.ts`: class/style/meta/image DOM helpers
35
+ - `src/event.ts`: custom event registry on `window.MAZEY_DEFINE_LISTENERS`
36
+ - `src/store.ts`: `sessionStorage`, `localStorage`, and cookie helpers
37
+ - `src/load.ts`: dynamic script/CSS/image loading and page-load helpers
38
+ - `src/browser.ts`: browser/platform/PWA detection
39
+ - `src/perf.ts`: Performance API and navigation timing helpers
40
+ - `src/debug.ts`: custom console wrappers
41
+ - `src/calc.ts`: standalone algorithms and probability helpers
42
+
43
+ ## Data Flow
44
+
45
+ Typical runtime flow:
46
+
47
+ 1. Consumer imports from `mazey`
48
+ 2. Package resolves to a built file from `lib/`
49
+ 3. Built file originates from `src/index.ts`
50
+ 4. `src/index.ts` re-exports functions from the feature modules
51
+ 5. Feature modules call browser APIs directly, with light reuse of shared helpers in `util.ts`, `debug.ts`, and `typing.d.ts`
52
+
53
+ Important internal dependencies:
54
+
55
+ - `util.ts` is the main shared dependency
56
+ - `typing.d.ts` is imported across modules for signatures and shared types
57
+ - `debug.ts` provides `mazeyCon`, used by modules like `dom.ts` and `browser.ts`
58
+ - `load.ts` depends on `util.ts` and `url.ts`
59
+ - `perf.ts` depends on `util.ts`
60
+ - `browser.ts` depends on `util.ts`
61
+ - `calc.ts` depends on `util.ts`
62
+
63
+ This is a mostly flat architecture, not a layered service system.
64
+
65
+ ## Build And Dev Flow
66
+
67
+ - `npm run build`: Rollup bundles `src/index.ts` into CJS, ESM, and IIFE outputs in `lib/`
68
+ - `npm run dev`: Webpack serves `examples/index.ts` via `examples/index.html`
69
+ - `npm test`: Jest suite across `test/`
70
+ - `npm run docs`: TypeDoc using `README.md`
71
+
72
+ Relevant config files:
73
+
74
+ - `package.json`
75
+ - `scripts/rollup.config.mjs`
76
+ - `scripts/webpack.config.dev.js`
77
+ - `tsconfig.json`
78
+
79
+ ## Working Style For Agents
80
+
81
+ - Preserve the flat public API unless there is a strong reason to change it
82
+ - Check `src/index.ts` whenever adding, renaming, or removing exported functions
83
+ - Prefer small, targeted changes; most modules are independent
84
+ - Be careful with browser globals like `window`, `document`, `location`, `navigator`, and `performance`
85
+ - Keep examples and tests aligned with public behavior when you change an exported helper
86
+ - Avoid introducing app-style abstractions unless the repo is clearly moving in that direction
87
+
88
+ ## Common Change Paths
89
+
90
+ - Add a new utility:
91
+ - implement in the relevant `src/*.ts`
92
+ - export via `src/index.ts`
93
+ - add or update tests under `test/`
94
+ - ensure build output still succeeds
95
+
96
+ - Change packaging behavior:
97
+ - inspect `package.json`
98
+ - inspect `scripts/rollup.config.mjs`
99
+ - inspect any generated type outputs in `lib/`
100
+
101
+ - Change local demo behavior:
102
+ - inspect `examples/index.ts`
103
+ - inspect `examples/index.html`
104
+ - inspect `scripts/webpack.config.dev.js`
105
+
106
+ ## Notes
107
+
108
+ - The library targets browser environments first
109
+ - Some helpers intentionally cache data on `window`
110
+ - Several functions have compatibility-oriented logic for older browsers
111
+ - The README is broad, but the code in `src/` is the authoritative map of behavior
package/Dockerfile ADDED
@@ -0,0 +1,30 @@
1
+ FROM node:22-bookworm
2
+
3
+ ENV DEBIAN_FRONTEND=noninteractive
4
+ WORKDIR /workspace
5
+
6
+ # Match ubuntu-latest style tooling needed by your workflow
7
+ RUN apt-get update && apt-get install -y --no-install-recommends \
8
+ dos2unix \
9
+ git \
10
+ ca-certificates \
11
+ && rm -rf /var/lib/apt/lists/*
12
+
13
+ # Copy repo
14
+ COPY . .
15
+
16
+ # Simulate workflow env
17
+ ENV NODE_VERSION=22
18
+ ENV PROJECT_NAME=mazey
19
+ ENV GITHUB_ACTOR=local-dev
20
+
21
+ # Default command runs "test job" behavior
22
+ CMD bash -lc '\
23
+ set -euo pipefail; \
24
+ echo "== Install dependencies =="; \
25
+ npm install; \
26
+ echo "== Build package =="; \
27
+ npm run build --if-present; \
28
+ echo "== Run tests =="; \
29
+ npm test \
30
+ '
package/README.md CHANGED
@@ -28,7 +28,7 @@ Use Mazey from CDN.
28
28
  <script type="text/javascript" src="//cdn.jsdelivr.net/npm/mazey@latest/lib/mazey.min.js"></script>
29
29
  ```
30
30
 
31
- Of course, you can also download and serve the file [lib/mazey.min.js](https://cdn.jsdelivr.net/npm/mazey@latest/lib/mazey.min.js) yourself.
31
+ Of course, you can also download and serve the file [jsdelivr/lib/mazey.min.js](https://cdn.jsdelivr.net/npm/mazey@latest/lib/mazey.min.js) yourself.
32
32
 
33
33
  ## Usage
34
34
 
@@ -77,11 +77,11 @@ There are some examples maintained by hand below. For more information, please c
77
77
  - [isValidData](#isvaliddata)
78
78
  - [genRndNumString](#genrndnumstring)
79
79
  - [formatDate](#formatdate)
80
+ - [deepCopy](#deepcopy)
80
81
  - [debounce](#debounce)
81
82
  - [throttle](#throttle)
82
83
  - [convertCamelToKebab](#convertcameltokebab)
83
84
  - [convertCamelToUnder](#convertcameltounder)
84
- - [deepCopy](#deepcopy)
85
85
  - [URL](#url)
86
86
  - [getQueryParam](#getqueryparam)
87
87
  - [getUrlParam](#geturlparam)
@@ -91,11 +91,12 @@ There are some examples maintained by hand below. For more information, please c
91
91
  - [isValidUrl](#isvalidurl)
92
92
  - [isValidHttpUrl](#isvalidhttpurl)
93
93
  - [Store](#store)
94
- - [Cookie](#cookie)
95
- - [Storage](#storage)
94
+ - [Cookie Helpers](#cookie-helpers)
95
+ - [Storage Helpers](#storage-helpers)
96
96
  - [DOM](#dom)
97
+ - [Class Helpers](#class-helpers)
97
98
  - [addStyle](#addstyle)
98
- - [Class](#class)
99
+ - [genStyleString](#genstylestring)
99
100
  - [newLine](#newline)
100
101
  - [Calculate and Formula](#calculate-and-formula)
101
102
  - [inRate](#inrate)
@@ -360,6 +361,26 @@ Number formatDate value: 2022-01-11 14:07:15
360
361
  Date formatDate value: 02/11/2014
361
362
  ```
362
363
 
364
+ #### deepCopy
365
+
366
+ Copy/Clone Object deeply.
367
+
368
+ Usage:
369
+
370
+ ```javascript
371
+ const ret1 = deepCopy(["a", "b", "c"]);
372
+ const ret2 = deepCopy("abc");
373
+ console.log(ret1);
374
+ console.log(ret2);
375
+ ```
376
+
377
+ Output:
378
+
379
+ ```text
380
+ ["a", "b", "c"]
381
+ abc
382
+ ```
383
+
363
384
  #### debounce
364
385
 
365
386
  Debounce
@@ -426,26 +447,6 @@ a_b_c
426
447
  a_b_c
427
448
  ```
428
449
 
429
- #### deepCopy
430
-
431
- Copy/Clone Object deeply.
432
-
433
- Usage:
434
-
435
- ```javascript
436
- const ret1 = deepCopy(["a", "b", "c"]);
437
- const ret2 = deepCopy("abc");
438
- console.log(ret1);
439
- console.log(ret2);
440
- ```
441
-
442
- Output:
443
-
444
- ```text
445
- ["a", "b", "c"]
446
- abc
447
- ```
448
-
449
450
  ### URL
450
451
 
451
452
  #### getQueryParam
@@ -605,7 +606,7 @@ true true true true false
605
606
 
606
607
  ### Store
607
608
 
608
- #### Cookie
609
+ #### Cookie Helpers
609
610
 
610
611
  Handle Cookie.
611
612
 
@@ -623,7 +624,7 @@ Output:
623
624
  123
624
625
  ```
625
626
 
626
- #### Storage
627
+ #### Storage Helpers
627
628
 
628
629
  Handle Storage (Keep fit for JSON, it can transfer format automatically).
629
630
 
@@ -655,62 +656,140 @@ Output:
655
656
 
656
657
  ### DOM
657
658
 
659
+ #### Class Helpers
660
+
661
+ Modify `class`.
662
+
663
+ Usage:
664
+
665
+ ```javascript
666
+ const dom = document.querySelector("#box");
667
+
668
+ // Determine `class`
669
+ hasClass(dom, "test");
670
+ // Add `class`
671
+ addClass(dom, "test");
672
+ // Remove `class`
673
+ removeClass(dom, "test");
674
+ ```
675
+
658
676
  #### addStyle
659
677
 
660
678
  Add `<style>` in `<head>`.
661
679
 
680
+ Usage:
681
+
662
682
  Example 1: Add the `<style>` with `id`, and repeated invoking will update the content instead of adding a new one.
663
683
 
664
684
  ```javascript
685
+ import { addStyle } from "mazey";
686
+
665
687
  addStyle(
666
- `
667
- body {
668
- background-color: #333;
669
- }
670
- `,
671
- {
672
- id: "test",
673
- }
688
+ "body { background-color: #333; }",
689
+ { id: "test" }
674
690
  );
675
- // <style id="test">
676
- // body {
677
- // background-color: #333;
678
- // }
679
- // </style>
691
+ ```
692
+
693
+ Output:
694
+
695
+ ```html
696
+ <style id="test">body { background-color: #333; }</style>
680
697
  ```
681
698
 
682
699
  Example 2: Add the `<style>` without `id`, and repeated invoking will add a new one.
683
700
 
684
701
  ```javascript
685
- addStyle(
686
- `
687
- body {
688
- background-color: #444;
689
- }
690
- `
702
+ import { addStyle } from "mazey";
703
+
704
+ addStyle("body { background-color: #444; }");
705
+ ```
706
+
707
+ Output:
708
+
709
+ ```html
710
+ <style>body { background-color: #444; }</style>
711
+ ```
712
+
713
+ Example 3: Combine `genStyleString` and `addStyle` to add multiple styles at once.
714
+
715
+ ```javascript
716
+ import { genStyleString, addStyle } from "mazey";
717
+
718
+ const xStyle = genStyleString(
719
+ ".footer>.x-wish>a:first-child" +
720
+ ",div.wish-flex>a[href^='https://github.com/chengchuu']" +
721
+ ",.m-hide",
722
+ [ "display: none" ]
723
+ );
724
+ const yStyle = genStyleString(
725
+ ".footer>.y-wish:before",
726
+ [
727
+ `content: 'Copyright (c) chengchuu'`,
728
+ "color: inherit",
729
+ "padding-inline-start: var(--y-wish-1_5)",
730
+ "padding-inline-end: var(--y-wish-1_5)",
731
+ "padding-top: var(--y-wish-1)",
732
+ "padding-bottom: var(--y-wish-1)",
733
+ ]
691
734
  );
692
- // <style>
693
- // body {
694
- // background-color: #444;
695
- // }
696
- // </style>
735
+ addStyle(xStyle + yStyle, { id: "z-style" });
697
736
  ```
698
737
 
699
- #### Class
738
+ Output:
700
739
 
701
- Modify `class`.
740
+ ```html
741
+ <style id="z-style">.footer>.x-wish>a:first-child,div.wish-flex>a[href^='https://github.com/chengchuu'],.m-hide{display: none;}.footer>.y-wish:before{content: 'Copyright (c) chengchuu';color: inherit;padding-inline-start: var(--y-wish-1_5);padding-inline-end: var(--y-wish-1_5);padding-top: var(--y-wish-1);padding-bottom: var(--y-wish-1);}</style>
742
+ ```
743
+
744
+ #### genStyleString
745
+
746
+ Generate the inline style string from the given parameters. The first parameter is the query selector, and the second parameter is the style array.
702
747
 
703
748
  Usage:
704
749
 
705
750
  ```javascript
706
- const dom = document.querySelector("#box");
751
+ const ret1 = genStyleString(".a", [ "color:red" ]);
752
+ const ret2 = genStyleString("#b", [ "color:red", "font-size:12px" ]);
753
+ console.log(ret1);
754
+ console.log(ret2);
755
+ ```
707
756
 
708
- // Determine `class`
709
- hasClass(dom, "test");
710
- // Add `class`
711
- addClass(dom, "test");
712
- // Remove `class`
713
- removeClass(dom, "test");
757
+ Output:
758
+
759
+ ```text
760
+ .a{color:red;}
761
+ #b{color:red;font-size:12px;}
762
+ ```
763
+
764
+ Example: Combine `genStyleString` and `addStyle` to add multiple styles at once.
765
+
766
+ ```javascript
767
+ import { genStyleString, addStyle } from "mazey";
768
+
769
+ const xStyle = genStyleString(
770
+ ".footer>.x-wish>a:first-child" +
771
+ ",div.wish-flex>a[href^='https://github.com/chengchuu']" +
772
+ ",.m-hide",
773
+ [ "display: none" ]
774
+ );
775
+ const yStyle = genStyleString(
776
+ ".footer>.y-wish:before",
777
+ [
778
+ `content: 'Copyright (c) chengchuu'`,
779
+ "color: inherit",
780
+ "padding-inline-start: var(--y-wish-1_5)",
781
+ "padding-inline-end: var(--y-wish-1_5)",
782
+ "padding-top: var(--y-wish-1)",
783
+ "padding-bottom: var(--y-wish-1)",
784
+ ]
785
+ );
786
+ addStyle(xStyle + yStyle, { id: "z-style" });
787
+ ```
788
+
789
+ Output:
790
+
791
+ ```html
792
+ <style id="z-style">.footer>.x-wish>a:first-child,div.wish-flex>a[href^='https://github.com/chengchuu'],.m-hide{display: none;}.footer>.y-wish:before{content: 'Copyright (c) chengchuu';color: inherit;padding-inline-start: var(--y-wish-1_5);padding-inline-end: var(--y-wish-1_5);padding-top: var(--y-wish-1);padding-bottom: var(--y-wish-1);}</style>
714
793
  ```
715
794
 
716
795
  #### newLine