xiangjsoncraft 1.1.1 → 1.2.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/README.md +257 -304
- package/config.json +69 -174
- package/dist/xiangjsoncraft.cjs.js +18 -29
- package/dist/xiangjsoncraft.esm.js +18 -28
- package/dist/xiangjsoncraft.umd.js +19 -29
- package/package.json +2 -2
- package/renderJson.js +107 -66
package/config.json
CHANGED
|
@@ -1,218 +1,113 @@
|
|
|
1
1
|
{
|
|
2
2
|
"styles": {
|
|
3
3
|
"*": {
|
|
4
|
-
"margin":
|
|
5
|
-
"padding":
|
|
4
|
+
"margin": 0,
|
|
5
|
+
"padding": 0,
|
|
6
6
|
"boxSizing": "border-box",
|
|
7
|
-
"fontFamily": "
|
|
7
|
+
"fontFamily": "Segoe UI, Roboto, 微软雅黑, sans-serif"
|
|
8
8
|
},
|
|
9
9
|
"body": {
|
|
10
10
|
"backgroundColor": "#f0f4f8",
|
|
11
11
|
"color": "#334e68",
|
|
12
12
|
"lineHeight": "1.6",
|
|
13
|
-
"
|
|
14
|
-
"
|
|
13
|
+
"minHeight": "100vh",
|
|
14
|
+
"padding": "2rem 1rem"
|
|
15
15
|
},
|
|
16
16
|
".welcome-container": {
|
|
17
17
|
"maxWidth": "1200px",
|
|
18
18
|
"margin": "0 auto",
|
|
19
|
-
"padding": "
|
|
20
|
-
},
|
|
21
|
-
".welcome-header": {
|
|
22
|
-
"textAlign": "center",
|
|
23
|
-
"padding": "60px 20px",
|
|
24
|
-
"marginBottom": "40px",
|
|
25
|
-
"borderRadius": "12px",
|
|
26
|
-
"background": "linear-gradient(135deg, #4299e1, #63b3ed)",
|
|
27
|
-
"color": "white",
|
|
28
|
-
"boxShadow": "0 10px 25px -5px rgba(66, 153, 225, 0.3)",
|
|
29
|
-
"transition": "transform 0.5s ease, boxShadow 0.5s ease"
|
|
30
|
-
},
|
|
31
|
-
".welcome-header:hover": {
|
|
32
|
-
"transform": "translateY(-5px)",
|
|
33
|
-
"boxShadow": "0 15px 30px -8px rgba(66, 153, 225, 0.4)"
|
|
34
|
-
},
|
|
35
|
-
".logo-container": {
|
|
36
|
-
"marginBottom": "30px"
|
|
37
|
-
},
|
|
38
|
-
".logo": {
|
|
39
|
-
"width": "120px",
|
|
40
|
-
"height": "120px",
|
|
41
|
-
"margin": "0 auto",
|
|
42
|
-
"backgroundColor": "white",
|
|
43
|
-
"borderRadius": "50%",
|
|
44
|
-
"display": "flex",
|
|
45
|
-
"alignItems": "center",
|
|
46
|
-
"justifyContent": "center",
|
|
47
|
-
"fontSize": "48px",
|
|
48
|
-
"color": "#4299e1",
|
|
49
|
-
"boxShadow": "0 4px 12px rgba(0, 0, 0, 0.1)"
|
|
50
|
-
},
|
|
51
|
-
".logo::after": {
|
|
52
|
-
"content": "'J'",
|
|
53
|
-
"fontWeight": "bold"
|
|
19
|
+
"padding": "2rem"
|
|
54
20
|
},
|
|
55
21
|
".main-title": {
|
|
56
|
-
"fontSize": "2.
|
|
57
|
-
"
|
|
58
|
-
"
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
".main-title": {
|
|
62
|
-
"fontSize": "2rem"
|
|
63
|
-
}
|
|
22
|
+
"fontSize": "2.2rem",
|
|
23
|
+
"color": "#2d3748",
|
|
24
|
+
"textAlign": "center",
|
|
25
|
+
"marginBottom": "1.5rem",
|
|
26
|
+
"fontWeight": 700
|
|
64
27
|
},
|
|
65
28
|
".subtitle": {
|
|
66
29
|
"fontSize": "1.1rem",
|
|
67
|
-
"
|
|
68
|
-
"
|
|
69
|
-
"
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
"display": "grid",
|
|
73
|
-
"gridTemplateColumns": "repeat(auto-fit, minmax(300px, 1fr))",
|
|
74
|
-
"gap": "30px",
|
|
75
|
-
"marginBottom": "60px"
|
|
30
|
+
"color": "#718096",
|
|
31
|
+
"textAlign": "center",
|
|
32
|
+
"maxWidth": "800px",
|
|
33
|
+
"margin": "0 auto 3rem",
|
|
34
|
+
"lineHeight": "1.8"
|
|
76
35
|
},
|
|
77
36
|
".feature-card": {
|
|
78
|
-
"backgroundColor": "
|
|
37
|
+
"backgroundColor": "#ffffff",
|
|
79
38
|
"borderRadius": "12px",
|
|
80
|
-
"padding": "
|
|
81
|
-
"boxShadow": "0 4px 12px rgba(0,
|
|
39
|
+
"padding": "2rem",
|
|
40
|
+
"boxShadow": "0 4px 12px rgba(0,0,0,0.05)",
|
|
41
|
+
"maxWidth": "600px",
|
|
42
|
+
"margin": "0 auto 2rem",
|
|
82
43
|
"transition": "transform 0.3s ease, boxShadow 0.3s ease"
|
|
83
44
|
},
|
|
84
45
|
".feature-card:hover": {
|
|
85
|
-
"transform": "translateY(-
|
|
86
|
-
"boxShadow": "0
|
|
87
|
-
},
|
|
88
|
-
".feature-icon": {
|
|
89
|
-
"width": "60px",
|
|
90
|
-
"height": "60px",
|
|
91
|
-
"borderRadius": "12px",
|
|
92
|
-
"backgroundColor": "#ebf8ff",
|
|
93
|
-
"color": "#4299e1",
|
|
94
|
-
"display": "flex",
|
|
95
|
-
"alignItems": "center",
|
|
96
|
-
"justifyContent": "center",
|
|
97
|
-
"fontSize": "24px",
|
|
98
|
-
"marginBottom": "20px"
|
|
46
|
+
"transform": "translateY(-6px)",
|
|
47
|
+
"boxShadow": "0 8px 20px rgba(0,0,0,0.08)"
|
|
99
48
|
},
|
|
100
49
|
".feature-title": {
|
|
101
|
-
"fontSize": "1.
|
|
102
|
-
"
|
|
103
|
-
"
|
|
50
|
+
"fontSize": "1.4rem",
|
|
51
|
+
"color": "#4299e1",
|
|
52
|
+
"marginBottom": "1rem",
|
|
53
|
+
"fontWeight": 600
|
|
104
54
|
},
|
|
105
|
-
".feature-
|
|
55
|
+
".feature-desc": {
|
|
106
56
|
"color": "#718096",
|
|
107
57
|
"lineHeight": "1.7"
|
|
108
58
|
},
|
|
109
|
-
".
|
|
59
|
+
".primary-btn": {
|
|
60
|
+
"display": "block",
|
|
61
|
+
"width": "200px",
|
|
62
|
+
"height": "50px",
|
|
63
|
+
"lineHeight": "50px",
|
|
110
64
|
"textAlign": "center",
|
|
111
|
-
"marginBottom": "80px"
|
|
112
|
-
},
|
|
113
|
-
".primary-button": {
|
|
114
65
|
"backgroundColor": "#4299e1",
|
|
115
|
-
"color": "
|
|
66
|
+
"color": "#ffffff",
|
|
116
67
|
"border": "none",
|
|
117
68
|
"borderRadius": "8px",
|
|
118
|
-
"
|
|
69
|
+
"margin": "0 auto",
|
|
119
70
|
"fontSize": "1rem",
|
|
120
|
-
"fontWeight":
|
|
71
|
+
"fontWeight": 600,
|
|
121
72
|
"cursor": "pointer",
|
|
122
|
-
"transition": "
|
|
123
|
-
"boxShadow": "0 4px 6px rgba(66, 153, 225, 0.2)"
|
|
73
|
+
"transition": "backgroundColor 0.3s ease, transform 0.2s ease"
|
|
124
74
|
},
|
|
125
|
-
".primary-
|
|
75
|
+
".primary-btn:hover": {
|
|
126
76
|
"backgroundColor": "#3182ce",
|
|
127
|
-
"transform": "translateY(-2px)"
|
|
128
|
-
"boxShadow": "0 6px 10px rgba(66, 153, 225, 0.3)"
|
|
77
|
+
"transform": "translateY(-2px)"
|
|
129
78
|
},
|
|
130
|
-
"
|
|
131
|
-
"
|
|
132
|
-
|
|
133
|
-
"fontSize": "0.95rem"
|
|
134
|
-
},
|
|
135
|
-
".page-footer": {
|
|
136
|
-
"textAlign": "center",
|
|
137
|
-
"paddingTop": "30px",
|
|
138
|
-
"borderTop": "1px solid #e2e8f0",
|
|
139
|
-
"color": "#718096"
|
|
140
|
-
},
|
|
141
|
-
".copyright": {
|
|
142
|
-
"marginBottom": "15px",
|
|
143
|
-
"fontSize": "0.9rem"
|
|
144
|
-
},
|
|
145
|
-
".social-links": {
|
|
146
|
-
"display": "flex",
|
|
147
|
-
"justifyContent": "center",
|
|
148
|
-
"gap": "15px"
|
|
149
|
-
},
|
|
150
|
-
".social-icon": {
|
|
151
|
-
"color": "#718096",
|
|
152
|
-
"fontSize": "1.2rem",
|
|
153
|
-
"transition": "color 0.3s ease"
|
|
154
|
-
},
|
|
155
|
-
".social-icon:hover": {
|
|
156
|
-
"color": "#4299e1"
|
|
157
|
-
},
|
|
158
|
-
|
|
159
|
-
"body:not(.loaded) .welcome-header": {
|
|
160
|
-
"opacity": "0",
|
|
161
|
-
"transform": "translateY(20px)"
|
|
162
|
-
},
|
|
163
|
-
"body.loaded .welcome-header": {
|
|
164
|
-
"opacity": "1",
|
|
165
|
-
"transform": "translateY(0)",
|
|
166
|
-
"transition": "opacity 0.8s ease, transform 0.8s ease"
|
|
167
|
-
},
|
|
168
|
-
"body:not(.loaded) .feature-card": {
|
|
169
|
-
"opacity": "0",
|
|
170
|
-
"transform": "scale(0.95)"
|
|
171
|
-
},
|
|
172
|
-
"body.loaded .feature-card": {
|
|
173
|
-
"opacity": "1",
|
|
174
|
-
"transform": "scale(1)",
|
|
175
|
-
"transition": "opacity 0.6s ease, transform 0.6s ease"
|
|
176
|
-
},
|
|
177
|
-
"body.loaded .feature-card:nth-child(1)": { "transitionDelay": "0.2s" },
|
|
178
|
-
"body.loaded .feature-card:nth-child(2)": { "transitionDelay": "0.4s" },
|
|
179
|
-
"body.loaded .feature-card:nth-child(3)": { "transitionDelay": "0.6s" }
|
|
180
|
-
},
|
|
181
|
-
"content": {
|
|
182
|
-
".main-title": "Welcome to xiangjsoncraft",
|
|
183
|
-
".subtitle": "Create beautiful web pages with simple JSON configuration",
|
|
184
|
-
".primary-button": "Get Started",
|
|
185
|
-
".additional-info": "Join thousands of developers using our JSON configuration system",
|
|
186
|
-
".copyright": "© 2025 Dong Xiang. All rights reserved."
|
|
187
|
-
},
|
|
188
|
-
"features": {
|
|
189
|
-
"selectorPrefix": "#feature",
|
|
190
|
-
"items": [
|
|
191
|
-
{
|
|
192
|
-
"iconClass": "fas fa-code",
|
|
193
|
-
"title": "Simple Configuration",
|
|
194
|
-
"description": "Define your entire page style and content with easy-to-understand JSON"
|
|
79
|
+
"@media (max-width: 768px)": {
|
|
80
|
+
".main-title": {
|
|
81
|
+
"fontSize": "1.8rem"
|
|
195
82
|
},
|
|
196
|
-
{
|
|
197
|
-
"
|
|
198
|
-
"title": "Beautiful Designs",
|
|
199
|
-
"description": "Create stunning interfaces without writing complex CSS code"
|
|
83
|
+
".welcome-container": {
|
|
84
|
+
"padding": "1rem"
|
|
200
85
|
},
|
|
201
|
-
{
|
|
202
|
-
"
|
|
203
|
-
"title": "Responsive by Default",
|
|
204
|
-
"description": "Your pages will look great on all devices with built-in responsiveness"
|
|
86
|
+
".feature-card": {
|
|
87
|
+
"padding": "1.5rem"
|
|
205
88
|
}
|
|
206
|
-
|
|
89
|
+
}
|
|
207
90
|
},
|
|
208
|
-
"
|
|
209
|
-
"
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
91
|
+
"content": {
|
|
92
|
+
".main-title": {
|
|
93
|
+
"value": "XiangJsonCraft 测试页面",
|
|
94
|
+
"isHtml": false
|
|
95
|
+
},
|
|
96
|
+
".subtitle": {
|
|
97
|
+
"value": "基于JSON配置渲染的页面,无需手写CSS,修改JSON即可定制样式和内容!",
|
|
98
|
+
"isHtml": false
|
|
99
|
+
},
|
|
100
|
+
".feature-title": {
|
|
101
|
+
"value": "核心特色:JSON解耦",
|
|
102
|
+
"isHtml": false
|
|
103
|
+
},
|
|
104
|
+
".feature-desc": {
|
|
105
|
+
"value": "HTML仅负责搭建DOM骨架,样式、内容全由JSON控制,后期维护只需修改JSON,无需触碰HTML/JS代码。",
|
|
106
|
+
"isHtml": false
|
|
107
|
+
},
|
|
108
|
+
".primary-btn": {
|
|
109
|
+
"value": "<span onclick=\"window.open('https://www.npmjs.com/package/xiangjsoncraft', '_blank')\">点我查看 NPM 包地址</span>",
|
|
110
|
+
"isHtml": true
|
|
111
|
+
}
|
|
216
112
|
}
|
|
217
|
-
}
|
|
218
|
-
|
|
113
|
+
}
|
|
@@ -1,41 +1,30 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
|
|
4
|
-
// 定义 replaceCamelCase 方法,用于将驼峰式命名转换为连字符命名
|
|
5
|
-
String.prototype.replaceCamelCase = function (separator = '-') {
|
|
6
|
-
return this.replace(/[A-Z]/g, function (match) {
|
|
7
|
-
return separator + match.toLowerCase();
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
// 创建样式块并添加到文档头部
|
|
12
|
-
function createStyleBlock() {
|
|
13
|
-
const style = document.createElement('style');
|
|
14
|
-
style.id = 'dynamic-styles';
|
|
15
|
-
document.head.appendChild(style);
|
|
16
|
-
return style;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
3
|
// 封装通用JSON样式渲染函数,支持任意CSS选择器、HTML内容、媒体查询(v1.1.0核心功能)
|
|
20
4
|
function renderJsonStyles() {
|
|
21
|
-
//
|
|
22
|
-
const
|
|
23
|
-
const
|
|
24
|
-
? 'https://cdn.jsdelivr.net/npm/xiangjsoncraft@1.1.1/config.json'
|
|
25
|
-
: './config.json';
|
|
5
|
+
// 核心原则:本地config.json永远最高优先级,加载失败再用CDN官方配置
|
|
6
|
+
const localConfigUrl = './config.json'; // 本地用户自定义配置
|
|
7
|
+
const cdnConfigUrl = 'https://cdn.jsdelivr.net/npm/xiangjsoncraft@1.1.1/config.json'; // CDN兜底配置
|
|
26
8
|
|
|
27
|
-
//
|
|
28
|
-
fetch(
|
|
9
|
+
// 先尝试加载本地config.json
|
|
10
|
+
fetch(localConfigUrl)
|
|
29
11
|
.then(response => {
|
|
30
|
-
|
|
31
|
-
|
|
12
|
+
// 本地配置存在(状态码200),则使用本地配置
|
|
13
|
+
if (response.ok) {
|
|
14
|
+
console.log('🔧 检测到本地config.json,优先加载用户自定义配置');
|
|
15
|
+
return response.json();
|
|
32
16
|
}
|
|
33
|
-
|
|
17
|
+
// 本地配置不存在/加载失败,切换到CDN兜底配置
|
|
18
|
+
console.log('ℹ️ 本地未检测到config.json,加载CDN官方示例配置');
|
|
19
|
+
return fetch(cdnConfigUrl).then(res => {
|
|
20
|
+
if (!res.ok) throw new Error('CDN官方配置加载失败');
|
|
21
|
+
return res.json();
|
|
22
|
+
});
|
|
34
23
|
})
|
|
35
24
|
.then(config => {
|
|
36
25
|
// 获取或创建样式块,避免重复创建
|
|
37
26
|
const styleBlock = document.getElementById('dynamic-styles') || createStyleBlock();
|
|
38
|
-
if (!styleBlock) return console.error('样式块创建失败,无法渲染样式');
|
|
27
|
+
if (!styleBlock) return console.error('❌ 样式块创建失败,无法渲染样式');
|
|
39
28
|
|
|
40
29
|
// 生成CSS规则
|
|
41
30
|
let cssRules = '';
|
|
@@ -87,10 +76,10 @@ function renderJsonStyles() {
|
|
|
87
76
|
});
|
|
88
77
|
}
|
|
89
78
|
|
|
90
|
-
console.log('✅ XiangJsonCraft v1.1.
|
|
79
|
+
console.log('✅ XiangJsonCraft v1.1.1 渲染成功!');
|
|
91
80
|
})
|
|
92
81
|
.catch(error => {
|
|
93
|
-
console.error('❌ XiangJsonCraft
|
|
82
|
+
console.error('❌ XiangJsonCraft 处理配置时出错:', error.message);
|
|
94
83
|
});
|
|
95
84
|
}
|
|
96
85
|
|
|
@@ -1,38 +1,28 @@
|
|
|
1
|
-
// 定义 replaceCamelCase 方法,用于将驼峰式命名转换为连字符命名
|
|
2
|
-
String.prototype.replaceCamelCase = function (separator = '-') {
|
|
3
|
-
return this.replace(/[A-Z]/g, function (match) {
|
|
4
|
-
return separator + match.toLowerCase();
|
|
5
|
-
});
|
|
6
|
-
};
|
|
7
|
-
|
|
8
|
-
// 创建样式块并添加到文档头部
|
|
9
|
-
function createStyleBlock() {
|
|
10
|
-
const style = document.createElement('style');
|
|
11
|
-
style.id = 'dynamic-styles';
|
|
12
|
-
document.head.appendChild(style);
|
|
13
|
-
return style;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
1
|
// 封装通用JSON样式渲染函数,支持任意CSS选择器、HTML内容、媒体查询(v1.1.0核心功能)
|
|
17
2
|
function renderJsonStyles() {
|
|
18
|
-
//
|
|
19
|
-
const
|
|
20
|
-
const
|
|
21
|
-
? 'https://cdn.jsdelivr.net/npm/xiangjsoncraft@1.1.1/config.json'
|
|
22
|
-
: './config.json';
|
|
3
|
+
// 核心原则:本地config.json永远最高优先级,加载失败再用CDN官方配置
|
|
4
|
+
const localConfigUrl = './config.json'; // 本地用户自定义配置
|
|
5
|
+
const cdnConfigUrl = 'https://cdn.jsdelivr.net/npm/xiangjsoncraft@1.1.1/config.json'; // CDN兜底配置
|
|
23
6
|
|
|
24
|
-
//
|
|
25
|
-
fetch(
|
|
7
|
+
// 先尝试加载本地config.json
|
|
8
|
+
fetch(localConfigUrl)
|
|
26
9
|
.then(response => {
|
|
27
|
-
|
|
28
|
-
|
|
10
|
+
// 本地配置存在(状态码200),则使用本地配置
|
|
11
|
+
if (response.ok) {
|
|
12
|
+
console.log('🔧 检测到本地config.json,优先加载用户自定义配置');
|
|
13
|
+
return response.json();
|
|
29
14
|
}
|
|
30
|
-
|
|
15
|
+
// 本地配置不存在/加载失败,切换到CDN兜底配置
|
|
16
|
+
console.log('ℹ️ 本地未检测到config.json,加载CDN官方示例配置');
|
|
17
|
+
return fetch(cdnConfigUrl).then(res => {
|
|
18
|
+
if (!res.ok) throw new Error('CDN官方配置加载失败');
|
|
19
|
+
return res.json();
|
|
20
|
+
});
|
|
31
21
|
})
|
|
32
22
|
.then(config => {
|
|
33
23
|
// 获取或创建样式块,避免重复创建
|
|
34
24
|
const styleBlock = document.getElementById('dynamic-styles') || createStyleBlock();
|
|
35
|
-
if (!styleBlock) return console.error('样式块创建失败,无法渲染样式');
|
|
25
|
+
if (!styleBlock) return console.error('❌ 样式块创建失败,无法渲染样式');
|
|
36
26
|
|
|
37
27
|
// 生成CSS规则
|
|
38
28
|
let cssRules = '';
|
|
@@ -84,10 +74,10 @@ function renderJsonStyles() {
|
|
|
84
74
|
});
|
|
85
75
|
}
|
|
86
76
|
|
|
87
|
-
console.log('✅ XiangJsonCraft v1.1.
|
|
77
|
+
console.log('✅ XiangJsonCraft v1.1.1 渲染成功!');
|
|
88
78
|
})
|
|
89
79
|
.catch(error => {
|
|
90
|
-
console.error('❌ XiangJsonCraft
|
|
80
|
+
console.error('❌ XiangJsonCraft 处理配置时出错:', error.message);
|
|
91
81
|
});
|
|
92
82
|
}
|
|
93
83
|
|
|
@@ -1,38 +1,28 @@
|
|
|
1
|
-
(function(g,f){typeof exports==='object'&&typeof module!=='undefined'?f(exports):typeof define==='function'&&define.amd?define(['exports'],f):(g=typeof globalThis!=='undefined'?globalThis:g||self,f(g.XiangJsonCraft={}));})(this,(function(exports){'use strict'
|
|
2
|
-
String.prototype.replaceCamelCase = function (separator = '-') {
|
|
3
|
-
return this.replace(/[A-Z]/g, function (match) {
|
|
4
|
-
return separator + match.toLowerCase();
|
|
5
|
-
});
|
|
6
|
-
};
|
|
7
|
-
|
|
8
|
-
// 创建样式块并添加到文档头部
|
|
9
|
-
function createStyleBlock() {
|
|
10
|
-
const style = document.createElement('style');
|
|
11
|
-
style.id = 'dynamic-styles';
|
|
12
|
-
document.head.appendChild(style);
|
|
13
|
-
return style;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
// 封装通用JSON样式渲染函数,支持任意CSS选择器、HTML内容、媒体查询(v1.1.0核心功能)
|
|
1
|
+
(function(g,f){typeof exports==='object'&&typeof module!=='undefined'?f(exports):typeof define==='function'&&define.amd?define(['exports'],f):(g=typeof globalThis!=='undefined'?globalThis:g||self,f(g.XiangJsonCraft={}));})(this,(function(exports){'use strict';// 封装通用JSON样式渲染函数,支持任意CSS选择器、HTML内容、媒体查询(v1.1.0核心功能)
|
|
17
2
|
function renderJsonStyles() {
|
|
18
|
-
//
|
|
19
|
-
const
|
|
20
|
-
const
|
|
21
|
-
? 'https://cdn.jsdelivr.net/npm/xiangjsoncraft@1.1.1/config.json'
|
|
22
|
-
: './config.json';
|
|
3
|
+
// 核心原则:本地config.json永远最高优先级,加载失败再用CDN官方配置
|
|
4
|
+
const localConfigUrl = './config.json'; // 本地用户自定义配置
|
|
5
|
+
const cdnConfigUrl = 'https://cdn.jsdelivr.net/npm/xiangjsoncraft@1.1.1/config.json'; // CDN兜底配置
|
|
23
6
|
|
|
24
|
-
//
|
|
25
|
-
fetch(
|
|
7
|
+
// 先尝试加载本地config.json
|
|
8
|
+
fetch(localConfigUrl)
|
|
26
9
|
.then(response => {
|
|
27
|
-
|
|
28
|
-
|
|
10
|
+
// 本地配置存在(状态码200),则使用本地配置
|
|
11
|
+
if (response.ok) {
|
|
12
|
+
console.log('🔧 检测到本地config.json,优先加载用户自定义配置');
|
|
13
|
+
return response.json();
|
|
29
14
|
}
|
|
30
|
-
|
|
15
|
+
// 本地配置不存在/加载失败,切换到CDN兜底配置
|
|
16
|
+
console.log('ℹ️ 本地未检测到config.json,加载CDN官方示例配置');
|
|
17
|
+
return fetch(cdnConfigUrl).then(res => {
|
|
18
|
+
if (!res.ok) throw new Error('CDN官方配置加载失败');
|
|
19
|
+
return res.json();
|
|
20
|
+
});
|
|
31
21
|
})
|
|
32
22
|
.then(config => {
|
|
33
23
|
// 获取或创建样式块,避免重复创建
|
|
34
24
|
const styleBlock = document.getElementById('dynamic-styles') || createStyleBlock();
|
|
35
|
-
if (!styleBlock) return console.error('样式块创建失败,无法渲染样式');
|
|
25
|
+
if (!styleBlock) return console.error('❌ 样式块创建失败,无法渲染样式');
|
|
36
26
|
|
|
37
27
|
// 生成CSS规则
|
|
38
28
|
let cssRules = '';
|
|
@@ -84,9 +74,9 @@ function renderJsonStyles() {
|
|
|
84
74
|
});
|
|
85
75
|
}
|
|
86
76
|
|
|
87
|
-
console.log('✅ XiangJsonCraft v1.1.
|
|
77
|
+
console.log('✅ XiangJsonCraft v1.1.1 渲染成功!');
|
|
88
78
|
})
|
|
89
79
|
.catch(error => {
|
|
90
|
-
console.error('❌ XiangJsonCraft
|
|
80
|
+
console.error('❌ XiangJsonCraft 处理配置时出错:', error.message);
|
|
91
81
|
});
|
|
92
82
|
}exports.renderJsonStyles=renderJsonStyles;}));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "xiangjsoncraft",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "简单而强大的JSON配置与HTML页面渲染工具,支持任意CSS选择器、响应式设计、HTML内容动态注入,轻量无依赖",
|
|
5
5
|
"main": "dist/xiangjsoncraft.cjs.js",
|
|
6
6
|
"module": "dist/xiangjsoncraft.esm.js",
|
|
@@ -30,4 +30,4 @@
|
|
|
30
30
|
"author": "董翔 <3631247406@qq.com>",
|
|
31
31
|
"license": "MIT",
|
|
32
32
|
"homepage": "https://www.npmjs.com/package/xiangjsoncraft"
|
|
33
|
-
}
|
|
33
|
+
}
|