@ecomconsult/consentkit 0.4.0 → 0.5.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.
- package/README.md +117 -19
- package/npm/index.d.ts +160 -2
- package/npm/internal-stub.mjs +6 -1
- package/package.json +1 -1
- package/src/ck-core.js +146 -13
- package/src/ck-debug.js +120 -1
- package/src/ck-ui.js +489 -43
package/src/ck-debug.js
CHANGED
|
@@ -199,6 +199,28 @@
|
|
|
199
199
|
note: NOTE_RU,
|
|
200
200
|
secConsentMode: 'Consent Mode / dataLayer',
|
|
201
201
|
noEvents: 'событий не было',
|
|
202
|
+
secTheme: 'Оформление',
|
|
203
|
+
themeMode: 'тема',
|
|
204
|
+
themeModeLight: 'светлая',
|
|
205
|
+
themeModeDark: 'тёмная',
|
|
206
|
+
themeFont: 'шрифт',
|
|
207
|
+
themeFontInherit: 'как на сайте',
|
|
208
|
+
themeFontSystem: 'системный',
|
|
209
|
+
themeRadius: 'скругления',
|
|
210
|
+
themeCard: 'карточка',
|
|
211
|
+
themeBtn: 'кнопки',
|
|
212
|
+
themeLink: 'Ссылки',
|
|
213
|
+
btnAccept: 'Принять всё',
|
|
214
|
+
btnReject: 'Отклонить всё',
|
|
215
|
+
btnSettings: 'Настроить',
|
|
216
|
+
btnFilled: 'залитая',
|
|
217
|
+
btnOutline: 'обводка',
|
|
218
|
+
btnText: 'текст',
|
|
219
|
+
btnBorder: 'обводка',
|
|
220
|
+
btnOn: 'на',
|
|
221
|
+
btnAdjusted: 'исправлено автоматически',
|
|
222
|
+
btnOk: 'AA',
|
|
223
|
+
btnFail: 'ниже AA',
|
|
202
224
|
secActions: 'Действия',
|
|
203
225
|
reset: 'Сбросить согласие',
|
|
204
226
|
showPrefs: 'Показать настройки',
|
|
@@ -236,6 +258,28 @@
|
|
|
236
258
|
note: NOTE_EN,
|
|
237
259
|
secConsentMode: 'Consent Mode / dataLayer',
|
|
238
260
|
noEvents: 'no events',
|
|
261
|
+
secTheme: 'Appearance',
|
|
262
|
+
themeMode: 'theme',
|
|
263
|
+
themeModeLight: 'light',
|
|
264
|
+
themeModeDark: 'dark',
|
|
265
|
+
themeFont: 'font',
|
|
266
|
+
themeFontInherit: 'site font',
|
|
267
|
+
themeFontSystem: 'system',
|
|
268
|
+
themeRadius: 'radii',
|
|
269
|
+
themeCard: 'card',
|
|
270
|
+
themeBtn: 'buttons',
|
|
271
|
+
themeLink: 'Links',
|
|
272
|
+
btnAccept: 'Accept all',
|
|
273
|
+
btnReject: 'Reject all',
|
|
274
|
+
btnSettings: 'Customize',
|
|
275
|
+
btnFilled: 'filled',
|
|
276
|
+
btnOutline: 'outline',
|
|
277
|
+
btnText: 'text',
|
|
278
|
+
btnBorder: 'border',
|
|
279
|
+
btnOn: 'on',
|
|
280
|
+
btnAdjusted: 'adjusted automatically',
|
|
281
|
+
btnOk: 'AA',
|
|
282
|
+
btnFail: 'below AA',
|
|
239
283
|
secActions: 'Actions',
|
|
240
284
|
reset: 'Reset consent',
|
|
241
285
|
showPrefs: 'Show preferences',
|
|
@@ -547,6 +591,13 @@
|
|
|
547
591
|
|
|
548
592
|
function tag(text, cls) { return el('span', { class: 't' + (cls ? ' ' + cls : '') }, text); }
|
|
549
593
|
|
|
594
|
+
// A contrast ratio the way WCAG tools quote it. null when the colour could
|
|
595
|
+
// not be measured (a colour name, an rgb() string) — shown as "?" rather
|
|
596
|
+
// than a made-up number.
|
|
597
|
+
function fmtRatio(r) {
|
|
598
|
+
return typeof r === 'number' && isFinite(r) ? (Math.round(r * 100) / 100) + ':1' : '?';
|
|
599
|
+
}
|
|
600
|
+
|
|
550
601
|
// Resolved lazily, not at parse time: this file runs before ConsentKit.init()
|
|
551
602
|
// has merged the site's config, so asking for the language now would always
|
|
552
603
|
// read the built-in default. Re-resolved on every render so a page that
|
|
@@ -663,7 +714,75 @@
|
|
|
663
714
|
}
|
|
664
715
|
body.appendChild(s5);
|
|
665
716
|
|
|
666
|
-
// 6.
|
|
717
|
+
// 6. Appearance (SPEC V1.6 §1) — the three buttons' RESOLVED colours and
|
|
718
|
+
// their contrast ratios, read straight off ConsentKit._contrast rather than
|
|
719
|
+
// recomputed here: the banner, this panel and the cabinet's theme editor
|
|
720
|
+
// must all quote the same numbers. The mode is named explicitly because
|
|
721
|
+
// light and dark resolve differently and only one of them is on screen.
|
|
722
|
+
var contrast = CK && CK._contrast;
|
|
723
|
+
if (contrast && typeof contrast.buildThemeCss === 'function') {
|
|
724
|
+
var sT = section(T.secTheme);
|
|
725
|
+
try {
|
|
726
|
+
var built = contrast.buildThemeCss((CK && CK.config) || {});
|
|
727
|
+
// Which palette the visitor is actually looking at right now.
|
|
728
|
+
var dark = built.mode === 'dark';
|
|
729
|
+
if (built.mode === 'auto') {
|
|
730
|
+
try {
|
|
731
|
+
dark = !!(global.matchMedia && global.matchMedia('(prefers-color-scheme: dark)').matches);
|
|
732
|
+
} catch (e) { dark = false; }
|
|
733
|
+
}
|
|
734
|
+
var resolved = dark ? built.dark : built.light;
|
|
735
|
+
|
|
736
|
+
// Fourth row: --ck-link, the accent as TEXT on the card. It is a
|
|
737
|
+
// separate number from every button's, because it is measured against
|
|
738
|
+
// the card rather than against a button fill — a brand accent can pass
|
|
739
|
+
// as a filled button's background and still be unreadable as a link.
|
|
740
|
+
var lk = resolved.link;
|
|
741
|
+
var lkTxt = '—';
|
|
742
|
+
if (lk) {
|
|
743
|
+
lkTxt = lk.color + ' ' + T.btnOn + ' ' + lk.against +
|
|
744
|
+
' · ' + fmtRatio(lk.ratio) +
|
|
745
|
+
' ' + ((typeof lk.ratio === 'number' && lk.ratio >= 4.5) ? T.btnOk : T.btnFail) +
|
|
746
|
+
(lk.adjusted ? ' · ' + T.btnAdjusted : '');
|
|
747
|
+
}
|
|
748
|
+
|
|
749
|
+
sT.appendChild(defs([
|
|
750
|
+
[T.themeMode, (dark ? T.themeModeDark : T.themeModeLight) +
|
|
751
|
+
(built.mode === 'auto' ? ' (auto)' : '')],
|
|
752
|
+
[T.themeFont, built.font === 'inherit' ? T.themeFontInherit : T.themeFontSystem],
|
|
753
|
+
[T.themeRadius, T.themeCard + ' ' + built.radius.card + 'px · ' +
|
|
754
|
+
T.themeBtn + ' ' + built.radius.button + 'px'],
|
|
755
|
+
[T.themeLink, lkTxt]
|
|
756
|
+
]));
|
|
757
|
+
|
|
758
|
+
var labels = { accept: T.btnAccept, reject: T.btnReject, settings: T.btnSettings };
|
|
759
|
+
var uT = doc.createElement('ul');
|
|
760
|
+
['accept', 'reject', 'settings'].forEach(function (role) {
|
|
761
|
+
var b = resolved.buttons[role];
|
|
762
|
+
if (!b) { return; }
|
|
763
|
+
var li = doc.createElement('li');
|
|
764
|
+
li.appendChild(tag(b.variant === 'filled' ? T.btnFilled : T.btnOutline));
|
|
765
|
+
var ok = typeof b.ratio === 'number' && b.ratio >= 4.5;
|
|
766
|
+
li.appendChild(tag(fmtRatio(b.ratio) + ' ' + (ok ? T.btnOk : T.btnFail),
|
|
767
|
+
ok ? 'on' : 'off'));
|
|
768
|
+
li.appendChild(doc.createTextNode(labels[role] + ' — ' +
|
|
769
|
+
T.btnText + ' ' + b.fg + ' ' + T.btnOn + ' ' + b.against +
|
|
770
|
+
(b.variant === 'outline'
|
|
771
|
+
? ' · ' + T.btnBorder + ' ' + b.border + ' (' + fmtRatio(b.borderRatio) + ')'
|
|
772
|
+
: '')));
|
|
773
|
+
if (b.adjusted) {
|
|
774
|
+
li.appendChild(el('span', { class: 'mut' }, ' · ' + T.btnAdjusted));
|
|
775
|
+
}
|
|
776
|
+
uT.appendChild(li);
|
|
777
|
+
});
|
|
778
|
+
sT.appendChild(uT);
|
|
779
|
+
} catch (e) {
|
|
780
|
+
sT.appendChild(el('div', { class: 'mut' }, '—'));
|
|
781
|
+
}
|
|
782
|
+
body.appendChild(sT);
|
|
783
|
+
}
|
|
784
|
+
|
|
785
|
+
// 7. Buttons
|
|
667
786
|
var s6 = section(T.secActions);
|
|
668
787
|
var row = el('div', { class: 'row' });
|
|
669
788
|
var bReset = el('button', { type: 'button' }, T.reset);
|