@aiursoft/autodark.js 1.2.12 → 1.2.14

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/.gitlab-ci.yml CHANGED
@@ -40,27 +40,58 @@ check:
40
40
  paths:
41
41
  - '*.tgz'
42
42
 
43
- publish:
43
+ publish_local_npm:
44
44
  stage: publish
45
45
  needs:
46
46
  - job: check
47
47
  artifacts: true
48
- resource_group: npm-publish
48
+ resource_group: npm-publish-local
49
49
  script:
50
50
  - |
51
51
  set -- *.tgz
52
52
  test "$#" -eq 1
53
53
  test -f "$1"
54
+ : "${NOPKG_API_KEY:?npm publishing credential is required}"
54
55
  package_name=$(node -p 'encodeURIComponent(require("./package.json").name)')
55
56
  package_version=$(node -p 'require("./package.json").version')
56
57
  status=$(curl --silent --show-error --location --output /dev/null --write-out '%{http_code}' \
57
- "https://registry.npmjs.org/$package_name/$package_version")
58
+ "https://nopkg.aiursoft.com/npm/$package_name/$package_version")
58
59
  case "$status" in
59
60
  200) echo "Version $package_version is already published; skipping."; exit 0 ;;
60
- 404) ;;
61
+ # A new local package may be denied by mirror policy before publication.
62
+ 403|404) ;;
61
63
  *) echo "Cannot check published versions (HTTP $status)." >&2; exit 1 ;;
62
64
  esac
65
+ npm_config_userconfig=$(mktemp)
66
+ export npm_config_userconfig
67
+ trap 'rm -f "$npm_config_userconfig"' EXIT
68
+ printf '%s\n' '//nopkg.aiursoft.com/npm/:_authToken=${NOPKG_API_KEY}' > "$npm_config_userconfig"
69
+ npm publish "$1" --registry=https://nopkg.aiursoft.com/npm/ --access public --ignore-scripts
70
+ rules:
71
+ - if: '$CI_COMMIT_BRANCH == "master"'
72
+
73
+ publish_public_npm:
74
+ stage: publish
75
+ needs:
76
+ - job: check
77
+ artifacts: true
78
+ resource_group: npm-publish-public
79
+ script:
80
+ - |
81
+ set -- *.tgz
82
+ test "$#" -eq 1
83
+ test -f "$1"
63
84
  : "${NPM_TOKEN:?npm publishing credential is required}"
85
+ package_name=$(node -p 'encodeURIComponent(require("./package.json").name)')
86
+ package_version=$(node -p 'require("./package.json").version')
87
+ status=$(curl --silent --show-error --location --output /dev/null --write-out '%{http_code}' \
88
+ "https://registry.npmjs.org/$package_name/$package_version")
89
+ case "$status" in
90
+ 200) echo "Version $package_version is already published; skipping."; exit 0 ;;
91
+ # A new local package may be denied by mirror policy before publication.
92
+ 403|404) ;;
93
+ *) echo "Cannot check published versions (HTTP $status)." >&2; exit 1 ;;
94
+ esac
64
95
  npm_config_userconfig=$(mktemp)
65
96
  export npm_config_userconfig
66
97
  trap 'rm -f "$npm_config_userconfig"' EXIT
package/README.md CHANGED
@@ -1,17 +1,52 @@
1
- # AutoDark.Js
1
+ <a name="autodarkjs"></a>
2
+
3
+ # Aiursoft AutoDark.js
2
4
 
