@timus-networks/theme 1.0.3 → 1.0.4
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/components-js/interfaces.js +1 -0
- package/components-js/utils.d.ts +6 -0
- package/components-js/utils.js +17 -0
- package/convert.js +9 -0
- package/index.d.ts +1 -0
- package/package.json +2 -2
- package/plugins/theme-provider.js +68 -0
- package/components-js/interfaces.ts +0 -11
- package/components-js/utils.ts +0 -20
- package/js-converter.js +0 -90
- package/plugins/theme-provider.ts +0 -75
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export class Utils {
|
|
2
|
+
timeout = null;
|
|
3
|
+
debounce(func, delay) {
|
|
4
|
+
return (...args) => {
|
|
5
|
+
if (this.timeout !== null) {
|
|
6
|
+
clearTimeout(this.timeout);
|
|
7
|
+
}
|
|
8
|
+
this.timeout = setTimeout(() => {
|
|
9
|
+
func(...args);
|
|
10
|
+
}, delay);
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
generateRandomId() {
|
|
14
|
+
return Date.now().toString(36) + Math.random().toString(36).slice(2, 9);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
export const utils = new Utils();
|
package/convert.js
CHANGED
|
@@ -95,4 +95,13 @@ let imports = declarationFiles
|
|
|
95
95
|
.join('\n');
|
|
96
96
|
|
|
97
97
|
fs.writeFileSync('./index.d.ts', imports);
|
|
98
|
+
|
|
99
|
+
const tsFiles = glob.sync('./components-js/**/*.ts');
|
|
100
|
+
tsFiles.forEach((file) => {
|
|
101
|
+
if (!file.endsWith('.d.ts') && fs.existsSync(file)) {
|
|
102
|
+
fs.unlinkSync(file);
|
|
103
|
+
console.log(`### Ts dosyası silindi: ${file}`);
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
|
|
98
107
|
console.log('### index.d.ts dosyası oluşturuldu.');
|
package/index.d.ts
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './components-js/utils';
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@timus-networks/theme",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.4",
|
|
4
4
|
"description": "A comprehensive Nuxt.js module providing a tailored theme experience with integrated TailwindCSS support for applications.",
|
|
5
5
|
"main": "module.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
7
7
|
"scripts": {
|
|
8
8
|
"test": "echo \"Error: no test specified\" && exit 1",
|
|
9
|
-
"convert": "node
|
|
9
|
+
"convert": "node convert.js",
|
|
10
10
|
"pub": "npm run convert && npm publish --access public"
|
|
11
11
|
},
|
|
12
12
|
"repository": {
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import Vue from 'vue';
|
|
2
|
+
/**
|
|
3
|
+
* Helper functions to handle localStorage safely
|
|
4
|
+
*/
|
|
5
|
+
function getDarkModeFromLocalStorage() {
|
|
6
|
+
return process.client && localStorage.getItem('darkMode') === 'true';
|
|
7
|
+
}
|
|
8
|
+
function setDarkModeToLocalStorage(value) {
|
|
9
|
+
if (process.client) {
|
|
10
|
+
localStorage.setItem('darkMode', value.toString());
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
function setHtmlDarkClass(isDark) {
|
|
14
|
+
if (process.client) {
|
|
15
|
+
const htmlElement = document.documentElement;
|
|
16
|
+
if (isDark) {
|
|
17
|
+
htmlElement.classList.add('dark');
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
htmlElement.classList.remove('dark');
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* ThemeProvider: A Vue instance to provide theme related functionalities.
|
|
26
|
+
*
|
|
27
|
+
* Usage:
|
|
28
|
+
* - Change the theme on button click:
|
|
29
|
+
* this.$theme.setDarkMode(!this.$theme.isDark);
|
|
30
|
+
*
|
|
31
|
+
* - Register the theme change listener:
|
|
32
|
+
* this.$theme.$on('darkMode', (value) => { console.log('darkMode:', value); });
|
|
33
|
+
*/
|
|
34
|
+
export const ThemeProvider = new Vue({
|
|
35
|
+
data() {
|
|
36
|
+
return {
|
|
37
|
+
isDarkMode: getDarkModeFromLocalStorage(),
|
|
38
|
+
};
|
|
39
|
+
},
|
|
40
|
+
computed: {
|
|
41
|
+
isDark: {
|
|
42
|
+
get() {
|
|
43
|
+
return this.isDarkMode;
|
|
44
|
+
},
|
|
45
|
+
set(value) {
|
|
46
|
+
this.isDarkMode = value;
|
|
47
|
+
setDarkModeToLocalStorage(value);
|
|
48
|
+
this.$emit('darkMode', value);
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
watch: {
|
|
53
|
+
isDark(newVal) {
|
|
54
|
+
setHtmlDarkClass(newVal);
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
methods: {
|
|
58
|
+
setDarkMode(value) {
|
|
59
|
+
this.isDark = value; // This will trigger the setter of isDark.
|
|
60
|
+
},
|
|
61
|
+
},
|
|
62
|
+
created() {
|
|
63
|
+
setHtmlDarkClass(this.isDark); // Sayfa yüklendiğinde fonksiyonu manuel olarak tetikle
|
|
64
|
+
},
|
|
65
|
+
});
|
|
66
|
+
export default (context, inject) => {
|
|
67
|
+
inject('theme', ThemeProvider);
|
|
68
|
+
};
|
package/components-js/utils.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
export class Utils {
|
|
2
|
-
private timeout: ReturnType<typeof setTimeout> | null = null;
|
|
3
|
-
|
|
4
|
-
debounce(func: Function, delay: number) {
|
|
5
|
-
return (...args: any[]) => {
|
|
6
|
-
if (this.timeout !== null) {
|
|
7
|
-
clearTimeout(this.timeout);
|
|
8
|
-
}
|
|
9
|
-
this.timeout = setTimeout(() => {
|
|
10
|
-
func(...args);
|
|
11
|
-
}, delay);
|
|
12
|
-
};
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
generateRandomId(): string {
|
|
16
|
-
return Date.now().toString(36) + Math.random().toString(36).slice(2, 9);
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export const utils = new Utils();
|
package/js-converter.js
DELETED
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
const fs = require('fs');
|
|
2
|
-
const path = require('path');
|
|
3
|
-
const execSync = require('child_process').execSync;
|
|
4
|
-
const glob = require('glob');
|
|
5
|
-
|
|
6
|
-
// Eğer 'components-js' klasörü varsa sil
|
|
7
|
-
if (fs.existsSync('components-js')) {
|
|
8
|
-
fs.rmSync('components-js', { recursive: true, force: true });
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
// Yeni bir 'components-js' klasörü oluştur
|
|
12
|
-
fs.mkdirSync('components-js');
|
|
13
|
-
|
|
14
|
-
// components'in içerisindeki her şeyi output'a kopyala
|
|
15
|
-
const copyRecursiveSync = function (src, dest) {
|
|
16
|
-
const exists = fs.existsSync(src);
|
|
17
|
-
const stats = exists && fs.statSync(src);
|
|
18
|
-
const isDirectory = exists && stats.isDirectory();
|
|
19
|
-
if (exists && isDirectory) {
|
|
20
|
-
if (!fs.existsSync(dest)) fs.mkdirSync(dest);
|
|
21
|
-
fs.readdirSync(src).forEach((childItemName) => {
|
|
22
|
-
copyRecursiveSync(path.join(src, childItemName), path.join(dest, childItemName));
|
|
23
|
-
});
|
|
24
|
-
} else {
|
|
25
|
-
fs.copyFileSync(src, dest);
|
|
26
|
-
}
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
copyRecursiveSync('./components-ts', './components-js');
|
|
30
|
-
|
|
31
|
-
// output klasöründeki .vue dosyalarını bul
|
|
32
|
-
const vueFiles = glob.sync('./components-js/**/*.vue');
|
|
33
|
-
|
|
34
|
-
vueFiles.forEach((file) => {
|
|
35
|
-
const content = fs.readFileSync(file, 'utf-8');
|
|
36
|
-
const scriptMatch = content.match(/<script lang="ts">(.*?)<\/script>/s);
|
|
37
|
-
|
|
38
|
-
if (scriptMatch) {
|
|
39
|
-
let tsCode = scriptMatch[1];
|
|
40
|
-
tsCode = tsCode.replace(/import .*?from '.*?.vue';/g, (match) => `// ${match}`);
|
|
41
|
-
|
|
42
|
-
const tsFilePath = file.replace('.vue', '.temp.ts');
|
|
43
|
-
fs.writeFileSync(tsFilePath, tsCode, 'utf-8');
|
|
44
|
-
|
|
45
|
-
let hasError = false;
|
|
46
|
-
const tscPath = path.resolve(__dirname, '../../../node_modules/.bin/tsc');
|
|
47
|
-
|
|
48
|
-
try {
|
|
49
|
-
execSync(`${tscPath} ${tsFilePath} --allowJs false --module esnext --target esnext --declaration true`, { encoding: 'utf8' });
|
|
50
|
-
} catch (e) {
|
|
51
|
-
// console.error("### Derleme hatası:", tsFilePath, e);
|
|
52
|
-
// console.error('DERLEME HATASI: ', e.stdout.toString());
|
|
53
|
-
hasError = true;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
if (hasError) {
|
|
57
|
-
// temp.d.ts dosyasını yeniden oluştur ve adını
|
|
58
|
-
const tsOutputFilePath = tsFilePath.replace('.temp.ts', '.temp.d.ts');
|
|
59
|
-
const desiredOutputFilePath = tsFilePath.replace('.temp.ts', '.d.ts');
|
|
60
|
-
if (fs.existsSync(tsOutputFilePath)) {
|
|
61
|
-
fs.renameSync(tsOutputFilePath, desiredOutputFilePath);
|
|
62
|
-
}
|
|
63
|
-
const jsCode = fs.readFileSync(tsFilePath.replace('.ts', '.js'), 'utf-8');
|
|
64
|
-
const finalJsCode = jsCode.replace(/\/\/ import/g, 'import');
|
|
65
|
-
const newContent = content.replace(/<script lang="ts">(.*?)<\/script>/s, `<script>${finalJsCode}</script>`);
|
|
66
|
-
fs.writeFileSync(file, newContent, 'utf-8');
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
// Dosyaları sil
|
|
70
|
-
if (fs.existsSync(tsFilePath)) fs.unlinkSync(tsFilePath);
|
|
71
|
-
if (fs.existsSync(tsFilePath.replace('.ts', '.js'))) fs.unlinkSync(tsFilePath.replace('.ts', '.js'));
|
|
72
|
-
}
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
// vueFiles.forEach döngüsünden sonra
|
|
76
|
-
const declarationFiles = glob.sync('./components-js/**/*.d.ts');
|
|
77
|
-
|
|
78
|
-
// Bu dosyaları import eden bir index.d.ts oluştur
|
|
79
|
-
let imports = declarationFiles
|
|
80
|
-
.map((file) => {
|
|
81
|
-
// Dosya yolundan modül adını elde etmek için gereken işlemler
|
|
82
|
-
let modulePath = path.relative('.', file);
|
|
83
|
-
modulePath = modulePath.replace('.d.ts', '');
|
|
84
|
-
modulePath = modulePath.replace(/\\/g, '/'); // Windows için ters eğik çizgileri düzelt
|
|
85
|
-
return `export * from './${modulePath}';`;
|
|
86
|
-
})
|
|
87
|
-
.join('\n');
|
|
88
|
-
|
|
89
|
-
fs.writeFileSync('./index.d.ts', imports);
|
|
90
|
-
console.log("### index.d.ts dosyası oluşturuldu.");
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import { Context } from '@nuxt/types';
|
|
2
|
-
import Vue from 'vue';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Helper functions to handle localStorage safely
|
|
6
|
-
*/
|
|
7
|
-
function getDarkModeFromLocalStorage(): boolean {
|
|
8
|
-
return process.client && localStorage.getItem('darkMode') === 'true';
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
function setDarkModeToLocalStorage(value: boolean): void {
|
|
12
|
-
if (process.client) {
|
|
13
|
-
localStorage.setItem('darkMode', value.toString());
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
function setHtmlDarkClass(isDark: boolean): void {
|
|
18
|
-
if (process.client) {
|
|
19
|
-
const htmlElement = document.documentElement;
|
|
20
|
-
if (isDark) {
|
|
21
|
-
htmlElement.classList.add('dark');
|
|
22
|
-
} else {
|
|
23
|
-
htmlElement.classList.remove('dark');
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* ThemeProvider: A Vue instance to provide theme related functionalities.
|
|
30
|
-
*
|
|
31
|
-
* Usage:
|
|
32
|
-
* - Change the theme on button click:
|
|
33
|
-
* this.$theme.setDarkMode(!this.$theme.isDark);
|
|
34
|
-
*
|
|
35
|
-
* - Register the theme change listener:
|
|
36
|
-
* this.$theme.$on('darkMode', (value) => { console.log('darkMode:', value); });
|
|
37
|
-
*/
|
|
38
|
-
export const ThemeProvider = new Vue({
|
|
39
|
-
data() {
|
|
40
|
-
return {
|
|
41
|
-
isDarkMode: getDarkModeFromLocalStorage(),
|
|
42
|
-
};
|
|
43
|
-
},
|
|
44
|
-
computed: {
|
|
45
|
-
isDark: {
|
|
46
|
-
get(): boolean {
|
|
47
|
-
return this.isDarkMode;
|
|
48
|
-
},
|
|
49
|
-
set(value: boolean) {
|
|
50
|
-
this.isDarkMode = value;
|
|
51
|
-
setDarkModeToLocalStorage(value);
|
|
52
|
-
this.$emit('darkMode', value);
|
|
53
|
-
},
|
|
54
|
-
},
|
|
55
|
-
},
|
|
56
|
-
watch: {
|
|
57
|
-
isDark(newVal: boolean) {
|
|
58
|
-
setHtmlDarkClass(newVal);
|
|
59
|
-
},
|
|
60
|
-
},
|
|
61
|
-
methods: {
|
|
62
|
-
setDarkMode(value: boolean) {
|
|
63
|
-
this.isDark = value; // This will trigger the setter of isDark.
|
|
64
|
-
},
|
|
65
|
-
},
|
|
66
|
-
created() {
|
|
67
|
-
setHtmlDarkClass(this.isDark); // Sayfa yüklendiğinde fonksiyonu manuel olarak tetikle
|
|
68
|
-
},
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
type InjectFunction = (key: string, value: any) => void;
|
|
72
|
-
|
|
73
|
-
export default (context: Context, inject: InjectFunction) => {
|
|
74
|
-
inject('theme', ThemeProvider);
|
|
75
|
-
};
|