var MultimodalWebSurfer = MultimodalWebSurfer || (function() { let nextLabel = 10; let roleMapping = { "a": "link", "area": "link", "button": "button", "input, type=button": "button", "input, type=checkbox": "checkbox", "input, type=email": "textbox", "input, type=number": "spinbutton", "input, type=radio": "radio", "input, type=range": "slider", "input, type=reset": "button", "input, type=search": "searchbox", "input, type=submit": "button", "input, type=tel": "textbox", "input, type=text": "textbox", "input, type=url": "textbox", "search": "search", "select": "combobox", "option": "option", "textarea": "textbox" }; let getCursor = function(elm) { return window.getComputedStyle(elm)["cursor"]; }; let getInteractiveElements = function() { let results = [] let roles = ["scrollbar", "searchbox", "slider", "spinbutton", "switch", "tab", "treeitem", "button", "checkbox", "gridcell", "link", "menuitem", "menuitemcheckbox", "menuitemradio", "option", "progressbar", "radio", "textbox", "combobox", "menu", "tree", "treegrid", "grid", "listbox", "radiogroup", "widget"]; let inertCursors = ["auto", "default", "none", "text", "vertical-text", "not-allowed", "no-drop"]; // Get the main interactive elements let nodeList = document.querySelectorAll("input, select, textarea, button, [href], [onclick], [contenteditable], [tabindex]:not([tabindex='-1'])"); for (let i=0; i -1) { results.push(nodeList[i]); } } } // Any element that changes the cursor to something implying interactivity nodeList = document.querySelectorAll("*"); for (let i=0; i= 0) { continue; } // Move up to the first instance of this cursor change parent = node.parentNode; while (parent && getCursor(parent) == cursor) { node = parent; parent = node.parentNode; } // Add the node if it is new if (results.indexOf(node) == -1) { results.push(node); } } return results; }; let labelElements = function(elements) { for (let i=0; i= 1; let record = { "tag_name": ariaRole[1], "role": ariaRole[0], "aria-name": ariaName, "v-scrollable": vScrollable, "rects": [] }; for (const rect of rects) { let x = rect.left + rect.width/2; let y = rect.top + rect.height/2; if (isTopmost(elements[i], x, y)) { record["rects"].push(JSON.parse(JSON.stringify(rect))); } } if (record["rects"].length > 0) { results[key] = record; } } return results; }; let getVisualViewport = function() { let vv = window.visualViewport; let de = document.documentElement; return { "height": vv ? vv.height : 0, "width": vv ? vv.width : 0, "offsetLeft": vv ? vv.offsetLeft : 0, "offsetTop": vv ? vv.offsetTop : 0, "pageLeft": vv ? vv.pageLeft : 0, "pageTop": vv ? vv.pageTop : 0, "scale": vv ? vv.scale : 0, "clientWidth": de ? de.clientWidth : 0, "clientHeight": de ? de.clientHeight : 0, "scrollWidth": de ? de.scrollWidth : 0, "scrollHeight": de ? de.scrollHeight : 0 }; }; let _getMetaTags = function() { let meta = document.querySelectorAll("meta"); let results = {}; for (let i = 0; i { addValue(information, propName, childInfo); }); } } else if (child.hasAttribute('itemprop')) { const itemProp = child.getAttribute('itemprop'); itemProp.split(' ').forEach(propName => { if (propName === 'url') { addValue(information, propName, child.href); } else { addValue(information, propName, sanitize(child.getAttribute("content") || child.content || child.textContent || child.src || "")); } }); traverseItem(child, information); } else { traverseItem(child, information); } } } const microdata = []; document.querySelectorAll("[itemscope]").forEach(function(elem, i) { const itemType = elem.getAttribute('itemtype'); const information = { itemType: itemType }; traverseItem(elem, information); microdata.push(information); }); return microdata; }; let getPageMetadata = function() { let jsonld = _getJsonLd(); let metaTags = _getMetaTags(); let microdata = _getMicrodata(); let results = {} if (jsonld.length > 0) { try { results["jsonld"] = JSON.parse(jsonld); } catch (e) { results["jsonld"] = jsonld; } } if (microdata.length > 0) { results["microdata"] = microdata; } for (let key in metaTags) { if (metaTags.hasOwnProperty(key)) { results["meta_tags"] = metaTags; break; } } return results; }; return { getInteractiveRects: getInteractiveRects, getVisualViewport: getVisualViewport, getFocusedElementId: getFocusedElementId, getPageMetadata: getPageMetadata, }; })();