@playcraft/devkit 1.0.23 → 1.0.24

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.
@@ -94,6 +94,12 @@ const hasHeadContent=headContent.length>0;const decompressCodeReadable=`
94
94
  // 提取并放在模板 head 中,这里只需追加未被模板覆盖的内联脚本和样式
95
95
  // 如果原始 HTML 是片段(__hasHeadContent=false),如 Adikteev 格式,
96
96
  // 所有资源引用都在压缩数据中,需要完整恢复——包括外部脚本和样式表
97
+ //
98
+ // 重要:动态注入的外部脚本在页面解析完成后才异步加载执行,
99
+ // 此时 DOMContentLoaded 已触发,脚本内的事件监听器将永远无法执行。
100
+ // 因此在外部脚本加载完成后手动 dispatch DOMContentLoaded,确保游戏等代码正常初始化。
101
+ var __extScriptCount = 0;
102
+ var __extScriptLoaded = 0;
97
103
  Array.from(doc.head.children).forEach(function(child) {
98
104
  if (child.tagName === 'SCRIPT') {
99
105
  if (!child.src && child.textContent) {
@@ -105,11 +111,18 @@ const hasHeadContent=headContent.length>0;const decompressCodeReadable=`
105
111
  } else if (child.src && !__hasHeadContent) {
106
112
  // 外部 script(有 src 属性,如 <script src="creative.js">)
107
113
  // 仅在原始 HTML 无 <head> 时恢复,避免与模板中已提取的重复
114
+ __extScriptCount++;
108
115
  var extScript = document.createElement('script');
109
116
  extScript.src = child.src;
110
117
  if (child.type) extScript.type = child.type;
111
118
  if (child.async) extScript.async = true;
112
119
  if (child.defer) extScript.defer = true;
120
+ extScript.onload = function() {
121
+ __extScriptLoaded++;
122
+ if (__extScriptLoaded >= __extScriptCount) {
123
+ document.dispatchEvent(new Event('DOMContentLoaded'));
124
+ }
125
+ };
113
126
  document.head.appendChild(extScript);
114
127
  }
115
128
  } else if (child.tagName === 'STYLE') {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@playcraft/devkit",
3
- "version": "1.0.23",
3
+ "version": "1.0.24",
4
4
  "description": "HTML5 Playable Ads 构建工具,支持多广告渠道打包",
5
5
  "main": "core/index.js",
6
6
  "module": "core/index.js",