mazey 4.10.0 → 4.11.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/.dockerignore +35 -0
- package/.gitattributes +5 -0
- package/.markdownlint.json +48 -0
- package/AGENTS.md +111 -0
- package/Dockerfile +30 -0
- package/README.md +146 -69
- package/lib/global.d.ts +0 -2
- package/lib/index.cjs.js +2 -2
- package/lib/index.esm.js +2 -2
- package/lib/mazey.min.js +2 -2
- package/lib/typing.d.ts +22 -1
- package/package.json +3 -2
- package/scripts/change-package-name.js +6 -4
- package/scripts/git-helper.js +13 -12
- package/scripts/release.js +1 -1
- package/scripts/rollup.config.mjs +5 -1
- package/lib/browser.d.ts +0 -124
- package/lib/browser.d.ts.map +0 -1
- package/lib/calc.d.ts +0 -117
- package/lib/calc.d.ts.map +0 -1
- package/lib/debug.d.ts +0 -74
- package/lib/debug.d.ts.map +0 -1
- package/lib/dom.d.ts +0 -232
- package/lib/dom.d.ts.map +0 -1
- package/lib/event.d.ts +0 -101
- package/lib/event.d.ts.map +0 -1
- package/lib/index.d.ts +0 -14
- package/lib/index.d.ts.map +0 -1
- package/lib/load.d.ts +0 -186
- package/lib/load.d.ts.map +0 -1
- package/lib/perf.d.ts +0 -213
- package/lib/perf.d.ts.map +0 -1
- package/lib/store.d.ts +0 -230
- package/lib/store.d.ts.map +0 -1
- package/lib/url.d.ts +0 -394
- package/lib/url.d.ts.map +0 -1
- package/lib/util.d.ts +0 -1174
- package/lib/util.d.ts.map +0 -1
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,48 @@
|
|
|
1
|
+
{
|
|
2
|
+
"default": true,
|
|
3
|
+
"MD001": true,
|
|
4
|
+
"MD003": {
|
|
5
|
+
"style": "atx"
|
|
6
|
+
},
|
|
7
|
+
"MD004": {
|
|
8
|
+
"style": "dash"
|
|
9
|
+
},
|
|
10
|
+
"MD007": {
|
|
11
|
+
"indent": 2
|
|
12
|
+
},
|
|
13
|
+
"MD010": {
|
|
14
|
+
"code_blocks": false
|
|
15
|
+
},
|
|
16
|
+
"MD013": {
|
|
17
|
+
"line_length": 700,
|
|
18
|
+
"code_blocks": false,
|
|
19
|
+
"tables": false
|
|
20
|
+
},
|
|
21
|
+
"MD022": {
|
|
22
|
+
"lines_above": 1,
|
|
23
|
+
"lines_below": 1
|
|
24
|
+
},
|
|
25
|
+
"MD024": {
|
|
26
|
+
"siblings_only": true
|
|
27
|
+
},
|
|
28
|
+
"MD025": {
|
|
29
|
+
"front_matter_title": ""
|
|
30
|
+
},
|
|
31
|
+
"MD026": {
|
|
32
|
+
"punctuation": ".,;:!?"
|
|
33
|
+
},
|
|
34
|
+
"MD029": {
|
|
35
|
+
"style": "ordered"
|
|
36
|
+
},
|
|
37
|
+
"MD033": {
|
|
38
|
+
"allowed_elements": ["img", "br", "kbd", "sub", "sup"]
|
|
39
|
+
},
|
|
40
|
+
"MD036": false,
|
|
41
|
+
"MD041": false,
|
|
42
|
+
"MD046": {
|
|
43
|
+
"style": "fenced"
|
|
44
|
+
},
|
|
45
|
+
"MD048": {
|
|
46
|
+
"style": "backtick"
|
|
47
|
+
}
|
|
48
|
+
}
|
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
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
<!-- markdownlint-disable MD041 -->
|
|
2
|
-
|
|
3
1
|
English | [简体中文](https://github.com/chengchuu/mazey/blob/main/README_ZH.md)
|
|
4
2
|
|
|
5
3
|
# Mazey
|
|
@@ -25,10 +23,10 @@ npm install mazey --save
|
|
|
25
23
|
Use Mazey from CDN.
|
|
26
24
|
|
|
27
25
|
```html
|
|
28
|
-
<script
|
|
26
|
+
<script src="//cdn.jsdelivr.net/npm/mazey@latest/lib/mazey.min.js"></script>
|
|
29
27
|
```
|
|
30
28
|
|
|
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.
|
|
29
|
+
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
30
|
|
|
33
31
|
## Usage
|
|
34
32
|
|
|
@@ -40,20 +38,20 @@ Import from [npm](https://www.npmjs.com/package/mazey).
|
|
|
40
38
|
import { isNumber } from "mazey";
|
|
41
39
|
|
|
42
40
|
const x = 123;
|
|
43
|
-
const y =
|
|
44
|
-
|
|
41
|
+
const y = "abc";
|
|
42
|
+
const z = Infinity;
|
|
45
43
|
isNumber(x); // Output: true
|
|
46
44
|
isNumber(y); // Output: false
|
|
45
|
+
isNumber(z, { isInfinityAsNumber: true }); // Output: true
|
|
47
46
|
```
|
|
48
47
|
|
|
49
48
|
Import from CDN.
|
|
50
49
|
|
|
51
50
|
```html
|
|
52
|
-
<script
|
|
51
|
+
<script src="//cdn.jsdelivr.net/npm/mazey@latest/lib/mazey.min.js"></script>
|
|
53
52
|
<script>
|
|
54
|
-
const x =
|
|
55
|
-
|
|
56
|
-
mazey.isNumber(x, { isInfinityAsNumber: true }); // Output: true
|
|
53
|
+
const x = 123;
|
|
54
|
+
mazey.isNumber(x); // Output: true
|
|
57
55
|
</script>
|
|
58
56
|
```
|
|
59
57
|
|
|
@@ -77,11 +75,11 @@ There are some examples maintained by hand below. For more information, please c
|
|
|
77
75
|
- [isValidData](#isvaliddata)
|
|
78
76
|
- [genRndNumString](#genrndnumstring)
|
|
79
77
|
- [formatDate](#formatdate)
|
|
78
|
+
- [deepCopy](#deepcopy)
|
|
80
79
|
- [debounce](#debounce)
|
|
81
80
|
- [throttle](#throttle)
|
|
82
81
|
- [convertCamelToKebab](#convertcameltokebab)
|
|
83
82
|
- [convertCamelToUnder](#convertcameltounder)
|
|
84
|
-
- [deepCopy](#deepcopy)
|
|
85
83
|
- [URL](#url)
|
|
86
84
|
- [getQueryParam](#getqueryparam)
|
|
87
85
|
- [getUrlParam](#geturlparam)
|
|
@@ -91,11 +89,12 @@ There are some examples maintained by hand below. For more information, please c
|
|
|
91
89
|
- [isValidUrl](#isvalidurl)
|
|
92
90
|
- [isValidHttpUrl](#isvalidhttpurl)
|
|
93
91
|
- [Store](#store)
|
|
94
|
-
- [Cookie](#cookie)
|
|
95
|
-
- [Storage](#storage)
|
|
92
|
+
- [Cookie Helpers](#cookie-helpers)
|
|
93
|
+
- [Storage Helpers](#storage-helpers)
|
|
96
94
|
- [DOM](#dom)
|
|
95
|
+
- [Class Helpers](#class-helpers)
|
|
97
96
|
- [addStyle](#addstyle)
|
|
98
|
-
- [
|
|
97
|
+
- [genStyleString](#genstylestring)
|
|
99
98
|
- [newLine](#newline)
|
|
100
99
|
- [Calculate and Formula](#calculate-and-formula)
|
|
101
100
|
- [inRate](#inrate)
|
|
@@ -360,6 +359,26 @@ Number formatDate value: 2022-01-11 14:07:15
|
|
|
360
359
|
Date formatDate value: 02/11/2014
|
|
361
360
|
```
|
|
362
361
|
|
|
362
|
+
#### deepCopy
|
|
363
|
+
|
|
364
|
+
Copy/Clone Object deeply.
|
|
365
|
+
|
|
366
|
+
Usage:
|
|
367
|
+
|
|
368
|
+
```javascript
|
|
369
|
+
const ret1 = deepCopy(["a", "b", "c"]);
|
|
370
|
+
const ret2 = deepCopy("abc");
|
|
371
|
+
console.log(ret1);
|
|
372
|
+
console.log(ret2);
|
|
373
|
+
```
|
|
374
|
+
|
|
375
|
+
Output:
|
|
376
|
+
|
|
377
|
+
```text
|
|
378
|
+
["a", "b", "c"]
|
|
379
|
+
abc
|
|
380
|
+
```
|
|
381
|
+
|
|
363
382
|
#### debounce
|
|
364
383
|
|
|
365
384
|
Debounce
|
|
@@ -426,26 +445,6 @@ a_b_c
|
|
|
426
445
|
a_b_c
|
|
427
446
|
```
|
|
428
447
|
|
|
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
448
|
### URL
|
|
450
449
|
|
|
451
450
|
#### getQueryParam
|
|
@@ -605,7 +604,7 @@ true true true true false
|
|
|
605
604
|
|
|
606
605
|
### Store
|
|
607
606
|
|
|
608
|
-
#### Cookie
|
|
607
|
+
#### Cookie Helpers
|
|
609
608
|
|
|
610
609
|
Handle Cookie.
|
|
611
610
|
|
|
@@ -623,7 +622,7 @@ Output:
|
|
|
623
622
|
123
|
|
624
623
|
```
|
|
625
624
|
|
|
626
|
-
#### Storage
|
|
625
|
+
#### Storage Helpers
|
|
627
626
|
|
|
628
627
|
Handle Storage (Keep fit for JSON, it can transfer format automatically).
|
|
629
628
|
|
|
@@ -655,62 +654,140 @@ Output:
|
|
|
655
654
|
|
|
656
655
|
### DOM
|
|
657
656
|
|
|
657
|
+
#### Class Helpers
|
|
658
|
+
|
|
659
|
+
Modify `class`.
|
|
660
|
+
|
|
661
|
+
Usage:
|
|
662
|
+
|
|
663
|
+
```javascript
|
|
664
|
+
const dom = document.querySelector("#box");
|
|
665
|
+
|
|
666
|
+
// Determine `class`
|
|
667
|
+
hasClass(dom, "test");
|
|
668
|
+
// Add `class`
|
|
669
|
+
addClass(dom, "test");
|
|
670
|
+
// Remove `class`
|
|
671
|
+
removeClass(dom, "test");
|
|
672
|
+
```
|
|
673
|
+
|
|
658
674
|
#### addStyle
|
|
659
675
|
|
|
660
676
|
Add `<style>` in `<head>`.
|
|
661
677
|
|
|
678
|
+
Usage:
|
|
679
|
+
|
|
662
680
|
Example 1: Add the `<style>` with `id`, and repeated invoking will update the content instead of adding a new one.
|
|
663
681
|
|
|
664
682
|
```javascript
|
|
683
|
+
import { addStyle } from "mazey";
|
|
684
|
+
|
|
665
685
|
addStyle(
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
background-color: #333;
|
|
669
|
-
}
|
|
670
|
-
`,
|
|
671
|
-
{
|
|
672
|
-
id: "test",
|
|
673
|
-
}
|
|
686
|
+
"body { background-color: #333; }",
|
|
687
|
+
{ id: "test" }
|
|
674
688
|
);
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
689
|
+
```
|
|
690
|
+
|
|
691
|
+
Output:
|
|
692
|
+
|
|
693
|
+
```html
|
|
694
|
+
<style id="test">body { background-color: #333; }</style>
|
|
680
695
|
```
|
|
681
696
|
|
|
682
697
|
Example 2: Add the `<style>` without `id`, and repeated invoking will add a new one.
|
|
683
698
|
|
|
684
699
|
```javascript
|
|
685
|
-
addStyle
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
700
|
+
import { addStyle } from "mazey";
|
|
701
|
+
|
|
702
|
+
addStyle("body { background-color: #444; }");
|
|
703
|
+
```
|
|
704
|
+
|
|
705
|
+
Output:
|
|
706
|
+
|
|
707
|
+
```html
|
|
708
|
+
<style>body { background-color: #444; }</style>
|
|
709
|
+
```
|
|
710
|
+
|
|
711
|
+
Example 3: Combine `genStyleString` and `addStyle` to add multiple styles at once.
|
|
712
|
+
|
|
713
|
+
```javascript
|
|
714
|
+
import { genStyleString, addStyle } from "mazey";
|
|
715
|
+
|
|
716
|
+
const xStyle = genStyleString(
|
|
717
|
+
".footer>.x-wish>a:first-child" +
|
|
718
|
+
",div.wish-flex>a[href^='https://github.com/chengchuu']" +
|
|
719
|
+
",.m-hide",
|
|
720
|
+
[ "display: none" ]
|
|
721
|
+
);
|
|
722
|
+
const yStyle = genStyleString(
|
|
723
|
+
".footer>.y-wish:before",
|
|
724
|
+
[
|
|
725
|
+
`content: 'Copyright (c) chengchuu'`,
|
|
726
|
+
"color: inherit",
|
|
727
|
+
"padding-inline-start: var(--y-wish-1_5)",
|
|
728
|
+
"padding-inline-end: var(--y-wish-1_5)",
|
|
729
|
+
"padding-top: var(--y-wish-1)",
|
|
730
|
+
"padding-bottom: var(--y-wish-1)",
|
|
731
|
+
]
|
|
691
732
|
);
|
|
692
|
-
|
|
693
|
-
// body {
|
|
694
|
-
// background-color: #444;
|
|
695
|
-
// }
|
|
696
|
-
// </style>
|
|
733
|
+
addStyle(xStyle + yStyle, { id: "z-style" });
|
|
697
734
|
```
|
|
698
735
|
|
|
699
|
-
|
|
736
|
+
Output:
|
|
700
737
|
|
|
701
|
-
|
|
738
|
+
```html
|
|
739
|
+
<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>
|
|
740
|
+
```
|
|
741
|
+
|
|
742
|
+
#### genStyleString
|
|
743
|
+
|
|
744
|
+
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
745
|
|
|
703
746
|
Usage:
|
|
704
747
|
|
|
705
748
|
```javascript
|
|
706
|
-
const
|
|
749
|
+
const ret1 = genStyleString(".a", [ "color:red" ]);
|
|
750
|
+
const ret2 = genStyleString("#b", [ "color:red", "font-size:12px" ]);
|
|
751
|
+
console.log(ret1);
|
|
752
|
+
console.log(ret2);
|
|
753
|
+
```
|
|
707
754
|
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
755
|
+
Output:
|
|
756
|
+
|
|
757
|
+
```text
|
|
758
|
+
.a{color:red;}
|
|
759
|
+
#b{color:red;font-size:12px;}
|
|
760
|
+
```
|
|
761
|
+
|
|
762
|
+
Example: Combine `genStyleString` and `addStyle` to add multiple styles at once.
|
|
763
|
+
|
|
764
|
+
```javascript
|
|
765
|
+
import { genStyleString, addStyle } from "mazey";
|
|
766
|
+
|
|
767
|
+
const xStyle = genStyleString(
|
|
768
|
+
".footer>.x-wish>a:first-child" +
|
|
769
|
+
",div.wish-flex>a[href^='https://github.com/chengchuu']" +
|
|
770
|
+
",.m-hide",
|
|
771
|
+
[ "display: none" ]
|
|
772
|
+
);
|
|
773
|
+
const yStyle = genStyleString(
|
|
774
|
+
".footer>.y-wish:before",
|
|
775
|
+
[
|
|
776
|
+
`content: 'Copyright (c) chengchuu'`,
|
|
777
|
+
"color: inherit",
|
|
778
|
+
"padding-inline-start: var(--y-wish-1_5)",
|
|
779
|
+
"padding-inline-end: var(--y-wish-1_5)",
|
|
780
|
+
"padding-top: var(--y-wish-1)",
|
|
781
|
+
"padding-bottom: var(--y-wish-1)",
|
|
782
|
+
]
|
|
783
|
+
);
|
|
784
|
+
addStyle(xStyle + yStyle, { id: "z-style" });
|
|
785
|
+
```
|
|
786
|
+
|
|
787
|
+
Output:
|
|
788
|
+
|
|
789
|
+
```html
|
|
790
|
+
<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
791
|
```
|
|
715
792
|
|
|
716
793
|
#### newLine
|