@aiursoft/autodark.js 1.1.4 → 1.2.1

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/docs/usage.md ADDED
@@ -0,0 +1,54 @@
1
+ # AutoDark.js
2
+
3
+ [![MIT licensed](https://img.shields.io/badge/license-MIT-blue.svg)](https://opensource.org/license/mit) [![Pipeline stat](https://badge-proxy.aiursoft.com/aiursoft/autodark.js/badges/master/pipeline.svg)](https://gitlab.aiursoft.com/aiursoft/autodark.js/-/pipelines) [![ManHours](https://manhours.aiursoft.com/r/github.com/aiursoftweb/autodark.js.svg)](https://manhours.aiursoft.com/r/github.com/aiursoftweb/autodark.js.html) [![npm](https://img.shields.io/npm/v/@aiursoft/autodark.js?color=blue)](https://www.npmjs.com/package/@aiursoft/autodark.js) [![npm](https://img.shields.io/npm/dm/@aiursoft/autodark.js)](https://www.npmjs.com/package/@aiursoft/autodark.js)
4
+
5
+ `@aiursoft/autodark.js` is a JavaScript library for detecting user's system dark mode and auto switch your website's theme.
6
+
7
+ ## Installation
8
+
9
+ Run the following command to install the most recent version of `@aiursoft/autodark.js` from npm:
10
+
11
+ ```sh
12
+ npm install @aiursoft/autodark.js
13
+ ```
14
+
15
+ Bootstrap 4.6.2 is the only version that is tested. To use this project, you need to use bootstrap 4.6.2 in your project.
16
+
17
+ ## Importing
18
+
19
+ ## Reference CSS
20
+
21
+ You also need to reference the CSS file in your HTML:
22
+
23
+ ```html
24
+ <link rel="stylesheet" href="./node_modules/bootstrap/dist/css/bootstrap.min.css" />
25
+ <link rel="stylesheet" href="./node_modules/@aiursoft/autodark.js/dist/css/autodark.min.css" />
26
+ ```
27
+
28
+ ## Reference JavaScript
29
+
30
+ You also need to reference bootstrap's JavaScript file:
31
+
32
+ ```html
33
+ <script src="./node_modules/jquery/dist/jquery.min.js" defer></script>
34
+ <script src="./node_modules/bootstrap/dist/js/bootstrap.bundle.min.js" defer></script>
35
+ <script type="module">
36
+ import { autoTheme } from './node_modules/@aiursoft/autodark.js/dist/esm/autodark.js'
37
+ autoTheme()
38
+ </script>
39
+ ```
40
+
41
+ ## How to build locally
42
+
43
+ ```bash
44
+ npm install
45
+ npm run build
46
+ ```
47
+
48
+ ## How to contribute
49
+
50
+ There are many ways to contribute to the project: logging bugs, submitting pull requests, reporting issues, and creating suggestions.
51
+
52
+ Even if you with 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.
53
+
54
+ 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.
package/package.json CHANGED
@@ -1,21 +1,21 @@
1
1
  {
2
2
  "name": "@aiursoft/autodark.js",
3
- "version": "1.1.4",
3
+ "version": "1.2.1",
4
4
  "description": "Auto dark theme",
5
- "main": "dist/cjs/autodark.js",
6
5
  "module": "dist/esm/autodark.js",
7
6
  "types": "dist/types/autodark.d.ts",
8
7
  "scripts": {
9
8
  "clean": "rm -rf ./dist",
10
- "build-css": "node-sass src/autodark.scss dist/css/autodark.min.css --output-style compressed --source-map true",
11
- "build-js": "tsc -b ./tsconfig.cjs.json ./tsconfig.esm.json ./tsconfig.types.json",
9
+ "build-css": "sass --style=compressed --source-map src/autodark.scss dist/css/autodark.min.css",
10
+ "build-js": "tsc -b ./tsconfig.json ./tsconfig.types.json",
12
11
  "build": "npm run build-css && npm run build-js",
13
12
  "format": "prettier --write .",
14
- "lint": "eslint src/ --ext .ts && prettier --check ."
13
+ "lint": "eslint src/ --ext .ts && prettier --check .",
14
+ "check": "npm run lint && npm run build"
15
15
  },
16
16
  "repository": {
17
17
  "type": "git",
18
- "url": "https://gitlab.aiursoft.cn/aiursoft/autodark.js"
18
+ "url": "https://github.com/AiursoftWeb/autodark.js"
19
19
  },
20
20
  "dependencies": {
21
21
  "bootstrap": "^4.6.2"
@@ -25,7 +25,7 @@
25
25
  "@typescript-eslint/eslint-plugin": "^6.16.0",
26
26
  "@typescript-eslint/parser": "^6.16.0",
27
27
  "eslint": "^8.56.0",
28
- "node-sass": "^9.0.0",
28
+ "sass": "^1.105.2",
29
29
  "prettier": "^3.1.1",
30
30
  "typescript": "^5.3.3"
31
31
  },
package/src/autodark.scss CHANGED
@@ -1,5 +1,3 @@
1
- @import '../node_modules/bootstrap/scss/bootstrap';
2
-
3
1
  .bg-dark {
4
2
  background-color: #24292e !important;
5
3
  }
package/tsconfig.json CHANGED
@@ -5,7 +5,9 @@
5
5
  "removeComments": false,
6
6
  "sourceMap": true,
7
7
  "strict": true,
8
- "target": "ESNext"
8
+ "target": "ESNext",
9
+ "outDir": "./dist/esm",
10
+ "module": "esnext"
9
11
  },
10
12
  "include": ["src/**/*"]
11
13
  }
@@ -1,208 +0,0 @@
1
- "use strict";
2
- /* eslint-disable @typescript-eslint/naming-convention */
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.switchTheme = exports.autoTheme = exports.lightThemeSettings = exports.darkThemeSettings = void 0;
5
- exports.darkThemeSettings = {
6
- body: [
7
- {
8
- classToAdd: ['bg-dark'],
9
- classToRemove: ['bg-light'],
10
- },
11
- ],
12
- table: [
13
- {
14
- classToAdd: ['table-dark'],
15
- classToRemove: ['table-light'],
16
- },
17
- ],
18
- '.navbar': [
19
- {
20
- classToAdd: ['navbar-dark', 'bg-dark'],
21
- classToRemove: ['navbar-light', 'bg-light', 'border-bottom', 'shadow-sm'],
22
- },
23
- ],
24
- '.modal-content': [
25
- {
26
- classToAdd: ['bg-dark'],
27
- classToRemove: ['bg-light'],
28
- },
29
- ],
30
- '.container-fluid': [
31
- {
32
- classToAdd: ['bg-dark'],
33
- classToRemove: ['bg-light'],
34
- },
35
- ],
36
- '.list-group-item': [
37
- {
38
- classToAdd: ['bg-dark'],
39
- classToRemove: ['bg-light'],
40
- },
41
- ],
42
- '.content-wrapper': [
43
- {
44
- classToAdd: ['bg-dark'],
45
- classToRemove: ['bg-light'],
46
- },
47
- ],
48
- '.card': [
49
- {
50
- classToAdd: ['bg-dark'],
51
- classToRemove: ['bg-light'],
52
- },
53
- ],
54
- '.bg-dark': [
55
- {
56
- classToAdd: [],
57
- classToRemove: ['bg-light'],
58
- },
59
- ],
60
- '.bg-light': [
61
- {
62
- classToAdd: ['bg-dark'],
63
- classToRemove: ['bg-light'],
64
- },
65
- ],
66
- '.bg-white': [
67
- {
68
- classToAdd: ['bg-dark'],
69
- classToRemove: ['bg-white', 'bg-light'],
70
- },
71
- ],
72
- '.bg': [
73
- {
74
- classToAdd: ['bg-dark'],
75
- classToRemove: ['bg-light'],
76
- },
77
- ],
78
- };
79
- exports.lightThemeSettings = {
80
- body: [
81
- {
82
- classToAdd: ['bg-light'],
83
- classToRemove: ['bg-dark'],
84
- },
85
- ],
86
- table: [
87
- {
88
- classToAdd: ['table-light'],
89
- classToRemove: ['table-dark'],
90
- },
91
- ],
92
- '.navbar': [
93
- {
94
- classToAdd: ['navbar-light', 'bg-light', 'border-bottom', 'shadow-sm'],
95
- classToRemove: ['navbar-dark', 'bg-dark'],
96
- },
97
- ],
98
- '.modal-content': [
99
- {
100
- classToAdd: ['bg-light'],
101
- classToRemove: ['bg-dark'],
102
- },
103
- ],
104
- '.container-fluid': [
105
- {
106
- classToAdd: ['bg-light'],
107
- classToRemove: ['bg-dark'],
108
- },
109
- ],
110
- '.list-group-item': [
111
- {
112
- classToAdd: ['bg-light'],
113
- classToRemove: ['bg-dark'],
114
- },
115
- ],
116
- '.content-wrapper': [
117
- {
118
- classToAdd: ['bg-light'],
119
- classToRemove: ['bg-dark'],
120
- },
121
- ],
122
- '.card': [
123
- {
124
- classToAdd: ['bg-light'],
125
- classToRemove: ['bg-dark'],
126
- },
127
- ],
128
- '.bg-dark': [
129
- {
130
- classToAdd: ['bg-light'],
131
- classToRemove: ['bg-dark'],
132
- },
133
- ],
134
- '.bg-light': [
135
- {
136
- classToAdd: [],
137
- classToRemove: ['bg-dark'],
138
- },
139
- ],
140
- '.bg-white': [
141
- {
142
- classToAdd: ['bg-light'],
143
- classToRemove: ['bg-white', 'bg-dark'],
144
- },
145
- ],
146
- '.bg': [
147
- {
148
- classToAdd: ['bg-light'],
149
- classToRemove: ['bg-dark'],
150
- },
151
- ],
152
- };
153
- const autoSwitchTheme = () => {
154
- // Replace dark theme class
155
- if (window.matchMedia &&
156
- window.matchMedia('(prefers-color-scheme: dark)').matches) {
157
- switchTheme('dark');
158
- // Hack body
159
- const bodyElement = document.querySelector('body');
160
- if (bodyElement) {
161
- bodyElement.style.color = 'white';
162
- }
163
- }
164
- else {
165
- switchTheme('light');
166
- // Hack body
167
- const bodyElement = document.querySelector('body');
168
- if (bodyElement) {
169
- bodyElement.style.color = 'black';
170
- }
171
- }
172
- };
173
- const switchTheme = (theme) => {
174
- const isDark = theme === 'dark';
175
- const themeSettings = isDark ? exports.darkThemeSettings : exports.lightThemeSettings;
176
- // Apply the theme Settings:
177
- Object.keys(themeSettings).forEach((key) => {
178
- const settings = themeSettings[key];
179
- // Get the elements:
180
- const elements = key.startsWith('.')
181
- ? document.querySelectorAll(key)
182
- : document.getElementsByTagName(key);
183
- Array.from(elements).forEach((el) => {
184
- if (!Array.isArray(settings)) {
185
- throw new Error('Invalid settings');
186
- }
187
- // Apply the settings:
188
- settings.forEach((itemChanges) => {
189
- itemChanges.classToAdd.forEach((className) => {
190
- el.classList.add(className);
191
- });
192
- itemChanges.classToRemove.forEach((className) => {
193
- el.classList.remove(className);
194
- });
195
- });
196
- });
197
- });
198
- };
199
- exports.switchTheme = switchTheme;
200
- const autoTheme = () => {
201
- autoSwitchTheme();
202
- window
203
- .matchMedia('(prefers-color-scheme: light)')
204
- .addEventListener('change', autoSwitchTheme);
205
- window.addEventListener('load', autoSwitchTheme);
206
- };
207
- exports.autoTheme = autoTheme;
208
- //# sourceMappingURL=autodark.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"autodark.js","sourceRoot":"","sources":["../../src/autodark.ts"],"names":[],"mappings":";AAAA,yDAAyD;;;AAU5C,QAAA,iBAAiB,GAAkB;IAC9C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js"
6
- }
7
- }
package/tsconfig.esm.json DELETED
@@ -1,7 +0,0 @@
1
- {
2
- "extends": "./tsconfig.json",
3
- "compilerOptions": {
4
- "outDir": "./dist/esm",
5
- "module": "esnext"
6
- }
7
- }