initial commit taken from gitlab.lrz.de

This commit is contained in:
privatereese
2018-08-24 18:09:42 +02:00
parent ae54ed4c48
commit fc05486403
28494 changed files with 2159823 additions and 0 deletions

21
node_modules/art/modes/canvas/_image.js generated vendored Normal file
View File

@@ -0,0 +1,21 @@
var Class = require('../../core/class');
var Base = require('./base');
module.exports = Class(Base, {
base_initialize: Base.prototype.initialize,
initialize: function(src, width, height){
this.base_initialize();
if (arguments.length == 3) this.draw.apply(this, arguments);
},
draw: function(src, width, height){
this.width = width;
this.height = height;
return this.invalidate();
},
renderTo: function(){ }
});

186
node_modules/art/modes/canvas/base.js generated vendored Normal file
View File

@@ -0,0 +1,186 @@
var Class = require('../../core/class');
var Color = require('../../core/color');
var Transform = require('../../core/transform');
var Node = require('./node');
var genericCanvas = typeof document !== 'undefined' && document.createElement('canvas'),
genericContext = genericCanvas && genericCanvas.getContext && genericCanvas.getContext('2d');
function recolorImage(img, color1, color2){
// TODO: Fix this experimental implementation
color1 = Color.detach(color1);
color2 = Color.detach(color2);
var canvas = document.createElement('canvas'),
context = canvas.getContext('2d');
canvas.width = img.width;
canvas.height = img.height;
context.fillStyle = color2[0];
context.fillRect(0, 0, img.width, img.height);
context.globalCompositeOperation = 'lighter';
context.drawImage(img, 0, 0);
return canvas;
}
var Base = Class(Node, {
initialize: function(){
this._fill = null;
this._pendingFill = null;
this._fillTransform = null;
this._stroke = null;
this._strokeCap = null;
this._strokeDash = null;
this._strokeJoin = null;
this._strokeWidth = null;
},
/* styles */
_addColors: function(gradient, stops){
// Enumerate stops, assumes offsets are enumerated in order
// TODO: Sort. Chrome doesn't always enumerate in expected order but requires stops to be specified in order.
if ('length' in stops) for (var i = 0, l = stops.length - 1; i <= l; i++)
gradient.addColorStop(i / l, new Color(stops[i]).toString());
else for (var offset in stops)
gradient.addColorStop(offset, new Color(stops[offset]).toString());
return gradient;
},
fill: function(color){
if (arguments.length > 1) return this.fillLinear(arguments);
if (this._pendingFill) this._pendingFill();
this._fill = color ? new Color(color).toString() : null;
return this.invalidate();
},
fillRadial: function(stops, focusX, focusY, radiusX, radiusY, centerX, centerY){
if (focusX == null) focusX = (this.left || 0) + (this.width || 0) * 0.5;
if (focusY == null) focusY = (this.top || 0) + (this.height || 0) * 0.5;
if (radiusY == null) radiusY = radiusX || (this.height * 0.5) || 0;
if (radiusX == null) radiusX = (this.width || 0) * 0.5;
if (centerX == null) centerX = focusX;
if (centerY == null) centerY = focusY;
centerX += centerX - focusX;
centerY += centerY - focusY;
if (radiusX === 0 || radiusX === '0') return this.fillLinear(stops);
var ys = radiusY / radiusX;
if (this._pendingFill) this._pendingFill();
var gradient = genericContext.createRadialGradient(focusX, focusY / ys, 0, centerX, centerY / ys, radiusX * 2);
// Double fill radius to simulate repeating gradient
if ('length' in stops) for (var i = 0, l = stops.length - 1; i <= l; i++){
gradient.addColorStop(i / l / 2, new Color(stops[i]).toString());
gradient.addColorStop(1 - i / l / 2, new Color(stops[i]).toString());
} else for (var offset in stops){
gradient.addColorStop(offset / 2, new Color(stops[offset]).toString());
gradient.addColorStop(1- offset / 2, new Color(stops[offset]).toString());
}
this._fill = gradient;
this._fillTransform = new Transform(1, 0, 0, ys);
return this.invalidate();
},
fillLinear: function(stops, x1, y1, x2, y2){
if (arguments.length < 5){
var angle = ((x1 == null) ? 270 : x1) * Math.PI / 180;
var x = Math.cos(angle), y = -Math.sin(angle),
l = (Math.abs(x) + Math.abs(y)) / 2,
w = this.width || 1, h = this.height || 1;
x *= l; y *= l;
x1 = 0.5 - x;
x2 = 0.5 + x;
y1 = 0.5 - y;
y2 = 0.5 + y;
this._fillTransform = new Transform(w, 0, 0, h);
} else {
this._fillTransform = null;
}
if (this._pendingFill) this._pendingFill();
var gradient = genericContext.createLinearGradient(x1, y1, x2, y2);
this._addColors(gradient, stops);
this._fill = gradient;
return this.invalidate();
},
fillImage: function(url, width, height, left, top, color1, color2){
if (this._pendingFill) this._pendingFill();
var img = url;
if (!(img instanceof Image)){
img = new Image();
img.src = url;
}
if (img.width && img.height){
return this._fillImage(img, width, height, left || 0, top || 0, color1, color2);
}
// Not yet loaded
this._fill = null;
var self = this,
callback = function(){
cancel();
self._fillImage(img, width, height, left || 0, top || 0, color1, color2);
},
cancel = function(){
img.removeEventListener('load', callback, false);
self._pendingFill = null;
};
this._pendingFill = cancel;
img.addEventListener('load', callback, false);
return this;
},
_fillImage: function(img, width, height, left, top, color1, color2){
var w = width ? width / img.width : 1,
h = height ? height / img.height : 1;
if (color1 != null) img = recolorImage(img, color1, color2);
this._fill = genericContext.createPattern(img, 'repeat');
this._fillTransform = new Transform(w, 0, 0, h, left || 0, top || 0);
return this.invalidate();
},
stroke: function(color, width, cap, join, dash){
this._stroke = color ? new Color(color).toString() : null;
this._strokeWidth = (width != null) ? width : 1;
this._strokeCap = (cap != null) ? cap : 'round';
this._strokeJoin = (join != null) ? join : 'round';
this._strokeDash = dash;
return this.invalidate();
},
// Rendering
element_renderTo: Node.prototype.renderTo,
renderTo: function(context, xx, yx, xy, yy, x, y){
var opacity = this._opacity;
if (opacity == null || opacity >= 1){
return this.renderLayerTo(context, xx, yx, xy, yy, x, y);
}
if (this._fill && this._stroke){
return this.element_renderTo(context, xx, yx, xy, yy, x, y);
}
context.globalAlpha = opacity;
var r = this.renderLayerTo(context, xx, yx, xy, yy, x, y);
context.globalAlpha = 1;
return r;
},
renderLayerTo: function(context, xx, yx, xy, yy, x, y){
context.setTransform(xx, yx, xy, yy, x, y);
this.renderShapeTo(context);
}
});
Base._genericContext = genericContext;
module.exports = Base;

