first commit

This commit is contained in:
2026-08-07 12:53:18 +09:00
commit 0b0415f0f4
1523 changed files with 496649 additions and 0 deletions

View File

@@ -0,0 +1,6 @@
configure({
configs: [
'./test.js',
'./prod.js'
]
});

View File

@@ -0,0 +1,6 @@
configure({
configs: [
'./test.js',
'./prod.js'
]
});

View File

@@ -0,0 +1,8 @@
configure({
configs: [
'./prod.js'
],
sources: [
source('amd', 'tinymce/imagetoolsplugin/Demo', '../../src/demo/js', function(id) {return id.replace(/^tinymce\/imagetoolsplugin\//, '')})
]
});

View File

@@ -0,0 +1,6 @@
configure({
sources: [
source('amd', 'ephox/imagetools', '../../../../../../node_modules/@ephox/imagetools/src/main/js', mapper.hierarchical),
source('amd', 'tinymce/imagetoolsplugin', '../../src/main/js', function(id) {return id.replace(/^tinymce\/imagetoolsplugin\//, '');})
]
});

View File

@@ -0,0 +1,149 @@
/**
* Inline development version. Only to be used while developing since it uses document.write to load scripts.
*/
/*jshint smarttabs:true, undef:true, latedef:true, curly:true, bitwise:true, camelcase:true */
/*globals $code */
(function(exports) {
"use strict";
var html = "", baseDir;
var modules = {}, exposedModules = [], moduleCount = 0;
var scripts = document.getElementsByTagName('script');
for (var i = 0; i < scripts.length; i++) {
var src = scripts[i].src;
if (src.indexOf('/plugin.dev.js') != -1) {
baseDir = src.substring(0, src.lastIndexOf('/'));
}
}
function require(ids, callback) {
var module, defs = [];
for (var i = 0; i < ids.length; ++i) {
module = modules[ids[i]] || resolve(ids[i]);
if (!module) {
throw 'module definition dependecy not found: ' + ids[i];
}
defs.push(module);
}
callback.apply(null, defs);
}
function resolve(id) {
if (exports.privateModules && id in exports.privateModules) {
return;
}
var target = exports;
var fragments = id.split(/[.\/]/);
for (var fi = 0; fi < fragments.length; ++fi) {
if (!target[fragments[fi]]) {
return;
}
target = target[fragments[fi]];
}
return target;
}
function register(id) {
var target = exports;
var fragments = id.split(/[.\/]/);
for (var fi = 0; fi < fragments.length - 1; ++fi) {
if (target[fragments[fi]] === undefined) {
target[fragments[fi]] = {};
}
target = target[fragments[fi]];
}
target[fragments[fragments.length - 1]] = modules[id];
}
function define(id, dependencies, definition) {
var privateModules, i;
if (typeof id !== 'string') {
throw 'invalid module definition, module id must be defined and be a string';
}
if (dependencies === undefined) {
throw 'invalid module definition, dependencies must be specified';
}
if (definition === undefined) {
throw 'invalid module definition, definition function must be specified';
}
require(dependencies, function() {
modules[id] = definition.apply(null, arguments);
});
if (--moduleCount === 0) {
for (i = 0; i < exposedModules.length; i++) {
register(exposedModules[i]);
}
}
// Expose private modules for unit tests
if (exports.AMDLC_TESTS) {
privateModules = exports.privateModules || {};
for (id in modules) {
privateModules[id] = modules[id];
}
for (i = 0; i < exposedModules.length; i++) {
delete privateModules[exposedModules[i]];
}
exports.privateModules = privateModules;
}
}
function expose(ids) {
exposedModules = ids;
}
function writeScripts() {
document.write(html);
}
function load(path) {
html += '<script type="text/javascript" src="' + baseDir + '/' + path + '"></script>\n';
moduleCount++;
}
// Expose globally
exports.define = define;
exports.require = require;
expose(["tinymce/imagetoolsplugin/Canvas","tinymce/imagetoolsplugin/Mime","tinymce/imagetoolsplugin/ImageSize","tinymce/imagetoolsplugin/Conversions","tinymce/imagetoolsplugin/ImageTools","tinymce/imagetoolsplugin/CropRect","tinymce/imagetoolsplugin/ImagePanel","tinymce/imagetoolsplugin/ColorMatrix","tinymce/imagetoolsplugin/Filters","tinymce/imagetoolsplugin/UndoStack","tinymce/imagetoolsplugin/Dialog","tinymce/imagetoolsplugin/Plugin"]);
load('classes/Canvas.js');
load('classes/Mime.js');
load('classes/ImageSize.js');
load('classes/Conversions.js');
load('classes/ImageTools.js');
load('classes/CropRect.js');
load('classes/ImagePanel.js');
load('classes/ColorMatrix.js');
load('classes/Filters.js');
load('classes/UndoStack.js');
load('classes/Dialog.js');
load('classes/Plugin.js');
writeScripts();
})(this);
// $hash: 5de378762dc738e226443999f4a0ee2f

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,16 @@
<!DOCTYPE html>
<html>
<head>
<title>ImageTools Demo Page</title>
<script src="../../../../../tinymce.js"></script>
<script src="../../../config/bolt/bootstrap-demo.js"></script>
<script>
ephox.bolt.module.api.main('tinymce/imagetoolsplugin/Demo');
</script>
</head>
<body>
<h2>ImageTools Demo Page</h2>
<div id="ephox-ui"></div>
</body>
</html>

View File

@@ -0,0 +1,92 @@
/**
* Demo.js
*
* Released under LGPL License.
* Copyright (c) 1999-2016 Ephox Corp. All rights reserved
*
* License: http://www.tinymce.com/license
* Contributing: http://www.tinymce.com/contributing
*/
/*eslint no-console:0 */
define("tinymce/imagetoolsplugin/Demo", [
"tinymce/imagetoolsplugin/Plugin",
"global!tinymce",
"global!tinymce.dom.DomQuery",
"global!console"
], function(Plugin, tinymce, $, console) {
return function() {
var imgSrc = '../../../../../../../tests/manual/img/dogleft.jpg';
$(
'<textarea class="tinymce">' +
'<p>' +
'<img src="' + imgSrc + '" width="160" height="100">' +
'<img src="' + imgSrc + '" style="width: 160px; height: 100px">' +
'<img src="' + imgSrc + '" style="width: 20%">' +
'<img src="' + imgSrc + '">' +
'<img src="http://moxiecode.cachefly.net/tinymce/v9/images/logo.png">' +
'</p>' +
'</textarea>'
).appendTo('#ephox-ui');
tinymce.init({
//imagetools_cors_hosts: ["moxiecode.cachefly.net"],
//imagetools_proxy: "proxy.php",
//images_upload_url: 'postAcceptor.php',
//images_upload_base_path: 'base/path',
//images_upload_credentials: true,
selector: "textarea.tinymce",
theme: "modern",
plugins: [
"imagetools"
],
add_unload_trigger: false,
image_caption: true,
height: 600,
toolbar1: "undo redo | styleselect | alignleft aligncenter alignright alignjustify | link image | media | emoticons",
images_upload_handler: function(data, success, failure, openNotification) {
var notification;
console.log('blob upload [started]', data.id());
notification = openNotification();
notification.progressBar.value(100);
setTimeout(function() {
console.log('blob upload [ended]', data.id());
success(data.id() + '.png');
notification.close();
}, 1000);
}
});
function send() {
tinymce.activeEditor.uploadImages(function() {
console.log('saving:', tinymce.activeEditor.getContent());
});
}
function upload() {
console.log('upload [started]');
tinymce.activeEditor.uploadImages(function(success) {
console.log('upload [ended]', success);
});
}
function dump() {
var content = tinymce.activeEditor.getContent();
$('#view').html(content);
console.log(content);
}
$('<button>send()</button>').appendTo('#ephox-ui').on('click', send);
$('<button>upload()</button>').appendTo('#ephox-ui').on('click', upload);
$('<button>dump()</button>').appendTo('#ephox-ui').on('click', dump);
};
});

View File

@@ -0,0 +1,214 @@
/**
* CropRect.js
*
* Released under LGPL License.
* Copyright (c) 1999-2016 Ephox Corp. All rights reserved
*
* License: http://www.tinymce.com/license
* Contributing: http://www.tinymce.com/contributing
*/
/**
* ...
*/
define("tinymce/imagetoolsplugin/CropRect", [
"global!tinymce.dom.DomQuery",
"global!tinymce.ui.DragHelper",
"global!tinymce.geom.Rect",
"global!tinymce.util.Tools",
"global!tinymce.util.Observable"
], function($, DragHelper, Rect, Tools, Observable) {
var count = 0;
return function(currentRect, viewPortRect, clampRect, containerElm) {
var instance, handles, dragHelpers, blockers, prefix = 'mce-', id = prefix + 'crid-' + (count++);
handles = [
{name: 'move', xMul: 0, yMul: 0, deltaX: 1, deltaY: 1, deltaW: 0, deltaH: 0},
{name: 'nw', xMul: 0, yMul: 0, deltaX: 1, deltaY: 1, deltaW: -1, deltaH: -1},
{name: 'ne', xMul: 1, yMul: 0, deltaX: 0, deltaY: 1, deltaW: 1, deltaH: -1},
{name: 'sw', xMul: 0, yMul: 1, deltaX: 1, deltaY: 0, deltaW: -1, deltaH: 1},
{name: 'se', xMul: 1, yMul: 1, deltaX: 0, deltaY: 0, deltaW: 1, deltaH: 1}
];
blockers = ["top", "right", "bottom", "left"];
function getAbsoluteRect(outerRect, relativeRect) {
return {
x: relativeRect.x + outerRect.x,
y: relativeRect.y + outerRect.y,
w: relativeRect.w,
h: relativeRect.h
};
}
function getRelativeRect(outerRect, innerRect) {
return {
x: innerRect.x - outerRect.x,
y: innerRect.y - outerRect.y,
w: innerRect.w,
h: innerRect.h
};
}
function getInnerRect() {
return getRelativeRect(clampRect, currentRect);
}
function render() {
function createDragHelper(handle) {
var startRect;
return new DragHelper(id, {
document: containerElm.ownerDocument,
handle: id + '-' + handle.name,
start: function() {
startRect = currentRect;
},
drag: function(e) {
var x, y, w, h, rect;
x = startRect.x;
y = startRect.y;
w = startRect.w;
h = startRect.h;
x += e.deltaX * handle.deltaX;
y += e.deltaY * handle.deltaY;
w += e.deltaX * handle.deltaW;
h += e.deltaY * handle.deltaH;
if (w < 20) {
w = 20;
}
if (h < 20) {
h = 20;
}
rect = currentRect = Rect.clamp({x: x, y: y, w: w, h: h}, clampRect, handle.name == 'move');
rect = getRelativeRect(clampRect, rect);
instance.fire('updateRect', {rect: rect});
setInnerRect(rect);
}
});
}
$('<div id="' + id + '" class="' + prefix + 'croprect-container" data-mce-bogus="all">').appendTo(containerElm);
Tools.each(blockers, function(blocker) {
$('#' + id, containerElm).append(
'<div id="' + id + '-' + blocker + '"class="' + prefix + 'croprect-block" style="display: none" data-mce-bogus="all">'
);
});
Tools.each(handles, function(handle) {
$('#' + id, containerElm).append(
'<div id="' + id + '-' + handle.name + '" class="' + prefix +
'croprect-handle ' + prefix + 'croprect-handle-' + handle.name + '" style="display: none" data-mce-bogus="all">'
);
});
dragHelpers = Tools.map(handles, createDragHelper);
repaint(currentRect);
}
function toggleVisibility(state) {
var selectors;
selectors = Tools.map(handles, function(handle) {
return '#' + id + '-' + handle.name;
}).concat(Tools.map(blockers, function(blocker) {
return '#' + id + '-' + blocker;
})).join(',');
if (state) {
$(selectors, containerElm).show();
} else {
$(selectors, containerElm).hide();
}
}
function repaint(rect) {
function updateElementRect(name, rect) {
if (rect.h < 0) {
rect.h = 0;
}
if (rect.w < 0) {
rect.w = 0;
}
$('#' + id + '-' + name, containerElm).css({
left: rect.x,
top: rect.y,
width: rect.w,
height: rect.h
});
}
Tools.each(handles, function(handle) {
$('#' + id + '-' + handle.name, containerElm).css({
left: rect.w * handle.xMul + rect.x,
top: rect.h * handle.yMul + rect.y
});
});
updateElementRect('top', {x: viewPortRect.x, y: viewPortRect.y, w: viewPortRect.w, h: rect.y - viewPortRect.y});
updateElementRect('right', {x: rect.x + rect.w, y: rect.y, w: viewPortRect.w - rect.x - rect.w + viewPortRect.x, h: rect.h});
updateElementRect('bottom', {
x: viewPortRect.x,
y: rect.y + rect.h,
w: viewPortRect.w,
h: viewPortRect.h - rect.y - rect.h + viewPortRect.y
});
updateElementRect('left', {x: viewPortRect.x, y: rect.y, w: rect.x - viewPortRect.x, h: rect.h});
updateElementRect('move', rect);
}
function setRect(rect) {
currentRect = rect;
repaint(currentRect);
}
function setViewPortRect(rect) {
viewPortRect = rect;
repaint(currentRect);
}
function setInnerRect(rect) {
setRect(getAbsoluteRect(clampRect, rect));
}
function setClampRect(rect) {
clampRect = rect;
repaint(currentRect);
}
function destroy() {
Tools.each(dragHelpers, function(helper) {
helper.destroy();
});
dragHelpers = [];
}
render(containerElm);
instance = Tools.extend({
toggleVisibility: toggleVisibility,
setClampRect: setClampRect,
setRect: setRect,
getInnerRect: getInnerRect,
setInnerRect: setInnerRect,
setViewPortRect: setViewPortRect,
destroy: destroy
}, Observable);
return instance;
};
});

View File

@@ -0,0 +1,485 @@
/**
* Dialog.js
*
* Released under LGPL License.
* Copyright (c) 1999-2016 Ephox Corp. All rights reserved
*
* License: http://www.tinymce.com/license
* Contributing: http://www.tinymce.com/contributing
*/
/**
* ...
*/
define("tinymce/imagetoolsplugin/Dialog", [
"global!tinymce.dom.DOMUtils",
"global!tinymce.util.Tools",
"global!tinymce.util.Promise",
"global!tinymce.ui.Factory",
"global!tinymce.ui.Form",
"global!tinymce.ui.Container",
"tinymce/imagetoolsplugin/ImagePanel",
"ephox/imagetools/api/ImageTransformations",
"ephox/imagetools/api/BlobConversions",
"tinymce/imagetoolsplugin/UndoStack"
], function(DOMUtils, Tools, Promise, Factory, Form, Container, ImagePanel, ImageTransformations, BlobConversions, UndoStack) {
function createState(blob) {
return {
blob: blob,
url: URL.createObjectURL(blob)
};
}
function destroyState(state) {
if (state) {
URL.revokeObjectURL(state.url);
}
}
function destroyStates(states) {
Tools.each(states, destroyState);
}
function open(currentState, resolve, reject) {
var win, undoStack = new UndoStack(), mainPanel, filtersPanel, tempState,
cropPanel, resizePanel, flipRotatePanel, imagePanel, sidePanel, mainViewContainer,
invertPanel, brightnessPanel, huePanel, saturatePanel, contrastPanel, grayscalePanel,
sepiaPanel, colorizePanel, sharpenPanel, embossPanel, gammaPanel, exposurePanel, panels,
width, height, ratioW, ratioH;
function recalcSize(e) {
var widthCtrl, heightCtrl, newWidth, newHeight;
widthCtrl = win.find('#w')[0];
heightCtrl = win.find('#h')[0];
newWidth = parseInt(widthCtrl.value(), 10);
newHeight = parseInt(heightCtrl.value(), 10);
if (win.find('#constrain')[0].checked() && width && height && newWidth && newHeight) {
if (e.control.settings.name == 'w') {
newHeight = Math.round(newWidth * ratioW);
heightCtrl.value(newHeight);
} else {
newWidth = Math.round(newHeight * ratioH);
widthCtrl.value(newWidth);
}
}
width = newWidth;
height = newHeight;
}
function floatToPercent(value) {
return Math.round(value * 100) + '%';
}
function updateButtonUndoStates() {
win.find('#undo').disabled(!undoStack.canUndo());
win.find('#redo').disabled(!undoStack.canRedo());
win.statusbar.find('#save').disabled(!undoStack.canUndo());
}
function disableUndoRedo() {
win.find('#undo').disabled(true);
win.find('#redo').disabled(true);
}
function displayState(state) {
if (state) {
imagePanel.imageSrc(state.url);
}
}
function switchPanel(targetPanel) {
return function() {
var hidePanels = Tools.grep(panels, function(panel) {
return panel.settings.name != targetPanel;
});
Tools.each(hidePanels, function(panel) {
panel.hide();
});
targetPanel.show();
};
}
function addTempState(blob) {
tempState = createState(blob);
displayState(tempState);
}
function addBlobState(blob) {
currentState = createState(blob);
displayState(currentState);
destroyStates(undoStack.add(currentState).removed);
updateButtonUndoStates();
}
function crop() {
var rect = imagePanel.selection();
ImageTransformations.crop(currentState.blob, rect.x, rect.y, rect.w, rect.h).then(function(blob) {
addBlobState(blob);
cancel();
});
}
function tempAction(fn) {
var args = [].slice.call(arguments, 1);
return function() {
var state = tempState || currentState;
fn.apply(this, [state.blob].concat(args)).then(addTempState);
};
}
function action(fn) {
var args = [].slice.call(arguments, 1);
return function() {
fn.apply(this, [currentState.blob].concat(args)).then(addBlobState);
};
}
function cancel() {
displayState(currentState);
destroyState(tempState);
switchPanel(mainPanel)();
updateButtonUndoStates();
}
function applyTempState() {
if (tempState) {
addBlobState(tempState.blob);
cancel();
}
}
function zoomIn() {
var zoom = imagePanel.zoom();
if (zoom < 2) {
zoom += 0.1;
}
imagePanel.zoom(zoom);
}
function zoomOut() {
var zoom = imagePanel.zoom();
if (zoom > 0.1) {
zoom -= 0.1;
}
imagePanel.zoom(zoom);
}
function undo() {
currentState = undoStack.undo();
displayState(currentState);
updateButtonUndoStates();
}
function redo() {
currentState = undoStack.redo();
displayState(currentState);
updateButtonUndoStates();
}
function save() {
resolve(currentState.blob);
win.close();
}
function createPanel(items) {
return new Form({
layout: 'flex',
direction: 'row',
labelGap: 5,
border: '0 0 1 0',
align: 'center',
pack: 'center',
padding: '0 10 0 10',
spacing: 5,
flex: 0,
minHeight: 60,
defaults: {
classes: 'imagetool',
type: 'button'
},
items: items
});
}
function createFilterPanel(title, filter) {
return createPanel([
{text: 'Back', onclick: cancel},
{type: 'spacer', flex: 1},
{text: 'Apply', subtype: 'primary', onclick: applyTempState}
]).hide().on('show', function() {
disableUndoRedo();
filter(currentState.blob).then(function(blob) {
var newTempState = createState(blob);
displayState(newTempState);
destroyState(tempState);
tempState = newTempState;
});
});
}
function createVariableFilterPanel(title, filter, value, min, max) {
function update(value) {
filter(currentState.blob, value).then(function(blob) {
var newTempState = createState(blob);
displayState(newTempState);
destroyState(tempState);
tempState = newTempState;
});
}
return createPanel([
{text: 'Back', onclick: cancel},
{type: 'spacer', flex: 1},
{
type: 'slider',
flex: 1,
ondragend: function(e) {
update(e.value);
},
minValue: min,
maxValue: max,
value: value,
previewFilter: floatToPercent
},
{type: 'spacer', flex: 1},
{text: 'Apply', subtype: 'primary', onclick: applyTempState}
]).hide().on('show', function() {
this.find('slider').value(value);
disableUndoRedo();
});
}
function createRgbFilterPanel(title, filter) {
function update() {
var r, g, b;
r = win.find('#r')[0].value();
g = win.find('#g')[0].value();
b = win.find('#b')[0].value();
filter(currentState.blob, r, g, b).then(function(blob) {
var newTempState = createState(blob);
displayState(newTempState);
destroyState(tempState);
tempState = newTempState;
});
}
return createPanel([
{text: 'Back', onclick: cancel},
{type: 'spacer', flex: 1},
{
type: 'slider', label: 'R', name: 'r', minValue: 0,
value: 1, maxValue: 2, ondragend: update, previewFilter: floatToPercent
},
{
type: 'slider', label: 'G', name: 'g', minValue: 0,
value: 1, maxValue: 2, ondragend: update, previewFilter: floatToPercent
},
{
type: 'slider', label: 'B', name: 'b', minValue: 0,
value: 1, maxValue: 2, ondragend: update, previewFilter: floatToPercent
},
{type: 'spacer', flex: 1},
{text: 'Apply', subtype: 'primary', onclick: applyTempState}
]).hide().on('show', function() {
win.find('#r,#g,#b').value(1);
disableUndoRedo();
});
}
cropPanel = createPanel([
{text: 'Back', onclick: cancel},
{type: 'spacer', flex: 1},
{text: 'Apply', subtype: 'primary', onclick: crop}
]).hide().on('show hide', function(e) {
imagePanel.toggleCropRect(e.type == 'show');
}).on('show', disableUndoRedo);
function toggleConstrain(e) {
if (e.control.value() === true) {
ratioW = height / width;
ratioH = width / height;
}
}
resizePanel = createPanel([
{text: 'Back', onclick: cancel},
{type: 'spacer', flex: 1},
{type: 'textbox', name: 'w', label: 'Width', size: 4, onkeyup: recalcSize},
{type: 'textbox', name: 'h', label: 'Height', size: 4, onkeyup: recalcSize},
{type: 'checkbox', name: 'constrain', text: 'Constrain proportions', checked: true, onchange: toggleConstrain},
{type: 'spacer', flex: 1},
{text: 'Apply', subtype: 'primary', onclick: 'submit'}
]).hide().on('submit', function(e) {
var width = parseInt(win.find('#w').value(), 10),
height = parseInt(win.find('#h').value(), 10);
e.preventDefault();
action(ImageTransformations.resize, width, height)();
cancel();
}).on('show', disableUndoRedo);
flipRotatePanel = createPanel([
{text: 'Back', onclick: cancel},
{type: 'spacer', flex: 1},
{icon: 'fliph', tooltip: 'Flip horizontally', onclick: tempAction(ImageTransformations.flip, 'h')},
{icon: 'flipv', tooltip: 'Flip vertically', onclick: tempAction(ImageTransformations.flip, 'v')},
{icon: 'rotateleft', tooltip: 'Rotate counterclockwise', onclick: tempAction(ImageTransformations.rotate, -90)},
{icon: 'rotateright', tooltip: 'Rotate clockwise', onclick: tempAction(ImageTransformations.rotate, 90)},
{type: 'spacer', flex: 1},
{text: 'Apply', subtype: 'primary', onclick: applyTempState}
]).hide().on('show', disableUndoRedo);
invertPanel = createFilterPanel("Invert", ImageTransformations.invert);
sharpenPanel = createFilterPanel("Sharpen", ImageTransformations.sharpen);
embossPanel = createFilterPanel("Emboss", ImageTransformations.emboss);
brightnessPanel = createVariableFilterPanel("Brightness", ImageTransformations.brightness, 0, -1, 1);
huePanel = createVariableFilterPanel("Hue", ImageTransformations.hue, 180, 0, 360);
saturatePanel = createVariableFilterPanel("Saturate", ImageTransformations.saturate, 0, -1, 1);
contrastPanel = createVariableFilterPanel("Contrast", ImageTransformations.contrast, 0, -1, 1);
grayscalePanel = createVariableFilterPanel("Grayscale", ImageTransformations.grayscale, 0, 0, 1);
sepiaPanel = createVariableFilterPanel("Sepia", ImageTransformations.sepia, 0, 0, 1);
colorizePanel = createRgbFilterPanel("Colorize", ImageTransformations.colorize);
gammaPanel = createVariableFilterPanel("Gamma", ImageTransformations.gamma, 0, -1, 1);
exposurePanel = createVariableFilterPanel("Exposure", ImageTransformations.exposure, 1, 0, 2);
filtersPanel = createPanel([
{text: 'Back', onclick: cancel},
{type: 'spacer', flex: 1},
{text: 'hue', icon: 'hue', onclick: switchPanel(huePanel)},
{text: 'saturate', icon: 'saturate', onclick: switchPanel(saturatePanel)},
{text: 'sepia', icon: 'sepia', onclick: switchPanel(sepiaPanel)},
{text: 'emboss', icon: 'emboss', onclick: switchPanel(embossPanel)},
{text: 'exposure', icon: 'exposure', onclick: switchPanel(exposurePanel)},
{type: 'spacer', flex: 1}
]).hide();
mainPanel = createPanel([
{tooltip: 'Crop', icon: 'crop', onclick: switchPanel(cropPanel)},
{tooltip: 'Resize', icon: 'resize2', onclick: switchPanel(resizePanel)},
{tooltip: 'Orientation', icon: 'orientation', onclick: switchPanel(flipRotatePanel)},
{tooltip: 'Brightness', icon: 'sun', onclick: switchPanel(brightnessPanel)},
{tooltip: 'Sharpen', icon: 'sharpen', onclick: switchPanel(sharpenPanel)},
{tooltip: 'Contrast', icon: 'contrast', onclick: switchPanel(contrastPanel)},
{tooltip: 'Color levels', icon: 'drop', onclick: switchPanel(colorizePanel)},
{tooltip: 'Gamma', icon: 'gamma', onclick: switchPanel(gammaPanel)},
{tooltip: 'Invert', icon: 'invert', onclick: switchPanel(invertPanel)}
//{text: 'More', onclick: switchPanel(filtersPanel)}
]);
imagePanel = new ImagePanel({
flex: 1,
imageSrc: currentState.url
});
sidePanel = new Container({
layout: 'flex',
direction: 'column',
border: '0 1 0 0',
padding: 5,
spacing: 5,
items: [
{type: 'button', icon: 'undo', tooltip: 'Undo', name: 'undo', onclick: undo},
{type: 'button', icon: 'redo', tooltip: 'Redo', name: 'redo', onclick: redo},
{type: 'button', icon: 'zoomin', tooltip: 'Zoom in', onclick: zoomIn},
{type: 'button', icon: 'zoomout', tooltip: 'Zoom out', onclick: zoomOut}
]
});
mainViewContainer = new Container({
type: 'container',
layout: 'flex',
direction: 'row',
align: 'stretch',
flex: 1,
items: [sidePanel, imagePanel]
});
panels = [
mainPanel,
cropPanel,
resizePanel,
flipRotatePanel,
filtersPanel,
invertPanel,
brightnessPanel,
huePanel,
saturatePanel,
contrastPanel,
grayscalePanel,
sepiaPanel,
colorizePanel,
sharpenPanel,
embossPanel,
gammaPanel,
exposurePanel
];
win = Factory.create('window', {
layout: 'flex',
direction: 'column',
align: 'stretch',
minWidth: Math.min(DOMUtils.DOM.getViewPort().w, 800),
minHeight: Math.min(DOMUtils.DOM.getViewPort().h, 650),
title: 'Edit image',
items: panels.concat([mainViewContainer]),
buttons: [
{text: 'Save', name: 'save', subtype: 'primary', onclick: save},
{text: 'Cancel', onclick: 'close'}
]
});
win.renderTo(document.body).reflow();
win.on('close', function() {
reject();
destroyStates(undoStack.data);
undoStack = null;
tempState = null;
});
undoStack.add(currentState);
updateButtonUndoStates();
imagePanel.on('load', function() {
width = imagePanel.imageSize().w;
height = imagePanel.imageSize().h;
ratioW = height / width;
ratioH = width / height;
win.find('#w').value(width);
win.find('#h').value(height);
});
}
function edit(blob) {
return new Promise(function(resolve, reject) {
open(createState(blob), resolve, reject);
});
}
//edit('img/dogleft.jpg');
return {
edit: edit
};
});

View File

@@ -0,0 +1,218 @@
/**
* ImagePanel.js
*
* Released under LGPL License.
* Copyright (c) 1999-2016 Ephox Corp. All rights reserved
*
* License: http://www.tinymce.com/license
* Contributing: http://www.tinymce.com/contributing
*/
/**
* ...
*
* @-x-less ImagePanel.less
*/
define("tinymce/imagetoolsplugin/ImagePanel", [
"global!tinymce.ui.Control",
"global!tinymce.ui.DragHelper",
"global!tinymce.geom.Rect",
"global!tinymce.util.Tools",
"global!tinymce.util.Promise",
"tinymce/imagetoolsplugin/CropRect"
], function(Control, DragHelper, Rect, Tools, Promise, CropRect) {
function loadImage(image) {
return new Promise(function(resolve) {
function loaded() {
image.removeEventListener('load', loaded);
resolve(image);
}
if (image.complete) {
resolve(image);
} else {
image.addEventListener('load', loaded);
}
});
}
return Control.extend({
Defaults: {
classes: "imagepanel"
},
selection: function(rect) {
if (arguments.length) {
this.state.set('rect', rect);
return this;
}
return this.state.get('rect');
},
imageSize: function() {
var viewRect = this.state.get('viewRect');
return {
w: viewRect.w,
h: viewRect.h
};
},
toggleCropRect: function(state) {
this.state.set('cropEnabled', state);
},
imageSrc: function(url) {
var self = this, img = new Image();
img.src = url;
loadImage(img).then(function() {
var rect, $img, lastRect = self.state.get('viewRect');
$img = self.$el.find('img');
if ($img[0]) {
$img.replaceWith(img);
} else {
self.getEl().appendChild(img);
}
rect = {x: 0, y: 0, w: img.naturalWidth, h: img.naturalHeight};
self.state.set('viewRect', rect);
self.state.set('rect', Rect.inflate(rect, -20, -20));
if (!lastRect || lastRect.w != rect.w || lastRect.h != rect.h) {
self.zoomFit();
}
self.repaintImage();
self.fire('load');
});
},
zoom: function(value) {
if (arguments.length) {
this.state.set('zoom', value);
return this;
}
return this.state.get('zoom');
},
postRender: function() {
this.imageSrc(this.settings.imageSrc);
return this._super();
},
zoomFit: function() {
var self = this, $img, pw, ph, w, h, zoom, padding;
padding = 10;
$img = self.$el.find('img');
pw = self.getEl().clientWidth;
ph = self.getEl().clientHeight;
w = $img[0].naturalWidth;
h = $img[0].naturalHeight;
zoom = Math.min((pw - padding) / w, (ph - padding) / h);
if (zoom >= 1) {
zoom = 1;
}
self.zoom(zoom);
},
repaintImage: function() {
var x, y, w, h, pw, ph, $img, zoom, rect, elm;
elm = this.getEl();
zoom = this.zoom();
rect = this.state.get('rect');
$img = this.$el.find('img');
pw = elm.offsetWidth;
ph = elm.offsetHeight;
w = $img[0].naturalWidth * zoom;
h = $img[0].naturalHeight * zoom;
x = Math.max(0, pw / 2 - w / 2);
y = Math.max(0, ph / 2 - h / 2);
$img.css({
left: x,
top: y,
width: w,
height: h
});
if (this.cropRect) {
this.cropRect.setRect({
x: rect.x * zoom + x,
y: rect.y * zoom + y,
w: rect.w * zoom,
h: rect.h * zoom
});
this.cropRect.setClampRect({
x: x,
y: y,
w: w,
h: h
});
this.cropRect.setViewPortRect({
x: 0,
y: 0,
w: pw,
h: ph
});
}
},
bindStates: function() {
var self = this;
function setupCropRect(rect) {
self.cropRect = new CropRect(
rect,
self.state.get('viewRect'),
self.state.get('viewRect'),
self.getEl()
);
self.cropRect.on('updateRect', function(e) {
var rect = e.rect, zoom = self.zoom();
rect = {
x: Math.round(rect.x / zoom),
y: Math.round(rect.y / zoom),
w: Math.round(rect.w / zoom),
h: Math.round(rect.h / zoom)
};
self.state.set('rect', rect);
});
self.on('remove', self.cropRect.destroy);
}
self.state.on('change:cropEnabled', function(e) {
self.cropRect.toggleVisibility(e.value);
self.repaintImage();
});
self.state.on('change:zoom', function() {
self.repaintImage();
});
self.state.on('change:rect', function(e) {
var rect = e.value;
if (!self.cropRect) {
setupCropRect(rect);
}
self.cropRect.setRect(rect);
});
}
});
});

View File

@@ -0,0 +1,411 @@
/**
* Plugin.js
*
* Released under LGPL License.
* Copyright (c) 1999-2016 Ephox Corp. All rights reserved
*
* License: http://www.tinymce.com/license
* Contributing: http://www.tinymce.com/contributing
*/
/**
*
* Settings:
* imagetools_cors_hosts - Array of remote domains that has CORS setup.
* imagetools_proxy - Url to proxy that streams images from remote host to local host.
* imagetools_toolbar - Toolbar items to render when an editable image is selected.
*/
define("tinymce/imagetoolsplugin/Plugin", [
"global!tinymce.PluginManager",
"global!tinymce.Env",
"global!tinymce.util.Promise",
"global!tinymce.util.URI",
"global!tinymce.util.Tools",
"global!tinymce.util.Delay",
"ephox/imagetools/api/ImageTransformations",
"ephox/imagetools/api/BlobConversions",
"tinymce/imagetoolsplugin/Dialog"
], function(PluginManager, Env, Promise, URI, Tools, Delay, ImageTransformations, BlobConversions, Dialog) {
var plugin = function(editor) {
var count = 0, imageUploadTimer, lastSelectedImage;
if (!Env.fileApi) {
return;
}
/*
function startCrop() {
var imageRect, viewPortRect;
imageRect = getSelectedImage().getBoundingClientRect();
imageRect = {
x: imageRect.left,
y: imageRect.top,
w: imageRect.width,
h: imageRect.height
};
viewPortRect = {
x: 0,
y: 0,
w: editor.getBody().scrollWidth,
h: editor.getBody().scrollHeight
};
cropRect = new CropRect(imageRect, viewPortRect, imageRect, editor.getBody());
cropRect.toggleVisibility(true);
editor.selection.getSel().removeAllRanges();
editor.nodeChanged();
}
function stopCrop() {
if (cropRect) {
cropRect.destroy();
cropRect = null;
}
}
*/
function getImageSize(img) {
var width, height;
function isPxValue(value) {
return value.indexOf('px') == value.length - 2;
}
width = img.style.width;
height = img.style.height;
if (width || height) {
if (isPxValue(width) && isPxValue(height)) {
return {
w: parseInt(width, 10),
h: parseInt(height, 10)
};
}
return null;
}
width = editor.$(img).attr('width');
height = editor.$(img).attr('height');
if (width && height) {
return {
w: parseInt(width, 10),
h: parseInt(height, 10)
};
}
return null;
}
function setImageSize(img, size) {
var width, height;
if (size) {
width = img.style.width;
height = img.style.height;
if (width || height) {
editor.$(img).css({
width: size.w,
height: size.h
}).removeAttr('data-mce-style');
}
width = img.width;
height = img.height;
if (width || height) {
editor.$(img).attr({
width: size.w,
height: size.h
});
}
}
}
function getNaturalImageSize(img) {
return {
w: img.naturalWidth,
h: img.naturalHeight
};
}
function getSelectedImage() {
return editor.selection.getNode();
}
function createId() {
return 'imagetools' + count++;
}
function isLocalImage(img) {
var url = img.src;
return url.indexOf('data:') === 0 || url.indexOf('blob:') === 0 || new URI(url).host === editor.documentBaseURI.host;
}
function isCorsImage(img) {
return Tools.inArray(editor.settings.imagetools_cors_hosts, new URI(img.src).host) !== -1;
}
function getApiKey() {
return editor.settings.api_key || editor.settings.imagetools_api_key;
}
function requestUrlAsBlob(url) {
return new Promise(function(resolve) {
var xhr, apiKey;
xhr = new XMLHttpRequest();
xhr.onload = function() {
resolve(this.response);
};
xhr.open('GET', url, true);
apiKey = getApiKey();
if (apiKey) {
xhr.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
xhr.setRequestHeader('tiny-api-key', apiKey);
}
xhr.responseType = 'blob';
xhr.send();
});
}
function imageToBlob(img) {
var src = img.src;
if (isCorsImage(img)) {
return requestUrlAsBlob(img.src);
}
if (!isLocalImage(img)) {
src = editor.settings.imagetools_proxy;
src += (src.indexOf('?') === -1 ? '?' : '&') + 'url=' + encodeURIComponent(img.src);
if (getApiKey()) {
return requestUrlAsBlob(src);
}
img = new Image();
img.src = src;
}
return BlobConversions.imageToBlob(img);
}
function findSelectedBlobInfo() {
var blobInfo;
blobInfo = editor.editorUpload.blobCache.getByUri(getSelectedImage().src);
if (blobInfo) {
return blobInfo;
}
return imageToBlob(getSelectedImage()).then(function(blob) {
return BlobConversions.blobToBase64(blob).then(function(base64) {
var blobCache = editor.editorUpload.blobCache;
var blobInfo = blobCache.create(createId(), blob, base64);
blobCache.add(blobInfo);
return blobInfo;
});
});
}
function startTimedUpload() {
imageUploadTimer = Delay.setEditorTimeout(editor, function() {
editor.editorUpload.uploadImagesAuto();
}, 30000);
}
function cancelTimedUpload() {
clearTimeout(imageUploadTimer);
}
function updateSelectedImage(blob, uploadImmediately) {
return BlobConversions.blobToDataUri(blob).then(function(dataUri) {
var id, base64, blobCache, blobInfo, selectedImage;
selectedImage = getSelectedImage();
id = createId();
blobCache = editor.editorUpload.blobCache;
base64 = URI.parseDataUri(dataUri).data;
blobInfo = blobCache.create(id, blob, base64);
blobCache.add(blobInfo);
editor.undoManager.transact(function() {
function imageLoadedHandler() {
editor.$(selectedImage).off('load', imageLoadedHandler);
editor.nodeChanged();
if (uploadImmediately) {
editor.editorUpload.uploadImagesAuto();
} else {
cancelTimedUpload();
startTimedUpload();
}
}
editor.$(selectedImage).on('load', imageLoadedHandler);
editor.$(selectedImage).attr({
src: blobInfo.blobUri()
}).removeAttr('data-mce-src');
});
return blobInfo;
});
}
function selectedImageOperation(fn) {
return function() {
return editor._scanForImages().then(findSelectedBlobInfo).then(fn).then(updateSelectedImage);
};
}
function rotate(angle) {
return function() {
return selectedImageOperation(function(blobInfo) {
var size = getImageSize(getSelectedImage());
if (size) {
setImageSize(getSelectedImage(), {
w: size.h,
h: size.w
});
}
return ImageTransformations.rotate(blobInfo.blob(), angle);
})();
};
}
function flip(axis) {
return function() {
return selectedImageOperation(function(blobInfo) {
return ImageTransformations.flip(blobInfo.blob(), axis);
})();
};
}
function editImageDialog() {
var img = getSelectedImage(), originalSize = getNaturalImageSize(img);
if (img) {
imageToBlob(img).then(Dialog.edit).then(function(blob) {
return new Promise(function(resolve) {
BlobConversions.blobToImage(blob).then(function(newImage) {
var newSize = getNaturalImageSize(newImage);
if (originalSize.w != newSize.w || originalSize.h != newSize.h) {
if (getImageSize(img)) {
setImageSize(img, newSize);
}
}
URL.revokeObjectURL(newImage.src);
resolve(blob);
});
});
}).then(function(blob) {
updateSelectedImage(blob, true);
}, function() {
// Close dialog
});
}
}
function addButtons() {
editor.addButton('rotateleft', {
title: 'Rotate counterclockwise',
onclick: rotate(-90)
});
editor.addButton('rotateright', {
title: 'Rotate clockwise',
onclick: rotate(90)
});
editor.addButton('flipv', {
title: 'Flip vertically',
onclick: flip('v')
});
editor.addButton('fliph', {
title: 'Flip horizontally',
onclick: flip('h')
});
editor.addButton('editimage', {
title: 'Edit image',
onclick: editImageDialog
});
editor.addButton('imageoptions', {
title: 'Image options',
icon: 'options',
cmd: 'mceImage'
});
/*
editor.addButton('crop', {
title: 'Crop',
onclick: startCrop
});
*/
}
function addEvents() {
editor.on('NodeChange', function(e) {
//If the last node we selected was an image
//And had a source that doesn't match the current blob url
//We need to attempt to upload it
if (lastSelectedImage && lastSelectedImage.src != e.element.src) {
cancelTimedUpload();
editor.editorUpload.uploadImagesAuto();
lastSelectedImage = undefined;
}
//Set up the lastSelectedImage
if (isEditableImage(e.element)) {
lastSelectedImage = e.element;
}
});
}
function isEditableImage(img) {
var selectorMatched = editor.dom.is(img, 'img:not([data-mce-object],[data-mce-placeholder])');
return selectorMatched && (isLocalImage(img) || isCorsImage(img) || editor.settings.imagetools_proxy);
}
function addToolbars() {
var toolbarItems = editor.settings.imagetools_toolbar;
if (!toolbarItems) {
toolbarItems = 'rotateleft rotateright | flipv fliph | crop editimage imageoptions';
}
editor.addContextToolbar(
isEditableImage,
toolbarItems
);
}
addButtons();
addToolbars();
addEvents();
editor.addCommand('mceEditImage', editImageDialog);
};
PluginManager.add('imagetools', plugin);
return function() {};
});

View File

@@ -0,0 +1,57 @@
/**
* UndoStack.js
*
* Released under LGPL License.
* Copyright (c) 1999-2016 Ephox Corp. All rights reserved
*
* License: http://www.tinymce.com/license
* Contributing: http://www.tinymce.com/contributing
*/
define("tinymce/imagetoolsplugin/UndoStack", [
], function() {
return function() {
var data = [], index = -1;
function add(state) {
var removed;
removed = data.splice(++index);
data.push(state);
return {
state: state,
removed: removed
};
}
function undo() {
if (canUndo()) {
return data[--index];
}
}
function redo() {
if (canRedo()) {
return data[++index];
}
}
function canUndo() {
return index > 0;
}
function canRedo() {
return index != -1 && index < data.length - 1;
}
return {
data: data,
add: add,
undo: undo,
redo: redo,
canUndo: canUndo,
canRedo: canRedo
};
};
});