@livo-tv/blocks 1.36.0 → 1.36.1-pr.6.435b966
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/dist/consent.cjs +85 -0
- package/dist/consent.cjs.map +1 -0
- package/dist/consent.d.cts +20 -0
- package/dist/consent.d.ts +20 -0
- package/dist/consent.js +73 -0
- package/dist/consent.js.map +1 -0
- package/dist/index.cjs +452 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +63 -1
- package/dist/index.d.ts +63 -1
- package/dist/index.js +435 -1
- package/dist/index.js.map +1 -1
- package/package.json +11 -1
package/dist/consent.cjs
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// src/lib/cookie-consent.ts
|
|
4
|
+
var COOKIE_CONSENT_NAME = "livo-cookie-consent";
|
|
5
|
+
var COOKIE_CONSENT_VALUES = ["necessary", "all"];
|
|
6
|
+
var COOKIE_CONSENT_MAX_AGE = 180 * 24 * 60 * 60;
|
|
7
|
+
function isCookieConsentValue(value) {
|
|
8
|
+
return typeof value === "string" && COOKIE_CONSENT_VALUES.includes(value);
|
|
9
|
+
}
|
|
10
|
+
function cookieConsentAllowsReplay(value) {
|
|
11
|
+
return value === "all";
|
|
12
|
+
}
|
|
13
|
+
function cookieDomainFromHostname(hostname) {
|
|
14
|
+
const host = hostname.toLowerCase();
|
|
15
|
+
if (host === "localhost" || host === "127.0.0.1") return void 0;
|
|
16
|
+
if (host.endsWith(".livo.tv") || host === "livo.tv") return ".livo.tv";
|
|
17
|
+
if (host.endsWith(".livo-tv.workers.dev") || host === "livo-tv.workers.dev") {
|
|
18
|
+
return ".livo-tv.workers.dev";
|
|
19
|
+
}
|
|
20
|
+
return void 0;
|
|
21
|
+
}
|
|
22
|
+
function readCookieMap(cookieSource) {
|
|
23
|
+
const map = /* @__PURE__ */ new Map();
|
|
24
|
+
for (const part of cookieSource.split(";")) {
|
|
25
|
+
const trimmed = part.trim();
|
|
26
|
+
if (!trimmed) continue;
|
|
27
|
+
const eq = trimmed.indexOf("=");
|
|
28
|
+
if (eq < 0) continue;
|
|
29
|
+
const name = trimmed.slice(0, eq).trim();
|
|
30
|
+
const raw = trimmed.slice(eq + 1).trim();
|
|
31
|
+
map.set(name, decodeURIComponent(raw));
|
|
32
|
+
}
|
|
33
|
+
return map;
|
|
34
|
+
}
|
|
35
|
+
function parseCookieConsent(cookieSource) {
|
|
36
|
+
const raw = readCookieMap(cookieSource).get(COOKIE_CONSENT_NAME);
|
|
37
|
+
return isCookieConsentValue(raw) ? raw : null;
|
|
38
|
+
}
|
|
39
|
+
function readCookieConsent() {
|
|
40
|
+
if (typeof document === "undefined") return null;
|
|
41
|
+
return parseCookieConsent(document.cookie);
|
|
42
|
+
}
|
|
43
|
+
function serializeCookieConsent(value, options = {}) {
|
|
44
|
+
const maxAge = options.maxAge ?? COOKIE_CONSENT_MAX_AGE;
|
|
45
|
+
const secure = options.secure ?? (typeof window !== "undefined" && window.location.protocol === "https:");
|
|
46
|
+
const parts = [
|
|
47
|
+
`${COOKIE_CONSENT_NAME}=${encodeURIComponent(value)}`,
|
|
48
|
+
"Path=/",
|
|
49
|
+
`Max-Age=${maxAge}`,
|
|
50
|
+
"SameSite=Lax"
|
|
51
|
+
];
|
|
52
|
+
if (options.domain) {
|
|
53
|
+
parts.push(`Domain=${options.domain}`);
|
|
54
|
+
}
|
|
55
|
+
if (secure) {
|
|
56
|
+
parts.push("Secure");
|
|
57
|
+
}
|
|
58
|
+
return parts.join("; ");
|
|
59
|
+
}
|
|
60
|
+
function writeCookieConsent(value, options = {}) {
|
|
61
|
+
if (typeof document === "undefined") return;
|
|
62
|
+
document.cookie = serializeCookieConsent(value, options);
|
|
63
|
+
}
|
|
64
|
+
function isEmbeddedWindow() {
|
|
65
|
+
if (typeof window === "undefined") return false;
|
|
66
|
+
try {
|
|
67
|
+
return window.self !== window.top;
|
|
68
|
+
} catch {
|
|
69
|
+
return true;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
exports.COOKIE_CONSENT_MAX_AGE = COOKIE_CONSENT_MAX_AGE;
|
|
74
|
+
exports.COOKIE_CONSENT_NAME = COOKIE_CONSENT_NAME;
|
|
75
|
+
exports.COOKIE_CONSENT_VALUES = COOKIE_CONSENT_VALUES;
|
|
76
|
+
exports.cookieConsentAllowsReplay = cookieConsentAllowsReplay;
|
|
77
|
+
exports.cookieDomainFromHostname = cookieDomainFromHostname;
|
|
78
|
+
exports.isCookieConsentValue = isCookieConsentValue;
|
|
79
|
+
exports.isEmbeddedWindow = isEmbeddedWindow;
|
|
80
|
+
exports.parseCookieConsent = parseCookieConsent;
|
|
81
|
+
exports.readCookieConsent = readCookieConsent;
|
|
82
|
+
exports.serializeCookieConsent = serializeCookieConsent;
|
|
83
|
+
exports.writeCookieConsent = writeCookieConsent;
|
|
84
|
+
//# sourceMappingURL=consent.cjs.map
|
|
85
|
+
//# sourceMappingURL=consent.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/lib/cookie-consent.ts"],"names":[],"mappings":";;;AAAO,IAAM,mBAAA,GAAsB;AAE5B,IAAM,qBAAA,GAAwB,CAAC,WAAA,EAAa,KAAK;AAKjD,IAAM,sBAAA,GAAyB,GAAA,GAAM,EAAA,GAAK,EAAA,GAAK;AAQ/C,SAAS,qBACf,KAAA,EAC8B;AAC9B,EAAA,OACC,OAAO,KAAA,KAAU,QAAA,IAChB,qBAAA,CAA4C,SAAS,KAAK,CAAA;AAE7D;AAEO,SAAS,0BACf,KAAA,EACU;AACV,EAAA,OAAO,KAAA,KAAU,KAAA;AAClB;AAEO,SAAS,yBAAyB,QAAA,EAAsC;AAC9E,EAAA,MAAM,IAAA,GAAO,SAAS,WAAA,EAAY;AAClC,EAAA,IAAI,IAAA,KAAS,WAAA,IAAe,IAAA,KAAS,WAAA,EAAa,OAAO,MAAA;AACzD,EAAA,IAAI,K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AqC,EAAC,EAC7B;AACT,EAAA,MAAM,MAAA,GAAS,QAAQ,MAAA,IAAU,sBAAA;AACjC,EAAA,MAAM,MAAA,GACL,QAAQ,MAAA,KACP,OAAO,WAAW,WAAA,IAAe,MAAA,CAAO,SAAS,QAAA,KAAa,QAAA,CAAA;AAChE,EAAA,MAAM,KAAA,GAAQ;AAAA,IACb,CAAA,EAAG,mBAAmB,CAAA,CAAA,EAAI,kBAAA,CAAmB,KAAK,CAAC,CAAA,CAAA;AAAA,IACnD,QAAA;AAAA,IACA,WAAW,MAAM,CAAA,CAAA;AAAA,IACjB;AAAA,GACD;AACA,EAAA,IAAI,QAAQ,MAAA,EAAQ;AACnB,IAAA,KAAA,CAAM,IAAA,CAAK,CAAA,OAAA,EAAU,OAAA,CAAQ,MAAM,CAAA,CAAE,CAAA;AAAA,EACtC;AACA,EAAA,IAAI,MAAA,EAAQ;AACX,IAAA,KAAA,CAAM,KAAK,QAAQ,CAAA;AAAA,EACpB;AACA,EAAA,OAAO,KAAA,CAAM,KAAK,IAAI,CAAA;AACvB;AAEO,SAAS,kBAAA,CACf,KAAA,EACA,OAAA,GAAqC,EAAC,EAC/B;AACP,EAAA,IAAI,OAAO,aAAa,WAAA,EAAa;AACrC,EAAA,QAAA,CAAS,MAAA,GAAS,sBAAA,CAAuB,KAAA,EAAO,OAAO,CAAA;AACxD;AAEO,SAAS,gBAAA,GAA4B;AAC3C,EAAA,IAAI,OAAO,MAAA,KAAW,WAAA,EAAa,OAAO,KAAA;AAC1C,EAAA,IAAI;AACH,IAAA,OAAO,MAAA,CAAO,SAAS,MAAA,CAAO,GAAA;AAAA,EAC/B,CAAA,CAAA,MAAQ;AACP,IAAA,OAAO,IAAA;AAAA,EACR;AACD","file":"consent.cjs","sourcesContent":["export const COOKIE_CONSENT_NAME = \"livo-cookie-consent\";\n\nexport const COOKIE_CONSENT_VALUES = [\"necessary\", \"all\"] as const;\n\nexport type CookieConsentValue = (typeof COOKIE_CONSENT_VALUES)[number];\n\n/** ~180 days, matching contracts §1.2. */\nexport const COOKIE_CONSENT_MAX_AGE = 180 * 24 * 60 * 60;\n\nexport type WriteCookieConsentOptions = {\n\tdomain?: string;\n\tsecure?: boolean;\n\tmaxAge?: number;\n};\n\nexport function isCookieConsentValue(\n\tvalue: unknown,\n): value is CookieConsentValue {\n\treturn (\n\t\ttypeof value === \"string\" &&\n\t\t(COOKIE_CONSENT_VALUES as readonly string[]).includes(value)\n\t);\n}\n\nexport function cookieConsentAllowsReplay(\n\tvalue: CookieConsentValue | null | undefined,\n): boolean {\n\treturn value === \"all\";\n}\n\nexport function cookieDomainFromHostname(hostname: string): string | undefined {\n\tconst host = hostname.toLowerCase();\n\tif (host === \"localhost\" || host === \"127.0.0.1\") return undefined;\n\tif (host.endsWith(\".livo.tv\") || host === \"livo.tv\") return \".livo.tv\";\n\tif (host.endsWith(\".livo-tv.workers.dev\") || host === \"livo-tv.workers.dev\") {\n\t\treturn \".livo-tv.workers.dev\";\n\t}\n\treturn undefined;\n}\n\nfunction readCookieMap(cookieSource: string): Map<string, string> {\n\tconst map = new Map<string, string>();\n\tfor (const part of cookieSource.split(\";\")) {\n\t\tconst trimmed = part.trim();\n\t\tif (!trimmed) continue;\n\t\tconst eq = trimmed.indexOf(\"=\");\n\t\tif (eq < 0) continue;\n\t\tconst name = trimmed.slice(0, eq).trim();\n\t\tconst raw = trimmed.slice(eq + 1).trim();\n\t\tmap.set(name, decodeURIComponent(raw));\n\t}\n\treturn map;\n}\n\nexport function parseCookieConsent(\n\tcookieSource: string,\n): CookieConsentValue | null {\n\tconst raw = readCookieMap(cookieSource).get(COOKIE_CONSENT_NAME);\n\treturn isCookieConsentValue(raw) ? raw : null;\n}\n\nexport function readCookieConsent(): CookieConsentValue | null {\n\tif (typeof document === \"undefined\") return null;\n\treturn parseCookieConsent(document.cookie);\n}\n\nexport function serializeCookieConsent(\n\tvalue: CookieConsentValue,\n\toptions: WriteCookieConsentOptions = {},\n): string {\n\tconst maxAge = options.maxAge ?? COOKIE_CONSENT_MAX_AGE;\n\tconst secure =\n\t\toptions.secure ??\n\t\t(typeof window !== \"undefined\" && window.location.protocol === \"https:\");\n\tconst parts = [\n\t\t`${COOKIE_CONSENT_NAME}=${encodeURIComponent(value)}`,\n\t\t\"Path=/\",\n\t\t`Max-Age=${maxAge}`,\n\t\t\"SameSite=Lax\",\n\t];\n\tif (options.domain) {\n\t\tparts.push(`Domain=${options.domain}`);\n\t}\n\tif (secure) {\n\t\tparts.push(\"Secure\");\n\t}\n\treturn parts.join(\"; \");\n}\n\nexport function writeCookieConsent(\n\tvalue: CookieConsentValue,\n\toptions: WriteCookieConsentOptions = {},\n): void {\n\tif (typeof document === \"undefined\") return;\n\tdocument.cookie = serializeCookieConsent(value, options);\n}\n\nexport function isEmbeddedWindow(): boolean {\n\tif (typeof window === \"undefined\") return false;\n\ttry {\n\t\treturn window.self !== window.top;\n\t} catch {\n\t\treturn true;\n\t}\n}\n"]}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
declare const COOKIE_CONSENT_NAME = "livo-cookie-consent";
|
|
2
|
+
declare const COOKIE_CONSENT_VALUES: readonly ["necessary", "all"];
|
|
3
|
+
type CookieConsentValue = (typeof COOKIE_CONSENT_VALUES)[number];
|
|
4
|
+
/** ~180 days, matching contracts §1.2. */
|
|
5
|
+
declare const COOKIE_CONSENT_MAX_AGE: number;
|
|
6
|
+
type WriteCookieConsentOptions = {
|
|
7
|
+
domain?: string;
|
|
8
|
+
secure?: boolean;
|
|
9
|
+
maxAge?: number;
|
|
10
|
+
};
|
|
11
|
+
declare function isCookieConsentValue(value: unknown): value is CookieConsentValue;
|
|
12
|
+
declare function cookieConsentAllowsReplay(value: CookieConsentValue | null | undefined): boolean;
|
|
13
|
+
declare function cookieDomainFromHostname(hostname: string): string | undefined;
|
|
14
|
+
declare function parseCookieConsent(cookieSource: string): CookieConsentValue | null;
|
|
15
|
+
declare function readCookieConsent(): CookieConsentValue | null;
|
|
16
|
+
declare function serializeCookieConsent(value: CookieConsentValue, options?: WriteCookieConsentOptions): string;
|
|
17
|
+
declare function writeCookieConsent(value: CookieConsentValue, options?: WriteCookieConsentOptions): void;
|
|
18
|
+
declare function isEmbeddedWindow(): boolean;
|
|
19
|
+
|
|
20
|
+
export { COOKIE_CONSENT_MAX_AGE, COOKIE_CONSENT_NAME, COOKIE_CONSENT_VALUES, type CookieConsentValue, type WriteCookieConsentOptions, cookieConsentAllowsReplay, cookieDomainFromHostname, isCookieConsentValue, isEmbeddedWindow, parseCookieConsent, readCookieConsent, serializeCookieConsent, writeCookieConsent };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
declare const COOKIE_CONSENT_NAME = "livo-cookie-consent";
|
|
2
|
+
declare const COOKIE_CONSENT_VALUES: readonly ["necessary", "all"];
|
|
3
|
+
type CookieConsentValue = (typeof COOKIE_CONSENT_VALUES)[number];
|
|
4
|
+
/** ~180 days, matching contracts §1.2. */
|
|
5
|
+
declare const COOKIE_CONSENT_MAX_AGE: number;
|
|
6
|
+
type WriteCookieConsentOptions = {
|
|
7
|
+
domain?: string;
|
|
8
|
+
secure?: boolean;
|
|
9
|
+
maxAge?: number;
|
|
10
|
+
};
|
|
11
|
+
declare function isCookieConsentValue(value: unknown): value is CookieConsentValue;
|
|
12
|
+
declare function cookieConsentAllowsReplay(value: CookieConsentValue | null | undefined): boolean;
|
|
13
|
+
declare function cookieDomainFromHostname(hostname: string): string | undefined;
|
|
14
|
+
declare function parseCookieConsent(cookieSource: string): CookieConsentValue | null;
|
|
15
|
+
declare function readCookieConsent(): CookieConsentValue | null;
|
|
16
|
+
declare function serializeCookieConsent(value: CookieConsentValue, options?: WriteCookieConsentOptions): string;
|
|
17
|
+
declare function writeCookieConsent(value: CookieConsentValue, options?: WriteCookieConsentOptions): void;
|
|
18
|
+
declare function isEmbeddedWindow(): boolean;
|
|
19
|
+
|
|
20
|
+
export { COOKIE_CONSENT_MAX_AGE, COOKIE_CONSENT_NAME, COOKIE_CONSENT_VALUES, type CookieConsentValue, type WriteCookieConsentOptions, cookieConsentAllowsReplay, cookieDomainFromHostname, isCookieConsentValue, isEmbeddedWindow, parseCookieConsent, readCookieConsent, serializeCookieConsent, writeCookieConsent };
|
package/dist/consent.js
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
// src/lib/cookie-consent.ts
|
|
2
|
+
var COOKIE_CONSENT_NAME = "livo-cookie-consent";
|
|
3
|
+
var COOKIE_CONSENT_VALUES = ["necessary", "all"];
|
|
4
|
+
var COOKIE_CONSENT_MAX_AGE = 180 * 24 * 60 * 60;
|
|
5
|
+
function isCookieConsentValue(value) {
|
|
6
|
+
return typeof value === "string" && COOKIE_CONSENT_VALUES.includes(value);
|
|
7
|
+
}
|
|
8
|
+
function cookieConsentAllowsReplay(value) {
|
|
9
|
+
return value === "all";
|
|
10
|
+
}
|
|
11
|
+
function cookieDomainFromHostname(hostname) {
|
|
12
|
+
const host = hostname.toLowerCase();
|
|
13
|
+
if (host === "localhost" || host === "127.0.0.1") return void 0;
|
|
14
|
+
if (host.endsWith(".livo.tv") || host === "livo.tv") return ".livo.tv";
|
|
15
|
+
if (host.endsWith(".livo-tv.workers.dev") || host === "livo-tv.workers.dev") {
|
|
16
|
+
return ".livo-tv.workers.dev";
|
|
17
|
+
}
|
|
18
|
+
return void 0;
|
|
19
|
+
}
|
|
20
|
+
function readCookieMap(cookieSource) {
|
|
21
|
+
const map = /* @__PURE__ */ new Map();
|
|
22
|
+
for (const part of cookieSource.split(";")) {
|
|
23
|
+
const trimmed = part.trim();
|
|
24
|
+
if (!trimmed) continue;
|
|
25
|
+
const eq = trimmed.indexOf("=");
|
|
26
|
+
if (eq < 0) continue;
|
|
27
|
+
const name = trimmed.slice(0, eq).trim();
|
|
28
|
+
const raw = trimmed.slice(eq + 1).trim();
|
|
29
|
+
map.set(name, decodeURIComponent(raw));
|
|
30
|
+
}
|
|
31
|
+
return map;
|
|
32
|
+
}
|
|
33
|
+
function parseCookieConsent(cookieSource) {
|
|
34
|
+
const raw = readCookieMap(cookieSource).get(COOKIE_CONSENT_NAME);
|
|
35
|
+
return isCookieConsentValue(raw) ? raw : null;
|
|
36
|
+
}
|
|
37
|
+
function readCookieConsent() {
|
|
38
|
+
if (typeof document === "undefined") return null;
|
|
39
|
+
return parseCookieConsent(document.cookie);
|
|
40
|
+
}
|
|
41
|
+
function serializeCookieConsent(value, options = {}) {
|
|
42
|
+
const maxAge = options.maxAge ?? COOKIE_CONSENT_MAX_AGE;
|
|
43
|
+
const secure = options.secure ?? (typeof window !== "undefined" && window.location.protocol === "https:");
|
|
44
|
+
const parts = [
|
|
45
|
+
`${COOKIE_CONSENT_NAME}=${encodeURIComponent(value)}`,
|
|
46
|
+
"Path=/",
|
|
47
|
+
`Max-Age=${maxAge}`,
|
|
48
|
+
"SameSite=Lax"
|
|
49
|
+
];
|
|
50
|
+
if (options.domain) {
|
|
51
|
+
parts.push(`Domain=${options.domain}`);
|
|
52
|
+
}
|
|
53
|
+
if (secure) {
|
|
54
|
+
parts.push("Secure");
|
|
55
|
+
}
|
|
56
|
+
return parts.join("; ");
|
|
57
|
+
}
|
|
58
|
+
function writeCookieConsent(value, options = {}) {
|
|
59
|
+
if (typeof document === "undefined") return;
|
|
60
|
+
document.cookie = serializeCookieConsent(value, options);
|
|
61
|
+
}
|
|
62
|
+
function isEmbeddedWindow() {
|
|
63
|
+
if (typeof window === "undefined") return false;
|
|
64
|
+
try {
|
|
65
|
+
return window.self !== window.top;
|
|
66
|
+
} catch {
|
|
67
|
+
return true;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export { COOKIE_CONSENT_MAX_AGE, COOKIE_CONSENT_NAME, COOKIE_CONSENT_VALUES, cookieConsentAllowsReplay, cookieDomainFromHostname, isCookieConsentValue, isEmbeddedWindow, parseCookieConsent, readCookieConsent, serializeCookieConsent, writeCookieConsent };
|
|
72
|
+
//# sourceMappingURL=consent.js.map
|
|
73
|
+
//# sourceMappingURL=consent.js.map
|
|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K,IAAI,CAAA;AACvB;AAEO,SAAS,kBAAA,CACf,KAAA,EACA,OAAA,GAAqC,EAAC,EAC/B;AACP,EAAA,IAAI,OAAO,aAAa,WAAA,EAAa;AACrC,EAAA,QAAA,CAAS,MAAA,GAAS,sBAAA,CAAuB,KAAA,EAAO,OAAO,CAAA;AACxD;AAEO,SAAS,gBAAA,GAA4B;AAC3C,EAAA,IAAI,OAAO,MAAA,KAAW,WAAA,EAAa,OAAO,KAAA;AAC1C,EAAA,IAAI;AACH,IAAA,OAAO,MAAA,CAAO,SAAS,MAAA,CAAO,GAAA;AAAA,EAC/B,CAAA,CAAA,MAAQ;AACP,IAAA,OAAO,IAAA;AAAA,EACR;AACD","file":"consent.js","sourcesContent":["export const COOKIE_CONSENT_NAME = \"livo-cookie-consent\";\n\nexport const COOKIE_CONSENT_VALUES = [\"necessary\", \"all\"] as const;\n\nexport type CookieConsentValue = (typeof COOKIE_CONSENT_VALUES)[number];\n\n/** ~180 days, matching contracts §1.2. */\nexport const COOKIE_CONSENT_MAX_AGE = 180 * 24 * 60 * 60;\n\nexport type WriteCookieConsentOptions = {\n\tdomain?: string;\n\tsecure?: boolean;\n\tmaxAge?: number;\n};\n\nexport function isCookieConsentValue(\n\tvalue: unknown,\n): value is CookieConsentValue {\n\treturn (\n\t\ttypeof value === \"string\" &&\n\t\t(COOKIE_CONSENT_VALUES as readonly string[]).includes(value)\n\t);\n}\n\nexport function cookieConsentAllowsReplay(\n\tvalue: CookieConsentValue | null | undefined,\n): boolean {\n\treturn value === \"all\";\n}\n\nexport function cookieDomainFromHostname(hostname: string): string | undefined {\n\tconst host = hostname.toLowerCase();\n\tif (host === \"localhost\" || host === \"127.0.0.1\") return undefined;\n\tif (host.endsWith(\".livo.tv\") || host === \"livo.tv\") return \".livo.tv\";\n\tif (host.endsWith(\".livo-tv.workers.dev\") || host === \"livo-tv.workers.dev\") {\n\t\treturn \".livo-tv.workers.dev\";\n\t}\n\treturn undefined;\n}\n\nfunction readCookieMap(cookieSource: string): Map<string, string> {\n\tconst map = new Map<string, string>();\n\tfor (const part of cookieSource.split(\";\")) {\n\t\tconst trimmed = part.trim();\n\t\tif (!trimmed) continue;\n\t\tconst eq = trimmed.indexOf(\"=\");\n\t\tif (eq < 0) continue;\n\t\tconst name = trimmed.slice(0, eq).trim();\n\t\tconst raw = trimmed.slice(eq + 1).trim();\n\t\tmap.set(name, decodeURIComponent(raw));\n\t}\n\treturn map;\n}\n\nexport function parseCookieConsent(\n\tcookieSource: string,\n): CookieConsentValue | null {\n\tconst raw = readCookieMap(cookieSource).get(COOKIE_CONSENT_NAME);\n\treturn isCookieConsentValue(raw) ? raw : null;\n}\n\nexport function readCookieConsent(): CookieConsentValue | null {\n\tif (typeof document === \"undefined\") return null;\n\treturn parseCookieConsent(document.cookie);\n}\n\nexport function serializeCookieConsent(\n\tvalue: CookieConsentValue,\n\toptions: WriteCookieConsentOptions = {},\n): string {\n\tconst maxAge = options.maxAge ?? COOKIE_CONSENT_MAX_AGE;\n\tconst secure =\n\t\toptions.secure ??\n\t\t(typeof window !== \"undefined\" && window.location.protocol === \"https:\");\n\tconst parts = [\n\t\t`${COOKIE_CONSENT_NAME}=${encodeURIComponent(value)}`,\n\t\t\"Path=/\",\n\t\t`Max-Age=${maxAge}`,\n\t\t\"SameSite=Lax\",\n\t];\n\tif (options.domain) {\n\t\tparts.push(`Domain=${options.domain}`);\n\t}\n\tif (secure) {\n\t\tparts.push(\"Secure\");\n\t}\n\treturn parts.join(\"; \");\n}\n\nexport function writeCookieConsent(\n\tvalue: CookieConsentValue,\n\toptions: WriteCookieConsentOptions = {},\n): void {\n\tif (typeof document === \"undefined\") return;\n\tdocument.cookie = serializeCookieConsent(value, options);\n}\n\nexport function isEmbeddedWindow(): boolean {\n\tif (typeof window === \"undefined\") return false;\n\ttry {\n\t\treturn window.self !== window.top;\n\t} catch {\n\t\treturn true;\n\t}\n}\n"]}
|