astro-ghostcms/.pnpm-store/v3/files/7a/fdaba8875979710620bd0d7cb2e...

40 lines
1.8 KiB
Plaintext

/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
(function (factory) {
if (typeof module === "object" && typeof module.exports === "object") {
var v = factory(require, exports);
if (v !== undefined) module.exports = v;
}
else if (typeof define === "function" && define.amd) {
define(["require", "exports"], factory);
}
})(function (require, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.findMatchingTagPosition = void 0;
function findMatchingTagPosition(document, position, htmlDocument) {
const offset = document.offsetAt(position);
const node = htmlDocument.findNodeAt(offset);
if (!node.tag) {
return null;
}
if (!node.endTagStart) {
return null;
}
// Within open tag, compute close tag
if (node.start + '<'.length <= offset && offset <= node.start + '<'.length + node.tag.length) {
const mirrorOffset = (offset - '<'.length - node.start) + node.endTagStart + '</'.length;
return document.positionAt(mirrorOffset);
}
// Within closing tag, compute open tag
if (node.endTagStart + '</'.length <= offset && offset <= node.endTagStart + '</'.length + node.tag.length) {
const mirrorOffset = (offset - '</'.length - node.endTagStart) + node.start + '<'.length;
return document.positionAt(mirrorOffset);
}
return null;
}
exports.findMatchingTagPosition = findMatchingTagPosition;
});