njk-tool 0.0.5 → 0.0.7

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.
@@ -1,6 +1,5 @@
1
1
  'use strict';
2
2
 
3
- var node_fs = require('node:fs');
4
3
  var require$$0$1 = require('domain');
5
4
  var require$$0$2 = require('events');
6
5
  var require$$0$4 = require('fs');
@@ -12,38 +11,6 @@ var node_path = require('node:path');
12
11
  var node_url = require('node:url');
13
12
 
14
13
  var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
15
- /******************************************************************************
16
- Copyright (c) Microsoft Corporation.
17
-
18
- Permission to use, copy, modify, and/or distribute this software for any
19
- purpose with or without fee is hereby granted.
20
-
21
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
22
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
23
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
24
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
25
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
26
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
27
- PERFORMANCE OF THIS SOFTWARE.
28
- ***************************************************************************** */
29
- /* global Reflect, Promise, SuppressedError, Symbol, Iterator */
30
-
31
-
32
- function __awaiter(thisArg, _arguments, P, generator) {
33
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
34
- return new (P || (P = Promise))(function (resolve, reject) {
35
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
36
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
37
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
38
- step((generator = generator.apply(thisArg, _arguments || [])).next());
39
- });
40
- }
41
-
42
- typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
43
- var e = new Error(message);
44
- return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
45
- };
46
-
47
14
  function getDefaultExportFromCjs (x) {
48
15
  return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
49
16
  }
@@ -13331,43 +13298,631 @@ var TagType;
13331
13298
  TagType["Table"] = "table";
13332
13299
  })(TagType || (TagType = {}));
13333
13300
 
