@yqg/aminofx-css-kit 1.0.3 → 1.0.5

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.
@@ -10,9 +10,15 @@ declare class AnimationPlayer {
10
10
  private isReady;
11
11
  private readyPromise;
12
12
  private loopTimerId;
13
+ private slotObservers;
13
14
  constructor(container: HTMLElement, options: IPlayerOptions);
14
15
  private init;
15
16
  private replacePlaceholders;
17
+ private handleSlotList;
18
+ private moveElementToSlot;
19
+ private performMove;
20
+ private observeElementMount;
21
+ private cleanupSlotObservers;
16
22
  private handleLoop;
17
23
  ready(): Promise<void>;
18
24
  play(): Promise<void>;
package/dist/esm/index.js CHANGED
@@ -98,7 +98,7 @@ var ResourceLoader = /*#__PURE__*/function () {
98
98
  _defineProperty(ResourceLoader, "imageCache", new Map());
99
99
  _defineProperty(ResourceLoader, "loadingQueue", new Map());
100
100
  var AnimationPlayer = /*#__PURE__*/function () {
101
- // 保存定时器ID,用于清理
101
+ // 保存 MutationObserver 实例,用于清理
102
102
 
103
103
  function AnimationPlayer(container, options) {
104
104
  _classCallCheck(this, AnimationPlayer);
@@ -107,6 +107,8 @@ var AnimationPlayer = /*#__PURE__*/function () {
107
107
  _defineProperty(this, "isReady", false);
108
108
  _defineProperty(this, "readyPromise", null);
109
109
  _defineProperty(this, "loopTimerId", null);
110
+ // 保存定时器ID,用于清理
111
+ _defineProperty(this, "slotObservers", []);
110
112
  this.container = container;
111
113
  this.options = options;
112
114
  this.init();
@@ -124,8 +126,8 @@ var AnimationPlayer = /*#__PURE__*/function () {
124
126
  height: '100vh',
125
127
  overflow: 'hidden',
126
128
  alignItems: this.options.alignItems || 'center',
129
+ background: this.options.background || '',
127
130
  justifyContent: 'center',
128
- backgroundColor: 'rgba(0, 0, 0, 0.85)',
129
131
  backdropFilter: 'blur(10px)'
130
132
  });
131
133
  _context2.next = 3;
@@ -163,11 +165,136 @@ var AnimationPlayer = /*#__PURE__*/function () {
163
165
  return ((_this2$options$dynami = _this2.options.dynamicData) === null || _this2$options$dynami === void 0 ? void 0 : _this2$options$dynami[key]) !== undefined ? String(_this2.options.dynamicData[key]) : match;
164
166
  });
165
167
  }
168
+
169
+ /**
170
+ * 处理插槽列表,将 elementId 对应的元素移动到 slotId 对应的插槽中
171
+ * 需要处理时序问题:slotId 需要弹窗渲染后才存在,elementId 可能尚未挂载
172
+ */
173
+ }, {
174
+ key: "handleSlotList",
175
+ value: function handleSlotList() {
176
+ var _this3 = this;
177
+ if (!this.options.extensions || this.options.extensions.length === 0 || !this.options.extensions.some(function (item) {
178
+ return item.slotId;
179
+ }) || !this.options.extensions.some(function (item) {
180
+ return item.elementId;
181
+ })) {
182
+ return;
183
+ }
184
+ console.log('aminofx: 🎰 开始处理插槽列表');
185
+ this.options.extensions.forEach(function (slotItem, index) {
186
+ var slotId = slotItem.slotId,
187
+ elementId = slotItem.elementId;
188
+ if (!slotId || !elementId) {
189
+ console.warn("aminofx: \u26A0\uFE0F \u63D2\u69FD\u914D\u7F6E ".concat(index + 1, " \u7F3A\u5C11 slotId \u6216 elementId"));
190
+ return;
191
+ }
192
+ _this3.moveElementToSlot(slotId, elementId, index);
193
+ });
194
+ }
195
+
196
+ /**
197
+ * 将元素移动到插槽中
198
+ * @param slotId - 插槽 DOM id
199
+ * @param elementId - 元素 DOM id
200
+ * @param index - 插槽索引,用于日志
201
+ */
202
+ }, {
203
+ key: "moveElementToSlot",
204
+ value: function moveElementToSlot(slotId, elementId, index) {
205
+ var slotElement = this.container.querySelector("#".concat(slotId));
206
+ if (!slotElement) {
207
+ console.warn("aminofx: \u26A0\uFE0F \u63D2\u69FD ".concat(index + 1, " \u7684 slotId \"").concat(slotId, "\" \u5728\u5F39\u7A97\u4E2D\u672A\u627E\u5230"));
208
+ return;
209
+ }
210
+ var targetElement = document.getElementById(elementId);
211
+ if (targetElement) {
212
+ // elementId 已存在,直接移动
213
+ this.performMove(slotElement, targetElement, index);
214
+ } else {
215
+ // elementId 尚未挂载,添加 MutationObserver 监听
216
+ console.log("aminofx: \u23F3 \u63D2\u69FD ".concat(index + 1, " \u7684 elementId \"").concat(elementId, "\" \u5C1A\u672A\u6302\u8F7D\uFF0C\u7B49\u5F85\u4E2D..."));
217
+ this.observeElementMount(slotId, elementId, slotElement, index);
218
+ }
219
+ }
220
+
221
+ /**
222
+ * 执行元素移动操作
223
+ * @param slotElement - 插槽元素
224
+ * @param targetElement - 目标元素
225
+ * @param index - 插槽索引,用于日志
226
+ */
227
+ }, {
228
+ key: "performMove",
229
+ value: function performMove(slotElement, targetElement, index) {
230
+ try {
231
+ slotElement.appendChild(targetElement);
232
+ console.log("aminofx: \u2705 \u63D2\u69FD ".concat(index + 1, " \u5143\u7D20\u79FB\u52A8\u6210\u529F: ").concat(targetElement.id, " -> ").concat(slotElement.id));
233
+ } catch (error) {
234
+ console.error("aminofx: \u274C \u63D2\u69FD ".concat(index + 1, " \u5143\u7D20\u79FB\u52A8\u5931\u8D25:"), error);
235
+ }
236
+ }
237
+
238
+ /**
239
+ * 使用 MutationObserver 监听 elementId 元素的挂载
240
+ * @param slotId - 插槽 DOM id
241
+ * @param elementId - 元素 DOM id
242
+ * @param slotElement - 插槽元素
243
+ * @param index - 插槽索引,用于日志
244
+ */
245
+ }, {
246
+ key: "observeElementMount",
247
+ value: function observeElementMount(slotId, elementId, slotElement, index) {
248
+ var _this4 = this;
249
+ var observer = new MutationObserver(function (mutations, obs) {
250
+ var targetElement = document.getElementById(elementId);
251
+ if (targetElement) {
252
+ console.log("aminofx: \uD83C\uDFAF \u63D2\u69FD ".concat(index + 1, " \u68C0\u6D4B\u5230 elementId \"").concat(elementId, "\" \u5DF2\u6302\u8F7D"));
253
+
254
+ // 再次检查 slotElement 是否仍然有效(防止弹窗已销毁)
255
+ if (_this4.container.contains(slotElement)) {
256
+ _this4.performMove(slotElement, targetElement, index);
257
+ } else {
258
+ console.warn("aminofx: \u26A0\uFE0F \u63D2\u69FD ".concat(index + 1, " \u7684 slotId \"").concat(slotId, "\" \u5DF2\u4E0D\u5728 DOM \u4E2D"));
259
+ }
260
+
261
+ // 停止观察
262
+ obs.disconnect();
263
+ // 从数组中移除
264
+ var observerIndex = _this4.slotObservers.indexOf(obs);
265
+ if (observerIndex > -1) {
266
+ _this4.slotObservers.splice(observerIndex, 1);
267
+ }
268
+ }
269
+ });
270
+
271
+ // 保存 observer 实例,用于销毁时清理
272
+ this.slotObservers.push(observer);
273
+
274
+ // 观察整个 document.body 的子树变化
275
+ observer.observe(document.body, {
276
+ childList: true,
277
+ subtree: true
278
+ });
279
+ }
280
+
281
+ /**
282
+ * 清理所有 MutationObserver
283
+ */
284
+ }, {
285
+ key: "cleanupSlotObservers",
286
+ value: function cleanupSlotObservers() {
287
+ this.slotObservers.forEach(function (observer) {
288
+ observer.disconnect();
289
+ });
290
+ this.slotObservers = [];
291
+ console.log('aminofx: 🧹 清理所有插槽观察器');
292
+ }
166
293
  }, {
167
294
  key: "handleLoop",
168
295
  value: function handleLoop() {
169
296
  var _this$options$jsonSch,
170
- _this3 = this,
297
+ _this5 = this,
171
298
  _this$options$jsonSch2,
172
299
  _this$options$jsonSch3;
173
300
  if (!this.options.autoLoop || !Number((_this$options$jsonSch = this.options.jsonSchema) === null || _this$options$jsonSch === void 0 ? void 0 : _this$options$jsonSch.duration)) {
@@ -183,10 +310,10 @@ var AnimationPlayer = /*#__PURE__*/function () {
183
310
 
184
311
  // 后续根据使用情况看是否调整为监听css动画结束事件
185
312
  this.loopTimerId = window.setTimeout(function () {
186
- _this3.container.style.display = 'none';
313
+ _this5.container.style.display = 'none';
187
314
  window.setTimeout(function () {
188
- _this3.loopTimerId = null;
189
- _this3.play();
315
+ _this5.loopTimerId = null;
316
+ _this5.play();
190
317
  }, 100);
191
318
  }, Number((_this$options$jsonSch2 = this.options.jsonSchema) === null || _this$options$jsonSch2 === void 0 ? void 0 : _this$options$jsonSch2.duration));
192
319
  console.log("aminofx: \uD83D\uDD04 \u542F\u52A8\u5FAA\u73AF\u5B9A\u65F6\u5668\uFF0C\u65F6\u957F: ".concat((_this$options$jsonSch3 = this.options.jsonSchema) === null || _this$options$jsonSch3 === void 0 ? void 0 : _this$options$jsonSch3.duration, "ms"));
@@ -195,7 +322,7 @@ var AnimationPlayer = /*#__PURE__*/function () {
195
322
  key: "ready",
196
323
  value: function () {
197
324
  var _ready = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5() {
198
- var _this4 = this;
325
+ var _this6 = this;
199
326
  return _regeneratorRuntime().wrap(function _callee5$(_context5) {
200
327
  while (1) switch (_context5.prev = _context5.next) {
201
328
  case 0:
@@ -222,35 +349,35 @@ var AnimationPlayer = /*#__PURE__*/function () {
222
349
  _context4.prev = 0;
223
350
  jsonPromise = new Promise( /*#__PURE__*/function () {
224
351
  var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(resolve, reject) {
225
- var _this4$options;
226
- var _this4$options2, _this4$options$jsonSc, response, data;
352
+ var _this6$options;
353
+ var _this6$options2, _this6$options$jsonSc, response, data;
227
354
  return _regeneratorRuntime().wrap(function _callee3$(_context3) {
228
355
  while (1) switch (_context3.prev = _context3.next) {
229
356
  case 0:
230
- if (!_this4.options.jsonSchema) {
357
+ if (!_this6.options.jsonSchema) {
231
358
  _context3.next = 5;
232
359
  break;
233
360
  }
234
- _this4.container.innerHTML = _this4.replacePlaceholders(_this4.options.jsonSchema.content);
361
+ _this6.container.innerHTML = _this6.replacePlaceholders(_this6.options.jsonSchema.content);
235
362
  resolve();
236
363
  _context3.next = 24;
237
364
  break;
238
365
  case 5:
239
- if (!((_this4$options = _this4.options) !== null && _this4$options !== void 0 && _this4$options.jsonUrl)) {
366
+ if (!((_this6$options = _this6.options) !== null && _this6$options !== void 0 && _this6$options.jsonUrl)) {
240
367
  _context3.next = 23;
241
368
  break;
242
369
  }
243
370
  _context3.prev = 6;
244
371
  _context3.next = 9;
245
- return fetch((_this4$options2 = _this4.options) === null || _this4$options2 === void 0 ? void 0 : _this4$options2.jsonUrl);
372
+ return fetch((_this6$options2 = _this6.options) === null || _this6$options2 === void 0 ? void 0 : _this6$options2.jsonUrl);
246
373
  case 9:
247
374
  response = _context3.sent;
248
375
  _context3.next = 12;
249
376
  return response.json();
250
377
  case 12:
251
378
  data = _context3.sent;
252
- _this4.options.jsonSchema = data;
253
- _this4.container.innerHTML = _this4.replacePlaceholders(((_this4$options$jsonSc = _this4.options.jsonSchema) === null || _this4$options$jsonSc === void 0 ? void 0 : _this4$options$jsonSc.content) || '');
379
+ _this6.options.jsonSchema = data;
380
+ _this6.container.innerHTML = _this6.replacePlaceholders(((_this6$options$jsonSc = _this6.options.jsonSchema) === null || _this6$options$jsonSc === void 0 ? void 0 : _this6$options$jsonSc.content) || '');
254
381
  resolve();
255
382
  _context3.next = 21;
256
383
  break;
@@ -273,25 +400,28 @@ var AnimationPlayer = /*#__PURE__*/function () {
273
400
  return _ref2.apply(this, arguments);
274
401
  };
275
402
  }());
276
- imgPromise = ResourceLoader.loadImages(_this4.options.preloadImgList || []);
403
+ imgPromise = ResourceLoader.loadImages(_this6.options.preloadImgList || []);
277
404
  _context4.next = 5;
278
405
  return Promise.all([jsonPromise, imgPromise]);
279
406
  case 5:
280
- _this4.isReady = true; // 设置准备完成状态
407
+ _this6.isReady = true; // 设置准备完成状态
408
+
409
+ // 处理插槽列表(此时弹窗内容已渲染,slotId 存在)
410
+ _this6.handleSlotList();
281
411
  resolve();
282
412
  console.log('aminofx: 🎉 动画准备完成,可以开始播放');
283
- _context4.next = 14;
413
+ _context4.next = 15;
284
414
  break;
285
- case 10:
286
- _context4.prev = 10;
415
+ case 11:
416
+ _context4.prev = 11;
287
417
  _context4.t0 = _context4["catch"](0);
288
418
  reject(_context4.t0);
289
419
  console.error('aminofx: ❌ 动画准备失败:', _context4.t0);
290
- case 14:
420
+ case 15:
291
421
  case "end":
292
422
  return _context4.stop();
293
423
  }
294
- }, _callee4, null, [[0, 10]]);
424
+ }, _callee4, null, [[0, 11]]);
295
425
  }));
296
426
  return function (_x2, _x3) {
297
427
  return _ref.apply(this, arguments);
@@ -351,6 +481,9 @@ var AnimationPlayer = /*#__PURE__*/function () {
351
481
  console.log('aminofx: 🧹 销毁时清理循环定时器');
352
482
  }
353
483
 
484
+ // 清理插槽观察器
485
+ this.cleanupSlotObservers();
486
+
354
487
  // 重置状态
355
488
  this.container.innerHTML = '';
356
489
  this.isReady = false;
@@ -9,5 +9,16 @@ interface IPlayerOptions {
9
9
  preloadImgList?: string[];
10
10
  autoLoop?: boolean;
11
11
  dynamicData?: Record<string, string | number | boolean>;
12
+ extensions?: {
13
+ slotId?: string;
14
+ elementId?: string;
15
+ clickAreas?: {
16
+ x?: number;
17
+ y?: number;
18
+ width?: number;
19
+ height?: number;
20
+ };
21
+ }[];
22
+ background?: string;
12
23
  }
13
24
  export type { IPlayerOptions, IJsonSchema };
@@ -1 +1 @@
1
- !function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports["@yqg/aminofx-css-kit"]=e():t["@yqg/aminofx-css-kit"]=e()}(self,(function(){return function(){var t={506:function(){},365:function(t){function e(t,e,r,n,o,i,a){try{var c=t[i](a),u=c.value}catch(t){return void r(t)}c.done?e(u):Promise.resolve(u).then(n,o)}t.exports=function(t){return function(){var r=this,n=arguments;return new Promise((function(o,i){var a=t.apply(r,n);function c(t){e(a,o,i,c,u,"next",t)}function u(t){e(a,o,i,c,u,"throw",t)}c(void 0)}))}},t.exports.__esModule=!0,t.exports.default=t.exports},156:function(t){t.exports=function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")},t.exports.__esModule=!0,t.exports.default=t.exports},499:function(t,e,r){var n=r(714);function o(t,e){for(var r=0;r<e.length;r++){var o=e[r];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,n(o.key),o)}}t.exports=function(t,e,r){return e&&o(t.prototype,e),r&&o(t,r),Object.defineProperty(t,"prototype",{writable:!1}),t},t.exports.__esModule=!0,t.exports.default=t.exports},173:function(t,e,r){var n=r(714);t.exports=function(t,e,r){return(e=n(e))in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t},t.exports.__esModule=!0,t.exports.default=t.exports},298:function(t,e,r){var n=r(241).default;function o(){"use strict";t.exports=o=function(){return r},t.exports.__esModule=!0,t.exports.default=t.exports;var e,r={},i=Object.prototype,a=i.hasOwnProperty,c=Object.defineProperty||function(t,e,r){t[e]=r.value},u="function"==typeof Symbol?Symbol:{},s=u.iterator||"@@iterator",l=u.asyncIterator||"@@asyncIterator",f=u.toStringTag||"@@toStringTag";function p(t,e,r){return Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{p({},"")}catch(e){p=function(t,e,r){return t[e]=r}}function h(t,e,r,n){var o=e&&e.prototype instanceof g?e:g,i=Object.create(o.prototype),a=new M(n||[]);return c(i,"_invoke",{value:S(t,r,a)}),i}function d(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(t){return{type:"throw",arg:t}}}r.wrap=h;var y="suspendedStart",v="executing",m="completed",x={};function g(){}function w(){}function b(){}var P={};p(P,s,(function(){return this}));var j=Object.getPrototypeOf,k=j&&j(j(N([])));k&&k!==i&&a.call(k,s)&&(P=k);var _=b.prototype=g.prototype=Object.create(P);function L(t){["next","throw","return"].forEach((function(e){p(t,e,(function(t){return this._invoke(e,t)}))}))}function E(t,e){function r(o,i,c,u){var s=d(t[o],t,i);if("throw"!==s.type){var l=s.arg,f=l.value;return f&&"object"==n(f)&&a.call(f,"__await")?e.resolve(f.__await).then((function(t){r("next",t,c,u)}),(function(t){r("throw",t,c,u)})):e.resolve(f).then((function(t){l.value=t,c(l)}),(function(t){return r("throw",t,c,u)}))}u(s.arg)}var o;c(this,"_invoke",{value:function(t,n){function i(){return new e((function(e,o){r(t,n,e,o)}))}return o=o?o.then(i,i):i()}})}function S(t,r,n){var o=y;return function(i,a){if(o===v)throw new Error("Generator is already running");if(o===m){if("throw"===i)throw a;return{value:e,done:!0}}for(n.method=i,n.arg=a;;){var c=n.delegate;if(c){var u=T(c,n);if(u){if(u===x)continue;return u}}if("next"===n.method)n.sent=n._sent=n.arg;else if("throw"===n.method){if(o===y)throw o=m,n.arg;n.dispatchException(n.arg)}else"return"===n.method&&n.abrupt("return",n.arg);o=v;var s=d(t,r,n);if("normal"===s.type){if(o=n.done?m:"suspendedYield",s.arg===x)continue;return{value:s.arg,done:n.done}}"throw"===s.type&&(o=m,n.method="throw",n.arg=s.arg)}}}function T(t,r){var n=r.method,o=t.iterator[n];if(o===e)return r.delegate=null,"throw"===n&&t.iterator.return&&(r.method="return",r.arg=e,T(t,r),"throw"===r.method)||"return"!==n&&(r.method="throw",r.arg=new TypeError("The iterator does not provide a '"+n+"' method")),x;var i=d(o,t.iterator,r.arg);if("throw"===i.type)return r.method="throw",r.arg=i.arg,r.delegate=null,x;var a=i.arg;return a?a.done?(r[t.resultName]=a.value,r.next=t.nextLoc,"return"!==r.method&&(r.method="next",r.arg=e),r.delegate=null,x):a:(r.method="throw",r.arg=new TypeError("iterator result is not an object"),r.delegate=null,x)}function O(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function I(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function M(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(O,this),this.reset(!0)}function N(t){if(t||""===t){var r=t[s];if(r)return r.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var o=-1,i=function r(){for(;++o<t.length;)if(a.call(t,o))return r.value=t[o],r.done=!1,r;return r.value=e,r.done=!0,r};return i.next=i}}throw new TypeError(n(t)+" is not iterable")}return w.prototype=b,c(_,"constructor",{value:b,configurable:!0}),c(b,"constructor",{value:w,configurable:!0}),w.displayName=p(b,f,"GeneratorFunction"),r.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===w||"GeneratorFunction"===(e.displayName||e.name))},r.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,b):(t.__proto__=b,p(t,f,"GeneratorFunction")),t.prototype=Object.create(_),t},r.awrap=function(t){return{__await:t}},L(E.prototype),p(E.prototype,l,(function(){return this})),r.AsyncIterator=E,r.async=function(t,e,n,o,i){void 0===i&&(i=Promise);var a=new E(h(t,e,n,o),i);return r.isGeneratorFunction(e)?a:a.next().then((function(t){return t.done?t.value:a.next()}))},L(_),p(_,f,"Generator"),p(_,s,(function(){return this})),p(_,"toString",(function(){return"[object Generator]"})),r.keys=function(t){var e=Object(t),r=[];for(var n in e)r.push(n);return r.reverse(),function t(){for(;r.length;){var n=r.pop();if(n in e)return t.value=n,t.done=!1,t}return t.done=!0,t}},r.values=N,M.prototype={constructor:M,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=e,this.done=!1,this.delegate=null,this.method="next",this.arg=e,this.tryEntries.forEach(I),!t)for(var r in this)"t"===r.charAt(0)&&a.call(this,r)&&!isNaN(+r.slice(1))&&(this[r]=e)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(t){if(this.done)throw t;var r=this;function n(n,o){return c.type="throw",c.arg=t,r.next=n,o&&(r.method="next",r.arg=e),!!o}for(var o=this.tryEntries.length-1;o>=0;--o){var i=this.tryEntries[o],c=i.completion;if("root"===i.tryLoc)return n("end");if(i.tryLoc<=this.prev){var u=a.call(i,"catchLoc"),s=a.call(i,"finallyLoc");if(u&&s){if(this.prev<i.catchLoc)return n(i.catchLoc,!0);if(this.prev<i.finallyLoc)return n(i.finallyLoc)}else if(u){if(this.prev<i.catchLoc)return n(i.catchLoc,!0)}else{if(!s)throw new Error("try statement without catch or finally");if(this.prev<i.finallyLoc)return n(i.finallyLoc)}}}},abrupt:function(t,e){for(var r=this.tryEntries.length-1;r>=0;--r){var n=this.tryEntries[r];if(n.tryLoc<=this.prev&&a.call(n,"finallyLoc")&&this.prev<n.finallyLoc){var o=n;break}}o&&("break"===t||"continue"===t)&&o.tryLoc<=e&&e<=o.finallyLoc&&(o=null);var i=o?o.completion:{};return i.type=t,i.arg=e,o?(this.method="next",this.next=o.finallyLoc,x):this.complete(i)},complete:function(t,e){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&e&&(this.next=e),x},finish:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.finallyLoc===t)return this.complete(r.completion,r.afterLoc),I(r),x}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.tryLoc===t){var n=r.completion;if("throw"===n.type){var o=n.arg;I(r)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(t,r,n){return this.delegate={iterator:N(t),resultName:r,nextLoc:n},"next"===this.method&&(this.arg=e),x}},r}t.exports=o,t.exports.__esModule=!0,t.exports.default=t.exports},569:function(t,e,r){var n=r(241).default;t.exports=function(t,e){if("object"!=n(t)||!t)return t;var r=t[Symbol.toPrimitive];if(void 0!==r){var o=r.call(t,e||"default");if("object"!=n(o))return o;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)},t.exports.__esModule=!0,t.exports.default=t.exports},714:function(t,e,r){var n=r(241).default,o=r(569);t.exports=function(t){var e=o(t,"string");return"symbol"==n(e)?e:String(e)},t.exports.__esModule=!0,t.exports.default=t.exports},241:function(t){function e(r){return t.exports=e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},t.exports.__esModule=!0,t.exports.default=t.exports,e(r)}t.exports=e,t.exports.__esModule=!0,t.exports.default=t.exports}},e={};function r(n){var o=e[n];if(void 0!==o)return o.exports;var i=e[n]={exports:{}};return t[n](i,i.exports,r),i.exports}r.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return r.d(e,{a:e}),e},r.d=function(t,e){for(var n in e)r.o(e,n)&&!r.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:e[n]})},r.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},r.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};var n={};return function(){"use strict";r.r(n),r.d(n,{AnimationPlayer:function(){return v}});var t=r(298),e=r.n(t),o=r(365),i=r.n(o),a=r(156),c=r.n(a),u=r(499),s=r.n(u),l=r(173),f=r.n(l),p=r(506),h={};for(var d in p)["default","AnimationPlayer"].indexOf(d)<0&&(h[d]=function(t){return p[t]}.bind(0,d));r.d(n,h);var y=function(){function t(){c()(this,t)}var r;return s()(t,null,[{key:"loadImages",value:(r=i()(e()().mark((function t(r){var n,o=this;return e()().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(Array.isArray(r)&&0!==r.length){t.next=2;break}return t.abrupt("return",Promise.resolve());case 2:return n=r.map((function(t,e){if(!t.startsWith("http"))return Promise.resolve();if(o.imageCache.has(t))return console.log("aminofx: ✅ 图片 ".concat(e+1," 已缓存: ").concat(t)),Promise.resolve();if(o.loadingQueue.has(t))return o.loadingQueue.get(t);var r=new Promise((function(r){var n=new Image;n.onload=function(){o.imageCache.set(t,!0),o.loadingQueue.delete(t),console.log("aminofx: ✅ 图片 ".concat(e+1," 加载成功: ").concat(t)),"function"==typeof n.decode?n.decode().then((function(){console.log("aminofx: 🎨 图片 ".concat(e+1," 解码完成: ").concat(t)),r()})).catch((function(){console.log("aminofx: ⚠️ 图片 ".concat(e+1," decode失败,使用fallback: ").concat(t)),r()})):(console.log("aminofx: 📱 图片 ".concat(e+1," 使用兼容模式: ").concat(t)),r())},n.src=t,n.onerror=function(){o.loadingQueue.delete(t),console.error("aminofx: ❌ 图片 ".concat(e+1," 加载失败: ").concat(t)),r()}}));return o.loadingQueue.set(t,r),r})),t.prev=3,t.next=6,Promise.all(n);case 6:console.log("aminofx: 🎉 所有图片资源加载完成"),t.next=12;break;case 9:t.prev=9,t.t0=t.catch(3),console.error("aminofx: ❌ 图片加载过程中出现错误:",t.t0);case 12:case"end":return t.stop()}}),t,null,[[3,9]])}))),function(t){return r.apply(this,arguments)})}]),t}();f()(y,"imageCache",new Map),f()(y,"loadingQueue",new Map);var v=function(){function t(e,r){c()(this,t),f()(this,"container",void 0),f()(this,"options",void 0),f()(this,"isReady",!1),f()(this,"readyPromise",null),f()(this,"loopTimerId",null),this.container=e,this.options=r,this.init()}var r,n,o;return s()(t,[{key:"init",value:(o=i()(e()().mark((function t(){return e()().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return Object.assign(this.container.style,{display:"none",width:"100vw",height:"100vh",overflow:"hidden",alignItems:this.options.alignItems||"center",justifyContent:"center",backgroundColor:"rgba(0, 0, 0, 0.85)",backdropFilter:"blur(10px)"}),t.next=3,this.ready();case 3:case"end":return t.stop()}}),t,this)}))),function(){return o.apply(this,arguments)})},{key:"replacePlaceholders",value:function(t){var e=this;return this.options.dynamicData&&t?t.replace(/\{\{(\w+)\}\}|\$\{(\w+)\}/g,(function(t,r,n){var o,i=r||n;return void 0!==(null===(o=e.options.dynamicData)||void 0===o?void 0:o[i])?String(e.options.dynamicData[i]):t})):t}},{key:"handleLoop",value:function(){var t,e,r,n=this;this.options.autoLoop&&Number(null===(t=this.options.jsonSchema)||void 0===t?void 0:t.duration)&&(null!==this.loopTimerId&&(clearTimeout(this.loopTimerId),this.loopTimerId=null,console.log("aminofx: 🧹 清理旧的循环定时器")),this.loopTimerId=window.setTimeout((function(){n.container.style.display="none",window.setTimeout((function(){n.loopTimerId=null,n.play()}),100)}),Number(null===(e=this.options.jsonSchema)||void 0===e?void 0:e.duration)),console.log("aminofx: 🔄 启动循环定时器,时长: ".concat(null===(r=this.options.jsonSchema)||void 0===r?void 0:r.duration,"ms")))}},{key:"ready",value:(n=i()(e()().mark((function t(){var r=this;return e()().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(!this.isReady){t.next=3;break}return console.log("aminofx: ✅ 动画已准备就绪,直接返回"),t.abrupt("return",Promise.resolve());case 3:if(!this.readyPromise){t.next=6;break}return console.log("aminofx: ⏳ 正在准备中,等待现有Promise..."),t.abrupt("return",this.readyPromise);case 6:return this.readyPromise=new Promise(function(){var t=i()(e()().mark((function t(n,o){var a,c;return e()().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.prev=0,a=new Promise(function(){var t=i()(e()().mark((function t(n,o){var i,a,c,u,s;return e()().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(!r.options.jsonSchema){t.next=5;break}r.container.innerHTML=r.replacePlaceholders(r.options.jsonSchema.content),n(),t.next=24;break;case 5:if(null===(i=r.options)||void 0===i||!i.jsonUrl){t.next=23;break}return t.prev=6,t.next=9,fetch(null===(a=r.options)||void 0===a?void 0:a.jsonUrl);case 9:return u=t.sent,t.next=12,u.json();case 12:s=t.sent,r.options.jsonSchema=s,r.container.innerHTML=r.replacePlaceholders((null===(c=r.options.jsonSchema)||void 0===c?void 0:c.content)||""),n(),t.next=21;break;case 18:t.prev=18,t.t0=t.catch(6),o(t.t0);case 21:t.next=24;break;case 23:throw new Error("没有提供jsonSchema或jsonUrl");case 24:case"end":return t.stop()}}),t,null,[[6,18]])})));return function(e,r){return t.apply(this,arguments)}}()),c=y.loadImages(r.options.preloadImgList||[]),t.next=5,Promise.all([a,c]);case 5:r.isReady=!0,n(),console.log("aminofx: 🎉 动画准备完成,可以开始播放"),t.next=14;break;case 10:t.prev=10,t.t0=t.catch(0),o(t.t0),console.error("aminofx: ❌ 动画准备失败:",t.t0);case 14:case"end":return t.stop()}}),t,null,[[0,10]])})));return function(e,r){return t.apply(this,arguments)}}()),t.abrupt("return",this.readyPromise);case 8:case"end":return t.stop()}}),t,this)}))),function(){return n.apply(this,arguments)})},{key:"play",value:(r=i()(e()().mark((function t(){return e()().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(this.isReady){t.next=4;break}return console.warn("aminofx: ⚠️ 动画尚未准备就绪,自动调用ready()..."),t.next=4,this.ready();case 4:this.container.style.display="flex",this.options.autoLoop&&null===this.loopTimerId&&this.handleLoop();case 6:case"end":return t.stop()}}),t,this)}))),function(){return r.apply(this,arguments)})},{key:"destroy",value:function(){null!==this.loopTimerId&&(clearTimeout(this.loopTimerId),this.loopTimerId=null,console.log("aminofx: 🧹 销毁时清理循环定时器")),this.container.innerHTML="",this.isReady=!1,this.readyPromise=null,console.log("aminofx: 🗑️ AnimationPlayer 已销毁")}},{key:"updateSchema",value:function(t){this.destroy(),this.options=t,this.init()}}]),t}();function m(t,e){var r=document.getElementById(t);if(!r)throw new Error('Container with id "'.concat(t,'" not found'));var n=document.createElement("div"),o=new v(n,e);return r.appendChild(n),o}n.default=m,window.createCssAnimationPlayer=m}(),n}()}));
1
+ !function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports["@yqg/aminofx-css-kit"]=e():t["@yqg/aminofx-css-kit"]=e()}(self,(function(){return function(){var t={506:function(){},365:function(t){function e(t,e,n,o,r,i,a){try{var s=t[i](a),c=s.value}catch(t){return void n(t)}s.done?e(c):Promise.resolve(c).then(o,r)}t.exports=function(t){return function(){var n=this,o=arguments;return new Promise((function(r,i){var a=t.apply(n,o);function s(t){e(a,r,i,s,c,"next",t)}function c(t){e(a,r,i,s,c,"throw",t)}s(void 0)}))}},t.exports.__esModule=!0,t.exports.default=t.exports},156:function(t){t.exports=function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")},t.exports.__esModule=!0,t.exports.default=t.exports},499:function(t,e,n){var o=n(714);function r(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,o(r.key),r)}}t.exports=function(t,e,n){return e&&r(t.prototype,e),n&&r(t,n),Object.defineProperty(t,"prototype",{writable:!1}),t},t.exports.__esModule=!0,t.exports.default=t.exports},173:function(t,e,n){var o=n(714);t.exports=function(t,e,n){return(e=o(e))in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t},t.exports.__esModule=!0,t.exports.default=t.exports},298:function(t,e,n){var o=n(241).default;function r(){"use strict";t.exports=r=function(){return n},t.exports.__esModule=!0,t.exports.default=t.exports;var e,n={},i=Object.prototype,a=i.hasOwnProperty,s=Object.defineProperty||function(t,e,n){t[e]=n.value},c="function"==typeof Symbol?Symbol:{},u=c.iterator||"@@iterator",l=c.asyncIterator||"@@asyncIterator",f=c.toStringTag||"@@toStringTag";function p(t,e,n){return Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{p({},"")}catch(e){p=function(t,e,n){return t[e]=n}}function h(t,e,n,o){var r=e&&e.prototype instanceof g?e:g,i=Object.create(r.prototype),a=new M(o||[]);return s(i,"_invoke",{value:S(t,n,a)}),i}function d(t,e,n){try{return{type:"normal",arg:t.call(e,n)}}catch(t){return{type:"throw",arg:t}}}n.wrap=h;var v="suspendedStart",m="executing",y="completed",x={};function g(){}function b(){}function w(){}var k={};p(k,u,(function(){return this}));var P=Object.getPrototypeOf,j=P&&P(P(N([])));j&&j!==i&&a.call(j,u)&&(k=j);var L=w.prototype=g.prototype=Object.create(k);function _(t){["next","throw","return"].forEach((function(e){p(t,e,(function(t){return this._invoke(e,t)}))}))}function E(t,e){function n(r,i,s,c){var u=d(t[r],t,i);if("throw"!==u.type){var l=u.arg,f=l.value;return f&&"object"==o(f)&&a.call(f,"__await")?e.resolve(f.__await).then((function(t){n("next",t,s,c)}),(function(t){n("throw",t,s,c)})):e.resolve(f).then((function(t){l.value=t,s(l)}),(function(t){return n("throw",t,s,c)}))}c(u.arg)}var r;s(this,"_invoke",{value:function(t,o){function i(){return new e((function(e,r){n(t,o,e,r)}))}return r=r?r.then(i,i):i()}})}function S(t,n,o){var r=v;return function(i,a){if(r===m)throw new Error("Generator is already running");if(r===y){if("throw"===i)throw a;return{value:e,done:!0}}for(o.method=i,o.arg=a;;){var s=o.delegate;if(s){var c=O(s,o);if(c){if(c===x)continue;return c}}if("next"===o.method)o.sent=o._sent=o.arg;else if("throw"===o.method){if(r===v)throw r=y,o.arg;o.dispatchException(o.arg)}else"return"===o.method&&o.abrupt("return",o.arg);r=m;var u=d(t,n,o);if("normal"===u.type){if(r=o.done?y:"suspendedYield",u.arg===x)continue;return{value:u.arg,done:o.done}}"throw"===u.type&&(r=y,o.method="throw",o.arg=u.arg)}}}function O(t,n){var o=n.method,r=t.iterator[o];if(r===e)return n.delegate=null,"throw"===o&&t.iterator.return&&(n.method="return",n.arg=e,O(t,n),"throw"===n.method)||"return"!==o&&(n.method="throw",n.arg=new TypeError("The iterator does not provide a '"+o+"' method")),x;var i=d(r,t.iterator,n.arg);if("throw"===i.type)return n.method="throw",n.arg=i.arg,n.delegate=null,x;var a=i.arg;return a?a.done?(n[t.resultName]=a.value,n.next=t.nextLoc,"return"!==n.method&&(n.method="next",n.arg=e),n.delegate=null,x):a:(n.method="throw",n.arg=new TypeError("iterator result is not an object"),n.delegate=null,x)}function I(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function T(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function M(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(I,this),this.reset(!0)}function N(t){if(t||""===t){var n=t[u];if(n)return n.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var r=-1,i=function n(){for(;++r<t.length;)if(a.call(t,r))return n.value=t[r],n.done=!1,n;return n.value=e,n.done=!0,n};return i.next=i}}throw new TypeError(o(t)+" is not iterable")}return b.prototype=w,s(L,"constructor",{value:w,configurable:!0}),s(w,"constructor",{value:b,configurable:!0}),b.displayName=p(w,f,"GeneratorFunction"),n.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===b||"GeneratorFunction"===(e.displayName||e.name))},n.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,w):(t.__proto__=w,p(t,f,"GeneratorFunction")),t.prototype=Object.create(L),t},n.awrap=function(t){return{__await:t}},_(E.prototype),p(E.prototype,l,(function(){return this})),n.AsyncIterator=E,n.async=function(t,e,o,r,i){void 0===i&&(i=Promise);var a=new E(h(t,e,o,r),i);return n.isGeneratorFunction(e)?a:a.next().then((function(t){return t.done?t.value:a.next()}))},_(L),p(L,f,"Generator"),p(L,u,(function(){return this})),p(L,"toString",(function(){return"[object Generator]"})),n.keys=function(t){var e=Object(t),n=[];for(var o in e)n.push(o);return n.reverse(),function t(){for(;n.length;){var o=n.pop();if(o in e)return t.value=o,t.done=!1,t}return t.done=!0,t}},n.values=N,M.prototype={constructor:M,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=e,this.done=!1,this.delegate=null,this.method="next",this.arg=e,this.tryEntries.forEach(T),!t)for(var n in this)"t"===n.charAt(0)&&a.call(this,n)&&!isNaN(+n.slice(1))&&(this[n]=e)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(t){if(this.done)throw t;var n=this;function o(o,r){return s.type="throw",s.arg=t,n.next=o,r&&(n.method="next",n.arg=e),!!r}for(var r=this.tryEntries.length-1;r>=0;--r){var i=this.tryEntries[r],s=i.completion;if("root"===i.tryLoc)return o("end");if(i.tryLoc<=this.prev){var c=a.call(i,"catchLoc"),u=a.call(i,"finallyLoc");if(c&&u){if(this.prev<i.catchLoc)return o(i.catchLoc,!0);if(this.prev<i.finallyLoc)return o(i.finallyLoc)}else if(c){if(this.prev<i.catchLoc)return o(i.catchLoc,!0)}else{if(!u)throw new Error("try statement without catch or finally");if(this.prev<i.finallyLoc)return o(i.finallyLoc)}}}},abrupt:function(t,e){for(var n=this.tryEntries.length-1;n>=0;--n){var o=this.tryEntries[n];if(o.tryLoc<=this.prev&&a.call(o,"finallyLoc")&&this.prev<o.finallyLoc){var r=o;break}}r&&("break"===t||"continue"===t)&&r.tryLoc<=e&&e<=r.finallyLoc&&(r=null);var i=r?r.completion:{};return i.type=t,i.arg=e,r?(this.method="next",this.next=r.finallyLoc,x):this.complete(i)},complete:function(t,e){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&e&&(this.next=e),x},finish:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var n=this.tryEntries[e];if(n.finallyLoc===t)return this.complete(n.completion,n.afterLoc),T(n),x}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var n=this.tryEntries[e];if(n.tryLoc===t){var o=n.completion;if("throw"===o.type){var r=o.arg;T(n)}return r}}throw new Error("illegal catch attempt")},delegateYield:function(t,n,o){return this.delegate={iterator:N(t),resultName:n,nextLoc:o},"next"===this.method&&(this.arg=e),x}},n}t.exports=r,t.exports.__esModule=!0,t.exports.default=t.exports},569:function(t,e,n){var o=n(241).default;t.exports=function(t,e){if("object"!=o(t)||!t)return t;var n=t[Symbol.toPrimitive];if(void 0!==n){var r=n.call(t,e||"default");if("object"!=o(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)},t.exports.__esModule=!0,t.exports.default=t.exports},714:function(t,e,n){var o=n(241).default,r=n(569);t.exports=function(t){var e=r(t,"string");return"symbol"==o(e)?e:String(e)},t.exports.__esModule=!0,t.exports.default=t.exports},241:function(t){function e(n){return t.exports=e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},t.exports.__esModule=!0,t.exports.default=t.exports,e(n)}t.exports=e,t.exports.__esModule=!0,t.exports.default=t.exports}},e={};function n(o){var r=e[o];if(void 0!==r)return r.exports;var i=e[o]={exports:{}};return t[o](i,i.exports,n),i.exports}n.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return n.d(e,{a:e}),e},n.d=function(t,e){for(var o in e)n.o(e,o)&&!n.o(t,o)&&Object.defineProperty(t,o,{enumerable:!0,get:e[o]})},n.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},n.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};var o={};return function(){"use strict";n.r(o),n.d(o,{AnimationPlayer:function(){return m}});var t=n(298),e=n.n(t),r=n(365),i=n.n(r),a=n(156),s=n.n(a),c=n(499),u=n.n(c),l=n(173),f=n.n(l),p=n(506),h={};for(var d in p)["default","AnimationPlayer"].indexOf(d)<0&&(h[d]=function(t){return p[t]}.bind(0,d));n.d(o,h);var v=function(){function t(){s()(this,t)}var n;return u()(t,null,[{key:"loadImages",value:(n=i()(e()().mark((function t(n){var o,r=this;return e()().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(Array.isArray(n)&&0!==n.length){t.next=2;break}return t.abrupt("return",Promise.resolve());case 2:return o=n.map((function(t,e){if(!t.startsWith("http"))return Promise.resolve();if(r.imageCache.has(t))return console.log("aminofx: ✅ 图片 ".concat(e+1," 已缓存: ").concat(t)),Promise.resolve();if(r.loadingQueue.has(t))return r.loadingQueue.get(t);var n=new Promise((function(n){var o=new Image;o.onload=function(){r.imageCache.set(t,!0),r.loadingQueue.delete(t),console.log("aminofx: ✅ 图片 ".concat(e+1," 加载成功: ").concat(t)),"function"==typeof o.decode?o.decode().then((function(){console.log("aminofx: 🎨 图片 ".concat(e+1," 解码完成: ").concat(t)),n()})).catch((function(){console.log("aminofx: ⚠️ 图片 ".concat(e+1," decode失败,使用fallback: ").concat(t)),n()})):(console.log("aminofx: 📱 图片 ".concat(e+1," 使用兼容模式: ").concat(t)),n())},o.src=t,o.onerror=function(){r.loadingQueue.delete(t),console.error("aminofx: ❌ 图片 ".concat(e+1," 加载失败: ").concat(t)),n()}}));return r.loadingQueue.set(t,n),n})),t.prev=3,t.next=6,Promise.all(o);case 6:console.log("aminofx: 🎉 所有图片资源加载完成"),t.next=12;break;case 9:t.prev=9,t.t0=t.catch(3),console.error("aminofx: ❌ 图片加载过程中出现错误:",t.t0);case 12:case"end":return t.stop()}}),t,null,[[3,9]])}))),function(t){return n.apply(this,arguments)})}]),t}();f()(v,"imageCache",new Map),f()(v,"loadingQueue",new Map);var m=function(){function t(e,n){s()(this,t),f()(this,"container",void 0),f()(this,"options",void 0),f()(this,"isReady",!1),f()(this,"readyPromise",null),f()(this,"loopTimerId",null),f()(this,"slotObservers",[]),this.container=e,this.options=n,this.init()}var n,o,r;return u()(t,[{key:"init",value:(r=i()(e()().mark((function t(){return e()().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return Object.assign(this.container.style,{display:"none",width:"100vw",height:"100vh",overflow:"hidden",alignItems:this.options.alignItems||"center",background:this.options.background||"",justifyContent:"center",backdropFilter:"blur(10px)"}),t.next=3,this.ready();case 3:case"end":return t.stop()}}),t,this)}))),function(){return r.apply(this,arguments)})},{key:"replacePlaceholders",value:function(t){var e=this;return this.options.dynamicData&&t?t.replace(/\{\{(\w+)\}\}|\$\{(\w+)\}/g,(function(t,n,o){var r,i=n||o;return void 0!==(null===(r=e.options.dynamicData)||void 0===r?void 0:r[i])?String(e.options.dynamicData[i]):t})):t}},{key:"handleSlotList",value:function(){var t=this;this.options.extensions&&0!==this.options.extensions.length&&this.options.extensions.some((function(t){return t.slotId}))&&this.options.extensions.some((function(t){return t.elementId}))&&(console.log("aminofx: 🎰 开始处理插槽列表"),this.options.extensions.forEach((function(e,n){var o=e.slotId,r=e.elementId;o&&r?t.moveElementToSlot(o,r,n):console.warn("aminofx: ⚠️ 插槽配置 ".concat(n+1," 缺少 slotId 或 elementId"))})))}},{key:"moveElementToSlot",value:function(t,e,n){var o=this.container.querySelector("#".concat(t));if(o){var r=document.getElementById(e);r?this.performMove(o,r,n):(console.log("aminofx: ⏳ 插槽 ".concat(n+1,' 的 elementId "').concat(e,'" 尚未挂载,等待中...')),this.observeElementMount(t,e,o,n))}else console.warn("aminofx: ⚠️ 插槽 ".concat(n+1,' 的 slotId "').concat(t,'" 在弹窗中未找到'))}},{key:"performMove",value:function(t,e,n){try{t.appendChild(e),console.log("aminofx: ✅ 插槽 ".concat(n+1," 元素移动成功: ").concat(e.id," -> ").concat(t.id))}catch(t){console.error("aminofx: ❌ 插槽 ".concat(n+1," 元素移动失败:"),t)}}},{key:"observeElementMount",value:function(t,e,n,o){var r=this,i=new MutationObserver((function(i,a){var s=document.getElementById(e);if(s){console.log("aminofx: 🎯 插槽 ".concat(o+1,' 检测到 elementId "').concat(e,'" 已挂载')),r.container.contains(n)?r.performMove(n,s,o):console.warn("aminofx: ⚠️ 插槽 ".concat(o+1,' 的 slotId "').concat(t,'" 已不在 DOM 中')),a.disconnect();var c=r.slotObservers.indexOf(a);c>-1&&r.slotObservers.splice(c,1)}}));this.slotObservers.push(i),i.observe(document.body,{childList:!0,subtree:!0})}},{key:"cleanupSlotObservers",value:function(){this.slotObservers.forEach((function(t){t.disconnect()})),this.slotObservers=[],console.log("aminofx: 🧹 清理所有插槽观察器")}},{key:"handleLoop",value:function(){var t,e,n,o=this;this.options.autoLoop&&Number(null===(t=this.options.jsonSchema)||void 0===t?void 0:t.duration)&&(null!==this.loopTimerId&&(clearTimeout(this.loopTimerId),this.loopTimerId=null,console.log("aminofx: 🧹 清理旧的循环定时器")),this.loopTimerId=window.setTimeout((function(){o.container.style.display="none",window.setTimeout((function(){o.loopTimerId=null,o.play()}),100)}),Number(null===(e=this.options.jsonSchema)||void 0===e?void 0:e.duration)),console.log("aminofx: 🔄 启动循环定时器,时长: ".concat(null===(n=this.options.jsonSchema)||void 0===n?void 0:n.duration,"ms")))}},{key:"ready",value:(o=i()(e()().mark((function t(){var n=this;return e()().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(!this.isReady){t.next=3;break}return console.log("aminofx: ✅ 动画已准备就绪,直接返回"),t.abrupt("return",Promise.resolve());case 3:if(!this.readyPromise){t.next=6;break}return console.log("aminofx: ⏳ 正在准备中,等待现有Promise..."),t.abrupt("return",this.readyPromise);case 6:return this.readyPromise=new Promise(function(){var t=i()(e()().mark((function t(o,r){var a,s;return e()().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.prev=0,a=new Promise(function(){var t=i()(e()().mark((function t(o,r){var i,a,s,c,u;return e()().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(!n.options.jsonSchema){t.next=5;break}n.container.innerHTML=n.replacePlaceholders(n.options.jsonSchema.content),o(),t.next=24;break;case 5:if(null===(i=n.options)||void 0===i||!i.jsonUrl){t.next=23;break}return t.prev=6,t.next=9,fetch(null===(a=n.options)||void 0===a?void 0:a.jsonUrl);case 9:return c=t.sent,t.next=12,c.json();case 12:u=t.sent,n.options.jsonSchema=u,n.container.innerHTML=n.replacePlaceholders((null===(s=n.options.jsonSchema)||void 0===s?void 0:s.content)||""),o(),t.next=21;break;case 18:t.prev=18,t.t0=t.catch(6),r(t.t0);case 21:t.next=24;break;case 23:throw new Error("没有提供jsonSchema或jsonUrl");case 24:case"end":return t.stop()}}),t,null,[[6,18]])})));return function(e,n){return t.apply(this,arguments)}}()),s=v.loadImages(n.options.preloadImgList||[]),t.next=5,Promise.all([a,s]);case 5:n.isReady=!0,n.handleSlotList(),o(),console.log("aminofx: 🎉 动画准备完成,可以开始播放"),t.next=15;break;case 11:t.prev=11,t.t0=t.catch(0),r(t.t0),console.error("aminofx: ❌ 动画准备失败:",t.t0);case 15:case"end":return t.stop()}}),t,null,[[0,11]])})));return function(e,n){return t.apply(this,arguments)}}()),t.abrupt("return",this.readyPromise);case 8:case"end":return t.stop()}}),t,this)}))),function(){return o.apply(this,arguments)})},{key:"play",value:(n=i()(e()().mark((function t(){return e()().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(this.isReady){t.next=4;break}return console.warn("aminofx: ⚠️ 动画尚未准备就绪,自动调用ready()..."),t.next=4,this.ready();case 4:this.container.style.display="flex",this.options.autoLoop&&null===this.loopTimerId&&this.handleLoop();case 6:case"end":return t.stop()}}),t,this)}))),function(){return n.apply(this,arguments)})},{key:"destroy",value:function(){null!==this.loopTimerId&&(clearTimeout(this.loopTimerId),this.loopTimerId=null,console.log("aminofx: 🧹 销毁时清理循环定时器")),this.cleanupSlotObservers(),this.container.innerHTML="",this.isReady=!1,this.readyPromise=null,console.log("aminofx: 🗑️ AnimationPlayer 已销毁")}},{key:"updateSchema",value:function(t){this.destroy(),this.options=t,this.init()}}]),t}();function y(t,e){var n=document.getElementById(t);if(!n)throw new Error('Container with id "'.concat(t,'" not found'));var o=document.createElement("div"),r=new m(o,e);return n.appendChild(o),r}o.default=y,window.createCssAnimationPlayer=y}(),o}()}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yqg/aminofx-css-kit",
3
- "version": "1.0.3",
3
+ "version": "1.0.5",
4
4
  "description": "YQG AminoFX CSS animation kit - Core animation utilities and effects",
5
5
  "main": "dist/esm/index.js",
6
6
  "module": "dist/esm/index.js",
package/src/index.ts CHANGED
@@ -91,6 +91,7 @@ class AnimationPlayer {
91
91
  private isReady = false;
92
92
  private readyPromise: Promise<void> | null = null;
93
93
  private loopTimerId: number | null = null; // 保存定时器ID,用于清理
94
+ private slotObservers: MutationObserver[] = []; // 保存 MutationObserver 实例,用于清理
94
95
 
95
96
  constructor(container: HTMLElement, options: IPlayerOptions) {
96
97
  this.container = container;
@@ -105,8 +106,8 @@ class AnimationPlayer {
105
106
  height: '100vh',
106
107
  overflow: 'hidden',
107
108
  alignItems: this.options.alignItems || 'center',
109
+ background: this.options.background || '',
108
110
  justifyContent: 'center',
109
- backgroundColor: 'rgba(0, 0, 0, 0.85)',
110
111
  backdropFilter: 'blur(10px)',
111
112
  });
112
113
 
@@ -137,6 +138,152 @@ class AnimationPlayer {
137
138
  );
138
139
  }
139
140
 
141
+ /**
142
+ * 处理插槽列表,将 elementId 对应的元素移动到 slotId 对应的插槽中
143
+ * 需要处理时序问题:slotId 需要弹窗渲染后才存在,elementId 可能尚未挂载
144
+ */
145
+ private handleSlotList(): void {
146
+ if (!this.options.extensions || this.options.extensions.length === 0 || !this.options.extensions.some(item => item.slotId) || !this.options.extensions.some(item => item.elementId)) {
147
+ return;
148
+ }
149
+
150
+ console.log('aminofx: 🎰 开始处理插槽列表');
151
+
152
+ this.options.extensions.forEach((slotItem, index) => {
153
+ const { slotId, elementId } = slotItem;
154
+
155
+ if (!slotId || !elementId) {
156
+ console.warn(
157
+ `aminofx: ⚠️ 插槽配置 ${index + 1} 缺少 slotId 或 elementId`,
158
+ );
159
+ return;
160
+ }
161
+
162
+ this.moveElementToSlot(slotId, elementId, index);
163
+ });
164
+ }
165
+
166
+ /**
167
+ * 将元素移动到插槽中
168
+ * @param slotId - 插槽 DOM id
169
+ * @param elementId - 元素 DOM id
170
+ * @param index - 插槽索引,用于日志
171
+ */
172
+ private moveElementToSlot(
173
+ slotId: string,
174
+ elementId: string,
175
+ index: number,
176
+ ): void {
177
+ const slotElement = this.container.querySelector(`#${slotId}`);
178
+
179
+ if (!slotElement) {
180
+ console.warn(
181
+ `aminofx: ⚠️ 插槽 ${index + 1} 的 slotId "${slotId}" 在弹窗中未找到`,
182
+ );
183
+ return;
184
+ }
185
+
186
+ const targetElement = document.getElementById(elementId);
187
+
188
+ if (targetElement) {
189
+ // elementId 已存在,直接移动
190
+ this.performMove(slotElement as HTMLElement, targetElement, index);
191
+ } else {
192
+ // elementId 尚未挂载,添加 MutationObserver 监听
193
+ console.log(
194
+ `aminofx: ⏳ 插槽 ${index + 1} 的 elementId "${elementId}" 尚未挂载,等待中...`,
195
+ );
196
+ this.observeElementMount(
197
+ slotId,
198
+ elementId,
199
+ slotElement as HTMLElement,
200
+ index,
201
+ );
202
+ }
203
+ }
204
+
205
+ /**
206
+ * 执行元素移动操作
207
+ * @param slotElement - 插槽元素
208
+ * @param targetElement - 目标元素
209
+ * @param index - 插槽索引,用于日志
210
+ */
211
+ private performMove(
212
+ slotElement: HTMLElement,
213
+ targetElement: HTMLElement,
214
+ index: number,
215
+ ): void {
216
+ try {
217
+ slotElement.appendChild(targetElement);
218
+ console.log(
219
+ `aminofx: ✅ 插槽 ${index + 1} 元素移动成功: ${targetElement.id} -> ${slotElement.id}`,
220
+ );
221
+ } catch (error) {
222
+ console.error(`aminofx: ❌ 插槽 ${index + 1} 元素移动失败:`, error);
223
+ }
224
+ }
225
+
226
+ /**
227
+ * 使用 MutationObserver 监听 elementId 元素的挂载
228
+ * @param slotId - 插槽 DOM id
229
+ * @param elementId - 元素 DOM id
230
+ * @param slotElement - 插槽元素
231
+ * @param index - 插槽索引,用于日志
232
+ */
233
+ private observeElementMount(
234
+ slotId: string,
235
+ elementId: string,
236
+ slotElement: HTMLElement,
237
+ index: number,
238
+ ): void {
239
+ const observer = new MutationObserver((mutations, obs) => {
240
+ const targetElement = document.getElementById(elementId);
241
+
242
+ if (targetElement) {
243
+ console.log(
244
+ `aminofx: 🎯 插槽 ${index + 1} 检测到 elementId "${elementId}" 已挂载`,
245
+ );
246
+
247
+ // 再次检查 slotElement 是否仍然有效(防止弹窗已销毁)
248
+ if (this.container.contains(slotElement)) {
249
+ this.performMove(slotElement, targetElement, index);
250
+ } else {
251
+ console.warn(
252
+ `aminofx: ⚠️ 插槽 ${index + 1} 的 slotId "${slotId}" 已不在 DOM 中`,
253
+ );
254
+ }
255
+
256
+ // 停止观察
257
+ obs.disconnect();
258
+ // 从数组中移除
259
+ const observerIndex = this.slotObservers.indexOf(obs);
260
+ if (observerIndex > -1) {
261
+ this.slotObservers.splice(observerIndex, 1);
262
+ }
263
+ }
264
+ });
265
+
266
+ // 保存 observer 实例,用于销毁时清理
267
+ this.slotObservers.push(observer);
268
+
269
+ // 观察整个 document.body 的子树变化
270
+ observer.observe(document.body, {
271
+ childList: true,
272
+ subtree: true,
273
+ });
274
+ }
275
+
276
+ /**
277
+ * 清理所有 MutationObserver
278
+ */
279
+ private cleanupSlotObservers(): void {
280
+ this.slotObservers.forEach((observer) => {
281
+ observer.disconnect();
282
+ });
283
+ this.slotObservers = [];
284
+ console.log('aminofx: 🧹 清理所有插槽观察器');
285
+ }
286
+
140
287
  private handleLoop() {
141
288
  if (!this.options.autoLoop || !Number(this.options.jsonSchema?.duration)) {
142
289
  return;
@@ -207,6 +354,10 @@ class AnimationPlayer {
207
354
 
208
355
  await Promise.all([jsonPromise, imgPromise]);
209
356
  this.isReady = true; // 设置准备完成状态
357
+
358
+ // 处理插槽列表(此时弹窗内容已渲染,slotId 存在)
359
+ this.handleSlotList();
360
+
210
361
  resolve();
211
362
  console.log('aminofx: 🎉 动画准备完成,可以开始播放');
212
363
  } catch (error) {
@@ -240,6 +391,9 @@ class AnimationPlayer {
240
391
  console.log('aminofx: 🧹 销毁时清理循环定时器');
241
392
  }
242
393
 
394
+ // 清理插槽观察器
395
+ this.cleanupSlotObservers();
396
+
243
397
  // 重置状态
244
398
  this.container.innerHTML = '';
245
399
  this.isReady = false;
package/src/type.ts CHANGED
@@ -17,6 +17,22 @@ interface IPlayerOptions {
17
17
  autoLoop?: boolean;
18
18
  // 动态变量
19
19
  dynamicData?: Record<string, string | number | boolean>;
20
+ // 扩展列表
21
+ extensions?: {
22
+ // 插槽 dom id
23
+ slotId?: string;
24
+ // 元素 dom id
25
+ elementId?: string;
26
+ // 点击区域
27
+ clickAreas?: {
28
+ x?: number;
29
+ y?: number;
30
+ width?: number;
31
+ height?: number;
32
+ };
33
+ }[];
34
+ // 背景颜色
35
+ background?: string;
20
36
  }
21
37
 
22
38
  export type { IPlayerOptions, IJsonSchema };