"use strict";
var __webpack_require__ = {};
(()=>{
    __webpack_require__.d = (exports1, definition)=>{
        for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
            enumerable: true,
            get: definition[key]
        });
    };
})();
(()=>{
    __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
})();
(()=>{
    __webpack_require__.r = (exports1)=>{
        if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
            value: 'Module'
        });
        Object.defineProperty(exports1, '__esModule', {
            value: true
        });
    };
})();
var __webpack_exports__ = {};
__webpack_require__.r(__webpack_exports__);
__webpack_require__.d(__webpack_exports__, {
    extractTextToHighlight: ()=>extractTextToHighlight,
    generatePdfPageUrl: ()=>generatePdfPageUrl,
    generateTextFragmentUrl: ()=>generateTextFragmentUrl
});
function extractTextToHighlight(text) {
    text = text.trim();
    const sentenceRegex = /(?<=^|\p{P}\s)\p{P}?\p{Lu}.*?[.!?]+(?=\s+(?:\p{Lu}|\d)|$)/gu;
    const fallbackWordCount = 5;
    const sentences = text.match(sentenceRegex);
    if (sentences?.length) return sentences[0].trim();
    return text.split(/\s+/).slice(0, fallbackWordCount).join(' ');
}
function generateTextFragmentUrl(uri, text, filetype) {
    if ('html' !== filetype || !text) return uri;
    const highlight = extractTextToHighlight(text);
    const encodedTextFragment = encodeURIComponent(highlight).replace(/-/g, '%2D');
    return `${uri}#:~:text=${encodedTextFragment}`;
}
function generatePdfPageUrl(uri, pageNumber) {
    if (!pageNumber || pageNumber <= 0) return uri;
    return `${uri}#page=${pageNumber}`;
}
exports.extractTextToHighlight = __webpack_exports__.extractTextToHighlight;
exports.generatePdfPageUrl = __webpack_exports__.generatePdfPageUrl;
exports.generateTextFragmentUrl = __webpack_exports__.generateTextFragmentUrl;
for(var __rspack_i in __webpack_exports__)if (-1 === [
    "extractTextToHighlight",
    "generatePdfPageUrl",
    "generateTextFragmentUrl"
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
Object.defineProperty(exports, '__esModule', {
    value: true
});