13301
+ const styleText = `
13302
+ <style>
13303
+ /* Components.css */
13304
+
13305
+ /* END-Components.css */
13306
+
13307
+ /* TOC.css */
13308
+ /* 基础样式 */
13309
+ .article-toc {
13310
+ position: fixed;
13311
+ top: 50px;
13312
+ right: 2rem;
13313
+ max-height: calc(100vh - 4rem);
13314
+ margin-left: 2rem;
13315
+ font-size: 0.95rem;
13316
+ }
13317
+
13318
+ /* 隐藏 checkbox */
13319
+ .toc-toggle-checkbox {
13320
+ position: absolute;
13321
+ opacity: 0;
13322
+ height: 0;
13323
+ width: 0;
13324
+ }
13325
+
13326
+ /* 切换按钮样式 */
13327
+ .toc-toggle-label {
13328
+ display: flex;
13329
+ align-items: center;
13330
+ background: #f8f9fa;
13331
+ padding: 0.3rem 0.6rem;
13332
+ border-radius: 4px;
13333
+ cursor: pointer;
13334
+ margin-bottom: 0.5rem;
13335
+ }
13336
+
13337
+ .toc-icon {
13338
+ font-size: 1.2rem;
13339
+ margin-right: 0.3rem;
13340
+ }
13341
+
13342
+ /* 目录导航 */
13343
+ .toc-nav {
13344
+ padding: 0.5rem;
13345
+ background: white;
13346
+ border-radius: 6px;
13347
+ box-shadow: 0 1px 3px rgba(0,0,0,0.1);
13348
+ }
13349
+
13350
+ .toc-section {
13351
+ margin-bottom: 0.8rem;
13352
+ }
13353
+
13354
+ .toc-heading {
13355
+ font-size: 1rem;
13356
+ margin: 0 0 0.4rem 0;
13357
+ padding-bottom: 0.2rem;
13358
+ border-bottom: 1px solid #eee;
13359
+ }
13360
+
13361
+ .toc-list {
13362
+ list-style: none;
13363
+ padding-left: 0.4rem;
13364
+ margin: 0;
13365
+ }
13366
+
13367
+ .toc-item {
13368
+ margin: 0.2rem 0;
13369
+ }
13370
+
13371
+ .toc-link {
13372
+ display: block;
13373
+ padding: 0.2rem 0.4rem;
13374
+ color: #495057;
13375
+ text-decoration: none;
13376
+ border-radius: 3px;
13377
+ transition: all 0.2s;
13378
+ }
13379
+
13380
+ .toc-link:hover {
13381
+ background: #f0f0f0;
13382
+ color: #007bff;
13383
+ }
13384
+
13385
+ /* 层级缩进 */
13386
+ .toc-link[data-level="2"] {
13387
+ padding-left: 0.8rem;
13388
+ }
13389
+
13390
+ .toc-link[data-level="3"] {
13391
+ padding-left: 1.6rem;
13392
+ }
13393
+
13394
+ /* 激活状态 */
13395
+ .toc-link.active {
13396
+ background: #e7f5ff;
13397
+ color: #0066cc;
13398
+ font-weight: 500;
13399
+ }
13400
+
13401
+ /* 折叠功能实现 */
13402
+ .toc-toggle-checkbox:not(:checked) ~ .toc-nav {
13403
+ display: none;
13404
+ }
13405
+
13406
+ /* 响应式设计 */
13407
+ @media (max-width: 768px) {
13408
+ .article-toc {
13409
+ margin-left: 1rem;
13410
+ font-size: 0.9rem;
13411
+ }
13412
+ }
13413
+ /* END-TOC.css */
13414
+
13415
+ /* Text.css */
13416
+
13417
+ /* END-Text.css */
13418
+
13419
+ /* Title.css */
13420
+ .title-base {
13421
+ --align: left;
13422
+ --text-color: black;
13423
+ --font-weight: 800;
13424
+ --font-size: 18px;
13425
+ color: var(--text-color);
13426
+ text-align: var(--align);
13427
+ font-weight: var(--font-weight);
13428
+ font-size: var(--font-size);
13429
+ padding: 8px 30px;
13430
+ }
13431
+
13432
+ h1 {
13433
+ --align: left;
13434
+ --text-color: #606266;
13435
+ --margin: 36px 0 20px;
13436
+ position: relative;
13437
+ font-size: 35.2px;
13438
+ padding: 0 0 4.8px;
13439
+ margin: var(--margin);
13440
+ color: var(--text-color);
13441
+ text-align: var(--align);
13442
+ }
13443
+
13444
+ h2 {
13445
+ --align: left;
13446
+ --text-color: #606266;
13447
+ --margin: 36px 0 20px;
13448
+ position: relative;
13449
+ font-size: 26.4px;
13450
+ padding: 0 0 4.8px;
13451
+ margin: var(--margin);
13452
+ color: var(--text-color);
13453
+ text-align: var(--align);
13454
+ }
13455
+
13456
+ h2::before,
13457
+ h1::before {
13458
+ display: none;
13459
+ position: absolute;
13460
+ content: "#";
13461
+ color: #007bff;
13462
+ }
13463
+
13464
+ h1::before {
13465
+ left: -26px;
13466
+ }
13467
+
13468
+ h2::before {
13469
+ left: -18px;
13470
+ }
13471
+
13472
+ h1:hover::before,
13473
+ h2:hover::before {
13474
+ display: inline-block;
13475
+ }
13476
+
13477
+ .title-main {
13478
+ --align: left;
13479
+ --text-color: black;
13480
+ --font-weight: 800;
13481
+ --font-size: 28px;
13482
+ color: var(--text-color);
13483
+ text-align: var(--align);
13484
+ font-weight: var(--font-weight);
13485
+ font-size: var(--font-size);
13486
+ padding: 8px 30px;
13487
+ margin-bottom: 20px;
13488
+ }
13489
+
13490
+ /* END-Title.css */
13491
+
13492
+ /* Notice.css */
13493
+ /* Notice */
13494
+ .notice {
13495
+ margin: 16px 0;
13496
+ padding: 12px 16px;
13497
+ margin-bottom: 1rem;
13498
+ border-radius: 4px;
13499
+ font-size: 14px;
13500
+ }
13501
+
13502
+ .notice-title {
13503
+ font-weight: bold;
13504
+ margin-bottom: 4px;
13505
+ }
13506
+
13507
+ /* 不同类型的通知样式 */
13508
+ .notice-info {
13509
+ background-color: #e8f4ff;
13510
+ border-left: 4px solid #1890ff;
13511
+ }
13512
+
13513
+ .notice-warning {
13514
+ background-color: #fff7e6;
13515
+ border-left: 4px solid #faad14;
13516
+ }
13517
+
13518
+ .notice-success {
13519
+ background-color: #f6ffed;
13520
+ border-left: 4px solid #52c41a;
13521
+ }
13522
+
13523
+ .notice-error {
13524
+ background-color: #fff2f0;
13525
+ border-left: 4px solid #f5222d;
13526
+ }
13527
+ /* END-Notice.css */
13528
+
13529
+ /* Block.css */
13530
+ /* Block.njk */
13531
+ .code-block {
13532
+ margin: 16px 0;
13533
+ border-radius: 4px;
13534
+ overflow: hidden;
13535
+ box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
13536
+ }
13537
+
13538
+ .code-block pre {
13539
+ margin: 0;
13540
+ padding: 1rem;
13541
+ background-color: #f5f5f5;
13542
+ font-family: 'Courier New', monospace;
13543
+ font-size: 14px;
13544
+ line-height: 1.5;
13545
+ white-space: pre-wrap;
13546
+ }
13547
+
13548
+ .code-block code {
13549
+ display: block;
13550
+ overflow-x: auto;
13551
+
13552
+ }
13553
+ /* END-Block.css */
13554
+
13555
+ /* Table.css */
13556
+ .default-table {
13557
+ margin: 0;
13558
+ width: 80%;
13559
+ border-collapse: collapse;
13560
+ /* 合并边框 */
13561
+ font-family: Arial, Helvetica, sans-serif;
13562
+ font-size: 14px;
13563
+ color: #444444;
13564
+ }
13565
+
13566
+ .thead-light th {
13567
+ background-color: #f5f7fa;
13568
+ color: #333333;
13569
+ font-weight: 600;
13570
+ padding: 12px 16px;
13571
+ text-align: left;
13572
+ border: 1px solid #e1e4e8;
13573
+ font-size: 16px;
13574
+ }
13575
+
13576
+ .default-row {
13577
+ border: 1px solid #eee;
13578
+ background-color: #fff;
13579
+
13580
+ }
13581
+
13582
+ .default-row:hover {
13583
+ background-color: #f0f4f8;
13584
+ color: rebeccapurple;
13585
+ }
13586
+
13587
+ .default-cell {
13588
+ padding: 10px 16px;
13589
+ border: 1px solid #e1e4e8;
13590
+ font-weight: 400;
13591
+ font-size: 14px;
13592
+ color: #444;
13593
+ background-color: transparent;
13594
+ }
13595
+ /* END-Table.css */
13596
+
13597
+ /* Tab.css */
13598
+ /* Tab 容器 */
13599
+ .tab-container {
13600
+ max-width: 600px;
13601
+ margin: 0 auto;
13602
+ }
13603
+
13604
+ /* 隐藏 Radio 按钮 */
13605
+ .tab-radio {
13606
+ display: none;
13607
+ }
13608
+
13609
+ /* Tab 按钮样式 */
13610
+ .tab-labels {
13611
+ display: flex;
13612
+ border-bottom: 1px solid #ccc;
13613
+ }
13614
+
13615
+ .tab-label {
13616
+ padding: 5px 10px;
13617
+ cursor: pointer;
13618
+ background-color: #f1f1f1;
13619
+ border: 1px solid #ccc;
13620
+ border-bottom: none;
13621
+ margin-right: 2px;
13622
+ border-radius: 5px 5px 0 0;
13623
+ }
13624
+
13625
+ .tab-label:hover {
13626
+ background-color: #ddd;
13627
+ }
13628
+
13629
+ .tab-radio:checked+.tab-label {
13630
+ background-color: #fff;
13631
+ border-bottom: 1px solid #fff;
13632
+ margin-bottom: -1px;
13633
+ }
13634
+
13635
+ /* Tab 内容区域 */
13636
+ .tab-content {
13637
+ display: none;
13638
+ padding: 20px;
13639
+ border: 1px solid #ccc;
13640
+ border-top: none;
13641
+ }
13642
+ /* END-Tab.css */
13643
+
13644
+ /* Base.css */
13645
+ body {
13646
+ margin: 0;
13647
+ padding: 50px;
13648
+ }
13649
+ /* END-Base.css */
13650
+ </style>
13651
+ `;
13652
+
13653
+ const templateText = `
13654
+ <!-- Head.njk -->
13655
+ {% macro use_head(ctx) %}
13656
+ <head>
13657
+ <meta charset="UTF-8" />
13658
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
13659
+ <title>{{ ctx.title }}</title>
13660
+ {% if ctx.jsFiles%}
13661
+ {% for css in ctx.cssFiles %}
13662
+ <link rel="stylesheet" href="{{ css }}" />
13663
+ {% endfor %}
13664
+ {% endif %}
13665
+ </head>
13666
+ {% if ctx.jsFiles%}
13667
+ {% for js in ctx.jsFiles %}
13668
+ <script src="{{ js }}"></script>
13669
+ {% endfor %}
13670
+ {% endif %}
13671
+ {% endmacro %}
13672
+ <!-- /Head.njk -->
13673
+
13674
+ <!-- TOC.njk -->
13675
+ {% macro use_toc(ctx) %}
13676
+ <div class="article-toc">
13677
+ <input type="checkbox" id="toc-toggle" class="toc-toggle-checkbox">
13678
+ <label for="toc-toggle" class="toc-toggle-label">
13679
+ <span class="toc-icon">≡</span>
13680
+ <span class="toc-text">目录</span>
13681
+ </label>
13682
+
13683
+ <nav class="toc-nav">
13684
+ {% for section in ctx.data %}
13685
+ <section class="toc-section">
13686
+ {% if section.link %}
13687
+ <h3 class="toc-heading">
13688
+ <a href="{{ section.link }}" class="toc-link">{{ section.text }}</a>
13689
+ </h3>
13690
+ {% else%}
13691
+ <h3 class="toc-heading">{{ section.text }}</h3>
13692
+ {% endif %}
13693
+ <ul class="toc-list">
13694
+ {% for item in section.items %}
13695
+ <li class="toc-item">
13696
+ <a href="{{ item.link }}" class="toc-link" data-level="{{ loop.depth }}">
13697
+ {% if loop.depth > 1 %}•{% endif %}
13698
+ {{ item.text }}
13699
+ </a>
13700
+ </li>
13701
+ {% endfor %}
13702
+ </ul>
13703
+ </section>
13704
+ {% endfor %}
13705
+ </nav>
13706
+ </div>
13707
+ {% endmacro %}
13708
+ <!-- /TOC.njk -->
13709
+
13710
+ <!-- Title.njk -->
13711
+ {% macro title_default(ctx) %}
13712
+ <h1 style="text-align: center">{{ ctx.text }}</h1>
13713
+ {% endmacro %}
13714
+ {% macro title_h1(ctx) %}
13715
+ <h1 id="{{ ctx.text }}" class="title-color" style="{{ ctx.style }}">
13716
+ {{ ctx.text }}
13717
+ </h1>
13718
+ {% endmacro %}
13719
+ {% macro title_h2(ctx) %}
13720
+ <h2 id="{{ ctx.text }}" class="title-color" style="{{ ctx.style }}">
13721
+ {{ ctx.text }}
13722
+ </h2>
13723
+ {% endmacro %}
13724
+ {% macro title_h3(ctx) %}
13725
+ <h3 id="{{ ctx.text }}" class="title-color" style="{{ ctx.style }}">
13726
+ {{ ctx.text }}
13727
+ </h3>
13728
+ {% endmacro %}
13729
+ {% macro title_table_default(ctx) %}
13730
+ <h3 id="{{ ctx.text }}" class="title_table_default" style="{{ ctx.style }}">
13731
+ {{ ctx.text }}
13732
+ </h3>
13733
+ {% endmacro %}
13734
+ {% macro use_title(ctx) %}
13735
+ {% if ctx.type == "h1" %}
13736
+ {{ title_h1(ctx) }}
13737
+ {% elif ctx.type == "h2" %}
13738
+ {{ title_h2(ctx) }}
13739
+ {% elif ctx.type == "h3" %}
13740
+ {{ title_h3(ctx) }}
13741
+ {% else %}
13742
+ {{ title_default(ctx) }}
13743
+ {% endif %}
13744
+ {% endmacro %}
13745
+ <!-- /Title.njk -->
13746
+
13747
+ <!-- Notice.njk -->
13748
+ {% macro use_notice(ctx) %}
13749
+ {% if ctx.type %}
13750
+ {% set type = ctx.type %}
13751
+ {% else %}
13752
+ {% set type = "info" %}
13753
+ {% endif %}
13754
+ <div class="notice notice-{{ type }}">
13755
+ <div class="notice-title">{{ type|capitalize }}:</div>
13756
+ <pre class="notice-content">{{ ctx.text }}</pre>
13757
+ </div>
13758
+ {% endmacro %}
13759
+ <!-- /Notice.njk -->
13760
+
13761
+ <!-- Block.njk -->
13762
+ {% macro use_block(ctx) %}
13763
+ <div class="code-block">
13764
+ <pre><code>{{ ctx.text }}</code></pre>
13765
+ </div>
13766
+ {% endmacro %}
13767
+ <!-- /Block.njk -->
13768
+
13769
+ <!-- Date.njk -->
13770
+ {% macro use_date(ctx) %}
13771
+ <div>Date:{{ ctx.text}}</div>
13772
+ {% endmacro %}
13773
+ {% macro use_checker(ctx) %}
13774
+ <div>Checker:{{ ctx.text}}</div>
13775
+ {% endmacro %}
13776
+ <!-- /Date.njk -->
13777
+
13778
+ <!-- Table.njk -->
13779
+ {% macro table_default(ctx) %}
13780
+ {% if ctx.columns %}
13781
+ {% set columns = ctx.columns %}
13782
+ {% elif ctx.th %}
13783
+ {% set columns = ctx.th %}
13784
+ {% else %}
13785
+ {% set columns = [] %}
13786
+ {% endif %}
13787
+ {% if ctx.data %}
13788
+ {% set data = ctx.data %}
13789
+ {% elif ctx.tbody %}
13790
+ {% set data = ctx.tbody %}
13791
+ {% endif %}
13792
+ {% if ctx.title %}
13793
+ {% set title = {text:ctx.title} %}
13794
+ {{ title_h2(title) }}
13795
+ {% endif %}
13796
+ <table class="default-table">
13797
+ <thead class="thead-light">
13798
+ <tr>
13799
+ {% for column in columns %}
13800
+ <th>{{ column }}</th>
13801
+ {% endfor %}
13802
+ </tr>
13803
+ </thead>
13804
+ <tbody>
13805
+ {% for row in data %}
13806
+ <tr class="default-row">
13807
+ {% if ctx.data %}
13808
+ {% for column in columns %}
13809
+ <td class="default-cell">{{ row[column] | replace("false", "❌") | replace("true", "✔️") }}</td>
13810
+ {% endfor %}
13811
+ {% else %}
13812
+ {% for value in row %}
13813
+ <td class="default-cell">{{ value | replace("false", "❌") | replace("true", "✔️") }}</td>
13814
+ {% endfor %}
13815
+ {% endif %}
13816
+ </tr>
13817
+ {% endfor %}
13818
+ </tbody>
13819
+ </table>
13820
+ {% endmacro %}
13821
+ {% macro use_table(ctx) %}
13822
+ {% if ctx.type == "h1" %}
13823
+ {{ title_h1(ctx) }}
13824
+ {% else %}
13825
+ {{ table_default(ctx) }}
13826
+ {% endif %}
13827
+ {% endmacro %}
13828
+ <!-- /Table.njk -->
13829
+
13830
+ <!-- Tab.njk -->
13831
+ {% macro useTab(tabs) %}
13832
+ <style>
13833
+ /* 显示选中的 Tab 内容 */
13834
+ {% for tab in tabs %}
13835
+ #{{tab.id}}:checked~#{{tab.content_id}} {
13836
+ display: block;
13837
+ }
13838
+ {% endfor %}
13839
+ </style>
13840
+ <div class="tab-container">
13841
+ {% for tab in tabs %}
13842
+ <!-- Radio 按钮(隐藏) -->
13843
+ <input {% if loop.first %} checked {% endif %} type="radio" name="tabs" id="{{ tab.id }}" class="tab-radio">
13844
+ {% endfor %}
13845
+ <!-- Tab 按钮(用 label 包裹) -->
13846
+ <div class="tab-labels">
13847
+ {% for tab in tabs %}
13848
+ <label for="{{ tab.id }}" class="tab-label">{{ tab.title }}
13849
+ </label>
13850
+ {% endfor %}
13851
+ </div>
13852
+ <!-- Tab 内容 -->
13853
+ {% for tab in tabs %}
13854
+ <div id="{{ tab.content_id }}" class="tab-content">
13855
+ {{ tab.content }}
13856
+ </div>
13857
+ {% endfor %}
13858
+ </div>
13859
+ {% endmacro %}
13860
+ <!-- /Tab.njk -->
13861
+
13862
+ <!-- Component.njk -->
13863
+ {% macro pick_component(ctx) %}
13864
+ {% if ctx.tag == "head" %}
13865
+ {{ use_head(ctx) }}
13866
+ {% elif ctx.tag == "text" %}
13867
+ {{ use_text(ctx) }}
13868
+ {% elif ctx.tag == "title" %}
13869
+ {{ use_title(ctx) }}
13870
+ {% elif ctx.tag == "table" %}
13871
+ {{ use_table(ctx) }}
13872
+ {% elif ctx.tag == "toc" %}
13873
+ {{ use_toc(ctx) }}
13874
+ {% elif ctx.tag == "notice" %}
13875
+ {{ use_notice(ctx) }}
13876
+ {% elif ctx.tag == "block" %}
13877
+ {{ use_block(ctx) }}
13878
+ {% elif ctx.tag == "date" %}
13879
+ {{ use_date(ctx) }}
13880
+ {% elif ctx.tag == "checker" %}
13881
+ {{ use_checker(ctx) }}
13882
+ {% else %}
13883
+ {{ title_default(ctx) }}
13884
+ {% endif %}
13885
+ {% endmacro %}
13886
+ {% macro use_component(ctx) %}
13887
+ {% if ctx.tag %}
13888
+ {{ pick_component(ctx) }}
13889
+ {% else %}
13890
+ {% for i in ctx %}
13891
+ {{ pick_component(i) }}
13892
+ {% endfor %}
13893
+ {% endif %}
13894
+ {% endmacro %}
13895
+
13896
+ {{ use_component(ctx) }}
13897
+ <!-- /Component.njk -->
13898
+
13899
+ <!-- Text.njk -->
13900
+ {% macro text_default(ctx) %}
13901
+ {{ ctx.text | replace("false", "❌") | replace("true", "✔️") }}
13902
+ {% endmacro %}
13903
+
13904
+ {% macro bool_text(ctx) %}
13905
+ {{ ctx.text | replace("false", "❌") | replace("true", "✔️") }}
13906
+ {% endmacro %}
13907
+
13908
+ {% macro use_text(ctx) %}
13909
+ {% if ctx.type == "h1" %}
13910
+ {{ title_h1(ctx) }}
13911
+ {% else %}
13912
+ {{ text_default(ctx) }}
13913
+ {% endif %}
13914
+ {% endmacro %}
13915
+ <!-- /Text.njk -->
13916
+
13917
+ `;
13918
+
13334
13919
  const externalTemplatesDir = node_url.fileURLToPath(new URL("../bundle/src", `${(typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('app.min.cjs', document.baseURI).href))}`));
