@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/index.js
CHANGED
|
@@ -493,6 +493,38 @@ function extractDefaultsFromSchema(schema) {
|
|
|
493
493
|
}
|
|
494
494
|
return void 0;
|
|
495
495
|
}
|
|
496
|
+
function getLanguageCode() {
|
|
497
|
+
try {
|
|
498
|
+
return (navigator.language || "en").split("-")[0].toLowerCase();
|
|
499
|
+
} catch (e) {
|
|
500
|
+
return "en";
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
function lookupI18nRuntime(runtime, key, langCode) {
|
|
504
|
+
var _a, _b;
|
|
505
|
+
const map = runtime[key];
|
|
506
|
+
if (!map || typeof map !== "object") return void 0;
|
|
507
|
+
return (_b = (_a = map[langCode]) != null ? _a : map["en"]) != null ? _b : Object.values(map)[0];
|
|
508
|
+
}
|
|
509
|
+
function resolveI18nRefs(config, i18nRecord, langCode) {
|
|
510
|
+
var _a;
|
|
511
|
+
if (!config || typeof config !== "object" || Array.isArray(config)) return;
|
|
512
|
+
const runtime = (_a = i18nRecord.runtime) != null ? _a : {};
|
|
513
|
+
for (const key of Object.keys(config)) {
|
|
514
|
+
const value = config[key];
|
|
515
|
+
if (typeof value === "string") {
|
|
516
|
+
if (value.startsWith("i18n.runtime.")) {
|
|
517
|
+
const i18nKey = value.slice("i18n.runtime.".length);
|
|
518
|
+
const resolved = lookupI18nRuntime(runtime, i18nKey, langCode);
|
|
519
|
+
if (resolved !== void 0) {
|
|
520
|
+
config[key] = resolved;
|
|
521
|
+
}
|
|
522
|
+
}
|
|
523
|
+
} else if (value !== null && typeof value === "object" && !Array.isArray(value)) {
|
|
524
|
+
resolveI18nRefs(value, i18nRecord, langCode);
|
|
525
|
+
}
|
|
526
|
+
}
|
|
527
|
+
}
|
|
496
528
|
function resolveImagePaths(config, assetRecordByPath) {
|
|
497
529
|
if (!assetRecordByPath || !config || typeof config !== "object") return;
|
|
498
530
|
for (const key of Object.keys(config)) {
|
|
@@ -520,7 +552,7 @@ function deepMerge(target, source) {
|
|
|
520
552
|
return target;
|
|
521
553
|
}
|
|
522
554
|
function setConfig(configList, config) {
|
|
523
|
-
const { assetRecordByPath } = config;
|
|
555
|
+
const { assetRecordByPath, i18nRecord } = config;
|
|
524
556
|
const resolvedConfigs = configList.map((item) => {
|
|
525
557
|
var _a;
|
|
526
558
|
if (!item) return {};
|
|
@@ -531,6 +563,10 @@ function setConfig(configList, config) {
|
|
|
531
563
|
for (const data of rest) {
|
|
532
564
|
deepMerge(mergedConfig, data);
|
|
533
565
|
}
|
|
566
|
+
if (i18nRecord) {
|
|
567
|
+
const langCode = getLanguageCode();
|
|
568
|
+
resolveI18nRefs(mergedConfig, i18nRecord, langCode);
|
|
569
|
+
}
|
|
534
570
|
resolveImagePaths(mergedConfig, assetRecordByPath);
|
|
535
571
|
_cachedConfig = mergedConfig;
|
|
536
572
|
}
|
|
@@ -542,6 +578,83 @@ function getConfig() {
|
|
|
542
578
|
return _cachedConfig;
|
|
543
579
|
}
|
|
544
580
|
|
|
581
|
+
// src/cursor.ts
|
|
582
|
+
var cleanup = null;
|
|
583
|
+
function toCursor(src, size) {
|
|
584
|
+
const hotspot = Math.round(size / 8);
|
|
585
|
+
return new Promise((resolve, reject) => {
|
|
586
|
+
const img = new Image();
|
|
587
|
+
img.onload = () => {
|
|
588
|
+
const c = document.createElement("canvas");
|
|
589
|
+
c.width = size;
|
|
590
|
+
c.height = size;
|
|
591
|
+
const ctx = c.getContext("2d");
|
|
592
|
+
if (!ctx) {
|
|
593
|
+
reject(new Error("[PlayableSDK] Failed to get 2d context for cursor"));
|
|
594
|
+
return;
|
|
595
|
+
}
|
|
596
|
+
ctx.drawImage(img, 0, 0, size, size);
|
|
597
|
+
resolve(`url(${c.toDataURL("image/png")}) ${hotspot} ${hotspot}, pointer`);
|
|
598
|
+
};
|
|
599
|
+
img.onerror = () => reject(new Error("[PlayableSDK] Failed to load cursor image"));
|
|
600
|
+
img.src = src;
|
|
601
|
+
});
|
|
602
|
+
}
|
|
603
|
+
function enableCustomCursor(opts = {}) {
|
|
604
|
+
var _a, _b;
|
|
605
|
+
cleanup == null ? void 0 : cleanup();
|
|
606
|
+
cleanup = null;
|
|
607
|
+
if (typeof document === "undefined") return () => {
|
|
608
|
+
};
|
|
609
|
+
const target = (_a = opts.target) != null ? _a : document.body;
|
|
610
|
+
if (!target) {
|
|
611
|
+
console.warn("[PlayableSDK] enableCustomCursor: target not found");
|
|
612
|
+
return () => {
|
|
613
|
+
};
|
|
614
|
+
}
|
|
615
|
+
const size = (_b = opts.size) != null ? _b : 64;
|
|
616
|
+
const prevCursor = target.style.cursor;
|
|
617
|
+
let disposed = false;
|
|
618
|
+
let down = null;
|
|
619
|
+
let up = null;
|
|
620
|
+
const dispose = () => {
|
|
621
|
+
if (disposed) return;
|
|
622
|
+
disposed = true;
|
|
623
|
+
target.style.cursor = prevCursor;
|
|
624
|
+
if (down) target.removeEventListener("pointerdown", down);
|
|
625
|
+
if (up) {
|
|
626
|
+
target.removeEventListener("pointerup", up);
|
|
627
|
+
target.removeEventListener("pointercancel", up);
|
|
628
|
+
}
|
|
629
|
+
if (cleanup === dispose) cleanup = null;
|
|
630
|
+
};
|
|
631
|
+
cleanup = dispose;
|
|
632
|
+
Promise.all([
|
|
633
|
+
toCursor(FINGER_HOVERING, size),
|
|
634
|
+
toCursor(FINGER_PRESSING, size)
|
|
635
|
+
]).then(([hover, press]) => {
|
|
636
|
+
if (disposed) return;
|
|
637
|
+
target.style.cursor = hover;
|
|
638
|
+
down = () => {
|
|
639
|
+
target.style.cursor = press;
|
|
640
|
+
};
|
|
641
|
+
up = () => {
|
|
642
|
+
target.style.cursor = hover;
|
|
643
|
+
};
|
|
644
|
+
target.addEventListener("pointerdown", down);
|
|
645
|
+
target.addEventListener("pointerup", up);
|
|
646
|
+
target.addEventListener("pointercancel", up);
|
|
647
|
+
}).catch((err) => {
|
|
648
|
+
console.warn("[PlayableSDK] enableCustomCursor failed:", err);
|
|
649
|
+
dispose();
|
|
650
|
+
});
|
|
651
|
+
return dispose;
|
|
652
|
+
}
|
|
653
|
+
function disableCustomCursor() {
|
|
654
|
+
cleanup == null ? void 0 : cleanup();
|
|
655
|
+
cleanup = null;
|
|
656
|
+
}
|
|
657
|
+
|
|
545
658
|
// src/core.ts
|
|
546
659
|
var destinationUrl = "";
|
|
547
660
|
var isSDKInitialized = false;
|
|
@@ -877,6 +990,7 @@ var _sdk = class _sdk {
|
|
|
877
990
|
* This must be called as earlier as possible.
|
|
878
991
|
*
|
|
879
992
|
* @param callback Optional function called when ad container is ready
|
|
993
|
+
* @param options Optional configuration options
|
|
880
994
|
* @example
|
|
881
995
|
* // Basic initialization
|
|
882
996
|
* sdk.playcraftInit();
|
|
@@ -889,12 +1003,15 @@ var _sdk = class _sdk {
|
|
|
889
1003
|
* @fires playcraftInit When SDK initialization starts
|
|
890
1004
|
* @fires playcraftReady When game instance is created and ready to load resources
|
|
891
1005
|
*/
|
|
892
|
-
static playcraftInit(callback) {
|
|
1006
|
+
static playcraftInit(callback, options) {
|
|
893
1007
|
if (isSDKInitialized) return;
|
|
894
1008
|
if (callback) initCallback = callback;
|
|
895
1009
|
initTrackingProtocols();
|
|
896
1010
|
document.readyState === "loading" ? window.addEventListener("DOMContentLoaded", initSDK) : initSDK();
|
|
897
1011
|
isSDKInitialized = true;
|
|
1012
|
+
if ((options == null ? void 0 : options.useCustomCursor) !== false) {
|
|
1013
|
+
enableCustomCursor();
|
|
1014
|
+
}
|
|
898
1015
|
}
|
|
899
1016
|
/**
|
|
900
1017
|
* Starts the playable ad experience.
|
|
@@ -1287,9 +1404,35 @@ var _sdk = class _sdk {
|
|
|
1287
1404
|
static getConfig() {
|
|
1288
1405
|
return getConfig();
|
|
1289
1406
|
}
|
|
1407
|
+
/**
|
|
1408
|
+
* 启用自定义鼠标指针。默认挂载到 `document.body`,作用于整个页面。
|
|
1409
|
+
* 悬浮显示手指图标,按下时切换为按压态图标。
|
|
1410
|
+
* 多次调用会先清理上一次的状态再重新绑定。
|
|
1411
|
+
*
|
|
1412
|
+
* @param opts 可选配置
|
|
1413
|
+
* - opts.target: 目标元素,未传则默认 document.body
|
|
1414
|
+
* - opts.size: 光标尺寸(像素),默认 64,热点固定为 size 的 1/8
|
|
1415
|
+
* @returns 清理函数,调用后会恢复默认光标并解除事件监听
|
|
1416
|
+
*
|
|
1417
|
+
* @example
|
|
1418
|
+
* sdk.enableCustomCursor();
|
|
1419
|
+
* sdk.enableCustomCursor({ size: 96 });
|
|
1420
|
+
*/
|
|
1421
|
+
static enableCustomCursor(opts) {
|
|
1422
|
+
return enableCustomCursor(opts);
|
|
1423
|
+
}
|
|
1424
|
+
/**
|
|
1425
|
+
* 关闭自定义鼠标指针,恢复默认光标。
|
|
1426
|
+
*
|
|
1427
|
+
* @example
|
|
1428
|
+
* sdk.disableCustomCursor();
|
|
1429
|
+
*/
|
|
1430
|
+
static disableCustomCursor() {
|
|
1431
|
+
disableCustomCursor();
|
|
1432
|
+
}
|
|
1290
1433
|
};
|
|
1291
1434
|
/** Current version of the SDK */
|
|
1292
|
-
_sdk.version = "1.0.
|
|
1435
|
+
_sdk.version = "1.0.18-beta.1";
|
|
1293
1436
|
/** Current maximum width of the playable ad container in pixels */
|
|
1294
1437
|
_sdk.maxWidth = Math.floor(window.innerWidth);
|
|
1295
1438
|
/** Current maximum height of the playable ad container in pixels */
|
|
@@ -1315,83 +1458,6 @@ window["console"].log(
|
|
|
1315
1458
|
"background: #e1e4e8; color: #333; font-size: 14px; padding: 4px 8px; border-top-right-radius: 4px; border-bottom-right-radius: 4px;"
|
|
1316
1459
|
);
|
|
1317
1460
|
window.PlayableSDK = sdk;
|
|
1318
|
-
|
|
1319
|
-
// src/cursor.ts
|
|
1320
|
-
var cleanup = null;
|
|
1321
|
-
function toCursor(src, size) {
|
|
1322
|
-
const hotspot = Math.round(size / 8);
|
|
1323
|
-
return new Promise((resolve, reject) => {
|
|
1324
|
-
const img = new Image();
|
|
1325
|
-
img.onload = () => {
|
|
1326
|
-
const c = document.createElement("canvas");
|
|
1327
|
-
c.width = size;
|
|
1328
|
-
c.height = size;
|
|
1329
|
-
const ctx = c.getContext("2d");
|
|
1330
|
-
if (!ctx) {
|
|
1331
|
-
reject(new Error("[PlayableSDK] Failed to get 2d context for cursor"));
|
|
1332
|
-
return;
|
|
1333
|
-
}
|
|
1334
|
-
ctx.drawImage(img, 0, 0, size, size);
|
|
1335
|
-
resolve(`url(${c.toDataURL("image/png")}) ${hotspot} ${hotspot}, pointer`);
|
|
1336
|
-
};
|
|
1337
|
-
img.onerror = () => reject(new Error("[PlayableSDK] Failed to load cursor image"));
|
|
1338
|
-
img.src = src;
|
|
1339
|
-
});
|
|
1340
|
-
}
|
|
1341
|
-
function enableCustomCursor(opts = {}) {
|
|
1342
|
-
var _a, _b;
|
|
1343
|
-
cleanup == null ? void 0 : cleanup();
|
|
1344
|
-
cleanup = null;
|
|
1345
|
-
if (typeof document === "undefined") return () => {
|
|
1346
|
-
};
|
|
1347
|
-
const target = (_a = opts.target) != null ? _a : document.body;
|
|
1348
|
-
if (!target) {
|
|
1349
|
-
console.warn("[PlayableSDK] enableCustomCursor: target not found");
|
|
1350
|
-
return () => {
|
|
1351
|
-
};
|
|
1352
|
-
}
|
|
1353
|
-
const size = (_b = opts.size) != null ? _b : 64;
|
|
1354
|
-
const prevCursor = target.style.cursor;
|
|
1355
|
-
let disposed = false;
|
|
1356
|
-
let down = null;
|
|
1357
|
-
let up = null;
|
|
1358
|
-
const dispose = () => {
|
|
1359
|
-
if (disposed) return;
|
|
1360
|
-
disposed = true;
|
|
1361
|
-
target.style.cursor = prevCursor;
|
|
1362
|
-
if (down) target.removeEventListener("pointerdown", down);
|
|
1363
|
-
if (up) {
|
|
1364
|
-
target.removeEventListener("pointerup", up);
|
|
1365
|
-
target.removeEventListener("pointercancel", up);
|
|
1366
|
-
}
|
|
1367
|
-
if (cleanup === dispose) cleanup = null;
|
|
1368
|
-
};
|
|
1369
|
-
cleanup = dispose;
|
|
1370
|
-
Promise.all([
|
|
1371
|
-
toCursor(FINGER_HOVERING, size),
|
|
1372
|
-
toCursor(FINGER_PRESSING, size)
|
|
1373
|
-
]).then(([hover, press]) => {
|
|
1374
|
-
if (disposed) return;
|
|
1375
|
-
target.style.cursor = hover;
|
|
1376
|
-
down = () => {
|
|
1377
|
-
target.style.cursor = press;
|
|
1378
|
-
};
|
|
1379
|
-
up = () => {
|
|
1380
|
-
target.style.cursor = hover;
|
|
1381
|
-
};
|
|
1382
|
-
target.addEventListener("pointerdown", down);
|
|
1383
|
-
target.addEventListener("pointerup", up);
|
|
1384
|
-
target.addEventListener("pointercancel", up);
|
|
1385
|
-
}).catch((err) => {
|
|
1386
|
-
console.warn("[PlayableSDK] enableCustomCursor failed:", err);
|
|
1387
|
-
dispose();
|
|
1388
|
-
});
|
|
1389
|
-
return dispose;
|
|
1390
|
-
}
|
|
1391
|
-
function disableCustomCursor() {
|
|
1392
|
-
cleanup == null ? void 0 : cleanup();
|
|
1393
|
-
cleanup = null;
|
|
1394
|
-
}
|
|
1395
1461
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1396
1462
|
0 && (module.exports = {
|
|
1397
1463
|
disableCustomCursor,
|
package/package.json
CHANGED
|
@@ -1,56 +1,56 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@playcraft/adsdk",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"description": "统一的 Playable SDK,支持 MRAID、Google、Facebook、Vungle、BigoAds 等多广告渠道",
|
|
5
|
-
"main": "dist/index.js",
|
|
6
|
-
"module": "dist/esm/index.js",
|
|
7
|
-
"types": "dist/index.d.ts",
|
|
8
|
-
"repository": {
|
|
9
|
-
"type": "git"
|
|
10
|
-
},
|
|
11
|
-
"files": [
|
|
12
|
-
"dist",
|
|
13
|
-
"LICENSE",
|
|
14
|
-
"defines.d.ts"
|
|
15
|
-
],
|
|
16
|
-
"scripts": {
|
|
17
|
-
"build": "npx tsup",
|
|
18
|
-
"test": "jest",
|
|
19
|
-
"deploy": "npm run build && node scripts/publish.js",
|
|
20
|
-
"deploy:beta": "npm run build && node scripts/publish.js --tag beta"
|
|
21
|
-
},
|
|
22
|
-
"author": "Tencent ADS Team",
|
|
23
|
-
"license": "MIT",
|
|
24
|
-
"devDependencies": {
|
|
25
|
-
"@types/jest": "^29.5.14",
|
|
26
|
-
"jest": "^29.7.0",
|
|
27
|
-
"jest-environment-jsdom": "^29.7.0",
|
|
28
|
-
"ts-jest": "^29.2.5",
|
|
29
|
-
"tsup": "^8.4.0",
|
|
30
|
-
"typescript": "^5.7.2"
|
|
31
|
-
},
|
|
32
|
-
"keywords": [
|
|
33
|
-
"playable",
|
|
34
|
-
"sdk",
|
|
35
|
-
"playable-sdk",
|
|
36
|
-
"PlayableSDK",
|
|
37
|
-
"playable-ads",
|
|
38
|
-
"html5",
|
|
39
|
-
"tencent",
|
|
40
|
-
"bigoads",
|
|
41
|
-
"mraid",
|
|
42
|
-
"google-ads",
|
|
43
|
-
"facebook-playable",
|
|
44
|
-
"unity-ads",
|
|
45
|
-
"vungle",
|
|
46
|
-
"ironsource",
|
|
47
|
-
"javascript-sdk",
|
|
48
|
-
"typescript-sdk"
|
|
49
|
-
],
|
|
50
|
-
"publishConfig": {
|
|
51
|
-
"registry": "https://mirrors.tencent.com/npm/"
|
|
52
|
-
},
|
|
53
|
-
"dependencies": {
|
|
54
|
-
"@playcraft/ads-tracking": "*"
|
|
55
|
-
}
|
|
56
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@playcraft/adsdk",
|
|
3
|
+
"version": "1.0.18-beta.1",
|
|
4
|
+
"description": "统一的 Playable SDK,支持 MRAID、Google、Facebook、Vungle、BigoAds 等多广告渠道",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"module": "dist/esm/index.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git"
|
|
10
|
+
},
|
|
11
|
+
"files": [
|
|
12
|
+
"dist",
|
|
13
|
+
"LICENSE",
|
|
14
|
+
"defines.d.ts"
|
|
15
|
+
],
|
|
16
|
+
"scripts": {
|
|
17
|
+
"build": "npx tsup",
|
|
18
|
+
"test": "jest",
|
|
19
|
+
"deploy": "npm run build && node scripts/publish.js",
|
|
20
|
+
"deploy:beta": "npm run build && node scripts/publish.js --tag beta"
|
|
21
|
+
},
|
|
22
|
+
"author": "Tencent ADS Team",
|
|
23
|
+
"license": "MIT",
|
|
24
|
+
"devDependencies": {
|
|
25
|
+
"@types/jest": "^29.5.14",
|
|
26
|
+
"jest": "^29.7.0",
|
|
27
|
+
"jest-environment-jsdom": "^29.7.0",
|
|
28
|
+
"ts-jest": "^29.2.5",
|
|
29
|
+
"tsup": "^8.4.0",
|
|
30
|
+
"typescript": "^5.7.2"
|
|
31
|
+
},
|
|
32
|
+
"keywords": [
|
|
33
|
+
"playable",
|
|
34
|
+
"sdk",
|
|
35
|
+
"playable-sdk",
|
|
36
|
+
"PlayableSDK",
|
|
37
|
+
"playable-ads",
|
|
38
|
+
"html5",
|
|
39
|
+
"tencent",
|
|
40
|
+
"bigoads",
|
|
41
|
+
"mraid",
|
|
42
|
+
"google-ads",
|
|
43
|
+
"facebook-playable",
|
|
44
|
+
"unity-ads",
|
|
45
|
+
"vungle",
|
|
46
|
+
"ironsource",
|
|
47
|
+
"javascript-sdk",
|
|
48
|
+
"typescript-sdk"
|
|
49
|
+
],
|
|
50
|
+
"publishConfig": {
|
|
51
|
+
"registry": "https://mirrors.tencent.com/npm/"
|
|
52
|
+
},
|
|
53
|
+
"dependencies": {
|
|
54
|
+
"@playcraft/ads-tracking": "*"
|
|
55
|
+
}
|
|
56
|
+
}
|