37
node_modules/art/modes/canvas/clippingrectangle.js generated vendored Normal file
View File

@@ -0,0 +1,37 @@
var Class = require('../../core/class');
var Container = require('../../dom/container');
var Node = require('./node');
module.exports = Class(Node, Container, {
initialize: function(width, height){
this.width = width;
this.height = height;
},
localHitTest: function(x, y) {
var node = this.lastChild;
while (node){
var hit = node.hitTest(x, y);
if (hit) return hit;
node = node.previousSibling;
}
return null;
},
renderLayerTo: function(context, xx, yx, xy, yy, x, y) {
context.setTransform(xx, yx, xy, yy, x, y);
context.save();
// Need beginPath to fix Firefox bug. See 3354054.
context.beginPath();
context.rect(this.x, this.y, this.width, this.height);
context.clip();
var node = this.firstChild;
while(node) {
node.renderTo(context, xx, yx, xy, yy, x, y);
node = node.nextSibling;
}
context.restore();
}
});

42
node_modules/art/modes/canvas/group.js generated vendored Normal file
View File

@@ -0,0 +1,42 @@
var Class = require('../../core/class');
var Container = require('../../dom/container');
var Node = require('./node');
module.exports = Class(Node, Container, {
initialize: function(width, height){
this.width = width;
this.height = height;
},
localHitTest: function(x, y){
var node = this.lastChild;
while (node){
var hit = node.hitTest(x, y);
if (hit) return hit;
node = node.previousSibling;
}
return null;
},
renderLayerTo: function(context, xx, yx, xy, yy, x, y){
if (this._invisible) return;
x = xx * this.x + xy * this.y + x;
y = yx * this.x + yy * this.y + y;
var t = xx;
xx = t * this.xx + xy * this.yx;
xy = t * this.xy + xy * this.yy;
t = yx;
yx = t * this.xx + yy * this.yx;
yy = t * this.xy + yy * this.yy;
var node = this.firstChild;
while (node){
node.renderTo(context, xx, yx, xy, yy, x, y);
node = node.nextSibling;
}
}
});

