@playcraft/devkit 1.0.22 → 1.0.23

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.
@@ -64,9 +64,13 @@ const linkRegex=/<link\s+[^>]*?\/?>/gi;while((match=linkRegex.exec(headHtml))!==
64
64
  * @param {string} headContent - 从原始 HTML 提取的 head 内容
65
65
  * @returns {Promise<string>} 完整的自解压 HTML
66
66
  */async generateDecompressHtml(compressedBase64,fflateLibCode,headContent=""){// 可读的解压代码(保持格式以便维护)
67
- const decompressCodeReadable=`
67
+ // hasHeadContent: 标记 extractHeadContent 是否从原始 HTML 提取了外部资源引用
68
+ // - true: 原始 HTML 有 <head>,外部资源已提取到模板 head,避免解压时重复
69
+ // - false: 原始 HTML 是片段(如 Adikteev),外部资源在压缩数据中,需要完整恢复
70
+ const hasHeadContent=headContent.length>0;const decompressCodeReadable=`
68
71
  (function() {
69
72
  var compressedData = '${compressedBase64}';
73
+ var __hasHeadContent = ${hasHeadContent};
70
74
 
71
75
  try {
72
76
  // Base64 解码为 Uint8Array
@@ -85,20 +89,39 @@ const decompressCodeReadable=`
85
89
  // 替换 body
86
90
  document.body.replaceWith(doc.body);
87
91
 
88
- // 恢复 head 中的内联 style 和内联 script
89
- // (meta、title、外部 script、link 标签已在自解压模板的 head 中保留,无需重复添加)
92
+ // 恢复 head 中的资源引用和内联脚本
93
+ // 如果原始 HTML 有 <head>(__hasHeadContent=true),外部资源已由 extractHeadContent
94
+ // 提取并放在模板 head 中,这里只需追加未被模板覆盖的内联脚本和样式
95
+ // 如果原始 HTML 是片段(__hasHeadContent=false),如 Adikteev 格式,
96
+ // 所有资源引用都在压缩数据中,需要完整恢复——包括外部脚本和样式表
90
97
  Array.from(doc.head.children).forEach(function(child) {
91
- if (child.tagName === 'SCRIPT' && !child.src && child.textContent) {
92
- // 仅恢复内联 script(有内容但无 src 的)
93
- var script = document.createElement('script');
94
- script.textContent = child.textContent;
95
- if (child.type) {
96
- script.type = child.type;
98
+ if (child.tagName === 'SCRIPT') {
99
+ if (!child.src && child.textContent) {
100
+ // 内联 script(有内容但无 src)——始终需要恢复
101
+ var script = document.createElement('script');
102
+ script.textContent = child.textContent;
103
+ if (child.type) script.type = child.type;
104
+ document.head.appendChild(script);
105
+ } else if (child.src && !__hasHeadContent) {
106
+ // 外部 script(有 src 属性,如 <script src="creative.js">)
107
+ // 仅在原始 HTML 无 <head> 时恢复,避免与模板中已提取的重复
108
+ var extScript = document.createElement('script');
109
+ extScript.src = child.src;
110
+ if (child.type) extScript.type = child.type;
111
+ if (child.async) extScript.async = true;
112
+ if (child.defer) extScript.defer = true;
113
+ document.head.appendChild(extScript);
97
114
  }
98
- document.head.appendChild(script);
99
115
  } else if (child.tagName === 'STYLE') {
100
- // 恢复内联 style
116
+ // 内联 style——始终需要恢复
101
117
  document.head.appendChild(child.cloneNode(true));
118
+ } else if (child.tagName === 'LINK' && /stylesheet/i.test(child.rel) && !__hasHeadContent) {
119
+ // 外部样式表(如 <link rel="stylesheet" href="style.css">)
120
+ // 仅在原始 HTML 无 <head> 时恢复,避免与模板中已提取的重复
121
+ var link = document.createElement('link');
122
+ link.rel = 'stylesheet';
123
+ link.href = child.href;
124
+ document.head.appendChild(link);
102
125
  }
103
126
  });
104
127
  } catch (error) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@playcraft/devkit",
3
- "version": "1.0.22",
3
+ "version": "1.0.23",
4
4
  "description": "HTML5 Playable Ads 构建工具,支持多广告渠道打包",
5
5
  "main": "core/index.js",
6
6
  "module": "core/index.js",