hyperbook 0.84.5 → 0.85.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.
@@ -0,0 +1,112 @@
1
+ /// <reference path="../hyperbook.types.js" />
2
+ window.hyperbook = window.hyperbook || {};
3
+
4
+ hyperbook.embed = hyperbook.embed || {};
5
+
6
+ hyperbook.embed.consent = (function () {
7
+ function getDomain(url) {
8
+ try {
9
+ return new URL(url).hostname;
10
+ } catch (e) {
11
+ return url;
12
+ }
13
+ }
14
+
15
+ async function isAllowed(consentId) {
16
+ try {
17
+ var entry = await hyperbook.store.consent.get(consentId);
18
+ return entry?.allowed === true;
19
+ } catch (e) {
20
+ return false;
21
+ }
22
+ }
23
+
24
+ async function allow(consentId) {
25
+ await hyperbook.store.consent.put({ id: consentId, allowed: true });
26
+ }
27
+
28
+ function loadContent(wrapper) {
29
+ var banner = wrapper.querySelector(".directive-embed-consent-banner");
30
+ if (banner) {
31
+ banner.remove();
32
+ }
33
+ var iframe = wrapper.querySelector("iframe");
34
+ if (iframe) {
35
+ var src = iframe.getAttribute("data-consent-src");
36
+ if (src) {
37
+ iframe.setAttribute("src", src);
38
+ iframe.removeAttribute("data-consent-src");
39
+ iframe.style.display = "";
40
+ }
41
+ }
42
+ }
43
+
44
+ async function initWrapper(wrapper) {
45
+ if (wrapper.getAttribute("data-consent-initialized")) return;
46
+ wrapper.setAttribute("data-consent-initialized", "true");
47
+
48
+ var consentSrc = wrapper.getAttribute("data-consent-src");
49
+ var domain = getDomain(consentSrc);
50
+ var consentId = "domain:" + domain;
51
+
52
+ var allowed = await isAllowed(consentId);
53
+ if (allowed) {
54
+ loadContent(wrapper);
55
+ return;
56
+ }
57
+
58
+ var btn = wrapper.querySelector(".directive-embed-consent-accept-btn");
59
+ var checkbox = wrapper.querySelector(
60
+ ".directive-embed-consent-always-checkbox"
61
+ );
62
+ if (btn) {
63
+ btn.addEventListener("click", async function () {
64
+ if (checkbox && checkbox.checked) {
65
+ await allow(consentId);
66
+ }
67
+ loadContent(wrapper);
68
+ if (checkbox && checkbox.checked) {
69
+ document
70
+ .querySelectorAll(".directive-embed-consent")
71
+ .forEach(function (el) {
72
+ var elSrc = el.getAttribute("data-consent-src");
73
+ if (getDomain(elSrc) === domain) {
74
+ loadContent(el);
75
+ }
76
+ });
77
+ }
78
+ });
79
+ }
80
+ }
81
+
82
+ function init(root) {
83
+ var wrappers = root.querySelectorAll
84
+ ? root.querySelectorAll(".directive-embed-consent")
85
+ : [];
86
+ wrappers.forEach(function (w) {
87
+ initWrapper(w);
88
+ });
89
+ }
90
+
91
+ document.addEventListener("DOMContentLoaded", function () {
92
+ init(document);
93
+ });
94
+
95
+ var observer = new MutationObserver(function (mutations) {
96
+ mutations.forEach(function (mutation) {
97
+ mutation.addedNodes.forEach(function (node) {
98
+ if (node.nodeType === 1) {
99
+ init(node);
100
+ }
101
+ });
102
+ });
103
+ });
104
+
105
+ observer.observe(document.body, { childList: true, subtree: true });
106
+
107
+ return {
108
+ isAllowed: isAllowed,
109
+ allow: allow,
110
+ init: init,
111
+ };
112
+ })();
@@ -5,7 +5,7 @@
5
5
  background-color: white;
6
6
  border-radius: 8px;
7
7
  border-style: solid;
8
- border-width: 4px;
8
+ border-width: 2px;
9
9
  border-color: var(--color-brand);
