@ad-execute-manager/ad 2.0.0-alpha.1

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.
@@ -0,0 +1,109 @@
1
+ export default RewardAdGlobalRecorder;
2
+ export type RecordType = "halfway" | "finished" | "completed";
3
+ /**
4
+ * @typedef {'halfway' | 'finished' | 'completed'} RecordType
5
+ */
6
+ declare class RewardAdGlobalRecorder {
7
+ static instance: any;
8
+ /**
9
+ *
10
+ * @param {object} args
11
+ * @param {string} args.sign 初始化标识
12
+ * @returns {RewardAdGlobalRecorder}
13
+ */
14
+ static build(args: {
15
+ sign: string;
16
+ }): RewardAdGlobalRecorder;
17
+ /**
18
+ *
19
+ * @returns {RewardAdGlobalRecorder}
20
+ */
21
+ static getInstance(): RewardAdGlobalRecorder;
22
+ /**
23
+ * @param {object} args
24
+ * @param {string} args.sign 初始化标识
25
+ */
26
+ constructor(args: {
27
+ sign: string;
28
+ });
29
+ _initSign: string;
30
+ /** @type {import('../typings/ad.js').SceneTextMap} */
31
+ _halfway: import("../typings/ad.js").SceneTextMap;
32
+ _finished: {
33
+ scene: number;
34
+ count: number;
35
+ }[];
36
+ /**
37
+ * @param {object} args
38
+ * @param {string} args.sign 初始化标识
39
+ */
40
+ initialize(args: {
41
+ sign: string;
42
+ }): void;
43
+ /**
44
+ * 找到相同的场景值,如果没有则新增
45
+ * @param {object} args
46
+ * @param {RecordType} args.type
47
+ * @param {number} args.scene
48
+ */
49
+ _halfwayUpdate(args: {
50
+ type: RecordType;
51
+ scene: number;
52
+ }): void;
53
+ /**
54
+ * @param {object} args
55
+ * @param {number[]} args.scenes
56
+ * @returns
57
+ */
58
+ _halfwayGet(args: {
59
+ scenes: number[];
60
+ }): any;
61
+ _halfwayReset(): void;
62
+ /**
63
+ * 找到相同的场景值,如果没有则新增
64
+ * @param {object} args
65
+ * @param {RecordType} args.type
66
+ * @param {number} args.scene
67
+ */
68
+ _finishedUpdate(args: {
69
+ type: RecordType;
70
+ scene: number;
71
+ }): void;
72
+ /**
73
+ * @param {object} args
74
+ * @param {number[]} args.scenes
75
+ * @returns
76
+ */
77
+ _finishedGet(args: {
78
+ scenes: number[];
79
+ }): number;
80
+ _finishedReset(): void;
81
+ /**
82
+ * @param {object} args
83
+ * @param {RecordType} args.type
84
+ * @param {number} args.scene
85
+ */
86
+ record(args: {
87
+ type: RecordType;
88
+ scene: number;
89
+ }): void;
90
+ /**
91
+ *
92
+ * @param {RecordType} type
93
+ */
94
+ rest(type: RecordType): void;
95
+ /**
96
+ * @param {object} args
97
+ * @param {number[]} [args.scenes]
98
+ * @param {RecordType} args.type
99
+ */
100
+ get(args: {
101
+ scenes?: number[];
102
+ type: RecordType;
103
+ }): any;
104
+ /**
105
+ * 站位方法,没有任何左右
106
+ * @returns
107
+ */
108
+ placeholder(): any;
109
+ }
@@ -0,0 +1,71 @@
1
+ export default RewardAdSceneTriggerManager;
2
+ /**
3
+ * 场景值枚举 可持续添加
4
+ */
5
+ export type RewardAdTriggerScene = import("../typings/ad.js").RewardAdTriggerScene;
6
+ /**
7
+ * 场景值枚举 可持续添加
8
+ * @typedef {import('../typings/ad.js').RewardAdTriggerScene} RewardAdTriggerScene
9
+ */
10
+ declare class RewardAdSceneTriggerManager {
11
+ static instance: any;
12
+ /**
13
+ *
14
+ * @param {object} args
15
+ * @param {string} args.sign 初始化标识
16
+ * @param {import('../typings/ad.js').SceneTypeMap} args.sceneTypeObj 当前场景sceneTypeMap 场景值类型映射表
17
+ * @returns {RewardAdSceneTriggerManager}
18
+ */
19
+ static build(args: {
20
+ sign: string;
21
+ sceneTypeObj: import("../typings/ad.js").SceneTypeMap;
22
+ }): RewardAdSceneTriggerManager;
23
+ /**
24
+ *
25
+ * @returns {RewardAdSceneTriggerManager}
26
+ */
27
+ static getInstance(): RewardAdSceneTriggerManager;
28
+ /**
29
+ * @param {object} args
30
+ * @param {string} args.sign 初始化标识
31
+ * @param {import('../typings/ad.js').SceneTypeMap} args.sceneTypeObj 当前场景sceneTypeMap 场景值类型映射表
32
+ */
33
+ constructor(args: {
34
+ sign: string;
35
+ sceneTypeObj: import("../typings/ad.js").SceneTypeMap;
36
+ });
37
+ _initSign: string;
38
+ /** @type {RewardAdTriggerScene} */
39
+ _currScene: RewardAdTriggerScene;
40
+ /** @type {import('../typings/ad.js').SceneTypeMap} */
41
+ _sceneTypeObj: import("../typings/ad.js").SceneTypeMap;
42
+ /**
43
+ * @param {object} args
44
+ * @param {string} args.sign 初始化标识
45
+ */
46
+ initialize(args: {
47
+ sign: string;
48
+ }): void;
49
+ /**
50
+ * 获取场景值
51
+ * @param {RewardAdTriggerScene} value 场景值
52
+ * @returns
53
+ */
54
+ addScene(value: RewardAdTriggerScene): this;
55
+ /**
56
+ * 获取场景值
57
+ * @param {import('../typings/ad.js').RewardAdTriggerSceneType} value 场景值类型
58
+ * @returns
59
+ */
60
+ addSceneType(value?: import("../typings/ad.js").RewardAdTriggerSceneType): this;
61
+ /**
62
+ * 获取当前场景值
63
+ * @returns
64
+ */
65
+ getCurrentScene(): string;
66
+ /**
67
+ * 站位方法,没有任何左右
68
+ * @returns
69
+ */
70
+ placeholder(): any;
71
+ }
@@ -0,0 +1,9 @@
1
+ export class SerializableError extends Error {
2
+ constructor(message: any);
3
+ stack: string;
4
+ toJSON(): {
5
+ name: string;
6
+ message: string;
7
+ stack: string;
8
+ };
9
+ }
@@ -0,0 +1,124 @@
1
+ export default Storage;
2
+ export type StorageOptions = {
3
+ /**
4
+ * 存储key的前缀
5
+ */
6
+ prefix?: string;
7
+ /**
8
+ * 默认过期时间(毫秒),null表示永不过期
9
+ */
10
+ expire?: number | null;
11
+ /**
12
+ * 用户ID
13
+ */
14
+ userId?: string | number;
15
+ };
16
+ /**
17
+ * @example
18
+ const storage = new Storage({
19
+ prefix: 'myapp_',
20
+ });
21
+
22
+ // 设置当天有效的数据
23
+ *storage.setItem('dailyTask', { completed: false }, 'today');
24
+
25
+ // 设置普通带过期时间的数据(2小时)
26
+ storage.setItem('tempData', { value: 123 }, 2 * 60 * 60 * 1000);
27
+
28
+ // 设置永久有效的数据
29
+ storage.setItem('userSettings', { theme: 'dark' });
30
+
31
+ // 获取数据
32
+ const dailyTask = storage.getStorageSync('dailyTask');
33
+ const tempData = storage.getStorageSync('tempData');
34
+ const userSettings = storage.getStorageSync('userSettings');
35
+
36
+ console.log('Daily Task:', dailyTask);
37
+ console.log('Temp Data:', tempData);
38
+ console.log('User Settings:', userSettings);
39
+ */
40
+ declare class Storage {
41
+ /**
42
+ * @param {StorageOptions=} args
43
+ * @returns
44
+ */
45
+ static "new"(args?: StorageOptions | undefined): Storage;
46
+ /**
47
+ * @param {StorageOptions} [options]
48
+ */
49
+ constructor(options?: StorageOptions);
50
+ config: {
51
+ /**
52
+ * 存储key的前缀
53
+ */
54
+ prefix: string;
55
+ /**
56
+ * 默认过期时间(毫秒),null表示永不过期
57
+ */
58
+ expire: number | null;
59
+ /**
60
+ * 用户ID
61
+ */
62
+ userId?: string | number;
63
+ };
64
+ logger: Logger;
65
+ /**
66
+ * 获取当天结束时间的时间戳
67
+ * @returns {number} 当天23:59:59的时间戳
68
+ */
69
+ getTodayEndTimestamp(): number;
70
+ /**
71
+ * 设置存储项 - 内部使用
72
+ * @param {string} key 存储键
73
+ * @param {any} value 存储值
74
+ * @param {number|'today'} expire 过期时间(毫秒)或'today'表示当天有效,可选
75
+ */
76
+ _setItem(storageKey: any, value: any, expire: number | "today"): void;
77
+ /**
78
+ * 获取存储项 - 内部使用
79
+ * @param {string} key 存储键
80
+ * @returns {any} 存储的值,如果过期或不存在则返回null
81
+ */
82
+ _getItem(storageKey: any): any;
83
+ /**
84
+ * 设置存储项
85
+ * @param {string} key 存储键
86
+ * @param {any} value 存储值
87
+ * @param {number|'today'} expire 过期时间(毫秒)或'today'表示当天有效,可选
88
+ */
89
+ setItem(key: string, value: any, expire: number | "today"): void;
90
+ /**
91
+ * 获取存储项
92
+ * @param {string} key 存储键
93
+ * @returns {any} 存储的值,如果过期或不存在则返回null
94
+ */
95
+ getItem(key: string): any;
96
+ /**
97
+ * 获取存储项 - 用户维度
98
+ * @param {string} key 存储键
99
+ * @returns {any} 存储的值,如果过期或不存在则返回null
100
+ */
101
+ getUserItem(key: string): any;
102
+ /**
103
+ * 设置存储项 - 用户维度
104
+ * @param {string} key 存储键
105
+ * @param {any} value 存储值
106
+ * @param {number|'today'} expire 过期时间(毫秒)或'today'表示当天有效,可选
107
+ */
108
+ setUserItem(key: string, value: any, expire: number | "today"): void;
109
+ /**
110
+ * 删除存储项
111
+ * @param {string} key 存储键
112
+ */
113
+ removeItem(key: string): void;
114
+ /**
115
+ * 清空所有存储项
116
+ */
117
+ clear(): void;
118
+ /**
119
+ * 获取所有未过期的存储键
120
+ * @returns {string[]} 键数组
121
+ */
122
+ keys(): string[];
123
+ }
124
+ import { Logger } from './Logger';
@@ -0,0 +1,10 @@
1
+ export { CountRecorder } from "./CountRecorder.js";
2
+ export { Logger } from "./Logger.js";
3
+ export { SerializableError } from "./SerializableError.js";
4
+ export { default as Storage } from "./Storage.js";
5
+ export { default as PubSub } from "./PubSub.js";
6
+ export { EventEmitter } from "./EventEmitter.js";
7
+ export { default as AdAnalyticsJS } from "./AdAnalyticsJS.js";
8
+ export { default as LovelUnlockManager } from "./LovelUnlockManager.js";
9
+ export { default as RewardAdGlobalRecorder } from "./RewardAdGlobalRecorder.js";
10
+ export { default as RewardAdSceneTriggerManager } from "./RewardAdSceneTriggerManager.js";
@@ -0,0 +1,15 @@
1
+ export default AdExecuteManager;
2
+ import AdExecuteManager from './core/AdExecuteManager';
3
+ import RewardAdFather from './ad/RewardAdFather';
4
+ import { SerializableError } from './helper/SerializableError';
5
+ import { Logger } from './helper/Logger';
6
+ import Storage from './helper/Storage';
7
+ import { CountRecorder } from './helper/CountRecorder';
8
+ import RewardAdGlobalRecorder from './helper/RewardAdGlobalRecorder';
9
+ import RewardAdSceneTriggerManager from './helper/RewardAdSceneTriggerManager';
10
+ import AdAnalyticsJS from './helper/AdAnalyticsJS';
11
+ import RewardAdNovel from './ad/RewardAdNovel';
12
+ import InterstitialAdFather from './ad/InterstitialAdFather';
13
+ import InterstitialAdNovel from './ad/InterstitialAdNovel';
14
+ import PubSub from './helper/PubSub';
15
+ export { AdExecuteManager, RewardAdFather, SerializableError, Logger, Storage, CountRecorder, RewardAdGlobalRecorder, RewardAdSceneTriggerManager, AdAnalyticsJS, RewardAdNovel, InterstitialAdFather, InterstitialAdNovel, PubSub };
package/dist/index.js ADDED
@@ -0,0 +1 @@
1
+ "use strict";const __rslib_import_meta_url__="u"<typeof document?new(require("url".replace("",""))).URL("file:"+__filename).href:document.currentScript&&document.currentScript.src||new URL("main.js",document.baseURI).href;var __webpack_require__={};__webpack_require__.d=(e,t)=>{for(var i in t)__webpack_require__.o(t,i)&&!__webpack_require__.o(e,i)&&Object.defineProperty(e,i,{enumerable:!0,get:t[i]})},__webpack_require__.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),__webpack_require__.r=e=>{"u">typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var __webpack_exports__={};__webpack_require__.r(__webpack_exports__),__webpack_require__.d(__webpack_exports__,{RewardAdNovel:()=>ad_RewardAdNovel,RewardAdFather:()=>ad_RewardAdFather,InterstitialAdFather:()=>ad_InterstitialAdFather,InterstitialAdNovel:()=>ad_InterstitialAdNovel});const compose=e=>e.map(e=>(t,i)=>async s=>await e(Object.assign({},t,s),i)).reduce((e,t)=>(i,s)=>e(i,t(i,s))),core_compose=compose;class Logger{constructor(e={}){const{prefix:t="Logger",level:i="log",enabled:s=!0}=e;this.prefix=t,this.enabled=s,this.levels={error:0,warn:1,info:2,log:3,debug:4},this.currentLevel=this.levels[i]||this.levels.log}enable(){this.enabled=!0}disable(){this.enabled=!1}isEnabled(){return this.enabled}setLevel(e){Object.prototype.hasOwnProperty.call(this.levels,e)&&(this.currentLevel=this.levels[e])}formatMessage(e,t){let i=new Date,s=`${i.getFullYear()}/${i.getMonth()+1}/${i.getDate()} ${i.getHours()}:${i.getMinutes()}:${i.getSeconds()}`;return`[${s}] [${e.toUpperCase()}] [${this.prefix}] ${t}`}_log(e,t,...i){if(!this.enabled)return;let s=this.levels[e];if(void 0!==s&&this.currentLevel>=s){let s=this.formatMessage(e,t);switch(e){case"error":console.error(s,...i);break;case"warn":console.warn(s,...i);break;case"info":console.info(s,...i);break;case"log":default:console.log(s,...i);break;case"debug":console.debug(s,...i)}}}error(e,...t){this._log("error",e,...t)}warn(e,...t){this._log("warn",e,...t)}info(e,...t){this._log("info",e,...t)}log(e,...t){this._log("log",e,...t)}debug(e,...t){this._log("debug",e,...t)}}class AdExecuteManager{static _instance=null;_taskStack=[];_currentBatchTasks=[];_isRunning=!1;_currentTask=null;constructor(e){if(this.logger=new Logger({prefix:"AdExecuteManager",enabled:!!e?.log}),AdExecuteManager._instance)return AdExecuteManager._instance;AdExecuteManager._instance=this}static getInstance(e){return AdExecuteManager._instance||(AdExecuteManager._instance=new AdExecuteManager(e)),AdExecuteManager._instance}static getSafeInstance(){return AdExecuteManager._instance?AdExecuteManager._instance:(this.logger.error("AdExecuteManager实例不存在"),null)}addTask(e,t){return e&&"function"==typeof e.ad?new Promise((i,s)=>{let r={adInstance:e,options:t.options??{},callbackCollection:t.collection??{},resolve:i,reject:s,id:`ad_${Date.now()}_${Math.random().toString(36).substr(2,9)}`,_isResolved:!1,_isRejected:!1};this._taskStack.push(r),this._isRunning||this._compose()}):(this.logger.error("无效的广告实例 请正确实现.ad方法"),Promise.reject(Error("无效的广告实例")))}_compose(){if(0===this._taskStack.length){this._isRunning=!1,this._currentTask=null;return}this._isRunning=!0;let e=[...this._taskStack];this._taskStack=[],this._currentBatchTasks=e;let t=e.map(e=>async(t,i)=>{let{adInstance:s,options:r,callbackCollection:n,resolve:l,id:o}=e;if(e._isResolved||e._isRejected)return void await i(t);this._currentTask=e;try{let a=async e=>{await i(Object.assign({},t,e))},d=await s.initialize(r).ad({options:r,collection:n},a),h=Object.assign({id:o},d);this.logger.info(`任务执行成功,成功信息:${JSON.stringify(h)}`),e._isResolved=!0,l(h),s?.record(h)}catch(n){let r=Object.assign({id:o,apiError:n});this.logger.error(`任务执行失败, 继续下一个任务,错误信息:${JSON.stringify(r)}`),e._isRejected=!0;try{s?.clear()}catch(e){this.logger.error("clear error: ",JSON.stringify(Object.assign({id:o,apiError:e})))}l(r),s?.record(r),await i(t)}}),i={roundTasks:t.length};compose(t)(i,async e=>{this.logger.info("本轮活动队列已经清空",e),this._taskStack.length>0?Promise.resolve().then(()=>{this._compose()}):(this._isRunning=!1,this._currentTask=null,this._currentBatchTasks=[])})()}clearTasks(){if(this._currentTask){if(this._currentTask._isResolved||this._currentTask._isRejected){this._currentTask=null;return}try{this._currentTask.callbackCollection&&this._currentTask.callbackCollection.onCancel&&this._currentTask.callbackCollection.onCancel(),this._currentTask._isResolved=!0,this._currentTask.resolve()}catch(e){this.logger.error("clear current task error: ",e)}this._currentTask=null}this._currentBatchTasks.length>0&&(this._currentBatchTasks.forEach(e=>{if(e!==this._currentTask&&!e._isResolved&&!e._isRejected)try{e.callbackCollection&&e.callbackCollection.onCancel&&e.callbackCollection.onCancel(),e._isResolved=!0,e.resolve()}catch(e){this.logger.error("clear current batch task error: ",e)}}),this._currentBatchTasks=[]),this._taskStack.forEach(e=>{if(!e._isResolved&&!e._isRejected&&(e._isResolved=!0,e.resolve(),e.callbackCollection&&e.callbackCollection.onCancel))try{e.callbackCollection.onCancel()}catch(e){this.logger.error("clear task error: ",e)}}),this._taskStack=[],this._isRunning=!1}getTaskCount(){return this._taskStack.filter(e=>!e._isResolved&&!e._isRejected).length+this._currentBatchTasks.filter(e=>e!==this._currentTask&&!e._isResolved&&!e._isRejected).length+(!this._currentTask||this._currentTask._isResolved||this._currentTask._isRejected?0:1)}isRunning(){return this._isRunning}getCurrentTaskId(){return this._currentTask?.id||null}whenAllTasksComplete(){return new Promise(e=>{let t=null,i=()=>{let s=0===this._taskStack.length,r=!this._isRunning,n=null===this._currentTask,l=0===this._currentBatchTasks.length||this._currentBatchTasks.every(e=>e._isResolved||e._isRejected);s&&r&&n&&l?(t&&clearTimeout(t),e()):t=setTimeout(i,500)};i()})}}const core_AdExecuteManager=AdExecuteManager;class SerializableError extends Error{constructor(e){super(e),this.name=this.constructor.name,this.stack=Error(e).stack,Object.defineProperty(this,"message",{enumerable:!0}),Object.defineProperty(this,"name",{enumerable:!0}),Object.defineProperty(this,"stack",{enumerable:!0})}toJSON(){return{name:this.name,message:this.message,stack:this.stack}}}class RewardAdFather{static args=null;_initSign="";_preserveOnEnd=!1;_rewardAd=null;_ttErrorMsgs=["The adUnitId is closed","The adUnitId is prohibit","The adUnitId is invalid","The adUnitId is empty","feature is not supported in app"];_ttErrorCodes=[139902,123302];constructor(e){this._initSign=e?.sign??"",this._adConfig=e?.adConfig??{},this._preserveOnEnd=e?.preserveOnEnd??!1}initialize(e,t){if(this._rewardAd)return console.warn("RewardAdFather: rewardAd has been initialized"),t?.(this._rewardAd),this;let i=Object.assign({},RewardAdFather.args,this._adConfig,e);if(!i.adUnitId)throw console.error("[RewardAdFather] reward args adUnitId is required",i),new SerializableError("[RewardAdFather] reward args adUnitId is required");return this._rewardAd=tt.createRewardedVideoAd(i),t?.(this._rewardAd),this}initialized(){return!!this._rewardAd}async ad(e,t=null){throw Error("子类必须实现ad方法")}async addExecuteManager(e){let t=Object.assign({},this._adConfig,e?.options??{});return RewardAdFather.executeWithManager(this,Object.assign({},e,{options:t}))}destroy(){this._rewardAd&&!this._preserveOnEnd&&(this._rewardAd.destroy(),this._rewardAd=null)}clear(){throw Error("子类必须实现clear方法")}record(e){return this}onClose(e){this._rewardAd&&this._rewardAd.onClose(e)}offClose(e){this._rewardAd&&this._rewardAd.offClose(e)}show(){return this._rewardAd?this._rewardAd.show():Promise.reject({errMsg:"rewardAd is null"})}load(){return this._rewardAd?this._rewardAd.load():Promise.reject({errMsg:"rewardAd is null"})}onError(e){this._rewardAd&&this._rewardAd.onError(e)}offError(e){this._rewardAd&&this._rewardAd.offError(e)}onLoad(e){this._rewardAd&&this._rewardAd.onLoad(e)}offLoad(e){this._rewardAd&&this._rewardAd.offLoad(e)}placeholder(){return null}static buildArgs(e){e?.adUnitId||console.error("[RewardAdFather] RewardParams.adUnitId is required"),RewardAdFather.args=e}static async executeWithManager(e,t){return e&&e instanceof RewardAdFather?AdExecuteManager.getInstance({log:t?.options?.log??!0}).addTask(e,t):(console.error("RewardAdFather: executeWithManager - 无效的广告实例"),Promise.reject(Error("无效的广告实例")))}}const ad_RewardAdFather=RewardAdFather;function matchErrorWithKeywords(e,t){return!!t&&e.some(e=>RegExp(e,"i").test(t))}function getAdSceneTextObj(e){return Object.entries(e).reduce((e,[t,i])=>(e[i]=Number(t),e),{})}const DEFAULT_SCENT_TYPE_OBJ={9999:"inner_default_other"},DEFAULT_SCENT_TEXT_OBJ=getAdSceneTextObj(DEFAULT_SCENT_TYPE_OBJ),AD_TYPE_ENUM={AD_TYPE_REWARD:1,AD_TYPE_INTERSTITIAL:2},AD_TYPE_ENUM_REVERSE=Object.entries(AD_TYPE_ENUM).reduce((e,[t,i])=>(e[i]=t,e),{});class RewardAdNovel extends ad_RewardAdFather{_onHalfway=null;_onShow=null;_onFinish=null;_onAlways=null;_onError=null;_initSign="";_alwaysCallback=null;_halfwayCallback=null;_finishedCallback=null;_resolve=null;_next=null;_scene=DEFAULT_SCENT_TEXT_OBJ.inner_default_other;_adTypeR=AD_TYPE_ENUM.AD_TYPE_REWARD;_adTimeout=null;_adTimeoutTime=8e3;_adBeforeShowTimer=null;_adBeforeShowTime=300;_adSpeedCloseTimer=null;_adSpeedCloseTime=5e3;_needEndOnTimeout=!0;_needSpeedEndOnTimeout=!1;bindAdCloseLister=this.adCloseLister.bind(this);bindAdErrorLister=this.adErrorLister.bind(this);bindAdLoadLister=this.adLoadLister.bind(this);bindApiAdErrorLister=this.apiAdErrorLister.bind(this);_bindShiftCloseLister=this._shiftCloseLister.bind(this);_bindShiftErrorLister=this._shiftErrorLister.bind(this);constructor(e){super(e),this._initSign=e?.sign??"",this._adConfig=e?.adConfig??{},this._needEndOnTimeout=e?.needEndOnTimeout??!0,this._onHalfway=e?.collection?.onHalfway??null,this._onShow=e?.collection?.onShow??null,this._onFinish=e?.collection?.onFinish??null,this._onAlways=e?.collection?.onAlways??null,this._onError=e?.collection?.onError??null}initialize(e,t){return super.initialize(e,t),this._initAdLister(),this._initNovelConfig(e),this}_initAdLister(){this.onClose(this.bindAdCloseLister),this.onError(this.bindAdErrorLister),this.onLoad(this.bindAdLoadLister),tt.onError(this.bindApiAdErrorLister)}_initNovelConfig(e){this.novelConfig=RewardAdNovelConfig.new({retry:e?.retry})}_onInnerExecuteBefore(){return null}_onInnerAdShowSuccess(){return null}_setAdTimeout(e){if(this._needSpeedEndOnTimeout&&(this._adSpeedCloseTimer=setTimeout(()=>{if("ios"==tt.getSystemInfoSync().platform){let t=()=>{tt.offAppShow(t),console.warn("[RewardAdNovel] ad_show_timeout: ios platform close ad onAppShow, handling fallback ad case, scene:",e?.scene);let i="ad_show_timeout: ios platform close ad onAppShow";this._adShowFailureAnalytics({scene:e?.scene,msg:i,errorCode:0,result:0}),this._adTimeout&&clearTimeout(this._adTimeout),e?.end({resolvedValue:{apiError:{errMsg:i}},nextValue:null})};tt.onAppShow(t)}clearTimeout(this._adSpeedCloseTimer)},this._adSpeedCloseTime)),this._needEndOnTimeout){let t=e?.timeout??this._adTimeoutTime;this._adTimeout=setTimeout(()=>{console.warn("[RewardAdNovel] Ad show timeout, handling fallback ad case,",`scene: ${e?.scene},timeout: ${t}`),this._adShowFailureAnalytics({scene:e?.scene,msg:"ad_show_timeout: normal",errorCode:0,result:0}),e?.end({resolvedValue:{apiError:{errMsg:"ad_show_timeout: normal",errorCode:0}},nextValue:null})},t)}}_adPreludeInterval(e){e.prelude?.({scene:e?.scene,frequency:this._adBeforeShowTime,time:new Date().getTime()}),this._adBeforeShowTimer=setInterval(()=>{e.prelude?.({scene:e?.scene,frequency:this._adBeforeShowTime,time:new Date().getTime()})},this._adBeforeShowTime)}_clearAdTimeout(){this._adTimeout&&(clearTimeout(this._adTimeout),this._adTimeout=null),this._adBeforeShowTimer&&(clearTimeout(this._adBeforeShowTimer),this._adBeforeShowTimer=null),this._adSpeedCloseTimer&&(clearTimeout(this._adSpeedCloseTimer),this._adSpeedCloseTimer=null)}_adShowBeforeAnalytics(e){return null}_adShowSuccessAnalytics(e){return null}_adShowFailureAnalytics(e){return null}_adLoadSuccessAnalytics(e){return null}_adLoadFailureAnalytics(e){return null}_adCloseSuccessAnalytics(e){return null}get rewardAd(){return this._rewardAd}addExecuteManager(e){return super.addExecuteManager(e)}ad(e,t=null){return this._alwaysCallback=e?.collection?.always,this._halfwayCallback=e?.collection?.halfway,this._finishedCallback=e?.collection?.finished,this._onInnerExecuteBefore(),new Promise(i=>{this._adInner({options:{scene:e?.options?.scene,timeout:e?.options?.timeout},collection:{resolve:i,before:e.collection?.before,success:e.collection?.success,prelude:e.collection?.prelude}},t)})}_adInner(e,t=null){let i=e?.collection?.resolve,s=e?.options?.scene??this._scene??DEFAULT_SCENT_TEXT_OBJ.inner_default_other,r=e?.collection?.before,n=e?.collection?.success,l=e?.collection?.prelude,o=e=>{this._clearAdTimeout(),this.adDestroy(),i?.(Object.assign({scene:s,adTypeR:this._adTypeR},e?.resolvedValue)),t?.(Object.assign({scene:s},e?.nextValue))},a=()=>{this._scene=s,r?.({scene:s}),this._before=r,this._onShow?.({scene:s}),this._adShowBeforeAnalytics({scene:s}),this._resolve=i,this._next=t,this._setAdTimeout({scene:s,end:o,timeout:e?.options?.timeout}),this._adPreludeInterval({scene:s,prelude:l}),this.adShow().then(()=>{this._clearAdTimeout(),n?.({scene:s}),this._success=n,this._adShowSuccessAnalytics({scene:s,result:1}),this._onInnerAdShowSuccess()}).catch(e=>{(this._clearAdTimeout(),this._adShowFailureAnalytics({scene:s,msg:e?.errMsg,errorCode:e?.errorCode,result:0}),matchErrorWithKeywords(this._ttErrorMsgs,e?.errMsg)||this._ttErrorCodes.includes(e?.errorCode))?o({scene:s,resolvedValue:{apiError:e},nextValue:null}):0>=this.novelConfig.remain()?o({scene:s,resolvedValue:null,nextValue:null}):(this.novelConfig.updateRetry(),this.adLoad().then(()=>{this._adLoadSuccessAnalytics({scene:s,result:1}),a()}).catch(e=>{this._adLoadFailureAnalytics({scene:s,msg:e?.errMsg,result:0}),o({scene:s,resolvedValue:{apiError:e},nextValue:null})}))})};a()}adLoad(){return this.load()}adShow(){return this.show()}_outerCloseCallback(e){this._alwaysCallback?.(e)}_outerHalfwayCallback(e){this._halfwayCallback?.(e)}_outerFinishedCallback(e){this._finishedCallback?.(e)}adCloseLister(e){this._clearAdTimeout(),this._adCloseSuccessAnalytics({scene:this._scene,ad_is_completed:+!!e.isEnded,ad_count:e.count});let t={...e,scene:this._scene},i=t=>{this.adDestroy(),this._resolve?.(Object.assign({},e,{scene:this._scene,adTypeR:this._adTypeR},t)),this._resolve=null,this._next?.(),this._next=null,this._success=null,this._before=null};e?.isEnded?(this._outerFinishedCallback(t),this._onFinish?.(t)):(this._outerHalfwayCallback(t),this._onHalfway?.(t)),this._outerCloseCallback(t),this._onAlways?.(t),i({end_type:e.isEnded?"finished":"halfway"})}adErrorLister(e){this._clearAdTimeout(),console.error("[RewardAdNovel] adErrorLister",JSON.stringify(e)),this._adShowFailureAnalytics({scene:this._scene,msg:e?.errMsg,errorCode:e?.errorCode,result:0}),this.adDestroy(),this._onError?.(e),this._resolve?.({apiError:e,scene:this._scene,adTypeR:this._adTypeR}),this._resolve=null,this._next?.(),this._next=null,this._success=null,this._before=null}apiAdErrorLister(e){this._clearAdTimeout(),console.error("[API RewardAdNovel] apiAdErrorLister:",JSON.stringify(e)),this._adShowFailureAnalytics({scene:this._scene,msg:e?.errMsg,errorCode:e?.errorCode,result:0}),this.adDestroy(),this._onError?.(e),this._resolve?.({apiError:e,scene:this._scene,adTypeR:this._adTypeR}),this._resolve=null,this._next?.(),this._next=null,this._success=null,this._before=null}adLoadLister(e){this._adLoadSuccessAnalytics({scene:this._scene,result:1,msg:e?.errMsg}),console.info("[RewardAdNovel] adLoadLister:",JSON.stringify({scene:this._scene,info:e}))}adDestroy(){this.offClose(this.bindAdCloseLister),this.offError(this.bindAdErrorLister),this.offLoad(this.bindAdLoadLister),tt.offError(this.bindApiAdErrorLister),this._onHalfway=null,this._onFinish=null,this._onAlways=null,this._onShow=null,this._onError=null,this._alwaysCallback=null,this._halfwayCallback=null,this._finishedCallback=null,this.destroy()}clear(){this._clearAdTimeout(),this.offClose(this.bindAdCloseLister),this.offClose(this._bindShiftCloseLister),this.offError(this.bindAdErrorLister),this.offError(this._bindShiftErrorLister),this.offLoad(this.bindAdLoadLister),tt.offError(this.bindApiAdErrorLister),this._onHalfway=null,this._onFinish=null,this._onAlways=null,this._onShow=null,this._onError=null,this._alwaysCallback=null,this._halfwayCallback=null,this._finishedCallback=null,this.destroy(),this._resolve=null,this._next=null,this._success=null,this._before=null}_shiftCloseLister(e){this._clearAdTimeout(),this.offError(this._bindShiftErrorLister),this.offLoad(this.bindAdLoadLister),tt.offError(this.bindApiAdErrorLister),this._onHalfway=null,this._onFinish=null,this._onAlways=null,this._onShow=null,this._onError=null,this._alwaysCallback=null,this._halfwayCallback=null,this._finishedCallback=null,this.offClose(this._bindShiftCloseLister),this.destroy(),this._resolve?.(Object.assign({},e,{scene:this._scene,adTypeR:this._adTypeR})),this._resolve=null,this._next?.(),this._next=null,this._success=null,this._before=null}_shiftErrorLister(e){this._clearAdTimeout(),this.offClose(this._bindShiftCloseLister),this.offLoad(this.bindAdLoadLister),tt.offError(this.bindApiAdErrorLister),this._onHalfway=null,this._onFinish=null,this._onAlways=null,this._onShow=null,this._onError=null,this._alwaysCallback=null,this._halfwayCallback=null,this._finishedCallback=null,this.offError(this._bindShiftErrorLister),this.destroy(),this._resolve?.(Object.assign({},e,{scene:this._scene,adTypeR:this._adTypeR})),this._resolve=null,this._next?.(),this._next=null,this._success=null,this._before=null}shift(){this.offClose(this.bindAdCloseLister),this.onClose(this._bindShiftCloseLister),this.offError(this.bindAdErrorLister),this.onError(this._bindShiftErrorLister)}static build(e){return RewardAdNovel.instance||(RewardAdNovel.instance=new RewardAdNovel(e)),RewardAdNovel.instance}static getInstance(){if(!RewardAdNovel.instance)throw Error("RewardAdNovel instance is not init");return RewardAdNovel.instance}static new(e){return new RewardAdNovel(e)}}class RewardAdNovelConfig{frequency={total:0,current:0};constructor(e){this._init(e)}_init(e){this._adTimes(e)}_adTimes(e){this.frequency.total=e?.retry??4}reset(){this.frequency.current=0}updateRetry(){this.frequency.current=this.frequency.current+1}remain(){return this.frequency.total-this.frequency.current}static new(e){return new RewardAdNovelConfig(e)}}const ad_RewardAdNovel=RewardAdNovel;class InterstitialAdFather{static args=null;_initSign="";_preserveOnEnd=!1;_interstitialAd=null;_ttErrorMsgs=["The adUnitId is closed","The adUnitId is prohibit","The adUnitId is invalid","The adUnitId is empty","feature is not supported in app"];_ttErrorCodes=[139902,123302,140502];constructor(e){this._initSign=e?.sign??"",this._adConfig=e?.adConfig??{},this._preserveOnEnd=e?.preserveOnEnd??!1}initialize(e,t){if(this._interstitialAd)return console.warn("InterstitialAdFather: interstitialAd has been initialized"),t?.(this._interstitialAd),this;let i=Object.assign({},InterstitialAdFather.args,this._adConfig,e);if(!i.adUnitId)throw console.error("[InterstitialAdFather] interstitialAd args adUnitId is required",i),new SerializableError("[InterstitialAdFather] interstitialAd args adUnitId is required");return this._interstitialAd=tt.createInterstitialAd(i),t?.(this._interstitialAd),this}initialized(){return!!this._interstitialAd}async ad(e,t=null){throw Error("子类必须实现ad方法")}async addExecuteManager(e){let t=Object.assign({},this._adConfig,e?.options??{});return InterstitialAdFather.executeWithManager(this,Object.assign({},e,{options:t}))}destroy(){this._interstitialAd&&!this._preserveOnEnd&&(this._interstitialAd.destroy(),this._interstitialAd=null)}clear(){throw Error("子类必须实现clear方法")}record(e){return this}onClose(e){this._interstitialAd&&this._interstitialAd.onClose(e)}offClose(e){this._interstitialAd&&this._interstitialAd.offClose(e)}show(){return this._interstitialAd?this._interstitialAd.show():Promise.reject({errMsg:"interstitialAd is null"})}load(){return this._interstitialAd?this._interstitialAd.load():Promise.reject({errMsg:"interstitialAd is null"})}onError(e){this._interstitialAd&&this._interstitialAd.onError(e)}offError(e){this._interstitialAd&&this._interstitialAd.offError(e)}onLoad(e){this._interstitialAd&&this._interstitialAd.onLoad(e)}offLoad(e){this._interstitialAd&&this._interstitialAd.offLoad(e)}placeholder(){return null}static buildArgs(e){e?.adUnitId||console.error("[InterstitialAdFather] interstitialAdParams.adUnitId is required"),InterstitialAdFather.args=e}static async executeWithManager(e,t){return e&&e instanceof InterstitialAdFather?AdExecuteManager.getInstance({log:t?.options?.log??!0}).addTask(e,t):(console.error("InterstitialAdFather: executeWithManager - 无效的广告实例"),Promise.reject(Error("无效的广告实例")))}}const ad_InterstitialAdFather=InterstitialAdFather;class InterstitialAdNovel extends ad_InterstitialAdFather{_onHalfway=null;_onShow=null;_onFinish=null;_onAlways=null;_onError=null;_initSign="";_alwaysCallback=null;_halfwayCallback=null;_finishedCallback=null;_resolve=null;_next=null;_scene=DEFAULT_SCENT_TEXT_OBJ.inner_default_other;_adTypeR=AD_TYPE_ENUM.AD_TYPE_INTERSTITIAL;_adTimeout=null;_adTimeoutTime=8e3;_adBeforeShowTimer=null;_adBeforeShowTime=300;_adSpeedCloseTimer=null;_adSpeedCloseTime=5e3;_needEndOnTimeout=!0;_needSpeedEndOnTimeout=!1;bindAdCloseLister=this.adCloseLister.bind(this);bindAdErrorLister=this.adErrorLister.bind(this);bindAdLoadLister=this.adLoadLister.bind(this);bindApiAdErrorLister=this.apiAdErrorLister.bind(this);_bindShiftCloseLister=this._shiftCloseLister.bind(this);_bindShiftErrorLister=this._shiftErrorLister.bind(this);constructor(e){super(e),this._initSign=e?.sign??"",this._adConfig=e?.adConfig??{},this._needEndOnTimeout=e?.needEndOnTimeout??!0,this._onHalfway=e?.collection?.onHalfway??null,this._onShow=e?.collection?.onShow??null,this._onFinish=e?.collection?.onFinish??null,this._onAlways=e?.collection?.onAlways??null,this._onError=e?.collection?.onError??null}initialize(e,t){return super.initialize(e,t),this._initAdLister(),this._initNovelConfig(e),this}_initAdLister(){this.onClose(this.bindAdCloseLister),this.onError(this.bindAdErrorLister),this.onLoad(this.bindAdLoadLister),tt.onError(this.bindApiAdErrorLister)}_initNovelConfig(e){this.novelConfig=InterstitialAdNovel_RewardAdNovelConfig.new({retry:e?.retry})}_onInnerExecuteBefore(){return null}_onInnerAdShowSuccess(){return null}_setAdTimeout(e){this._needSpeedEndOnTimeout&&(this._adSpeedCloseTimer=setTimeout(()=>{if("ios"==tt.getSystemInfoSync().platform){let t=()=>{tt.offAppShow(t),console.warn("[InterstitialAdNovel] ad_show_timeout: ios platform close ad onAppShow, handling fallback ad case, scene:",e?.scene);let i="ad_show_timeout: ios platform close ad onAppShow";this._adShowFailureAnalytics({scene:e?.scene,msg:i,errorCode:0,result:0}),this._adTimeout&&clearTimeout(this._adTimeout),e?.end({resolvedValue:{apiError:{errMsg:i}},nextValue:null})};tt.onAppShow(t)}clearTimeout(this._adSpeedCloseTimer)},this._adSpeedCloseTime)),this._needEndOnTimeout&&(this._adTimeout=setTimeout(()=>{console.warn("[InterstitialAdNovel] Ad show timeout, handling fallback ad case, scene:",e?.scene),this._adShowFailureAnalytics({scene:e?.scene,msg:"ad_show_timeout: normal",errorCode:0,result:0}),e?.end({resolvedValue:{apiError:{errMsg:"ad_show_timeout: normal"}},nextValue:null})},this._adTimeoutTime))}_adPreludeInterval(e){e.prelude?.({scene:e?.scene,frequency:this._adBeforeShowTime,time:new Date().getTime()}),this._adBeforeShowTimer=setInterval(()=>{e.prelude?.({scene:e?.scene,frequency:this._adBeforeShowTime,time:new Date().getTime()})},this._adBeforeShowTime)}_clearAdTimeout(){this._adTimeout&&(clearTimeout(this._adTimeout),this._adTimeout=null),this._adBeforeShowTimer&&(clearTimeout(this._adBeforeShowTimer),this._adBeforeShowTimer=null),this._adSpeedCloseTimer&&(clearTimeout(this._adSpeedCloseTimer),this._adSpeedCloseTimer=null)}_adShowBeforeAnalytics(e){return null}_adShowSuccessAnalytics(e){return null}_adShowFailureAnalytics(e){return null}_adLoadSuccessAnalytics(e){return null}_adLoadFailureAnalytics(e){return null}_adCloseSuccessAnalytics(e){return null}get rewardAd(){return this._rewardAd}addExecuteManager(e){return super.addExecuteManager(e)}ad(e,t=null){return this._alwaysCallback=e?.collection?.always,this._halfwayCallback=e?.collection?.halfway,this._finishedCallback=e?.collection?.finished,this._onInnerExecuteBefore(),new Promise(i=>{this._adInner({options:{scene:e?.options?.scene},collection:{resolve:i,before:e.collection?.before,success:e.collection?.success,prelude:e.collection?.prelude}},t)})}_adInner(e,t=null){let i=e?.collection?.resolve,s=e?.options?.scene??this._scene??DEFAULT_SCENT_TEXT_OBJ.inner_default_other,r=e?.collection?.before,n=e?.collection?.success,l=e?.collection?.prelude,o=e=>{this._clearAdTimeout(),this.adDestroy(),i?.(Object.assign({scene:s,adTypeR:this._adTypeR},e?.resolvedValue)),t?.(Object.assign({scene:s},e?.nextValue))},a=()=>{this._scene=s,r?.({scene:s}),this._before=r,this._onShow?.({scene:s}),this._adShowBeforeAnalytics({scene:s}),this._resolve=i,this._next=t,this._setAdTimeout({scene:s,end:o}),this._adPreludeInterval({scene:s,prelude:l}),this.adShow().then(()=>{this._clearAdTimeout(),n?.({scene:s}),this._success=n,this._adShowSuccessAnalytics({scene:s,result:1}),this._onInnerAdShowSuccess()}).catch(e=>{(this._clearAdTimeout(),this._adShowFailureAnalytics({scene:s,msg:e?.errMsg,errorCode:e?.errorCode,result:0}),matchErrorWithKeywords(this._ttErrorMsgs,e?.errMsg)||this._ttErrorCodes.includes(e?.errorCode))?o({scene:s,resolvedValue:{apiError:e},nextValue:null}):0>=this.novelConfig.remain()?o({scene:s,resolvedValue:null,nextValue:null}):(this.novelConfig.updateRetry(),this.adLoad().then(()=>{this._adLoadSuccessAnalytics({scene:s,result:1}),a()}).catch(e=>{this._adLoadFailureAnalytics({scene:s,msg:e?.errMsg,result:0}),o({scene:s,resolvedValue:{apiError:e},nextValue:null})}))})};a()}adLoad(){return this.load()}adShow(){return this.show()}_outerCloseCallback(e){this._alwaysCallback?.(e)}_outerHalfwayCallback(e){this._halfwayCallback?.(e)}_outerFinishedCallback(e){this._finishedCallback?.(e)}adCloseLister(){this._clearAdTimeout(),this._adCloseSuccessAnalytics({scene:this._scene,ad_is_completed:1});let e={scene:this._scene},t=e=>{this.adDestroy(),this._resolve?.(Object.assign({},{scene:this._scene,adTypeR:this._adTypeR},e)),this._resolve=null,this._next?.(),this._next=null,this._success=null,this._before=null};this._outerFinishedCallback(e),this._onFinish?.(e),this._outerHalfwayCallback(e),this._onHalfway?.(e),this._outerCloseCallback(e),this._onAlways?.(e),t({end_type:"finished"})}adErrorLister(e){this._clearAdTimeout(),console.error("[InterstitialAdNovel] adErrorLister",JSON.stringify(e)),this._adShowFailureAnalytics({scene:this._scene,msg:e?.errMsg,errorCode:e?.errorCode,result:0}),this._onError?.(e),0>=this.novelConfig.remain()&&(this.adDestroy(),this._resolve?.({apiError:e,scene:this._scene,adTypeR:this._adTypeR}),this._resolve=null,this._next?.(),this._next=null,this._success=null,this._before=null)}apiAdErrorLister(e){this._clearAdTimeout(),console.error("[API InterstitialAdNovel] apiAdErrorLister:",JSON.stringify(e)),this._adShowFailureAnalytics({scene:this._scene,msg:e?.errMsg,errorCode:e?.errorCode,result:0}),this.adDestroy(),this._onError?.(e),this._resolve?.({apiError:e,scene:this._scene,adTypeR:this._adTypeR}),this._resolve=null,this._next?.(),this._next=null,this._success=null,this._before=null}adLoadLister(e){this._adLoadSuccessAnalytics({scene:this._scene,result:1,msg:e?.errMsg}),console.info("[InterstitialAdNovel] adLoadLister:",JSON.stringify({scene:this._scene,info:e}))}adDestroy(){this.offClose(this.bindAdCloseLister),this.offError(this.bindAdErrorLister),this.offLoad(this.bindAdLoadLister),tt.offError(this.bindApiAdErrorLister),this._onHalfway=null,this._onFinish=null,this._onAlways=null,this._onShow=null,this._onError=null,this._alwaysCallback=null,this._halfwayCallback=null,this._finishedCallback=null,this.destroy()}clear(){this._clearAdTimeout(),this.offClose(this.bindAdCloseLister),this.offClose(this._bindShiftCloseLister),this.offError(this.bindAdErrorLister),this.offError(this._bindShiftErrorLister),this.offLoad(this.bindAdLoadLister),tt.offError(this.bindApiAdErrorLister),this._onHalfway=null,this._onFinish=null,this._onAlways=null,this._onShow=null,this._onError=null,this._alwaysCallback=null,this._halfwayCallback=null,this._finishedCallback=null,this.destroy(),this._resolve=null,this._next=null,this._success=null,this._before=null}_shiftCloseLister(e){this._clearAdTimeout(),this.offError(this._bindShiftErrorLister),this.offLoad(this.bindAdLoadLister),tt.offError(this.bindApiAdErrorLister),this._onHalfway=null,this._onFinish=null,this._onAlways=null,this._onShow=null,this._onError=null,this._alwaysCallback=null,this._halfwayCallback=null,this._finishedCallback=null,this.offClose(this._bindShiftCloseLister),this.destroy(),this._resolve?.(Object.assign({},e,{scene:this._scene,adTypeR:this._adTypeR})),this._resolve=null,this._next?.(),this._next=null,this._success=null,this._before=null}_shiftErrorLister(e){this._clearAdTimeout(),this.offClose(this._bindShiftCloseLister),this.offLoad(this.bindAdLoadLister),tt.offError(this.bindApiAdErrorLister),this._onHalfway=null,this._onFinish=null,this._onAlways=null,this._onShow=null,this._onError=null,this._alwaysCallback=null,this._halfwayCallback=null,this._finishedCallback=null,this.offError(this._bindShiftErrorLister),this.destroy(),this._resolve?.(Object.assign({},e,{scene:this._scene,adTypeR:this._adTypeR})),this._resolve=null,this._next?.(),this._next=null,this._success=null,this._before=null}shift(){this.offClose(this.bindAdCloseLister),this.onClose(this._bindShiftCloseLister),this.offError(this.bindAdErrorLister),this.onError(this._bindShiftErrorLister)}static build(e){return InterstitialAdNovel.instance||(InterstitialAdNovel.instance=new InterstitialAdNovel(e)),InterstitialAdNovel.instance}static getInstance(){if(!InterstitialAdNovel.instance)throw Error("InterstitialAdNovel instance is not init");return InterstitialAdNovel.instance}static new(e){return new InterstitialAdNovel(e)}}class InterstitialAdNovel_RewardAdNovelConfig{frequency={total:0,current:0};constructor(e){this._init(e)}_init(e){this._adTimes(e)}_adTimes(e){this.frequency.total=e?.retry??4}reset(){this.frequency.current=0}updateRetry(){this.frequency.current=this.frequency.current+1}remain(){return this.frequency.total-this.frequency.current}static new(e){return new InterstitialAdNovel_RewardAdNovelConfig(e)}}const ad_InterstitialAdNovel=InterstitialAdNovel;for(var __rspack_i in exports.InterstitialAdFather=__webpack_exports__.InterstitialAdFather,exports.InterstitialAdNovel=__webpack_exports__.InterstitialAdNovel,exports.RewardAdFather=__webpack_exports__.RewardAdFather,exports.RewardAdNovel=__webpack_exports__.RewardAdNovel,__webpack_exports__)-1===["InterstitialAdFather","InterstitialAdNovel","RewardAdFather","RewardAdNovel"].indexOf(__rspack_i)&&(exports[__rspack_i]=__webpack_exports__[__rspack_i]);Object.defineProperty(exports,"__esModule",{value:!0});
@@ -0,0 +1,188 @@
1
+ export type IRewordAdConfig = {
2
+ /**
3
+ * 激励视频广告id - 必填
4
+ */
5
+ adUnitId: string;
6
+ /**
7
+ * 是否开启进度提醒。开启时广告文案为「再看 n 个xxx」,关闭时为「再看 1 个xxx」。其中 n 表示用户当前还需额外观看广告的次数
8
+ * 再得广告的奖励文案,用户每看完一个广告都会展示,multiton 为 true 时必填。
9
+ * 文案完整内容为「再看 1 个xxx」,其中 xxx 是 multitonRewardMsg 配置的文案内容,最大长度为 7,
10
+ * 文案内容根据 multitonRewardMsg 的配置按顺序展示。若 multitonRewardMsg 长度小于 multitonRewardTimes ,
11
+ * 则后续的激励再得广告文案取 multitonRewardMsg 数组最后一个。
12
+ */
13
+ progressTip?: boolean | undefined;
14
+ multitonRewardMsg?: Array<string> | undefined;
15
+ /**
16
+ * 是否开启激励再得广告
17
+ */
18
+ multiton?: boolean | undefined;
19
+ /**
20
+ * 额外观看广告的次数,合法的数据范围为 1~4,multiton 为 true 时必填
21
+ */
22
+ multitonRewardTimes?: number | undefined;
23
+ /**
24
+ * 场景值 - 自用参数,非tt API要求的参数
25
+ */
26
+ scene?: number | undefined;
27
+ /**
28
+ * 广告超时时间 单位ms - 自用参数,非tt API要求的参数
29
+ */
30
+ timeout?: number | undefined;
31
+ /**
32
+ * 奖励金额 - 自用参数 ,非tt API要求的参数
33
+ */
34
+ log?: boolean | undefined;
35
+ /**
36
+ * 重试次数 - 自用参数 ,非tt API要求的参数
37
+ */
38
+ retry: number;
39
+ };
40
+ export type InterstitialAdConfig = {
41
+ /**
42
+ * 单个广告单元的 id。可从「开放平台控制台-进入对应小程序-运营-商业化变现-广告管理」中获取 - 必填
43
+ */
44
+ adUnitId: string;
45
+ /**
46
+ * 场景值 - 自用参数
47
+ */
48
+ scene?: number | undefined;
49
+ };
50
+ export type IExeCallbackArgs = {
51
+ /**
52
+ * 广告执行场景
53
+ */
54
+ scene: number;
55
+ /**
56
+ * 是否看完
57
+ */
58
+ isEnded: boolean;
59
+ /**
60
+ * 完整观看次数
61
+ */
62
+ count: number;
63
+ /**
64
+ * 剩余观看次数
65
+ */
66
+ remain?: number;
67
+ };
68
+ export type CallbackCollection = {
69
+ /**
70
+ * 每次外部回调
71
+ */
72
+ always?: (ctx?: IExeCallbackArgs) => void;
73
+ /**
74
+ * 完整看完广告外部回调 不管一个还是几个
75
+ */
76
+ finished?: (ctx?: IExeCallbackArgs) => void;
77
+ /**
78
+ * 半途退出广告外部回调
79
+ */
80
+ halfway?: (ctx?: IExeCallbackArgs) => void;
81
+ /**
82
+ * 完成广告外部回调 不管看不看完
83
+ */
84
+ complete?: (ctx?: IExeCallbackArgs) => void;
85
+ /**
86
+ * 取消广告外部回调
87
+ */
88
+ onCancel?: (ctx?: IExeCallbackArgs) => void;
89
+ /**
90
+ * 展示广告外部回调
91
+ */
92
+ before?: (ctx?: IExeCallbackArgs) => void;
93
+ /**
94
+ * 展示广告成功外部回调
95
+ */
96
+ success?: (ctx?: IExeCallbackArgs) => void;
97
+ /**
98
+ * 计时回调
99
+ */
100
+ prelude?: (ctx?: unknown) => void;
101
+ };
102
+ export type ICallbackArgs = {
103
+ /**
104
+ * 广告执行场景
105
+ */
106
+ scene: number;
107
+ /**
108
+ * 是否看完
109
+ */
110
+ isEnded: boolean;
111
+ /**
112
+ * 完整观看次数
113
+ */
114
+ count: number;
115
+ /**
116
+ * 剩余观看次数
117
+ */
118
+ remain?: number;
119
+ /**
120
+ * 执行下一个任务的回调函数,手动调用以继续执行流程[end]
121
+ */
122
+ end?: () => void;
123
+ /**
124
+ * 执行下一个任务的回调函数, 手动调用以继续执行流程[circle]
125
+ */
126
+ circle?: (args: {
127
+ ignoreRemain: boolean;
128
+ scene: number;
129
+ }) => void;
130
+ };
131
+ export type IConnection = {
132
+ /**
133
+ * 广告中途退出回调
134
+ */
135
+ onHalfway?: (args: ICallbackArgs) => void;
136
+ /**
137
+ * 广告展示回调
138
+ */
139
+ onShow?: (args: ICallbackArgs) => void;
140
+ /**
141
+ * 广告执行成功回调
142
+ */
143
+ onFinish?: (args: ICallbackArgs) => void;
144
+ /**
145
+ * 广告执行失败回调
146
+ */
147
+ onError?: (e: unknown) => void;
148
+ };
149
+ export type IConstructArgs = {
150
+ /**
151
+ * 初始化标识
152
+ */
153
+ sign: string;
154
+ /**
155
+ * 重试次数
156
+ */
157
+ retry: number;
158
+ /**
159
+ * 是否保留tt激励视频广告实例
160
+ */
161
+ preserveOnEnd: boolean;
162
+ /**
163
+ * 激励视频参数 (可选)
164
+ */
165
+ adConfig?: IRewordAdConfig | undefined;
166
+ /**
167
+ * 回调集合
168
+ */
169
+ collection?: IConnection | undefined;
170
+ };
171
+ /**
172
+ * 广告场景类型映射对象
173
+ */
174
+ export type SceneTypeMap = {
175
+ readonly [x: number]: string;
176
+ };
177
+ /**
178
+ * 广告场景类型文本映射对象(反向映射)
179
+ */
180
+ export type SceneTextMap = { readonly [K in SceneTypeMap[keyof SceneTypeMap]]: { [P in keyof SceneTypeMap]: SceneTypeMap[P] extends K ? P : never; }[keyof SceneTypeMap]; };
181
+ /**
182
+ * 场景值枚举 可持续添加
183
+ */
184
+ export type RewardAdTriggerScene = keyof SceneTextMap;
185
+ /**
186
+ * 场景值枚举 可持续添加
187
+ */
188
+ export type RewardAdTriggerSceneType = keyof SceneTypeMap;
@@ -0,0 +1,14 @@
1
+ export type IAdType = {
2
+ /**
3
+ * 激励视频
4
+ */
5
+ AD_TYPE_REWARD: 1;
6
+ /**
7
+ * 插屏广告
8
+ */
9
+ AD_TYPE_INTERSTITIAL: 2;
10
+ };
11
+ /**
12
+ * 广告场景类型文本映射对象(反向映射)
13
+ */
14
+ export type IAdTypeReverse = { readonly [K in IAdType[keyof IAdType]]: { [P in keyof IAdType]: IAdType[P] extends K ? P : never; }[keyof IAdType]; };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,13 @@
1
+ /**
2
+ *
3
+ * @param {string[]} ttErrorMsgs
4
+ * @param {string[]} keyword
5
+ * @returns
6
+ */
7
+ export function matchErrorWithKeywords(ttErrorMsgs: string[], keyword: string[]): boolean;
8
+ /**
9
+ * 广告场景类型映射对象
10
+ * @param {import('../typings/ad.js').SceneTypeMap} scentTypeObj
11
+ * @returns {import('../typings/ad.js').SceneTextMap}
12
+ */
13
+ export function getAdSceneTextObj(scentTypeObj: import("../typings/ad.js").SceneTypeMap): import("../typings/ad.js").SceneTextMap;
package/package.json ADDED
@@ -0,0 +1,24 @@
1
+ {
2
+ "name": "@ad-execute-manager/ad",
3
+ "version": "2.0.0-alpha.1",
4
+ "type": "module",
5
+ "main": "./dist/index.cjs",
6
+ "module": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "files": [
9
+ "dist"
10
+ ],
11
+ "exports": {
12
+ ".": {
13
+ "import": "./dist/index.js",
14
+ "require": "./dist/index.cjs",
15
+ "types": "./dist/index.d.ts"
16
+ }
17
+ },
18
+ "author": "singcl",
19
+ "license": "MIT",
20
+ "homepage": "https://npmjs.com/package/@ad-execute-manager/ad",
21
+ "peerDependencies": {
22
+ "@singcl/ad-execute-manager": ">=2.0.0"
23
+ }
24
+ }