- Fix (Embedded editor): (Though embedding cross-origin iframes apparently

only working now in Chrome if same origin or if https?--at least not
  localhost of different ports), PDF export has been fixed (we download the
  PDF to workaround data URI limitations in Chrome)
- Fix (Embedded editor): Avoid using same origin shortcut if there is no
  global available to use (e.g., if using the modular editor)
- Fix (Embedded editor): Add events only after load is complete and
  svgCanvas is available; also log blocked error objects
- Enhancement: For PDF export, switch Chrome by default to "save" `outputType`
- Docs (JSdoc): Denote optional arguments
master
Brett Zamir 2018-10-23 22:24:09 +08:00
parent 5b4dae0d30
commit a714c122d3
13 changed files with 68 additions and 41 deletions

View File

@ -1,10 +1,20 @@
# ? # ?
- Fix (Embedded editor): (Though embedding cross-origin iframes apparently
only working now in Chrome if same origin or if https?--at least not
localhost of different ports), PDF export has been fixed (we download the
PDF to workaround data URI limitations in Chrome)
- Fix (Embedded editor): Avoid using same origin shortcut if there is no
global available to use (e.g., if using the modular editor)
- Fix (Embedded editor): Add events only after load is complete and
svgCanvas is available; also log blocked error objects
- Enhancement: For PDF export, switch Chrome by default to "save" `outputType`
- Refactoring (canvg): Better type-checking on `canvasRGBA_` (but set - Refactoring (canvg): Better type-checking on `canvasRGBA_` (but set
correctly by default anyways) correctly by default anyways)
- Refactoring: Avoid redundant use of \*AttributeNS methods with - Refactoring: Avoid redundant use of \*AttributeNS methods with
`null` value; just use \*Attribute methods without namespace `null` value; just use \*Attribute methods without namespace
- Docs: CHANGES clarifications - Docs: CHANGES clarifications
- Docs (JSdoc): Denote optional arguments
- Docs: More info on `importLocale` for extensions - Docs: More info on `importLocale` for extensions
- Build: Remove unused `Makefile` - Build: Remove unused `Makefile`

10
dist/index-es.js vendored
View File

