Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

als-render

Package Overview
Dependencies
Maintainers
0
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

als-render - npm Package Compare versions

Comparing version 3.1.0 to 3.2.0

3

lib/browser.js

@@ -11,2 +11,3 @@ const RenderJsx = require('als-render-jsx')

context.isBrowser = true
context.lang = lang
Require.version = version

@@ -25,3 +26,3 @@ const plugins = jsx ? [mod => mod.content = RenderJsx.render(mod.content)] : []

scriptAfter: [
`const resultObj = new result(${JSON.stringify({ data, lang })})`,
`const resultObj = new result(${JSON.stringify(data)})`,
`${selector ? `resultObj.selector = '${selector}'` : ''}`,

@@ -28,0 +29,0 @@ `resultObj.update()`,

{
"name": "als-render",
"version": "3.1.0",
"version": "3.2.0",
"main": "index.js",

@@ -5,0 +5,0 @@ "scripts": {

@@ -494,4 +494,4 @@ const render = (function(){

merge(data = {}) {
const newLangInstance = new Lang(data,this.defaultLang)
merge(newLangInstance) {
if(newLangInstance instanceof Lang === false) newLangInstance = new Lang(newLangInstance,this.defaultLang)
for(const lang in this.langs) {

@@ -503,3 +503,2 @@ if(newLangInstance.langs[lang] === undefined) newLangInstance.langs[lang] = {}

}
}

@@ -600,2 +599,3 @@ class Component {

context.isBrowser = true
context.lang = lang
Require.version = version

@@ -614,3 +614,3 @@ const plugins = jsx ? [mod => mod.content = RenderJsx.render(mod.content)] : []

scriptAfter: [
`const resultObj = new result(${JSON.stringify({ data, lang })})`,
`const resultObj = new result(${JSON.stringify(data)})`,
`${selector ? `resultObj.selector = '${selector}'` : ''}`,

@@ -617,0 +617,0 @@ `resultObj.update()`,

@@ -13,5 +13,5 @@ const render = (function(){

let RenderJsx=(()=>{let c=["disabled","checked","readonly","required","hidden","autofocus","multiple","selected","controls","loop","muted","open","spellcheck","draggable","contenteditable","novalidate"];function i(e,t,r,l){let a="",h="",o=!0,u=!1,f,i=0;function n(e,i,n="attributes"){var s=r;if(i){let[e,t]=i;"async"===(e="className"===e?"class":e)?s.async=!0:c.includes(e)?(t&&(e=`\${${t} ? '${e}' : ''}`),s.attributes.push([e])):"props"===n&&e.startsWith("on")?s.buildAction([e,t]):s[n].push([e,t])}for(o=!0,u=!1,a="",h="",f=null;0===l[e].trim().length;)e++;return e}for(;">"!==e&&!(t>=l.length);){if(o)if("{"===e){for(;t<l.length&&"}"!==(e=l[++t]);)r.rest+=e;n(t)}else if("="===e||0===e.trim().length)0<a.length&&(" "===e&&"="!==l[t+1]?(r.attributes.push([a]),a=""):(o=!1,u=!0));else{if(">"===l[t+1]){"/"===e?r.selfClosed=!0:""!==a&&r.attributes.push([a+e]),t++;break}a+=e}else u&&(f?"{"===f?(h+=e,"{"===e?i++:"}"===e&&(0<i?i--:t=n(t,[a,h.slice(0,-1)],"props"))):"\\"!==l[t-1]&&e===f?t=n(t,[a,h]):h+=e:/["'`{]/.test(e)?f=e:/[a-zA-Z]/.test(e)&&(""!==a&&r.attributes.push([a]),o=!0,u=!1,a=e));">"===(e=l[++t])&&u&&(h+=e,e=l[++t])}return++t}class f{static render(e){return f.jsxParser((t=>{var i={'"':!0,"'":!0,"`":!0};let n="",s=null;for(let e=0;e<t.length;e++){var r=t[e];if(i[r]&&"\\"!==t[e-1])s=s===r&&"\\"!==t[e-1]?null:r,n+=t[e];else if(s||"/"!==r||"/"!==t[e+1])if(s||"{"!==r||"/"!==t[e+1]||"*"!==t[e+2])if(s||"/"!==r||"*"!==t[e+1])n+=t[e];else{for(;e<t.length&&("*"!==t[e]||"/"!==t[e+1]);)e++;e++}else{for(;e<t.length&&("*"!==t[e]||"/"!==t[e+1]||"}"!==t[e+2]);)e++;e+=2}else{for(;e<t.length&&"\n"!==t[e];)e++;"\n"===t[e]&&(n+=t[e])}}return n})(e))}static componentFn(e,t,i,n){return e+`(new ${t}(${i},\`${n}\`)).call()`}static buildAction([e,t]){e=e.split("on")[1].toLowerCase();return[e,t="$"+`{this.action('${e}',${t})}`]}static getOuter(h){{var o=f.componentFn;let{tagName:e,selfClosed:t,attributes:i,props:n,isComponent:s,rest:r,inner:l}=h,a="";if(s){var u=[...n,...i.map(([e,t])=>[e,'"'+t+'"'])].map(([e,t])=>e+":"+t),h=(r&&u.push(r),h.async?"await ":"");n="{"+u.join(",")+"}",a="${"+o(h,e,n,l)+"}"}else{if(""===e)return l||"";n=n.map(([e,t])=>[e,"${"+t+"}"]);u=[...i,...n].map(([e,t])=>t?`${e}="${t.replace(/\"/g,'\\"')}"`:e).join(" ");a=`<${e}${u.length?" "+u:""}>`,t||(a+=l+`</${e}>`)}return a}}static jsxParser(t){let i="";for(let e=0;e<t.length;e++)if("("===t[e]){var n=e;for(e++;0===t[e].trim().length;)e++;if("<"===t[e]){var s=new f(t,e);for(e=s.i,i+="`"+s.outer+"`";")"!==t[e];)e++}else i+=t.slice(n,e+1)}else i+=t[e];return i}tagName="";rest="";inner="";attributes=[];props=[];selfClosed=!1;constructor(e,t){if(">"===e[t+1])this.isComponent=!1,this.tagName="",this.i=t+2;else{for(this.isComponent=/[A-Z]/.test(e[t+1]);t<e.length&&!1!==/[A-Za-z0-9.]/.test(e[++t]);)this.tagName+=e[t];this.i=i(e[t],t,this,e)}!1===this.selfClosed&&this.getInner(e)}get outer(){return f.getOuter(this)}buildAction([e,t]){this.attributes.push(f.buildAction([e,t]))}getInner(e){var t=`</${this.tagName}>`;let i=0;for(var n="</>"==t?"<>":"<"+this.tagName;this.i<e.length;){if(this.inner+=e[this.i],this.inner.endsWith(n)&&i++,this.inner.endsWith(t)){if(!(0<i)){this.inner=this.inner.slice(0,-t.length).trim();break}i--}this.i++}this.buildInner()}buildInner(){let t="";if(!(this.inner.trim().length<2)&&(this.inner.includes("<")||this.inner.includes("{"))){for(let e=0;e<this.inner.length;e++){var i,n;"<"===this.inner[e]?(i=new f(this.inner,e),t+=i.outer,e=i.i):"{"===this.inner[e]?(e=((t,i)=>{let e=0,n={'"':[],"'":[],"`":[]};for(i.replace(/["'`]/g,(e,t)=>{"\\"!==i[t-1]&&n[e].push(t)});t<i.length;){var s=i[++t];if(n[s]&&n[s].length){let e;for(var r of n[s])if(r>t){e=r;break}e&&(t=e,n[s]=n[s].filter(e=>t<e))}else if("{"===s)e++;else if("}"===s){if(!(0<e))break;e--}}return t+1})(i=e,this.inner),n=this.inner.slice(i,e+1),t+="$"+f.jsxParser(n)):t+=this.inner[e]}this.inner=t}}}return f})();
class Lang{static _start="~";static _end="~";static set start(a){this._start=a.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}static set end(a){this._end=a.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}constructor(a={},t="en"){let{dictionary:n={},langs:e=[]}=a;if(!Array.isArray(e))throw new Error("Langs must be an array");this.defaultLang=t,this.regex=new RegExp(Lang._start+"([\\s\\S]*?)"+Lang._end,"g"),this.langs={},(this.langOrder=e).forEach(a=>this.langs[a]={});for(let s in n){if(!Array.isArray(n[s]))throw new Error(`Translations for "${s}" must be an array.`);let r=e.map((a,t)=>n[s][t]||"");e.forEach((a,t)=>{this.langs[a][s]=r[t]})}}dictionary(a){return this.langs[a]||this.langs[this.defaultLang]||{}}dictionaryFn(a){let t=this.dictionary(a);return a=>t[a]||a}replace(a,t){let r=this.dictionaryFn(t);return a.replace(this.regex,(a,t)=>r(t))}add(s={}){for(let r in s)this.langOrder.forEach((a,t)=>{this.langs[a][r]=s[r][t]||""})}merge(a={}){var t,r=new Lang(a,this.defaultLang);for(t in this.langs)void 0===r.langs[t]&&(r.langs[t]={}),r.langs[t]={...r.langs[t],...this.langs[t]};return r}}
class Lang{static _start="~";static _end="~";static set start(a){this._start=a.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}static set end(a){this._end=a.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}constructor(a={},t="en"){let{dictionary:s={},langs:e=[]}=a;if(!Array.isArray(e))throw new Error("Langs must be an array");this.defaultLang=t,this.regex=new RegExp(Lang._start+"([\\s\\S]*?)"+Lang._end,"g"),this.langs={},(this.langOrder=e).forEach(a=>this.langs[a]={});for(let n in s){if(!Array.isArray(s[n]))throw new Error(`Translations for "${n}" must be an array.`);let r=e.map((a,t)=>s[n][t]||"");e.forEach((a,t)=>{this.langs[a][n]=r[t]})}}dictionary(a){return this.langs[a]||this.langs[this.defaultLang]||{}}dictionaryFn(a){let t=this.dictionary(a);return a=>t[a]||a}replace(a,t){let r=this.dictionaryFn(t);return a.replace(this.regex,(a,t)=>r(t))}add(n={}){for(let r in n)this.langOrder.forEach((a,t)=>{this.langs[a][r]=n[r][t]||""})}merge(a){for(var t in a instanceof Lang==!1&&(a=new Lang(a,this.defaultLang)),this.langs)void 0===a.langs[t]&&(a.langs[t]={}),a.langs[t]={...a.langs[t],...this.langs[t]};return a}}
class Component{static isBrowser=!0;static componentsToUpdate=new Set;static components=new WeakMap;static qs(t,e=document){return e.querySelector(t)}static qsa(t,e=document){return[...e.querySelectorAll(t)]}static get isAsync(){return"AsyncFunction"===this.prototype.render.constructor.name}actions=[];counter=0;get element(){return Component.isBrowser?document.querySelector(this.selector):null}set elementOuter(t){var e=this.element;e&&(e.outerHTML=t)}constructor(t={},e){this.isAsync=this.constructor.isAsync,this.props=t,this.inner=e,this.name=this.constructor.name+(this.props.key||""),this.selector=`[component=${this.name}]`,this.hooks={mount:[],unmount:[]},(Component.components[this.name]=this).Component=Component}on(t,e){this.hooks[t]&&this.hooks[t].push(e)}async callAsync(){return(await this.render(this.props,this.inner)).replace(/^\<\w\w*/,t=>`${t} component="${this.name}"`)}callSync(){return this.render(this.props,this.inner).replace(/^\<\w\w*/,t=>`${t} component="${this.name}"`)}call(){return this.Component.componentsToUpdate.add(this),this.isAsync?this.callAsync():this.callSync()}action(t,e){var n=this.name+this.counter++;return this.actions.push({event:t,id:n,fn:e}),n}async buildAsync(t=!0){var e=await this.call();return t&&(this.elementOuter=e),this.Component.isBrowser&&this.runActions(),e}buildSync(t=!0){var e=this.call();return t&&(this.elementOuter=e),this.Component.isBrowser&&this.runActions(),e}build(t){return this.isAsync?this.buildAsync(t):this.buildSync(t)}update(t=this.props,e=this.inner){return this.props=t,this.inner=e,this.build(!0)}runActions(){var{components:t,componentsToUpdate:e}=this.Component;e.forEach(t=>{var{actions:e,hooks:n,selector:s}=t;let o=document.querySelector(s),r=o&&o.childNodes.length?o:document;n.mount.forEach(t=>t(o)),e.forEach(({event:e,fn:n,id:t})=>{let s=r.querySelectorAll(`[${e}="${t}"]`);0!==(s=0===s.length?document.querySelectorAll(`[${e}="${t}"]`):s).length&&s.forEach(t=>{"load"===e?n(t):"function"==typeof t.addEventListener&&t.addEventListener(e,n)})}),t.actions=[],t.hooks.mount=[],t.count=0});for(let e in t){var{selector:n,hooks:s}=t[e];document.querySelector(n)||(s.unmount.forEach(t=>t(e)),delete t[e])}this.Component.componentsToUpdate.clear()}}
return async function render(e,t={},n={}){var{selector:n,version:r,jsx:s=!0,context:i={},langs:c,lang:o,cyclicDependencies:a,logger:l,parameters:p={},scriptBefore:u="",scriptAfter:g=""}=n,r=(i.isBrowser=!0,Require.version=r,s?[e=>e.content=RenderJsx.render(e.content)]:[]),s=new Require(e,{plugins:r,cyclicDependencies:a,logger:l}),e=(await s.getContent(),[Component.toString()]);return c&&(e.push("const __dictionary__ = "+JSON.stringify(new Lang(c).dictionary(o))),e.push("const _ = (text) => __dictionary__[text] || text")),u&&e.push(u),s.fn({scriptBefore:e.join("\n"),scriptAfter:[`const resultObj = new result(${JSON.stringify({data:t,lang:o})})`,n?`resultObj.selector = '${n}'`:"","resultObj.update()",g].join("\n"),parameters:["context={}",...Object.keys(p)]})(i,...Object.values(p))}
return async function render(e,t={},n={}){var{selector:n,version:r,jsx:s=!0,context:i={},langs:c,lang:o,cyclicDependencies:a,logger:l,parameters:p={},scriptBefore:u="",scriptAfter:g=""}=n,r=(i.isBrowser=!0,i.lang=o,Require.version=r,s?[e=>e.content=RenderJsx.render(e.content)]:[]),s=new Require(e,{plugins:r,cyclicDependencies:a,logger:l}),e=(await s.getContent(),[Component.toString()]);return c&&(e.push("const __dictionary__ = "+JSON.stringify(new Lang(c).dictionary(o))),e.push("const _ = (text) => __dictionary__[text] || text")),u&&e.push(u),s.fn({scriptBefore:e.join("\n"),scriptAfter:[`const resultObj = new result(${JSON.stringify(t)})`,n?`resultObj.selector = '${n}'`:"","resultObj.update()",g].join("\n"),parameters:["context={}",...Object.keys(p)]})(i,...Object.values(p))}
})()
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc