@playcraft/adsdk 1.0.16 → 1.0.18-beta.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.
- package/LICENSE +21 -21
- package/defines.d.ts +130 -130
- package/dist/esm/index.js +146 -80
- package/dist/iife/index.js +146 -80
- package/dist/index.d.mts +69 -31
- package/dist/index.d.ts +69 -31
- package/dist/index.js +146 -80
- package/package.json +56 -56
package/dist/iife/index.js
CHANGED
|
@@ -699,6 +699,38 @@
|
|
|
699
699
|
}
|
|
700
700
|
return void 0;
|
|
701
701
|
}
|
|
702
|
+
function getLanguageCode() {
|
|
703
|
+
try {
|
|
704
|
+
return (navigator.language || "en").split("-")[0].toLowerCase();
|
|
705
|
+
} catch (e) {
|
|
706
|
+
return "en";
|
|
707
|
+
}
|
|
708
|
+
}
|
|
709
|
+
function lookupI18nRuntime(runtime, key, langCode) {
|
|
710
|
+
var _a, _b;
|
|
711
|
+
const map = runtime[key];
|
|
712
|
+
if (!map || typeof map !== "object") return void 0;
|
|
713
|
+
return (_b = (_a = map[langCode]) != null ? _a : map["en"]) != null ? _b : Object.values(map)[0];
|
|
714
|
+
}
|
|
715
|
+
function resolveI18nRefs(config, i18nRecord, langCode) {
|
|
716
|
+
var _a;
|
|
717
|
+
if (!config || typeof config !== "object" || Array.isArray(config)) return;
|
|
718
|
+
const runtime = (_a = i18nRecord.runtime) != null ? _a : {};
|
|
719
|
+
for (const key of Object.keys(config)) {
|
|
720
|
+
const value = config[key];
|
|
721
|
+
if (typeof value === "string") {
|
|
722
|
+
if (value.startsWith("i18n.runtime.")) {
|
|
723
|
+
const i18nKey = value.slice("i18n.runtime.".length);
|
|
724
|
+
const resolved = lookupI18nRuntime(runtime, i18nKey, langCode);
|
|
725
|
+
if (resolved !== void 0) {
|
|
726
|
+
config[key] = resolved;
|
|
727
|
+
}
|
|
728
|
+
}
|
|
729
|
+
} else if (value !== null && typeof value === "object" && !Array.isArray(value)) {
|
|
730
|
+
resolveI18nRefs(value, i18nRecord, langCode);
|
|
731
|
+
}
|
|
732
|
+
}
|
|
733
|
+
}
|
|
702
734
|
function resolveImagePaths(config, assetRecordByPath) {
|
|
703
735
|
if (!assetRecordByPath || !config || typeof config !== "object") return;
|
|
704
736
|
for (const key of Object.keys(config)) {
|
|
@@ -726,7 +758,7 @@
|
|
|
726
758
|
return target;
|
|
727
759
|
}
|
|
728
760
|
function setConfig(configList, config) {
|
|
729
|
-
const { assetRecordByPath } = config;
|
|
761
|
+
const { assetRecordByPath, i18nRecord } = config;
|
|
730
762
|
const resolvedConfigs = configList.map((item) => {
|
|
731
763
|
var _a;
|
|
732
764
|
if (!item) return {};
|
|
@@ -737,6 +769,10 @@
|
|
|
737
769
|
for (const data of rest) {
|
|
738
770
|
deepMerge(mergedConfig, data);
|
|
739
771
|
}
|
|
772
|
+
if (i18nRecord) {
|
|
773
|
+
const langCode = getLanguageCode();
|
|
774
|
+
resolveI18nRefs(mergedConfig, i18nRecord, langCode);
|
|
775
|
+
}
|
|
740
776
|
resolveImagePaths(mergedConfig, assetRecordByPath);
|
|
741
777
|
_cachedConfig = mergedConfig;
|
|
742
778
|
}
|
|
@@ -748,6 +784,83 @@
|
|
|
748
784
|
return _cachedConfig;
|
|
749
785
|
}
|
|
750
786
|
|
|
787
|
+
// src/cursor.ts
|
|
788
|
+
var cleanup = null;
|
|
789
|
+
function toCursor(src, size) {
|
|
790
|
+
const hotspot = Math.round(size / 8);
|
|
791
|
+
return new Promise((resolve, reject) => {
|
|
792
|
+
const img = new Image();
|
|
793
|
+
img.onload = () => {
|
|
794
|
+
const c = document.createElement("canvas");
|
|
795
|
+
c.width = size;
|
|
796
|
+
c.height = size;
|
|
797
|
+
const ctx = c.getContext("2d");
|
|
798
|
+
if (!ctx) {
|
|
799
|
+
reject(new Error("[PlayableSDK] Failed to get 2d context for cursor"));
|
|
800
|
+
return;
|
|
801
|
+
}
|
|
802
|
+
ctx.drawImage(img, 0, 0, size, size);
|
|
803
|
+
resolve(`url(${c.toDataURL("image/png")}) ${hotspot} ${hotspot}, pointer`);
|
|
804
|
+
};
|
|
805
|
+
img.onerror = () => reject(new Error("[PlayableSDK] Failed to load cursor image"));
|
|
806
|
+
img.src = src;
|
|
807
|
+
});
|
|
808
|
+
}
|
|
809
|
+
function enableCustomCursor(opts = {}) {
|
|
810
|
+
var _a, _b;
|
|
811
|
+
cleanup == null ? void 0 : cleanup();
|
|
812
|
+
cleanup = null;
|
|
813
|
+
if (typeof document === "undefined") return () => {
|
|
814
|
+
};
|
|
815
|
+
const target = (_a = opts.target) != null ? _a : document.body;
|
|
816
|
+
if (!target) {
|
|
817
|
+
console.warn("[PlayableSDK] enableCustomCursor: target not found");
|
|
818
|
+
return () => {
|
|
819
|
+
};
|
|
820
|
+
}
|
|
821
|
+
const size = (_b = opts.size) != null ? _b : 64;
|
|
822
|
+
const prevCursor = target.style.cursor;
|
|
823
|
+
let disposed = false;
|
|
824
|
+
let down = null;
|
|
825
|
+
let up = null;
|
|
826
|
+
const dispose = () => {
|
|
827
|
+
if (disposed) return;
|
|
828
|
+
disposed = true;
|
|
829
|
+
target.style.cursor = prevCursor;
|
|
830
|
+
if (down) target.removeEventListener("pointerdown", down);
|
|
831
|
+
if (up) {
|
|
832
|
+
target.removeEventListener("pointerup", up);
|
|
833
|
+
target.removeEventListener("pointercancel", up);
|
|
834
|
+
}
|
|
835
|
+
if (cleanup === dispose) cleanup = null;
|
|
836
|
+
};
|
|
837
|
+
cleanup = dispose;
|
|
838
|
+
Promise.all([
|
|
839
|
+
toCursor(FINGER_HOVERING, size),
|
|
840
|
+
toCursor(FINGER_PRESSING, size)
|
|
841
|
+
]).then(([hover, press]) => {
|
|
842
|
+
if (disposed) return;
|
|
843
|
+
target.style.cursor = hover;
|
|
844
|
+
down = () => {
|
|
845
|
+
target.style.cursor = press;
|
|
846
|
+
};
|
|
847
|
+
up = () => {
|
|
848
|
+
target.style.cursor = hover;
|
|
849
|
+
};
|
|
850
|
+
target.addEventListener("pointerdown", down);
|
|
851
|
+
target.addEventListener("pointerup", up);
|
|
852
|
+
target.addEventListener("pointercancel", up);
|
|
853
|
+
}).catch((err) => {
|
|
854
|
+
console.warn("[PlayableSDK] enableCustomCursor failed:", err);
|
|
855
|
+
dispose();
|
|
856
|
+
});
|
|
857
|
+
return dispose;
|
|
858
|
+
}
|
|
859
|
+
function disableCustomCursor() {
|
|
860
|
+
cleanup == null ? void 0 : cleanup();
|
|
861
|
+
cleanup = null;
|
|
862
|
+
}
|
|
863
|
+
|
|
751
864
|
// src/core.ts
|
|
752
865
|
var destinationUrl = "";
|
|
753
866
|
var isSDKInitialized = false;
|
|
@@ -1083,6 +1196,7 @@
|
|
|
1083
1196
|
* This must be called as earlier as possible.
|
|
1084
1197
|
*
|
|
1085
1198
|
* @param callback Optional function called when ad container is ready
|
|
1199
|
+
* @param options Optional configuration options
|
|
1086
1200
|
* @example
|
|
1087
1201
|
* // Basic initialization
|
|
1088
1202
|
* sdk.playcraftInit();
|
|
@@ -1095,12 +1209,15 @@
|
|
|
1095
1209
|
* @fires playcraftInit When SDK initialization starts
|
|
1096
1210
|
* @fires playcraftReady When game instance is created and ready to load resources
|
|
1097
1211
|
*/
|
|
1098
|
-
static playcraftInit(callback) {
|
|
1212
|
+
static playcraftInit(callback, options) {
|
|
1099
1213
|
if (isSDKInitialized) return;
|
|
1100
1214
|
if (callback) initCallback = callback;
|
|
1101
1215
|
initTrackingProtocols();
|
|
1102
1216
|
document.readyState === "loading" ? window.addEventListener("DOMContentLoaded", initSDK) : initSDK();
|
|
1103
1217
|
isSDKInitialized = true;
|
|
1218
|
+
if ((options == null ? void 0 : options.useCustomCursor) !== false) {
|
|
1219
|
+
enableCustomCursor();
|
|
1220
|
+
}
|
|
1104
1221
|
}
|
|
1105
1222
|
/**
|
|
1106
1223
|
* Starts the playable ad experience.
|
|
@@ -1493,9 +1610,35 @@
|
|
|
1493
1610
|
static getConfig() {
|
|
1494
1611
|
return getConfig();
|
|
1495
1612
|
}
|
|
1613
|
+
/**
|
|
1614
|
+
* 启用自定义鼠标指针。默认挂载到 `document.body`,作用于整个页面。
|
|
1615
|
+
* 悬浮显示手指图标,按下时切换为按压态图标。
|
|
1616
|
+
* 多次调用会先清理上一次的状态再重新绑定。
|
|
1617
|
+
*
|
|
1618
|
+
* @param opts 可选配置
|
|
1619
|
+
* - opts.target: 目标元素,未传则默认 document.body
|
|
1620
|
+
* - opts.size: 光标尺寸(像素),默认 64,热点固定为 size 的 1/8
|
|
1621
|
+
* @returns 清理函数,调用后会恢复默认光标并解除事件监听
|
|
1622
|
+
*
|
|
1623
|
+
* @example
|
|
1624
|
+
* sdk.enableCustomCursor();
|
|
1625
|
+
* sdk.enableCustomCursor({ size: 96 });
|
|
1626
|
+
*/
|
|
1627
|
+
static enableCustomCursor(opts) {
|
|
1628
|
+
return enableCustomCursor(opts);
|
|
1629
|
+
}
|
|
1630
|
+
/**
|
|
1631
|
+
* 关闭自定义鼠标指针,恢复默认光标。
|
|
1632
|
+
*
|
|
1633
|
+
* @example
|
|
1634
|
+
* sdk.disableCustomCursor();
|
|
1635
|
+
*/
|
|
1636
|
+
static disableCustomCursor() {
|
|
1637
|
+
disableCustomCursor();
|
|
1638
|
+
}
|
|
1496
1639
|
};
|
|
1497
1640
|
/** Current version of the SDK */
|
|
1498
|
-
_sdk.version = "1.0.
|
|
1641
|
+
_sdk.version = "1.0.18-beta.1";
|
|
1499
1642
|
/** Current maximum width of the playable ad container in pixels */
|
|
1500
1643
|
_sdk.maxWidth = Math.floor(window.innerWidth);
|
|
1501
1644
|
/** Current maximum height of the playable ad container in pixels */
|
|
@@ -1521,81 +1664,4 @@
|
|
|
1521
1664
|
"background: #e1e4e8; color: #333; font-size: 14px; padding: 4px 8px; border-top-right-radius: 4px; border-bottom-right-radius: 4px;"
|
|
1522
1665
|
);
|
|
1523
1666
|
window.PlayableSDK = sdk;
|
|
1524
|
-
|
|
1525
|
-
// src/cursor.ts
|
|
1526
|
-
var cleanup = null;
|
|
1527
|
-
function toCursor(src, size) {
|
|
1528
|
-
const hotspot = Math.round(size / 8);
|
|
1529
|
-
return new Promise((resolve, reject) => {
|
|
1530
|
-
const img = new Image();
|
|
1531
|
-
img.onload = () => {
|
|
1532
|
-
const c = document.createElement("canvas");
|
|
1533
|
-
c.width = size;
|
|
1534
|
-
c.height = size;
|
|
1535
|
-
const ctx = c.getContext("2d");
|
|
1536
|
-
if (!ctx) {
|
|
1537
|
-
reject(new Error("[PlayableSDK] Failed to get 2d context for cursor"));
|
|
1538
|
-
return;
|
|
1539
|
-
}
|
|
1540
|
-
ctx.drawImage(img, 0, 0, size, size);
|
|
1541
|
-
resolve(`url(${c.toDataURL("image/png")}) ${hotspot} ${hotspot}, pointer`);
|
|
1542
|
-
};
|
|
1543
|
-
img.onerror = () => reject(new Error("[PlayableSDK] Failed to load cursor image"));
|
|
1544
|
-
img.src = src;
|
|
1545
|
-
});
|
|
1546
|
-
}
|
|
1547
|
-
function enableCustomCursor(opts = {}) {
|
|
1548
|
-
var _a, _b;
|
|
1549
|
-
cleanup == null ? void 0 : cleanup();
|
|
1550
|
-
cleanup = null;
|
|
1551
|
-
if (typeof document === "undefined") return () => {
|
|
1552
|
-
};
|
|
1553
|
-
const target = (_a = opts.target) != null ? _a : document.body;
|
|
1554
|
-
if (!target) {
|
|
1555
|
-
console.warn("[PlayableSDK] enableCustomCursor: target not found");
|
|
1556
|
-
return () => {
|
|
1557
|
-
};
|
|
1558
|
-
}
|
|
1559
|
-
const size = (_b = opts.size) != null ? _b : 64;
|
|
1560
|
-
const prevCursor = target.style.cursor;
|
|
1561
|
-
let disposed = false;
|
|
1562
|
-
let down = null;
|
|
1563
|
-
let up = null;
|
|
1564
|
-
const dispose = () => {
|
|
1565
|
-
if (disposed) return;
|
|
1566
|
-
disposed = true;
|
|
1567
|
-
target.style.cursor = prevCursor;
|
|
1568
|
-
if (down) target.removeEventListener("pointerdown", down);
|
|
1569
|
-
if (up) {
|
|
1570
|
-
target.removeEventListener("pointerup", up);
|
|
1571
|
-
target.removeEventListener("pointercancel", up);
|
|
1572
|
-
}
|
|
1573
|
-
if (cleanup === dispose) cleanup = null;
|
|
1574
|
-
};
|
|
1575
|
-
cleanup = dispose;
|
|
1576
|
-
Promise.all([
|
|
1577
|
-
toCursor(FINGER_HOVERING, size),
|
|
1578
|
-
toCursor(FINGER_PRESSING, size)
|
|
1579
|
-
]).then(([hover, press]) => {
|
|
1580
|
-
if (disposed) return;
|
|
1581
|
-
target.style.cursor = hover;
|
|
1582
|
-
down = () => {
|
|
1583
|
-
target.style.cursor = press;
|
|
1584
|
-
};
|
|
1585
|
-
up = () => {
|
|
1586
|
-
target.style.cursor = hover;
|
|
1587
|
-
};
|
|
1588
|
-
target.addEventListener("pointerdown", down);
|
|
1589
|
-
target.addEventListener("pointerup", up);
|
|
1590
|
-
target.addEventListener("pointercancel", up);
|
|
1591
|
-
}).catch((err) => {
|
|
1592
|
-
console.warn("[PlayableSDK] enableCustomCursor failed:", err);
|
|
1593
|
-
dispose();
|
|
1594
|
-
});
|
|
1595
|
-
return dispose;
|
|
1596
|
-
}
|
|
1597
|
-
function disableCustomCursor() {
|
|
1598
|
-
cleanup == null ? void 0 : cleanup();
|
|
1599
|
-
cleanup = null;
|
|
1600
|
-
}
|
|
1601
1667
|
})();
|
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* i18n 数据结构(仅 runtime,SDK 只处理游戏内运行时多语言):
|
|
3
|
+
* runtime: { [key]: { [langCode]: "文案" } }
|
|
4
|
+
*
|
|
5
|
+
* xplatform(配置平台 UI 标题)由外部配置平台自行解析,不传入 SDK。
|
|
6
|
+
*/
|
|
7
|
+
type I18nRecord = {
|
|
8
|
+
runtime?: Record<string, Record<string, string>>;
|
|
9
|
+
};
|
|
10
|
+
|
|
1
11
|
type EventName = 'playcraftInit' | 'playcraftReady' | 'playcraftStart' | 'playcraftInteractive' | 'playcraftInteraction' | 'playcraftChallengeStart' | 'playcraftChallengeProgress' | 'playcraftChallengeSuccess' | 'playcraftChallengeFailed' | 'playcraftResize' | 'playcraftPause' | 'playcraftResume' | 'playcraftVolume' | 'playcraftRetry' | 'playcraftFinish' | 'playcraftInstall';
|
|
2
12
|
|
|
13
|
+
/**
|
|
14
|
+
* 自定义鼠标指针模块。
|
|
15
|
+
*
|
|
16
|
+
* 默认挂载到 `document.body`,把整页的默认光标替换为内置的手指图标:
|
|
17
|
+
* - 悬浮时显示 FingerHovering
|
|
18
|
+
* - 按下时显示 FingerPressing
|
|
19
|
+
*
|
|
20
|
+
* 图片以 base64 dataURL 形式内置到产物中,无需额外加载资源。
|
|
21
|
+
*/
|
|
22
|
+
interface CursorOptions {
|
|
23
|
+
/** 目标元素,未传则默认挂载到 document.body */
|
|
24
|
+
target?: HTMLElement;
|
|
25
|
+
/** 光标尺寸(像素),默认 64。热点固定为 size 的 1/8 */
|
|
26
|
+
size?: number;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* 启用自定义鼠标指针。默认挂载到 `document.body`,作用于整个页面。
|
|
30
|
+
*
|
|
31
|
+
* 多次调用时,会先清理上一次的状态再重新绑定。
|
|
32
|
+
*
|
|
33
|
+
* @returns 清理函数,调用后会恢复默认光标并解除事件监听。
|
|
34
|
+
*/
|
|
35
|
+
declare function enableCustomCursor(opts?: CursorOptions): () => void;
|
|
36
|
+
/**
|
|
37
|
+
* 关闭自定义鼠标指针,恢复默认光标。
|
|
38
|
+
*/
|
|
39
|
+
declare function disableCustomCursor(): void;
|
|
40
|
+
|
|
3
41
|
type InitCallbackType = (maxWidth: number, maxHeight: number) => void;
|
|
4
42
|
/**
|
|
5
43
|
* Main SDK class providing playable ad functionality and state management.
|
|
@@ -31,6 +69,7 @@ declare class sdk {
|
|
|
31
69
|
* This must be called as earlier as possible.
|
|
32
70
|
*
|
|
33
71
|
* @param callback Optional function called when ad container is ready
|
|
72
|
+
* @param options Optional configuration options
|
|
34
73
|
* @example
|
|
35
74
|
* // Basic initialization
|
|
36
75
|
* sdk.playcraftInit();
|
|
@@ -43,7 +82,9 @@ declare class sdk {
|
|
|
43
82
|
* @fires playcraftInit When SDK initialization starts
|
|
44
83
|
* @fires playcraftReady When game instance is created and ready to load resources
|
|
45
84
|
*/
|
|
46
|
-
static playcraftInit(callback?: InitCallbackType
|
|
85
|
+
static playcraftInit(callback?: InitCallbackType, options?: {
|
|
86
|
+
useCustomCursor?: boolean;
|
|
87
|
+
}): void;
|
|
47
88
|
/**
|
|
48
89
|
* Starts the playable ad experience.
|
|
49
90
|
* Should be called after all resources are loaded and first frame is rendered.
|
|
@@ -238,7 +279,10 @@ declare class sdk {
|
|
|
238
279
|
* { assetRecordByPath: imageAssets }
|
|
239
280
|
* );
|
|
240
281
|
*/
|
|
241
|
-
static setConfig(configList: any[], config:
|
|
282
|
+
static setConfig(configList: any[], config: {
|
|
283
|
+
assetRecordByPath: Record<string, string>;
|
|
284
|
+
i18nRecord?: I18nRecord;
|
|
285
|
+
}): void;
|
|
242
286
|
/**
|
|
243
287
|
* 获取合并后的主题配置。
|
|
244
288
|
* 返回 schema 默认值与用户主题数据深度合并后的结果。
|
|
@@ -251,6 +295,28 @@ declare class sdk {
|
|
|
251
295
|
* console.log(config.primaryColor); // '#ff0000'
|
|
252
296
|
*/
|
|
253
297
|
static getConfig(): Record<string, any>;
|
|
298
|
+
/**
|
|
299
|
+
* 启用自定义鼠标指针。默认挂载到 `document.body`,作用于整个页面。
|
|
300
|
+
* 悬浮显示手指图标,按下时切换为按压态图标。
|
|
301
|
+
* 多次调用会先清理上一次的状态再重新绑定。
|
|
302
|
+
*
|
|
303
|
+
* @param opts 可选配置
|
|
304
|
+
* - opts.target: 目标元素,未传则默认 document.body
|
|
305
|
+
* - opts.size: 光标尺寸(像素),默认 64,热点固定为 size 的 1/8
|
|
306
|
+
* @returns 清理函数,调用后会恢复默认光标并解除事件监听
|
|
307
|
+
*
|
|
308
|
+
* @example
|
|
309
|
+
* sdk.enableCustomCursor();
|
|
310
|
+
* sdk.enableCustomCursor({ size: 96 });
|
|
311
|
+
*/
|
|
312
|
+
static enableCustomCursor(opts?: CursorOptions): () => void;
|
|
313
|
+
/**
|
|
314
|
+
* 关闭自定义鼠标指针,恢复默认光标。
|
|
315
|
+
*
|
|
316
|
+
* @example
|
|
317
|
+
* sdk.disableCustomCursor();
|
|
318
|
+
*/
|
|
319
|
+
static disableCustomCursor(): void;
|
|
254
320
|
}
|
|
255
321
|
|
|
256
322
|
/**
|
|
@@ -270,32 +336,4 @@ declare function hideWechatGuide(): void;
|
|
|
270
336
|
*/
|
|
271
337
|
declare function removeWechatGuide(): void;
|
|
272
338
|
|
|
273
|
-
|
|
274
|
-
* 自定义鼠标指针模块。
|
|
275
|
-
*
|
|
276
|
-
* 默认挂载到 `document.body`,把整页的默认光标替换为内置的手指图标:
|
|
277
|
-
* - 悬浮时显示 FingerHovering
|
|
278
|
-
* - 按下时显示 FingerPressing
|
|
279
|
-
*
|
|
280
|
-
* 图片以 base64 dataURL 形式内置到产物中,无需额外加载资源。
|
|
281
|
-
*/
|
|
282
|
-
interface CursorOptions {
|
|
283
|
-
/** 目标元素,未传则默认挂载到 document.body */
|
|
284
|
-
target?: HTMLElement;
|
|
285
|
-
/** 光标尺寸(像素),默认 64。热点固定为 size 的 1/8 */
|
|
286
|
-
size?: number;
|
|
287
|
-
}
|
|
288
|
-
/**
|
|
289
|
-
* 启用自定义鼠标指针。默认挂载到 `document.body`,作用于整个页面。
|
|
290
|
-
*
|
|
291
|
-
* 多次调用时,会先清理上一次的状态再重新绑定。
|
|
292
|
-
*
|
|
293
|
-
* @returns 清理函数,调用后会恢复默认光标并解除事件监听。
|
|
294
|
-
*/
|
|
295
|
-
declare function enableCustomCursor(opts?: CursorOptions): () => void;
|
|
296
|
-
/**
|
|
297
|
-
* 关闭自定义鼠标指针,恢复默认光标。
|
|
298
|
-
*/
|
|
299
|
-
declare function disableCustomCursor(): void;
|
|
300
|
-
|
|
301
|
-
export { type CursorOptions, sdk as default, disableCustomCursor, enableCustomCursor, hideWechatGuide, removeWechatGuide, sdk, showWechatGuide };
|
|
339
|
+
export { type CursorOptions, type I18nRecord, sdk as default, disableCustomCursor, enableCustomCursor, hideWechatGuide, removeWechatGuide, sdk, showWechatGuide };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* i18n 数据结构(仅 runtime,SDK 只处理游戏内运行时多语言):
|
|
3
|
+
* runtime: { [key]: { [langCode]: "文案" } }
|
|
4
|
+
*
|
|
5
|
+
* xplatform(配置平台 UI 标题)由外部配置平台自行解析,不传入 SDK。
|
|
6
|
+
*/
|
|
7
|
+
type I18nRecord = {
|
|
8
|
+
runtime?: Record<string, Record<string, string>>;
|
|
9
|
+
};
|
|
10
|
+
|
|
1
11
|
type EventName = 'playcraftInit' | 'playcraftReady' | 'playcraftStart' | 'playcraftInteractive' | 'playcraftInteraction' | 'playcraftChallengeStart' | 'playcraftChallengeProgress' | 'playcraftChallengeSuccess' | 'playcraftChallengeFailed' | 'playcraftResize' | 'playcraftPause' | 'playcraftResume' | 'playcraftVolume' | 'playcraftRetry' | 'playcraftFinish' | 'playcraftInstall';
|
|
2
12
|
|
|
13
|
+
/**
|
|
14
|
+
* 自定义鼠标指针模块。
|
|
15
|
+
*
|
|
16
|
+
* 默认挂载到 `document.body`,把整页的默认光标替换为内置的手指图标:
|
|
17
|
+
* - 悬浮时显示 FingerHovering
|
|
18
|
+
* - 按下时显示 FingerPressing
|
|
19
|
+
*
|
|
20
|
+
* 图片以 base64 dataURL 形式内置到产物中,无需额外加载资源。
|
|
21
|
+
*/
|
|
22
|
+
interface CursorOptions {
|
|
23
|
+
/** 目标元素,未传则默认挂载到 document.body */
|
|
24
|
+
target?: HTMLElement;
|
|
25
|
+
/** 光标尺寸(像素),默认 64。热点固定为 size 的 1/8 */
|
|
26
|
+
size?: number;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* 启用自定义鼠标指针。默认挂载到 `document.body`,作用于整个页面。
|
|
30
|
+
*
|
|
31
|
+
* 多次调用时,会先清理上一次的状态再重新绑定。
|
|
32
|
+
*
|
|
33
|
+
* @returns 清理函数,调用后会恢复默认光标并解除事件监听。
|
|
34
|
+
*/
|
|
35
|
+
declare function enableCustomCursor(opts?: CursorOptions): () => void;
|
|
36
|
+
/**
|
|
37
|
+
* 关闭自定义鼠标指针,恢复默认光标。
|
|
38
|
+
*/
|
|
39
|
+
declare function disableCustomCursor(): void;
|
|
40
|
+
|
|
3
41
|
type InitCallbackType = (maxWidth: number, maxHeight: number) => void;
|
|
4
42
|
/**
|
|
5
43
|
* Main SDK class providing playable ad functionality and state management.
|
|
@@ -31,6 +69,7 @@ declare class sdk {
|
|
|
31
69
|
* This must be called as earlier as possible.
|
|
32
70
|
*
|
|
33
71
|
* @param callback Optional function called when ad container is ready
|
|
72
|
+
* @param options Optional configuration options
|
|
34
73
|
* @example
|
|
35
74
|
* // Basic initialization
|
|
36
75
|
* sdk.playcraftInit();
|
|
@@ -43,7 +82,9 @@ declare class sdk {
|
|
|
43
82
|
* @fires playcraftInit When SDK initialization starts
|
|
44
83
|
* @fires playcraftReady When game instance is created and ready to load resources
|
|
45
84
|
*/
|
|
46
|
-
static playcraftInit(callback?: InitCallbackType
|
|
85
|
+
static playcraftInit(callback?: InitCallbackType, options?: {
|
|
86
|
+
useCustomCursor?: boolean;
|
|
87
|
+
}): void;
|
|
47
88
|
/**
|
|
48
89
|
* Starts the playable ad experience.
|
|
49
90
|
* Should be called after all resources are loaded and first frame is rendered.
|
|
@@ -238,7 +279,10 @@ declare class sdk {
|
|
|
238
279
|
* { assetRecordByPath: imageAssets }
|
|
239
280
|
* );
|
|
240
281
|
*/
|
|
241
|
-
static setConfig(configList: any[], config:
|
|
282
|
+
static setConfig(configList: any[], config: {
|
|
283
|
+
assetRecordByPath: Record<string, string>;
|
|
284
|
+
i18nRecord?: I18nRecord;
|
|
285
|
+
}): void;
|
|
242
286
|
/**
|
|
243
287
|
* 获取合并后的主题配置。
|
|
244
288
|
* 返回 schema 默认值与用户主题数据深度合并后的结果。
|
|
@@ -251,6 +295,28 @@ declare class sdk {
|
|
|
251
295
|
* console.log(config.primaryColor); // '#ff0000'
|
|
252
296
|
*/
|
|
253
297
|
static getConfig(): Record<string, any>;
|
|
298
|
+
/**
|
|
299
|
+
* 启用自定义鼠标指针。默认挂载到 `document.body`,作用于整个页面。
|
|
300
|
+
* 悬浮显示手指图标,按下时切换为按压态图标。
|
|
301
|
+
* 多次调用会先清理上一次的状态再重新绑定。
|
|
302
|
+
*
|
|
303
|
+
* @param opts 可选配置
|
|
304
|
+
* - opts.target: 目标元素,未传则默认 document.body
|
|
305
|
+
* - opts.size: 光标尺寸(像素),默认 64,热点固定为 size 的 1/8
|
|
306
|
+
* @returns 清理函数,调用后会恢复默认光标并解除事件监听
|
|
307
|
+
*
|
|
308
|
+
* @example
|
|
309
|
+
* sdk.enableCustomCursor();
|
|
310
|
+
* sdk.enableCustomCursor({ size: 96 });
|
|
311
|
+
*/
|
|
312
|
+
static enableCustomCursor(opts?: CursorOptions): () => void;
|
|
313
|
+
/**
|
|
314
|
+
* 关闭自定义鼠标指针,恢复默认光标。
|
|
315
|
+
*
|
|
316
|
+
* @example
|
|
317
|
+
* sdk.disableCustomCursor();
|
|
318
|
+
*/
|
|
319
|
+
static disableCustomCursor(): void;
|
|
254
320
|
}
|
|
255
321
|
|
|
256
322
|
/**
|
|
@@ -270,32 +336,4 @@ declare function hideWechatGuide(): void;
|
|
|
270
336
|
*/
|
|
271
337
|
declare function removeWechatGuide(): void;
|
|
272
338
|
|
|
273
|
-
|
|
274
|
-
* 自定义鼠标指针模块。
|
|
275
|
-
*
|
|
276
|
-
* 默认挂载到 `document.body`,把整页的默认光标替换为内置的手指图标:
|
|
277
|
-
* - 悬浮时显示 FingerHovering
|
|
278
|
-
* - 按下时显示 FingerPressing
|
|
279
|
-
*
|
|
280
|
-
* 图片以 base64 dataURL 形式内置到产物中,无需额外加载资源。
|
|
281
|
-
*/
|
|
282
|
-
interface CursorOptions {
|
|
283
|
-
/** 目标元素,未传则默认挂载到 document.body */
|
|
284
|
-
target?: HTMLElement;
|
|
285
|
-
/** 光标尺寸(像素),默认 64。热点固定为 size 的 1/8 */
|
|
286
|
-
size?: number;
|
|
287
|
-
}
|
|
288
|
-
/**
|
|
289
|
-
* 启用自定义鼠标指针。默认挂载到 `document.body`,作用于整个页面。
|
|
290
|
-
*
|
|
291
|
-
* 多次调用时,会先清理上一次的状态再重新绑定。
|
|
292
|
-
*
|
|
293
|
-
* @returns 清理函数,调用后会恢复默认光标并解除事件监听。
|
|
294
|
-
*/
|
|
295
|
-
declare function enableCustomCursor(opts?: CursorOptions): () => void;
|
|
296
|
-
/**
|
|
297
|
-
* 关闭自定义鼠标指针,恢复默认光标。
|
|
298
|
-
*/
|
|
299
|
-
declare function disableCustomCursor(): void;
|
|
300
|
-
|
|
301
|
-
export { type CursorOptions, sdk as default, disableCustomCursor, enableCustomCursor, hideWechatGuide, removeWechatGuide, sdk, showWechatGuide };
|
|
339
|
+
export { type CursorOptions, type I18nRecord, sdk as default, disableCustomCursor, enableCustomCursor, hideWechatGuide, removeWechatGuide, sdk, showWechatGuide };
|