@nerimity/solid-i18lite 1.5.1 → 1.5.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.
@@ -1,6 +1,6 @@
1
1
  import { createComponent as f, memo as d } from "solid-js/web";
2
2
  import { useContext as m, createContext as y, createSignal as x, children as C } from "solid-js";
3
- import T from "./i18lite-browser.mjs";
3
+ import T from "./i18lite.mjs";
4
4
  const g = y();
5
5
  function w(t, r) {
6
6
  const [n, e] = x(r.resources ? t.t : () => null);
package/package.json CHANGED
@@ -20,27 +20,33 @@
20
20
  "exports": {
21
21
  ".": {
22
22
  "types": "./dist/types/index.d.ts",
23
- "browser": {
24
- "default": "./dist/index-browser.mjs"
25
- },
26
- "import": "./dist/index-ssr.mjs",
27
- "require": "./dist/index-ssr.js"
23
+ "default": "./dist/index.mjs",
24
+ "import": "./dist/index.mjs",
25
+ "require": "./dist/index.mjs"
28
26
  },
29
27
  "./index": {
30
28
  "types": "./dist/types/index.d.ts",
31
- "browser": {
32
- "default": "./dist/index-browser.mjs"
33
- },
34
- "import": "./dist/index-ssr.mjs",
35
- "require": "./dist/index-ssr.js"
29
+ "default": "./dist/index.mjs",
30
+ "import": "./dist/index.mjs",
31
+ "require": "./dist/index.mjs"
36
32
  },
37
33
  "./i18lite": {
38
- "types": "./dist/types/i18lite.d.ts",
39
- "browser": {
40
- "default": "./dist/i18lite-browser.mjs"
41
- },
42
- "import": "./dist/i18lite-ssr.mjs",
43
- "require": "./dist/i18lite-ssr.js"
34
+ "types": "./dist/types/index.d.ts",
35
+ "default": "./dist/i18lite.mjs",
36
+ "import": "./dist/i18lite.mjs",
37
+ "require": "./dist/i18lite.mjs"
38
+ },
39
+ "./i18lite.mjs": {
40
+ "types": "./dist/types/index.d.ts",
41
+ "default": "./dist/i18lite.mjs",
42
+ "import": "./dist/i18lite.mjs",
43
+ "require": "./dist/i18lite.mjs"
44
+ },
45
+ "./index.mjs": {
46
+ "types": "./dist/types/index.d.ts",
47
+ "default": "./dist/index.mjs",
48
+ "import": "./dist/index.mjs",
49
+ "require": "./dist/index.mjs"
44
50
  }
45
51
  },
46
52
  "files": [
@@ -77,7 +83,6 @@
77
83
  "scripts": {
78
84
  "build:browser": "vite build --config vite.browser.config.js",
79
85
  "build:docs": "vite build --config vite.docs.config.js",
80
- "build:ssr": "vite build --config vite.ssr.config.js",
81
86
  "build:types": "tsc --project tsconfig.types.json",
82
87
  "docs": "vite --config vite.docs.config.js",
83
88
  "test": "jest --coverage",
@@ -86,5 +91,5 @@
86
91
  "sideEffects": false,
87
92
  "type": "module",
88
93
  "types": "./dist/types/index.d.ts",
89
- "version": "1.5.1"
94
+ "version": "1.5.2"
90
95
  }
@@ -1 +0,0 @@
1
- "use strict";let h={},S="translation",d="";const A={resources:{},interpolation:{prefix:"{{",suffix:"}}"}};let c=A;const R=e=>e.replace(/[-|\\{}()[\]^$+*?.]/g,t=>t==="-"?"\\x2d":`\\${t}`),v=new Map,$=(e,t)=>{if(!e)return"";const o=c?.interpolation,s=o?.prefix??"{{",a=o?.suffix??"}}",i=s+"|"+a;let r=v.get(i);if(!r){const f=R(s),u=R(a);r=new RegExp(`${f}\\s*(\\w+)\\s*${u}`,"g"),v.set(i,r)}return e.replace(r,(f,u)=>Object.prototype.hasOwnProperty.call(t,u)?t[u]:f)},g=(e,t,o)=>{let s=j(n.language,S,e)??(typeof t=="string"?t:e);return o||typeof t=="object"&&t!==null?$(s,o||t):s},P=(e,t)=>{h[e]=t},L=(e,t)=>{c=A,e&&(c={...e,interpolation:e?.interpolation||{}},c.interpolation.prefix=e.interpolation?.prefix||"{{",c.interpolation.suffix=e.interpolation?.suffix||"}}"),d=e?.lng||"",n.store={data:c.resources||{}},c.resources={},t?.(null,g)},M=e=>(d=e,Promise.resolve(g)),b=(e,t,o=!0)=>{const s=e;for(const a in t){const i=s[a],r=t[a];r&&typeof r=="object"&&!Array.isArray(r)?((typeof i!="object"||Array.isArray(i))&&(s[a]={}),b(s[a],r,o)):(o||i===void 0)&&(s[a]=r)}return e},V=(e,t,o,s=!0,a=!0)=>{n.store=n.store||{data:{}},n.store.data=n.store.data||{},n.store.data[e]=n.store.data[e]||{},n.store.data[e][t]=n.store.data[e][t]||{};const i=n.store.data[e][t],r=o;return s?b(i,r,a):n.store.data[e][t]=a?r:{...r,...i},(h.loaded||(()=>{}))(e,t),n},j=(e,t,o,s)=>{const a=n.store;if(!a)return;const i=a.data?.[e];if(!i)return;const r=i[t];if(!r||typeof r=="string")return;const f=s?.keySeparator??n.options?.keySeparator??".";if(f===!1)return r[o];const u=String(f);if(o.indexOf(u)===-1)return r[o];let p=r,x=0;for(let l=0;l<=o.length;l++)if(l===o.length||o[l]===u){const y=o.slice(x,l);if(p==null||!(y in p))return;p=p[y],x=l+1}return p},B=()=>n,n={get language(){return d},createInstance:B,t:g,on:P,init:L,changeLanguage:M,addResourceBundle:V,options:c,getResource:j};module.exports=n;
@@ -1,66 +0,0 @@
1
- let h = {}, S = "translation", d = "";
2
- const A = { resources: {}, interpolation: { prefix: "{{", suffix: "}}" } };
3
- let c = A;
4
- const R = (e) => e.replace(/[-|\\{}()[\]^$+*?.]/g, (t) => t === "-" ? "\\x2d" : `\\${t}`), v = /* @__PURE__ */ new Map(), $ = (e, t) => {
5
- if (!e) return "";
6
- const o = c?.interpolation, s = o?.prefix ?? "{{", a = o?.suffix ?? "}}", i = s + "|" + a;
7
- let r = v.get(i);
8
- if (!r) {
9
- const f = R(s), u = R(a);
10
- r = new RegExp(`${f}\\s*(\\w+)\\s*${u}`, "g"), v.set(i, r);
11
- }
12
- return e.replace(r, (f, u) => Object.prototype.hasOwnProperty.call(t, u) ? t[u] : f);
13
- }, g = (e, t, o) => {
14
- let s = j(n.language, S, e) ?? (typeof t == "string" ? t : e);
15
- return o || typeof t == "object" && t !== null ? $(s, o || t) : s;
16
- }, P = (e, t) => {
17
- h[e] = t;
18
- }, L = (e, t) => {
19
- c = A, e && (c = { ...e, interpolation: e?.interpolation || {} }, c.interpolation.prefix = e.interpolation?.prefix || "{{", c.interpolation.suffix = e.interpolation?.suffix || "}}"), d = e?.lng || "", n.store = { data: c.resources || {} }, c.resources = {}, t?.(null, g);
20
- }, M = (e) => (d = e, Promise.resolve(g)), b = (e, t, o = !0) => {
21
- const s = e;
22
- for (const a in t) {
23
- const i = s[a], r = t[a];
24
- r && typeof r == "object" && !Array.isArray(r) ? ((typeof i != "object" || Array.isArray(i)) && (s[a] = {}), b(s[a], r, o)) : (o || i === void 0) && (s[a] = r);
25
- }
26
- return e;
27
- }, V = (e, t, o, s = !0, a = !0) => {
28
- n.store = n.store || { data: {} }, n.store.data = n.store.data || {}, n.store.data[e] = n.store.data[e] || {}, n.store.data[e][t] = n.store.data[e][t] || {};
29
- const i = n.store.data[e][t], r = o;
30
- return s ? b(i, r, a) : n.store.data[e][t] = a ? r : { ...r, ...i }, (h.loaded || (() => {
31
- }))(e, t), n;
32
- }, j = (e, t, o, s) => {
33
- const a = n.store;
34
- if (!a) return;
35
- const i = a.data?.[e];
36
- if (!i) return;
37
- const r = i[t];
38
- if (!r || typeof r == "string") return;
39
- const f = s?.keySeparator ?? n.options?.keySeparator ?? ".";
40
- if (f === !1) return r[o];
41
- const u = String(f);
42
- if (o.indexOf(u) === -1) return r[o];
43
- let p = r, x = 0;
44
- for (let l = 0; l <= o.length; l++)
45
- if (l === o.length || o[l] === u) {
46
- const y = o.slice(x, l);
47
- if (p == null || !(y in p)) return;
48
- p = p[y], x = l + 1;
49
- }
50
- return p;
51
- }, B = () => n, n = {
52
- get language() {
53
- return d;
54
- },
55
- createInstance: B,
56
- t: g,
57
- on: P,
58
- init: L,
59
- changeLanguage: M,
60
- addResourceBundle: V,
61
- options: c,
62
- getResource: j
63
- };
64
- export {
65
- n as default
66
- };
package/dist/index-ssr.js DELETED
@@ -1 +0,0 @@
1
- "use strict";var T=Object.create;var g=Object.defineProperty;var C=Object.getOwnPropertyDescriptor;var x=Object.getOwnPropertyNames;var w=Object.getPrototypeOf,m=Object.prototype.hasOwnProperty;var S=(t,e,n,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of x(e))!m.call(t,o)&&o!==n&&g(t,o,{get:()=>e[o],enumerable:!(r=C(e,o))||r.enumerable});return t};var b=(t,e,n)=>(n=t!=null?T(w(t)):{},S(e||!t||!t.__esModule?g(n,"default",{value:t,enumerable:!0}):n,t));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("solid-js"),v=require("solid-js/web"),I=require("./i18lite-ssr.js"),h=i.createContext();function P(t,e){const[n,r]=i.createSignal(e.resources?t.t:()=>null);t.on("loaded",()=>r(()=>t.t)),t.init(e,(s,a)=>r(()=>a));async function o(s){const a=await t.changeLanguage(s);r(()=>a)}function c(s,a,y,d={}){return t.addResourceBundle(s,a,y,d.deep,d.overwrite)}return[((...s)=>n().apply(null,s)),{addResources:c,getI18next:()=>t,changeLanguage:o}]}const f=()=>i.useContext(h),k=t=>v.createComponent(h.Provider,{get value(){return P(t.instance||I,{lng:t.lng,...t.options})},get children(){return t.children}}),l=(t,{prefix:e,suffix:n})=>t.includes(e)&&t.includes(n),q=(t,{interpolation:e})=>(n,r)=>typeof n=="string"?l(n,e)?t.children[r].children?.[0].content:t.children[r].content:(n.textContent=t.children[r].children?.[0].content,n),J=!globalThis.window,L=(t,e,n)=>r=>{const o=typeof r;if(o==="string"&&l(r,e.interpolation))return t(r,n.options);if(o==="object"){const c=r.textContent??r.t;c&&l(c,e.interpolation)&&(r[J?"t":"textContent"]=t(c,n.options))}return r};let u;(async()=>{try{u=(await import("html-parse-string")).parse}catch{}})();const j=()=>{console.error("In order to use JSX nesting, install %chtml-parse-string","font-weight: 700","https://github.com/ryansolid/html-parse-string.")},E=({i18n:{options:t},t:e,props:n},r)=>{const o=e(n.key,n.options);if(!n.children)return o;if(o===n.key)return r.map(L(e,t,n));if(!u){j();return}try{const[c]=u(`<0>${o}</0>`);return r.map(q(c,t))}catch(c){console.error(c)}},M=t=>{const[e,{getI18next:n}]=f();return typeof t.children=="string"?e(t.key,t.children,t.options):E({i18n:n(),t:e,props:t},i.children(()=>t.children)())};exports.Trans=M;exports.TransProvider=k;exports.useTransContext=f;
@@ -1,81 +0,0 @@
1
- import { useContext as h, createContext as f, createSignal as y, children as m } from "solid-js";
2
- import { createComponent as x } from "solid-js/web";
3
- import C from "./i18lite-ssr.mjs";
4
- const d = f();
5
- function T(t, r) {
6
- const [n, e] = y(r.resources ? t.t : () => null);
7
- t.on("loaded", () => e(() => t.t)), t.init(r, (a, i) => e(() => i));
8
- async function c(a) {
9
- const i = await t.changeLanguage(a);
10
- e(() => i);
11
- }
12
- function o(a, i, g, u = {}) {
13
- return t.addResourceBundle(a, i, g, u.deep, u.overwrite);
14
- }
15
- return [((...a) => n().apply(null, a)), {
16
- addResources: o,
17
- getI18next: () => t,
18
- changeLanguage: c
19
- }];
20
- }
21
- const w = () => h(d), J = (t) => x(d.Provider, {
22
- get value() {
23
- return T(t.instance || C, {
24
- lng: t.lng,
25
- ...t.options
26
- });
27
- },
28
- get children() {
29
- return t.children;
30
- }
31
- }), s = (t, { prefix: r, suffix: n }) => t.includes(r) && t.includes(n), I = (t, { interpolation: r }) => (n, e) => typeof n == "string" ? s(n, r) ? t.children[e].children?.[0].content : t.children[e].content : (n.textContent = t.children[e].children?.[0].content, n), S = !globalThis.window, k = (t, r, n) => (e) => {
32
- const c = typeof e;
33
- if (c === "string" && s(e, r.interpolation)) return t(e, n.options);
34
- if (c === "object") {
35
- const o = e.textContent ?? e.t;
36
- o && s(o, r.interpolation) && (e[S ? "t" : "textContent"] = t(o, n.options));
37
- }
38
- return e;
39
- };
40
- let l;
41
- (async () => {
42
- try {
43
- l = (await import("html-parse-string")).parse;
44
- } catch {
45
- }
46
- })();
47
- const v = () => {
48
- console.error(
49
- "In order to use JSX nesting, install %chtml-parse-string",
50
- "font-weight: 700",
51
- "https://github.com/ryansolid/html-parse-string."
52
- );
53
- }, L = ({ i18n: { options: t }, t: r, props: n }, e) => {
54
- const c = r(n.key, n.options);
55
- if (!n.children) return c;
56
- if (c === n.key) return e.map(k(r, t, n));
57
- if (!l) {
58
- v();
59
- return;
60
- }
61
- try {
62
- const [o] = l(`<0>${c}</0>`);
63
- return e.map(I(o, t));
64
- } catch (o) {
65
- console.error(o);
66
- }
67
- }, N = (t) => {
68
- const [r, {
69
- getI18next: n
70
- }] = w();
71
- return typeof t.children == "string" ? r(t.key, t.children, t.options) : L({
72
- i18n: n(),
73
- t: r,
74
- props: t
75
- }, m(() => t.children)());
76
- };
77
- export {
78
- N as Trans,
79
- J as TransProvider,
80
- w as useTransContext
81
- };
File without changes