moodle_local_treestudyplan/amd/build/simpleline.min.js.map

1 line
24 KiB
Plaintext
Raw Normal View History

{"version":3,"file":"simpleline.min.js","sources":["../src/simpleline.js"],"sourcesContent":["/*eslint no-console: \"off\"*/\n/*eslint no-trailing-spaces: \"off\"*/\n\nimport {calc} from \"./css-calc\";\n\n\n/**\n * Copies defined properties in to, over from the from object. Does so recursively\n * Used to copy user defined parameters onto a pre-existing object with defaults preset.\n * @param {Object} to The object to copy to\n * @param {Object} from The object tp copy from (but only the properties already named in \"to\")\n */\nconst specsCopy = (to, from) => {\n for(const ix in to){\n if(from.hasOwnProperty(ix)){\n if( typeof to[ix] == \"object\"\n && typeof from[ix] == \"object\")\n {\n if(Array.isArray(to[ix])){\n if(Array.isArray(from[ix])){\n to[ix] = Array.from(from[ix]);\n } // else, skip...\n } else {\n specsCopy(to[ix], from[ix]); // recursive copy\n }\n }\n else {\n to[ix] = from[ix];\n }\n }\n }\n};\n\nconst debounce = (func, delay) => {\n let timer;\n return function(...args) {\n const context = this;\n clearTimeout(timer);\n timer = setTimeout(() => {\n func.apply(context, args);\n }, delay);\n };\n};\n\n/**\n * Get the position of an element relative to another\n * @param {HTMLElement} el The element whose position to determine\n * @param {HTMLElement} reference Relative to this element\n * @returns {object} Position object with {x: ..., y:...}\n */\nconst getElementPosition = (el, reference) => {\n if(!el || !(el instanceof HTMLElement)){\n // Always return 0,0 if the element is invalid\n return {x: 0, y: 0};\n }\n\n if (!reference || !(reference instanceof HTMLElement)){\n // Take the document body as reference if the reference is invalud\n reference = document.querySelector(\"body\");\n }\n\n if( el.offsetParent === reference){\n // easily done if the reference element is also the offsetParent..\n return {x: el.offsetLeft, y: el.offsetTop};\n } else {\n const elR = el.getBoundingClientRect();\n const refR = reference.getBoundingClientRect();\n\n return {x: elR.left - refR.left,\n y: elR.top - refR.top};\n }\n};\n\nexport class SimpleLine {\n static idCounter = 0;\n\n /**\n * Create a new line object\n * \n * @param {HTMLElement|string} start The element the line starts from\n * @param {HTMLElement|string} end The element the line ends at\n * @param {object} config Configuration for the \n * @returns {SimpleLine} object\n */\n constructor(start, end, config){\n this.svg = null;\n this.id = SimpleLine.idCounter++;\n\n this.setConfig(config);\n // Validate start element\n if(start instanceof HTMLElement) {\n this.start = start;\n } else if (typeof start === 'string' || this.start instanceof String) {\n this.startSelector = start;\n this.start = document.querySelector(start);\n if(!(this.start instanceof HTMLElement)){\n console.error(\"Cannot find start element:\",start);\n return;\n }\n } else {\n console.error(\"Start element not string or dom element\",start);\n return;\n }\n\n // Validate end element\n if(end instanceof HTMLElement) {\n this.end = end;\n } else if (typeof end === 'string' || this.end instanceof String) {\n this.endSelector = end;\n this.end = document.querySelector(end);\n if(!(this.end instanceof HTMLElement)){\n console.error(\"Cannot find end element:\",end);\n return;\n }\n } else {\n console.error(\"End element not string or dom element\",start);\n return;\n }\n\n //