imba-localization 0.1.3 → 0.1.4

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.
Files changed (3) hide show
  1. package/index.imba +1 -0
  2. package/index.js +1 -1
  3. package/package.json +1 -1
package/index.imba CHANGED
@@ -17,6 +17,7 @@ export class Localization
17
17
  return new Proxy self, {
18
18
  get: do(target, p, receiver)
19
19
  return Reflect.get(target, p, receiver) if self[p]
20
+ return target.languages[p] if target.languages[p]
20
21
  return target.languages[active][p] if target.languages[active] and target.languages[active][p]
21
22
  return ''
22
23
  }
package/index.js CHANGED
@@ -1 +1 @@
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};
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"),g=Symbol.for("#beforeReconcile"),i=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[z])return n.languages[z];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,6 +1,6 @@
1
1
  {
2
2
  "name": "imba-localization",
3
- "version": "0.1.3",
3
+ "version": "0.1.4",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/HeapVoid/imba-localization.git"