@flun/html-template 4.0.10

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.
Files changed (59) hide show
  1. package/.env +9 -0
  2. package/LICENSE +15 -0
  3. package/build.js +3 -0
  4. package/compile.js +349 -0
  5. package/copy-files.js +200 -0
  6. package/customize/account.js +726 -0
  7. package/customize/data.json +484 -0
  8. package/customize/functions.js +48 -0
  9. package/customize/hotReloadInjector.js +25 -0
  10. package/customize/routes.js +141 -0
  11. package/customize/users.json +44 -0
  12. package/customize/variables.js +70 -0
  13. package/dev-server.js +344 -0
  14. package/dev.js +4 -0
  15. package/f-CHANGELOG.md +4 -0
  16. package/f-README.md +485 -0
  17. package/index.d.ts +133 -0
  18. package/index.js +4 -0
  19. package/package.json +77 -0
  20. package/restoreDefaults.js +8 -0
  21. package/services/templateService.js +962 -0
  22. package/static/about.css +118 -0
  23. package/static/auth.js +27 -0
  24. package/static/constants.css +138 -0
  25. package/static/img/dark.png +0 -0
  26. package/static/img/favicon.ico +0 -0
  27. package/static/img/light.png +0 -0
  28. package/static/img/top.png +0 -0
  29. package/static/index.css +86 -0
  30. package/static/mouseOrTouch.js +156 -0
  31. package/static/public.css +288 -0
  32. package/static/script.css +318 -0
  33. package/static/script.js +392 -0
  34. package/static/styling.css +874 -0
  35. package/static/styling.js +933 -0
  36. package/static/themeImg.css +10 -0
  37. package/static/themeImg.js +19 -0
  38. package/static/themeModule.js +222 -0
  39. package/static/topImg.css +19 -0
  40. package/static/topImg.js +21 -0
  41. package/static/utils/browser13.js +270 -0
  42. package/static/utils/closebrackets.js +166 -0
  43. package/static/utils/css-lint.js +308 -0
  44. package/static/utils/custom-css-hint.js +876 -0
  45. package/static/utils/foldgutter.js +141 -0
  46. package/static/utils/match-highlighter.js +70 -0
  47. package/templates/about.html +236 -0
  48. package/templates/account/2fa.html +184 -0
  49. package/templates/account/forgot-password.html +226 -0
  50. package/templates/account/login.html +230 -0
  51. package/templates/account/profile.html +977 -0
  52. package/templates/account/register.html +224 -0
  53. package/templates/account/reset-password.html +205 -0
  54. package/templates/account/verify-email.html +163 -0
  55. package/templates/base.html +71 -0
  56. package/templates/footer-content.html +5 -0
  57. package/templates/index.html +140 -0
  58. package/templates/script.html +209 -0
  59. package/templates/test-include.html +11 -0
