New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@react-pdf-viewer/search

Package Overview
Dependencies
Maintainers
1
Versions
42
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@react-pdf-viewer/search - npm Package Compare versions

Comparing version 3.4.0 to 3.5.0

550

lib/cjs/search.js

@@ -37,3 +37,3 @@ 'use strict';

/******************************************************************************
/*! *****************************************************************************
Copyright (c) Microsoft Corporation.

@@ -70,2 +70,290 @@

var calculateOffset = function (children, parent) {
var top = children.offsetTop;
var left = children.offsetLeft;
var p = children.parentElement;
while (p && p !== parent) {
top += p.offsetTop;
left += p.offsetLeft;
p = p.parentElement;
}
return {
left: left,
top: top,
};
};
var getCssProperties = function (area) {
return {
left: "".concat(area.left, "%"),
top: "".concat(area.top, "%"),
height: "".concat(area.height, "%"),
width: "".concat(area.width, "%"),
};
};
var HightlightItem = function (_a) {
var index = _a.index, area = _a.area, onHighlightKeyword = _a.onHighlightKeyword;
var containerRef = React__namespace.useRef();
core.useIsomorphicLayoutEffect(function () {
var highlightEle = containerRef.current;
if (onHighlightKeyword && highlightEle) {
onHighlightKeyword({
highlightEle: highlightEle,
keyword: area.keyword,
});
}
}, []);
return (React__namespace.createElement("div", { className: "rpv-search__highlight", "data-index": index, ref: containerRef, style: getCssProperties(area), title: area.keywordStr.trim() }));
};
var removeNode = function (ele) {
var parent = ele.parentNode;
if (parent) {
parent.removeChild(ele);
}
};
var replaceNode = function (replacementNode, node) {
removeNode(replacementNode);
var parent = node.parentNode;
if (parent) {
parent.insertBefore(replacementNode, node);
}
removeNode(node);
};
var unwrap = function (ele) {
var parent = ele.parentNode;
if (!parent) {
return;
}
var range = document.createRange();
range.selectNodeContents(ele);
replaceNode(range.extractContents(), ele);
parent.normalize();
};
var sortHighlightPosition = function (a, b) {
if (a.top < b.top) {
return -1;
}
if (a.top > b.top) {
return 1;
}
if (a.left < b.left) {
return -1;
}
if (a.left > b.left) {
return 1;
}
return 0;
};
var Highlights = function (_a) {
var numPages = _a.numPages, pageIndex = _a.pageIndex, renderHighlights = _a.renderHighlights, store = _a.store, onHighlightKeyword = _a.onHighlightKeyword;
var containerRef = React__namespace.useRef();
var defaultRenderHighlights = React__namespace.useCallback(function (renderProps) { return (React__namespace.createElement(React__namespace.Fragment, null, renderProps.highlightAreas.map(function (area, index) { return (React__namespace.createElement(HightlightItem, { index: index, key: index, area: area, onHighlightKeyword: onHighlightKeyword })); }))); }, []);
var renderHighlightElements = renderHighlights || defaultRenderHighlights;
var _b = React__namespace.useState(store.get('matchPosition')), matchPosition = _b[0], setMatchPosition = _b[1];
var _c = React__namespace.useState(store.get('keyword') || [EMPTY_KEYWORD_REGEXP]), keywordRegexp = _c[0], setKeywordRegexp = _c[1];
var _d = React__namespace.useState({
pageIndex: pageIndex,
scale: 1,
status: core.LayerRenderStatus.PreRender,
}), renderStatus = _d[0], setRenderStatus = _d[1];
var currentMatchRef = React__namespace.useRef(null);
var characterIndexesRef = React__namespace.useRef([]);
var _e = React__namespace.useState([]), highlightAreas = _e[0], setHighlightAreas = _e[1];
var defaultTargetPageFilter = function () { return true; };
var targetPageFilter = React__namespace.useCallback(function () { return store.get('targetPageFilter') || defaultTargetPageFilter; }, [store.get('targetPageFilter')]);
var highlight = function (keywordStr, keyword, textLayerEle, span, charIndexSpan) {
var range = document.createRange();
var firstChild = span.firstChild;
if (!firstChild || firstChild.nodeType !== Node.TEXT_NODE) {
return null;
}
var length = firstChild.textContent.length;
var startOffset = charIndexSpan[0].charIndexInSpan;
var endOffset = charIndexSpan.length === 1 ? startOffset : charIndexSpan[charIndexSpan.length - 1].charIndexInSpan;
if (startOffset > length || endOffset + 1 > length) {
return null;
}
range.setStart(firstChild, startOffset);
range.setEnd(firstChild, endOffset + 1);
var wrapper = document.createElement('span');
range.surroundContents(wrapper);
var wrapperRect = wrapper.getBoundingClientRect();
var textLayerRect = textLayerEle.getBoundingClientRect();
var pageHeight = textLayerRect.height;
var pageWidth = textLayerRect.width;
var left = (100 * (wrapperRect.left - textLayerRect.left)) / pageWidth;
var top = (100 * (wrapperRect.top - textLayerRect.top)) / pageHeight;
var height = (100 * wrapperRect.height) / pageHeight;
var width = (100 * wrapperRect.width) / pageWidth;
unwrap(wrapper);
return {
keyword: keyword,
keywordStr: keywordStr,
numPages: numPages,
pageIndex: pageIndex,
left: left,
top: top,
height: height,
width: width,
pageHeight: pageHeight,
pageWidth: pageWidth,
};
};
var highlightAll = function (textLayerEle) {
var charIndexes = characterIndexesRef.current;
if (charIndexes.length === 0) {
return;
}
var highlightPos = [];
var spans = [].slice.call(textLayerEle.querySelectorAll('.rpv-core__text-layer-text'));
var fullText = charIndexes.map(function (item) { return item.char; }).join('');
keywordRegexp.forEach(function (keyword) {
var keywordStr = keyword.keyword;
if (!keywordStr.trim()) {
return;
}
var cloneKeyword = keyword.regExp.flags.indexOf('g') === -1
? new RegExp(keyword.regExp, "".concat(keyword.regExp.flags, "g"))
: keyword.regExp;
var match;
var matches = [];
while ((match = cloneKeyword.exec(fullText)) !== null) {
matches.push({
keyword: cloneKeyword,
startIndex: match.index,
endIndex: cloneKeyword.lastIndex,
});
}
matches
.map(function (item) { return ({
keyword: item.keyword,
indexes: charIndexes.slice(item.startIndex, item.endIndex),
}); })
.forEach(function (item) {
var spanIndexes = item.indexes.reduce(function (acc, item) {
acc[item.spanIndex] = (acc[item.spanIndex] || []).concat([item]);
return acc;
}, {});
Object.values(spanIndexes).forEach(function (charIndexSpan) {
if (charIndexSpan.length !== 1 || charIndexSpan[0].char.trim() !== '') {
var normalizedCharSpan = keyword.wholeWords ? charIndexSpan.slice(1, -1) : charIndexSpan;
var hightlighPosition = highlight(keywordStr, item.keyword, textLayerEle, spans[normalizedCharSpan[0].spanIndex], normalizedCharSpan);
if (hightlighPosition) {
highlightPos.push(hightlighPosition);
}
}
});
});
});
return highlightPos.sort(sortHighlightPosition);
};
var handleKeywordChanged = function (keyword) {
if (keyword && keyword.length > 0) {
setKeywordRegexp(keyword);
}
};
var handleMatchPositionChanged = function (currentPosition) { return setMatchPosition(currentPosition); };
var handleRenderStatusChanged = function (status) {
if (!status.has(pageIndex)) {
return;
}
var currentStatus = status.get(pageIndex);
if (currentStatus) {
setRenderStatus({
ele: currentStatus.ele,
pageIndex: pageIndex,
scale: currentStatus.scale,
status: currentStatus.status,
});
}
};
var isEmptyKeyword = function () {
return keywordRegexp.length === 0 || (keywordRegexp.length === 1 && keywordRegexp[0].keyword.trim() === '');
};
React__namespace.useEffect(function () {
if (isEmptyKeyword() ||
renderStatus.status !== core.LayerRenderStatus.DidRender ||
characterIndexesRef.current.length) {
return;
}
var textLayerEle = renderStatus.ele;
var spans = [].slice.call(textLayerEle.querySelectorAll('.rpv-core__text-layer-text'));
var charIndexes = spans
.map(function (span) { return span.textContent; })
.reduce(function (prev, curr, index) {
return prev.concat(curr.split('').map(function (c, i) { return ({
char: c,
charIndexInSpan: i,
spanIndex: index,
}); }));
}, [
{
char: '',
charIndexInSpan: 0,
spanIndex: 0,
},
])
.slice(1);
characterIndexesRef.current = charIndexes;
}, [keywordRegexp, renderStatus.status]);
React__namespace.useEffect(function () {
if (isEmptyKeyword() ||
!renderStatus.ele ||
renderStatus.status !== core.LayerRenderStatus.DidRender ||
!targetPageFilter()({ pageIndex: pageIndex, numPages: numPages })) {
return;
}
var textLayerEle = renderStatus.ele;
var highlightPos = highlightAll(textLayerEle);
setHighlightAreas(highlightPos);
}, [keywordRegexp, matchPosition, renderStatus.status, characterIndexesRef.current]);
React__namespace.useEffect(function () {
if (isEmptyKeyword() && renderStatus.ele && renderStatus.status === core.LayerRenderStatus.DidRender) {
setHighlightAreas([]);
}
}, [keywordRegexp, renderStatus.status]);
React__namespace.useEffect(function () {
if (highlightAreas.length === 0) {
return;
}
var container = containerRef.current;
if (matchPosition.pageIndex !== pageIndex ||
!container ||
renderStatus.status !== core.LayerRenderStatus.DidRender) {
return;
}
var highlightEle = container.querySelector(".rpv-search__highlight[data-index=\"".concat(matchPosition.matchIndex, "\"]"));
if (!highlightEle) {
return;
}
var _a = calculateOffset(highlightEle, container), left = _a.left, top = _a.top;
var jump = store.get('jumpToDestination');
if (jump) {
jump(pageIndex, (container.getBoundingClientRect().height - top) / renderStatus.scale, left / renderStatus.scale, renderStatus.scale);
if (currentMatchRef.current) {
currentMatchRef.current.classList.remove('rpv-search__highlight--current');
}
currentMatchRef.current = highlightEle;
highlightEle.classList.add('rpv-search__highlight--current');
}
}, [highlightAreas, matchPosition]);
React__namespace.useEffect(function () {
store.subscribe('keyword', handleKeywordChanged);
store.subscribe('matchPosition', handleMatchPositionChanged);
store.subscribe('renderStatus', handleRenderStatusChanged);
return function () {
store.unsubscribe('keyword', handleKeywordChanged);
store.unsubscribe('matchPosition', handleMatchPositionChanged);
store.unsubscribe('renderStatus', handleRenderStatusChanged);
};
}, []);
return (React__namespace.createElement("div", { className: "rpv-search__highlights", "data-testid": "search__highlights-".concat(pageIndex), ref: containerRef }, renderHighlightElements({
getCssProperties: getCssProperties,
highlightAreas: highlightAreas,
})));
};
var escapeRegExp = function (input) { return input.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); };

@@ -446,260 +734,2 @@ var normalizeFlagKeyword = function (flagKeyword) {

var calculateOffset = function (children, parent) {
var top = children.offsetTop;
var left = children.offsetLeft;
var p = children.parentElement;
while (p && p !== parent) {
top += p.offsetTop;
left += p.offsetLeft;
p = p.parentElement;
}
return {
left: left,
top: top,
};
};
var removeNode = function (ele) {
var parent = ele.parentNode;
if (parent) {
parent.removeChild(ele);
}
};
var replaceNode = function (replacementNode, node) {
removeNode(replacementNode);
var parent = node.parentNode;
if (parent) {
parent.insertBefore(replacementNode, node);
}
removeNode(node);
};
var unwrap = function (ele) {
var parent = ele.parentNode;
if (!parent) {
return;
}
var range = document.createRange();
range.selectNodeContents(ele);
replaceNode(range.extractContents(), ele);
parent.normalize();
};
var percentToNumber = function (input) { return parseFloat(input.slice(0, -1)); };
var sortHighlightElements = function (a, b) {
var aTop = percentToNumber(a.style.top);
var aLeft = percentToNumber(a.style.left);
var bTop = percentToNumber(b.style.top);
var bLeft = percentToNumber(b.style.left);
if (aTop < bTop) {
return -1;
}
if (aTop > bTop) {
return 1;
}
if (aLeft < bLeft) {
return -1;
}
if (aLeft > bLeft) {
return 1;
}
return 0;
};
var Tracker = function (_a) {
var numPages = _a.numPages, pageIndex = _a.pageIndex, store = _a.store, onHighlightKeyword = _a.onHighlightKeyword;
var _b = React__namespace.useState(store.get('matchPosition')), matchPosition = _b[0], setMatchPosition = _b[1];
var _c = React__namespace.useState(store.get('keyword') || [EMPTY_KEYWORD_REGEXP]), keywordRegexp = _c[0], setKeywordRegexp = _c[1];
var _d = React__namespace.useState({
pageIndex: pageIndex,
scale: 1,
status: core.LayerRenderStatus.PreRender,
}), renderStatus = _d[0], setRenderStatus = _d[1];
var currentMatchRef = React__namespace.useRef(null);
var characterIndexesRef = React__namespace.useRef([]);
var defaultTargetPageFilter = function () { return true; };
var targetPageFilter = React__namespace.useCallback(function () { return store.get('targetPageFilter') || defaultTargetPageFilter; }, [store.get('targetPageFilter')]);
var unhighlightAll = function (containerEle) {
var highlightNodes = containerEle.querySelectorAll('span.rpv-search__highlight');
var total = highlightNodes.length;
for (var i = 0; i < total; i++) {
highlightNodes[i].parentElement.removeChild(highlightNodes[i]);
}
};
var highlight = function (keywordStr, keyword, containerEle, span, charIndexSpan) {
var range = document.createRange();
var firstChild = span.firstChild;
if (!firstChild) {
return;
}
var startOffset = charIndexSpan[0].charIndexInSpan;
var endOffset = charIndexSpan.length === 1 ? startOffset : charIndexSpan[charIndexSpan.length - 1].charIndexInSpan;
range.setStart(firstChild, startOffset);
range.setEnd(firstChild, endOffset + 1);
var wrapper = document.createElement('span');
range.surroundContents(wrapper);
var wrapperRect = wrapper.getBoundingClientRect();
var containerRect = containerEle.getBoundingClientRect();
var highlightEle = document.createElement('span');
containerEle.insertBefore(highlightEle, containerEle.firstChild);
highlightEle.style.left = "".concat((100 * (wrapperRect.left - containerRect.left)) / containerRect.width, "%");
highlightEle.style.top = "".concat((100 * (wrapperRect.top - containerRect.top)) / containerRect.height, "%");
highlightEle.style.width = "".concat((100 * wrapperRect.width) / containerRect.width, "%");
highlightEle.style.height = "".concat((100 * wrapperRect.height) / containerRect.height, "%");
highlightEle.classList.add('rpv-search__highlight');
highlightEle.setAttribute('title', keywordStr.trim());
unwrap(wrapper);
if (onHighlightKeyword) {
onHighlightKeyword({
highlightEle: highlightEle,
keyword: keyword,
});
}
};
var highlightAll = function (containerEle) {
var charIndexes = characterIndexesRef.current;
if (charIndexes.length === 0) {
return;
}
var spans = [].slice.call(containerEle.querySelectorAll('.rpv-core__text-layer-text'));
var fullText = charIndexes.map(function (item) { return item.char; }).join('');
keywordRegexp.forEach(function (keyword) {
var keywordStr = keyword.keyword;
if (!keywordStr.trim()) {
return;
}
var cloneKeyword = keyword.regExp.flags.indexOf('g') === -1
? new RegExp(keyword.regExp, "".concat(keyword.regExp.flags, "g"))
: keyword.regExp;
var match;
var matches = [];
while ((match = cloneKeyword.exec(fullText)) !== null) {
matches.push({
keyword: cloneKeyword,
startIndex: match.index,
endIndex: cloneKeyword.lastIndex,
});
}
matches
.map(function (item) { return ({
keyword: item.keyword,
indexes: charIndexes.slice(item.startIndex, item.endIndex),
}); })
.forEach(function (item) {
var spanIndexes = item.indexes.reduce(function (acc, item) {
acc[item.spanIndex] = (acc[item.spanIndex] || []).concat([item]);
return acc;
}, {});
Object.values(spanIndexes).forEach(function (charIndexSpan) {
if (charIndexSpan.length !== 1 || charIndexSpan[0].char.trim() !== '') {
var normalizedCharSpan = keyword.wholeWords ? charIndexSpan.slice(1, -1) : charIndexSpan;
highlight(keywordStr, item.keyword, containerEle, spans[normalizedCharSpan[0].spanIndex], normalizedCharSpan);
}
});
});
});
var highlightEles = [].slice.call(containerEle.querySelectorAll('.rpv-search__highlight'));
highlightEles.sort(sortHighlightElements).forEach(function (ele, i) {
ele.setAttribute('data-index', "".concat(i));
});
};
var handleKeywordChanged = function (keyword) {
if (keyword && keyword.length > 0) {
setKeywordRegexp(keyword);
}
};
var handleMatchPositionChanged = function (currentPosition) { return setMatchPosition(currentPosition); };
var handleRenderStatusChanged = function (status) {
if (!status.has(pageIndex)) {
return;
}
var currentStatus = status.get(pageIndex);
if (currentStatus) {
setRenderStatus({
ele: currentStatus.ele,
pageIndex: pageIndex,
scale: currentStatus.scale,
status: currentStatus.status,
});
}
};
var isEmptyKeyword = function () {
return keywordRegexp.length === 0 || (keywordRegexp.length === 1 && keywordRegexp[0].keyword.trim() === '');
};
React__namespace.useEffect(function () {
if (isEmptyKeyword() ||
renderStatus.status !== core.LayerRenderStatus.DidRender ||
characterIndexesRef.current.length) {
return;
}
var containerEle = renderStatus.ele;
var spans = [].slice.call(containerEle.querySelectorAll('.rpv-core__text-layer-text'));
var charIndexes = spans
.map(function (span) { return span.textContent; })
.reduce(function (prev, curr, index) {
return prev.concat(curr.split('').map(function (c, i) { return ({
char: c,
charIndexInSpan: i,
spanIndex: index,
}); }));
}, [
{
char: '',
charIndexInSpan: 0,
spanIndex: 0,
},
])
.slice(1);
characterIndexesRef.current = charIndexes;
}, [keywordRegexp, renderStatus.status]);
React__namespace.useEffect(function () {
if (isEmptyKeyword() ||
!renderStatus.ele ||
renderStatus.status !== core.LayerRenderStatus.DidRender ||
!targetPageFilter()({ pageIndex: pageIndex, numPages: numPages })) {
return;
}
var containerEle = renderStatus.ele;
unhighlightAll(containerEle);
highlightAll(containerEle);
scrollToMatch();
}, [keywordRegexp, matchPosition, renderStatus.status, characterIndexesRef.current]);
React__namespace.useEffect(function () {
if (isEmptyKeyword() && renderStatus.ele && renderStatus.status === core.LayerRenderStatus.DidRender) {
unhighlightAll(renderStatus.ele);
}
}, [keywordRegexp, renderStatus.status]);
var scrollToMatch = function () {
if (matchPosition.pageIndex !== pageIndex ||
!renderStatus.ele ||
renderStatus.status !== core.LayerRenderStatus.DidRender) {
return;
}
var container = renderStatus.ele;
var highlightEle = container.querySelector(".rpv-search__highlight[data-index=\"".concat(matchPosition.matchIndex, "\"]"));
if (!highlightEle) {
return;
}
var _a = calculateOffset(highlightEle, container), left = _a.left, top = _a.top;
var jump = store.get('jumpToDestination');
if (jump) {
jump(pageIndex, (container.getBoundingClientRect().height - top) / renderStatus.scale, left / renderStatus.scale, renderStatus.scale);
if (currentMatchRef.current) {
currentMatchRef.current.classList.remove('rpv-search__highlight--current');
}
currentMatchRef.current = highlightEle;
highlightEle.classList.add('rpv-search__highlight--current');
}
};
React__namespace.useEffect(function () {
store.subscribe('keyword', handleKeywordChanged);
store.subscribe('matchPosition', handleMatchPositionChanged);
store.subscribe('renderStatus', handleRenderStatusChanged);
return function () {
store.unsubscribe('keyword', handleKeywordChanged);
store.unsubscribe('matchPosition', handleMatchPositionChanged);
store.unsubscribe('renderStatus', handleRenderStatusChanged);
};
}, []);
return React__namespace.createElement(React__namespace.Fragment, null);
};
var normalizeKeywords = function (keyword) {

@@ -733,3 +763,3 @@ return Array.isArray(keyword) ? keyword.map(function (k) { return normalizeSingleKeyword(k); }) : [normalizeSingleKeyword(keyword)];

};
var renderPageLayer = function (renderProps) { return (React__namespace.createElement(Tracker, { key: renderProps.pageIndex, numPages: renderProps.doc.numPages, pageIndex: renderProps.pageIndex, store: store, onHighlightKeyword: searchPluginProps.onHighlightKeyword })); };
var renderPageLayer = function (renderProps) { return (React__namespace.createElement(Highlights, { key: renderProps.pageIndex, numPages: renderProps.doc.numPages, pageIndex: renderProps.pageIndex, renderHighlights: props === null || props === void 0 ? void 0 : props.renderHighlights, store: store, onHighlightKeyword: searchPluginProps.onHighlightKeyword })); };
return {

@@ -736,0 +766,0 @@ install: function (pluginFunctions) {

@@ -1,1 +0,1 @@

"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@react-pdf-viewer/core");function t(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach((function(r){if("default"!==r){var n=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,n.get?n:{enumerable:!0,get:function(){return e[r]}})}})),t.default=e,Object.freeze(t)}var r=t(require("react")),n=function(){return r.createElement(e.Icon,{size:16},r.createElement("path",{d:"M0.541,5.627L11.666,18.2c0.183,0.207,0.499,0.226,0.706,0.043c0.015-0.014,0.03-0.028,0.043-0.043\n L23.541,5.627"}))},o=function(){return r.createElement(e.Icon,{size:16},r.createElement("path",{d:"M23.535,18.373L12.409,5.8c-0.183-0.207-0.499-0.226-0.706-0.043C11.688,5.77,11.674,5.785,11.66,5.8\n L0.535,18.373"}))},a=function(){return r.createElement(e.Icon,{ignoreDirection:!0,size:16},r.createElement("path",{d:"M10.5,0.5c5.523,0,10,4.477,10,10s-4.477,10-10,10s-10-4.477-10-10S4.977,0.5,10.5,0.5z\n M23.5,23.5\n l-5.929-5.929"}))},c=function(){return c=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var o in t=arguments[r])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},c.apply(this,arguments)},u={keyword:"",regExp:new RegExp(" "),wholeWords:!1},s=function(e){var t,r=e.wholeWords?" ".concat(e.keyword," "):e.keyword,n=e.matchCase?"g":"gi";return{keyword:e.keyword,regExp:new RegExp((t=r,t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")),n),wholeWords:e.wholeWords||!1}},i=function(e,t,r){return e instanceof RegExp?{keyword:e.source,regExp:e,wholeWords:r||!1}:"string"==typeof e?""===e?u:s({keyword:e,matchCase:t||!1,wholeWords:r||!1}):(void 0!==t&&(e.matchCase=t),void 0!==r&&(e.wholeWords=r),s(e))},l=function(t){var n,o=function(e){var t=r.useRef(e.get("doc")),n=function(e){t.current=e};return r.useEffect((function(){return e.subscribe("doc",n),function(){e.unsubscribe("doc",n)}}),[]),t}(t),a=r.useState([]),c=a[0],s=a[1],l=r.useState([]),h=l[0],f=l[1],d=r.useState(0),p=d[0],g=d[1],m=r.useState(!1),v=m[0],x=m[1],y=r.useRef([]),E=r.useState(!1),b=E[0],w=E[1],S=function(){return!0},k=r.useCallback((function(){return t.get("targetPageFilter")||S}),[t.get("targetPageFilter")]),P=function(e){var t=h.length;if(0===c.length||0===t)return null;var r=e===t+1?1:Math.max(1,Math.min(t,e));return g(r),C(h[r-1])},_=function(e){return s(""===e?[]:[e])},C=function(e){var r=t.get("jumpToPage");return r&&r(e.pageIndex),t.update("matchPosition",{matchIndex:e.matchIndex,pageIndex:e.pageIndex}),e},I=function(r,n,a){var c=o.current;if(!c)return Promise.resolve([]);var u=c.numPages,s=r.map((function(e){return i(e,n,a)}));return t.update("keyword",s),g(0),f([]),new Promise((function(t,r){var n=0===y.current.length?function(){var t=o.current;if(!t)return Promise.resolve([]);var r=Array(t.numPages).fill(0).map((function(r,n){return e.getPage(t,n).then((function(e){return e.getTextContent()})).then((function(e){var t=e.items.map((function(e){return e.str||""})).join("");return Promise.resolve({pageContent:t,pageIndex:n})}))}));return Promise.all(r).then((function(e){return e.sort((function(e,t){return e.pageIndex-t.pageIndex})),Promise.resolve(e.map((function(e){return e.pageContent})))}))}().then((function(e){return y.current=e,Promise.resolve(e)})):Promise.resolve(y.current);n.then((function(e){var r=[];e.forEach((function(e,t){k()({pageIndex:t,numPages:u})&&s.forEach((function(n){for(var o,a=0;null!==(o=n.regExp.exec(e));)r.push({keyword:n.regExp,matchIndex:a,pageIndex:t,pageText:e,startIndex:o.index,endIndex:n.regExp.lastIndex}),a++}))})),f(r),r.length>0&&(g(1),C(r[0])),t(r)}))}))};return r.useEffect((function(){y.current=[]}),[o.current]),{clearKeyword:function(){t.update("keyword",[u]),_(""),g(0),f([]),x(!1),w(!1)},changeMatchCase:function(e){x(e),c.length>0&&I(c,e,b)},changeWholeWords:function(e){w(e),c.length>0&&I(c,v,e)},currentMatch:p,jumpToMatch:P,jumpToNextMatch:function(){return P(p+1)},jumpToPreviousMatch:function(){return P(p-1)},keywords:c,matchCase:v,numberOfMatches:h.length,wholeWords:b,search:function(){return I(c,v,b)},searchFor:I,setKeywords:s,keyword:0===c.length?"":(n=c[0],n instanceof RegExp?n.source:"string"==typeof n?n:n.keyword),setKeyword:_,setTargetPages:function(e){t.update("targetPageFilter",e)}}},h=function(e){var t=e.children,r=e.store,n=l(r);return t(c({},n))},f=function(t){var n=t.containerRef,o=t.store,a=r.useState(!0),c=a[0],u=a[1],s=function(){return u(!0)},i=function(){return u(!1)},l=function(t){var r=n.current;r&&(t.shiftKey||t.altKey||"f"!==t.key||(e.isMac()?t.metaKey&&!t.ctrlKey:t.ctrlKey)&&(c||document.activeElement&&r.contains(document.activeElement))&&(t.preventDefault(),o.update("areShortcutsPressed",!0)))};return r.useEffect((function(){var e=n.current;if(e)return document.addEventListener("keydown",l),e.addEventListener("mouseenter",s),e.addEventListener("mouseleave",i),function(){document.removeEventListener("keydown",l),e.removeEventListener("mouseenter",s),e.removeEventListener("mouseleave",i)}}),[n.current]),r.createElement(r.Fragment,null)},d={left:0,top:8},p=function(t){var a=t.store,c=t.onToggle,u=r.useContext(e.LocalizationContext).l10n,s=r.useContext(e.ThemeContext).direction,i=r.useState(!1),h=i[0],f=i[1],p=r.useState(!1),g=p[0],m=p[1],v=s===e.TextDirection.RightToLeft,x=l(a),y=x.clearKeyword,E=x.changeMatchCase,b=x.changeWholeWords,w=x.currentMatch,S=x.jumpToNextMatch,k=x.jumpToPreviousMatch,P=x.keyword,_=x.matchCase,C=x.numberOfMatches,I=x.wholeWords,T=x.search,M=x.setKeyword,L=u&&u.search?u.search.enterToSearch:"Enter to search",R=u&&u.search?u.search.previousMatch:"Previous match",j=u&&u.search?u.search.nextMatch:"Next match";return r.createElement("div",{className:"rpv-search__popover"},r.createElement("div",{className:"rpv-search__popover-input-counter"},r.createElement(e.TextBox,{ariaLabel:L,autoFocus:!0,placeholder:L,type:"text",value:P,onChange:function(e){m(!1),M(e)},onKeyDown:function(e){"Enter"===e.key&&P&&(g?S():(f(!0),T().then((function(e){f(!1),m(!0)}))))}}),r.createElement("div",{className:e.classNames({"rpv-search__popover-counter":!0,"rpv-search__popover-counter--ltr":!v,"rpv-search__popover-counter--rtl":v})},h&&r.createElement(e.Spinner,{testId:"search__popover-searching",size:"1rem"}),!h&&r.createElement("span",{"data-testid":"search__popover-num-matches"},w,"/",C))),r.createElement("label",{className:"rpv-search__popover-label"},r.createElement("input",{className:"rpv-search__popover-label-checkbox",checked:_,type:"checkbox",onChange:function(e){m(!1),E(e.target.checked)}})," ",u&&u.search?u.search.matchCase:"Match case"),r.createElement("label",{className:"rpv-search__popover-label"},r.createElement("input",{className:"rpv-search__popover-label-checkbox",checked:I,type:"checkbox",onChange:function(e){m(!1),b(e.target.checked)}})," ",u&&u.search?u.search.wholeWords:"Whole words"),r.createElement("div",{className:"rpv-search__popover-footer"},r.createElement("div",{className:"rpv-search__popover-footer-item"},r.createElement(e.Tooltip,{ariaControlsSuffix:"search-previous-match",position:v?e.Position.BottomRight:e.Position.BottomCenter,target:r.createElement(e.MinimalButton,{ariaLabel:R,isDisabled:w<=1,onClick:k},r.createElement(o,null)),content:function(){return R},offset:d})),r.createElement("div",{className:"rpv-search__popover-footer-item"},r.createElement(e.Tooltip,{ariaControlsSuffix:"search-next-match",position:e.Position.BottomCenter,target:r.createElement(e.MinimalButton,{ariaLabel:j,isDisabled:w>C-1,onClick:S},r.createElement(n,null)),content:function(){return j},offset:d})),r.createElement("div",{className:e.classNames({"rpv-search__popover-footer-button":!0,"rpv-search__popover-footer-button--ltr":!v,"rpv-search__popover-footer-button--rtl":v})},r.createElement(e.Button,{onClick:function(){c(),y()}},u&&u.search?u.search.close:"Close"))))},g=function(t){var n=t.children,o=t.onClick,c=r.useContext(e.LocalizationContext).l10n,u=c&&c.search?c.search.search:"Search";return n({icon:r.createElement(a,null),label:u,onClick:o})},m={left:0,top:8},v=function(t){var n=t.enableShortcuts,o=t.store,a=t.onClick,c=n?e.isMac()?"Meta+F":"Ctrl+F":"",u=function(e){e&&a()};return r.useEffect((function(){return o.subscribe("areShortcutsPressed",u),function(){o.unsubscribe("areShortcutsPressed",u)}}),[]),r.createElement(g,{onClick:a},(function(t){return r.createElement(e.Tooltip,{ariaControlsSuffix:"search-popover",position:e.Position.BottomCenter,target:r.createElement(e.MinimalButton,{ariaKeyShortcuts:c,ariaLabel:t.label,testId:"search__popover-button",onClick:a},t.icon),content:function(){return t.label},offset:m})}))},x={left:0,top:8},y=function(t){var n=t.children,o=t.enableShortcuts,a=t.store,u=r.useContext(e.ThemeContext).direction===e.TextDirection.RightToLeft?e.Position.BottomRight:e.Position.BottomLeft,s=n||function(e){return r.createElement(v,c({enableShortcuts:o,store:a},e))};return r.createElement(e.Popover,{ariaControlsSuffix:"search",lockScroll:!1,position:u,target:function(e){return s({onClick:e})},content:function(e){return r.createElement(p,{store:a,onToggle:e})},offset:x,closeOnClickOutside:!1,closeOnEscape:!0})},E=function(e){var t=e.parentNode;t&&t.removeChild(e)},b=function(e){var t=e.parentNode;if(t){var r=document.createRange();r.selectNodeContents(e),function(e,t){E(e);var r=t.parentNode;r&&r.insertBefore(e,t),E(t)}(r.extractContents(),e),t.normalize()}},w=function(e){return parseFloat(e.slice(0,-1))},S=function(e,t){var r=w(e.style.top),n=w(e.style.left),o=w(t.style.top),a=w(t.style.left);return r<o?-1:r>o?1:n<a?-1:n>a?1:0},k=function(t){var n=t.numPages,o=t.pageIndex,a=t.store,c=t.onHighlightKeyword,s=r.useState(a.get("matchPosition")),i=s[0],l=s[1],h=r.useState(a.get("keyword")||[u]),f=h[0],d=h[1],p=r.useState({pageIndex:o,scale:1,status:e.LayerRenderStatus.PreRender}),g=p[0],m=p[1],v=r.useRef(null),x=r.useRef([]),y=function(){return!0},E=r.useCallback((function(){return a.get("targetPageFilter")||y}),[a.get("targetPageFilter")]),w=function(e){for(var t=e.querySelectorAll("span.rpv-search__highlight"),r=t.length,n=0;n<r;n++)t[n].parentElement.removeChild(t[n])},k=function(e){var t=x.current;if(0!==t.length){var r=[].slice.call(e.querySelectorAll(".rpv-core__text-layer-text")),n=t.map((function(e){return e.char})).join("");f.forEach((function(o){var a=o.keyword;if(a.trim()){for(var u,s=-1===o.regExp.flags.indexOf("g")?new RegExp(o.regExp,"".concat(o.regExp.flags,"g")):o.regExp,i=[];null!==(u=s.exec(n));)i.push({keyword:s,startIndex:u.index,endIndex:s.lastIndex});i.map((function(e){return{keyword:e.keyword,indexes:t.slice(e.startIndex,e.endIndex)}})).forEach((function(t){var n=t.indexes.reduce((function(e,t){return e[t.spanIndex]=(e[t.spanIndex]||[]).concat([t]),e}),{});Object.values(n).forEach((function(n){if(1!==n.length||""!==n[0].char.trim()){var u=o.wholeWords?n.slice(1,-1):n;!function(e,t,r,n,o){var a=document.createRange(),u=n.firstChild;if(u){var s=o[0].charIndexInSpan,i=1===o.length?s:o[o.length-1].charIndexInSpan;a.setStart(u,s),a.setEnd(u,i+1);var l=document.createElement("span");a.surroundContents(l);var h=l.getBoundingClientRect(),f=r.getBoundingClientRect(),d=document.createElement("span");r.insertBefore(d,r.firstChild),d.style.left="".concat(100*(h.left-f.left)/f.width,"%"),d.style.top="".concat(100*(h.top-f.top)/f.height,"%"),d.style.width="".concat(100*h.width/f.width,"%"),d.style.height="".concat(100*h.height/f.height,"%"),d.classList.add("rpv-search__highlight"),d.setAttribute("title",e.trim()),b(l),c&&c({highlightEle:d,keyword:t})}}(a,t.keyword,e,r[u[0].spanIndex],u)}}))}))}})),[].slice.call(e.querySelectorAll(".rpv-search__highlight")).sort(S).forEach((function(e,t){e.setAttribute("data-index","".concat(t))}))}},P=function(e){e&&e.length>0&&d(e)},_=function(e){return l(e)},C=function(e){if(e.has(o)){var t=e.get(o);t&&m({ele:t.ele,pageIndex:o,scale:t.scale,status:t.status})}},I=function(){return 0===f.length||1===f.length&&""===f[0].keyword.trim()};r.useEffect((function(){if(!I()&&g.status===e.LayerRenderStatus.DidRender&&!x.current.length){var t=g.ele,r=[].slice.call(t.querySelectorAll(".rpv-core__text-layer-text")).map((function(e){return e.textContent})).reduce((function(e,t,r){return e.concat(t.split("").map((function(e,t){return{char:e,charIndexInSpan:t,spanIndex:r}})))}),[{char:"",charIndexInSpan:0,spanIndex:0}]).slice(1);x.current=r}}),[f,g.status]),r.useEffect((function(){if(!I()&&g.ele&&g.status===e.LayerRenderStatus.DidRender&&E()({pageIndex:o,numPages:n})){var t=g.ele;w(t),k(t),T()}}),[f,i,g.status,x.current]),r.useEffect((function(){I()&&g.ele&&g.status===e.LayerRenderStatus.DidRender&&w(g.ele)}),[f,g.status]);var T=function(){if(i.pageIndex===o&&g.ele&&g.status===e.LayerRenderStatus.DidRender){var t=g.ele,r=t.querySelector('.rpv-search__highlight[data-index="'.concat(i.matchIndex,'"]'));if(r){var n=function(e,t){for(var r=e.offsetTop,n=e.offsetLeft,o=e.parentElement;o&&o!==t;)r+=o.offsetTop,n+=o.offsetLeft,o=o.parentElement;return{left:n,top:r}}(r,t),c=n.left,u=n.top,s=a.get("jumpToDestination");s&&(s(o,(t.getBoundingClientRect().height-u)/g.scale,c/g.scale,g.scale),v.current&&v.current.classList.remove("rpv-search__highlight--current"),v.current=r,r.classList.add("rpv-search__highlight--current"))}}};return r.useEffect((function(){return a.subscribe("keyword",P),a.subscribe("matchPosition",_),a.subscribe("renderStatus",C),function(){a.unsubscribe("keyword",P),a.unsubscribe("matchPosition",_),a.unsubscribe("renderStatus",C)}}),[]),r.createElement(r.Fragment,null)},P=function(e){return Array.isArray(e)?e.map((function(e){return i(e)})):[i(e)]};exports.NextIcon=n,exports.PreviousIcon=o,exports.SearchIcon=a,exports.searchPlugin=function(t){var n=r.useMemo((function(){return Object.assign({},{enableShortcuts:!0,onHighlightKeyword:function(){}},t)}),[]),o=r.useMemo((function(){return e.createStore({matchPosition:{matchIndex:-1,pageIndex:-1},renderStatus:new Map,keyword:t&&t.keyword?P(t.keyword):[u]})}),[]),a=l(o),s=a.clearKeyword,i=a.jumpToMatch,d=a.jumpToNextMatch,p=a.jumpToPreviousMatch,g=a.searchFor,m=a.setKeywords,x=a.setTargetPages,E=function(e){return r.createElement(y,c({enableShortcuts:n.enableShortcuts},e,{store:o}))};return{install:function(e){var r=t&&t.keyword?P(t.keyword):[u];o.update("jumpToDestination",e.jumpToDestination),o.update("jumpToPage",e.jumpToPage),o.update("keyword",r)},renderPageLayer:function(e){return r.createElement(k,{key:e.pageIndex,numPages:e.doc.numPages,pageIndex:e.pageIndex,store:o,onHighlightKeyword:n.onHighlightKeyword})},renderViewer:function(e){var t=e.slot;return t.subSlot&&(t.subSlot.children=r.createElement(r.Fragment,null,n.enableShortcuts&&r.createElement(f,{containerRef:e.containerRef,store:o}),t.subSlot.children)),t},uninstall:function(e){var t=o.get("renderStatus");t&&t.clear()},onDocumentLoad:function(e){o.update("doc",e.doc)},onTextLayerRender:function(e){var t=o.get("renderStatus");t&&(t=t.set(e.pageIndex,e),o.update("renderStatus",t))},Search:function(e){return r.createElement(h,c({},e,{store:o}))},ShowSearchPopover:E,ShowSearchPopoverButton:function(){return r.createElement(E,null,(function(e){return r.createElement(v,c({enableShortcuts:n.enableShortcuts,store:o},e))}))},clearHighlights:function(){s()},highlight:function(e){var t=Array.isArray(e)?e:[e];return m(t),g(t)},jumpToMatch:i,jumpToNextMatch:d,jumpToPreviousMatch:p,setTargetPages:x}};
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@react-pdf-viewer/core");function t(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach((function(r){if("default"!==r){var n=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,n.get?n:{enumerable:!0,get:function(){return e[r]}})}})),t.default=e,Object.freeze(t)}var r=t(require("react")),n=function(){return r.createElement(e.Icon,{size:16},r.createElement("path",{d:"M0.541,5.627L11.666,18.2c0.183,0.207,0.499,0.226,0.706,0.043c0.015-0.014,0.03-0.028,0.043-0.043\n L23.541,5.627"}))},o=function(){return r.createElement(e.Icon,{size:16},r.createElement("path",{d:"M23.535,18.373L12.409,5.8c-0.183-0.207-0.499-0.226-0.706-0.043C11.688,5.77,11.674,5.785,11.66,5.8\n L0.535,18.373"}))},a=function(){return r.createElement(e.Icon,{ignoreDirection:!0,size:16},r.createElement("path",{d:"M10.5,0.5c5.523,0,10,4.477,10,10s-4.477,10-10,10s-10-4.477-10-10S4.977,0.5,10.5,0.5z\n M23.5,23.5\n l-5.929-5.929"}))},c=function(){return c=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var o in t=arguments[r])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},c.apply(this,arguments)},u={keyword:"",regExp:new RegExp(" "),wholeWords:!1},s=function(e){return{left:"".concat(e.left,"%"),top:"".concat(e.top,"%"),height:"".concat(e.height,"%"),width:"".concat(e.width,"%")}},i=function(t){var n=t.index,o=t.area,a=t.onHighlightKeyword,c=r.useRef();return e.useIsomorphicLayoutEffect((function(){var e=c.current;a&&e&&a({highlightEle:e,keyword:o.keyword})}),[]),r.createElement("div",{className:"rpv-search__highlight","data-index":n,ref:c,style:s(o),title:o.keywordStr.trim()})},l=function(e){var t=e.parentNode;t&&t.removeChild(e)},h=function(e){var t=e.parentNode;if(t){var r=document.createRange();r.selectNodeContents(e),function(e,t){l(e);var r=t.parentNode;r&&r.insertBefore(e,t),l(t)}(r.extractContents(),e),t.normalize()}},f=function(e,t){return e.top<t.top?-1:e.top>t.top?1:e.left<t.left?-1:e.left>t.left?1:0},d=function(t){var n=t.numPages,o=t.pageIndex,a=t.renderHighlights,c=t.store,l=t.onHighlightKeyword,d=r.useRef(),p=r.useCallback((function(e){return r.createElement(r.Fragment,null,e.highlightAreas.map((function(e,t){return r.createElement(i,{index:t,key:t,area:e,onHighlightKeyword:l})})))}),[]),g=a||p,m=r.useState(c.get("matchPosition")),v=m[0],x=m[1],E=r.useState(c.get("keyword")||[u]),y=E[0],w=E[1],b=r.useState({pageIndex:o,scale:1,status:e.LayerRenderStatus.PreRender}),S=b[0],k=b[1],P=r.useRef(null),_=r.useRef([]),C=r.useState([]),I=C[0],T=C[1],M=function(){return!0},R=r.useCallback((function(){return c.get("targetPageFilter")||M}),[c.get("targetPageFilter")]),L=function(e){var t=_.current;if(0!==t.length){var r=[],a=[].slice.call(e.querySelectorAll(".rpv-core__text-layer-text")),c=t.map((function(e){return e.char})).join("");return y.forEach((function(u){var s=u.keyword;if(s.trim()){for(var i,l=-1===u.regExp.flags.indexOf("g")?new RegExp(u.regExp,"".concat(u.regExp.flags,"g")):u.regExp,f=[];null!==(i=l.exec(c));)f.push({keyword:l,startIndex:i.index,endIndex:l.lastIndex});f.map((function(e){return{keyword:e.keyword,indexes:t.slice(e.startIndex,e.endIndex)}})).forEach((function(t){var c=t.indexes.reduce((function(e,t){return e[t.spanIndex]=(e[t.spanIndex]||[]).concat([t]),e}),{});Object.values(c).forEach((function(c){if(1!==c.length||""!==c[0].char.trim()){var i=u.wholeWords?c.slice(1,-1):c,l=function(e,t,r,a,c){var u=document.createRange(),s=a.firstChild;if(!s||s.nodeType!==Node.TEXT_NODE)return null;var i=s.textContent.length,l=c[0].charIndexInSpan,f=1===c.length?l:c[c.length-1].charIndexInSpan;if(l>i||f+1>i)return null;u.setStart(s,l),u.setEnd(s,f+1);var d=document.createElement("span");u.surroundContents(d);var p=d.getBoundingClientRect(),g=r.getBoundingClientRect(),m=g.height,v=g.width,x=100*(p.left-g.left)/v,E=100*(p.top-g.top)/m,y=100*p.height/m,w=100*p.width/v;return h(d),{keyword:t,keywordStr:e,numPages:n,pageIndex:o,left:x,top:E,height:y,width:w,pageHeight:m,pageWidth:v}}(s,t.keyword,e,a[i[0].spanIndex],i);l&&r.push(l)}}))}))}})),r.sort(f)}},j=function(e){e&&e.length>0&&w(e)},N=function(e){return x(e)},K=function(e){if(e.has(o)){var t=e.get(o);t&&k({ele:t.ele,pageIndex:o,scale:t.scale,status:t.status})}},O=function(){return 0===y.length||1===y.length&&""===y[0].keyword.trim()};return r.useEffect((function(){if(!O()&&S.status===e.LayerRenderStatus.DidRender&&!_.current.length){var t=S.ele,r=[].slice.call(t.querySelectorAll(".rpv-core__text-layer-text")).map((function(e){return e.textContent})).reduce((function(e,t,r){return e.concat(t.split("").map((function(e,t){return{char:e,charIndexInSpan:t,spanIndex:r}})))}),[{char:"",charIndexInSpan:0,spanIndex:0}]).slice(1);_.current=r}}),[y,S.status]),r.useEffect((function(){if(!O()&&S.ele&&S.status===e.LayerRenderStatus.DidRender&&R()({pageIndex:o,numPages:n})){var t=S.ele,r=L(t);T(r)}}),[y,v,S.status,_.current]),r.useEffect((function(){O()&&S.ele&&S.status===e.LayerRenderStatus.DidRender&&T([])}),[y,S.status]),r.useEffect((function(){if(0!==I.length){var t=d.current;if(v.pageIndex===o&&t&&S.status===e.LayerRenderStatus.DidRender){var r=t.querySelector('.rpv-search__highlight[data-index="'.concat(v.matchIndex,'"]'));if(r){var n=function(e,t){for(var r=e.offsetTop,n=e.offsetLeft,o=e.parentElement;o&&o!==t;)r+=o.offsetTop,n+=o.offsetLeft,o=o.parentElement;return{left:n,top:r}}(r,t),a=n.left,u=n.top,s=c.get("jumpToDestination");s&&(s(o,(t.getBoundingClientRect().height-u)/S.scale,a/S.scale,S.scale),P.current&&P.current.classList.remove("rpv-search__highlight--current"),P.current=r,r.classList.add("rpv-search__highlight--current"))}}}}),[I,v]),r.useEffect((function(){return c.subscribe("keyword",j),c.subscribe("matchPosition",N),c.subscribe("renderStatus",K),function(){c.unsubscribe("keyword",j),c.unsubscribe("matchPosition",N),c.unsubscribe("renderStatus",K)}}),[]),r.createElement("div",{className:"rpv-search__highlights","data-testid":"search__highlights-".concat(o),ref:d},g({getCssProperties:s,highlightAreas:I}))},p=function(e){var t,r=e.wholeWords?" ".concat(e.keyword," "):e.keyword,n=e.matchCase?"g":"gi";return{keyword:e.keyword,regExp:new RegExp((t=r,t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")),n),wholeWords:e.wholeWords||!1}},g=function(e,t,r){return e instanceof RegExp?{keyword:e.source,regExp:e,wholeWords:r||!1}:"string"==typeof e?""===e?u:p({keyword:e,matchCase:t||!1,wholeWords:r||!1}):(void 0!==t&&(e.matchCase=t),void 0!==r&&(e.wholeWords=r),p(e))},m=function(t){var n,o=function(e){var t=r.useRef(e.get("doc")),n=function(e){t.current=e};return r.useEffect((function(){return e.subscribe("doc",n),function(){e.unsubscribe("doc",n)}}),[]),t}(t),a=r.useState([]),c=a[0],s=a[1],i=r.useState([]),l=i[0],h=i[1],f=r.useState(0),d=f[0],p=f[1],m=r.useState(!1),v=m[0],x=m[1],E=r.useRef([]),y=r.useState(!1),w=y[0],b=y[1],S=function(){return!0},k=r.useCallback((function(){return t.get("targetPageFilter")||S}),[t.get("targetPageFilter")]),P=function(e){var t=l.length;if(0===c.length||0===t)return null;var r=e===t+1?1:Math.max(1,Math.min(t,e));return p(r),C(l[r-1])},_=function(e){return s(""===e?[]:[e])},C=function(e){var r=t.get("jumpToPage");return r&&r(e.pageIndex),t.update("matchPosition",{matchIndex:e.matchIndex,pageIndex:e.pageIndex}),e},I=function(r,n,a){var c=o.current;if(!c)return Promise.resolve([]);var u=c.numPages,s=r.map((function(e){return g(e,n,a)}));return t.update("keyword",s),p(0),h([]),new Promise((function(t,r){var n=0===E.current.length?function(){var t=o.current;if(!t)return Promise.resolve([]);var r=Array(t.numPages).fill(0).map((function(r,n){return e.getPage(t,n).then((function(e){return e.getTextContent()})).then((function(e){var t=e.items.map((function(e){return e.str||""})).join("");return Promise.resolve({pageContent:t,pageIndex:n})}))}));return Promise.all(r).then((function(e){return e.sort((function(e,t){return e.pageIndex-t.pageIndex})),Promise.resolve(e.map((function(e){return e.pageContent})))}))}().then((function(e){return E.current=e,Promise.resolve(e)})):Promise.resolve(E.current);n.then((function(e){var r=[];e.forEach((function(e,t){k()({pageIndex:t,numPages:u})&&s.forEach((function(n){for(var o,a=0;null!==(o=n.regExp.exec(e));)r.push({keyword:n.regExp,matchIndex:a,pageIndex:t,pageText:e,startIndex:o.index,endIndex:n.regExp.lastIndex}),a++}))})),h(r),r.length>0&&(p(1),C(r[0])),t(r)}))}))};return r.useEffect((function(){E.current=[]}),[o.current]),{clearKeyword:function(){t.update("keyword",[u]),_(""),p(0),h([]),x(!1),b(!1)},changeMatchCase:function(e){x(e),c.length>0&&I(c,e,w)},changeWholeWords:function(e){b(e),c.length>0&&I(c,v,e)},currentMatch:d,jumpToMatch:P,jumpToNextMatch:function(){return P(d+1)},jumpToPreviousMatch:function(){return P(d-1)},keywords:c,matchCase:v,numberOfMatches:l.length,wholeWords:w,search:function(){return I(c,v,w)},searchFor:I,setKeywords:s,keyword:0===c.length?"":(n=c[0],n instanceof RegExp?n.source:"string"==typeof n?n:n.keyword),setKeyword:_,setTargetPages:function(e){t.update("targetPageFilter",e)}}},v=function(e){var t=e.children,r=e.store,n=m(r);return t(c({},n))},x=function(t){var n=t.containerRef,o=t.store,a=r.useState(!0),c=a[0],u=a[1],s=function(){return u(!0)},i=function(){return u(!1)},l=function(t){var r=n.current;r&&(t.shiftKey||t.altKey||"f"!==t.key||(e.isMac()?t.metaKey&&!t.ctrlKey:t.ctrlKey)&&(c||document.activeElement&&r.contains(document.activeElement))&&(t.preventDefault(),o.update("areShortcutsPressed",!0)))};return r.useEffect((function(){var e=n.current;if(e)return document.addEventListener("keydown",l),e.addEventListener("mouseenter",s),e.addEventListener("mouseleave",i),function(){document.removeEventListener("keydown",l),e.removeEventListener("mouseenter",s),e.removeEventListener("mouseleave",i)}}),[n.current]),r.createElement(r.Fragment,null)},E={left:0,top:8},y=function(t){var a=t.store,c=t.onToggle,u=r.useContext(e.LocalizationContext).l10n,s=r.useContext(e.ThemeContext).direction,i=r.useState(!1),l=i[0],h=i[1],f=r.useState(!1),d=f[0],p=f[1],g=s===e.TextDirection.RightToLeft,v=m(a),x=v.clearKeyword,y=v.changeMatchCase,w=v.changeWholeWords,b=v.currentMatch,S=v.jumpToNextMatch,k=v.jumpToPreviousMatch,P=v.keyword,_=v.matchCase,C=v.numberOfMatches,I=v.wholeWords,T=v.search,M=v.setKeyword,R=u&&u.search?u.search.enterToSearch:"Enter to search",L=u&&u.search?u.search.previousMatch:"Previous match",j=u&&u.search?u.search.nextMatch:"Next match";return r.createElement("div",{className:"rpv-search__popover"},r.createElement("div",{className:"rpv-search__popover-input-counter"},r.createElement(e.TextBox,{ariaLabel:R,autoFocus:!0,placeholder:R,type:"text",value:P,onChange:function(e){p(!1),M(e)},onKeyDown:function(e){"Enter"===e.key&&P&&(d?S():(h(!0),T().then((function(e){h(!1),p(!0)}))))}}),r.createElement("div",{className:e.classNames({"rpv-search__popover-counter":!0,"rpv-search__popover-counter--ltr":!g,"rpv-search__popover-counter--rtl":g})},l&&r.createElement(e.Spinner,{testId:"search__popover-searching",size:"1rem"}),!l&&r.createElement("span",{"data-testid":"search__popover-num-matches"},b,"/",C))),r.createElement("label",{className:"rpv-search__popover-label"},r.createElement("input",{className:"rpv-search__popover-label-checkbox",checked:_,type:"checkbox",onChange:function(e){p(!1),y(e.target.checked)}})," ",u&&u.search?u.search.matchCase:"Match case"),r.createElement("label",{className:"rpv-search__popover-label"},r.createElement("input",{className:"rpv-search__popover-label-checkbox",checked:I,type:"checkbox",onChange:function(e){p(!1),w(e.target.checked)}})," ",u&&u.search?u.search.wholeWords:"Whole words"),r.createElement("div",{className:"rpv-search__popover-footer"},r.createElement("div",{className:"rpv-search__popover-footer-item"},r.createElement(e.Tooltip,{ariaControlsSuffix:"search-previous-match",position:g?e.Position.BottomRight:e.Position.BottomCenter,target:r.createElement(e.MinimalButton,{ariaLabel:L,isDisabled:b<=1,onClick:k},r.createElement(o,null)),content:function(){return L},offset:E})),r.createElement("div",{className:"rpv-search__popover-footer-item"},r.createElement(e.Tooltip,{ariaControlsSuffix:"search-next-match",position:e.Position.BottomCenter,target:r.createElement(e.MinimalButton,{ariaLabel:j,isDisabled:b>C-1,onClick:S},r.createElement(n,null)),content:function(){return j},offset:E})),r.createElement("div",{className:e.classNames({"rpv-search__popover-footer-button":!0,"rpv-search__popover-footer-button--ltr":!g,"rpv-search__popover-footer-button--rtl":g})},r.createElement(e.Button,{onClick:function(){c(),x()}},u&&u.search?u.search.close:"Close"))))},w=function(t){var n=t.children,o=t.onClick,c=r.useContext(e.LocalizationContext).l10n,u=c&&c.search?c.search.search:"Search";return n({icon:r.createElement(a,null),label:u,onClick:o})},b={left:0,top:8},S=function(t){var n=t.enableShortcuts,o=t.store,a=t.onClick,c=n?e.isMac()?"Meta+F":"Ctrl+F":"",u=function(e){e&&a()};return r.useEffect((function(){return o.subscribe("areShortcutsPressed",u),function(){o.unsubscribe("areShortcutsPressed",u)}}),[]),r.createElement(w,{onClick:a},(function(t){return r.createElement(e.Tooltip,{ariaControlsSuffix:"search-popover",position:e.Position.BottomCenter,target:r.createElement(e.MinimalButton,{ariaKeyShortcuts:c,ariaLabel:t.label,testId:"search__popover-button",onClick:a},t.icon),content:function(){return t.label},offset:b})}))},k={left:0,top:8},P=function(t){var n=t.children,o=t.enableShortcuts,a=t.store,u=r.useContext(e.ThemeContext).direction===e.TextDirection.RightToLeft?e.Position.BottomRight:e.Position.BottomLeft,s=n||function(e){return r.createElement(S,c({enableShortcuts:o,store:a},e))};return r.createElement(e.Popover,{ariaControlsSuffix:"search",lockScroll:!1,position:u,target:function(e){return s({onClick:e})},content:function(e){return r.createElement(y,{store:a,onToggle:e})},offset:k,closeOnClickOutside:!1,closeOnEscape:!0})},_=function(e){return Array.isArray(e)?e.map((function(e){return g(e)})):[g(e)]};exports.NextIcon=n,exports.PreviousIcon=o,exports.SearchIcon=a,exports.searchPlugin=function(t){var n=r.useMemo((function(){return Object.assign({},{enableShortcuts:!0,onHighlightKeyword:function(){}},t)}),[]),o=r.useMemo((function(){return e.createStore({matchPosition:{matchIndex:-1,pageIndex:-1},renderStatus:new Map,keyword:t&&t.keyword?_(t.keyword):[u]})}),[]),a=m(o),s=a.clearKeyword,i=a.jumpToMatch,l=a.jumpToNextMatch,h=a.jumpToPreviousMatch,f=a.searchFor,p=a.setKeywords,g=a.setTargetPages,E=function(e){return r.createElement(P,c({enableShortcuts:n.enableShortcuts},e,{store:o}))};return{install:function(e){var r=t&&t.keyword?_(t.keyword):[u];o.update("jumpToDestination",e.jumpToDestination),o.update("jumpToPage",e.jumpToPage),o.update("keyword",r)},renderPageLayer:function(e){return r.createElement(d,{key:e.pageIndex,numPages:e.doc.numPages,pageIndex:e.pageIndex,renderHighlights:null==t?void 0:t.renderHighlights,store:o,onHighlightKeyword:n.onHighlightKeyword})},renderViewer:function(e){var t=e.slot;return t.subSlot&&(t.subSlot.children=r.createElement(r.Fragment,null,n.enableShortcuts&&r.createElement(x,{containerRef:e.containerRef,store:o}),t.subSlot.children)),t},uninstall:function(e){var t=o.get("renderStatus");t&&t.clear()},onDocumentLoad:function(e){o.update("doc",e.doc)},onTextLayerRender:function(e){var t=o.get("renderStatus");t&&(t=t.set(e.pageIndex,e),o.update("renderStatus",t))},Search:function(e){return r.createElement(v,c({},e,{store:o}))},ShowSearchPopover:E,ShowSearchPopoverButton:function(){return r.createElement(E,null,(function(e){return r.createElement(S,c({enableShortcuts:n.enableShortcuts,store:o},e))}))},clearHighlights:function(){s()},highlight:function(e){var t=Array.isArray(e)?e:[e];return p(t),f(t)},jumpToMatch:i,jumpToNextMatch:l,jumpToPreviousMatch:h,setTargetPages:g}};

@@ -93,2 +93,22 @@ /**

export interface HighlightArea {
keyword: RegExp;
keywordStr: string;
numPages: number;
pageIndex: number;
// The position of the highlight element
left: number;
top: number;
// The size of the highlight element
height: number;
width: number;
// The size of the page in pixels
pageHeight: number;
pageWidth: number;
}
export interface RenderHighlightsProps {
getCssProperties(area: HighlightArea): React.CSSProperties;
highlightAreas: HighlightArea[];
}
export interface SearchPluginProps {

@@ -98,2 +118,3 @@ enableShortcuts?: boolean;

keyword?: SingleKeyword | SingleKeyword[];
renderHighlights?(props: RenderHighlightsProps): React.ReactElement;
onHighlightKeyword?(props: OnHighlightKeyword): void;

@@ -100,0 +121,0 @@ }

{
"name": "@react-pdf-viewer/search",
"version": "3.4.0",
"version": "3.5.0",
"description": "A React component to view a PDF document",

@@ -36,3 +36,3 @@ "license": "https://react-pdf-viewer.dev/license",

"dependencies": {
"@react-pdf-viewer/core": "3.4.0"
"@react-pdf-viewer/core": "3.5.0"
},

@@ -53,3 +53,3 @@ "peerDependencies": {

},
"gitHead": "f815ceb86a9737f0474f860233117868683ce123"
"gitHead": "ef310dae187c20927b4856de77ac6a32226d802b"
}

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc