UNPKG

@caspingus/lt

Version:

A utility library of helpers and extensions useful when working with Learnosity APIs.

512 lines (511 loc) 17.2 kB
import { r as e, t } from "../../chunk-BPfpcrXh.js"; import { r as n, t as r } from "../../extensionsFactory-hk5ijx1G.js"; //#region node_modules/platform-detect/index.js var i = /* @__PURE__ */ t(((e, t) => { (function(n, r) { typeof e == "object" && t !== void 0 ? t.exports = r() : typeof define == "function" && define.amd ? define("platform-detect", r) : (n ||= self, n["platform-detect"] = r()); })(e, function() { function e(e, t) { var n = window.matchMedia(e); t(n.matches); var r = function() { return t(n.matches); }; return n.addListener(r), function() { return n.removeListener(r); }; } function t(e, t) { return a[e] !== t && (a[e] = t, s(e, t), !0); } var n = typeof navigator < "u" && typeof window < "u"; if (n && typeof nw < "u") try { nw.Window.get(); } catch { n = !1; } var r = !n, i = n ? navigator.userAgent : void 0, a = { gui: n, terminal: r, registerQuery: e }; a.node = typeof process < "u" && !!process.versions && !!process.versions.node, a.pwa = a.gui && window.matchMedia("(display-mode: standalone)").matches && document.head.querySelector("[rel=\"manifest\"]") !== null, a.uwp = typeof Windows < "u" && typeof MSApp < "u", a.nwjs = !(!a.node || !process.versions.nw), a.electron = !(!a.node || !process.versions.electron), a.cordova = !(!a.gui || !window.cordova), a.packaged = a.uwp || a.nwjs || a.electron || a.cordova, a.web = !a.node && !a.packaged, a.browser = a.web, a.website = a.web && !a.pwa, a.worker = !a.gui && typeof self < "u" && self.importScripts !== void 0, a.serviceWorker = a.worker && !!navigator.serviceWorker.controller || !1, a.android = !!a.gui && i.includes("Android"), a.chromeos = !!a.gui && i.includes("CrOS"), a.tizen = !!a.gui && i.includes("Tizen"), a.ios = a.gui && /iPad|iPhone|iPod/.test(i) && !window.MSStream || !1, a.linuxBased = a.android || a.tizen, a.windows = a.node ? process.platform === "win32" : i.includes("Windows"), a.macos = a.node ? process.platform === "darwin" : i.includes("Macintosh"), a.linux = a.node ? process.platform === "linux" : i.includes("Linux") && !a.linuxBased && !a.macos, a.edgeHtml = a.gui && i.includes("Edge/"), a.edgeChromium = a.gui && i.includes("Edg/"), a.edgeAndroid = a.gui && i.includes("EdgA/"), a.edgeIos = a.gui && i.includes("EdgiOS/"), a.chromeIos = a.gui && i.includes("CriOS/"), a.firefoxIos = a.gui && i.includes("FxiOS/"), a.edge = a.edgeHtml || a.edgeChromium || a.edgeAndroid || a.edgeIos, a.samsungBrowser = a.gui && i.includes("SamsungBrowser/"), a.opera = a.gui && (i.includes("Opera") || i.includes("OPR/")), a.firefox = a.gui && (i.includes("Firefox") || a.firefoxIos), a.chrome = a.gui && (i.includes("Chrome") || a.chromeIos) && !a.edge && !a.opera && !a.samsungBrowser, a.safari = a.gui && i.includes("Safari") && !a.chrome && !a.edge && !a.firefox && !a.opera && !a.samsungBrowser || a.edgeIos || a.chromeIos || a.firefoxIos, a.ie = a.trident = a.gui && i.includes("Trident"), a.blink = a.chrome && !a.chromeIos || a.edgeChromium || a.edgeAndroid || a.samsungBrowser, a.webkit = a.blink || a.safari, a.gecko = a.firefox && !a.firefoxIos && !a.webkit && !a.safari; var o = {}; a.on = function(e, t) { o[e] = o[e] || /* @__PURE__ */ new Set(), o[e].add(t); }, a.off = a.removeListener = function(e, t) { o[e] && o[e].delete(t); }; var s = a.emit = function(e, t) { o[e] && o[e].forEach(function(e) { return e(t); }); }; if (a.gui) { a.pixelRatio = parseFloat(window.devicePixelRatio.toFixed(2)), a.gameconsole = i.includes("Xbox") || i.includes("PlayStation"); var c = 0; if (window.addEventListener("gamepadconnected", function(e) { return c++; }), window.addEventListener("gamepaddisconnected", function(e) { return c--; }), a.gameconsole) a.gamepad = !0, a.mouse = !0, a.touch = !1, a.tv = !0, a.battery = !1, a.phone = a.tablet = a.hybrid = a.laptop = a.desktop = !1, a.formfactor = "gameconsole"; else { var l = function() { t("tv", a.formfactor === "tv"), t("phone", a.formfactor === "phone"), t("tablet", a.formfactor === "tablet"), t("hybrid", a.formfactor === "hybrid"), t("laptop", a.formfactor === "laptop"), t("desktop", a.formfactor === "desktop"); }, u = function() { var e = Math.min(window.screen.width, window.screen.height); return a.tv ? "tv" : a.touch && e < 600 ? "phone" : a.touch && !a.mouse ? "tablet" : a.touch && a.mouse ? "hybrid" : a.battery ? "laptop" : "desktop"; }; a.touch = navigator.maxTouchPoints > 0, a.tv = i.includes("TV"), c = navigator.getGamepads ? Array.from(navigator.getGamepads()).filter(function(e) { return e != null; }).length : 0, a.gamepad = c > 0, e("(orientation: portrait)", function(e) { a.portrait = e, a.landscape = !e, a.orientation = e ? "portrait" : "landscape", s("portrait", a.portrait), s("landscape", a.landscape), s("orientation", a.orientation); }), e("(any-pointer: coarse)", function(e) { t("touch", e), t("formfactor", u()) && l(); }), e("(hover: hover)", function(e) { t("mouse", e), t("input", e ? "mouse" : "touch"), t("formfactor", u()) && l(); }); } } return a.csp = a.uwp || !1, a.nwjs ? a.dev = process.versions["nw-flavor"] === "sdk" : a.electron ? a.dev = process.execPath.replace(/\\/g, "/").includes("node_modules/electron/") : a.uwp ? a.dev = Windows.ApplicationModel.Package.current.isDevelopmentMode : a.node ? a.dev = process.env.NODE_ENV !== "production" : a.dev = void 0, a; }); })), a = /* @__PURE__ */ t(((e, t) => { (function(e, n, r) { if (!e) return; for (var i = { 8: "backspace", 9: "tab", 13: "enter", 16: "shift", 17: "ctrl", 18: "alt", 20: "capslock", 27: "esc", 32: "space", 33: "pageup", 34: "pagedown", 35: "end", 36: "home", 37: "left", 38: "up", 39: "right", 40: "down", 45: "ins", 46: "del", 91: "meta", 93: "meta", 224: "meta" }, a = { 106: "*", 107: "+", 109: "-", 110: ".", 111: "/", 186: ";", 187: "=", 188: ",", 189: "-", 190: ".", 191: "/", 192: "`", 219: "[", 220: "\\", 221: "]", 222: "'" }, o = { "~": "`", "!": "1", "@": "2", "#": "3", $: "4", "%": "5", "^": "6", "&": "7", "*": "8", "(": "9", ")": "0", _: "-", "+": "=", ":": ";", "\"": "'", "<": ",", ">": ".", "?": "/", "|": "\\" }, s = { option: "alt", command: "meta", return: "enter", escape: "esc", plus: "+", mod: /Mac|iPod|iPhone|iPad/.test(navigator.platform) ? "meta" : "ctrl" }, c, l = 1; l < 20; ++l) i[111 + l] = "f" + l; for (l = 0; l <= 9; ++l) i[l + 96] = l.toString(); function u(e, t, n) { if (e.addEventListener) { e.addEventListener(t, n, !1); return; } e.attachEvent("on" + t, n); } function d(e) { if (e.type == "keypress") { var t = String.fromCharCode(e.which); return e.shiftKey || (t = t.toLowerCase()), t; } return i[e.which] ? i[e.which] : a[e.which] ? a[e.which] : String.fromCharCode(e.which).toLowerCase(); } function f(e, t) { return e.sort().join(",") === t.sort().join(","); } function p(e) { var t = []; return e.shiftKey && t.push("shift"), e.altKey && t.push("alt"), e.ctrlKey && t.push("ctrl"), e.metaKey && t.push("meta"), t; } function m(e) { if (e.preventDefault) { e.preventDefault(); return; } e.returnValue = !1; } function h(e) { if (e.stopPropagation) { e.stopPropagation(); return; } e.cancelBubble = !0; } function g(e) { return e == "shift" || e == "ctrl" || e == "alt" || e == "meta"; } function _() { if (!c) for (var e in c = {}, i) e > 95 && e < 112 || i.hasOwnProperty(e) && (c[i[e]] = e); return c; } function v(e, t, n) { return n ||= _()[e] ? "keydown" : "keypress", n == "keypress" && t.length && (n = "keydown"), n; } function y(e) { return e === "+" ? ["+"] : (e = e.replace(/\+{2}/g, "+plus"), e.split("+")); } function b(e, t) { var n, r, i, a = []; for (n = y(e), i = 0; i < n.length; ++i) r = n[i], s[r] && (r = s[r]), t && t != "keypress" && o[r] && (r = o[r], a.push("shift")), g(r) && a.push(r); return t = v(r, a, t), { key: r, modifiers: a, action: t }; } function x(e, t) { return e === null || e === n ? !1 : e === t ? !0 : x(e.parentNode, t); } function S(e) { var t = this; if (e ||= n, !(t instanceof S)) return new S(e); t.target = e, t._callbacks = {}, t._directMap = {}; var r = {}, i, a = !1, o = !1, s = !1; function c(e) { e ||= {}; var t = !1, n; for (n in r) { if (e[n]) { t = !0; continue; } r[n] = 0; } t || (s = !1); } function l(e, n, i, a, o, s) { var c, l, u = [], d = i.type; if (!t._callbacks[e]) return []; for (d == "keyup" && g(e) && (n = [e]), c = 0; c < t._callbacks[e].length; ++c) if (l = t._callbacks[e][c], !(!a && l.seq && r[l.seq] != l.level) && d == l.action && (d == "keypress" && !i.metaKey && !i.ctrlKey || f(n, l.modifiers))) { var p = !a && l.combo == o, m = a && l.seq == a && l.level == s; (p || m) && t._callbacks[e].splice(c, 1), u.push(l); } return u; } function _(e, n, r, i) { t.stopCallback(n, n.target || n.srcElement, r, i) || e(n, r) === !1 && (m(n), h(n)); } t._handleKey = function(e, t, n) { var r = l(e, t, n), i, a = {}, u = 0, d = !1; for (i = 0; i < r.length; ++i) r[i].seq && (u = Math.max(u, r[i].level)); for (i = 0; i < r.length; ++i) { if (r[i].seq) { if (r[i].level != u) continue; d = !0, a[r[i].seq] = 1, _(r[i].callback, n, r[i].combo, r[i].seq); continue; } d || _(r[i].callback, n, r[i].combo); } var f = n.type == "keypress" && o; n.type == s && !g(e) && !f && c(a), o = d && n.type == "keydown"; }; function v(e) { typeof e.which != "number" && (e.which = e.keyCode); var n = d(e); if (n) { if (e.type == "keyup" && a === n) { a = !1; return; } t.handleKey(n, p(e), e); } } function y() { clearTimeout(i), i = setTimeout(c, 1e3); } function x(e, t, n, i) { r[e] = 0; function o(t) { return function() { s = t, ++r[e], y(); }; } function l(t) { _(n, t, e), i !== "keyup" && (a = d(t)), setTimeout(c, 10); } for (var u = 0; u < t.length; ++u) { var f = u + 1 === t.length ? l : o(i || b(t[u + 1]).action); C(t[u], f, i, e, u); } } function C(e, n, r, i, a) { t._directMap[e + ":" + r] = n, e = e.replace(/\s+/g, " "); var o = e.split(" "), s; if (o.length > 1) { x(e, o, n, r); return; } s = b(e, r), t._callbacks[s.key] = t._callbacks[s.key] || [], l(s.key, s.modifiers, { type: s.action }, i, e, a), t._callbacks[s.key][i ? "unshift" : "push"]({ callback: n, modifiers: s.modifiers, action: s.action, seq: i, level: a, combo: e }); } t._bindMultiple = function(e, t, n) { for (var r = 0; r < e.length; ++r) C(e[r], t, n); }, u(e, "keypress", v), u(e, "keydown", v), u(e, "keyup", v); } S.prototype.bind = function(e, t, n) { var r = this; return e = e instanceof Array ? e : [e], r._bindMultiple.call(r, e, t, n), r; }, S.prototype.unbind = function(e, t) { var n = this; return n.bind.call(n, e, function() {}, t); }, S.prototype.trigger = function(e, t) { var n = this; return n._directMap[e + ":" + t] && n._directMap[e + ":" + t]({}, e), n; }, S.prototype.reset = function() { var e = this; return e._callbacks = {}, e._directMap = {}, e; }, S.prototype.stopCallback = function(e, t) { var n = this; if ((" " + t.className + " ").indexOf(" mousetrap ") > -1 || x(t, n.target)) return !1; if ("composedPath" in e && typeof e.composedPath == "function") { var r = e.composedPath()[0]; r !== e.target && (t = r); } return t.tagName == "INPUT" || t.tagName == "SELECT" || t.tagName == "TEXTAREA" || t.isContentEditable; }, S.prototype.handleKey = function() { var e = this; return e._handleKey.apply(e, arguments); }, S.addKeycodes = function(e) { for (var t in e) e.hasOwnProperty(t) && (i[t] = e[t]); c = null; }, S.init = function() { var e = S(n); for (var t in e) t.charAt(0) !== "_" && (S[t] = function(t) { return function() { return e[t].apply(e, arguments); }; }(t)); }, S.init(), e.Mousetrap = S, t !== void 0 && t.exports && (t.exports = S), typeof define == "function" && define.amd && define(function() { return S; }); })(typeof window < "u" ? window : null, typeof window < "u" ? document : null); })), o = /* @__PURE__ */ e(i(), 1), s = /* @__PURE__ */ e(a(), 1); function c(e) { return Object.keys(e).length === 0; } //#endregion //#region src/assessment/extensions/accessibility/ux/keyboardShortcuts/index.js var l = { bound: !1, effective: null, overrideDone: !1, platform: null, supportedPlatforms: [ "chromeos", "macos", "windows" ] }; function u(e = x()) { l.platform ||= y(), l.platform && (l.overrideDone ||= (b(), !0), l.effective ||= v(e, l.platform), l.bound ||= (d(l.effective), !0)); } function d(e) { e.global.itemFlag.length && s.bind(e.global.itemFlag, f), e.global.maskingEnable.length && s.bind(e.global.maskingEnable, p), e.item.responseSet.length && s.bind(e.item.responseSet, m), e.item.responseMask.length && s.bind(e.item.responseMask, h); } function f() { r.items.flag(); } function p() { let e = r.questions.questionInstance(); !c(e) && typeof e.isMaskable == "function" && e.isMaskable() && r.itemsApp().questionsApp().masking(!r.items.isMaskingEnabled()); } function m(e, t) { let n = _(); if (!n) return; let r = g(t); if (r != null && Array.isArray(n.options) && n.options.length >= r) { let e = document.getElementById(n.response_id); if (!e) return; let t = e.querySelectorAll(".lrn-input"); t && t[r - 1] && t[r - 1].click(); } } function h(e, t) { if (!r.items.isMaskingEnabled() || !_()) return; let n = g(t); if (n == null) return; let i = r.items.itemElement(); if (!i) return; let a = i.querySelectorAll(".lrn-mcq-option"), o = a && a[n - 1]; if (!o) return; let s = o.querySelector(".lrn-mask"); s && s.click(); } function g(e) { let t = /(\d)$/.exec(e); if (!t) return null; let n = Number(t[1]); return Number.isFinite(n) ? n : null; } function _() { let e = r.questions(), t = null; for (let n of e) if (n && n.type === "mcq") { if (t) return null; t = n; } return t; } function v(e, t) { let n = { global: { itemFlag: [], maskingEnable: [] }, item: { responseSet: [], responseMask: [] } }; if (e && Array.isArray(e.global)) for (let r of e.global) { if (!r || !r.type || !r.bindings) continue; let e = r.bindings[t] || []; !Array.isArray(e) || e.length === 0 || (r.type === "item.flag" ? n.global.itemFlag.push(...e) : r.type === "masking.enable" && n.global.maskingEnable.push(...e)); } if (e && Array.isArray(e.item)) for (let r of e.item) { if (!r || !r.type || !r.bindings) continue; let e = r.bindings[t] || []; !Array.isArray(e) || e.length === 0 || (r.type === "response.set" ? n.item.responseSet.push(...e) : r.type === "response.mask" && n.item.responseMask.push(...e)); } return n; } function y() { for (let e of l.supportedPlatforms) if (o[e]) return e; return null; } function b() { s.prototype.stopCallback = (e, t) => { let n = document.activeElement; return n && (n.getAttribute("type") === "radio" || n.getAttribute("type") === "checkbox") || (" " + t.className + " ").indexOf(" mousetrap ") > -1 ? !1 : t.tagName === "INPUT" || t.tagName === "SELECT" || t.tagName === "TEXTAREA" || t.contentEditable && t.contentEditable === "true"; }; } function x() { return { global: [{ bindings: { chromeos: ["ctrl+shift+v"], macos: ["command+shift+v"], windows: ["ctrl+shift+v"] }, type: "item.flag" }, { bindings: { chromeos: ["ctrl+alt+0"], macos: ["command+option+0"], windows: ["ctrl+alt+0"] }, type: "masking.enable" }], item: [{ bindings: { chromeos: [ "ctrl+shift+1", "ctrl+shift+2", "ctrl+shift+3", "ctrl+shift+4", "ctrl+shift+5", "ctrl+shift+6" ], macos: [ "command+ctrl+1", "command+ctrl+2", "command+ctrl+3", "command+ctrl+4", "command+ctrl+5", "command+ctrl+6" ], windows: [ "ctrl+shift+1", "ctrl+shift+2", "ctrl+shift+3", "ctrl+shift+4", "ctrl+shift+5", "ctrl+shift+6" ] }, restrictTo: ["mcq"], type: "response.set" }, { bindings: { chromeos: [ "ctrl+alt+1", "ctrl+alt+2", "ctrl+alt+3", "ctrl+alt+4", "ctrl+alt+5", "ctrl+alt+6" ], macos: [ "command+option+1", "command+option+2", "command+option+3", "command+option+4", "command+option+5", "command+option+6" ], windows: [ "ctrl+alt+1", "ctrl+alt+2", "ctrl+alt+3", "ctrl+alt+4", "ctrl+alt+5", "ctrl+alt+6" ] }, type: "response.mask" }] }; } var S = n("keyboardShortcuts", u); //#endregion export { S as keyboardShortcuts };