- Security fix: 'extPath', 'imgPath', 'extIconsPath', 'canvgPath', 'langPath', 'jGraduatePath', and 'jspdfPath' were not being prevented
- Breaking change: Rename "svgutils.js" to "utilities.js" (make in conformity with JSDoc module naming convention) - Breaking change: Rename "svgedit.js" to "namespaces.js" (to make clear purpose and avoid confusing with editor) - Breaking change: Rename "jquery-svg.js" to "jQuery.attr.js" - Breaking change: Rename "jquery.contextMenu.js" to "jQuery.contextMenu.js" - Breaking change: Rename "jquery.jpicker.js" to "jQuery.jPicker.js" - Breaking change: Rename "JQuerySpinBtn.css" to "jQuery.SpinButton.css" - Breaking change: Rename "JQuerySpinBtn.js" to "jQuery.SpinButton.js" (to have file name more closely reflect name) - Breaking change: Rename "jquery.svgicons.js" to "jQuery.svgIcons.js" - Breaking change: Rename "jquery.jgraduate.js" to "jQuery.jGraduate.js" - Breaking change: Rename "pathseg.js" to "svgpathseg.js" (as it is a poyfill of SVGPathSeg) - Breaking change: Rename `addSvgElementFromJson()` to `addSVGElementFromJson` for consistency - Breaking change: Rename `changeSvgContent()` to `changeSVGContent()` for consistency - Breaking change: Have `exportPDF` resolve with `output` and `outputType` rather than `dataurlstring` (as type may vary) - Breaking change: Rename `extensions/mathjax/MathJax.js` to `extensions/mathjax/MathJax.min.js` - Breaking change: Avoid recent change to have editor ready callbacks return Promises (we're not using and advantageous to keep sequential) - Breaking change: Avoid recent addition of locale-side function in ext-imagelib for l10n - Breaking change: Change name of ext-arrows.js from `Arrows` to `arrows` for sake of file path (not localized anyways). - Breaking change: Change `addlangData` extension event to `addLangData` for consistency with method name - Breaking change: Have `readLang` return lang and data but do not call `setLang` - Fix: Have general locales load first so extensions may use - Fix: Provide `importLocale` to extensions `init` so it may delay adding of the extension until locale data loaded - Fix: Ensure call to `rasterExport` without `imgType` properly sets MIME type to PNG - Fix: Wrong name for moinsave - Update: Update WebAppFind per new API changes - Enhancement: Make `setStrings` public on editor for late setting (used by `ext-shapes.js`) - Enhancement: Add `extensions_added` event - Enhancement: Add `message` event (Relay messages including those which have been been received prior to extension load) - Enhancement: Allow SVGEdit to work out of the box--avoid need for copying sample config file. Should also help with Github-based file servers - Enhancement: Allow avoiding "name" in extension export (just extract out of file name) - Enhancement: Add stack blur to canvg by default (and refactoring it) - Enhancement: Return `Promise` for `embedImage` (as with some other loading methods) - Enhancement: Supply `importLocale` to `langReady` to facilitate extension locale loading - Enhancement: Recover if an extension fails to load (just log and otherwise ignore) - Enhancement: More i18n of extensions (also fixed issue with some console warnings about missing locale strings); i18nize Hello World too - Enhancement: Allowing importing of locales within `addLangData` - npm: Update devDeps - Docs: Migrate copies of all old wiki pages to docs/from-old-wiki folder; intended for a possible move to Markdown, so raw HTML (with formatting) was not preserved, though named links had their absolute URL links preserved - Docs: Begin deleting `SvgCanvas.md` as ensuring jsdoc has replacements - Docs: Add Edtior doc file for help to general users - Docs: Clarify/simplify install instructions - npm/Docs (JSDoc): Add script to check for overly generic types - Docs (JSDoc): For config/prefs and extension creating, link to tutorials (moved tutorials to own directory to avoid recursion problems by jsdoc) - Docs (JSDoc): Add modules (upper case for usual main entrance files or regular names) - Docs (JSDoc): Fill out missing areas; indicate return of `undefined`; consistency with `@returns` - Docs (JSDoc): Add our own layout template to support overflow - Docs (JSDoc): Use cleverLinks and disallow unknown tags - Docs (JSDoc): Insist on "pedantic" flag; put output directory in config - Docs (JSDoc): Use more precise Integer/Float over number, the specific type of array/function/object - Docs (JSDoc): Use `@throws`, `@enum`, `@event`/`@fires`/`@listens` - Docs: Generally update/improve docs (fixes #92) - Docs: Update links to `latest` path (Avoid needing to update such references upon each release) - Docs: 80 chars max - Refactoring: Drop code for extension as function (already requiring export to be an object) - Refactoring: Object destructuring, `Object.entries`, Object shorthand, array extras, more camelCase variable names - Refactoring: Add a `Command` base class - Refactoring: Simplify svgicons `callback` ready detection - Refactoring: Put `let` or `const` closer to scope - Refactoring: Remove unneeded `delimiter` from regex escaping utility - Refactoring: Clearer variable names - Refactoring: Use (non-deprecated) Event constructors - Testing: Use new Sinon
This commit is contained in:
@@ -1,33 +1,64 @@
|
||||
/* eslint-disable new-cap */
|
||||
/*
|
||||
// Todo: Compare with latest canvg (add any improvements of ours) and add full JSDocs (denoting links to standard APIs and which are custom): https://github.com/canvg/canvg
|
||||
/**
|
||||
* canvg.js - Javascript SVG parser and renderer on Canvas
|
||||
* MIT Licensed
|
||||
* Gabe Lerner (gabelerner@gmail.com)
|
||||
* http://code.google.com/p/canvg/
|
||||
* @module canvg
|
||||
* @license MIT
|
||||
* @author Gabe Lerner <gabelerner@gmail.com>
|
||||
* @see https://github.com/canvg/canvg
|
||||
*/
|
||||
|
||||
import RGBColor from './rgbcolor.js';
|
||||
import {canvasRGBA} from './StackBlur.js';
|
||||
|
||||
let stackBlurCanvasRGBA;
|
||||
export const setStackBlurCanvasRGBA = (value) => {
|
||||
stackBlurCanvasRGBA = value;
|
||||
let canvasRGBA_ = canvasRGBA;
|
||||
|
||||
/**
|
||||
* @callback module:canvg.StackBlurCanvasRGBA
|
||||
* @param {string} id
|
||||
* @param {Float} x
|
||||
* @param {Float} y
|
||||
* @param {Float} width
|
||||
* @param {Float} height
|
||||
* @param {Float} blurRadius
|
||||
*/
|
||||
|
||||
/**
|
||||
* @callback module:canvg.ForceRedraw
|
||||
* @returns {boolean}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @function module:canvg.setStackBlurCanvasRGBA
|
||||
* @param {module:canvg.StackBlurCanvasRGBA} cb Will be passed the canvas ID, x, y, width, height, blurRadius
|
||||
*/
|
||||
export const setStackBlurCanvasRGBA = (cb) => {
|
||||
canvasRGBA_ = cb;
|
||||
};
|
||||
|
||||
// canvg(target, s)
|
||||
// empty parameters: replace all 'svg' elements on page with 'canvas' elements
|
||||
// target: canvas element or the id of a canvas element
|
||||
// s: svg string, url to svg file, or xml document
|
||||
// opts: optional hash of options
|
||||
// ignoreMouse: true => ignore mouse events
|
||||
// ignoreAnimation: true => ignore animations
|
||||
// ignoreDimensions: true => does not try to resize canvas
|
||||
// ignoreClear: true => does not clear canvas
|
||||
// offsetX: int => draws at a x offset
|
||||
// offsetY: int => draws at a y offset
|
||||
// scaleWidth: int => scales horizontally to width
|
||||
// scaleHeight: int => scales vertically to height
|
||||
// forceRedraw: function => will call the function on every frame, if it returns true, will redraw
|
||||
// returns all the function after the first render is completed with dom
|
||||
/**
|
||||
* @typedef {PlainObject} module:canvg.CanvgOptions
|
||||
* @property {boolean} opts.ignoreMouse true => ignore mouse events
|
||||
* @property {boolean} opts.ignoreAnimation true => ignore animations
|
||||
* @property {boolean} opts.ignoreDimensions true => does not try to resize canvas
|
||||
* @property {boolean} opts.ignoreClear true => does not clear canvas
|
||||
* @property {Integer} opts.offsetX int => draws at a x offset
|
||||
* @property {Integer} opts.offsetY int => draws at a y offset
|
||||
* @property {Integer} opts.scaleWidth int => scales horizontally to width
|
||||
* @property {Integer} opts.scaleHeight int => scales vertically to height
|
||||
* @property {module:canvg.ForceRedraw} opts.forceRedraw function => will call the function on every frame, if it returns true, will redraw
|
||||
* @property {boolean} opts.log Adds log function
|
||||
* @property {boolean} opts.useCORS Whether to set CORS `crossOrigin` for the image to `Anonymous`
|
||||
*/
|
||||
|
||||
/**
|
||||
* If called with no arguments, it will replace all `<svg>` elements on the page with `<canvas>` elements
|
||||
* @function module:canvg.canvg
|
||||
* @param {HTMLCanvasElement|string} target canvas element or the id of a canvas element
|
||||
* @param {string|XMLDocument} s: svg string, url to svg file, or xml document
|
||||
* @param {module:canvg.CanvgOptions} [opts] Optional hash of options
|
||||
* @returns {Promise} All the function after the first render is completed with dom
|
||||
*/
|
||||
export const canvg = function (target, s, opts) {
|
||||
// no parameters
|
||||
if (target == null && s == null && opts == null) {
|
||||
@@ -69,6 +100,11 @@ export const canvg = function (target, s, opts) {
|
||||
return svg.load(ctx, s);
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {module:canvg.CanvgOptions} opts
|
||||
* @returns {object}
|
||||
* @todo Flesh out exactly what object is returned here (after updating to latest and reincluding our changes here and those of StackBlur)
|
||||
*/
|
||||
function build (opts) {
|
||||
const svg = {opts};
|
||||
|
||||
@@ -2644,16 +2680,17 @@ function build (opts) {
|
||||
}
|
||||
|
||||
apply (ctx, x, y, width, height) {
|
||||
if (typeof stackBlurCanvasRGBA === 'undefined') {
|
||||
if (typeof canvasRGBA_ === 'undefined') {
|
||||
svg.log('ERROR: `setStackBlurCanvasRGBA` must be run for blur to work');
|
||||
return;
|
||||
}
|
||||
|
||||
// Todo: This might not be a problem anymore with out `instanceof` fix
|
||||
// StackBlur requires canvas be on document
|
||||
ctx.canvas.id = svg.UniqueId();
|
||||
ctx.canvas.style.display = 'none';
|
||||
document.body.append(ctx.canvas);
|
||||
stackBlurCanvasRGBA(ctx.canvas.id, x, y, width, height, this.blurRadius);
|
||||
canvasRGBA_(ctx.canvas.id, x, y, width, height, this.blurRadius);
|
||||
ctx.canvas.remove();
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user