10
10
  }
11
11
 
@@ -21,3 +21,72 @@
21
21
  right: 0;
22
22
  position: absolute;
23
23
  }
24
+
25
+ .directive-embed-consent {
26
+ position: absolute;
27
+ top: 0;
28
+ left: 0;
29
+ width: 100%;
30
+ height: 100%;
31
+ }
32
+
33
+ .directive-embed-consent iframe[data-consent-src] {
34
+ display: none;
35
+ }
36
+
37
+ .directive-embed-consent-banner {
38
+ display: flex;
39
+ flex-direction: column;
40
+ align-items: center;
41
+ justify-content: center;
42
+ gap: 12px;
43
+ padding: 24px;
44
+ background-color: var(--color-background-tinted, #f5f5f5);
45
+ border-radius: 8px;
46
+ text-align: center;
47
+ height: 100%;
48
+ box-sizing: border-box;
49
+ }
50
+
51
+ .directive-embed-consent-banner-text {
52
+ font-size: 0.95em;
53
+ line-height: 1.5;
54
+ color: var(--color-text, #333);
55
+ max-width: 600px;
56
+ }
57
+
58
+ .directive-embed-consent-banner-url {
59
+ font-size: 0.85em;
60
+ color: var(--color-text-muted, #666);
61
+ word-break: break-all;
62
+ }
63
+
64
+ .directive-embed-consent-always-label {
65
+ display: flex;
66
+ align-items: center;
67
+ gap: 6px;
68
+ font-size: 0.85em;
69
+ color: var(--color-text, #333);
70
+ cursor: pointer;
71
+ }
72
+
73
+ .directive-embed-consent-always-checkbox {
74
+ cursor: pointer;
75
+ margin: 0!important;
76
+ vertical-align: middle;
77
+ }
78
+
79
+ .directive-embed-consent-accept-btn {
80
+ padding: 8px 24px;
81
+ background-color: var(--color-brand, #333);
82
+ color: var(--color-brand-text, #fff);
83
+ border: none;
84
+ border-radius: 4px;
85
+ cursor: pointer;
86
+ font-size: 0.95em;
87
+ }
88
+
89
+ .directive-embed-consent-accept-btn:hover {
90
+ opacity: 0.9;
91
+ }
92
+
@@ -0,0 +1,99 @@
1
+ /// <reference path="../hyperbook.types.js" />
2
+ window.hyperbook = window.hyperbook || {};
3
+
4
+ hyperbook.youtube = hyperbook.youtube || {};
5
+
6
+ hyperbook.youtube.consent = (function () {
7
+ var CONSENT_ID = "youtube";
8
+
9
+ async function isAllowed() {
10
+ try {
11
+ var entry = await hyperbook.store.consent.get(CONSENT_ID);
12
+ return entry?.allowed === true;
13
+ } catch (e) {
14
+ return false;
15
+ }
16
+ }
17
+
18
+ async function allow() {
19
+ await hyperbook.store.consent.put({ id: CONSENT_ID, allowed: true });
20
+ }
21
+
22
+ function loadContent(wrapper) {
23
+ var banner = wrapper.querySelector(".directive-youtube-consent-banner");
24
+ if (banner) {
25
+ banner.remove();
26
+ }
27
+ var iframe = wrapper.querySelector("iframe");
28
+ if (iframe) {
29
+ var src = iframe.getAttribute("data-consent-src");
30
+ if (src) {
31
+ iframe.setAttribute("src", src);
32
+ iframe.removeAttribute("data-consent-src");
33
+ iframe.style.display = "";
34
+ }
35
+ }
36
+ }
37
+
38
+ async function initWrapper(wrapper) {
39
+ if (wrapper.getAttribute("data-consent-initialized")) return;
40
+ wrapper.setAttribute("data-consent-initialized", "true");
41
+
42
+ var allowed = await isAllowed();
43
+ if (allowed) {
44
+ loadContent(wrapper);
45
+ return;
46
+ }
47
+
48
+ var btn = wrapper.querySelector(".directive-youtube-consent-accept-btn");
49
+ var checkbox = wrapper.querySelector(
50
+ ".directive-youtube-consent-always-checkbox"
51
+ );
52
+ if (btn) {
53
+ btn.addEventListener("click", async function () {
54
+ if (checkbox && checkbox.checked) {
55
+ await allow();
56
+ }
57
+ loadContent(wrapper);
58
+ if (checkbox && checkbox.checked) {
59
+ document
60
+ .querySelectorAll(".directive-youtube-consent")
61
+ .forEach(function (el) {
62
+ loadContent(el);
63
+ });
64
+ }
65
+ });
66
+ }
67
+ }
68
+
69
+ function init(root) {
70
+ var wrappers = root.querySelectorAll
71
+ ? root.querySelectorAll(".directive-youtube-consent")
72
+ : [];
73
+ wrappers.forEach(function (w) {
74
+ initWrapper(w);
75
+ });
76
+ }
77
+
78
+ document.addEventListener("DOMContentLoaded", function () {
79
+ init(document);
80
+ });
81
+
82
+ var observer = new MutationObserver(function (mutations) {
83
+ mutations.forEach(function (mutation) {
84
+ mutation.addedNodes.forEach(function (node) {
85
+ if (node.nodeType === 1) {
86
+ init(node);
87
+ }
88
+ });
89
+ });
90
+ });
91
+
92
+ observer.observe(document.body, { childList: true, subtree: true });
93
+
94
+ return {
95
+ isAllowed: isAllowed,
96
+ allow: allow,
97
+ init: init,
98
+ };
99
+ })();
@@ -14,3 +14,66 @@
14
14
  height: 100%;
15
15
  }
16
16
 
17
+ .directive-youtube-consent {
18
+ position: absolute;
19
+ top: 0;
20
+ left: 0;
21
+ width: 100%;
22
+ height: 100%;
23
+ }
24
+
25
+ .directive-youtube-consent iframe[data-consent-src] {
26
+ display: none;
27
+ }
28
+
29
+ .directive-youtube-consent-banner {
30
+ display: flex;
31
+ flex-direction: column;
32
+ align-items: center;
33
+ justify-content: center;
34
+ gap: 12px;
35
+ padding: 24px;
36
+ background-color: var(--color-background-tinted, #f5f5f5);
37
+ border: 2px solid var(--color-brand, #333);
38
+ border-radius: 8px;
39
+ text-align: center;
40
+ height: 100%;
41
+ box-sizing: border-box;
42
+ }
43
+
44
+ .directive-youtube-consent-banner-text {
45
+ font-size: 0.95em;
46
+ line-height: 1.5;
47
+ color: var(--color-text, #333);
48
+ max-width: 600px;
49
+ }
50
+
51
+ .directive-youtube-consent-always-label {
52
+ display: flex;
53
+ align-items: center;
54
+ gap: 6px;
55
+ font-size: 0.85em;
56
+ color: var(--color-text, #333);
57
+ cursor: pointer;
58
+ }
59
+
60
+ .directive-youtube-consent-always-checkbox {
61
+ cursor: pointer;
62
+ margin: 0!important;
63
+ vertical-align: middle;
64
+ }
65
+
66
+ .directive-youtube-consent-accept-btn {
67
+ padding: 8px 24px;
68
+ background-color: var(--color-brand, #333);
69
+ color: var(--color-brand-text, #fff);
70
+ border: none;
71
+ border-radius: 4px;
72
+ cursor: pointer;
73
+ font-size: 0.95em;
74
+ }
75
+
76
+ .directive-youtube-consent-accept-btn:hover {
77
+ opacity: 0.9;
78
+ }
79
+
@@ -12,7 +12,8 @@ window.hyperbook = window.hyperbook || {};
12
12
  hyperbook.store = (function () {
13
13
  /** @type {import("dexie").Dexie} */
14
14
  var db = new Dexie("Hyperbook");
15
- db.version(2).stores({
15
+ db.version(3).stores({
16
+ consent: `id`,
16
17
  currentState: `
17
18
  id,
18
19
  path,