{"size": 9861, "ext": "js", "max_stars_repo_path": "node_modules/molstar/lib/mol-util/marker-action.js", "max_stars_repo_name": "Harry-Hopkinson/VSCoding-Sequence", "max_stars_repo_stars_event_min_datetime": "2021-11-29T17:38:12.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-11T21:59:22.000Z", "max_issues_repo_path": "node_modules/molstar/lib/mol-util/marker-action.js", "max_issues_repo_name": "Harry-Hopkinson/VSCoding-Sequence", "max_issues_repo_issues_event_min_datetime": "2021-11-29T22:03:21.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-15T07:51:12.000Z", "max_forks_repo_path": "node_modules/molstar/lib/mol-util/marker-action.js", "max_forks_repo_name": "Harry-Hopkinson/VSCoding-Sequence", "max_forks_repo_forks_event_min_datetime": "2021-12-04T20:30:29.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-11T21:59:42.000Z"}
{"max_stars_count": 30, "max_issues_count": 7, "max_forks_count": 3, "avg_line_length": 35.4712230216, "max_line_length": 99, "alphanum_fraction": 0.4627319744}
/**
 * Copyright (c) 2018-2021 mol* contributors, licensed under MIT, See LICENSE file for more info.
 *
 * @author Alexander Rose <alexander.rose@weirdbyte.de>
 */