115
node_modules/art/modes/canvas/node.js generated vendored Normal file
View File

@@ -0,0 +1,115 @@
var Class = require('../../core/class');
var Transform = require('../../core/transform');
var Element = require('../../dom/dummy');
var CanvasNode = Class(Transform, Element, {
invalidate: function(){
if (this.parentNode) this.parentNode.invalidate();
if (this._layer) this._layerCache = null;
return this;
},
_place: function(){
this.invalidate();
},
_transform: function(){
this.invalidate();
},
blend: function(opacity){
if (opacity >= 1 && this._layer) this._layer = null;
this._opacity = opacity;
if (this.parentNode) this.parentNode.invalidate();
return this;
},
// visibility
hide: function(){
this._invisible = true;
if (this.parentNode) this.parentNode.invalidate();
return this;
},
show: function(){
this._invisible = false;
if (this.parentNode) this.parentNode.invalidate();
return this;
},
// interaction
indicate: function(cursor, tooltip){
this._cursor = cursor;
this._tooltip = tooltip;
return this.invalidate();
},
hitTest: function(x, y){
if (this._invisible) return null;
var point = this.inversePoint(x, y);
if (!point) return null;
return this.localHitTest(point.x, point.y);
},
// rendering
renderTo: function(context, xx, yx, xy, yy, x, y){
var opacity = this._opacity;
if (opacity == null || opacity >= 1){
return this.renderLayerTo(context, xx, yx, xy, yy, x, y);
}
// Render to a compositing layer and cache it
var layer = this._layer, canvas, isDirty = true,
w = context.canvas.width, h = context.canvas.height;
if (layer){
layer.setTransform(1, 0, 0, 1, 0, 0);
canvas = layer.canvas;
if (canvas.width < w || canvas.height < h){
canvas.width = w;
canvas.height = h;
} else {
var c = this._layerCache;
if (c && c.xx === xx && c.yx === yx && c.xy === xy
&& c.yy === yy && c.x === x && c.y === y){
isDirty = false;
} else {
layer.clearRect(0, 0, w, h);
}
}
} else {
canvas = document.createElement('canvas');
canvas.width = w;
canvas.height = h;
this._layer = layer = canvas.getContext('2d');
}
if (isDirty){
this.renderLayerTo(layer, xx, yx, xy, yy, x, y);
this._layerCache = {
xx: xx,
yx: yx,
xy: xy,
yy: yy,
x: x,
y: y
};
}
context.globalAlpha = opacity;
context.setTransform(1, 0, 0, 1, 0, 0);
context.drawImage(
canvas,
0, 0, w, h,
0, 0, w, h
);
context.globalAlpha = 1;
}
});
module.exports = CanvasNode;

61
node_modules/art/modes/canvas/path.js generated vendored Normal file
View File

@@ -0,0 +1,61 @@
var Class = require('../../core/class');
var Path = require('../../core/path');
var CanvasPath = Class(Path, {
initialize: function(path){
this.reset();
if (path instanceof CanvasPath){
this.path = path.path.slice(0);
} else if (path){
if (path.applyToPath)
path.applyToPath(this);
else
this.push(path);
}
},
onReset: function(){
this.path = [];
},
onMove: function(sx, sy, x, y){
this.path.push(function(context){
context.moveTo(x, y);
});
},
onLine: function(sx, sy, x, y){
this.path.push(function(context){
context.lineTo(x, y);
});
},
onBezierCurve: function(sx, sy, p1x, p1y, p2x, p2y, x, y){
this.path.push(function(context){
context.bezierCurveTo(p1x, p1y, p2x, p2y, x, y);
});
},
_arcToBezier: Path.prototype.onArc,
onArc: function(sx, sy, ex, ey, cx, cy, rx, ry, sa, ea, ccw, rotation){
if (rx != ry || rotation) return this._arcToBezier(sx, sy, ex, ey, cx, cy, rx, ry, sa, ea, ccw, rotation);
this.path.push(function(context){
context.arc(cx, cy, rx, sa, ea, ccw);
});
},
onClose: function(){
this.path.push(function(context){
context.closePath();
});
},
toCommands: function(){
return this.path.slice(0);
}
});
module.exports = CanvasPath;

94
node_modules/art/modes/canvas/shape.js generated vendored Normal file
View File

