@playcraft/adsdk 1.0.17 → 1.0.18-beta.2
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 +249 -2
- package/dist/iife/index.js +247 -2
- package/dist/index.d.mts +63 -2
- package/dist/index.d.ts +63 -2
- package/dist/index.js +251 -2
- package/package.json +56 -56
package/dist/index.js
CHANGED
|
@@ -23,6 +23,8 @@ __export(index_exports, {
|
|
|
23
23
|
default: () => sdk,
|
|
24
24
|
disableCustomCursor: () => disableCustomCursor,
|
|
25
25
|
enableCustomCursor: () => enableCustomCursor,
|
|
26
|
+
getLanguage: () => getLanguage,
|
|
27
|
+
getLanguageCode: () => getLanguageCode,
|
|
26
28
|
hideWechatGuide: () => hideWechatGuide,
|
|
27
29
|
removeWechatGuide: () => removeWechatGuide,
|
|
28
30
|
sdk: () => sdk,
|
|
@@ -475,6 +477,196 @@ function removeWechatGuide() {
|
|
|
475
477
|
}
|
|
476
478
|
}
|
|
477
479
|
|
|
480
|
+
// src/language.ts
|
|
481
|
+
function readQuerystring(key) {
|
|
482
|
+
try {
|
|
483
|
+
if (typeof window === "undefined" || !window.location) return void 0;
|
|
484
|
+
const search = window.location.search || "";
|
|
485
|
+
if (!search) return void 0;
|
|
486
|
+
if (typeof URLSearchParams !== "undefined") {
|
|
487
|
+
const params = new URLSearchParams(search);
|
|
488
|
+
return params.get(key) || void 0;
|
|
489
|
+
}
|
|
490
|
+
const re = new RegExp("[?&]" + key.replace(/[.*+?^${}()|[\]\\]/g, "\\$&") + "=([^&#]*)");
|
|
491
|
+
const m = re.exec(search);
|
|
492
|
+
return m ? decodeURIComponent(m[1]) : void 0;
|
|
493
|
+
} catch (e) {
|
|
494
|
+
return void 0;
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
function readLocalStorage(key) {
|
|
498
|
+
try {
|
|
499
|
+
if (typeof localStorage === "undefined") return void 0;
|
|
500
|
+
return localStorage.getItem(key) || void 0;
|
|
501
|
+
} catch (e) {
|
|
502
|
+
return void 0;
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
function readCookie(name) {
|
|
506
|
+
try {
|
|
507
|
+
if (typeof document === "undefined" || !document.cookie) return void 0;
|
|
508
|
+
const re = new RegExp("(?:^|; )" + name.replace(/[.*+?^${}()|[\]\\]/g, "\\$&") + "=([^;]*)");
|
|
509
|
+
const m = re.exec(document.cookie);
|
|
510
|
+
return m ? decodeURIComponent(m[1]) : void 0;
|
|
511
|
+
} catch (e) {
|
|
512
|
+
return void 0;
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
function readNavigatorLanguages() {
|
|
516
|
+
try {
|
|
517
|
+
if (typeof navigator === "undefined") return [];
|
|
518
|
+
const list = [];
|
|
519
|
+
const langs = navigator.languages;
|
|
520
|
+
if (Array.isArray(langs)) list.push(...langs);
|
|
521
|
+
if (navigator.language) list.push(navigator.language);
|
|
522
|
+
const userLang = navigator.userLanguage || navigator.browserLanguage;
|
|
523
|
+
if (userLang) list.push(userLang);
|
|
524
|
+
return list.filter(Boolean);
|
|
525
|
+
} catch (e) {
|
|
526
|
+
return [];
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
function readHtmlTag() {
|
|
530
|
+
try {
|
|
531
|
+
if (typeof document === "undefined" || !document.documentElement) return void 0;
|
|
532
|
+
return document.documentElement.lang || void 0;
|
|
533
|
+
} catch (e) {
|
|
534
|
+
return void 0;
|
|
535
|
+
}
|
|
536
|
+
}
|
|
537
|
+
function detectCandidates() {
|
|
538
|
+
return [
|
|
539
|
+
readQuerystring("lng"),
|
|
540
|
+
readLocalStorage("i18nextLng"),
|
|
541
|
+
readCookie("i18next"),
|
|
542
|
+
...readNavigatorLanguages(),
|
|
543
|
+
readHtmlTag()
|
|
544
|
+
];
|
|
545
|
+
}
|
|
546
|
+
var SUPPORTED_LANG_CODES = [
|
|
547
|
+
"en",
|
|
548
|
+
"zh",
|
|
549
|
+
"ja",
|
|
550
|
+
"ko",
|
|
551
|
+
"de",
|
|
552
|
+
"fr",
|
|
553
|
+
"es",
|
|
554
|
+
"pt",
|
|
555
|
+
"it",
|
|
556
|
+
"hi",
|
|
557
|
+
"bn",
|
|
558
|
+
"ur",
|
|
559
|
+
"ar",
|
|
560
|
+
"tr",
|
|
561
|
+
"ru",
|
|
562
|
+
"ms",
|
|
563
|
+
"id"
|
|
564
|
+
];
|
|
565
|
+
function normalizeLangTag(tag) {
|
|
566
|
+
if (!tag || typeof tag !== "string") return void 0;
|
|
567
|
+
const primary = tag.split(/[-_]/)[0].toLowerCase();
|
|
568
|
+
return SUPPORTED_LANG_CODES.indexOf(primary) >= 0 ? primary : void 0;
|
|
569
|
+
}
|
|
570
|
+
function getLanguageCode() {
|
|
571
|
+
const candidates = detectCandidates();
|
|
572
|
+
for (const tag of candidates) {
|
|
573
|
+
const code = normalizeLangTag(tag);
|
|
574
|
+
if (code) return code;
|
|
575
|
+
}
|
|
576
|
+
return "en";
|
|
577
|
+
}
|
|
578
|
+
var LANGUAGE_MAP = {
|
|
579
|
+
// 英语
|
|
580
|
+
"en": "EN",
|
|
581
|
+
// 中文(简体)
|
|
582
|
+
"zh": "CN_S",
|
|
583
|
+
"zh-cn": "CN_S",
|
|
584
|
+
"zh-sg": "CN_S",
|
|
585
|
+
"zh-my": "CN_S",
|
|
586
|
+
"zh-hans": "CN_S",
|
|
587
|
+
"zh-hans-cn": "CN_S",
|
|
588
|
+
"zh-hans-sg": "CN_S",
|
|
589
|
+
"zh-hans-my": "CN_S",
|
|
590
|
+
// 中文(繁体)
|
|
591
|
+
"zh-tw": "CN_T",
|
|
592
|
+
"zh-hk": "CN_T",
|
|
593
|
+
"zh-mo": "CN_T",
|
|
594
|
+
"zh-hant": "CN_T",
|
|
595
|
+
"zh-hant-tw": "CN_T",
|
|
596
|
+
"zh-hant-hk": "CN_T",
|
|
597
|
+
"zh-hant-mo": "CN_T",
|
|
598
|
+
// 德语
|
|
599
|
+
"de": "DE",
|
|
600
|
+
// 法语
|
|
601
|
+
"fr": "FR",
|
|
602
|
+
// 西班牙语
|
|
603
|
+
"es": "ES",
|
|
604
|
+
// 日语
|
|
605
|
+
"ja": "JA",
|
|
606
|
+
// 韩语
|
|
607
|
+
"ko": "KO",
|
|
608
|
+
// 葡萄牙语
|
|
609
|
+
"pt": "PT",
|
|
610
|
+
// 意大利语
|
|
611
|
+
"it": "IT",
|
|
612
|
+
// 印地语
|
|
613
|
+
"hi": "HI",
|
|
614
|
+
// 孟加拉语
|
|
615
|
+
"bn": "BN",
|
|
616
|
+
// 乌尔都语
|
|
617
|
+
"ur": "UR",
|
|
618
|
+
// 阿拉伯语
|
|
619
|
+
"ar": "AR",
|
|
620
|
+
// 土耳其语
|
|
621
|
+
"tr": "TR",
|
|
622
|
+
// 俄语
|
|
623
|
+
"ru": "RU",
|
|
624
|
+
// 马来语
|
|
625
|
+
"ms": "MS",
|
|
626
|
+
// 印尼语
|
|
627
|
+
"id": "ID"
|
|
628
|
+
};
|
|
629
|
+
var SUPPORTED_PROJECT_LANGUAGES = /* @__PURE__ */ new Set([
|
|
630
|
+
"EN",
|
|
631
|
+
"CN_S",
|
|
632
|
+
"CN_T",
|
|
633
|
+
"DE",
|
|
634
|
+
"FR",
|
|
635
|
+
"ES",
|
|
636
|
+
"JA",
|
|
637
|
+
"KO",
|
|
638
|
+
"PT",
|
|
639
|
+
"IT",
|
|
640
|
+
"HI",
|
|
641
|
+
"BN",
|
|
642
|
+
"UR",
|
|
643
|
+
"AR",
|
|
644
|
+
"TR",
|
|
645
|
+
"RU",
|
|
646
|
+
"MS",
|
|
647
|
+
"IN",
|
|
648
|
+
"ID"
|
|
649
|
+
]);
|
|
650
|
+
function resolveLanguageTag(tag) {
|
|
651
|
+
if (!tag || typeof tag !== "string") return void 0;
|
|
652
|
+
const normalized = tag.trim();
|
|
653
|
+
if (!normalized) return void 0;
|
|
654
|
+
const projectCode = normalized.toUpperCase().replace(/-/g, "_");
|
|
655
|
+
if (SUPPORTED_PROJECT_LANGUAGES.has(projectCode)) return projectCode;
|
|
656
|
+
const lower = normalized.toLowerCase();
|
|
657
|
+
if (LANGUAGE_MAP[lower]) return LANGUAGE_MAP[lower];
|
|
658
|
+
const primary = lower.split(/[-_]/)[0];
|
|
659
|
+
return LANGUAGE_MAP[primary];
|
|
660
|
+
}
|
|
661
|
+
function getLanguage() {
|
|
662
|
+
const candidates = detectCandidates();
|
|
663
|
+
for (const tag of candidates) {
|
|
664
|
+
const code = resolveLanguageTag(tag);
|
|
665
|
+
if (code) return code;
|
|
666
|
+
}
|
|
667
|
+
return "EN";
|
|
668
|
+
}
|
|
669
|
+
|
|
478
670
|
// src/theme-config.ts
|
|
479
671
|
function extractDefaultsFromSchema(schema) {
|
|
480
672
|
if (!schema || typeof schema !== "object") return void 0;
|
|
@@ -493,6 +685,31 @@ function extractDefaultsFromSchema(schema) {
|
|
|
493
685
|
}
|
|
494
686
|
return void 0;
|
|
495
687
|
}
|
|
688
|
+
function lookupI18nRuntime(runtime, key, langCode) {
|
|
689
|
+
var _a, _b;
|
|
690
|
+
const map = runtime[key];
|
|
691
|
+
if (!map || typeof map !== "object") return void 0;
|
|
692
|
+
return (_b = (_a = map[langCode]) != null ? _a : map["en"]) != null ? _b : Object.values(map)[0];
|
|
693
|
+
}
|
|
694
|
+
function resolveI18nRefs(config, i18nRecord, langCode) {
|
|
695
|
+
var _a;
|
|
696
|
+
if (!config || typeof config !== "object" || Array.isArray(config)) return;
|
|
697
|
+
const runtime = (_a = i18nRecord.runtime) != null ? _a : {};
|
|
698
|
+
for (const key of Object.keys(config)) {
|
|
699
|
+
const value = config[key];
|
|
700
|
+
if (typeof value === "string") {
|
|
701
|
+
if (value.startsWith("i18n.runtime.")) {
|
|
702
|
+
const i18nKey = value.slice("i18n.runtime.".length);
|
|
703
|
+
const resolved = lookupI18nRuntime(runtime, i18nKey, langCode);
|
|
704
|
+
if (resolved !== void 0) {
|
|
705
|
+
config[key] = resolved;
|
|
706
|
+
}
|
|
707
|
+
}
|
|
708
|
+
} else if (value !== null && typeof value === "object" && !Array.isArray(value)) {
|
|
709
|
+
resolveI18nRefs(value, i18nRecord, langCode);
|
|
710
|
+
}
|
|
711
|
+
}
|
|
712
|
+
}
|
|
496
713
|
function resolveImagePaths(config, assetRecordByPath) {
|
|
497
714
|
if (!assetRecordByPath || !config || typeof config !== "object") return;
|
|
498
715
|
for (const key of Object.keys(config)) {
|
|
@@ -520,7 +737,7 @@ function deepMerge(target, source) {
|
|
|
520
737
|
return target;
|
|
521
738
|
}
|
|
522
739
|
function setConfig(configList, config) {
|
|
523
|
-
const { assetRecordByPath } = config;
|
|
740
|
+
const { assetRecordByPath, i18nRecord } = config;
|
|
524
741
|
const resolvedConfigs = configList.map((item) => {
|
|
525
742
|
var _a;
|
|
526
743
|
if (!item) return {};
|
|
@@ -531,6 +748,11 @@ function setConfig(configList, config) {
|
|
|
531
748
|
for (const data of rest) {
|
|
532
749
|
deepMerge(mergedConfig, data);
|
|
533
750
|
}
|
|
751
|
+
if (i18nRecord) {
|
|
752
|
+
const langCode = getLanguageCode();
|
|
753
|
+
console.log("detect target langCode", langCode);
|
|
754
|
+
resolveI18nRefs(mergedConfig, i18nRecord, langCode);
|
|
755
|
+
}
|
|
534
756
|
resolveImagePaths(mergedConfig, assetRecordByPath);
|
|
535
757
|
_cachedConfig = mergedConfig;
|
|
536
758
|
}
|
|
@@ -1334,6 +1556,31 @@ var _sdk = class _sdk {
|
|
|
1334
1556
|
static isGoogle() {
|
|
1335
1557
|
return _sdk.getCurChannel() === "google";
|
|
1336
1558
|
}
|
|
1559
|
+
/**
|
|
1560
|
+
* 获取当前用户语言的 i18n 简码。
|
|
1561
|
+
* 多源探测(querystring → localStorage → cookie → navigator → html tag)。
|
|
1562
|
+
*
|
|
1563
|
+
* @returns i18n 简码:en | zh | ja | ko | de | fr | es | pt | it | hi | bn | ur | ar | tr | ru | ms | id,默认 'en'
|
|
1564
|
+
*
|
|
1565
|
+
* @example
|
|
1566
|
+
* const langCode = sdk.getLanguageCode(); // 'zh'
|
|
1567
|
+
*/
|
|
1568
|
+
static getLanguageCode() {
|
|
1569
|
+
return getLanguageCode();
|
|
1570
|
+
}
|
|
1571
|
+
/**
|
|
1572
|
+
* 获取当前用户语言的业务代号。
|
|
1573
|
+
* 多源探测(querystring → localStorage → cookie → navigator → html tag),
|
|
1574
|
+
* 并映射到业务语言代号(区分简繁中文)。
|
|
1575
|
+
*
|
|
1576
|
+
* @returns 业务代号:EN | CN_S | CN_T | DE | FR | ES | JA | KO | PT | IT | HI | BN | UR | AR | TR | RU | MS | IN | ID,默认 'EN'
|
|
1577
|
+
*
|
|
1578
|
+
* @example
|
|
1579
|
+
* const lang = sdk.getLanguage(); // 'CN_S'
|
|
1580
|
+
*/
|
|
1581
|
+
static getLanguage() {
|
|
1582
|
+
return getLanguage();
|
|
1583
|
+
}
|
|
1337
1584
|
/**
|
|
1338
1585
|
* 设置主题配置,支持传入多份 JSON5 配置。
|
|
1339
1586
|
* 每一份配置都可以是 JSON Schema(带 $schema 字段),会自动提取其中的 default 值。
|
|
@@ -1396,7 +1643,7 @@ var _sdk = class _sdk {
|
|
|
1396
1643
|
}
|
|
1397
1644
|
};
|
|
1398
1645
|
/** Current version of the SDK */
|
|
1399
|
-
_sdk.version = "1.0.
|
|
1646
|
+
_sdk.version = "1.0.18-beta.2";
|
|
1400
1647
|
/** Current maximum width of the playable ad container in pixels */
|
|
1401
1648
|
_sdk.maxWidth = Math.floor(window.innerWidth);
|
|
1402
1649
|
/** Current maximum height of the playable ad container in pixels */
|
|
@@ -1426,6 +1673,8 @@ window.PlayableSDK = sdk;
|
|
|
1426
1673
|
0 && (module.exports = {
|
|
1427
1674
|
disableCustomCursor,
|
|
1428
1675
|
enableCustomCursor,
|
|
1676
|
+
getLanguage,
|
|
1677
|
+
getLanguageCode,
|
|
1429
1678
|
hideWechatGuide,
|
|
1430
1679
|
removeWechatGuide,
|
|
1431
1680
|
sdk,
|
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.2",
|
|
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
|
+
}
|