UNPKG

solid-intlayer

Version:

Easily internationalize i18n your Solid applications with type-safe multilingual content management.

2 lines (1 loc) 11.2 kB
"use strict";const a=require("solid-js"),L=["allowfullscreen","async","alpha","autofocus","autoplay","checked","controls","default","disabled","formnovalidate","hidden","indeterminate","inert","ismap","loop","multiple","muted","nomodule","novalidate","open","playsinline","readonly","required","reversed","seamless","selected","adauctionheaders","browsingtopics","credentialless","defaultchecked","defaultmuted","defaultselected","defer","disablepictureinpicture","disableremoteplayback","preservespitch","shadowrootclonable","shadowrootcustomelementregistry","shadowrootdelegatesfocus","shadowrootserializable","sharedstoragewritable"],x=new Set(["className","value","readOnly","noValidate","formNoValidate","isMap","noModule","playsInline","adAuctionHeaders","allowFullscreen","browsingTopics","defaultChecked","defaultMuted","defaultSelected","disablePictureInPicture","disableRemotePlayback","preservesPitch","shadowRootClonable","shadowRootCustomElementRegistry","shadowRootDelegatesFocus","shadowRootSerializable","sharedStorageWritable",...L]),I=new Set(["innerHTML","textContent","innerText","children"]),k=Object.assign(Object.create(null),{className:"class",htmlFor:"for"}),O=Object.assign(Object.create(null),{class:"className",novalidate:{$:"noValidate",FORM:1},formnovalidate:{$:"formNoValidate",BUTTON:1,INPUT:1},ismap:{$:"isMap",IMG:1},nomodule:{$:"noModule",SCRIPT:1},playsinline:{$:"playsInline",VIDEO:1},readonly:{$:"readOnly",INPUT:1,TEXTAREA:1},adauctionheaders:{$:"adAuctionHeaders",IFRAME:1},allowfullscreen:{$:"allowFullscreen",IFRAME:1},browsingtopics:{$:"browsingTopics",IMG:1},defaultchecked:{$:"defaultChecked",INPUT:1},defaultmuted:{$:"defaultMuted",AUDIO:1,VIDEO:1},defaultselected:{$:"defaultSelected",OPTION:1},disablepictureinpicture:{$:"disablePictureInPicture",VIDEO:1},disableremoteplayback:{$:"disableRemotePlayback",AUDIO:1,VIDEO:1},preservespitch:{$:"preservesPitch",AUDIO:1,VIDEO:1},shadowrootclonable:{$:"shadowRootClonable",TEMPLATE:1},shadowrootdelegatesfocus:{$:"shadowRootDelegatesFocus",TEMPLATE:1},shadowrootserializable:{$:"shadowRootSerializable",TEMPLATE:1},sharedstoragewritable:{$:"sharedStorageWritable",IFRAME:1,IMG:1}});function D(i,e){const t=O[i];return typeof t=="object"?t[e]?t.$:void 0:t}const R=new Set(["beforeinput","click","dblclick","contextmenu","focusin","focusout","input","keydown","keyup","mousedown","mousemove","mouseout","mouseover","mouseup","pointerdown","pointermove","pointerout","pointerover","pointerup","touchend","touchmove","touchstart"]),p=new Set(["altGlyph","altGlyphDef","altGlyphItem","animate","animateColor","animateMotion","animateTransform","circle","clipPath","color-profile","cursor","defs","desc","ellipse","feBlend","feColorMatrix","feComponentTransfer","feComposite","feConvolveMatrix","feDiffuseLighting","feDisplacementMap","feDistantLight","feDropShadow","feFlood","feFuncA","feFuncB","feFuncG","feFuncR","feGaussianBlur","feImage","feMerge","feMergeNode","feMorphology","feOffset","fePointLight","feSpecularLighting","feSpotLight","feTile","feTurbulence","filter","font","font-face","font-face-format","font-face-name","font-face-src","font-face-uri","foreignObject","g","glyph","glyphRef","hkern","image","line","linearGradient","marker","mask","metadata","missing-glyph","mpath","path","pattern","polygon","polyline","radialGradient","rect","set","stop","svg","switch","symbol","text","textPath","tref","tspan","use","view","vkern"]),F={xlink:"http://www.w3.org/1999/xlink",xml:"http://www.w3.org/XML/1998/namespace"},B=i=>a.createMemo(()=>i());function G(i,e,t){let l=t.length,s=e.length,o=l,f=0,n=0,r=e[s-1].nextSibling,c=null;for(;f<s||n<o;){if(e[f]===t[n]){f++,n++;continue}for(;e[s-1]===t[o-1];)s--,o--;if(s===f){const u=o<l?n?t[n-1].nextSibling:t[o-n]:r;for(;n<o;)i.insertBefore(t[n++],u)}else if(o===n)for(;f<s;)(!c||!c.has(e[f]))&&e[f].remove(),f++;else if(e[f]===t[o-1]&&t[n]===e[s-1]){const u=e[--s].nextSibling;i.insertBefore(t[n++],e[f++].nextSibling),i.insertBefore(t[--o],u),e[s]=t[o]}else{if(!c){c=new Map;let h=n;for(;h<o;)c.set(t[h],h++)}const u=c.get(e[f]);if(u!=null)if(n<u&&u<o){let h=f,d=1,g;for(;++h<s&&h<o&&!((g=c.get(e[h]))==null||g!==u+d);)d++;if(d>u-n){const b=e[f];for(;n<u;)i.insertBefore(t[n++],b)}else i.replaceChild(t[n++],e[f++])}else f++;else e[f++].remove()}}}const C="_$DX_DELEGATE";function V(i,e,t,l){let s;const o=()=>{const n=document.createElement("template");return n.innerHTML=i,n.content.firstChild},f=()=>(s||(s=o())).cloneNode(!0);return f.cloneNode=f,f}function P(i,e=window.document){const t=e[C]||(e[C]=new Set);for(let l=0,s=i.length;l<s;l++){const o=i[l];t.has(o)||(t.add(o),e.addEventListener(o,z))}}function A(i,e,t){y(i)||(t==null?i.removeAttribute(e):i.setAttribute(e,t))}function j(i,e,t,l){y(i)||(l==null?i.removeAttributeNS(e,t):i.setAttributeNS(e,t,l))}function U(i,e,t){y(i)||(t?i.setAttribute(e,""):i.removeAttribute(e))}function _(i,e){y(i)||(e==null?i.removeAttribute("class"):i.className=e)}function H(i,e,t,l){if(l)Array.isArray(t)?(i[`$$${e}`]=t[0],i[`$$${e}Data`]=t[1]):i[`$$${e}`]=t;else if(Array.isArray(t)){const s=t[0];i.addEventListener(e,t[0]=o=>s.call(i,t[1],o))}else i.addEventListener(e,t,typeof t!="function"&&t)}function K(i,e,t={}){const l=Object.keys(e||{}),s=Object.keys(t);let o,f;for(o=0,f=s.length;o<f;o++){const n=s[o];!n||n==="undefined"||e[n]||($(i,n,!1),delete t[n])}for(o=0,f=l.length;o<f;o++){const n=l[o],r=!!e[n];!n||n==="undefined"||t[n]===r||!r||($(i,n,!0),t[n]=r)}return t}function q(i,e,t){if(!e)return t?A(i,"style"):e;const l=i.style;if(typeof e=="string")return l.cssText=e;typeof t=="string"&&(l.cssText=t=void 0),t||(t={}),e||(e={});let s,o;for(o in t)e[o]==null&&l.removeProperty(o),delete t[o];for(o in e)s=e[o],s!==t[o]&&(l.setProperty(o,s),t[o]=s);return t}function M(i,e={},t,l){const s={};return l||a.createRenderEffect(()=>s.children=m(i,e.children,s.children)),a.createRenderEffect(()=>typeof e.ref=="function"&&S(e.ref,i)),a.createRenderEffect(()=>W(i,e,t,!0,s,!0)),s}function S(i,e,t){return a.untrack(()=>i(e,t))}function X(i,e,t,l){if(typeof e!="function")return m(i,e,l,t);a.createRenderEffect(s=>m(i,e(),s,t),l)}function W(i,e,t,l,s={},o=!1){e||(e={});for(const f in s)if(!(f in e)){if(f==="children")continue;s[f]=T(i,f,null,s[f],t,o,e)}for(const f in e){if(f==="children")continue;const n=e[f];s[f]=T(i,f,n,s[f],t,o,e)}}function J(i){let e,t;return!y()||!(e=a.sharedConfig.registry.get(t=Q()))?i():(a.sharedConfig.completed&&a.sharedConfig.completed.add(e),a.sharedConfig.registry.delete(t),e)}function y(i){return!!a.sharedConfig.context&&!a.sharedConfig.done&&(!i||i.isConnected)}function Y(i){return i.toLowerCase().replace(/-([a-z])/g,(e,t)=>t.toUpperCase())}function $(i,e,t){const l=e.trim().split(/\s+/);for(let s=0,o=l.length;s<o;s++)i.classList.toggle(l[s],t)}function T(i,e,t,l,s,o,f){let n,r,c,u,h;if(e==="style")return q(i,t,l);if(e==="classList")return K(i,t,l);if(t===l)return l;if(e==="ref")o||t(i);else if(e.slice(0,3)==="on:"){const d=e.slice(3);l&&i.removeEventListener(d,l,typeof l!="function"&&l),t&&i.addEventListener(d,t,typeof t!="function"&&t)}else if(e.slice(0,10)==="oncapture:"){const d=e.slice(10);l&&i.removeEventListener(d,l,!0),t&&i.addEventListener(d,t,!0)}else if(e.slice(0,2)==="on"){const d=e.slice(2).toLowerCase(),g=R.has(d);if(!g&&l){const b=Array.isArray(l)?l[0]:l;i.removeEventListener(d,b)}(g||t)&&(H(i,d,t,g),g&&P([d]))}else if(e.slice(0,5)==="attr:")A(i,e.slice(5),t);else if(e.slice(0,5)==="bool:")U(i,e.slice(5),t);else if((h=e.slice(0,5)==="prop:")||(c=I.has(e))||!s&&((u=D(e,i.tagName))||(r=x.has(e)))||(n=i.nodeName.includes("-")||"is"in f)){if(h)e=e.slice(5),r=!0;else if(y(i))return t;e==="class"||e==="className"?_(i,t):n&&!r&&!c?i[Y(e)]=t:i[u||e]=t}else{const d=s&&e.indexOf(":")>-1&&F[e.split(":")[0]];d?j(i,d,e,t):A(i,k[e]||e,t)}return t}function z(i){if(a.sharedConfig.registry&&a.sharedConfig.events&&a.sharedConfig.events.find(([r,c])=>c===i))return;let e=i.target;const t=`$$${i.type}`,l=i.target,s=i.currentTarget,o=r=>Object.defineProperty(i,"target",{configurable:!0,value:r}),f=()=>{const r=e[t];if(r&&!e.disabled){const c=e[`${t}Data`];if(c!==void 0?r.call(e,c,i):r.call(e,i),i.cancelBubble)return}return e.host&&typeof e.host!="string"&&!e.host._$host&&e.contains(i.target)&&o(e.host),!0},n=()=>{for(;f()&&(e=e._$host||e.parentNode||e.host););};if(Object.defineProperty(i,"currentTarget",{configurable:!0,get(){return e||document}}),a.sharedConfig.registry&&!a.sharedConfig.done&&(a.sharedConfig.done=_$HY.done=!0),i.composedPath){const r=i.composedPath();o(r[0]);for(let c=0;c<r.length-2&&(e=r[c],!!f());c++){if(e._$host){e=e._$host,n();break}if(e.parentNode===s)break}}else n();o(l)}function m(i,e,t,l,s){const o=y(i);if(o){!t&&(t=[...i.childNodes]);let n=[];for(let r=0;r<t.length;r++){const c=t[r];c.nodeType===8&&c.data.slice(0,2)==="!$"?c.remove():n.push(c)}t=n}for(;typeof t=="function";)t=t();if(e===t)return t;const f=typeof e;if(i=i,f==="string"||f==="number"){if(o||f==="number"&&(e=e.toString(),e===t))return t;t!==""&&typeof t=="string"?t=i.firstChild.data=e:t=i.textContent=e}else if(e==null||f==="boolean"){if(o)return t;t=w(i,t,l)}else{if(f==="function")return a.createRenderEffect(()=>{let n=e();for(;typeof n=="function";)n=n();t=m(i,n,t,l)}),()=>t;if(Array.isArray(e)){const n=[],r=t&&Array.isArray(t);if(E(n,e,t,s))return a.createRenderEffect(()=>t=m(i,n,t,l,!0)),()=>t;if(o)return n.length?t=[...i.childNodes]:t;n.length===0?t=w(i,t,l):r?t.length===0?N(i,n,l):G(i,t,n):(t&&w(i),N(i,n)),t=n}else if(e.nodeType){if(o&&e.parentNode)return t=e;Array.isArray(t)?w(i,t,null,e):t==null||t===""||!i.firstChild?i.appendChild(e):i.replaceChild(e,i.firstChild),t=e}}return t}function E(i,e,t,l){let s=!1;for(let o=0,f=e.length;o<f;o++){let n=e[o],r=t&&t[i.length],c;if(!(n==null||n===!0||n===!1))if((c=typeof n)=="object"&&n.nodeType)i.push(n);else if(Array.isArray(n))s=E(i,n,r)||s;else if(c==="function")if(l){for(;typeof n=="function";)n=n();s=E(i,Array.isArray(n)?n:[n],Array.isArray(r)?r:[r])||s}else i.push(n),s=!0;else{const u=String(n);r&&r.nodeType===3&&r.data===u?i.push(r):i.push(document.createTextNode(u))}}return s}function N(i,e,t=null){for(let l=0,s=e.length;l<s;l++)i.insertBefore(e[l],t)}function w(i,e,t,l){if(t===void 0)return i.textContent="";const s=l||document.createTextNode("");if(e.length){let o=!1;for(let f=e.length-1;f>=0;f--){const n=e[f];if(s!==n){const r=n.parentNode===i;!o&&!f?r?i.replaceChild(s,n):i.insertBefore(s,t):r&&n.remove()}else o=!0}}else i.insertBefore(s,t);return[s]}function Q(){return a.sharedConfig.getNextContextId()}const Z="http://www.w3.org/2000/svg";function v(i,e=!1,t=void 0){return e?document.createElementNS(Z,i):document.createElement(i,{is:t})}function ee(i,e){const t=a.createMemo(i);return a.createMemo(()=>{const l=t();switch(typeof l){case"function":return a.untrack(()=>l(e));case"string":const s=p.has(l),o=a.sharedConfig.context?J():v(l,s,a.untrack(()=>e.is));return M(o,e,s),o}})}function te(i){const[,e]=a.splitProps(i,["component"]);return ee(()=>i.component,e)}exports.Dynamic=te;exports.delegateEvents=P;exports.insert=X;exports.memo=B;exports.spread=M;exports.template=V;exports.use=S;