xiangjsoncraft 1.1.1 → 1.1.2
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/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 +18 -28
|
@@ -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.1.
|
|
3
|
+
"version": "1.1.2",
|
|
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
|
+
}
|
package/renderJson.js
CHANGED
|
@@ -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
|
export 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 @@ export 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
|
}
|