update
This commit is contained in:
@@ -0,0 +1,115 @@
|
||||
import invariant from 'tiny-invariant';
|
||||
|
||||
import Ref from './Ref.js';
|
||||
|
||||
import useCachedValue from './shared/hooks/useCachedValue.js';
|
||||
import useDocumentContext from './shared/hooks/useDocumentContext.js';
|
||||
import useOutlineContext from './shared/hooks/useOutlineContext.js';
|
||||
|
||||
import type { PDFDocumentProxy } from 'pdfjs-dist';
|
||||
import type { RefProxy } from 'pdfjs-dist/types/src/display/api.js';
|
||||
|
||||
type PDFOutline = Awaited<ReturnType<PDFDocumentProxy['getOutline']>>;
|
||||
|
||||
type PDFOutlineItem = PDFOutline[number];
|
||||
|
||||
type OutlineItemProps = {
|
||||
item: PDFOutlineItem;
|
||||
pdf?: PDFDocumentProxy | false;
|
||||
};
|
||||
|
||||
export default function OutlineItem(props: OutlineItemProps): React.ReactElement {
|
||||
const documentContext = useDocumentContext();
|
||||
|
||||
const outlineContext = useOutlineContext();
|
||||
|
||||
invariant(outlineContext, 'Unable to find Outline context.');
|
||||
|
||||
const mergedProps = { ...documentContext, ...outlineContext, ...props };
|
||||
const { item, linkService, onItemClick, pdf, ...otherProps } = mergedProps;
|
||||
|
||||
invariant(
|
||||
pdf,
|
||||
'Attempted to load an outline, but no document was specified. Wrap <Outline /> in a <Document /> or pass explicit `pdf` prop.',
|
||||
);
|
||||
|
||||
const getDestination = useCachedValue(() => {
|
||||
if (typeof item.dest === 'string') {
|
||||
return pdf.getDestination(item.dest);
|
||||
}
|
||||
|
||||
return item.dest;
|
||||
});
|
||||
|
||||
const getPageIndex = useCachedValue(async () => {
|
||||
const destination = await getDestination();
|
||||
|
||||
if (!destination) {
|
||||
throw new Error('Destination not found.');
|
||||
}
|
||||
|
||||
const [ref] = destination as [RefProxy];
|
||||
|
||||
return pdf.getPageIndex(new Ref(ref));
|
||||
});
|
||||
|
||||
const getPageNumber = useCachedValue(async () => {
|
||||
const pageIndex = await getPageIndex();
|
||||
|
||||
return pageIndex + 1;
|
||||
});
|
||||
|
||||
function onClick(event: React.MouseEvent<HTMLAnchorElement>) {
|
||||
event.preventDefault();
|
||||
|
||||
invariant(
|
||||
onItemClick || linkService,
|
||||
'Either onItemClick callback or linkService must be defined in order to navigate to an outline item.',
|
||||
);
|
||||
|
||||
if (onItemClick) {
|
||||
Promise.all([getDestination(), getPageIndex(), getPageNumber()]).then(
|
||||
([dest, pageIndex, pageNumber]) => {
|
||||
onItemClick({
|
||||
dest,
|
||||
pageIndex,
|
||||
pageNumber,
|
||||
});
|
||||
},
|
||||
);
|
||||
} else if (linkService) {
|
||||
linkService.goToDestination(item.dest);
|
||||
}
|
||||
}
|
||||
|
||||
function renderSubitems() {
|
||||
if (!item.items || !item.items.length) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const { items: subitems } = item;
|
||||
|
||||
return (
|
||||
<ul>
|
||||
{subitems.map((subitem, subitemIndex) => (
|
||||
<OutlineItem
|
||||
key={typeof subitem.dest === 'string' ? subitem.dest : subitemIndex}
|
||||
item={subitem}
|
||||
pdf={pdf}
|
||||
{...otherProps}
|
||||
/>
|
||||
))}
|
||||
</ul>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<li>
|
||||
{/* biome-ignore lint/a11y/useValidAnchor: We can't provide real href here */}
|
||||
<a href="#" onClick={onClick}>
|
||||
{item.title}
|
||||
</a>
|
||||
{renderSubitems()}
|
||||
</li>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
module.exports={C:{"2":0.00722,"11":0.02526,"44":0.00361,"52":0.02886,"53":0.01443,"55":0.00361,"56":0.00722,"59":0.00722,"72":0.00361,"78":0.01082,"88":0.00722,"94":0.00361,"113":0.00361,"115":0.21648,"118":0.09381,"120":0.00361,"125":0.00722,"127":0.00722,"128":0.0902,"131":0.00361,"132":0.00722,"133":0.01443,"134":0.02526,"135":0.34998,"136":1.1257,"137":0.00722,_:"3 4 5 6 7 8 9 10 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 45 46 47 48 49 50 51 54 57 58 60 61 62 63 64 65 66 67 68 69 70 71 73 74 75 76 77 79 80 81 82 83 84 85 86 87 89 90 91 92 93 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 114 116 117 119 121 122 123 124 126 129 130 138 139 140 3.5 3.6"},D:{"38":0.00722,"39":0.00722,"40":0.00361,"41":0.00722,"42":0.00722,"43":0.00722,"44":0.00722,"45":0.00722,"46":0.00722,"47":0.00722,"48":0.01804,"49":0.01804,"50":0.00722,"51":0.00722,"52":0.01082,"53":0.00722,"54":0.00722,"55":0.00722,"56":0.01443,"57":0.00722,"58":0.01082,"59":0.00722,"60":0.00722,"66":0.01804,"69":0.01082,"70":0.01082,"73":0.00722,"74":0.00361,"75":0.00722,"76":0.00361,"77":0.01443,"78":0.01082,"79":0.06855,"80":0.01082,"81":0.01443,"83":0.02886,"84":0.00361,"85":0.00722,"86":0.01443,"87":0.05412,"88":0.01443,"89":0.00361,"90":0.00722,"91":0.03608,"92":0.01082,"93":0.01443,"94":0.01443,"95":0.00722,"96":0.00361,"97":0.01443,"98":0.03608,"99":0.01082,"100":0.02886,"101":0.01443,"102":0.01082,"103":0.07577,"104":0.05051,"105":0.01082,"106":0.01804,"107":0.02165,"108":0.03969,"109":0.91643,"110":0.01804,"111":0.03247,"112":0.03247,"113":0.01804,"114":0.05412,"115":0.03247,"116":0.10102,"117":0.09742,"118":0.05051,"119":0.03608,"120":0.08298,"121":0.07938,"122":0.07577,"123":0.08659,"124":0.11546,"125":0.34276,"126":0.15154,"127":0.10102,"128":0.12989,"129":0.09381,"130":0.14793,"131":1.17982,"132":0.81541,"133":5.9099,"134":9.96169,"135":0.02165,"136":0.01443,_:"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 63 64 65 67 68 71 72 137 138"},F:{"40":0.00361,"46":0.01082,"87":0.02526,"88":0.00722,"95":0.03247,"102":0.01804,"114":0.00361,"116":0.20566,"117":0.69634,_:"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 41 42 43 44 45 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 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.00722,"92":0.01443,"108":0.00361,"109":0.0469,"113":0.00722,"114":0.01443,"115":0.00722,"117":0.00361,"118":0.00361,"119":0.00361,"120":0.03608,"121":0.00722,"122":0.01443,"123":0.00722,"124":0.00722,"125":0.00722,"126":0.01804,"127":0.01804,"128":0.01443,"129":0.01443,"130":0.02526,"131":0.06494,"132":0.07938,"133":1.34578,"134":3.03794,_:"12 13 14 15 16 17 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 110 111 112 116"},E:{"14":0.01443,"15":0.00361,_:"0 4 5 6 7 8 9 10 11 12 13 3.1 3.2 5.1 6.1 7.1 9.1 10.1","11.1":0.00361,"12.1":0.00722,"13.1":0.03247,"14.1":0.0433,"15.1":0.01443,"15.2-15.3":0.00361,"15.4":0.01082,"15.5":0.01443,"15.6":0.14793,"16.0":0.03247,"16.1":0.02526,"16.2":0.01804,"16.3":0.03969,"16.4":0.01443,"16.5":0.02526,"16.6":0.20205,"17.0":0.01082,"17.1":0.12267,"17.2":0.01804,"17.3":0.02165,"17.4":0.05051,"17.5":0.0902,"17.6":0.26338,"18.0":0.03608,"18.1":0.11906,"18.2":0.05773,"18.3":1.41073,"18.4":0.01804},G:{"8":0,"3.2":0,"4.0-4.1":0,"4.2-4.3":0.0029,"5.0-5.1":0,"6.0-6.1":0.00869,"7.0-7.1":0.0058,"8.1-8.4":0,"9.0-9.2":0.00435,"9.3":0.02029,"10.0-10.2":0.00145,"10.3":0.03333,"11.0-11.2":0.1536,"11.3-11.4":0.01014,"12.0-12.1":0.0058,"12.2-12.5":0.14346,"13.0-13.1":0.0029,"13.2":0.00435,"13.3":0.0058,"13.4-13.7":0.02029,"14.0-14.4":0.05072,"14.5-14.8":0.06086,"15.0-15.1":0.03333,"15.2-15.3":0.03333,"15.4":0.04057,"15.5":0.04637,"15.6-15.8":0.57093,"16.0":0.08115,"16.1":0.16664,"16.2":0.08694,"16.3":0.1507,"16.4":0.03333,"16.5":0.06231,"16.6-16.7":0.67671,"17.0":0.04057,"17.1":0.07245,"17.2":0.05506,"17.3":0.0768,"17.4":0.1536,"17.5":0.34198,"17.6-17.7":0.99261,"18.0":0.27822,"18.1":0.91001,"18.2":0.40719,"18.3":8.51037,"18.4":0.12607},P:{"4":0.03276,"21":0.02184,"22":0.02184,"23":0.03276,"24":0.04367,"25":0.04367,"26":0.08735,"27":1.96531,_:"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 18.0 19.0","7.2-7.4":0.02184,"17.0":0.01092},I:{"0":0.85473,"3":0,"4":0,"2.1":0,"2.2":0,"2.3":0,"4.1":0,"4.2-4.3":0.00026,"4.4":0,"4.4.3-4.4.4":0.00094},K:{"0":1.05582,_:"10 11 12 11.1 11.5 12.1"},A:{"9":0.03235,"11":0.43669,_:"6 7 8 10 5.5"},S:{"2.5":0.01278,_:"3.0-3.1"},J:{_:"7 10"},N:{_:"10 11"},R:{_:"0"},M:{"0":0.35156},Q:{"14.9":0.23011},O:{"0":0.85653},H:{"0":0.05},L:{"0":44.82018}};
|
||||
@@ -0,0 +1 @@
|
||||
module.exports={C:{"16":0.03327,"48":0.02218,"52":0.01664,"60":0.01109,"65":0.00555,"72":0.01109,"78":0.02773,"88":0.00555,"104":0.00555,"106":0.00555,"108":0.00555,"109":0.00555,"110":0.03882,"112":0.00555,"113":0.01664,"115":0.68758,"125":0.01109,"127":0.02773,"128":0.16081,"129":0.02773,"130":0.02773,"131":0.03327,"132":0.04991,"133":0.01664,"134":0.07209,"135":1.0591,"136":3.53217,"137":0.02773,_:"2 3 4 5 6 7 8 9 10 11 12 13 14 15 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 49 50 51 53 54 55 56 57 58 59 61 62 63 64 66 67 68 69 70 71 73 74 75 76 77 79 80 81 82 83 84 85 86 87 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 105 107 111 114 116 117 118 119 120 121 122 123 124 126 138 139 140 3.5 3.6"},D:{"38":0.00555,"41":0.00555,"48":0.00555,"49":0.01109,"53":0.00555,"79":0.09981,"85":0.00555,"87":0.02773,"89":0.00555,"90":0.01109,"92":0.00555,"93":0.00555,"94":0.00555,"95":0.00555,"97":0.00555,"98":0.00555,"101":0.01109,"102":0.03327,"103":0.04436,"104":0.07209,"105":0.01109,"106":0.02218,"107":0.02218,"108":0.08318,"109":1.49715,"110":0.01109,"111":0.01664,"112":0.00555,"113":0.00555,"114":0.09427,"115":0.061,"116":0.12199,"117":0.00555,"118":0.02773,"119":0.02218,"120":0.39924,"121":0.82066,"122":0.08872,"123":0.061,"124":0.06654,"125":0.01664,"126":0.04436,"127":0.02773,"128":0.30498,"129":0.1719,"130":0.20517,"131":0.49905,"132":0.84839,"133":10.1529,"134":19.70693,"135":0.04436,"136":0.09981,_:"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 39 40 42 43 44 45 46 47 50 51 52 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 80 81 83 84 86 88 91 96 99 100 137 138"},F:{"86":0.00555,"87":0.01664,"88":0.00555,"95":0.12199,"96":0.00555,"104":0.00555,"114":0.00555,"115":0.00555,"116":0.36043,"117":2.10156,_:"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 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 89 90 91 92 93 94 97 98 99 100 101 102 103 105 106 107 108 109 110 111 112 113 9.5-9.6 10.0-10.1 10.5 10.6 11.1 11.5 11.6 12.1"},B:{"92":0.00555,"102":0.00555,"107":0.01109,"108":0.00555,"109":0.01664,"114":0.00555,"122":0.00555,"123":0.00555,"125":0.04991,"126":0.04436,"127":0.02218,"128":0.07209,"129":0.01109,"130":0.04991,"131":0.04991,"132":0.14417,"133":1.35298,"134":3.06084,_:"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 103 104 105 106 110 111 112 113 115 116 117 118 119 120 121 124"},E:{"8":0.00555,"14":0.00555,_:"0 4 5 6 7 9 10 11 12 13 15 3.1 3.2 5.1 6.1 7.1 9.1 10.1 11.1 15.1 15.2-15.3 15.5","12.1":0.02218,"13.1":0.04436,"14.1":0.01664,"15.4":0.00555,"15.6":0.14417,"16.0":0.01109,"16.1":0.03327,"16.2":0.01109,"16.3":0.02773,"16.4":0.02773,"16.5":0.01109,"16.6":0.1109,"17.0":0.02218,"17.1":0.12199,"17.2":0.02218,"17.3":0.03882,"17.4":0.03882,"17.5":0.07209,"17.6":0.31607,"18.0":0.03327,"18.1":0.10536,"18.2":0.13308,"18.3":1.2809,"18.4":0.02218},G:{"8":0,"3.2":0,"4.0-4.1":0,"4.2-4.3":0.00203,"5.0-5.1":0,"6.0-6.1":0.00609,"7.0-7.1":0.00406,"8.1-8.4":0,"9.0-9.2":0.00305,"9.3":0.01422,"10.0-10.2":0.00102,"10.3":0.02336,"11.0-11.2":0.10767,"11.3-11.4":0.00711,"12.0-12.1":0.00406,"12.2-12.5":0.10056,"13.0-13.1":0.00203,"13.2":0.00305,"13.3":0.00406,"13.4-13.7":0.01422,"14.0-14.4":0.03555,"14.5-14.8":0.04266,"15.0-15.1":0.02336,"15.2-15.3":0.02336,"15.4":0.02844,"15.5":0.0325,"15.6-15.8":0.4002,"16.0":0.05688,"16.1":0.11681,"16.2":0.06094,"16.3":0.10564,"16.4":0.02336,"16.5":0.04368,"16.6-16.7":0.47435,"17.0":0.02844,"17.1":0.05079,"17.2":0.0386,"17.3":0.05383,"17.4":0.10767,"17.5":0.23971,"17.6-17.7":0.69578,"18.0":0.19502,"18.1":0.63788,"18.2":0.28542,"18.3":5.96544,"18.4":0.08837},P:{"4":0.01039,"20":0.02078,"21":0.02078,"22":0.02078,"23":0.03117,"24":0.03117,"25":0.02078,"26":0.09351,"27":3.12753,"5.0-5.4":0.01039,_:"6.2-6.4 7.2-7.4 8.2 9.2 10.1 11.1-11.2 13.0 14.0 15.0 16.0 17.0 18.0","12.0":0.01039,"19.0":0.01039},I:{"0":0.06668,"3":0,"4":0,"2.1":0,"2.2":0,"2.3":0,"4.1":0,"4.2-4.3":0.00002,"4.4":0,"4.4.3-4.4.4":0.00007},K:{"0":0.36422,_:"10 11 12 11.1 11.5 12.1"},A:{"8":0.0061,"10":0.0061,"11":0.10979,_:"6 7 9 5.5"},S:{_:"2.5 3.0-3.1"},J:{_:"7 10"},N:{_:"10 11"},R:{_:"0"},M:{"0":0.36977},Q:{"14.9":0.00446},O:{"0":0.1292},H:{"0":0.01},L:{"0":30.84939}};
|
||||
@@ -0,0 +1,150 @@
|
||||
/**
|
||||
* @license React
|
||||
* scheduler-unstable_post_task.development.js
|
||||
*
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
"production" !== process.env.NODE_ENV &&
|
||||
(function () {
|
||||
function runTask(priorityLevel, postTaskPriority, node, callback) {
|
||||
deadline = getCurrentTime() + 5;
|
||||
try {
|
||||
currentPriorityLevel_DEPRECATED = priorityLevel;
|
||||
var result = callback(!1);
|
||||
if ("function" === typeof result) {
|
||||
var continuationOptions = { signal: node._controller.signal },
|
||||
nextTask = runTask.bind(
|
||||
null,
|
||||
priorityLevel,
|
||||
postTaskPriority,
|
||||
node,
|
||||
result
|
||||
);
|
||||
void 0 !== scheduler.yield
|
||||
? scheduler
|
||||
.yield(continuationOptions)
|
||||
.then(nextTask)
|
||||
.catch(handleAbortError)
|
||||
: scheduler
|
||||
.postTask(nextTask, continuationOptions)
|
||||
.catch(handleAbortError);
|
||||
}
|
||||
} catch (error) {
|
||||
setTimeout(function () {
|
||||
throw error;
|
||||
});
|
||||
} finally {
|
||||
currentPriorityLevel_DEPRECATED = 3;
|
||||
}
|
||||
}
|
||||
function handleAbortError() {}
|
||||
var perf = window.performance,
|
||||
setTimeout = window.setTimeout,
|
||||
scheduler = global.scheduler,
|
||||
getCurrentTime = perf.now.bind(perf),
|
||||
deadline = 0,
|
||||
currentPriorityLevel_DEPRECATED = 3;
|
||||
exports.unstable_IdlePriority = 5;
|
||||
exports.unstable_ImmediatePriority = 1;
|
||||
exports.unstable_LowPriority = 4;
|
||||
exports.unstable_NormalPriority = 3;
|
||||
exports.unstable_Profiling = null;
|
||||
exports.unstable_UserBlockingPriority = 2;
|
||||
exports.unstable_cancelCallback = function (node) {
|
||||
node._controller.abort();
|
||||
};
|
||||
exports.unstable_forceFrameRate = function () {};
|
||||
exports.unstable_getCurrentPriorityLevel = function () {
|
||||
return currentPriorityLevel_DEPRECATED;
|
||||
};
|
||||
exports.unstable_next = function (callback) {
|
||||
switch (currentPriorityLevel_DEPRECATED) {
|
||||
case 1:
|
||||
case 2:
|
||||
case 3:
|
||||
var priorityLevel = 3;
|
||||
break;
|
||||
default:
|
||||
priorityLevel = currentPriorityLevel_DEPRECATED;
|
||||
}
|
||||
var previousPriorityLevel = currentPriorityLevel_DEPRECATED;
|
||||
currentPriorityLevel_DEPRECATED = priorityLevel;
|
||||
try {
|
||||
return callback();
|
||||
} finally {
|
||||
currentPriorityLevel_DEPRECATED = previousPriorityLevel;
|
||||
}
|
||||
};
|
||||
exports.unstable_now = getCurrentTime;
|
||||
exports.unstable_requestPaint = function () {};
|
||||
exports.unstable_runWithPriority = function (priorityLevel, callback) {
|
||||
var previousPriorityLevel = currentPriorityLevel_DEPRECATED;
|
||||
currentPriorityLevel_DEPRECATED = priorityLevel;
|
||||
try {
|
||||
return callback();
|
||||
} finally {
|
||||
currentPriorityLevel_DEPRECATED = previousPriorityLevel;
|
||||
}
|
||||
};
|
||||
exports.unstable_scheduleCallback = function (
|
||||
priorityLevel,
|
||||
callback,
|
||||
options
|
||||
) {
|
||||
switch (priorityLevel) {
|
||||
case 1:
|
||||
case 2:
|
||||
var postTaskPriority = "user-blocking";
|
||||
break;
|
||||
case 4:
|
||||
case 3:
|
||||
postTaskPriority = "user-visible";
|
||||
break;
|
||||
case 5:
|
||||
postTaskPriority = "background";
|
||||
break;
|
||||
default:
|
||||
postTaskPriority = "user-visible";
|
||||
}
|
||||
var controller = new TaskController({ priority: postTaskPriority });
|
||||
options = {
|
||||
delay:
|
||||
"object" === typeof options && null !== options ? options.delay : 0,
|
||||
signal: controller.signal
|
||||
};
|
||||
controller = { _controller: controller };
|
||||
scheduler
|
||||
.postTask(
|
||||
runTask.bind(
|
||||
null,
|
||||
priorityLevel,
|
||||
postTaskPriority,
|
||||
controller,
|
||||
callback
|
||||
),
|
||||
options
|
||||
)
|
||||
.catch(handleAbortError);
|
||||
return controller;
|
||||
};
|
||||
exports.unstable_shouldYield = function () {
|
||||
return getCurrentTime() >= deadline;
|
||||
};
|
||||
exports.unstable_wrapCallback = function (callback) {
|
||||
var parentPriorityLevel = currentPriorityLevel_DEPRECATED;
|
||||
return function () {
|
||||
var previousPriorityLevel = currentPriorityLevel_DEPRECATED;
|
||||
currentPriorityLevel_DEPRECATED = parentPriorityLevel;
|
||||
try {
|
||||
return callback();
|
||||
} finally {
|
||||
currentPriorityLevel_DEPRECATED = previousPriorityLevel;
|
||||
}
|
||||
};
|
||||
};
|
||||
})();
|
||||
@@ -0,0 +1,99 @@
|
||||
import type { SourceMapSegment } from './sourcemap-segment';
|
||||
import type { GREATEST_LOWER_BOUND, LEAST_UPPER_BOUND, TraceMap } from './trace-mapping';
|
||||
export interface SourceMapV3 {
|
||||
file?: string | null;
|
||||
names: string[];
|
||||
sourceRoot?: string;
|
||||
sources: (string | null)[];
|
||||
sourcesContent?: (string | null)[];
|
||||
version: 3;
|
||||
ignoreList?: number[];
|
||||
}
|
||||
export interface EncodedSourceMap extends SourceMapV3 {
|
||||
mappings: string;
|
||||
}
|
||||
export interface DecodedSourceMap extends SourceMapV3 {
|
||||
mappings: SourceMapSegment[][];
|
||||
}
|
||||
export interface Section {
|
||||
offset: {
|
||||
line: number;
|
||||
column: number;
|
||||
};
|
||||
map: EncodedSourceMap | DecodedSourceMap | SectionedSourceMap;
|
||||
}
|
||||
export interface SectionedSourceMap {
|
||||
file?: string | null;
|
||||
sections: Section[];
|
||||
version: 3;
|
||||
}
|
||||
export type OriginalMapping = {
|
||||
source: string | null;
|
||||
line: number;
|
||||
column: number;
|
||||
name: string | null;
|
||||
};
|
||||
export type InvalidOriginalMapping = {
|
||||
source: null;
|
||||
line: null;
|
||||
column: null;
|
||||
name: null;
|
||||
};
|
||||
export type GeneratedMapping = {
|
||||
line: number;
|
||||
column: number;
|
||||
};
|
||||
export type InvalidGeneratedMapping = {
|
||||
line: null;
|
||||
column: null;
|
||||
};
|
||||
export type Bias = typeof GREATEST_LOWER_BOUND | typeof LEAST_UPPER_BOUND;
|
||||
export type XInput = {
|
||||
x_google_ignoreList?: SourceMapV3['ignoreList'];
|
||||
};
|
||||
export type EncodedSourceMapXInput = EncodedSourceMap & XInput;
|
||||
export type DecodedSourceMapXInput = DecodedSourceMap & XInput;
|
||||
export type SectionedSourceMapXInput = Omit<SectionedSourceMap, 'sections'> & {
|
||||
sections: SectionXInput[];
|
||||
};
|
||||
export type SectionXInput = Omit<Section, 'map'> & {
|
||||
map: SectionedSourceMapInput;
|
||||
};
|
||||
export type SourceMapInput = string | EncodedSourceMapXInput | DecodedSourceMapXInput | TraceMap;
|
||||
export type SectionedSourceMapInput = SourceMapInput | SectionedSourceMapXInput;
|
||||
export type Needle = {
|
||||
line: number;
|
||||
column: number;
|
||||
bias?: Bias;
|
||||
};
|
||||
export type SourceNeedle = {
|
||||
source: string;
|
||||
line: number;
|
||||
column: number;
|
||||
bias?: Bias;
|
||||
};
|
||||
export type EachMapping = {
|
||||
generatedLine: number;
|
||||
generatedColumn: number;
|
||||
source: null;
|
||||
originalLine: null;
|
||||
originalColumn: null;
|
||||
name: null;
|
||||
} | {
|
||||
generatedLine: number;
|
||||
generatedColumn: number;
|
||||
source: string | null;
|
||||
originalLine: number;
|
||||
originalColumn: number;
|
||||
name: string | null;
|
||||
};
|
||||
export declare abstract class SourceMap {
|
||||
version: SourceMapV3['version'];
|
||||
file: SourceMapV3['file'];
|
||||
names: SourceMapV3['names'];
|
||||
sourceRoot: SourceMapV3['sourceRoot'];
|
||||
sources: SourceMapV3['sources'];
|
||||
sourcesContent: SourceMapV3['sourcesContent'];
|
||||
resolvedSources: SourceMapV3['sources'];
|
||||
ignoreList: SourceMapV3['ignoreList'];
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<svg
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
width="40"
|
||||
height="40"
|
||||
viewBox="0 0 40 40">
|
||||
<path
|
||||
d="M 1.5006714,23.536225 6.8925879,18.994244 14.585721,26.037937 34.019683,4.5410479 38.499329,9.2235032 14.585721,35.458952 z"
|
||||
id="path4"
|
||||
style="fill:#ffff00;fill-opacity:1;stroke:#000000;stroke-width:1.25402856;stroke-opacity:1" />
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 415 B |
@@ -0,0 +1,128 @@
|
||||
# @vitejs/plugin-react [](https://npmjs.com/package/@vitejs/plugin-react)
|
||||
|
||||
The default Vite plugin for React projects.
|
||||
|
||||
- enable [Fast Refresh](https://www.npmjs.com/package/react-refresh) in development (requires react >= 16.9)
|
||||
- use the [automatic JSX runtime](https://legacy.reactjs.org/blog/2020/09/22/introducing-the-new-jsx-transform.html)
|
||||
- use custom Babel plugins/presets
|
||||
- small installation size
|
||||
|
||||
```js
|
||||
// vite.config.js
|
||||
import { defineConfig } from 'vite'
|
||||
import react from '@vitejs/plugin-react'
|
||||
|
||||
export default defineConfig({
|
||||
plugins: [react()],
|
||||
})
|
||||
```
|
||||
|
||||
## Options
|
||||
|
||||
### include/exclude
|
||||
|
||||
Includes `.js`, `.jsx`, `.ts` & `.tsx` by default. This option can be used to add fast refresh to `.mdx` files:
|
||||
|
||||
```js
|
||||
import { defineConfig } from 'vite'
|
||||
import react from '@vitejs/plugin-react'
|
||||
import mdx from '@mdx-js/rollup'
|
||||
|
||||
export default defineConfig({
|
||||
plugins: [
|
||||
{ enforce: 'pre', ...mdx() },
|
||||
react({ include: /\.(mdx|js|jsx|ts|tsx)$/ }),
|
||||
],
|
||||
})
|
||||
```
|
||||
|
||||
> `node_modules` are never processed by this plugin (but esbuild will)
|
||||
|
||||
### jsxImportSource
|
||||
|
||||
Control where the JSX factory is imported from. Default to `'react'`
|
||||
|
||||
```js
|
||||
react({ jsxImportSource: '@emotion/react' })
|
||||
```
|
||||
|
||||
### jsxRuntime
|
||||
|
||||
By default, the plugin uses the [automatic JSX runtime](https://legacy.reactjs.org/blog/2020/09/22/introducing-the-new-jsx-transform.html). However, if you encounter any issues, you may opt out using the `jsxRuntime` option.
|
||||
|
||||
```js
|
||||
react({ jsxRuntime: 'classic' })
|
||||
```
|
||||
|
||||
### babel
|
||||
|
||||
The `babel` option lets you add plugins, presets, and [other configuration](https://babeljs.io/docs/en/options) to the Babel transformation performed on each included file.
|
||||
|
||||
```js
|
||||
react({
|
||||
babel: {
|
||||
presets: [...],
|
||||
// Your plugins run before any built-in transform (eg: Fast Refresh)
|
||||
plugins: [...],
|
||||
// Use .babelrc files
|
||||
babelrc: true,
|
||||
// Use babel.config.js files
|
||||
configFile: true,
|
||||
}
|
||||
})
|
||||
```
|
||||
|
||||
Note: When not using plugins, only esbuild is used for production builds, resulting in faster builds.
|
||||
|
||||
#### Proposed syntax
|
||||
|
||||
If you are using ES syntax that are still in proposal status (e.g. class properties), you can selectively enable them with the `babel.parserOpts.plugins` option:
|
||||
|
||||
```js
|
||||
react({
|
||||
babel: {
|
||||
parserOpts: {
|
||||
plugins: ['decorators-legacy'],
|
||||
},
|
||||
},
|
||||
})
|
||||
```
|
||||
|
||||
This option does not enable _code transformation_. That is handled by esbuild.
|
||||
|
||||
**Note:** TypeScript syntax is handled automatically.
|
||||
|
||||
Here's the [complete list of Babel parser plugins](https://babeljs.io/docs/en/babel-parser#ecmascript-proposalshttpsgithubcombabelproposals).
|
||||
|
||||
## Middleware mode
|
||||
|
||||
In [middleware mode](https://vitejs.dev/config/server-options.html#server-middlewaremode), you should make sure your entry `index.html` file is transformed by Vite. Here's an example for an Express server:
|
||||
|
||||
```js
|
||||
app.get('/', async (req, res, next) => {
|
||||
try {
|
||||
let html = fs.readFileSync(path.resolve(root, 'index.html'), 'utf-8')
|
||||
|
||||
// Transform HTML using Vite plugins.
|
||||
html = await viteServer.transformIndexHtml(req.url, html)
|
||||
|
||||
res.send(html)
|
||||
} catch (e) {
|
||||
return next(e)
|
||||
}
|
||||
})
|
||||
```
|
||||
|
||||
Otherwise, you'll probably get this error:
|
||||
|
||||
```
|
||||
Uncaught Error: @vitejs/plugin-react can't detect preamble. Something is wrong.
|
||||
```
|
||||
|
||||
## Consistent components exports
|
||||
|
||||
For React refresh to work correctly, your file should only export React components. You can find a good explanation in the [Gatsby docs](https://www.gatsbyjs.com/docs/reference/local-development/fast-refresh/#how-it-works).
|
||||
|
||||
If an incompatible change in exports is found, the module will be invalidated and HMR will propagate. To make it easier to export simple constants alongside your component, the module is only invalidated when their value changes.
|
||||
|
||||
You can catch mistakes and get more detailed warning with this [eslint rule](https://github.com/ArnaudBarre/eslint-plugin-react-refresh).
|
||||
@@ -0,0 +1 @@
|
||||
module.exports={A:{A:{"2":"K D E F A B mC"},B:{"1":"0 9 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","2":"C L M G N O P","66":"Q H R S T U V W X"},C:{"2":"0 1 2 3 4 5 6 7 8 9 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 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 qC rC"},D:{"1":"0 9 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","2":"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 3B 4B 5B 6B 7B 8B 9B AC BC CC","66":"DC Q H R S T U V W X"},E:{"2":"J PB K D E F A B C L M G sC SC 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"},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","2":"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 sB tB uB vB wB xB yB zB 4C 5C 6C 7C FC kC 8C GC","66":"0B 1B 2B 3B 4B 5B 6B 7B 8B 9B AC"},G:{"2":"E SC 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:{"2":"LC J I XD YD ZD aD lC bD cD"},J:{"2":"D A"},K:{"2":"A B C H FC kC GC"},L:{"2":"I"},M:{"2":"EC"},N:{"2":"A B"},O:{"2":"HC"},P:{"2":"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:{"2":"oD"},R:{"2":"pD"},S:{"2":"qD rD"}},B:7,C:"Web Serial API",D:true};
|
||||
@@ -0,0 +1 @@
|
||||
module.exports={C:{"52":52.53753,"56":0.00743,"109":0.01486,"112":0.00743,"113":0.00743,"115":0.24519,"128":0.01486,"134":0.01486,"135":0.21547,"136":0.49781,_:"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 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 110 111 114 116 117 118 119 120 121 122 123 124 125 126 127 129 130 131 132 133 137 138 139 140 3.5 3.6"},D:{"43":0.00743,"49":0.00743,"51":0.02972,"58":0.00743,"79":0.00743,"87":0.00743,"88":0.00743,"92":0.0743,"94":0.00743,"97":0.01486,"98":0.00743,"100":0.00743,"102":0.00743,"103":0.01486,"106":0.02229,"108":0.02229,"109":1.42656,"110":0.02229,"111":0.00743,"112":0.02229,"114":0.00743,"115":0.80244,"116":0.01486,"118":0.02972,"119":0.00743,"120":0.01486,"121":0.01486,"122":0.01486,"123":0.05201,"124":0.01486,"125":0.09659,"126":0.02229,"127":0.02972,"128":0.04458,"129":0.02229,"130":0.05201,"131":0.2229,"132":0.18575,"133":4.36884,"134":8.51478,"135":0.02972,"136":0.02972,_:"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 44 45 46 47 48 50 52 53 54 55 56 57 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 80 81 83 84 85 86 89 90 91 93 95 96 99 101 104 105 107 113 117 137 138"},F:{"36":0.04458,"46":0.00743,"87":0.00743,"95":0.01486,"116":0.05201,"117":0.43094,_:"9 11 12 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 37 38 39 40 41 42 43 44 45 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 88 89 90 91 92 93 94 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 9.5-9.6 10.0-10.1 10.5 10.6 11.1 11.5 11.6 12.1"},B:{"92":0.00743,"109":0.04458,"128":0.00743,"131":0.00743,"132":0.01486,"133":0.2972,"134":0.79501,_:"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 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 129 130"},E:{"14":0.00743,_:"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 13.1 14.1 15.1 15.2-15.3 15.4 15.5 16.0 16.2 16.3","15.6":0.01486,"16.1":0.00743,"16.4":0.00743,"16.5":0.00743,"16.6":0.06687,"17.0":0.01486,"17.1":0.02972,"17.2":0.00743,"17.3":0.00743,"17.4":0.05944,"17.5":0.04458,"17.6":0.05201,"18.0":0.01486,"18.1":0.12631,"18.2":0.01486,"18.3":0.69099,"18.4":0.00743},G:{"8":0,"3.2":0,"4.0-4.1":0,"4.2-4.3":0.00139,"5.0-5.1":0,"6.0-6.1":0.00417,"7.0-7.1":0.00278,"8.1-8.4":0,"9.0-9.2":0.00208,"9.3":0.00973,"10.0-10.2":0.00069,"10.3":0.01598,"11.0-11.2":0.07364,"11.3-11.4":0.00486,"12.0-12.1":0.00278,"12.2-12.5":0.06877,"13.0-13.1":0.00139,"13.2":0.00208,"13.3":0.00278,"13.4-13.7":0.00973,"14.0-14.4":0.02431,"14.5-14.8":0.02918,"15.0-15.1":0.01598,"15.2-15.3":0.01598,"15.4":0.01945,"15.5":0.02223,"15.6-15.8":0.2737,"16.0":0.0389,"16.1":0.07989,"16.2":0.04168,"16.3":0.07225,"16.4":0.01598,"16.5":0.02987,"16.6-16.7":0.32441,"17.0":0.01945,"17.1":0.03473,"17.2":0.0264,"17.3":0.03682,"17.4":0.07364,"17.5":0.16394,"17.6-17.7":0.47585,"18.0":0.13338,"18.1":0.43625,"18.2":0.1952,"18.3":4.0798,"18.4":0.06044},P:{"20":0.01061,"21":0.01061,"22":0.01061,"23":0.02122,"24":0.02122,"25":0.02122,"26":0.04243,"27":0.732,_:"4 5.0-5.4 6.2-6.4 8.2 9.2 10.1 12.0 13.0 14.0 15.0 16.0 17.0 19.0","7.2-7.4":0.02122,"11.1-11.2":0.01061,"18.0":0.01061},I:{"0":0.01282,"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.00001},K:{"0":0.36064,_:"10 11 12 11.1 11.5 12.1"},A:{"11":0.02972,_:"6 7 8 9 10 5.5"},S:{_:"2.5 3.0-3.1"},J:{_:"7 10"},N:{_:"10 11"},R:{_:"0"},M:{"0":0.15934},Q:{_:"14.9"},O:{"0":0.16448},H:{"0":0.03},L:{"0":17.24258}};
|
||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Author Tobias Koppers @sokra
|
||||
*/
|
||||
"use strict";
|
||||
|
||||
const Hook = require("./Hook");
|
||||
const HookCodeFactory = require("./HookCodeFactory");
|
||||
|
||||
class SyncWaterfallHookCodeFactory extends HookCodeFactory {
|
||||
content({ onError, onResult, resultReturns, rethrowIfPossible }) {
|
||||
return this.callTapsSeries({
|
||||
onError: (i, err) => onError(err),
|
||||
onResult: (i, result, next) => {
|
||||
let code = "";
|
||||
code += `if(${result} !== undefined) {\n`;
|
||||
code += `${this._args[0]} = ${result};\n`;
|
||||
code += `}\n`;
|
||||
code += next();
|
||||
return code;
|
||||
},
|
||||
onDone: () => onResult(this._args[0]),
|
||||
doneReturns: resultReturns,
|
||||
rethrowIfPossible
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
const factory = new SyncWaterfallHookCodeFactory();
|
||||
|
||||
const TAP_ASYNC = () => {
|
||||
throw new Error("tapAsync is not supported on a SyncWaterfallHook");
|
||||
};
|
||||
|
||||
const TAP_PROMISE = () => {
|
||||
throw new Error("tapPromise is not supported on a SyncWaterfallHook");
|
||||
};
|
||||
|
||||
const COMPILE = function(options) {
|
||||
factory.setup(this, options);
|
||||
return factory.create(options);
|
||||
};
|
||||
|
||||
function SyncWaterfallHook(args = [], name = undefined) {
|
||||
if (args.length < 1)
|
||||
throw new Error("Waterfall hooks must have at least one argument");
|
||||
const hook = new Hook(args, name);
|
||||
hook.constructor = SyncWaterfallHook;
|
||||
hook.tapAsync = TAP_ASYNC;
|
||||
hook.tapPromise = TAP_PROMISE;
|
||||
hook.compile = COMPILE;
|
||||
return hook;
|
||||
}
|
||||
|
||||
SyncWaterfallHook.prototype = null;
|
||||
|
||||
module.exports = SyncWaterfallHook;
|
||||
@@ -0,0 +1,749 @@
|
||||
// ==================================================================================================
|
||||
// JSON Schema Draft 04
|
||||
// ==================================================================================================
|
||||
|
||||
/**
|
||||
* @see https://tools.ietf.org/html/draft-zyp-json-schema-03#section-5.1
|
||||
*/
|
||||
export type JSONSchema4TypeName =
|
||||
| "string" //
|
||||
| "number"
|
||||
| "integer"
|
||||
| "boolean"
|
||||
| "object"
|
||||
| "array"
|
||||
| "null"
|
||||
| "any";
|
||||
|
||||
/**
|
||||
* @see https://tools.ietf.org/html/draft-zyp-json-schema-04#section-3.5
|
||||
*/
|
||||
export type JSONSchema4Type =
|
||||
| string //
|
||||
| number
|
||||
| boolean
|
||||
| JSONSchema4Object
|
||||
| JSONSchema4Array
|
||||
| null;
|
||||
|
||||
// Workaround for infinite type recursion
|
||||
export interface JSONSchema4Object {
|
||||
[key: string]: JSONSchema4Type;
|
||||
}
|
||||
|
||||
// Workaround for infinite type recursion
|
||||
// https://github.com/Microsoft/TypeScript/issues/3496#issuecomment-128553540
|
||||
export interface JSONSchema4Array extends Array<JSONSchema4Type> {}
|
||||
|
||||
/**
|
||||
* Meta schema
|
||||
*
|
||||
* Recommended values:
|
||||
* - 'http://json-schema.org/schema#'
|
||||
* - 'http://json-schema.org/hyper-schema#'
|
||||
* - 'http://json-schema.org/draft-04/schema#'
|
||||
* - 'http://json-schema.org/draft-04/hyper-schema#'
|
||||
* - 'http://json-schema.org/draft-03/schema#'
|
||||
* - 'http://json-schema.org/draft-03/hyper-schema#'
|
||||
*
|
||||
* @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-5
|
||||
*/
|
||||
export type JSONSchema4Version = string;
|
||||
|
||||
/**
|
||||
* JSON Schema V4
|
||||
* @see https://tools.ietf.org/html/draft-zyp-json-schema-04
|
||||
*/
|
||||
export interface JSONSchema4 {
|
||||
id?: string | undefined;
|
||||
$ref?: string | undefined;
|
||||
$schema?: JSONSchema4Version | undefined;
|
||||
|
||||
/**
|
||||
* This attribute is a string that provides a short description of the
|
||||
* instance property.
|
||||
*
|
||||
* @see https://tools.ietf.org/html/draft-zyp-json-schema-03#section-5.21
|
||||
*/
|
||||
title?: string | undefined;
|
||||
|
||||
/**
|
||||
* This attribute is a string that provides a full description of the of
|
||||
* purpose the instance property.
|
||||
*
|
||||
* @see https://tools.ietf.org/html/draft-zyp-json-schema-03#section-5.22
|
||||
*/
|
||||
description?: string | undefined;
|
||||
|
||||
default?: JSONSchema4Type | undefined;
|
||||
multipleOf?: number | undefined;
|
||||
maximum?: number | undefined;
|
||||
exclusiveMaximum?: boolean | undefined;
|
||||
minimum?: number | undefined;
|
||||
exclusiveMinimum?: boolean | undefined;
|
||||
maxLength?: number | undefined;
|
||||
minLength?: number | undefined;
|
||||
pattern?: string | undefined;
|
||||
|
||||
/**
|
||||
* May only be defined when "items" is defined, and is a tuple of JSONSchemas.
|
||||
*
|
||||
* This provides a definition for additional items in an array instance
|
||||
* when tuple definitions of the items is provided. This can be false
|
||||
* to indicate additional items in the array are not allowed, or it can
|
||||
* be a schema that defines the schema of the additional items.
|
||||
*
|
||||
* @see https://tools.ietf.org/html/draft-zyp-json-schema-03#section-5.6
|
||||
*/
|
||||
additionalItems?: boolean | JSONSchema4 | undefined;
|
||||
|
||||
/**
|
||||
* This attribute defines the allowed items in an instance array, and
|
||||
* MUST be a schema or an array of schemas. The default value is an
|
||||
* empty schema which allows any value for items in the instance array.
|
||||
*
|
||||
* When this attribute value is a schema and the instance value is an
|
||||
* array, then all the items in the array MUST be valid according to the
|
||||
* schema.
|
||||
*
|
||||
* When this attribute value is an array of schemas and the instance
|
||||
* value is an array, each position in the instance array MUST conform
|
||||
* to the schema in the corresponding position for this array. This
|
||||
* called tuple typing. When tuple typing is used, additional items are
|
||||
* allowed, disallowed, or constrained by the "additionalItems"
|
||||
* (Section 5.6) attribute using the same rules as
|
||||
* "additionalProperties" (Section 5.4) for objects.
|
||||
*
|
||||
* @see https://tools.ietf.org/html/draft-zyp-json-schema-03#section-5.5
|
||||
*/
|
||||
items?: JSONSchema4 | JSONSchema4[] | undefined;
|
||||
|
||||
maxItems?: number | undefined;
|
||||
minItems?: number | undefined;
|
||||
uniqueItems?: boolean | undefined;
|
||||
maxProperties?: number | undefined;
|
||||
minProperties?: number | undefined;
|
||||
|
||||
/**
|
||||
* This attribute indicates if the instance must have a value, and not
|
||||
* be undefined. This is false by default, making the instance
|
||||
* optional.
|
||||
*
|
||||
* @see https://tools.ietf.org/html/draft-zyp-json-schema-03#section-5.7
|
||||
*/
|
||||
required?: boolean | string[] | undefined;
|
||||
|
||||
/**
|
||||
* This attribute defines a schema for all properties that are not
|
||||
* explicitly defined in an object type definition. If specified, the
|
||||
* value MUST be a schema or a boolean. If false is provided, no
|
||||
* additional properties are allowed beyond the properties defined in
|
||||
* the schema. The default value is an empty schema which allows any
|
||||
* value for additional properties.
|
||||
*
|
||||
* @see https://tools.ietf.org/html/draft-zyp-json-schema-03#section-5.4
|
||||
*/
|
||||
additionalProperties?: boolean | JSONSchema4 | undefined;
|
||||
|
||||
definitions?: {
|
||||
[k: string]: JSONSchema4;
|
||||
} | undefined;
|
||||
|
||||
/**
|
||||
* This attribute is an object with property definitions that define the
|
||||
* valid values of instance object property values. When the instance
|
||||
* value is an object, the property values of the instance object MUST
|
||||
* conform to the property definitions in this object. In this object,
|
||||
* each property definition's value MUST be a schema, and the property's
|
||||
* name MUST be the name of the instance property that it defines. The
|
||||
* instance property value MUST be valid according to the schema from
|
||||
* the property definition. Properties are considered unordered, the
|
||||
* order of the instance properties MAY be in any order.
|
||||
*
|
||||
* @see https://tools.ietf.org/html/draft-zyp-json-schema-03#section-5.2
|
||||
*/
|
||||
properties?: {
|
||||
[k: string]: JSONSchema4;
|
||||
} | undefined;
|
||||
|
||||
/**
|
||||
* This attribute is an object that defines the schema for a set of
|
||||
* property names of an object instance. The name of each property of
|
||||
* this attribute's object is a regular expression pattern in the ECMA
|
||||
* 262/Perl 5 format, while the value is a schema. If the pattern
|
||||
* matches the name of a property on the instance object, the value of
|
||||
* the instance's property MUST be valid against the pattern name's
|
||||
* schema value.
|
||||
*
|
||||
* @see https://tools.ietf.org/html/draft-zyp-json-schema-03#section-5.3
|
||||
*/
|
||||
patternProperties?: {
|
||||
[k: string]: JSONSchema4;
|
||||
} | undefined;
|
||||
dependencies?: {
|
||||
[k: string]: JSONSchema4 | string[];
|
||||
} | undefined;
|
||||
|
||||
/**
|
||||
* This provides an enumeration of all possible values that are valid
|
||||
* for the instance property. This MUST be an array, and each item in
|
||||
* the array represents a possible value for the instance value. If
|
||||
* this attribute is defined, the instance value MUST be one of the
|
||||
* values in the array in order for the schema to be valid.
|
||||
*
|
||||
* @see https://tools.ietf.org/html/draft-zyp-json-schema-03#section-5.19
|
||||
*/
|
||||
enum?: JSONSchema4Type[] | undefined;
|
||||
|
||||
/**
|
||||
* A single type, or a union of simple types
|
||||
*/
|
||||
type?: JSONSchema4TypeName | JSONSchema4TypeName[] | undefined;
|
||||
|
||||
allOf?: JSONSchema4[] | undefined;
|
||||
anyOf?: JSONSchema4[] | undefined;
|
||||
oneOf?: JSONSchema4[] | undefined;
|
||||
not?: JSONSchema4 | undefined;
|
||||
|
||||
/**
|
||||
* The value of this property MUST be another schema which will provide
|
||||
* a base schema which the current schema will inherit from. The
|
||||
* inheritance rules are such that any instance that is valid according
|
||||
* to the current schema MUST be valid according to the referenced
|
||||
* schema. This MAY also be an array, in which case, the instance MUST
|
||||
* be valid for all the schemas in the array. A schema that extends
|
||||
* another schema MAY define additional attributes, constrain existing
|
||||
* attributes, or add other constraints.
|
||||
*
|
||||
* Conceptually, the behavior of extends can be seen as validating an
|
||||
* instance against all constraints in the extending schema as well as
|
||||
* the extended schema(s).
|
||||
*
|
||||
* @see https://tools.ietf.org/html/draft-zyp-json-schema-03#section-5.26
|
||||
*/
|
||||
extends?: string | string[] | undefined;
|
||||
|
||||
/**
|
||||
* @see https://tools.ietf.org/html/draft-zyp-json-schema-04#section-5.6
|
||||
*/
|
||||
[k: string]: any;
|
||||
|
||||
format?: string | undefined;
|
||||
}
|
||||
|
||||
// ==================================================================================================
|
||||
// JSON Schema Draft 06
|
||||
// ==================================================================================================
|
||||
|
||||
export type JSONSchema6TypeName =
|
||||
| "string" //
|
||||
| "number"
|
||||
| "integer"
|
||||
| "boolean"
|
||||
| "object"
|
||||
| "array"
|
||||
| "null"
|
||||
| "any";
|
||||
|
||||
export type JSONSchema6Type =
|
||||
| string //
|
||||
| number
|
||||
| boolean
|
||||
| JSONSchema6Object
|
||||
| JSONSchema6Array
|
||||
| null;
|
||||
|
||||
// Workaround for infinite type recursion
|
||||
export interface JSONSchema6Object {
|
||||
[key: string]: JSONSchema6Type;
|
||||
}
|
||||
|
||||
// Workaround for infinite type recursion
|
||||
// https://github.com/Microsoft/TypeScript/issues/3496#issuecomment-128553540
|
||||
export interface JSONSchema6Array extends Array<JSONSchema6Type> {}
|
||||
|
||||
/**
|
||||
* Meta schema
|
||||
*
|
||||
* Recommended values:
|
||||
* - 'http://json-schema.org/schema#'
|
||||
* - 'http://json-schema.org/hyper-schema#'
|
||||
* - 'http://json-schema.org/draft-06/schema#'
|
||||
* - 'http://json-schema.org/draft-06/hyper-schema#'
|
||||
*
|
||||
* @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-5
|
||||
*/
|
||||
export type JSONSchema6Version = string;
|
||||
|
||||
/**
|
||||
* JSON Schema V6
|
||||
* @see https://tools.ietf.org/html/draft-wright-json-schema-validation-01
|
||||
*/
|
||||
export type JSONSchema6Definition = JSONSchema6 | boolean;
|
||||
export interface JSONSchema6 {
|
||||
$id?: string | undefined;
|
||||
$ref?: string | undefined;
|
||||
$schema?: JSONSchema6Version | undefined;
|
||||
|
||||
/**
|
||||
* Must be strictly greater than 0.
|
||||
* A numeric instance is valid only if division by this keyword's value results in an integer.
|
||||
* @see https://tools.ietf.org/html/draft-wright-json-schema-validation-01#section-6.1
|
||||
*/
|
||||
multipleOf?: number | undefined;
|
||||
|
||||
/**
|
||||
* Representing an inclusive upper limit for a numeric instance.
|
||||
* This keyword validates only if the instance is less than or exactly equal to "maximum".
|
||||
* @see https://tools.ietf.org/html/draft-wright-json-schema-validation-01#section-6.2
|
||||
*/
|
||||
maximum?: number | undefined;
|
||||
|
||||
/**
|
||||
* Representing an exclusive upper limit for a numeric instance.
|
||||
* This keyword validates only if the instance is strictly less than (not equal to) to "exclusiveMaximum".
|
||||
* @see https://tools.ietf.org/html/draft-wright-json-schema-validation-01#section-6.3
|
||||
*/
|
||||
exclusiveMaximum?: number | undefined;
|
||||
|
||||
/**
|
||||
* Representing an inclusive lower limit for a numeric instance.
|
||||
* This keyword validates only if the instance is greater than or exactly equal to "minimum".
|
||||
* @see https://tools.ietf.org/html/draft-wright-json-schema-validation-01#section-6.4
|
||||
*/
|
||||
minimum?: number | undefined;
|
||||
|
||||
/**
|
||||
* Representing an exclusive lower limit for a numeric instance.
|
||||
* This keyword validates only if the instance is strictly greater than (not equal to) to "exclusiveMinimum".
|
||||
* @see https://tools.ietf.org/html/draft-wright-json-schema-validation-01#section-6.5
|
||||
*/
|
||||
exclusiveMinimum?: number | undefined;
|
||||
|
||||
/**
|
||||
* Must be a non-negative integer.
|
||||
* A string instance is valid against this keyword if its length is less than, or equal to, the value of this keyword.
|
||||
* @see https://tools.ietf.org/html/draft-wright-json-schema-validation-01#section-6.6
|
||||
*/
|
||||
maxLength?: number | undefined;
|
||||
|
||||
/**
|
||||
* Must be a non-negative integer.
|
||||
* A string instance is valid against this keyword if its length is greater than, or equal to, the value of this keyword.
|
||||
* Omitting this keyword has the same behavior as a value of 0.
|
||||
* @see https://tools.ietf.org/html/draft-wright-json-schema-validation-01#section-6.7
|
||||
*/
|
||||
minLength?: number | undefined;
|
||||
|
||||
/**
|
||||
* Should be a valid regular expression, according to the ECMA 262 regular expression dialect.
|
||||
* @see https://tools.ietf.org/html/draft-wright-json-schema-validation-01#section-6.8
|
||||
*/
|
||||
pattern?: string | undefined;
|
||||
|
||||
/**
|
||||
* This keyword determines how child instances validate for arrays, and does not directly validate the immediate instance itself.
|
||||
* Omitting this keyword has the same behavior as an empty schema.
|
||||
* @see https://tools.ietf.org/html/draft-wright-json-schema-validation-01#section-6.9
|
||||
*/
|
||||
items?: JSONSchema6Definition | JSONSchema6Definition[] | undefined;
|
||||
|
||||
/**
|
||||
* This keyword determines how child instances validate for arrays, and does not directly validate the immediate instance itself.
|
||||
* If "items" is an array of schemas, validation succeeds if every instance element
|
||||
* at a position greater than the size of "items" validates against "additionalItems".
|
||||
* Otherwise, "additionalItems" MUST be ignored, as the "items" schema
|
||||
* (possibly the default value of an empty schema) is applied to all elements.
|
||||
* Omitting this keyword has the same behavior as an empty schema.
|
||||
* @see https://tools.ietf.org/html/draft-wright-json-schema-validation-01#section-6.10
|
||||
*/
|
||||
additionalItems?: JSONSchema6Definition | undefined;
|
||||
|
||||
/**
|
||||
* Must be a non-negative integer.
|
||||
* An array instance is valid against "maxItems" if its size is less than, or equal to, the value of this keyword.
|
||||
* @see https://tools.ietf.org/html/draft-wright-json-schema-validation-01#section-6.11
|
||||
*/
|
||||
maxItems?: number | undefined;
|
||||
|
||||
/**
|
||||
* Must be a non-negative integer.
|
||||
* An array instance is valid against "maxItems" if its size is greater than, or equal to, the value of this keyword.
|
||||
* Omitting this keyword has the same behavior as a value of 0.
|
||||
* @see https://tools.ietf.org/html/draft-wright-json-schema-validation-01#section-6.12
|
||||
*/
|
||||
minItems?: number | undefined;
|
||||
|
||||
/**
|
||||
* If this keyword has boolean value false, the instance validates successfully.
|
||||
* If it has boolean value true, the instance validates successfully if all of its elements are unique.
|
||||
* Omitting this keyword has the same behavior as a value of false.
|
||||
* @see https://tools.ietf.org/html/draft-wright-json-schema-validation-01#section-6.13
|
||||
*/
|
||||
uniqueItems?: boolean | undefined;
|
||||
|
||||
/**
|
||||
* An array instance is valid against "contains" if at least one of its elements is valid against the given schema.
|
||||
* @see https://tools.ietf.org/html/draft-wright-json-schema-validation-01#section-6.14
|
||||
*/
|
||||
contains?: JSONSchema6Definition | undefined;
|
||||
|
||||
/**
|
||||
* Must be a non-negative integer.
|
||||
* An object instance is valid against "maxProperties" if its number of properties is less than, or equal to, the value of this keyword.
|
||||
* @see https://tools.ietf.org/html/draft-wright-json-schema-validation-01#section-6.15
|
||||
*/
|
||||
maxProperties?: number | undefined;
|
||||
|
||||
/**
|
||||
* Must be a non-negative integer.
|
||||
* An object instance is valid against "maxProperties" if its number of properties is greater than,
|
||||
* or equal to, the value of this keyword.
|
||||
* Omitting this keyword has the same behavior as a value of 0.
|
||||
* @see https://tools.ietf.org/html/draft-wright-json-schema-validation-01#section-6.16
|
||||
*/
|
||||
minProperties?: number | undefined;
|
||||
|
||||
/**
|
||||
* Elements of this array must be unique.
|
||||
* An object instance is valid against this keyword if every item in the array is the name of a property in the instance.
|
||||
* Omitting this keyword has the same behavior as an empty array.
|
||||
*
|
||||
* @see https://tools.ietf.org/html/draft-wright-json-schema-validation-01#section-6.17
|
||||
*/
|
||||
required?: string[] | undefined;
|
||||
|
||||
/**
|
||||
* This keyword determines how child instances validate for objects, and does not directly validate the immediate instance itself.
|
||||
* Validation succeeds if, for each name that appears in both the instance and as a name within this keyword's value,
|
||||
* the child instance for that name successfully validates against the corresponding schema.
|
||||
* Omitting this keyword has the same behavior as an empty object.
|
||||
* @see https://tools.ietf.org/html/draft-wright-json-schema-validation-01#section-6.18
|
||||
*/
|
||||
properties?: {
|
||||
[k: string]: JSONSchema6Definition;
|
||||
} | undefined;
|
||||
|
||||
/**
|
||||
* This attribute is an object that defines the schema for a set of property names of an object instance.
|
||||
* The name of each property of this attribute's object is a regular expression pattern in the ECMA 262, while the value is a schema.
|
||||
* If the pattern matches the name of a property on the instance object, the value of the instance's property
|
||||
* MUST be valid against the pattern name's schema value.
|
||||
* Omitting this keyword has the same behavior as an empty object.
|
||||
* @see https://tools.ietf.org/html/draft-wright-json-schema-validation-01#section-6.19
|
||||
*/
|
||||
patternProperties?: {
|
||||
[k: string]: JSONSchema6Definition;
|
||||
} | undefined;
|
||||
|
||||
/**
|
||||
* This attribute defines a schema for all properties that are not explicitly defined in an object type definition.
|
||||
* If specified, the value MUST be a schema or a boolean.
|
||||
* If false is provided, no additional properties are allowed beyond the properties defined in the schema.
|
||||
* The default value is an empty schema which allows any value for additional properties.
|
||||
* @see https://tools.ietf.org/html/draft-wright-json-schema-validation-01#section-6.20
|
||||
*/
|
||||
additionalProperties?: JSONSchema6Definition | undefined;
|
||||
|
||||
/**
|
||||
* This keyword specifies rules that are evaluated if the instance is an object and contains a certain property.
|
||||
* Each property specifies a dependency.
|
||||
* If the dependency value is an array, each element in the array must be unique.
|
||||
* Omitting this keyword has the same behavior as an empty object.
|
||||
* @see https://tools.ietf.org/html/draft-wright-json-schema-validation-01#section-6.21
|
||||
*/
|
||||
dependencies?: {
|
||||
[k: string]: JSONSchema6Definition | string[];
|
||||
} | undefined;
|
||||
|
||||
/**
|
||||
* Takes a schema which validates the names of all properties rather than their values.
|
||||
* Note the property name that the schema is testing will always be a string.
|
||||
* Omitting this keyword has the same behavior as an empty schema.
|
||||
* @see https://tools.ietf.org/html/draft-wright-json-schema-validation-01#section-6.22
|
||||
*/
|
||||
propertyNames?: JSONSchema6Definition | undefined;
|
||||
|
||||
/**
|
||||
* This provides an enumeration of all possible values that are valid
|
||||
* for the instance property. This MUST be an array, and each item in
|
||||
* the array represents a possible value for the instance value. If
|
||||
* this attribute is defined, the instance value MUST be one of the
|
||||
* values in the array in order for the schema to be valid.
|
||||
*
|
||||
* @see https://tools.ietf.org/html/draft-wright-json-schema-validation-01#section-6.23
|
||||
*/
|
||||
enum?: JSONSchema6Type[] | undefined;
|
||||
|
||||
/**
|
||||
* More readable form of a one-element "enum"
|
||||
* @see https://tools.ietf.org/html/draft-wright-json-schema-validation-01#section-6.24
|
||||
*/
|
||||
const?: JSONSchema6Type | undefined;
|
||||
|
||||
/**
|
||||
* A single type, or a union of simple types
|
||||
* @see https://tools.ietf.org/html/draft-wright-json-schema-validation-01#section-6.25
|
||||
*/
|
||||
type?: JSONSchema6TypeName | JSONSchema6TypeName[] | undefined;
|
||||
|
||||
/**
|
||||
* @see https://tools.ietf.org/html/draft-wright-json-schema-validation-01#section-6.26
|
||||
*/
|
||||
allOf?: JSONSchema6Definition[] | undefined;
|
||||
|
||||
/**
|
||||
* @see https://tools.ietf.org/html/draft-wright-json-schema-validation-01#section-6.27
|
||||
*/
|
||||
anyOf?: JSONSchema6Definition[] | undefined;
|
||||
|
||||
/**
|
||||
* @see https://tools.ietf.org/html/draft-wright-json-schema-validation-01#section-6.28
|
||||
*/
|
||||
oneOf?: JSONSchema6Definition[] | undefined;
|
||||
|
||||
/**
|
||||
* @see https://tools.ietf.org/html/draft-wright-json-schema-validation-01#section-6.29
|
||||
*/
|
||||
not?: JSONSchema6Definition | undefined;
|
||||
|
||||
/**
|
||||
* @see https://tools.ietf.org/html/draft-wright-json-schema-validation-01#section-7.1
|
||||
*/
|
||||
definitions?: {
|
||||
[k: string]: JSONSchema6Definition;
|
||||
} | undefined;
|
||||
|
||||
/**
|
||||
* This attribute is a string that provides a short description of the instance property.
|
||||
*
|
||||
* @see https://tools.ietf.org/html/draft-wright-json-schema-validation-01#section-7.2
|
||||
*/
|
||||
title?: string | undefined;
|
||||
|
||||
/**
|
||||
* This attribute is a string that provides a full description of the of purpose the instance property.
|
||||
*
|
||||
* @see https://tools.ietf.org/html/draft-wright-json-schema-validation-01#section-7.2
|
||||
*/
|
||||
description?: string | undefined;
|
||||
|
||||
/**
|
||||
* This keyword can be used to supply a default JSON value associated with a particular schema.
|
||||
* It is RECOMMENDED that a default value be valid against the associated schema.
|
||||
* @see https://tools.ietf.org/html/draft-wright-json-schema-validation-01#section-7.3
|
||||
*/
|
||||
default?: JSONSchema6Type | undefined;
|
||||
|
||||
/**
|
||||
* Array of examples with no validation effect the value of "default" is usable as an example without repeating it under this keyword
|
||||
* @see https://tools.ietf.org/html/draft-wright-json-schema-validation-01#section-7.4
|
||||
*/
|
||||
examples?: JSONSchema6Type[] | undefined;
|
||||
|
||||
/**
|
||||
* @see https://tools.ietf.org/html/draft-wright-json-schema-validation-01#section-8
|
||||
*/
|
||||
format?: string | undefined;
|
||||
}
|
||||
|
||||
// ==================================================================================================
|
||||
// JSON Schema Draft 07
|
||||
// ==================================================================================================
|
||||
// https://tools.ietf.org/html/draft-handrews-json-schema-validation-01
|
||||
// --------------------------------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Primitive type
|
||||
* @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.1.1
|
||||
*/
|
||||
export type JSONSchema7TypeName =
|
||||
| "string" //
|
||||
| "number"
|
||||
| "integer"
|
||||
| "boolean"
|
||||
| "object"
|
||||
| "array"
|
||||
| "null";
|
||||
|
||||
/**
|
||||
* Primitive type
|
||||
* @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.1.1
|
||||
*/
|
||||
export type JSONSchema7Type =
|
||||
| string //
|
||||
| number
|
||||
| boolean
|
||||
| JSONSchema7Object
|
||||
| JSONSchema7Array
|
||||
| null;
|
||||
|
||||
// Workaround for infinite type recursion
|
||||
export interface JSONSchema7Object {
|
||||
[key: string]: JSONSchema7Type;
|
||||
}
|
||||
|
||||
// Workaround for infinite type recursion
|
||||
// https://github.com/Microsoft/TypeScript/issues/3496#issuecomment-128553540
|
||||
export interface JSONSchema7Array extends Array<JSONSchema7Type> {}
|
||||
|
||||
/**
|
||||
* Meta schema
|
||||
*
|
||||
* Recommended values:
|
||||
* - 'http://json-schema.org/schema#'
|
||||
* - 'http://json-schema.org/hyper-schema#'
|
||||
* - 'http://json-schema.org/draft-07/schema#'
|
||||
* - 'http://json-schema.org/draft-07/hyper-schema#'
|
||||
*
|
||||
* @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-5
|
||||
*/
|
||||
export type JSONSchema7Version = string;
|
||||
|
||||
/**
|
||||
* JSON Schema v7
|
||||
* @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01
|
||||
*/
|
||||
export type JSONSchema7Definition = JSONSchema7 | boolean;
|
||||
export interface JSONSchema7 {
|
||||
$id?: string | undefined;
|
||||
$ref?: string | undefined;
|
||||
$schema?: JSONSchema7Version | undefined;
|
||||
$comment?: string | undefined;
|
||||
|
||||
/**
|
||||
* @see https://datatracker.ietf.org/doc/html/draft-bhutton-json-schema-00#section-8.2.4
|
||||
* @see https://datatracker.ietf.org/doc/html/draft-bhutton-json-schema-validation-00#appendix-A
|
||||
*/
|
||||
$defs?: {
|
||||
[key: string]: JSONSchema7Definition;
|
||||
} | undefined;
|
||||
|
||||
/**
|
||||
* @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.1
|
||||
*/
|
||||
type?: JSONSchema7TypeName | JSONSchema7TypeName[] | undefined;
|
||||
enum?: JSONSchema7Type[] | undefined;
|
||||
const?: JSONSchema7Type | undefined;
|
||||
|
||||
/**
|
||||
* @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.2
|
||||
*/
|
||||
multipleOf?: number | undefined;
|
||||
maximum?: number | undefined;
|
||||
exclusiveMaximum?: number | undefined;
|
||||
minimum?: number | undefined;
|
||||
exclusiveMinimum?: number | undefined;
|
||||
|
||||
/**
|
||||
* @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.3
|
||||
*/
|
||||
maxLength?: number | undefined;
|
||||
minLength?: number | undefined;
|
||||
pattern?: string | undefined;
|
||||
|
||||
/**
|
||||
* @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.4
|
||||
*/
|
||||
items?: JSONSchema7Definition | JSONSchema7Definition[] | undefined;
|
||||
additionalItems?: JSONSchema7Definition | undefined;
|
||||
maxItems?: number | undefined;
|
||||
minItems?: number | undefined;
|
||||
uniqueItems?: boolean | undefined;
|
||||
contains?: JSONSchema7Definition | undefined;
|
||||
|
||||
/**
|
||||
* @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.5
|
||||
*/
|
||||
maxProperties?: number | undefined;
|
||||
minProperties?: number | undefined;
|
||||
required?: string[] | undefined;
|
||||
properties?: {
|
||||
[key: string]: JSONSchema7Definition;
|
||||
} | undefined;
|
||||
patternProperties?: {
|
||||
[key: string]: JSONSchema7Definition;
|
||||
} | undefined;
|
||||
additionalProperties?: JSONSchema7Definition | undefined;
|
||||
dependencies?: {
|
||||
[key: string]: JSONSchema7Definition | string[];
|
||||
} | undefined;
|
||||
propertyNames?: JSONSchema7Definition | undefined;
|
||||
|
||||
/**
|
||||
* @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.6
|
||||
*/
|
||||
if?: JSONSchema7Definition | undefined;
|
||||
then?: JSONSchema7Definition | undefined;
|
||||
else?: JSONSchema7Definition | undefined;
|
||||
|
||||
/**
|
||||
* @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-6.7
|
||||
*/
|
||||
allOf?: JSONSchema7Definition[] | undefined;
|
||||
anyOf?: JSONSchema7Definition[] | undefined;
|
||||
oneOf?: JSONSchema7Definition[] | undefined;
|
||||
not?: JSONSchema7Definition | undefined;
|
||||
|
||||
/**
|
||||
* @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-7
|
||||
*/
|
||||
format?: string | undefined;
|
||||
|
||||
/**
|
||||
* @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-8
|
||||
*/
|
||||
contentMediaType?: string | undefined;
|
||||
contentEncoding?: string | undefined;
|
||||
|
||||
/**
|
||||
* @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-9
|
||||
*/
|
||||
definitions?: {
|
||||
[key: string]: JSONSchema7Definition;
|
||||
} | undefined;
|
||||
|
||||
/**
|
||||
* @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-10
|
||||
*/
|
||||
title?: string | undefined;
|
||||
description?: string | undefined;
|
||||
default?: JSONSchema7Type | undefined;
|
||||
readOnly?: boolean | undefined;
|
||||
writeOnly?: boolean | undefined;
|
||||
examples?: JSONSchema7Type | undefined;
|
||||
}
|
||||
|
||||
export interface ValidationResult {
|
||||
valid: boolean;
|
||||
errors: ValidationError[];
|
||||
}
|
||||
|
||||
export interface ValidationError {
|
||||
property: string;
|
||||
message: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* To use the validator call JSONSchema.validate with an instance object and an optional schema object.
|
||||
* If a schema is provided, it will be used to validate. If the instance object refers to a schema (self-validating),
|
||||
* that schema will be used to validate and the schema parameter is not necessary (if both exist,
|
||||
* both validations will occur).
|
||||
*/
|
||||
export function validate(instance: {}, schema: JSONSchema4 | JSONSchema6 | JSONSchema7): ValidationResult;
|
||||
|
||||
/**
|
||||
* The checkPropertyChange method will check to see if an value can legally be in property with the given schema
|
||||
* This is slightly different than the validate method in that it will fail if the schema is readonly and it will
|
||||
* not check for self-validation, it is assumed that the passed in value is already internally valid.
|
||||
*/
|
||||
export function checkPropertyChange(
|
||||
value: any,
|
||||
schema: JSONSchema4 | JSONSchema6 | JSONSchema7,
|
||||
property: string,
|
||||
): ValidationResult;
|
||||
|
||||
/**
|
||||
* This checks to ensure that the result is valid and will throw an appropriate error message if it is not.
|
||||
*/
|
||||
export function mustBeValid(result: ValidationResult): void;
|
||||
@@ -0,0 +1,17 @@
|
||||
export default class Ref {
|
||||
num: number;
|
||||
gen: number;
|
||||
|
||||
constructor({ num, gen }: { num: number; gen: number }) {
|
||||
this.num = num;
|
||||
this.gen = gen;
|
||||
}
|
||||
|
||||
toString(): string {
|
||||
let str = `${this.num}R`;
|
||||
if (this.gen !== 0) {
|
||||
str += this.gen;
|
||||
}
|
||||
return str;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
import type * as React from 'react';
|
||||
|
||||
/**
|
||||
* A function that merges React refs into one.
|
||||
* Supports both functions and ref objects created using createRef() and useRef().
|
||||
*
|
||||
* Usage:
|
||||
* ```tsx
|
||||
* <div ref={mergeRefs(ref1, ref2, ref3)} />
|
||||
* ```
|
||||
*
|
||||
* @param {(React.Ref<T> | undefined)[]} inputRefs Array of refs
|
||||
* @returns {React.Ref<T> | React.RefCallback<T>} Merged refs
|
||||
*/
|
||||
export default function mergeRefs<T>(
|
||||
...inputRefs: (React.Ref<T> | undefined)[]
|
||||
): React.Ref<T> | React.RefCallback<T> {
|
||||
const filteredInputRefs = inputRefs.filter(Boolean);
|
||||
|
||||
if (filteredInputRefs.length <= 1) {
|
||||
const firstRef = filteredInputRefs[0];
|
||||
|
||||
return firstRef || null;
|
||||
}
|
||||
|
||||
return function mergedRefs(ref) {
|
||||
filteredInputRefs.forEach((inputRef) => {
|
||||
if (typeof inputRef === 'function') {
|
||||
inputRef(ref);
|
||||
} else if (inputRef) {
|
||||
(inputRef as React.MutableRefObject<T | null>).current = ref;
|
||||
}
|
||||
});
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
# ieee754 [![travis][travis-image]][travis-url] [![npm][npm-image]][npm-url] [![downloads][downloads-image]][downloads-url] [![javascript style guide][standard-image]][standard-url]
|
||||
|
||||
[travis-image]: https://img.shields.io/travis/feross/ieee754/master.svg
|
||||
[travis-url]: https://travis-ci.org/feross/ieee754
|
||||
[npm-image]: https://img.shields.io/npm/v/ieee754.svg
|
||||
[npm-url]: https://npmjs.org/package/ieee754
|
||||
[downloads-image]: https://img.shields.io/npm/dm/ieee754.svg
|
||||
[downloads-url]: https://npmjs.org/package/ieee754
|
||||
[standard-image]: https://img.shields.io/badge/code_style-standard-brightgreen.svg
|
||||
[standard-url]: https://standardjs.com
|
||||
|
||||
[![saucelabs][saucelabs-image]][saucelabs-url]
|
||||
|
||||
[saucelabs-image]: https://saucelabs.com/browser-matrix/ieee754.svg
|
||||
[saucelabs-url]: https://saucelabs.com/u/ieee754
|
||||
|
||||
### Read/write IEEE754 floating point numbers from/to a Buffer or array-like object.
|
||||
|
||||
## install
|
||||
|
||||
```
|
||||
npm install ieee754
|
||||
```
|
||||
|
||||
## methods
|
||||
|
||||
`var ieee754 = require('ieee754')`
|
||||
|
||||
The `ieee754` object has the following functions:
|
||||
|
||||
```
|
||||
ieee754.read = function (buffer, offset, isLE, mLen, nBytes)
|
||||
ieee754.write = function (buffer, value, offset, isLE, mLen, nBytes)
|
||||
```
|
||||
|
||||
The arguments mean the following:
|
||||
|
||||
- buffer = the buffer
|
||||
- offset = offset into the buffer
|
||||
- value = value to set (only for `write`)
|
||||
- isLe = is little endian?
|
||||
- mLen = mantissa length
|
||||
- nBytes = number of bytes
|
||||
|
||||
## what is ieee754?
|
||||
|
||||
The IEEE Standard for Floating-Point Arithmetic (IEEE 754) is a technical standard for floating-point computation. [Read more](http://en.wikipedia.org/wiki/IEEE_floating_point).
|
||||
|
||||
## license
|
||||
|
||||
BSD 3 Clause. Copyright (c) 2008, Fair Oaks Labs, Inc.
|
||||
@@ -0,0 +1 @@
|
||||
module.exports={A:{A:{"1":"A B","132":"K D E F mC"},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 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","2":"nC LC","257":"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 qC rC"},D:{"1":"0 1 2 3 4 5 6 7 8 9 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 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","2":"J PB K D"},E:{"1":"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","2":"J 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","2":"F B C 4C 5C 6C 7C FC kC 8C GC"},G:{"1":"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","2":"SC 9C lC"},H:{"2":"WD"},I:{"1":"LC J I aD lC bD cD","2":"XD YD ZD"},J:{"1":"D A"},K:{"1":"H","2":"A B C FC kC GC"},L:{"1":"I"},M:{"1":"EC"},N:{"1":"A B"},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":"qD rD"}},B:1,C:"defer attribute for external scripts",D:true};
|
||||
@@ -0,0 +1 @@
|
||||
module.exports={A:{A:{"2":"K D E F A B mC"},B:{"2":"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:{"2":"0 1 2 3 4 5 6 7 8 9 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 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 qC rC"},D:{"2":"0 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 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","66":"1 2 3 4 5 6 7"},E:{"2":"J PB K E F A B C L M G sC SC tC uC 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","130":"D vC"},F:{"2":"0 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 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"},G:{"2":"E SC 9C lC AD BD 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","130":"CD"},H:{"2":"WD"},I:{"2":"LC J I XD YD ZD aD lC bD cD"},J:{"2":"D A"},K:{"2":"A B C H FC kC GC"},L:{"2":"I"},M:{"2":"EC"},N:{"2":"A B"},O:{"2":"HC"},P:{"2":"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:{"2":"oD"},R:{"2":"pD"},S:{"2":"qD rD"}},B:7,C:"seamless attribute for iframes",D:true};
|
||||
@@ -0,0 +1,7 @@
|
||||
'use strict';
|
||||
|
||||
if (process.env.NODE_ENV === 'production') {
|
||||
module.exports = require('./cjs/react-jsx-dev-runtime.production.js');
|
||||
} else {
|
||||
module.exports = require('./cjs/react-jsx-dev-runtime.development.js');
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
'use strict'
|
||||
|
||||
/*!
|
||||
* Canvas - PDFStream
|
||||
*/
|
||||
|
||||
const { Readable } = require('stream')
|
||||
function noop () {}
|
||||
|
||||
class PDFStream extends Readable {
|
||||
constructor (canvas, options) {
|
||||
super()
|
||||
|
||||
this.canvas = canvas
|
||||
this.options = options
|
||||
}
|
||||
|
||||
_read () {
|
||||
// For now we're not controlling the c++ code's data emission, so we only
|
||||
// call canvas.streamPDFSync once and let it emit data at will.
|
||||
this._read = noop
|
||||
|
||||
this.canvas.streamPDFSync((err, chunk, len) => {
|
||||
if (err) {
|
||||
this.emit('error', err)
|
||||
} else if (len) {
|
||||
this.push(chunk)
|
||||
} else {
|
||||
this.push(null)
|
||||
}
|
||||
}, this.options)
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = PDFStream
|
||||
@@ -0,0 +1,76 @@
|
||||
/**
|
||||
* @fileoverview Define the abstract class about cursors which iterate tokens.
|
||||
* @author Toru Nagashima
|
||||
*/
|
||||
"use strict";
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Exports
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* The abstract class about cursors which iterate tokens.
|
||||
*
|
||||
* This class has 2 abstract methods.
|
||||
*
|
||||
* - `current: Token | Comment | null` ... The current token.
|
||||
* - `moveNext(): boolean` ... Moves this cursor to the next token. If the next token didn't exist, it returns `false`.
|
||||
*
|
||||
* This is similar to ES2015 Iterators.
|
||||
* However, Iterators were slow (at 2017-01), so I created this class as similar to C# IEnumerable.
|
||||
*
|
||||
* There are the following known sub classes.
|
||||
*
|
||||
* - ForwardTokenCursor .......... The cursor which iterates tokens only.
|
||||
* - BackwardTokenCursor ......... The cursor which iterates tokens only in reverse.
|
||||
* - ForwardTokenCommentCursor ... The cursor which iterates tokens and comments.
|
||||
* - BackwardTokenCommentCursor .. The cursor which iterates tokens and comments in reverse.
|
||||
* - DecorativeCursor
|
||||
* - FilterCursor ............ The cursor which ignores the specified tokens.
|
||||
* - SkipCursor .............. The cursor which ignores the first few tokens.
|
||||
* - LimitCursor ............. The cursor which limits the count of tokens.
|
||||
*
|
||||
*/
|
||||
module.exports = class Cursor {
|
||||
/**
|
||||
* Initializes this cursor.
|
||||
*/
|
||||
constructor() {
|
||||
this.current = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the first token.
|
||||
* This consumes this cursor.
|
||||
* @returns {Token|Comment} The first token or null.
|
||||
*/
|
||||
getOneToken() {
|
||||
return this.moveNext() ? this.current : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the first tokens.
|
||||
* This consumes this cursor.
|
||||
* @returns {(Token|Comment)[]} All tokens.
|
||||
*/
|
||||
getAllTokens() {
|
||||
const tokens = [];
|
||||
|
||||
while (this.moveNext()) {
|
||||
tokens.push(this.current);
|
||||
}
|
||||
|
||||
return tokens;
|
||||
}
|
||||
|
||||
/**
|
||||
* Moves this cursor to the next token.
|
||||
* @returns {boolean} `true` if the next token exists.
|
||||
* @abstract
|
||||
*/
|
||||
/* c8 ignore next */
|
||||
// eslint-disable-next-line class-methods-use-this -- Unused
|
||||
moveNext() {
|
||||
throw new Error("Not implemented.");
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,641 @@
|
||||
// Copyright Joyent, Inc. and other Node contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a
|
||||
// copy of this software and associated documentation files (the
|
||||
// "Software"), to deal in the Software without restriction, including
|
||||
// without limitation the rights to use, copy, modify, merge, publish,
|
||||
// distribute, sublicense, and/or sell copies of the Software, and to permit
|
||||
// persons to whom the Software is furnished to do so, subject to the
|
||||
// following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included
|
||||
// in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
|
||||
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
||||
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
|
||||
// USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
// A bit simpler than readable streams.
|
||||
// Implement an async ._write(chunk, encoding, cb), and it'll handle all
|
||||
// the drain event emission and buffering.
|
||||
|
||||
'use strict';
|
||||
|
||||
module.exports = Writable;
|
||||
|
||||
/* <replacement> */
|
||||
function WriteReq(chunk, encoding, cb) {
|
||||
this.chunk = chunk;
|
||||
this.encoding = encoding;
|
||||
this.callback = cb;
|
||||
this.next = null;
|
||||
}
|
||||
|
||||
// It seems a linked list but it is not
|
||||
// there will be only 2 of these for each stream
|
||||
function CorkedRequest(state) {
|
||||
var _this = this;
|
||||
this.next = null;
|
||||
this.entry = null;
|
||||
this.finish = function () {
|
||||
onCorkedFinish(_this, state);
|
||||
};
|
||||
}
|
||||
/* </replacement> */
|
||||
|
||||
/*<replacement>*/
|
||||
var Duplex;
|
||||
/*</replacement>*/
|
||||
|
||||
Writable.WritableState = WritableState;
|
||||
|
||||
/*<replacement>*/
|
||||
var internalUtil = {
|
||||
deprecate: require('util-deprecate')
|
||||
};
|
||||
/*</replacement>*/
|
||||
|
||||
/*<replacement>*/
|
||||
var Stream = require('./internal/streams/stream');
|
||||
/*</replacement>*/
|
||||
|
||||
var Buffer = require('buffer').Buffer;
|
||||
var OurUint8Array = (typeof global !== 'undefined' ? global : typeof window !== 'undefined' ? window : typeof self !== 'undefined' ? self : {}).Uint8Array || function () {};
|
||||
function _uint8ArrayToBuffer(chunk) {
|
||||
return Buffer.from(chunk);
|
||||
}
|
||||
function _isUint8Array(obj) {
|
||||
return Buffer.isBuffer(obj) || obj instanceof OurUint8Array;
|
||||
}
|
||||
var destroyImpl = require('./internal/streams/destroy');
|
||||
var _require = require('./internal/streams/state'),
|
||||
getHighWaterMark = _require.getHighWaterMark;
|
||||
var _require$codes = require('../errors').codes,
|
||||
ERR_INVALID_ARG_TYPE = _require$codes.ERR_INVALID_ARG_TYPE,
|
||||
ERR_METHOD_NOT_IMPLEMENTED = _require$codes.ERR_METHOD_NOT_IMPLEMENTED,
|
||||
ERR_MULTIPLE_CALLBACK = _require$codes.ERR_MULTIPLE_CALLBACK,
|
||||
ERR_STREAM_CANNOT_PIPE = _require$codes.ERR_STREAM_CANNOT_PIPE,
|
||||
ERR_STREAM_DESTROYED = _require$codes.ERR_STREAM_DESTROYED,
|
||||
ERR_STREAM_NULL_VALUES = _require$codes.ERR_STREAM_NULL_VALUES,
|
||||
ERR_STREAM_WRITE_AFTER_END = _require$codes.ERR_STREAM_WRITE_AFTER_END,
|
||||
ERR_UNKNOWN_ENCODING = _require$codes.ERR_UNKNOWN_ENCODING;
|
||||
var errorOrDestroy = destroyImpl.errorOrDestroy;
|
||||
require('inherits')(Writable, Stream);
|
||||
function nop() {}
|
||||
function WritableState(options, stream, isDuplex) {
|
||||
Duplex = Duplex || require('./_stream_duplex');
|
||||
options = options || {};
|
||||
|
||||
// Duplex streams are both readable and writable, but share
|
||||
// the same options object.
|
||||
// However, some cases require setting options to different
|
||||
// values for the readable and the writable sides of the duplex stream,
|
||||
// e.g. options.readableObjectMode vs. options.writableObjectMode, etc.
|
||||
if (typeof isDuplex !== 'boolean') isDuplex = stream instanceof Duplex;
|
||||
|
||||
// object stream flag to indicate whether or not this stream
|
||||
// contains buffers or objects.
|
||||
this.objectMode = !!options.objectMode;
|
||||
if (isDuplex) this.objectMode = this.objectMode || !!options.writableObjectMode;
|
||||
|
||||
// the point at which write() starts returning false
|
||||
// Note: 0 is a valid value, means that we always return false if
|
||||
// the entire buffer is not flushed immediately on write()
|
||||
this.highWaterMark = getHighWaterMark(this, options, 'writableHighWaterMark', isDuplex);
|
||||
|
||||
// if _final has been called
|
||||
this.finalCalled = false;
|
||||
|
||||
// drain event flag.
|
||||
this.needDrain = false;
|
||||
// at the start of calling end()
|
||||
this.ending = false;
|
||||
// when end() has been called, and returned
|
||||
this.ended = false;
|
||||
// when 'finish' is emitted
|
||||
this.finished = false;
|
||||
|
||||
// has it been destroyed
|
||||
this.destroyed = false;
|
||||
|
||||
// should we decode strings into buffers before passing to _write?
|
||||
// this is here so that some node-core streams can optimize string
|
||||
// handling at a lower level.
|
||||
var noDecode = options.decodeStrings === false;
|
||||
this.decodeStrings = !noDecode;
|
||||
|
||||
// Crypto is kind of old and crusty. Historically, its default string
|
||||
// encoding is 'binary' so we have to make this configurable.
|
||||
// Everything else in the universe uses 'utf8', though.
|
||||
this.defaultEncoding = options.defaultEncoding || 'utf8';
|
||||
|
||||
// not an actual buffer we keep track of, but a measurement
|
||||
// of how much we're waiting to get pushed to some underlying
|
||||
// socket or file.
|
||||
this.length = 0;
|
||||
|
||||
// a flag to see when we're in the middle of a write.
|
||||
this.writing = false;
|
||||
|
||||
// when true all writes will be buffered until .uncork() call
|
||||
this.corked = 0;
|
||||
|
||||
// a flag to be able to tell if the onwrite cb is called immediately,
|
||||
// or on a later tick. We set this to true at first, because any
|
||||
// actions that shouldn't happen until "later" should generally also
|
||||
// not happen before the first write call.
|
||||
this.sync = true;
|
||||
|
||||
// a flag to know if we're processing previously buffered items, which
|
||||
// may call the _write() callback in the same tick, so that we don't
|
||||
// end up in an overlapped onwrite situation.
|
||||
this.bufferProcessing = false;
|
||||
|
||||
// the callback that's passed to _write(chunk,cb)
|
||||
this.onwrite = function (er) {
|
||||
onwrite(stream, er);
|
||||
};
|
||||
|
||||
// the callback that the user supplies to write(chunk,encoding,cb)
|
||||
this.writecb = null;
|
||||
|
||||
// the amount that is being written when _write is called.
|
||||
this.writelen = 0;
|
||||
this.bufferedRequest = null;
|
||||
this.lastBufferedRequest = null;
|
||||
|
||||
// number of pending user-supplied write callbacks
|
||||
// this must be 0 before 'finish' can be emitted
|
||||
this.pendingcb = 0;
|
||||
|
||||
// emit prefinish if the only thing we're waiting for is _write cbs
|
||||
// This is relevant for synchronous Transform streams
|
||||
this.prefinished = false;
|
||||
|
||||
// True if the error was already emitted and should not be thrown again
|
||||
this.errorEmitted = false;
|
||||
|
||||
// Should close be emitted on destroy. Defaults to true.
|
||||
this.emitClose = options.emitClose !== false;
|
||||
|
||||
// Should .destroy() be called after 'finish' (and potentially 'end')
|
||||
this.autoDestroy = !!options.autoDestroy;
|
||||
|
||||
// count buffered requests
|
||||
this.bufferedRequestCount = 0;
|
||||
|
||||
// allocate the first CorkedRequest, there is always
|
||||
// one allocated and free to use, and we maintain at most two
|
||||
this.corkedRequestsFree = new CorkedRequest(this);
|
||||
}
|
||||
WritableState.prototype.getBuffer = function getBuffer() {
|
||||
var current = this.bufferedRequest;
|
||||
var out = [];
|
||||
while (current) {
|
||||
out.push(current);
|
||||
current = current.next;
|
||||
}
|
||||
return out;
|
||||
};
|
||||
(function () {
|
||||
try {
|
||||
Object.defineProperty(WritableState.prototype, 'buffer', {
|
||||
get: internalUtil.deprecate(function writableStateBufferGetter() {
|
||||
return this.getBuffer();
|
||||
}, '_writableState.buffer is deprecated. Use _writableState.getBuffer ' + 'instead.', 'DEP0003')
|
||||
});
|
||||
} catch (_) {}
|
||||
})();
|
||||
|
||||
// Test _writableState for inheritance to account for Duplex streams,
|
||||
// whose prototype chain only points to Readable.
|
||||
var realHasInstance;
|
||||
if (typeof Symbol === 'function' && Symbol.hasInstance && typeof Function.prototype[Symbol.hasInstance] === 'function') {
|
||||
realHasInstance = Function.prototype[Symbol.hasInstance];
|
||||
Object.defineProperty(Writable, Symbol.hasInstance, {
|
||||
value: function value(object) {
|
||||
if (realHasInstance.call(this, object)) return true;
|
||||
if (this !== Writable) return false;
|
||||
return object && object._writableState instanceof WritableState;
|
||||
}
|
||||
});
|
||||
} else {
|
||||
realHasInstance = function realHasInstance(object) {
|
||||
return object instanceof this;
|
||||
};
|
||||
}
|
||||
function Writable(options) {
|
||||
Duplex = Duplex || require('./_stream_duplex');
|
||||
|
||||
// Writable ctor is applied to Duplexes, too.
|
||||
// `realHasInstance` is necessary because using plain `instanceof`
|
||||
// would return false, as no `_writableState` property is attached.
|
||||
|
||||
// Trying to use the custom `instanceof` for Writable here will also break the
|
||||
// Node.js LazyTransform implementation, which has a non-trivial getter for
|
||||
// `_writableState` that would lead to infinite recursion.
|
||||
|
||||
// Checking for a Stream.Duplex instance is faster here instead of inside
|
||||
// the WritableState constructor, at least with V8 6.5
|
||||
var isDuplex = this instanceof Duplex;
|
||||
if (!isDuplex && !realHasInstance.call(Writable, this)) return new Writable(options);
|
||||
this._writableState = new WritableState(options, this, isDuplex);
|
||||
|
||||
// legacy.
|
||||
this.writable = true;
|
||||
if (options) {
|
||||
if (typeof options.write === 'function') this._write = options.write;
|
||||
if (typeof options.writev === 'function') this._writev = options.writev;
|
||||
if (typeof options.destroy === 'function') this._destroy = options.destroy;
|
||||
if (typeof options.final === 'function') this._final = options.final;
|
||||
}
|
||||
Stream.call(this);
|
||||
}
|
||||
|
||||
// Otherwise people can pipe Writable streams, which is just wrong.
|
||||
Writable.prototype.pipe = function () {
|
||||
errorOrDestroy(this, new ERR_STREAM_CANNOT_PIPE());
|
||||
};
|
||||
function writeAfterEnd(stream, cb) {
|
||||
var er = new ERR_STREAM_WRITE_AFTER_END();
|
||||
// TODO: defer error events consistently everywhere, not just the cb
|
||||
errorOrDestroy(stream, er);
|
||||
process.nextTick(cb, er);
|
||||
}
|
||||
|
||||
// Checks that a user-supplied chunk is valid, especially for the particular
|
||||
// mode the stream is in. Currently this means that `null` is never accepted
|
||||
// and undefined/non-string values are only allowed in object mode.
|
||||
function validChunk(stream, state, chunk, cb) {
|
||||
var er;
|
||||
if (chunk === null) {
|
||||
er = new ERR_STREAM_NULL_VALUES();
|
||||
} else if (typeof chunk !== 'string' && !state.objectMode) {
|
||||
er = new ERR_INVALID_ARG_TYPE('chunk', ['string', 'Buffer'], chunk);
|
||||
}
|
||||
if (er) {
|
||||
errorOrDestroy(stream, er);
|
||||
process.nextTick(cb, er);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
Writable.prototype.write = function (chunk, encoding, cb) {
|
||||
var state = this._writableState;
|
||||
var ret = false;
|
||||
var isBuf = !state.objectMode && _isUint8Array(chunk);
|
||||
if (isBuf && !Buffer.isBuffer(chunk)) {
|
||||
chunk = _uint8ArrayToBuffer(chunk);
|
||||
}
|
||||
if (typeof encoding === 'function') {
|
||||
cb = encoding;
|
||||
encoding = null;
|
||||
}
|
||||
if (isBuf) encoding = 'buffer';else if (!encoding) encoding = state.defaultEncoding;
|
||||
if (typeof cb !== 'function') cb = nop;
|
||||
if (state.ending) writeAfterEnd(this, cb);else if (isBuf || validChunk(this, state, chunk, cb)) {
|
||||
state.pendingcb++;
|
||||
ret = writeOrBuffer(this, state, isBuf, chunk, encoding, cb);
|
||||
}
|
||||
return ret;
|
||||
};
|
||||
Writable.prototype.cork = function () {
|
||||
this._writableState.corked++;
|
||||
};
|
||||
Writable.prototype.uncork = function () {
|
||||
var state = this._writableState;
|
||||
if (state.corked) {
|
||||
state.corked--;
|
||||
if (!state.writing && !state.corked && !state.bufferProcessing && state.bufferedRequest) clearBuffer(this, state);
|
||||
}
|
||||
};
|
||||
Writable.prototype.setDefaultEncoding = function setDefaultEncoding(encoding) {
|
||||
// node::ParseEncoding() requires lower case.
|
||||
if (typeof encoding === 'string') encoding = encoding.toLowerCase();
|
||||
if (!(['hex', 'utf8', 'utf-8', 'ascii', 'binary', 'base64', 'ucs2', 'ucs-2', 'utf16le', 'utf-16le', 'raw'].indexOf((encoding + '').toLowerCase()) > -1)) throw new ERR_UNKNOWN_ENCODING(encoding);
|
||||
this._writableState.defaultEncoding = encoding;
|
||||
return this;
|
||||
};
|
||||
Object.defineProperty(Writable.prototype, 'writableBuffer', {
|
||||
// making it explicit this property is not enumerable
|
||||
// because otherwise some prototype manipulation in
|
||||
// userland will fail
|
||||
enumerable: false,
|
||||
get: function get() {
|
||||
return this._writableState && this._writableState.getBuffer();
|
||||
}
|
||||
});
|
||||
function decodeChunk(state, chunk, encoding) {
|
||||
if (!state.objectMode && state.decodeStrings !== false && typeof chunk === 'string') {
|
||||
chunk = Buffer.from(chunk, encoding);
|
||||
}
|
||||
return chunk;
|
||||
}
|
||||
Object.defineProperty(Writable.prototype, 'writableHighWaterMark', {
|
||||
// making it explicit this property is not enumerable
|
||||
// because otherwise some prototype manipulation in
|
||||
// userland will fail
|
||||
enumerable: false,
|
||||
get: function get() {
|
||||
return this._writableState.highWaterMark;
|
||||
}
|
||||
});
|
||||
|
||||
// if we're already writing something, then just put this
|
||||
// in the queue, and wait our turn. Otherwise, call _write
|
||||
// If we return false, then we need a drain event, so set that flag.
|
||||
function writeOrBuffer(stream, state, isBuf, chunk, encoding, cb) {
|
||||
if (!isBuf) {
|
||||
var newChunk = decodeChunk(state, chunk, encoding);
|
||||
if (chunk !== newChunk) {
|
||||
isBuf = true;
|
||||
encoding = 'buffer';
|
||||
chunk = newChunk;
|
||||
}
|
||||
}
|
||||
var len = state.objectMode ? 1 : chunk.length;
|
||||
state.length += len;
|
||||
var ret = state.length < state.highWaterMark;
|
||||
// we must ensure that previous needDrain will not be reset to false.
|
||||
if (!ret) state.needDrain = true;
|
||||
if (state.writing || state.corked) {
|
||||
var last = state.lastBufferedRequest;
|
||||
state.lastBufferedRequest = {
|
||||
chunk: chunk,
|
||||
encoding: encoding,
|
||||
isBuf: isBuf,
|
||||
callback: cb,
|
||||
next: null
|
||||
};
|
||||
if (last) {
|
||||
last.next = state.lastBufferedRequest;
|
||||
} else {
|
||||
state.bufferedRequest = state.lastBufferedRequest;
|
||||
}
|
||||
state.bufferedRequestCount += 1;
|
||||
} else {
|
||||
doWrite(stream, state, false, len, chunk, encoding, cb);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
function doWrite(stream, state, writev, len, chunk, encoding, cb) {
|
||||
state.writelen = len;
|
||||
state.writecb = cb;
|
||||
state.writing = true;
|
||||
state.sync = true;
|
||||
if (state.destroyed) state.onwrite(new ERR_STREAM_DESTROYED('write'));else if (writev) stream._writev(chunk, state.onwrite);else stream._write(chunk, encoding, state.onwrite);
|
||||
state.sync = false;
|
||||
}
|
||||
function onwriteError(stream, state, sync, er, cb) {
|
||||
--state.pendingcb;
|
||||
if (sync) {
|
||||
// defer the callback if we are being called synchronously
|
||||
// to avoid piling up things on the stack
|
||||
process.nextTick(cb, er);
|
||||
// this can emit finish, and it will always happen
|
||||
// after error
|
||||
process.nextTick(finishMaybe, stream, state);
|
||||
stream._writableState.errorEmitted = true;
|
||||
errorOrDestroy(stream, er);
|
||||
} else {
|
||||
// the caller expect this to happen before if
|
||||
// it is async
|
||||
cb(er);
|
||||
stream._writableState.errorEmitted = true;
|
||||
errorOrDestroy(stream, er);
|
||||
// this can emit finish, but finish must
|
||||
// always follow error
|
||||
finishMaybe(stream, state);
|
||||
}
|
||||
}
|
||||
function onwriteStateUpdate(state) {
|
||||
state.writing = false;
|
||||
state.writecb = null;
|
||||
state.length -= state.writelen;
|
||||
state.writelen = 0;
|
||||
}
|
||||
function onwrite(stream, er) {
|
||||
var state = stream._writableState;
|
||||
var sync = state.sync;
|
||||
var cb = state.writecb;
|
||||
if (typeof cb !== 'function') throw new ERR_MULTIPLE_CALLBACK();
|
||||
onwriteStateUpdate(state);
|
||||
if (er) onwriteError(stream, state, sync, er, cb);else {
|
||||
// Check if we're actually ready to finish, but don't emit yet
|
||||
var finished = needFinish(state) || stream.destroyed;
|
||||
if (!finished && !state.corked && !state.bufferProcessing && state.bufferedRequest) {
|
||||
clearBuffer(stream, state);
|
||||
}
|
||||
if (sync) {
|
||||
process.nextTick(afterWrite, stream, state, finished, cb);
|
||||
} else {
|
||||
afterWrite(stream, state, finished, cb);
|
||||
}
|
||||
}
|
||||
}
|
||||
function afterWrite(stream, state, finished, cb) {
|
||||
if (!finished) onwriteDrain(stream, state);
|
||||
state.pendingcb--;
|
||||
cb();
|
||||
finishMaybe(stream, state);
|
||||
}
|
||||
|
||||
// Must force callback to be called on nextTick, so that we don't
|
||||
// emit 'drain' before the write() consumer gets the 'false' return
|
||||
// value, and has a chance to attach a 'drain' listener.
|
||||
function onwriteDrain(stream, state) {
|
||||
if (state.length === 0 && state.needDrain) {
|
||||
state.needDrain = false;
|
||||
stream.emit('drain');
|
||||
}
|
||||
}
|
||||
|
||||
// if there's something in the buffer waiting, then process it
|
||||
function clearBuffer(stream, state) {
|
||||
state.bufferProcessing = true;
|
||||
var entry = state.bufferedRequest;
|
||||
if (stream._writev && entry && entry.next) {
|
||||
// Fast case, write everything using _writev()
|
||||
var l = state.bufferedRequestCount;
|
||||
var buffer = new Array(l);
|
||||
var holder = state.corkedRequestsFree;
|
||||
holder.entry = entry;
|
||||
var count = 0;
|
||||
var allBuffers = true;
|
||||
while (entry) {
|
||||
buffer[count] = entry;
|
||||
if (!entry.isBuf) allBuffers = false;
|
||||
entry = entry.next;
|
||||
count += 1;
|
||||
}
|
||||
buffer.allBuffers = allBuffers;
|
||||
doWrite(stream, state, true, state.length, buffer, '', holder.finish);
|
||||
|
||||
// doWrite is almost always async, defer these to save a bit of time
|
||||
// as the hot path ends with doWrite
|
||||
state.pendingcb++;
|
||||
state.lastBufferedRequest = null;
|
||||
if (holder.next) {
|
||||
state.corkedRequestsFree = holder.next;
|
||||
holder.next = null;
|
||||
} else {
|
||||
state.corkedRequestsFree = new CorkedRequest(state);
|
||||
}
|
||||
state.bufferedRequestCount = 0;
|
||||
} else {
|
||||
// Slow case, write chunks one-by-one
|
||||
while (entry) {
|
||||
var chunk = entry.chunk;
|
||||
var encoding = entry.encoding;
|
||||
var cb = entry.callback;
|
||||
var len = state.objectMode ? 1 : chunk.length;
|
||||
doWrite(stream, state, false, len, chunk, encoding, cb);
|
||||
entry = entry.next;
|
||||
state.bufferedRequestCount--;
|
||||
// if we didn't call the onwrite immediately, then
|
||||
// it means that we need to wait until it does.
|
||||
// also, that means that the chunk and cb are currently
|
||||
// being processed, so move the buffer counter past them.
|
||||
if (state.writing) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (entry === null) state.lastBufferedRequest = null;
|
||||
}
|
||||
state.bufferedRequest = entry;
|
||||
state.bufferProcessing = false;
|
||||
}
|
||||
Writable.prototype._write = function (chunk, encoding, cb) {
|
||||
cb(new ERR_METHOD_NOT_IMPLEMENTED('_write()'));
|
||||
};
|
||||
Writable.prototype._writev = null;
|
||||
Writable.prototype.end = function (chunk, encoding, cb) {
|
||||
var state = this._writableState;
|
||||
if (typeof chunk === 'function') {
|
||||
cb = chunk;
|
||||
chunk = null;
|
||||
encoding = null;
|
||||
} else if (typeof encoding === 'function') {
|
||||
cb = encoding;
|
||||
encoding = null;
|
||||
}
|
||||
if (chunk !== null && chunk !== undefined) this.write(chunk, encoding);
|
||||
|
||||
// .end() fully uncorks
|
||||
if (state.corked) {
|
||||
state.corked = 1;
|
||||
this.uncork();
|
||||
}
|
||||
|
||||
// ignore unnecessary end() calls.
|
||||
if (!state.ending) endWritable(this, state, cb);
|
||||
return this;
|
||||
};
|
||||
Object.defineProperty(Writable.prototype, 'writableLength', {
|
||||
// making it explicit this property is not enumerable
|
||||
// because otherwise some prototype manipulation in
|
||||
// userland will fail
|
||||
enumerable: false,
|
||||
get: function get() {
|
||||
return this._writableState.length;
|
||||
}
|
||||
});
|
||||
function needFinish(state) {
|
||||
return state.ending && state.length === 0 && state.bufferedRequest === null && !state.finished && !state.writing;
|
||||
}
|
||||
function callFinal(stream, state) {
|
||||
stream._final(function (err) {
|
||||
state.pendingcb--;
|
||||
if (err) {
|
||||
errorOrDestroy(stream, err);
|
||||
}
|
||||
state.prefinished = true;
|
||||
stream.emit('prefinish');
|
||||
finishMaybe(stream, state);
|
||||
});
|
||||
}
|
||||
function prefinish(stream, state) {
|
||||
if (!state.prefinished && !state.finalCalled) {
|
||||
if (typeof stream._final === 'function' && !state.destroyed) {
|
||||
state.pendingcb++;
|
||||
state.finalCalled = true;
|
||||
process.nextTick(callFinal, stream, state);
|
||||
} else {
|
||||
state.prefinished = true;
|
||||
stream.emit('prefinish');
|
||||
}
|
||||
}
|
||||
}
|
||||
function finishMaybe(stream, state) {
|
||||
var need = needFinish(state);
|
||||
if (need) {
|
||||
prefinish(stream, state);
|
||||
if (state.pendingcb === 0) {
|
||||
state.finished = true;
|
||||
stream.emit('finish');
|
||||
if (state.autoDestroy) {
|
||||
// In case of duplex streams we need a way to detect
|
||||
// if the readable side is ready for autoDestroy as well
|
||||
var rState = stream._readableState;
|
||||
if (!rState || rState.autoDestroy && rState.endEmitted) {
|
||||
stream.destroy();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return need;
|
||||
}
|
||||
function endWritable(stream, state, cb) {
|
||||
state.ending = true;
|
||||
finishMaybe(stream, state);
|
||||
if (cb) {
|
||||
if (state.finished) process.nextTick(cb);else stream.once('finish', cb);
|
||||
}
|
||||
state.ended = true;
|
||||
stream.writable = false;
|
||||
}
|
||||
function onCorkedFinish(corkReq, state, err) {
|
||||
var entry = corkReq.entry;
|
||||
corkReq.entry = null;
|
||||
while (entry) {
|
||||
var cb = entry.callback;
|
||||
state.pendingcb--;
|
||||
cb(err);
|
||||
entry = entry.next;
|
||||
}
|
||||
|
||||
// reuse the free corkReq.
|
||||
state.corkedRequestsFree.next = corkReq;
|
||||
}
|
||||
Object.defineProperty(Writable.prototype, 'destroyed', {
|
||||
// making it explicit this property is not enumerable
|
||||
// because otherwise some prototype manipulation in
|
||||
// userland will fail
|
||||
enumerable: false,
|
||||
get: function get() {
|
||||
if (this._writableState === undefined) {
|
||||
return false;
|
||||
}
|
||||
return this._writableState.destroyed;
|
||||
},
|
||||
set: function set(value) {
|
||||
// we ignore the value if the stream
|
||||
// has not been initialized yet
|
||||
if (!this._writableState) {
|
||||
return;
|
||||
}
|
||||
|
||||
// backward compatibility, the user is explicitly
|
||||
// managing destroyed
|
||||
this._writableState.destroyed = value;
|
||||
}
|
||||
});
|
||||
Writable.prototype.destroy = destroyImpl.destroy;
|
||||
Writable.prototype._undestroy = destroyImpl.undestroy;
|
||||
Writable.prototype._destroy = function (err, cb) {
|
||||
cb(err);
|
||||
};
|
||||
@@ -0,0 +1 @@
|
||||
module.exports={A:{A:{"2":"K D E F A B mC"},B:{"2":"C L M G N O P","132":"0 9 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:{"2":"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 qC rC","132":"0 9 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"},D:{"2":"J PB K D E F A B C L M G N O","132":"0 1 2 3 4 5 6 7 8 9 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"},E:{"2":"J PB sC SC tC","132":"K D E F A B C L M G 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"},F:{"2":"F B C 4C 5C 6C 7C FC kC 8C GC","132":"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"},G:{"2":"SC 9C lC AD BD CD","132":"E 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:{"2":"LC J XD YD ZD aD lC","132":"I bD cD"},J:{"2":"D A"},K:{"2":"A B C FC kC GC","132":"H"},L:{"132":"I"},M:{"132":"EC"},N:{"132":"A B"},O:{"132":"HC"},P:{"2":"J dD","132":"1 2 3 4 5 6 7 8 eD fD gD hD TC iD jD kD lD mD IC JC KC nD"},Q:{"132":"oD"},R:{"132":"pD"},S:{"132":"qD rD"}},B:2,C:"Media Fragments",D:true};
|
||||
Binary file not shown.
@@ -0,0 +1,383 @@
|
||||
/**
|
||||
* @fileoverview Rule to require or disallow line breaks inside braces.
|
||||
* @author Toru Nagashima
|
||||
* @deprecated in ESLint v8.53.0
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Requirements
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
const astUtils = require("./utils/ast-utils");
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Helpers
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
// Schema objects.
|
||||
const OPTION_VALUE = {
|
||||
oneOf: [
|
||||
{
|
||||
enum: ["always", "never"],
|
||||
},
|
||||
{
|
||||
type: "object",
|
||||
properties: {
|
||||
multiline: {
|
||||
type: "boolean",
|
||||
},
|
||||
minProperties: {
|
||||
type: "integer",
|
||||
minimum: 0,
|
||||
},
|
||||
consistent: {
|
||||
type: "boolean",
|
||||
},
|
||||
},
|
||||
additionalProperties: false,
|
||||
minProperties: 1,
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
/**
|
||||
* Normalizes a given option value.
|
||||
* @param {string|Object|undefined} value An option value to parse.
|
||||
* @returns {{multiline: boolean, minProperties: number, consistent: boolean}} Normalized option object.
|
||||
*/
|
||||
function normalizeOptionValue(value) {
|
||||
let multiline = false;
|
||||
let minProperties = Number.POSITIVE_INFINITY;
|
||||
let consistent = false;
|
||||
|
||||
if (value) {
|
||||
if (value === "always") {
|
||||
minProperties = 0;
|
||||
} else if (value === "never") {
|
||||
minProperties = Number.POSITIVE_INFINITY;
|
||||
} else {
|
||||
multiline = Boolean(value.multiline);
|
||||
minProperties = value.minProperties || Number.POSITIVE_INFINITY;
|
||||
consistent = Boolean(value.consistent);
|
||||
}
|
||||
} else {
|
||||
consistent = true;
|
||||
}
|
||||
|
||||
return { multiline, minProperties, consistent };
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a value is an object.
|
||||
* @param {any} value The value to check
|
||||
* @returns {boolean} `true` if the value is an object, otherwise `false`
|
||||
*/
|
||||
function isObject(value) {
|
||||
return typeof value === "object" && value !== null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if an option is a node-specific option
|
||||
* @param {any} option The option to check
|
||||
* @returns {boolean} `true` if the option is node-specific, otherwise `false`
|
||||
*/
|
||||
function isNodeSpecificOption(option) {
|
||||
return isObject(option) || typeof option === "string";
|
||||
}
|
||||
|
||||
/**
|
||||
* Normalizes a given option value.
|
||||
* @param {string|Object|undefined} options An option value to parse.
|
||||
* @returns {{
|
||||
* ObjectExpression: {multiline: boolean, minProperties: number, consistent: boolean},
|
||||
* ObjectPattern: {multiline: boolean, minProperties: number, consistent: boolean},
|
||||
* ImportDeclaration: {multiline: boolean, minProperties: number, consistent: boolean},
|
||||
* ExportNamedDeclaration : {multiline: boolean, minProperties: number, consistent: boolean}
|
||||
* }} Normalized option object.
|
||||
*/
|
||||
function normalizeOptions(options) {
|
||||
if (
|
||||
isObject(options) &&
|
||||
Object.values(options).some(isNodeSpecificOption)
|
||||
) {
|
||||
return {
|
||||
ObjectExpression: normalizeOptionValue(options.ObjectExpression),
|
||||
ObjectPattern: normalizeOptionValue(options.ObjectPattern),
|
||||
ImportDeclaration: normalizeOptionValue(options.ImportDeclaration),
|
||||
ExportNamedDeclaration: normalizeOptionValue(
|
||||
options.ExportDeclaration,
|
||||
),
|
||||
};
|
||||
}
|
||||
|
||||
const value = normalizeOptionValue(options);
|
||||
|
||||
return {
|
||||
ObjectExpression: value,
|
||||
ObjectPattern: value,
|
||||
ImportDeclaration: value,
|
||||
ExportNamedDeclaration: value,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if ObjectExpression, ObjectPattern, ImportDeclaration or ExportNamedDeclaration
|
||||
* node needs to be checked for missing line breaks
|
||||
* @param {ASTNode} node Node under inspection
|
||||
* @param {Object} options option specific to node type
|
||||
* @param {Token} first First object property
|
||||
* @param {Token} last Last object property
|
||||
* @returns {boolean} `true` if node needs to be checked for missing line breaks
|
||||
*/
|
||||
function areLineBreaksRequired(node, options, first, last) {
|
||||
let objectProperties;
|
||||
|
||||
if (node.type === "ObjectExpression" || node.type === "ObjectPattern") {
|
||||
objectProperties = node.properties;
|
||||
} else {
|
||||
// is ImportDeclaration or ExportNamedDeclaration
|
||||
objectProperties = node.specifiers.filter(
|
||||
s => s.type === "ImportSpecifier" || s.type === "ExportSpecifier",
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
objectProperties.length >= options.minProperties ||
|
||||
(options.multiline &&
|
||||
objectProperties.length > 0 &&
|
||||
first.loc.start.line !== last.loc.end.line)
|
||||
);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Rule Definition
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/** @type {import('../shared/types').Rule} */
|
||||
module.exports = {
|
||||
meta: {
|
||||
deprecated: {
|
||||
message: "Formatting rules are being moved out of ESLint core.",
|
||||
url: "https://eslint.org/blog/2023/10/deprecating-formatting-rules/",
|
||||
deprecatedSince: "8.53.0",
|
||||
availableUntil: "10.0.0",
|
||||
replacedBy: [
|
||||
{
|
||||
message:
|
||||
"ESLint Stylistic now maintains deprecated stylistic core rules.",
|
||||
url: "https://eslint.style/guide/migration",
|
||||
plugin: {
|
||||
name: "@stylistic/eslint-plugin-js",
|
||||
url: "https://eslint.style/packages/js",
|
||||
},
|
||||
rule: {
|
||||
name: "object-curly-newline",
|
||||
url: "https://eslint.style/rules/js/object-curly-newline",
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
type: "layout",
|
||||
|
||||
docs: {
|
||||
description:
|
||||
"Enforce consistent line breaks after opening and before closing braces",
|
||||
recommended: false,
|
||||
url: "https://eslint.org/docs/latest/rules/object-curly-newline",
|
||||
},
|
||||
|
||||
fixable: "whitespace",
|
||||
|
||||
schema: [
|
||||
{
|
||||
oneOf: [
|
||||
OPTION_VALUE,
|
||||
{
|
||||
type: "object",
|
||||
properties: {
|
||||
ObjectExpression: OPTION_VALUE,
|
||||
ObjectPattern: OPTION_VALUE,
|
||||
ImportDeclaration: OPTION_VALUE,
|
||||
ExportDeclaration: OPTION_VALUE,
|
||||
},
|
||||
additionalProperties: false,
|
||||
minProperties: 1,
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
|
||||
messages: {
|
||||
unexpectedLinebreakBeforeClosingBrace:
|
||||
"Unexpected line break before this closing brace.",
|
||||
unexpectedLinebreakAfterOpeningBrace:
|
||||
"Unexpected line break after this opening brace.",
|
||||
expectedLinebreakBeforeClosingBrace:
|
||||
"Expected a line break before this closing brace.",
|
||||
expectedLinebreakAfterOpeningBrace:
|
||||
"Expected a line break after this opening brace.",
|
||||
},
|
||||
},
|
||||
|
||||
create(context) {
|
||||
const sourceCode = context.sourceCode;
|
||||
const normalizedOptions = normalizeOptions(context.options[0]);
|
||||
|
||||
/**
|
||||
* Reports a given node if it violated this rule.
|
||||
* @param {ASTNode} node A node to check. This is an ObjectExpression, ObjectPattern, ImportDeclaration or ExportNamedDeclaration node.
|
||||
* @returns {void}
|
||||
*/
|
||||
function check(node) {
|
||||
const options = normalizedOptions[node.type];
|
||||
|
||||
if (
|
||||
(node.type === "ImportDeclaration" &&
|
||||
!node.specifiers.some(
|
||||
specifier => specifier.type === "ImportSpecifier",
|
||||
)) ||
|
||||
(node.type === "ExportNamedDeclaration" &&
|
||||
!node.specifiers.some(
|
||||
specifier => specifier.type === "ExportSpecifier",
|
||||
))
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
const openBrace = sourceCode.getFirstToken(
|
||||
node,
|
||||
token => token.value === "{",
|
||||
);
|
||||
|
||||
let closeBrace;
|
||||
|
||||
if (node.typeAnnotation) {
|
||||
closeBrace = sourceCode.getTokenBefore(node.typeAnnotation);
|
||||
} else {
|
||||
closeBrace = sourceCode.getLastToken(
|
||||
node,
|
||||
token => token.value === "}",
|
||||
);
|
||||
}
|
||||
|
||||
let first = sourceCode.getTokenAfter(openBrace, {
|
||||
includeComments: true,
|
||||
});
|
||||
let last = sourceCode.getTokenBefore(closeBrace, {
|
||||
includeComments: true,
|
||||
});
|
||||
|
||||
const needsLineBreaks = areLineBreaksRequired(
|
||||
node,
|
||||
options,
|
||||
first,
|
||||
last,
|
||||
);
|
||||
|
||||
const hasCommentsFirstToken = astUtils.isCommentToken(first);
|
||||
const hasCommentsLastToken = astUtils.isCommentToken(last);
|
||||
|
||||
/*
|
||||
* Use tokens or comments to check multiline or not.
|
||||
* But use only tokens to check whether line breaks are needed.
|
||||
* This allows:
|
||||
* var obj = { // eslint-disable-line foo
|
||||
* a: 1
|
||||
* }
|
||||
*/
|
||||
first = sourceCode.getTokenAfter(openBrace);
|
||||
last = sourceCode.getTokenBefore(closeBrace);
|
||||
|
||||
if (needsLineBreaks) {
|
||||
if (astUtils.isTokenOnSameLine(openBrace, first)) {
|
||||
context.report({
|
||||
messageId: "expectedLinebreakAfterOpeningBrace",
|
||||
node,
|
||||
loc: openBrace.loc,
|
||||
fix(fixer) {
|
||||
if (hasCommentsFirstToken) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return fixer.insertTextAfter(openBrace, "\n");
|
||||
},
|
||||
});
|
||||
}
|
||||
if (astUtils.isTokenOnSameLine(last, closeBrace)) {
|
||||
context.report({
|
||||
messageId: "expectedLinebreakBeforeClosingBrace",
|
||||
node,
|
||||
loc: closeBrace.loc,
|
||||
fix(fixer) {
|
||||
if (hasCommentsLastToken) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return fixer.insertTextBefore(closeBrace, "\n");
|
||||
},
|
||||
});
|
||||
}
|
||||
} else {
|
||||
const consistent = options.consistent;
|
||||
const hasLineBreakBetweenOpenBraceAndFirst =
|
||||
!astUtils.isTokenOnSameLine(openBrace, first);
|
||||
const hasLineBreakBetweenCloseBraceAndLast =
|
||||
!astUtils.isTokenOnSameLine(last, closeBrace);
|
||||
|
||||
if (
|
||||
(!consistent && hasLineBreakBetweenOpenBraceAndFirst) ||
|
||||
(consistent &&
|
||||
hasLineBreakBetweenOpenBraceAndFirst &&
|
||||
!hasLineBreakBetweenCloseBraceAndLast)
|
||||
) {
|
||||
context.report({
|
||||
messageId: "unexpectedLinebreakAfterOpeningBrace",
|
||||
node,
|
||||
loc: openBrace.loc,
|
||||
fix(fixer) {
|
||||
if (hasCommentsFirstToken) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return fixer.removeRange([
|
||||
openBrace.range[1],
|
||||
first.range[0],
|
||||
]);
|
||||
},
|
||||
});
|
||||
}
|
||||
if (
|
||||
(!consistent && hasLineBreakBetweenCloseBraceAndLast) ||
|
||||
(consistent &&
|
||||
!hasLineBreakBetweenOpenBraceAndFirst &&
|
||||
hasLineBreakBetweenCloseBraceAndLast)
|
||||
) {
|
||||
context.report({
|
||||
messageId: "unexpectedLinebreakBeforeClosingBrace",
|
||||
node,
|
||||
loc: closeBrace.loc,
|
||||
fix(fixer) {
|
||||
if (hasCommentsLastToken) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return fixer.removeRange([
|
||||
last.range[1],
|
||||
closeBrace.range[0],
|
||||
]);
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
ObjectExpression: check,
|
||||
ObjectPattern: check,
|
||||
ImportDeclaration: check,
|
||||
ExportNamedDeclaration: check,
|
||||
};
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user