update
This commit is contained in:
@@ -0,0 +1,79 @@
|
||||
#!/usr/bin/env node
|
||||
import { performance } from 'node:perf_hooks'
|
||||
import module from 'node:module'
|
||||
|
||||
if (!import.meta.url.includes('node_modules')) {
|
||||
try {
|
||||
// only available as dev dependency
|
||||
await import('source-map-support').then((r) => r.default.install())
|
||||
} catch {}
|
||||
|
||||
process.on('unhandledRejection', (err) => {
|
||||
throw new Error('UNHANDLED PROMISE REJECTION', { cause: err })
|
||||
})
|
||||
}
|
||||
|
||||
global.__vite_start_time = performance.now()
|
||||
|
||||
// check debug mode first before requiring the CLI.
|
||||
const debugIndex = process.argv.findIndex((arg) => /^(?:-d|--debug)$/.test(arg))
|
||||
const filterIndex = process.argv.findIndex((arg) =>
|
||||
/^(?:-f|--filter)$/.test(arg),
|
||||
)
|
||||
const profileIndex = process.argv.indexOf('--profile')
|
||||
|
||||
if (debugIndex > 0) {
|
||||
let value = process.argv[debugIndex + 1]
|
||||
if (!value || value.startsWith('-')) {
|
||||
value = 'vite:*'
|
||||
} else {
|
||||
// support debugging multiple flags with comma-separated list
|
||||
value = value
|
||||
.split(',')
|
||||
.map((v) => `vite:${v}`)
|
||||
.join(',')
|
||||
}
|
||||
process.env.DEBUG = `${
|
||||
process.env.DEBUG ? process.env.DEBUG + ',' : ''
|
||||
}${value}`
|
||||
|
||||
if (filterIndex > 0) {
|
||||
const filter = process.argv[filterIndex + 1]
|
||||
if (filter && !filter.startsWith('-')) {
|
||||
process.env.VITE_DEBUG_FILTER = filter
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function start() {
|
||||
try {
|
||||
// eslint-disable-next-line n/no-unsupported-features/node-builtins -- it is supported in Node 22.8.0+ and only called if it exists
|
||||
module.enableCompileCache?.()
|
||||
// flush the cache after 10s because the cache is not flushed until process end
|
||||
// for dev server, the cache is never flushed unless manually flushed because the process.exit is called
|
||||
// also flushing the cache in SIGINT handler seems to cause the process to hang
|
||||
setTimeout(() => {
|
||||
try {
|
||||
// eslint-disable-next-line n/no-unsupported-features/node-builtins -- it is supported in Node 22.12.0+ and only called if it exists
|
||||
module.flushCompileCache?.()
|
||||
} catch {}
|
||||
}, 10 * 1000).unref()
|
||||
} catch {}
|
||||
return import('../dist/node/cli.js')
|
||||
}
|
||||
|
||||
if (profileIndex > 0) {
|
||||
process.argv.splice(profileIndex, 1)
|
||||
const next = process.argv[profileIndex]
|
||||
if (next && !next.startsWith('-')) {
|
||||
process.argv.splice(profileIndex, 1)
|
||||
}
|
||||
const inspector = await import('node:inspector').then((r) => r.default)
|
||||
const session = (global.__vite_profile_session = new inspector.Session())
|
||||
session.connect()
|
||||
session.post('Profiler.enable', () => {
|
||||
session.post('Profiler.start', start)
|
||||
})
|
||||
} else {
|
||||
start()
|
||||
}
|
||||
@@ -0,0 +1,358 @@
|
||||
/**
|
||||
* @license React
|
||||
* react-jsx-runtime.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 getComponentNameFromType(type) {
|
||||
if (null == type) return null;
|
||||
if ("function" === typeof type)
|
||||
return type.$$typeof === REACT_CLIENT_REFERENCE
|
||||
? null
|
||||
: type.displayName || type.name || null;
|
||||
if ("string" === typeof type) return type;
|
||||
switch (type) {
|
||||
case REACT_FRAGMENT_TYPE:
|
||||
return "Fragment";
|
||||
case REACT_PROFILER_TYPE:
|
||||
return "Profiler";
|
||||
case REACT_STRICT_MODE_TYPE:
|
||||
return "StrictMode";
|
||||
case REACT_SUSPENSE_TYPE:
|
||||
return "Suspense";
|
||||
case REACT_SUSPENSE_LIST_TYPE:
|
||||
return "SuspenseList";
|
||||
case REACT_ACTIVITY_TYPE:
|
||||
return "Activity";
|
||||
}
|
||||
if ("object" === typeof type)
|
||||
switch (
|
||||
("number" === typeof type.tag &&
|
||||
console.error(
|
||||
"Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."
|
||||
),
|
||||
type.$$typeof)
|
||||
) {
|
||||
case REACT_PORTAL_TYPE:
|
||||
return "Portal";
|
||||
case REACT_CONTEXT_TYPE:
|
||||
return (type.displayName || "Context") + ".Provider";
|
||||
case REACT_CONSUMER_TYPE:
|
||||
return (type._context.displayName || "Context") + ".Consumer";
|
||||
case REACT_FORWARD_REF_TYPE:
|
||||
var innerType = type.render;
|
||||
type = type.displayName;
|
||||
type ||
|
||||
((type = innerType.displayName || innerType.name || ""),
|
||||
(type = "" !== type ? "ForwardRef(" + type + ")" : "ForwardRef"));
|
||||
return type;
|
||||
case REACT_MEMO_TYPE:
|
||||
return (
|
||||
(innerType = type.displayName || null),
|
||||
null !== innerType
|
||||
? innerType
|
||||
: getComponentNameFromType(type.type) || "Memo"
|
||||
);
|
||||
case REACT_LAZY_TYPE:
|
||||
innerType = type._payload;
|
||||
type = type._init;
|
||||
try {
|
||||
return getComponentNameFromType(type(innerType));
|
||||
} catch (x) {}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
function testStringCoercion(value) {
|
||||
return "" + value;
|
||||
}
|
||||
function checkKeyStringCoercion(value) {
|
||||
try {
|
||||
testStringCoercion(value);
|
||||
var JSCompiler_inline_result = !1;
|
||||
} catch (e) {
|
||||
JSCompiler_inline_result = !0;
|
||||
}
|
||||
if (JSCompiler_inline_result) {
|
||||
JSCompiler_inline_result = console;
|
||||
var JSCompiler_temp_const = JSCompiler_inline_result.error;
|
||||
var JSCompiler_inline_result$jscomp$0 =
|
||||
("function" === typeof Symbol &&
|
||||
Symbol.toStringTag &&
|
||||
value[Symbol.toStringTag]) ||
|
||||
value.constructor.name ||
|
||||
"Object";
|
||||
JSCompiler_temp_const.call(
|
||||
JSCompiler_inline_result,
|
||||
"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",
|
||||
JSCompiler_inline_result$jscomp$0
|
||||
);
|
||||
return testStringCoercion(value);
|
||||
}
|
||||
}
|
||||
function getTaskName(type) {
|
||||
if (type === REACT_FRAGMENT_TYPE) return "<>";
|
||||
if (
|
||||
"object" === typeof type &&
|
||||
null !== type &&
|
||||
type.$$typeof === REACT_LAZY_TYPE
|
||||
)
|
||||
return "<...>";
|
||||
try {
|
||||
var name = getComponentNameFromType(type);
|
||||
return name ? "<" + name + ">" : "<...>";
|
||||
} catch (x) {
|
||||
return "<...>";
|
||||
}
|
||||
}
|
||||
function getOwner() {
|
||||
var dispatcher = ReactSharedInternals.A;
|
||||
return null === dispatcher ? null : dispatcher.getOwner();
|
||||
}
|
||||
function UnknownOwner() {
|
||||
return Error("react-stack-top-frame");
|
||||
}
|
||||
function hasValidKey(config) {
|
||||
if (hasOwnProperty.call(config, "key")) {
|
||||
var getter = Object.getOwnPropertyDescriptor(config, "key").get;
|
||||
if (getter && getter.isReactWarning) return !1;
|
||||
}
|
||||
return void 0 !== config.key;
|
||||
}
|
||||
function defineKeyPropWarningGetter(props, displayName) {
|
||||
function warnAboutAccessingKey() {
|
||||
specialPropKeyWarningShown ||
|
||||
((specialPropKeyWarningShown = !0),
|
||||
console.error(
|
||||
"%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)",
|
||||
displayName
|
||||
));
|
||||
}
|
||||
warnAboutAccessingKey.isReactWarning = !0;
|
||||
Object.defineProperty(props, "key", {
|
||||
get: warnAboutAccessingKey,
|
||||
configurable: !0
|
||||
});
|
||||
}
|
||||
function elementRefGetterWithDeprecationWarning() {
|
||||
var componentName = getComponentNameFromType(this.type);
|
||||
didWarnAboutElementRef[componentName] ||
|
||||
((didWarnAboutElementRef[componentName] = !0),
|
||||
console.error(
|
||||
"Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release."
|
||||
));
|
||||
componentName = this.props.ref;
|
||||
return void 0 !== componentName ? componentName : null;
|
||||
}
|
||||
function ReactElement(
|
||||
type,
|
||||
key,
|
||||
self,
|
||||
source,
|
||||
owner,
|
||||
props,
|
||||
debugStack,
|
||||
debugTask
|
||||
) {
|
||||
self = props.ref;
|
||||
type = {
|
||||
$$typeof: REACT_ELEMENT_TYPE,
|
||||
type: type,
|
||||
key: key,
|
||||
props: props,
|
||||
_owner: owner
|
||||
};
|
||||
null !== (void 0 !== self ? self : null)
|
||||
? Object.defineProperty(type, "ref", {
|
||||
enumerable: !1,
|
||||
get: elementRefGetterWithDeprecationWarning
|
||||
})
|
||||
: Object.defineProperty(type, "ref", { enumerable: !1, value: null });
|
||||
type._store = {};
|
||||
Object.defineProperty(type._store, "validated", {
|
||||
configurable: !1,
|
||||
enumerable: !1,
|
||||
writable: !0,
|
||||
value: 0
|
||||
});
|
||||
Object.defineProperty(type, "_debugInfo", {
|
||||
configurable: !1,
|
||||
enumerable: !1,
|
||||
writable: !0,
|
||||
value: null
|
||||
});
|
||||
Object.defineProperty(type, "_debugStack", {
|
||||
configurable: !1,
|
||||
enumerable: !1,
|
||||
writable: !0,
|
||||
value: debugStack
|
||||
});
|
||||
Object.defineProperty(type, "_debugTask", {
|
||||
configurable: !1,
|
||||
enumerable: !1,
|
||||
writable: !0,
|
||||
value: debugTask
|
||||
});
|
||||
Object.freeze && (Object.freeze(type.props), Object.freeze(type));
|
||||
return type;
|
||||
}
|
||||
function jsxDEVImpl(
|
||||
type,
|
||||
config,
|
||||
maybeKey,
|
||||
isStaticChildren,
|
||||
source,
|
||||
self,
|
||||
debugStack,
|
||||
debugTask
|
||||
) {
|
||||
var children = config.children;
|
||||
if (void 0 !== children)
|
||||
if (isStaticChildren)
|
||||
if (isArrayImpl(children)) {
|
||||
for (
|
||||
isStaticChildren = 0;
|
||||
isStaticChildren < children.length;
|
||||
isStaticChildren++
|
||||
)
|
||||
validateChildKeys(children[isStaticChildren]);
|
||||
Object.freeze && Object.freeze(children);
|
||||
} else
|
||||
console.error(
|
||||
"React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead."
|
||||
);
|
||||
else validateChildKeys(children);
|
||||
if (hasOwnProperty.call(config, "key")) {
|
||||
children = getComponentNameFromType(type);
|
||||
var keys = Object.keys(config).filter(function (k) {
|
||||
return "key" !== k;
|
||||
});
|
||||
isStaticChildren =
|
||||
0 < keys.length
|
||||
? "{key: someKey, " + keys.join(": ..., ") + ": ...}"
|
||||
: "{key: someKey}";
|
||||
didWarnAboutKeySpread[children + isStaticChildren] ||
|
||||
((keys =
|
||||
0 < keys.length ? "{" + keys.join(": ..., ") + ": ...}" : "{}"),
|
||||
console.error(
|
||||
'A props object containing a "key" prop is being spread into JSX:\n let props = %s;\n <%s {...props} />\nReact keys must be passed directly to JSX without using spread:\n let props = %s;\n <%s key={someKey} {...props} />',
|
||||
isStaticChildren,
|
||||
children,
|
||||
keys,
|
||||
children
|
||||
),
|
||||
(didWarnAboutKeySpread[children + isStaticChildren] = !0));
|
||||
}
|
||||
children = null;
|
||||
void 0 !== maybeKey &&
|
||||
(checkKeyStringCoercion(maybeKey), (children = "" + maybeKey));
|
||||
hasValidKey(config) &&
|
||||
(checkKeyStringCoercion(config.key), (children = "" + config.key));
|
||||
if ("key" in config) {
|
||||
maybeKey = {};
|
||||
for (var propName in config)
|
||||
"key" !== propName && (maybeKey[propName] = config[propName]);
|
||||
} else maybeKey = config;
|
||||
children &&
|
||||
defineKeyPropWarningGetter(
|
||||
maybeKey,
|
||||
"function" === typeof type
|
||||
? type.displayName || type.name || "Unknown"
|
||||
: type
|
||||
);
|
||||
return ReactElement(
|
||||
type,
|
||||
children,
|
||||
self,
|
||||
source,
|
||||
getOwner(),
|
||||
maybeKey,
|
||||
debugStack,
|
||||
debugTask
|
||||
);
|
||||
}
|
||||
function validateChildKeys(node) {
|
||||
"object" === typeof node &&
|
||||
null !== node &&
|
||||
node.$$typeof === REACT_ELEMENT_TYPE &&
|
||||
node._store &&
|
||||
(node._store.validated = 1);
|
||||
}
|
||||
var React = require("react"),
|
||||
REACT_ELEMENT_TYPE = Symbol.for("react.transitional.element"),
|
||||
REACT_PORTAL_TYPE = Symbol.for("react.portal"),
|
||||
REACT_FRAGMENT_TYPE = Symbol.for("react.fragment"),
|
||||
REACT_STRICT_MODE_TYPE = Symbol.for("react.strict_mode"),
|
||||
REACT_PROFILER_TYPE = Symbol.for("react.profiler");
|
||||
Symbol.for("react.provider");
|
||||
var REACT_CONSUMER_TYPE = Symbol.for("react.consumer"),
|
||||
REACT_CONTEXT_TYPE = Symbol.for("react.context"),
|
||||
REACT_FORWARD_REF_TYPE = Symbol.for("react.forward_ref"),
|
||||
REACT_SUSPENSE_TYPE = Symbol.for("react.suspense"),
|
||||
REACT_SUSPENSE_LIST_TYPE = Symbol.for("react.suspense_list"),
|
||||
REACT_MEMO_TYPE = Symbol.for("react.memo"),
|
||||
REACT_LAZY_TYPE = Symbol.for("react.lazy"),
|
||||
REACT_ACTIVITY_TYPE = Symbol.for("react.activity"),
|
||||
REACT_CLIENT_REFERENCE = Symbol.for("react.client.reference"),
|
||||
ReactSharedInternals =
|
||||
React.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,
|
||||
hasOwnProperty = Object.prototype.hasOwnProperty,
|
||||
isArrayImpl = Array.isArray,
|
||||
createTask = console.createTask
|
||||
? console.createTask
|
||||
: function () {
|
||||
return null;
|
||||
};
|
||||
React = {
|
||||
"react-stack-bottom-frame": function (callStackForError) {
|
||||
return callStackForError();
|
||||
}
|
||||
};
|
||||
var specialPropKeyWarningShown;
|
||||
var didWarnAboutElementRef = {};
|
||||
var unknownOwnerDebugStack = React["react-stack-bottom-frame"].bind(
|
||||
React,
|
||||
UnknownOwner
|
||||
)();
|
||||
var unknownOwnerDebugTask = createTask(getTaskName(UnknownOwner));
|
||||
var didWarnAboutKeySpread = {};
|
||||
exports.Fragment = REACT_FRAGMENT_TYPE;
|
||||
exports.jsx = function (type, config, maybeKey, source, self) {
|
||||
var trackActualOwner =
|
||||
1e4 > ReactSharedInternals.recentlyCreatedOwnerStacks++;
|
||||
return jsxDEVImpl(
|
||||
type,
|
||||
config,
|
||||
maybeKey,
|
||||
!1,
|
||||
source,
|
||||
self,
|
||||
trackActualOwner
|
||||
? Error("react-stack-top-frame")
|
||||
: unknownOwnerDebugStack,
|
||||
trackActualOwner ? createTask(getTaskName(type)) : unknownOwnerDebugTask
|
||||
);
|
||||
};
|
||||
exports.jsxs = function (type, config, maybeKey, source, self) {
|
||||
var trackActualOwner =
|
||||
1e4 > ReactSharedInternals.recentlyCreatedOwnerStacks++;
|
||||
return jsxDEVImpl(
|
||||
type,
|
||||
config,
|
||||
maybeKey,
|
||||
!0,
|
||||
source,
|
||||
self,
|
||||
trackActualOwner
|
||||
? Error("react-stack-top-frame")
|
||||
: unknownOwnerDebugStack,
|
||||
trackActualOwner ? createTask(getTaskName(type)) : unknownOwnerDebugTask
|
||||
);
|
||||
};
|
||||
})();
|
||||
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Author Tobias Koppers @sokra
|
||||
*/
|
||||
"use strict";
|
||||
|
||||
const util = require("util");
|
||||
|
||||
const defaultFactory = (key, hook) => hook;
|
||||
|
||||
class HookMap {
|
||||
constructor(factory, name = undefined) {
|
||||
this._map = new Map();
|
||||
this.name = name;
|
||||
this._factory = factory;
|
||||
this._interceptors = [];
|
||||
}
|
||||
|
||||
get(key) {
|
||||
return this._map.get(key);
|
||||
}
|
||||
|
||||
for(key) {
|
||||
const hook = this.get(key);
|
||||
if (hook !== undefined) {
|
||||
return hook;
|
||||
}
|
||||
let newHook = this._factory(key);
|
||||
const interceptors = this._interceptors;
|
||||
for (let i = 0; i < interceptors.length; i++) {
|
||||
newHook = interceptors[i].factory(key, newHook);
|
||||
}
|
||||
this._map.set(key, newHook);
|
||||
return newHook;
|
||||
}
|
||||
|
||||
intercept(interceptor) {
|
||||
this._interceptors.push(
|
||||
Object.assign(
|
||||
{
|
||||
factory: defaultFactory
|
||||
},
|
||||
interceptor
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
HookMap.prototype.tap = util.deprecate(function(key, options, fn) {
|
||||
return this.for(key).tap(options, fn);
|
||||
}, "HookMap#tap(key,…) is deprecated. Use HookMap#for(key).tap(…) instead.");
|
||||
|
||||
HookMap.prototype.tapAsync = util.deprecate(function(key, options, fn) {
|
||||
return this.for(key).tapAsync(options, fn);
|
||||
}, "HookMap#tapAsync(key,…) is deprecated. Use HookMap#for(key).tapAsync(…) instead.");
|
||||
|
||||
HookMap.prototype.tapPromise = util.deprecate(function(key, options, fn) {
|
||||
return this.for(key).tapPromise(options, fn);
|
||||
}, "HookMap#tapPromise(key,…) is deprecated. Use HookMap#for(key).tapPromise(…) instead.");
|
||||
|
||||
module.exports = HookMap;
|
||||
@@ -0,0 +1,49 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
||||
const React = require("react");
|
||||
const useRouter = require("./useRouter.cjs");
|
||||
function _interopNamespaceDefault(e) {
|
||||
const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
|
||||
if (e) {
|
||||
for (const k in e) {
|
||||
if (k !== "default") {
|
||||
const d = Object.getOwnPropertyDescriptor(e, k);
|
||||
Object.defineProperty(n, k, d.get ? d : {
|
||||
enumerable: true,
|
||||
get: () => e[k]
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
n.default = e;
|
||||
return Object.freeze(n);
|
||||
}
|
||||
const React__namespace = /* @__PURE__ */ _interopNamespaceDefault(React);
|
||||
function useNavigate(_defaultOpts) {
|
||||
const { navigate } = useRouter.useRouter();
|
||||
return React__namespace.useCallback(
|
||||
(options) => {
|
||||
return navigate({
|
||||
from: _defaultOpts == null ? void 0 : _defaultOpts.from,
|
||||
...options
|
||||
});
|
||||
},
|
||||
[_defaultOpts == null ? void 0 : _defaultOpts.from, navigate]
|
||||
);
|
||||
}
|
||||
function Navigate(props) {
|
||||
const router = useRouter.useRouter();
|
||||
const previousPropsRef = React__namespace.useRef(null);
|
||||
React__namespace.useEffect(() => {
|
||||
if (previousPropsRef.current !== props) {
|
||||
router.navigate({
|
||||
...props
|
||||
});
|
||||
previousPropsRef.current = props;
|
||||
}
|
||||
}, [router, props]);
|
||||
return null;
|
||||
}
|
||||
exports.Navigate = Navigate;
|
||||
exports.useNavigate = useNavigate;
|
||||
//# sourceMappingURL=useNavigate.cjs.map
|
||||
@@ -0,0 +1,86 @@
|
||||
// Ported from https://github.com/mafintosh/end-of-stream with
|
||||
// permission from the author, Mathias Buus (@mafintosh).
|
||||
|
||||
'use strict';
|
||||
|
||||
var ERR_STREAM_PREMATURE_CLOSE = require('../../../errors').codes.ERR_STREAM_PREMATURE_CLOSE;
|
||||
function once(callback) {
|
||||
var called = false;
|
||||
return function () {
|
||||
if (called) return;
|
||||
called = true;
|
||||
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
||||
args[_key] = arguments[_key];
|
||||
}
|
||||
callback.apply(this, args);
|
||||
};
|
||||
}
|
||||
function noop() {}
|
||||
function isRequest(stream) {
|
||||
return stream.setHeader && typeof stream.abort === 'function';
|
||||
}
|
||||
function eos(stream, opts, callback) {
|
||||
if (typeof opts === 'function') return eos(stream, null, opts);
|
||||
if (!opts) opts = {};
|
||||
callback = once(callback || noop);
|
||||
var readable = opts.readable || opts.readable !== false && stream.readable;
|
||||
var writable = opts.writable || opts.writable !== false && stream.writable;
|
||||
var onlegacyfinish = function onlegacyfinish() {
|
||||
if (!stream.writable) onfinish();
|
||||
};
|
||||
var writableEnded = stream._writableState && stream._writableState.finished;
|
||||
var onfinish = function onfinish() {
|
||||
writable = false;
|
||||
writableEnded = true;
|
||||
if (!readable) callback.call(stream);
|
||||
};
|
||||
var readableEnded = stream._readableState && stream._readableState.endEmitted;
|
||||
var onend = function onend() {
|
||||
readable = false;
|
||||
readableEnded = true;
|
||||
if (!writable) callback.call(stream);
|
||||
};
|
||||
var onerror = function onerror(err) {
|
||||
callback.call(stream, err);
|
||||
};
|
||||
var onclose = function onclose() {
|
||||
var err;
|
||||
if (readable && !readableEnded) {
|
||||
if (!stream._readableState || !stream._readableState.ended) err = new ERR_STREAM_PREMATURE_CLOSE();
|
||||
return callback.call(stream, err);
|
||||
}
|
||||
if (writable && !writableEnded) {
|
||||
if (!stream._writableState || !stream._writableState.ended) err = new ERR_STREAM_PREMATURE_CLOSE();
|
||||
return callback.call(stream, err);
|
||||
}
|
||||
};
|
||||
var onrequest = function onrequest() {
|
||||
stream.req.on('finish', onfinish);
|
||||
};
|
||||
if (isRequest(stream)) {
|
||||
stream.on('complete', onfinish);
|
||||
stream.on('abort', onclose);
|
||||
if (stream.req) onrequest();else stream.on('request', onrequest);
|
||||
} else if (writable && !stream._writableState) {
|
||||
// legacy streams
|
||||
stream.on('end', onlegacyfinish);
|
||||
stream.on('close', onlegacyfinish);
|
||||
}
|
||||
stream.on('end', onend);
|
||||
stream.on('finish', onfinish);
|
||||
if (opts.error !== false) stream.on('error', onerror);
|
||||
stream.on('close', onclose);
|
||||
return function () {
|
||||
stream.removeListener('complete', onfinish);
|
||||
stream.removeListener('abort', onclose);
|
||||
stream.removeListener('request', onrequest);
|
||||
if (stream.req) stream.req.removeListener('finish', onfinish);
|
||||
stream.removeListener('end', onlegacyfinish);
|
||||
stream.removeListener('close', onlegacyfinish);
|
||||
stream.removeListener('finish', onfinish);
|
||||
stream.removeListener('end', onend);
|
||||
stream.removeListener('error', onerror);
|
||||
stream.removeListener('close', onclose);
|
||||
};
|
||||
}
|
||||
module.exports = eos;
|
||||
@@ -0,0 +1,196 @@
|
||||
# levn [](https://travis-ci.org/gkz/levn) <a name="levn" />
|
||||
__Light ECMAScript (JavaScript) Value Notation__
|
||||
Levn is a library which allows you to parse a string into a JavaScript value based on an expected type. It is meant for short amounts of human entered data (eg. config files, command line arguments).
|
||||
|
||||
Levn aims to concisely describe JavaScript values in text, and allow for the extraction and validation of those values. Levn uses [type-check](https://github.com/gkz/type-check) for its type format, and to validate the results. MIT license. Version 0.4.1.
|
||||
|
||||
__How is this different than JSON?__ levn is meant to be written by humans only, is (due to the previous point) much more concise, can be validated against supplied types, has regex and date literals, and can easily be extended with custom types. On the other hand, it is probably slower and thus less efficient at transporting large amounts of data, which is fine since this is not its purpose.
|
||||
|
||||
npm install levn
|
||||
|
||||
For updates on levn, [follow me on twitter](https://twitter.com/gkzahariev).
|
||||
|
||||
|
||||
## Quick Examples
|
||||
|
||||
```js
|
||||
var parse = require('levn').parse;
|
||||
parse('Number', '2'); // 2
|
||||
parse('String', '2'); // '2'
|
||||
parse('String', 'levn'); // 'levn'
|
||||
parse('String', 'a b'); // 'a b'
|
||||
parse('Boolean', 'true'); // true
|
||||
|
||||
parse('Date', '#2011-11-11#'); // (Date object)
|
||||
parse('Date', '2011-11-11'); // (Date object)
|
||||
parse('RegExp', '/[a-z]/gi'); // /[a-z]/gi
|
||||
parse('RegExp', 're'); // /re/
|
||||
parse('Int', '2'); // 2
|
||||
|
||||
parse('Number | String', 'str'); // 'str'
|
||||
parse('Number | String', '2'); // 2
|
||||
|
||||
parse('[Number]', '[1,2,3]'); // [1,2,3]
|
||||
parse('(String, Boolean)', '(hi, false)'); // ['hi', false]
|
||||
parse('{a: String, b: Number}', '{a: str, b: 2}'); // {a: 'str', b: 2}
|
||||
|
||||
// at the top level, you can ommit surrounding delimiters
|
||||
parse('[Number]', '1,2,3'); // [1,2,3]
|
||||
parse('(String, Boolean)', 'hi, false'); // ['hi', false]
|
||||
parse('{a: String, b: Number}', 'a: str, b: 2'); // {a: 'str', b: 2}
|
||||
|
||||
// wildcard - auto choose type
|
||||
parse('*', '[hi,(null,[42]),{k: true}]'); // ['hi', [null, [42]], {k: true}]
|
||||
```
|
||||
## Usage
|
||||
|
||||
`require('levn');` returns an object that exposes three properties. `VERSION` is the current version of the library as a string. `parse` and `parsedTypeParse` are functions.
|
||||
|
||||
```js
|
||||
// parse(type, input, options);
|
||||
parse('[Number]', '1,2,3'); // [1, 2, 3]
|
||||
|
||||
// parsedTypeParse(parsedType, input, options);
|
||||
var parsedType = require('type-check').parseType('[Number]');
|
||||
parsedTypeParse(parsedType, '1,2,3'); // [1, 2, 3]
|
||||
```
|
||||
|
||||
### parse(type, input, options)
|
||||
|
||||
`parse` casts the string `input` into a JavaScript value according to the specified `type` in the [type format](https://github.com/gkz/type-check#type-format) (and taking account the optional `options`) and returns the resulting JavaScript value.
|
||||
|
||||
##### arguments
|
||||
* type - `String` - the type written in the [type format](https://github.com/gkz/type-check#type-format) which to check against
|
||||
* input - `String` - the value written in the [levn format](#levn-format)
|
||||
* options - `Maybe Object` - an optional parameter specifying additional [options](#options)
|
||||
|
||||
##### returns
|
||||
`*` - the resulting JavaScript value
|
||||
|
||||
##### example
|
||||
```js
|
||||
parse('[Number]', '1,2,3'); // [1, 2, 3]
|
||||
```
|
||||
|
||||
### parsedTypeParse(parsedType, input, options)
|
||||
|
||||
`parsedTypeParse` casts the string `input` into a JavaScript value according to the specified `type` which has already been parsed (and taking account the optional `options`) and returns the resulting JavaScript value. You can parse a type using the [type-check](https://github.com/gkz/type-check) library's `parseType` function.
|
||||
|
||||
##### arguments
|
||||
* type - `Object` - the type in the parsed type format which to check against
|
||||
* input - `String` - the value written in the [levn format](#levn-format)
|
||||
* options - `Maybe Object` - an optional parameter specifying additional [options](#options)
|
||||
|
||||
##### returns
|
||||
`*` - the resulting JavaScript value
|
||||
|
||||
##### example
|
||||
```js
|
||||
var parsedType = require('type-check').parseType('[Number]');
|
||||
parsedTypeParse(parsedType, '1,2,3'); // [1, 2, 3]
|
||||
```
|
||||
|
||||
## Levn Format
|
||||
|
||||
Levn can use the type information you provide to choose the appropriate value to produce from the input. For the same input, it will choose a different output value depending on the type provided. For example, `parse('Number', '2')` will produce the number `2`, but `parse('String', '2')` will produce the string `"2"`.
|
||||
|
||||
If you do not provide type information, and simply use `*`, levn will parse the input according the unambiguous "explicit" mode, which we will now detail - you can also set the `explicit` option to true manually in the [options](#options).
|
||||
|
||||
* `"string"`, `'string'` are parsed as a String, eg. `"a msg"` is `"a msg"`
|
||||
* `#date#` is parsed as a Date, eg. `#2011-11-11#` is `new Date('2011-11-11')`
|
||||
* `/regexp/flags` is parsed as a RegExp, eg. `/re/gi` is `/re/gi`
|
||||
* `undefined`, `null`, `NaN`, `true`, and `false` are all their JavaScript equivalents
|
||||
* `[element1, element2, etc]` is an Array, and the casting procedure is recursively applied to each element. Eg. `[1,2,3]` is `[1,2,3]`.
|
||||
* `(element1, element2, etc)` is an tuple, and the casting procedure is recursively applied to each element. Eg. `(1, a)` is `(1, a)` (is `[1, 'a']`).
|
||||
* `{key1: val1, key2: val2, ...}` is an Object, and the casting procedure is recursively applied to each property. Eg. `{a: 1, b: 2}` is `{a: 1, b: 2}`.
|
||||
* Any test which does not fall under the above, and which does not contain special characters (`[``]``(``)``{``}``:``,`) is a string, eg. `$12- blah` is `"$12- blah"`.
|
||||
|
||||
If you do provide type information, you can make your input more concise as the program already has some information about what it expects. Please see the [type format](https://github.com/gkz/type-check#type-format) section of [type-check](https://github.com/gkz/type-check) for more information about how to specify types. There are some rules about what levn can do with the information:
|
||||
|
||||
* If a String is expected, and only a String, all characters of the input (including any special ones) will become part of the output. Eg. `[({})]` is `"[({})]"`, and `"hi"` is `'"hi"'`.
|
||||
* If a Date is expected, the surrounding `#` can be omitted from date literals. Eg. `2011-11-11` is `new Date('2011-11-11')`.
|
||||
* If a RegExp is expected, no flags need to be specified, and the regex is not using any of the special characters,the opening and closing `/` can be omitted - this will have the affect of setting the source of the regex to the input. Eg. `regex` is `/regex/`.
|
||||
* If an Array is expected, and it is the root node (at the top level), the opening `[` and closing `]` can be omitted. Eg. `1,2,3` is `[1,2,3]`.
|
||||
* If a tuple is expected, and it is the root node (at the top level), the opening `(` and closing `)` can be omitted. Eg. `1, a` is `(1, a)` (is `[1, 'a']`).
|
||||
* If an Object is expected, and it is the root node (at the top level), the opening `{` and closing `}` can be omitted. Eg `a: 1, b: 2` is `{a: 1, b: 2}`.
|
||||
|
||||
If you list multiple types (eg. `Number | String`), it will first attempt to cast to the first type and then validate - if the validation fails it will move on to the next type and so forth, left to right. You must be careful as some types will succeed with any input, such as String. Thus put String at the end of your list. In non-explicit mode, Date and RegExp will succeed with a large variety of input - also be careful with these and list them near the end if not last in your list.
|
||||
|
||||
Whitespace between special characters and elements is inconsequential.
|
||||
|
||||
## Options
|
||||
|
||||
Options is an object. It is an optional parameter to the `parse` and `parsedTypeParse` functions.
|
||||
|
||||
### Explicit
|
||||
|
||||
A `Boolean`. By default it is `false`.
|
||||
|
||||
__Example:__
|
||||
|
||||
```js
|
||||
parse('RegExp', 're', {explicit: false}); // /re/
|
||||
parse('RegExp', 're', {explicit: true}); // Error: ... does not type check...
|
||||
parse('RegExp | String', 're', {explicit: true}); // 're'
|
||||
```
|
||||
|
||||
`explicit` sets whether to be in explicit mode or not. Using `*` automatically activates explicit mode. For more information, read the [levn format](#levn-format) section.
|
||||
|
||||
### customTypes
|
||||
|
||||
An `Object`. Empty `{}` by default.
|
||||
|
||||
__Example:__
|
||||
|
||||
```js
|
||||
var options = {
|
||||
customTypes: {
|
||||
Even: {
|
||||
typeOf: 'Number',
|
||||
validate: function (x) {
|
||||
return x % 2 === 0;
|
||||
},
|
||||
cast: function (x) {
|
||||
return {type: 'Just', value: parseInt(x)};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
parse('Even', '2', options); // 2
|
||||
parse('Even', '3', options); // Error: Value: "3" does not type check...
|
||||
```
|
||||
|
||||
__Another Example:__
|
||||
```js
|
||||
function Person(name, age){
|
||||
this.name = name;
|
||||
this.age = age;
|
||||
}
|
||||
var options = {
|
||||
customTypes: {
|
||||
Person: {
|
||||
typeOf: 'Object',
|
||||
validate: function (x) {
|
||||
x instanceof Person;
|
||||
},
|
||||
cast: function (value, options, typesCast) {
|
||||
var name, age;
|
||||
if ({}.toString.call(value).slice(8, -1) !== 'Object') {
|
||||
return {type: 'Nothing'};
|
||||
}
|
||||
name = typesCast(value.name, [{type: 'String'}], options);
|
||||
age = typesCast(value.age, [{type: 'Numger'}], options);
|
||||
return {type: 'Just', value: new Person(name, age)};
|
||||
}
|
||||
}
|
||||
}
|
||||
parse('Person', '{name: Laura, age: 25}', options); // Person {name: 'Laura', age: 25}
|
||||
```
|
||||
|
||||
`customTypes` is an object whose keys are the name of the types, and whose values are an object with three properties, `typeOf`, `validate`, and `cast`. For more information about `typeOf` and `validate`, please see the [custom types](https://github.com/gkz/type-check#custom-types) section of type-check.
|
||||
|
||||
`cast` is a function which receives three arguments, the value under question, options, and the typesCast function. In `cast`, attempt to cast the value into the specified type. If you are successful, return an object in the format `{type: 'Just', value: CAST-VALUE}`, if you know it won't work, return `{type: 'Nothing'}`. You can use the `typesCast` function to cast any child values. Remember to pass `options` to it. In your function you can also check for `options.explicit` and act accordingly.
|
||||
|
||||
## Technical About
|
||||
|
||||
`levn` is written in [LiveScript](http://livescript.net/) - a language that compiles to JavaScript. It uses [type-check](https://github.com/gkz/type-check) to both parse types and validate values. It also uses the [prelude.ls](http://preludels.com/) library.
|
||||
@@ -0,0 +1,3 @@
|
||||
<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<path d="M7.85822 8.84922L4.85322 11.8542C4.75891 11.9453 4.63261 11.9957 4.50151 11.9946C4.37042 11.9934 4.24501 11.9408 4.15231 11.8481C4.0596 11.7554 4.00702 11.63 4.00588 11.4989C4.00474 11.3678 4.05514 11.2415 4.14622 11.1472L7.15122 8.14222V7.85922L4.14622 4.85322C4.05514 4.75891 4.00474 4.63261 4.00588 4.50151C4.00702 4.37042 4.0596 4.24501 4.15231 4.15231C4.24501 4.0596 4.37042 4.00702 4.50151 4.00588C4.63261 4.00474 4.75891 4.05514 4.85322 4.14622L7.85822 7.15122H8.14122L11.1462 4.14622C11.2405 4.05514 11.3668 4.00474 11.4979 4.00588C11.629 4.00702 11.7544 4.0596 11.8471 4.15231C11.9398 4.24501 11.9924 4.37042 11.9936 4.50151C11.9947 4.63261 11.9443 4.75891 11.8532 4.85322L8.84822 7.85922V8.14222L11.8532 11.1472C11.9443 11.2415 11.9947 11.3678 11.9936 11.4989C11.9924 11.63 11.9398 11.7554 11.8471 11.8481C11.7544 11.9408 11.629 11.9934 11.4979 11.9946C11.3668 11.9957 11.2405 11.9453 11.1462 11.8542L8.14122 8.84922L8.14222 8.85022L7.85822 8.84922Z" fill="black"/>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 1.1 KiB |
@@ -0,0 +1 @@
|
||||
module.exports={A:{A:{"2":"K D E F mC","130":"A B"},B:{"1":"0 9 u v w x y z AB BB CB DB EB FB GB HB IB JB KB LB MB NB OB I","130":"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"},C:{"1":"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","2":"nC LC qC rC","130":"1 2 3 4 J PB K D E F A B C L M G N O P QB","322":"5 6 7 8 RB SB TB UB VB WB"},D:{"1":"0 9 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 F A B C L M G","130":"1 2 3 4 5 6 7 8 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"},E:{"1":"A B C L M G 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":"D E F sC SC uC vC","130":"J PB K tC"},F:{"1":"0 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","130":"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"},G:{"1":"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":"E SC CD DD ED","130":"9C lC AD BD"},H:{"2":"WD"},I:{"1":"I","2":"LC J XD YD ZD aD lC","130":"bD cD"},J:{"2":"D","130":"A"},K:{"1":"H","2":"A B C FC kC GC"},L:{"1":"I"},M:{"1":"EC"},N:{"2":"A B"},O:{"130":"HC"},P:{"1":"3 4 5 6 7 8","130":"1 2 J dD eD fD gD hD TC iD jD kD lD mD IC JC KC nD"},Q:{"130":"oD"},R:{"130":"pD"},S:{"1":"qD rD"}},B:5,C:"CSS font-variant-alternates",D:true};
|
||||
@@ -0,0 +1 @@
|
||||
module.exports={A:{A:{"2":"K D E F mC","129":"A B"},B:{"1":"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","129":"C L M G N O P"},C:{"1":"0 1 2 3 4 5 6 7 8 9 J PB K D E F A B C L M G N O P QB RB SB TB UB VB WB XB YB ZB aB bB cB dB eB fB gB hB iB jB kB lB mB nB oB pB qB rB sB tB uB vB MC wB NC xB yB zB 0B 1B 2B 3B 4B 5B 6B 7B 8B 9B AC BC CC DC Q H R OC S T U V W X Y Z a b c d e f g h i j k l m n o p q r s t u v w x y z AB BB CB DB EB FB GB HB IB JB KB LB MB NB OB I PC EC QC RC oC pC qC rC","2":"nC LC"},D:{"1":"0 1 2 3 4 5 6 7 8 9 J PB K D E F A B C L M G N O P QB RB SB TB UB VB WB XB YB ZB aB bB cB dB eB fB gB hB iB jB kB lB mB nB oB pB qB rB sB tB uB vB MC wB NC xB yB zB 0B 1B 2B 3B 4B 5B 6B 7B 8B 9B AC BC CC DC Q H R 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:{"1":"J PB K D E F A B C L M G tC uC vC wC TC FC GC xC yC zC UC VC HC 0C IC WC XC YC ZC aC 1C JC bC cC dC eC fC 2C KC gC hC iC jC 3C","260":"sC SC"},F:{"1":"0 1 2 3 4 5 6 7 8 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","2":"F"},G:{"1":"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:{"4":"WD"},I:{"1":"LC J I XD YD ZD aD lC bD cD"},J:{"1":"A","4":"D"},K:{"1":"A B C H FC kC GC"},L:{"1":"I"},M:{"1":"EC"},N:{"129":"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:4,C:"CSS3 Text-shadow",D:true};
|
||||
@@ -0,0 +1 @@
|
||||
module.exports={C:{"52":0.0285,"78":0.0057,"80":0.00285,"82":0.00285,"89":0.00285,"91":0.0057,"111":0.00285,"115":0.13965,"125":0.00285,"127":0.00285,"128":0.0171,"131":0.00285,"132":0.0057,"133":0.0057,"134":0.00855,"135":0.1995,"136":0.92055,"138":0.0057,_:"2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 79 81 83 84 85 86 87 88 90 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 112 113 114 116 117 118 119 120 121 122 123 124 126 129 130 137 139 140 3.5 3.6"},D:{"49":0.03135,"53":0.0057,"58":0.01425,"68":0.0057,"69":0.00285,"70":0.00285,"75":0.00285,"77":0.01425,"79":0.4389,"80":0.00285,"83":0.07125,"85":0.0114,"86":0.0057,"87":0.3477,"88":0.01995,"89":0.0171,"91":0.00855,"93":0.00285,"94":0.08265,"98":0.0057,"99":0.00285,"100":0.00285,"102":0.0057,"103":0.02565,"104":0.15105,"105":0.0285,"106":0.0171,"107":0.00285,"108":0.0228,"109":1.30815,"110":0.0114,"111":0.0228,"112":0.01425,"113":0.00285,"114":0.00285,"116":0.04275,"117":0.02565,"119":0.04845,"120":0.04275,"121":0.0114,"122":0.0741,"123":0.01995,"124":0.0228,"125":0.03705,"126":0.0798,"127":0.0285,"128":0.0456,"129":0.0342,"130":0.04275,"131":0.2052,"132":0.3135,"133":5.2326,"134":12.29205,"135":0.01995,_:"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 50 51 52 54 55 56 57 59 60 61 62 63 64 65 66 67 71 72 73 74 76 78 81 84 90 92 95 96 97 101 115 118 136 137 138"},F:{"31":0.00285,"36":0.00285,"40":0.01995,"46":0.03705,"68":0.342,"85":0.0057,"87":0.00285,"95":0.0228,"102":0.00285,"115":0.00285,"116":0.1767,"117":1.0032,_:"9 11 12 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 32 33 34 35 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 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 86 88 89 90 91 92 93 94 96 97 98 99 100 101 103 104 105 106 107 108 109 110 111 112 113 114 9.5-9.6 10.0-10.1 10.5 10.6 11.1 11.5 11.6 12.1"},B:{"92":0.0228,"107":0.00285,"109":0.00285,"114":0.0057,"119":0.00285,"120":0.00285,"122":0.00285,"123":0.0057,"124":0.0057,"125":0.00285,"126":0.0057,"130":0.00855,"131":0.01425,"132":0.02565,"133":0.31065,"134":0.88635,_:"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 108 110 111 112 113 115 116 117 118 121 127 128 129"},E:{"14":0.01425,_:"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 15.4 17.0","13.1":0.01425,"14.1":0.03705,"15.1":0.00855,"15.2-15.3":0.00285,"15.5":0.00285,"15.6":0.057,"16.0":0.00285,"16.1":0.0057,"16.2":0.00285,"16.3":0.0114,"16.4":0.01995,"16.5":0.0114,"16.6":0.09975,"17.1":0.02565,"17.2":0.0057,"17.3":0.00285,"17.4":0.0171,"17.5":0.04275,"17.6":0.1197,"18.0":0.01425,"18.1":0.0399,"18.2":0.03135,"18.3":0.49305,"18.4":0.0057},G:{"8":0,"3.2":0,"4.0-4.1":0,"4.2-4.3":0.00296,"5.0-5.1":0,"6.0-6.1":0.00888,"7.0-7.1":0.00592,"8.1-8.4":0,"9.0-9.2":0.00444,"9.3":0.02073,"10.0-10.2":0.00148,"10.3":0.03406,"11.0-11.2":0.15696,"11.3-11.4":0.01037,"12.0-12.1":0.00592,"12.2-12.5":0.1466,"13.0-13.1":0.00296,"13.2":0.00444,"13.3":0.00592,"13.4-13.7":0.02073,"14.0-14.4":0.05183,"14.5-14.8":0.06219,"15.0-15.1":0.03406,"15.2-15.3":0.03406,"15.4":0.04146,"15.5":0.04738,"15.6-15.8":0.58342,"16.0":0.08292,"16.1":0.17029,"16.2":0.08885,"16.3":0.154,"16.4":0.03406,"16.5":0.06367,"16.6-16.7":0.69152,"17.0":0.04146,"17.1":0.07404,"17.2":0.05627,"17.3":0.07848,"17.4":0.15696,"17.5":0.34946,"17.6-17.7":1.01432,"18.0":0.28431,"18.1":0.92992,"18.2":0.41609,"18.3":8.69653,"18.4":0.12883},P:{"4":0.2887,"20":0.03093,"21":0.03093,"22":0.05155,"23":0.18559,"24":0.12373,"25":0.08249,"26":0.24746,"27":4.23773,"5.0-5.4":0.01031,"6.2-6.4":0.13404,"7.2-7.4":0.22684,_:"8.2 9.2 12.0 13.0 14.0 15.0 16.0","10.1":0.06186,"11.1-11.2":0.04124,"17.0":0.01031,"18.0":0.01031,"19.0":0.01031},I:{"0":0.00713,"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.5005,_:"10 11 12 11.1 11.5 12.1"},A:{"11":0.0171,_:"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.1716},Q:{_:"14.9"},O:{"0":0.0143},H:{"0":0},L:{"0":51.31235}};
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"names":["_superPropBase","require","_get","Reflect","get","exports","default","bind","target","property","receiver","base","superPropBase","desc","Object","getOwnPropertyDescriptor","call","arguments","length","value","apply"],"sources":["../../src/helpers/get.ts"],"sourcesContent":["/* @minVersion 7.0.0-beta.0 */\n\nimport superPropBase from \"./superPropBase.ts\";\n\n// https://tc39.es/ecma262/multipage/reflection.html#sec-reflect.get\n//\n// 28.1ak.5 Reflect.get ( target, propertyKey [ , receiver ] )\nexport default function _get<T extends object, P extends PropertyKey>(\n target: T,\n property: P,\n receiver?: unknown,\n): P extends keyof T ? T[P] : any;\nexport default function _get(): any {\n if (typeof Reflect !== \"undefined\" && Reflect.get) {\n // need a bind because https://github.com/babel/babel/issues/14527\n // @ts-expect-error function reassign\n _get = Reflect.get.bind(/* undefined */);\n } else {\n // @ts-expect-error function reassign\n _get = function _get(target, property, receiver) {\n var base = superPropBase(target, property);\n\n if (!base) return;\n\n var desc = Object.getOwnPropertyDescriptor(base, property)!;\n if (desc.get) {\n // STEP 3. If receiver is not present, then set receiver to target.\n return desc.get.call(arguments.length < 3 ? target : receiver);\n }\n\n return desc.value;\n };\n }\n\n return _get.apply(null, arguments as any as Parameters<typeof Reflect.get>);\n}\n"],"mappings":";;;;;;AAEA,IAAAA,cAAA,GAAAC,OAAA;AAUe,SAASC,IAAIA,CAAA,EAAQ;EAClC,IAAI,OAAOC,OAAO,KAAK,WAAW,IAAIA,OAAO,CAACC,GAAG,EAAE;IAGjDC,OAAA,CAAAC,OAAA,GAAAJ,IAAI,GAAGC,OAAO,CAACC,GAAG,CAACG,IAAI,CAAgB,CAAC;EAC1C,CAAC,MAAM;IAELF,OAAA,CAAAC,OAAA,GAAAJ,IAAI,GAAG,SAASA,IAAIA,CAACM,MAAM,EAAEC,QAAQ,EAAEC,QAAQ,EAAE;MAC/C,IAAIC,IAAI,GAAG,IAAAC,sBAAa,EAACJ,MAAM,EAAEC,QAAQ,CAAC;MAE1C,IAAI,CAACE,IAAI,EAAE;MAEX,IAAIE,IAAI,GAAGC,MAAM,CAACC,wBAAwB,CAACJ,IAAI,EAAEF,QAAQ,CAAE;MAC3D,IAAII,IAAI,CAACT,GAAG,EAAE;QAEZ,OAAOS,IAAI,CAACT,GAAG,CAACY,IAAI,CAACC,SAAS,CAACC,MAAM,GAAG,CAAC,GAAGV,MAAM,GAAGE,QAAQ,CAAC;MAChE;MAEA,OAAOG,IAAI,CAACM,KAAK;IACnB,CAAC;EACH;EAEA,OAAOjB,IAAI,CAACkB,KAAK,CAAC,IAAI,EAAEH,SAAkD,CAAC;AAC7E","ignoreList":[]}
|
||||
@@ -0,0 +1,12 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = _classPrivateFieldKey;
|
||||
var id = 0;
|
||||
function _classPrivateFieldKey(name) {
|
||||
return "__private_" + id++ + "_" + name;
|
||||
}
|
||||
|
||||
//# sourceMappingURL=classPrivateFieldLooseKey.js.map
|
||||
@@ -0,0 +1,79 @@
|
||||
{
|
||||
"name": "merge-refs",
|
||||
"version": "1.3.0",
|
||||
"description": "A function that merges React refs into one.",
|
||||
"type": "module",
|
||||
"sideEffects": false,
|
||||
"main": "./dist/cjs/index.js",
|
||||
"module": "./dist/esm/index.js",
|
||||
"source": "./src/index.ts",
|
||||
"types": "./dist/cjs/index.d.ts",
|
||||
"exports": {
|
||||
"import": "./dist/esm/index.js",
|
||||
"require": "./dist/cjs/index.js"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "yarn build-esm && yarn build-cjs && yarn build-cjs-package",
|
||||
"build-esm": "tsc --project tsconfig.build.json --outDir dist/esm",
|
||||
"build-cjs": "tsc --project tsconfig.build.json --outDir dist/cjs --module commonjs --moduleResolution node --verbatimModuleSyntax false",
|
||||
"build-cjs-package": "echo '{\n \"type\": \"commonjs\"\n}' > dist/cjs/package.json",
|
||||
"clean": "rimraf dist",
|
||||
"format": "prettier --check . --cache",
|
||||
"lint": "eslint . --ext .js,.jsx,.ts,.tsx",
|
||||
"prepack": "yarn clean && yarn build",
|
||||
"test": "yarn lint && yarn tsc && yarn format && yarn unit",
|
||||
"tsc": "tsc",
|
||||
"unit": "vitest"
|
||||
},
|
||||
"keywords": [
|
||||
"react",
|
||||
"react ref",
|
||||
"react refs",
|
||||
"merge"
|
||||
],
|
||||
"author": {
|
||||
"name": "Wojciech Maj",
|
||||
"email": "kontakt@wojtekmaj.pl"
|
||||
},
|
||||
"license": "MIT",
|
||||
"devDependencies": {
|
||||
"@testing-library/react": "^15.0.0",
|
||||
"@types/react": "*",
|
||||
"eslint": "^8.56.0",
|
||||
"eslint-config-wojtekmaj": "^1.0.0",
|
||||
"happy-dom": "^12.6.0",
|
||||
"husky": "^9.0.0",
|
||||
"lint-staged": "^15.0.0",
|
||||
"prettier": "^3.2.0",
|
||||
"react": "^18.2.0",
|
||||
"react-dom": "^18.2.0",
|
||||
"rimraf": "^3.0.0",
|
||||
"typescript": "^5.4.2",
|
||||
"vitest": "^1.0.2"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@types/react": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"@types/react": {
|
||||
"optional": true
|
||||
}
|
||||
},
|
||||
"resolutions": {
|
||||
"eslint-plugin-import": "npm:eslint-plugin-i@^2.28.0"
|
||||
},
|
||||
"publishConfig": {
|
||||
"access": "public",
|
||||
"provenance": true
|
||||
},
|
||||
"files": [
|
||||
"dist",
|
||||
"src"
|
||||
],
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/wojtekmaj/merge-refs.git"
|
||||
},
|
||||
"funding": "https://github.com/wojtekmaj/merge-refs?sponsor=1",
|
||||
"packageManager": "yarn@4.1.1"
|
||||
}
|
||||
@@ -0,0 +1,316 @@
|
||||
'use client';
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
var __rest = (this && this.__rest) || function (s, e) {
|
||||
var t = {};
|
||||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
||||
t[p] = s[p];
|
||||
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
||||
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
||||
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
||||
t[p[i]] = s[p[i]];
|
||||
}
|
||||
return t;
|
||||
};
|
||||
import { jsx as _jsx } from "react/jsx-runtime";
|
||||
import { forwardRef, useCallback, useEffect, useImperativeHandle, useMemo, useRef } from 'react';
|
||||
import makeEventProps from 'make-event-props';
|
||||
import makeCancellable from 'make-cancellable-promise';
|
||||
import clsx from 'clsx';
|
||||
import invariant from 'tiny-invariant';
|
||||
import warning from 'warning';
|
||||
import { dequal } from 'dequal';
|
||||
import * as pdfjs from 'pdfjs-dist';
|
||||
import DocumentContext from './DocumentContext.js';
|
||||
import Message from './Message.js';
|
||||
import LinkService from './LinkService.js';
|
||||
import PasswordResponses from './PasswordResponses.js';
|
||||
import { cancelRunningTask, dataURItoByteString, displayCORSWarning, isArrayBuffer, isBlob, isBrowser, isDataURI, loadFromFile, } from './shared/utils.js';
|
||||
import useResolver from './shared/hooks/useResolver.js';
|
||||
const { PDFDataRangeTransport } = pdfjs;
|
||||
const defaultOnPassword = (callback, reason) => {
|
||||
switch (reason) {
|
||||
case PasswordResponses.NEED_PASSWORD: {
|
||||
const password = prompt('Enter the password to open this PDF file.');
|
||||
callback(password);
|
||||
break;
|
||||
}
|
||||
case PasswordResponses.INCORRECT_PASSWORD: {
|
||||
const password = prompt('Invalid password. Please try again.');
|
||||
callback(password);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
}
|
||||
};
|
||||
function isParameterObject(file) {
|
||||
return (typeof file === 'object' &&
|
||||
file !== null &&
|
||||
('data' in file || 'range' in file || 'url' in file));
|
||||
}
|
||||
/**
|
||||
* Loads a document passed using `file` prop.
|
||||
*/
|
||||
const Document = forwardRef(function Document(_a, ref) {
|
||||
var { children, className, error = 'Failed to load PDF file.', externalLinkRel, externalLinkTarget, file, inputRef, imageResourcesPath, loading = 'Loading PDF…', noData = 'No PDF file specified.', onItemClick, onLoadError: onLoadErrorProps, onLoadProgress, onLoadSuccess: onLoadSuccessProps, onPassword = defaultOnPassword, onSourceError: onSourceErrorProps, onSourceSuccess: onSourceSuccessProps, options, renderMode, rotate } = _a, otherProps = __rest(_a, ["children", "className", "error", "externalLinkRel", "externalLinkTarget", "file", "inputRef", "imageResourcesPath", "loading", "noData", "onItemClick", "onLoadError", "onLoadProgress", "onLoadSuccess", "onPassword", "onSourceError", "onSourceSuccess", "options", "renderMode", "rotate"]);
|
||||
const [sourceState, sourceDispatch] = useResolver();
|
||||
const { value: source, error: sourceError } = sourceState;
|
||||
const [pdfState, pdfDispatch] = useResolver();
|
||||
const { value: pdf, error: pdfError } = pdfState;
|
||||
const linkService = useRef(new LinkService());
|
||||
const pages = useRef([]);
|
||||
const prevFile = useRef(undefined);
|
||||
const prevOptions = useRef(undefined);
|
||||
if (file && file !== prevFile.current && isParameterObject(file)) {
|
||||
warning(!dequal(file, prevFile.current), `File prop passed to <Document /> changed, but it's equal to previous one. This might result in unnecessary reloads. Consider memoizing the value passed to "file" prop.`);
|
||||
prevFile.current = file;
|
||||
}
|
||||
// Detect non-memoized changes in options prop
|
||||
if (options && options !== prevOptions.current) {
|
||||
warning(!dequal(options, prevOptions.current), `Options prop passed to <Document /> changed, but it's equal to previous one. This might result in unnecessary reloads. Consider memoizing the value passed to "options" prop.`);
|
||||
prevOptions.current = options;
|
||||
}
|
||||
const viewer = useRef({
|
||||
// Handling jumping to internal links target
|
||||
scrollPageIntoView: (args) => {
|
||||
const { dest, pageNumber, pageIndex = pageNumber - 1 } = args;
|
||||
// First, check if custom handling of onItemClick was provided
|
||||
if (onItemClick) {
|
||||
onItemClick({ dest, pageIndex, pageNumber });
|
||||
return;
|
||||
}
|
||||
// If not, try to look for target page within the <Document>.
|
||||
const page = pages.current[pageIndex];
|
||||
if (page) {
|
||||
// Scroll to the page automatically
|
||||
page.scrollIntoView();
|
||||
return;
|
||||
}
|
||||
warning(false, `An internal link leading to page ${pageNumber} was clicked, but neither <Document> was provided with onItemClick nor it was able to find the page within itself. Either provide onItemClick to <Document> and handle navigating by yourself or ensure that all pages are rendered within <Document>.`);
|
||||
},
|
||||
});
|
||||
useImperativeHandle(ref, () => ({
|
||||
linkService,
|
||||
pages,
|
||||
viewer,
|
||||
}), []);
|
||||
/**
|
||||
* Called when a document source is resolved correctly
|
||||
*/
|
||||
function onSourceSuccess() {
|
||||
if (onSourceSuccessProps) {
|
||||
onSourceSuccessProps();
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Called when a document source failed to be resolved correctly
|
||||
*/
|
||||
function onSourceError() {
|
||||
if (!sourceError) {
|
||||
// Impossible, but TypeScript doesn't know that
|
||||
return;
|
||||
}
|
||||
warning(false, sourceError.toString());
|
||||
if (onSourceErrorProps) {
|
||||
onSourceErrorProps(sourceError);
|
||||
}
|
||||
}
|
||||
function resetSource() {
|
||||
sourceDispatch({ type: 'RESET' });
|
||||
}
|
||||
// biome-ignore lint/correctness/useExhaustiveDependencies: See https://github.com/biomejs/biome/issues/3080
|
||||
useEffect(resetSource, [file, sourceDispatch]);
|
||||
const findDocumentSource = useCallback(() => __awaiter(this, void 0, void 0, function* () {
|
||||
if (!file) {
|
||||
return null;
|
||||
}
|
||||
// File is a string
|
||||
if (typeof file === 'string') {
|
||||
if (isDataURI(file)) {
|
||||
const fileByteString = dataURItoByteString(file);
|
||||
return { data: fileByteString };
|
||||
}
|
||||
displayCORSWarning();
|
||||
return { url: file };
|
||||
}
|
||||
// File is PDFDataRangeTransport
|
||||
if (file instanceof PDFDataRangeTransport) {
|
||||
return { range: file };
|
||||
}
|
||||
// File is an ArrayBuffer
|
||||
if (isArrayBuffer(file)) {
|
||||
return { data: file };
|
||||
}
|
||||
/**
|
||||
* The cases below are browser-only.
|
||||
* If you're running on a non-browser environment, these cases will be of no use.
|
||||
*/
|
||||
if (isBrowser) {
|
||||
// File is a Blob
|
||||
if (isBlob(file)) {
|
||||
const data = yield loadFromFile(file);
|
||||
return { data };
|
||||
}
|
||||
}
|
||||
// At this point, file must be an object
|
||||
invariant(typeof file === 'object', 'Invalid parameter in file, need either Uint8Array, string or a parameter object');
|
||||
invariant(isParameterObject(file), 'Invalid parameter object: need either .data, .range or .url');
|
||||
// File .url is a string
|
||||
if ('url' in file && typeof file.url === 'string') {
|
||||
if (isDataURI(file.url)) {
|
||||
const { url } = file, otherParams = __rest(file, ["url"]);
|
||||
const fileByteString = dataURItoByteString(url);
|
||||
return Object.assign({ data: fileByteString }, otherParams);
|
||||
}
|
||||
displayCORSWarning();
|
||||
}
|
||||
return file;
|
||||
}), [file]);
|
||||
useEffect(() => {
|
||||
const cancellable = makeCancellable(findDocumentSource());
|
||||
cancellable.promise
|
||||
.then((nextSource) => {
|
||||
sourceDispatch({ type: 'RESOLVE', value: nextSource });
|
||||
})
|
||||
.catch((error) => {
|
||||
sourceDispatch({ type: 'REJECT', error });
|
||||
});
|
||||
return () => {
|
||||
cancelRunningTask(cancellable);
|
||||
};
|
||||
}, [findDocumentSource, sourceDispatch]);
|
||||
// biome-ignore lint/correctness/useExhaustiveDependencies: Ommitted callbacks so they are not called every time they change
|
||||
useEffect(() => {
|
||||
if (typeof source === 'undefined') {
|
||||
return;
|
||||
}
|
||||
if (source === false) {
|
||||
onSourceError();
|
||||
return;
|
||||
}
|
||||
onSourceSuccess();
|
||||
}, [source]);
|
||||
/**
|
||||
* Called when a document is read successfully
|
||||
*/
|
||||
function onLoadSuccess() {
|
||||
if (!pdf) {
|
||||
// Impossible, but TypeScript doesn't know that
|
||||
return;
|
||||
}
|
||||
if (onLoadSuccessProps) {
|
||||
onLoadSuccessProps(pdf);
|
||||
}
|
||||
pages.current = new Array(pdf.numPages);
|
||||
linkService.current.setDocument(pdf);
|
||||
}
|
||||
/**
|
||||
* Called when a document failed to read successfully
|
||||
*/
|
||||
function onLoadError() {
|
||||
if (!pdfError) {
|
||||
// Impossible, but TypeScript doesn't know that
|
||||
return;
|
||||
}
|
||||
warning(false, pdfError.toString());
|
||||
if (onLoadErrorProps) {
|
||||
onLoadErrorProps(pdfError);
|
||||
}
|
||||
}
|
||||
// biome-ignore lint/correctness/useExhaustiveDependencies: useEffect intentionally triggered on source change
|
||||
useEffect(function resetDocument() {
|
||||
pdfDispatch({ type: 'RESET' });
|
||||
}, [pdfDispatch, source]);
|
||||
// biome-ignore lint/correctness/useExhaustiveDependencies: Ommitted callbacks so they are not called every time they change
|
||||
useEffect(function loadDocument() {
|
||||
if (!source) {
|
||||
return;
|
||||
}
|
||||
const documentInitParams = options
|
||||
? Object.assign(Object.assign({}, source), options) : source;
|
||||
const destroyable = pdfjs.getDocument(documentInitParams);
|
||||
if (onLoadProgress) {
|
||||
destroyable.onProgress = onLoadProgress;
|
||||
}
|
||||
if (onPassword) {
|
||||
destroyable.onPassword = onPassword;
|
||||
}
|
||||
const loadingTask = destroyable;
|
||||
const loadingPromise = loadingTask.promise
|
||||
.then((nextPdf) => {
|
||||
pdfDispatch({ type: 'RESOLVE', value: nextPdf });
|
||||
})
|
||||
.catch((error) => {
|
||||
if (loadingTask.destroyed) {
|
||||
return;
|
||||
}
|
||||
pdfDispatch({ type: 'REJECT', error });
|
||||
});
|
||||
return () => {
|
||||
loadingPromise.finally(() => loadingTask.destroy());
|
||||
};
|
||||
}, [options, pdfDispatch, source]);
|
||||
// biome-ignore lint/correctness/useExhaustiveDependencies: Ommitted callbacks so they are not called every time they change
|
||||
useEffect(() => {
|
||||
if (typeof pdf === 'undefined') {
|
||||
return;
|
||||
}
|
||||
if (pdf === false) {
|
||||
onLoadError();
|
||||
return;
|
||||
}
|
||||
onLoadSuccess();
|
||||
}, [pdf]);
|
||||
useEffect(function setupLinkService() {
|
||||
linkService.current.setViewer(viewer.current);
|
||||
linkService.current.setExternalLinkRel(externalLinkRel);
|
||||
linkService.current.setExternalLinkTarget(externalLinkTarget);
|
||||
}, [externalLinkRel, externalLinkTarget]);
|
||||
const registerPage = useCallback((pageIndex, ref) => {
|
||||
pages.current[pageIndex] = ref;
|
||||
}, []);
|
||||
const unregisterPage = useCallback((pageIndex) => {
|
||||
delete pages.current[pageIndex];
|
||||
}, []);
|
||||
const childContext = useMemo(() => ({
|
||||
imageResourcesPath,
|
||||
linkService: linkService.current,
|
||||
onItemClick,
|
||||
pdf,
|
||||
registerPage,
|
||||
renderMode,
|
||||
rotate,
|
||||
unregisterPage,
|
||||
}), [imageResourcesPath, onItemClick, pdf, registerPage, renderMode, rotate, unregisterPage]);
|
||||
const eventProps = useMemo(() => makeEventProps(otherProps, () => pdf),
|
||||
// biome-ignore lint/correctness/useExhaustiveDependencies: FIXME
|
||||
[otherProps, pdf]);
|
||||
function renderChildren() {
|
||||
return _jsx(DocumentContext.Provider, { value: childContext, children: children });
|
||||
}
|
||||
function renderContent() {
|
||||
if (!file) {
|
||||
return _jsx(Message, { type: "no-data", children: typeof noData === 'function' ? noData() : noData });
|
||||
}
|
||||
if (pdf === undefined || pdf === null) {
|
||||
return (_jsx(Message, { type: "loading", children: typeof loading === 'function' ? loading() : loading }));
|
||||
}
|
||||
if (pdf === false) {
|
||||
return _jsx(Message, { type: "error", children: typeof error === 'function' ? error() : error });
|
||||
}
|
||||
return renderChildren();
|
||||
}
|
||||
return (_jsx("div", Object.assign({ className: clsx('react-pdf__Document', className),
|
||||
// Assertion is needed for React 18 compatibility
|
||||
ref: inputRef, style: {
|
||||
['--scale-factor']: '1',
|
||||
} }, eventProps, { children: renderContent() })));
|
||||
});
|
||||
export default Document;
|
||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1 @@
|
||||
{"version":3,"names":["_arrayLikeToArray","require","_maybeArrayLike","orElse","arr","i","Array","isArray","length","len","arrayLikeToArray"],"sources":["../../src/helpers/maybeArrayLike.ts"],"sourcesContent":["/* @minVersion 7.9.0 */\n\nimport arrayLikeToArray from \"./arrayLikeToArray.ts\";\n\nexport default function _maybeArrayLike<T>(\n orElse: (arr: any, i: number) => T[] | undefined,\n arr: ArrayLike<T>,\n i: number,\n) {\n if (arr && !Array.isArray(arr) && typeof arr.length === \"number\") {\n var len = arr.length;\n return arrayLikeToArray<T>(arr, i !== void 0 && i < len ? i : len);\n }\n return orElse(arr, i);\n}\n"],"mappings":";;;;;;AAEA,IAAAA,iBAAA,GAAAC,OAAA;AAEe,SAASC,eAAeA,CACrCC,MAAgD,EAChDC,GAAiB,EACjBC,CAAS,EACT;EACA,IAAID,GAAG,IAAI,CAACE,KAAK,CAACC,OAAO,CAACH,GAAG,CAAC,IAAI,OAAOA,GAAG,CAACI,MAAM,KAAK,QAAQ,EAAE;IAChE,IAAIC,GAAG,GAAGL,GAAG,CAACI,MAAM;IACpB,OAAO,IAAAE,yBAAgB,EAAIN,GAAG,EAAEC,CAAC,KAAK,KAAK,CAAC,IAAIA,CAAC,GAAGI,GAAG,GAAGJ,CAAC,GAAGI,GAAG,CAAC;EACpE;EACA,OAAON,MAAM,CAACC,GAAG,EAAEC,CAAC,CAAC;AACvB","ignoreList":[]}
|
||||
@@ -0,0 +1,22 @@
|
||||
Copyright (c) 2012, 2013 Thorsten Lorenz <thlorenz@gmx.de>
|
||||
Copyright (c) 2012 James Halliday <mail@substack.net>
|
||||
Copyright (c) 2009 Thomas Robinson <280north.com>
|
||||
|
||||
This software is released under the MIT license:
|
||||
|
||||
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.
|
||||
Reference in New Issue
Block a user