@nohemia/widgets 0.1.1 → 0.1.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/README.de.md +19 -19
- package/README.es.md +19 -19
- package/README.fr.md +19 -19
- package/README.it.md +19 -19
- package/README.ja.md +19 -19
- package/README.ko.md +19 -19
- package/README.md +39 -15
- package/README.pl.md +19 -19
- package/README.pt.md +19 -19
- package/README.tr.md +19 -19
- package/examples/index.html +3 -3
- package/package.json +1 -1
- package/src/nohemia-widget.js +44 -17
package/src/nohemia-widget.js
CHANGED
|
@@ -5,41 +5,68 @@
|
|
|
5
5
|
* styling always stay in sync with the source. No tracking, no cookies, no external runtime.
|
|
6
6
|
*
|
|
7
7
|
* <script type="module">import '@nohemia/widgets'</script>
|
|
8
|
-
* <nohemia-widget type="
|
|
8
|
+
* <nohemia-widget type="moon" locale="en" theme="light" size="m"></nohemia-widget>
|
|
9
9
|
*
|
|
10
10
|
* Attributes:
|
|
11
|
-
* type
|
|
12
|
-
*
|
|
13
|
-
*
|
|
11
|
+
* type "moon" | "sky" (default "moon")
|
|
12
|
+
* locale "en"|"fr"|"pt"|"es"|"it"|"de"|"pl"|"ko"|"ja"|"tr" (default "en")
|
|
13
|
+
* theme "light" | "dark" (default "light")
|
|
14
|
+
* size "s" | "m" (default "m")
|
|
14
15
|
*
|
|
15
|
-
*
|
|
16
|
+
* The slug and theme word in the URL are localized for SEO (e.g. /de/widgets/mond/hell-m/),
|
|
17
|
+
* but you always pass the canonical English keys above - the component maps them per locale.
|
|
18
|
+
*
|
|
19
|
+
* MIT (c) Jade Nohemia / Nohemia - https://nohemia.com/en/widgets/
|
|
16
20
|
*/
|
|
17
21
|
|
|
18
|
-
const BASE = 'https://nohemia.com
|
|
22
|
+
const BASE = 'https://nohemia.com'
|
|
19
23
|
|
|
24
|
+
// Localized URL slug per widget type (the word natives search) - mirrors widget-locales.ts.
|
|
25
|
+
const SLUG = {
|
|
26
|
+
moon: { en: 'moon', fr: 'lune', pt: 'lua', es: 'luna', it: 'luna', de: 'mond', pl: 'ksiezyc', ko: 'dal', ja: 'tsuki', tr: 'ay' },
|
|
27
|
+
sky: { en: 'sky', fr: 'ciel', pt: 'ceu', es: 'cielo', it: 'cielo', de: 'himmel', pl: 'niebo', ko: 'haneul', ja: 'sora', tr: 'gokyuzu' },
|
|
28
|
+
}
|
|
29
|
+
// Localized theme word in the URL.
|
|
30
|
+
const THEME = {
|
|
31
|
+
light: { en: 'light', fr: 'clair', pt: 'claro', es: 'claro', it: 'chiaro', de: 'hell', pl: 'jasny', ko: 'light', ja: 'light', tr: 'acik' },
|
|
32
|
+
dark: { en: 'dark', fr: 'sombre', pt: 'escuro', es: 'oscuro', it: 'scuro', de: 'dunkel', pl: 'ciemny', ko: 'dark', ja: 'dark', tr: 'koyu' },
|
|
33
|
+
}
|
|
20
34
|
// Pixel dimensions per type and size, matching the official widget pages.
|
|
21
35
|
const DIMS = {
|
|
22
|
-
|
|
23
|
-
|
|
36
|
+
moon: { s: [220, 140], m: [300, 210] },
|
|
37
|
+
sky: { s: [230, 150], m: [300, 200] },
|
|
24
38
|
}
|
|
25
39
|
|
|
40
|
+
// Backward-compatible aliases (the first release used the French keys).
|
|
41
|
+
const TYPE_ALIAS = { lune: 'moon', ciel: 'sky' }
|
|
42
|
+
const THEME_ALIAS = { clair: 'light', sombre: 'dark' }
|
|
43
|
+
const LOCALES = ['en', 'fr', 'pt', 'es', 'it', 'de', 'pl', 'ko', 'ja', 'tr']
|
|
44
|
+
|
|
26
45
|
class NohemiaWidget extends HTMLElement {
|
|
27
46
|
connectedCallback() {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
47
|
+
let type = (this.getAttribute('type') || 'moon').toLowerCase()
|
|
48
|
+
type = TYPE_ALIAS[type] || type
|
|
49
|
+
if (!DIMS[type]) type = 'moon'
|
|
50
|
+
|
|
51
|
+
let locale = (this.getAttribute('locale') || 'en').toLowerCase()
|
|
52
|
+
if (LOCALES.indexOf(locale) === -1) locale = 'en'
|
|
53
|
+
|
|
54
|
+
let theme = (this.getAttribute('theme') || 'light').toLowerCase()
|
|
55
|
+
theme = THEME_ALIAS[theme] || theme
|
|
56
|
+
if (theme !== 'dark') theme = 'light'
|
|
57
|
+
|
|
58
|
+
const size = this.getAttribute('size') === 's' ? 's' : 'm'
|
|
59
|
+
const [w, h] = DIMS[type][size]
|
|
31
60
|
|
|
32
|
-
const
|
|
33
|
-
const
|
|
34
|
-
const safeTheme = theme === 'sombre' ? 'sombre' : 'clair'
|
|
35
|
-
const [w, h] = DIMS[safeType][safeSize]
|
|
61
|
+
const slug = SLUG[type][locale]
|
|
62
|
+
const themeWord = THEME[theme][locale]
|
|
36
63
|
|
|
37
64
|
const iframe = document.createElement('iframe')
|
|
38
|
-
iframe.src = `${BASE}/${
|
|
65
|
+
iframe.src = `${BASE}/${locale}/widgets/${slug}/${themeWord}-${size}/`
|
|
39
66
|
iframe.width = String(w)
|
|
40
67
|
iframe.height = String(h)
|
|
41
68
|
iframe.loading = 'lazy'
|
|
42
|
-
iframe.title = '
|
|
69
|
+
iframe.title = 'Nohemia widget'
|
|
43
70
|
iframe.style.cssText = 'border:0;border-radius:12px;max-width:100%'
|
|
44
71
|
iframe.setAttribute('referrerpolicy', 'strict-origin-when-cross-origin')
|
|
45
72
|
|