xiangjsoncraft 2.0.1 → 2.0.3
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 +1 -1
- package/bin/create.js +3 -2
- package/package.json +11 -48
- package/rollup.config.js +10 -14
- package/dist/xiangjsoncraft.cjs.js +0 -86
- package/dist/xiangjsoncraft.esm.js +0 -84
package/README.md
CHANGED
package/bin/create.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
1
|
+
#!/usr/bin/env node
|
|
2
2
|
import fs from 'fs-extra';
|
|
3
3
|
import path from 'path';
|
|
4
4
|
import { fileURLToPath } from 'url';
|
|
@@ -71,6 +71,7 @@ try {
|
|
|
71
71
|
fs.ensureDirSync(projectDir);
|
|
72
72
|
|
|
73
73
|
// 2. 生成 package.json(修复本地路径依赖问题)
|
|
74
|
+
// 生成 package.json(核心:删除本地路径,改用 npm 版本)
|
|
74
75
|
const packageJson = {
|
|
75
76
|
"name": projectName,
|
|
76
77
|
"version": "1.0.0",
|
|
@@ -81,7 +82,7 @@ try {
|
|
|
81
82
|
"test": "echo \"Error: no test specified\" && exit 1"
|
|
82
83
|
},
|
|
83
84
|
"dependencies": {
|
|
84
|
-
|
|
85
|
+
|
|
85
86
|
"xiangjsoncraft": "^2.0.1"
|
|
86
87
|
},
|
|
87
88
|
"license": "MIT"
|
package/package.json
CHANGED
|
@@ -1,56 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "xiangjsoncraft",
|
|
3
|
-
"version": "2.0.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "2.0.3",
|
|
4
|
+
"description": "XiangJsonCraft 2.0 项目 - Write JSON, Get a Website",
|
|
5
5
|
"type": "module",
|
|
6
|
-
"
|
|
7
|
-
"
|
|
8
|
-
"
|
|
6
|
+
"scripts": {
|
|
7
|
+
"start": "npx live-server . --port=3000",
|
|
8
|
+
"test": "echo \"XiangJsonCraft 测试成功!\"",
|
|
9
|
+
"build": "rollup -c rollup.config.js"
|
|
9
10
|
},
|
|
10
|
-
"main": "./dist/xiangjsoncraft.umd.js",
|
|
11
|
-
"module": "./src/renderJson.js",
|
|
12
|
-
"files": [
|
|
13
|
-
"bin",
|
|
14
|
-
"dist",
|
|
15
|
-
"src",
|
|
16
|
-
"template",
|
|
17
|
-
"rollup.config.js",
|
|
18
|
-
"README.md"
|
|
19
|
-
],
|
|
20
|
-
"keywords": [
|
|
21
|
-
"json",
|
|
22
|
-
"framework",
|
|
23
|
-
"no-css",
|
|
24
|
-
"no-js",
|
|
25
|
-
"low-code",
|
|
26
|
-
"轻量框架",
|
|
27
|
-
"json驱动",
|
|
28
|
-
"可视化配置",
|
|
29
|
-
"前端零代码"
|
|
30
|
-
],
|
|
31
|
-
"author": "",
|
|
32
|
-
"license": "MIT",
|
|
33
11
|
"dependencies": {
|
|
34
|
-
"
|
|
35
|
-
"commander": "^12.0.0",
|
|
36
|
-
"fs-extra": "^11.2.0",
|
|
37
|
-
"inquirer": "^9.2.16",
|
|
38
|
-
"ora": "^8.0.1"
|
|
12
|
+
"xiangjsoncraft": "^2.0.2"
|
|
39
13
|
},
|
|
40
14
|
"devDependencies": {
|
|
41
|
-
"
|
|
42
|
-
"rollup": "^4.
|
|
43
|
-
},
|
|
44
|
-
"scripts": {
|
|
45
|
-
"build": "npx rollup -c rollup.config.js",
|
|
46
|
-
"prepublishOnly": "npm run build"
|
|
47
|
-
},
|
|
48
|
-
"repository": {
|
|
49
|
-
"type": "git",
|
|
50
|
-
"url": "https://github.com/dxiangwiki/xiangjsoncraft.git"
|
|
15
|
+
"live-server": "^1.2.2",
|
|
16
|
+
"rollup": "^4.57.1"
|
|
51
17
|
},
|
|
52
|
-
"
|
|
53
|
-
|
|
54
|
-
"url": "https://github.com/dxiangwiki/xiangjsoncraft/issues"
|
|
55
|
-
}
|
|
56
|
-
}
|
|
18
|
+
"license": "MIT"
|
|
19
|
+
}
|
package/rollup.config.js
CHANGED
|
@@ -1,21 +1,17 @@
|
|
|
1
|
-
import terser from '@rollup/plugin-terser';
|
|
1
|
+
import terser from '@rollup/plugin-terser';
|
|
2
|
+
|
|
2
3
|
export default {
|
|
3
|
-
input: 'src/renderJson.js',
|
|
4
|
+
input: 'src/renderJson.js', // 你的核心渲染文件
|
|
4
5
|
output: {
|
|
5
6
|
file: 'dist/xiangjsoncraft.umd.js',
|
|
6
|
-
format: 'umd',
|
|
7
|
-
name: 'XiangJsonCraft',
|
|
8
|
-
|
|
7
|
+
format: 'umd', // UMD 格式兼容浏览器/Node.js
|
|
8
|
+
name: 'XiangJsonCraft', // 全局变量名,对应 window.XiangJsonCraft
|
|
9
|
+
globals: {},
|
|
10
|
+
// ✅ 确保打包后的代码兼容低版本浏览器
|
|
11
|
+
compact: true,
|
|
12
|
+
sourcemap: false
|
|
9
13
|
},
|
|
10
14
|
plugins: [
|
|
11
|
-
terser(
|
|
12
|
-
compress: {
|
|
13
|
-
drop_console: false,
|
|
14
|
-
pure_funcs: []
|
|
15
|
-
},
|
|
16
|
-
format: {
|
|
17
|
-
comments: false
|
|
18
|
-
}
|
|
19
|
-
})
|
|
15
|
+
terser() // 压缩但不改变语法
|
|
20
16
|
]
|
|
21
17
|
};
|
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
// 封装通用JSON样式渲染函数,支持任意CSS选择器、HTML内容、媒体查询(v1.1.0核心功能)
|
|
4
|
-
function renderJsonStyles() {
|
|
5
|
-
// 核心原则:本地config.json永远最高优先级,加载失败再用CDN官方配置
|
|
6
|
-
const localConfigUrl = './config.json'; // 本地用户自定义配置
|
|
7
|
-
const cdnConfigUrl = 'https://cdn.jsdelivr.net/npm/xiangjsoncraft@1.1.1/config.json'; // CDN兜底配置
|
|
8
|
-
|
|
9
|
-
// 先尝试加载本地config.json
|
|
10
|
-
fetch(localConfigUrl)
|
|
11
|
-
.then(response => {
|
|
12
|
-
// 本地配置存在(状态码200),则使用本地配置
|
|
13
|
-
if (response.ok) {
|
|
14
|
-
console.log('🔧 检测到本地config.json,优先加载用户自定义配置');
|
|
15
|
-
return response.json();
|
|
16
|
-
}
|
|
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
|
-
});
|
|
23
|
-
})
|
|
24
|
-
.then(config => {
|
|
25
|
-
// 获取或创建样式块,避免重复创建
|
|
26
|
-
const styleBlock = document.getElementById('dynamic-styles') || createStyleBlock();
|
|
27
|
-
if (!styleBlock) return console.error('❌ 样式块创建失败,无法渲染样式');
|
|
28
|
-
|
|
29
|
-
// 生成CSS规则
|
|
30
|
-
let cssRules = '';
|
|
31
|
-
|
|
32
|
-
// 处理所有选择器样式(支持任意CSS选择器、媒体查询)
|
|
33
|
-
if (config.styles && typeof config.styles === 'object' && Object.keys(config.styles).length > 0) {
|
|
34
|
-
// 遍历所有选择器(类、ID、伪类、媒体查询等)
|
|
35
|
-
Object.entries(config.styles).forEach(([selector, styles]) => {
|
|
36
|
-
// 过滤空样式,避免无效CSS
|
|
37
|
-
if (!styles || typeof styles !== 'object') return;
|
|
38
|
-
// 生成该选择器的所有样式属性
|
|
39
|
-
const styleProperties = Object.entries(styles)
|
|
40
|
-
.map(([prop, value]) => {
|
|
41
|
-
// 过滤空属性,驼峰式属性名转换为CSS标准格式
|
|
42
|
-
if (!prop || value === undefined || value === null) return '';
|
|
43
|
-
const cssProp = prop.replaceCamelCase();
|
|
44
|
-
return `${cssProp}: ${value};`;
|
|
45
|
-
})
|
|
46
|
-
.filter(Boolean) // 移除空属性
|
|
47
|
-
.join('\n ');
|
|
48
|
-
|
|
49
|
-
// 仅当有样式属性时,添加到CSS规则
|
|
50
|
-
if (styleProperties) {
|
|
51
|
-
cssRules += `${selector} {\n ${styleProperties}\n}\n\n`;
|
|
52
|
-
}
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
// 应用生成的CSS规则到样式块
|
|
57
|
-
if (cssRules) {
|
|
58
|
-
styleBlock.innerHTML = cssRules;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
// 处理内容配置(支持纯文本/HTML内容,通过isHtml标识)
|
|
62
|
-
if (config.content && typeof config.content === 'object' && Object.keys(config.content).length > 0) {
|
|
63
|
-
Object.entries(config.content).forEach(([selector, content]) => {
|
|
64
|
-
// 过滤无效选择器和内容
|
|
65
|
-
if (!selector || !content || !content.hasOwnProperty('value')) return;
|
|
66
|
-
const elements = document.querySelectorAll(selector);
|
|
67
|
-
elements.forEach(el => {
|
|
68
|
-
if (!el) return;
|
|
69
|
-
// 支持HTML内容或纯文本,默认纯文本
|
|
70
|
-
if (content.isHtml) {
|
|
71
|
-
el.innerHTML = content.value;
|
|
72
|
-
} else {
|
|
73
|
-
el.textContent = content.value;
|
|
74
|
-
}
|
|
75
|
-
});
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
console.log('✅ XiangJsonCraft v1.1.1 渲染成功!');
|
|
80
|
-
})
|
|
81
|
-
.catch(error => {
|
|
82
|
-
console.error('❌ XiangJsonCraft 处理配置时出错:', error.message);
|
|
83
|
-
});
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
exports.renderJsonStyles = renderJsonStyles;
|
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
// 封装通用JSON样式渲染函数,支持任意CSS选择器、HTML内容、媒体查询(v1.1.0核心功能)
|
|
2
|
-
function renderJsonStyles() {
|
|
3
|
-
// 核心原则:本地config.json永远最高优先级,加载失败再用CDN官方配置
|
|
4
|
-
const localConfigUrl = './config.json'; // 本地用户自定义配置
|
|
5
|
-
const cdnConfigUrl = 'https://cdn.jsdelivr.net/npm/xiangjsoncraft@1.1.1/config.json'; // CDN兜底配置
|
|
6
|
-
|
|
7
|
-
// 先尝试加载本地config.json
|
|
8
|
-
fetch(localConfigUrl)
|
|
9
|
-
.then(response => {
|
|
10
|
-
// 本地配置存在(状态码200),则使用本地配置
|
|
11
|
-
if (response.ok) {
|
|
12
|
-
console.log('🔧 检测到本地config.json,优先加载用户自定义配置');
|
|
13
|
-
return response.json();
|
|
14
|
-
}
|
|
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
|
-
});
|
|
21
|
-
})
|
|
22
|
-
.then(config => {
|
|
23
|
-
// 获取或创建样式块,避免重复创建
|
|
24
|
-
const styleBlock = document.getElementById('dynamic-styles') || createStyleBlock();
|
|
25
|
-
if (!styleBlock) return console.error('❌ 样式块创建失败,无法渲染样式');
|
|
26
|
-
|
|
27
|
-
// 生成CSS规则
|
|
28
|
-
let cssRules = '';
|
|
29
|
-
|
|
30
|
-
// 处理所有选择器样式(支持任意CSS选择器、媒体查询)
|
|
31
|
-
if (config.styles && typeof config.styles === 'object' && Object.keys(config.styles).length > 0) {
|
|
32
|
-
// 遍历所有选择器(类、ID、伪类、媒体查询等)
|
|
33
|
-
Object.entries(config.styles).forEach(([selector, styles]) => {
|
|
34
|
-
// 过滤空样式,避免无效CSS
|
|
35
|
-
if (!styles || typeof styles !== 'object') return;
|
|
36
|
-
// 生成该选择器的所有样式属性
|
|
37
|
-
const styleProperties = Object.entries(styles)
|
|
38
|
-
.map(([prop, value]) => {
|
|
39
|
-
// 过滤空属性,驼峰式属性名转换为CSS标准格式
|
|
40
|
-
if (!prop || value === undefined || value === null) return '';
|
|
41
|
-
const cssProp = prop.replaceCamelCase();
|
|
42
|
-
return `${cssProp}: ${value};`;
|
|
43
|
-
})
|
|
44
|
-
.filter(Boolean) // 移除空属性
|
|
45
|
-
.join('\n ');
|
|
46
|
-
|
|
47
|
-
// 仅当有样式属性时,添加到CSS规则
|
|
48
|
-
if (styleProperties) {
|
|
49
|
-
cssRules += `${selector} {\n ${styleProperties}\n}\n\n`;
|
|
50
|
-
}
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
// 应用生成的CSS规则到样式块
|
|
55
|
-
if (cssRules) {
|
|
56
|
-
styleBlock.innerHTML = cssRules;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
// 处理内容配置(支持纯文本/HTML内容,通过isHtml标识)
|
|
60
|
-
if (config.content && typeof config.content === 'object' && Object.keys(config.content).length > 0) {
|
|
61
|
-
Object.entries(config.content).forEach(([selector, content]) => {
|
|
62
|
-
// 过滤无效选择器和内容
|
|
63
|
-
if (!selector || !content || !content.hasOwnProperty('value')) return;
|
|
64
|
-
const elements = document.querySelectorAll(selector);
|
|
65
|
-
elements.forEach(el => {
|
|
66
|
-
if (!el) return;
|
|
67
|
-
// 支持HTML内容或纯文本,默认纯文本
|
|
68
|
-
if (content.isHtml) {
|
|
69
|
-
el.innerHTML = content.value;
|
|
70
|
-
} else {
|
|
71
|
-
el.textContent = content.value;
|
|
72
|
-
}
|
|
73
|
-
});
|
|
74
|
-
});
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
console.log('✅ XiangJsonCraft v1.1.1 渲染成功!');
|
|
78
|
-
})
|
|
79
|
-
.catch(error => {
|
|
80
|
-
console.error('❌ XiangJsonCraft 处理配置时出错:', error.message);
|
|
81
|
-
});
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
export { renderJsonStyles };
|