ylh-pc-ad-sdk 0.1.0

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.
Files changed (53) hide show
  1. package/dist/api/loadFeedAd.d.ts +2 -0
  2. package/dist/api/mockData.d.ts +2 -0
  3. package/dist/api/mockParams.d.ts +26 -0
  4. package/dist/api/reportClickCGI.d.ts +6 -0
  5. package/dist/api/reportExposeCGI.d.ts +7 -0
  6. package/dist/api/reportVideoCGI.d.ts +6 -0
  7. package/dist/beacon/index.d.ts +15 -0
  8. package/dist/bridge.d.ts +11 -0
  9. package/dist/common/baseAd.d.ts +16 -0
  10. package/dist/common/constants.d.ts +63 -0
  11. package/dist/common/types.d.ts +157 -0
  12. package/dist/core/BaseClickHandler.d.ts +23 -0
  13. package/dist/core/BaseExposureHandler.d.ts +29 -0
  14. package/dist/core/BeaconTracker.d.ts +13 -0
  15. package/dist/core/CacheManager.d.ts +11 -0
  16. package/dist/core/ContainerObserver.d.ts +29 -0
  17. package/dist/core/EventEmitter.d.ts +10 -0
  18. package/dist/core/EventManager.d.ts +11 -0
  19. package/dist/core/ParamsManager.d.ts +17 -0
  20. package/dist/core/WxGameSDK.d.ts +11 -0
  21. package/dist/gdt-union-bridge.esm.js +1 -0
  22. package/dist/gdt-union-bridge.esm.js.map +1 -0
  23. package/dist/gdt-union-bridge.js +1 -0
  24. package/dist/gdt-union-bridge.js.map +1 -0
  25. package/dist/gdt-union-sdk.esm.js +1 -0
  26. package/dist/gdt-union-sdk.esm.js.map +1 -0
  27. package/dist/gdt-union-sdk.js +1 -0
  28. package/dist/gdt-union-sdk.js.map +1 -0
  29. package/dist/http/adapter/FetchAdapter.d.ts +5 -0
  30. package/dist/http/adapter/JSBridgeAdapter.d.ts +5 -0
  31. package/dist/http/adapter/JSONPAdapter.d.ts +20 -0
  32. package/dist/http/adapter/XHRAdapter.d.ts +5 -0
  33. package/dist/http/http.types.d.ts +24 -0
  34. package/dist/http/index.d.ts +11 -0
  35. package/dist/http/utils.d.ts +1 -0
  36. package/dist/index.d.ts +14 -0
  37. package/dist/lib/wxgamesdk.js +1 -0
  38. package/dist/native/MsgChannel/index.d.ts +15 -0
  39. package/dist/native/VideoManager/index.d.ts +28 -0
  40. package/dist/native/constants.d.ts +37 -0
  41. package/dist/native/index.d.ts +72 -0
  42. package/dist/native/typings.d.ts +52 -0
  43. package/dist/native/utils.d.ts +13 -0
  44. package/dist/sence/banner/index.d.ts +7 -0
  45. package/dist/sence/feed/AdViewBinder.d.ts +13 -0
  46. package/dist/sence/feed/MediaViewBinder.d.ts +12 -0
  47. package/dist/sence/feed/index.d.ts +30 -0
  48. package/dist/utils/crypto.d.ts +18 -0
  49. package/dist/utils/index.d.ts +31 -0
  50. package/dist/utils/viewport.d.ts +19 -0
  51. package/dist/widgets/AdContainer.d.ts +9 -0
  52. package/dist/widgets/VideoContainer.d.ts +55 -0
  53. package/package.json +54 -0
