@lionrapid/core 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/dist/browser/auto-init.d.ts +5 -0
- package/dist/browser/auto-init.d.ts.map +1 -1
- package/dist/browser/auto-init.js +22 -2
- package/dist/browser/auto-init.js.map +1 -1
- package/dist/browser/lionrapid.auto.dev.js +175 -98
- package/dist/browser/lionrapid.auto.dev.js.map +3 -3
- package/dist/browser/lionrapid.auto.js +175 -98
- package/dist/browser/lionrapid.auto.js.map +3 -3
- package/dist/browser/lionrapid.auto.min.js +3 -3
- package/dist/browser/lionrapid.auto.min.js.map +4 -4
- package/dist/browser/lionrapid.esm.js +367 -95
- package/dist/browser/lionrapid.esm.js.map +3 -3
- package/dist/browser/lionrapid.esm.min.js +2 -2
- package/dist/browser/lionrapid.esm.min.js.map +4 -4
- package/dist/browser/lionrapid.iife.dev.js +367 -95
- package/dist/browser/lionrapid.iife.dev.js.map +3 -3
- package/dist/browser/lionrapid.iife.js +367 -95
- package/dist/browser/lionrapid.iife.js.map +3 -3
- package/dist/browser/lionrapid.iife.min.js +2 -2
- package/dist/browser/lionrapid.iife.min.js.map +4 -4
- package/dist/browser/lionrapid.umd.js +367 -95
- package/dist/browser/lionrapid.umd.js.map +3 -3
- package/dist/browser/lionrapid.umd.min.js +2 -2
- package/dist/browser/lionrapid.umd.min.js.map +4 -4
- package/dist/builder.d.ts +8 -0
- package/dist/builder.d.ts.map +1 -1
- package/dist/builder.js +10 -0
- package/dist/builder.js.map +1 -1
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +11 -0
- package/dist/index.js.map +1 -1
- package/dist/repositories/index.d.ts +1 -0
- package/dist/repositories/index.d.ts.map +1 -1
- package/dist/repositories/index.js +1 -0
- package/dist/repositories/index.js.map +1 -1
- package/dist/repositories/static-repository.d.ts +40 -0
- package/dist/repositories/static-repository.d.ts.map +1 -0
- package/dist/repositories/static-repository.js +60 -0
- package/dist/repositories/static-repository.js.map +1 -0
- package/package.json +1 -1
|
@@ -3143,6 +3143,155 @@ var LionRapid = (() => {
|
|
|
3143
3143
|
}
|
|
3144
3144
|
};
|
|
3145
3145
|
|
|
3146
|
+
// src/repositories/memory-repository.ts
|
|
3147
|
+
var MemoryRepository = class {
|
|
3148
|
+
constructor(config) {
|
|
3149
|
+
__publicField(this, "name", "MemoryRepository");
|
|
3150
|
+
__publicField(this, "type", "memory");
|
|
3151
|
+
__publicField(this, "config", {});
|
|
3152
|
+
__publicField(this, "cache", /* @__PURE__ */ new Map());
|
|
3153
|
+
__publicField(this, "accessOrder", /* @__PURE__ */ new Map());
|
|
3154
|
+
__publicField(this, "maxSize", 1e3);
|
|
3155
|
+
this.config = config;
|
|
3156
|
+
this.maxSize = this.config.options?.maxSize || 1e3;
|
|
3157
|
+
}
|
|
3158
|
+
get(key) {
|
|
3159
|
+
const value = this.cache.get(key);
|
|
3160
|
+
if (value !== void 0) {
|
|
3161
|
+
this.accessOrder.set(key, Date.now());
|
|
3162
|
+
return value;
|
|
3163
|
+
}
|
|
3164
|
+
return null;
|
|
3165
|
+
}
|
|
3166
|
+
set(key, value) {
|
|
3167
|
+
if (this.cache.size >= this.maxSize && !this.cache.has(key)) {
|
|
3168
|
+
this.evictOldest();
|
|
3169
|
+
}
|
|
3170
|
+
this.cache.set(key, value);
|
|
3171
|
+
this.accessOrder.set(key, Date.now());
|
|
3172
|
+
}
|
|
3173
|
+
remove(key) {
|
|
3174
|
+
this.cache.delete(key);
|
|
3175
|
+
this.accessOrder.delete(key);
|
|
3176
|
+
}
|
|
3177
|
+
clear() {
|
|
3178
|
+
this.cache.clear();
|
|
3179
|
+
this.accessOrder.clear();
|
|
3180
|
+
}
|
|
3181
|
+
/**
|
|
3182
|
+
* Clear all entries for a specific namespace
|
|
3183
|
+
* Removes both the namespace cache entry and all individual translation keys
|
|
3184
|
+
*/
|
|
3185
|
+
clearNamespace(locale, namespace) {
|
|
3186
|
+
const namespaceCacheKey = createNamespaceCacheKey(locale, namespace);
|
|
3187
|
+
const keyPrefix = `${locale}:${namespace}:`;
|
|
3188
|
+
this.cache.delete(namespaceCacheKey);
|
|
3189
|
+
this.accessOrder.delete(namespaceCacheKey);
|
|
3190
|
+
for (const key of this.cache.keys()) {
|
|
3191
|
+
if (key.startsWith(keyPrefix)) {
|
|
3192
|
+
this.cache.delete(key);
|
|
3193
|
+
this.accessOrder.delete(key);
|
|
3194
|
+
}
|
|
3195
|
+
}
|
|
3196
|
+
}
|
|
3197
|
+
getNamespace(locale, namespace) {
|
|
3198
|
+
const namespaceCacheKey = createNamespaceCacheKey(locale, namespace);
|
|
3199
|
+
const namespaceData = this.cache.get(namespaceCacheKey);
|
|
3200
|
+
if (!namespaceData) return null;
|
|
3201
|
+
try {
|
|
3202
|
+
return JSON.parse(namespaceData);
|
|
3203
|
+
} catch (error) {
|
|
3204
|
+
this.cache.delete(namespaceCacheKey);
|
|
3205
|
+
return null;
|
|
3206
|
+
}
|
|
3207
|
+
}
|
|
3208
|
+
setNamespace(locale, namespace, translations) {
|
|
3209
|
+
const namespaceCacheKey = createNamespaceCacheKey(locale, namespace);
|
|
3210
|
+
this.cache.set(namespaceCacheKey, JSON.stringify(translations));
|
|
3211
|
+
}
|
|
3212
|
+
evictOldest() {
|
|
3213
|
+
let oldestKey = "";
|
|
3214
|
+
let oldestTime = Date.now();
|
|
3215
|
+
for (const [key, time] of this.accessOrder.entries()) {
|
|
3216
|
+
if (time < oldestTime) {
|
|
3217
|
+
oldestTime = time;
|
|
3218
|
+
oldestKey = key;
|
|
3219
|
+
}
|
|
3220
|
+
}
|
|
3221
|
+
if (oldestKey) {
|
|
3222
|
+
this.cache.delete(oldestKey);
|
|
3223
|
+
this.accessOrder.delete(oldestKey);
|
|
3224
|
+
}
|
|
3225
|
+
}
|
|
3226
|
+
/**
|
|
3227
|
+
* Get all cache entries for debugging
|
|
3228
|
+
*/
|
|
3229
|
+
getEntries() {
|
|
3230
|
+
const entries = {};
|
|
3231
|
+
for (const [key, value] of this.cache.entries()) {
|
|
3232
|
+
entries[key] = value;
|
|
3233
|
+
}
|
|
3234
|
+
return entries;
|
|
3235
|
+
}
|
|
3236
|
+
getConfig() {
|
|
3237
|
+
return this.config;
|
|
3238
|
+
}
|
|
3239
|
+
};
|
|
3240
|
+
|
|
3241
|
+
// src/repositories/static-repository.ts
|
|
3242
|
+
var StaticRepository = class {
|
|
3243
|
+
constructor(bundle, config = {}) {
|
|
3244
|
+
__publicField(this, "name", "StaticRepository");
|
|
3245
|
+
__publicField(this, "type", "memory");
|
|
3246
|
+
__publicField(this, "config");
|
|
3247
|
+
__publicField(this, "mem");
|
|
3248
|
+
this.config = {
|
|
3249
|
+
enabled: config.enabled ?? true,
|
|
3250
|
+
priority: config.priority ?? 0.5,
|
|
3251
|
+
// after the live memory (0), before storage
|
|
3252
|
+
options: {
|
|
3253
|
+
ttl: Number.MAX_SAFE_INTEGER,
|
|
3254
|
+
maxSize: Number.MAX_SAFE_INTEGER,
|
|
3255
|
+
...config.options
|
|
3256
|
+
}
|
|
3257
|
+
};
|
|
3258
|
+
this.mem = new MemoryRepository({ options: { maxSize: Number.MAX_SAFE_INTEGER } });
|
|
3259
|
+
for (const [locale, namespaces] of Object.entries(bundle)) {
|
|
3260
|
+
for (const [namespace, translations] of Object.entries(namespaces)) {
|
|
3261
|
+
this.mem.setNamespace(locale, namespace, translations);
|
|
3262
|
+
const flat = flattenTranslations(
|
|
3263
|
+
translations,
|
|
3264
|
+
"",
|
|
3265
|
+
locale,
|
|
3266
|
+
namespace
|
|
3267
|
+
);
|
|
3268
|
+
for (const [key, value] of Object.entries(flat)) this.mem.set(key, value);
|
|
3269
|
+
}
|
|
3270
|
+
}
|
|
3271
|
+
}
|
|
3272
|
+
get(key) {
|
|
3273
|
+
return this.mem.get(key);
|
|
3274
|
+
}
|
|
3275
|
+
getNamespace(locale, namespace) {
|
|
3276
|
+
return this.mem.getNamespace(locale, namespace);
|
|
3277
|
+
}
|
|
3278
|
+
getEntries() {
|
|
3279
|
+
return this.mem.getEntries();
|
|
3280
|
+
}
|
|
3281
|
+
getConfig() {
|
|
3282
|
+
return this.config;
|
|
3283
|
+
}
|
|
3284
|
+
// Read-only: the live memory layer owns fresh network data; this stays pristine.
|
|
3285
|
+
set() {
|
|
3286
|
+
}
|
|
3287
|
+
remove() {
|
|
3288
|
+
}
|
|
3289
|
+
clear() {
|
|
3290
|
+
}
|
|
3291
|
+
setNamespace() {
|
|
3292
|
+
}
|
|
3293
|
+
};
|
|
3294
|
+
|
|
3146
3295
|
// src/sync/missing-translation-queue.ts
|
|
3147
3296
|
var COOLDOWN_MS = 6e4;
|
|
3148
3297
|
var MissingTranslationQueue = class {
|
|
@@ -3351,6 +3500,15 @@ var LionRapid = (() => {
|
|
|
3351
3500
|
}
|
|
3352
3501
|
return this;
|
|
3353
3502
|
}
|
|
3503
|
+
/**
|
|
3504
|
+
* Offline resilience: seed a translation bundle (or the CLI's snapshot files)
|
|
3505
|
+
* as a read-only sync layer that resolves synchronously even with the server
|
|
3506
|
+
* down and nothing cached. Sits after the live memory layer (priority 0) at
|
|
3507
|
+
* `priority` (default 0.5), so fresh network data always shadows it.
|
|
3508
|
+
*/
|
|
3509
|
+
useStaticBundle(bundle, priority = 0.5) {
|
|
3510
|
+
return this.use(new StaticRepository(bundle, { priority }));
|
|
3511
|
+
}
|
|
3354
3512
|
async build() {
|
|
3355
3513
|
const eventEmitter = new EventEmitter();
|
|
3356
3514
|
const buildBus = eventEmitter.builder();
|
|
@@ -3948,101 +4106,6 @@ var LionRapid = (() => {
|
|
|
3948
4106
|
__publicField(_NetworkRepository, "VERSION_PREFIX", "lionrapid:v:");
|
|
3949
4107
|
var NetworkRepository = _NetworkRepository;
|
|
3950
4108
|
|
|
3951
|
-
// src/repositories/memory-repository.ts
|
|
3952
|
-
var MemoryRepository = class {
|
|
3953
|
-
constructor(config) {
|
|
3954
|
-
__publicField(this, "name", "MemoryRepository");
|
|
3955
|
-
__publicField(this, "type", "memory");
|
|
3956
|
-
__publicField(this, "config", {});
|
|
3957
|
-
__publicField(this, "cache", /* @__PURE__ */ new Map());
|
|
3958
|
-
__publicField(this, "accessOrder", /* @__PURE__ */ new Map());
|
|
3959
|
-
__publicField(this, "maxSize", 1e3);
|
|
3960
|
-
this.config = config;
|
|
3961
|
-
this.maxSize = this.config.options?.maxSize || 1e3;
|
|
3962
|
-
}
|
|
3963
|
-
get(key) {
|
|
3964
|
-
const value = this.cache.get(key);
|
|
3965
|
-
if (value !== void 0) {
|
|
3966
|
-
this.accessOrder.set(key, Date.now());
|
|
3967
|
-
return value;
|
|
3968
|
-
}
|
|
3969
|
-
return null;
|
|
3970
|
-
}
|
|
3971
|
-
set(key, value) {
|
|
3972
|
-
if (this.cache.size >= this.maxSize && !this.cache.has(key)) {
|
|
3973
|
-
this.evictOldest();
|
|
3974
|
-
}
|
|
3975
|
-
this.cache.set(key, value);
|
|
3976
|
-
this.accessOrder.set(key, Date.now());
|
|
3977
|
-
}
|
|
3978
|
-
remove(key) {
|
|
3979
|
-
this.cache.delete(key);
|
|
3980
|
-
this.accessOrder.delete(key);
|
|
3981
|
-
}
|
|
3982
|
-
clear() {
|
|
3983
|
-
this.cache.clear();
|
|
3984
|
-
this.accessOrder.clear();
|
|
3985
|
-
}
|
|
3986
|
-
/**
|
|
3987
|
-
* Clear all entries for a specific namespace
|
|
3988
|
-
* Removes both the namespace cache entry and all individual translation keys
|
|
3989
|
-
*/
|
|
3990
|
-
clearNamespace(locale, namespace) {
|
|
3991
|
-
const namespaceCacheKey = createNamespaceCacheKey(locale, namespace);
|
|
3992
|
-
const keyPrefix = `${locale}:${namespace}:`;
|
|
3993
|
-
this.cache.delete(namespaceCacheKey);
|
|
3994
|
-
this.accessOrder.delete(namespaceCacheKey);
|
|
3995
|
-
for (const key of this.cache.keys()) {
|
|
3996
|
-
if (key.startsWith(keyPrefix)) {
|
|
3997
|
-
this.cache.delete(key);
|
|
3998
|
-
this.accessOrder.delete(key);
|
|
3999
|
-
}
|
|
4000
|
-
}
|
|
4001
|
-
}
|
|
4002
|
-
getNamespace(locale, namespace) {
|
|
4003
|
-
const namespaceCacheKey = createNamespaceCacheKey(locale, namespace);
|
|
4004
|
-
const namespaceData = this.cache.get(namespaceCacheKey);
|
|
4005
|
-
if (!namespaceData) return null;
|
|
4006
|
-
try {
|
|
4007
|
-
return JSON.parse(namespaceData);
|
|
4008
|
-
} catch (error) {
|
|
4009
|
-
this.cache.delete(namespaceCacheKey);
|
|
4010
|
-
return null;
|
|
4011
|
-
}
|
|
4012
|
-
}
|
|
4013
|
-
setNamespace(locale, namespace, translations) {
|
|
4014
|
-
const namespaceCacheKey = createNamespaceCacheKey(locale, namespace);
|
|
4015
|
-
this.cache.set(namespaceCacheKey, JSON.stringify(translations));
|
|
4016
|
-
}
|
|
4017
|
-
evictOldest() {
|
|
4018
|
-
let oldestKey = "";
|
|
4019
|
-
let oldestTime = Date.now();
|
|
4020
|
-
for (const [key, time] of this.accessOrder.entries()) {
|
|
4021
|
-
if (time < oldestTime) {
|
|
4022
|
-
oldestTime = time;
|
|
4023
|
-
oldestKey = key;
|
|
4024
|
-
}
|
|
4025
|
-
}
|
|
4026
|
-
if (oldestKey) {
|
|
4027
|
-
this.cache.delete(oldestKey);
|
|
4028
|
-
this.accessOrder.delete(oldestKey);
|
|
4029
|
-
}
|
|
4030
|
-
}
|
|
4031
|
-
/**
|
|
4032
|
-
* Get all cache entries for debugging
|
|
4033
|
-
*/
|
|
4034
|
-
getEntries() {
|
|
4035
|
-
const entries = {};
|
|
4036
|
-
for (const [key, value] of this.cache.entries()) {
|
|
4037
|
-
entries[key] = value;
|
|
4038
|
-
}
|
|
4039
|
-
return entries;
|
|
4040
|
-
}
|
|
4041
|
-
getConfig() {
|
|
4042
|
-
return this.config;
|
|
4043
|
-
}
|
|
4044
|
-
};
|
|
4045
|
-
|
|
4046
4109
|
// src/browser/exclude-filter.ts
|
|
4047
4110
|
var DEFAULT_PATTERNS = {
|
|
4048
4111
|
emails: true,
|
|
@@ -5675,6 +5738,7 @@ var LionRapid = (() => {
|
|
|
5675
5738
|
const switcherShowNames = script.dataset.switcherShowNames === "true";
|
|
5676
5739
|
const switcherCustomCss = script.dataset.switcherCustomCss || void 0;
|
|
5677
5740
|
const editorCdnUrl = script.dataset.editorCdn || void 0;
|
|
5741
|
+
const offline = script.dataset.offline !== "false";
|
|
5678
5742
|
return {
|
|
5679
5743
|
apiKey,
|
|
5680
5744
|
baseUrl,
|
|
@@ -5689,7 +5753,8 @@ var LionRapid = (() => {
|
|
|
5689
5753
|
switcherShowFlags,
|
|
5690
5754
|
switcherShowNames,
|
|
5691
5755
|
switcherCustomCss,
|
|
5692
|
-
editorCdnUrl
|
|
5756
|
+
editorCdnUrl,
|
|
5757
|
+
offline
|
|
5693
5758
|
};
|
|
5694
5759
|
}
|
|
5695
5760
|
function readLocaleCookie(availableLanguages) {
|
|
@@ -5769,10 +5834,22 @@ var LionRapid = (() => {
|
|
|
5769
5834
|
renderSwitcher();
|
|
5770
5835
|
}
|
|
5771
5836
|
try {
|
|
5772
|
-
const
|
|
5837
|
+
const builder = LionRapidBuilder.init({
|
|
5773
5838
|
defaultLocale: initialLocale,
|
|
5774
5839
|
namespace: config.namespace
|
|
5775
|
-
}).use(new MemoryRepository({ enabled: true })).use(new LocalStorageRepository({ enabled: true })).use(new CacheStorageRepository({ enabled: true }))
|
|
5840
|
+
}).use(new MemoryRepository({ enabled: true })).use(new LocalStorageRepository({ enabled: true })).use(new CacheStorageRepository({ enabled: true }));
|
|
5841
|
+
if (config.offline !== false) {
|
|
5842
|
+
builder.use(
|
|
5843
|
+
new CacheStorageRepository({
|
|
5844
|
+
enabled: true,
|
|
5845
|
+
options: {
|
|
5846
|
+
ttl: Number.MAX_SAFE_INTEGER,
|
|
5847
|
+
cacheName: "lionrapid-offline-v1"
|
|
5848
|
+
}
|
|
5849
|
+
})
|
|
5850
|
+
);
|
|
5851
|
+
}
|
|
5852
|
+
const core = await builder.use(
|
|
5776
5853
|
new NetworkRepository({
|
|
5777
5854
|
enabled: true,
|
|
5778
5855
|
options: {
|