@gringow/gringow-shadow 0.0.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.md +57 -0
- package/dist/gringow-component.d.mts +20 -0
- package/dist/gringow-component.mjs +81 -0
- package/dist/gringow-default-language.d.mts +3 -0
- package/dist/gringow-default-language.mjs +4 -0
- package/dist/gringow-event.d.mts +11 -0
- package/dist/gringow-event.mjs +19 -0
- package/dist/gringow-store.d.mts +21 -0
- package/dist/gringow-store.mjs +66 -0
- package/dist/index.d.mts +5 -0
- package/dist/index.mjs +149 -0
- package/package.json +71 -0
package/README.md
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
# @gringow/gringow-shadow
|
|
2
|
+
|
|
3
|
+
Lightweight Web Component layer used by the React bindings. It ships the `<g-gringow>` custom element, a minimal
|
|
4
|
+
translation store, and a typed language change event so you can render Gringow translations without React.
|
|
5
|
+
|
|
6
|
+
## What it provides
|
|
7
|
+
- `<g-gringow>` custom element that renders translated text from a Gringow cache file
|
|
8
|
+
- `GringowStore` singleton to fetch and hold the cache (URL + language aware)
|
|
9
|
+
- `LanguageChangeEvent` helper to broadcast language switches
|
|
10
|
+
|
|
11
|
+
## Installation
|
|
12
|
+
```bash
|
|
13
|
+
pnpm add @gringow/gringow-shadow
|
|
14
|
+
# npm install @gringow/gringow-shadow
|
|
15
|
+
# yarn add @gringow/gringow-shadow
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## Quick start (vanilla HTML)
|
|
19
|
+
```html
|
|
20
|
+
<script type="module">
|
|
21
|
+
import { GringowComponent, GringowStore, LanguageChangeEvent } from '@gringow/gringow-shadow'
|
|
22
|
+
|
|
23
|
+
GringowStore.cacheUrl = '/gringow/gringow.json'
|
|
24
|
+
GringowStore.language = 'en-US'
|
|
25
|
+
await GringowStore.fetchCache()
|
|
26
|
+
|
|
27
|
+
// Wire the custom element to the store once
|
|
28
|
+
GringowComponent.defaults = { store: GringowStore }
|
|
29
|
+
customElements.define(GringowComponent.GRINGOW_ELEMENT_NAME, GringowComponent)
|
|
30
|
+
|
|
31
|
+
// Listen to language changes
|
|
32
|
+
addEventListener(LanguageChangeEvent.EVENT_NAME, (event) => console.log(event.detail.lang))
|
|
33
|
+
</script>
|
|
34
|
+
|
|
35
|
+
<g-gringow data-cache-id="grw-abc123" data-flatten="Hello world"></g-gringow>
|
|
36
|
+
<button onclick="dispatchEvent(LanguageChangeEvent.create('pt-BR'))">pt-BR</button>
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
`data-cache-id` must match the cache entry key from `gringow/gringow.json`, and `data-flatten` is the original
|
|
40
|
+
flattened string used as a fallback.
|
|
41
|
+
|
|
42
|
+
## Store & events
|
|
43
|
+
- `GringowStore.cacheUrl` — can also be provided via `<meta name="gringow-cache-url">` or `data-gringow-cache-url` on
|
|
44
|
+
`<html>`.
|
|
45
|
+
- `GringowStore.language` — defaults to `document.documentElement.lang` when not set.
|
|
46
|
+
- `GringowStore.fetchCache()` — fetches and memoizes the cache file (throws if URL or language is missing).
|
|
47
|
+
- `GringowStore.getCacheItem(cacheId)` — returns the translated string for the active language or `null`.
|
|
48
|
+
- `LanguageChangeEvent.EVENT_NAME` and `LanguageChangeEvent.create(lang)` — helper to dispatch language changes.
|
|
49
|
+
|
|
50
|
+
## Development scripts
|
|
51
|
+
```bash
|
|
52
|
+
pnpm run build # Emit dist/ with tsup
|
|
53
|
+
pnpm run watch # Continuous rebuild for local development
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
## License
|
|
57
|
+
MIT © Renato Gaspar
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { GringowStoreType } from './gringow-store.mjs';
|
|
2
|
+
import '@gringow/gringow';
|
|
3
|
+
|
|
4
|
+
type GringowComponentDefaults = {
|
|
5
|
+
store?: GringowStoreType;
|
|
6
|
+
lang?: string;
|
|
7
|
+
};
|
|
8
|
+
declare class GringowComponent extends HTMLElement {
|
|
9
|
+
#private;
|
|
10
|
+
static defaults: GringowComponentDefaults;
|
|
11
|
+
static GRINGOW_ELEMENT_NAME: string;
|
|
12
|
+
constructor();
|
|
13
|
+
connectedCallback(): void;
|
|
14
|
+
disconnectedCallback(): void;
|
|
15
|
+
private buildShadowRoot;
|
|
16
|
+
private updateLanguage;
|
|
17
|
+
private render;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export { GringowComponent };
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { interpolateTemplate } from '@gringow/gringow/browser';
|
|
2
|
+
|
|
3
|
+
// src/gringow-component.ts
|
|
4
|
+
|
|
5
|
+
// src/gringow-event.ts
|
|
6
|
+
var LanguageChangeEvent = class _LanguageChangeEvent extends CustomEvent {
|
|
7
|
+
static EVENT_NAME = "language-change";
|
|
8
|
+
constructor(detail) {
|
|
9
|
+
super(_LanguageChangeEvent.EVENT_NAME, {
|
|
10
|
+
detail: {
|
|
11
|
+
lang: detail.lang ?? "en-US",
|
|
12
|
+
timestamp: detail.timestamp || Date.now()
|
|
13
|
+
},
|
|
14
|
+
bubbles: true,
|
|
15
|
+
cancelable: true
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
static create(lang) {
|
|
19
|
+
return new _LanguageChangeEvent({ lang });
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
// src/gringow-component.ts
|
|
24
|
+
var GringowComponent = class _GringowComponent extends HTMLElement {
|
|
25
|
+
static defaults = {};
|
|
26
|
+
static GRINGOW_ELEMENT_NAME = "g-gringow";
|
|
27
|
+
#flatten = "";
|
|
28
|
+
// data-flatten="..."
|
|
29
|
+
#cacheId = "";
|
|
30
|
+
// data-cache-id="uuid"
|
|
31
|
+
#replacements = [];
|
|
32
|
+
// data-replacements="[...]"
|
|
33
|
+
#shadowRoot;
|
|
34
|
+
#store = null;
|
|
35
|
+
#initialized = false;
|
|
36
|
+
#onLanguageChange = this.updateLanguage.bind(this);
|
|
37
|
+
constructor() {
|
|
38
|
+
super();
|
|
39
|
+
if (!_GringowComponent.defaults.store) {
|
|
40
|
+
throw new Error("GringowComponent requires a GringowStore instance in defaults.store");
|
|
41
|
+
}
|
|
42
|
+
this.#store = _GringowComponent.defaults.store;
|
|
43
|
+
this.#shadowRoot = this.buildShadowRoot();
|
|
44
|
+
this.render();
|
|
45
|
+
}
|
|
46
|
+
connectedCallback() {
|
|
47
|
+
if (this.#initialized) return;
|
|
48
|
+
this.#initialized = true;
|
|
49
|
+
this.#cacheId = this.getAttribute("data-cache-id") ?? "";
|
|
50
|
+
this.#flatten = this.getAttribute("data-flatten") ?? "";
|
|
51
|
+
this.render();
|
|
52
|
+
window.addEventListener(LanguageChangeEvent.EVENT_NAME, this.#onLanguageChange);
|
|
53
|
+
}
|
|
54
|
+
disconnectedCallback() {
|
|
55
|
+
window.removeEventListener(LanguageChangeEvent.EVENT_NAME, this.#onLanguageChange);
|
|
56
|
+
}
|
|
57
|
+
buildShadowRoot() {
|
|
58
|
+
this.#shadowRoot = this.attachShadow({ mode: "open" });
|
|
59
|
+
return this.#shadowRoot;
|
|
60
|
+
}
|
|
61
|
+
updateLanguage(event) {
|
|
62
|
+
const languageChangeEvent = event;
|
|
63
|
+
if (!this.#store) {
|
|
64
|
+
throw new Error("GringowComponent requires a GringowStore");
|
|
65
|
+
}
|
|
66
|
+
if (this.#store.language !== languageChangeEvent.detail.lang) {
|
|
67
|
+
this.#store.language = languageChangeEvent.detail.lang;
|
|
68
|
+
}
|
|
69
|
+
this.render();
|
|
70
|
+
}
|
|
71
|
+
async render() {
|
|
72
|
+
if (!this.#shadowRoot || !this.#store || !this.#cacheId) return;
|
|
73
|
+
const nextContent = await this.#store?.getCacheItem(this.#cacheId) ?? this.#flatten;
|
|
74
|
+
if (!nextContent) {
|
|
75
|
+
throw new Error(`No content found for cache ID "${this.#cacheId}" and language "${this.#store.language}"`);
|
|
76
|
+
}
|
|
77
|
+
this.#shadowRoot.innerHTML = `<g-outlet>${interpolateTemplate(nextContent, this.#replacements)}</g-outlet>`;
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
export { GringowComponent };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
interface LanguageChangeEventDetail {
|
|
2
|
+
lang: string;
|
|
3
|
+
timestamp?: number;
|
|
4
|
+
}
|
|
5
|
+
declare class LanguageChangeEvent extends CustomEvent<LanguageChangeEventDetail> {
|
|
6
|
+
static readonly EVENT_NAME = "language-change";
|
|
7
|
+
constructor(detail: LanguageChangeEventDetail);
|
|
8
|
+
static create(lang: string): LanguageChangeEvent;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export { LanguageChangeEvent, type LanguageChangeEventDetail };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// src/gringow-event.ts
|
|
2
|
+
var LanguageChangeEvent = class _LanguageChangeEvent extends CustomEvent {
|
|
3
|
+
static EVENT_NAME = "language-change";
|
|
4
|
+
constructor(detail) {
|
|
5
|
+
super(_LanguageChangeEvent.EVENT_NAME, {
|
|
6
|
+
detail: {
|
|
7
|
+
lang: detail.lang ?? "en-US",
|
|
8
|
+
timestamp: detail.timestamp || Date.now()
|
|
9
|
+
},
|
|
10
|
+
bubbles: true,
|
|
11
|
+
cancelable: true
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
static create(lang) {
|
|
15
|
+
return new _LanguageChangeEvent({ lang });
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export { LanguageChangeEvent };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { GringowCache } from '@gringow/gringow';
|
|
2
|
+
|
|
3
|
+
declare class GringowStoreSingleton {
|
|
4
|
+
#private;
|
|
5
|
+
private static instance;
|
|
6
|
+
static getInstance(): GringowStoreSingleton;
|
|
7
|
+
get cacheUrl(): string | null;
|
|
8
|
+
set cacheUrl(value: string);
|
|
9
|
+
get cache(): GringowCache | null;
|
|
10
|
+
set cache(value: GringowCache);
|
|
11
|
+
set language(value: string);
|
|
12
|
+
get language(): string | null;
|
|
13
|
+
private constructor();
|
|
14
|
+
fetchCache(): Promise<GringowCache>;
|
|
15
|
+
getCacheItem(item: string): Promise<string | null>;
|
|
16
|
+
}
|
|
17
|
+
declare const GringowStore: GringowStoreSingleton;
|
|
18
|
+
|
|
19
|
+
type GringowStoreType = GringowStoreSingleton;
|
|
20
|
+
|
|
21
|
+
export { GringowStore, type GringowStoreType };
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
// src/gringow-store.ts
|
|
2
|
+
var GringowStoreSingleton = class _GringowStoreSingleton {
|
|
3
|
+
static instance = new _GringowStoreSingleton();
|
|
4
|
+
#language = null;
|
|
5
|
+
#cache = null;
|
|
6
|
+
#cacheUrl = null;
|
|
7
|
+
static getInstance() {
|
|
8
|
+
if (!_GringowStoreSingleton.instance) {
|
|
9
|
+
_GringowStoreSingleton.instance = new _GringowStoreSingleton();
|
|
10
|
+
}
|
|
11
|
+
return _GringowStoreSingleton.instance;
|
|
12
|
+
}
|
|
13
|
+
get cacheUrl() {
|
|
14
|
+
return this.#cacheUrl ?? document.head.querySelector('meta[name="gringow-cache-url"]')?.getAttribute("content") ?? document.documentElement.getAttribute("data-gringow-cache-url");
|
|
15
|
+
}
|
|
16
|
+
set cacheUrl(value) {
|
|
17
|
+
if (typeof value !== "string" || value.trim().length <= 0) return;
|
|
18
|
+
this.#cacheUrl = value;
|
|
19
|
+
}
|
|
20
|
+
get cache() {
|
|
21
|
+
return this.#cache;
|
|
22
|
+
}
|
|
23
|
+
set cache(value) {
|
|
24
|
+
this.#cache = value;
|
|
25
|
+
}
|
|
26
|
+
set language(value) {
|
|
27
|
+
if (typeof value !== "string" || value.trim().length <= 0) return;
|
|
28
|
+
this.#language = value;
|
|
29
|
+
}
|
|
30
|
+
get language() {
|
|
31
|
+
return this.#language ?? document?.documentElement?.getAttribute("lang");
|
|
32
|
+
}
|
|
33
|
+
constructor() {
|
|
34
|
+
}
|
|
35
|
+
async fetchCache() {
|
|
36
|
+
if (!this.cacheUrl) {
|
|
37
|
+
throw new Error("Cache URL is not set");
|
|
38
|
+
}
|
|
39
|
+
if (!this.language) {
|
|
40
|
+
throw new Error("Language is not set");
|
|
41
|
+
}
|
|
42
|
+
if (!this.cache) {
|
|
43
|
+
try {
|
|
44
|
+
const urlString = this.cacheUrl ?? "";
|
|
45
|
+
const url = new URL(urlString);
|
|
46
|
+
const response = await fetch(url.toString());
|
|
47
|
+
this.cache = await response.json();
|
|
48
|
+
if (Object.keys(this.cache || {}).length === 0) {
|
|
49
|
+
throw new Error("Gringow cache is empty");
|
|
50
|
+
}
|
|
51
|
+
} catch (error) {
|
|
52
|
+
throw new Error(`Error fetching gringow cache: ${error?.message ?? String(error)}`);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return this.cache ?? {};
|
|
56
|
+
}
|
|
57
|
+
async getCacheItem(item) {
|
|
58
|
+
await this.fetchCache();
|
|
59
|
+
const cacheItem = this.#cache?.[item];
|
|
60
|
+
if (!cacheItem) return null;
|
|
61
|
+
return cacheItem.translation?.[this.language ?? ""] ?? cacheItem.original ?? null;
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
var GringowStore = GringowStoreSingleton.getInstance();
|
|
65
|
+
|
|
66
|
+
export { GringowStore };
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { GringowComponent } from './gringow-component.mjs';
|
|
2
|
+
export { GringowDefaultLanguage } from './gringow-default-language.mjs';
|
|
3
|
+
export { LanguageChangeEvent } from './gringow-event.mjs';
|
|
4
|
+
export { GringowStore, GringowStoreType } from './gringow-store.mjs';
|
|
5
|
+
import '@gringow/gringow';
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import { interpolateTemplate } from '@gringow/gringow/browser';
|
|
2
|
+
|
|
3
|
+
// src/gringow-component.ts
|
|
4
|
+
|
|
5
|
+
// src/gringow-event.ts
|
|
6
|
+
var LanguageChangeEvent = class _LanguageChangeEvent extends CustomEvent {
|
|
7
|
+
static EVENT_NAME = "language-change";
|
|
8
|
+
constructor(detail) {
|
|
9
|
+
super(_LanguageChangeEvent.EVENT_NAME, {
|
|
10
|
+
detail: {
|
|
11
|
+
lang: detail.lang ?? "en-US",
|
|
12
|
+
timestamp: detail.timestamp || Date.now()
|
|
13
|
+
},
|
|
14
|
+
bubbles: true,
|
|
15
|
+
cancelable: true
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
static create(lang) {
|
|
19
|
+
return new _LanguageChangeEvent({ lang });
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
// src/gringow-component.ts
|
|
24
|
+
var GringowComponent = class _GringowComponent extends HTMLElement {
|
|
25
|
+
static defaults = {};
|
|
26
|
+
static GRINGOW_ELEMENT_NAME = "g-gringow";
|
|
27
|
+
#flatten = "";
|
|
28
|
+
// data-flatten="..."
|
|
29
|
+
#cacheId = "";
|
|
30
|
+
// data-cache-id="uuid"
|
|
31
|
+
#replacements = [];
|
|
32
|
+
// data-replacements="[...]"
|
|
33
|
+
#shadowRoot;
|
|
34
|
+
#store = null;
|
|
35
|
+
#initialized = false;
|
|
36
|
+
#onLanguageChange = this.updateLanguage.bind(this);
|
|
37
|
+
constructor() {
|
|
38
|
+
super();
|
|
39
|
+
if (!_GringowComponent.defaults.store) {
|
|
40
|
+
throw new Error("GringowComponent requires a GringowStore instance in defaults.store");
|
|
41
|
+
}
|
|
42
|
+
this.#store = _GringowComponent.defaults.store;
|
|
43
|
+
this.#shadowRoot = this.buildShadowRoot();
|
|
44
|
+
this.render();
|
|
45
|
+
}
|
|
46
|
+
connectedCallback() {
|
|
47
|
+
if (this.#initialized) return;
|
|
48
|
+
this.#initialized = true;
|
|
49
|
+
this.#cacheId = this.getAttribute("data-cache-id") ?? "";
|
|
50
|
+
this.#flatten = this.getAttribute("data-flatten") ?? "";
|
|
51
|
+
this.render();
|
|
52
|
+
window.addEventListener(LanguageChangeEvent.EVENT_NAME, this.#onLanguageChange);
|
|
53
|
+
}
|
|
54
|
+
disconnectedCallback() {
|
|
55
|
+
window.removeEventListener(LanguageChangeEvent.EVENT_NAME, this.#onLanguageChange);
|
|
56
|
+
}
|
|
57
|
+
buildShadowRoot() {
|
|
58
|
+
this.#shadowRoot = this.attachShadow({ mode: "open" });
|
|
59
|
+
return this.#shadowRoot;
|
|
60
|
+
}
|
|
61
|
+
updateLanguage(event) {
|
|
62
|
+
const languageChangeEvent = event;
|
|
63
|
+
if (!this.#store) {
|
|
64
|
+
throw new Error("GringowComponent requires a GringowStore");
|
|
65
|
+
}
|
|
66
|
+
if (this.#store.language !== languageChangeEvent.detail.lang) {
|
|
67
|
+
this.#store.language = languageChangeEvent.detail.lang;
|
|
68
|
+
}
|
|
69
|
+
this.render();
|
|
70
|
+
}
|
|
71
|
+
async render() {
|
|
72
|
+
if (!this.#shadowRoot || !this.#store || !this.#cacheId) return;
|
|
73
|
+
const nextContent = await this.#store?.getCacheItem(this.#cacheId) ?? this.#flatten;
|
|
74
|
+
if (!nextContent) {
|
|
75
|
+
throw new Error(`No content found for cache ID "${this.#cacheId}" and language "${this.#store.language}"`);
|
|
76
|
+
}
|
|
77
|
+
this.#shadowRoot.innerHTML = `<g-outlet>${interpolateTemplate(nextContent, this.#replacements)}</g-outlet>`;
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
// src/gringow-default-language.ts
|
|
82
|
+
var GringowDefaultLanguage = "es-ES";
|
|
83
|
+
|
|
84
|
+
// src/gringow-store.ts
|
|
85
|
+
var GringowStoreSingleton = class _GringowStoreSingleton {
|
|
86
|
+
static instance = new _GringowStoreSingleton();
|
|
87
|
+
#language = null;
|
|
88
|
+
#cache = null;
|
|
89
|
+
#cacheUrl = null;
|
|
90
|
+
static getInstance() {
|
|
91
|
+
if (!_GringowStoreSingleton.instance) {
|
|
92
|
+
_GringowStoreSingleton.instance = new _GringowStoreSingleton();
|
|
93
|
+
}
|
|
94
|
+
return _GringowStoreSingleton.instance;
|
|
95
|
+
}
|
|
96
|
+
get cacheUrl() {
|
|
97
|
+
return this.#cacheUrl ?? document.head.querySelector('meta[name="gringow-cache-url"]')?.getAttribute("content") ?? document.documentElement.getAttribute("data-gringow-cache-url");
|
|
98
|
+
}
|
|
99
|
+
set cacheUrl(value) {
|
|
100
|
+
if (typeof value !== "string" || value.trim().length <= 0) return;
|
|
101
|
+
this.#cacheUrl = value;
|
|
102
|
+
}
|
|
103
|
+
get cache() {
|
|
104
|
+
return this.#cache;
|
|
105
|
+
}
|
|
106
|
+
set cache(value) {
|
|
107
|
+
this.#cache = value;
|
|
108
|
+
}
|
|
109
|
+
set language(value) {
|
|
110
|
+
if (typeof value !== "string" || value.trim().length <= 0) return;
|
|
111
|
+
this.#language = value;
|
|
112
|
+
}
|
|
113
|
+
get language() {
|
|
114
|
+
return this.#language ?? document?.documentElement?.getAttribute("lang");
|
|
115
|
+
}
|
|
116
|
+
constructor() {
|
|
117
|
+
}
|
|
118
|
+
async fetchCache() {
|
|
119
|
+
if (!this.cacheUrl) {
|
|
120
|
+
throw new Error("Cache URL is not set");
|
|
121
|
+
}
|
|
122
|
+
if (!this.language) {
|
|
123
|
+
throw new Error("Language is not set");
|
|
124
|
+
}
|
|
125
|
+
if (!this.cache) {
|
|
126
|
+
try {
|
|
127
|
+
const urlString = this.cacheUrl ?? "";
|
|
128
|
+
const url = new URL(urlString);
|
|
129
|
+
const response = await fetch(url.toString());
|
|
130
|
+
this.cache = await response.json();
|
|
131
|
+
if (Object.keys(this.cache || {}).length === 0) {
|
|
132
|
+
throw new Error("Gringow cache is empty");
|
|
133
|
+
}
|
|
134
|
+
} catch (error) {
|
|
135
|
+
throw new Error(`Error fetching gringow cache: ${error?.message ?? String(error)}`);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
return this.cache ?? {};
|
|
139
|
+
}
|
|
140
|
+
async getCacheItem(item) {
|
|
141
|
+
await this.fetchCache();
|
|
142
|
+
const cacheItem = this.#cache?.[item];
|
|
143
|
+
if (!cacheItem) return null;
|
|
144
|
+
return cacheItem.translation?.[this.language ?? ""] ?? cacheItem.original ?? null;
|
|
145
|
+
}
|
|
146
|
+
};
|
|
147
|
+
var GringowStore = GringowStoreSingleton.getInstance();
|
|
148
|
+
|
|
149
|
+
export { GringowComponent, GringowDefaultLanguage, GringowStore, LanguageChangeEvent };
|
package/package.json
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@gringow/gringow-shadow",
|
|
3
|
+
"version": "0.0.2",
|
|
4
|
+
"description": "A HTML class for Gringow AI-powered translation tool",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"module": "dist/index.mjs",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"files": [
|
|
9
|
+
"dist",
|
|
10
|
+
"README.md"
|
|
11
|
+
],
|
|
12
|
+
"exports": {
|
|
13
|
+
".": {
|
|
14
|
+
"types": "./dist/index.d.mts",
|
|
15
|
+
"import": "./dist/index.mjs",
|
|
16
|
+
"require": "./dist/index.mjs"
|
|
17
|
+
},
|
|
18
|
+
"./event": {
|
|
19
|
+
"types": "./dist/gringow-event.d.mts",
|
|
20
|
+
"import": "./dist/gringow-event.mjs",
|
|
21
|
+
"require": "./dist/gringow-event.mjs"
|
|
22
|
+
},
|
|
23
|
+
"./store": {
|
|
24
|
+
"types": "./dist/gringow-store.d.mts",
|
|
25
|
+
"import": "./dist/gringow-store.mjs",
|
|
26
|
+
"require": "./dist/gringow-store.mjs"
|
|
27
|
+
},
|
|
28
|
+
"./component": {
|
|
29
|
+
"types": "./dist/gringow-component.d.mts",
|
|
30
|
+
"import": "./dist/gringow-component.mjs",
|
|
31
|
+
"require": "./dist/gringow-component.mjs"
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
"keywords": [
|
|
35
|
+
"gringow",
|
|
36
|
+
"translation",
|
|
37
|
+
"i18n",
|
|
38
|
+
"internationalization",
|
|
39
|
+
"llm",
|
|
40
|
+
"ai",
|
|
41
|
+
"html5"
|
|
42
|
+
],
|
|
43
|
+
"repository": {
|
|
44
|
+
"type": "git",
|
|
45
|
+
"url": "https://github.com/rntgspr/gringow.git",
|
|
46
|
+
"directory": "gringow-shadow"
|
|
47
|
+
},
|
|
48
|
+
"author": "Renato Gaspar <rntgspr@gmail.com>",
|
|
49
|
+
"license": "MIT",
|
|
50
|
+
"publishConfig": {
|
|
51
|
+
"access": "public"
|
|
52
|
+
},
|
|
53
|
+
"dependencies": {
|
|
54
|
+
"globby": "14.1.0",
|
|
55
|
+
"vite": "7.0.0",
|
|
56
|
+
"@gringow/gringow": "0.1.3"
|
|
57
|
+
},
|
|
58
|
+
"devDependencies": {
|
|
59
|
+
"@types/node": "22.15.0",
|
|
60
|
+
"tsc-alias": "1.8.16",
|
|
61
|
+
"tsup": "8.5.0",
|
|
62
|
+
"typescript": "5.8.3"
|
|
63
|
+
},
|
|
64
|
+
"scripts": {
|
|
65
|
+
"build": "rm -rf ./dist/* ./tsconfig.tsbuildinfo && tsup",
|
|
66
|
+
"watch": "pnpm run build && tsup --watch --config ../tsup.config.ts",
|
|
67
|
+
"prepublish": "pnpm install && pnpm build",
|
|
68
|
+
"__postinstall": "pnpm run build",
|
|
69
|
+
"test": "echo \"Warning: no test specified\" && exit 0"
|
|
70
|
+
}
|
|
71
|
+
}
|