import { Interval } from '../mol-data/int';
import { BitFlags } from './bit-flags';
import { assertUnreachable } from './type-helpers';
export var MarkerAction;
(function (MarkerAction) {
    MarkerAction[MarkerAction["None"] = 0] = "None";
    MarkerAction[MarkerAction["Highlight"] = 1] = "Highlight";
    MarkerAction[MarkerAction["RemoveHighlight"] = 2] = "RemoveHighlight";
    MarkerAction[MarkerAction["Select"] = 4] = "Select";
    MarkerAction[MarkerAction["Deselect"] = 8] = "Deselect";
    MarkerAction[MarkerAction["Toggle"] = 16] = "Toggle";
    MarkerAction[MarkerAction["Clear"] = 32] = "Clear";
})(MarkerAction || (MarkerAction = {}));
export var MarkerActions;
(function (MarkerActions) {
    MarkerActions.is = BitFlags.has;
    MarkerActions.All = (MarkerAction.Highlight | MarkerAction.RemoveHighlight |
        MarkerAction.Select | MarkerAction.Deselect | MarkerAction.Toggle |
        MarkerAction.Clear);
    MarkerActions.Highlighting = (MarkerAction.Highlight | MarkerAction.RemoveHighlight |
        MarkerAction.Clear);
    MarkerActions.Selecting = (MarkerAction.Select | MarkerAction.Deselect | MarkerAction.Toggle |
        MarkerAction.Clear);
    function isReverse(a, b) {
        return ((a === MarkerAction.Highlight && b === MarkerAction.RemoveHighlight) ||
            (a === MarkerAction.RemoveHighlight && b === MarkerAction.Highlight) ||
            (a === MarkerAction.Select && b === MarkerAction.Deselect) ||
            (a === MarkerAction.Deselect && b === MarkerAction.Select) ||
            (a === MarkerAction.Toggle && b === MarkerAction.Toggle));
    }
    MarkerActions.isReverse = isReverse;
})(MarkerActions || (MarkerActions = {}));
export function setMarkerValue(array, status, count) {
    array.fill(status, 0, count);
}
export function applyMarkerActionAtPosition(array, i, action) {
    switch (action) {
        case MarkerAction.Highlight:
            array[i] |= 1;
            break;
        case MarkerAction.RemoveHighlight:
            array[i] &= ~1;
            break;
        case MarkerAction.Select:
            array[i] |= 2;
            break;
        case MarkerAction.Deselect:
            array[i] &= ~2;
            break;
        case MarkerAction.Toggle:
            array[i] ^= 2;
            break;
        case MarkerAction.Clear:
            array[i] = 0;
            break;
    }
}
export function applyMarkerAction(array, set, action) {
    if (action === MarkerAction.None)
        return false;
    if (Interval.is(set)) {
        var start = Interval.start(set);
        var end = Interval.end(set);
        var viewStart = (start + 3) >> 2;
        var viewEnd = viewStart + ((end - 4 * viewStart) >> 2);
        if (viewEnd <= viewStart) {
            // avoid edge cases with overlapping front/end intervals
            for (var i = start; i < end; ++i) {
                applyMarkerActionAtPosition(array, i, action);
            }
            return true;
        }
        var view = new Uint32Array(array.buffer, 0, array.buffer.byteLength >> 2);
        var frontStart = start;
        var frontEnd = Math.min(4 * viewStart, end);
        var backStart = Math.max(start, 4 * viewEnd);
        var backEnd = end;
        switch (action) {
            case MarkerAction.Highlight:
                for (var i = viewStart; i < viewEnd; ++i)
                    view[i] |= 0x01010101;
                break;
            case MarkerAction.RemoveHighlight:
                for (var i = viewStart; i < viewEnd; ++i)
                    view[i] &= ~0x01010101;
                break;
            case MarkerAction.Select:
                for (var i = viewStart; i < viewEnd; ++i)
                    view[i] |= 0x02020202;
                break;
            case MarkerAction.Deselect:
                for (var i = viewStart; i < viewEnd; ++i)
                    view[i] &= ~0x02020202;
                break;
            case MarkerAction.Toggle:
                for (var i = viewStart; i < viewEnd; ++i)
                    view[i] ^= 0x02020202;
                break;
            case MarkerAction.Clear:
                for (var i = viewStart; i < viewEnd; ++i)
                    view[i] = 0;
                break;
            default:
                assertUnreachable(action);
        }
        for (var i = frontStart; i < frontEnd; ++i) {
            applyMarkerActionAtPosition(array, i, action);
        }
        for (var i = backStart; i < backEnd; ++i) {
            applyMarkerActionAtPosition(array, i, action);
        }
    }
    else {
        switch (action) {
            case MarkerAction.Highlight:
                for (var i = 0, il = set.length; i < il; ++i)
                    array[set[i]] |= 1;
                break;
            case MarkerAction.RemoveHighlight:
                for (var i = 0, il = set.length; i < il; ++i)
                    array[set[i]] &= ~1;
                break;
            case MarkerAction.Select:
                for (var i = 0, il = set.length; i < il; ++i)
                    array[set[i]] |= 2;
                break;
            case MarkerAction.Deselect:
                for (var i = 0, il = set.length; i < il; ++i)
                    array[set[i]] &= ~2;
                break;
            case MarkerAction.Toggle:
                for (var i = 0, il = set.length; i < il; ++i)
                    array[set[i]] ^= 2;
                break;
            case MarkerAction.Clear:
                for (var i = 0, il = set.length; i < il; ++i)
                    array[set[i]] = 0;
                break;
            default:
                assertUnreachable(action);
        }
    }
    return true;
}
export function getMarkerInfo(action, currentStatus) {
    var average = -1;
    var status = -1;
    switch (action) {
        case MarkerAction.Highlight:
            if (currentStatus === 0 || currentStatus === 1) {
                average = 1;
                status = 1;
            }
            else if (currentStatus === 2 || currentStatus === 3) {
                average = 1;
                status = 3;
            }
            else {
                average = 1;
            }
            break;
        case MarkerAction.RemoveHighlight:
            if (currentStatus === 0 || currentStatus === 1) {
                average = 0;
                status = 0;
            }
            else if (currentStatus === 2 || currentStatus === 3) {
                average = 1;
                status = 2;
            }
            break;
        case MarkerAction.Select:
            if (currentStatus === 1 || currentStatus === 3) {
                average = 1;
                status = 3;
            }
            else if (currentStatus === 0 || currentStatus === 2) {
                average = 1;
                status = 2;
            }
            else {
                average = 1;
            }
            break;
        case MarkerAction.Deselect:
            if (currentStatus === 1 || currentStatus === 3) {
                average = 1;
                status = 1;
            }
            else if (currentStatus === 0 || currentStatus === 2) {
                average = 0;
                status = 0;
            }
            break;
        case MarkerAction.Toggle:
            if (currentStatus === 1) {
                average = 1;
                status = 3;
            }
            else if (currentStatus === 2) {
                average = 0;
                status = 0;
            }
            else if (currentStatus === 3) {
                average = 1;
                status = 1;
            }
            else if (currentStatus === 0) {
                average = 1;
                status = 2;
            }
            break;
        case MarkerAction.Clear:
            average = 0;
            status = 0;
            break;
    }
    return { average: average, status: status };
}
/**
 * Assumes the action is applied to a partial set that is
 * neither the empty set nor the full set.
 */
export function getPartialMarkerAverage(action, currentStatus) {
    switch (action) {
        case MarkerAction.Highlight:
            return 0.5;
        case MarkerAction.RemoveHighlight:
            if (currentStatus === 0) {
                return 0;
            }
            else if (currentStatus === 2 || currentStatus === 3) {
                return 0.5;
            }
            else { // 1 | -1
                return -1;
            }
        case MarkerAction.Select:
            return 0.5;
        case MarkerAction.Deselect:
            if (currentStatus === 1 || currentStatus === 3) {
                return 0.5;
            }
            else if (currentStatus === 0) {
                return 0;
            }
            else { // 2 | -1
                return -1;
            }
        case MarkerAction.Toggle:
            if (currentStatus === -1) {
                return -1;
            }
            else { // 0 | 1 | 2 | 3
                return 0.5;
            }
        case MarkerAction.Clear:
            if (currentStatus === -1) {
                return -1;
            }
            else if (currentStatus === 0) {
                return 0;
            }
            else { // 1 | 2 | 3
                return 0.5;
            }
        case MarkerAction.None:
            return -1;
        default:
            assertUnreachable(action);
    }
}
//# sourceMappingURL=marker-action.js.map