UNPKG

svelte-parse

Version:

An increidbly relaxed svelte-parser

298 lines (297 loc) 6.19 kB
{ "type": "root", "children": [ { "type": "svelteScript", "tagName": "script", "properties": [], "selfClosing": false, "children": [ { "type": "text", "value": "\n\timport { onMount } from 'svelte';\n\n\texport let once = false;\n\texport let top = 0;\n\texport let bottom = 0;\n\texport let left = 0;\n\texport let right = 0;\n\n\tlet intersecting = false;\n\tlet container;\n\n\tonMount(() => {\n\t\tif (typeof IntersectionObserver !== 'undefined') {\n\t\t\tconst rootMargin = `${bottom}px ${left}px ${top}px ${right}px`;\n\n\t\t\tconst observer = new IntersectionObserver(entries => {\n\t\t\t\tintersecting = entries[0].isIntersecting;\n\t\t\t\tif (intersecting && once) {\n\t\t\t\t\tobserver.unobserve(container);\n\t\t\t\t}\n\t\t\t}, {\n\t\t\t\trootMargin\n\t\t\t});\n\n\t\t\tobserver.observe(container);\n\t\t\treturn () => observer.unobserve(container);\n\t\t}\n\n\t\tfunction handler() {\n\t\t\tconst bcr = container.getBoundingClientRect();\n\n\t\t\tintersecting = (\n\t\t\t\t(bcr.bottom + bottom) > 0 &&\n\t\t\t\t(bcr.right + right) > 0 &&\n\t\t\t\t(bcr.top - top) < window.innerHeight &&\n\t\t\t\t(bcr.left - left) < window.innerWidth\n\t\t\t);\n\n\t\t\tif (intersecting && once) {\n\t\t\t\twindow.removeEventListener('scroll', handler);\n\t\t\t}\n\t\t}\n\n\t\twindow.addEventListener('scroll', handler);\n\t\treturn () => window.removeEventListener('scroll', handler);\n\t});\n", "position": { "start": { "line": 1, "column": 9, "offset": 8 }, "end": { "line": 48, "column": 1, "offset": 1093 } } } ], "position": { "start": { "line": 1, "column": 1, "offset": 0 }, "end": { "line": 48, "column": 10, "offset": 1102 } } }, { "type": "text", "value": "\n\n", "position": { "start": { "line": 48, "column": 10, "offset": 1102 }, "end": { "line": 50, "column": 1, "offset": 1104 } } }, { "type": "svelteStyle", "tagName": "style", "properties": [], "selfClosing": false, "children": [ { "type": "text", "value": "\n\tdiv {\n\t\twidth: 100%;\n\t\theight: 100%;\n\t}\n", "position": { "start": { "line": 50, "column": 8, "offset": 1111 }, "end": { "line": 55, "column": 1, "offset": 1153 } } } ], "position": { "start": { "line": 50, "column": 1, "offset": 1104 }, "end": { "line": 55, "column": 9, "offset": 1161 } } }, { "type": "text", "value": "\n\n", "position": { "start": { "line": 55, "column": 9, "offset": 1161 }, "end": { "line": 57, "column": 1, "offset": 1163 } } }, { "type": "svelteElement", "tagName": "div", "properties": [ { "type": "svelteDirective", "name": "bind", "value": [ { "type": "svelteDynamicContent", "position": { "start": { "line": 57, "column": 16, "offset": 1178 }, "end": { "line": 57, "column": 27, "offset": 1189 } }, "expression": { "type": "svelteExpression", "value": "container", "position": { "start": { "line": 57, "column": 17, "offset": 1179 }, "end": { "line": 57, "column": 26, "offset": 1188 } } } } ], "modifiers": [], "shorthand": "none", "position": { "start": { "line": 57, "column": 6, "offset": 1168 }, "end": { "line": 57, "column": 27, "offset": 1189 } }, "specifier": "this" } ], "selfClosing": false, "children": [ { "type": "text", "value": "\n\t", "position": { "start": { "line": 57, "column": 28, "offset": 1190 }, "end": { "line": 58, "column": 2, "offset": 1192 } } }, { "type": "svelteElement", "tagName": "slot", "properties": [ { "type": "svelteProperty", "name": "intersecting", "value": [ { "type": "svelteDynamicContent", "expression": { "type": "svelteExpression", "value": "intersecting", "position": { "start": { "line": 58, "column": 9, "offset": 1199 }, "end": { "line": 58, "column": 21, "offset": 1211 } } }, "position": { "start": { "line": 58, "column": 8, "offset": 1198 }, "end": { "line": 58, "column": 21, "offset": 1211 } } } ], "modifiers": [], "shorthand": "expression", "position": { "start": { "line": 58, "column": 8, "offset": 1198 }, "end": { "line": 58, "column": 21, "offset": 1211 } } } ], "selfClosing": false, "children": [], "position": { "start": { "line": 58, "column": 2, "offset": 1192 }, "end": { "line": 58, "column": 30, "offset": 1220 } } }, { "type": "text", "value": "\n", "position": { "start": { "line": 58, "column": 30, "offset": 1220 }, "end": { "line": 59, "column": 1, "offset": 1221 } } } ], "position": { "start": { "line": 57, "column": 1, "offset": 1163 }, "end": { "line": 59, "column": 7, "offset": 1227 } } } ], "position": { "start": { "column": 1, "line": 1, "offset": 0 }, "end": { "line": 59, "column": 7, "offset": 1227 } } }