@moneko/core 3.1.4 → 3.1.5

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/lib/locales.js CHANGED
@@ -1,3 +1,3 @@
1
- import{existsSync as e}from"fs";import{basename as t,join as o}from"path";import{watch as a}from"chokidar";import{CONFIG as l}from"./config.js";import r from"./esm.js";import{FRAMEWORK as s,isLibrary as n}from"./process-env.js";import c from"./reactive-object.js";import{resolveProgramPath as i,tfc as g}from"./utils.js";let p={react:'import sso from "shared-store-object";',solid:'import { createEffect, createRoot, getOwner } from "solid-js";import { createStore } from "solid-js/store";'},f={react:'let storageKey="localizable.language",language=localStorage.getItem(storageKey)||"zh_CN",{translation:a,...defaultLocale}=Object.assign({title:"简体中文",language:"zh_CN",translation:{}},resources[language]||resources.zh_CN),localizable=sso({lang:defaultLocale,t:a});export function setLang(a){let{translation:e,...l}=resources[a]||{};e&&(localizable.lang=l,localizable.t=e,localStorage.setItem(storageKey,l.language))}export default localizable;',solid:'let locale=createRoot(()=>{let e="localizable.language",a=localStorage.getItem(e)||"zh_CN",{translation:l,...o}=Object.assign({title:"简体中文",language:"zh_CN",translation:{}},resources[a]||resources.zh_CN),[n,c]=createStore({lang:o,t:l});return createEffect(()=>{let a=resources[n.lang.language]?.translation;a&&(c("t",a),localStorage.setItem(e,n.lang.language))}),{localizable:n,setLocalizable:c,setLang:function(e){let{translation:a,...l}=resources[e]||{};a&&c("lang",l)}}},getOwner());export const setLocalizable=locale.setLocalizable;export const t=locale.localizable.t;export const lang=locale.localizable.lang;export const setLang=locale.setLang;'}[s];export const localesModuleName="@app/locales";export const locales=new c({[localesModuleName]:"export const locales = [];"});let u={};// 要执行的函数
2
- async function d(e,o){let a=t(e).replace(/\.[^.]+$/,"");if("deleted"===o)delete u[a];else{let t=await import(r`${g(e)}`);Object.assign(u,{[a]:t.default})}let l=[],n={};for(let e in u)if(Object.prototype.hasOwnProperty.call(u,e)){let t=u[e],{language:o=a,title:r=o,icon:s,translation:c={}}=t;l.push({language:o,title:r,icon:s}),n[o]={language:o,title:r,icon:s,translation:c}}locales.setData(localesModuleName,`${p[s]}
3
- export function interpolateString(r,n){return r.replace(/\\\${\\w+}/g,function(r){var t=r.slice(2,-1);var e=n[t];return e!==void 0?e.toString():""})}function deepFreeze(o) { const p = Reflect.ownKeys(o);for (const k of p) {const v = o[k];if ((v && typeof v === "object") || typeof v === "function") {deepFreeze(v);}}return Object.freeze(o);}export const locales = ${JSON.stringify(l)};const _res = ${JSON.stringify(n)};const resources = deepFreeze(_res);${f}`)}e(o(l.alias["@"],"./locales"))&&function(e,t){let o=[],l=a(e,{ignored:t,persistent:!0,ignoreInitial:!1});l.on("add",e=>{d(e,"added"),o.push(e)}),l.on("change",e=>{d(e,"change")}),l.on("unlink",e=>{d(e,"deleted"),o.splice(o.indexOf(e),1)}),l.on("ready",()=>{o.forEach(e=>{d(e,"change")})}),process.on("SIGINT",function(){l.close()})}(i(n?"site/locales":"src/locales"),[/^\..*/,/!\.ts$/,/\.d\.ts$/]);
1
+ import{existsSync as e}from"fs";import{basename as t,join as o}from"path";import{watch as a}from"chokidar";import{CONFIG as l}from"./config.js";import r from"./esm.js";import{FRAMEWORK as n,isLibrary as s}from"./process-env.js";import c from"./reactive-object.js";import{resolveProgramPath as i,tfc as g}from"./utils.js";let f={react:'import sso from "shared-store-object";',solid:'import { createEffect, createRoot, getOwner } from "solid-js";import { createStore } from "solid-js/store";'},p={react:'let storageKey="localizable.language",language=localStorage.getItem(storageKey)||"zh_CN",{translation:a,...defaultLocale}=Object.assign({title:"简体中文",language:"zh_CN",translation:{}},resources[language]||resources.zh_CN),localizable=sso({lang:defaultLocale,t:a});export function setLang(a){let{translation:e,...l}=resources[a]||{};e&&(localizable.lang=l,localizable.t=e,localStorage.setItem(storageKey,l.language))}export default localizable;',solid:'let locale=createRoot(()=>{let e="localizable.language",a=localStorage.getItem(e)||"zh_CN",{translation:l,...o}=Object.assign({title:"简体中文",language:"zh_CN",translation:{}},resources[a]||resources.zh_CN),[n,c]=createStore({lang:o,t:l});return createEffect(()=>{let a=resources[n.lang.language]?.translation;a&&(c("t",a),localStorage.setItem(e,n.lang.language))}),{localizable:n,setLocalizable:c,setLang:function(e){let{translation:a,...l}=resources[e]||{};a&&c("lang",l)}}},getOwner());export const setLocalizable=locale.setLocalizable;export const t=locale.localizable.t;export const lang=locale.localizable.lang;export const setLang=locale.setLang;'}[n];function u(e,t){return`${f[n]}
2
+ export function interpolateString(r,n){return r.replace(/\\\${\\w+}/g,function(r){var t=r.slice(2,-1);var e=n[t];return e!==void 0?e.toString():""})}function deepFreeze(o) { const p = Reflect.ownKeys(o);for (const k of p) {const v = o[k];if ((v && typeof v === "object") || typeof v === "function") {deepFreeze(v);}}return Object.freeze(o);}export const locales = ${JSON.stringify(e)};const _res = ${JSON.stringify(t)};const resources = deepFreeze(_res);${p}`}export const localesModuleName="@app/locales";export const locales=new c({[localesModuleName]:u([],{})});let d={};// 要执行的函数
3
+ async function m(e,o){let a=t(e).replace(/\.[^.]+$/,"");if("deleted"===o)delete d[a];else{let t=await import(r`${g(e)}`);Object.assign(d,{[a]:t.default})}let l=[],n={};for(let e in d)if(Object.prototype.hasOwnProperty.call(d,e)){let t=d[e],{language:o=a,title:r=o,icon:s,translation:c={}}=t;l.push({language:o,title:r,icon:s}),n[o]={language:o,title:r,icon:s,translation:c}}locales.setData(localesModuleName,u(l,n))}e(o(l.alias["@"],"./locales"))&&function(e,t){let o=[],l=a(e,{ignored:t,persistent:!0,ignoreInitial:!1});l.on("add",e=>{m(e,"added"),o.push(e)}),l.on("change",e=>{m(e,"change")}),l.on("unlink",e=>{m(e,"deleted"),o.splice(o.indexOf(e),1)}),l.on("ready",()=>{o.forEach(e=>{m(e,"change")})}),process.on("SIGINT",function(){l.close()})}(i(s?"site/locales":"src/locales"),[/^\..*/,/!\.ts$/,/\.d\.ts$/]);
@@ -1 +1 @@
1
- import o from"webpack-virtual-modules";import{docs as t}from"./docs.js";import{locales as e,localesModuleName as s}from"./locales.js";import{isLibrary as p}from"./process-env.js";import{exampleModuleName as r,examples as i,route as a,routesModuleName as l}from"./routes.js";import{resolveNodeModulesPath as n}from"./utils.js";export default class{constructor(o){this.options=o,this.hasTapped=!1}apply(f){let c=new o({[n(l)]:"export default []",[n(r)]:"export default []",[n(s)]:"export const locales = [];"});function h(o,t){c.writeModule(n(o),t||"")}c.apply(f),a.on("change",h),e.on("change",h),p&&(i.on("change",h),t.on("change",h)),f.hooks.compilation.tap("VirtualModulePlugin",()=>{if(!this.hasTapped){for(let o in this.options)if(Object.prototype.hasOwnProperty.call(this.options,o)){let t=this.options[o];h(o,"string"==typeof t?t:`export default ${JSON.stringify(t)}`)}for(let o of i)h(...o);for(let o of t)h(...o);this.hasTapped=!0}})}}
1
+ import o from"webpack-virtual-modules";import{docs as t}from"./docs.js";import{locales as e,localesModuleName as s}from"./locales.js";import{isLibrary as i}from"./process-env.js";import{exampleModuleName as p,examples as r,route as a,routesModuleName as l}from"./routes.js";import{resolveNodeModulesPath as n}from"./utils.js";export default class{constructor(o){this.options=o,this.hasTapped=!1}apply(f){let h=new o({[n(l)]:a.getData(l),[n(p)]:"export default []",[n(s)]:e.getData(s)});function c(o,t){h.writeModule(n(o),t||"")}h.apply(f),a.on("change",c),e.on("change",c),i&&(r.on("change",c),t.on("change",c)),f.hooks.compilation.tap("VirtualModulePlugin",()=>{if(!this.hasTapped){for(let o in this.options)if(Object.prototype.hasOwnProperty.call(this.options,o)){let t=this.options[o];c(o,"string"==typeof t?t:`export default ${JSON.stringify(t)}`)}for(let o of r)c(...o);for(let o of t)c(...o);this.hasTapped=!0}})}}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@moneko/core",
3
- "version": "3.1.4",
3
+ "version": "3.1.5",
4
4
  "description": "core",
5
5
  "main": "lib/index.js",
6
6
  "type": "module",