@damian-buho/support-ukraine 1.0.0 β 1.0.1
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 +1 -1
- package/dist/i18n.d.ts +38 -0
- package/dist/index.d.ts +33 -0
- package/dist/locales/index.d.ts +11 -0
- package/dist/types.d.ts +64 -0
- package/package.json +7 -5
package/README.md
CHANGED
|
@@ -35,7 +35,7 @@ npm install @damian-buho/support-ukraine
|
|
|
35
35
|
```html
|
|
36
36
|
|
|
37
37
|
<script type="module">
|
|
38
|
-
import {supportUkraineBlock} from 'https://cdn.jsdelivr.net/npm/@damian-buho/support-ukraine'
|
|
38
|
+
import {supportUkraineBlock} from 'https://cdn.jsdelivr.net/npm/@damian-buho/support-ukraine@1/+esm'
|
|
39
39
|
|
|
40
40
|
await supportUkraineBlock()
|
|
41
41
|
</script>
|
package/dist/i18n.d.ts
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { Charity, LocaleMessages } from './types.js';
|
|
2
|
+
import { type SupportedLocale } from './locales/index.js';
|
|
3
|
+
export type { SupportedLocale } from './locales/index.js';
|
|
4
|
+
/**
|
|
5
|
+
* Detect the user's preferred locale from browser APIs.
|
|
6
|
+
*
|
|
7
|
+
* Resolution order:
|
|
8
|
+
* 1. Explicit `locale` option
|
|
9
|
+
* 2. First match from `navigator.languages[]` (user-ordered preference list)
|
|
10
|
+
* 3. `navigator.language` base tag (e.g. "es" from "es-MX")
|
|
11
|
+
* 4. Fallback: "en"
|
|
12
|
+
*/
|
|
13
|
+
export declare function detectLocale(preferred?: string): SupportedLocale;
|
|
14
|
+
/**
|
|
15
|
+
* Load locale messages for the given language code.
|
|
16
|
+
* Returns cached result on repeat calls. Falls back to 'en' on error.
|
|
17
|
+
*/
|
|
18
|
+
export declare function loadLocale(lang: string): Promise<LocaleMessages>;
|
|
19
|
+
/**
|
|
20
|
+
* Merge base charities with locale-specific translations.
|
|
21
|
+
*
|
|
22
|
+
* For each charity: use the locale tagline if available, otherwise keep
|
|
23
|
+
* the English default from the base data.
|
|
24
|
+
*/
|
|
25
|
+
export declare function mergeCharities(base: readonly Charity[], locale: LocaleMessages): Charity[];
|
|
26
|
+
/** Returns true if the locale uses right-to-left script. */
|
|
27
|
+
export declare function isRTL(lang: string): boolean;
|
|
28
|
+
/**
|
|
29
|
+
* Build a translated banner text line for a charity.
|
|
30
|
+
*
|
|
31
|
+
* @returns The formatted string "UA_FLAG supportUkraine: name: tagline"
|
|
32
|
+
*/
|
|
33
|
+
export declare function formatBannerText(charity: Charity, messages: LocaleMessages): string;
|
|
34
|
+
/**
|
|
35
|
+
* Eagerly pre-load the English locale so it is always available synchronously.
|
|
36
|
+
* Other locales are loaded on demand via `loadLocale()`.
|
|
37
|
+
*/
|
|
38
|
+
export declare function preloadDefault(): Promise<LocaleMessages>;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { type Charity, type SupportUkraineBlockOptions } from './types.js';
|
|
2
|
+
export type { Charity, CharityTag, SupportUkraineBlockOptions } from './types.js';
|
|
3
|
+
export { charitySchema, charitiesSchema } from './types.js';
|
|
4
|
+
export { detectLocale, loadLocale, mergeCharities, isRTL, formatBannerText } from './i18n.js';
|
|
5
|
+
export { resolveLocale, RTL_LOCALES } from './locales/index.js';
|
|
6
|
+
export type { SupportedLocale } from './locales/index.js';
|
|
7
|
+
export declare const DEFAULT_CHARITIES: Charity[];
|
|
8
|
+
/**
|
|
9
|
+
* Pick a random item from an array.
|
|
10
|
+
*
|
|
11
|
+
* @internal
|
|
12
|
+
*/
|
|
13
|
+
export declare function randomItem<T>(items: T[]): T;
|
|
14
|
+
/**
|
|
15
|
+
* Create and mount the Ukraine-support charity banner.
|
|
16
|
+
*
|
|
17
|
+
* The banner is placed at the top of the page. It displays a randomly
|
|
18
|
+
* selected charity with the format "πΊπ¦ Support Ukraine: Name: tagline" β
|
|
19
|
+
* the entire block is a clickable link. Text is translated to the user's
|
|
20
|
+
* detected locale (or the explicit `locale` option).
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```ts
|
|
24
|
+
* import { supportUkraineBlock } from '@damian-buho/support-ukraine'
|
|
25
|
+
*
|
|
26
|
+
* // Auto-detect locale from navigator.language
|
|
27
|
+
* await supportUkraineBlock()
|
|
28
|
+
*
|
|
29
|
+
* // Force a specific locale
|
|
30
|
+
* await supportUkraineBlock({ locale: 'es' })
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
export declare function supportUkraineBlock(options?: SupportUkraineBlockOptions): Promise<HTMLElement>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { LocaleMessages } from '../types.js';
|
|
2
|
+
/** Map of BCP 47 base language β dynamic import loader. */
|
|
3
|
+
export declare const localeLoaders: Record<string, () => Promise<{
|
|
4
|
+
default: LocaleMessages;
|
|
5
|
+
}>>;
|
|
6
|
+
/** All supported locale codes. */
|
|
7
|
+
export type SupportedLocale = keyof typeof localeLoaders;
|
|
8
|
+
/** List of RTL locale codes. */
|
|
9
|
+
export declare const RTL_LOCALES: readonly ["ar"];
|
|
10
|
+
/** Resolve a raw BCP 47 tag to a supported locale code, or 'en'. */
|
|
11
|
+
export declare function resolveLocale(tag: string): SupportedLocale;
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
/** Category tag for a charity. */
|
|
3
|
+
export declare const charityTagSchema: z.ZodEnum<{
|
|
4
|
+
military: "military";
|
|
5
|
+
humanitarian: "humanitarian";
|
|
6
|
+
animals: "animals";
|
|
7
|
+
}>;
|
|
8
|
+
export type CharityTag = z.infer<typeof charityTagSchema>;
|
|
9
|
+
/** A charity foundation that can appear in the banner. */
|
|
10
|
+
export declare const charitySchema: z.ZodObject<{
|
|
11
|
+
id: z.ZodString;
|
|
12
|
+
name: z.ZodString;
|
|
13
|
+
tagline: z.ZodString;
|
|
14
|
+
url: z.ZodString;
|
|
15
|
+
tags: z.ZodArray<z.ZodEnum<{
|
|
16
|
+
military: "military";
|
|
17
|
+
humanitarian: "humanitarian";
|
|
18
|
+
animals: "animals";
|
|
19
|
+
}>>;
|
|
20
|
+
}, z.core.$strip>;
|
|
21
|
+
export type Charity = z.infer<typeof charitySchema>;
|
|
22
|
+
export declare const charitiesSchema: z.ZodArray<z.ZodObject<{
|
|
23
|
+
id: z.ZodString;
|
|
24
|
+
name: z.ZodString;
|
|
25
|
+
tagline: z.ZodString;
|
|
26
|
+
url: z.ZodString;
|
|
27
|
+
tags: z.ZodArray<z.ZodEnum<{
|
|
28
|
+
military: "military";
|
|
29
|
+
humanitarian: "humanitarian";
|
|
30
|
+
animals: "animals";
|
|
31
|
+
}>>;
|
|
32
|
+
}, z.core.$strip>>;
|
|
33
|
+
/** Translated UI strings and charity taglines for a single locale. */
|
|
34
|
+
export interface LocaleMessages {
|
|
35
|
+
/** Banner prefix, e.g. "Support Ukraine". */
|
|
36
|
+
supportUkraine: string;
|
|
37
|
+
/** "All charities" link text. */
|
|
38
|
+
allCharities: string;
|
|
39
|
+
/** Card donate button text, e.g. "Donate". */
|
|
40
|
+
donate: string;
|
|
41
|
+
/** Translated taglines keyed by charity id. Missing keys fall back to EN. */
|
|
42
|
+
charities: Record<string, {
|
|
43
|
+
tagline: string;
|
|
44
|
+
}>;
|
|
45
|
+
}
|
|
46
|
+
export interface SupportUkraineBlockOptions {
|
|
47
|
+
/** Target mount element. If omitted the banner is prepended to document.body. */
|
|
48
|
+
element?: HTMLElement;
|
|
49
|
+
/** Positioning mode: 'shift' pushes content down, 'overlap' floats on top. */
|
|
50
|
+
mode?: 'shift' | 'overlap';
|
|
51
|
+
/** Font size (default '0.875rem'). */
|
|
52
|
+
fontSize?: string;
|
|
53
|
+
/** Category tags to filter by. If omitted all charities are shown. */
|
|
54
|
+
tags?: CharityTag[];
|
|
55
|
+
/** Avoid repeating charities across page loads using localStorage. */
|
|
56
|
+
dontRepeat?: boolean;
|
|
57
|
+
/** Log a message to the dev console. */
|
|
58
|
+
isInConsole?: boolean;
|
|
59
|
+
/**
|
|
60
|
+
* Override the auto-detected locale (BCP 47 language tag).
|
|
61
|
+
* If omitted the locale is detected from `navigator.language`.
|
|
62
|
+
*/
|
|
63
|
+
locale?: string;
|
|
64
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@damian-buho/support-ukraine",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Browser library that adds a Ukraine-support charity banner to any website.",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
},
|
|
20
20
|
"scripts": {
|
|
21
21
|
"clean": "rm -rf dist",
|
|
22
|
-
"build": "npm run clean && tsup",
|
|
22
|
+
"build": "npm run clean && tsup && tsc --emitDeclarationOnly --noCheck",
|
|
23
23
|
"prepublishOnly": "npm run build",
|
|
24
24
|
"test": "npm run build && node --test 'dist/test/index.test.js'",
|
|
25
25
|
"test:verbose": "npm run build && node --test --test-reporter spec 'dist/test/index.test.js'",
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
},
|
|
47
47
|
"repository": {
|
|
48
48
|
"type": "git",
|
|
49
|
-
"url": "git@github.com
|
|
49
|
+
"url": "git+ssh://git@github.com/damian-buho/support-ukraine.git"
|
|
50
50
|
},
|
|
51
51
|
"bugs": {
|
|
52
52
|
"url": "https://github.com/damian-buho/support-ukraine/issues"
|
|
@@ -56,7 +56,7 @@
|
|
|
56
56
|
"@eslint/js": "10.0.1",
|
|
57
57
|
"@types/eslint": "9.6.1",
|
|
58
58
|
"@types/js-yaml": "4.0.9",
|
|
59
|
-
"@types/node": "26.1.
|
|
59
|
+
"@types/node": "26.1.1",
|
|
60
60
|
"esbuild": "0.28.1",
|
|
61
61
|
"eslint": "10.6.0",
|
|
62
62
|
"eslint-config-prettier": "10.1.8",
|
|
@@ -88,6 +88,8 @@
|
|
|
88
88
|
"zod": "4.4.3"
|
|
89
89
|
},
|
|
90
90
|
"overrides": {
|
|
91
|
-
"esbuild": "0.28.1"
|
|
91
|
+
"esbuild": "0.28.1",
|
|
92
|
+
"@typescript-eslint/utils": "8.63.0",
|
|
93
|
+
"globals": "$globals"
|
|
92
94
|
}
|
|
93
95
|
}
|