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