@mccustomapps/helaui 0.1.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/dist/assets/rain/builtinImages.ts +7 -0
- package/dist/assets/rain/fritter.png +0 -0
- package/dist/assets/rain/kokis.png +0 -0
- package/dist/assets/rain/leaf.png +0 -0
- package/dist/assets/rain/swirl.png +0 -0
- package/dist/assets/sun-mandala/builtinImage.ts +4 -0
- package/dist/assets/sun-mandala/ira-handa.jpg +0 -0
- package/dist/assets/sun-mandala/ira-handa.png +0 -0
- package/dist/calendar.css +280 -0
- package/dist/fritter-INYFVKEH.png +0 -0
- package/dist/index.cjs +1026 -0
- package/dist/index.d.cts +341 -0
- package/dist/index.d.ts +341 -0
- package/dist/index.js +972 -0
- package/dist/ira-handa-7DIWZWI4.png +0 -0
- package/dist/kokis-R6R5HA62.png +0 -0
- package/dist/leaf-DEJYVWQI.png +0 -0
- package/dist/rain-background.css +40 -0
- package/dist/sinhala.css +10 -0
- package/dist/sun-mandala.css +66 -0
- package/dist/swirl-RVLEF6L5.png +0 -0
- package/dist/textfield.css +99 -0
- package/dist/theme.css +24 -0
- package/package.json +52 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,972 @@
|
|
|
1
|
+
// src/fonts/sinhala.ts
|
|
2
|
+
var SINHALA_FONT_FAMILY = '"Noto Sans Sinhala", "Iskoola Pota", "FM Abhaya", sans-serif';
|
|
3
|
+
var sinhalaFontStyles = {
|
|
4
|
+
fontFamily: SINHALA_FONT_FAMILY
|
|
5
|
+
};
|
|
6
|
+
var SINHALA_FONT_CLASS = "helaui-sinhala";
|
|
7
|
+
function applySinhalaFont(element) {
|
|
8
|
+
element.classList.add(SINHALA_FONT_CLASS);
|
|
9
|
+
element.style.fontFamily = SINHALA_FONT_FAMILY;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
// src/i18n/defaultTranslations.ts
|
|
13
|
+
var defaultTranslations = {
|
|
14
|
+
en: {
|
|
15
|
+
textField: {
|
|
16
|
+
name: { label: "Name", placeholder: "Enter your name" },
|
|
17
|
+
password: { label: "Password", placeholder: "Enter your password" },
|
|
18
|
+
email: { label: "Email", placeholder: "example@email.com" },
|
|
19
|
+
disabled: {
|
|
20
|
+
label: "Disabled",
|
|
21
|
+
placeholder: "Cannot be used",
|
|
22
|
+
value: "Disabled value"
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
calendar: {
|
|
26
|
+
monthNames: [
|
|
27
|
+
"January",
|
|
28
|
+
"February",
|
|
29
|
+
"March",
|
|
30
|
+
"April",
|
|
31
|
+
"May",
|
|
32
|
+
"June",
|
|
33
|
+
"July",
|
|
34
|
+
"August",
|
|
35
|
+
"September",
|
|
36
|
+
"October",
|
|
37
|
+
"November",
|
|
38
|
+
"December"
|
|
39
|
+
],
|
|
40
|
+
sinhalaMonthNames: [
|
|
41
|
+
"Duruthu",
|
|
42
|
+
"Navam",
|
|
43
|
+
"Meddin",
|
|
44
|
+
"Bak",
|
|
45
|
+
"Vesak",
|
|
46
|
+
"Poson",
|
|
47
|
+
"Esala",
|
|
48
|
+
"Nikini",
|
|
49
|
+
"Binara",
|
|
50
|
+
"Vap",
|
|
51
|
+
"Il",
|
|
52
|
+
"Unduvap"
|
|
53
|
+
],
|
|
54
|
+
weekdayNames: [
|
|
55
|
+
"Sunday",
|
|
56
|
+
"Monday",
|
|
57
|
+
"Tuesday",
|
|
58
|
+
"Wednesday",
|
|
59
|
+
"Thursday",
|
|
60
|
+
"Friday",
|
|
61
|
+
"Saturday"
|
|
62
|
+
],
|
|
63
|
+
shortWeekdayNames: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"],
|
|
64
|
+
buddhistEra: "BE",
|
|
65
|
+
today: "Today",
|
|
66
|
+
clear: "Clear",
|
|
67
|
+
selectMonth: "Select Month",
|
|
68
|
+
poyaDay: "Poya Day"
|
|
69
|
+
}
|
|
70
|
+
},
|
|
71
|
+
si: {
|
|
72
|
+
textField: {
|
|
73
|
+
name: { label: "\u0DB1\u0DB8", placeholder: "\u0D94\u0DB6\u0DDA \u0DB1\u0DB8 \u0D87\u0DAD\u0DD4\u0DC5\u0DAD\u0DCA \u0D9A\u0DBB\u0DB1\u0DCA\u0DB1" },
|
|
74
|
+
password: { label: "\u0DB8\u0DD4\u0DBB\u0DB4\u0DAF\u0DBA", placeholder: "\u0DB8\u0DD4\u0DBB\u0DB4\u0DAF\u0DBA \u0D87\u0DAD\u0DD4\u0DC5\u0DAD\u0DCA \u0D9A\u0DBB\u0DB1\u0DCA\u0DB1" },
|
|
75
|
+
email: { label: "\u0DC0\u0DD2\u0DAF\u0DCA\u200D\u0DBA\u0DD4\u0DAD\u0DCA \u0DAD\u0DD0\u0DB4\u0DD1\u0DBD", placeholder: "example@email.com" },
|
|
76
|
+
disabled: {
|
|
77
|
+
label: "\u0D85\u0D9A\u0DCA\u200D\u0DBB\u0DD2\u0DBA \u0D9A\u0DC5",
|
|
78
|
+
placeholder: "\u0DB8\u0DD9\u0DBA \u0DB7\u0DCF\u0DC0\u0DD2\u0DAD\u0DCF \u0D9A\u0DC5 \u0DB1\u0DDC\u0DC4\u0DD0\u0D9A",
|
|
79
|
+
value: "\u0D85\u0D9A\u0DCA\u200D\u0DBB\u0DD2\u0DBA \u0D9A\u0DC5 \u0D85\u0D9C\u0DBA"
|
|
80
|
+
}
|
|
81
|
+
},
|
|
82
|
+
calendar: {
|
|
83
|
+
monthNames: [
|
|
84
|
+
"\u0DA2\u0DB1\u0DC0\u0DCF\u0DBB\u0DD2",
|
|
85
|
+
"\u0DB4\u0DD9\u0DB6\u0DBB\u0DC0\u0DCF\u0DBB\u0DD2",
|
|
86
|
+
"\u0DB8\u0DCF\u0DBB\u0DCA\u0DAD\u0DD4",
|
|
87
|
+
"\u0D85\u0DB4\u0DCA\u200D\u0DBB\u0DDA\u0DBD\u0DCA",
|
|
88
|
+
"\u0DB8\u0DD0\u0DBA\u0DD2",
|
|
89
|
+
"\u0DA2\u0DD6\u0DB1\u0DD2",
|
|
90
|
+
"\u0DA2\u0DD6\u0DBD\u0DD2",
|
|
91
|
+
"\u0D85\u0D9C\u0DDD\u0DC3\u0DCA\u0DAD\u0DD4",
|
|
92
|
+
"\u0DC3\u0DD0\u0DB4\u0DCA\u0DAD\u0DD0\u0DB8\u0DCA\u0DB6\u0DBB\u0DCA",
|
|
93
|
+
"\u0D94\u0D9A\u0DCA\u0DAD\u0DDD\u0DB6\u0DBB\u0DCA",
|
|
94
|
+
"\u0DB1\u0DDC\u0DC0\u0DD0\u0DB8\u0DCA\u0DB6\u0DBB\u0DCA",
|
|
95
|
+
"\u0DAF\u0DD9\u0DC3\u0DD0\u0DB8\u0DCA\u0DB6\u0DBB\u0DCA"
|
|
96
|
+
],
|
|
97
|
+
sinhalaMonthNames: [
|
|
98
|
+
"\u0DAF\u0DD4\u0DBB\u0DD4\u0DAD\u0DD4",
|
|
99
|
+
"\u0DB1\u0DC0\u0DB8\u0DCA",
|
|
100
|
+
"\u0DB8\u0DD0\u0DAF\u0DD2\u0DB1\u0DCA",
|
|
101
|
+
"\u0DB6\u0D9A\u0DCA",
|
|
102
|
+
"\u0DC0\u0DD9\u0DC3\u0D9A\u0DCA",
|
|
103
|
+
"\u0DB4\u0DDC\u0DC3\u0DDC\u0DB1\u0DCA",
|
|
104
|
+
"\u0D87\u0DC3\u0DC5",
|
|
105
|
+
"\u0DB1\u0DD2\u0D9A\u0DD2\u0DAB\u0DD2",
|
|
106
|
+
"\u0DB6\u0DD2\u0DB1\u0DBB",
|
|
107
|
+
"\u0DC0\u0DB4\u0DCA",
|
|
108
|
+
"\u0D89\u0DBD\u0DCA",
|
|
109
|
+
"\u0D8B\u0DB3\u0DD4\u0D85\u0DB4\u0DCA"
|
|
110
|
+
],
|
|
111
|
+
weekdayNames: [
|
|
112
|
+
"\u0D89\u0DBB\u0DD2\u0DAF\u0DCF",
|
|
113
|
+
"\u0DC3\u0DB3\u0DD4\u0DAF\u0DCF",
|
|
114
|
+
"\u0D85\u0D9F\u0DC4\u0DBB\u0DD4\u0DC0\u0DCF\u0DAF\u0DCF",
|
|
115
|
+
"\u0DB6\u0DAF\u0DCF\u0DAF\u0DCF",
|
|
116
|
+
"\u0DB6\u0DCA\u200D\u0DBB\u0DC4\u0DC3\u0DCA\u0DB4\u0DAD\u0DD2\u0DB1\u0DCA\u0DAF\u0DCF",
|
|
117
|
+
"\u0DC3\u0DD2\u0D9A\u0DD4\u0DBB\u0DCF\u0DAF\u0DCF",
|
|
118
|
+
"\u0DC3\u0DD9\u0DB1\u0DC3\u0DD4\u0DBB\u0DCF\u0DAF\u0DCF"
|
|
119
|
+
],
|
|
120
|
+
shortWeekdayNames: ["\u0D89", "\u0DC3", "\u0D85", "\u0DB6", "\u0DB6\u0DCA\u200D\u0DBB", "\u0DC3\u0DD2", "\u0DC3\u0DD9"],
|
|
121
|
+
buddhistEra: "\u0DB6\u0DD4\u0DAF\u0DCA\u0DB0 \u0DC0\u0DBB\u0DCA\u0DC2",
|
|
122
|
+
today: "\u0D85\u0DAF",
|
|
123
|
+
clear: "\u0DB4\u0DD2\u0DBB\u0DD2\u0DC3\u0DD2\u0DAF\u0DD4 \u0D9A\u0DBB\u0DB1\u0DCA\u0DB1",
|
|
124
|
+
selectMonth: "\u0DB8\u0DCF\u0DC3\u0DBA \u0DAD\u0DDD\u0DBB\u0DB1\u0DCA\u0DB1",
|
|
125
|
+
poyaDay: "\u0DB4\u0DDD\u0DBA \u0DAF\u0DD2\u0DB1"
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
// src/i18n/merge.ts
|
|
131
|
+
function deepMerge(base, overrides) {
|
|
132
|
+
const result = { ...base };
|
|
133
|
+
for (const key of Object.keys(overrides)) {
|
|
134
|
+
const overrideValue = overrides[key];
|
|
135
|
+
const baseValue = base[key];
|
|
136
|
+
if (overrideValue !== void 0 && typeof overrideValue === "object" && overrideValue !== null && !Array.isArray(overrideValue) && typeof baseValue === "object" && baseValue !== null && !Array.isArray(baseValue)) {
|
|
137
|
+
result[key] = deepMerge(baseValue, overrideValue);
|
|
138
|
+
} else if (overrideValue !== void 0) {
|
|
139
|
+
result[key] = overrideValue;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
return result;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// src/i18n/resolve.ts
|
|
146
|
+
function resolvePath(source, path) {
|
|
147
|
+
const value = path.split(".").reduce((current, segment) => {
|
|
148
|
+
if (current === null || current === void 0 || typeof current !== "object") {
|
|
149
|
+
return void 0;
|
|
150
|
+
}
|
|
151
|
+
return current[segment];
|
|
152
|
+
}, source);
|
|
153
|
+
return typeof value === "string" ? value : void 0;
|
|
154
|
+
}
|
|
155
|
+
function getTextFieldStrings(translations, variant) {
|
|
156
|
+
return translations.textField[variant];
|
|
157
|
+
}
|
|
158
|
+
function resolveTranslation(translationsByLocale, path, locale) {
|
|
159
|
+
return resolvePath(translationsByLocale[locale], path) ?? resolvePath(translationsByLocale.en, path) ?? path;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
// src/i18n/applyTranslations.ts
|
|
163
|
+
var currentLocale = "en";
|
|
164
|
+
var userOverrides = {};
|
|
165
|
+
var localeListeners = /* @__PURE__ */ new Set();
|
|
166
|
+
function getMergedTranslations(locale) {
|
|
167
|
+
const base = defaultTranslations[locale];
|
|
168
|
+
const overrides = userOverrides[locale];
|
|
169
|
+
return overrides ? deepMerge(base, overrides) : base;
|
|
170
|
+
}
|
|
171
|
+
function notifyLocaleListeners() {
|
|
172
|
+
localeListeners.forEach((listener) => listener());
|
|
173
|
+
}
|
|
174
|
+
function applyDocumentLang(locale) {
|
|
175
|
+
if (typeof document !== "undefined") {
|
|
176
|
+
document.documentElement.lang = locale === "si" ? "si" : "en";
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
function applyTranslations(options = {}) {
|
|
180
|
+
if (options.locale !== void 0) {
|
|
181
|
+
currentLocale = options.locale;
|
|
182
|
+
applyDocumentLang(currentLocale);
|
|
183
|
+
notifyLocaleListeners();
|
|
184
|
+
}
|
|
185
|
+
if (options.overrides !== void 0) {
|
|
186
|
+
userOverrides = deepMerge(userOverrides, options.overrides);
|
|
187
|
+
notifyLocaleListeners();
|
|
188
|
+
}
|
|
189
|
+
return getMergedTranslations(currentLocale);
|
|
190
|
+
}
|
|
191
|
+
function setLocale(locale) {
|
|
192
|
+
return applyTranslations({ locale });
|
|
193
|
+
}
|
|
194
|
+
function getLocale() {
|
|
195
|
+
return currentLocale;
|
|
196
|
+
}
|
|
197
|
+
function resetTranslations() {
|
|
198
|
+
userOverrides = {};
|
|
199
|
+
notifyLocaleListeners();
|
|
200
|
+
return getMergedTranslations(currentLocale);
|
|
201
|
+
}
|
|
202
|
+
function t(path, locale = currentLocale) {
|
|
203
|
+
const merged = {
|
|
204
|
+
en: getMergedTranslations("en"),
|
|
205
|
+
si: getMergedTranslations("si")
|
|
206
|
+
};
|
|
207
|
+
return resolveTranslation(merged, path, locale);
|
|
208
|
+
}
|
|
209
|
+
function getTextFieldTranslation(variant, locale = currentLocale) {
|
|
210
|
+
return getTextFieldStrings(getMergedTranslations(locale), variant);
|
|
211
|
+
}
|
|
212
|
+
function getCalendarTranslation(locale = currentLocale) {
|
|
213
|
+
return getMergedTranslations(locale).calendar ?? defaultTranslations[locale].calendar;
|
|
214
|
+
}
|
|
215
|
+
function subscribeLocaleChange(listener) {
|
|
216
|
+
localeListeners.add(listener);
|
|
217
|
+
return () => localeListeners.delete(listener);
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
// src/components/TextField.ts
|
|
221
|
+
var TextField = class {
|
|
222
|
+
element;
|
|
223
|
+
input;
|
|
224
|
+
labelEl;
|
|
225
|
+
unsubscribeLocale;
|
|
226
|
+
localeAware;
|
|
227
|
+
fixedLabel;
|
|
228
|
+
fixedPlaceholder;
|
|
229
|
+
fixedValue;
|
|
230
|
+
variant;
|
|
231
|
+
labelKey;
|
|
232
|
+
placeholderKey;
|
|
233
|
+
sinhalaExplicit;
|
|
234
|
+
sinhalaEnabled;
|
|
235
|
+
constructor(options = {}) {
|
|
236
|
+
const {
|
|
237
|
+
variant,
|
|
238
|
+
labelKey,
|
|
239
|
+
placeholderKey,
|
|
240
|
+
label,
|
|
241
|
+
placeholder,
|
|
242
|
+
type = "text",
|
|
243
|
+
value,
|
|
244
|
+
id = `helaui-field-${Math.random().toString(36).slice(2, 9)}`,
|
|
245
|
+
sinhala
|
|
246
|
+
} = options;
|
|
247
|
+
this.localeAware = !!(variant || labelKey || placeholderKey);
|
|
248
|
+
this.variant = variant;
|
|
249
|
+
this.labelKey = labelKey;
|
|
250
|
+
this.placeholderKey = placeholderKey;
|
|
251
|
+
this.fixedLabel = label;
|
|
252
|
+
this.fixedPlaceholder = placeholder;
|
|
253
|
+
this.fixedValue = value;
|
|
254
|
+
this.sinhalaExplicit = sinhala !== void 0;
|
|
255
|
+
this.sinhalaEnabled = sinhala ?? (this.localeAware ? getLocale() === "si" : true);
|
|
256
|
+
const resolved = this.resolveStrings();
|
|
257
|
+
this.element = document.createElement("div");
|
|
258
|
+
this.element.className = "helaui-textfield";
|
|
259
|
+
if (resolved.label) {
|
|
260
|
+
this.labelEl = document.createElement("label");
|
|
261
|
+
this.labelEl.className = "helaui-textfield__label";
|
|
262
|
+
this.labelEl.htmlFor = id;
|
|
263
|
+
this.labelEl.textContent = resolved.label;
|
|
264
|
+
if (this.sinhalaEnabled) this.labelEl.classList.add(SINHALA_FONT_CLASS);
|
|
265
|
+
this.element.appendChild(this.labelEl);
|
|
266
|
+
}
|
|
267
|
+
this.input = document.createElement("input");
|
|
268
|
+
this.input.className = "helaui-textfield__input";
|
|
269
|
+
this.input.id = id;
|
|
270
|
+
this.input.type = type;
|
|
271
|
+
this.input.placeholder = resolved.placeholder;
|
|
272
|
+
this.input.value = resolved.value;
|
|
273
|
+
if (this.sinhalaEnabled) this.input.classList.add(SINHALA_FONT_CLASS);
|
|
274
|
+
this.element.appendChild(this.input);
|
|
275
|
+
if (this.localeAware) {
|
|
276
|
+
this.unsubscribeLocale = subscribeLocaleChange(() => this.applyLocaleStrings());
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
resolveStrings() {
|
|
280
|
+
const fromVariant = this.variant ? getTextFieldTranslation(this.variant) : void 0;
|
|
281
|
+
const label = this.fixedLabel ?? (this.labelKey ? t(this.labelKey) : fromVariant?.label) ?? "";
|
|
282
|
+
const placeholder = this.fixedPlaceholder ?? (this.placeholderKey ? t(this.placeholderKey) : fromVariant?.placeholder) ?? "";
|
|
283
|
+
const value = this.fixedValue ?? fromVariant?.value ?? "";
|
|
284
|
+
return { label, placeholder, value };
|
|
285
|
+
}
|
|
286
|
+
applyLocaleStrings() {
|
|
287
|
+
const resolved = this.resolveStrings();
|
|
288
|
+
if (this.labelEl && !this.fixedLabel) {
|
|
289
|
+
this.labelEl.textContent = resolved.label;
|
|
290
|
+
}
|
|
291
|
+
if (!this.fixedPlaceholder) {
|
|
292
|
+
this.input.placeholder = resolved.placeholder;
|
|
293
|
+
}
|
|
294
|
+
if (this.fixedValue === void 0 && this.variant === "disabled") {
|
|
295
|
+
this.input.value = resolved.value;
|
|
296
|
+
}
|
|
297
|
+
if (!this.sinhalaExplicit) {
|
|
298
|
+
this.setSinhala(getLocale() === "si");
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
getValue() {
|
|
302
|
+
return this.input.value;
|
|
303
|
+
}
|
|
304
|
+
setValue(value) {
|
|
305
|
+
this.input.value = value;
|
|
306
|
+
}
|
|
307
|
+
focus() {
|
|
308
|
+
this.input.focus();
|
|
309
|
+
}
|
|
310
|
+
setDisabled(disabled) {
|
|
311
|
+
this.input.disabled = disabled;
|
|
312
|
+
this.element.classList.toggle("helaui-textfield--disabled", disabled);
|
|
313
|
+
}
|
|
314
|
+
setLabel(label) {
|
|
315
|
+
if (this.labelEl) {
|
|
316
|
+
this.labelEl.textContent = label;
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
setPlaceholder(placeholder) {
|
|
320
|
+
this.input.placeholder = placeholder;
|
|
321
|
+
}
|
|
322
|
+
setSinhala(enabled) {
|
|
323
|
+
this.input.classList.toggle(SINHALA_FONT_CLASS, enabled);
|
|
324
|
+
this.labelEl?.classList.toggle(SINHALA_FONT_CLASS, enabled);
|
|
325
|
+
}
|
|
326
|
+
/** Removes locale subscription. Call when discarding the field. */
|
|
327
|
+
destroy() {
|
|
328
|
+
this.unsubscribeLocale?.();
|
|
329
|
+
}
|
|
330
|
+
};
|
|
331
|
+
|
|
332
|
+
// src/assets/rain/fritter.png
|
|
333
|
+
var fritter_default = "./fritter-INYFVKEH.png";
|
|
334
|
+
|
|
335
|
+
// src/assets/rain/kokis.png
|
|
336
|
+
var kokis_default = "./kokis-R6R5HA62.png";
|
|
337
|
+
|
|
338
|
+
// src/assets/rain/leaf.png
|
|
339
|
+
var leaf_default = "./leaf-DEJYVWQI.png";
|
|
340
|
+
|
|
341
|
+
// src/assets/rain/swirl.png
|
|
342
|
+
var swirl_default = "./swirl-RVLEF6L5.png";
|
|
343
|
+
|
|
344
|
+
// src/assets/rain/builtinImages.ts
|
|
345
|
+
var BUILTIN_RAIN_IMAGES = [fritter_default, swirl_default, kokis_default, leaf_default];
|
|
346
|
+
|
|
347
|
+
// src/components/RainBackground.ts
|
|
348
|
+
function randomBetween(min, max) {
|
|
349
|
+
return min + Math.random() * (max - min);
|
|
350
|
+
}
|
|
351
|
+
function pick(items) {
|
|
352
|
+
return items[Math.floor(Math.random() * items.length)];
|
|
353
|
+
}
|
|
354
|
+
var RainBackground = class {
|
|
355
|
+
element;
|
|
356
|
+
constructor(options = {}) {
|
|
357
|
+
const {
|
|
358
|
+
images = [...BUILTIN_RAIN_IMAGES],
|
|
359
|
+
density = 28,
|
|
360
|
+
minSize = 28,
|
|
361
|
+
maxSize = 28,
|
|
362
|
+
minDuration = 8,
|
|
363
|
+
maxDuration = 18,
|
|
364
|
+
target = document.body,
|
|
365
|
+
zIndex = 0
|
|
366
|
+
} = options;
|
|
367
|
+
if (images.length === 0) {
|
|
368
|
+
throw new Error("RainBackground requires at least one image URL.");
|
|
369
|
+
}
|
|
370
|
+
this.element = document.createElement("div");
|
|
371
|
+
this.element.className = "helaui-rain-background";
|
|
372
|
+
this.element.setAttribute("aria-hidden", "true");
|
|
373
|
+
this.element.style.zIndex = String(zIndex);
|
|
374
|
+
for (let index = 0; index < density; index += 1) {
|
|
375
|
+
this.element.appendChild(this.createDrop(images, minSize, maxSize, minDuration, maxDuration));
|
|
376
|
+
}
|
|
377
|
+
target.prepend(this.element);
|
|
378
|
+
}
|
|
379
|
+
createDrop(images, minSize, maxSize, minDuration, maxDuration) {
|
|
380
|
+
const drop = document.createElement("img");
|
|
381
|
+
const duration = randomBetween(minDuration, maxDuration);
|
|
382
|
+
const size = randomBetween(minSize, maxSize);
|
|
383
|
+
drop.className = "helaui-rain-background__drop";
|
|
384
|
+
drop.src = pick(images);
|
|
385
|
+
drop.alt = "";
|
|
386
|
+
drop.decoding = "async";
|
|
387
|
+
drop.loading = "lazy";
|
|
388
|
+
drop.draggable = false;
|
|
389
|
+
drop.style.setProperty("--helaui-rain-x", `${randomBetween(0, 100)}%`);
|
|
390
|
+
drop.style.setProperty("--helaui-rain-size", `${size}px`);
|
|
391
|
+
drop.style.setProperty("--helaui-rain-duration", `${duration.toFixed(2)}s`);
|
|
392
|
+
drop.style.setProperty("--helaui-rain-delay", `-${randomBetween(0, duration).toFixed(2)}s`);
|
|
393
|
+
drop.style.setProperty("--helaui-rain-rotation", `${randomBetween(-35, 35).toFixed(1)}deg`);
|
|
394
|
+
drop.style.setProperty("--helaui-rain-spin", `${randomBetween(90, 360).toFixed(0)}deg`);
|
|
395
|
+
drop.style.setProperty("--helaui-rain-drift", `${randomBetween(-40, 40).toFixed(0)}px`);
|
|
396
|
+
return drop;
|
|
397
|
+
}
|
|
398
|
+
/** Removes the background from the DOM. */
|
|
399
|
+
destroy() {
|
|
400
|
+
this.element.remove();
|
|
401
|
+
}
|
|
402
|
+
};
|
|
403
|
+
var DEFAULT_RAIN_IMAGES = ["fritter.png", "swirl.png", "kokis.png", "leaf.png"];
|
|
404
|
+
function getDefaultRainImageUrls(basePath) {
|
|
405
|
+
const normalizedBase = basePath.endsWith("/") ? basePath : `${basePath}/`;
|
|
406
|
+
return DEFAULT_RAIN_IMAGES.map((name) => `${normalizedBase}${name}`);
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
// src/components/Calendar.ts
|
|
410
|
+
var SINHALA_NUMERALS = ["\u0DE6", "\u0DE7", "\u0DE8", "\u0DE9", "\u0DEA", "\u0DEB", "\u0DEC", "\u0DED", "\u0DEE", "\u0DEF"];
|
|
411
|
+
function formatSinhalaNumeral(num) {
|
|
412
|
+
return num.toString().replace(/[0-9]/g, (digit) => SINHALA_NUMERALS[parseInt(digit, 10)]);
|
|
413
|
+
}
|
|
414
|
+
var SINHALA_MONTH_NAMES = [
|
|
415
|
+
"\u0DAF\u0DD4\u0DBB\u0DD4\u0DAD\u0DD4",
|
|
416
|
+
"\u0DB1\u0DC0\u0DB8\u0DCA",
|
|
417
|
+
"\u0DB8\u0DD0\u0DAF\u0DD2\u0DB1\u0DCA",
|
|
418
|
+
"\u0DB6\u0D9A\u0DCA",
|
|
419
|
+
"\u0DC0\u0DD9\u0DC3\u0D9A\u0DCA",
|
|
420
|
+
"\u0DB4\u0DDC\u0DC3\u0DDC\u0DB1\u0DCA",
|
|
421
|
+
"\u0D87\u0DC3\u0DC5",
|
|
422
|
+
"\u0DB1\u0DD2\u0D9A\u0DD2\u0DAB\u0DD2",
|
|
423
|
+
"\u0DB6\u0DD2\u0DB1\u0DBB",
|
|
424
|
+
"\u0DC0\u0DB4\u0DCA",
|
|
425
|
+
"\u0D89\u0DBD\u0DCA",
|
|
426
|
+
"\u0D8B\u0DB3\u0DD4\u0D85\u0DB4\u0DCA"
|
|
427
|
+
];
|
|
428
|
+
var Calendar = class {
|
|
429
|
+
element;
|
|
430
|
+
selectedDate = null;
|
|
431
|
+
viewYear;
|
|
432
|
+
viewMonth;
|
|
433
|
+
// 0-11
|
|
434
|
+
showBuddhistEra;
|
|
435
|
+
highlightToday;
|
|
436
|
+
sinhalaExplicit;
|
|
437
|
+
sinhalaEnabled;
|
|
438
|
+
minDate;
|
|
439
|
+
maxDate;
|
|
440
|
+
poyaDatesSet;
|
|
441
|
+
onSelectCallback;
|
|
442
|
+
onMonthChangeCallback;
|
|
443
|
+
unsubscribeLocale;
|
|
444
|
+
/** True when the caller passed an explicit height — prevents auto six-row adjustment */
|
|
445
|
+
customHeight;
|
|
446
|
+
// DOM Elements
|
|
447
|
+
monthTitleEl;
|
|
448
|
+
subTitleEl;
|
|
449
|
+
eraBadgeEl;
|
|
450
|
+
weekdaysEl;
|
|
451
|
+
daysGridEl;
|
|
452
|
+
footerEl;
|
|
453
|
+
selectedTextEl;
|
|
454
|
+
monthPopoverEl = null;
|
|
455
|
+
constructor(options = {}) {
|
|
456
|
+
const {
|
|
457
|
+
value,
|
|
458
|
+
initialDate,
|
|
459
|
+
minDate,
|
|
460
|
+
maxDate,
|
|
461
|
+
showBuddhistEra = true,
|
|
462
|
+
sinhala,
|
|
463
|
+
poyaDates = [],
|
|
464
|
+
highlightToday = true,
|
|
465
|
+
width,
|
|
466
|
+
height,
|
|
467
|
+
onSelect,
|
|
468
|
+
onMonthChange
|
|
469
|
+
} = options;
|
|
470
|
+
if (value) {
|
|
471
|
+
this.selectedDate = typeof value === "string" ? new Date(value) : new Date(value);
|
|
472
|
+
}
|
|
473
|
+
const initRef = this.selectedDate || initialDate || /* @__PURE__ */ new Date();
|
|
474
|
+
this.viewYear = initRef.getFullYear();
|
|
475
|
+
this.viewMonth = initRef.getMonth();
|
|
476
|
+
this.minDate = minDate;
|
|
477
|
+
this.maxDate = maxDate;
|
|
478
|
+
this.showBuddhistEra = showBuddhistEra;
|
|
479
|
+
this.highlightToday = highlightToday;
|
|
480
|
+
this.onSelectCallback = onSelect;
|
|
481
|
+
this.onMonthChangeCallback = onMonthChange;
|
|
482
|
+
this.poyaDatesSet = new Set(
|
|
483
|
+
poyaDates.map(
|
|
484
|
+
(d) => typeof d === "string" ? d : `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, "0")}-${String(
|
|
485
|
+
d.getDate()
|
|
486
|
+
).padStart(2, "0")}`
|
|
487
|
+
)
|
|
488
|
+
);
|
|
489
|
+
this.sinhalaExplicit = sinhala !== void 0;
|
|
490
|
+
this.sinhalaEnabled = sinhala ?? getLocale() === "si";
|
|
491
|
+
this.customHeight = height !== void 0;
|
|
492
|
+
this.element = document.createElement("div");
|
|
493
|
+
this.element.className = "helaui-calendar";
|
|
494
|
+
this.element.style.width = width ?? "360px";
|
|
495
|
+
this.element.style.height = height ?? "420px";
|
|
496
|
+
if (this.sinhalaEnabled) this.element.classList.add(SINHALA_FONT_CLASS);
|
|
497
|
+
this.renderSkeleton();
|
|
498
|
+
this.render();
|
|
499
|
+
this.unsubscribeLocale = subscribeLocaleChange(() => {
|
|
500
|
+
if (!this.sinhalaExplicit) {
|
|
501
|
+
this.setSinhala(getLocale() === "si");
|
|
502
|
+
} else {
|
|
503
|
+
this.render();
|
|
504
|
+
}
|
|
505
|
+
});
|
|
506
|
+
}
|
|
507
|
+
renderSkeleton() {
|
|
508
|
+
const header = document.createElement("div");
|
|
509
|
+
header.className = "helaui-calendar__header";
|
|
510
|
+
const prevBtn = document.createElement("button");
|
|
511
|
+
prevBtn.type = "button";
|
|
512
|
+
prevBtn.className = "helaui-calendar__nav-btn";
|
|
513
|
+
prevBtn.innerHTML = "❮";
|
|
514
|
+
prevBtn.ariaLabel = "Previous Month";
|
|
515
|
+
prevBtn.addEventListener("click", () => this.prevMonth());
|
|
516
|
+
const titleWrap = document.createElement("div");
|
|
517
|
+
titleWrap.className = "helaui-calendar__title-wrap";
|
|
518
|
+
titleWrap.title = "Click to choose month";
|
|
519
|
+
titleWrap.addEventListener("click", (e) => {
|
|
520
|
+
e.stopPropagation();
|
|
521
|
+
this.toggleMonthPopover();
|
|
522
|
+
});
|
|
523
|
+
this.monthTitleEl = document.createElement("span");
|
|
524
|
+
this.monthTitleEl.className = "helaui-calendar__month-name";
|
|
525
|
+
this.subTitleEl = document.createElement("span");
|
|
526
|
+
this.subTitleEl.className = "helaui-calendar__sub-name";
|
|
527
|
+
this.eraBadgeEl = document.createElement("span");
|
|
528
|
+
this.eraBadgeEl.className = "helaui-calendar__era-badge";
|
|
529
|
+
titleWrap.appendChild(this.monthTitleEl);
|
|
530
|
+
titleWrap.appendChild(this.subTitleEl);
|
|
531
|
+
const nextBtn = document.createElement("button");
|
|
532
|
+
nextBtn.type = "button";
|
|
533
|
+
nextBtn.className = "helaui-calendar__nav-btn";
|
|
534
|
+
nextBtn.innerHTML = "❯";
|
|
535
|
+
nextBtn.ariaLabel = "Next Month";
|
|
536
|
+
nextBtn.addEventListener("click", () => this.nextMonth());
|
|
537
|
+
header.appendChild(prevBtn);
|
|
538
|
+
header.appendChild(titleWrap);
|
|
539
|
+
header.appendChild(nextBtn);
|
|
540
|
+
this.weekdaysEl = document.createElement("div");
|
|
541
|
+
this.weekdaysEl.className = "helaui-calendar__weekdays";
|
|
542
|
+
this.daysGridEl = document.createElement("div");
|
|
543
|
+
this.daysGridEl.className = "helaui-calendar__days";
|
|
544
|
+
this.footerEl = document.createElement("div");
|
|
545
|
+
this.footerEl.className = "helaui-calendar__footer";
|
|
546
|
+
const todayBtn = document.createElement("button");
|
|
547
|
+
todayBtn.type = "button";
|
|
548
|
+
todayBtn.className = "helaui-calendar__footer-btn";
|
|
549
|
+
todayBtn.dataset.action = "today";
|
|
550
|
+
todayBtn.addEventListener("click", () => this.goToToday());
|
|
551
|
+
this.selectedTextEl = document.createElement("span");
|
|
552
|
+
this.selectedTextEl.className = "helaui-calendar__selected-text";
|
|
553
|
+
const clearBtn = document.createElement("button");
|
|
554
|
+
clearBtn.type = "button";
|
|
555
|
+
clearBtn.className = "helaui-calendar__footer-btn";
|
|
556
|
+
clearBtn.dataset.action = "clear";
|
|
557
|
+
clearBtn.addEventListener("click", () => this.clear());
|
|
558
|
+
this.footerEl.appendChild(todayBtn);
|
|
559
|
+
this.footerEl.appendChild(this.selectedTextEl);
|
|
560
|
+
this.footerEl.appendChild(clearBtn);
|
|
561
|
+
this.element.appendChild(header);
|
|
562
|
+
this.element.appendChild(this.weekdaysEl);
|
|
563
|
+
this.element.appendChild(this.daysGridEl);
|
|
564
|
+
this.element.appendChild(this.footerEl);
|
|
565
|
+
document.addEventListener("click", (e) => {
|
|
566
|
+
if (this.monthPopoverEl && !this.element.contains(e.target)) {
|
|
567
|
+
this.closeMonthPopover();
|
|
568
|
+
}
|
|
569
|
+
});
|
|
570
|
+
}
|
|
571
|
+
render() {
|
|
572
|
+
const locale = getLocale();
|
|
573
|
+
const isSinhalaMode = this.sinhalaEnabled || locale === "si";
|
|
574
|
+
const calendarStrings = getCalendarTranslation();
|
|
575
|
+
const sinhalaMonthName = calendarStrings.sinhalaMonthNames?.[this.viewMonth] ?? SINHALA_MONTH_NAMES[this.viewMonth];
|
|
576
|
+
const englishMonthName = calendarStrings.monthNames?.[this.viewMonth] ?? "Month";
|
|
577
|
+
const beYear = this.viewYear + 543;
|
|
578
|
+
const yearDisplay = this.viewYear.toString();
|
|
579
|
+
const beYearDisplay = beYear.toString();
|
|
580
|
+
if (isSinhalaMode) {
|
|
581
|
+
this.monthTitleEl.textContent = sinhalaMonthName;
|
|
582
|
+
this.subTitleEl.textContent = yearDisplay;
|
|
583
|
+
if (this.showBuddhistEra) {
|
|
584
|
+
this.eraBadgeEl.textContent = `\u0DB6\u0DD4.\u0DC0. ${beYearDisplay}`;
|
|
585
|
+
this.subTitleEl.appendChild(this.eraBadgeEl);
|
|
586
|
+
}
|
|
587
|
+
} else {
|
|
588
|
+
this.monthTitleEl.textContent = englishMonthName;
|
|
589
|
+
this.subTitleEl.textContent = yearDisplay;
|
|
590
|
+
if (this.showBuddhistEra) {
|
|
591
|
+
this.eraBadgeEl.textContent = `BE ${beYearDisplay}`;
|
|
592
|
+
this.subTitleEl.appendChild(this.eraBadgeEl);
|
|
593
|
+
}
|
|
594
|
+
}
|
|
595
|
+
this.weekdaysEl.innerHTML = "";
|
|
596
|
+
const shortWeekdays = calendarStrings.shortWeekdayNames || ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
|
|
597
|
+
const fullWeekdays = calendarStrings.weekdayNames || [
|
|
598
|
+
"Sunday",
|
|
599
|
+
"Monday",
|
|
600
|
+
"Tuesday",
|
|
601
|
+
"Wednesday",
|
|
602
|
+
"Thursday",
|
|
603
|
+
"Friday",
|
|
604
|
+
"Saturday"
|
|
605
|
+
];
|
|
606
|
+
shortWeekdays.forEach((shortDay, i) => {
|
|
607
|
+
const dayEl = document.createElement("div");
|
|
608
|
+
dayEl.className = "helaui-calendar__weekday";
|
|
609
|
+
if (i === 0 || i === 6) {
|
|
610
|
+
dayEl.classList.add("helaui-calendar__weekday--weekend");
|
|
611
|
+
}
|
|
612
|
+
dayEl.textContent = shortDay;
|
|
613
|
+
dayEl.title = fullWeekdays[i];
|
|
614
|
+
this.weekdaysEl.appendChild(dayEl);
|
|
615
|
+
});
|
|
616
|
+
this.daysGridEl.innerHTML = "";
|
|
617
|
+
const firstDayIndex = new Date(this.viewYear, this.viewMonth, 1).getDay();
|
|
618
|
+
const daysInMonth = new Date(this.viewYear, this.viewMonth + 1, 0).getDate();
|
|
619
|
+
const daysInPrevMonth = new Date(this.viewYear, this.viewMonth, 0).getDate();
|
|
620
|
+
const today = /* @__PURE__ */ new Date();
|
|
621
|
+
for (let i = firstDayIndex - 1; i >= 0; i--) {
|
|
622
|
+
const dayNum = daysInPrevMonth - i;
|
|
623
|
+
const prevDate = new Date(this.viewYear, this.viewMonth - 1, dayNum);
|
|
624
|
+
const dayBtn = this.createDayButton(prevDate, dayNum, true);
|
|
625
|
+
this.daysGridEl.appendChild(dayBtn);
|
|
626
|
+
}
|
|
627
|
+
for (let dayNum = 1; dayNum <= daysInMonth; dayNum++) {
|
|
628
|
+
const currDate = new Date(this.viewYear, this.viewMonth, dayNum);
|
|
629
|
+
const isToday = this.highlightToday && today.getFullYear() === currDate.getFullYear() && today.getMonth() === currDate.getMonth() && today.getDate() === currDate.getDate();
|
|
630
|
+
const isSelected = !!this.selectedDate && this.selectedDate.getFullYear() === currDate.getFullYear() && this.selectedDate.getMonth() === currDate.getMonth() && this.selectedDate.getDate() === currDate.getDate();
|
|
631
|
+
const dayBtn = this.createDayButton(currDate, dayNum, false, isToday, isSelected);
|
|
632
|
+
this.daysGridEl.appendChild(dayBtn);
|
|
633
|
+
}
|
|
634
|
+
const totalCells = firstDayIndex + daysInMonth;
|
|
635
|
+
const remainingCells = (7 - totalCells % 7) % 7;
|
|
636
|
+
for (let dayNum = 1; dayNum <= remainingCells; dayNum++) {
|
|
637
|
+
const nextDate = new Date(this.viewYear, this.viewMonth + 1, dayNum);
|
|
638
|
+
const dayBtn = this.createDayButton(nextDate, dayNum, true);
|
|
639
|
+
this.daysGridEl.appendChild(dayBtn);
|
|
640
|
+
}
|
|
641
|
+
const needsSixRows = firstDayIndex + daysInMonth > 35;
|
|
642
|
+
this.element.classList.toggle("helaui-calendar--six-rows", needsSixRows && !this.customHeight);
|
|
643
|
+
if (!this.customHeight) {
|
|
644
|
+
this.element.style.height = needsSixRows ? "468px" : "420px";
|
|
645
|
+
}
|
|
646
|
+
const todayBtn = this.footerEl.querySelector('[data-action="today"]');
|
|
647
|
+
if (todayBtn) todayBtn.textContent = calendarStrings.today || "Today";
|
|
648
|
+
const clearBtn = this.footerEl.querySelector('[data-action="clear"]');
|
|
649
|
+
if (clearBtn) clearBtn.textContent = calendarStrings.clear || "Clear";
|
|
650
|
+
this.updateSelectedText();
|
|
651
|
+
}
|
|
652
|
+
createDayButton(date, dayNum, isOutside, isToday = false, isSelected = false) {
|
|
653
|
+
const btn = document.createElement("button");
|
|
654
|
+
btn.type = "button";
|
|
655
|
+
btn.className = "helaui-calendar__day";
|
|
656
|
+
btn.textContent = dayNum.toString();
|
|
657
|
+
const dateKey = `${date.getFullYear()}-${String(date.getMonth() + 1).padStart(
|
|
658
|
+
2,
|
|
659
|
+
"0"
|
|
660
|
+
)}-${String(date.getDate()).padStart(2, "0")}`;
|
|
661
|
+
if (isOutside) btn.classList.add("helaui-calendar__day--outside");
|
|
662
|
+
if (isToday) btn.classList.add("helaui-calendar__day--today");
|
|
663
|
+
if (isSelected) btn.classList.add("helaui-calendar__day--selected");
|
|
664
|
+
if (this.poyaDatesSet.has(dateKey) || date.getDate() === 15 && !isOutside) {
|
|
665
|
+
btn.classList.add("helaui-calendar__day--poya");
|
|
666
|
+
const poyaName = SINHALA_MONTH_NAMES[date.getMonth()] + " \u0DB4\u0DDD\u0DBA";
|
|
667
|
+
btn.title = `${dateKey} (${poyaName})`;
|
|
668
|
+
}
|
|
669
|
+
if (this.minDate && date < this.minDate || this.maxDate && date > this.maxDate) {
|
|
670
|
+
btn.classList.add("helaui-calendar__day--disabled");
|
|
671
|
+
btn.disabled = true;
|
|
672
|
+
} else {
|
|
673
|
+
btn.addEventListener("click", () => this.selectDate(date));
|
|
674
|
+
}
|
|
675
|
+
return btn;
|
|
676
|
+
}
|
|
677
|
+
updateSelectedText() {
|
|
678
|
+
if (!this.selectedDate) {
|
|
679
|
+
this.selectedTextEl.textContent = "";
|
|
680
|
+
return;
|
|
681
|
+
}
|
|
682
|
+
this.selectedTextEl.textContent = this.getFormattedSinhalaDate(this.selectedDate);
|
|
683
|
+
}
|
|
684
|
+
/** Gets formatted string e.g. "2026 වෙසක් 15" (Western digits) */
|
|
685
|
+
getFormattedSinhalaDate(date) {
|
|
686
|
+
const year = date.getFullYear();
|
|
687
|
+
const monthName = SINHALA_MONTH_NAMES[date.getMonth()];
|
|
688
|
+
const day = date.getDate();
|
|
689
|
+
return `${year} ${monthName} ${day}`;
|
|
690
|
+
}
|
|
691
|
+
selectDate(date) {
|
|
692
|
+
this.selectedDate = new Date(date);
|
|
693
|
+
this.viewYear = date.getFullYear();
|
|
694
|
+
this.viewMonth = date.getMonth();
|
|
695
|
+
this.render();
|
|
696
|
+
const formatted = this.getFormattedSinhalaDate(this.selectedDate);
|
|
697
|
+
this.onSelectCallback?.(this.selectedDate, formatted);
|
|
698
|
+
}
|
|
699
|
+
getValue() {
|
|
700
|
+
return this.selectedDate ? new Date(this.selectedDate) : null;
|
|
701
|
+
}
|
|
702
|
+
setValue(value) {
|
|
703
|
+
if (!value) {
|
|
704
|
+
this.selectedDate = null;
|
|
705
|
+
} else {
|
|
706
|
+
this.selectedDate = typeof value === "string" ? new Date(value) : new Date(value);
|
|
707
|
+
this.viewYear = this.selectedDate.getFullYear();
|
|
708
|
+
this.viewMonth = this.selectedDate.getMonth();
|
|
709
|
+
}
|
|
710
|
+
this.render();
|
|
711
|
+
}
|
|
712
|
+
setSinhala(enabled) {
|
|
713
|
+
this.sinhalaEnabled = enabled;
|
|
714
|
+
this.element.classList.toggle(SINHALA_FONT_CLASS, enabled);
|
|
715
|
+
this.render();
|
|
716
|
+
}
|
|
717
|
+
setShowBuddhistEra(show) {
|
|
718
|
+
this.showBuddhistEra = show;
|
|
719
|
+
this.render();
|
|
720
|
+
}
|
|
721
|
+
nextMonth() {
|
|
722
|
+
if (this.viewMonth === 11) {
|
|
723
|
+
this.viewMonth = 0;
|
|
724
|
+
this.viewYear++;
|
|
725
|
+
} else {
|
|
726
|
+
this.viewMonth++;
|
|
727
|
+
}
|
|
728
|
+
this.render();
|
|
729
|
+
this.onMonthChangeCallback?.(this.viewYear, this.viewMonth);
|
|
730
|
+
}
|
|
731
|
+
prevMonth() {
|
|
732
|
+
if (this.viewMonth === 0) {
|
|
733
|
+
this.viewMonth = 11;
|
|
734
|
+
this.viewYear--;
|
|
735
|
+
} else {
|
|
736
|
+
this.viewMonth--;
|
|
737
|
+
}
|
|
738
|
+
this.render();
|
|
739
|
+
this.onMonthChangeCallback?.(this.viewYear, this.viewMonth);
|
|
740
|
+
}
|
|
741
|
+
goToToday() {
|
|
742
|
+
const today = /* @__PURE__ */ new Date();
|
|
743
|
+
this.viewYear = today.getFullYear();
|
|
744
|
+
this.viewMonth = today.getMonth();
|
|
745
|
+
this.selectDate(today);
|
|
746
|
+
}
|
|
747
|
+
clear() {
|
|
748
|
+
this.selectedDate = null;
|
|
749
|
+
this.render();
|
|
750
|
+
}
|
|
751
|
+
toggleMonthPopover() {
|
|
752
|
+
if (this.monthPopoverEl) {
|
|
753
|
+
this.closeMonthPopover();
|
|
754
|
+
} else {
|
|
755
|
+
this.openMonthPopover();
|
|
756
|
+
}
|
|
757
|
+
}
|
|
758
|
+
openMonthPopover() {
|
|
759
|
+
this.closeMonthPopover();
|
|
760
|
+
this.monthPopoverEl = document.createElement("div");
|
|
761
|
+
this.monthPopoverEl.className = "helaui-calendar__month-popover";
|
|
762
|
+
const isSinhalaMode = this.sinhalaEnabled || getLocale() === "si";
|
|
763
|
+
const calendarStrings = getCalendarTranslation();
|
|
764
|
+
SINHALA_MONTH_NAMES.forEach((siMonth, i) => {
|
|
765
|
+
const item = document.createElement("button");
|
|
766
|
+
item.type = "button";
|
|
767
|
+
item.className = "helaui-calendar__month-item";
|
|
768
|
+
if (i === this.viewMonth) {
|
|
769
|
+
item.classList.add("helaui-calendar__month-item--active");
|
|
770
|
+
}
|
|
771
|
+
const engMonth = calendarStrings.monthNames ? calendarStrings.monthNames[i] : "";
|
|
772
|
+
item.textContent = isSinhalaMode ? siMonth : engMonth;
|
|
773
|
+
item.addEventListener("click", (e) => {
|
|
774
|
+
e.stopPropagation();
|
|
775
|
+
this.viewMonth = i;
|
|
776
|
+
this.closeMonthPopover();
|
|
777
|
+
this.render();
|
|
778
|
+
this.onMonthChangeCallback?.(this.viewYear, this.viewMonth);
|
|
779
|
+
});
|
|
780
|
+
this.monthPopoverEl.appendChild(item);
|
|
781
|
+
});
|
|
782
|
+
this.element.appendChild(this.monthPopoverEl);
|
|
783
|
+
}
|
|
784
|
+
closeMonthPopover() {
|
|
785
|
+
if (this.monthPopoverEl) {
|
|
786
|
+
this.monthPopoverEl.remove();
|
|
787
|
+
this.monthPopoverEl = null;
|
|
788
|
+
}
|
|
789
|
+
}
|
|
790
|
+
/** Cleans up subscriptions and event listeners */
|
|
791
|
+
destroy() {
|
|
792
|
+
this.unsubscribeLocale?.();
|
|
793
|
+
this.closeMonthPopover();
|
|
794
|
+
}
|
|
795
|
+
};
|
|
796
|
+
|
|
797
|
+
// src/assets/sun-mandala/ira-handa.png
|
|
798
|
+
var ira_handa_default = "./ira-handa-7DIWZWI4.png";
|
|
799
|
+
|
|
800
|
+
// src/assets/sun-mandala/builtinImage.ts
|
|
801
|
+
var BUILTIN_SUN_MANDALA_IMAGE = ira_handa_default;
|
|
802
|
+
|
|
803
|
+
// src/components/SunMandala.ts
|
|
804
|
+
var SunMandala = class {
|
|
805
|
+
element;
|
|
806
|
+
spinEl;
|
|
807
|
+
faceEl;
|
|
808
|
+
spinImg;
|
|
809
|
+
faceImg;
|
|
810
|
+
constructor(options = {}) {
|
|
811
|
+
const {
|
|
812
|
+
src = BUILTIN_SUN_MANDALA_IMAGE,
|
|
813
|
+
alt = "Sri Lankan Ira Handa sun mandala",
|
|
814
|
+
size = "280px",
|
|
815
|
+
duration = 36,
|
|
816
|
+
faceRadius = "22%",
|
|
817
|
+
paused = false
|
|
818
|
+
} = options;
|
|
819
|
+
this.element = document.createElement("div");
|
|
820
|
+
this.element.className = "helaui-sun-mandala";
|
|
821
|
+
this.element.style.setProperty("--helaui-sun-mandala-size", size);
|
|
822
|
+
this.element.style.setProperty("--helaui-sun-mandala-duration", `${duration}s`);
|
|
823
|
+
this.element.style.setProperty("--helaui-sun-mandala-face-radius", faceRadius);
|
|
824
|
+
this.element.setAttribute("role", "img");
|
|
825
|
+
this.element.setAttribute("aria-label", alt);
|
|
826
|
+
this.spinEl = document.createElement("div");
|
|
827
|
+
this.spinEl.className = "helaui-sun-mandala__spin";
|
|
828
|
+
this.spinEl.setAttribute("aria-hidden", "true");
|
|
829
|
+
this.spinImg = document.createElement("img");
|
|
830
|
+
this.spinImg.className = "helaui-sun-mandala__image";
|
|
831
|
+
this.spinImg.src = src;
|
|
832
|
+
this.spinImg.alt = "";
|
|
833
|
+
this.spinImg.draggable = false;
|
|
834
|
+
this.spinImg.decoding = "async";
|
|
835
|
+
this.spinEl.appendChild(this.spinImg);
|
|
836
|
+
this.faceEl = document.createElement("div");
|
|
837
|
+
this.faceEl.className = "helaui-sun-mandala__face";
|
|
838
|
+
this.faceEl.setAttribute("aria-hidden", "true");
|
|
839
|
+
this.faceImg = document.createElement("img");
|
|
840
|
+
this.faceImg.className = "helaui-sun-mandala__image";
|
|
841
|
+
this.faceImg.src = src;
|
|
842
|
+
this.faceImg.alt = "";
|
|
843
|
+
this.faceImg.draggable = false;
|
|
844
|
+
this.faceImg.decoding = "async";
|
|
845
|
+
this.faceEl.appendChild(this.faceImg);
|
|
846
|
+
this.element.appendChild(this.spinEl);
|
|
847
|
+
this.element.appendChild(this.faceEl);
|
|
848
|
+
if (paused) this.setPaused(true);
|
|
849
|
+
}
|
|
850
|
+
/** Pause or resume the aura rotation. */
|
|
851
|
+
setPaused(paused) {
|
|
852
|
+
this.element.classList.toggle("helaui-sun-mandala--paused", paused);
|
|
853
|
+
}
|
|
854
|
+
isPaused() {
|
|
855
|
+
return this.element.classList.contains("helaui-sun-mandala--paused");
|
|
856
|
+
}
|
|
857
|
+
/** Set full-circle rotation duration in seconds. */
|
|
858
|
+
setDuration(seconds) {
|
|
859
|
+
this.element.style.setProperty("--helaui-sun-mandala-duration", `${seconds}s`);
|
|
860
|
+
}
|
|
861
|
+
/** Update display size (width & height). */
|
|
862
|
+
setSize(size) {
|
|
863
|
+
this.element.style.setProperty("--helaui-sun-mandala-size", size);
|
|
864
|
+
}
|
|
865
|
+
/** Update the static face clip radius. */
|
|
866
|
+
setFaceRadius(radius) {
|
|
867
|
+
this.element.style.setProperty("--helaui-sun-mandala-face-radius", radius);
|
|
868
|
+
}
|
|
869
|
+
destroy() {
|
|
870
|
+
this.element.remove();
|
|
871
|
+
}
|
|
872
|
+
};
|
|
873
|
+
|
|
874
|
+
// src/theme/defaultTheme.ts
|
|
875
|
+
var defaultTheme = {
|
|
876
|
+
primary: "#8D153A",
|
|
877
|
+
secondary: "#FFBE00",
|
|
878
|
+
success: "#005B33",
|
|
879
|
+
accent: "#FF7A00",
|
|
880
|
+
black: "#000000",
|
|
881
|
+
white: "#FFFFFF",
|
|
882
|
+
grey: "#808080"
|
|
883
|
+
};
|
|
884
|
+
|
|
885
|
+
// src/theme/themeVars.ts
|
|
886
|
+
var THEME_VAR_MAP = {
|
|
887
|
+
primary: "--helaui-primary",
|
|
888
|
+
secondary: "--helaui-secondary",
|
|
889
|
+
success: "--helaui-success",
|
|
890
|
+
accent: "--helaui-accent",
|
|
891
|
+
black: "--helaui-black",
|
|
892
|
+
white: "--helaui-white",
|
|
893
|
+
grey: "--helaui-grey"
|
|
894
|
+
};
|
|
895
|
+
|
|
896
|
+
// src/theme/applyTheme.ts
|
|
897
|
+
function hexToRgba(hex, alpha) {
|
|
898
|
+
const normalized = hex.replace("#", "");
|
|
899
|
+
const full = normalized.length === 3 ? normalized.split("").map((char) => char + char).join("") : normalized.padStart(6, "0").slice(0, 6);
|
|
900
|
+
const r = Number.parseInt(full.slice(0, 2), 16);
|
|
901
|
+
const g = Number.parseInt(full.slice(2, 4), 16);
|
|
902
|
+
const b = Number.parseInt(full.slice(4, 6), 16);
|
|
903
|
+
return `rgba(${r}, ${g}, ${b}, ${alpha})`;
|
|
904
|
+
}
|
|
905
|
+
function applySemanticTokens(theme, target) {
|
|
906
|
+
target.style.setProperty("--helaui-text", theme.black);
|
|
907
|
+
target.style.setProperty("--helaui-text-muted", theme.grey);
|
|
908
|
+
target.style.setProperty("--helaui-text-inverse", theme.white);
|
|
909
|
+
target.style.setProperty("--helaui-background", theme.white);
|
|
910
|
+
target.style.setProperty("--helaui-surface", theme.white);
|
|
911
|
+
target.style.setProperty("--helaui-focus", theme.primary);
|
|
912
|
+
target.style.setProperty("--helaui-focus-ring", hexToRgba(theme.primary, 0.2));
|
|
913
|
+
}
|
|
914
|
+
function applyTheme(overrides = {}, target = document.documentElement) {
|
|
915
|
+
const theme = { ...defaultTheme, ...overrides };
|
|
916
|
+
Object.keys(THEME_VAR_MAP).forEach((key) => {
|
|
917
|
+
target.style.setProperty(THEME_VAR_MAP[key], theme[key]);
|
|
918
|
+
});
|
|
919
|
+
applySemanticTokens(theme, target);
|
|
920
|
+
return theme;
|
|
921
|
+
}
|
|
922
|
+
function resetTheme(target = document.documentElement) {
|
|
923
|
+
Object.values(THEME_VAR_MAP).forEach((varName) => {
|
|
924
|
+
target.style.removeProperty(varName);
|
|
925
|
+
});
|
|
926
|
+
[
|
|
927
|
+
"--helaui-text",
|
|
928
|
+
"--helaui-text-muted",
|
|
929
|
+
"--helaui-text-inverse",
|
|
930
|
+
"--helaui-background",
|
|
931
|
+
"--helaui-surface",
|
|
932
|
+
"--helaui-focus",
|
|
933
|
+
"--helaui-focus-ring"
|
|
934
|
+
].forEach((varName) => {
|
|
935
|
+
target.style.removeProperty(varName);
|
|
936
|
+
});
|
|
937
|
+
return { ...defaultTheme };
|
|
938
|
+
}
|
|
939
|
+
function createThemeStyle(theme = {}) {
|
|
940
|
+
const merged = { ...defaultTheme, ...theme };
|
|
941
|
+
return Object.keys(THEME_VAR_MAP).map((key) => `${THEME_VAR_MAP[key]}: ${merged[key]};`).join(" ");
|
|
942
|
+
}
|
|
943
|
+
export {
|
|
944
|
+
BUILTIN_RAIN_IMAGES,
|
|
945
|
+
BUILTIN_SUN_MANDALA_IMAGE,
|
|
946
|
+
Calendar,
|
|
947
|
+
DEFAULT_RAIN_IMAGES,
|
|
948
|
+
RainBackground,
|
|
949
|
+
SINHALA_FONT_CLASS,
|
|
950
|
+
SINHALA_FONT_FAMILY,
|
|
951
|
+
SINHALA_MONTH_NAMES,
|
|
952
|
+
SunMandala,
|
|
953
|
+
THEME_VAR_MAP,
|
|
954
|
+
TextField,
|
|
955
|
+
applySinhalaFont,
|
|
956
|
+
applyTheme,
|
|
957
|
+
applyTranslations,
|
|
958
|
+
createThemeStyle,
|
|
959
|
+
defaultTheme,
|
|
960
|
+
defaultTranslations,
|
|
961
|
+
formatSinhalaNumeral,
|
|
962
|
+
getCalendarTranslation,
|
|
963
|
+
getDefaultRainImageUrls,
|
|
964
|
+
getLocale,
|
|
965
|
+
getTextFieldTranslation,
|
|
966
|
+
resetTheme,
|
|
967
|
+
resetTranslations,
|
|
968
|
+
setLocale,
|
|
969
|
+
sinhalaFontStyles,
|
|
970
|
+
subscribeLocaleChange,
|
|
971
|
+
t
|
|
972
|
+
};
|