13335
13920
  nunjucks.configure(externalTemplatesDir, {
13336
13921
  autoescape: true,
13337
13922
  noCache: true
13338
13923
  });
13339
- const BASE_STYLE_PATH = node_path.join(externalTemplatesDir, "base.style");
13924
+ node_path.join(externalTemplatesDir, "base.style");
13340
13925
  const TEMPLATES_DIR = node_path.join(externalTemplatesDir, "index.html");
13341
- console.log({ externalTemplatesDir });
13342
- console.log({ BASE_STYLE_PATH });
13343
- console.log({ TEMPLATES_DIR });
13344
- const loadStyle = (basePath) => __awaiter(void 0, void 0, void 0, function* () {
13345
- try {
13346
- return yield import('fs/promises').then(({ readFile }) => readFile(basePath, "utf8"));
13347
- }
13348
- catch (error) {
13349
- console.error(`[样式加载失败] ${basePath}:`, error);
13350
- return "";
13351
- }
13352
- });
13353
- // 同步版本(保留备用)
13354
- const loadStyleSync = (basePath) => {
13355
- try {
13356
- return node_fs.readFileSync(basePath, "utf8");
13357
- }
13358
- catch (error) {
13359
- console.error(`[样式加载失败] ${basePath}:`, error);
13360
- return "";
13361
- }
13362
- };
13363
- // 样式处理优化
13364
- const getStyleContent = ({ isAsync = false, basePath = BASE_STYLE_PATH, } = {}) => isAsync ? loadStyle(basePath) : Promise.resolve(loadStyleSync(basePath));
13365
- // 配置验证函数
13366
- const validateConfig = (config) => {
13367
- if (!Array.isArray(config) && !("tag" in config)) {
13368
- throw new Error("无效的配置结构:必须为ConfItem数组或单个ConfItem对象");
13369
- }
13370
- };
13371
13926
  // 样式注入逻辑优化
