imba-localization 0.1.2 → 0.1.3

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 CHANGED
@@ -48,6 +48,10 @@ const loc = new Localization("ADDRESS_TO_JSON", "en")
48
48
  loc.onready = do
49
49
  console.log loc['hello'] # Output: "Hello" (or translated value)
50
50
  console.log loc['goodbye'] # Output: "Goodbye" (or translated value)
51
+ # or
52
+ console.log loc.hello
53
+ # or
54
+ console.log loc..hello
51
55
 
52
56
  loc.onerror = do(msg, err)
53
57
  console.error "Localization load error:", msg, err
package/index.imba CHANGED
@@ -1,4 +1,4 @@
1
- export default class Localization
1
+ export class Localization
2
2
  onready
3
3
  onerror
4
4
  onchange
@@ -35,15 +35,15 @@ export default class Localization
35
35
  else
36
36
  console.log('There is no Localization for the default language', default)
37
37
  return
38
- #active = languages[preferred] ? preferred : default
38
+ active = preferred
39
39
  onready! if onready isa Function
40
40
 
41
41
  get active
42
42
  return languages[#active] ? #active : default
43
43
 
44
44
  set active name
45
- if languages[name]
45
+ if name and languages[name]
46
46
  #active = name
47
- onchange(name) if onchange isa Function
48
47
  else
49
- console.log('Localization for the language not found', name)
48
+ #active = languages[preferred] ? preferred : default
49
+ onchange(#active) if onchange isa Function
package/index.js CHANGED
@@ -1 +1 @@
1
- var S=Symbol.for("#__init__"),H=Symbol.for("#__initor__"),X=Symbol.for("#__inited__"),G=Symbol.for("#__hooks__"),O=Symbol.for("#__patch__"),K=Symbol.for("#has"),Y=Symbol.for("#meta"),Z=Symbol.for("imba"),M=Symbol.for("#__mixin__"),c=Symbol.for("#matcher"),C=Symbol.for("#L"),j=Symbol.for("#appendChild"),d=Symbol.for("#afterVisit"),g=Symbol.for("#beforeReconcile"),i=Symbol.for("#afterReconcile"),y=Symbol.for("##up");var F={IsExtension:1,IsTag:2,HasDescriptors:4,HasSuperCalls:8,HasConstructor:16,HasFields:32,HasMixins:64,HasInitor:128,HasDecorators:256,IsObjectExtension:512},T=new Map,A=globalThis[Z]||={counter:0,classes:T};function B(h,n={}){return T.has(h)||T.set(h,{symbol:Symbol(h.name),parent:Object.getPrototypeOf(h.prototype)?.constructor,for:h,uses:null,inits:null,id:A.counter++,...n}),T.get(h)}function E(h,n){return typeof n==="string"?typeof h===n:n?.[Symbol.hasInstance]?.(h)}function D(h,n){if(!h||!n)return!1;if(h.get)return n.get===h.get;if(h.set)return n.set===h.set;if(h.value)return h.value===n.value}function I(h,n,f,u={}){let z=h.constructor;if(!f&&n){if(f=Object.getOwnPropertyDescriptors(n),delete f.constructor,f[S])console.warn(`Cannot define plain fields when extending class ${z.name}`),delete f[S]}let r=B(z);if(r&&r.augments){let L=new Map;for(let o of Object.keys(f)){let v=Object.getOwnPropertyDescriptor(h,o);for(let w of r.augments){let R=L.get(w);R||L.set(w,R={});let q=Object.getOwnPropertyDescriptor(w.prototype,o);if(q&&!D(v,q))console.warn("wont extend",o,q,v);else R[o]=f[o]}}for(let[o,v]of L)if(Object.keys(v).length)I(o.prototype,null,v)}return Object.defineProperties(h,f),h}function J(h,n){let f=B(h),u=B(n);if(u.parent){if(!(h.prototype instanceof u.parent))throw new Error(`Mixin ${n.name} has superclass not present in target class`)}if(!u.augments){u.augments=new Set;let r=u.ref=Symbol(n.name),L=Object[Symbol.hasInstance];n.prototype[r]=!0,Object.defineProperty(n,Symbol.hasInstance,{value:function(o){return this===n?o&&!!o[r]:L.call(this,o)}})}if(h.prototype[u.ref])return h;if(u.uses)for(let r of u.uses)J(h,r);u.augments.add(h),f.uses||=[],f.uses.push(n);let z=Object.getOwnPropertyDescriptors(n.prototype);if(delete z.constructor,z[S])f.inits||=[],f.inits.push(n.prototype[S]),delete z[S];if(Object.defineProperties(h.prototype,z),n?.mixed instanceof Function)n.mixed(h);return h}var P={cache:{},self:null,target:null,proxy:new Proxy({},{apply:(h,n,...f)=>{return P.target[n].apply(P.self,f)},get:(h,n)=>{return Reflect.get(P.target,n,P.self)},set:(h,n,f,u)=>{return Reflect.set(P.target,n,f,P.self)}})};function N(h,n,f,u,z=null){let r=Object.getPrototypeOf(h.prototype),L=u&F.HasMixins,o;if(L)T.set(h,T.get(r.constructor)),r=Object.getPrototypeOf(r);if(z){let w=u&F.IsObjectExtension?z:z.prototype,R=B(h);if(R.uses){if(z===w)console.warn("Cannot extend object with mixins");for(let q of R.uses)J(z,q)}if(u&F.HasSuperCalls)P.cache[n]=Object.create(Object.getPrototypeOf(w),Object.getOwnPropertyDescriptors(w));return I(w,h.prototype),z}let v=r?.constructor;if(o=B(h,{symbol:n}),Object.defineProperty(h,Y,{value:o,enumerable:!1,configurable:!0}),f&&h.name!==f)Object.defineProperty(h,"name",{value:f,configurable:!0});if(o.flags=u,u&F.HasConstructor)h.prototype[H]=n;if(o.uses)for(let w of o.uses)w.mixes?.(h);if(v?.inherited instanceof Function)v.inherited(h);return h}function Q(h,n){if(h[H]===n)h[X]?.(),h[G]&&h[G].inited(h)}var U=Symbol.for("#active"),V=Symbol();class W{[S](h=null,n=!0,f=!0){var u;this.onready=h?h.onready:void 0,this.onerror=h?h.onerror:void 0,this.onchange=h?h.onchange:void 0,this.languages=h&&(u=h.languages)!==void 0?u:{},this.preferred=h&&(u=h.preferred)!==void 0?u:(window?.navigator?.language||"en-US").slice(0,2),this[U]=h?h[U]:void 0,this.default=h?h.default:void 0}constructor(h,n="en"){var f=this;return this[S](),this.default=n,window.fetch(h).then(function(u){return u.json()}).then(function(u){return f._finalize(u,void 0)}).catch(function(u){return f._finalize(void 0,u)}),new Proxy(this,{get:function(u,z,r){if(f[z])return Reflect.get(u,z,r);if(u.languages[f.active]&&u.languages[f.active][z])return u.languages[f.active][z];return""}});Q(this,V)}_finalize(h,n){if(n){if(E(this.onerror,Function))this.onerror("no_localization_file",n);else console.log("Localization file was not loaded",n);return}if(h)this.languages=h;if(!this.languages[this.default]){if(E(this.onerror,Function))this.onerror("no_default_localization");else console.log("There is no Localization for the default language",this.default);return}if(this[U]=this.languages[this.preferred]?this.preferred:this.default,E(this.onready,Function))return this.onready()}get active(){return this.languages[this[U]]?this[U]:this.default}set active(h){if(this.languages[h]){if(this[U]=h,E(this.onchange,Function))this.onchange(h)}else console.log("Localization for the language not found",h)}static{N(this,V,"Localization",16)}}export{W as default};
1
+ var P=Symbol.for("#__init__"),J=Symbol.for("#__initor__"),X=Symbol.for("#__inited__"),I=Symbol.for("#__hooks__"),o=Symbol.for("#__patch__"),K=Symbol.for("#has"),Y=Symbol.for("#meta"),Z=Symbol.for("imba"),M=Symbol.for("#__mixin__"),C=Symbol.for("#matcher"),c=Symbol.for("#L"),j=Symbol.for("#appendChild"),d=Symbol.for("#afterVisit"),i=Symbol.for("#beforeReconcile"),g=Symbol.for("#afterReconcile"),y=Symbol.for("##up");var H={IsExtension:1,IsTag:2,HasDescriptors:4,HasSuperCalls:8,HasConstructor:16,HasFields:32,HasMixins:64,HasInitor:128,HasDecorators:256,IsObjectExtension:512},B=new Map,A=globalThis[Z]||={counter:0,classes:B};function F(h,u={}){return B.has(h)||B.set(h,{symbol:Symbol(h.name),parent:Object.getPrototypeOf(h.prototype)?.constructor,for:h,uses:null,inits:null,id:A.counter++,...u}),B.get(h)}function G(h,u){return typeof u==="string"?typeof h===u:u?.[Symbol.hasInstance]?.(h)}function D(h,u){if(!h||!u)return!1;if(h.get)return u.get===h.get;if(h.set)return u.set===h.set;if(h.value)return h.value===u.value}function L(h,u,f,n={}){let z=h.constructor;if(!f&&u){if(f=Object.getOwnPropertyDescriptors(u),delete f.constructor,f[P])console.warn(`Cannot define plain fields when extending class ${z.name}`),delete f[P]}let v=F(z);if(v&&v.augments){let R=new Map;for(let r of Object.keys(f)){let S=Object.getOwnPropertyDescriptor(h,r);for(let w of v.augments){let q=R.get(w);q||R.set(w,q={});let E=Object.getOwnPropertyDescriptor(w.prototype,r);if(E&&!D(S,E))console.warn("wont extend",r,E,S);else q[r]=f[r]}}for(let[r,S]of R)if(Object.keys(S).length)L(r.prototype,null,S)}return Object.defineProperties(h,f),h}function N(h,u){let f=F(h),n=F(u);if(n.parent){if(!(h.prototype instanceof n.parent))throw new Error(`Mixin ${u.name} has superclass not present in target class`)}if(!n.augments){n.augments=new Set;let v=n.ref=Symbol(u.name),R=Object[Symbol.hasInstance];u.prototype[v]=!0,Object.defineProperty(u,Symbol.hasInstance,{value:function(r){return this===u?r&&!!r[v]:R.call(this,r)}})}if(h.prototype[n.ref])return h;if(n.uses)for(let v of n.uses)N(h,v);n.augments.add(h),f.uses||=[],f.uses.push(u);let z=Object.getOwnPropertyDescriptors(u.prototype);if(delete z.constructor,z[P])f.inits||=[],f.inits.push(u.prototype[P]),delete z[P];if(Object.defineProperties(h.prototype,z),u?.mixed instanceof Function)u.mixed(h);return h}var T={cache:{},self:null,target:null,proxy:new Proxy({},{apply:(h,u,...f)=>{return T.target[u].apply(T.self,f)},get:(h,u)=>{return Reflect.get(T.target,u,T.self)},set:(h,u,f,n)=>{return Reflect.set(T.target,u,f,T.self)}})};function Q(h,u,f,n,z=null){let v=Object.getPrototypeOf(h.prototype),R=n&H.HasMixins,r;if(R)B.set(h,B.get(v.constructor)),v=Object.getPrototypeOf(v);if(z){let w=n&H.IsObjectExtension?z:z.prototype,q=F(h);if(q.uses){if(z===w)console.warn("Cannot extend object with mixins");for(let E of q.uses)N(z,E)}if(n&H.HasSuperCalls)T.cache[u]=Object.create(Object.getPrototypeOf(w),Object.getOwnPropertyDescriptors(w));return L(w,h.prototype),z}let S=v?.constructor;if(r=F(h,{symbol:u}),Object.defineProperty(h,Y,{value:r,enumerable:!1,configurable:!0}),f&&h.name!==f)Object.defineProperty(h,"name",{value:f,configurable:!0});if(r.flags=n,n&H.HasConstructor)h.prototype[J]=u;if(r.uses)for(let w of r.uses)w.mixes?.(h);if(S?.inherited instanceof Function)S.inherited(h);return h}function V(h,u){if(h[J]===u)h[X]?.(),h[I]&&h[I].inited(h)}var U=Symbol.for("#active"),W=Symbol();class O{[P](h=null,u=!0,f=!0){var n;this.onready=h?h.onready:void 0,this.onerror=h?h.onerror:void 0,this.onchange=h?h.onchange:void 0,this.languages=h&&(n=h.languages)!==void 0?n:{},this.preferred=h&&(n=h.preferred)!==void 0?n:(window?.navigator?.language||"en-US").slice(0,2),this[U]=h?h[U]:void 0,this.default=h?h.default:void 0}constructor(h,u="en"){var f=this;return this[P](),this.default=u,window.fetch(h).then(function(n){return n.json()}).then(function(n){return f._finalize(n,void 0)}).catch(function(n){return f._finalize(void 0,n)}),new Proxy(this,{get:function(n,z,v){if(f[z])return Reflect.get(n,z,v);if(n.languages[f.active]&&n.languages[f.active][z])return n.languages[f.active][z];return""}});V(this,W)}_finalize(h,u){if(u){if(G(this.onerror,Function))this.onerror("no_localization_file",u);else console.log("Localization file was not loaded",u);return}if(h)this.languages=h;if(!this.languages[this.default]){if(G(this.onerror,Function))this.onerror("no_default_localization");else console.log("There is no Localization for the default language",this.default);return}if(this.active=this.preferred,G(this.onready,Function))return this.onready()}get active(){return this.languages[this[U]]?this[U]:this.default}set active(h){if(h&&this.languages[h])this[U]=h;else this[U]=this.languages[this.preferred]?this.preferred:this.default;if(G(this.onchange,Function))this.onchange(this[U])}static{Q(this,W,"Localization",16)}}export{O as Localization};
package/package.json CHANGED
@@ -1,13 +1,16 @@
1
1
  {
2
2
  "name": "imba-localization",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/HeapVoid/imba-localization.git"
7
7
  },
8
- "main": "./index.js",
8
+ "main": "index.js",
9
+ "module": "index.js",
10
+ "browser": "index.js",
9
11
  "devDependencies": {
10
- "imba": "latest"
12
+ "imba": "latest",
13
+ "bimba-cli": "latest"
11
14
  },
12
15
  "scripts": {
13
16
  "bundle": "bunx bimba index.imba --outdir . --minify",
@@ -17,9 +20,6 @@
17
20
  "keywords": ["imba", "theme", "localization"],
18
21
  "license": "MIT",
19
22
  "type": "module",
20
- "dependencies": {
21
- "bimba-cli": "^0.3.2"
22
- },
23
23
  "files": [
24
24
  "index.imba",
25
25
  "index.js"