update
This commit is contained in:
@@ -0,0 +1 @@
|
||||
module.exports={A:{A:{"388":"K D E F A B mC"},B:{"1":"0 9 Z a b c d e f g h i j k l m n o p q r s t u v w x y z AB BB CB DB EB FB GB HB IB JB KB LB MB NB OB I","260":"Q H R S T U V W X Y","388":"C L M G N O P"},C:{"1":"0 9 R OC S T U V W X Y Z a b c d e f g h i j k l m n o p q r s t u v w x y z AB BB CB DB EB FB GB HB IB JB KB LB MB NB OB I PC EC QC RC oC pC","260":"NC xB yB zB 0B 1B 2B 3B 4B 5B 6B 7B 8B 9B AC BC CC DC Q H","388":"1 2 3 4 5 6 7 8 nC LC J PB K D E F A B C L M G N O P QB RB SB TB UB VB WB XB YB ZB aB bB cB dB eB fB gB hB iB jB kB lB mB nB oB pB qB rB sB tB uB vB MC wB qC rC"},D:{"1":"0 9 Z a b c d e f g h i j k l m n o p q r s t u v w x y z AB BB CB DB EB FB GB HB IB JB KB LB MB NB OB I PC EC QC RC","260":"3B 4B 5B 6B 7B 8B 9B AC BC CC DC Q H R S T U V W X Y","388":"1 2 3 4 5 6 7 8 J PB K D E F A B C L M G N O P QB RB SB TB UB VB WB XB YB ZB aB bB cB dB eB fB gB hB iB jB kB lB mB nB oB pB qB rB sB tB uB vB MC wB NC xB yB zB 0B 1B 2B"},E:{"1":"IC WC XC YC ZC aC 1C JC bC cC dC eC fC 2C KC gC hC iC jC 3C","260":"M G xC yC zC UC VC HC 0C","388":"J PB K D E F A B C L sC SC tC uC vC wC TC FC GC"},F:{"1":"0 BC CC DC Q H R OC S T U V W X Y Z a b c d e f g h i j k l m n o p q r s t u v w x y z","260":"sB tB uB vB wB xB yB zB 0B 1B 2B 3B 4B 5B 6B 7B 8B 9B AC","388":"1 2 3 4 5 6 7 8 F B C G N O P QB RB SB TB UB VB WB XB YB ZB aB bB cB dB eB fB gB hB iB jB kB lB mB nB oB pB qB rB 4C 5C 6C 7C FC kC 8C GC"},G:{"1":"IC WC XC YC ZC aC UD JC bC cC dC eC fC VD KC gC hC iC jC","260":"PD QD RD SD UC VC HC TD","388":"E SC 9C lC AD BD CD DD ED FD GD HD ID JD KD LD MD ND OD"},H:{"388":"WD"},I:{"1":"I","388":"LC J XD YD ZD aD lC bD cD"},J:{"388":"D A"},K:{"1":"H","388":"A B C FC kC GC"},L:{"1":"I"},M:{"1":"EC"},N:{"388":"A B"},O:{"388":"HC"},P:{"1":"1 2 3 4 5 6 7 8 mD IC JC KC nD","388":"J dD eD fD gD hD TC iD jD kD lD"},Q:{"388":"oD"},R:{"1":"pD"},S:{"1":"rD","388":"qD"}},B:5,C:"CSS overflow property",D:true};
|
||||
@@ -0,0 +1,8 @@
|
||||
import { TraceMap } from './trace-mapping';
|
||||
import type { SectionedSourceMapInput } from './types';
|
||||
type AnyMap = {
|
||||
new (map: SectionedSourceMapInput, mapUrl?: string | null): TraceMap;
|
||||
(map: SectionedSourceMapInput, mapUrl?: string | null): TraceMap;
|
||||
};
|
||||
export declare const AnyMap: AnyMap;
|
||||
export {};
|
||||
Binary file not shown.
@@ -0,0 +1 @@
|
||||
module.exports={C:{"52":0.01484,"68":0.00495,"78":0.00989,"82":0.00495,"83":0.00989,"88":0.02967,"108":0.00495,"113":0.00989,"114":0.00989,"115":0.18297,"120":0.00495,"121":0.01978,"125":0.03956,"127":0.00495,"128":0.06429,"129":0.00495,"130":0.00989,"131":0.00495,"133":0.01484,"134":0.03462,"135":0.2967,"136":1.23625,_:"2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 69 70 71 72 73 74 75 76 77 79 80 81 84 85 86 87 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 109 110 111 112 116 117 118 119 122 123 124 126 132 137 138 139 140 3.5 3.6"},D:{"38":0.00495,"39":0.00495,"40":0.00495,"41":0.00495,"42":0.00495,"43":0.00989,"44":0.00495,"45":0.00495,"46":0.00495,"47":0.00989,"48":0.00495,"49":0.01978,"50":0.00495,"51":0.00495,"52":0.00495,"53":0.00495,"54":0.00495,"55":0.00989,"56":0.00495,"57":0.00495,"58":0.00989,"59":0.00495,"60":0.00495,"63":0.00495,"65":0.00989,"66":0.00495,"70":0.00495,"72":0.00495,"73":0.00989,"74":0.00495,"75":0.00989,"79":0.01484,"80":0.01978,"81":0.01484,"83":0.00495,"85":0.00495,"86":0.06429,"87":0.01484,"88":0.00989,"90":0.00989,"91":0.00495,"93":0.00989,"94":0.02473,"95":0.00495,"98":0.00495,"99":0.0544,"102":0.00495,"103":0.02967,"104":0.00495,"105":0.01484,"106":0.01484,"107":0.00989,"108":0.02473,"109":1.31043,"110":0.02967,"112":0.01978,"113":0.00495,"114":0.01978,"116":0.04451,"117":0.00495,"118":0.00495,"119":0.02473,"120":0.01484,"121":0.00989,"122":0.04945,"123":0.02967,"124":0.10385,"125":0.22747,"126":0.09396,"127":0.05934,"128":0.06923,"129":0.04945,"130":0.08407,"131":0.41538,"132":0.43022,"133":9.67737,"134":22.33162,"135":0.01484,_:"4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 61 62 64 67 68 69 71 76 77 78 84 89 92 96 97 100 101 111 115 136 137 138"},F:{"69":0.00989,"87":0.00989,"95":0.01484,"99":0.00495,"114":0.00495,"116":1.08296,"117":2.63074,_:"9 11 12 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 60 62 63 64 65 66 67 68 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 88 89 90 91 92 93 94 96 97 98 100 101 102 103 104 105 106 107 108 109 110 111 112 113 115 9.5-9.6 10.0-10.1 10.5 10.6 11.1 11.5 11.6 12.1"},B:{"18":0.00495,"83":0.00495,"92":0.01978,"105":0.00495,"108":0.00495,"109":0.00989,"114":0.00495,"122":0.00495,"125":0.00495,"126":0.01484,"129":0.00495,"130":0.0544,"131":0.02967,"132":0.07418,"133":1.10768,"134":2.98678,_:"12 13 14 15 16 17 79 80 81 84 85 86 87 88 89 90 91 93 94 95 96 97 98 99 100 101 102 103 104 106 107 110 111 112 113 115 116 117 118 119 120 121 123 124 127 128"},E:{"14":0.01484,_:"0 4 5 6 7 8 9 10 11 12 13 15 3.1 3.2 5.1 6.1 7.1 9.1 10.1 11.1 15.2-15.3 15.4","12.1":0.00495,"13.1":0.01978,"14.1":0.02967,"15.1":0.02473,"15.5":0.00495,"15.6":0.04451,"16.0":0.00495,"16.1":0.01484,"16.2":0.00495,"16.3":0.00989,"16.4":0.00989,"16.5":0.02473,"16.6":0.06429,"17.0":0.02967,"17.1":0.01978,"17.2":0.00495,"17.3":0.00989,"17.4":0.00989,"17.5":0.04945,"17.6":0.11374,"18.0":0.04451,"18.1":0.10385,"18.2":0.0544,"18.3":0.62802,"18.4":0.00989},G:{"8":0,"3.2":0,"4.0-4.1":0,"4.2-4.3":0.00219,"5.0-5.1":0,"6.0-6.1":0.00658,"7.0-7.1":0.00439,"8.1-8.4":0,"9.0-9.2":0.00329,"9.3":0.01536,"10.0-10.2":0.0011,"10.3":0.02524,"11.0-11.2":0.11633,"11.3-11.4":0.00768,"12.0-12.1":0.00439,"12.2-12.5":0.10865,"13.0-13.1":0.00219,"13.2":0.00329,"13.3":0.00439,"13.4-13.7":0.01536,"14.0-14.4":0.03841,"14.5-14.8":0.04609,"15.0-15.1":0.02524,"15.2-15.3":0.02524,"15.4":0.03073,"15.5":0.03512,"15.6-15.8":0.43239,"16.0":0.06146,"16.1":0.12621,"16.2":0.06585,"16.3":0.11413,"16.4":0.02524,"16.5":0.04719,"16.6-16.7":0.5125,"17.0":0.03073,"17.1":0.05487,"17.2":0.0417,"17.3":0.05816,"17.4":0.11633,"17.5":0.259,"17.6-17.7":0.75175,"18.0":0.21071,"18.1":0.68919,"18.2":0.30838,"18.3":6.44527,"18.4":0.09548},P:{"4":0.03098,"21":0.13425,"22":0.02065,"23":0.02065,"24":0.04131,"25":0.04131,"26":0.03098,"27":1.28056,_:"20 5.0-5.4 6.2-6.4 8.2 9.2 10.1 11.1-11.2 12.0 13.0 14.0 15.0 16.0 17.0 19.0","7.2-7.4":0.05164,"18.0":0.03098},I:{"0":0.01513,"3":0,"4":0,"2.1":0,"2.2":0,"2.3":0,"4.1":0,"4.2-4.3":0,"4.4":0,"4.4.3-4.4.4":0.00002},K:{"0":0.13143,_:"10 11 12 11.1 11.5 12.1"},A:{_:"6 7 8 9 10 11 5.5"},S:{_:"2.5 3.0-3.1"},J:{_:"7 10"},N:{_:"10 11"},R:{_:"0"},M:{"0":0.22748},Q:{_:"14.9"},O:{"0":0.00506},H:{"0":0},L:{"0":38.73511}};
|
||||
@@ -0,0 +1 @@
|
||||
module.exports={C:{"111":0.00475,"113":0.00475,"115":0.06175,"116":0.07125,"122":0.00475,"124":0.00475,"125":0.00475,"128":0.0095,"132":0.00475,"133":0.0095,"134":0.01425,"135":0.36575,"136":0.82175,_:"2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 112 114 117 118 119 120 121 123 126 127 129 130 131 137 138 139 140 3.5 3.6"},D:{"39":0.00475,"49":0.00475,"58":0.00475,"70":0.00475,"76":0.00475,"79":0.0095,"86":0.00475,"87":0.0095,"88":0.00475,"91":0.00475,"93":0.00475,"96":0.00475,"98":0.00475,"99":0.00475,"103":0.0665,"106":0.00475,"107":0.04275,"108":0.00475,"109":0.6555,"110":0.00475,"111":0.0095,"114":0.00475,"115":0.03325,"116":0.114,"117":0.057,"118":0.03325,"119":0.0285,"120":0.0665,"121":0.01425,"122":0.28025,"123":0.969,"124":0.33725,"125":0.0095,"126":0.07125,"127":0.01425,"128":0.133,"129":0.209,"130":0.07125,"131":0.54625,"132":0.475,"133":10.26,"134":18.52975,"135":0.04275,_:"4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 40 41 42 43 44 45 46 47 48 50 51 52 53 54 55 56 57 59 60 61 62 63 64 65 66 67 68 69 71 72 73 74 75 77 78 80 81 83 84 85 89 90 92 94 95 97 100 101 102 104 105 112 113 136 137 138"},F:{"28":0.00475,"87":0.019,"88":0.00475,"95":0.00475,"102":0.01425,"111":0.019,"115":0.00475,"116":0.28025,"117":0.779,_:"9 11 12 15 16 17 18 19 20 21 22 23 24 25 26 27 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 60 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 89 90 91 92 93 94 96 97 98 99 100 101 103 104 105 106 107 108 109 110 112 113 114 9.5-9.6 10.0-10.1 10.5 10.6 11.1 11.5 11.6 12.1"},B:{"92":0.00475,"109":0.01425,"112":0.114,"114":0.00475,"115":0.00475,"117":0.00475,"120":0.00475,"122":0.00475,"126":0.0095,"127":0.0475,"129":0.01425,"130":0.01425,"131":0.0855,"132":0.11875,"133":1.95225,"134":4.37,_:"12 13 14 15 16 17 18 79 80 81 83 84 85 86 87 88 89 90 91 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 110 111 113 116 118 119 121 123 124 125 128"},E:{"14":0.00475,_:"0 4 5 6 7 8 9 10 11 12 13 15 3.1 3.2 5.1 6.1 7.1 9.1 10.1 11.1","12.1":0.06175,"13.1":0.0095,"14.1":0.0285,"15.1":0.0095,"15.2-15.3":0.01425,"15.4":0.00475,"15.5":0.00475,"15.6":0.16625,"16.0":0.038,"16.1":0.0095,"16.2":0.0095,"16.3":0.1235,"16.4":0.01425,"16.5":0.0285,"16.6":0.1995,"17.0":0.038,"17.1":0.18525,"17.2":0.02375,"17.3":0.09975,"17.4":0.076,"17.5":0.16625,"17.6":0.22325,"18.0":0.05225,"18.1":0.171,"18.2":0.0855,"18.3":1.7955,"18.4":0.09025},G:{"8":0,"3.2":0,"4.0-4.1":0,"4.2-4.3":0.00353,"5.0-5.1":0,"6.0-6.1":0.01058,"7.0-7.1":0.00706,"8.1-8.4":0,"9.0-9.2":0.00529,"9.3":0.0247,"10.0-10.2":0.00176,"10.3":0.04057,"11.0-11.2":0.18698,"11.3-11.4":0.01235,"12.0-12.1":0.00706,"12.2-12.5":0.17464,"13.0-13.1":0.00353,"13.2":0.00529,"13.3":0.00706,"13.4-13.7":0.0247,"14.0-14.4":0.06174,"14.5-14.8":0.07409,"15.0-15.1":0.04057,"15.2-15.3":0.04057,"15.4":0.04939,"15.5":0.05645,"15.6-15.8":0.69502,"16.0":0.09878,"16.1":0.20286,"16.2":0.10584,"16.3":0.18346,"16.4":0.04057,"16.5":0.07585,"16.6-16.7":0.82379,"17.0":0.04939,"17.1":0.0882,"17.2":0.06703,"17.3":0.09349,"17.4":0.18698,"17.5":0.4163,"17.6-17.7":1.20834,"18.0":0.33869,"18.1":1.10779,"18.2":0.49568,"18.3":10.35997,"18.4":0.15347},P:{"4":0.02092,"21":0.01046,"23":0.02092,"24":0.02092,"25":0.02092,"26":0.07322,"27":2.52073,_:"20 22 5.0-5.4 6.2-6.4 8.2 9.2 10.1 11.1-11.2 12.0 13.0 14.0 15.0 16.0 17.0 18.0 19.0","7.2-7.4":0.02092},I:{"0":0.09954,"3":0,"4":0,"2.1":0,"2.2":0,"2.3":0,"4.1":0,"4.2-4.3":0.00003,"4.4":0,"4.4.3-4.4.4":0.00011},K:{"0":0.21575,_:"10 11 12 11.1 11.5 12.1"},A:{_:"6 7 8 9 10 11 5.5"},S:{_:"2.5 3.0-3.1"},J:{_:"7 10"},N:{_:"10 11"},R:{_:"0"},M:{"0":0.2205},Q:{_:"14.9"},O:{"0":0.1155},H:{"0":0.01},L:{"0":31.55625}};
|
||||
@@ -0,0 +1,59 @@
|
||||
var test = require('tape');
|
||||
var stringify = require('../');
|
||||
|
||||
test('space parameter', function (t) {
|
||||
t.plan(1);
|
||||
var obj = { one: 1, two: 2 };
|
||||
t.equal(stringify(obj, {space: ' '}), ''
|
||||
+ '{\n'
|
||||
+ ' "one": 1,\n'
|
||||
+ ' "two": 2\n'
|
||||
+ '}'
|
||||
);
|
||||
});
|
||||
|
||||
test('space parameter (with tabs)', function (t) {
|
||||
t.plan(1);
|
||||
var obj = { one: 1, two: 2 };
|
||||
t.equal(stringify(obj, {space: '\t'}), ''
|
||||
+ '{\n'
|
||||
+ '\t"one": 1,\n'
|
||||
+ '\t"two": 2\n'
|
||||
+ '}'
|
||||
);
|
||||
});
|
||||
|
||||
test('space parameter (with a number)', function (t) {
|
||||
t.plan(1);
|
||||
var obj = { one: 1, two: 2 };
|
||||
t.equal(stringify(obj, {space: 3}), ''
|
||||
+ '{\n'
|
||||
+ ' "one": 1,\n'
|
||||
+ ' "two": 2\n'
|
||||
+ '}'
|
||||
);
|
||||
});
|
||||
|
||||
test('space parameter (nested objects)', function (t) {
|
||||
t.plan(1);
|
||||
var obj = { one: 1, two: { b: 4, a: [2,3] } };
|
||||
t.equal(stringify(obj, {space: ' '}), ''
|
||||
+ '{\n'
|
||||
+ ' "one": 1,\n'
|
||||
+ ' "two": {\n'
|
||||
+ ' "a": [\n'
|
||||
+ ' 2,\n'
|
||||
+ ' 3\n'
|
||||
+ ' ],\n'
|
||||
+ ' "b": 4\n'
|
||||
+ ' }\n'
|
||||
+ '}'
|
||||
);
|
||||
});
|
||||
|
||||
test('space parameter (same as native)', function (t) {
|
||||
t.plan(1);
|
||||
// for this test, properties need to be in alphabetical order
|
||||
var obj = { one: 1, two: { a: [2,3], b: 4 } };
|
||||
t.equal(stringify(obj, {space: ' '}), JSON.stringify(obj, null, ' '));
|
||||
});
|
||||
@@ -0,0 +1,55 @@
|
||||
/**
|
||||
* @fileoverview Serialization utils.
|
||||
* @author Bryan Mishkin
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
/**
|
||||
* Check if a value is a primitive or plain object created by the Object constructor.
|
||||
* @param {any} val the value to check
|
||||
* @returns {boolean} true if so
|
||||
* @private
|
||||
*/
|
||||
function isSerializablePrimitiveOrPlainObject(val) {
|
||||
return (
|
||||
val === null ||
|
||||
typeof val === "string" ||
|
||||
typeof val === "boolean" ||
|
||||
typeof val === "number" ||
|
||||
(typeof val === "object" && val.constructor === Object) ||
|
||||
Array.isArray(val)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a value is serializable.
|
||||
* Functions or objects like RegExp cannot be serialized by JSON.stringify().
|
||||
* Inspired by: https://stackoverflow.com/questions/30579940/reliable-way-to-check-if-objects-is-serializable-in-javascript
|
||||
* @param {any} val the value
|
||||
* @returns {boolean} true if the value is serializable
|
||||
*/
|
||||
function isSerializable(val) {
|
||||
if (!isSerializablePrimitiveOrPlainObject(val)) {
|
||||
return false;
|
||||
}
|
||||
if (typeof val === "object") {
|
||||
for (const property in val) {
|
||||
if (Object.hasOwn(val, property)) {
|
||||
if (!isSerializablePrimitiveOrPlainObject(val[property])) {
|
||||
return false;
|
||||
}
|
||||
if (typeof val[property] === "object") {
|
||||
if (!isSerializable(val[property])) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
isSerializable,
|
||||
};
|
||||
@@ -0,0 +1,38 @@
|
||||
/**
|
||||
* @fileoverview Handle logging for ESLint
|
||||
* @author Gyandeep Singh
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
/* eslint no-console: "off" -- Logging util */
|
||||
|
||||
/* c8 ignore next */
|
||||
module.exports = {
|
||||
/**
|
||||
* Cover for console.info
|
||||
* @param {...any} args The elements to log.
|
||||
* @returns {void}
|
||||
*/
|
||||
info(...args) {
|
||||
console.log(...args);
|
||||
},
|
||||
|
||||
/**
|
||||
* Cover for console.warn
|
||||
* @param {...any} args The elements to log.
|
||||
* @returns {void}
|
||||
*/
|
||||
warn(...args) {
|
||||
console.warn(...args);
|
||||
},
|
||||
|
||||
/**
|
||||
* Cover for console.error
|
||||
* @param {...any} args The elements to log.
|
||||
* @returns {void}
|
||||
*/
|
||||
error(...args) {
|
||||
console.error(...args);
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,33 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.UPDATE_OPERATORS = exports.UNARY_OPERATORS = exports.STRING_UNARY_OPERATORS = exports.STATEMENT_OR_BLOCK_KEYS = exports.NUMBER_UNARY_OPERATORS = exports.NUMBER_BINARY_OPERATORS = exports.LOGICAL_OPERATORS = exports.INHERIT_KEYS = exports.FOR_INIT_KEYS = exports.FLATTENABLE_KEYS = exports.EQUALITY_BINARY_OPERATORS = exports.COMPARISON_BINARY_OPERATORS = exports.COMMENT_KEYS = exports.BOOLEAN_UNARY_OPERATORS = exports.BOOLEAN_NUMBER_BINARY_OPERATORS = exports.BOOLEAN_BINARY_OPERATORS = exports.BINARY_OPERATORS = exports.ASSIGNMENT_OPERATORS = void 0;
|
||||
const STATEMENT_OR_BLOCK_KEYS = exports.STATEMENT_OR_BLOCK_KEYS = ["consequent", "body", "alternate"];
|
||||
const FLATTENABLE_KEYS = exports.FLATTENABLE_KEYS = ["body", "expressions"];
|
||||
const FOR_INIT_KEYS = exports.FOR_INIT_KEYS = ["left", "init"];
|
||||
const COMMENT_KEYS = exports.COMMENT_KEYS = ["leadingComments", "trailingComments", "innerComments"];
|
||||
const LOGICAL_OPERATORS = exports.LOGICAL_OPERATORS = ["||", "&&", "??"];
|
||||
const UPDATE_OPERATORS = exports.UPDATE_OPERATORS = ["++", "--"];
|
||||
const BOOLEAN_NUMBER_BINARY_OPERATORS = exports.BOOLEAN_NUMBER_BINARY_OPERATORS = [">", "<", ">=", "<="];
|
||||
const EQUALITY_BINARY_OPERATORS = exports.EQUALITY_BINARY_OPERATORS = ["==", "===", "!=", "!=="];
|
||||
const COMPARISON_BINARY_OPERATORS = exports.COMPARISON_BINARY_OPERATORS = [...EQUALITY_BINARY_OPERATORS, "in", "instanceof"];
|
||||
const BOOLEAN_BINARY_OPERATORS = exports.BOOLEAN_BINARY_OPERATORS = [...COMPARISON_BINARY_OPERATORS, ...BOOLEAN_NUMBER_BINARY_OPERATORS];
|
||||
const NUMBER_BINARY_OPERATORS = exports.NUMBER_BINARY_OPERATORS = ["-", "/", "%", "*", "**", "&", "|", ">>", ">>>", "<<", "^"];
|
||||
const BINARY_OPERATORS = exports.BINARY_OPERATORS = ["+", ...NUMBER_BINARY_OPERATORS, ...BOOLEAN_BINARY_OPERATORS, "|>"];
|
||||
const ASSIGNMENT_OPERATORS = exports.ASSIGNMENT_OPERATORS = ["=", "+=", ...NUMBER_BINARY_OPERATORS.map(op => op + "="), ...LOGICAL_OPERATORS.map(op => op + "=")];
|
||||
const BOOLEAN_UNARY_OPERATORS = exports.BOOLEAN_UNARY_OPERATORS = ["delete", "!"];
|
||||
const NUMBER_UNARY_OPERATORS = exports.NUMBER_UNARY_OPERATORS = ["+", "-", "~"];
|
||||
const STRING_UNARY_OPERATORS = exports.STRING_UNARY_OPERATORS = ["typeof"];
|
||||
const UNARY_OPERATORS = exports.UNARY_OPERATORS = ["void", "throw", ...BOOLEAN_UNARY_OPERATORS, ...NUMBER_UNARY_OPERATORS, ...STRING_UNARY_OPERATORS];
|
||||
const INHERIT_KEYS = exports.INHERIT_KEYS = {
|
||||
optional: ["typeAnnotation", "typeParameters", "returnType"],
|
||||
force: ["start", "loc", "end"]
|
||||
};
|
||||
{
|
||||
exports.BLOCK_SCOPED_SYMBOL = Symbol.for("var used to be block scoped");
|
||||
exports.NOT_LOCAL_BINDING = Symbol.for("should not be considered a local binding");
|
||||
}
|
||||
|
||||
//# sourceMappingURL=index.js.map
|
||||
@@ -0,0 +1,92 @@
|
||||
import { ParserOptions } from "@babel/parser";
|
||||
import { Expression, Program, Statement } from "@babel/types";
|
||||
|
||||
export interface TemplateBuilderOptions extends ParserOptions {
|
||||
/**
|
||||
* A set of placeholder names to automatically accept.
|
||||
* Items in this list do not need to match `placeholderPattern`.
|
||||
*
|
||||
* This option cannot be used when using `%%foo%%` style placeholders.
|
||||
*/
|
||||
placeholderWhitelist?: Set<string> | null | undefined;
|
||||
|
||||
/**
|
||||
* A pattern to search for when looking for `Identifier` and `StringLiteral`
|
||||
* nodes that should be considered as placeholders.
|
||||
*
|
||||
* `false` will disable placeholder searching placeholders, leaving only
|
||||
* the `placeholderWhitelist` value to find replacements.
|
||||
*
|
||||
* This option cannot be used when using `%%foo%%` style placeholders.
|
||||
*
|
||||
* @default /^[_$A-Z0-9]+$/
|
||||
*/
|
||||
placeholderPattern?: RegExp | false | null | undefined;
|
||||
|
||||
/**
|
||||
* Set this to `true` to preserve comments from the template string
|
||||
* into the resulting AST, or `false` to automatically discard comments.
|
||||
*
|
||||
* @default false
|
||||
*/
|
||||
preserveComments?: boolean | null | undefined;
|
||||
|
||||
/**
|
||||
* Set to `true` to use `%%foo%%` style placeholders, `false` to use legacy placeholders
|
||||
* described by `placeholderPattern` or `placeholderWhitelist`.
|
||||
*
|
||||
* When it is not set, it behaves as `true` if there are syntactic placeholders, otherwise as `false`.
|
||||
*
|
||||
* @since 7.4.0
|
||||
*/
|
||||
syntacticPlaceholders?: boolean | null | undefined;
|
||||
}
|
||||
|
||||
export interface TemplateBuilder<T> {
|
||||
/**
|
||||
* Build a new builder, merging the given options with the previous ones.
|
||||
*/
|
||||
(opts: TemplateBuilderOptions): TemplateBuilder<T>;
|
||||
|
||||
/**
|
||||
* Building from a string produces an AST builder function by default.
|
||||
*/
|
||||
(code: string, opts?: TemplateBuilderOptions): (arg?: PublicReplacements) => T;
|
||||
|
||||
/**
|
||||
* Building from a template literal produces an AST builder function by default.
|
||||
*/
|
||||
(tpl: TemplateStringsArray, ...args: unknown[]): (arg?: PublicReplacements) => T;
|
||||
|
||||
/**
|
||||
* Allow users to explicitly create templates that produce ASTs,
|
||||
* skipping the need for an intermediate function.
|
||||
*
|
||||
* Does not allow `%%foo%%` style placeholders.
|
||||
*/
|
||||
ast: {
|
||||
(tpl: string, opts?: TemplateBuilderOptions): T;
|
||||
(tpl: TemplateStringsArray, ...args: unknown[]): T;
|
||||
};
|
||||
}
|
||||
|
||||
export type PublicReplacements = { [index: string]: unknown } | unknown[];
|
||||
|
||||
export const smart: TemplateBuilder<Statement | Statement[]>;
|
||||
export const statement: TemplateBuilder<Statement>;
|
||||
export const statements: TemplateBuilder<Statement[]>;
|
||||
export const expression: TemplateBuilder<Expression>;
|
||||
export const program: TemplateBuilder<Program>;
|
||||
|
||||
type DefaultTemplateBuilder = typeof smart & {
|
||||
smart: typeof smart;
|
||||
statement: typeof statement;
|
||||
statements: typeof statements;
|
||||
expression: typeof expression;
|
||||
program: typeof program;
|
||||
ast: typeof smart.ast;
|
||||
};
|
||||
|
||||
declare const templateBuilder: DefaultTemplateBuilder;
|
||||
|
||||
export default templateBuilder;
|
||||
@@ -0,0 +1,53 @@
|
||||
{
|
||||
"name": "supports-color",
|
||||
"version": "7.2.0",
|
||||
"description": "Detect whether a terminal supports color",
|
||||
"license": "MIT",
|
||||
"repository": "chalk/supports-color",
|
||||
"author": {
|
||||
"name": "Sindre Sorhus",
|
||||
"email": "sindresorhus@gmail.com",
|
||||
"url": "sindresorhus.com"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=8"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "xo && ava"
|
||||
},
|
||||
"files": [
|
||||
"index.js",
|
||||
"browser.js"
|
||||
],
|
||||
"keywords": [
|
||||
"color",
|
||||
"colour",
|
||||
"colors",
|
||||
"terminal",
|
||||
"console",
|
||||
"cli",
|
||||
"ansi",
|
||||
"styles",
|
||||
"tty",
|
||||
"rgb",
|
||||
"256",
|
||||
"shell",
|
||||
"xterm",
|
||||
"command-line",
|
||||
"support",
|
||||
"supports",
|
||||
"capability",
|
||||
"detect",
|
||||
"truecolor",
|
||||
"16m"
|
||||
],
|
||||
"dependencies": {
|
||||
"has-flag": "^4.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"ava": "^1.4.1",
|
||||
"import-fresh": "^3.0.0",
|
||||
"xo": "^0.24.0"
|
||||
},
|
||||
"browser": "browser.js"
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
module.exports={A:{A:{"2":"mC","4":"A B","8":"K D E F"},B:{"1":"0 9 N O P Q H R S T U V W X Y Z a b c d e f g h i j k l m n o p q r s t u v w x y z AB BB CB DB EB FB GB HB IB JB KB LB MB NB OB I","4":"C L M G"},C:{"4":"0 1 2 3 4 5 6 7 8 9 J PB K D E F A B C L M G N O P QB RB SB TB UB VB WB XB YB ZB aB bB cB dB eB fB gB hB iB jB kB lB mB nB oB pB qB rB sB tB uB vB MC wB NC xB yB zB 0B 1B 2B 3B 4B 5B 6B 7B 8B 9B AC BC CC DC Q H R OC S T U V W X Y Z a b c d e f g h i j k l m n o p q r s t u v w x y z AB BB CB DB EB FB GB HB IB JB KB LB MB NB OB I PC EC QC RC oC pC","8":"nC LC qC rC"},D:{"1":"0 9 NC xB yB zB 0B 1B 2B 3B 4B 5B 6B 7B 8B 9B AC BC CC DC Q H R S T U V W X Y Z a b c d e f g h i j k l m n o p q r s t u v w x y z AB BB CB DB EB FB GB HB IB JB KB LB MB NB OB I PC EC QC RC","4":"1 2 3 4 5 6 7 8 J PB K D E F A B C L M G N O P QB RB SB TB UB VB WB XB YB ZB aB bB cB dB eB fB gB hB iB jB kB lB mB nB oB pB qB rB sB tB uB vB MC wB"},E:{"4":"J PB K D E F A B C L M G tC uC vC wC TC FC GC xC yC zC UC VC HC 0C IC WC XC YC ZC aC 1C JC bC cC dC eC fC 2C KC gC hC iC jC 3C","8":"sC SC"},F:{"1":"0 F B C pB qB rB sB tB uB vB wB xB yB zB 0B 1B 2B 3B 4B 5B 6B 7B 8B 9B AC BC CC DC Q H R OC S T U V W X Y Z a b c d e f g h i j k l m n o p q r s t u v w x y z 4C 5C 6C 7C FC kC 8C GC","4":"1 2 3 4 5 6 7 8 G N O P QB RB SB TB UB VB WB XB YB ZB aB bB cB dB eB fB gB hB iB jB kB lB mB nB oB"},G:{"2":"SC","4":"E 9C lC AD BD CD DD ED FD GD HD ID JD KD LD MD ND OD PD QD RD SD UC VC HC TD IC WC XC YC ZC aC UD JC bC cC dC eC fC VD KC gC hC iC jC"},H:{"2":"WD"},I:{"1":"I","2":"LC J XD YD ZD aD lC","4":"bD cD"},J:{"2":"D","4":"A"},K:{"1":"A B C H FC kC GC"},L:{"1":"I"},M:{"4":"EC"},N:{"4":"A B"},O:{"1":"HC"},P:{"1":"1 2 3 4 5 6 7 8 gD hD TC iD jD kD lD mD IC JC KC nD","4":"J dD eD fD"},Q:{"1":"oD"},R:{"1":"pD"},S:{"4":"qD rD"}},B:1,C:"HTML5 form features",D:false};
|
||||
@@ -0,0 +1 @@
|
||||
module.exports={A:{A:{"1":"F A B","16":"mC","260":"K D E"},B:{"1":"0 9 C L M G N O P Q H R S T U V W X Y Z a b c d e f g h i j k l m n o p q r s t u v w x y z AB BB CB DB EB FB GB HB IB JB KB LB MB NB OB I"},C:{"1":"0 9 pB qB rB sB tB uB vB MC wB NC xB yB zB 0B 1B 2B 3B 4B 5B 6B 7B 8B 9B AC BC CC DC Q H R OC S T U V W X Y Z a b c d e f g h i j k l m n o p q r s t u v w x y z AB BB CB DB EB FB GB HB IB JB KB LB MB NB OB I PC EC QC RC oC pC","132":"1 2 3 4 5 6 7 8 nC LC J PB K D E F A B C L M G N O P QB RB SB TB UB VB WB XB YB ZB aB bB cB dB eB fB qC rC","2180":"gB hB iB jB kB lB mB nB oB"},D:{"1":"0 1 2 3 4 5 6 7 8 9 G N O P QB RB SB TB UB VB WB XB YB ZB aB bB cB dB eB fB gB hB iB jB kB lB mB nB oB pB qB rB sB tB uB vB MC wB NC xB yB zB 0B 1B 2B 3B 4B 5B 6B 7B 8B 9B AC BC CC DC Q H R S T U V W X Y Z a b c d e f g h i j k l m n o p q r s t u v w x y z AB BB CB DB EB FB GB HB IB JB KB LB MB NB OB I PC EC QC RC","16":"J PB K D E F A B C L M"},E:{"1":"K D E F A B C L M G tC uC vC wC TC FC GC xC yC zC UC VC HC 0C IC WC XC YC ZC aC 1C JC bC cC dC eC fC 2C KC gC hC iC jC 3C","16":"J PB sC SC"},F:{"1":"0 1 2 3 4 5 6 7 8 G N O P QB RB SB TB UB VB WB XB YB ZB aB bB cB dB eB fB gB hB iB jB kB lB mB nB oB pB qB rB sB tB uB vB wB xB yB zB 0B 1B 2B 3B 4B 5B 6B 7B 8B 9B AC BC CC DC Q H R OC S T U V W X Y Z a b c d e f g h i j k l m n o p q r s t u v w x y z","132":"F B C 4C 5C 6C 7C FC kC 8C GC"},G:{"16":"lC","132":"SC 9C","516":"E AD BD CD DD ED FD GD HD ID JD KD LD MD ND OD PD QD RD SD UC VC HC TD IC WC XC YC ZC aC UD JC bC cC dC eC fC VD KC gC hC iC jC"},H:{"2":"WD"},I:{"1":"I bD cD","16":"LC J XD YD ZD aD","1025":"lC"},J:{"1":"A","16":"D"},K:{"1":"H","16":"A B C FC kC","132":"GC"},L:{"1":"I"},M:{"1":"EC"},N:{"1":"B","16":"A"},O:{"1":"HC"},P:{"1":"1 2 3 4 5 6 7 8 J dD eD fD gD hD TC iD jD kD lD mD IC JC KC nD"},Q:{"1":"oD"},R:{"1":"pD"},S:{"1":"rD","2180":"qD"}},B:5,C:"Selection API",D:true};
|
||||
Binary file not shown.
@@ -0,0 +1,130 @@
|
||||
import * as React from 'react'
|
||||
import {
|
||||
getLocationChangeInfo,
|
||||
handleHashScroll,
|
||||
trimPathRight,
|
||||
} from '@tanstack/router-core'
|
||||
import { useLayoutEffect, usePrevious } from './utils'
|
||||
import { useRouter } from './useRouter'
|
||||
import { useRouterState } from './useRouterState'
|
||||
|
||||
export function Transitioner() {
|
||||
const router = useRouter()
|
||||
const mountLoadForRouter = React.useRef({ router, mounted: false })
|
||||
const isLoading = useRouterState({
|
||||
select: ({ isLoading }) => isLoading,
|
||||
})
|
||||
|
||||
const [isTransitioning, setIsTransitioning] = React.useState(false)
|
||||
// Track pending state changes
|
||||
const hasPendingMatches = useRouterState({
|
||||
select: (s) => s.matches.some((d) => d.status === 'pending'),
|
||||
structuralSharing: true,
|
||||
})
|
||||
|
||||
const previousIsLoading = usePrevious(isLoading)
|
||||
|
||||
const isAnyPending = isLoading || isTransitioning || hasPendingMatches
|
||||
const previousIsAnyPending = usePrevious(isAnyPending)
|
||||
|
||||
const isPagePending = isLoading || hasPendingMatches
|
||||
const previousIsPagePending = usePrevious(isPagePending)
|
||||
|
||||
if (!router.isServer) {
|
||||
router.startTransition = (fn: () => void) => {
|
||||
setIsTransitioning(true)
|
||||
React.startTransition(() => {
|
||||
fn()
|
||||
setIsTransitioning(false)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// Subscribe to location changes
|
||||
// and try to load the new location
|
||||
React.useEffect(() => {
|
||||
const unsub = router.history.subscribe(router.load)
|
||||
|
||||
const nextLocation = router.buildLocation({
|
||||
to: router.latestLocation.pathname,
|
||||
search: true,
|
||||
params: true,
|
||||
hash: true,
|
||||
state: true,
|
||||
_includeValidateSearch: true,
|
||||
})
|
||||
|
||||
if (
|
||||
trimPathRight(router.latestLocation.href) !==
|
||||
trimPathRight(nextLocation.href)
|
||||
) {
|
||||
router.commitLocation({ ...nextLocation, replace: true })
|
||||
}
|
||||
|
||||
return () => {
|
||||
unsub()
|
||||
}
|
||||
}, [router, router.history])
|
||||
|
||||
// Try to load the initial location
|
||||
useLayoutEffect(() => {
|
||||
if (
|
||||
(typeof window !== 'undefined' && router.clientSsr) ||
|
||||
(mountLoadForRouter.current.router === router &&
|
||||
mountLoadForRouter.current.mounted)
|
||||
) {
|
||||
return
|
||||
}
|
||||
mountLoadForRouter.current = { router, mounted: true }
|
||||
|
||||
const tryLoad = async () => {
|
||||
try {
|
||||
await router.load()
|
||||
} catch (err) {
|
||||
console.error(err)
|
||||
}
|
||||
}
|
||||
|
||||
tryLoad()
|
||||
}, [router])
|
||||
|
||||
useLayoutEffect(() => {
|
||||
// The router was loading and now it's not
|
||||
if (previousIsLoading && !isLoading) {
|
||||
router.emit({
|
||||
type: 'onLoad', // When the new URL has committed, when the new matches have been loaded into state.matches
|
||||
...getLocationChangeInfo(router.state),
|
||||
})
|
||||
}
|
||||
}, [previousIsLoading, router, isLoading])
|
||||
|
||||
useLayoutEffect(() => {
|
||||
// emit onBeforeRouteMount
|
||||
if (previousIsPagePending && !isPagePending) {
|
||||
router.emit({
|
||||
type: 'onBeforeRouteMount',
|
||||
...getLocationChangeInfo(router.state),
|
||||
})
|
||||
}
|
||||
}, [isPagePending, previousIsPagePending, router])
|
||||
|
||||
useLayoutEffect(() => {
|
||||
// The router was pending and now it's not
|
||||
if (previousIsAnyPending && !isAnyPending) {
|
||||
router.emit({
|
||||
type: 'onResolved',
|
||||
...getLocationChangeInfo(router.state),
|
||||
})
|
||||
|
||||
router.__store.setState((s) => ({
|
||||
...s,
|
||||
status: 'idle',
|
||||
resolvedLocation: s.location,
|
||||
}))
|
||||
|
||||
handleHashScroll(router)
|
||||
}
|
||||
}, [isAnyPending, previousIsAnyPending, router])
|
||||
|
||||
return null
|
||||
}
|
||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1,642 @@
|
||||
[](https://www.npmjs.com/package/react-pdf)  [](https://github.com/wojtekmaj/react-pdf/actions)
|
||||
|
||||
# React-PDF
|
||||
|
||||
Display PDFs in your React app as easily as if they were images.
|
||||
|
||||
## Lost?
|
||||
|
||||
This package is used to _display_ existing PDFs. If you wish to _create_ PDFs using React, you may be looking for [@react-pdf/renderer](https://www.npmjs.com/package/@react-pdf/renderer).
|
||||
|
||||
## tl;dr
|
||||
|
||||
- Install by executing `npm install react-pdf` or `yarn add react-pdf`.
|
||||
- Import by adding `import { Document } from 'react-pdf'`.
|
||||
- Use by adding `<Document file="..." />`. `file` can be a URL, base64 content, Uint8Array, and more.
|
||||
- Put `<Page />` components inside `<Document />` to render pages.
|
||||
|
||||
## Demo
|
||||
|
||||
A minimal demo page can be found in `sample` directory.
|
||||
|
||||
[Online demo](https://projects.wojtekmaj.pl/react-pdf/) is also available!
|
||||
|
||||
## Before you continue
|
||||
|
||||
React-PDF is under constant development. This documentation is written for React-PDF 9.x branch. If you want to see documentation for other versions of React-PDF, use dropdown on top of GitHub page to switch to an appropriate tag. Here are quick links to the newest docs from each branch:
|
||||
|
||||
- [v8.x](https://github.com/wojtekmaj/react-pdf/blob/v8.x/packages/react-pdf/README.md)
|
||||
- [v7.x](https://github.com/wojtekmaj/react-pdf/blob/v7.x/packages/react-pdf/README.md)
|
||||
- [v6.x](https://github.com/wojtekmaj/react-pdf/blob/v6.x/README.md)
|
||||
- [v5.x](https://github.com/wojtekmaj/react-pdf/blob/v5.x/README.md)
|
||||
- [v4.x](https://github.com/wojtekmaj/react-pdf/blob/v4.x/README.md)
|
||||
- [v3.x](https://github.com/wojtekmaj/react-pdf/blob/v3.x/README.md)
|
||||
- [v2.x](https://github.com/wojtekmaj/react-pdf/blob/v2.x/README.md)
|
||||
- [v1.x](https://github.com/wojtekmaj/react-pdf/blob/v1.x/README.md)
|
||||
|
||||
## Getting started
|
||||
|
||||
### Compatibility
|
||||
|
||||
#### Browser support
|
||||
|
||||
React-PDF supports all modern browsers. It is tested with the latest versions of Chrome, Edge, Safari, Firefox, and Opera.
|
||||
|
||||
The following browsers are supported out of the box in React-PDF v9:
|
||||
|
||||
- Chrome ≥119
|
||||
- Edge ≥119
|
||||
- Safari ≥17.4
|
||||
- Firefox ≥121
|
||||
|
||||
You may extend the list of supported browsers by providing additional polyfills (e.g. for `Array.prototype.at`, `Promise.allSettled` or `Promise.withResolvers`) and either configuring your bundler to transpile `pdfjs-dist` or using [legacy PDF.js worker](#legacy-pdfjs-worker).
|
||||
|
||||
If you need to support older browsers, you will need to use React-PDF v6 or earlier.
|
||||
|
||||
#### React
|
||||
|
||||
To use the latest version of React-PDF, your project needs to use React 16.8 or later.
|
||||
|
||||
If you use an older version of React, please refer to the table below to a find suitable React-PDF version.
|
||||
|
||||
| React version | Newest compatible React-PDF version |
|
||||
| ------------- | ----------------------------------- |
|
||||
| ≥16.8 | latest |
|
||||
| ≥16.3 | 5.x |
|
||||
| ≥15.5 | 4.x |
|
||||
|
||||
#### Preact
|
||||
|
||||
React-PDF may be used with Preact.
|
||||
|
||||
### Installation
|
||||
|
||||
Add React-PDF to your project by executing `npm install react-pdf` or `yarn add react-pdf`.
|
||||
|
||||
#### Next.js
|
||||
|
||||
If you use Next.js without Turbopack enabled, add the following to your `next.config.js`:
|
||||
|
||||
```diff
|
||||
module.exports = {
|
||||
+ webpack: (config) => {
|
||||
+ config.resolve.alias.canvas = false;
|
||||
|
||||
+ return config;
|
||||
+ },
|
||||
}
|
||||
```
|
||||
|
||||
If you use Next.js with Turbopack enabled, add `empty-module.ts` file:
|
||||
|
||||
```ts
|
||||
export default {};
|
||||
```
|
||||
|
||||
and add the following to your `next.config.js`:
|
||||
|
||||
```diff
|
||||
module.exports = {
|
||||
+ experimental: {
|
||||
+ turbo: {
|
||||
+ resolveAlias: {
|
||||
+ canvas: './empty-module.ts',
|
||||
+ },
|
||||
+ },
|
||||
+ },
|
||||
};
|
||||
```
|
||||
|
||||
If you use Next.js prior to v15 (v15.0.0-canary.53, specifically), you may need to add the following to your `next.config.js`:
|
||||
|
||||
```diff
|
||||
module.exports = {
|
||||
+ swcMinify: false,
|
||||
}
|
||||
```
|
||||
|
||||
### Configure PDF.js worker
|
||||
|
||||
For React-PDF to work, PDF.js worker needs to be provided. You have several options.
|
||||
|
||||
#### Import worker (recommended)
|
||||
|
||||
For most cases, the following example will work:
|
||||
|
||||
```ts
|
||||
import { pdfjs } from 'react-pdf';
|
||||
|
||||
pdfjs.GlobalWorkerOptions.workerSrc = new URL(
|
||||
'pdfjs-dist/build/pdf.worker.min.mjs',
|
||||
import.meta.url,
|
||||
).toString();
|
||||
```
|
||||
|
||||
> [!NOTE]
|
||||
> In Next.js:
|
||||
>
|
||||
> - Using App Router, make sure to add `'use client';` to the top of the file.
|
||||
> - Using Pages Router, make sure to [disable SSR](https://nextjs.org/docs/pages/building-your-application/optimizing/lazy-loading#with-no-ssr) when importing the component you're using this code in.
|
||||
|
||||
> [!NOTE]
|
||||
> pnpm requires an `.npmrc` file with `public-hoist-pattern[]=pdfjs-dist` for this to work.
|
||||
|
||||
<details>
|
||||
<summary>See more examples</summary>
|
||||
|
||||
##### Parcel 2
|
||||
|
||||
For Parcel 2, you need to use a slightly different code:
|
||||
|
||||
```diff
|
||||
pdfjs.GlobalWorkerOptions.workerSrc = new URL(
|
||||
- 'pdfjs-dist/build/pdf.worker.min.mjs',
|
||||
+ 'npm:pdfjs-dist/build/pdf.worker.min.mjs',
|
||||
import.meta.url,
|
||||
).toString();
|
||||
```
|
||||
|
||||
</details>
|
||||
|
||||
#### Copy worker to public directory
|
||||
|
||||
You will have to make sure on your own that `pdf.worker.mjs` file from `pdfjs-dist/build` is copied to your project's output folder.
|
||||
|
||||
For example, you could use a custom script like:
|
||||
|
||||
```ts
|
||||
import path from 'node:path';
|
||||
import fs from 'node:fs';
|
||||
|
||||
const pdfjsDistPath = path.dirname(require.resolve('pdfjs-dist/package.json'));
|
||||
const pdfWorkerPath = path.join(pdfjsDistPath, 'build', 'pdf.worker.mjs');
|
||||
|
||||
fs.cpSync(pdfWorkerPath, './dist/pdf.worker.mjs', { recursive: true });
|
||||
```
|
||||
|
||||
#### Use external CDN
|
||||
|
||||
```ts
|
||||
import { pdfjs } from 'react-pdf';
|
||||
|
||||
pdfjs.GlobalWorkerOptions.workerSrc = `//unpkg.com/pdfjs-dist@${pdfjs.version}/build/pdf.worker.min.mjs`;
|
||||
```
|
||||
|
||||
#### Legacy PDF.js worker
|
||||
|
||||
If you need to support older browsers, you may use legacy PDF.js worker. To do so, follow the instructions above, but replace `/build/` with `legacy/build/` in PDF.js worker import path, for example:
|
||||
|
||||
```diff
|
||||
pdfjs.GlobalWorkerOptions.workerSrc = new URL(
|
||||
- 'pdfjs-dist/build/pdf.worker.min.mjs',
|
||||
+ 'pdfjs-dist/legacy/build/pdf.worker.min.mjs',
|
||||
import.meta.url,
|
||||
).toString();
|
||||
```
|
||||
|
||||
or:
|
||||
|
||||
```diff
|
||||
-pdfjs.GlobalWorkerOptions.workerSrc = `//unpkg.com/pdfjs-dist@${pdfjs.version}/build/pdf.worker.min.mjs`;
|
||||
+pdfjs.GlobalWorkerOptions.workerSrc = `//unpkg.com/pdfjs-dist@${pdfjs.version}/legacy/build/pdf.worker.min.mjs`;
|
||||
```
|
||||
|
||||
### Usage
|
||||
|
||||
Here's an example of basic usage:
|
||||
|
||||
```tsx
|
||||
import { useState } from 'react';
|
||||
import { Document, Page } from 'react-pdf';
|
||||
|
||||
function MyApp() {
|
||||
const [numPages, setNumPages] = useState<number>();
|
||||
const [pageNumber, setPageNumber] = useState<number>(1);
|
||||
|
||||
function onDocumentLoadSuccess({ numPages }: { numPages: number }): void {
|
||||
setNumPages(numPages);
|
||||
}
|
||||
|
||||
return (
|
||||
<div>
|
||||
<Document file="somefile.pdf" onLoadSuccess={onDocumentLoadSuccess}>
|
||||
<Page pageNumber={pageNumber} />
|
||||
</Document>
|
||||
<p>
|
||||
Page {pageNumber} of {numPages}
|
||||
</p>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
```
|
||||
|
||||
Check the [sample directory](https://github.com/wojtekmaj/react-pdf/tree/main/sample) in this repository for a full working example. For more examples and more advanced use cases, check [Recipes](https://github.com/wojtekmaj/react-pdf/wiki/Recipes) in [React-PDF Wiki](https://github.com/wojtekmaj/react-pdf/wiki/).
|
||||
|
||||
### Support for annotations
|
||||
|
||||
If you want to use annotations (e.g. links) in PDFs rendered by React-PDF, then you would need to include stylesheet necessary for annotations to be correctly displayed like so:
|
||||
|
||||
```ts
|
||||
import 'react-pdf/dist/Page/AnnotationLayer.css';
|
||||
```
|
||||
|
||||
### Support for text layer
|
||||
|
||||
If you want to use text layer in PDFs rendered by React-PDF, then you would need to include stylesheet necessary for text layer to be correctly displayed like so:
|
||||
|
||||
```ts
|
||||
import 'react-pdf/dist/Page/TextLayer.css';
|
||||
```
|
||||
|
||||
### Support for non-latin characters
|
||||
|
||||
If you want to ensure that PDFs with non-latin characters will render perfectly, or you have encountered the following warning:
|
||||
|
||||
```
|
||||
Warning: The CMap "baseUrl" parameter must be specified, ensure that the "cMapUrl" and "cMapPacked" API parameters are provided.
|
||||
```
|
||||
|
||||
then you would also need to include cMaps in your build and tell React-PDF where they are.
|
||||
|
||||
#### Copying cMaps
|
||||
|
||||
First, you need to copy cMaps from `pdfjs-dist` (React-PDF's dependency - it should be in your `node_modules` if you have React-PDF installed). cMaps are located in `pdfjs-dist/cmaps`.
|
||||
|
||||
##### Vite
|
||||
|
||||
Add [`vite-plugin-static-copy`](https://www.npmjs.com/package/vite-plugin-static-copy) by executing `npm install vite-plugin-static-copy --save-dev` or `yarn add vite-plugin-static-copy --dev` and add the following to your Vite config:
|
||||
|
||||
```diff
|
||||
+import path from 'node:path';
|
||||
+import { createRequire } from 'node:module';
|
||||
|
||||
-import { defineConfig } from 'vite';
|
||||
+import { defineConfig, normalizePath } from 'vite';
|
||||
+import { viteStaticCopy } from 'vite-plugin-static-copy';
|
||||
|
||||
+const require = createRequire(import.meta.url);
|
||||
+
|
||||
+const pdfjsDistPath = path.dirname(require.resolve('pdfjs-dist/package.json'));
|
||||
+const cMapsDir = normalizePath(path.join(pdfjsDistPath, 'cmaps'));
|
||||
|
||||
export default defineConfig({
|
||||
plugins: [
|
||||
+ viteStaticCopy({
|
||||
+ targets: [
|
||||
+ {
|
||||
+ src: cMapsDir,
|
||||
+ dest: '',
|
||||
+ },
|
||||
+ ],
|
||||
+ }),
|
||||
]
|
||||
});
|
||||
```
|
||||
|
||||
##### Webpack
|
||||
|
||||
Add [`copy-webpack-plugin`](https://www.npmjs.com/package/copy-webpack-plugin) by executing `npm install copy-webpack-plugin --save-dev` or `yarn add copy-webpack-plugin --dev` and add the following to your Webpack config:
|
||||
|
||||
```diff
|
||||
+import path from 'node:path';
|
||||
+import CopyWebpackPlugin from 'copy-webpack-plugin';
|
||||
|
||||
+const pdfjsDistPath = path.dirname(require.resolve('pdfjs-dist/package.json'));
|
||||
+const cMapsDir = path.join(pdfjsDistPath, 'cmaps');
|
||||
|
||||
module.exports = {
|
||||
plugins: [
|
||||
+ new CopyWebpackPlugin({
|
||||
+ patterns: [
|
||||
+ {
|
||||
+ from: cMapsDir,
|
||||
+ to: 'cmaps/'
|
||||
+ },
|
||||
+ ],
|
||||
+ }),
|
||||
],
|
||||
};
|
||||
```
|
||||
|
||||
##### Other tools
|
||||
|
||||
If you use other bundlers, you will have to make sure on your own that cMaps are copied to your project's output folder.
|
||||
|
||||
For example, you could use a custom script like:
|
||||
|
||||
```ts
|
||||
import path from 'node:path';
|
||||
import fs from 'node:fs';
|
||||
|
||||
const pdfjsDistPath = path.dirname(require.resolve('pdfjs-dist/package.json'));
|
||||
const cMapsDir = path.join(pdfjsDistPath, 'cmaps');
|
||||
|
||||
fs.cpSync(cMapsDir, 'dist/cmaps/', { recursive: true });
|
||||
```
|
||||
|
||||
#### Setting up React-PDF
|
||||
|
||||
Now that you have cMaps in your build, pass required options to Document component by using `options` prop, like so:
|
||||
|
||||
```ts
|
||||
// Outside of React component
|
||||
const options = {
|
||||
cMapUrl: '/cmaps/',
|
||||
};
|
||||
|
||||
// Inside of React component
|
||||
<Document options={options} />;
|
||||
```
|
||||
|
||||
> [!NOTE]
|
||||
> Make sure to define `options` object outside of your React component, and use `useMemo` if you can't.
|
||||
|
||||
Alternatively, you could use cMaps from external CDN:
|
||||
|
||||
```tsx
|
||||
// Outside of React component
|
||||
import { pdfjs } from 'react-pdf';
|
||||
|
||||
const options = {
|
||||
cMapUrl: `https://unpkg.com/pdfjs-dist@${pdfjs.version}/cmaps/`,
|
||||
};
|
||||
|
||||
// Inside of React component
|
||||
<Document options={options} />;
|
||||
```
|
||||
|
||||
### Support for standard fonts
|
||||
|
||||
If you want to support PDFs using standard fonts (deprecated in PDF 1.5, but still around), ot you have encountered the following warning:
|
||||
|
||||
```
|
||||
The standard font "baseUrl" parameter must be specified, ensure that the "standardFontDataUrl" API parameter is provided.
|
||||
```
|
||||
|
||||
then you would also need to include standard fonts in your build and tell React-PDF where they are.
|
||||
|
||||
#### Copying fonts
|
||||
|
||||
First, you need to copy standard fonts from `pdfjs-dist` (React-PDF's dependency - it should be in your `node_modules` if you have React-PDF installed). Standard fonts are located in `pdfjs-dist/standard_fonts`.
|
||||
|
||||
##### Vite
|
||||
|
||||
Add [`vite-plugin-static-copy`](https://www.npmjs.com/package/vite-plugin-static-copy) by executing `npm install vite-plugin-static-copy --save-dev` or `yarn add vite-plugin-static-copy --dev` and add the following to your Vite config:
|
||||
|
||||
```diff
|
||||
+import path from 'node:path';
|
||||
+import { createRequire } from 'node:module';
|
||||
|
||||
-import { defineConfig } from 'vite';
|
||||
+import { defineConfig, normalizePath } from 'vite';
|
||||
+import { viteStaticCopy } from 'vite-plugin-static-copy';
|
||||
|
||||
+const require = createRequire(import.meta.url);
|
||||
+const standardFontsDir = normalizePath(
|
||||
+ path.join(path.dirname(require.resolve('pdfjs-dist/package.json')), 'standard_fonts')
|
||||
+);
|
||||
|
||||
export default defineConfig({
|
||||
plugins: [
|
||||
+ viteStaticCopy({
|
||||
+ targets: [
|
||||
+ {
|
||||
+ src: standardFontsDir,
|
||||
+ dest: '',
|
||||
+ },
|
||||
+ ],
|
||||
+ }),
|
||||
]
|
||||
});
|
||||
```
|
||||
|
||||
##### Webpack
|
||||
|
||||
Add [`copy-webpack-plugin`](https://www.npmjs.com/package/copy-webpack-plugin) by executing `npm install copy-webpack-plugin --save-dev` or `yarn add copy-webpack-plugin --dev` and add the following to your Webpack config:
|
||||
|
||||
```diff
|
||||
+import path from 'node:path';
|
||||
+import CopyWebpackPlugin from 'copy-webpack-plugin';
|
||||
|
||||
+const standardFontsDir = path.join(path.dirname(require.resolve('pdfjs-dist/package.json')), 'standard_fonts');
|
||||
|
||||
module.exports = {
|
||||
plugins: [
|
||||
+ new CopyWebpackPlugin({
|
||||
+ patterns: [
|
||||
+ {
|
||||
+ from: standardFontsDir,
|
||||
+ to: 'standard_fonts/'
|
||||
+ },
|
||||
+ ],
|
||||
+ }),
|
||||
],
|
||||
};
|
||||
```
|
||||
|
||||
##### Other tools
|
||||
|
||||
If you use other bundlers, you will have to make sure on your own that standard fonts are copied to your project's output folder.
|
||||
|
||||
For example, you could use a custom script like:
|
||||
|
||||
```ts
|
||||
import path from 'node:path';
|
||||
import fs from 'node:fs';
|
||||
|
||||
const pdfjsDistPath = path.dirname(require.resolve('pdfjs-dist/package.json'));
|
||||
const standardFontsDir = path.join(pdfjsDistPath, 'standard_fonts');
|
||||
|
||||
fs.cpSync(standardFontsDir, 'dist/standard_fonts/', { recursive: true });
|
||||
```
|
||||
|
||||
#### Setting up React-PDF
|
||||
|
||||
Now that you have standard fonts in your build, pass required options to Document component by using `options` prop, like so:
|
||||
|
||||
```tsx
|
||||
// Outside of React component
|
||||
const options = {
|
||||
standardFontDataUrl: '/standard_fonts/',
|
||||
};
|
||||
|
||||
// Inside of React component
|
||||
<Document options={options} />;
|
||||
```
|
||||
|
||||
> [!NOTE]
|
||||
> Make sure to define `options` object outside of your React component, and use `useMemo` if you can't.
|
||||
|
||||
Alternatively, you could use standard fonts from external CDN:
|
||||
|
||||
```tsx
|
||||
// Outside of React component
|
||||
import { pdfjs } from 'react-pdf';
|
||||
|
||||
const options = {
|
||||
standardFontDataUrl: `https://unpkg.com/pdfjs-dist@${pdfjs.version}/standard_fonts`,
|
||||
};
|
||||
|
||||
// Inside of React component
|
||||
<Document options={options} />;
|
||||
```
|
||||
|
||||
## User guide
|
||||
|
||||
### Document
|
||||
|
||||
Loads a document passed using `file` prop.
|
||||
|
||||
#### Props
|
||||
|
||||
| Prop name | Description | Default value | Example values |
|
||||
| ------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| className | Class name(s) that will be added to rendered element along with the default `react-pdf__Document`. | n/a | <ul><li>String:<br />`"custom-class-name-1 custom-class-name-2"`</li><li>Array of strings:<br />`["custom-class-name-1", "custom-class-name-2"]`</li></ul> |
|
||||
| error | What the component should display in case of an error. | `"Failed to load PDF file."` | <ul><li>String:<br />`"An error occurred!"`</li><li>React element:<br />`<p>An error occurred!</p>`</li><li>Function:<br />`this.renderError`</li></ul> |
|
||||
| externalLinkRel | Link rel for links rendered in annotations. | `"noopener noreferrer nofollow"` | One of valid [values for `rel` attribute](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a#attr-rel).<ul><li>`"noopener"`</li><li>`"noreferrer"`</li><li>`"nofollow"`</li><li>`"noopener noreferrer"`</li></ul> |
|
||||
| externalLinkTarget | Link target for external links rendered in annotations. | unset, which means that default behavior will be used | One of valid [values for `target` attribute](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a#attr-target).<ul><li>`"_self"`</li><li>`"_blank"`</li><li>`"_parent"`</li><li>`"_top"`</li></ul> |
|
||||
| file | What PDF should be displayed.<br />Its value can be an URL, a file (imported using `import … from …` or from file input form element), or an object with parameters (`url` - URL; `data` - data, preferably Uint8Array; `range` - PDFDataRangeTransport.<br />**Warning**: Since equality check (`===`) is used to determine if `file` object has changed, it must be memoized by setting it in component's state, `useMemo` or other similar technique. | n/a | <ul><li>URL:<br />`"https://example.com/sample.pdf"`</li><li>File:<br />`import importedPdf from '../static/sample.pdf'` and then<br />`sample`</li><li>Parameter object:<br />`{ url: 'https://example.com/sample.pdf' }`</ul> |
|
||||
| imageResourcesPath | The path used to prefix the src attributes of annotation SVGs. | n/a (pdf.js will fallback to an empty string) | `"/public/images/"` |
|
||||
| inputRef | A prop that behaves like [ref](https://reactjs.org/docs/refs-and-the-dom.html), but it's passed to main `<div>` rendered by `<Document>` component. | n/a | <ul><li>Function:<br />`(ref) => { this.myDocument = ref; }`</li><li>Ref created using `createRef`:<br />`this.ref = createRef();`<br />…<br />`inputRef={this.ref}`</li><li>Ref created using `useRef`:<br />`const ref = useRef();`<br />…<br />`inputRef={ref}`</li></ul> |
|
||||
| loading | What the component should display while loading. | `"Loading PDF…"` | <ul><li>String:<br />`"Please wait!"`</li><li>React element:<br />`<p>Please wait!</p>`</li><li>Function:<br />`this.renderLoader`</li></ul> |
|
||||
| noData | What the component should display in case of no data. | `"No PDF file specified."` | <ul><li>String:<br />`"Please select a file."`</li><li>React element:<br />`<p>Please select a file.</p>`</li><li>Function:<br />`this.renderNoData`</li></ul> |
|
||||
| onItemClick | Function called when an outline item or a thumbnail has been clicked. Usually, you would like to use this callback to move the user wherever they requested to. | n/a | `({ dest, pageIndex, pageNumber }) => alert('Clicked an item from page ' + pageNumber + '!')` |
|
||||
| onLoadError | Function called in case of an error while loading a document. | n/a | `(error) => alert('Error while loading document! ' + error.message)` |
|
||||
| onLoadProgress | Function called, potentially multiple times, as the loading progresses. | n/a | `({ loaded, total }) => alert('Loading a document: ' + (loaded / total) * 100 + '%')` |
|
||||
| onLoadSuccess | Function called when the document is successfully loaded. | n/a | `(pdf) => alert('Loaded a file with ' + pdf.numPages + ' pages!')` |
|
||||
| onPassword | Function called when a password-protected PDF is loaded. | Function that prompts the user for password. | `(callback) => callback('s3cr3t_p4ssw0rd')` |
|
||||
| onSourceError | Function called in case of an error while retrieving document source from `file` prop. | n/a | `(error) => alert('Error while retrieving document source! ' + error.message)` |
|
||||
| onSourceSuccess | Function called when document source is successfully retrieved from `file` prop. | n/a | `() => alert('Document source retrieved!')` |
|
||||
| options | An object in which additional parameters to be passed to PDF.js can be defined. Most notably:<ul><li>`cMapUrl`;</li><li>`httpHeaders` - custom request headers, e.g. for authorization);</li><li>`withCredentials` - a boolean to indicate whether or not to include cookies in the request (defaults to `false`)</li></ul>For a full list of possible parameters, check [PDF.js documentation on DocumentInitParameters](https://mozilla.github.io/pdf.js/api/draft/module-pdfjsLib.html#~DocumentInitParameters).<br /><br />**Note**: Make sure to define options object outside of your React component, and use `useMemo` if you can't. | n/a | `{ cMapUrl: '/cmaps/' }` |
|
||||
| renderMode | Rendering mode of the document. Can be `"canvas"`, `"custom"` or `"none"`. If set to `"custom"`, `customRenderer` must also be provided. | `"canvas"` | `"custom"` |
|
||||
| rotate | Rotation of the document in degrees. If provided, will change rotation globally, even for the pages which were given `rotate` prop of their own. `90` = rotated to the right, `180` = upside down, `270` = rotated to the left. | n/a | `90` |
|
||||
|
||||
### Page
|
||||
|
||||
Displays a page. Should be placed inside `<Document />`. Alternatively, it can have `pdf` prop passed, which can be obtained from `<Document />`'s `onLoadSuccess` callback function, however some advanced functions like rendering annotations and linking between pages inside a document may not be working correctly.
|
||||
|
||||
#### Props
|
||||
|
||||
| Prop name | Description | Default value | Example values |
|
||||
| ------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | --------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| canvasBackground | Canvas background color. Any valid `canvas.fillStyle` can be used. | n/a | `"transparent"` |
|
||||
| canvasRef | A prop that behaves like [ref](https://reactjs.org/docs/refs-and-the-dom.html), but it's passed to `<canvas>` rendered by `<Canvas>` component. | n/a | <ul><li>Function:<br />`(ref) => { this.myCanvas = ref; }`</li><li>Ref created using `createRef`:<br />`this.ref = createRef();`<br />…<br />`inputRef={this.ref}`</li><li>Ref created using `useRef`:<br />`const ref = useRef();`<br />…<br />`inputRef={ref}`</li></ul> |
|
||||
| className | Class name(s) that will be added to rendered element along with the default `react-pdf__Page`. | n/a | <ul><li>String:<br />`"custom-class-name-1 custom-class-name-2"`</li><li>Array of strings:<br />`["custom-class-name-1", "custom-class-name-2"]`</li></ul> |
|
||||
| customRenderer | Function that customizes how a page is rendered. You must set `renderMode` to `"custom"` to use this prop. | n/a | `MyCustomRenderer` |
|
||||
| customTextRenderer | Function that customizes how a text layer is rendered. | n/a | ``({ str, itemIndex }) => str.replace(/ipsum/g, value => `<mark>${value}</mark>`)`` |
|
||||
| devicePixelRatio | The ratio between physical pixels and device-independent pixels (DIPs) on the current device. | `window.devicePixelRatio` | `1` |
|
||||
| error | What the component should display in case of an error. | `"Failed to load the page."` | <ul><li>String:<br />`"An error occurred!"`</li><li>React element:<br />`<p>An error occurred!</p>`</li><li>Function:<br />`this.renderError`</li></ul> |
|
||||
| height | Page height. If neither `height` nor `width` are defined, page will be rendered at the size defined in PDF. If you define `width` and `height` at the same time, `height` will be ignored. If you define `height` and `scale` at the same time, the height will be multiplied by a given factor. | Page's default height | `300` |
|
||||
| imageResourcesPath | The path used to prefix the src attributes of annotation SVGs. | n/a (pdf.js will fallback to an empty string) | `"/public/images/"` |
|
||||
| inputRef | A prop that behaves like [ref](https://reactjs.org/docs/refs-and-the-dom.html), but it's passed to main `<div>` rendered by `<Page>` component. | n/a | <ul><li>Function:<br />`(ref) => { this.myPage = ref; }`</li><li>Ref created using `createRef`:<br />`this.ref = createRef();`<br />…<br />`inputRef={this.ref}`</li><li>Ref created using `useRef`:<br />`const ref = useRef();`<br />…<br />`inputRef={ref}`</li></ul> |
|
||||
| loading | What the component should display while loading. | `"Loading page…"` | <ul><li>String:<br />`"Please wait!"`</li><li>React element:<br />`<p>Please wait!</p>`</li><li>Function:<br />`this.renderLoader`</li></ul> |
|
||||
| noData | What the component should display in case of no data. | `"No page specified."` | <ul><li>String:<br />`"Please select a page."`</li><li>React element:<br />`<p>Please select a page.</p>`</li><li>Function:<br />`this.renderNoData`</li></ul> |
|
||||
| onGetAnnotationsError | Function called in case of an error while loading annotations. | n/a | `(error) => alert('Error while loading annotations! ' + error.message)` |
|
||||
| onGetAnnotationsSuccess | Function called when annotations are successfully loaded. | n/a | `(annotations) => alert('Now displaying ' + annotations.length + ' annotations!')` |
|
||||
| onGetStructTreeError | Function called in case of an error while loading structure tree. | n/a | `(error) => alert('Error while loading structure tree! ' + error.message)` |
|
||||
| onGetStructTreeSuccess | Function called when structure tree is successfully loaded. | n/a | `(structTree) => alert(JSON.stringify(structTree))` |
|
||||
| onGetTextError | Function called in case of an error while loading text layer items. | n/a | `(error) => alert('Error while loading text layer items! ' + error.message)` |
|
||||
| onGetTextSuccess | Function called when text layer items are successfully loaded. | n/a | `({ items, styles }) => alert('Now displaying ' + items.length + ' text layer items!')` |
|
||||
| onLoadError | Function called in case of an error while loading the page. | n/a | `(error) => alert('Error while loading page! ' + error.message)` |
|
||||
| onLoadSuccess | Function called when the page is successfully loaded. | n/a | `(page) => alert('Now displaying a page number ' + page.pageNumber + '!')` |
|
||||
| onRenderAnnotationLayerError | Function called in case of an error while rendering the annotation layer. | n/a | `(error) => alert('Error while loading annotation layer! ' + error.message)` |
|
||||
| onRenderAnnotationLayerSuccess | Function called when annotations are successfully rendered on the screen. | n/a | `() => alert('Rendered the annotation layer!')` |
|
||||
| onRenderError | Function called in case of an error while rendering the page. | n/a | `(error) => alert('Error while loading page! ' + error.message)` |
|
||||
| onRenderSuccess | Function called when the page is successfully rendered on the screen. | n/a | `() => alert('Rendered the page!')` |
|
||||
| onRenderTextLayerError | Function called in case of an error while rendering the text layer. | n/a | `(error) => alert('Error while rendering text layer! ' + error.message)` |
|
||||
| onRenderTextLayerSuccess | Function called when the text layer is successfully rendered on the screen. | n/a | `() => alert('Rendered the text layer!')` |
|
||||
| pageIndex | Which page from PDF file should be displayed, by page index. Ignored if `pageNumber` prop is provided. | `0` | `1` |
|
||||
| pageNumber | Which page from PDF file should be displayed, by page number. If provided, `pageIndex` prop will be ignored. | `1` | `2` |
|
||||
| pdf | pdf object obtained from `<Document />`'s `onLoadSuccess` callback function. | (automatically obtained from parent `<Document />`) | `pdf` |
|
||||
| renderAnnotationLayer | Whether annotations (e.g. links) should be rendered. | `true` | `false` |
|
||||
| renderForms | Whether forms should be rendered. `renderAnnotationLayer` prop must be set to `true`. | `false` | `true` |
|
||||
| renderMode | Rendering mode of the document. Can be `"canvas"`, `"custom"` or `"none"`. If set to `"custom"`, `customRenderer` must also be provided. | `"canvas"` | `"custom"` |
|
||||
| renderTextLayer | Whether a text layer should be rendered. | `true` | `false` |
|
||||
| rotate | Rotation of the page in degrees. `90` = rotated to the right, `180` = upside down, `270` = rotated to the left. | Page's default setting, usually `0` | `90` |
|
||||
| scale | Page scale. | `1` | `0.5` |
|
||||
| width | Page width. If neither `height` nor `width` are defined, page will be rendered at the size defined in PDF. If you define `width` and `height` at the same time, `height` will be ignored. If you define `width` and `scale` at the same time, the width will be multiplied by a given factor. | Page's default width | `300` |
|
||||
|
||||
### Outline
|
||||
|
||||
Displays an outline (table of contents). Should be placed inside `<Document />`. Alternatively, it can have `pdf` prop passed, which can be obtained from `<Document />`'s `onLoadSuccess` callback function.
|
||||
|
||||
#### Props
|
||||
|
||||
| Prop name | Description | Default value | Example values |
|
||||
| ------------- | -------------------------------------------------------------------------------------------------------------------------------------------------- | ------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| className | Class name(s) that will be added to rendered element along with the default `react-pdf__Outline`. | n/a | <ul><li>String:<br />`"custom-class-name-1 custom-class-name-2"`</li><li>Array of strings:<br />`["custom-class-name-1", "custom-class-name-2"]`</li></ul> |
|
||||
| inputRef | A prop that behaves like [ref](https://reactjs.org/docs/refs-and-the-dom.html), but it's passed to main `<div>` rendered by `<Outline>` component. | n/a | <ul><li>Function:<br />`(ref) => { this.myOutline = ref; }`</li><li>Ref created using `createRef`:<br />`this.ref = createRef();`<br />…<br />`inputRef={this.ref}`</li><li>Ref created using `useRef`:<br />`const ref = useRef();`<br />…<br />`inputRef={ref}`</li></ul> |
|
||||
| onItemClick | Function called when an outline item has been clicked. Usually, you would like to use this callback to move the user wherever they requested to. | n/a | `({ dest, pageIndex, pageNumber }) => alert('Clicked an item from page ' + pageNumber + '!')` |
|
||||
| onLoadError | Function called in case of an error while retrieving the outline. | n/a | `(error) => alert('Error while retrieving the outline! ' + error.message)` |
|
||||
| onLoadSuccess | Function called when the outline is successfully retrieved. | n/a | `(outline) => alert('The outline has been successfully retrieved.')` |
|
||||
|
||||
### Thumbnail
|
||||
|
||||
Displays a thumbnail of a page. Does not render the annotation layer or the text layer. Does not register itself as a link target, so the user will not be scrolled to a Thumbnail component when clicked on an internal link (e.g. in Table of Contents). When clicked, attempts to navigate to the page clicked (similarly to a link in Outline). Should be placed inside `<Document />`. Alternatively, it can have `pdf` prop passed, which can be obtained from `<Document />`'s `onLoadSuccess` callback function.
|
||||
|
||||
#### Props
|
||||
|
||||
Props are the same as in `<Page />` component, but certain annotation layer and text layer-related props are not available:
|
||||
|
||||
- customTextRenderer
|
||||
- onGetAnnotationsError
|
||||
- onGetAnnotationsSuccess
|
||||
- onGetTextError
|
||||
- onGetTextSuccess
|
||||
- onRenderAnnotationLayerError
|
||||
- onRenderAnnotationLayerSuccess
|
||||
- onRenderTextLayerError
|
||||
- onRenderTextLayerSuccess
|
||||
- renderAnnotationLayer
|
||||
- renderForms
|
||||
- renderTextLayer
|
||||
|
||||
On top of that, additional props are available:
|
||||
|
||||
| Prop name | Description | Default value | Example values |
|
||||
| ----------- | -------------------------------------------------------------------------------------------------------------------------------------------- | ------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| className | Class name(s) that will be added to rendered element along with the default `react-pdf__Thumbnail`. | n/a | <ul><li>String:<br />`"custom-class-name-1 custom-class-name-2"`</li><li>Array of strings:<br />`["custom-class-name-1", "custom-class-name-2"]`</li></ul> |
|
||||
| onItemClick | Function called when a thumbnail has been clicked. Usually, you would like to use this callback to move the user wherever they requested to. | n/a | `({ dest, pageIndex, pageNumber }) => alert('Clicked an item from page ' + pageNumber + '!')` |
|
||||
|
||||
## Useful links
|
||||
|
||||
- [React-PDF Wiki](https://github.com/wojtekmaj/react-pdf/wiki/)
|
||||
|
||||
## License
|
||||
|
||||
The MIT License.
|
||||
|
||||
## Author
|
||||
|
||||
<table>
|
||||
<tr>
|
||||
<td >
|
||||
<img src="https://avatars.githubusercontent.com/u/5426427?v=4&s=128" width="64" height="64" alt="Wojciech Maj">
|
||||
</td>
|
||||
<td>
|
||||
<a href="https://github.com/wojtekmaj">Wojciech Maj</a>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
## Thank you
|
||||
|
||||
This project wouldn't be possible without the awesome work of [Niklas Närhinen](https://github.com/nnarhinen) who created its original version and without Mozilla, author of [pdf.js](http://mozilla.github.io/pdf.js). Thank you!
|
||||
|
||||
### Sponsors
|
||||
|
||||
Thank you to all our sponsors! [Become a sponsor](https://opencollective.com/react-pdf-wojtekmaj#sponsor) and get your image on our README on GitHub.
|
||||
|
||||
<a href="https://opencollective.com/react-pdf-wojtekmaj#sponsors" target="_blank"><img src="https://opencollective.com/react-pdf-wojtekmaj/sponsors.svg?width=890"></a>
|
||||
|
||||
### Backers
|
||||
|
||||
Thank you to all our backers! [Become a backer](https://opencollective.com/react-pdf-wojtekmaj#backer) and get your image on our README on GitHub.
|
||||
|
||||
<a href="https://opencollective.com/react-pdf-wojtekmaj#backers" target="_blank"><img src="https://opencollective.com/react-pdf-wojtekmaj/backers.svg?width=890"></a>
|
||||
|
||||
### Top Contributors
|
||||
|
||||
Thank you to all our contributors that helped on this project!
|
||||
|
||||

|
||||
@@ -0,0 +1,39 @@
|
||||
{
|
||||
"name": "callsites",
|
||||
"version": "3.1.0",
|
||||
"description": "Get callsites from the V8 stack trace API",
|
||||
"license": "MIT",
|
||||
"repository": "sindresorhus/callsites",
|
||||
"author": {
|
||||
"name": "Sindre Sorhus",
|
||||
"email": "sindresorhus@gmail.com",
|
||||
"url": "sindresorhus.com"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=6"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "xo && ava && tsd"
|
||||
},
|
||||
"files": [
|
||||
"index.js",
|
||||
"index.d.ts"
|
||||
],
|
||||
"keywords": [
|
||||
"stacktrace",
|
||||
"v8",
|
||||
"callsite",
|
||||
"callsites",
|
||||
"stack",
|
||||
"trace",
|
||||
"function",
|
||||
"file",
|
||||
"line",
|
||||
"debug"
|
||||
],
|
||||
"devDependencies": {
|
||||
"ava": "^1.4.1",
|
||||
"tsd": "^0.7.2",
|
||||
"xo": "^0.24.0"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user