@@ -0,0 +1,20 @@
1
+ import { HttpAdapter, HttpResponse, RequestOptions } from '../http.types';
2
+ declare global {
3
+ interface Window {
4
+ [key: string]: any;
5
+ }
6
+ }
7
+ export default class JsonpAdapter implements HttpAdapter {
8
+ private readonly defaultTimeout;
9
+ private timer;
10
+ private readonly callbackPrefix;
11
+ private isCallbackCalled;
12
+ execute(options: RequestOptions): Promise<HttpResponse>;
13
+ private generateCallbackName;
14
+ private createScriptElement;
15
+ private buildQueryString;
16
+ private handleResponse;
17
+ private handleError;
18
+ private setupTimeout;
19
+ private cleanup;
20
+ }
@@ -0,0 +1,5 @@
1
+ import { HttpAdapter, HttpResponse, RequestOptions } from '../http.types';
2
+ declare class XHRAdapter implements HttpAdapter {
3
+ execute(options: RequestOptions): Promise<HttpResponse>;
4
+ }
5
+ export default XHRAdapter;
@@ -0,0 +1,24 @@
1
+ export type HttpMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
2
+ export interface HttpAdapter {
3
+ execute(options: RequestOptions): Promise<HttpResponse>;
4
+ }
5
+ export interface RequestOptions {
6
+ url: string;
7
+ params?: any;
8
+ headers?: Record<string, string>;
9
+ timeout?: number;
10
+ jsonpCallbackName?: string;
11
+ }
12
+ export interface HttpResponse {
13
+ status: number;
14
+ data: {
15
+ ret: number;
16
+ msg?: string;
17
+ [key: string]: any;
18
+ };
19
+ }
20
+ export interface JsonpResponse {
21
+ ret: number;
22
+ msg?: string;
23
+ [key: string]: any;
24
+ }
@@ -0,0 +1,11 @@
1
+ import { HttpResponse, RequestOptions } from './http.types';
2
+ declare class HttpService {
3
+ private static instance;
4
+ private adapter;
5
+ private constructor();
6
+ static getInstance(): HttpService;
7
+ private createAdapter;
8
+ request(options: RequestOptions): Promise<HttpResponse>;
9
+ }
10
+ declare const _default: HttpService;
11
+ export default _default;
@@ -0,0 +1 @@
1
+ export declare const isJSBridgeSupported: () => boolean;
@@ -0,0 +1,14 @@
1
+ import { GDTAdLoadConfig, AdInterface, SDKConfig } from './common/types';
2
+ declare class GDTAdSDK {
3
+ private static instance;
4
+ private initialized;
5
+ private config?;
6
+ private _initPromise?;
7
+ static getInstance(): GDTAdSDK;
8
+ init(config?: SDKConfig): Promise<void>;
9
+ isInitialized(): boolean;
10
+ private checkInitialized;
11
+ loadFeedAdData(options: GDTAdLoadConfig): Promise<AdInterface[]>;
12
+ }
13
+ declare const _default: GDTAdSDK;
14
+ export default _default;
@@ -0,0 +1 @@
1
+ (()=>{"use strict";var e={208:function(e,t,n){var i,s,r,o,a,c=this&&this.__awaiter||function(e,t,n,i){return new(n||(n=Promise))((function(s,r){function o(e){try{c(i.next(e))}catch(e){r(e)}}function a(e){try{c(i.throw(e))}catch(e){r(e)}}function c(e){var t;e.done?s(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(o,a)}c((i=i.apply(e,t||[])).next())}))},u=this&&this.__classPrivateFieldGet||function(e,t,n,i){if("a"===n&&!i)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof t?e!==t||!i:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===n?i:"a"===n?i.call(e):i?i.value:t.get(e)},l=this&&this.__classPrivateFieldSet||function(e,t,n,i,s){if("m"===i)throw new TypeError("Private method is not writable");if("a"===i&&!s)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof t?e!==t||!s:!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===i?s.call(e,n):s?s.value=n:t.set(e,n),n};Object.defineProperty(t,"__esModule",{value:!0});const h=n(439);s=new WeakMap,r=new WeakMap,i=new WeakSet,o=function(){this.methodOutputTarget.ready=!1;const e=document.currentScript.getAttribute("src"),t=document.createElement("iframe");t.src=e.replace(/\/[^/]+$/,`/${this.frameSrc}`),t.style.display="none",l(this,s,t,"f"),t.addEventListener("load",(()=>{if(!t.contentWindow)return!1;l(this,r,new h.CrossSiteWindowMessageChannel(t.contentWindow),"f"),u(this,r,"f").send("sync_method",void 0).then((e=>{var t,n;e.forEach((e=>{this.methodOutputTarget[e]=u(this,i,"m",a).call(this,e)})),this.methodOutputTarget.ready=!0,"function"==typeof this.methodOutputTarget.onReady&&(null===(n=(t=this.methodOutputTarget).onReady)||void 0===n||n.call(t))}))})),document.body.appendChild(t)},a=function(e){return t=>c(this,void 0,void 0,(function*(){if(!u(this,r,"f"))throw new Error("sdk not inited.");return yield u(this,r,"f").send("invoke",{apiName:e,args:t})}))},t.default=class{constructor(e,t){i.add(this),this.frameSrc=e,this.methodOutputTarget=t,s.set(this,void 0),r.set(this,void 0),u(this,i,"m",o).call(this)}}},576:function(e,t){var n,i=this&&this.__awaiter||function(e,t,n,i){return new(n||(n=Promise))((function(s,r){function o(e){try{c(i.next(e))}catch(e){r(e)}}function a(e){try{c(i.throw(e))}catch(e){r(e)}}function c(e){var t;e.done?s(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(o,a)}c((i=i.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0}),t.waitAnimationFrame=t.waitTimeout=t.AsyncQueue=t.AsyncMutex=t.Waiting=t.AsyncValue=void 0,t.createAsyncRef=function(){const e=new s;return{ref(t){null!=t&&t!==e.getSync()&&e.set(t)},get current(){return e.get()},get currentSync(){return e.getSync()}}},function(e){e[e.PENDING=0]="PENDING",e[e.RESOLVE=1]="RESOLVE",e[e.REJECT=2]="REJECT"}(n||(n={}));class s{constructor(){this.state=n.PENDING,this.resolvePending=null,this.rejectPending=null}get(){return i(this,void 0,void 0,(function*(){return this.state===n.RESOLVE?this.value:this.state===n.REJECT?Promise.reject(this.value):(this.pendingRequest||(this.pendingRequest=new Promise(((e,t)=>{this.resolvePending=e,this.rejectPending=t}))),this.pendingRequest)}))}getSync(){return this.state===n.PENDING?void 0:this.value}set(e,t=!1){if(this.state!==n.PENDING)throw new Error("forbidden: set value more than once");this.value=e,t?(this.state=n.REJECT,this.rejectPending&&this.rejectPending(this.value)):(this.state=n.RESOLVE,this.resolvePending&&this.resolvePending(this.value)),this.resolvePending=null,this.rejectPending=null,this.pendingRequest=null}isPending(){return this.state===n.PENDING}isResolved(){return this.state===n.RESOLVE}isRejected(){return this.state===n.REJECT}}t.AsyncValue=s,t.Waiting=class{constructor(){this.value=new s}waitUntil(e){return i(this,void 0,void 0,(function*(){const t=yield this.value.get();return"function"==typeof e&&(yield e(t)),t}))}done(e){this.value.set(e)}},t.AsyncMutex=class{lock(){if(this._lockPromise)throw new Error("mutex is locked!");this._lockPromise=new Promise((e=>{this._resolveHandler=e}))}unlock(){this._resolveHandler(),this._lockPromise=void 0}waitUnlock(){return this._lockPromise}requestLock(){return i(this,void 0,void 0,(function*(){return yield this.waitUnlock(),this.lock()}))}},t.AsyncQueue=class{constructor(){this._queues=[]}requestTask(e){return i(this,void 0,void 0,(function*(){const t=this._queues.length>0?this._queues[this._queues.length-1]:void 0;let n;const i=new Promise((e=>{n=e})),s={resolveHandler:n,taskPromise:i};return this._queues.push(s),t&&(yield null==t?void 0:t.taskPromise),"number"==typeof e&&setTimeout((()=>{this._queues.includes(s)&&n()}),e),{done:()=>{console.assert(s===this._queues.shift()),n()}}}))}},t.waitTimeout=e=>new Promise((t=>{setTimeout(t,e)})),t.waitAnimationFrame=()=>new Promise((e=>{requestAnimationFrame(e)}))},315:function(e,t){var n=this&&this.__awaiter||function(e,t,n,i){return new(n||(n=Promise))((function(s,r){function o(e){try{c(i.next(e))}catch(e){r(e)}}function a(e){try{c(i.throw(e))}catch(e){r(e)}}function c(e){var t;e.done?s(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(o,a)}c((i=i.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0}),t.BaseWindowMessageChannel=void 0,t.BaseWindowMessageChannel=class{constructor(){this._callbacks={},this._id=String(Date.now())}send(e,t){return n(this,arguments,void 0,(function*(e,t,n={}){throw new Error("unimplented error")}))}on(e,t){this._callbacks[e]&&console.warn("already has "+e),console.debug(`channel received on listener[${e}]`),this._callbacks[e]=t}emit(e,t){if(this._callbacks[e])return this._callbacks[e](t);console.warn(`event ${e} haven't listeners!`,this)}}},439:function(e,t,n){var i=this&&this.__awaiter||function(e,t,n,i){return new(n||(n=Promise))((function(s,r){function o(e){try{c(i.next(e))}catch(e){r(e)}}function a(e){try{c(i.throw(e))}catch(e){r(e)}}function c(e){var t;e.done?s(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(o,a)}c((i=i.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0}),t.CrossSiteWindowMessageChannel=void 0;const s=n(576),r=n(315);let o=0;class a extends r.BaseWindowMessageChannel{constructor(e){super(),this.targetWindow=e,this._callbackPromises={},window.addEventListener("message",(e=>i(this,void 0,void 0,(function*(){var t;e.source===this.targetWindow&&("_callback"===e.data.name?(null===(t=this._callbackPromises[e.data._id])||void 0===t||t.set(e.data.content),delete this._callbackPromises[e.data._id]):this._sendCallback(e.data._id,yield this.emit(e.data.name,e.data.content)))}))))}_sendCallback(e,t){this.targetWindow.postMessage({name:"_callback",content:t,_id:e},"*")}static _processMessage(e){return JSON.parse(JSON.stringify(e))}send(e,t){const n=o++;let i={name:e,content:t,_id:n};i=a._processMessage(i),this.targetWindow.postMessage(i,"*");const r=new s.AsyncValue;return this._callbackPromises[n]=r,r.get()}}t.CrossSiteWindowMessageChannel=a},504:function(e,t,n){var i=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const s=i(n(208)),r={};window.wxgamesdk=r,new s.default("./wxgamesdkframe.html",r)}},t={};!function n(i){var s=t[i];if(void 0!==s)return s.exports;var r=t[i]={exports:{}};return e[i].call(r.exports,r,r.exports,n),r.exports}(504)})();
@@ -0,0 +1,15 @@
1
+ import { WebEventType } from '../constants';
2
+ import { IInvokeError, IInvokeResult, IWebMessage } from '../typings';
3
+ declare class MsgChannel {
4
+ private static instance;
5
+ private invokeHandler?;
6
+ private setuped;
7
+ static getInstance: () => MsgChannel;
8
+ setupMessageListener: () => void;
9
+ registerHandler: (handler: (method: string, params: unknown[], targetId: string) => Promise<IInvokeResult | IInvokeError>) => void;
10
+ send: <T extends WebEventType>(event: T, data: IWebMessage["data"]) => Promise<void>;
11
+ private sendInvokeResult;
12
+ private handleInvokeMessage;
13
+ private handleSystemMessage;
14
+ }
15
+ export default MsgChannel;
@@ -0,0 +1,28 @@
1
+ import { WebEventType } from '../constants';
2
+ import { ICreateVideoParams } from '../typings';
3
+ declare class VideoManager {
4
+ private static instance;
5
+ static getInstance: () => VideoManager;
6
+ private eventCallback;
7
+ private videoElement;
8
+ registerEventCallback: (callback: (event: WebEventType, data: Record<string, unknown>) => void) => void;
9
+ createVideoAd: (params: ICreateVideoParams) => Promise<{
10
+ error: {
11
+ code: number;
12
+ message: string;
13
+ };
14
+ } | {
15
+ result: unknown;
16
+ }>;
17
+ play: () => {
18
+ result: unknown;
19
+ };
20
+ pause: () => {
21
+ result: unknown;
22
+ };
23
+ replay: () => {
24
+ result: unknown;
25
+ };
26
+ private createVideoCallbacks;
27
+ }
28
+ export default VideoManager;
@@ -0,0 +1,37 @@
1
+ declare enum NativeEventType {
2
+ INVOKE = "invoke"
3
+ }
4
+ declare enum WebEventType {
5
+ INIT = "sdk_initialized",
6
+ RETURN = "return",
7
+ INVALID_MESSAGE = "invalid_message",
8
+ VIDEO_PLAY = "video_play",
9
+ VIDEO_PAUSE = "video_pause",
10
+ VIDEO_ENDED = "video_ended",
11
+ VIDEO_ERROR = "video_error",
12
+ VIDEO_TIMEUPDATE = "video_timeupdate",
13
+ VIDEO_READY = "video_ready"
14
+ }
15
+ declare enum ErrorCode {
16
+ PARSE_ERROR = -32700,
17
+ INVALID_REQUEST = -32600,
18
+ METHOD_NOT_FOUND = -32601,
19
+ INVALID_PARAMS = -32602,
20
+ INTERNAL_ERROR = -32603,
21
+ UNKNOWN = -32000,
22
+ INVALID_APPID = -32001,
23
+ AD_NOT_FOUND = -32002,
24
+ CONTAINER_NOT_FOUND = -32003
25
+ }
26
+ declare enum ErrorMessage {
27
+ PARSE_ERROR = "Parse error: JSON\u89E3\u6790\u9519\u8BEF",
28
+ INVALID_REQUEST = "Invalid request: \u65E0\u6548\u7684\u8BF7\u6C42",
29
+ METHOD_NOT_FOUND = "Method not found: \u65B9\u6CD5\u4E0D\u5B58\u5728",
30
+ INVALID_PARAMS = "Invalid params: \u65E0\u6548\u7684\u53C2\u6570",
31
+ INTERNAL_ERROR = "Internal error: \u5185\u90E8\u9519\u8BEF",
32
+ UNKNOWN = "Unknown error: \u672A\u77E5\u9519\u8BEF",
33
+ INVALID_APPID = "Invalid AppID: \u65E0\u6548\u7684AppID",
34
+ AD_NOT_FOUND = "Ad not found: \u5E7F\u544A\u6570\u636E\u4E0D\u5B58\u5728",
35
+ CONTAINER_NOT_FOUND = "Container not found: \u5BB9\u5668\u4E0D\u5B58\u5728"
36
+ }
37
+ export { NativeEventType, WebEventType, ErrorCode, ErrorMessage };
@@ -0,0 +1,72 @@
1
+ import { IAdRequestParams, ICreateVideoParams, IDoClickParams, IMethodParams } from './typings';
2
+ declare class NativeBridge {
3
+ private static instance;
4
+ private adDataMap;
5
+ private channel?;
6
+ private videoMananger?;
7
+ private appId?;
8
+ static getInstance: () => NativeBridge;
9
+ init: (config: {
10
+ appId?: string;
11
+ }) => void;
12
+ loadFeedAdData: ({ params }: IMethodParams<[IAdRequestParams]>) => Promise<{
13
+ error: {
14
+ code: number;
15
+ message: string;
16
+ };
17
+ } | {
18
+ result: unknown;
19
+ }>;
20
+ doExpose: ({ targetId }: IMethodParams) => Promise<{
21
+ error: {
22
+ code: number;
23
+ message: string;
24
+ };
25
+ } | {
26
+ result: unknown;
27
+ }>;
28
+ doClick: ({ targetId, params }: IMethodParams<[IDoClickParams]>) => Promise<{
29
+ error: {
30
+ code: number;
31
+ message: string;
32
+ };
33
+ } | {
34
+ result: unknown;
35
+ }>;
36
+ createVideoAd: ({ params }: IMethodParams<[ICreateVideoParams]>) => Promise<{
37
+ error: {
38
+ code: number;
39
+ message: string;
40
+ };
41
+ } | {
42
+ result: unknown;
43
+ }>;
44
+ playVideo: () => {
45
+ result: unknown;
46
+ } | undefined;
47
+ pauseVideo: () => {
48
+ result: unknown;
49
+ } | undefined;
50
+ replayVideo: () => {
51
+ result: unknown;
52
+ } | undefined;
53
+ destroy: ({ targetId }: IMethodParams) => {
54
+ error: {
55
+ code: number;
56
+ message: string;
57
+ };
58
+ } | {
59
+ result: unknown;
60
+ };
61
+ isValid: ({ targetId }: IMethodParams) => {
62
+ error: {
63
+ code: number;
64
+ message: string;
65
+ };
66
+ } | {
67
+ result: unknown;
68
+ };
69
+ private handleNativeInvoke;
70
+ }
71
+ declare const _default: NativeBridge;
72
+ export default _default;
@@ -0,0 +1,52 @@
1
+ import { AdData, GDTAdLoadConfig, VideoOption } from '@/common/types';
2
+ import { NativeEventType, WebEventType } from './constants';
3
+ interface IAdRequestParams extends GDTAdLoadConfig {
4
+ ext?: Record<string, any>;
5
+ }
6
+ interface IDoClickParams {
7
+ x: number;
8
+ y: number;
9
+ }
10
+ interface ICreateVideoParams {
11
+ containerId: string;
12
+ adData: AdData;
13
+ videoOptions?: VideoOption;
14
+ }
15
+ interface INativeMessage {
16
+ event: NativeEventType;
17
+ data: Record<string, any>;
18
+ }
19
+ interface IWebMessage {
20
+ event: WebEventType;
21
+ data: Record<string, any>;
22
+ }
23
+ interface IReturnWebMessage {
24
+ event: WebEventType.RETURN;
25
+ data: ISuccessReturnData | IFailedReturnData;
26
+ }
27
+ interface IInvokeData {
28
+ method: string;
29
+ targetId: string;
30
+ params: unknown[];
31
+ id: number;
32
+ }
33
+ interface IInvokeResult {
34
+ result: unknown;
35
+ }
36
+ interface IInvokeError {
37
+ error: {
38
+ code: number;
39
+ message: string;
40
+ };
41
+ }
42
+ interface ISuccessReturnData extends IInvokeResult {
43
+ id: number;
44
+ }
45
+ interface IFailedReturnData extends IInvokeError {
46
+ id: number;
47
+ }
48
+ interface IMethodParams<T extends any[] = unknown[]> {
49
+ targetId: string;
50
+ params: T;
51
+ }
52
+ export type { IAdRequestParams, IDoClickParams, ICreateVideoParams, INativeMessage, IInvokeData, IInvokeResult, IInvokeError, IWebMessage, IReturnWebMessage, IMethodParams, };
@@ -0,0 +1,13 @@
1
+ declare const geneInvokeError: (code: number, message: string) => {
2
+ error: {
3
+ code: number;
4
+ message: string;
5
+ };
6
+ };
7
+ declare const geneInvokeResult: (result: unknown) => {
8
+ result: unknown;
9
+ };
10
+ declare const isMethodOfObject: <T extends Object = {}>(key: string, target: T) => key is Extract<keyof T, string>;
11
+ declare const getIsNativeEnv: () => boolean;
12
+ declare const isParamValid: (param: unknown, keys?: string[]) => boolean;
13
+ export { geneInvokeError, geneInvokeResult, isMethodOfObject, getIsNativeEnv, isParamValid };
@@ -0,0 +1,7 @@
1
+ import GDTBaseAd from "../../common/baseAd";
2
+ declare class GDTSplashAd extends GDTBaseAd {
3
+ init(): void;
4
+ loadSplashAdData(): Promise<void>;
5
+ destroy(): void;
6
+ }
7
+ export default GDTSplashAd;
@@ -0,0 +1,13 @@
1
+ import { BindAdToViewProps, AdData, AdEventListeners } from '../../common/types';
2
+ export declare class AdViewBinder {
3
+ private readonly adInfo;
4
+ private containerObserver;
5
+ private exposureHandler;
6
+ private clickHandler;
7
+ private readonly eventManager;
8
+ constructor(adInfo: AdData);
9
+ mount({ containerView, clickableElements }: Pick<BindAdToViewProps, 'clickableElements' | 'containerView'>): void;
10
+ setupEventListeners({ onExpose, onClick, onError }: AdEventListeners): void;
11
+ destroy(): void;
12
+ private emitError;
13
+ }
@@ -0,0 +1,12 @@
1
+ import { BindMediaViewProps, AdData } from '../../common/types';
2
+ export declare class MediaViewBinder {
3
+ private readonly adInfo;
4
+ private videoContainer;
5
+ private readonly eventManager;
6
+ constructor(adInfo: AdData);
7
+ mount({ mediaView, videoOptions, mediaListener }: BindMediaViewProps): void;
8
+ private initializeVideoContainer;
9
+ private createVideoCallbacks;
10
+ private emitError;
11
+ destroy(): void;
12
+ }
@@ -0,0 +1,30 @@
1
+ import { AdError, GDTBaseAdInterface, BaseAdConfig, BindAdToViewProps, BindMediaViewProps } from '../../common/types';
2
+ import GDTBaseAd from '../../common/baseAd';
3
+ import EventManager from '../../core/EventManager';
4
+ declare class GDTFeedAd extends GDTBaseAd implements GDTBaseAdInterface {
5
+ private adViewBinder;
6
+ private mediaViewBinder;
7
+ private adContainerView;
8
+ protected isDestroyed: boolean;
9
+ protected readonly eventManager: EventManager;
10
+ constructor(options: BaseAdConfig);
11
+ bindAdToView(props: BindAdToViewProps): void;
12
+ bindMediaView(props: BindMediaViewProps): void;
13
+ isValid(): boolean;
14
+ private checkAdValidity;
15
+ destroy(): void;
16
+ emitError(error: AdError): void;
17
+ cleanupEventListeners(): void;
18
+ getECPM(): number;
19
+ getTitle(): string;
20
+ getDescription(): string;
21
+ getIconUrl(): string;
22
+ getImageUrl(): string;
23
+ getImageWidth(): number;
24
+ getImageHeight(): number;
25
+ getImageUrls(): string[];
26
+ getAdPatternType(): string;
27
+ getAdLogoUrl(): string;
28
+ hasVideo(): boolean;
29
+ }
30
+ export default GDTFeedAd;
@@ -0,0 +1,18 @@
1
+ interface RawData {
2
+ nonce: string;
3
+ timestamp: number;
4
+ client_ip: string;
5
+ url: string;
6
+ raw_iv?: string;
7
+ }
8
+ interface EncryptedData {
9
+ encrypted_data: string;
10
+ iv: string;
11
+ appid: string;
12
+ }
13
+ export declare class CryptoUtil {
14
+ private static generateIV;
15
+ private static generateNonce;
16
+ static encryptData(rawData: RawData, appid: string): EncryptedData;
17
+ }
18
+ export {};
@@ -0,0 +1,31 @@
1
+ type LoadScriptFunction = () => Promise<void>;
2
+ export declare const loadScript: (src: string) => LoadScriptFunction;
3
+ export declare function minuteToMillisecond(minute: any): number;
4
+ export declare function getDateNow(): number;
5
+ export declare function checkDataType(source: any, targetType: string): boolean;
6
+ /**
7
+ * 是否为对象
8
+ * @param {any} source 需要检测的数据
9
+ * @returns Boolean
10
+ */
11
+ export declare function isObject(source: any): boolean;
12
+ export declare function isArray(source: any): boolean;
13
+ /**
14
+ * 是否为函数
15
+ * @param {any} source 需要检测的数据
16
+ * @returns Boolean
17
+ */
18
+ export declare function isFunction(fn: any): boolean;
19
+ /**
20
+ * 是否为数字
21
+ * @param {any} source 需要检测的数据
22
+ * @returns Boolean
23
+ */
24
+ export declare function isNumber(num: any): boolean;
25
+ export declare function isUndefined(val: any): boolean;
26
+ export declare function generateUniqueId(): string;
27
+ export declare const isWechatBrowser: boolean;
28
+ export declare const isIosBrowser: boolean;
29
+ export declare const formatDimensionValue: (value: string | number | undefined, defaultValue: string) => string;
30
+ export declare function parserViewId(apurl: string): string;
31
+ export {};
@@ -0,0 +1,19 @@
1
+ interface Viewport {
2
+ ww: number;
3
+ wh: number;
4
+ }
5
+ interface Rect {
6
+ top: number;
7
+ right: number;
8
+ bottom: number;
9
+ left: number;
10
+ width: number;
11
+ height: number;
12
+ }
13
+ interface VisibilityResult {
14
+ appearWidth: number;
15
+ appearHeight: number;
16
+ }
17
+ export declare function getViewport(): Viewport;
18
+ export declare function isInView(viewport: Viewport, rect: Rect): VisibilityResult;
19
+ export {};
@@ -0,0 +1,9 @@
1
+ export declare class AdContainer {
2
+ private adContainer;
3
+ private containerId;
4
+ constructor(containerId: string);
5
+ private setupContainer;
6
+ private setupCommonStyle;
7
+ getAdContainer(): HTMLElement | null;
8
+ destroy(): void;
9
+ }
@@ -0,0 +1,55 @@
1
+ import { VideoControl, VideoOption } from '../common/types';
2
+ interface VideoContainerProps {
3
+ videoInfo?: {
4
+ traceid?: string;
5
+ video?: string;
6
+ viewId?: string;
7
+ video_report_url?: string;
8
+ video_duration?: number;
9
+ video_file_size?: number;
10
+ video_width?: number;
11
+ video_height?: number;
12
+ };
13
+ containerStyle?: {
14
+ position?: string;
15
+ width?: string | number;
16
+ height?: string | number;
17
+ };
18
+ videoOptions?: {
19
+ autoplay?: boolean;
20
+ muted?: boolean;
21
+ controls?: boolean;
22
+ width?: string | number;
23
+ height?: string | number;
24
+ preload?: string;
25
+ objectFit?: string;
26
+ } & VideoOption;
27
+ callbacks?: {
28
+ onPlay?: (videoId?: string) => void;
29
+ onPause?: (videoId?: string) => void;
30
+ onEnded?: (videoId?: string) => void;
31
+ onError?: (error: Error, videoId?: string) => void;
32
+ onTimeUpdate?: (currentTime: number, duration: number, videoId?: string) => void;
33
+ onReady?: ($video: VideoControl, videoId?: string) => void;
34
+ };
35
+ }
36
+ export default class VideoContainer {
37
+ private readonly element;
38
+ private videoElement;
39
+ private readonly props;
40
+ private pauseCount;
41
+ private eventHandlers;
42
+ constructor(props: VideoContainerProps);
43
+ private formatDimensionValue;
44
+ private setupContainer;
45
+ private cleanupVideoElement;
46
+ private createVideoElement;
47
+ private bindVideoEvents;
48
+ private unbindVideoEvents;
49
+ private getVideoErrorMessage;
50
+ mount(target: HTMLElement): void;
51
+ destroy(): void;
52
+ getVideoElement(): HTMLVideoElement | null;
53
+ togglePlayback(): void;
54
+ }
55
+ export {};
package/package.json ADDED
@@ -0,0 +1,54 @@
1
+ {
2
+ "name": "ylh-pc-ad-sdk",
3
+ "version": "0.1.0",
4
+ "type": "module",
5
+ "publishConfig": {
6
+ "access": "public",
7
+ "registry": "https://registry.npmjs.org/"
8
+ },
9
+ "main": "dist/gdt-union-sdk.js",
10
+ "module": "dist/gdt-union-sdk.esm.js",
11
+ "types": "dist/index.d.ts",
12
+ "files": [
13
+ "dist"
14
+ ],
15
+ "exports": {
16
+ ".": {
17
+ "import": "./dist/gdt-union-sdk.esm.js",
18
+ "require": "./dist/gdt-union-sdk.js",
19
+ "types": "./dist/index.d.ts"
20
+ },
21
+ "./bridge": {
22
+ "import": "./dist/gdt-union-bridge.esm.js",
23
+ "require": "./dist/gdt-union-bridge.js",
24
+ "types": "./dist/bridge.d.ts"
25
+ }
26
+ },
27
+ "scripts": {
28
+ "build": "cross-env NODE_ENV=production BUILD_ENV=production rollup -c",
29
+ "build:test": "cross-env NODE_ENV=production BUILD_ENV=test rollup -c",
30
+ "build:dev": "cross-env NODE_ENV=development BUILD_ENV=development rollup -c",
31
+ "dev": "cross-env NODE_ENV=development BUILD_ENV=development rollup -c -w",
32
+ "prepublishOnly": "npm run build",
33
+ "publish:npm": "npm publish --access public"
34
+ },
35
+ "devDependencies": {
36
+ "@rollup/plugin-commonjs": "^28.0.2",
37
+ "@rollup/plugin-json": "^6.1.0",
38
+ "@rollup/plugin-node-resolve": "^16.0.0",
39
+ "@rollup/plugin-replace": "^6.0.2",
40
+ "@rollup/plugin-terser": "^0.4.4",
41
+ "@rollup/plugin-typescript": "^11.1.5",
42
+ "@types/crypto-js": "^4.2.2",
43
+ "@types/node": "^22.13.4",
44
+ "cross-env": "^7.0.3",
45
+ "rollup": "^4.1.4",
46
+ "rollup-plugin-analyzer": "^4.0.0",
47
+ "rollup-plugin-filesize": "^10.0.0",
48
+ "tslib": "^2.6.2",
49
+ "typescript": "^5.2.2"
50
+ },
51
+ "dependencies": {
52
+ "crypto-js": "^4.2.0"
53
+ }
54
+ }