@peter.naydenov/cuts 1.2.4 → 1.2.6
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/Changelog.md +5 -0
- package/dist/cuts.cjs +1 -1
- package/dist/cuts.esm.mjs +1 -1
- package/dist/cuts.umd.js +1 -1
- package/package.json +5 -5
- package/src/methods/setScenes.js +7 -1
- package/types/methods/setScenes.d.ts.map +1 -1
- package/test/01-general.cy.js +0 -243
- package/test/blue.vue +0 -13
- package/test/dummy.vue +0 -34
- package/test/gray.vue +0 -12
- package/test/red.vue +0 -11
- package/test-mocha/01-findPosition.js +0 -109
package/Changelog.md
CHANGED
package/dist/cuts.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var e=require("@peter.naydenov/shortcuts"),n=require("ask-for-promise"),r=require("@peter.naydenov/log");function*t(e,n,r,t){let s=null;if(null===e)return yield*t.map((e=>[e,"show"])),void(yield[r,"show"]);if(!t||0===t.length)return n?(yield[e,"hide"],n.reverse(),yield*n.map((e=>[e,"hide"])),void(yield[r,"show"])):(yield[e,"hide"],void(yield[r,"show"]));if(t.includes(e)){for(let n=t.indexOf(e)+1;n<t.length;n++)yield[t[n],"show"];yield[r,"show"]}else{if(!n)return yield[e,"hide"],void(yield*t.map((e=>[e,"show"])));if(t.every(((e,r)=>n[r]===t[r]&&(s=r,!0))),null==s)return yield[e,"hide"],n.reverse(),yield*n.map((e=>[e,"hide"])),yield*t.map((e=>[e,"show"])),void(yield[r,"show"]);yield[e,"hide"];for(let e=n.length;e>s+1;e--)yield[n[e-1],"hide"];for(let e=s+1;e<t.length;e++)yield[t[e],"show"];yield[r,"show"]}}function s(e){return function(n,...r){const{askForPromise:t,deps:s}=e;return function(){const e=t();return n({task:e,dependencies:s()},...r),e.promise}}}function o(e,n){return function(e){const{scenes:r,sceneNames:t}=n;if(!t.has(e))return null;const{show:s,hide:o,parents:i,beforeUnload:c,afterLoad:u,...
|
|
1
|
+
"use strict";var e=require("@peter.naydenov/shortcuts"),n=require("ask-for-promise"),r=require("@peter.naydenov/log");function*t(e,n,r,t){let s=null;if(null===e)return yield*t.map((e=>[e,"show"])),void(yield[r,"show"]);if(!t||0===t.length)return n?(yield[e,"hide"],n.reverse(),yield*n.map((e=>[e,"hide"])),void(yield[r,"show"])):(yield[e,"hide"],void(yield[r,"show"]));if(t.includes(e)){for(let n=t.indexOf(e)+1;n<t.length;n++)yield[t[n],"show"];yield[r,"show"]}else{if(!n)return yield[e,"hide"],void(yield*t.map((e=>[e,"show"])));if(t.every(((e,r)=>n[r]===t[r]&&(s=r,!0))),null==s)return yield[e,"hide"],n.reverse(),yield*n.map((e=>[e,"hide"])),yield*t.map((e=>[e,"show"])),void(yield[r,"show"]);yield[e,"hide"];for(let e=n.length;e>s+1;e--)yield[n[e-1],"hide"];for(let e=s+1;e<t.length;e++)yield[t[e],"show"];yield[r,"show"]}}function s(e){return function(n,...r){const{askForPromise:t,deps:s}=e;return function(){const e=t();return n({task:e,dependencies:s()},...r),e.promise}}}function o(e,n){return function(e){const{scenes:r,sceneNames:t}=n;if(!t.has(e))return null;const{show:s,hide:o,parents:i,beforeUnload:c,afterLoad:u,...l}=r[e];return Object.keys(l)}}module.exports=function(i={logLevel:0}){const c=e.shortcuts(),u=i.logLevel||0,l=r({level:u}),d={currentScene:null,currentParents:null,sceneNames:new Set,scenes:{},opened:!1},a={},p={shortcutMngr:c,API:a,inAPI:{},findInstructions:t,askForPromise:n,setInstruction:s({askForPromise:n,deps:c.getDependencies}),log:l};return a.hide=function(e,n){return function(r=1){const{askForPromise:t,shortcutMngr:s,setInstruction:o}=e,{currentScene:i,currentParents:c,scenes:u}=n,l=t(),d=[],a=c.length>0;let p;return s.pause(),d.push(o(u[i].hide)),a||(n.currentScene=null),a&&"*"===r&&[...c].reverse().forEach((e=>{p=n.currentParents.pop(),n.currentScene=p,d.push(o(u[e].hide))})),a&&!["*",1].includes(r)&&c.slice("-"+(r-1)).reverse().map((e=>{p=n.currentParents.pop(),n.currentScene=p,d.push(o(u[e].hide))})),(r=t.sequence(d)).onComplete((()=>{s.changeContext(n.currentScene),l.done()})),l.promise}}(p,d),a.listShortcuts=o(0,d),a.listShortcuts=o(0,d),a.setScenes=function(e,n){return function(r){const{shortcutMngr:t}=e;r.forEach((e=>{if(null==e)return;const{name:r,scene:s}=e;if(null==s)return void console.warn(`Scene ${r} is not defined`);s.parents||(s.parents=[]),n.scenes[r]=s,n.sceneNames.add(r);const{show:o,hide:i,parents:c,...u}=s,l={};l[r]=u,t.load(l)}))}}(p,d),a.show=function(e,n){return function({scene:r,options:t={ssr:!1}},...s){const{shortcutMngr:o,askForPromise:i,log:c,findInstructions:u,setInstruction:l}=e,d=i(),a=i(),{opened:p,scenes:h,sceneNames:f,currentPage:m}=n;if(m){const e=h[m].beforeHide;"function"==typeof e&&e({done:a.done,dependencies:o.getDependencies()})}else a.done(!0);return a.onComplete((e=>{if(!e)return d.done(),d.promise;if(!f.has(r)&&c)return c({message:`Scene ${r} is not available.`,level:1,type:"error"}),d.done(),d.promise;if(!p&&t.ssr)return n.opened=!0,n.currentPage=r,o.changeContext(r),d.done(),d.promise;const{show:a,parents:m=[]}=h[r];if("*"===m[0])return a().then((()=>d.done())),n.currentParents.push(n.currentPage),n.currentPage=r,d.promise;function g([e,r]){if("show"===r)n.currentScene&&n.currentParents.push(n.currentScene),n.currentScene=e;else{let e=n.currentParents.pop();n.currentScene=e}return h[e][r]}m.forEach((e=>f.has(e))),n.currentParents||(n.currentParents=[]);const y=u(n.currentScene,n.currentParents,r,m),P=[];for(let e of y)[e].map(g).map((e=>P.push(l(e),...s)));i.sequence(P).onComplete((()=>{n.opened=!0,o.changeContext(r),"function"==typeof h[r].afterShow&&h[r].afterShow({dependencies:o.getDependencies(),done:()=>{}}),d.done()}))})),d.promise}}(p,d),a.loadPlugins=async function(e){const n=e.map((e=>`plugin${e}`)),r=await import("@peter.naydenov/shortcuts");return n.map((e=>r[e]))},a.setDependencies=e=>c.setDependencies(e),a.getDependencies=()=>c.getDependencies(),a.setNote=n=>e.shortcuts.setNote(n),a.listScenes=()=>[...d.sceneNames],a.enablePlugin=(e,n)=>c.enablePlugin(e,n),a.disablePlugin=e=>c.disablePlugin(e),a.emit=(e,...n)=>c.emit(e,...n),a};
|
package/dist/cuts.esm.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{shortcuts as e}from"@peter.naydenov/shortcuts";import n from"ask-for-promise";import r from"@peter.naydenov/log";function*t(e,n,r,t){let s=null;if(null===e)return yield*t.map((e=>[e,"show"])),void(yield[r,"show"]);if(!t||0===t.length)return n?(yield[e,"hide"],n.reverse(),yield*n.map((e=>[e,"hide"])),void(yield[r,"show"])):(yield[e,"hide"],void(yield[r,"show"]));if(t.includes(e)){for(let n=t.indexOf(e)+1;n<t.length;n++)yield[t[n],"show"];yield[r,"show"]}else{if(!n)return yield[e,"hide"],void(yield*t.map((e=>[e,"show"])));if(t.every(((e,r)=>n[r]===t[r]&&(s=r,!0))),null==s)return yield[e,"hide"],n.reverse(),yield*n.map((e=>[e,"hide"])),yield*t.map((e=>[e,"show"])),void(yield[r,"show"]);yield[e,"hide"];for(let e=n.length;e>s+1;e--)yield[n[e-1],"hide"];for(let e=s+1;e<t.length;e++)yield[t[e],"show"];yield[r,"show"]}}function s(e){return function(n,...r){const{askForPromise:t,deps:s}=e;return function(){const e=t();return n({task:e,dependencies:s()},...r),e.promise}}}function o(e,n){return function(e){const{scenes:r,sceneNames:t}=n;if(!t.has(e))return null;const{show:s,hide:o,parents:i,beforeUnload:c,afterLoad:u,...
|
|
1
|
+
import{shortcuts as e}from"@peter.naydenov/shortcuts";import n from"ask-for-promise";import r from"@peter.naydenov/log";function*t(e,n,r,t){let s=null;if(null===e)return yield*t.map((e=>[e,"show"])),void(yield[r,"show"]);if(!t||0===t.length)return n?(yield[e,"hide"],n.reverse(),yield*n.map((e=>[e,"hide"])),void(yield[r,"show"])):(yield[e,"hide"],void(yield[r,"show"]));if(t.includes(e)){for(let n=t.indexOf(e)+1;n<t.length;n++)yield[t[n],"show"];yield[r,"show"]}else{if(!n)return yield[e,"hide"],void(yield*t.map((e=>[e,"show"])));if(t.every(((e,r)=>n[r]===t[r]&&(s=r,!0))),null==s)return yield[e,"hide"],n.reverse(),yield*n.map((e=>[e,"hide"])),yield*t.map((e=>[e,"show"])),void(yield[r,"show"]);yield[e,"hide"];for(let e=n.length;e>s+1;e--)yield[n[e-1],"hide"];for(let e=s+1;e<t.length;e++)yield[t[e],"show"];yield[r,"show"]}}function s(e){return function(n,...r){const{askForPromise:t,deps:s}=e;return function(){const e=t();return n({task:e,dependencies:s()},...r),e.promise}}}function o(e,n){return function(e){const{scenes:r,sceneNames:t}=n;if(!t.has(e))return null;const{show:s,hide:o,parents:i,beforeUnload:c,afterLoad:u,...l}=r[e];return Object.keys(l)}}function i(i={logLevel:0}){const c=e(),u=i.logLevel||0,l=r({level:u}),d={currentScene:null,currentParents:null,sceneNames:new Set,scenes:{},opened:!1},a={},p={shortcutMngr:c,API:a,inAPI:{},findInstructions:t,askForPromise:n,setInstruction:s({askForPromise:n,deps:c.getDependencies}),log:l};return a.hide=function(e,n){return function(r=1){const{askForPromise:t,shortcutMngr:s,setInstruction:o}=e,{currentScene:i,currentParents:c,scenes:u}=n,l=t(),d=[],a=c.length>0;let p;return s.pause(),d.push(o(u[i].hide)),a||(n.currentScene=null),a&&"*"===r&&[...c].reverse().forEach((e=>{p=n.currentParents.pop(),n.currentScene=p,d.push(o(u[e].hide))})),a&&!["*",1].includes(r)&&c.slice("-"+(r-1)).reverse().map((e=>{p=n.currentParents.pop(),n.currentScene=p,d.push(o(u[e].hide))})),(r=t.sequence(d)).onComplete((()=>{s.changeContext(n.currentScene),l.done()})),l.promise}}(p,d),a.listShortcuts=o(0,d),a.listShortcuts=o(0,d),a.setScenes=function(e,n){return function(r){const{shortcutMngr:t}=e;r.forEach((e=>{if(null==e)return;const{name:r,scene:s}=e;if(null==s)return void console.warn(`Scene ${r} is not defined`);s.parents||(s.parents=[]),n.scenes[r]=s,n.sceneNames.add(r);const{show:o,hide:i,parents:c,...u}=s,l={};l[r]=u,t.load(l)}))}}(p,d),a.show=function(e,n){return function({scene:r,options:t={ssr:!1}},...s){const{shortcutMngr:o,askForPromise:i,log:c,findInstructions:u,setInstruction:l}=e,d=i(),a=i(),{opened:p,scenes:h,sceneNames:f,currentPage:m}=n;if(m){const e=h[m].beforeHide;"function"==typeof e&&e({done:a.done,dependencies:o.getDependencies()})}else a.done(!0);return a.onComplete((e=>{if(!e)return d.done(),d.promise;if(!f.has(r)&&c)return c({message:`Scene ${r} is not available.`,level:1,type:"error"}),d.done(),d.promise;if(!p&&t.ssr)return n.opened=!0,n.currentPage=r,o.changeContext(r),d.done(),d.promise;const{show:a,parents:m=[]}=h[r];if("*"===m[0])return a().then((()=>d.done())),n.currentParents.push(n.currentPage),n.currentPage=r,d.promise;function g([e,r]){if("show"===r)n.currentScene&&n.currentParents.push(n.currentScene),n.currentScene=e;else{let e=n.currentParents.pop();n.currentScene=e}return h[e][r]}m.forEach((e=>f.has(e))),n.currentParents||(n.currentParents=[]);const y=u(n.currentScene,n.currentParents,r,m),P=[];for(let e of y)[e].map(g).map((e=>P.push(l(e),...s)));i.sequence(P).onComplete((()=>{n.opened=!0,o.changeContext(r),"function"==typeof h[r].afterShow&&h[r].afterShow({dependencies:o.getDependencies(),done:()=>{}}),d.done()}))})),d.promise}}(p,d),a.loadPlugins=async function(e){const n=e.map((e=>`plugin${e}`)),r=await import("@peter.naydenov/shortcuts");return n.map((e=>r[e]))},a.setDependencies=e=>c.setDependencies(e),a.getDependencies=()=>c.getDependencies(),a.setNote=n=>e.setNote(n),a.listScenes=()=>[...d.sceneNames],a.enablePlugin=(e,n)=>c.enablePlugin(e,n),a.disablePlugin=e=>c.disablePlugin(e),a.emit=(e,...n)=>c.emit(e,...n),a}export{i as default};
|
package/dist/cuts.umd.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).cuts=t()}(this,(function(){"use strict";var e={_normalizeWithPlugins:function(e,t){return function(e){const n=t.shortcuts;Object.keys(n).forEach((t=>{Object.entries(n[t]).forEach((([o,r])=>{const s=e(o);s!==o&&(delete n[t][o],n[t][s]=r)}))}))}},_readShortcutWithPlugins:function(e,t){return function(n){const{inAPI:o}=e,r=n.split(":")[0],s=o._systemAction(r,"none");let i=n;return-1!==s&&(i=t.plugins[s].shortcutName(n)),i}},_systemAction:function(e,t){return function(e,n,o=null){return t.plugins.findIndex((t=>t.getPrefix()===e&&(t[n]&&t[n](o),!0)))}},changeContext:function(e,t){const{shortcuts:n,currentContext:o}=t,{ev:r}=e;return function(e=!1){const s=o.name;if(!e)return r.reset(),void(o.name=null);s!==e&&(n[e]?(n[s]&&r.reset(),o.name=e,t.plugins.forEach((t=>t.contextChange(e))),Object.entries(n[e]).forEach((([e,t])=>{t.forEach((t=>r.on(e,t)))})),r.on("*",((...e)=>{t.exposeShortcut&&t.exposeShortcut(...e)}))):r.emit("@shortcuts-error",`Context '${e}' does not exist`))}},listShortcuts:function(e,t){const n=t.shortcuts;return function(e=null){if(null!=e){let t=n[e];return null==t?null:Object.entries(t).map((([e,t])=>e))}return Object.keys(n).map((e=>{let t={};return t.context=e,t.shortcuts=Object.entries(n[e]).map((([e,t])=>e)),t}))}},load:function(e,t){const{shortcuts:n,plugins:o}=t,{API:{changeContext:r,getContext:s}}=e;return function(e){const t=s(),i=o.map((e=>e.getPrefix().toUpperCase()));let c=!1;Object.entries(e).forEach((([e,r])=>{e===t&&(c=!0),n[e]={},Object.entries(r).forEach((([t,r])=>{let s=t,c=t.toUpperCase().trim(),u=i.map(((e,t)=>c.startsWith(e)?t:null)).filter((e=>null!==e));if(u.length){let e=u[0];s=o[e].shortcutName(t)}r instanceof Function&&(r=[r]),n[e][s]=r}))})),c&&(r(),r(t))}},unload:function(e,t){const{currentContext:n,shortcuts:o}=t,{ev:r}=e;return function(e){n.name!==e?o[e]?delete o[e]:r.emit("shortcuts-error",`Context '${e}' does not exist`):r.emit("shortcuts-error",`Context '${e}' can't be removed during is current active context. Change the context first`)}}};function t(e){const t=e.toUpperCase(),n=/KEY\s*\:/i.test(t),o=t.indexOf(":");return n?`KEY:${t.slice(o+1).split(",").map((e=>e.trim())).map((e=>e.split("+").map((e=>e.trim())).sort().join("+"))).join(",")}`:e}function n(e,t){let{shiftKey:n,altKey:o,ctrlKey:r}=e,s=e.code.replace("Key","").replace("Digit",""),i=[];return r&&i.push("CTRL"),n&&i.push("SHIFT"),o&&i.push("ALT"),t.hasOwnProperty(s)?i.push(t[s].toUpperCase()):["ControlLeft","ControlRight","ShiftLeft","ShiftRight","AltLeft","AltRight","Meta"].includes(s)||i.push(s.toUpperCase()),i.sort()}function o(e,t){let n=0;const{regex:o}=e,{listenOptions:r,currentContext:{name:s},shortcuts:i}=t;return null==s?0:(Object.entries(i[s]).forEach((([e,t])=>{if(!o.test(e))return;n++;let s=e.slice(4).split(",").length;r.maxSequence<s&&(r.maxSequence=s)})),n)}function r(){return{ArrowLeft:"LEFT",ArrowUp:"UP",ArrowRight:"RIGHT",ArrowDown:"DOWN",Enter:"ENTER",NumpadEnter:"ENTER",Escape:"ESC",Backspace:"BACKSPACE",Space:"SPACE",Tab:"TAB",Backquote:"`",BracketLeft:"[",BracketRight:"]",Equal:"=",Slash:"/",Backslash:"\\",IntlBackslash:"`",F1:"F1",F2:"F2",F3:"F3",F4:"F4",F5:"F5",F6:"F6",F7:"F7",F8:"F8",F9:"F9",F10:"F10",F11:"F11",F12:"F12"}}function s(e,t,n){const{listenOptions:{clickTarget:o}}=t;let r=n;return r===document||r===document.body?null:r.dataset[o]||"A"===r.nodeName?r:s(e,t,r.parentNode)}function i(e){const t=e.toUpperCase(),n=/CLICK\s*\:/i.test(t),o=["LEFT","MIDDLE","RIGHT"],r=["ALT","SHIFT","CTRL"];let s=null,i=[],c=0,u=t.indexOf(":");return n?(t.slice(u+1).trim().split("-").map((e=>e.trim())).forEach((e=>{o.includes(e)?s=e:r.includes(e)?i.push(e):isNaN(e)||(c=e)})),`CLICK:${s}-${c}${i.length>0?"-":""}${i.sort().join("-")}`):e}function c(e,t){let{shiftKey:n,altKey:o,ctrlKey:r,key:s,button:i}=e,c=`CLICK:${["LEFT","MIDDLE","RIGHT"][i]}-${t}`,u=[];return r&&u.push("CTRL"),n&&u.push("SHIFT"),o&&u.push("ALT"),u.length>0?`${c}${u.length>0?"-":""}${u.sort().join("-")}`:`${c}`}function u(e,t){let n=0;const{regex:o}=e,{listenOptions:r,currentContext:{name:s},shortcuts:i}=t;return null==s?0:(Object.entries(i[s]).forEach((([e,t])=>{if(!o.test(e))return;n++;let[,s]=e.slice(6).split("-");r.maxClicks<s&&(r.maxClicks=s)})),n)}function l(t={}){const n=function(){let e={"*":[]},t={},n=[],o=!1,r="";return{on:function(t,n){e[t]||(e[t]=[]),e[t].push(n)},once:function(e,n){"*"!==e&&(t[e]||(t[e]=[]),t[e].push(n))},off:function(n,o){if(o)return e[n]&&(e[n]=e[n].filter((e=>e!==o))),t[n]&&(t[n]=t[n].filter((e=>e!==o))),e[n]&&0===e[n].length&&delete e[n],void(t[n]&&0===t[n].length&&delete e[n]);t[n]&&delete t[n],e[n]&&delete e[n]},reset:function(){e={"*":[]},t={},n=[]},emit:function(){const[s,...i]=arguments;function c(t){let o=!1;"*"!==t&&(n.includes(t)||(e[t].every((e=>{const t=e(...i);return"string"!=typeof t||"STOP"!==t.toUpperCase()||(o=!0,!1)})),o||e["*"].forEach((e=>e(s,...i)))))}if(o&&(console.log(`${r} Event "${s}" was triggered.`),i.length>0&&(console.log("Arguments:"),console.log(...i),console.log("^----"))),"*"!==s){if(t[s]){if(n.includes(s))return;t[s].forEach((e=>e(...i))),delete t[s]}e[s]&&c(s)}else Object.keys(e).forEach((e=>c(e)))},stop:function(o){if("*"!==o)n.push(o);else{const o=Object.keys(e),r=Object.keys(t);n=[...r,...o]}},start:function(e){n="*"!==e?n.filter((t=>e!=t)):[]},debug:function(e,t){o=!!e,t&&"string"==typeof t&&(r=t)}}}(),o={},r={},s={currentContext:{name:null,note:null},shortcuts:{},plugins:[],exposeShortcut:!(!t.onShortcut||"function"!=typeof t.onShortcut)&&t.onShortcut},i={ev:n,inAPI:o,API:r,extra:{}};return r.enablePlugin=(e,t={})=>{const n=e.name;if(-1===o._systemAction(n,"none")){let n;n=e(i,s,t),s.plugins.push(n)}},r.disablePlugin=e=>{const t=o._systemAction(e,"destroy");-1!==t&&(s.plugins=s.plugins.filter(((e,n)=>n!==t)))},r.mutePlugin=e=>o._systemAction(e,"mute"),r.unmutePlugin=e=>o._systemAction(e,"unmute"),r.getContext=()=>s.currentContext.name,r.getNote=()=>s.currentContext.note,r.setNote=(e=null)=>{"string"!=typeof e&&null!=e||(s.currentContext.note=e)},r.pause=(e="*")=>{let t=o._readShortcutWithPlugins(e);n.stop(t)},r.resume=(e="*")=>{const t=o._readShortcutWithPlugins(e);n.start(t)},r.emit=(e,...t)=>n.emit(o._readShortcutWithPlugins(e),...t),r.listContexts=()=>Object.keys(s.shortcuts),r.setDependencies=e=>i.extra={...i.extra,...e},r.getDependencies=()=>i.extra,Object.entries(e).forEach((([e,t])=>{e.startsWith("_")?o[e]=t(i,s):r[e]=t(i,s)})),r}var a=Object.freeze({__proto__:null,pluginClick:function(e,t,n){let{currentContext:o,shortcuts:r}=t,{inAPI:l}=e,a={ev:e.ev,_findTarget:s,_readClickEvent:c,mainDependencies:e,regex:/CLICK\s*\:/i},f={currentContext:o,shortcuts:r,listenOptions:{mouseWait:n.mouseWait?n.mouseWait:320,maxClicks:1,clickTarget:n.clickTarget?n.clickTarget:"click"}};l._normalizeWithPlugins(i);let d=function(e,t){const{ev:n,_findTarget:o,_readClickEvent:r,mainDependencies:s}=e,{listenOptions:i,currentContext:c}=t,{mouseWait:u}=i;let l=null,a=null,f=null,d=null,p=0;function m(){const e=r(a,p),t={target:l,targetProps:l?l.getBoundingClientRect():null,x:a.clientX,y:a.clientY,context:c.name,note:c.note,event:a,dependencies:s.extra,type:"click"};n.emit(e,t),f=null,d=null,l=null,a=null,p=0}function h(n){let r=i.maxClicks;return clearTimeout(f),d?(clearTimeout(d),void(d=setTimeout((()=>d=null),u))):(l=o(e,t,n.target),l&&l.dataset.hasOwnProperty("quickClick")&&(r=1),l&&"A"===l.tagName&&(r=1),a=n,p++,p>=r?(m(),void(r>1&&(d=setTimeout((()=>d=null),u)))):void(f=setTimeout(m,u)))}function g(n){let r=i.maxClicks;return clearTimeout(f),d?(clearTimeout(d),void(d=setTimeout((()=>d=null),u))):(l=o(e,t,n.target),l&&l.dataset.hasOwnProperty("quickClick")&&(r=1),l&&"A"===l.tagName&&(r=1),a=n,p++,p>=r?(m(),void(r>1&&(d=setTimeout((()=>d=null),u)))):void(f=setTimeout(m,u)))}return{start:function(){t.active||(window.addEventListener("contextmenu",g),document.addEventListener("click",h),t.active=!0)},stop:function(){t.active&&(window.removeEventListener("contextmenu",g),document.removeEventListener("click",h),t.active=!1)}}}(a,f),p=u(a,f);p>0&&d.start();let m={getPrefix:()=>"click",shortcutName:e=>i(e),contextChange:()=>{p=u(a,f),p<1&&d.stop(),p>0&&d.start()},mute:()=>d.stop(),unmute:()=>d.start(),destroy:()=>{d.stop(),f=null,m=null}};return Object.freeze(m),m},pluginKey:function(e,s,i={}){let{currentContext:c,shortcuts:u,exposeShortcut:l}=s,{inAPI:a}=e,f={ev:e.ev,_specialChars:r,_readKeyEvent:n,mainDependencies:e,regex:/KEY\s*\:/i},d={currentContext:c,shortcuts:u,active:!1,listenOptions:{keyWait:i.keyWait?i.keyWait:480,maxSequence:1,keyIgnore:null},streamKeys:!(!i.streamKeys||"function"!=typeof i.streamKeys)&&i.streamKeys,exposeShortcut:l};a._normalizeWithPlugins(t);let p=function(e,t){const{ev:n,_specialChars:o,_readKeyEvent:r,mainDependencies:s}=e,{currentContext:i,streamKeys:c,listenOptions:u}=t,{keyWait:l}=u;let a=[],f=null,d=!0,p=!1;const m=()=>d=!1,h=()=>d=!0,g=()=>p=!0,y=()=>!1===d;function v(){let e=a.map((e=>[e.join("+")]));const t={wait:m,end:h,ignore:g,isWaiting:y,note:i.note,context:i.name,dependencies:s.extra,type:"key"};if(!d){let o=e.at(-1);n.emit(o,t),p&&(e=e.slice(0,-1),p=!1)}if(d){const o=`KEY:${e.join(",")}`;n.emit(o,t),a=[],f=null}}function x(t){if(clearTimeout(f),o.hasOwnProperty(t.code))return a.push(r(t,o)),c&&c({key:t.key,context:i.name,note:i.note,dependencies:e.extra}),u.keyIgnore?(clearTimeout(u.keyIgnore),void(u.keyIgnore=setTimeout((()=>u.keyIgnore=null),l))):d&&a.length===u.maxSequence?(v(),void(u.keyIgnore=setTimeout((()=>u.keyIgnore=null),l))):void(d?f=setTimeout(v,l):v())}function C(t){if(!o.hasOwnProperty(t.code)){if(clearTimeout(f),c&&c({key:t.key,context:i.name,note:i.note,dependencies:e.extra}),u.keyIgnore)return clearTimeout(u.keyIgnore),void(u.keyIgnore=setTimeout((()=>u.keyIgnore=null),l));if(a.push(r(t,o)),d&&a.length===u.maxSequence)return v(),void(u.keyIgnore=setTimeout((()=>u.keyIgnore=null),l));d?f=setTimeout(v,l):v()}}return{start:function(){t.active||(document.addEventListener("keydown",x),document.addEventListener("keypress",C),t.active=!0)},stop:function(){t.active&&(document.removeEventListener("keydown",x),document.removeEventListener("keypress",C),t.active=!1)}}}(f,d),m=o(f,d);m>0&&p.start();let h={getPrefix:()=>"key",shortcutName:e=>t(e),contextChange:e=>{m=o(f,d),m<1&&p.stop(),m>0&&p.start()},mute:()=>p.stop(),unmute:()=>p.start(),destroy:()=>{p.stop(),d=null,h=null}};return Object.freeze(h),h},shortcuts:l});function f(e){return e?function(e){let t=e.map((e=>d())),n=t.map((e=>e.promise));t.promises=t;let o=p(Promise.all(n));function r(e){let t="pending";return e.then((()=>t="fulfilled")).catch((()=>t="rejected")),t}function s(n,...o){t.forEach(((t,s)=>n({value:e[s],done:t.done,cancel:t.cancel,timeout:t.timeout,state:r(t.promise)},...o)))}const i={promise:Promise.all(n),promises:t,done:e=>{t.forEach((t=>t.done(e)))},cancel:e=>{t.forEach((t=>t.cancel(e)))},each:s,onComplete:o,timeout:()=>{}};return i.timeout=m(!0,i),i}(e):d()}function d(){let e,t;const n=new Promise(((n,o)=>{e=n,t=o})),o={promise:n,promises:null,done:e,cancel:t,each:()=>{},onComplete:p(n),timeout:()=>{}};return o.timeout=m(!1,o),o.each=(n,...r)=>{n({value:null,done:e,cancel:t,timeout:o.timeout},...r)},o}function p(e){return function(t,n=null){null===n?e.then((e=>t(e))):e.then((e=>t(e)),(e=>n(e)))}}function m(e,t){let n;return n=e?Promise.all(t.promises.map((e=>e.promise))):t.promise,function(e,o){let r,s=new Promise(((t,s)=>{r=setTimeout((()=>{t(o),Promise.resolve(n)}),e)}));return n.then((()=>clearTimeout(r))),t.onComplete=p(Promise.race([n,s])),t}}function h({message:e,level:t,type:n,logLevel:o}){if(0===o)return null;if(o<t)return null;const r=`[Debug]: ${e}`;switch(n){case"warn":console.warn(r);break;case"error":console.error(r);break;default:console.log(r)}return r}function g(e={},t=h){return function({message:n,type:o,level:r,...s}){const{level:i,type:c,defaultMessageLevel:u}=Object.assign({},{level:1e3,type:"log",defaultMessageLevel:1},e);return o||(o=c),r||(r=u),t({message:n,type:o,level:r,logLevel:i,...s})}}function*y(e,t,n,o){let r=null;if(null===e)return yield*o.map((e=>[e,"show"])),void(yield[n,"show"]);if(!o||0===o.length)return t?(yield[e,"hide"],t.reverse(),yield*t.map((e=>[e,"hide"])),void(yield[n,"show"])):(yield[e,"hide"],void(yield[n,"show"]));if(o.includes(e)){for(let t=o.indexOf(e)+1;t<o.length;t++)yield[o[t],"show"];yield[n,"show"]}else{if(!t)return yield[e,"hide"],void(yield*o.map((e=>[e,"show"])));if(o.every(((e,n)=>t[n]===o[n]&&(r=n,!0))),null==r)return yield[e,"hide"],t.reverse(),yield*t.map((e=>[e,"hide"])),yield*o.map((e=>[e,"show"])),void(yield[n,"show"]);yield[e,"hide"];for(let e=t.length;e>r+1;e--)yield[t[e-1],"hide"];for(let e=r+1;e<o.length;e++)yield[o[e],"show"];yield[n,"show"]}}function v(e){return function(t,...n){const{askForPromise:o,deps:r}=e;return function(){const e=o();return t({task:e,dependencies:r()},...n),e.promise}}}function x(e,t){return function(e){const{scenes:n,sceneNames:o}=t;if(!o.has(e))return null;const{show:r,hide:s,parents:i,beforeUnload:c,afterLoad:u,...l}=n[e];return Object.keys(l)}}return f.sequence=function(e,...t){const n=f(),o=[];const r=function*(e){for(const t of e)yield t}(e);return function e(t,...s){t.done?n.done(o):t.value(...s).then((t=>{o.push(t),e(r.next(),...s,t)}))}(r.next(),...t),n},f.all=function(e,...t){const n=f(),o=[],r=e.map(((e,n)=>"function"==typeof e?e(...t).then((e=>o[n]=e)):e.then((e=>o[n]=e))));return Promise.all(r).then((()=>n.done(o))),n},function(e={logLevel:0}){const t=l(),n=g({level:e.logLevel||0}),o={currentScene:null,currentParents:null,sceneNames:new Set,scenes:{},opened:!1},r={},s={shortcutMngr:t,API:r,inAPI:{},findInstructions:y,askForPromise:f,setInstruction:v({askForPromise:f,deps:t.getDependencies}),log:n};return r.hide=function(e,t){return function(n=1){const{askForPromise:o,shortcutMngr:r,setInstruction:s}=e,{currentScene:i,currentParents:c,scenes:u}=t,l=o(),a=[],f=c.length>0;let d;return r.pause(),a.push(s(u[i].hide)),f||(t.currentScene=null),f&&"*"===n&&[...c].reverse().forEach((e=>{d=t.currentParents.pop(),t.currentScene=d,a.push(s(u[e].hide))})),f&&!["*",1].includes(n)&&c.slice("-"+(n-1)).reverse().map((e=>{d=t.currentParents.pop(),t.currentScene=d,a.push(s(u[e].hide))})),(n=o.sequence(a)).onComplete((()=>{r.changeContext(t.currentScene),l.done()})),l.promise}}(s,o),r.listShortcuts=x(0,o),r.listShortcuts=x(0,o),r.setScenes=function(e,t){return function(n){const{shortcutMngr:o}=e;n.forEach((({name:e,scene:n})=>{n.parents||(n.parents=[]),t.scenes[e]=n,t.sceneNames.add(e);const{show:r,hide:s,parents:i,...c}=n,u={};u[e]=c,o.load(u)}))}}(s,o),r.show=function(e,t){return function({scene:n,options:o={ssr:!1}},...r){const{shortcutMngr:s,askForPromise:i,log:c,findInstructions:u,setInstruction:l}=e,a=i(),f=i(),{opened:d,scenes:p,sceneNames:m,currentPage:h}=t;if(h){const e=p[h].beforeHide;"function"==typeof e&&e({done:f.done,dependencies:s.getDependencies()})}else f.done(!0);return f.onComplete((e=>{if(!e)return a.done(),a.promise;if(!m.has(n)&&c)return c({message:`Scene ${n} is not available.`,level:1,type:"error"}),a.done(),a.promise;if(!d&&o.ssr)return t.opened=!0,t.currentPage=n,s.changeContext(n),a.done(),a.promise;const{show:f,parents:h=[]}=p[n];if("*"===h[0])return f().then((()=>a.done())),t.currentParents.push(t.currentPage),t.currentPage=n,a.promise;function g([e,n]){if("show"===n)t.currentScene&&t.currentParents.push(t.currentScene),t.currentScene=e;else{let e=t.currentParents.pop();t.currentScene=e}return p[e][n]}h.forEach((e=>m.has(e))),t.currentParents||(t.currentParents=[]);const y=u(t.currentScene,t.currentParents,n,h),v=[];for(let e of y)[e].map(g).map((e=>v.push(l(e),...r)));i.sequence(v).onComplete((()=>{t.opened=!0,s.changeContext(n),"function"==typeof p[n].afterShow&&p[n].afterShow({dependencies:s.getDependencies(),done:()=>{}}),a.done()}))})),a.promise}}(s,o),r.loadPlugins=async function(e){const t=e.map((e=>`plugin${e}`)),n=await Promise.resolve().then((function(){return a}));return t.map((e=>n[e]))},r.setDependencies=e=>t.setDependencies(e),r.getDependencies=()=>t.getDependencies(),r.setNote=e=>l.setNote(e),r.listScenes=()=>[...o.sceneNames],r.enablePlugin=(e,n)=>t.enablePlugin(e,n),r.disablePlugin=e=>t.disablePlugin(e),r.emit=(e,...n)=>t.emit(e,...n),r}}));
|
|
1
|
+
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).cuts=t()}(this,(function(){"use strict";var e={_normalizeWithPlugins:function(e,t){return function(e){const n=t.shortcuts;Object.keys(n).forEach((t=>{Object.entries(n[t]).forEach((([o,r])=>{const s=e(o);s!==o&&(delete n[t][o],n[t][s]=r)}))}))}},_readShortcutWithPlugins:function(e,t){return function(n){const{inAPI:o}=e,r=n.split(":")[0],s=o._systemAction(r,"none");let i=n;return-1!==s&&(i=t.plugins[s].shortcutName(n)),i}},_systemAction:function(e,t){return function(e,n,o=null){return t.plugins.findIndex((t=>t.getPrefix()===e&&(t[n]&&t[n](o),!0)))}},changeContext:function(e,t){const{shortcuts:n,currentContext:o}=t,{ev:r}=e;return function(e=!1){const s=o.name;if(!e)return r.reset(),void(o.name=null);s!==e&&(n[e]?(n[s]&&r.reset(),o.name=e,t.plugins.forEach((t=>t.contextChange(e))),Object.entries(n[e]).forEach((([e,t])=>{t.forEach((t=>r.on(e,t)))})),r.on("*",((...e)=>{t.exposeShortcut&&t.exposeShortcut(...e)}))):r.emit("@shortcuts-error",`Context '${e}' does not exist`))}},listShortcuts:function(e,t){const n=t.shortcuts;return function(e=null){if(null!=e){let t=n[e];return null==t?null:Object.entries(t).map((([e,t])=>e))}return Object.keys(n).map((e=>{let t={};return t.context=e,t.shortcuts=Object.entries(n[e]).map((([e,t])=>e)),t}))}},load:function(e,t){const{shortcuts:n,plugins:o}=t,{API:{changeContext:r,getContext:s}}=e;return function(e){const t=s(),i=o.map((e=>e.getPrefix().toUpperCase()));let c=!1;Object.entries(e).forEach((([e,r])=>{e===t&&(c=!0),n[e]={},Object.entries(r).forEach((([t,r])=>{let s=t,c=t.toUpperCase().trim(),u=i.map(((e,t)=>c.startsWith(e)?t:null)).filter((e=>null!==e));if(u.length){let e=u[0];s=o[e].shortcutName(t)}r instanceof Function&&(r=[r]),n[e][s]=r}))})),c&&(r(),r(t))}},unload:function(e,t){const{currentContext:n,shortcuts:o}=t,{ev:r}=e;return function(e){n.name!==e?o[e]?delete o[e]:r.emit("shortcuts-error",`Context '${e}' does not exist`):r.emit("shortcuts-error",`Context '${e}' can't be removed during is current active context. Change the context first`)}}};function t(e){const t=e.toUpperCase(),n=/KEY\s*\:/i.test(t),o=t.indexOf(":");return n?`KEY:${t.slice(o+1).split(",").map((e=>e.trim())).map((e=>e.split("+").map((e=>e.trim())).sort().join("+"))).join(",")}`:e}function n(e,t){let{shiftKey:n,altKey:o,ctrlKey:r}=e,s=e.code.replace("Key","").replace("Digit",""),i=[];return r&&i.push("CTRL"),n&&i.push("SHIFT"),o&&i.push("ALT"),t.hasOwnProperty(s)?i.push(t[s].toUpperCase()):["ControlLeft","ControlRight","ShiftLeft","ShiftRight","AltLeft","AltRight","Meta"].includes(s)||i.push(s.toUpperCase()),i.sort()}function o(e,t){let n=0;const{regex:o}=e,{listenOptions:r,currentContext:{name:s},shortcuts:i}=t;return null==s?0:(Object.entries(i[s]).forEach((([e,t])=>{if(!o.test(e))return;n++;let s=e.slice(4).split(",").length;r.maxSequence<s&&(r.maxSequence=s)})),n)}function r(){return{ArrowLeft:"LEFT",ArrowUp:"UP",ArrowRight:"RIGHT",ArrowDown:"DOWN",Enter:"ENTER",NumpadEnter:"ENTER",Escape:"ESC",Backspace:"BACKSPACE",Space:"SPACE",Tab:"TAB",Backquote:"`",BracketLeft:"[",BracketRight:"]",Equal:"=",Slash:"/",Backslash:"\\",IntlBackslash:"`",F1:"F1",F2:"F2",F3:"F3",F4:"F4",F5:"F5",F6:"F6",F7:"F7",F8:"F8",F9:"F9",F10:"F10",F11:"F11",F12:"F12"}}function s(e,t,n){const{listenOptions:{clickTarget:o}}=t;let r=n;return r===document||r===document.body?null:r.dataset[o]||"A"===r.nodeName?r:s(e,t,r.parentNode)}function i(e){const t=e.toUpperCase(),n=/CLICK\s*\:/i.test(t),o=["LEFT","MIDDLE","RIGHT"],r=["ALT","SHIFT","CTRL"];let s=null,i=[],c=0,u=t.indexOf(":");return n?(t.slice(u+1).trim().split("-").map((e=>e.trim())).forEach((e=>{o.includes(e)?s=e:r.includes(e)?i.push(e):isNaN(e)||(c=e)})),`CLICK:${s}-${c}${i.length>0?"-":""}${i.sort().join("-")}`):e}function c(e,t){let{shiftKey:n,altKey:o,ctrlKey:r,key:s,button:i}=e,c=`CLICK:${["LEFT","MIDDLE","RIGHT"][i]}-${t}`,u=[];return r&&u.push("CTRL"),n&&u.push("SHIFT"),o&&u.push("ALT"),u.length>0?`${c}${u.length>0?"-":""}${u.sort().join("-")}`:`${c}`}function u(e,t){let n=0;const{regex:o}=e,{listenOptions:r,currentContext:{name:s},shortcuts:i}=t;return null==s?0:(Object.entries(i[s]).forEach((([e,t])=>{if(!o.test(e))return;n++;let[,s]=e.slice(6).split("-");r.maxClicks<s&&(r.maxClicks=s)})),n)}function l(t={}){const n=function(){let e={"*":[]},t={},n=[],o=!1,r="";return{on:function(t,n){e[t]||(e[t]=[]),e[t].push(n)},once:function(e,n){"*"!==e&&(t[e]||(t[e]=[]),t[e].push(n))},off:function(n,o){if(o)return e[n]&&(e[n]=e[n].filter((e=>e!==o))),t[n]&&(t[n]=t[n].filter((e=>e!==o))),e[n]&&0===e[n].length&&delete e[n],void(t[n]&&0===t[n].length&&delete e[n]);t[n]&&delete t[n],e[n]&&delete e[n]},reset:function(){e={"*":[]},t={},n=[]},emit:function(){const[s,...i]=arguments;function c(t){let o=!1;"*"!==t&&(n.includes(t)||(e[t].every((e=>{const t=e(...i);return"string"!=typeof t||"STOP"!==t.toUpperCase()||(o=!0,!1)})),o||e["*"].forEach((e=>e(s,...i)))))}if(o&&(console.log(`${r} Event "${s}" was triggered.`),i.length>0&&(console.log("Arguments:"),console.log(...i),console.log("^----"))),"*"!==s){if(t[s]){if(n.includes(s))return;t[s].forEach((e=>e(...i))),delete t[s]}e[s]&&c(s)}else Object.keys(e).forEach((e=>c(e)))},stop:function(o){if("*"!==o)n.push(o);else{const o=Object.keys(e),r=Object.keys(t);n=[...r,...o]}},start:function(e){n="*"!==e?n.filter((t=>e!=t)):[]},debug:function(e,t){o=!!e,t&&"string"==typeof t&&(r=t)}}}(),o={},r={},s={currentContext:{name:null,note:null},shortcuts:{},plugins:[],exposeShortcut:!(!t.onShortcut||"function"!=typeof t.onShortcut)&&t.onShortcut},i={ev:n,inAPI:o,API:r,extra:{}};return r.enablePlugin=(e,t={})=>{const n=e.name;if(-1===o._systemAction(n,"none")){let n;n=e(i,s,t),s.plugins.push(n)}},r.disablePlugin=e=>{const t=o._systemAction(e,"destroy");-1!==t&&(s.plugins=s.plugins.filter(((e,n)=>n!==t)))},r.mutePlugin=e=>o._systemAction(e,"mute"),r.unmutePlugin=e=>o._systemAction(e,"unmute"),r.getContext=()=>s.currentContext.name,r.getNote=()=>s.currentContext.note,r.setNote=(e=null)=>{"string"!=typeof e&&null!=e||(s.currentContext.note=e)},r.pause=(e="*")=>{let t=o._readShortcutWithPlugins(e);n.stop(t)},r.resume=(e="*")=>{const t=o._readShortcutWithPlugins(e);n.start(t)},r.emit=(e,...t)=>n.emit(o._readShortcutWithPlugins(e),...t),r.listContexts=()=>Object.keys(s.shortcuts),r.setDependencies=e=>i.extra={...i.extra,...e},r.getDependencies=()=>i.extra,Object.entries(e).forEach((([e,t])=>{e.startsWith("_")?o[e]=t(i,s):r[e]=t(i,s)})),r}var a=Object.freeze({__proto__:null,pluginClick:function(e,t,n){let{currentContext:o,shortcuts:r}=t,{inAPI:l}=e,a={ev:e.ev,_findTarget:s,_readClickEvent:c,mainDependencies:e,regex:/CLICK\s*\:/i},f={currentContext:o,shortcuts:r,listenOptions:{mouseWait:n.mouseWait?n.mouseWait:320,maxClicks:1,clickTarget:n.clickTarget?n.clickTarget:"click"}};l._normalizeWithPlugins(i);let d=function(e,t){const{ev:n,_findTarget:o,_readClickEvent:r,mainDependencies:s}=e,{listenOptions:i,currentContext:c}=t,{mouseWait:u}=i;let l=null,a=null,f=null,d=null,p=0;function m(){const e=r(a,p),t={target:l,targetProps:l?l.getBoundingClientRect():null,x:a.clientX,y:a.clientY,context:c.name,note:c.note,event:a,dependencies:s.extra,type:"click"};n.emit(e,t),f=null,d=null,l=null,a=null,p=0}function h(n){let r=i.maxClicks;return clearTimeout(f),d?(clearTimeout(d),void(d=setTimeout((()=>d=null),u))):(l=o(e,t,n.target),l&&l.dataset.hasOwnProperty("quickClick")&&(r=1),l&&"A"===l.tagName&&(r=1),a=n,p++,p>=r?(m(),void(r>1&&(d=setTimeout((()=>d=null),u)))):void(f=setTimeout(m,u)))}function g(n){let r=i.maxClicks;return clearTimeout(f),d?(clearTimeout(d),void(d=setTimeout((()=>d=null),u))):(l=o(e,t,n.target),l&&l.dataset.hasOwnProperty("quickClick")&&(r=1),l&&"A"===l.tagName&&(r=1),a=n,p++,p>=r?(m(),void(r>1&&(d=setTimeout((()=>d=null),u)))):void(f=setTimeout(m,u)))}return{start:function(){t.active||(window.addEventListener("contextmenu",g),document.addEventListener("click",h),t.active=!0)},stop:function(){t.active&&(window.removeEventListener("contextmenu",g),document.removeEventListener("click",h),t.active=!1)}}}(a,f),p=u(a,f);p>0&&d.start();let m={getPrefix:()=>"click",shortcutName:e=>i(e),contextChange:()=>{p=u(a,f),p<1&&d.stop(),p>0&&d.start()},mute:()=>d.stop(),unmute:()=>d.start(),destroy:()=>{d.stop(),f=null,m=null}};return Object.freeze(m),m},pluginKey:function(e,s,i={}){let{currentContext:c,shortcuts:u,exposeShortcut:l}=s,{inAPI:a}=e,f={ev:e.ev,_specialChars:r,_readKeyEvent:n,mainDependencies:e,regex:/KEY\s*\:/i},d={currentContext:c,shortcuts:u,active:!1,listenOptions:{keyWait:i.keyWait?i.keyWait:480,maxSequence:1,keyIgnore:null},streamKeys:!(!i.streamKeys||"function"!=typeof i.streamKeys)&&i.streamKeys,exposeShortcut:l};a._normalizeWithPlugins(t);let p=function(e,t){const{ev:n,_specialChars:o,_readKeyEvent:r,mainDependencies:s}=e,{currentContext:i,streamKeys:c,listenOptions:u}=t,{keyWait:l}=u;let a=[],f=null,d=!0,p=!1;const m=()=>d=!1,h=()=>d=!0,g=()=>p=!0,y=()=>!1===d;function v(){let e=a.map((e=>[e.join("+")]));const t={wait:m,end:h,ignore:g,isWaiting:y,note:i.note,context:i.name,dependencies:s.extra,type:"key"};if(!d){let o=e.at(-1);n.emit(o,t),p&&(e=e.slice(0,-1),p=!1)}if(d){const o=`KEY:${e.join(",")}`;n.emit(o,t),a=[],f=null}}function x(t){if(clearTimeout(f),o.hasOwnProperty(t.code))return a.push(r(t,o)),c&&c({key:t.key,context:i.name,note:i.note,dependencies:e.extra}),u.keyIgnore?(clearTimeout(u.keyIgnore),void(u.keyIgnore=setTimeout((()=>u.keyIgnore=null),l))):d&&a.length===u.maxSequence?(v(),void(u.keyIgnore=setTimeout((()=>u.keyIgnore=null),l))):void(d?f=setTimeout(v,l):v())}function C(t){if(!o.hasOwnProperty(t.code)){if(clearTimeout(f),c&&c({key:t.key,context:i.name,note:i.note,dependencies:e.extra}),u.keyIgnore)return clearTimeout(u.keyIgnore),void(u.keyIgnore=setTimeout((()=>u.keyIgnore=null),l));if(a.push(r(t,o)),d&&a.length===u.maxSequence)return v(),void(u.keyIgnore=setTimeout((()=>u.keyIgnore=null),l));d?f=setTimeout(v,l):v()}}return{start:function(){t.active||(document.addEventListener("keydown",x),document.addEventListener("keypress",C),t.active=!0)},stop:function(){t.active&&(document.removeEventListener("keydown",x),document.removeEventListener("keypress",C),t.active=!1)}}}(f,d),m=o(f,d);m>0&&p.start();let h={getPrefix:()=>"key",shortcutName:e=>t(e),contextChange:e=>{m=o(f,d),m<1&&p.stop(),m>0&&p.start()},mute:()=>p.stop(),unmute:()=>p.start(),destroy:()=>{p.stop(),d=null,h=null}};return Object.freeze(h),h},shortcuts:l});function f(e){return e?function(e){let t=e.map((e=>d())),n=t.map((e=>e.promise));t.promises=t;let o=p(Promise.all(n));function r(e){let t="pending";return e.then((()=>t="fulfilled")).catch((()=>t="rejected")),t}function s(n,...o){t.forEach(((t,s)=>n({value:e[s],done:t.done,cancel:t.cancel,timeout:t.timeout,state:r(t.promise)},...o)))}const i={promise:Promise.all(n),promises:t,done:e=>{t.forEach((t=>t.done(e)))},cancel:e=>{t.forEach((t=>t.cancel(e)))},each:s,onComplete:o,timeout:()=>{}};return i.timeout=m(!0,i),i}(e):d()}function d(){let e,t;const n=new Promise(((n,o)=>{e=n,t=o})),o={promise:n,promises:null,done:e,cancel:t,each:()=>{},onComplete:p(n),timeout:()=>{}};return o.timeout=m(!1,o),o.each=(n,...r)=>{n({value:null,done:e,cancel:t,timeout:o.timeout},...r)},o}function p(e){return function(t,n=null){null===n?e.then((e=>t(e))):e.then((e=>t(e)),(e=>n(e)))}}function m(e,t){let n;return n=e?Promise.all(t.promises.map((e=>e.promise))):t.promise,function(e,o){let r,s=new Promise(((t,s)=>{r=setTimeout((()=>{t(o),Promise.resolve(n)}),e)}));return n.then((()=>clearTimeout(r))),t.onComplete=p(Promise.race([n,s])),t}}function h({message:e,level:t,type:n,logLevel:o}){if(0===o)return null;if(o<t)return null;const r=`[Debug]: ${e}`;switch(n){case"warn":console.warn(r);break;case"error":console.error(r);break;default:console.log(r)}return r}function g(e={},t=h){return function({message:n,type:o,level:r,...s}){const{level:i,type:c,defaultMessageLevel:u}=Object.assign({},{level:1e3,type:"log",defaultMessageLevel:1},e);return o||(o=c),r||(r=u),t({message:n,type:o,level:r,logLevel:i,...s})}}function*y(e,t,n,o){let r=null;if(null===e)return yield*o.map((e=>[e,"show"])),void(yield[n,"show"]);if(!o||0===o.length)return t?(yield[e,"hide"],t.reverse(),yield*t.map((e=>[e,"hide"])),void(yield[n,"show"])):(yield[e,"hide"],void(yield[n,"show"]));if(o.includes(e)){for(let t=o.indexOf(e)+1;t<o.length;t++)yield[o[t],"show"];yield[n,"show"]}else{if(!t)return yield[e,"hide"],void(yield*o.map((e=>[e,"show"])));if(o.every(((e,n)=>t[n]===o[n]&&(r=n,!0))),null==r)return yield[e,"hide"],t.reverse(),yield*t.map((e=>[e,"hide"])),yield*o.map((e=>[e,"show"])),void(yield[n,"show"]);yield[e,"hide"];for(let e=t.length;e>r+1;e--)yield[t[e-1],"hide"];for(let e=r+1;e<o.length;e++)yield[o[e],"show"];yield[n,"show"]}}function v(e){return function(t,...n){const{askForPromise:o,deps:r}=e;return function(){const e=o();return t({task:e,dependencies:r()},...n),e.promise}}}function x(e,t){return function(e){const{scenes:n,sceneNames:o}=t;if(!o.has(e))return null;const{show:r,hide:s,parents:i,beforeUnload:c,afterLoad:u,...l}=n[e];return Object.keys(l)}}return f.sequence=function(e,...t){const n=f(),o=[];const r=function*(e){for(const t of e)yield t}(e);return function e(t,...s){t.done?n.done(o):t.value(...s).then((t=>{o.push(t),e(r.next(),...s,t)}))}(r.next(),...t),n},f.all=function(e,...t){const n=f(),o=[],r=e.map(((e,n)=>"function"==typeof e?e(...t).then((e=>o[n]=e)):e.then((e=>o[n]=e))));return Promise.all(r).then((()=>n.done(o))),n},function(e={logLevel:0}){const t=l(),n=g({level:e.logLevel||0}),o={currentScene:null,currentParents:null,sceneNames:new Set,scenes:{},opened:!1},r={},s={shortcutMngr:t,API:r,inAPI:{},findInstructions:y,askForPromise:f,setInstruction:v({askForPromise:f,deps:t.getDependencies}),log:n};return r.hide=function(e,t){return function(n=1){const{askForPromise:o,shortcutMngr:r,setInstruction:s}=e,{currentScene:i,currentParents:c,scenes:u}=t,l=o(),a=[],f=c.length>0;let d;return r.pause(),a.push(s(u[i].hide)),f||(t.currentScene=null),f&&"*"===n&&[...c].reverse().forEach((e=>{d=t.currentParents.pop(),t.currentScene=d,a.push(s(u[e].hide))})),f&&!["*",1].includes(n)&&c.slice("-"+(n-1)).reverse().map((e=>{d=t.currentParents.pop(),t.currentScene=d,a.push(s(u[e].hide))})),(n=o.sequence(a)).onComplete((()=>{r.changeContext(t.currentScene),l.done()})),l.promise}}(s,o),r.listShortcuts=x(0,o),r.listShortcuts=x(0,o),r.setScenes=function(e,t){return function(n){const{shortcutMngr:o}=e;n.forEach((e=>{if(null==e)return;const{name:n,scene:r}=e;if(null==r)return void console.warn(`Scene ${n} is not defined`);r.parents||(r.parents=[]),t.scenes[n]=r,t.sceneNames.add(n);const{show:s,hide:i,parents:c,...u}=r,l={};l[n]=u,o.load(l)}))}}(s,o),r.show=function(e,t){return function({scene:n,options:o={ssr:!1}},...r){const{shortcutMngr:s,askForPromise:i,log:c,findInstructions:u,setInstruction:l}=e,a=i(),f=i(),{opened:d,scenes:p,sceneNames:m,currentPage:h}=t;if(h){const e=p[h].beforeHide;"function"==typeof e&&e({done:f.done,dependencies:s.getDependencies()})}else f.done(!0);return f.onComplete((e=>{if(!e)return a.done(),a.promise;if(!m.has(n)&&c)return c({message:`Scene ${n} is not available.`,level:1,type:"error"}),a.done(),a.promise;if(!d&&o.ssr)return t.opened=!0,t.currentPage=n,s.changeContext(n),a.done(),a.promise;const{show:f,parents:h=[]}=p[n];if("*"===h[0])return f().then((()=>a.done())),t.currentParents.push(t.currentPage),t.currentPage=n,a.promise;function g([e,n]){if("show"===n)t.currentScene&&t.currentParents.push(t.currentScene),t.currentScene=e;else{let e=t.currentParents.pop();t.currentScene=e}return p[e][n]}h.forEach((e=>m.has(e))),t.currentParents||(t.currentParents=[]);const y=u(t.currentScene,t.currentParents,n,h),v=[];for(let e of y)[e].map(g).map((e=>v.push(l(e),...r)));i.sequence(v).onComplete((()=>{t.opened=!0,s.changeContext(n),"function"==typeof p[n].afterShow&&p[n].afterShow({dependencies:s.getDependencies(),done:()=>{}}),a.done()}))})),a.promise}}(s,o),r.loadPlugins=async function(e){const t=e.map((e=>`plugin${e}`)),n=await Promise.resolve().then((function(){return a}));return t.map((e=>n[e]))},r.setDependencies=e=>t.setDependencies(e),r.getDependencies=()=>t.getDependencies(),r.setNote=e=>l.setNote(e),r.listScenes=()=>[...o.sceneNames],r.enablePlugin=(e,n)=>t.enablePlugin(e,n),r.disablePlugin=e=>t.disablePlugin(e),r.emit=(e,...n)=>t.emit(e,...n),r}}));
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@peter.naydenov/cuts",
|
|
3
3
|
"description": "SPA scene manager",
|
|
4
|
-
"version": "1.2.
|
|
4
|
+
"version": "1.2.6",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Peter Naydenov",
|
|
7
7
|
"main": "./src/main.js",
|
|
@@ -35,15 +35,15 @@
|
|
|
35
35
|
"@rollup/plugin-commonjs": "^28.0.2",
|
|
36
36
|
"@rollup/plugin-node-resolve": "^16.0.0",
|
|
37
37
|
"@rollup/plugin-terser": "^0.4.4",
|
|
38
|
-
"@types/node": "^22.10.
|
|
38
|
+
"@types/node": "^22.10.7",
|
|
39
39
|
"@vitejs/plugin-vue": "^5.2.1",
|
|
40
40
|
"c8": "^10.1.3",
|
|
41
41
|
"chai": "^5.1.2",
|
|
42
|
-
"cypress": "^
|
|
42
|
+
"cypress": "^14.0.0",
|
|
43
43
|
"mocha": "^11.0.1",
|
|
44
|
-
"rollup": "^4.
|
|
44
|
+
"rollup": "^4.31.0",
|
|
45
45
|
"typescript": "^5.7.3",
|
|
46
|
-
"vite": "^6.0.
|
|
46
|
+
"vite": "^6.0.10",
|
|
47
47
|
"vue": "^3.5.13"
|
|
48
48
|
},
|
|
49
49
|
"dependencies": {
|
package/src/methods/setScenes.js
CHANGED
|
@@ -31,7 +31,13 @@ function setScenes ( dependencies, state ) {
|
|
|
31
31
|
*/
|
|
32
32
|
return function setScenes ( list ) {
|
|
33
33
|
const { shortcutMngr } = dependencies;
|
|
34
|
-
list.forEach (
|
|
34
|
+
list.forEach ( item => {
|
|
35
|
+
if ( item == null ) return
|
|
36
|
+
const {name, scene } = item;
|
|
37
|
+
if ( scene == null ) {
|
|
38
|
+
console.warn ( `Scene ${name} is not defined` )
|
|
39
|
+
return
|
|
40
|
+
}
|
|
35
41
|
if ( !scene.parents ) scene.parents = []
|
|
36
42
|
state.scenes[name] = scene
|
|
37
43
|
state.sceneNames.add ( name )
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"setScenes.d.ts","sourceRoot":"","sources":["../../src/methods/setScenes.js"],"names":[],"mappings":";;;AAGA;;;;;;;;GAQG;AAIH;;;;GAIG;AAKH,kEAGe,gBAAgB,EAAE,
|
|
1
|
+
{"version":3,"file":"setScenes.d.ts","sourceRoot":"","sources":["../../src/methods/setScenes.js"],"names":[],"mappings":";;;AAGA;;;;;;;;GAQG;AAIH;;;;GAIG;AAKH,kEAGe,gBAAgB,EAAE,UA0B/B"}
|
package/test/01-general.cy.js
DELETED
|
@@ -1,243 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
import VisualController from '@peter.naydenov/visual-controller-for-vue3' // Docs : https://github.com/PeterNaydenov/visual-controller-for-vue3
|
|
4
|
-
import { expect } from 'chai'
|
|
5
|
-
import cuts from '../src/main.js'
|
|
6
|
-
import { pluginClick } from '@peter.naydenov/shortcuts'
|
|
7
|
-
|
|
8
|
-
import Dummy from './dummy.vue'
|
|
9
|
-
import Red from './red.vue'
|
|
10
|
-
import Blue from './blue.vue'
|
|
11
|
-
import Gray from './gray.vue'
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
describe ( 'General', () => {
|
|
16
|
-
|
|
17
|
-
it ( 'Start a sreenWriter. ScreenWriter API', () => {
|
|
18
|
-
const script = cuts ();
|
|
19
|
-
expect ( script ).to.have.property ( 'show' )
|
|
20
|
-
expect ( script ).to.have.property ( 'hide' )
|
|
21
|
-
expect ( script ).to.have.property ( 'setScenes' )
|
|
22
|
-
expect ( script ).to.have.property ( 'setNote' )
|
|
23
|
-
expect ( script ).to.have.property ( 'listScenes' )
|
|
24
|
-
expect ( script ).to.have.property ( 'listShortcuts' )
|
|
25
|
-
expect ( script ).to.have.property ( 'setDependencies' )
|
|
26
|
-
expect ( script ).to.have.property ( 'getDependencies' )
|
|
27
|
-
}) // it start a director
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
it ( 'Load a top level page', done => {
|
|
32
|
-
let
|
|
33
|
-
render = false
|
|
34
|
-
, click = false
|
|
35
|
-
, html = new VisualController ()
|
|
36
|
-
;
|
|
37
|
-
const
|
|
38
|
-
script = cuts ()
|
|
39
|
-
, d = document.querySelector ('[data-cy-root]')
|
|
40
|
-
, testScene = {
|
|
41
|
-
show : ({ task, dependencies }) => {
|
|
42
|
-
const { html } = dependencies;
|
|
43
|
-
html.publish ( Red, {}, 'container' )
|
|
44
|
-
render = true
|
|
45
|
-
task.done ()
|
|
46
|
-
}
|
|
47
|
-
, hide : ({task, dependencies}) => {
|
|
48
|
-
const { html } = dependencies;
|
|
49
|
-
html.destroy ( 'container' )
|
|
50
|
-
task.done ()
|
|
51
|
-
}
|
|
52
|
-
, 'click: left-1' : ({dependencies,target}) => {
|
|
53
|
-
click = true
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
;
|
|
57
|
-
script.enablePlugin ( pluginClick )
|
|
58
|
-
d.id = 'root'
|
|
59
|
-
html.publish ( Dummy, {}, 'root' )
|
|
60
|
-
|
|
61
|
-
cy.wait ( 0 )
|
|
62
|
-
.then ( () => {
|
|
63
|
-
script.setDependencies ({ html })
|
|
64
|
-
script.setScenes ([
|
|
65
|
-
{ name:'test', scene:testScene }
|
|
66
|
-
])
|
|
67
|
-
script.show ({ scene : 'test' })
|
|
68
|
-
// cy.get ( '#target' ).click ()
|
|
69
|
-
})
|
|
70
|
-
.then ( () => {
|
|
71
|
-
expect ( render ).to.be.true
|
|
72
|
-
// expect ( click ).to.be.true
|
|
73
|
-
return cy.wait ( 0 )
|
|
74
|
-
})
|
|
75
|
-
.then ( () => {
|
|
76
|
-
return script.hide ()
|
|
77
|
-
})
|
|
78
|
-
.then ( () => {
|
|
79
|
-
const pageContent = document.getElementById('container').innerHTML
|
|
80
|
-
expect ( pageContent ).to.be.empty
|
|
81
|
-
done ()
|
|
82
|
-
})
|
|
83
|
-
}) // it load a top level page
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
it ( 'Load a deep level page', done => {
|
|
88
|
-
let
|
|
89
|
-
render = false
|
|
90
|
-
, click = false
|
|
91
|
-
, html = new VisualController ()
|
|
92
|
-
;
|
|
93
|
-
const
|
|
94
|
-
script = cuts ()
|
|
95
|
-
, d = document.querySelector ('[data-cy-root]' )
|
|
96
|
-
, testScene = {
|
|
97
|
-
show : ({ task, dependencies }) => {
|
|
98
|
-
const { html } = dependencies;
|
|
99
|
-
html.publish ( Red, {}, 'container' )
|
|
100
|
-
render = true
|
|
101
|
-
task.done ()
|
|
102
|
-
}
|
|
103
|
-
, hide : ({task, dependencies}) => {
|
|
104
|
-
const { html } = dependencies;
|
|
105
|
-
html.destroy ( 'container' )
|
|
106
|
-
task.done ()
|
|
107
|
-
}
|
|
108
|
-
, parents : [ 'blue' ]
|
|
109
|
-
, 'click: 1-left' : ({dependencies,target}) => { // Order in the event name after the prefix is not important
|
|
110
|
-
click = true
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
, bluePage = {
|
|
114
|
-
show : ({ task, dependencies }) => {
|
|
115
|
-
const { html } = dependencies;
|
|
116
|
-
html.publish ( Blue, {}, 'blue' )
|
|
117
|
-
task.done ()
|
|
118
|
-
}
|
|
119
|
-
, hide : ({task, dependencies}) => {
|
|
120
|
-
const { html } = dependencies;
|
|
121
|
-
html.destroy ( 'blue' )
|
|
122
|
-
task.done ()
|
|
123
|
-
}
|
|
124
|
-
, 'click: left-1' : ({dependencies,target}) => {}
|
|
125
|
-
}
|
|
126
|
-
;
|
|
127
|
-
script.enablePlugin ( pluginClick )
|
|
128
|
-
d.id = 'root'
|
|
129
|
-
html.publish ( Dummy, {}, 'root' )
|
|
130
|
-
|
|
131
|
-
cy.wait ( 0 )
|
|
132
|
-
.then ( () => {
|
|
133
|
-
script.setDependencies ({ html })
|
|
134
|
-
script.setScenes ([
|
|
135
|
-
{ name:'test' , scene : testScene }
|
|
136
|
-
, { name: 'blue', scene : bluePage }
|
|
137
|
-
])
|
|
138
|
-
script.show ({ scene: 'test' })
|
|
139
|
-
cy.get ( '#target' ).click ()
|
|
140
|
-
})
|
|
141
|
-
.then ( () => {
|
|
142
|
-
expect ( render ).to.be.true
|
|
143
|
-
expect ( click ).to.be.true
|
|
144
|
-
return cy.wait ( 0 )
|
|
145
|
-
})
|
|
146
|
-
.then ( () => {
|
|
147
|
-
return script.hide ( '*' )
|
|
148
|
-
})
|
|
149
|
-
.then ( () => {
|
|
150
|
-
const pageContent = document.getElementById('container').innerHTML
|
|
151
|
-
expect ( pageContent ).to.be.empty
|
|
152
|
-
done ()
|
|
153
|
-
})
|
|
154
|
-
}) // it load a deep level page
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
it ( 'Turn to other branch', done => {
|
|
159
|
-
let
|
|
160
|
-
render = false
|
|
161
|
-
, click = false
|
|
162
|
-
, html = new VisualController ()
|
|
163
|
-
;
|
|
164
|
-
const
|
|
165
|
-
script = cuts ()
|
|
166
|
-
, d = document.querySelector ('[data-cy-root]' )
|
|
167
|
-
, testScene = {
|
|
168
|
-
show : ({ task, dependencies }) => {
|
|
169
|
-
const { html } = dependencies;
|
|
170
|
-
html.publish ( Red, {}, 'subgray' ) // subgray is inside 'blue' component
|
|
171
|
-
render = true
|
|
172
|
-
task.done ()
|
|
173
|
-
}
|
|
174
|
-
, hide : ({task, dependencies}) => {
|
|
175
|
-
const { html } = dependencies;
|
|
176
|
-
html.destroy ( 'subgray' )
|
|
177
|
-
task.done ()
|
|
178
|
-
}
|
|
179
|
-
, parents : [ 'blue' ]
|
|
180
|
-
, 'click: left-1' : ({dependencies,target}) => {
|
|
181
|
-
click = true
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
, bluePage = {
|
|
185
|
-
show : ({ task, dependencies }) => {
|
|
186
|
-
const { html } = dependencies;
|
|
187
|
-
html.publish ( Blue, {}, 'blue' )
|
|
188
|
-
task.done ()
|
|
189
|
-
}
|
|
190
|
-
, hide : ({task, dependencies}) => {
|
|
191
|
-
const { html } = dependencies;
|
|
192
|
-
html.destroy ( 'blue' )
|
|
193
|
-
task.done ()
|
|
194
|
-
}
|
|
195
|
-
, 'click: left-1' : ({dependencies,target}) => {}
|
|
196
|
-
}
|
|
197
|
-
, grayPage = {
|
|
198
|
-
show : ({ task, dependencies }) => {
|
|
199
|
-
const { html } = dependencies;
|
|
200
|
-
html.publish ( Gray, {}, 'subgray' )
|
|
201
|
-
task.done ()
|
|
202
|
-
}
|
|
203
|
-
, hide : ({task, dependencies}) => {
|
|
204
|
-
const { html } = dependencies;
|
|
205
|
-
html.destroy ( 'subgray' )
|
|
206
|
-
task.done ()
|
|
207
|
-
}
|
|
208
|
-
, parents : [ 'blue' ]
|
|
209
|
-
, 'click: left-1' : ({dependencies,target}) => {}
|
|
210
|
-
}
|
|
211
|
-
;
|
|
212
|
-
script.enablePlugin ( pluginClick )
|
|
213
|
-
d.id = 'root'
|
|
214
|
-
html.publish ( Dummy, {}, 'root' )
|
|
215
|
-
|
|
216
|
-
cy.wait ( 0 )
|
|
217
|
-
.then ( () => {
|
|
218
|
-
script.setDependencies ({ html })
|
|
219
|
-
script.setScenes ([
|
|
220
|
-
{ name:'test', scene : testScene }
|
|
221
|
-
, { name: 'blue', scene : bluePage }
|
|
222
|
-
, { name: 'gray', scene : grayPage }
|
|
223
|
-
])
|
|
224
|
-
script.show ({ scene : 'test' })
|
|
225
|
-
cy.get ( '#target' ).click ()
|
|
226
|
-
})
|
|
227
|
-
.then ( () => {
|
|
228
|
-
expect ( render ).to.be.true
|
|
229
|
-
expect ( click ).to.be.true
|
|
230
|
-
return cy.wait ( 0 )
|
|
231
|
-
})
|
|
232
|
-
.then ( () => script.show ({ scene : 'gray' } ))
|
|
233
|
-
.then ( () => {
|
|
234
|
-
const
|
|
235
|
-
red = document.querySelectorAll ( '.red' )
|
|
236
|
-
, blue = document.querySelectorAll ( '.gray' )
|
|
237
|
-
;
|
|
238
|
-
expect ( blue.length ).to.be.equal ( 1 )
|
|
239
|
-
expect ( red.length ).to.be.equal ( 0 )
|
|
240
|
-
done ()
|
|
241
|
-
})
|
|
242
|
-
}) // it turn to other branch
|
|
243
|
-
}) // describe
|
package/test/blue.vue
DELETED
package/test/dummy.vue
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<div>
|
|
3
|
-
<h1>Test</h1>
|
|
4
|
-
<p id="target">Test <a href="#">lorem ipsum</a></p>
|
|
5
|
-
<div id="container">
|
|
6
|
-
|
|
7
|
-
</div>
|
|
8
|
-
<div id="blue"></div>
|
|
9
|
-
<div id="gray"></div>
|
|
10
|
-
</div>
|
|
11
|
-
</template>
|
|
12
|
-
|
|
13
|
-
<style>
|
|
14
|
-
:root {
|
|
15
|
-
--blue: #007bff;
|
|
16
|
-
--gray: #6c757d;
|
|
17
|
-
--link-color: rgb(204, 51, 10);
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
body.dark {
|
|
21
|
-
--background-color: #000;
|
|
22
|
-
--link-color: rgb(249, 249, 249);
|
|
23
|
-
background-color: var(--background-color);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
#target {
|
|
27
|
-
--blue: var(--link-color);
|
|
28
|
-
color: var(--blue);
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
#target a {
|
|
32
|
-
color: var(--link-color);
|
|
33
|
-
}
|
|
34
|
-
</style>
|
package/test/gray.vue
DELETED
package/test/red.vue
DELETED
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
import findInstructions from "../src/findInstructions.js"
|
|
4
|
-
import { expect } from 'chai'
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
describe ( 'Find a Position', () => {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
it ( 'Switch top level pages', () => {
|
|
12
|
-
let result = []
|
|
13
|
-
let g = findInstructions ( 'old', undefined, 'new', undefined );
|
|
14
|
-
|
|
15
|
-
for ( const n of g ) { result.push ( n ) }
|
|
16
|
-
|
|
17
|
-
expect ( result.length ).to.be.equal ( 2 )
|
|
18
|
-
expect ( result[0][0] ).to.be.equal ( 'old' )
|
|
19
|
-
expect ( result[0][1] ).to.be.equal ( 'hide' )
|
|
20
|
-
|
|
21
|
-
expect ( result[1][0] ).to.be.equal ( 'new' )
|
|
22
|
-
expect ( result[1][1] ).to.be.equal ( 'show' )
|
|
23
|
-
}) // it switch top level pages
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
it ( 'Switch from child page to top level page', () => {
|
|
28
|
-
let result = [];
|
|
29
|
-
let g = findInstructions ( 'old', ['one','two'], 'new', undefined );
|
|
30
|
-
|
|
31
|
-
for ( const n of g ) { result.push ( n ) }
|
|
32
|
-
|
|
33
|
-
expect ( result[0]).to.be.deep.equal ( ['old', 'hide'] )
|
|
34
|
-
expect ( result[1]).to.be.deep.equal ( ['two', 'hide'] )
|
|
35
|
-
expect ( result[2]).to.be.deep.equal ( ['one', 'hide'] )
|
|
36
|
-
expect ( result[3]).to.be.deep.equal ( ['new', 'show'] )
|
|
37
|
-
}) // it switch from child page to top level page
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
it ( 'Switch to child page', () => {
|
|
42
|
-
let result = [];
|
|
43
|
-
let g = findInstructions ( 'old', ['bla'], 'new', ['old','two','three'] );
|
|
44
|
-
for ( const n of g ) { result.push ( n ) }
|
|
45
|
-
|
|
46
|
-
expect ( result ).to.have.lengthOf ( 3 )
|
|
47
|
-
expect ( result[0]).to.be.deep.equal ( ['two', 'show'] )
|
|
48
|
-
expect ( result[1]).to.be.deep.equal ( ['three', 'show'] )
|
|
49
|
-
expect ( result[2]).to.be.deep.equal ( ['new', 'show'] )
|
|
50
|
-
}) // it switch to child page
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
it ( 'From child page to other siblings page', () => {
|
|
55
|
-
let result = [];
|
|
56
|
-
let g = findInstructions ( 'old', ['two', 'three'], 'new', ['two','three'] );
|
|
57
|
-
for ( const n of g ) { result.push ( n ) }
|
|
58
|
-
|
|
59
|
-
expect ( result ).to.have.lengthOf ( 2 )
|
|
60
|
-
expect ( result[0]).to.be.deep.equal ( ['old', 'hide'] )
|
|
61
|
-
expect ( result[1]).to.be.deep.equal ( ['new', 'show'] )
|
|
62
|
-
}) // it from top level page to not own child page
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
it ( 'From top level page to not own child page', () => {
|
|
67
|
-
let result = [];
|
|
68
|
-
let g = findInstructions ( 'old', undefined, 'new', ['two','three'] );
|
|
69
|
-
for ( const n of g ) { result.push ( n ) }
|
|
70
|
-
|
|
71
|
-
expect ( result ).to.have.lengthOf ( 3 )
|
|
72
|
-
expect ( result[0]).to.be.deep.equal ( ['old', 'hide'] )
|
|
73
|
-
expect ( result[1]).to.be.deep.equal ( ['two', 'show'] )
|
|
74
|
-
expect ( result[2]).to.be.deep.equal ( ['three', 'show'] )
|
|
75
|
-
}) // it from top level page to not own child page
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
it ( 'Long chain of parents', () => {
|
|
80
|
-
let result = [];
|
|
81
|
-
let g = findInstructions ( 'old', [ 'one', 'branch' ], 'new', [ 'one','two','three'] );
|
|
82
|
-
for ( const n of g ) { result.push ( n ) }
|
|
83
|
-
|
|
84
|
-
expect ( result ).to.have.lengthOf ( 5 )
|
|
85
|
-
expect ( result[0]).to.be.deep.equal ( ['old', 'hide'] )
|
|
86
|
-
expect ( result[1]).to.be.deep.equal ( ['branch', 'hide'] )
|
|
87
|
-
expect ( result[2]).to.be.deep.equal ( ['two', 'show'] )
|
|
88
|
-
expect ( result[3]).to.be.deep.equal ( ['three', 'show'] )
|
|
89
|
-
expect ( result[4]).to.be.deep.equal ( ['new', 'show'] )
|
|
90
|
-
}) // it long chain of parents
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
it ( 'Different branches', () => {
|
|
95
|
-
let result = [];
|
|
96
|
-
let g = findInstructions ( 'old', [ 'something', 'branch' ], 'new', [ 'one','two','three'] );
|
|
97
|
-
for ( const n of g ) { result.push ( n ) }
|
|
98
|
-
|
|
99
|
-
expect ( result ).to.have.lengthOf ( 7 )
|
|
100
|
-
expect ( result[0]).to.be.deep.equal ( ['old', 'hide'] )
|
|
101
|
-
expect ( result[1]).to.be.deep.equal ( ['branch', 'hide'] )
|
|
102
|
-
expect ( result[2]).to.be.deep.equal ( ['something', 'hide'] )
|
|
103
|
-
expect ( result[3]).to.be.deep.equal ( ['one', 'show'] )
|
|
104
|
-
expect ( result[4]).to.be.deep.equal ( ['two', 'show'] )
|
|
105
|
-
expect ( result[5]).to.be.deep.equal ( ['three', 'show'] )
|
|
106
|
-
expect ( result[6]).to.be.deep.equal ( ['new', 'show'] )
|
|
107
|
-
}) // it long chain of parents
|
|
108
|
-
|
|
109
|
-
}) // describe
|