@anmiles/theme-switcher 1.0.2 → 2.0.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/.nycrc.json +27 -0
- package/CHANGELOG.md +10 -1
- package/README.md +43 -43
- package/cspell.json +18 -0
- package/dist/theme-switcher-2.0.0.js +307 -0
- package/dist/theme-switcher-2.0.0.min.js +22 -0
- package/eslint.config.mts +16 -0
- package/index.html +38 -0
- package/jest.config.js +13 -15
- package/package.json +56 -36
- package/server.mjs +11 -0
- package/src/__tests__/index.test.tsx +10 -8
- package/src/__tests__/theme.test.ts +1 -1
- package/src/components/App.tsx +13 -11
- package/src/components/Icon.tsx +3 -1
- package/src/components/ThemeSelector.tsx +3 -2
- package/src/components/__tests__/App.test.tsx +47 -48
- package/src/components/__tests__/__snapshots__/App.test.tsx.snap +60 -20
- package/src/components/icons/Dark.tsx +0 -1
- package/src/index.tsx +4 -3
- package/src/lib/__tests__/eventEmitter.test.ts +6 -6
- package/src/lib/eventEmitter.ts +5 -7
- package/src/lib/theme.ts +7 -9
- package/src/providers/__tests__/systemProvider.test.ts +16 -16
- package/src/providers/__tests__/userProvider.test.ts +4 -4
- package/src/providers/systemProvider.ts +1 -3
- package/src/providers/userProvider.ts +1 -3
- package/static/development/index.html +39 -0
- package/static/production/index.html +39 -0
- package/tsconfig.json +7 -11
- package/tsconfig.test.json +1 -1
- package/vite.config.mts +54 -0
- package/.eslintignore +0 -2
- package/.eslintrc.js +0 -10
- package/.vscode/settings.json +0 -6
- package/coverage.config.js +0 -8
- package/dev/index.html +0 -35
- package/dist/theme-switcher-1.0.2.js +0 -2194
- package/dist/theme-switcher-1.0.2.min.js +0 -2
- package/dist/theme-switcher-1.0.2.min.js.LICENSE.txt +0 -9
- package/tsconfig.build.json +0 -7
- package/webpack.config.js +0 -67
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { EventEmitter } from '../eventEmitter';
|
|
2
2
|
|
|
3
3
|
describe('src/lib/eventEmitter', () => {
|
|
4
|
-
const data = { key
|
|
4
|
+
const data = { key: 'value' };
|
|
5
5
|
|
|
6
6
|
const changeListener1 = jest.fn();
|
|
7
7
|
const changeListener2 = jest.fn();
|
|
@@ -23,8 +23,8 @@ describe('src/lib/eventEmitter', () => {
|
|
|
23
23
|
|
|
24
24
|
it('should register added listeners', () => {
|
|
25
25
|
const expectedListeners = {
|
|
26
|
-
change
|
|
27
|
-
delete
|
|
26
|
+
change: [ changeListener1, changeListener2 ],
|
|
27
|
+
delete: [ deleteListener1, deleteListener2 ],
|
|
28
28
|
};
|
|
29
29
|
|
|
30
30
|
expect(eventEmitter['listeners']).toEqual(expectedListeners);
|
|
@@ -93,7 +93,7 @@ describe('src/lib/eventEmitter', () => {
|
|
|
93
93
|
it('should work correctly in derived class', () => {
|
|
94
94
|
const spy = jest.fn();
|
|
95
95
|
|
|
96
|
-
class EventEmitterChild extends EventEmitter<{ myEvent
|
|
96
|
+
class EventEmitterChild extends EventEmitter<{ myEvent: [{ id: number }, string] }> {
|
|
97
97
|
}
|
|
98
98
|
|
|
99
99
|
const instance = new EventEmitterChild();
|
|
@@ -102,8 +102,8 @@ describe('src/lib/eventEmitter', () => {
|
|
|
102
102
|
spy(...data);
|
|
103
103
|
});
|
|
104
104
|
|
|
105
|
-
instance['emit']('myEvent', { id
|
|
105
|
+
instance['emit']('myEvent', { id: 1 }, 'something');
|
|
106
106
|
|
|
107
|
-
expect(spy).toHaveBeenCalledWith({ id
|
|
107
|
+
expect(spy).toHaveBeenCalledWith({ id: 1 }, 'something');
|
|
108
108
|
});
|
|
109
109
|
});
|
package/src/lib/eventEmitter.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
class EventEmitter<TEventMap extends Record<string, Array<unknown>>> {
|
|
2
|
-
private readonly listeners
|
|
3
|
-
[TEvent in keyof TEventMap]?: Array<(...data: TEventMap[TEvent])
|
|
1
|
+
export class EventEmitter<TEventMap extends Record<string, Array<unknown>>> {
|
|
2
|
+
private readonly listeners: {
|
|
3
|
+
[TEvent in keyof TEventMap]?: Array<(...data: TEventMap[TEvent])=> void>
|
|
4
4
|
} = {};
|
|
5
5
|
|
|
6
6
|
public on<TEvent extends keyof TEventMap>(
|
|
7
7
|
event: TEvent,
|
|
8
|
-
listener: (...data: TEventMap[TEvent])
|
|
8
|
+
listener: (...data: TEventMap[TEvent])=> void,
|
|
9
9
|
): void {
|
|
10
10
|
const listeners = this.listeners[event] ??= [];
|
|
11
11
|
listeners.push(listener);
|
|
@@ -13,7 +13,7 @@ class EventEmitter<TEventMap extends Record<string, Array<unknown>>> {
|
|
|
13
13
|
|
|
14
14
|
public off<TEvent extends keyof TEventMap>(
|
|
15
15
|
event: TEvent,
|
|
16
|
-
listener: (...data: TEventMap[TEvent])
|
|
16
|
+
listener: (...data: TEventMap[TEvent])=> void,
|
|
17
17
|
): void {
|
|
18
18
|
const listeners = this.listeners[event] ??= [];
|
|
19
19
|
listeners.splice(listeners.indexOf(listener), 1);
|
|
@@ -28,5 +28,3 @@ class EventEmitter<TEventMap extends Record<string, Array<unknown>>> {
|
|
|
28
28
|
});
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
|
-
|
|
32
|
-
export { EventEmitter };
|
package/src/lib/theme.ts
CHANGED
|
@@ -1,21 +1,19 @@
|
|
|
1
|
-
const themes = [ 'light', 'dark' ] as const;
|
|
2
|
-
type Theme = typeof themes[number];
|
|
3
|
-
const defaultTheme: Theme = 'light';
|
|
1
|
+
export const themes = [ 'light', 'dark' ] as const;
|
|
2
|
+
export type Theme = typeof themes[number];
|
|
3
|
+
export const defaultTheme: Theme = 'light';
|
|
4
4
|
|
|
5
|
-
function isTheme(arg: unknown): arg is Theme {
|
|
6
|
-
return typeof arg === 'string' && themes.includes(arg
|
|
5
|
+
export function isTheme(arg: unknown): arg is Theme {
|
|
6
|
+
return typeof arg === 'string' && themes.map(String).includes(arg);
|
|
7
7
|
}
|
|
8
8
|
|
|
9
|
-
function getThemeName(theme: Theme | undefined): string {
|
|
9
|
+
export function getThemeName(theme: Theme | undefined): string {
|
|
10
10
|
switch (theme) {
|
|
11
11
|
case 'light':
|
|
12
12
|
return 'Light';
|
|
13
13
|
case 'dark':
|
|
14
14
|
return 'Dark';
|
|
15
|
+
case undefined:
|
|
15
16
|
default:
|
|
16
17
|
return 'System';
|
|
17
18
|
}
|
|
18
19
|
}
|
|
19
|
-
|
|
20
|
-
export type { Theme };
|
|
21
|
-
export { themes, defaultTheme, isTheme, getThemeName };
|
|
@@ -6,29 +6,29 @@ import { SystemProvider } from '../systemProvider';
|
|
|
6
6
|
let systemProvider: SystemProvider;
|
|
7
7
|
const changeSpy = jest.fn();
|
|
8
8
|
|
|
9
|
-
class MediaQueryListEvents extends EventEmitter<{ change
|
|
9
|
+
class MediaQueryListEvents extends EventEmitter<{ change: [Partial<MediaQueryListEvent>] }> {}
|
|
10
10
|
|
|
11
11
|
const mediaQueryListEvents: Record<Theme, InstanceType<typeof MediaQueryListEvents>> = {
|
|
12
|
-
light
|
|
13
|
-
dark
|
|
12
|
+
light: new MediaQueryListEvents(),
|
|
13
|
+
dark : new MediaQueryListEvents(),
|
|
14
14
|
};
|
|
15
15
|
|
|
16
16
|
let systemPreference: Theme | undefined;
|
|
17
17
|
|
|
18
18
|
beforeEach(() => {
|
|
19
|
-
|
|
19
|
+
localStorage.clear();
|
|
20
20
|
systemProvider = new SystemProvider();
|
|
21
21
|
systemProvider.on('change', changeSpy);
|
|
22
22
|
systemPreference = undefined;
|
|
23
23
|
|
|
24
24
|
window.matchMedia = jest.fn().mockImplementation((query: string): Partial<MediaQueryList> => {
|
|
25
|
-
const parsedTheme = /\(prefers-color-scheme: (.*)\)/.exec(query)?.[1] as Theme;
|
|
25
|
+
const parsedTheme = /\(prefers-color-scheme: (.*)\)/.exec(query)?.[1] as Theme; // eslint-disable-line @typescript-eslint/no-unsafe-type-assertion
|
|
26
26
|
|
|
27
27
|
return {
|
|
28
|
-
matches
|
|
29
|
-
addEventListener
|
|
28
|
+
matches : parsedTheme === systemPreference,
|
|
29
|
+
addEventListener: (
|
|
30
30
|
event: keyof MediaQueryListEventMap,
|
|
31
|
-
listener: (ev: Partial<MediaQueryListEvent>)
|
|
31
|
+
listener: (ev: Partial<MediaQueryListEvent>)=> void,
|
|
32
32
|
) => {
|
|
33
33
|
mediaQueryListEvents[parsedTheme].on(event, listener);
|
|
34
34
|
},
|
|
@@ -64,37 +64,37 @@ describe('src/providers/systemProvider', () => {
|
|
|
64
64
|
// @ts-expect-error window always has matchMedia
|
|
65
65
|
delete window.matchMedia;
|
|
66
66
|
systemProvider.watch();
|
|
67
|
-
mediaQueryListEvents.light['emit']('change', { matches
|
|
68
|
-
mediaQueryListEvents.dark['emit']('change', { matches
|
|
67
|
+
mediaQueryListEvents.light['emit']('change', { matches: true });
|
|
68
|
+
mediaQueryListEvents.dark['emit']('change', { matches: true });
|
|
69
69
|
|
|
70
70
|
expect(changeSpy).not.toHaveBeenCalled();
|
|
71
71
|
});
|
|
72
72
|
|
|
73
73
|
it('should never emit change events if not called', () => {
|
|
74
|
-
mediaQueryListEvents.light['emit']('change', { matches
|
|
75
|
-
mediaQueryListEvents.dark['emit']('change', { matches
|
|
74
|
+
mediaQueryListEvents.light['emit']('change', { matches: true });
|
|
75
|
+
mediaQueryListEvents.dark['emit']('change', { matches: true });
|
|
76
76
|
|
|
77
77
|
expect(changeSpy).not.toHaveBeenCalled();
|
|
78
78
|
});
|
|
79
79
|
|
|
80
80
|
it('should emit change event on mediaQueryList change for light theme with match', () => {
|
|
81
81
|
systemProvider.watch();
|
|
82
|
-
mediaQueryListEvents.light['emit']('change', { matches
|
|
82
|
+
mediaQueryListEvents.light['emit']('change', { matches: true });
|
|
83
83
|
|
|
84
84
|
expect(changeSpy).toHaveBeenCalledWith('light');
|
|
85
85
|
});
|
|
86
86
|
|
|
87
87
|
it('should emit change event on mediaQueryList change for dark theme with match', () => {
|
|
88
88
|
systemProvider.watch();
|
|
89
|
-
mediaQueryListEvents.dark['emit']('change', { matches
|
|
89
|
+
mediaQueryListEvents.dark['emit']('change', { matches: true });
|
|
90
90
|
|
|
91
91
|
expect(changeSpy).toHaveBeenCalledWith('dark');
|
|
92
92
|
});
|
|
93
93
|
|
|
94
94
|
it('should not emit change event on mediaQueryList changes with no match', () => {
|
|
95
95
|
systemProvider.watch();
|
|
96
|
-
mediaQueryListEvents.light['emit']('change', { matches
|
|
97
|
-
mediaQueryListEvents.dark['emit']('change', { matches
|
|
96
|
+
mediaQueryListEvents.light['emit']('change', { matches: false });
|
|
97
|
+
mediaQueryListEvents.dark['emit']('change', { matches: false });
|
|
98
98
|
|
|
99
99
|
expect(changeSpy).not.toHaveBeenCalled();
|
|
100
100
|
});
|
|
@@ -5,7 +5,7 @@ const changeSpy = jest.fn();
|
|
|
5
5
|
let userProvider: UserProvider;
|
|
6
6
|
|
|
7
7
|
beforeEach(() => {
|
|
8
|
-
|
|
8
|
+
localStorage.clear();
|
|
9
9
|
userProvider = new UserProvider();
|
|
10
10
|
userProvider.on('change', changeSpy);
|
|
11
11
|
});
|
|
@@ -13,19 +13,19 @@ beforeEach(() => {
|
|
|
13
13
|
describe('src/providers/userProvider', () => {
|
|
14
14
|
describe('get', () => {
|
|
15
15
|
it('should return light theme if set in localStorage', () => {
|
|
16
|
-
|
|
16
|
+
localStorage.setItem(storageKey, 'light');
|
|
17
17
|
|
|
18
18
|
expect(userProvider.get()).toEqual('light');
|
|
19
19
|
});
|
|
20
20
|
|
|
21
21
|
it('should return dark theme if set in localStorage', () => {
|
|
22
|
-
|
|
22
|
+
localStorage.setItem(storageKey, 'dark');
|
|
23
23
|
|
|
24
24
|
expect(userProvider.get()).toEqual('dark');
|
|
25
25
|
});
|
|
26
26
|
|
|
27
27
|
it('should return undefined if unknown string set in localStorage', () => {
|
|
28
|
-
|
|
28
|
+
localStorage.setItem(storageKey, 'unknown');
|
|
29
29
|
|
|
30
30
|
expect(userProvider.get()).toEqual(undefined);
|
|
31
31
|
});
|
|
@@ -2,7 +2,7 @@ import { EventEmitter } from '../lib/eventEmitter';
|
|
|
2
2
|
import { defaultTheme, themes } from '../lib/theme';
|
|
3
3
|
import type { Theme } from '../lib/theme';
|
|
4
4
|
|
|
5
|
-
class SystemProvider extends EventEmitter<{ change
|
|
5
|
+
export class SystemProvider extends EventEmitter<{ change: [Theme] }> {
|
|
6
6
|
|
|
7
7
|
public get(): Theme {
|
|
8
8
|
if (!('matchMedia' in window)) {
|
|
@@ -36,5 +36,3 @@ class SystemProvider extends EventEmitter<{ change : [Theme] }> {
|
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
38
|
}
|
|
39
|
-
|
|
40
|
-
export { SystemProvider };
|
|
@@ -2,7 +2,7 @@ import { EventEmitter } from '../lib/eventEmitter';
|
|
|
2
2
|
import { isTheme } from '../lib/theme';
|
|
3
3
|
import type { Theme } from '../lib/theme';
|
|
4
4
|
|
|
5
|
-
class UserProvider extends EventEmitter<{ change
|
|
5
|
+
export class UserProvider extends EventEmitter<{ change: [Theme | undefined] }> {
|
|
6
6
|
private readonly storageKey = 'theme';
|
|
7
7
|
|
|
8
8
|
public get(): Theme | undefined {
|
|
@@ -20,5 +20,3 @@ class UserProvider extends EventEmitter<{ change : [Theme | undefined] }> {
|
|
|
20
20
|
this.emit('change', theme);
|
|
21
21
|
}
|
|
22
22
|
}
|
|
23
|
-
|
|
24
|
-
export { UserProvider };
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html>
|
|
3
|
+
<head>
|
|
4
|
+
<title>Theme switcher</title>
|
|
5
|
+
<meta charset="utf-8">
|
|
6
|
+
<link rel="stylesheet" href="https://dev.anmiles.net/index.css" type="text/css">
|
|
7
|
+
<link rel="icon" href="https://dev.anmiles.net/favicon.ico" type="image/x-icon">
|
|
8
|
+
<style type="text/css">
|
|
9
|
+
.theme {
|
|
10
|
+
cursor: pointer;
|
|
11
|
+
float: right;
|
|
12
|
+
}
|
|
13
|
+
</style>
|
|
14
|
+
</head>
|
|
15
|
+
<body>
|
|
16
|
+
|
|
17
|
+
<div class="top">
|
|
18
|
+
<div class="theme"></div>
|
|
19
|
+
</div>
|
|
20
|
+
|
|
21
|
+
<div class="box">
|
|
22
|
+
|
|
23
|
+
<p>Merry alone do it burst me songs. Sorry equal charm joy her those folly ham. In they no is many both. Recommend new contented intention improving bed performed age. Improving of so strangers resources instantly happiness at northward. Danger nearer length oppose really add now either. But ask regret eat branch fat garden. Become am he except wishes. Past so at door we walk want such sang. Feeling colonel get her garrets own.</p>
|
|
24
|
+
|
|
25
|
+
<p>Boisterous he on understood attachment as entreaties ye devonshire. In mile an form snug were been sell. Hastened admitted joy nor absolute gay its. Extremely ham any his departure for contained curiosity defective. Way now instrument had eat diminution melancholy expression sentiments stimulated. One built fat you out manor books. Mrs interested now his affronting inquietude contrasted cultivated. Lasting showing expense greater on colonel no.</p>
|
|
26
|
+
|
|
27
|
+
<p>Man request adapted spirits set pressed. Up to denoting subjects sensible feelings it indulged directly. We dwelling elegance do shutters appetite yourself diverted. Our next drew much you with rank. Tore many held age hold rose than our. She literature sentiments any contrasted. Set aware joy sense young now tears china shy.</p>
|
|
28
|
+
|
|
29
|
+
</div>
|
|
30
|
+
|
|
31
|
+
<script type="text/javascript" src="https://dev.anmiles.net/libs/react-18.3.1.js"></script>
|
|
32
|
+
<script type="text/javascript" src="https://dev.anmiles.net/libs/react-dom-18.3.1.js"></script>
|
|
33
|
+
<script type="text/javascript" src="./theme-switcher-1.0.2.js"></script>
|
|
34
|
+
<script type="text/javascript">
|
|
35
|
+
new ThemeSwitcher.Element({ float: 'right' }).render(document.querySelector('.theme'));
|
|
36
|
+
</script>
|
|
37
|
+
|
|
38
|
+
</body>
|
|
39
|
+
</html>
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html>
|
|
3
|
+
<head>
|
|
4
|
+
<title>Theme switcher</title>
|
|
5
|
+
<meta charset="utf-8">
|
|
6
|
+
<link rel="stylesheet" href="https://dev.anmiles.net/index.css" type="text/css">
|
|
7
|
+
<link rel="icon" href="https://dev.anmiles.net/favicon.ico" type="image/x-icon">
|
|
8
|
+
<style type="text/css">
|
|
9
|
+
.theme {
|
|
10
|
+
cursor: pointer;
|
|
11
|
+
float: right;
|
|
12
|
+
}
|
|
13
|
+
</style>
|
|
14
|
+
</head>
|
|
15
|
+
<body>
|
|
16
|
+
|
|
17
|
+
<div class="top">
|
|
18
|
+
<div class="theme"></div>
|
|
19
|
+
</div>
|
|
20
|
+
|
|
21
|
+
<div class="box">
|
|
22
|
+
|
|
23
|
+
<p>Merry alone do it burst me songs. Sorry equal charm joy her those folly ham. In they no is many both. Recommend new contented intention improving bed performed age. Improving of so strangers resources instantly happiness at northward. Danger nearer length oppose really add now either. But ask regret eat branch fat garden. Become am he except wishes. Past so at door we walk want such sang. Feeling colonel get her garrets own.</p>
|
|
24
|
+
|
|
25
|
+
<p>Boisterous he on understood attachment as entreaties ye devonshire. In mile an form snug were been sell. Hastened admitted joy nor absolute gay its. Extremely ham any his departure for contained curiosity defective. Way now instrument had eat diminution melancholy expression sentiments stimulated. One built fat you out manor books. Mrs interested now his affronting inquietude contrasted cultivated. Lasting showing expense greater on colonel no.</p>
|
|
26
|
+
|
|
27
|
+
<p>Man request adapted spirits set pressed. Up to denoting subjects sensible feelings it indulged directly. We dwelling elegance do shutters appetite yourself diverted. Our next drew much you with rank. Tore many held age hold rose than our. She literature sentiments any contrasted. Set aware joy sense young now tears china shy.</p>
|
|
28
|
+
|
|
29
|
+
</div>
|
|
30
|
+
|
|
31
|
+
<script type="text/javascript" src="https://dev.anmiles.net/libs/react-18.3.1.min.js"></script>
|
|
32
|
+
<script type="text/javascript" src="https://dev.anmiles.net/libs/react-dom-18.3.1.min.js"></script>
|
|
33
|
+
<script type="text/javascript" src="./theme-switcher-1.0.2.min.js"></script>
|
|
34
|
+
<script type="text/javascript">
|
|
35
|
+
new ThemeSwitcher.Element({ float: 'right' }).render(document.querySelector('.theme'));
|
|
36
|
+
</script>
|
|
37
|
+
|
|
38
|
+
</body>
|
|
39
|
+
</html>
|
package/tsconfig.json
CHANGED
|
@@ -1,16 +1,12 @@
|
|
|
1
1
|
{
|
|
2
|
-
"extends" : "./node_modules/@anmiles/tsconfig/tsconfig.json",
|
|
3
|
-
|
|
4
|
-
"compilerOptions" : {
|
|
5
|
-
"rootDir" : "./src",
|
|
6
|
-
"outDir" : "./dist",
|
|
7
|
-
"jsx" : "react-jsx",
|
|
8
|
-
"sourceMap" : false,
|
|
9
|
-
"declaration" : false,
|
|
10
|
-
"declarationMap" : false
|
|
11
|
-
},
|
|
2
|
+
"extends" : "./node_modules/@anmiles/tsconfig/tsconfig.client.json",
|
|
12
3
|
|
|
13
4
|
"include" : [
|
|
14
|
-
"src"
|
|
5
|
+
"src",
|
|
6
|
+
"vite.config.mts",
|
|
15
7
|
],
|
|
8
|
+
|
|
9
|
+
"compilerOptions" : {
|
|
10
|
+
"types" : [ "vite/client" ],
|
|
11
|
+
},
|
|
16
12
|
}
|
package/tsconfig.test.json
CHANGED
package/vite.config.mts
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import react from '@vitejs/plugin-react';
|
|
2
|
+
import { defineConfig } from 'vite';
|
|
3
|
+
import { libInjectCss } from 'vite-plugin-lib-inject-css';
|
|
4
|
+
|
|
5
|
+
import { version } from './package.json';
|
|
6
|
+
|
|
7
|
+
export default defineConfig(({ mode }) => {
|
|
8
|
+
const isProduction = mode === 'production';
|
|
9
|
+
|
|
10
|
+
return {
|
|
11
|
+
plugins: [
|
|
12
|
+
react(),
|
|
13
|
+
libInjectCss(),
|
|
14
|
+
],
|
|
15
|
+
resolve: {
|
|
16
|
+
extensions: [
|
|
17
|
+
'.js', '.mjs', '.cjs',
|
|
18
|
+
'.ts', '.cts', '.mts',
|
|
19
|
+
'.jsx', '.tsx', '.json',
|
|
20
|
+
],
|
|
21
|
+
},
|
|
22
|
+
server: {
|
|
23
|
+
open: true,
|
|
24
|
+
},
|
|
25
|
+
build: {
|
|
26
|
+
lib: {
|
|
27
|
+
entry : 'src/index.tsx',
|
|
28
|
+
name : 'ThemeSwitcher',
|
|
29
|
+
fileName: () =>
|
|
30
|
+
isProduction
|
|
31
|
+
? `theme-switcher-${version}.min.js`
|
|
32
|
+
: `theme-switcher-${version}.js`,
|
|
33
|
+
formats: [ 'iife' ],
|
|
34
|
+
},
|
|
35
|
+
rollupOptions: {
|
|
36
|
+
external: [
|
|
37
|
+
'react',
|
|
38
|
+
'react-dom',
|
|
39
|
+
],
|
|
40
|
+
output: {
|
|
41
|
+
globals: {
|
|
42
|
+
'react' : 'React',
|
|
43
|
+
'react-dom': 'ReactDOM',
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
},
|
|
47
|
+
minify : isProduction ? 'esbuild' : false,
|
|
48
|
+
emptyOutDir: false,
|
|
49
|
+
},
|
|
50
|
+
define: {
|
|
51
|
+
'process.env.NODE_ENV': JSON.stringify(process.env['NODE_ENV'] || 'development'),
|
|
52
|
+
},
|
|
53
|
+
};
|
|
54
|
+
});
|
package/.eslintignore
DELETED
package/.eslintrc.js
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
module.exports = {
|
|
2
|
-
root : true,
|
|
3
|
-
|
|
4
|
-
extends : [
|
|
5
|
-
'./node_modules/@anmiles/eslint-config/src/base.preset.js',
|
|
6
|
-
'./node_modules/@anmiles/eslint-config/src/ts.preset.js',
|
|
7
|
-
'./node_modules/@anmiles/eslint-config/src/jest.preset.js',
|
|
8
|
-
'./node_modules/@anmiles/eslint-config/src/react.preset.js',
|
|
9
|
-
],
|
|
10
|
-
};
|
package/.vscode/settings.json
DELETED
package/coverage.config.js
DELETED
package/dev/index.html
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
<!DOCTYPE html>
|
|
2
|
-
<html>
|
|
3
|
-
<head>
|
|
4
|
-
<title>Debug</title>
|
|
5
|
-
<meta charset="utf-8">
|
|
6
|
-
<link rel="stylesheet" href="https://dev.anmiles.net/index.css" type="text/css">
|
|
7
|
-
<link rel="icon" href="https://dev.anmiles.net/favicon.ico" type="image/x-icon">
|
|
8
|
-
<style type="text/css">
|
|
9
|
-
.theme {
|
|
10
|
-
cursor: pointer;
|
|
11
|
-
float: right;
|
|
12
|
-
}
|
|
13
|
-
</style>
|
|
14
|
-
</head>
|
|
15
|
-
<body>
|
|
16
|
-
|
|
17
|
-
<div class="top">
|
|
18
|
-
<div class="theme"></div>
|
|
19
|
-
</div>
|
|
20
|
-
|
|
21
|
-
<div class="box">
|
|
22
|
-
|
|
23
|
-
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam semper pretium nunc vel fermentum. Morbi egestas dictum maximus. Sed convallis vulputate nibh nec elementum. Nunc maximus posuere ipsum sit amet sollicitudin. In ullamcorper sagittis neque non tristique. Phasellus ac purus sit amet enim cursus aliquet et quis enim. Suspendisse sit amet tincidunt ante, at interdum tellus. Proin mauris nulla, porttitor a neque nec, lacinia tristique turpis. Aenean ac commodo turpis.</p>
|
|
24
|
-
|
|
25
|
-
<p>Nulla consectetur magna eget felis dignissim, ut pellentesque libero venenatis. Suspendisse tempus blandit dui, ut volutpat nisl. Nam laoreet sit amet dui eu pretium. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed accumsan nisi blandit, volutpat sem sed, placerat eros. Duis dignissim id velit eu placerat. Sed a magna efficitur diam ultrices pulvinar. Suspendisse placerat massa orci. Ut a facilisis nisi. Morbi imperdiet neque id orci luctus facilisis. Suspendisse sit amet consectetur tortor, a elementum ipsum.</p>
|
|
26
|
-
|
|
27
|
-
</div>
|
|
28
|
-
|
|
29
|
-
<script type="text/javascript" src="https://dev.anmiles.net/libs/react-18.3.1.js"></script>
|
|
30
|
-
<script type="text/javascript" src="https://dev.anmiles.net/libs/react-dom-18.3.1.js"></script>
|
|
31
|
-
<script type="text/javascript" src="./theme-switcher-1.0.2.js"></script>
|
|
32
|
-
<script type="text/javascript">new ThemeSwitcherElement({ float: 'right' }).render(document.querySelector('.theme'));</script>
|
|
33
|
-
|
|
34
|
-
</body>
|
|
35
|
-
</html>
|