@@ -0,0 +1,140 @@
1
+ [extends base.html] <!-- 继承基础模板 -->
2
+
3
+ [!keywords]"关键字测试"[~keywords]
4
+ [!description]"测试网站"[~description]
5
+ <!-- 这里故意不引入模板标签,是因为不引入代表默认继承 -->
6
+ <!-- 只要引入就会替换基础模板对应标签内容 -->
7
+ [!title]首页 - 模板功能测试[~title]
8
+
9
+ [!style]
10
+ <link rel="stylesheet" href="/static/styling.css">
11
+ <link rel="stylesheet" href="/static/index.css">
12
+ [~style]
13
+
14
+ [!header]<a href="about.html" class="home-link">跳转到关于我们</a>[~header]
15
+
16
+ [!content]
17
+ [!test]<h1>欢迎来到首页 - 模板功能测试</h1>[~test]
18
+ <div class="ind_content_main">
19
+ <h2>主内容区</h2>
20
+ <p><a href="about.html">了解更多 →</a></p>
21
+ </div>
22
+
23
+ <!-- 模板功能测试区域 -->
24
+ <div class="template-test">
25
+ <h3>模板功能测试</h3>
26
+
27
+ <div class="test-result">
28
+ <h4>1. 模板继承与区块替换测试</h4>
29
+ <p>状态: <span style="color: green;">✓ 成功</span></p>
30
+ <p>此页面通过 <code>"[extends base.html]"</code> 正确继承了基础模板</p>
31
+ </div>
32
+
33
+ <div class="test-result">
34
+ <h4>2. 变量替换测试</h4>
35
+ <p>当前路径: {{currentUrl}}</p>
36
+ <p>状态: <span style="color: green;">✓ 成功</span></p>
37
+ </div>
38
+ </div>
39
+
40
+ <!-- 用户自定义功能测试区域 -->
41
+ <div class="user-function-test">
42
+ <h3>用户自定义功能测试</h3>
43
+
44
+ <div class="test-result">
45
+ <h4>1. 实用函数测试</h4>
46
+ <p>加法测试: 10 + 5 = {{user:functions.add(10, 5)}}</p>
47
+ <p>乘法测试: 7 × 3 = {{user:functions.multiply(7, 3)}}</p>
48
+ <p>格式化日期测试: {{user:functions.formatDate()}}</p>
49
+ <p>状态: <span style="color: green;">✓ 成功</span></p>
50
+ </div>
51
+
52
+ <div class="test-result">
53
+ <h4>2. 路由函数测试</h4>
54
+ <p>简单问候: {{user:functions.greet('访客')}}</p>
55
+ <p>带时间问候: {{user:functions.greetWithTime('用户')}}</p>
56
+ <p>年份变量加10: {{user:functions.add({{year}}, 10)}}</p>
57
+ <p>状态: <span style="color: green;">✓ 成功</span></p>
58
+ </div>
59
+ </div>
60
+
61
+ <!-- 路由功能测试区域 -->
62
+ <div class="route-test">
63
+ <h3>用户自定义路由测试</h3>
64
+
65
+ <div class="test-result">
66
+ <h4>1. GET路由测试</h4>
67
+ <button class="test-button" type="button" onclick="testRoute('/api/greeting')">测试问候路由</button>
68
+ <button class="test-button" type="button" onclick="testRoute('/api/hi/小明')">测试用户路由</button>
69
+ <div id="get-result" class="api-result">点击按钮测试路由...</div>
70
+ </div>
71
+
72
+ <div class="test-result">
73
+ <h4>2. POST路由测试</h4>
74
+ <button class="test-button" type="button" onclick="testPostRoute()">测试联系表单路由</button>
75
+ <div id="post-result" class="api-result">点击按钮测试POST路由...</div>
76
+ </div>
77
+ </div>
78
+ [~content]
79
+
80
+ [!footer]
81
+ © {{year}} 我的网站 | 首页 | 模板测试
82
+ [~footer]
83
+
84
+ [!script]
85
+ <script src="/static/styling.js" defer></script>
86
+ <script>
87
+ // 获取当前样式文件路径
88
+ window.getCurrentStyleFile = () => {
89
+ return '/static/index.css';
90
+ }
91
+ // 首页特定的模板测试脚本
92
+ console.log('首页模板测试完成');
93
+
94
+ // 用户功能测试脚本
95
+ console.log('用户功能测试:');
96
+ // 注意函数和变量标签结果非字符串的,在js中如果单独存在,需要使用反引号包裹,目的不被格式化并能高亮辨识
97
+ console.log('加法结果:', `{{user:functions.add(10, 5)}}`);
98
+ // 字符串型结果需引号包裹,并拼接引号,因为解析时会去掉外层引号,内部添加引号目的是保持高亮和不被解析为数学表达式
99
+ console.log('格式化日期:', '"' + '{{user:functions.formatDate()}}' + '"');
100
+ // 如果你习惯不高亮,可以直接这样写
101
+ console.log('格式化日期:', '{{user:functions.formatDate()}}');
102
+
103
+ // 路由测试函数
104
+ async function testRoute(url) {
105
+ try {
106
+ document.getElementById('get-result').innerHTML = '请求中...';
107
+ const response = await fetch(url), data = await response.json();
108
+ document.getElementById('get-result').innerHTML = JSON.stringify(data, null, 2);
109
+ } catch (error) {
110
+ document.getElementById('get-result').innerHTML = `错误: ${error.message}`;
111
+ }
112
+ }
113
+
114
+ async function testPostRoute() {
115
+ try {
116
+ document.getElementById('post-result').innerHTML = '请求中...';
117
+ const response = await fetch('/api/contact', {
118
+ method: 'POST',
119
+ headers: {
120
+ 'Content-Type': 'application/json'
121
+ },
122
+ body: JSON.stringify({
123
+ name: '测试用户',
124
+ email: 'test@index.com',
125
+ message: '这是一个测试消息'
126
+ })
127
+ }), data = await response.json();
128
+ document.getElementById('post-result').innerHTML = JSON.stringify(data, null, 2);
129
+ } catch (error) {
130
+ document.getElementById('post-result').innerHTML = `错误: ${error.message}`;
131
+ }
132
+ }
133
+
134
+ // 页面加载时测试一个简单路由
135
+ window.addEventListener('load', () => {
136
+ testRoute('/api/greeting').catch(console.error);
137
+ });
138
+
139
+ </script>
140
+ [~script]
@@ -0,0 +1,209 @@
1
+ [extends base.html]
2
+
3
+ [!title]html样式编辑器[~title]
4
+ [!style]
5
+ <link rel="stylesheet" href="/static/script.css">
6
+ <!-- CodeMirror 核心库与主题 -->
7
+ <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/codemirror/6.65.7/codemirror.min.css">
8
+ <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/codemirror/6.65.7/theme/dracula.min.css">
9
+ <!-- 折叠、lint、自动补全样式 -->
10
+ <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/codemirror/6.65.7/addon/fold/foldgutter.min.css">
11
+ <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/codemirror/6.65.7/addon/lint/lint.min.css">
12
+ <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/codemirror/6.65.7/addon/hint/show-hint.min.css">
13
+ [~style]
14
+
15
+ [!my] [~my]
16
+ [!header][~header]
17
+ [!content]
18
+ <!-- CSS编辑器模态框 <label for="code">代码编辑区:</label> -->
19
+ <div class="modal">
20
+ <div id="cssEditor">
21
+ <div class="header">
22
+ <h2>编辑CSS样式</h2>
23
+ <span class="close-btn">&times;</span>
24
+ </div>
25
+ <h3 class="editor-info">
26
+ ⚡ 编辑器功能: 颜色选择 · 编辑 · 自动补全 · 代码折叠 · 预览 · 保存应用· 取消
27
+ </h3>
28
+ <textarea id="cssContent" placeholder="CSS内容将在这里显示..." spellcheck="false"></textarea>
29
+ <div class="actions">
30
+ <button id="previewBtn" type="button">预览</button>
31
+ <button id="cancelPreviewBtn" type="button">取消预览</button>
32
+ <button id="saveBtn" type="button">保存并应用</button>
33
+ <button id="cancelBtn" type="button">取消</button>
34
+ </div>
35
+ </div>
36
+ </div>
37
+
38
+ <!-- 预览容器 -->
39
+ <div id="preview" class="preview-container">
40
+ <iframe id="previewFrame" title="预览页面"></iframe>
41
+ </div>
42
+
43
+ <!-- 加载指示器 -->
44
+ <div id="loader" class="loader">
45
+ <p>加载中...</p>
46
+ </div>
47
+ [~content]
48
+
49
+ [!variables] [~variables]
50
+ [!footer]
51
+ © {{year}} 我的网站 | 编辑器页 | 样式编辑器
52
+ [~footer]
53
+
54
+ [!script]
55
+ <!-- CodeMirror JS 与 CSS 模式 -->
56
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/6.65.7/codemirror.min.js"></script>
57
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/6.65.7/mode/css/css.min.js"></script>
58
+
59
+ <!-- 折叠功能 -->
60
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/6.65.7/addon/fold/foldcode.min.js"></script>
61
+ <script src="/static/utils/foldgutter.js"></script>
62
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/6.65.7/addon/fold/brace-fold.min.js"></script>
63
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/6.65.7/addon/fold/comment-fold.min.js"></script>
64
+
65
+ <!-- 语法检查依赖:CodeMirror lint 核心 + CSSTree -->
66
+ <script src="/static/utils/css-lint.js"></script>
67
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/6.65.7/addon/lint/lint.min.js"></script>
68
+ <script src="https://cdn.jsdelivr.net/npm/css-tree@3.1.0/dist/csstree.min.js"></script>
69
+
70
+ <!-- 自动补全 -->
71
+ <script src="/static/utils/closebrackets.js"></script>
72
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/6.65.7/addon/edit/matchbrackets.min.js"></script>
73
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/6.65.7/addon/hint/show-hint.min.js"></script>
74
+ <script src="/static/utils/custom-css-hint.js"></script>
75
+
76
+ <!-- 高亮匹配选中词、活动行 -->
77
+ <script src="/static/utils/match-highlighter.js"></script>
78
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/6.65.7/addon/selection/active-line.min.js"></script>
79
+
80
+ <!-- 库插件样式自定义 -->
81
+ <style>
82
+ /* 增大折叠按钮 */
83
+ #cssEditor .CodeMirror .CodeMirror-foldgutter-open,
84
+ #cssEditor .CodeMirror .CodeMirror-foldgutter-folded,
85
+ #cssEditor .CodeMirror .CodeMirror-foldgutter-open::after,
86
+ #cssEditor .CodeMirror .CodeMirror-foldgutter-folded::after {
87
+ font-size: 25px;
88
+ }
89
+
90
+ /* 增加折叠 gutter 的宽度,避免按钮显示不全 */
91
+ #cssEditor .CodeMirror .CodeMirror-foldgutter {
92
+ width: 26px;
93
+ }
94
+
95
+ /* 强制 tooltip 显示的样式 */
96
+ .CodeMirror-lint-tooltip {
97
+ z-index: 10000;
98
+ background-color: #ffd;
99
+ border: 1px solid #000;
100
+ color: #000;
101
+ font-family: monospace;
102
+ font-size: 12px;
103
+ padding: 6px 10px;
104
+ max-width: 600px;
105
+ word-wrap: break-word;
106
+ white-space: pre-wrap;
107
+ line-height: 1.5;
108
+ transition: none;
109
+ }
110
+
111
+ /* 自动补全列表样式 */
112
+ .CodeMirror-hints {
113
+ background-color: #282a36;
114
+ border: 1px solid #6272a4;
115
+ border-radius: 4px;
116
+ box-shadow: 0 4px 10px rgba(0, 0, 0, 0.5);
117
+ font-family: 'Consolas', 'Monaco', monospace;
118
+ font-size: 13px;
119
+ max-height: 250px;
120
+ overflow-y: auto;
121
+ z-index: 10000;
122
+ }
123
+
124
+ .CodeMirror-hint {
125
+ color: #f8f8f2;
126
+ padding: 4px 8px;
127
+ cursor: pointer;
128
+ white-space: pre;
129
+ border-bottom: 1px solid #44475a;
130
+ }
131
+
132
+ .CodeMirror-hint-active {
133
+ background-color: #44475a;
134
+ color: #50fa7b;
135
+ }
136
+
137
+ .CodeMirror-hint:hover {
138
+ background-color: #6272a4;
139
+ color: #f8f8f2;
140
+ }
141
+
142
+ /* 匹配括号高亮 */
143
+ .CodeMirror-matchingbracket {
144
+ background-color: rgba(124, 136, 126, 1) !important;
145
+ font-weight: bold;
146
+ text-decoration: none !important;
147
+ }
148
+
149
+ /* 自定义高亮 */
150
+ .custom-highlight {
151
+ background-color: rgba(255, 255, 0, 0.3) !important;
152
+ }
153
+ </style>
154
+
155
+ <script>
156
+ // 等待 DOM 加载完成后初始化编辑器
157
+ (function () {
158
+ function initEditor() {
159
+ const textarea = document.getElementById('cssContent');
160
+ if (!textarea) return;
161
+
162
+ window.cssEditor = CodeMirror.fromTextArea(textarea, {
163
+ lineNumbers: true,
164
+ mode: 'css',
165
+ theme: 'dracula',
166
+ lineWrapping: true,
167
+ indentUnit: 4,
168
+ autoCloseBrackets: true,
169
+ matchBrackets: true,
170
+ foldGutter: true,
171
+ gutters: ["CodeMirror-linenumbers", "CodeMirror-foldgutter", "CodeMirror-lint-markers"],
172
+ lint: {
173
+ getAnnotations: window.customCssLint,
174
+ async: true
175
+ },
176
+ styleActiveLine: true,
177
+ hintOptions: {
178
+ completeSingle: false, // 即使只有一个匹配也显示列表
179
+ closeOnUnfocus: false
180
+ }
181
+ });
182
+
183
+ window.cssEditor.setSize('100%', '100%');
184
+
185
+ // ----- 输入时自动弹出补全 -----
186
+ window.cssEditor.on("inputRead", (cm, change) => {
187
+ // 如果输入内容包含冒号,立即触发补全(优先响应)
188
+ if (change.text.join('').includes(':')) {
189
+ clearTimeout(cm.autocompletionTimeout);
190
+ cm.autocompletionTimeout = setTimeout(() => cm.showHint({ completeSingle: false }), 0);
191
+ return;
192
+ }
193
+ // 其他输入(字母、数字、删除等)延迟触发
194
+ clearTimeout(cm.autocompletionTimeout);
195
+ cm.autocompletionTimeout = setTimeout(() => cm.showHint({ completeSingle: false }), 150);
196
+ });
197
+
198
+ attachCustomHighlight(window.cssEditor); // 高亮匹配选中词(自定义)
199
+ setTimeout(() => window.cssEditor.performLint(), 100);
200
+ }
201
+
202
+ if (document.readyState === 'loading') document.addEventListener('DOMContentLoaded', initEditor);
203
+ else initEditor();
204
+ })();
205
+ </script>
206
+
207
+ <!-- 本地文件 -->
208
+ <script src="/static/script.js"></script>
209
+ [~script]
@@ -0,0 +1,11 @@
1
+ <div style="background: #a89148; padding: 15px; border-radius: 4px; border: 1px solid #ffeaa7; margin: 10px 0;">
2
+ <h4 style="margin-top: 0; color: #043885;">包含文件测试成功!</h4>
3
+ <p>这个内容来自 <strong>"test-include.html"</strong> 文件</p>
4
+ <p>当前年份: {{year}}</p>
5
+ <p>页面URL: {{currentUrl}}</p>
6
+ <p>生成时间戳: {{timestamp}}</p>
7
+
8
+ <div style="margin-top: 10px; padding: 8px; background: #0f7934; border-radius: 3px;">
9
+ <small>注意: 如果这个框显示为深绿色背景,说明包含功能正常工作!</small>
10
+ </div>
11
+ </div>