@@ -0,0 +1,94 @@
var Class = require('../../core/class');
var Base = require('./base');
var Path = require('./path');
module.exports = Class(Base, {
base_initialize: Base.prototype.initialize,
initialize: function(path, width, height){
this.base_initialize();
this.width = width;
this.height = height;
if (path != null) this.draw(path);
},
draw: function(path, width, height){
if (!(path instanceof Path)) path = new Path(path);
this.path = path;
this._commands = path.toCommands();
if (width != null) this.width = width;
if (height != null) this.height = height;
return this.invalidate();
},
localHitTest: function(x, y){
if (!this._fill) return null;
if (this.width == null || this.height == null){
var context = Base._genericContext, commands = this._commands;
if (!commands) return null;
context.beginPath();
for (var i = 0, l = commands.length; i < l; i++)
commands[i](context);
return context.isPointInPath(x, y) ? this : null;
}
if (x > 0 && y > 0 && x < this.width && y < this.height){
return this;
}
return null;
},
renderShapeTo: function(context){
if (this._invisible || !this._commands || (!this._fill && !this._stroke)) {
return null;
}
context.transform(this.xx, this.yx, this.xy, this.yy, this.x, this.y);
var commands = this._commands,
fill = this._fill,
stroke = this._stroke,
dash = this._strokeDash;
context.beginPath();
if (dash) {
if (context.setLineDash) {
context.setLineDash(dash);
} else {
// TODO: Remove when FF supports setLineDash.
context.mozDash = dash;
}
// TODO: Create fallback to other browsers.
} else {
if (context.setLineDash) {
context.setLineDash([]);
} else {
context.mozDash = null;
}
}
for (var i = 0, l = commands.length; i < l; i++)
commands[i](context);
if (fill){
var m = this._fillTransform;
if (m){
context.save(); // TODO: Optimize away this by restoring the transform before stroking
context.transform(m.xx, m.yx, m.xy, m.yy, m.x, m.y);
context.fillStyle = fill;
context.fill();
context.restore();
} else {
context.fillStyle = fill;
context.fill();
}
}
if (stroke){
context.strokeStyle = stroke;
context.lineWidth = this._strokeWidth;
context.lineCap = this._strokeCap;
context.lineJoin = this._strokeJoin;
context.stroke();
}
}
});

142
node_modules/art/modes/canvas/surface.js generated vendored Normal file
View File

@@ -0,0 +1,142 @@
var Class = require('../../core/class');
var Container = require('../../dom/container');
var Element = require('../../dom/native');
var fps = 1000 / 60, invalids = [], renderTimer, renderInvalids = function(){
clearTimeout(renderTimer);
renderTimer = null;
var canvases = invalids;
invalids = [];
for (var i = 0, l = canvases.length; i < l; i++){
var c = canvases[i];
c._valid = true;
c.render();
}
};
var resolution = typeof window !== 'undefined' && window.devicePixelRatio || 1;
var previousHit = null, previousHitSurface = null;
var CanvasSurface = Class(Element, Container, {
initialize: function(width, height, existingElement){
var element = this.element = existingElement || document.createElement('canvas');
var context = this.context = element.getContext('2d');
this._valid = true;
if (width != null && height != null) this.resize(width, height);
element.addEventListener('mousemove', this, false);
element.addEventListener('mouseout', this, false);
element.addEventListener('mouseover', this, false);
element.addEventListener('mouseup', this, false);
element.addEventListener('mousedown', this, false);
element.addEventListener('click', this, false);
},
handleEvent: function(event){
if (event.clientX == null) return;
var element = this.element,
rect = element.getBoundingClientRect(),
x = event.clientX - rect.left - element.clientLeft,
y = event.clientY - rect.top - element.clientTop,
hit = this.hitTest(x, y);
if (hit !== previousHit){
if (previousHit){
previousHit.dispatch({
type: 'mouseout',
target: previousHit,
relatedTarget: hit,
sourceEvent: event
});
}
if (hit){
hit.dispatch({
type: 'mouseover',
target: hit,
relatedTarget: previousHit,
sourceEvent: event
});
}
previousHit = hit;
previousHitSurface = this;
this.refreshCursor();
}
if (hit) hit.dispatch(event);
},
refreshCursor: function(){
if (previousHitSurface !== this) return;
var hit = previousHit, hitCursor = '', hitTooltip = '';
while (hit){
if (!hitCursor && hit._cursor){
hitCursor = hit._cursor;
if (hitTooltip) break;
}
if (!hitTooltip && hit._tooltip){
hitTooltip = hit._tooltip;
if (hitCursor) break;
}
hit = hit.parentNode;
}
// TODO: No way to set cursor/title on the surface
this.element.style.cursor = hitCursor;
this.element.title = hitTooltip;
},
resize: function(width, height){
var element = this.element;
element.setAttribute('width', width * resolution);
element.setAttribute('height', height * resolution);
element.style.width = width + 'px';
element.style.height = height + 'px';
this.width = width;
this.height = height;
return this;
},
invalidate: function(left, top, width, height){
if (this._valid){
this._valid = false;
invalids.push(this);
if (!renderTimer){
if (window.mozRequestAnimationFrame){
renderTimer = true;
window.mozRequestAnimationFrame(renderInvalids);
} else {
renderTimer = setTimeout(renderInvalids, fps);
}
}
}
return this;
},
hitTest: function(x, y){
if (x < 0 || y < 0 || x > this.width || y > this.height) return null;
var node = this.lastChild;
while (node){
var hit = node.hitTest(x, y);
if (hit) return hit;
node = node.previousSibling;
}
return null;
},
render: function(){
var node = this.firstChild, context = this.context;
context.setTransform(resolution, 0, 0, resolution, 0, 0);
context.clearRect(0, 0, this.width, this.height);
while (node){
node.renderTo(context, resolution, 0, 0, resolution, 0, 0);
node = node.nextSibling;
}
this.refreshCursor();
}
});
CanvasSurface.tagName = 'canvas';
module.exports = CanvasSurface;

