@huridocs/react-text-selection-handler 0.3.1 → 0.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export { Highlight } from './Highlight';
2
2
  export { HandleTextSelection } from './HandleTextSelection';
3
3
  export { SelectionRegion } from './SelectionRegion';
4
+ export type { TextSelection, SelectionRectangle } from './TextSelection';
4
5
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,YAAY,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC"}
package/package.json CHANGED
@@ -1,7 +1,11 @@
1
1
  {
2
2
  "name": "@huridocs/react-text-selection-handler",
3
- "version": "0.3.1",
3
+ "version": "0.3.2",
4
+ "type": "module",
4
5
  "main": "./dist/index.js",
6
+ "exports": {
7
+ ".": "./dist/index.js"
8
+ },
5
9
  "description": "React pdf handler allows to render a PDF and handle text selection and highlights.",
6
10
  "author": "HURIDOCS",
7
11
  "license": "Apache-2.0",
@@ -20,7 +24,7 @@
20
24
  "prepublish": "yarn build",
21
25
  "before_publish": "yarn eslint && yarn check-types && yarn test",
22
26
  "publish_to_npm": "np --access=public --testScript before_publish",
23
- "build-test-app": "webpack --config ./e2e/webpack.config.js",
27
+ "build-test-app": "webpack --config ./e2e/webpack.config.cjs",
24
28
  "test": "yarn build && yarn build-test-app && jest --projects e2e/jest.e2e.config.ts",
25
29
  "build": "tsc --build tsconfig.build.json",
26
30
  "eslint": "./node_modules/.bin/eslint e2e src --quiet --ext ts,tsx",
package/src/index.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  export { Highlight } from './Highlight';
2
2
  export { HandleTextSelection } from './HandleTextSelection';
3
3
  export { SelectionRegion } from './SelectionRegion';
4
+ export type { TextSelection, SelectionRectangle } from './TextSelection';
@@ -1,3 +0,0 @@
1
- export declare const normalizeSpaces: (text: string) => string;
2
- export declare const getRangeSelectedText: (range: Range, containerElement: HTMLElement) => string;
3
- //# sourceMappingURL=getRangeSelectedText.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"getRangeSelectedText.d.ts","sourceRoot":"","sources":["../src/getRangeSelectedText.ts"],"names":[],"mappings":"AAkBA,eAAO,MAAM,eAAe,SAAU,MAAM,WAyB3C,CAAC;AAEF,eAAO,MAAM,oBAAoB,UAAW,KAAK,oBAAoB,WAAW,KAAG,MAmBlF,CAAC"}
@@ -1,52 +0,0 @@
1
- const getLeafNodes = (node) => {
2
- if (node.nodeType === Node.TEXT_NODE) {
3
- return [node];
4
- }
5
- if (node.nodeType === Node.ELEMENT_NODE) {
6
- const element = node;
7
- if (element.tagName === 'BR') {
8
- return [node];
9
- }
10
- }
11
- return Array.from(node.childNodes).reduce((acc, child) => acc.concat(getLeafNodes(child)), []);
12
- };
13
- const escapeRegExp = (str) => str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
14
- export const normalizeSpaces = (text) => {
15
- const pairedCharacters = {
16
- '(': ')',
17
- '[': ']',
18
- '{': '}',
19
- '"': '"',
20
- "'": "'",
21
- };
22
- let result = text;
23
- Object.entries(pairedCharacters).forEach(([openChar, closeChar]) => {
24
- const escapedOpen = escapeRegExp(openChar);
25
- const escapedClose = escapeRegExp(closeChar);
26
- const pattern = new RegExp(`${escapedOpen}\\s*(.*?)\\s*${escapedClose}`, 'g');
27
- result = result.replace(pattern, `${openChar}$1${closeChar}`);
28
- });
29
- const spaceAfterChars = escapeRegExp('$£€@#');
30
- const spaceBeforeChars = escapeRegExp(',.!?:;');
31
- result = result.replace(new RegExp(`([${spaceAfterChars}])\\s+`, 'g'), '$1');
32
- result = result.replace(new RegExp(`\\s+([${spaceBeforeChars}])`, 'g'), '$1');
33
- return result;
34
- };
35
- export const getRangeSelectedText = (range, containerElement) => {
36
- const rangeContent = range.cloneContents();
37
- const elements = getLeafNodes(rangeContent)
38
- .filter(node => containerElement.contains(range.commonAncestorContainer.contains(node) ? node : range.commonAncestorContainer))
39
- .map((node) => {
40
- var _a, _b;
41
- if (node.nodeType === Node.ELEMENT_NODE) {
42
- const element = node;
43
- if (element.tagName === 'BR')
44
- return '\n';
45
- return ((_a = element.textContent) === null || _a === void 0 ? void 0 : _a.trim()) || '';
46
- }
47
- return ((_b = node.textContent) === null || _b === void 0 ? void 0 : _b.trim()) || '';
48
- })
49
- .filter(Boolean);
50
- return normalizeSpaces(elements.join(' '));
51
- };
52
- //# sourceMappingURL=getRangeSelectedText.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"getRangeSelectedText.js","sourceRoot":"","sources":["../src/getRangeSelectedText.ts"],"names":[],"mappings":"AAAA,MAAM,YAAY,GAAG,CAAC,IAAU,EAAU,EAAE;IAC1C,IAAI,IAAI,CAAC,QAAQ,KAAK,IAAI,CAAC,SAAS,EAAE,CAAC;QACrC,OAAO,CAAC,IAAI,CAAC,CAAC;IAChB,CAAC;IACD,IAAI,IAAI,CAAC,QAAQ,KAAK,IAAI,CAAC,YAAY,EAAE,CAAC;QACxC,MAAM,OAAO,GAAG,IAAe,CAAC;QAChC,IAAI,OAAO,CAAC,OAAO,KAAK,IAAI,EAAE,CAAC;YAC7B,OAAO,CAAC,IAAI,CAAC,CAAC;QAChB,CAAC;IACH,CAAC;IACD,OAAO,K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