update
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
export * from './middleware/redux.mjs';
|
||||
export * from './middleware/devtools.mjs';
|
||||
export * from './middleware/subscribeWithSelector.mjs';
|
||||
export * from './middleware/combine.mjs';
|
||||
export * from './middleware/persist.mjs';
|
||||
@@ -0,0 +1,52 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = _asyncGeneratorDelegate;
|
||||
var _OverloadYield = require("./OverloadYield.js");
|
||||
function _asyncGeneratorDelegate(inner) {
|
||||
var iter = {},
|
||||
waiting = false;
|
||||
function pump(key, value) {
|
||||
waiting = true;
|
||||
value = new Promise(function (resolve) {
|
||||
resolve(inner[key](value));
|
||||
});
|
||||
return {
|
||||
done: false,
|
||||
value: new _OverloadYield.default(value, 1)
|
||||
};
|
||||
}
|
||||
iter[typeof Symbol !== "undefined" && Symbol.iterator || "@@iterator"] = function () {
|
||||
return this;
|
||||
};
|
||||
iter.next = function (value) {
|
||||
if (waiting) {
|
||||
waiting = false;
|
||||
return value;
|
||||
}
|
||||
return pump("next", value);
|
||||
};
|
||||
if (typeof inner.throw === "function") {
|
||||
iter.throw = function (value) {
|
||||
if (waiting) {
|
||||
waiting = false;
|
||||
throw value;
|
||||
}
|
||||
return pump("throw", value);
|
||||
};
|
||||
}
|
||||
if (typeof inner.return === "function") {
|
||||
iter.return = function (value) {
|
||||
if (waiting) {
|
||||
waiting = false;
|
||||
return value;
|
||||
}
|
||||
return pump("return", value);
|
||||
};
|
||||
}
|
||||
return iter;
|
||||
}
|
||||
|
||||
//# sourceMappingURL=asyncGeneratorDelegate.js.map
|
||||
@@ -0,0 +1,11 @@
|
||||
Copyright 2011 Gary Court. All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY GARY COURT "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GARY COURT OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
The views and conclusions contained in the software and documentation are those of the authors and should not be interpreted as representing official policies, either expressed or implied, of Gary Court.
|
||||
@@ -0,0 +1,15 @@
|
||||
Apache License, Version 2.0
|
||||
|
||||
Copyright (c) 2011 Dominic Tarr
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -0,0 +1 @@
|
||||
{"version":3,"names":["_temporalUndefined","require","_tdz","_temporalRef","val","name","undef","err"],"sources":["../../src/helpers/temporalRef.ts"],"sourcesContent":["/* @minVersion 7.0.0-beta.0 */\n\nimport undef from \"./temporalUndefined.ts\";\nimport err from \"./tdz.ts\";\n\nexport default function _temporalRef<T>(val: T, name: string) {\n return val === undef ? err(name) : val;\n}\n"],"mappings":";;;;;;AAEA,IAAAA,kBAAA,GAAAC,OAAA;AACA,IAAAC,IAAA,GAAAD,OAAA;AAEe,SAASE,YAAYA,CAAIC,GAAM,EAAEC,IAAY,EAAE;EAC5D,OAAOD,GAAG,KAAKE,0BAAK,GAAG,IAAAC,YAAG,EAACF,IAAI,CAAC,GAAGD,GAAG;AACxC","ignoreList":[]}
|
||||
@@ -0,0 +1,43 @@
|
||||
{{# def.definitions }}
|
||||
{{# def.errors }}
|
||||
{{# def.setupKeyword }}
|
||||
{{# def.setupNextLevel }}
|
||||
|
||||
{{? {{# def.nonEmptySchema:$schema }} }}
|
||||
{{
|
||||
$it.schema = $schema;
|
||||
$it.schemaPath = $schemaPath;
|
||||
$it.errSchemaPath = $errSchemaPath;
|
||||
}}
|
||||
|
||||
var {{=$errs}} = errors;
|
||||
|
||||
{{# def.setCompositeRule }}
|
||||
|
||||
{{
|
||||
$it.createErrors = false;
|
||||
var $allErrorsOption;
|
||||
if ($it.opts.allErrors) {
|
||||
$allErrorsOption = $it.opts.allErrors;
|
||||
$it.opts.allErrors = false;
|
||||
}
|
||||
}}
|
||||
{{= it.validate($it) }}
|
||||
{{
|
||||
$it.createErrors = true;
|
||||
if ($allErrorsOption) $it.opts.allErrors = $allErrorsOption;
|
||||
}}
|
||||
|
||||
{{# def.resetCompositeRule }}
|
||||
|
||||
if ({{=$nextValid}}) {
|
||||
{{# def.error:'not' }}
|
||||
} else {
|
||||
{{# def.resetErrors }}
|
||||
{{? it.opts.allErrors }} } {{?}}
|
||||
{{??}}
|
||||
{{# def.addError:'not' }}
|
||||
{{? $breakOnError}}
|
||||
if (false) {
|
||||
{{?}}
|
||||
{{?}}
|
||||
@@ -0,0 +1,24 @@
|
||||
import { jsx } from "react/jsx-runtime";
|
||||
import { defaultGetScrollRestorationKey, restoreScroll, storageKey } from "@tanstack/router-core";
|
||||
import { useRouter } from "./useRouter.js";
|
||||
import { ScriptOnce } from "./ScriptOnce.js";
|
||||
function ScrollRestoration() {
|
||||
const router = useRouter();
|
||||
const getKey = router.options.getScrollRestorationKey || defaultGetScrollRestorationKey;
|
||||
const userKey = getKey(router.latestLocation);
|
||||
const resolvedKey = userKey !== defaultGetScrollRestorationKey(router.latestLocation) ? userKey : null;
|
||||
if (!router.isScrollRestoring || !router.isServer) {
|
||||
return null;
|
||||
}
|
||||
return /* @__PURE__ */ jsx(
|
||||
ScriptOnce,
|
||||
{
|
||||
children: `(${restoreScroll.toString()})(${JSON.stringify(storageKey)},${JSON.stringify(resolvedKey)}, undefined, true)`,
|
||||
log: false
|
||||
}
|
||||
);
|
||||
}
|
||||
export {
|
||||
ScrollRestoration
|
||||
};
|
||||
//# sourceMappingURL=scroll-restoration.js.map
|
||||
@@ -0,0 +1 @@
|
||||
module.exports={C:{"36":0.00195,"72":0.00584,"80":0.00195,"84":0.00195,"105":0.00195,"107":0.00195,"108":0.00195,"109":0.00195,"110":0.00195,"115":0.11871,"118":0.00195,"120":0.00195,"121":0.00195,"122":0.00195,"123":0.00195,"124":0.00195,"125":0.00195,"126":0.00389,"127":0.01946,"128":0.01168,"129":0.00389,"130":0.00389,"131":0.00584,"132":0.01168,"133":0.01362,"134":0.01946,"135":0.34444,"136":0.8757,"137":0.0253,_:"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 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 73 74 75 76 77 78 79 81 82 83 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 106 111 112 113 114 116 117 119 138 139 140 3.5 3.6"},D:{"11":0.00389,"38":0.00195,"39":0.00195,"40":0.00389,"41":0.00195,"42":0.00389,"43":0.00778,"44":0.00195,"45":0.00195,"46":0.00195,"47":0.00584,"48":0.00195,"49":0.00195,"50":0.00195,"51":0.00195,"52":0.00195,"53":0.00389,"54":0.00195,"55":0.00584,"56":0.00389,"57":0.00195,"58":0.00195,"59":0.00195,"60":0.00195,"61":0.02141,"62":0.00195,"67":0.00195,"69":0.00195,"70":0.00389,"71":0.01557,"72":0.00195,"74":0.00389,"78":0.00389,"79":0.01168,"80":0.00389,"83":0.00389,"85":0.00195,"86":0.00195,"87":0.00973,"88":0.00584,"89":0.01168,"90":0.00195,"91":0.00195,"92":0.00389,"94":0.00195,"95":0.00973,"97":0.00389,"98":0.00195,"99":0.00389,"100":0.01557,"101":0.00195,"102":0.00389,"103":0.01168,"104":0.00584,"105":0.00389,"106":0.01946,"107":0.01557,"108":0.00584,"109":0.42228,"110":0.00389,"111":0.00389,"112":0.00195,"113":0.00584,"114":0.02335,"115":0.01557,"116":0.01557,"117":0.00389,"118":0.01557,"119":0.01168,"120":0.03114,"121":0.00778,"122":0.06422,"123":0.01362,"124":0.05254,"125":0.01946,"126":0.06811,"127":0.02724,"128":0.03892,"129":0.03892,"130":0.05254,"131":0.12649,"132":0.11287,"133":3.13306,"134":5.74459,"135":0.00778,"136":0.00389,_:"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 63 64 65 66 68 73 75 76 77 81 84 93 96 137 138"},F:{"82":0.00389,"87":0.00389,"88":0.00195,"95":0.00195,"101":0.00389,"102":0.00195,"103":0.00195,"107":0.00195,"109":0.00389,"110":0.00389,"111":0.00195,"112":0.00195,"113":0.00584,"114":0.01557,"115":0.00973,"116":0.04865,"117":0.1479,_:"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 83 84 85 86 89 90 91 92 93 94 96 97 98 99 100 104 105 106 108 9.5-9.6 10.0-10.1 10.5 10.6 11.1 11.5 11.6 12.1"},B:{"17":0.00195,"18":0.00778,"84":0.00195,"89":0.00195,"90":0.00195,"92":0.02141,"100":0.00195,"105":0.00195,"109":0.00389,"114":0.00778,"117":0.01168,"122":0.00389,"125":0.00195,"126":0.00195,"127":0.00195,"128":0.00389,"129":0.01362,"130":0.00778,"131":0.07589,"132":0.04087,"133":0.54293,"134":1.07808,_:"12 13 14 15 16 79 80 81 83 85 86 87 88 91 93 94 95 96 97 98 99 101 102 103 104 106 107 108 110 111 112 113 115 116 118 119 120 121 123 124"},E:{_:"0 4 5 6 7 8 9 10 11 12 13 14 15 3.1 3.2 5.1 6.1 7.1 9.1 10.1 15.2-15.3 15.4","11.1":0.00195,"12.1":0.00195,"13.1":0.00389,"14.1":0.00778,"15.1":0.00389,"15.5":0.00195,"15.6":0.02141,"16.0":0.00389,"16.1":0.00389,"16.2":0.00195,"16.3":0.00584,"16.4":0.00389,"16.5":0.00973,"16.6":0.03308,"17.0":0.00584,"17.1":0.00778,"17.2":0.00195,"17.3":0.00195,"17.4":0.01557,"17.5":0.01946,"17.6":0.06616,"18.0":0.03892,"18.1":0.04865,"18.2":0.01946,"18.3":0.37752,"18.4":0.00584},G:{"8":0,"3.2":0,"4.0-4.1":0,"4.2-4.3":0.00089,"5.0-5.1":0,"6.0-6.1":0.00268,"7.0-7.1":0.00178,"8.1-8.4":0,"9.0-9.2":0.00134,"9.3":0.00625,"10.0-10.2":0.00045,"10.3":0.01026,"11.0-11.2":0.04729,"11.3-11.4":0.00312,"12.0-12.1":0.00178,"12.2-12.5":0.04417,"13.0-13.1":0.00089,"13.2":0.00134,"13.3":0.00178,"13.4-13.7":0.00625,"14.0-14.4":0.01561,"14.5-14.8":0.01874,"15.0-15.1":0.01026,"15.2-15.3":0.01026,"15.4":0.01249,"15.5":0.01428,"15.6-15.8":0.17578,"16.0":0.02498,"16.1":0.05131,"16.2":0.02677,"16.3":0.0464,"16.4":0.01026,"16.5":0.01918,"16.6-16.7":0.20835,"17.0":0.01249,"17.1":0.02231,"17.2":0.01695,"17.3":0.02365,"17.4":0.04729,"17.5":0.10529,"17.6-17.7":0.3056,"18.0":0.08566,"18.1":0.28017,"18.2":0.12536,"18.3":2.62016,"18.4":0.03881},P:{"4":0.10905,"21":0.01091,"23":0.01091,"24":0.01091,"25":0.03272,"26":0.03272,"27":0.29444,_:"20 22 5.0-5.4 6.2-6.4 8.2 9.2 10.1 11.1-11.2 13.0 14.0 15.0 16.0 17.0 18.0 19.0","7.2-7.4":0.01091,"12.0":0.01091},I:{"0":0.55449,"3":0,"4":0,"2.1":0,"2.2":0,"2.3":0,"4.1":0,"4.2-4.3":0.00017,"4.4":0,"4.4.3-4.4.4":0.00061},K:{"0":0.31407,_:"10 11 12 11.1 11.5 12.1"},A:{"11":0.03308,_:"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.1208},Q:{"14.9":0.11274},O:{"0":0.75698},H:{"0":0},L:{"0":78.01505}};
|
||||
@@ -0,0 +1,26 @@
|
||||
import { AnyUpdater, Listener } from './types.cjs';
|
||||
export interface StoreOptions<TState, TUpdater extends AnyUpdater = (cb: TState) => TState> {
|
||||
/**
|
||||
* Replace the default update function with a custom one.
|
||||
*/
|
||||
updateFn?: (previous: TState) => (updater: TUpdater) => TState;
|
||||
/**
|
||||
* Called when a listener subscribes to the store.
|
||||
*
|
||||
* @return a function to unsubscribe the listener
|
||||
*/
|
||||
onSubscribe?: (listener: Listener<TState>, store: Store<TState, TUpdater>) => () => void;
|
||||
/**
|
||||
* Called after the state has been updated, used to derive other state.
|
||||
*/
|
||||
onUpdate?: () => void;
|
||||
}
|
||||
export declare class Store<TState, TUpdater extends AnyUpdater = (cb: TState) => TState> {
|
||||
listeners: Set<Listener<TState>>;
|
||||
state: TState;
|
||||
prevState: TState;
|
||||
options?: StoreOptions<TState, TUpdater>;
|
||||
constructor(initialState: TState, options?: StoreOptions<TState, TUpdater>);
|
||||
subscribe: (listener: Listener<TState>) => () => void;
|
||||
setState: (updater: TUpdater) => void;
|
||||
}
|
||||
@@ -0,0 +1,440 @@
|
||||
export type AnnotationEditorLayer = import("./annotation_editor_layer.js").AnnotationEditorLayer;
|
||||
export type AnnotationEditorParameters = {
|
||||
/**
|
||||
* - the global manager
|
||||
*/
|
||||
uiManager: AnnotationEditorUIManager;
|
||||
/**
|
||||
* - the layer containing this editor
|
||||
*/
|
||||
parent: AnnotationEditorLayer;
|
||||
/**
|
||||
* - editor id
|
||||
*/
|
||||
id: string;
|
||||
/**
|
||||
* - x-coordinate
|
||||
*/
|
||||
x: number;
|
||||
/**
|
||||
* - y-coordinate
|
||||
*/
|
||||
y: number;
|
||||
};
|
||||
/**
|
||||
* @typedef {Object} AnnotationEditorParameters
|
||||
* @property {AnnotationEditorUIManager} uiManager - the global manager
|
||||
* @property {AnnotationEditorLayer} parent - the layer containing this editor
|
||||
* @property {string} id - editor id
|
||||
* @property {number} x - x-coordinate
|
||||
* @property {number} y - y-coordinate
|
||||
*/
|
||||
/**
|
||||
* Base class for editors.
|
||||
*/
|
||||
export class AnnotationEditor {
|
||||
static _l10n: null;
|
||||
static _l10nResizer: null;
|
||||
static _borderLineWidth: number;
|
||||
static _colorManager: ColorManager;
|
||||
static _zIndex: number;
|
||||
static _telemetryTimeout: number;
|
||||
static get _resizerKeyboardManager(): any;
|
||||
static get _defaultLineColor(): any;
|
||||
static deleteAnnotationElement(editor: any): void;
|
||||
/**
|
||||
* Initialize the l10n stuff for this type of editor.
|
||||
* @param {Object} l10n
|
||||
*/
|
||||
static initialize(l10n: Object, _uiManager: any): void;
|
||||
/**
|
||||
* Update the default parameters for this type of editor.
|
||||
* @param {number} _type
|
||||
* @param {*} _value
|
||||
*/
|
||||
static updateDefaultParams(_type: number, _value: any): void;
|
||||
/**
|
||||
* Get the default properties to set in the UI for this type of editor.
|
||||
* @returns {Array}
|
||||
*/
|
||||
static get defaultPropertiesToUpdate(): any[];
|
||||
/**
|
||||
* Check if this kind of editor is able to handle the given mime type for
|
||||
* pasting.
|
||||
* @param {string} mime
|
||||
* @returns {boolean}
|
||||
*/
|
||||
static isHandlingMimeForPasting(mime: string): boolean;
|
||||
/**
|
||||
* Extract the data from the clipboard item and delegate the creation of the
|
||||
* editor to the parent.
|
||||
* @param {DataTransferItem} item
|
||||
* @param {AnnotationEditorLayer} parent
|
||||
*/
|
||||
static paste(item: DataTransferItem, parent: AnnotationEditorLayer): void;
|
||||
static "__#35@#rotatePoint"(x: any, y: any, angle: any): any[];
|
||||
/**
|
||||
* Deserialize the editor.
|
||||
* The result of the deserialization is a new editor.
|
||||
*
|
||||
* @param {Object} data
|
||||
* @param {AnnotationEditorLayer} parent
|
||||
* @param {AnnotationEditorUIManager} uiManager
|
||||
* @returns {Promise<AnnotationEditor | null>}
|
||||
*/
|
||||
static deserialize(data: Object, parent: AnnotationEditorLayer, uiManager: AnnotationEditorUIManager): Promise<AnnotationEditor | null>;
|
||||
static get MIN_SIZE(): number;
|
||||
static canCreateNewEmptyEditor(): boolean;
|
||||
/**
|
||||
* @param {AnnotationEditorParameters} parameters
|
||||
*/
|
||||
constructor(parameters: AnnotationEditorParameters);
|
||||
_editToolbar: null;
|
||||
_initialOptions: any;
|
||||
_initialData: null;
|
||||
_isVisible: boolean;
|
||||
_uiManager: null;
|
||||
_focusEventsAllowed: boolean;
|
||||
parent: import("./annotation_editor_layer.js").AnnotationEditorLayer;
|
||||
id: string;
|
||||
width: any;
|
||||
height: any;
|
||||
pageIndex: number;
|
||||
name: any;
|
||||
div: HTMLDivElement | null;
|
||||
annotationElementId: any;
|
||||
_willKeepAspectRatio: boolean;
|
||||
_structTreeParentId: any;
|
||||
rotation: number;
|
||||
pageRotation: number;
|
||||
pageDimensions: any[];
|
||||
pageTranslation: any[];
|
||||
x: number;
|
||||
y: number;
|
||||
isAttachedToDOM: boolean;
|
||||
deleted: boolean;
|
||||
get editorType(): any;
|
||||
/**
|
||||
* Get the properties to update in the UI for this editor.
|
||||
* @returns {Array}
|
||||
*/
|
||||
get propertiesToUpdate(): any[];
|
||||
set _isDraggable(value: boolean);
|
||||
get _isDraggable(): boolean;
|
||||
/**
|
||||
* @returns {boolean} true if the editor handles the Enter key itself.
|
||||
*/
|
||||
get isEnterHandled(): boolean;
|
||||
center(): void;
|
||||
/**
|
||||
* Add some commands into the CommandManager (undo/redo stuff).
|
||||
* @param {Object} params
|
||||
*/
|
||||
addCommands(params: Object): void;
|
||||
get currentLayer(): any;
|
||||
/**
|
||||
* This editor will be behind the others.
|
||||
*/
|
||||
setInBackground(): void;
|
||||
/**
|
||||
* This editor will be in the foreground.
|
||||
*/
|
||||
setInForeground(): void;
|
||||
setParent(parent: any): void;
|
||||
/**
|
||||
* onfocus callback.
|
||||
*/
|
||||
focusin(event: any): void;
|
||||
/**
|
||||
* onblur callback.
|
||||
* @param {FocusEvent} event
|
||||
*/
|
||||
focusout(event: FocusEvent): void;
|
||||
commitOrRemove(): void;
|
||||
/**
|
||||
* Commit the data contained in this editor.
|
||||
*/
|
||||
commit(): void;
|
||||
addToAnnotationStorage(): void;
|
||||
/**
|
||||
* Set the editor position within its parent.
|
||||
* @param {number} x
|
||||
* @param {number} y
|
||||
* @param {number} tx - x-translation in screen coordinates.
|
||||
* @param {number} ty - y-translation in screen coordinates.
|
||||
*/
|
||||
setAt(x: number, y: number, tx: number, ty: number): void;
|
||||
/**
|
||||
* Translate the editor position within its parent.
|
||||
* @param {number} x - x-translation in screen coordinates.
|
||||
* @param {number} y - y-translation in screen coordinates.
|
||||
*/
|
||||
translate(x: number, y: number): void;
|
||||
/**
|
||||
* Translate the editor position within its page and adjust the scroll
|
||||
* in order to have the editor in the view.
|
||||
* @param {number} x - x-translation in page coordinates.
|
||||
* @param {number} y - y-translation in page coordinates.
|
||||
*/
|
||||
translateInPage(x: number, y: number): void;
|
||||
drag(tx: any, ty: any): void;
|
||||
get _hasBeenMoved(): boolean;
|
||||
/**
|
||||
* Get the translation to take into account the editor border.
|
||||
* The CSS engine positions the element by taking the border into account so
|
||||
* we must apply the opposite translation to have the editor in the right
|
||||
* position.
|
||||
* @returns {Array<number>}
|
||||
*/
|
||||
getBaseTranslation(): Array<number>;
|
||||
/**
|
||||
* @returns {boolean} true if position must be fixed (i.e. make the x and y
|
||||
* living in the page).
|
||||
*/
|
||||
get _mustFixPosition(): boolean;
|
||||
/**
|
||||
* Fix the position of the editor in order to keep it inside its parent page.
|
||||
* @param {number} [rotation] - the rotation of the page.
|
||||
*/
|
||||
fixAndSetPosition(rotation?: number | undefined): void;
|
||||
/**
|
||||
* Convert a screen translation into a page one.
|
||||
* @param {number} x
|
||||
* @param {number} y
|
||||
*/
|
||||
screenToPageTranslation(x: number, y: number): any[];
|
||||
/**
|
||||
* Convert a page translation into a screen one.
|
||||
* @param {number} x
|
||||
* @param {number} y
|
||||
*/
|
||||
pageTranslationToScreen(x: number, y: number): any[];
|
||||
get parentScale(): any;
|
||||
get parentRotation(): number;
|
||||
get parentDimensions(): number[];
|
||||
/**
|
||||
* Set the dimensions of this editor.
|
||||
* @param {number} width
|
||||
* @param {number} height
|
||||
*/
|
||||
setDims(width: number, height: number): void;
|
||||
fixDims(): void;
|
||||
/**
|
||||
* Get the translation used to position this editor when it's created.
|
||||
* @returns {Array<number>}
|
||||
*/
|
||||
getInitialTranslation(): Array<number>;
|
||||
/**
|
||||
* Called when the alt text dialog is closed.
|
||||
*/
|
||||
altTextFinish(): void;
|
||||
/**
|
||||
* Add a toolbar for this editor.
|
||||
* @returns {Promise<EditorToolbar|null>}
|
||||
*/
|
||||
addEditToolbar(): Promise<EditorToolbar | null>;
|
||||
removeEditToolbar(): void;
|
||||
addContainer(container: any): void;
|
||||
getClientDimensions(): DOMRect;
|
||||
addAltTextButton(): Promise<void>;
|
||||
/**
|
||||
* Set the alt text data.
|
||||
*/
|
||||
set altTextData(data: any);
|
||||
get altTextData(): any;
|
||||
get guessedAltText(): any;
|
||||
setGuessedAltText(text: any): Promise<void>;
|
||||
serializeAltText(isForCopying: any): any;
|
||||
hasAltText(): boolean;
|
||||
hasAltTextData(): any;
|
||||
/**
|
||||
* Render this editor in a div.
|
||||
* @returns {HTMLDivElement | null}
|
||||
*/
|
||||
render(): HTMLDivElement | null;
|
||||
/**
|
||||
* Onpointerdown callback.
|
||||
* @param {PointerEvent} event
|
||||
*/
|
||||
pointerdown(event: PointerEvent): void;
|
||||
get isSelected(): any;
|
||||
moveInDOM(): void;
|
||||
_setParentAndPosition(parent: any, x: any, y: any): void;
|
||||
/**
|
||||
* Convert the current rect into a page one.
|
||||
* @param {number} tx - x-translation in screen coordinates.
|
||||
* @param {number} ty - y-translation in screen coordinates.
|
||||
* @param {number} [rotation] - the rotation of the page.
|
||||
*/
|
||||
getRect(tx: number, ty: number, rotation?: number | undefined): any[];
|
||||
getRectInCurrentCoords(rect: any, pageHeight: any): any[];
|
||||
/**
|
||||
* Executed once this editor has been rendered.
|
||||
*/
|
||||
onceAdded(): void;
|
||||
/**
|
||||
* Check if the editor contains something.
|
||||
* @returns {boolean}
|
||||
*/
|
||||
isEmpty(): boolean;
|
||||
/**
|
||||
* Enable edit mode.
|
||||
*/
|
||||
enableEditMode(): void;
|
||||
/**
|
||||
* Disable edit mode.
|
||||
*/
|
||||
disableEditMode(): void;
|
||||
/**
|
||||
* Check if the editor is edited.
|
||||
* @returns {boolean}
|
||||
*/
|
||||
isInEditMode(): boolean;
|
||||
/**
|
||||
* If it returns true, then this editor handles the keyboard
|
||||
* events itself.
|
||||
* @returns {boolean}
|
||||
*/
|
||||
shouldGetKeyboardEvents(): boolean;
|
||||
/**
|
||||
* Check if this editor needs to be rebuilt or not.
|
||||
* @returns {boolean}
|
||||
*/
|
||||
needsToBeRebuilt(): boolean;
|
||||
/**
|
||||
* Rebuild the editor in case it has been removed on undo.
|
||||
*
|
||||
* To implement in subclasses.
|
||||
*/
|
||||
rebuild(): void;
|
||||
/**
|
||||
* Rotate the editor.
|
||||
* @param {number} angle
|
||||
*/
|
||||
rotate(_angle: any): void;
|
||||
/**
|
||||
* Serialize the editor when it has been deleted.
|
||||
* @returns {Object}
|
||||
*/
|
||||
serializeDeleted(): Object;
|
||||
/**
|
||||
* Serialize the editor.
|
||||
* The result of the serialization will be used to construct a
|
||||
* new annotation to add to the pdf document.
|
||||
*
|
||||
* To implement in subclasses.
|
||||
* @param {boolean} [isForCopying]
|
||||
* @param {Object | null} [context]
|
||||
* @returns {Object | null}
|
||||
*/
|
||||
serialize(isForCopying?: boolean | undefined, context?: Object | null | undefined): Object | null;
|
||||
/**
|
||||
* Check if an existing annotation associated with this editor has been
|
||||
* modified.
|
||||
* @returns {boolean}
|
||||
*/
|
||||
get hasBeenModified(): boolean;
|
||||
/**
|
||||
* Remove this editor.
|
||||
* It's used on ctrl+backspace action.
|
||||
*/
|
||||
remove(): void;
|
||||
/**
|
||||
* @returns {boolean} true if this editor can be resized.
|
||||
*/
|
||||
get isResizable(): boolean;
|
||||
/**
|
||||
* Add the resizers to this editor.
|
||||
*/
|
||||
makeResizable(): void;
|
||||
get toolbarPosition(): null;
|
||||
/**
|
||||
* onkeydown callback.
|
||||
* @param {KeyboardEvent} event
|
||||
*/
|
||||
keydown(event: KeyboardEvent): void;
|
||||
_resizeWithKeyboard(x: any, y: any): void;
|
||||
_stopResizingWithKeyboard(): void;
|
||||
/**
|
||||
* Select this editor.
|
||||
*/
|
||||
select(): void;
|
||||
/**
|
||||
* Unselect this editor.
|
||||
*/
|
||||
unselect(): void;
|
||||
/**
|
||||
* Update some parameters which have been changed through the UI.
|
||||
* @param {number} type
|
||||
* @param {*} value
|
||||
*/
|
||||
updateParams(type: number, value: any): void;
|
||||
/**
|
||||
* When the user disables the editing mode some editors can change some of
|
||||
* their properties.
|
||||
*/
|
||||
disableEditing(): void;
|
||||
/**
|
||||
* When the user enables the editing mode some editors can change some of
|
||||
* their properties.
|
||||
*/
|
||||
enableEditing(): void;
|
||||
/**
|
||||
* The editor is about to be edited.
|
||||
*/
|
||||
enterInEditMode(): void;
|
||||
/**
|
||||
* @returns {HTMLElement | null} the element requiring an alt text.
|
||||
*/
|
||||
getImageForAltText(): HTMLElement | null;
|
||||
/**
|
||||
* Get the div which really contains the displayed content.
|
||||
* @returns {HTMLDivElement | undefined}
|
||||
*/
|
||||
get contentDiv(): HTMLDivElement | undefined;
|
||||
/**
|
||||
* When set to true, it means that this editor is currently edited.
|
||||
* @param {boolean} value
|
||||
*/
|
||||
set isEditing(value: boolean);
|
||||
/**
|
||||
* If true then the editor is currently edited.
|
||||
* @type {boolean}
|
||||
*/
|
||||
get isEditing(): boolean;
|
||||
/**
|
||||
* Set the aspect ratio to use when resizing.
|
||||
* @param {number} width
|
||||
* @param {number} height
|
||||
*/
|
||||
setAspectRatio(width: number, height: number): void;
|
||||
/**
|
||||
* Get the data to report to the telemetry when the editor is added.
|
||||
* @returns {Object}
|
||||
*/
|
||||
get telemetryInitialData(): Object;
|
||||
/**
|
||||
* The telemetry data to use when saving/printing.
|
||||
* @returns {Object|null}
|
||||
*/
|
||||
get telemetryFinalData(): Object | null;
|
||||
_reportTelemetry(data: any, mustWait?: boolean): void;
|
||||
/**
|
||||
* Show or hide this editor.
|
||||
* @param {boolean|undefined} visible
|
||||
*/
|
||||
show(visible?: boolean | undefined): void;
|
||||
enable(): void;
|
||||
disable(): void;
|
||||
/**
|
||||
* Render an annotation in the annotation layer.
|
||||
* @param {Object} annotation
|
||||
* @returns {HTMLElement|null}
|
||||
*/
|
||||
renderAnnotationElement(annotation: Object): HTMLElement | null;
|
||||
resetAnnotationElement(annotation: any): void;
|
||||
#private;
|
||||
}
|
||||
import { AnnotationEditorUIManager } from "./tools.js";
|
||||
import { EditorToolbar } from "./toolbar.js";
|
||||
import { ColorManager } from "./tools.js";
|
||||
@@ -0,0 +1,350 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = _decorate;
|
||||
var _toArray = require("toArray");
|
||||
var _toPropertyKey = require("toPropertyKey");
|
||||
function _decorate(decorators, factory, superClass, mixins) {
|
||||
var api = _getDecoratorsApi();
|
||||
if (mixins) {
|
||||
for (var i = 0; i < mixins.length; i++) {
|
||||
api = mixins[i](api);
|
||||
}
|
||||
}
|
||||
var r = factory(function initialize(O) {
|
||||
api.initializeInstanceElements(O, decorated.elements);
|
||||
}, superClass);
|
||||
var decorated = api.decorateClass(_coalesceClassElements(r.d.map(_createElementDescriptor)), decorators);
|
||||
api.initializeClassElements(r.F, decorated.elements);
|
||||
return api.runClassFinishers(r.F, decorated.finishers);
|
||||
}
|
||||
function _getDecoratorsApi() {
|
||||
_getDecoratorsApi = function () {
|
||||
return api;
|
||||
};
|
||||
var api = {
|
||||
elementsDefinitionOrder: [["method"], ["field"]],
|
||||
initializeInstanceElements: function (O, elements) {
|
||||
["method", "field"].forEach(function (kind) {
|
||||
elements.forEach(function (element) {
|
||||
if (element.kind === kind && element.placement === "own") {
|
||||
this.defineClassElement(O, element);
|
||||
}
|
||||
}, this);
|
||||
}, this);
|
||||
},
|
||||
initializeClassElements: function (F, elements) {
|
||||
var proto = F.prototype;
|
||||
["method", "field"].forEach(function (kind) {
|
||||
elements.forEach(function (element) {
|
||||
var placement = element.placement;
|
||||
if (element.kind === kind && (placement === "static" || placement === "prototype")) {
|
||||
var receiver = placement === "static" ? F : proto;
|
||||
this.defineClassElement(receiver, element);
|
||||
}
|
||||
}, this);
|
||||
}, this);
|
||||
},
|
||||
defineClassElement: function (receiver, element) {
|
||||
var descriptor = element.descriptor;
|
||||
if (element.kind === "field") {
|
||||
var initializer = element.initializer;
|
||||
descriptor = {
|
||||
enumerable: descriptor.enumerable,
|
||||
writable: descriptor.writable,
|
||||
configurable: descriptor.configurable,
|
||||
value: initializer === void 0 ? void 0 : initializer.call(receiver)
|
||||
};
|
||||
}
|
||||
Object.defineProperty(receiver, element.key, descriptor);
|
||||
},
|
||||
decorateClass: function (elements, decorators) {
|
||||
var newElements = [];
|
||||
var finishers = [];
|
||||
var placements = {
|
||||
static: [],
|
||||
prototype: [],
|
||||
own: []
|
||||
};
|
||||
elements.forEach(function (element) {
|
||||
this.addElementPlacement(element, placements);
|
||||
}, this);
|
||||
elements.forEach(function (element) {
|
||||
if (!_hasDecorators(element)) return newElements.push(element);
|
||||
var elementFinishersExtras = this.decorateElement(element, placements);
|
||||
newElements.push(elementFinishersExtras.element);
|
||||
newElements.push.apply(newElements, elementFinishersExtras.extras);
|
||||
finishers.push.apply(finishers, elementFinishersExtras.finishers);
|
||||
}, this);
|
||||
if (!decorators) {
|
||||
return {
|
||||
elements: newElements,
|
||||
finishers: finishers
|
||||
};
|
||||
}
|
||||
var result = this.decorateConstructor(newElements, decorators);
|
||||
finishers.push.apply(finishers, result.finishers);
|
||||
result.finishers = finishers;
|
||||
return result;
|
||||
},
|
||||
addElementPlacement: function (element, placements, silent) {
|
||||
var keys = placements[element.placement];
|
||||
if (!silent && keys.indexOf(element.key) !== -1) {
|
||||
throw new TypeError("Duplicated element (" + element.key + ")");
|
||||
}
|
||||
keys.push(element.key);
|
||||
},
|
||||
decorateElement: function (element, placements) {
|
||||
var extras = [];
|
||||
var finishers = [];
|
||||
for (var decorators = element.decorators, i = decorators.length - 1; i >= 0; i--) {
|
||||
var keys = placements[element.placement];
|
||||
keys.splice(keys.indexOf(element.key), 1);
|
||||
var elementObject = this.fromElementDescriptor(element);
|
||||
var elementFinisherExtras = this.toElementFinisherExtras((0, decorators[i])(elementObject) || elementObject);
|
||||
element = elementFinisherExtras.element;
|
||||
this.addElementPlacement(element, placements);
|
||||
if (elementFinisherExtras.finisher) {
|
||||
finishers.push(elementFinisherExtras.finisher);
|
||||
}
|
||||
var newExtras = elementFinisherExtras.extras;
|
||||
if (newExtras) {
|
||||
for (var j = 0; j < newExtras.length; j++) {
|
||||
this.addElementPlacement(newExtras[j], placements);
|
||||
}
|
||||
extras.push.apply(extras, newExtras);
|
||||
}
|
||||
}
|
||||
return {
|
||||
element: element,
|
||||
finishers: finishers,
|
||||
extras: extras
|
||||
};
|
||||
},
|
||||
decorateConstructor: function (elements, decorators) {
|
||||
var finishers = [];
|
||||
for (var i = decorators.length - 1; i >= 0; i--) {
|
||||
var obj = this.fromClassDescriptor(elements);
|
||||
var elementsAndFinisher = this.toClassDescriptor((0, decorators[i])(obj) || obj);
|
||||
if (elementsAndFinisher.finisher !== undefined) {
|
||||
finishers.push(elementsAndFinisher.finisher);
|
||||
}
|
||||
if (elementsAndFinisher.elements !== undefined) {
|
||||
elements = elementsAndFinisher.elements;
|
||||
for (var j = 0; j < elements.length - 1; j++) {
|
||||
for (var k = j + 1; k < elements.length; k++) {
|
||||
if (elements[j].key === elements[k].key && elements[j].placement === elements[k].placement) {
|
||||
throw new TypeError("Duplicated element (" + elements[j].key + ")");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return {
|
||||
elements: elements,
|
||||
finishers: finishers
|
||||
};
|
||||
},
|
||||
fromElementDescriptor: function (element) {
|
||||
var obj = {
|
||||
kind: element.kind,
|
||||
key: element.key,
|
||||
placement: element.placement,
|
||||
descriptor: element.descriptor
|
||||
};
|
||||
var desc = {
|
||||
value: "Descriptor",
|
||||
configurable: true
|
||||
};
|
||||
Object.defineProperty(obj, Symbol.toStringTag, desc);
|
||||
if (element.kind === "field") obj.initializer = element.initializer;
|
||||
return obj;
|
||||
},
|
||||
toElementDescriptors: function (elementObjects) {
|
||||
if (elementObjects === undefined) return;
|
||||
return _toArray(elementObjects).map(function (elementObject) {
|
||||
var element = this.toElementDescriptor(elementObject);
|
||||
this.disallowProperty(elementObject, "finisher", "An element descriptor");
|
||||
this.disallowProperty(elementObject, "extras", "An element descriptor");
|
||||
return element;
|
||||
}, this);
|
||||
},
|
||||
toElementDescriptor: function (elementObject) {
|
||||
var kind = String(elementObject.kind);
|
||||
if (kind !== "method" && kind !== "field") {
|
||||
throw new TypeError('An element descriptor\'s .kind property must be either "method" or' + ' "field", but a decorator created an element descriptor with' + ' .kind "' + kind + '"');
|
||||
}
|
||||
var key = _toPropertyKey(elementObject.key);
|
||||
var placement = String(elementObject.placement);
|
||||
if (placement !== "static" && placement !== "prototype" && placement !== "own") {
|
||||
throw new TypeError('An element descriptor\'s .placement property must be one of "static",' + ' "prototype" or "own", but a decorator created an element descriptor' + ' with .placement "' + placement + '"');
|
||||
}
|
||||
var descriptor = elementObject.descriptor;
|
||||
this.disallowProperty(elementObject, "elements", "An element descriptor");
|
||||
var element = {
|
||||
kind: kind,
|
||||
key: key,
|
||||
placement: placement,
|
||||
descriptor: Object.assign({}, descriptor)
|
||||
};
|
||||
if (kind !== "field") {
|
||||
this.disallowProperty(elementObject, "initializer", "A method descriptor");
|
||||
} else {
|
||||
this.disallowProperty(descriptor, "get", "The property descriptor of a field descriptor");
|
||||
this.disallowProperty(descriptor, "set", "The property descriptor of a field descriptor");
|
||||
this.disallowProperty(descriptor, "value", "The property descriptor of a field descriptor");
|
||||
element.initializer = elementObject.initializer;
|
||||
}
|
||||
return element;
|
||||
},
|
||||
toElementFinisherExtras: function (elementObject) {
|
||||
var element = this.toElementDescriptor(elementObject);
|
||||
var finisher = _optionalCallableProperty(elementObject, "finisher");
|
||||
var extras = this.toElementDescriptors(elementObject.extras);
|
||||
return {
|
||||
element: element,
|
||||
finisher: finisher,
|
||||
extras: extras
|
||||
};
|
||||
},
|
||||
fromClassDescriptor: function (elements) {
|
||||
var obj = {
|
||||
kind: "class",
|
||||
elements: elements.map(this.fromElementDescriptor, this)
|
||||
};
|
||||
var desc = {
|
||||
value: "Descriptor",
|
||||
configurable: true
|
||||
};
|
||||
Object.defineProperty(obj, Symbol.toStringTag, desc);
|
||||
return obj;
|
||||
},
|
||||
toClassDescriptor: function (obj) {
|
||||
var kind = String(obj.kind);
|
||||
if (kind !== "class") {
|
||||
throw new TypeError('A class descriptor\'s .kind property must be "class", but a decorator' + ' created a class descriptor with .kind "' + kind + '"');
|
||||
}
|
||||
this.disallowProperty(obj, "key", "A class descriptor");
|
||||
this.disallowProperty(obj, "placement", "A class descriptor");
|
||||
this.disallowProperty(obj, "descriptor", "A class descriptor");
|
||||
this.disallowProperty(obj, "initializer", "A class descriptor");
|
||||
this.disallowProperty(obj, "extras", "A class descriptor");
|
||||
var finisher = _optionalCallableProperty(obj, "finisher");
|
||||
var elements = this.toElementDescriptors(obj.elements);
|
||||
return {
|
||||
elements: elements,
|
||||
finisher: finisher
|
||||
};
|
||||
},
|
||||
runClassFinishers: function (constructor, finishers) {
|
||||
for (var i = 0; i < finishers.length; i++) {
|
||||
var newConstructor = (0, finishers[i])(constructor);
|
||||
if (newConstructor !== undefined) {
|
||||
if (typeof newConstructor !== "function") {
|
||||
throw new TypeError("Finishers must return a constructor.");
|
||||
}
|
||||
constructor = newConstructor;
|
||||
}
|
||||
}
|
||||
return constructor;
|
||||
},
|
||||
disallowProperty: function (obj, name, objectType) {
|
||||
if (obj[name] !== undefined) {
|
||||
throw new TypeError(objectType + " can't have a ." + name + " property.");
|
||||
}
|
||||
}
|
||||
};
|
||||
return api;
|
||||
}
|
||||
function _createElementDescriptor(def) {
|
||||
var key = _toPropertyKey(def.key);
|
||||
var descriptor;
|
||||
if (def.kind === "method") {
|
||||
descriptor = {
|
||||
value: def.value,
|
||||
writable: true,
|
||||
configurable: true,
|
||||
enumerable: false
|
||||
};
|
||||
} else if (def.kind === "get") {
|
||||
descriptor = {
|
||||
get: def.value,
|
||||
configurable: true,
|
||||
enumerable: false
|
||||
};
|
||||
} else if (def.kind === "set") {
|
||||
descriptor = {
|
||||
set: def.value,
|
||||
configurable: true,
|
||||
enumerable: false
|
||||
};
|
||||
} else if (def.kind === "field") {
|
||||
descriptor = {
|
||||
configurable: true,
|
||||
writable: true,
|
||||
enumerable: true
|
||||
};
|
||||
}
|
||||
var element = {
|
||||
kind: def.kind === "field" ? "field" : "method",
|
||||
key: key,
|
||||
placement: def.static ? "static" : def.kind === "field" ? "own" : "prototype",
|
||||
descriptor: descriptor
|
||||
};
|
||||
if (def.decorators) element.decorators = def.decorators;
|
||||
if (def.kind === "field") element.initializer = def.value;
|
||||
return element;
|
||||
}
|
||||
function _coalesceGetterSetter(element, other) {
|
||||
if (element.descriptor.get !== undefined) {
|
||||
other.descriptor.get = element.descriptor.get;
|
||||
} else {
|
||||
other.descriptor.set = element.descriptor.set;
|
||||
}
|
||||
}
|
||||
function _coalesceClassElements(elements) {
|
||||
var newElements = [];
|
||||
var isSameElement = function (other) {
|
||||
return other.kind === "method" && other.key === element.key && other.placement === element.placement;
|
||||
};
|
||||
for (var i = 0; i < elements.length; i++) {
|
||||
var element = elements[i];
|
||||
var other;
|
||||
if (element.kind === "method" && (other = newElements.find(isSameElement))) {
|
||||
if (_isDataDescriptor(element.descriptor) || _isDataDescriptor(other.descriptor)) {
|
||||
if (_hasDecorators(element) || _hasDecorators(other)) {
|
||||
throw new ReferenceError("Duplicated methods (" + element.key + ") can't be decorated.");
|
||||
}
|
||||
other.descriptor = element.descriptor;
|
||||
} else {
|
||||
if (_hasDecorators(element)) {
|
||||
if (_hasDecorators(other)) {
|
||||
throw new ReferenceError("Decorators can't be placed on different accessors with for " + "the same property (" + element.key + ").");
|
||||
}
|
||||
other.decorators = element.decorators;
|
||||
}
|
||||
_coalesceGetterSetter(element, other);
|
||||
}
|
||||
} else {
|
||||
newElements.push(element);
|
||||
}
|
||||
}
|
||||
return newElements;
|
||||
}
|
||||
function _hasDecorators(element) {
|
||||
return element.decorators && element.decorators.length;
|
||||
}
|
||||
function _isDataDescriptor(desc) {
|
||||
return desc !== undefined && !(desc.value === undefined && desc.writable === undefined);
|
||||
}
|
||||
function _optionalCallableProperty(obj, name) {
|
||||
var value = obj[name];
|
||||
if (value !== undefined && typeof value !== "function") {
|
||||
throw new TypeError("Expected '" + name + "' to be a function");
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
//# sourceMappingURL=decorate.js.map
|
||||
@@ -0,0 +1 @@
|
||||
module.exports={A:{A:{"1":"B","4":"K D E F A mC"},B:{"1":"C L M G N","129":"0 9 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":"1 2 3 4 5 6 7 8 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","4":"nC LC J PB qC rC","129":"0 9 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:{"1":"iB jB kB lB mB nB oB pB qB rB","4":"J PB K","129":"0 1 2 3 4 5 6 7 8 9 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 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:{"4":"J PB sC SC","129":"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"},F:{"1":"C VB WB XB YB ZB aB bB cB dB eB FC kC 8C GC","4":"F B 4C 5C 6C 7C","129":"0 1 2 3 4 5 6 7 8 G N O P QB RB SB TB UB 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:{"4":"SC 9C lC","129":"E AD BD CD DD ED FD GD HD ID JD KD LD MD ND OD PD QD RD SD UC VC HC TD IC WC XC YC ZC aC UD JC bC cC dC eC fC VD KC gC hC iC jC"},H:{"4":"WD"},I:{"4":"XD YD ZD","129":"LC J I aD lC bD cD"},J:{"129":"D A"},K:{"1":"C FC kC GC","4":"A B","129":"H"},L:{"129":"I"},M:{"129":"EC"},N:{"1":"B","4":"A"},O:{"129":"HC"},P:{"129":"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:{"129":"oD"},R:{"129":"pD"},S:{"1":"qD","129":"rD"}},B:1,C:"dataset & data-* attributes",D:true};
|
||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1,657 @@
|
||||
# node-canvas
|
||||
|
||||

|
||||
[](http://badge.fury.io/js/canvas)
|
||||
|
||||
node-canvas is a [Cairo](http://cairographics.org/)-backed Canvas implementation for [Node.js](http://nodejs.org).
|
||||
|
||||
## Installation
|
||||
|
||||
```bash
|
||||
$ npm install canvas
|
||||
```
|
||||
|
||||
By default, pre-built binaries will be downloaded if you're on one of the following platforms:
|
||||
- macOS x86/64
|
||||
- macOS aarch64 (aka Apple silicon)
|
||||
- Linux x86/64 (glibc only)
|
||||
- Windows x86/64
|
||||
|
||||
If you want to build from source, use `npm install --build-from-source` and see the **Compiling** section below.
|
||||
|
||||
The minimum version of Node.js required is **18.12.0**.
|
||||
|
||||
### Compiling
|
||||
|
||||
If you don't have a supported OS or processor architecture, or you use `--build-from-source`, the module will be compiled on your system. This requires several dependencies, including Cairo and Pango.
|
||||
|
||||
For detailed installation information, see the [wiki](https://github.com/Automattic/node-canvas/wiki/_pages). One-line installation instructions for common OSes are below. Note that libgif/giflib, librsvg and libjpeg are optional and only required if you need GIF, SVG and JPEG support, respectively. Cairo v1.10.0 or later is required.
|
||||
|
||||
OS | Command
|
||||
----- | -----
|
||||
macOS | Using [Homebrew](https://brew.sh/):<br/>`brew install pkg-config cairo pango libpng jpeg giflib librsvg pixman python-setuptools`
|
||||
Ubuntu | `sudo apt-get install build-essential libcairo2-dev libpango1.0-dev libjpeg-dev libgif-dev librsvg2-dev`
|
||||
Fedora | `sudo yum install gcc-c++ cairo-devel pango-devel libjpeg-turbo-devel giflib-devel`
|
||||
Solaris | `pkgin install cairo pango pkg-config xproto renderproto kbproto xextproto`
|
||||
OpenBSD | `doas pkg_add cairo pango png jpeg giflib`
|
||||
Windows | See the [wiki](https://github.com/Automattic/node-canvas/wiki/Installation:-Windows)
|
||||
Others | See the [wiki](https://github.com/Automattic/node-canvas/wiki)
|
||||
|
||||
**Mac OS X v10.11+:** If you have recently updated to Mac OS X v10.11+ and are experiencing trouble when compiling, run the following command: `xcode-select --install`. Read more about the problem [on Stack Overflow](http://stackoverflow.com/a/32929012/148072).
|
||||
If you have xcode 10.0 or higher installed, in order to build from source you need NPM 6.4.1 or higher.
|
||||
|
||||
## Quick Example
|
||||
|
||||
```javascript
|
||||
const { createCanvas, loadImage } = require('canvas')
|
||||
const canvas = createCanvas(200, 200)
|
||||
const ctx = canvas.getContext('2d')
|
||||
|
||||
// Write "Awesome!"
|
||||
ctx.font = '30px Impact'
|
||||
ctx.rotate(0.1)
|
||||
ctx.fillText('Awesome!', 50, 100)
|
||||
|
||||
// Draw line under text
|
||||
var text = ctx.measureText('Awesome!')
|
||||
ctx.strokeStyle = 'rgba(0,0,0,0.5)'
|
||||
ctx.beginPath()
|
||||
ctx.lineTo(50, 102)
|
||||
ctx.lineTo(50 + text.width, 102)
|
||||
ctx.stroke()
|
||||
|
||||
// Draw cat with lime helmet
|
||||
loadImage('examples/images/lime-cat.jpg').then((image) => {
|
||||
ctx.drawImage(image, 50, 0, 70, 70)
|
||||
|
||||
console.log('<img src="' + canvas.toDataURL() + '" />')
|
||||
})
|
||||
```
|
||||
|
||||
## Upgrading from 1.x to 2.x
|
||||
|
||||
See the [changelog](https://github.com/Automattic/node-canvas/blob/master/CHANGELOG.md) for a guide to upgrading from 1.x to 2.x.
|
||||
|
||||
For version 1.x documentation, see [the v1.x branch](https://github.com/Automattic/node-canvas/tree/v1.x).
|
||||
|
||||
## Documentation
|
||||
|
||||
This project is an implementation of the Web Canvas API and implements that API as closely as possible. For API documentation, please visit [Mozilla Web Canvas API](https://developer.mozilla.org/en-US/docs/Web/API/Canvas_API). (See [Compatibility Status](https://github.com/Automattic/node-canvas/wiki/Compatibility-Status) for the current API compliance.) All utility methods and non-standard APIs are documented below.
|
||||
|
||||
### Utility methods
|
||||
|
||||
* [createCanvas()](#createcanvas)
|
||||
* [createImageData()](#createimagedata)
|
||||
* [loadImage()](#loadimage)
|
||||
* [registerFont()](#registerfont)
|
||||
* [deregisterAllFonts()](#deregisterAllFonts)
|
||||
|
||||
|
||||
### Non-standard APIs
|
||||
|
||||
* [Image#src](#imagesrc)
|
||||
* [Image#dataMode](#imagedatamode)
|
||||
* [Canvas#toBuffer()](#canvastobuffer)
|
||||
* [Canvas#createPNGStream()](#canvascreatepngstream)
|
||||
* [Canvas#createJPEGStream()](#canvascreatejpegstream)
|
||||
* [Canvas#createPDFStream()](#canvascreatepdfstream)
|
||||
* [Canvas#toDataURL()](#canvastodataurl)
|
||||
* [CanvasRenderingContext2D#patternQuality](#canvasrenderingcontext2dpatternquality)
|
||||
* [CanvasRenderingContext2D#quality](#canvasrenderingcontext2dquality)
|
||||
* [CanvasRenderingContext2D#textDrawingMode](#canvasrenderingcontext2dtextdrawingmode)
|
||||
* [CanvasRenderingContext2D#globalCompositeOperation = 'saturate'](#canvasrenderingcontext2dglobalcompositeoperation--saturate)
|
||||
* [CanvasRenderingContext2D#antialias](#canvasrenderingcontext2dantialias)
|
||||
|
||||
### createCanvas()
|
||||
|
||||
> ```ts
|
||||
> createCanvas(width: number, height: number, type?: 'PDF'|'SVG') => Canvas
|
||||
> ```
|
||||
|
||||
Creates a Canvas instance. This method works in both Node.js and Web browsers, where there is no Canvas constructor. (See `browser.js` for the implementation that runs in browsers.)
|
||||
|
||||
```js
|
||||
const { createCanvas } = require('canvas')
|
||||
const mycanvas = createCanvas(200, 200)
|
||||
const myPDFcanvas = createCanvas(600, 800, 'pdf') // see "PDF Support" section
|
||||
```
|
||||
|
||||
### createImageData()
|
||||
|
||||
> ```ts
|
||||
> createImageData(width: number, height: number) => ImageData
|
||||
> createImageData(data: Uint8ClampedArray, width: number, height?: number) => ImageData
|
||||
> // for alternative pixel formats:
|
||||
> createImageData(data: Uint16Array, width: number, height?: number) => ImageData
|
||||
> ```
|
||||
|
||||
Creates an ImageData instance. This method works in both Node.js and Web browsers.
|
||||
|
||||
```js
|
||||
const { createImageData } = require('canvas')
|
||||
const width = 20, height = 20
|
||||
const arraySize = width * height * 4
|
||||
const mydata = createImageData(new Uint8ClampedArray(arraySize), width)
|
||||
```
|
||||
|
||||
### loadImage()
|
||||
|
||||
> ```ts
|
||||
> loadImage() => Promise<Image>
|
||||
> ```
|
||||
|
||||
Convenience method for loading images. This method works in both Node.js and Web browsers.
|
||||
|
||||
```js
|
||||
const { loadImage } = require('canvas')
|
||||
const myimg = loadImage('http://server.com/image.png')
|
||||
|
||||
myimg.then(() => {
|
||||
// do something with image
|
||||
}).catch(err => {
|
||||
console.log('oh no!', err)
|
||||
})
|
||||
|
||||
// or with async/await:
|
||||
const myimg = await loadImage('http://server.com/image.png')
|
||||
// do something with image
|
||||
```
|
||||
|
||||
### registerFont()
|
||||
|
||||
> ```ts
|
||||
> registerFont(path: string, { family: string, weight?: string, style?: string }) => void
|
||||
> ```
|
||||
|
||||
To use a font file that is not installed as a system font, use `registerFont()` to register the font with Canvas.
|
||||
|
||||
```js
|
||||
const { registerFont, createCanvas } = require('canvas')
|
||||
registerFont('comicsans.ttf', { family: 'Comic Sans' })
|
||||
|
||||
const canvas = createCanvas(500, 500)
|
||||
const ctx = canvas.getContext('2d')
|
||||
|
||||
ctx.font = '12px "Comic Sans"'
|
||||
ctx.fillText('Everyone hates this font :(', 250, 10)
|
||||
```
|
||||
|
||||
The second argument is an object with properties that resemble the CSS properties that are specified in `@font-face` rules. You must specify at least `family`. `weight`, and `style` are optional and default to `'normal'`.
|
||||
|
||||
### deregisterAllFonts()
|
||||
|
||||
> ```ts
|
||||
> deregisterAllFonts() => void
|
||||
> ```
|
||||
|
||||
Use `deregisterAllFonts` to unregister all fonts that have been previously registered. This method is useful when you want to remove all registered fonts, such as when using the canvas in tests
|
||||
|
||||
```ts
|
||||
const { registerFont, createCanvas, deregisterAllFonts } = require('canvas')
|
||||
|
||||
describe('text rendering', () => {
|
||||
afterEach(() => {
|
||||
deregisterAllFonts();
|
||||
})
|
||||
it('should render text with Comic Sans', () => {
|
||||
registerFont('comicsans.ttf', { family: 'Comic Sans' })
|
||||
|
||||
const canvas = createCanvas(500, 500)
|
||||
const ctx = canvas.getContext('2d')
|
||||
|
||||
ctx.font = '12px "Comic Sans"'
|
||||
ctx.fillText('Everyone loves this font :)', 250, 10)
|
||||
|
||||
// assertScreenshot()
|
||||
})
|
||||
})
|
||||
```
|
||||
|
||||
### Image#src
|
||||
|
||||
> ```ts
|
||||
> img.src: string|Buffer
|
||||
> ```
|
||||
|
||||
As in browsers, `img.src` can be set to a `data:` URI or a remote URL. In addition, node-canvas allows setting `src` to a local file path or `Buffer` instance.
|
||||
|
||||
```javascript
|
||||
const { Image } = require('canvas')
|
||||
|
||||
// From a buffer:
|
||||
fs.readFile('images/squid.png', (err, squid) => {
|
||||
if (err) throw err
|
||||
const img = new Image()
|
||||
img.onload = () => ctx.drawImage(img, 0, 0)
|
||||
img.onerror = err => { throw err }
|
||||
img.src = squid
|
||||
})
|
||||
|
||||
// From a local file path:
|
||||
const img = new Image()
|
||||
img.onload = () => ctx.drawImage(img, 0, 0)
|
||||
img.onerror = err => { throw err }
|
||||
img.src = 'images/squid.png'
|
||||
|
||||
// From a remote URL:
|
||||
img.src = 'http://picsum.photos/200/300'
|
||||
// ... as above
|
||||
|
||||
// From a `data:` URI:
|
||||
img.src = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg=='
|
||||
// ... as above
|
||||
```
|
||||
|
||||
*Note: In some cases, `img.src=` is currently synchronous. However, you should always use `img.onload` and `img.onerror`, as we intend to make `img.src=` always asynchronous as it is in browsers. See https://github.com/Automattic/node-canvas/issues/1007.*
|
||||
|
||||
### Image#dataMode
|
||||
|
||||
> ```ts
|
||||
> img.dataMode: number
|
||||
> ```
|
||||
|
||||
Applies to JPEG images drawn to PDF canvases only.
|
||||
|
||||
Setting `img.dataMode = Image.MODE_MIME` or `Image.MODE_MIME|Image.MODE_IMAGE` enables MIME data tracking of images. When MIME data is tracked, PDF canvases can embed JPEGs directly into the output, rather than re-encoding into PNG. This can drastically reduce filesize and speed up rendering.
|
||||
|
||||
```javascript
|
||||
const { Image, createCanvas } = require('canvas')
|
||||
const canvas = createCanvas(w, h, 'pdf')
|
||||
const img = new Image()
|
||||
img.dataMode = Image.MODE_IMAGE // Only image data tracked
|
||||
img.dataMode = Image.MODE_MIME // Only mime data tracked
|
||||
img.dataMode = Image.MODE_MIME | Image.MODE_IMAGE // Both are tracked
|
||||
```
|
||||
|
||||
If working with a non-PDF canvas, image data *must* be tracked; otherwise the output will be junk.
|
||||
|
||||
Enabling mime data tracking has no benefits (only a slow down) unless you are generating a PDF.
|
||||
|
||||
### Canvas#toBuffer()
|
||||
|
||||
> ```ts
|
||||
> canvas.toBuffer((err: Error|null, result: Buffer) => void, mimeType?: string, config?: any) => void
|
||||
> canvas.toBuffer(mimeType?: string, config?: any) => Buffer
|
||||
> ```
|
||||
|
||||
Creates a [`Buffer`](https://nodejs.org/api/buffer.html) object representing the image contained in the canvas.
|
||||
|
||||
* **callback** If provided, the buffer will be provided in the callback instead of being returned by the function. Invoked with an error as the first argument if encoding failed, or the resulting buffer as the second argument if it succeeded. Not supported for mimeType `raw` or for PDF or SVG canvases.
|
||||
* **mimeType** A string indicating the image format. Valid options are `image/png`, `image/jpeg` (if node-canvas was built with JPEG support), `raw` (unencoded data in BGRA order on little-endian (most) systems, ARGB on big-endian systems; top-to-bottom), `application/pdf` (for PDF canvases) and `image/svg+xml` (for SVG canvases). Defaults to `image/png` for image canvases, or the corresponding type for PDF or SVG canvas.
|
||||
* **config**
|
||||
* For `image/jpeg`, an object specifying the quality (0 to 1), if progressive compression should be used and/or if chroma subsampling should be used: `{quality: 0.75, progressive: false, chromaSubsampling: true}`. All properties are optional.
|
||||
|
||||
* For `image/png`, an object specifying the ZLIB compression level (between 0 and 9), the compression filter(s), the palette (indexed PNGs only), the the background palette index (indexed PNGs only) and/or the resolution (ppi): `{compressionLevel: 6, filters: canvas.PNG_ALL_FILTERS, palette: undefined, backgroundIndex: 0, resolution: undefined}`. All properties are optional.
|
||||
|
||||
Note that the PNG format encodes the resolution in pixels per meter, so if you specify `96`, the file will encode 3780 ppm (~96.01 ppi). The resolution is undefined by default to match common browser behavior.
|
||||
|
||||
* For `application/pdf`, an object specifying optional document metadata: `{title: string, author: string, subject: string, keywords: string, creator: string, creationDate: Date, modDate: Date}`. All properties are optional and default to `undefined`, except for `creationDate`, which defaults to the current date. *Adding metadata requires Cairo 1.16.0 or later.*
|
||||
|
||||
For a description of these properties, see page 550 of [PDF 32000-1:2008](https://www.adobe.com/content/dam/acom/en/devnet/acrobat/pdfs/PDF32000_2008.pdf).
|
||||
|
||||
Note that there is no standard separator for `keywords`. A space is recommended because it is in common use by other applications, and Cairo will enclose the list of keywords in quotes if a comma or semicolon is used.
|
||||
|
||||
**Return value**
|
||||
|
||||
If no callback is provided, a [`Buffer`](https://nodejs.org/api/buffer.html). If a callback is provided, none.
|
||||
|
||||
#### Examples
|
||||
|
||||
```js
|
||||
// Default: buf contains a PNG-encoded image
|
||||
const buf = canvas.toBuffer()
|
||||
|
||||
// PNG-encoded, zlib compression level 3 for faster compression but bigger files, no filtering
|
||||
const buf2 = canvas.toBuffer('image/png', { compressionLevel: 3, filters: canvas.PNG_FILTER_NONE })
|
||||
|
||||
// JPEG-encoded, 50% quality
|
||||
const buf3 = canvas.toBuffer('image/jpeg', { quality: 0.5 })
|
||||
|
||||
// Asynchronous PNG
|
||||
canvas.toBuffer((err, buf) => {
|
||||
if (err) throw err // encoding failed
|
||||
// buf is PNG-encoded image
|
||||
})
|
||||
|
||||
canvas.toBuffer((err, buf) => {
|
||||
if (err) throw err // encoding failed
|
||||
// buf is JPEG-encoded image at 95% quality
|
||||
}, 'image/jpeg', { quality: 0.95 })
|
||||
|
||||
// BGRA pixel values, native-endian
|
||||
const buf4 = canvas.toBuffer('raw')
|
||||
const { stride, width } = canvas
|
||||
// In memory, this is `canvas.height * canvas.stride` bytes long.
|
||||
// The top row of pixels, in BGRA order on little-endian hardware,
|
||||
// left-to-right, is:
|
||||
const topPixelsBGRALeftToRight = buf4.slice(0, width * 4)
|
||||
// And the third row is:
|
||||
const row3 = buf4.slice(2 * stride, 2 * stride + width * 4)
|
||||
|
||||
// SVG and PDF canvases
|
||||
const myCanvas = createCanvas(w, h, 'pdf')
|
||||
myCanvas.toBuffer() // returns a buffer containing a PDF-encoded canvas
|
||||
// With optional metadata:
|
||||
myCanvas.toBuffer('application/pdf', {
|
||||
title: 'my picture',
|
||||
keywords: 'node.js demo cairo',
|
||||
creationDate: new Date()
|
||||
})
|
||||
```
|
||||
|
||||
### Canvas#createPNGStream()
|
||||
|
||||
> ```ts
|
||||
> canvas.createPNGStream(config?: any) => ReadableStream
|
||||
> ```
|
||||
|
||||
Creates a [`ReadableStream`](https://nodejs.org/api/stream.html#stream_class_stream_readable) that emits PNG-encoded data.
|
||||
|
||||
* `config` An object specifying the ZLIB compression level (between 0 and 9), the compression filter(s), the palette (indexed PNGs only) and/or the background palette index (indexed PNGs only): `{compressionLevel: 6, filters: canvas.PNG_ALL_FILTERS, palette: undefined, backgroundIndex: 0, resolution: undefined}`. All properties are optional.
|
||||
|
||||
#### Examples
|
||||
|
||||
```javascript
|
||||
const fs = require('fs')
|
||||
const out = fs.createWriteStream(__dirname + '/test.png')
|
||||
const stream = canvas.createPNGStream()
|
||||
stream.pipe(out)
|
||||
out.on('finish', () => console.log('The PNG file was created.'))
|
||||
```
|
||||
|
||||
To encode indexed PNGs from canvases with `pixelFormat: 'A8'` or `'A1'`, provide an options object:
|
||||
|
||||
```js
|
||||
const palette = new Uint8ClampedArray([
|
||||
//r g b a
|
||||
0, 50, 50, 255, // index 1
|
||||
10, 90, 90, 255, // index 2
|
||||
127, 127, 255, 255
|
||||
// ...
|
||||
])
|
||||
canvas.createPNGStream({
|
||||
palette: palette,
|
||||
backgroundIndex: 0 // optional, defaults to 0
|
||||
})
|
||||
```
|
||||
|
||||
### Canvas#createJPEGStream()
|
||||
|
||||
> ```ts
|
||||
> canvas.createJPEGStream(config?: any) => ReadableStream
|
||||
> ```
|
||||
|
||||
Creates a [`ReadableStream`](https://nodejs.org/api/stream.html#stream_class_stream_readable) that emits JPEG-encoded data.
|
||||
|
||||
*Note: At the moment, `createJPEGStream()` is synchronous under the hood. That is, it runs in the main thread, not in the libuv threadpool.*
|
||||
|
||||
* `config` an object specifying the quality (0 to 1), if progressive compression should be used and/or if chroma subsampling should be used: `{quality: 0.75, progressive: false, chromaSubsampling: true}`. All properties are optional.
|
||||
|
||||
#### Examples
|
||||
|
||||
```javascript
|
||||
const fs = require('fs')
|
||||
const out = fs.createWriteStream(__dirname + '/test.jpeg')
|
||||
const stream = canvas.createJPEGStream()
|
||||
stream.pipe(out)
|
||||
out.on('finish', () => console.log('The JPEG file was created.'))
|
||||
|
||||
// Disable 2x2 chromaSubsampling for deeper colors and use a higher quality
|
||||
const stream = canvas.createJPEGStream({
|
||||
quality: 0.95,
|
||||
chromaSubsampling: false
|
||||
})
|
||||
```
|
||||
|
||||
### Canvas#createPDFStream()
|
||||
|
||||
> ```ts
|
||||
> canvas.createPDFStream(config?: any) => ReadableStream
|
||||
> ```
|
||||
|
||||
* `config` an object specifying optional document metadata: `{title: string, author: string, subject: string, keywords: string, creator: string, creationDate: Date, modDate: Date}`. See `toBuffer()` for more information. *Adding metadata requires Cairo 1.16.0 or later.*
|
||||
|
||||
Applies to PDF canvases only. Creates a [`ReadableStream`](https://nodejs.org/api/stream.html#stream_class_stream_readable) that emits the encoded PDF. `canvas.toBuffer()` also produces an encoded PDF, but `createPDFStream()` can be used to reduce memory usage.
|
||||
|
||||
### Canvas#toDataURL()
|
||||
|
||||
This is a standard API, but several non-standard calls are supported. The full list of supported calls is:
|
||||
|
||||
```js
|
||||
dataUrl = canvas.toDataURL() // defaults to PNG
|
||||
dataUrl = canvas.toDataURL('image/png')
|
||||
dataUrl = canvas.toDataURL('image/jpeg')
|
||||
dataUrl = canvas.toDataURL('image/jpeg', quality) // quality from 0 to 1
|
||||
canvas.toDataURL((err, png) => { }) // defaults to PNG
|
||||
canvas.toDataURL('image/png', (err, png) => { })
|
||||
canvas.toDataURL('image/jpeg', (err, jpeg) => { }) // sync JPEG is not supported
|
||||
canvas.toDataURL('image/jpeg', {...opts}, (err, jpeg) => { }) // see Canvas#createJPEGStream for valid options
|
||||
canvas.toDataURL('image/jpeg', quality, (err, jpeg) => { }) // spec-following; quality from 0 to 1
|
||||
```
|
||||
|
||||
### CanvasRenderingContext2D#patternQuality
|
||||
|
||||
> ```ts
|
||||
> context.patternQuality: 'fast'|'good'|'best'|'nearest'|'bilinear'
|
||||
> ```
|
||||
|
||||
Defaults to `'good'`. Affects pattern (gradient, image, etc.) rendering quality.
|
||||
|
||||
### CanvasRenderingContext2D#quality
|
||||
|
||||
> ```ts
|
||||
> context.quality: 'fast'|'good'|'best'|'nearest'|'bilinear'
|
||||
> ```
|
||||
|
||||
Defaults to `'good'`. Like `patternQuality`, but applies to transformations affecting more than just patterns.
|
||||
|
||||
### CanvasRenderingContext2D#textDrawingMode
|
||||
|
||||
> ```ts
|
||||
> context.textDrawingMode: 'path'|'glyph'
|
||||
> ```
|
||||
|
||||
Defaults to `'path'`. The effect depends on the canvas type:
|
||||
|
||||
* **Standard (image)** `glyph` and `path` both result in rasterized text. Glyph mode is faster than `path`, but may result in lower-quality text, especially when rotated or translated.
|
||||
|
||||
* **PDF** `glyph` will embed text instead of paths into the PDF. This is faster to encode, faster to open with PDF viewers, yields a smaller file size and makes the text selectable. The subset of the font needed to render the glyphs will be embedded in the PDF. This is usually the mode you want to use with PDF canvases.
|
||||
|
||||
* **SVG** `glyph` does *not* cause `<text>` elements to be produced as one might expect ([cairo bug](https://gitlab.freedesktop.org/cairo/cairo/issues/253)). Rather, `glyph` will create a `<defs>` section with a `<symbol>` for each glyph, then those glyphs be reused via `<use>` elements. `path` mode creates a `<path>` element for each text string. `glyph` mode is faster and yields a smaller file size.
|
||||
|
||||
In `glyph` mode, `ctx.strokeText()` and `ctx.fillText()` behave the same (aside from using the stroke and fill style, respectively).
|
||||
|
||||
This property is tracked as part of the canvas state in save/restore.
|
||||
|
||||
### CanvasRenderingContext2D#globalCompositeOperation = 'saturate'
|
||||
|
||||
In addition to all of the standard global composite operations defined by the Canvas specification, the ['saturate'](https://www.cairographics.org/operators/#saturate) operation is also available.
|
||||
|
||||
### CanvasRenderingContext2D#antialias
|
||||
|
||||
> ```ts
|
||||
> context.antialias: 'default'|'none'|'gray'|'subpixel'
|
||||
> ```
|
||||
|
||||
Sets the anti-aliasing mode.
|
||||
|
||||
## PDF Output Support
|
||||
|
||||
node-canvas can create PDF documents instead of images. The canvas type must be set when creating the canvas as follows:
|
||||
|
||||
```js
|
||||
const canvas = createCanvas(200, 500, 'pdf')
|
||||
```
|
||||
|
||||
An additional method `.addPage()` is then available to create multiple page PDFs:
|
||||
|
||||
```js
|
||||
// On first page
|
||||
ctx.font = '22px Helvetica'
|
||||
ctx.fillText('Hello World', 50, 80)
|
||||
|
||||
ctx.addPage()
|
||||
// Now on second page
|
||||
ctx.font = '22px Helvetica'
|
||||
ctx.fillText('Hello World 2', 50, 80)
|
||||
|
||||
canvas.toBuffer() // returns a PDF file
|
||||
canvas.createPDFStream() // returns a ReadableStream that emits a PDF
|
||||
// With optional document metadata (requires Cairo 1.16.0):
|
||||
canvas.toBuffer('application/pdf', {
|
||||
title: 'my picture',
|
||||
keywords: 'node.js demo cairo',
|
||||
creationDate: new Date()
|
||||
})
|
||||
```
|
||||
|
||||
It is also possible to create pages with different sizes by passing `width` and `height` to the `.addPage()` method:
|
||||
|
||||
```js
|
||||
ctx.font = '22px Helvetica'
|
||||
ctx.fillText('Hello World', 50, 80)
|
||||
ctx.addPage(400, 800)
|
||||
|
||||
ctx.fillText('Hello World 2', 50, 80)
|
||||
```
|
||||
|
||||
It is possible to add hyperlinks using `.beginTag()` and `.endTag()`:
|
||||
|
||||
```js
|
||||
ctx.beginTag('Link', "uri='https://google.com'")
|
||||
ctx.font = '22px Helvetica'
|
||||
ctx.fillText('Hello World', 50, 80)
|
||||
ctx.endTag('Link')
|
||||
```
|
||||
|
||||
Or with a defined rectangle:
|
||||
|
||||
```js
|
||||
ctx.beginTag('Link', "uri='https://google.com' rect=[50 80 100 20]")
|
||||
ctx.endTag('Link')
|
||||
```
|
||||
|
||||
Note that the syntax for attributes is unique to Cairo. See [cairo_tag_begin](https://www.cairographics.org/manual/cairo-Tags-and-Links.html#cairo-tag-begin) for the full documentation.
|
||||
|
||||
You can create areas on the canvas using the "cairo.dest" tag, and then link to them using the "Link" tag with the `dest=` attribute. You can also define PDF structure for accessibility by using tag names like "P", "H1", and "TABLE". The standard tags are defined in §14.8.4 of the [PDF 1.7](https://opensource.adobe.com/dc-acrobat-sdk-docs/pdfstandards/PDF32000_2008.pdf) specification.
|
||||
|
||||
See also:
|
||||
|
||||
* [Image#dataMode](#imagedatamode) for embedding JPEGs in PDFs
|
||||
* [Canvas#createPDFStream()](#canvascreatepdfstream) for creating PDF streams
|
||||
* [CanvasRenderingContext2D#textDrawingMode](#canvasrenderingcontext2dtextdrawingmode)
|
||||
for embedding text instead of paths
|
||||
|
||||
## SVG Output Support
|
||||
|
||||
node-canvas can create SVG documents instead of images. The canvas type must be set when creating the canvas as follows:
|
||||
|
||||
```js
|
||||
const canvas = createCanvas(200, 500, 'svg')
|
||||
// Use the normal primitives.
|
||||
fs.writeFileSync('out.svg', canvas.toBuffer())
|
||||
```
|
||||
|
||||
## SVG Image Support
|
||||
|
||||
If librsvg is available when node-canvas is installed, node-canvas can render SVG images to your canvas context. This currently works by rasterizing the SVG image (i.e. drawing an SVG image to an SVG canvas will not preserve the SVG data).
|
||||
|
||||
```js
|
||||
const img = new Image()
|
||||
img.onload = () => ctx.drawImage(img, 0, 0)
|
||||
img.onerror = err => { throw err }
|
||||
img.src = './example.svg'
|
||||
```
|
||||
|
||||
## Image pixel formats (experimental)
|
||||
|
||||
node-canvas has experimental support for additional pixel formats, roughly following the [Canvas color space proposal](https://github.com/WICG/canvas-color-space/blob/master/CanvasColorSpaceProposal.md).
|
||||
|
||||
```js
|
||||
const canvas = createCanvas(200, 200)
|
||||
const ctx = canvas.getContext('2d', { pixelFormat: 'A8' })
|
||||
```
|
||||
|
||||
By default, canvases are created in the `RGBA32` format, which corresponds to the native HTML Canvas behavior. Each pixel is 32 bits. The JavaScript APIs that involve pixel data (`getImageData`, `putImageData`) store the colors in the order {red, green, blue, alpha} without alpha pre-multiplication. (The C++ API stores the colors in the order {alpha, red, green, blue} in native-[endian](https://en.wikipedia.org/wiki/Endianness) ordering, with alpha pre-multiplication.)
|
||||
|
||||
These additional pixel formats have experimental support:
|
||||
|
||||
* `RGB24` Like `RGBA32`, but the 8 alpha bits are always opaque. This format is always used if the `alpha` context attribute is set to false (i.e. `canvas.getContext('2d', {alpha: false})`). This format can be faster than `RGBA32` because transparency does not need to be calculated.
|
||||
* `A8` Each pixel is 8 bits. This format can either be used for creating grayscale images (treating each byte as an alpha value), or for creating indexed PNGs (treating each byte as a palette index) (see [the example using alpha values with `fillStyle`](examples/indexed-png-alpha.js) and [the example using `imageData`](examples/indexed-png-image-data.js)).
|
||||
* `RGB16_565` Each pixel is 16 bits, with red in the upper 5 bits, green in the middle 6 bits, and blue in the lower 5 bits, in native platform endianness. Some hardware devices and frame buffers use this format. Note that PNG does not support this format; when creating a PNG, the image will be converted to 24-bit RGB. This format is thus suboptimal for generating PNGs. `ImageData` instances for this mode use a `Uint16Array` instead of a `Uint8ClampedArray`.
|
||||
* `A1` Each pixel is 1 bit, and pixels are packed together into 32-bit quantities. The ordering of the bits matches the endianness of the
|
||||
platform: on a little-endian machine, the first pixel is the least-significant bit. This format can be used for creating single-color images. *Support for this format is incomplete, see note below.*
|
||||
* `RGB30` Each pixel is 30 bits, with red in the upper 10, green in the middle 10, and blue in the lower 10. (Requires Cairo 1.12 or later.) *Support for this format is incomplete, see note below.*
|
||||
|
||||
Notes and caveats:
|
||||
|
||||
* Using a non-default format can affect the behavior of APIs that involve pixel data:
|
||||
|
||||
* `context2d.createImageData` The size of the array returned depends on the number of bit per pixel for the underlying image data format, per the above descriptions.
|
||||
* `context2d.getImageData` The format of the array returned depends on the underlying image mode, per the above descriptions. Be aware of platform endianness, which can be determined using node.js's [`os.endianness()`](https://nodejs.org/api/os.html#os_os_endianness)
|
||||
function.
|
||||
* `context2d.putImageData` As above.
|
||||
|
||||
* `A1` and `RGB30` do not yet support `getImageData` or `putImageData`. Have a use case and/or opinion on working with these formats? Open an issue and let us know! (See #935.)
|
||||
|
||||
* `A1`, `A8`, `RGB30` and `RGB16_565` with shadow blurs may crash or not render properly.
|
||||
|
||||
* The `ImageData(width, height)` and `ImageData(Uint8ClampedArray, width)` constructors assume 4 bytes per pixel. To create an `ImageData` instance with a different number of bytes per pixel, use `new ImageData(new Uint8ClampedArray(size), width, height)` or `new ImageData(new Uint16ClampedArray(size), width, height)`.
|
||||
|
||||
## Testing
|
||||
|
||||
First make sure you've built the latest version. Get all the deps you need (see [compiling](#compiling) above), and run:
|
||||
|
||||
```
|
||||
npm install --build-from-source
|
||||
```
|
||||
|
||||
For visual tests: `npm run test-server` and point your browser to http://localhost:4000.
|
||||
|
||||
For unit tests: `npm run test`.
|
||||
|
||||
## Benchmarks
|
||||
|
||||
Benchmarks live in the `benchmarks` directory.
|
||||
|
||||
## Examples
|
||||
|
||||
Examples line in the `examples` directory. Most produce a png image of the same name, and others such as *live-clock.js* launch an HTTP server to be viewed in the browser.
|
||||
|
||||
## Original Authors
|
||||
|
||||
- TJ Holowaychuk ([tj](http://github.com/tj))
|
||||
- Nathan Rajlich ([TooTallNate](http://github.com/TooTallNate))
|
||||
- Rod Vagg ([rvagg](http://github.com/rvagg))
|
||||
- Juriy Zaytsev ([kangax](http://github.com/kangax))
|
||||
|
||||
## License
|
||||
|
||||
### node-canvas
|
||||
|
||||
(The MIT License)
|
||||
|
||||
Copyright (c) 2010 LearnBoost, and contributors <dev@learnboost.com>
|
||||
|
||||
Copyright (c) 2014 Automattic, Inc and contributors <dev@automattic.com>
|
||||
|
||||
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.
|
||||
|
||||
### BMP parser
|
||||
|
||||
See [license](src/bmp/LICENSE.md)
|
||||
Binary file not shown.
@@ -0,0 +1,287 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
||||
const invariant = require("tiny-invariant");
|
||||
const warning = require("tiny-warning");
|
||||
const routerCore = require("@tanstack/router-core");
|
||||
const history = require("@tanstack/history");
|
||||
const awaited = require("./awaited.cjs");
|
||||
const CatchBoundary = require("./CatchBoundary.cjs");
|
||||
const fileRoute = require("./fileRoute.cjs");
|
||||
const lazyRouteComponent = require("./lazyRouteComponent.cjs");
|
||||
const link = require("./link.cjs");
|
||||
const Matches = require("./Matches.cjs");
|
||||
const matchContext = require("./matchContext.cjs");
|
||||
const Match = require("./Match.cjs");
|
||||
const useMatch = require("./useMatch.cjs");
|
||||
const useLoaderDeps = require("./useLoaderDeps.cjs");
|
||||
const useLoaderData = require("./useLoaderData.cjs");
|
||||
const route = require("./route.cjs");
|
||||
const router = require("./router.cjs");
|
||||
const RouterProvider = require("./RouterProvider.cjs");
|
||||
const ScrollRestoration = require("./ScrollRestoration.cjs");
|
||||
const useBlocker = require("./useBlocker.cjs");
|
||||
const useNavigate = require("./useNavigate.cjs");
|
||||
const useParams = require("./useParams.cjs");
|
||||
const useSearch = require("./useSearch.cjs");
|
||||
const routerContext = require("./routerContext.cjs");
|
||||
const useRouteContext = require("./useRouteContext.cjs");
|
||||
const useRouter = require("./useRouter.cjs");
|
||||
const useRouterState = require("./useRouterState.cjs");
|
||||
const useLocation = require("./useLocation.cjs");
|
||||
const useCanGoBack = require("./useCanGoBack.cjs");
|
||||
const utils = require("./utils.cjs");
|
||||
const notFound = require("./not-found.cjs");
|
||||
const ScriptOnce = require("./ScriptOnce.cjs");
|
||||
const Asset = require("./Asset.cjs");
|
||||
const HeadContent = require("./HeadContent.cjs");
|
||||
const Scripts = require("./Scripts.cjs");
|
||||
exports.invariant = invariant;
|
||||
exports.warning = warning;
|
||||
Object.defineProperty(exports, "PathParamError", {
|
||||
enumerable: true,
|
||||
get: () => routerCore.PathParamError
|
||||
});
|
||||
Object.defineProperty(exports, "SearchParamError", {
|
||||
enumerable: true,
|
||||
get: () => routerCore.SearchParamError
|
||||
});
|
||||
Object.defineProperty(exports, "TSR_DEFERRED_PROMISE", {
|
||||
enumerable: true,
|
||||
get: () => routerCore.TSR_DEFERRED_PROMISE
|
||||
});
|
||||
Object.defineProperty(exports, "cleanPath", {
|
||||
enumerable: true,
|
||||
get: () => routerCore.cleanPath
|
||||
});
|
||||
Object.defineProperty(exports, "componentTypes", {
|
||||
enumerable: true,
|
||||
get: () => routerCore.componentTypes
|
||||
});
|
||||
Object.defineProperty(exports, "createControlledPromise", {
|
||||
enumerable: true,
|
||||
get: () => routerCore.createControlledPromise
|
||||
});
|
||||
Object.defineProperty(exports, "decode", {
|
||||
enumerable: true,
|
||||
get: () => routerCore.decode
|
||||
});
|
||||
Object.defineProperty(exports, "deepEqual", {
|
||||
enumerable: true,
|
||||
get: () => routerCore.deepEqual
|
||||
});
|
||||
Object.defineProperty(exports, "defaultParseSearch", {
|
||||
enumerable: true,
|
||||
get: () => routerCore.defaultParseSearch
|
||||
});
|
||||
Object.defineProperty(exports, "defaultSerializeError", {
|
||||
enumerable: true,
|
||||
get: () => routerCore.defaultSerializeError
|
||||
});
|
||||
Object.defineProperty(exports, "defaultStringifySearch", {
|
||||
enumerable: true,
|
||||
get: () => routerCore.defaultStringifySearch
|
||||
});
|
||||
Object.defineProperty(exports, "defer", {
|
||||
enumerable: true,
|
||||
get: () => routerCore.defer
|
||||
});
|
||||
Object.defineProperty(exports, "encode", {
|
||||
enumerable: true,
|
||||
get: () => routerCore.encode
|
||||
});
|
||||
Object.defineProperty(exports, "escapeJSON", {
|
||||
enumerable: true,
|
||||
get: () => routerCore.escapeJSON
|
||||
});
|
||||
Object.defineProperty(exports, "functionalUpdate", {
|
||||
enumerable: true,
|
||||
get: () => routerCore.functionalUpdate
|
||||
});
|
||||
Object.defineProperty(exports, "getInitialRouterState", {
|
||||
enumerable: true,
|
||||
get: () => routerCore.getInitialRouterState
|
||||
});
|
||||
Object.defineProperty(exports, "interpolatePath", {
|
||||
enumerable: true,
|
||||
get: () => routerCore.interpolatePath
|
||||
});
|
||||
Object.defineProperty(exports, "isMatch", {
|
||||
enumerable: true,
|
||||
get: () => routerCore.isMatch
|
||||
});
|
||||
Object.defineProperty(exports, "isNotFound", {
|
||||
enumerable: true,
|
||||
get: () => routerCore.isNotFound
|
||||
});
|
||||
Object.defineProperty(exports, "isPlainArray", {
|
||||
enumerable: true,
|
||||
get: () => routerCore.isPlainArray
|
||||
});
|
||||
Object.defineProperty(exports, "isPlainObject", {
|
||||
enumerable: true,
|
||||
get: () => routerCore.isPlainObject
|
||||
});
|
||||
Object.defineProperty(exports, "isRedirect", {
|
||||
enumerable: true,
|
||||
get: () => routerCore.isRedirect
|
||||
});
|
||||
Object.defineProperty(exports, "joinPaths", {
|
||||
enumerable: true,
|
||||
get: () => routerCore.joinPaths
|
||||
});
|
||||
Object.defineProperty(exports, "lazyFn", {
|
||||
enumerable: true,
|
||||
get: () => routerCore.lazyFn
|
||||
});
|
||||
Object.defineProperty(exports, "matchByPath", {
|
||||
enumerable: true,
|
||||
get: () => routerCore.matchByPath
|
||||
});
|
||||
Object.defineProperty(exports, "matchPathname", {
|
||||
enumerable: true,
|
||||
get: () => routerCore.matchPathname
|
||||
});
|
||||
Object.defineProperty(exports, "notFound", {
|
||||
enumerable: true,
|
||||
get: () => routerCore.notFound
|
||||
});
|
||||
Object.defineProperty(exports, "parsePathname", {
|
||||
enumerable: true,
|
||||
get: () => routerCore.parsePathname
|
||||
});
|
||||
Object.defineProperty(exports, "parseSearchWith", {
|
||||
enumerable: true,
|
||||
get: () => routerCore.parseSearchWith
|
||||
});
|
||||
Object.defineProperty(exports, "pick", {
|
||||
enumerable: true,
|
||||
get: () => routerCore.pick
|
||||
});
|
||||
Object.defineProperty(exports, "redirect", {
|
||||
enumerable: true,
|
||||
get: () => routerCore.redirect
|
||||
});
|
||||
Object.defineProperty(exports, "removeBasepath", {
|
||||
enumerable: true,
|
||||
get: () => routerCore.removeBasepath
|
||||
});
|
||||
Object.defineProperty(exports, "replaceEqualDeep", {
|
||||
enumerable: true,
|
||||
get: () => routerCore.replaceEqualDeep
|
||||
});
|
||||
Object.defineProperty(exports, "resolvePath", {
|
||||
enumerable: true,
|
||||
get: () => routerCore.resolvePath
|
||||
});
|
||||
Object.defineProperty(exports, "retainSearchParams", {
|
||||
enumerable: true,
|
||||
get: () => routerCore.retainSearchParams
|
||||
});
|
||||
Object.defineProperty(exports, "rootRouteId", {
|
||||
enumerable: true,
|
||||
get: () => routerCore.rootRouteId
|
||||
});
|
||||
Object.defineProperty(exports, "shallow", {
|
||||
enumerable: true,
|
||||
get: () => routerCore.shallow
|
||||
});
|
||||
Object.defineProperty(exports, "stringifySearchWith", {
|
||||
enumerable: true,
|
||||
get: () => routerCore.stringifySearchWith
|
||||
});
|
||||
Object.defineProperty(exports, "stripSearchParams", {
|
||||
enumerable: true,
|
||||
get: () => routerCore.stripSearchParams
|
||||
});
|
||||
Object.defineProperty(exports, "trimPath", {
|
||||
enumerable: true,
|
||||
get: () => routerCore.trimPath
|
||||
});
|
||||
Object.defineProperty(exports, "trimPathLeft", {
|
||||
enumerable: true,
|
||||
get: () => routerCore.trimPathLeft
|
||||
});
|
||||
Object.defineProperty(exports, "trimPathRight", {
|
||||
enumerable: true,
|
||||
get: () => routerCore.trimPathRight
|
||||
});
|
||||
Object.defineProperty(exports, "createBrowserHistory", {
|
||||
enumerable: true,
|
||||
get: () => history.createBrowserHistory
|
||||
});
|
||||
Object.defineProperty(exports, "createHashHistory", {
|
||||
enumerable: true,
|
||||
get: () => history.createHashHistory
|
||||
});
|
||||
Object.defineProperty(exports, "createHistory", {
|
||||
enumerable: true,
|
||||
get: () => history.createHistory
|
||||
});
|
||||
Object.defineProperty(exports, "createMemoryHistory", {
|
||||
enumerable: true,
|
||||
get: () => history.createMemoryHistory
|
||||
});
|
||||
exports.Await = awaited.Await;
|
||||
exports.useAwaited = awaited.useAwaited;
|
||||
exports.CatchBoundary = CatchBoundary.CatchBoundary;
|
||||
exports.ErrorComponent = CatchBoundary.ErrorComponent;
|
||||
exports.FileRoute = fileRoute.FileRoute;
|
||||
exports.FileRouteLoader = fileRoute.FileRouteLoader;
|
||||
exports.LazyRoute = fileRoute.LazyRoute;
|
||||
exports.createFileRoute = fileRoute.createFileRoute;
|
||||
exports.createLazyFileRoute = fileRoute.createLazyFileRoute;
|
||||
exports.createLazyRoute = fileRoute.createLazyRoute;
|
||||
exports.lazyRouteComponent = lazyRouteComponent.lazyRouteComponent;
|
||||
exports.Link = link.Link;
|
||||
exports.createLink = link.createLink;
|
||||
exports.linkOptions = link.linkOptions;
|
||||
exports.useLinkProps = link.useLinkProps;
|
||||
exports.MatchRoute = Matches.MatchRoute;
|
||||
exports.Matches = Matches.Matches;
|
||||
exports.useChildMatches = Matches.useChildMatches;
|
||||
exports.useMatchRoute = Matches.useMatchRoute;
|
||||
exports.useMatches = Matches.useMatches;
|
||||
exports.useParentMatches = Matches.useParentMatches;
|
||||
exports.matchContext = matchContext.matchContext;
|
||||
exports.Match = Match.Match;
|
||||
exports.Outlet = Match.Outlet;
|
||||
exports.useMatch = useMatch.useMatch;
|
||||
exports.useLoaderDeps = useLoaderDeps.useLoaderDeps;
|
||||
exports.useLoaderData = useLoaderData.useLoaderData;
|
||||
exports.NotFoundRoute = route.NotFoundRoute;
|
||||
exports.RootRoute = route.RootRoute;
|
||||
exports.Route = route.Route;
|
||||
exports.RouteApi = route.RouteApi;
|
||||
exports.createRootRoute = route.createRootRoute;
|
||||
exports.createRootRouteWithContext = route.createRootRouteWithContext;
|
||||
exports.createRoute = route.createRoute;
|
||||
exports.createRouteMask = route.createRouteMask;
|
||||
exports.getRouteApi = route.getRouteApi;
|
||||
exports.rootRouteWithContext = route.rootRouteWithContext;
|
||||
exports.Router = router.Router;
|
||||
exports.createRouter = router.createRouter;
|
||||
exports.RouterContextProvider = RouterProvider.RouterContextProvider;
|
||||
exports.RouterProvider = RouterProvider.RouterProvider;
|
||||
exports.ScrollRestoration = ScrollRestoration.ScrollRestoration;
|
||||
exports.useElementScrollRestoration = ScrollRestoration.useElementScrollRestoration;
|
||||
exports.Block = useBlocker.Block;
|
||||
exports.useBlocker = useBlocker.useBlocker;
|
||||
exports.Navigate = useNavigate.Navigate;
|
||||
exports.useNavigate = useNavigate.useNavigate;
|
||||
exports.useParams = useParams.useParams;
|
||||
exports.useSearch = useSearch.useSearch;
|
||||
exports.getRouterContext = routerContext.getRouterContext;
|
||||
exports.useRouteContext = useRouteContext.useRouteContext;
|
||||
exports.useRouter = useRouter.useRouter;
|
||||
exports.useRouterState = useRouterState.useRouterState;
|
||||
exports.useLocation = useLocation.useLocation;
|
||||
exports.useCanGoBack = useCanGoBack.useCanGoBack;
|
||||
exports.useLayoutEffect = utils.useLayoutEffect;
|
||||
exports.useStableCallback = utils.useStableCallback;
|
||||
exports.CatchNotFound = notFound.CatchNotFound;
|
||||
exports.DefaultGlobalNotFound = notFound.DefaultGlobalNotFound;
|
||||
exports.ScriptOnce = ScriptOnce.ScriptOnce;
|
||||
exports.Asset = Asset.Asset;
|
||||
exports.HeadContent = HeadContent.HeadContent;
|
||||
exports.Scripts = Scripts.Scripts;
|
||||
//# sourceMappingURL=index.cjs.map
|
||||
@@ -0,0 +1,114 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
||||
const jsxRuntime = require("react/jsx-runtime");
|
||||
const React = require("react");
|
||||
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 CatchBoundary(props) {
|
||||
const errorComponent = props.errorComponent ?? ErrorComponent;
|
||||
return /* @__PURE__ */ jsxRuntime.jsx(
|
||||
CatchBoundaryImpl,
|
||||
{
|
||||
getResetKey: props.getResetKey,
|
||||
onCatch: props.onCatch,
|
||||
children: ({ error, reset }) => {
|
||||
if (error) {
|
||||
return React__namespace.createElement(errorComponent, {
|
||||
error,
|
||||
reset
|
||||
});
|
||||
}
|
||||
return props.children;
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
class CatchBoundaryImpl extends React__namespace.Component {
|
||||
constructor() {
|
||||
super(...arguments);
|
||||
this.state = { error: null };
|
||||
}
|
||||
static getDerivedStateFromProps(props) {
|
||||
return { resetKey: props.getResetKey() };
|
||||
}
|
||||
static getDerivedStateFromError(error) {
|
||||
return { error };
|
||||
}
|
||||
reset() {
|
||||
this.setState({ error: null });
|
||||
}
|
||||
componentDidUpdate(prevProps, prevState) {
|
||||
if (prevState.error && prevState.resetKey !== this.state.resetKey) {
|
||||
this.reset();
|
||||
}
|
||||
}
|
||||
componentDidCatch(error, errorInfo) {
|
||||
if (this.props.onCatch) {
|
||||
this.props.onCatch(error, errorInfo);
|
||||
}
|
||||
}
|
||||
render() {
|
||||
return this.props.children({
|
||||
error: this.state.resetKey !== this.props.getResetKey() ? null : this.state.error,
|
||||
reset: () => {
|
||||
this.reset();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
function ErrorComponent({ error }) {
|
||||
const [show, setShow] = React__namespace.useState(process.env.NODE_ENV !== "production");
|
||||
return /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { padding: ".5rem", maxWidth: "100%" }, children: [
|
||||
/* @__PURE__ */ jsxRuntime.jsxs("div", { style: { display: "flex", alignItems: "center", gap: ".5rem" }, children: [
|
||||
/* @__PURE__ */ jsxRuntime.jsx("strong", { style: { fontSize: "1rem" }, children: "Something went wrong!" }),
|
||||
/* @__PURE__ */ jsxRuntime.jsx(
|
||||
"button",
|
||||
{
|
||||
style: {
|
||||
appearance: "none",
|
||||
fontSize: ".6em",
|
||||
border: "1px solid currentColor",
|
||||
padding: ".1rem .2rem",
|
||||
fontWeight: "bold",
|
||||
borderRadius: ".25rem"
|
||||
},
|
||||
onClick: () => setShow((d) => !d),
|
||||
children: show ? "Hide Error" : "Show Error"
|
||||
}
|
||||
)
|
||||
] }),
|
||||
/* @__PURE__ */ jsxRuntime.jsx("div", { style: { height: ".25rem" } }),
|
||||
show ? /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(
|
||||
"pre",
|
||||
{
|
||||
style: {
|
||||
fontSize: ".7em",
|
||||
border: "1px solid red",
|
||||
borderRadius: ".25rem",
|
||||
padding: ".3rem",
|
||||
color: "red",
|
||||
overflow: "auto"
|
||||
},
|
||||
children: error.message ? /* @__PURE__ */ jsxRuntime.jsx("code", { children: error.message }) : null
|
||||
}
|
||||
) }) : null
|
||||
] });
|
||||
}
|
||||
exports.CatchBoundary = CatchBoundary;
|
||||
exports.ErrorComponent = ErrorComponent;
|
||||
//# sourceMappingURL=CatchBoundary.cjs.map
|
||||
@@ -0,0 +1,41 @@
|
||||
/**
|
||||
* @fileoverview Rule to flag use of a debugger statement
|
||||
* @author Nicholas C. Zakas
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Rule Definition
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/** @type {import('../shared/types').Rule} */
|
||||
module.exports = {
|
||||
meta: {
|
||||
type: "problem",
|
||||
|
||||
docs: {
|
||||
description: "Disallow the use of `debugger`",
|
||||
recommended: true,
|
||||
url: "https://eslint.org/docs/latest/rules/no-debugger",
|
||||
},
|
||||
|
||||
fixable: null,
|
||||
schema: [],
|
||||
|
||||
messages: {
|
||||
unexpected: "Unexpected 'debugger' statement.",
|
||||
},
|
||||
},
|
||||
|
||||
create(context) {
|
||||
return {
|
||||
DebuggerStatement(node) {
|
||||
context.report({
|
||||
node,
|
||||
messageId: "unexpected",
|
||||
});
|
||||
},
|
||||
};
|
||||
},
|
||||
};
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user