116
node_modules/art/modes/canvas/text.js generated vendored Normal file
View File

@@ -0,0 +1,116 @@
var Class = require('../../core/class');
var Base = require('./base');
var fontAnchors = { middle: 'center' };
module.exports = Class(Base, {
base_initialize: Base.prototype.initialize,
initialize: function(text, font, alignment, path){
this.base_initialize();
this.draw.apply(this, arguments);
},
draw: function(text, font, alignment, path){
var em;
if (typeof font == 'string'){
em = Number(/(\d+)/.exec(font)[0]);
} else if (font){
em = parseFloat(font.fontSize || font['font-size'] || '12');
font = (font.fontStyle || font['font-style'] || '') + ' ' +
(font.fontVariant || font['font-variant'] || '') + ' ' +
(font.fontWeight || font['font-weight'] || '') + ' ' +
em + 'px ' +
(font.fontFamily || font['font-family'] || 'Arial');
} else {
font = this._font;
}
var lines = text && text.split(/\r?\n/);
this._font = font;
this._fontSize = em;
this._text = lines;
this._alignment = fontAnchors[alignment] || alignment || 'left';
var context = Base._genericContext;
context.font = this._font;
context.textAlign = this._alignment;
context.textBaseline = 'middle';
lines = this._text;
var l = lines.length, width = 0;
for (var i = 0; i < l; i++){
var w = context.measureText(lines[i]).width;
if (w > width) width = w;
}
this.width = width;
this.height = l ? l * 1.1 * em : 0;
return this.invalidate();
},
// Interaction
localHitTest: function(x, y){
if (!this._fill) return null;
if (x > 0 && y > 0 && x < this.width && y < this.height){
return this;
}
return null;
},
// Rendering
renderShapeTo: function(context){
if (this._invisible || !this._text || (!this._fill && !this._stroke)) {
return null;
}
context.transform(this.xx, this.yx, this.xy, this.yy, this.x, this.y);
var fill = this._fill,
stroke = this._stroke,
text = this._text,
dash = this._strokeDash;
context.font = this._font;
context.textAlign = this._alignment;
context.textBaseline = 'middle';
var em = this._fontSize,
y = em / 2,
lineHeight = 1.1 * em,
lines = text,
l = lines.length;
if (fill){
context.fillStyle = fill;
for (var i = 0; i < l; i++)
context.fillText(lines[i], 0, y + i * lineHeight);
}
if (stroke){
if (dash) {
if (context.setLineDash) {
context.setLineDash(dash);
} else {
// TODO: Remove when FF supports setLineDash.
context.mozDash = dash;
}
// TODO: Create fallback to other browsers.
} else {
if (context.setLineDash) {
context.setLineDash([]);
} else {
context.mozDash = null;
}
}
context.strokeStyle = stroke;
context.lineWidth = this._strokeWidth;
context.lineCap = this._strokeCap;
context.lineJoin = this._strokeJoin;
for (i = 0; i < l; i++)
context.strokeText(lines[i], 0, y + i * lineHeight);
}
}
});