3
5
  [![Pipeline](https://badge-proxy.aiursoft.com/aiursoft/autodark.js/badges/master/pipeline.svg)](https://gitlab.aiursoft.com/aiursoft/autodark.js/-/pipelines) [![npm](https://img.shields.io/npm/v/@aiursoft/autodark.js)](https://www.npmjs.com/package/@aiursoft/autodark.js)
4
6
 
5
7
  Detect the system color scheme and apply a Bootstrap 4.6.2 theme.
6
8
 
7
- ## Install
9
+ ## Overview
10
+
11
+ ### What is AutoDark.js?
12
+
13
+ Detect the system color scheme and apply a Bootstrap 4.6.2 theme.
14
+
15
+ <a name="install"></a>
16
+
17
+ ## Installation
18
+
19
+ Install the package in your project:
8
20
 
9
21
  ```bash
10
22
  npm install @aiursoft/autodark.js
11
23
  ```
12
24
 
25
+ Requires a browser with ES modules and `matchMedia` change events, Bootstrap 4.6.2 and the package stylesheet. Bootstrap 4.6.2 is the tested Bootstrap version. Node.js is needed to install or build the package, not to run the deployed browser assets.
26
+
13
27
  ## Usage
14
28
 
29
+ Save the following as `index.html` beside `node_modules/` and serve that directory over HTTP with your existing static-file server:
30
+
31
+ ```html
32
+ <!doctype html>
33
+ <html lang="en">
34
+ <meta charset="utf-8" />
35
+ <title>AutoDark example</title>
36
+ <link rel="stylesheet" href="./node_modules/bootstrap/dist/css/bootstrap.min.css" />
37
+ <link rel="stylesheet" href="./node_modules/@aiursoft/autodark.js/dist/css/autodark.min.css" />
38
+ <body class="bg-light">
39
+ <main class="container"><h1>System theme</h1></main>
40
+ <script type="module">
41
+ import { autoTheme } from './node_modules/@aiursoft/autodark.js/dist/esm/autodark.js'
42
+ autoTheme()
43
+ </script>
44
+ </body>
45
+ </html>
46
+ ```
47
+
48
+ The page follows the operating system color scheme. Theme changes are applied automatically.
49
+
15
50
  Requires Bootstrap 4.6.2 and the package stylesheet. See [usage](docs/usage.md) for the HTML setup.
16
51
 
17
52
  ```js
@@ -19,12 +54,71 @@ import { autoTheme } from './node_modules/@aiursoft/autodark.js/dist/esm/autodar
19
54
  autoTheme()
20
55
  ```
21
56
 
57
+ ### Theme selection
58
+
59
+ Use `switchTheme` when the application chooses the theme explicitly:
60
+
61
+ ```js
62
+ import { switchTheme } from './node_modules/@aiursoft/autodark.js/dist/esm/autodark.js'
63
+ switchTheme('dark')
64
+ switchTheme('light')
65
+ ```
66
+
67
+ `autoTheme()` applies the current preference, listens for light-preference changes and applies it again on window load. Call it once after the DOM is available. Automatic selection also sets the body text color to white or black.
68
+
69
+ ### Custom theme rules
70
+
71
+ The package exports mutable `darkThemeSettings` and `lightThemeSettings` maps. Each selector maps to an array of `classToAdd` and `classToRemove` rules. Set both directions before applying a theme:
72
+
73
+ ```js
74
+ import {
75
+ darkThemeSettings,
76
+ lightThemeSettings,
77
+ autoTheme,
78
+ } from './node_modules/@aiursoft/autodark.js/dist/esm/autodark.js'
79
+ darkThemeSettings['.custom-panel'] = [{ classToAdd: ['bg-dark'], classToRemove: ['bg-light'] }]
80
+ lightThemeSettings['.custom-panel'] = [{ classToAdd: ['bg-light'], classToRemove: ['bg-dark'] }]
81
+ autoTheme()
82
+ ```
83
+
84
+ ## Configuration
85
+
86
+ The library is configured through JavaScript; it has no configuration file or environment variables.
87
+
88
+ **Default rules**
89
+
90
+ Rules cover `body`, `table`, `.navbar`, `.modal-content`, `.container-fluid`, `.list-group-item`, `.content-wrapper`, `.card`, `.bg-dark`, `.bg-light`, `.bg-white` and `.bg`. They add and remove Bootstrap light/dark classes; navbar rules also adjust borders and shadows. The complete default maps are in [src/autodark.ts](src/autodark.ts).
91
+
92
+ **Resources and precedence**
93
+
94
+ Load Bootstrap CSS before `autodark.min.css`. Bootstrap widgets additionally need their own JavaScript dependencies; theme switching itself does not require jQuery or Bootstrap JavaScript. Explicit `switchTheme` calls apply immediately; later system or load events from `autoTheme` can apply the system preference again. There is no persisted user preference or teardown API.
95
+
22
96
  ## Development
23
97
 
24
- Use Node.js 20 or a newer supported LTS release.
98
+ Use Node.js 20 or a newer supported LTS release. The current build is verified with Node.js 24.
99
+
100
+ From the repository root, install the locked dependencies, run the existing checks and create a package:
25
101
 
26
102
  ```bash
27
103
  npm ci
28
104
  npm run check
29
105
  npm pack
30
106
  ```
107
+
108
+ The existing checks run ESLint, Prettier and the production build. `npm pack` creates a local archive; it does not publish a release.
109
+
110
+ ## Documentation
111
+
112
+ See [usage](docs/usage.md) for the existing HTML setup and Bootstrap integration.
113
+
114
+ ## How to contribute
115
+
116
+ There are many ways to contribute to the project: logging bugs, submitting pull requests, reporting issues, and creating suggestions.
117
+
118
+ Even if you have push rights on the repository, you should create a personal fork and create feature branches there when you need them. This keeps the main repository clean and your workflow cruft out of sight.
119
+
120
+ We're also interested in your feedback on the future of this project. You can submit a suggestion or feature request through the issue tracker. To make this process more effective, we're asking that these include more information to help define them more clearly.
121
+
122
+ ## License
123
+
124
+ Licensed under the [MIT License](LICENSE).
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aiursoft/autodark.js",
3
- "version": "1.2.12",
3
+ "version": "1.2.14",
4
4
  "description": "Auto dark theme",
5
5
  "module": "dist/esm/autodark.js",
6
6
  "types": "dist/types/autodark.d.ts",