{"version":3,"file":"simpleline.min.js","sources":["../../src/simpleline/simpleline.js"],"sourcesContent":["/* eslint no-console: \"off\"*/\n/* eslint no-trailing-spaces: \"off\"*/\n\n/*\nThe MIT License (MIT)\n\nCopyright (c) 2023 P.M. Kuipers\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n*/\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 el