13372
13927
  const processConfig = (config, cssUrls) => {
13373
13928
  const headConf = {
@@ -13379,41 +13934,40 @@ const processConfig = (config, cssUrls) => {
13379
13934
  : [headConf, config];
13380
13935
  };
13381
13936
  // 主渲染函数
13382
- const njkRender = (config_1, ...args_1) => __awaiter(void 0, [config_1, ...args_1], void 0, function* (config, options = {}) {
13383
- const { cssUrl, templateDir = TEMPLATES_DIR } = options;
13384
- // 配置验证
13385
- validateConfig(config);
13386
- // 处理配置
13387
- const processedConfig = Array.isArray(config)
13388
- ? processConfig(config, cssUrl)
13389
- : processConfig([config], cssUrl);
13390
- // 动态配置nunjucks
13391
- nunjucks.configure(templateDir, {
13392
- autoescape: true,
13393
- noCache: process.env.NODE_ENV !== "production" // 生产环境启用缓存
13394
- });
13395
- // 异步加载样式
13396
- const styleContent = yield getStyleContent();
13397
- return nunjucks.render("index.html", {
13398
- ctx: processedConfig,
13399
- style: styleContent || ""
13400
- });
13401
- });
13937
+ // export const njkRender = async (
13938
+ // config: ConfItem | ConfItem[],
13939
+ // options: Options = {}
13940
+ // ): Promise<string> => {
13941
+ // const { cssUrl, templateDir = TEMPLATES_DIR } = options;
13942
+ // // 配置验证
13943
+ // validateConfig(config);
13944
+ // // 处理配置
13945
+ // const processedConfig = Array.isArray(config)
13946
+ // ? processConfig(config, cssUrl as string[])
13947
+ // : processConfig([config], cssUrl as string[]);
13948
+ // // 动态配置nunjucks
13949
+ // nunjucks.configure(templateDir, {
13950
+ // autoescape: true,
13951
+ // noCache: process.env.NODE_ENV !== "production" // 生产环境启用缓存
13952
+ // });
13953
+ // // 异步加载样式
13954
+ // const styleContent = await getStyleContent();
13955
+ // return nunjucks.render("index.html", {
13956
+ // ctx: processedConfig,
13957
+ // style: styleContent || ""
13958
+ // });
13959
+ // };
13402
13960
  // 同步版本(保留备用)
13403
13961
  const njkRenderSync = (config, options = {}) => {
13404
- console.log({ externalTemplatesDir });
13405
- console.log({ BASE_STYLE_PATH });
13406
- console.log({ TEMPLATES_DIR });
13407
13962
  const { cssUrl, templateDir = TEMPLATES_DIR } = options;
13408
13963
  const processedConfig = Array.isArray(config)
13409
13964
  ? processConfig(config, cssUrl)
13410
13965
  : processConfig([config], cssUrl);
13411
- const html = nunjucks.render('index.html', {
13966
+ const html = nunjucks.renderString(templateText, {
13412
13967
  ctx: processedConfig,
13413
13968
  });
13414
- return getStyleContent({ isAsync: true }) + html;
13969
+ return styleText + html;
13415
13970
  };
13416
13971
 
13417
- exports.njkRender = njkRender;
13418
13972
  exports.njkRenderSync = njkRenderSync;
13419
13973
  //# sourceMappingURL=app.min.cjs.map