CoolFace
Datasetpublic

basant307/AI_Governance_Project

sourceHugging Faceapache-2.0updated 2mo agoView on Hugging Face
0likes48downloads
index.cjs11872 linesDownload Raw Back to dist
1'use strict';2 3var state = require('@codemirror/state');4var styleMod = require('style-mod');5var w3cKeyname = require('w3c-keyname');6var elt = require('crelt');7 8let nav = typeof navigator != "undefined" ? navigator : { userAgent: "", vendor: "", platform: "" };9let doc = typeof document != "undefined" ? document : { documentElement: { style: {} } };10const ie_edge = /Edge\/(\d+)/.exec(nav.userAgent);11const ie_upto10 = /MSIE \d/.test(nav.userAgent);12const ie_11up = /Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(nav.userAgent);13const ie = !!(ie_upto10 || ie_11up || ie_edge);14const gecko = !ie && /gecko\/(\d+)/i.test(nav.userAgent);15const chrome = !ie && /Chrome\/(\d+)/.exec(nav.userAgent);16const webkit = "webkitFontSmoothing" in doc.documentElement.style;17const safari = !ie && /Apple Computer/.test(nav.vendor);18const ios = safari && (/Mobile\/\w+/.test(nav.userAgent) || nav.maxTouchPoints > 2);19var browser = {20    mac: ios || /Mac/.test(nav.platform),21    windows: /Win/.test(nav.platform),22    linux: /Linux|X11/.test(nav.platform),23    ie,24    ie_version: ie_upto10 ? doc.documentMode || 6 : ie_11up ? +ie_11up[1] : ie_edge ? +ie_edge[1] : 0,25    gecko,26    gecko_version: gecko ? +(/Firefox\/(\d+)/.exec(nav.userAgent) || [0, 0])[1] : 0,27    chrome: !!chrome,28    chrome_version: chrome ? +chrome[1] : 0,29    ios,30    android: /Android\b/.test(nav.userAgent),31    webkit,32    webkit_version: webkit ? +(/\bAppleWebKit\/(\d+)/.exec(nav.userAgent) || [0, 0])[1] : 0,33    safari,34    safari_version: safari ? +(/\bVersion\/(\d+(\.\d+)?)/.exec(nav.userAgent) || [0, 0])[1] : 0,35    tabSize: doc.documentElement.style.tabSize != null ? "tab-size" : "-moz-tab-size"36};37 38function combineAttrs(source, target) {39    for (let name in source) {40        if (name == "class" && target.class)41            target.class += " " + source.class;42        else if (name == "style" && target.style)43            target.style += ";" + source.style;44        else45            target[name] = source[name];46    }47    return target;48}49const noAttrs = Object.create(null);50function attrsEq(a, b, ignore) {51    if (a == b)52        return true;53    if (!a)54        a = noAttrs;55    if (!b)56        b = noAttrs;57    let keysA = Object.keys(a), keysB = Object.keys(b);58    if (keysA.length - (ignore && keysA.indexOf(ignore) > -1 ? 1 : 0) !=59        keysB.length - (ignore && keysB.indexOf(ignore) > -1 ? 1 : 0))60        return false;61    for (let key of keysA) {62        if (key != ignore && (keysB.indexOf(key) == -1 || a[key] !== b[key]))63            return false;64    }65    return true;66}67function setAttrs(dom, attrs) {68    for (let i = dom.attributes.length - 1; i >= 0; i--) {69        let name = dom.attributes[i].name;70        if (attrs[name] == null)71            dom.removeAttribute(name);72    }73    for (let name in attrs) {74        let value = attrs[name];75        if (name == "style")76            dom.style.cssText = value;77        else if (dom.getAttribute(name) != value)78            dom.setAttribute(name, value);79    }80}81function updateAttrs(dom, prev, attrs) {82    let changed = false;83    if (prev)84        for (let name in prev)85            if (!(attrs && name in attrs)) {86                changed = true;87                if (name == "style")88                    dom.style.cssText = "";89                else90                    dom.removeAttribute(name);91            }92    if (attrs)93        for (let name in attrs)94            if (!(prev && prev[name] == attrs[name])) {95                changed = true;96                if (name == "style")97                    dom.style.cssText = attrs[name];98                else99                    dom.setAttribute(name, attrs[name]);100            }101    return changed;102}103function getAttrs(dom) {104    let attrs = Object.create(null);105    for (let i = 0; i < dom.attributes.length; i++) {106        let attr = dom.attributes[i];107        attrs[attr.name] = attr.value;108    }109    return attrs;110}111 112/**113Widgets added to the content are described by subclasses of this114class. Using a description object like that makes it possible to115delay creating of the DOM structure for a widget until it is116needed, and to avoid redrawing widgets even if the decorations117that define them are recreated.118*/119class WidgetType {120    /**121    Compare this instance to another instance of the same type.122    (TypeScript can't express this, but only instances of the same123    specific class will be passed to this method.) This is used to124    avoid redrawing widgets when they are replaced by a new125    decoration of the same type. The default implementation just126    returns `false`, which will cause new instances of the widget to127    always be redrawn.128    */129    eq(widget) { return false; }130    /**131    Update a DOM element created by a widget of the same type (but132    different, non-`eq` content) to reflect this widget. May return133    true to indicate that it could update, false to indicate it134    couldn't (in which case the widget will be redrawn). The default135    implementation just returns false.136    */137    updateDOM(dom, view, from) { return false; }138    /**139    @internal140    */141    compare(other) {142        return this == other || this.constructor == other.constructor && this.eq(other);143    }144    /**145    The estimated height this widget will have, to be used when146    estimating the height of content that hasn't been drawn. May147    return -1 to indicate you don't know. The default implementation148    returns -1.149    */150    get estimatedHeight() { return -1; }151    /**152    For inline widgets that are displayed inline (as opposed to153    `inline-block`) and introduce line breaks (through `<br>` tags154    or textual newlines), this must indicate the amount of line155    breaks they introduce. Defaults to 0.156    */157    get lineBreaks() { return 0; }158    /**159    Can be used to configure which kinds of events inside the widget160    should be ignored by the editor. The default is to ignore all161    events.162    */163    ignoreEvent(event) { return true; }164    /**165    Override the way screen coordinates for positions at/in the166    widget are found. `pos` will be the offset into the widget, and167    `side` the side of the position that is being queried—less than168    zero for before, greater than zero for after, and zero for169    directly at that position.170    */171    coordsAt(dom, pos, side) { return null; }172    /**173    @internal174    */175    get isHidden() { return false; }176    /**177    @internal178    */179    get editable() { return false; }180    /**181    This is called when the an instance of the widget is removed182    from the editor view.183    */184    destroy(dom) { }185}186/**187The different types of blocks that can occur in an editor view.188*/189exports.BlockType = void 0;190(function (BlockType) {191    /**192    A line of text.193    */194    BlockType[BlockType["Text"] = 0] = "Text";195    /**196    A block widget associated with the position after it.197    */198    BlockType[BlockType["WidgetBefore"] = 1] = "WidgetBefore";199    /**200    A block widget associated with the position before it.201    */202    BlockType[BlockType["WidgetAfter"] = 2] = "WidgetAfter";203    /**204    A block widget [replacing](https://codemirror.net/6/docs/ref/#view.Decoration^replace) a range of content.205    */206    BlockType[BlockType["WidgetRange"] = 3] = "WidgetRange";207})(exports.BlockType || (exports.BlockType = {}));208/**209A decoration provides information on how to draw or style a piece210of content. You'll usually use it wrapped in a211[`Range`](https://codemirror.net/6/docs/ref/#state.Range), which adds a start and end position.212@nonabstract213*/214class Decoration extends state.RangeValue {215    constructor(216    /**217    @internal218    */219    startSide, 220    /**221    @internal222    */223    endSide, 224    /**225    @internal226    */227    widget, 228    /**229    The config object used to create this decoration. You can230    include additional properties in there to store metadata about231    your decoration.232    */233    spec) {234        super();235        this.startSide = startSide;236        this.endSide = endSide;237        this.widget = widget;238        this.spec = spec;239    }240    /**241    @internal242    */243    get heightRelevant() { return false; }244    /**245    Create a mark decoration, which influences the styling of the246    content in its range. Nested mark decorations will cause nested247    DOM elements to be created. Nesting order is determined by248    precedence of the [facet](https://codemirror.net/6/docs/ref/#view.EditorView^decorations), with249    the higher-precedence decorations creating the inner DOM nodes.250    Such elements are split on line boundaries and on the boundaries251    of lower-precedence decorations.252    */253    static mark(spec) {254        return new MarkDecoration(spec);255    }256    /**257    Create a widget decoration, which displays a DOM element at the258    given position.259    */260    static widget(spec) {261        let side = Math.max(-10000, Math.min(10000, spec.side || 0)), block = !!spec.block;262        side += (block && !spec.inlineOrder)263            ? (side > 0 ? 300000000 /* Side.BlockAfter */ : -400000000 /* Side.BlockBefore */)264            : (side > 0 ? 100000000 /* Side.InlineAfter */ : -100000000 /* Side.InlineBefore */);265        return new PointDecoration(spec, side, side, block, spec.widget || null, false);266    }267    /**268    Create a replace decoration which replaces the given range with269    a widget, or simply hides it.270    */271    static replace(spec) {272        let block = !!spec.block, startSide, endSide;273        if (spec.isBlockGap) {274            startSide = -500000000 /* Side.GapStart */;275            endSide = 400000000 /* Side.GapEnd */;276        }277        else {278            let { start, end } = getInclusive(spec, block);279            startSide = (start ? (block ? -300000000 /* Side.BlockIncStart */ : -1 /* Side.InlineIncStart */) : 500000000 /* Side.NonIncStart */) - 1;280            endSide = (end ? (block ? 200000000 /* Side.BlockIncEnd */ : 1 /* Side.InlineIncEnd */) : -600000000 /* Side.NonIncEnd */) + 1;281        }282        return new PointDecoration(spec, startSide, endSide, block, spec.widget || null, true);283    }284    /**285    Create a line decoration, which can add DOM attributes to the286    line starting at the given position.287    */288    static line(spec) {289        return new LineDecoration(spec);290    }291    /**292    Build a [`DecorationSet`](https://codemirror.net/6/docs/ref/#view.DecorationSet) from the given293    decorated range or ranges. If the ranges aren't already sorted,294    pass `true` for `sort` to make the library sort them for you.295    */296    static set(of, sort = false) {297        return state.RangeSet.of(of, sort);298    }299    /**300    @internal301    */302    hasHeight() { return this.widget ? this.widget.estimatedHeight > -1 : false; }303}304/**305The empty set of decorations.306*/307Decoration.none = state.RangeSet.empty;308class MarkDecoration extends Decoration {309    constructor(spec) {310        let { start, end } = getInclusive(spec);311        super(start ? -1 /* Side.InlineIncStart */ : 500000000 /* Side.NonIncStart */, end ? 1 /* Side.InlineIncEnd */ : -600000000 /* Side.NonIncEnd */, null, spec);312        this.tagName = spec.tagName || "span";313        this.attrs = spec.class && spec.attributes ? combineAttrs(spec.attributes, { class: spec.class })314            : spec.class ? { class: spec.class } : spec.attributes || noAttrs;315    }316    eq(other) {317        return this == other || other instanceof MarkDecoration && this.tagName == other.tagName && attrsEq(this.attrs, other.attrs);318    }319    range(from, to = from) {320        if (from >= to)321            throw new RangeError("Mark decorations may not be empty");322        return super.range(from, to);323    }324}325MarkDecoration.prototype.point = false;326class LineDecoration extends Decoration {327    constructor(spec) {328        super(-200000000 /* Side.Line */, -200000000 /* Side.Line */, null, spec);329    }330    eq(other) {331        return other instanceof LineDecoration &&332            this.spec.class == other.spec.class &&333            attrsEq(this.spec.attributes, other.spec.attributes);334    }335    range(from, to = from) {336        if (to != from)337            throw new RangeError("Line decoration ranges must be zero-length");338        return super.range(from, to);339    }340}341LineDecoration.prototype.mapMode = state.MapMode.TrackBefore;342LineDecoration.prototype.point = true;343class PointDecoration extends Decoration {344    constructor(spec, startSide, endSide, block, widget, isReplace) {345        super(startSide, endSide, widget, spec);346        this.block = block;347        this.isReplace = isReplace;348        this.mapMode = !block ? state.MapMode.TrackDel : startSide <= 0 ? state.MapMode.TrackBefore : state.MapMode.TrackAfter;349    }350    // Only relevant when this.block == true351    get type() {352        return this.startSide != this.endSide ? exports.BlockType.WidgetRange353            : this.startSide <= 0 ? exports.BlockType.WidgetBefore : exports.BlockType.WidgetAfter;354    }355    get heightRelevant() {356        return this.block || !!this.widget && (this.widget.estimatedHeight >= 5 || this.widget.lineBreaks > 0);357    }358    eq(other) {359        return other instanceof PointDecoration &&360            widgetsEq(this.widget, other.widget) &&361            this.block == other.block &&362            this.startSide == other.startSide && this.endSide == other.endSide;363    }364    range(from, to = from) {365        if (this.isReplace && (from > to || (from == to && this.startSide > 0 && this.endSide <= 0)))366            throw new RangeError("Invalid range for replacement decoration");367        if (!this.isReplace && to != from)368            throw new RangeError("Widget decorations can only have zero-length ranges");369        return super.range(from, to);370    }371}372PointDecoration.prototype.point = true;373function getInclusive(spec, block = false) {374    let { inclusiveStart: start, inclusiveEnd: end } = spec;375    if (start == null)376        start = spec.inclusive;377    if (end == null)378        end = spec.inclusive;379    return { start: start !== null && start !== void 0 ? start : block, end: end !== null && end !== void 0 ? end : block };380}381function widgetsEq(a, b) {382    return a == b || !!(a && b && a.compare(b));383}384function addRange(from, to, ranges, margin = 0) {385    let last = ranges.length - 1;386    if (last >= 0 && ranges[last] + margin >= from)387        ranges[last] = Math.max(ranges[last], to);388    else389        ranges.push(from, to);390}391/**392A block wrapper defines a DOM node that wraps lines or other block393wrappers at the top of the document. It affects any line or block394widget that starts inside its range, including blocks starting395directly at `from` but not including `to`.396*/397class BlockWrapper extends state.RangeValue {398    constructor(399    /**400    @internal401    */402    tagName, 403    /**404    @internal405    */406    attributes, 407    /**408    @internal409    */410    rank) {411        super();412        this.tagName = tagName;413        this.attributes = attributes;414        this.rank = rank;415    }416    eq(other) {417        return other == this ||418            other instanceof BlockWrapper && this.tagName == other.tagName && attrsEq(this.attributes, other.attributes);419    }420    /**421    Create a block wrapper object with the given tag name and422    attributes.423    */424    static create(spec) {425        return new BlockWrapper(spec.tagName, spec.attributes || noAttrs, spec.rank == null ? 50 : Math.max(0, Math.min(spec.rank, 100)));426    }427    /**428    Create a range set from the given block wrapper ranges.429    */430    static set(of, sort = false) {431        return state.RangeSet.of(of, sort);432    }433}434BlockWrapper.prototype.startSide = BlockWrapper.prototype.endSide = -1;435 436function getSelection(root) {437    let target;438    // Browsers differ on whether shadow roots have a getSelection439    // method. If it exists, use that, otherwise, call it on the440    // document.441    if (root.nodeType == 11) { // Shadow root442        target = root.getSelection ? root : root.ownerDocument;443    }444    else {445        target = root;446    }447    return target.getSelection();448}449function contains(dom, node) {450    return node ? dom == node || dom.contains(node.nodeType != 1 ? node.parentNode : node) : false;451}452function hasSelection(dom, selection) {453    if (!selection.anchorNode)454        return false;455    try {456        // Firefox will raise 'permission denied' errors when accessing457        // properties of `sel.anchorNode` when it's in a generated CSS458        // element.459        return contains(dom, selection.anchorNode);460    }461    catch (_) {462        return false;463    }464}465function clientRectsFor(dom) {466    if (dom.nodeType == 3)467        return textRange(dom, 0, dom.nodeValue.length).getClientRects();468    else if (dom.nodeType == 1)469        return dom.getClientRects();470    else471        return [];472}473// Scans forward and backward through DOM positions equivalent to the474// given one to see if the two are in the same place (i.e. after a475// text node vs at the end of that text node)476function isEquivalentPosition(node, off, targetNode, targetOff) {477    return targetNode ? (scanFor(node, off, targetNode, targetOff, -1) ||478        scanFor(node, off, targetNode, targetOff, 1)) : false;479}480function domIndex(node) {481    for (var index = 0;; index++) {482        node = node.previousSibling;483        if (!node)484            return index;485    }486}487function isBlockElement(node) {488    return node.nodeType == 1 && /^(DIV|P|LI|UL|OL|BLOCKQUOTE|DD|DT|H\d|SECTION|PRE)$/.test(node.nodeName);489}490function scanFor(node, off, targetNode, targetOff, dir) {491    for (;;) {492        if (node == targetNode && off == targetOff)493            return true;494        if (off == (dir < 0 ? 0 : maxOffset(node))) {495            if (node.nodeName == "DIV")496                return false;497            let parent = node.parentNode;498            if (!parent || parent.nodeType != 1)499                return false;500            off = domIndex(node) + (dir < 0 ? 0 : 1);501            node = parent;502        }503        else if (node.nodeType == 1) {504            node = node.childNodes[off + (dir < 0 ? -1 : 0)];505            if (node.nodeType == 1 && node.contentEditable == "false")506                return false;507            off = dir < 0 ? maxOffset(node) : 0;508        }509        else {510            return false;511        }512    }513}514function maxOffset(node) {515    return node.nodeType == 3 ? node.nodeValue.length : node.childNodes.length;516}517function flattenRect(rect, left) {518    let x = left ? rect.left : rect.right;519    return { left: x, right: x, top: rect.top, bottom: rect.bottom };520}521function windowRect(win) {522    let vp = win.visualViewport;523    if (vp)524        return {525            left: 0, right: vp.width,526            top: 0, bottom: vp.height527        };528    return { left: 0, right: win.innerWidth,529        top: 0, bottom: win.innerHeight };530}531function getScale(elt, rect) {532    let scaleX = rect.width / elt.offsetWidth;533    let scaleY = rect.height / elt.offsetHeight;534    if (scaleX > 0.995 && scaleX < 1.005 || !isFinite(scaleX) || Math.abs(rect.width - elt.offsetWidth) < 1)535        scaleX = 1;536    if (scaleY > 0.995 && scaleY < 1.005 || !isFinite(scaleY) || Math.abs(rect.height - elt.offsetHeight) < 1)537        scaleY = 1;538    return { scaleX, scaleY };539}540function scrollRectIntoView(dom, rect, side, x, y, xMargin, yMargin, ltr) {541    let doc = dom.ownerDocument, win = doc.defaultView || window;542    for (let cur = dom, stop = false; cur && !stop;) {543        if (cur.nodeType == 1) { // Element544            let bounding, top = cur == doc.body;545            let scaleX = 1, scaleY = 1;546            if (top) {547                bounding = windowRect(win);548            }549            else {550                if (/^(fixed|sticky)$/.test(getComputedStyle(cur).position))551                    stop = true;552                if (cur.scrollHeight <= cur.clientHeight && cur.scrollWidth <= cur.clientWidth) {553                    cur = cur.assignedSlot || cur.parentNode;554                    continue;555                }556                let rect = cur.getBoundingClientRect();557                ({ scaleX, scaleY } = getScale(cur, rect));558                // Make sure scrollbar width isn't included in the rectangle559                bounding = { left: rect.left, right: rect.left + cur.clientWidth * scaleX,560                    top: rect.top, bottom: rect.top + cur.clientHeight * scaleY };561            }562            let moveX = 0, moveY = 0;563            if (y == "nearest") {564                if (rect.top < bounding.top + yMargin) {565                    moveY = rect.top - (bounding.top + yMargin);566                    if (side > 0 && rect.bottom > bounding.bottom + moveY)567                        moveY = rect.bottom - bounding.bottom + yMargin;568                }569                else if (rect.bottom > bounding.bottom - yMargin) {570                    moveY = rect.bottom - bounding.bottom + yMargin;571                    if (side < 0 && (rect.top - moveY) < bounding.top)572                        moveY = rect.top - (bounding.top + yMargin);573                }574            }575            else {576                let rectHeight = rect.bottom - rect.top, boundingHeight = bounding.bottom - bounding.top;577                let targetTop = y == "center" && rectHeight <= boundingHeight ? rect.top + rectHeight / 2 - boundingHeight / 2 :578                    y == "start" || y == "center" && side < 0 ? rect.top - yMargin :579                        rect.bottom - boundingHeight + yMargin;580                moveY = targetTop - bounding.top;581            }582            if (x == "nearest") {583                if (rect.left < bounding.left + xMargin) {584                    moveX = rect.left - (bounding.left + xMargin);585                    if (side > 0 && rect.right > bounding.right + moveX)586                        moveX = rect.right - bounding.right + xMargin;587                }588                else if (rect.right > bounding.right - xMargin) {589                    moveX = rect.right - bounding.right + xMargin;590                    if (side < 0 && rect.left < bounding.left + moveX)591                        moveX = rect.left - (bounding.left + xMargin);592                }593            }594            else {595                let targetLeft = x == "center" ? rect.left + (rect.right - rect.left) / 2 - (bounding.right - bounding.left) / 2 :596                    (x == "start") == ltr ? rect.left - xMargin :597                        rect.right - (bounding.right - bounding.left) + xMargin;598                moveX = targetLeft - bounding.left;599            }600            if (moveX || moveY) {601                if (top) {602                    win.scrollBy(moveX, moveY);603                }604                else {605                    let movedX = 0, movedY = 0;606                    if (moveY) {607                        let start = cur.scrollTop;608                        cur.scrollTop += moveY / scaleY;609                        movedY = (cur.scrollTop - start) * scaleY;610                    }611                    if (moveX) {612                        let start = cur.scrollLeft;613                        cur.scrollLeft += moveX / scaleX;614                        movedX = (cur.scrollLeft - start) * scaleX;615                    }616                    rect = { left: rect.left - movedX, top: rect.top - movedY,617                        right: rect.right - movedX, bottom: rect.bottom - movedY };618                    if (movedX && Math.abs(movedX - moveX) < 1)619                        x = "nearest";620                    if (movedY && Math.abs(movedY - moveY) < 1)621                        y = "nearest";622                }623            }624            if (top)625                break;626            if (rect.top < bounding.top || rect.bottom > bounding.bottom ||627                rect.left < bounding.left || rect.right > bounding.right)628                rect = { left: Math.max(rect.left, bounding.left), right: Math.min(rect.right, bounding.right),629                    top: Math.max(rect.top, bounding.top), bottom: Math.min(rect.bottom, bounding.bottom) };630            cur = cur.assignedSlot || cur.parentNode;631        }632        else if (cur.nodeType == 11) { // A shadow root633            cur = cur.host;634        }635        else {636            break;637        }638    }639}640function scrollableParents(dom, getX = true) {641    let doc = dom.ownerDocument, x = null, y = null;642    for (let cur = dom.parentNode; cur;) {643        if (cur == doc.body || ((!getX || x) && y)) {644            break;645        }646        else if (cur.nodeType == 1) {647            if (!y && cur.scrollHeight > cur.clientHeight)648                y = cur;649            if (getX && !x && cur.scrollWidth > cur.clientWidth)650                x = cur;651            cur = cur.assignedSlot || cur.parentNode;652        }653        else if (cur.nodeType == 11) {654            cur = cur.host;655        }656        else {657            break;658        }659    }660    return { x, y };661}662class DOMSelectionState {663    constructor() {664        this.anchorNode = null;665        this.anchorOffset = 0;666        this.focusNode = null;667        this.focusOffset = 0;668    }669    eq(domSel) {670        return this.anchorNode == domSel.anchorNode && this.anchorOffset == domSel.anchorOffset &&671            this.focusNode == domSel.focusNode && this.focusOffset == domSel.focusOffset;672    }673    setRange(range) {674        let { anchorNode, focusNode } = range;675        // Clip offsets to node size to avoid crashes when Safari reports bogus offsets (#1152)676        this.set(anchorNode, Math.min(range.anchorOffset, anchorNode ? maxOffset(anchorNode) : 0), focusNode, Math.min(range.focusOffset, focusNode ? maxOffset(focusNode) : 0));677    }678    set(anchorNode, anchorOffset, focusNode, focusOffset) {679        this.anchorNode = anchorNode;680        this.anchorOffset = anchorOffset;681        this.focusNode = focusNode;682        this.focusOffset = focusOffset;683    }684}685let preventScrollSupported = null;686// Safari 26 breaks preventScroll support687if (browser.safari && browser.safari_version >= 26)688    preventScrollSupported = false;689// Feature-detects support for .focus({preventScroll: true}), and uses690// a fallback kludge when not supported.691function focusPreventScroll(dom) {692    if (dom.setActive)693        return dom.setActive(); // in IE694    if (preventScrollSupported)695        return dom.focus(preventScrollSupported);696    let stack = [];697    for (let cur = dom; cur; cur = cur.parentNode) {698        stack.push(cur, cur.scrollTop, cur.scrollLeft);699        if (cur == cur.ownerDocument)700            break;701    }702    dom.focus(preventScrollSupported == null ? {703        get preventScroll() {704            preventScrollSupported = { preventScroll: true };705            return true;706        }707    } : undefined);708    if (!preventScrollSupported) {709        preventScrollSupported = false;710        for (let i = 0; i < stack.length;) {711            let elt = stack[i++], top = stack[i++], left = stack[i++];712            if (elt.scrollTop != top)713                elt.scrollTop = top;714            if (elt.scrollLeft != left)715                elt.scrollLeft = left;716        }717    }718}719let scratchRange;720function textRange(node, from, to = from) {721    let range = scratchRange || (scratchRange = document.createRange());722    range.setEnd(node, to);723    range.setStart(node, from);724    return range;725}726function dispatchKey(elt, name, code, mods) {727    let options = { key: name, code: name, keyCode: code, which: code, cancelable: true };728    if (mods)729        ({ altKey: options.altKey, ctrlKey: options.ctrlKey, shiftKey: options.shiftKey, metaKey: options.metaKey } = mods);730    let down = new KeyboardEvent("keydown", options);731    down.synthetic = true;732    elt.dispatchEvent(down);733    let up = new KeyboardEvent("keyup", options);734    up.synthetic = true;735    elt.dispatchEvent(up);736    return down.defaultPrevented || up.defaultPrevented;737}738function getRoot(node) {739    while (node) {740        if (node && (node.nodeType == 9 || node.nodeType == 11 && node.host))741            return node;742        node = node.assignedSlot || node.parentNode;743    }744    return null;745}746function atElementStart(doc, selection) {747    let node = selection.focusNode, offset = selection.focusOffset;748    if (!node || selection.anchorNode != node || selection.anchorOffset != offset)749        return false;750    // Safari can report bogus offsets (#1152)751    offset = Math.min(offset, maxOffset(node));752    for (;;) {753        if (offset) {754            if (node.nodeType != 1)755                return false;756            let prev = node.childNodes[offset - 1];757            if (prev.contentEditable == "false")758                offset--;759            else {760                node = prev;761                offset = maxOffset(node);762            }763        }764        else if (node == doc) {765            return true;766        }767        else {768            offset = domIndex(node);769            node = node.parentNode;770        }771    }772}773function isScrolledToBottom(elt) {774    if (elt instanceof Window)775        return elt.pageYOffset > Math.max(0, elt.document.documentElement.scrollHeight - elt.innerHeight - 4);776    return elt.scrollTop > Math.max(1, elt.scrollHeight - elt.clientHeight - 4);777}778function textNodeBefore(startNode, startOffset) {779    for (let node = startNode, offset = startOffset;;) {780        if (node.nodeType == 3 && offset > 0) {781            return { node: node, offset: offset };782        }783        else if (node.nodeType == 1 && offset > 0) {784            if (node.contentEditable == "false")785                return null;786            node = node.childNodes[offset - 1];787            offset = maxOffset(node);788        }789        else if (node.parentNode && !isBlockElement(node)) {790            offset = domIndex(node);791            node = node.parentNode;792        }793        else {794            return null;795        }796    }797}798function textNodeAfter(startNode, startOffset) {799    for (let node = startNode, offset = startOffset;;) {800        if (node.nodeType == 3 && offset < node.nodeValue.length) {801            return { node: node, offset: offset };802        }803        else if (node.nodeType == 1 && offset < node.childNodes.length) {804            if (node.contentEditable == "false")805                return null;806            node = node.childNodes[offset];807            offset = 0;808        }809        else if (node.parentNode && !isBlockElement(node)) {810            offset = domIndex(node) + 1;811            node = node.parentNode;812        }813        else {814            return null;815        }816    }817}818class DOMPos {819    constructor(node, offset, precise = true) {820        this.node = node;821        this.offset = offset;822        this.precise = precise;823    }824    static before(dom, precise) { return new DOMPos(dom.parentNode, domIndex(dom), precise); }825    static after(dom, precise) { return new DOMPos(dom.parentNode, domIndex(dom) + 1, precise); }826}827 828/**829Used to indicate [text direction](https://codemirror.net/6/docs/ref/#view.EditorView.textDirection).830*/831exports.Direction = void 0;832(function (Direction) {833    // (These are chosen to match the base levels, in bidi algorithm834    // terms, of spans in that direction.)835    /**836    Left-to-right.837    */838    Direction[Direction["LTR"] = 0] = "LTR";839    /**840    Right-to-left.841    */842    Direction[Direction["RTL"] = 1] = "RTL";843})(exports.Direction || (exports.Direction = {}));844const LTR = exports.Direction.LTR, RTL = exports.Direction.RTL;845// Decode a string with each type encoded as log2(type)846function dec(str) {847    let result = [];848    for (let i = 0; i < str.length; i++)849        result.push(1 << +str[i]);850    return result;851}852// Character types for codepoints 0 to 0xf8853const LowTypes = dec("88888888888888888888888888888888888666888888787833333333337888888000000000000000000000000008888880000000000000000000000000088888888888888888888888888888888888887866668888088888663380888308888800000000000000000000000800000000000000000000000000000008");854// Character types for codepoints 0x600 to 0x6f9855const ArabicTypes = dec("4444448826627288999999999992222222222222222222222222222222222222222222222229999999999999999999994444444444644222822222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222999999949999999229989999223333333333");856const Brackets = Object.create(null), BracketStack = [];857// There's a lot more in858// https://www.unicode.org/Public/UCD/latest/ucd/BidiBrackets.txt,859// which are left out to keep code size down.860for (let p of ["()", "[]", "{}"]) {861    let l = p.charCodeAt(0), r = p.charCodeAt(1);862    Brackets[l] = r;863    Brackets[r] = -l;864}865function charType(ch) {866    return ch <= 0xf7 ? LowTypes[ch] :867        0x590 <= ch && ch <= 0x5f4 ? 2 /* T.R */ :868            0x600 <= ch && ch <= 0x6f9 ? ArabicTypes[ch - 0x600] :869                0x6ee <= ch && ch <= 0x8ac ? 4 /* T.AL */ :870                    0x2000 <= ch && ch <= 0x200c ? 256 /* T.NI */ :871                        0xfb50 <= ch && ch <= 0xfdff ? 4 /* T.AL */ : 1 /* T.L */;872}873const BidiRE = /[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac\ufb50-\ufdff]/;874/**875Represents a contiguous range of text that has a single direction876(as in left-to-right or right-to-left).877*/878class BidiSpan {879    /**880    The direction of this span.881    */882    get dir() { return this.level % 2 ? RTL : LTR; }883    /**884    @internal885    */886    constructor(887    /**888    The start of the span (relative to the start of the line).889    */890    from, 891    /**892    The end of the span.893    */894    to, 895    /**896    The ["bidi897    level"](https://unicode.org/reports/tr9/#Basic_Display_Algorithm)898    of the span (in this context, 0 means899    left-to-right, 1 means right-to-left, 2 means left-to-right900    number inside right-to-left text).901    */902    level) {903        this.from = from;904        this.to = to;905        this.level = level;906    }907    /**908    @internal909    */910    side(end, dir) { return (this.dir == dir) == end ? this.to : this.from; }911    /**912    @internal913    */914    forward(forward, dir) { return forward == (this.dir == dir); }915    /**916    @internal917    */918    static find(order, index, level, assoc) {919        let maybe = -1;920        for (let i = 0; i < order.length; i++) {921            let span = order[i];922            if (span.from <= index && span.to >= index) {923                if (span.level == level)924                    return i;925                // When multiple spans match, if assoc != 0, take the one that926                // covers that side, otherwise take the one with the minimum927                // level.928                if (maybe < 0 || (assoc != 0 ? (assoc < 0 ? span.from < index : span.to > index) : order[maybe].level > span.level))929                    maybe = i;930            }931        }932        if (maybe < 0)933            throw new RangeError("Index out of range");934        return maybe;935    }936}937function isolatesEq(a, b) {938    if (a.length != b.length)939        return false;940    for (let i = 0; i < a.length; i++) {941        let iA = a[i], iB = b[i];942        if (iA.from != iB.from || iA.to != iB.to || iA.direction != iB.direction || !isolatesEq(iA.inner, iB.inner))943            return false;944    }945    return true;946}947// Reused array of character types948const types = [];949// Fill in the character types (in `types`) from `from` to `to` and950// apply W normalization rules.951function computeCharTypes(line, rFrom, rTo, isolates, outerType) {952    for (let iI = 0; iI <= isolates.length; iI++) {953        let from = iI ? isolates[iI - 1].to : rFrom, to = iI < isolates.length ? isolates[iI].from : rTo;954        let prevType = iI ? 256 /* T.NI */ : outerType;955        // W1. Examine each non-spacing mark (NSM) in the level run, and956        // change the type of the NSM to the type of the previous957        // character. If the NSM is at the start of the level run, it will958        // get the type of sor.959        // W2. Search backwards from each instance of a European number960        // until the first strong type (R, L, AL, or sor) is found. If an961        // AL is found, change the type of the European number to Arabic962        // number.963        // W3. Change all ALs to R.964        // (Left after this: L, R, EN, AN, ET, CS, NI)965        for (let i = from, prev = prevType, prevStrong = prevType; i < to; i++) {966            let type = charType(line.charCodeAt(i));967            if (type == 512 /* T.NSM */)968                type = prev;969            else if (type == 8 /* T.EN */ && prevStrong == 4 /* T.AL */)970                type = 16 /* T.AN */;971            types[i] = type == 4 /* T.AL */ ? 2 /* T.R */ : type;972            if (type & 7 /* T.Strong */)973                prevStrong = type;974            prev = type;975        }976        // W5. A sequence of European terminators adjacent to European977        // numbers changes to all European numbers.978        // W6. Otherwise, separators and terminators change to Other979        // Neutral.980        // W7. Search backwards from each instance of a European number981        // until the first strong type (R, L, or sor) is found. If an L is982        // found, then change the type of the European number to L.983        // (Left after this: L, R, EN+AN, NI)984        for (let i = from, prev = prevType, prevStrong = prevType; i < to; i++) {985            let type = types[i];986            if (type == 128 /* T.CS */) {987                if (i < to - 1 && prev == types[i + 1] && (prev & 24 /* T.Num */))988                    type = types[i] = prev;989                else990                    types[i] = 256 /* T.NI */;991            }992            else if (type == 64 /* T.ET */) {993                let end = i + 1;994                while (end < to && types[end] == 64 /* T.ET */)995                    end++;996                let replace = (i && prev == 8 /* T.EN */) || (end < rTo && types[end] == 8 /* T.EN */) ? (prevStrong == 1 /* T.L */ ? 1 /* T.L */ : 8 /* T.EN */) : 256 /* T.NI */;997                for (let j = i; j < end; j++)998                    types[j] = replace;999                i = end - 1;1000            }1001            else if (type == 8 /* T.EN */ && prevStrong == 1 /* T.L */) {1002                types[i] = 1 /* T.L */;1003            }1004            prev = type;1005            if (type & 7 /* T.Strong */)1006                prevStrong = type;1007        }1008    }1009}1010// Process brackets throughout a run sequence.1011function processBracketPairs(line, rFrom, rTo, isolates, outerType) {1012    let oppositeType = outerType == 1 /* T.L */ ? 2 /* T.R */ : 1 /* T.L */;1013    for (let iI = 0, sI = 0, context = 0; iI <= isolates.length; iI++) {1014        let from = iI ? isolates[iI - 1].to : rFrom, to = iI < isolates.length ? isolates[iI].from : rTo;1015        // N0. Process bracket pairs in an isolating run sequence1016        // sequentially in the logical order of the text positions of the1017        // opening paired brackets using the logic given below. Within this1018        // scope, bidirectional types EN and AN are treated as R.1019        for (let i = from, ch, br, type; i < to; i++) {1020            // Keeps [startIndex, type, strongSeen] triples for each open1021            // bracket on BracketStack.1022            if (br = Brackets[ch = line.charCodeAt(i)]) {1023                if (br < 0) { // Closing bracket1024                    for (let sJ = sI - 3; sJ >= 0; sJ -= 3) {1025                        if (BracketStack[sJ + 1] == -br) {1026                            let flags = BracketStack[sJ + 2];1027                            let type = (flags & 2 /* Bracketed.EmbedInside */) ? outerType :1028                                !(flags & 4 /* Bracketed.OppositeInside */) ? 0 :1029                                    (flags & 1 /* Bracketed.OppositeBefore */) ? oppositeType : outerType;1030                            if (type)1031                                types[i] = types[BracketStack[sJ]] = type;1032                            sI = sJ;1033                            break;1034                        }1035                    }1036                }1037                else if (BracketStack.length == 189 /* Bracketed.MaxDepth */) {1038                    break;1039                }1040                else {1041                    BracketStack[sI++] = i;1042                    BracketStack[sI++] = ch;1043                    BracketStack[sI++] = context;1044                }1045            }1046            else if ((type = types[i]) == 2 /* T.R */ || type == 1 /* T.L */) {1047                let embed = type == outerType;1048                context = embed ? 0 : 1 /* Bracketed.OppositeBefore */;1049                for (let sJ = sI - 3; sJ >= 0; sJ -= 3) {1050                    let cur = BracketStack[sJ + 2];1051                    if (cur & 2 /* Bracketed.EmbedInside */)1052                        break;1053                    if (embed) {1054                        BracketStack[sJ + 2] |= 2 /* Bracketed.EmbedInside */;1055                    }1056                    else {1057                        if (cur & 4 /* Bracketed.OppositeInside */)1058                            break;1059                        BracketStack[sJ + 2] |= 4 /* Bracketed.OppositeInside */;1060                    }1061                }1062            }1063        }1064    }1065}1066function processNeutrals(rFrom, rTo, isolates, outerType) {1067    for (let iI = 0, prev = outerType; iI <= isolates.length; iI++) {1068        let from = iI ? isolates[iI - 1].to : rFrom, to = iI < isolates.length ? isolates[iI].from : rTo;1069        // N1. A sequence of neutrals takes the direction of the1070        // surrounding strong text if the text on both sides has the same1071        // direction. European and Arabic numbers act as if they were R in1072        // terms of their influence on neutrals. Start-of-level-run (sor)1073        // and end-of-level-run (eor) are used at level run boundaries.1074        // N2. Any remaining neutrals take the embedding direction.1075        // (Left after this: L, R, EN+AN)1076        for (let i = from; i < to;) {1077            let type = types[i];1078            if (type == 256 /* T.NI */) {1079                let end = i + 1;1080                for (;;) {1081                    if (end == to) {1082                        if (iI == isolates.length)1083                            break;1084                        end = isolates[iI++].to;1085                        to = iI < isolates.length ? isolates[iI].from : rTo;1086                    }1087                    else if (types[end] == 256 /* T.NI */) {1088                        end++;1089                    }1090                    else {1091                        break;1092                    }1093                }1094                let beforeL = prev == 1 /* T.L */;1095                let afterL = (end < rTo ? types[end] : outerType) == 1 /* T.L */;1096                let replace = beforeL == afterL ? (beforeL ? 1 /* T.L */ : 2 /* T.R */) : outerType;1097                for (let j = end, jI = iI, fromJ = jI ? isolates[jI - 1].to : rFrom; j > i;) {1098                    if (j == fromJ) {1099                        j = isolates[--jI].from;1100                        fromJ = jI ? isolates[jI - 1].to : rFrom;1101                    }1102                    types[--j] = replace;1103                }1104                i = end;1105            }1106            else {1107                prev = type;1108                i++;1109            }1110        }1111    }1112}1113// Find the contiguous ranges of character types in a given range, and1114// emit spans for them. Flip the order of the spans as appropriate1115// based on the level, and call through to compute the spans for1116// isolates at the proper point.1117function emitSpans(line, from, to, level, baseLevel, isolates, order) {1118    let ourType = level % 2 ? 2 /* T.R */ : 1 /* T.L */;1119    if ((level % 2) == (baseLevel % 2)) { // Same dir as base direction, don't flip1120        for (let iCh = from, iI = 0; iCh < to;) {1121            // Scan a section of characters in direction ourType, unless1122            // there's another type of char right after iCh, in which case1123            // we scan a section of other characters (which, if ourType ==1124            // T.L, may contain both T.R and T.AN chars).1125            let sameDir = true, isNum = false;1126            if (iI == isolates.length || iCh < isolates[iI].from) {1127                let next = types[iCh];1128                if (next != ourType) {1129                    sameDir = false;1130                    isNum = next == 16 /* T.AN */;1131                }1132            }1133            // Holds an array of isolates to pass to a recursive call if we1134            // must recurse (to distinguish T.AN inside an RTL section in1135            // LTR text), null if we can emit directly1136            let recurse = !sameDir && ourType == 1 /* T.L */ ? [] : null;1137            let localLevel = sameDir ? level : level + 1;1138            let iScan = iCh;1139            run: for (;;) {1140                if (iI < isolates.length && iScan == isolates[iI].from) {1141                    if (isNum)1142                        break run;1143                    let iso = isolates[iI];1144                    // Scan ahead to verify that there is another char in this dir after the isolate(s)1145                    if (!sameDir)1146                        for (let upto = iso.to, jI = iI + 1;;) {1147                            if (upto == to)1148                                break run;1149                            if (jI < isolates.length && isolates[jI].from == upto)1150                                upto = isolates[jI++].to;1151                            else if (types[upto] == ourType)1152                                break run;1153                            else1154                                break;1155                        }1156                    iI++;1157                    if (recurse) {1158                        recurse.push(iso);1159                    }1160                    else {1161                        if (iso.from > iCh)1162                            order.push(new BidiSpan(iCh, iso.from, localLevel));1163                        let dirSwap = (iso.direction == LTR) != !(localLevel % 2);1164                        computeSectionOrder(line, dirSwap ? level + 1 : level, baseLevel, iso.inner, iso.from, iso.to, order);1165                        iCh = iso.to;1166                    }1167                    iScan = iso.to;1168                }1169                else if (iScan == to || (sameDir ? types[iScan] != ourType : types[iScan] == ourType)) {1170                    break;1171                }1172                else {1173                    iScan++;1174                }1175            }1176            if (recurse)1177                emitSpans(line, iCh, iScan, level + 1, baseLevel, recurse, order);1178            else if (iCh < iScan)1179                order.push(new BidiSpan(iCh, iScan, localLevel));1180            iCh = iScan;1181        }1182    }1183    else {1184        // Iterate in reverse to flip the span order. Same code again, but1185        // going from the back of the section to the front1186        for (let iCh = to, iI = isolates.length; iCh > from;) {1187            let sameDir = true, isNum = false;1188            if (!iI || iCh > isolates[iI - 1].to) {1189                let next = types[iCh - 1];1190                if (next != ourType) {1191                    sameDir = false;1192                    isNum = next == 16 /* T.AN */;1193                }1194            }1195            let recurse = !sameDir && ourType == 1 /* T.L */ ? [] : null;1196            let localLevel = sameDir ? level : level + 1;1197            let iScan = iCh;1198            run: for (;;) {1199                if (iI && iScan == isolates[iI - 1].to) {1200                    if (isNum)

Showing the first 1,200 of 11872 lines. Download the file for the rest.

basant307/AI_Governance_Project · CoolFace