@peter.naydenov/morph 3.3.1 → 3.3.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/.claude/scheduled_tasks.lock +1 -0
- package/.claude/settings.local.json +14 -0
- package/.graphify_cached.json +1 -0
- package/.graphify_semantic_new.json +1 -0
- package/.graphify_uncached.txt +14 -0
- package/.opencode/package-lock.json +115 -0
- package/.opencode/plugins/graphify.js +22 -0
- package/AGENTS.md +8 -0
- package/Changelog.md +16 -0
- package/dist/morph.cjs +1 -1
- package/dist/morph.esm.mjs +1 -1
- package/dist/morph.umd.js +1 -1
- package/dist/src/main.d.ts +100 -0
- package/dist/src/methods/_actionSupply.d.ts +18 -0
- package/dist/src/methods/_chopTemplates.d.ts +22 -0
- package/dist/src/methods/_defineData.d.ts +25 -0
- package/dist/src/methods/_defineType.d.ts +15 -0
- package/dist/src/methods/_readTemplate.d.ts +24 -0
- package/dist/src/methods/_renderHolder.d.ts +17 -0
- package/dist/src/methods/_setupActions.d.ts +19 -0
- package/dist/src/methods/actionData.d.ts +10 -0
- package/dist/src/methods/actionExtendedRender.d.ts +10 -0
- package/dist/src/methods/actionMix.d.ts +10 -0
- package/dist/src/methods/actionRender.d.ts +13 -0
- package/dist/src/methods/actionSave.d.ts +8 -0
- package/dist/src/methods/build.d.ts +61 -0
- package/dist/src/methods/executeActions.d.ts +11 -0
- package/dist/src/methods/processCommands.d.ts +46 -0
- package/dist/src/methods/processPlaceholders.d.ts +27 -0
- package/dist/src/methods/render.d.ts +14 -0
- package/dist/src/methods/settings.d.ts +7 -0
- package/graphify-out/.graphify_python +1 -0
- package/graphify-out/GRAPH_REPORT.md +147 -0
- package/graphify-out/cache/12d38a6879ec5b7a18b61b92920684a5e915c2255c41e2c56168c678dba94023.json +1 -0
- package/graphify-out/cache/1ba574be094f9bd868bbce1091b9988d6188ae071762a73d483516498b742434.json +1 -0
- package/graphify-out/cache/2dfd19c49f88b8af0c95f7692ae9453b54cf898dba6c24cad9cbd555b365f5e7.json +1 -0
- package/graphify-out/cache/343264caa0702ae2210efeb2d673fb69b59bd01403803c84f9da0ce21d93c6fe.json +1 -0
- package/graphify-out/cache/38f82a17b2933bf14206263846c7396b46ac0db01af525300ac20f2f3f2b0534.json +1 -0
- package/graphify-out/cache/3a8b3ccf38f1d380228dda52c3c595ec76b5827b6905ef7e2bef6e265ee4ac16.json +1 -0
- package/graphify-out/cache/3b3e764a57e1d2ce17e5a74bea1c7ee493260e27266c114a72688d441f712e52.json +1 -0
- package/graphify-out/cache/42bc18f8ec31b043b4c4ecc11c79c288afe0801207d60a7cc322d11ab4579864.json +1 -0
- package/graphify-out/cache/4e3d45485b073109c7d91f18dac64ffbf0cbc21ae0edac016cb7b5f061954af6.json +1 -0
- package/graphify-out/cache/4ed08a09c3f090fe62cd56647a5251d60cf2f095156e502244a4f732929e342c.json +1 -0
- package/graphify-out/cache/51c174d3534ae05ed6dcbdb7f0d16da0b22f05677ef2863920e0a541b06090dd.json +1 -0
- package/graphify-out/cache/51d65b15aad6e35883d6ccaa0688273d7e14d8b7b85b194c50c365e5ea6710c6.json +1 -0
- package/graphify-out/cache/5d96cf59b7e5e3ea65c2ddcc6267178ea8916e104ff3f82a5a4d90179f762d11.json +1 -0
- package/graphify-out/cache/63fa82962f6899c2c099e95b595c5106f5dd53b2dc65037b89d6c6578033c03c.json +1 -0
- package/graphify-out/cache/6878c29d96e13e9fee1e01e4ca4e77d28b1e8e6c4f1d05dbffdca58625ef5694.json +1 -0
- package/graphify-out/cache/6c7082448b871f8cce9c6e26f788252a3b0c7e88ce40b4d3652ca9b78a2df049.json +1 -0
- package/graphify-out/cache/7cb42a4ad6e7c2f8b66560c9c40053e479cc1cffdf074d6b00bc23e607535376.json +1 -0
- package/graphify-out/cache/8712e549b4b42d5dc14c3e4b56f384c9d8e37116dc61ad906a05e10a1445ff40.json +1 -0
- package/graphify-out/cache/8b1ea63dfe0d47683be14dd72078eb83cf5b182d497237adbcd50ebdc1fee1bc.json +1 -0
- package/graphify-out/cache/8cd02cb84a50696666d33fee84a4a7e75fce651780ba7a4474bfe9b4a2b79c46.json +1 -0
- package/graphify-out/cache/8d0520a089ffaa71927ddddad5cb4d8f796a9febf0b8c4d54f78453b955520c5.json +1 -0
- package/graphify-out/cache/9406e0a23a011eaa9d74fe717280e5be52142ba4db8b7baee948dcdea6fe2617.json +1 -0
- package/graphify-out/cache/98abf9b9fbeb7f5fdaef6b853c949d297586b99e2965330906234f2ae331c0af.json +1 -0
- package/graphify-out/cache/9decf23c89efbaa42811f95c737234abee72478582ce4a46d99ba12d7446bb7b.json +1 -0
- package/graphify-out/cache/a37bc5340c5f31d2ef717845d339f468853e6554f753466ba2d995147d25fedf.json +1 -0
- package/graphify-out/cache/a77d81d5705a824ba81dc3556452ecc99978bc335e65e961aee29ce01e7cf81c.json +1 -0
- package/graphify-out/cache/ast/v0.8.39/21cd1a6bc5dbd687522c86e9f7db1842400b31ee3ba62127533aba56a478da5d.json +1 -0
- package/graphify-out/cache/ast/v0.8.39/29c3826c5e1938406f9eaf50a1354609aeb16e8f0d27e5a454c069c982f21180.json +1 -0
- package/graphify-out/cache/ast/v0.8.39/c31ea4d76660d1000df3bd29929d120e900297c7a1c26e5266312c21a9432e55.json +1 -0
- package/graphify-out/cache/ast/v0.8.39/de54c2617a64a2a1c1db34e6494216dd949fe730b51270bebba55c63d54a31e9.json +1 -0
- package/graphify-out/cache/b83cba0b46f18ae8fc4d50b540eaa276c28745ea4639863c082cb41681220b9d.json +1 -0
- package/graphify-out/cache/bd607a8d62efb3cceb791e36c2495c5ceee38e913c2386d293cca88566f4c0aa.json +1 -0
- package/graphify-out/cache/beb2827f4b8ad2aaacd809c8d783eb1f5f3c3c997ce6941d1cc9b2f0df7a0d6e.json +1 -0
- package/graphify-out/cache/ca721e7772d7906c5fecc00d69aa50bdc5e73ba087807089f3ca26509e014889.json +1 -0
- package/graphify-out/cache/cb49f9ceae6e04f66081b0c73c0574bddaf01240ea0c7efc1880616b94b4c0d8.json +1 -0
- package/graphify-out/cache/ce9874dce6f3f855a53dd706b4b83a503dc4ba72f7f36b6d73ec2cc8354f3cdf.json +1 -0
- package/graphify-out/cache/d3e24fc669e3f2a2c5e9e864a97ca447f0dcc1c5aad33c88a2280ac97188e888.json +1 -0
- package/graphify-out/cache/d6c072004e2ea18f9a5380aa75980cd08b15e7d6d893d396a5baac37dfc24310.json +1 -0
- package/graphify-out/cache/d99f1759a41541d9ef41aefdf89a2dbcab7272ccc91a9794062224124222e333.json +1 -0
- package/graphify-out/cache/dbb69ddd98951e0d5e51b2e1a2cf97a8febb147e55b81b43b05b680844bf4a1f.json +1 -0
- package/graphify-out/cache/df270b9b613de7bbefce4cabc6b3dd6e66ebecdbf6f0cefde05bb676569ee1c3.json +1 -0
- package/graphify-out/cache/e56607f0791079dbd05e56cdac41f88124785d367f9da0eb436952406cb317da.json +1 -0
- package/graphify-out/cache/ecdfee4e64acdd666f25596341a8ff4a41d7ee1e637de40685ff33c1efa814c7.json +1 -0
- package/graphify-out/cache/f0f3005c7ec68d16fcde259d6bc996520841d021ce2531cbb7f3de343996c4ea.json +1 -0
- package/graphify-out/cache/f2bfcd400f076a7e8a9e54b821d555c90b93ef4dd8d3652f78ec35acad5e0615.json +1 -0
- package/graphify-out/cache/semantic/043be2e32281a59e2bacb95418b95816b558a290aa581434b22666fb9a6a3a6c.json +1 -0
- package/graphify-out/cache/semantic/13439df0f4f40e2c190340576c1a46c2cc82b9fc789f262c78d7129cc56ef13c.json +1 -0
- package/graphify-out/cache/semantic/136052be0f52f9258076b87da6bde0ea62763a63684cc6729f759910448ae675.json +1 -0
- package/graphify-out/cache/semantic/15cbc6ab30bfa8cf7bb9b5646a2598aa78531047ef5096d5d8ab08edbcf8ee7d.json +1 -0
- package/graphify-out/cache/semantic/21cd1a6bc5dbd687522c86e9f7db1842400b31ee3ba62127533aba56a478da5d.json +1 -0
- package/graphify-out/cache/semantic/22bd0d40f23b81ba30a703fc290cc518f18d3148f5553ffc79f4bf8a0a71722c.json +1 -0
- package/graphify-out/cache/semantic/29c3826c5e1938406f9eaf50a1354609aeb16e8f0d27e5a454c069c982f21180.json +1 -0
- package/graphify-out/cache/semantic/2e913a06516b6bff22019b157680d17617db82a9ed2277ce1e20eac945939a7e.json +1 -0
- package/graphify-out/cache/semantic/30db4df562575c6116ad9e8843f19c557ab6fc25288c7aed8926641748b21fd6.json +1 -0
- package/graphify-out/cache/semantic/325abe6948add2e47c2271195503ab21f897e27f2cc9af292f39408b94a2f51c.json +1 -0
- package/graphify-out/cache/semantic/3579f6cf2c93aa83eb9396e389c195f17e4cff527d43718e61503e5c0f223f84.json +1 -0
- package/graphify-out/cache/semantic/36cda2fb14ba2ee3b8bc721a278f4963bf001c72258dd707b4b141334be01c15.json +1 -0
- package/graphify-out/cache/semantic/403b6596e3414f78206fc02adf9b62f07af237be191e0f4b26706041bf1e0ee1.json +1 -0
- package/graphify-out/cache/semantic/40f4144bc24d137a1afdcac95143c2bc3e26c0086d150c73df85fdf236bebe01.json +1 -0
- package/graphify-out/cache/semantic/45d85f3ac35b83d9a076c6e25c220324a0c92d0e955ba85e04b20ef09ddad9fd.json +1 -0
- package/graphify-out/cache/semantic/468d9e0c3d92cce2723852d2f29033326433cdc368203092b8470f2f356e3cec.json +1 -0
- package/graphify-out/cache/semantic/5983c77253844a325cb78f45828115ede5a688908bd38fa1b32ca78ab319deb9.json +1 -0
- package/graphify-out/cache/semantic/59ef3e18c32f0f877d8854ecb5e9f8714c608d5d90ca7adc71f2859fe496f66f.json +1 -0
- package/graphify-out/cache/semantic/71dd26effab66822e1d20111accfa0cc434826661da83b1b86a6fc3119980a66.json +1 -0
- package/graphify-out/cache/semantic/78bc10fe7d8d145c2c12af97dd75ea16f6787f1f15f0af0b145ac315ce63dcb6.json +1 -0
- package/graphify-out/cache/semantic/7c92d89867073cc9e54a821be558de7322fa42f342cf4c52da9bf02c29f43b1d.json +1 -0
- package/graphify-out/cache/semantic/82c3b90b2523c47b43a3212e2d30ed8d06c0027697f89fe177d062baf4d4202f.json +1 -0
- package/graphify-out/cache/semantic/8917cb163ec1afce8e5d659680749a553be3aa6aef54ebc757dd1b7c81d707c6.json +1 -0
- package/graphify-out/cache/semantic/8da5742abeaeadae80c4f57a4e98432a4bfc789eadb5082d3919780d646546f6.json +1 -0
- package/graphify-out/cache/semantic/97f4eb2208c6b1e81c84600ab52507478f5e682e63e5546a92c97b4c3d9371eb.json +1 -0
- package/graphify-out/cache/semantic/9c01c0ac53d626004b3d72953063c71f251710e7f23a8765c149159b0f422ecc.json +1 -0
- package/graphify-out/cache/semantic/9d0bbf5bdbb2aa4e3507d2e118464ce70d165916e29cae54b5ead974bfc1bd04.json +1 -0
- package/graphify-out/cache/semantic/9e59357a8097ad32258c2cb47c066508049e7f8c21fa55a1a5f5a4b0eee41275.json +1 -0
- package/graphify-out/cache/semantic/aaaff53eae109640d8e48c4585390fa7a2c2ca04088d314e578c316ca95f53e0.json +1 -0
- package/graphify-out/cache/semantic/b18464395b8719578b14148fd37880916c62b10f78942c862da386815c05b628.json +1 -0
- package/graphify-out/cache/semantic/c31ea4d76660d1000df3bd29929d120e900297c7a1c26e5266312c21a9432e55.json +1 -0
- package/graphify-out/cache/semantic/c74b855b4778be378db8fa05e33582c33cb563d8698ba6dae566e1cd37d0fb09.json +1 -0
- package/graphify-out/cache/semantic/cc8bf09a84e6fcc420e2438b3d6403560128b0edbd907761350fa58536d844ff.json +1 -0
- package/graphify-out/cache/semantic/d39f7cd9481b6f19c88e62ff5f7a3bddbf3a3593b2b1257a5092b44374c70874.json +1 -0
- package/graphify-out/cache/semantic/d5472c5e2c6560c9de5c17a444e2060eb9ccaa5dc7f4f3fe0dc3a5f68625bb91.json +1 -0
- package/graphify-out/cache/semantic/de54c2617a64a2a1c1db34e6494216dd949fe730b51270bebba55c63d54a31e9.json +1 -0
- package/graphify-out/cache/semantic/e29c1a9e35ffd56ab3b1e2f4800b48e9a6880bddecfc028dfdaf14498f52d8b4.json +1 -0
- package/graphify-out/cache/semantic/e39668e1347ee1000e7fba8b922c76488e34c35f2088b8334806e0256cfd71a7.json +1 -0
- package/graphify-out/cache/semantic/e9eea1131268a154e037e558c1856fbb2941e129b405659416b4e69746759440.json +1 -0
- package/graphify-out/cache/semantic/f3863c3e1c42f444b735cf4042b01a07b4e2f0bff82580bfab9bad1a784b8f4d.json +1 -0
- package/graphify-out/cache/semantic/f6dde571c1b88858dbf6da9b447dba7e66d9cb211c0130abcbb0768efed52e7b.json +1 -0
- package/graphify-out/cache/semantic/fa84dbd8fb64d52d0d43ea31da6cff178668e3eba7efb6e96ff605f3838a2bea.json +1 -0
- package/graphify-out/cache/stat-index.json +1 -0
- package/graphify-out/cost.json +18 -0
- package/graphify-out/graph.html +307 -0
- package/graphify-out/graph.json +6531 -0
- package/graphify-out/manifest.json +467 -0
- package/opencode.json +6 -0
- package/package.json +17 -9
- package/src/main.js +3 -7
- package/src/methods/_chopTemplates.js +56 -63
- package/src/methods/_setupActions.js +7 -14
- package/src/methods/actionData.js +35 -21
- package/src/methods/actionExtendedRender.js +21 -22
- package/src/methods/actionMix.js +47 -49
- package/src/methods/actionRender.js +43 -75
- package/src/methods/build.js +75 -97
- package/src/methods/executeActions.js +63 -49
- package/src/methods/processCommands.js +6 -10
- package/src/methods/processPlaceholders.js +105 -123
- package/src/methods/render.js +11 -13
- package/tsconfig.json +2 -1
package/dist/morph.umd.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t(require("@peter.naydenov/walk")):"function"==typeof define&&define.amd?define(["@peter.naydenov/walk"],t):(e="undefined"!=typeof globalThis?globalThis:e||self).morph=t(e.walk)}(this,(function(e){"use strict";function t(e){return function t(n){const{TG_PRX:a,TG_SFX:o,TG_SIZE_P:l,TG_SIZE_S:s}=e;let i,c,u,f=[];if("string"!=typeof n)return r("notAString");if(0==n.length)return[];if(i=n.indexOf(a),0<i&&f.push(n.slice(0,i)),-1==i)return f.push(n),f;{if(u=n.indexOf(a,i+l),c=n.indexOf(o),-1==c)return r("missingClosing");if(c<i)return r("closedBeforeOpened");if(c+=s,-1!=u&&u<c)return r("newBeforeClosed");f.push(n.slice(i,c));let e=t(n.slice(c));return f.concat(e)}}}function r(e){switch(e){case"notAString":return"Error: Template is not a string.";case"missingClosing":return"Error: Placeholder with missing closing tag.";case"closedBeforeOpened":return"Error: Placeholder closing tag without starting one.";case"newBeforeClosed":return"Error: Nested placeholders. Close placeholder before open new one.";default:return"Error: Unknown template error."}}function*n(e,t){let r=function(e={}){let t=[],{type:r,limit:n,onLimit:a}=Object.assign({},{type:"FIFO",limit:!1,onLimit:"update"},e),o="LIFO"===r.toUpperCase(),l=!1;function s(e=1,r=0){let n=[];return r>0&&Array.from({length:r}).map((()=>t.pop())),1==e?t.pop():(Array.from({length:e}).map((()=>{let e=t.pop();null!=e&&n.push(e)})),n)}function i(e=1,r=0){let n=[],a=t.length-r;return e>1&&Array.from({length:e}).map((()=>{null!=t[a-1]&&n.push(t[a-1]),a--})),1==e?t[t.length-1]:n}function c(){}return c.prototype={pull:s,pullReverse:function(e=1,t=0){let r=s(e,t);return r instanceof Array?r.reverse():r},peek:i,peekReverse:function(e=1,t=0){const r=i(e,t);return r instanceof Array?r.reverse():r},getSize:()=>t.length,isEmpty:()=>0==t.length,reset:()=>(t=[],!0),debug:()=>[...t]},c.prototype.push=o?function(e){const r=e instanceof Array,o=r?e.length:1;let i=!1;if("full"!==a||!l){if(n&&r&&o>n&&(e=e.slice(0,-o+n)),n){const o=(r?e.length:1)+t.length;o>=n&&"full"===a&&(e=e.slice(0,-(o-n))),o>=n&&"update"===a&&(i=s(o-n))}return t=e instanceof Array?t.concat(e):t.concat([e]),l=!!n&&t.length===n,i||void 0}}:function(e){const r=e instanceof Array,o=r?e.length:1;let i=!1;if("full"!==a||!l){if(n&&r&&o>n&&(e=e.slice(o-n)),n){const o=(r?e.length:1)+t.length;o>=n&&"full"===a&&(e=e.slice(0,-(o-n))),o>=n&&"update"===a&&(i=s(o-n))}return t=r?e.reduce(((e,t)=>[t,...e]),t):[e].reduce(((e,t)=>[t,...e]),t),l=!!n&&t.length===n,i||void 0}},new c}({type:"LIFO"});for(let n=0;n<=t;n++)r.push(e[n]);for(;r&&!r.isEmpty();){let e=yield r.pull();e&&r.push(e)}}var a={TG_PRX:"{{",TG_SFX:"}}",TG_SIZE_P:2,TG_SIZE_S:2};function o(e){return null==e?"null":"string"==typeof e||"number"==typeof e||"boolean"==typeof e?"primitive":"function"==typeof e?"function":e instanceof Array?"array":e instanceof Object?"object":void 0}function l(e,r,n,o,l,...s){if(e instanceof Object&&Object.entries(e).forEach((([t,r])=>{r instanceof Object&&(e[t]=r.text),r instanceof Array&&(e[t]=r[0])})),!n[r])return`{{ Error: Helper '${r}' is not available}}`;const i="function"==typeof n[r];return e=function(e={}){return"string"==typeof e?{text:e}:e}(e),i?n[r]({theData:e,dependencies:l,full:o},...s):function(e,r){if(null==r)return null;const n=t(a)(e),o=a;return n.forEach(((e,t)=>{if(e.includes(o.TG_PRX)){const a=e.replace(o.TG_PRX,"").replace(o.TG_SFX,"").trim();r.hasOwnProperty(a)&&null!=r[a]&&(n[t]=r[a])}})),n.join("")}(n[r],e)}function s(r,i=!1,c={}){let{hasError:u,placeholders:f,chop:d,helpers:p,handshake:h,snippets:m}=function(e){const{template:r,helpers:n={},handshake:o}=e,{TG_PRX:l,TG_SFX:s}=a,i=[],c={},u="string"==typeof r?r.replace(/<!--[\s\S]*?-->/g,"").replace(/\s{2,}/g," "):r;let f=null;const d=t(a)(u);return"string"==typeof d?f=d:d.forEach(((e,t)=>{const r=RegExp(l+"\\s*(.*?)\\s*(?::\\s*(.*?)\\s*)?(?::\\s*(.*?)\\s*)?"+s,"g");if(e.includes(l)){const a=r.exec(e);if(!a)return;let o={index:t,data:(n=a[1],n||null),action:a[2]?a[2].split(",").map((e=>e.trim())):null,name:a[3]?a[3].trim():null};i.push(o),c[i.length-1]=o,o.name&&(c[o.name]=o)}var n})),{hasError:f,placeholders:i,chop:d,helpers:n,handshake:o,snippets:c}}(r);if(u){function y(){return u}return i?[!1,y]:y}{const g=structuredClone(f);function b(t="render",r={},a={},...i){const u=structuredClone(d);let y=!1;if("string"!=typeof t)return`Error: Wrong command "${t}". Available commands: render, debug, snippets, set, curry.`;if(!["render","debug","snippets","set","curry"].includes(t)&&!t.startsWith("snippets"))return`Error: Wrong command "${t}". Available commands: render, debug, snippets, set, curry.`;if(t.startsWith("snippets")&&t.includes(":")){y=!0;let e=t.split(":").slice(1)[0].trim().split(",").map((e=>e.trim()));f=e.map((e=>m[e]))}else if("snippets"===t)y=!0;else{if("set"===t){if("object"!=typeof r||!r)return"Error: 'set' command requires an object with placeholders, helpers, handshake.";const e={...p,...r.helpers||{}},t=h?{...h,...r.handshake||{}}:r.handshake||{},n=[...d];r.placeholders&&Object.entries(r.placeholders).forEach((([e,t])=>{if(isNaN(e)){let r=f.find((t=>t.name===e));n[r.index]=t}else{let r=f[e].index;n[r]=t}}));const a=s({template:n.join(""),helpers:e,handshake:t},!1,c);return"function"==typeof a?a:()=>a}if("curry"===t){return s({template:b("render",r,a,...i),helpers:p,handshake:h},!1,c)}f=structuredClone(g)}if("string"==typeof r)switch(r){case"raw":return u.join("");case"demo":if(!h)return"Error: No handshake data.";r=h;break;case"handshake":return h?structuredClone(h):"Error: No handshake data.";case"helpers":return Object.keys(p).join(", ");case"placeholders":return f.map((e=>u[e.index])).join(", ");case"count":return f.length;default:return`Error: Wrong instruction "${r}". Available instructions: raw, demo, handshake, helpers, placeholders, count.`}const v=[],k={};let E=o(r),j={...c,...a};r=e({data:r});let x=e({data:r});return"null"===E?u.join(""):("array"!==E&&(r=[r]),"null"===E?u.join(""):(r.forEach((t=>{f.forEach((a=>{const{index:s,data:i,action:c}=a,f=!c&&i,d=structuredClone(k),h={dependencies:j,memory:d};let m=t;if(i&&i.includes("/")?m.hasOwnProperty(i)?m=m[i]:i.split("/").forEach((e=>{m=m.hasOwnProperty(e)?m[e]:[]})):"@all"===i||null===i||"@root"===i?m=t:i&&(m=m[i]),f){switch(o(m)){case"function":return void(u[s]=m());case"primitive":return void(u[s]=m);case"array":return void("primitive"===o(m[0])&&(u[s]=m[0]));case"object":return void(m.text&&(u[s]=m.text))}}else{let{dataDeepLevel:a,nestedData:i}=function(t,r){const n=[];let a=0;if(t instanceof Function)return{dataDeepLevel:0,nestedData:[[t()]]};if(null==t)return{dataDeepLevel:0,nestedData:[null]};if("string"==typeof t)return{dataDeepLevel:0,nestedData:[[t]]};const o=structuredClone(t);return r.includes("#")?(e({data:o,objectCallback:function({key:e,value:t,breadcrumbs:r}){return e===r?(n[0]=[t],t):(a=r.split("/").length-1,n[a]||(n[a]=[]),n[a].push(t),t)}}),{dataDeepLevel:a,nestedData:n}):(n.push([o]),{dataDeepLevel:0,nestedData:n})}(m,c),f=n(function(e,t=10){let r={},n=[...e],a=0,o=0,l=0;n.forEach((e=>{"#"===e&&l++})),l<t&&console.error(`Error: Not enough level markers (#) for data with depth level ${t}. Found ${l} level markers in actions: ${e.join(", ")}`);do{r[o]=[],o++}while(o<=t);return n.every((e=>"#"===e?(a++,!(a>t)):e.startsWith("^")&&"^^"!==e?(r[a].push({type:"save",name:e.replace("^",""),level:a}),!0):"^^"===e?(r[a].push({type:"overwrite",name:"none",level:a}),!0):e.startsWith("+")?(r[a].push({type:"extendedRender",name:e.replace("+",""),level:a}),!0):e.startsWith("[]")?(r[a].push({type:"mix",name:e.replace("[]",""),level:a}),!0):e.startsWith(">")?(r[a].push({type:"data",name:e.replace(">",""),level:a}),!0):(""===e||r[a].push({type:"render",name:e,level:a}),!0))),r}(c,a),a);for(let n of f){let{type:a,name:s,level:c}=n;(i[c]||[]).forEach(((n,u)=>{let f=o(n);switch(a){case"route":switch(f){case"array":n.forEach(((e,t)=>{if(null==e)return;const r=o(e),a=p[s]({data:e,...h,full:e});null!=a&&("object"===r?n[t].text=l(e,a,p,x,j):n[t]=l(e,a,p,x,j))}));break;case"object":n.text=l(n,s,p,x,j)}break;case"save":k[s]=structuredClone(n);break;case"overwrite":t=structuredClone(n);break;case"data":switch(f){case"array":n.forEach(((e,t)=>n[t]=e instanceof Function?p[s]({data:e(),...h,full:e}):p[s]({data:e,...h,full:e})));break;case"object":i[c]=[p[s]({data:n,...h,full:r})];break;case"function":i[c]=[p[s]({data:n(),...h,full:r})];break;case"primitive":i[c]=p[s]({data:n,...h,full:r})}break;case"render":const d="function"==typeof p[s];switch(f){case"array":d?n.forEach(((e,t)=>{if(null==e)return;const r=o(e),a=p[s]({data:e,...h,full:x});null==a&&(n[t]=null),"object"===r?e.text=a:n[t]=a})):n.forEach(((e,t)=>{if(null==e)return;const r=o(e),a=l(e,s,p,x,j);null==a?n[t]=null:"object"===r?e.text=a:n[t]=a}));break;case"function":i[c]=p[s]({data:n(),...h,full:r});break;case"primitive":i[c]=d?p[s]({data:n,...h,full:r}):l(n,s,p,x,j);break;case"object":d?i[c][u].text=p[s]({data:n,...h,full:r}):n.text=l(n,s,p,x,j)}break;case"extendedRender":"function"==typeof p[s]&&i[0].forEach(((e,t)=>i[0][t]=p[s]({data:e,...h,full:e})));break;case"mix":if(""===s)switch(f){case"object":Object.keys(n).find((e=>e.includes("/")))?Object.entries(n).forEach((([e,t])=>i[c][e]=t.text)):i[c]=n.text;for(let y=c-1;y>=0;y--)i[y]=e({data:i[y],objectCallback:m});function m({value:e,breadcrumbs:t}){return i[c][t]?i[c][t]:e}break;case"array":n.forEach(((e,t)=>{if(t>0){let r=o(e);if(null==e)return;n[0]+="object"===r?`${e.text}`:`${e}`,n.toSpliced(t,1)}else{let t=o(e);if(n[0]="",null===t)return;n[0]="object"===t?`${e.text}`:`${e}`}})),n.length=1}else{let g=p[s]({data:n,...h,full:r}),b=o(g);switch(n.forEach(((e,t)=>n.splice(t,1))),n.length=0,b){case"primitive":n[0]=g;break;case"array":n.push(...g)}}}}))}if(i instanceof Array&&1===i.length&&i[0]instanceof Array&&(i=i[0]),null==i[0])return;let d=o(i[0]),y=i[0];switch(d){case"primitive":if(null==y)return;u[s]=y;break;case"object":if(null==y.text)return;u[s]=y.text;break;case"array":const e=o(y[0]);u[s]="object"===e?y.map((e=>e.text)).join(""):y.join("")}}})),y?v.push(f.map((e=>u[e.index])).join("<~>")):v.push(u.join(""))})),"array"===E?v:i?i.reduce(((e,t)=>"function"!=typeof t?e:t(e,j)),v.join("")):v.join("")))}return i?[!0,b]:b}}const i={default:{}};return{build:s,get:function(e){if(!(e instanceof Array))return function(){return'Error: Argument "location" is a string. Should be an array. E.g. ["templateName", "storageName"].'};const[t,r="default"]=e;return i[r]?i[r][t]?i[r][t]:function(){return`Error: Template "${t}" does not exist in storage "${r}".`}:function(){return`Error: Storage "${r}" does not exist.`}},add:function(e,t,...r){const[n,a="default"]=e;if(null==t)return void console.warn(`Warning: Template ${a}/${n} is not added to storage. The template is null.`);let o=t,l=!0;if(i[a]||(i[a]={}),"function"!=typeof t){let e=s(t,!0,...r);l=e[0],o=e[1]}l?i[a][n]=o:console.error(`Error: Template "${n}" looks broken and is not added to storage.`)},list:function(e=["default"]){return e.map((e=>i[e]?Object.keys(i[e]):[])).flat()},clear:function(){Object.keys(i).forEach((e=>{"default"!=e?delete i[e]:i.default={}}))},remove:function(e){const[t,r="default"]=e;return i[r]?i[r][t]?void delete i[r][t]:`Error: Template "${t}" does not exist in storage "${r}".`:`Error: Storage "${r}" does not exist.`}}}));
|
|
1
|
+
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t(require("@peter.naydenov/walk")):"function"==typeof define&&define.amd?define(["@peter.naydenov/walk"],t):(e="undefined"!=typeof globalThis?globalThis:e||self).morph=t(e.walk)}(this,(function(e){"use strict";function t(e){return function t(r){const{TG_PRX:a,TG_SFX:l,TG_SIZE_P:s,TG_SIZE_S:o}=e;let i,c,u,p=[];if("string"!=typeof r)return n("notAString");if(0==r.length)return[];if(i=r.indexOf(a),0<i&&p.push(r.slice(0,i)),-1==i)return p.push(r),p;{if(u=r.indexOf(a,i+s),c=r.indexOf(l),-1==c)return n("missingClosing");if(c<i)return n("closedBeforeOpened");if(c+=o,-1!=u&&u<c)return n("newBeforeClosed");p.push(r.slice(i,c));let e=t(r.slice(c));return p.concat(e)}}}function n(e){switch(e){case"notAString":return"Error: Template is not a string.";case"missingClosing":return"Error: Placeholder with missing closing tag.";case"closedBeforeOpened":return"Error: Placeholder closing tag without starting one.";case"newBeforeClosed":return"Error: Nested placeholders. Close placeholder before open new one.";default:return"Error: Unknown template error."}}var r={TG_PRX:"{{",TG_SFX:"}}",TG_SIZE_P:2,TG_SIZE_S:2};function a(e){return null==e?"null":"string"==typeof e||"number"==typeof e||"boolean"==typeof e?"primitive":"function"==typeof e?"function":e instanceof Array?"array":e instanceof Object?"object":void 0}function*l(e,t){let n=function(e={}){let t=[],{type:n,limit:r,onLimit:a}=Object.assign({},{type:"FIFO",limit:!1,onLimit:"update"},e),l="LIFO"===n.toUpperCase(),s=!1;function o(e=1,n=0){let r=[];return n>0&&Array.from({length:n}).map((()=>t.pop())),1==e?t.pop():(Array.from({length:e}).map((()=>{let e=t.pop();null!=e&&r.push(e)})),r)}function i(e=1,n=0){let r=[],a=t.length-n;return e>1&&Array.from({length:e}).map((()=>{null!=t[a-1]&&r.push(t[a-1]),a--})),1==e?t[t.length-1]:r}function c(){}return c.prototype={pull:o,pullReverse:function(e=1,t=0){let n=o(e,t);return n instanceof Array?n.reverse():n},peek:i,peekReverse:function(e=1,t=0){const n=i(e,t);return n instanceof Array?n.reverse():n},getSize:()=>t.length,isEmpty:()=>0==t.length,reset:()=>(t=[],!0),debug:()=>[...t]},c.prototype.push=l?function(e){const n=e instanceof Array,l=n?e.length:1;let i=!1;if("full"!==a||!s){if(r&&n&&l>r&&(e=e.slice(0,-l+r)),r){const l=(n?e.length:1)+t.length;l>=r&&"full"===a&&(e=e.slice(0,-(l-r))),l>=r&&"update"===a&&(i=o(l-r))}return t=e instanceof Array?t.concat(e):t.concat([e]),s=!!r&&t.length===r,i||void 0}}:function(e){const n=e instanceof Array,l=n?e.length:1;let i=!1;if("full"!==a||!s){if(r&&n&&l>r&&(e=e.slice(l-r)),r){const l=(n?e.length:1)+t.length;l>=r&&"full"===a&&(e=e.slice(0,-(l-r))),l>=r&&"update"===a&&(i=o(l-r))}return t=n?e.reduce(((e,t)=>[t,...e]),t):[e].reduce(((e,t)=>[t,...e]),t),s=!!r&&t.length===r,i||void 0}},new c}({type:"LIFO"});for(let r=0;r<=t;r++)n.push(e[r]);for(;n&&!n.isEmpty();){let e=yield n.pull();e&&n.push(e)}}function s(e,n,a,l,o,...i){if(!a[n])return`( Error: Helper '${n}' is not available )`;if("function"==typeof a[n])return a[n]({data:e,dependencies:o,full:l,useHelper:(t,n)=>s(n||e,t,a,l,o,...i)},...i);{let l=e;return"object"==typeof e&&null!==e||(l={text:e}),function(e,n){if(null==n)return null;const a=t(r)(e),l=r;return"string"==typeof a?a:(a.forEach(((e,t)=>{if(e.includes(l.TG_PRX)){const r=e.replace(l.TG_PRX,"").replace(l.TG_SFX,"").trim();if(n.hasOwnProperty(r)&&null!=n[r]){let e=n[r];"object"==typeof e&&e.text&&(e=e.text),a[t]=e}}})),a.join(""))}(a[n],l)}}function o({name:e},t,{helpers:n,original:r,dependencies:l,useHelper:o,extendArguments:i,nestedData:c,level:u,iData:p}){const d=t;let f=a(d);const h="function"==typeof n[e];switch(f){case"array":h?d.forEach(((t,l)=>{if(null==t)return;const s=a(t),c=o(t),u=n[e]({data:t,...i,full:r,useHelper:c});null==u&&(d[l]=null),"object"===s?t.text=u:d[l]=u})):d.forEach(((t,o)=>{if(null==t)return;const i=a(t),c=s(t,e,n,r,l);null==c?d[o]=null:"object"===i?t.text=c:d[o]=c}));break;case"function":const t=d(),f=o(t);c[u]=n[e]({data:t,...i,full:d,useHelper:f});break;case"primitive":if(h){const t=o(d);c[u]=n[e]({data:d,...i,full:d,useHelper:t})}else c[u]=s(d,e,n,r,l);break;case"object":if(h){const t=o(d);c[u][p].text=n[e]({data:d,...i,full:d,useHelper:t})}else d.text=s(d,e,n,r,l)}}function i({name:e},t,{helpers:n,extendArguments:r,nestedData:l,level:s,useHelper:o}){const i=t;switch(a(i)){case"array":i.forEach(((t,a)=>{const l=o(t);i[a]=t instanceof Function?n[e]({data:t(),...r,full:t,useHelper:l}):n[e]({data:t,...r,full:t,useHelper:l})}));break;case"object":const t=o(i);l[s]=[n[e]({data:i,...r,full:i,useHelper:t})];break;case"function":const a=i(),c=o(a);l[s]=[n[e]({data:a,...r,full:i,useHelper:c})];break;case"primitive":const u=o(i);l[s]=n[e]({data:i,...r,full:i,useHelper:u})}}function c({name:t},n,{helpers:r,extendArguments:l,nestedData:s,level:o,useHelper:i}){const c=n;let u=a(c);if(""===t)switch(u){case"object":Object.keys(c).find((e=>e.includes("/")))?Object.entries(c).forEach((([e,t])=>s[o][e]=t.text)):s[o]=c.text;for(let d=o-1;d>=0;d--)s[d]=e({data:s[d],objectCallback:p});function p({value:e,breadcrumbs:t}){return s[o][t]?s[o][t]:e}break;case"array":c.forEach(((e,t)=>{if(t>0){let n=a(e);if(null==e)return;c[0]+="object"===n?`${e.text}`:`${e}`,c.toSpliced(t,1)}else{let t=a(e);if(c[0]="",null===t)return;c[0]="object"===t?`${e.text}`:`${e}`}})),c.length=1}else{const f=i(c);let h=r[t]({data:c,...l,full:c,useHelper:f}),m=a(h);switch(c.forEach(((e,t)=>c.splice(t,1))),c.length=0,m){case"primitive":c[0]=h;break;case"array":c.push(...h)}}}function u({name:e},t,{helpers:n,extendArguments:r,nestedData:a,level:l,useHelper:s}){"function"==typeof n[e]&&a[0]&&Array.isArray(a[0])&&a[0].forEach(((t,l)=>{const o=s(t);a[0][l]=n[e]({data:t,...r,full:t,useHelper:o})}))}function p({name:e},t,{memory:n}){n[e]=structuredClone(t)}function d({name:e},t){return structuredClone(t)}function f({d:t,chop:n,placeholders:r,original:f,helpers:h,dependencies:m,memory:y,args:g,onlySnippets:b}){const v=[],k=e=>(t,n)=>{let r=h[t],a=r&&"function"==typeof r&&r.length>=2;if(!r)return`( Error: Helper '${t}' is not available )`;if(a)try{return r("render",n||e,m)}catch(r){return s(n||e,t,h,f,m,...g)}return s(n||e,t,h,f,m,...g)};return t.forEach((t=>{let s=structuredClone(n),g=t;r.forEach((t=>{const{index:n,data:r,action:b}=t,v=!b;structuredClone(y);let E=g;if(r&&r.includes("/")?E.hasOwnProperty(r)?E=E[r]:r.split("/").forEach((e=>{E=E.hasOwnProperty(e)?E[e]:[]})):"@all"===r||null===r||"@root"===r?E=g:r&&(E=E[r]),v){switch(a(E)){case"function":s[n]=E();break;case"primitive":s[n]=E;break;case"array":"primitive"===a(E[0])&&(s[n]=E[0]);break;case"object":E.text&&(s[n]=E.text)}}else{let{dataDeepLevel:t,nestedData:r}=function(t,n){const r=[];let a=0;if(t instanceof Function)return{dataDeepLevel:0,nestedData:[[t()]]};if(null==t)return{dataDeepLevel:0,nestedData:[null]};if("string"==typeof t)return{dataDeepLevel:0,nestedData:[[t]]};const l=structuredClone(t);return n.includes("#")?(e({data:l,objectCallback:function({key:e,value:t,breadcrumbs:n}){return e===n?(r[0]=[t],t):(a=n.split("/").length-1,r[a]||(r[a]=[]),r[a].push(t),t)}}),{dataDeepLevel:a,nestedData:r}):(r.push([l]),{dataDeepLevel:0,nestedData:r})}(E,b),v=l(function(e,t=10){let n={},r=[...e],a=0,l=0,s=0;r.forEach((e=>{"#"===e&&s++})),s<t&&console.error(`Error: Not enough level markers (#) for data with depth level ${t}. Found ${s} level markers in actions: ${e.join(", ")}`);do{n[l]=[],l++}while(l<=t);return r.every((e=>"#"===e?(a++,!(a>t)):e.startsWith("^")&&"^^"!==e?(n[a].push({type:"save",name:e.replace("^",""),level:a}),!0):"^^"===e?(n[a].push({type:"overwrite",name:"none",level:a}),!0):e.startsWith("+")?(n[a].push({type:"extendedRender",name:e.replace("+",""),level:a}),!0):e.startsWith("[]")?(n[a].push({type:"mix",name:e.replace("[]",""),level:a}),!0):e.startsWith(">")?(n[a].push({type:"data",name:e.replace(">",""),level:a}),!0):(""===e||n[a].push({type:"render",name:e,level:a}),!0))),n}(b,t),t);if(g=function({nestedData:e,actSetup:t,helpers:n,original:r,dependencies:a,memory:l,dElement:s,createUseHelper:f}){let h=s;for(let s of t){let{type:t,name:m,level:y}=s;(e[y]||[]).forEach(((m,g)=>{const b={helpers:n,original:r,dependencies:a,memory:l,useHelper:f,nestedData:e,level:y,iData:g,extendArguments:{dependencies:a,memory:l}};switch(t){case"render":o(s,m,b);break;case"data":i(s,m,b);break;case"mix":c(s,m,b);break;case"save":p(s,m,b);break;case"overwrite":h=d(s,m);break;case"route":break;case"extendedRender":u(s,0,b)}}))}return h}({nestedData:r,actSetup:v,helpers:h,original:f,dependencies:m,memory:y,dElement:g,createUseHelper:k}),r instanceof Array&&1===r.length&&r[0]instanceof Array&&(r=r[0]),null==r[0])return;let x=a(r[0]),j=r[0];switch(x){case"primitive":if(null==j)return;s[n]=j;break;case"object":if(null==j.text)return;s[n]=j.text;break;case"array":const e=a(j[0]);s[n]="object"===e?j.map((e=>e.text)).join(""):j.join("")}}})),b?v.push(r.map((e=>s[e.index])).join("<~>")):v.push(s.join(""))})),v}function h(n,l=!1,s={}){let{hasError:o,placeholders:i,chop:c,helpers:u,handshake:p,snippets:d}=function(e){const{template:n,helpers:a={},handshake:l}=e,{TG_PRX:s,TG_SFX:o}=r,i=[],c={},u="string"==typeof n?n.replace(/<!--[\s\S]*?-->/g,"").replace(/\s{2,}/g," "):n;let p=null;const d=t(r)(u);return"string"==typeof d?p=d:d.forEach(((e,t)=>{const n=RegExp(s+"\\s*(.*?)\\s*(?::\\s*(.*?)\\s*)?(?::\\s*(.*?)\\s*)?"+o,"g");if(e.includes(s)){const a=n.exec(e);if(!a)return;let l={index:t,data:(r=a[1],r||null),action:a[2]?a[2].split(",").map((e=>e.trim())):null,name:a[3]?a[3].trim():null};i.push(l),c[i.length-1]=l,l.name&&(c[l.name]=l)}var r})),{hasError:p,placeholders:i,chop:d,helpers:a,handshake:l,snippets:c}}(n);if(o){function m(){return o}return l?[!1,m]:m}{const y=structuredClone(i);function g(t="render",n={},r={},...l){const o=structuredClone(c);let m=!1;if("string"!=typeof t)return`Error: Wrong command "${t}". Available commands: render, debug, snippets, set, curry.`;if(!["render","debug","snippets","set","curry"].includes(t)&&!t.startsWith("snippets"))return`Error: Wrong command "${t}". Available commands: render, debug, snippets, set, curry.`;if(t.startsWith("snippets")){m=!0;const e=function(e,t){if(e.includes(":"))return e.split(":").slice(1)[0].trim().split(",").map((e=>e.trim())).map((e=>t[e]));return null}(t,d);e&&(i=e)}else if("snippets"===t)m=!0;else{if("set"===t)return function(e,{helpers:t,handshake:n,placeholders:r,chop:a,build:l,buildDependencies:s}){if("object"!=typeof e||!e)return"Error: 'set' command requires an object with placeholders, helpers, handshake.";const o={...t,...e.helpers||{}},i=n?{...n,...e.handshake||{}}:e.handshake||{},c=[...a];e.placeholders&&Object.entries(e.placeholders).forEach((([e,t])=>{if(isNaN(e)){let n=r.find((t=>t.name===e));c[n.index]=t}else{let n=r[e].index;c[n]=t}}));const u=l({template:c.join(""),helpers:o,handshake:i},!1,s);return"function"==typeof u?u:()=>u}(n,{helpers:u,handshake:p,placeholders:i,chop:c,build:h,buildDependencies:s});if("curry"===t){return h({template:g("render",n,r,...l),helpers:u,handshake:p},!1,s)}i=structuredClone(y)}if("string"==typeof n){const e=function(e,{handshake:t,helpers:n,placeholders:r,cuts:a}){switch(e){case"raw":return a.join("");case"demo":return t||"Error: No handshake data.";case"handshake":return t?structuredClone(t):"Error: No handshake data.";case"helpers":return Object.keys(n).join(", ");case"placeholders":return r.map((e=>a[e.index])).join(", ");case"count":return r.length;default:return`Error: Wrong instruction "${e}". Available instructions: raw, demo, handshake, helpers, placeholders, count.`}}(n,{handshake:p,helpers:u,placeholders:i,cuts:o});if("demo"!==n||"object"!=typeof e)return e;n=e}let b=a(n),v={...s,...r};n=e({data:n});let k=e({data:n});if("null"===b)return o.join("");if("array"!==b&&(n=[n]),"null"===b)return o.join("");const E=f({d:n,chop:c,placeholders:i,original:k,helpers:u,dependencies:v,memory:{},args:l,onlySnippets:m});return"array"===b?E:l?l.reduce(((e,t)=>"function"!=typeof t?e:t(e,v)),E.join("")):E.join("")}return l?[!0,g]:g}}const m={default:{}};return{build:h,get:function(e){if(!(e instanceof Array))return function(){return'Error: Argument "location" is a string. Should be an array. E.g. ["templateName", "storageName"].'};const[t,n="default"]=e;return m[n]?m[n][t]?m[n][t]:function(){return`Error: Template "${t}" does not exist in storage "${n}".`}:function(){return`Error: Storage "${n}" does not exist.`}},add:function(e,t,...n){const[r,a="default"]=e;if(null==t)return void console.warn(`Warning: Template ${a}/${r} is not added to storage. The template is null.`);let l=t,s=!0;if(m[a]||(m[a]={}),"function"!=typeof t){let e=h(t,!0,...n);s=e[0],l=e[1]}s?m[a][r]=l:console.error(`Error: Template "${r}" looks broken and is not added to storage.`)},list:function(e=["default"]){return e.map((e=>m[e]?Object.keys(m[e]):[])).flat()},clear:function(){Object.keys(m).forEach((e=>{"default"!=e?delete m[e]:m.default={}}))},remove:function(e){const[t,n="default"]=e;return m[n]?m[n][t]?void delete m[n][t]:`Error: Template "${t}" does not exist in storage "${n}".`:`Error: Storage "${n}" does not exist.`}}}));
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
export default morphAPI;
|
|
2
|
+
declare namespace morphAPI {
|
|
3
|
+
export { build };
|
|
4
|
+
export { get };
|
|
5
|
+
export { add };
|
|
6
|
+
export { list };
|
|
7
|
+
export { clear };
|
|
8
|
+
export { remove };
|
|
9
|
+
}
|
|
10
|
+
import build from "./methods/build.js";
|
|
11
|
+
/**
|
|
12
|
+
* Retrieves a template from storage.
|
|
13
|
+
*
|
|
14
|
+
* @param {string[]} location - The location of the template. Array of two elements:
|
|
15
|
+
* - First element: The name of the template
|
|
16
|
+
* - Second element (optional): The name of the storage. Defaults to 'default'
|
|
17
|
+
*
|
|
18
|
+
* @returns {Function} The template (render function) if found, or an error function that returns
|
|
19
|
+
* an error message if the storage or template doesn't exist.
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* // Get template from default storage
|
|
23
|
+
* const template = get(['myTemplate']);
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* // Get template from custom storage
|
|
27
|
+
* const template = get(['myTemplate', 'customStorage']);
|
|
28
|
+
*/
|
|
29
|
+
declare function get(location: string[]): Function;
|
|
30
|
+
/**
|
|
31
|
+
* Adds a template to storage.
|
|
32
|
+
*
|
|
33
|
+
* If the template is already a function, it's added directly to storage.
|
|
34
|
+
* If it's a template description object, it's built first and then added.
|
|
35
|
+
* If the template is null or broken, a warning/error is logged and it's not added.
|
|
36
|
+
*
|
|
37
|
+
* @param {string[]} location - The location to add the template to. Array of two elements:
|
|
38
|
+
* - First element: The name of the template
|
|
39
|
+
* - Second element (optional): The name of the storage. Defaults to 'default'
|
|
40
|
+
* @param {object|function|null} tplfn - The template description object, pre-built template function, or null
|
|
41
|
+
* @param {...any} args - Additional arguments passed to the build function (only used when tplfn is a template description)
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* // Add a pre-built template function
|
|
45
|
+
* add(['myTemplate'], templateFunction);
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* // Add and build a template description
|
|
49
|
+
* add(['myTemplate'], {
|
|
50
|
+
* template: 'Hello {{name}}!',
|
|
51
|
+
* helpers: { name: (data) => data.data.name }
|
|
52
|
+
* });
|
|
53
|
+
*/
|
|
54
|
+
declare function add(location: string[], tplfn: object | Function | null, ...args: any[]): void;
|
|
55
|
+
/**
|
|
56
|
+
* Returns an array of template names from specified storages.
|
|
57
|
+
*
|
|
58
|
+
* @param {string[]} [storageNames=['default']] - Array of storage names to retrieve template names from.
|
|
59
|
+
* Defaults to ['default'] if not provided.
|
|
60
|
+
*
|
|
61
|
+
* @returns {string[]} Array of all template names from the specified storages.
|
|
62
|
+
*
|
|
63
|
+
* @example
|
|
64
|
+
* // List templates from default storage
|
|
65
|
+
* const templates = list();
|
|
66
|
+
*
|
|
67
|
+
* @example
|
|
68
|
+
* // List templates from multiple storages
|
|
69
|
+
* const templates = list(['default', 'customStorage']);
|
|
70
|
+
*/
|
|
71
|
+
declare function list(storageNames?: string[]): string[];
|
|
72
|
+
/**
|
|
73
|
+
* Clears all templates from all storages.
|
|
74
|
+
*
|
|
75
|
+
* Deletes all custom storages and resets the 'default' storage to an empty object.
|
|
76
|
+
*
|
|
77
|
+
* @example
|
|
78
|
+
* // Clear all templates
|
|
79
|
+
* clear();
|
|
80
|
+
*/
|
|
81
|
+
declare function clear(): void;
|
|
82
|
+
/**
|
|
83
|
+
* Removes a template from storage.
|
|
84
|
+
*
|
|
85
|
+
* @param {string[]} location - The location of the template to remove. Array of two elements:
|
|
86
|
+
* - First element: The name of the template
|
|
87
|
+
* - Second element (optional): The name of the storage. Defaults to 'default'
|
|
88
|
+
*
|
|
89
|
+
* @returns {void|string} Returns an error message if the storage or template doesn't exist,
|
|
90
|
+
* otherwise returns undefined.
|
|
91
|
+
*
|
|
92
|
+
* @example
|
|
93
|
+
* // Remove template from default storage
|
|
94
|
+
* remove(['myTemplate']);
|
|
95
|
+
*
|
|
96
|
+
* @example
|
|
97
|
+
* // Remove template from custom storage
|
|
98
|
+
* remove(['myTemplate', 'customStorage']);
|
|
99
|
+
*/
|
|
100
|
+
declare function remove(location: string[]): void | string;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export default _actionSupply;
|
|
2
|
+
/**
|
|
3
|
+
* Generator function that supplies actions in a controlled sequence using a stack.
|
|
4
|
+
*
|
|
5
|
+
* Manages the flow of actions through different processing levels, allowing for
|
|
6
|
+
* dynamic action insertion during processing.
|
|
7
|
+
*
|
|
8
|
+
* @param {Object} act - Object containing action arrays organized by level
|
|
9
|
+
* @param {number} level - Maximum processing level
|
|
10
|
+
* @returns {Generator} Generator that yields action objects in sequence
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* const generator = _actionSupply(actionSetup, 2);
|
|
14
|
+
* for (const action of generator) {
|
|
15
|
+
* // Process each action
|
|
16
|
+
* }
|
|
17
|
+
*/
|
|
18
|
+
declare function _actionSupply(act: any, level: number): Generator;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export default _chopTemplate;
|
|
2
|
+
/**
|
|
3
|
+
* Creates a template chopping function that splits text into parts and placeholders.
|
|
4
|
+
*
|
|
5
|
+
* @param {object} settings - Configuration object containing template delimiters
|
|
6
|
+
* @param {string} settings.TG_PRX - Opening delimiter (e.g., '{{')
|
|
7
|
+
* @param {string} settings.TG_SFX - Closing delimiter (e.g., '}}')
|
|
8
|
+
* @param {number} settings.TG_SIZE_P - Length of opening delimiter
|
|
9
|
+
* @param {number} settings.TG_SIZE_S - Length of closing delimiter
|
|
10
|
+
*
|
|
11
|
+
* @returns {Function} Function that chops template text into array parts
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* const chop = _chopTemplate(settings);
|
|
15
|
+
* const result = chop('Hello {{name}}!');
|
|
16
|
+
*/
|
|
17
|
+
declare function _chopTemplate(settings: {
|
|
18
|
+
TG_PRX: string;
|
|
19
|
+
TG_SFX: string;
|
|
20
|
+
TG_SIZE_P: number;
|
|
21
|
+
TG_SIZE_S: number;
|
|
22
|
+
}): Function;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export default _defineData;
|
|
2
|
+
/**
|
|
3
|
+
* Processes data source based on action requirements and creates nested data structure.
|
|
4
|
+
*
|
|
5
|
+
* Analyzes the data source and action to determine if nested data processing is needed.
|
|
6
|
+
* If action contains '#', it walks through the data structure to collect nested objects.
|
|
7
|
+
*
|
|
8
|
+
* @param {any} dSource - The data source to process (function, null, string, or object)
|
|
9
|
+
* @param {string} action - Action string that may contain '#' indicating nested processing
|
|
10
|
+
*
|
|
11
|
+
* @returns {object} Data processing result containing:
|
|
12
|
+
* - dataDeepLevel: Maximum nesting level found
|
|
13
|
+
* - nestedData: Array of nested data arrays organized by level
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* // Simple data without nesting
|
|
17
|
+
* const result = _defineData('hello', 'render');
|
|
18
|
+
* // Returns: { dataDeepLevel: 0, nestedData: [['hello']] }
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* // Nested data with '#' action
|
|
22
|
+
* const result = _defineData({ user: { name: 'John' } }, 'render:#');
|
|
23
|
+
* // Returns: { dataDeepLevel: 1, nestedData: [[{ name: 'John' }]] }
|
|
24
|
+
*/
|
|
25
|
+
declare function _defineData(dSource: any, action: string): object;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export default _defineDataType;
|
|
2
|
+
/**
|
|
3
|
+
* Determines the data type of a value for template processing.
|
|
4
|
+
*
|
|
5
|
+
* @param {any} data - Value to type-check
|
|
6
|
+
* @returns {string|undefined} Returns one of: 'null', 'primitive', 'function', 'array', 'object', or undefined
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* _defineDataType(null); // 'null'
|
|
10
|
+
* _defineDataType('hello'); // 'primitive'
|
|
11
|
+
* _defineDataType([1,2,3]); // 'array'
|
|
12
|
+
* _defineDataType({}); // 'object'
|
|
13
|
+
* _defineDataType(() => {}); // 'function'
|
|
14
|
+
*/
|
|
15
|
+
declare function _defineDataType(data: any): string | undefined;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export default _readTemplate;
|
|
2
|
+
/**
|
|
3
|
+
* Parses and validates a template description object.
|
|
4
|
+
*
|
|
5
|
+
* Extracts placeholders, validates helpers, and prepares template for building.
|
|
6
|
+
*
|
|
7
|
+
* @param {object} tpl - Template description object
|
|
8
|
+
* @param {string} tpl.template - Template string with placeholders
|
|
9
|
+
* @param {object} [tpl.helpers={}] - Optional helper functions
|
|
10
|
+
* @param {object} [tpl.handshake] - Optional example data
|
|
11
|
+
*
|
|
12
|
+
* @returns {object} Template parsing result containing:
|
|
13
|
+
* - hasError: Error message or null
|
|
14
|
+
* - placeholders: Array of placeholder objects
|
|
15
|
+
* - chop: Array of template parts
|
|
16
|
+
* - helpers: Helper functions object
|
|
17
|
+
* - handshake: Example data object
|
|
18
|
+
* - snippets: Object mapping snippet names to placeholders
|
|
19
|
+
*/
|
|
20
|
+
declare function _readTemplate(tpl: {
|
|
21
|
+
template: string;
|
|
22
|
+
helpers?: object;
|
|
23
|
+
handshake?: object;
|
|
24
|
+
}): object;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export default _renderHolder;
|
|
2
|
+
/**
|
|
3
|
+
* Renders a simple template by replacing placeholders with data values.
|
|
4
|
+
*
|
|
5
|
+
* Processes templates with basic placeholder substitution without actions or helpers.
|
|
6
|
+
* Only supports direct field replacement from the data object.
|
|
7
|
+
*
|
|
8
|
+
* @param {string} template - Template string with placeholders
|
|
9
|
+
* @param {object} data - Data object containing values for placeholder replacement
|
|
10
|
+
*
|
|
11
|
+
* @returns {string|null} Rendered template string or null if data is null
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* const result = _renderHolder('Hello {{name}}!', { name: 'World' });
|
|
15
|
+
* // Returns: 'Hello World!'
|
|
16
|
+
*/
|
|
17
|
+
declare function _renderHolder(template: string, data: object): string | null;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export default _setupActions;
|
|
2
|
+
/**
|
|
3
|
+
* Parses and organizes template actions into a structured setup by processing level.
|
|
4
|
+
*
|
|
5
|
+
* Converts action strings into structured objects with types and levels. Validates that
|
|
6
|
+
* there are enough level markers (#) for the data depth.
|
|
7
|
+
*
|
|
8
|
+
* @param {string[]} actions - Array of action strings to process
|
|
9
|
+
* @param {number} [dataDeepLevel=10] - Maximum depth level for nested data processing
|
|
10
|
+
*
|
|
11
|
+
* @returns {Object} Object with numeric keys containing arrays of action objects by level
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* const setup = _setupActions(['render', '#', 'save:var'], 2);
|
|
15
|
+
* // Returns: { 0: [{type: 'render', name: 'render', level: 0}],
|
|
16
|
+
* // 1: [{type: 'save', name: 'var', level: 1}],
|
|
17
|
+
* // 2: [] }
|
|
18
|
+
*/
|
|
19
|
+
declare function _setupActions(actions: string[], dataDeepLevel?: number): any;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export default actionData;
|
|
2
|
+
declare function actionData({ name }: {
|
|
3
|
+
name: any;
|
|
4
|
+
}, levelData: any, { helpers, extendArguments, nestedData, level, useHelper }: {
|
|
5
|
+
helpers: any;
|
|
6
|
+
extendArguments: any;
|
|
7
|
+
nestedData: any;
|
|
8
|
+
level: any;
|
|
9
|
+
useHelper: any;
|
|
10
|
+
}): void;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export default actionExtendedRender;
|
|
2
|
+
declare function actionExtendedRender({ name }: {
|
|
3
|
+
name: any;
|
|
4
|
+
}, levelData: any, { helpers, extendArguments, nestedData, level, useHelper }: {
|
|
5
|
+
helpers: any;
|
|
6
|
+
extendArguments: any;
|
|
7
|
+
nestedData: any;
|
|
8
|
+
level: any;
|
|
9
|
+
useHelper: any;
|
|
10
|
+
}): void;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export default actionMix;
|
|
2
|
+
declare function actionMix({ name }: {
|
|
3
|
+
name: any;
|
|
4
|
+
}, levelData: any, { helpers, extendArguments, nestedData, level, useHelper }: {
|
|
5
|
+
helpers: any;
|
|
6
|
+
extendArguments: any;
|
|
7
|
+
nestedData: any;
|
|
8
|
+
level: any;
|
|
9
|
+
useHelper: any;
|
|
10
|
+
}): void;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export default actionRender;
|
|
2
|
+
declare function actionRender({ name }: {
|
|
3
|
+
name: any;
|
|
4
|
+
}, levelData: any, { helpers, original, dependencies, useHelper, extendArguments, nestedData, level, iData }: {
|
|
5
|
+
helpers: any;
|
|
6
|
+
original: any;
|
|
7
|
+
dependencies: any;
|
|
8
|
+
useHelper: any;
|
|
9
|
+
extendArguments: any;
|
|
10
|
+
nestedData: any;
|
|
11
|
+
level: any;
|
|
12
|
+
iData: any;
|
|
13
|
+
}): void;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
export default build;
|
|
2
|
+
export type UseHelperFn = (name: string, data?: any) => any;
|
|
3
|
+
export type HelperFn = (args: {
|
|
4
|
+
data: any;
|
|
5
|
+
dependencies: object;
|
|
6
|
+
full?: any;
|
|
7
|
+
useHelper?: UseHelperFn;
|
|
8
|
+
memory?: object;
|
|
9
|
+
}) => any;
|
|
10
|
+
export type Template = {
|
|
11
|
+
/**
|
|
12
|
+
* - Data to be rendered;
|
|
13
|
+
*/
|
|
14
|
+
template: string;
|
|
15
|
+
/**
|
|
16
|
+
* - Optional. Object with helper functions or simple templates for this template;
|
|
17
|
+
*/
|
|
18
|
+
helpers?: {
|
|
19
|
+
[x: string]: string | HelperFn;
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* - Optional. Example for data to be rendered with;
|
|
23
|
+
*/
|
|
24
|
+
handshake?: object;
|
|
25
|
+
};
|
|
26
|
+
export type tupleResult = any[];
|
|
27
|
+
/**
|
|
28
|
+
* @callback UseHelperFn
|
|
29
|
+
* @param {string} name - Name of the helper to call.
|
|
30
|
+
* @param {any} [data] - Optional data override.
|
|
31
|
+
* @returns {any} Result of the helper call.
|
|
32
|
+
*/
|
|
33
|
+
/**
|
|
34
|
+
* @callback HelperFn
|
|
35
|
+
* @param {object} args
|
|
36
|
+
* @param {any} args.data - The data context.
|
|
37
|
+
* @param {object} args.dependencies - Injected dependencies.
|
|
38
|
+
* @param {any} [args.full] - Full data context.
|
|
39
|
+
* @param {UseHelperFn} [args.useHelper] - Function to call other helpers.
|
|
40
|
+
* @param {object} [args.memory] - internal memory state.
|
|
41
|
+
* @returns {any} Rendered output.
|
|
42
|
+
*/
|
|
43
|
+
/**
|
|
44
|
+
* @typedef {Object} Template
|
|
45
|
+
* @property {string} template - Data to be rendered;
|
|
46
|
+
* @property {Object.<string, HelperFn|string>} [helpers] - Optional. Object with helper functions or simple templates for this template;
|
|
47
|
+
* @property {object} [handshake] - Optional. Example for data to be rendered with;
|
|
48
|
+
*/
|
|
49
|
+
/**
|
|
50
|
+
* @typedef {Array} tupleResult
|
|
51
|
+
* @property {boolean} 0 - Indicates success (true) or failure (false).
|
|
52
|
+
* @property {function} 1 - The rendering function or an error function.
|
|
53
|
+
*/
|
|
54
|
+
/**
|
|
55
|
+
*
|
|
56
|
+
* @param {Template} tpl - template definition;
|
|
57
|
+
* @param {boolean} [extra] - Optional. How to receive the answer - false:as a string(answer) or true: as tuple[success, answer];
|
|
58
|
+
* @param {object} [buildDependencies] - Optional. External dependencies injected;
|
|
59
|
+
* @returns {function|tupleResult} - rendering function
|
|
60
|
+
*/
|
|
61
|
+
declare function build(tpl: Template, extra?: boolean, buildDependencies?: object): Function | tupleResult;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export default executeActions;
|
|
2
|
+
declare function executeActions({ nestedData, actSetup, helpers, original, dependencies, memory, dElement, createUseHelper }: {
|
|
3
|
+
nestedData: any;
|
|
4
|
+
actSetup: any;
|
|
5
|
+
helpers: any;
|
|
6
|
+
original: any;
|
|
7
|
+
dependencies: any;
|
|
8
|
+
memory: any;
|
|
9
|
+
dElement: any;
|
|
10
|
+
createUseHelper: any;
|
|
11
|
+
}): any;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Handles debug commands for template inspection.
|
|
3
|
+
*
|
|
4
|
+
* @param {string} d - Debug instruction
|
|
5
|
+
* @param {object} context - Context object
|
|
6
|
+
* @param {object} context.handshake - Example data
|
|
7
|
+
* @param {object} context.helpers - Helper functions
|
|
8
|
+
* @param {array} context.placeholders - Placeholder definitions
|
|
9
|
+
* @param {array} context.cuts - Chopped template parts
|
|
10
|
+
* @returns {any} Debug result or error message
|
|
11
|
+
*/
|
|
12
|
+
export function handleDebug(d: string, { handshake, helpers, placeholders, cuts }: {
|
|
13
|
+
handshake: object;
|
|
14
|
+
helpers: object;
|
|
15
|
+
placeholders: any[];
|
|
16
|
+
cuts: any[];
|
|
17
|
+
}): any;
|
|
18
|
+
/**
|
|
19
|
+
* Handles the 'set' command to modify template properties.
|
|
20
|
+
*
|
|
21
|
+
* @param {object} d - Modification data
|
|
22
|
+
* @param {object} context - Context object
|
|
23
|
+
* @param {object} context.helpers - Current helper functions
|
|
24
|
+
* @param {object} context.handshake - Current handshake data
|
|
25
|
+
* @param {array} context.placeholders - Current placeholders
|
|
26
|
+
* @param {array} context.chop - Current chopped template
|
|
27
|
+
* @param {function} context.build - Build function
|
|
28
|
+
* @param {object} context.buildDependencies - Build dependencies
|
|
29
|
+
* @returns {function} Modified template function
|
|
30
|
+
*/
|
|
31
|
+
export function handleSet(d: object, { helpers, handshake, placeholders, chop, build, buildDependencies }: {
|
|
32
|
+
helpers: object;
|
|
33
|
+
handshake: object;
|
|
34
|
+
placeholders: any[];
|
|
35
|
+
chop: any[];
|
|
36
|
+
build: Function;
|
|
37
|
+
buildDependencies: object;
|
|
38
|
+
}): Function;
|
|
39
|
+
/**
|
|
40
|
+
* Handles snippets command to select specific placeholders.
|
|
41
|
+
*
|
|
42
|
+
* @param {string} command - Snippets command
|
|
43
|
+
* @param {object} snippets - Snippets mapping
|
|
44
|
+
* @returns {array|null} Selected placeholders or null
|
|
45
|
+
*/
|
|
46
|
+
export function handleSnippets(command: string, snippets: object): any[] | null;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export default processPlaceholders;
|
|
2
|
+
/**
|
|
3
|
+
* Processes placeholders in the template with provided data and context.
|
|
4
|
+
*
|
|
5
|
+
* @param {object} params - Parameters object
|
|
6
|
+
* @param {array} params.d - Data array to process
|
|
7
|
+
* @param {array} params.chop - Chopped template parts
|
|
8
|
+
* @param {array} params.placeholders - Placeholder definitions
|
|
9
|
+
* @param {any} params.original - Original data context
|
|
10
|
+
* @param {object} params.helpers - Helper functions
|
|
11
|
+
* @param {object} params.dependencies - Injected dependencies
|
|
12
|
+
* @param {object} params.memory - Internal memory state
|
|
13
|
+
* @param {array} params.args - Additional arguments
|
|
14
|
+
* @param {boolean} params.onlySnippets - Whether to process only snippets
|
|
15
|
+
* @returns {array} Processed template parts
|
|
16
|
+
*/
|
|
17
|
+
declare function processPlaceholders({ d, chop, placeholders, original, helpers, dependencies, memory, args, onlySnippets }: {
|
|
18
|
+
d: any[];
|
|
19
|
+
chop: any[];
|
|
20
|
+
placeholders: any[];
|
|
21
|
+
original: any;
|
|
22
|
+
helpers: object;
|
|
23
|
+
dependencies: object;
|
|
24
|
+
memory: object;
|
|
25
|
+
args: any[];
|
|
26
|
+
onlySnippets: boolean;
|
|
27
|
+
}): any[];
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export default render;
|
|
2
|
+
/**
|
|
3
|
+
* Renders a helper or template with the provided data and context.
|
|
4
|
+
*
|
|
5
|
+
* @param {any} theData - The data to process.
|
|
6
|
+
* @param {string} name - The name of the helper or template to render.
|
|
7
|
+
* @param {object} helpers - Dictionary of available helpers.
|
|
8
|
+
* @param {any} original - The full original data context.
|
|
9
|
+
* @param {object} dependencies - injected dependencies.
|
|
10
|
+
* @param {...any} args - Additional arguments.
|
|
11
|
+
*
|
|
12
|
+
* @returns {any} The result of the rendering process, or an error string if the helper is not available.
|
|
13
|
+
*/
|
|
14
|
+
declare function render(theData: any, name: string, helpers: object, original: any, dependencies: object, ...args: any[]): any;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
/opt/homebrew/opt/python@3.14/bin/python3.14
|