@ -17561,15 +17561,17 @@ function SvgCanvas(container, config) {
* Generates a PDF based on the current image, then calls "exportedPDF" with * Generates a PDF based on the current image, then calls "exportedPDF" with
* an object including the string, the data URL, and any issues found * an object including the string, the data URL, and any issues found
* @function module:svgcanvas.SvgCanvas#exportPDF * @function module:svgcanvas.SvgCanvas#exportPDF
* @param {string} exportWindowName Will also be used for the download file name here * @param {string} [exportWindowName] Will also be used for the download file name here
* @param {external:jsPDF.OutputType} [outputType="dataurlstring"] * @param {external:jsPDF.OutputType} [outputType="dataurlstring"]
* @param {module:svgcanvas.PDFExportedCallback} cb * @param {module:svgcanvas.PDFExportedCallback} [cb]
* @fires module:svgcanvas.SvgCanvas#event:exportedPDF * @fires module:svgcanvas.SvgCanvas#event:exportedPDF
* @returns {Promise} Resolves to {@link module:svgcanvas.PDFExportedResults} * @returns {Promise} Resolves to {@link module:svgcanvas.PDFExportedResults}
*/ */
this.exportPDF = function (exportWindowName, outputType, cb) { this.exportPDF = function (exportWindowName) {
var outputType = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : isChrome() ? 'save' : undefined;
var cb = arguments.length > 2 ? arguments[2] : undefined;
var that = this; var that = this;
return new Promise( return new Promise(
/*#__PURE__*/ /*#__PURE__*/
@ -32141,7 +32143,7 @@ editor.init = function () {
openExportWindow(); openExportWindow();
} }
svgCanvas.exportPDF(exportWindowName, chrome ? 'save' : undefined); svgCanvas.exportPDF(exportWindowName);
_context6.next = 13; _context6.next = 13;
break; break;

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

10
dist/index-umd.js vendored
View File

@ -17567,15 +17567,17 @@
* Generates a PDF based on the current image, then calls "exportedPDF" with * Generates a PDF based on the current image, then calls "exportedPDF" with
* an object including the string, the data URL, and any issues found * an object including the string, the data URL, and any issues found
* @function module:svgcanvas.SvgCanvas#exportPDF * @function module:svgcanvas.SvgCanvas#exportPDF
* @param {string} exportWindowName Will also be used for the download file name here * @param {string} [exportWindowName] Will also be used for the download file name here
* @param {external:jsPDF.OutputType} [outputType="dataurlstring"] * @param {external:jsPDF.OutputType} [outputType="dataurlstring"]
* @param {module:svgcanvas.PDFExportedCallback} cb * @param {module:svgcanvas.PDFExportedCallback} [cb]
* @fires module:svgcanvas.SvgCanvas#event:exportedPDF * @fires module:svgcanvas.SvgCanvas#event:exportedPDF
* @returns {Promise} Resolves to {@link module:svgcanvas.PDFExportedResults} * @returns {Promise} Resolves to {@link module:svgcanvas.PDFExportedResults}
*/ */
this.exportPDF = function (exportWindowName, outputType, cb) { this.exportPDF = function (exportWindowName) {
var outputType = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : isChrome() ? 'save' : undefined;
var cb = arguments.length > 2 ? arguments[2] : undefined;
var that = this; var that = this;
return new Promise( return new Promise(
/*#__PURE__*/ /*#__PURE__*/
@ -32147,7 +32149,7 @@
openExportWindow(); openExportWindow();
} }
svgCanvas.exportPDF(exportWindowName, chrome ? 'save' : undefined); svgCanvas.exportPDF(exportWindowName);
_context6.next = 13; _context6.next = 13;
break; break;

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -4,6 +4,7 @@
* @module EmbeddedSVGEditDOM * @module EmbeddedSVGEditDOM
*/ */
import EmbeddedSVGEdit from './embedapi.js'; import EmbeddedSVGEdit from './embedapi.js';
import {isChrome} from './browser.js';
const $ = jQuery; const $ = jQuery;
@ -29,7 +30,6 @@ function saveSvg () {
function exportPNG () { function exportPNG () {
svgCanvas.getUIStrings()(function (uiStrings) { svgCanvas.getUIStrings()(function (uiStrings) {
const str = uiStrings.notification.loadingImage; const str = uiStrings.notification.loadingImage;
const exportWindow = window.open( const exportWindow = window.open(
'data:text/html;charset=utf-8,' + encodeURIComponent('<title>' + str + '</title><h1>' + str + '</h1>'), 'data:text/html;charset=utf-8,' + encodeURIComponent('<title>' + str + '</title><h1>' + str + '</h1>'),
'svg-edit-exportWindow' 'svg-edit-exportWindow'
@ -51,22 +51,20 @@ function exportPDF () {
return; return;
*/ */
if (isChrome()) {
svgCanvas.exportPDF();
} else {
const exportWindow = window.open( const exportWindow = window.open(
'data:text/html;charset=utf-8,' + encodeURIComponent('<title>' + str + '</title><h1>' + str + '</h1>'), 'data:text/html;charset=utf-8,' + encodeURIComponent('<title>' + str + '</title><h1>' + str + '</h1>'),
'svg-edit-exportWindow' 'svg-edit-exportWindow'
); );
svgCanvas.exportPDF(exportWindow && exportWindow.name); svgCanvas.exportPDF(exportWindow && exportWindow.name);
}
}); });
} }
// Add event handlers
$('#load').click(loadSvg);
$('#save').click(saveSvg);
$('#exportPNG').click(exportPNG);
$('#exportPDF').click(exportPDF);
const frameBase = 'https://raw.githack.com/SVG-Edit/svgedit/master'; const frameBase = 'https://raw.githack.com/SVG-Edit/svgedit/master';
// const frameBase = 'http://localhost:8001'; // const frameBase = 'http://localhost:8000';
const framePath = '/editor/xdomain-svg-editor-es.html?extensions=ext-xdomain-messaging.js'; const framePath = '/editor/xdomain-svg-editor-es.html?extensions=ext-xdomain-messaging.js';
const iframe = $('<iframe width="900px" height="600px" id="svgedit"></iframe>'); const iframe = $('<iframe width="900px" height="600px" id="svgedit"></iframe>');
iframe[0].src = frameBase + framePath + iframe[0].src = frameBase + framePath +
@ -81,11 +79,17 @@ iframe[0].addEventListener('load', function () {
try { try {
doc = frame.contentDocument || frame.contentWindow.document; doc = frame.contentDocument || frame.contentWindow.document;
} catch (err) { } catch (err) {
console.log('Blocked from accessing document'); console.log('Blocked from accessing document', err);
return; return;
} }
const mainButton = doc.getElementById('main_button'); const mainButton = doc.getElementById('main_button');
mainButton.style.display = 'none'; mainButton.style.display = 'none';
// Add event handlers now that `svgCanvas` is ready
$('#load').click(loadSvg);
$('#save').click(saveSvg);
$('#exportPNG').click(exportPNG);
$('#exportPDF').click(exportPDF);
}); });
$('body').append(iframe); $('body').append(iframe);
const frame = document.getElementById('svgedit'); const frame = document.getElementById('svgedit');

View File

@ -357,12 +357,13 @@ class EmbeddedSVGEdit {
* made compatile with all API functionality * made compatile with all API functionality
*/ */
// We accept and post strings for the sake of IE9 support // We accept and post strings for the sake of IE9 support
let sameOrigin = false; let sameOriginWithGlobal = false;
try { try {
sameOrigin = window.location.origin === t.frame.contentWindow.location.origin; sameOriginWithGlobal = window.location.origin === t.frame.contentWindow.location.origin &&
t.frame.contentWindow.svgEditor.canvas;
} catch (err) {} } catch (err) {}
if (sameOrigin) { if (sameOriginWithGlobal) {
// Although we do not really need this API if we are working same // Although we do not really need this API if we are working same
// domain, it could allow us to write in a way that would work // domain, it could allow us to write in a way that would work
// cross-domain as well, assuming we stick to the argument limitations // cross-domain as well, assuming we stick to the argument limitations

View File

@ -4228,7 +4228,7 @@ editor.init = function () {
if (!customExportPDF && !chrome) { if (!customExportPDF && !chrome) {
openExportWindow(); openExportWindow();
} }
svgCanvas.exportPDF(exportWindowName, chrome ? 'save' : undefined); svgCanvas.exportPDF(exportWindowName);
} else { } else {
if (!customExportImage) { if (!customExportImage) {
openExportWindow(); openExportWindow();

View File

@ -3957,13 +3957,17 @@ this.rasterExport = function (imgType, quality, exportWindowName, cb) {
* Generates a PDF based on the current image, then calls "exportedPDF" with * Generates a PDF based on the current image, then calls "exportedPDF" with
* an object including the string, the data URL, and any issues found * an object including the string, the data URL, and any issues found
* @function module:svgcanvas.SvgCanvas#exportPDF * @function module:svgcanvas.SvgCanvas#exportPDF
* @param {string} exportWindowName Will also be used for the download file name here * @param {string} [exportWindowName] Will also be used for the download file name here
* @param {external:jsPDF.OutputType} [outputType="dataurlstring"] * @param {external:jsPDF.OutputType} [outputType="dataurlstring"]
* @param {module:svgcanvas.PDFExportedCallback} cb * @param {module:svgcanvas.PDFExportedCallback} [cb]
* @fires module:svgcanvas.SvgCanvas#event:exportedPDF * @fires module:svgcanvas.SvgCanvas#event:exportedPDF
* @returns {Promise} Resolves to {@link module:svgcanvas.PDFExportedResults} * @returns {Promise} Resolves to {@link module:svgcanvas.PDFExportedResults}
*/ */
this.exportPDF = function (exportWindowName, outputType, cb) { this.exportPDF = function (
exportWindowName,
outputType = isChrome() ? 'save' : undefined,
cb
) {
const that = this; const that = this;
return new Promise(async (resolve, reject) => { return new Promise(async (resolve, reject) => {
if (!window.jsPDF) { if (!window.jsPDF) {

View File

@ -17564,15 +17564,17 @@
* Generates a PDF based on the current image, then calls "exportedPDF" with * Generates a PDF based on the current image, then calls "exportedPDF" with
* an object including the string, the data URL, and any issues found * an object including the string, the data URL, and any issues found
* @function module:svgcanvas.SvgCanvas#exportPDF * @function module:svgcanvas.SvgCanvas#exportPDF
* @param {string} exportWindowName Will also be used for the download file name here * @param {string} [exportWindowName] Will also be used for the download file name here
* @param {external:jsPDF.OutputType} [outputType="dataurlstring"] * @param {external:jsPDF.OutputType} [outputType="dataurlstring"]
* @param {module:svgcanvas.PDFExportedCallback} cb * @param {module:svgcanvas.PDFExportedCallback} [cb]
* @fires module:svgcanvas.SvgCanvas#event:exportedPDF * @fires module:svgcanvas.SvgCanvas#event:exportedPDF
* @returns {Promise} Resolves to {@link module:svgcanvas.PDFExportedResults} * @returns {Promise} Resolves to {@link module:svgcanvas.PDFExportedResults}
*/ */
this.exportPDF = function (exportWindowName, outputType, cb) { this.exportPDF = function (exportWindowName) {
var outputType = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : isChrome() ? 'save' : undefined;
var cb = arguments.length > 2 ? arguments[2] : undefined;
var that = this; var that = this;
return new Promise( return new Promise(
/*#__PURE__*/ /*#__PURE__*/
@ -32144,7 +32146,7 @@
openExportWindow(); openExportWindow();
} }
svgCanvas.exportPDF(exportWindowName, chrome ? 'save' : undefined); svgCanvas.exportPDF(exportWindowName);
_context6.next = 13; _context6.next = 13;
break; break;

View File

@ -17564,15 +17564,17 @@
* Generates a PDF based on the current image, then calls "exportedPDF" with * Generates a PDF based on the current image, then calls "exportedPDF" with
* an object including the string, the data URL, and any issues found * an object including the string, the data URL, and any issues found
* @function module:svgcanvas.SvgCanvas#exportPDF * @function module:svgcanvas.SvgCanvas#exportPDF
* @param {string} exportWindowName Will also be used for the download file name here * @param {string} [exportWindowName] Will also be used for the download file name here
* @param {external:jsPDF.OutputType} [outputType="dataurlstring"] * @param {external:jsPDF.OutputType} [outputType="dataurlstring"]
* @param {module:svgcanvas.PDFExportedCallback} cb * @param {module:svgcanvas.PDFExportedCallback} [cb]
* @fires module:svgcanvas.SvgCanvas#event:exportedPDF * @fires module:svgcanvas.SvgCanvas#event:exportedPDF
* @returns {Promise} Resolves to {@link module:svgcanvas.PDFExportedResults} * @returns {Promise} Resolves to {@link module:svgcanvas.PDFExportedResults}
*/ */
this.exportPDF = function (exportWindowName, outputType, cb) { this.exportPDF = function (exportWindowName) {
var outputType = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : isChrome() ? 'save' : undefined;
var cb = arguments.length > 2 ? arguments[2] : undefined;
var that = this; var that = this;
return new Promise( return new Promise(
/*#__PURE__*/ /*#__PURE__*/
@ -32144,7 +32146,7 @@
openExportWindow(); openExportWindow();
} }
svgCanvas.exportPDF(exportWindowName, chrome ? 'save' : undefined); svgCanvas.exportPDF(exportWindowName);
_context6.next = 13; _context6.next = 13;
break; break;