var _createClass=function(){function defineProperties(target,props){for(var i=0;i1?radius[1]:radius[0],self.borderBox.height)];});this.cssFloat=computedStyle.cssFloat;}Metrics.prototype.unitToPx=function(unit){if(this.units[unit])return this.units[unit];var cached=this.element.style.getPropertyValue('line-height');this.element.style.setProperty('line-height',1+unit);this.units[unit]=parseFloat(getComputedStyle(this.element).getPropertyValue('line-height'));this.element.style.setProperty('line-height',cached);return this.units[unit];};Metrics.prototype.getUnitsMap=function(element){var units=['em','ex','ch','rem','vw','vh','vmin','vmax','cm','mm','in','px','pt','pc'];var child=document.createElement('div');child.style.width='0px';child.style.height='0px';element.appendChild(child);var style=getComputedStyle(child);var result={};units.forEach(function(unit){child.style.lineHeight='1'+unit; // computed height is in px result[unit]=parseFloat(style.lineHeight);});child.parentNode.removeChild(child);return result;};Metrics.prototype.toPixels=function(length,percentageBase){var split=/([\-0-9\.]*)([a-z%]*)/.exec(length);split[1]=parseFloat(split[1]);if(!split[2])return split[1];if(split[2]==='%')return split[1]*percentageBase/100;return split[1]*this.unitToPx(split[2]);}; /* Returns > 0 if the slope of the line through origin and endPoint2 is greater than the slope through * origin and endPoint1. Returns 0 if they have the same slope, negative otherwise. */function compareLineSlopes(origin,endPoint1,endPoint2){return (endPoint2.x-origin.x)*(endPoint1.y-origin.y)-(endPoint1.x-origin.x)*(endPoint2.y-origin.y);}function areCollinearPoints(p0,p1,p2){return Math.abs(compareLineSlopes(p0,p1,p2))<350; // FIXME: threshold is a hack and it's wrong }function areCoincidentPoints(p0,p1){return p0.x==p1.x&&p0.y==p1.y;}function isPointOnLineSegment(lineStartPoint,lineEndPoint,point){return point.x>=Math.min(lineStartPoint.x,lineEndPoint.x)&&point.x<=Math.max(lineStartPoint.x,lineEndPoint.x)&&areCollinearPoints(lineStartPoint,lineEndPoint,point);} /* Parent class for different edge types, child classes will need to call init * to initialize the appropriate member variables */function PolygonEdge(){}PolygonEdge.prototype.init=function(polygon,vertex1,vertex2){this.polygon=polygon;this.vertex1=vertex1;this.vertex2=vertex2;this.minX=Math.min(this.vertex1.x,this.vertex2.x);this.maxX=Math.max(this.vertex1.x,this.vertex2.x);};PolygonEdge.prototype.containsPoint=function(point){return isPointOnLineSegment(this.vertex1,this.vertex2,point);};PolygonEdge.prototype.overlapsYRange=function(y1,y2){ // y range: y1 <= y <= y2 var edgeY1=this.vertex1.y;var edgeY2=this.vertex2.y;return y2>=Math.min(edgeY1,edgeY2)&&y1<=Math.max(edgeY1,edgeY2);};PolygonEdge.prototype.isWithinYRange=function(y1,y2){ // y range: y1 <= y <= y2 var edgeY1=this.vertex1.y;var edgeY2=this.vertex2.y;return y1<=Math.min(edgeY1,edgeY2)&&y2>=Math.max(edgeY1,edgeY2);};PolygonEdge.prototype.inwardNormal=function(){ // "inward" - assuming that polygon's vertices are in clockwise order var dx=this.vertex2.x-this.vertex1.x;var dy=this.vertex2.y-this.vertex1.y;var edgeLength=Math.sqrt(dx*dx+dy*dy);return {x:-dy/edgeLength,y:dx/edgeLength};};PolygonEdge.prototype.outwardNormal=function(){var n=this.inwardNormal();return {x:-n.x,y:-n.y};};PolygonEdge.prototype.xIntercept=function(y){var vertex1Y=this.vertex1.y;var vertex2Y=this.vertex2.y;if(vertex1Y==vertex2Y)return Math.min(this.vertex1.x,this.vertex2.x);if(y==Math.min(vertex1Y,vertex2Y))return vertex1Yvertex2Y?this.vertex1.x:this.vertex2.x;return this.vertex1.x+(y-vertex1Y)*(this.vertex2.x-this.vertex1.x)/(vertex2Y-vertex1Y);}; /* Clip the edge line segment to the vertical range y1,y2 and then return * the clipped line segment's horizontal range as {x1, x2}, where x2 >= x1; * This method assumes that this edge overlaps y1,y2. */PolygonEdge.prototype.clippedEdgeXRange=function(y1,y2){if(this.isWithinYRange(y1,y2)){var vertex1X=this.vertex1.x;var vertex2X=this.vertex2.x;return {x1:Math.min(vertex1X,vertex2X),x2:Math.max(vertex1X,vertex2X)};}var minYVertex,maxYVertex;if(this.vertex1.yy2?this.xIntercept(y2):maxYVertex.x;return {x1:Math.min(xForY1,xForY2),x2:Math.max(xForY1,xForY2)};}; /* Clip the circle to the vertical range y1,y2 and return the extent of the clipped circle's * projection on the X axis as {x1, x2}, where x2 >= x1. This method assumes that the circle * overlaps y1, y2. */function clippedCircleXRange(center,radius,y1,y2){if(center.y>=y1&¢er.y<=y2)return {x1:center.x-radius,x2:center.x+radius};var yi,xi;if(y20?vertices[0].x:undefined;var minY=vertices.length>0?vertices[0].y:undefined;var maxX=minX;var maxY=minY;var clockwise=isVertexOrderClockwise(vertices);var vertex1Index=0;do {var vertex2Index=this.nextEdgeVertexIndex(vertex1Index,clockwise);edges.push(new ShapeEdge(this,vertices[vertex1Index],vertices[vertex2Index]));var x=vertices[vertex1Index].x;var y=vertices[vertex1Index].y;minX=Math.min(x,minX);minY=Math.min(y,minY);maxX=Math.max(x,maxX);maxY=Math.max(y,maxY);vertex1Index=vertex2Index;}while(vertex1Index!==0); // Where possible, combine 2 edges into 1 var edgeIndex=0,nextEdgeIndex;while(edgeIndex3){nextEdgeIndex=(edgeIndex+1)%edges.length;if(areCollinearPoints(edges[edgeIndex].vertex1,edges[edgeIndex].vertex2,edges[nextEdgeIndex].vertex2)){edges[edgeIndex].vertex2=edges[nextEdgeIndex].vertex2;edges.splice(nextEdgeIndex,1);}else edgeIndex++;}if(shapeMargin===0){this.shapeMarginEdges=edges;}else {var shapeMarginEdges=[];for(var i=0;i=this.bounds.y;};Polygon.prototype.nextVertexIndex=function(vertexIndex,clockwise){var nVertices=this.m_vertices.length;return (clockwise?vertexIndex+1:vertexIndex-1+nVertices)%nVertices;};Polygon.prototype.nextEdgeVertexIndex=function(vertex1Index,clockwise){var nVertices=this.m_vertices.length;var vertex2Index=this.nextVertexIndex(vertex1Index,clockwise);while(vertex2Index&&areCoincidentPoints(this.vertexAt(vertex1Index),this.vertexAt(vertex2Index))){vertex2Index=this.nextVertexIndex(vertex2Index,clockwise);}while(vertex2Index){var vertexIndex3=this.nextVertexIndex(vertex2Index,clockwise);if(!areCollinearPoints(this.vertexAt(vertex1Index),this.vertexAt(vertex2Index),this.vertexAt(vertexIndex3)))break;vertex2Index=vertexIndex3;}return vertex2Index;};Polygon.prototype.containsPointEvenOdd=function(point){var crossingCount=0;for(var i=0;ipoint.y||vertex1.y>point.y&&vertex2.y<=point.y){var vt=(point.y-vertex1.y)/(vertex2.y-vertex1.y);if(point.xpoint.y&&compareLineSlopes(vertex1,vertex2,point)>0)++windingNumber;}else if(vertex2.y>point.y){if(vertex1.y<=point.y&&compareLineSlopes(vertex1,vertex2,point)<0)--windingNumber;}}return windingNumber!==0;};Polygon.prototype.containsPoint=function(point){if(!this.bounds.containsPoint(point))return false;return this.fillRule=="nonzero"?this.containsPointNonZero(point):this.containsPointEvenOdd(point);};Polygon.prototype.edgeVerticesThatOverlapYRange=function(y1,y2){var result=[];for(var i=0;i=y1&&vertex.y= y1 if(this.isEmpty()||!this.bounds.overlapsYRange(y1,y2))return undefined;var result,i,xRange;var overlappingEdges=this.shapeMarginEdgesThatOverlapYRange(y1,y2);if(overlappingEdges.length!==0){overlappingEdges.sort(compareEdgeMinX);result=overlappingEdges[0].clippedEdgeXRange(y1,y2).x1;for(i=1;iresult)break;xRange=overlappingEdges[i].clippedEdgeXRange(y1,y2);result=result===undefined?xRange.x1:Math.min(result,xRange.x1);}}var shapeMargin=this.shapeMargin;if(shapeMargin>0){var overlappingVertices=this.edgeVerticesThatOverlapYRange(y1-shapeMargin,y2+shapeMargin);overlappingVertices.sort(compareVertexXIncreasing);for(i=0;i= y1 if(this.isEmpty()||!this.bounds.overlapsYRange(y1,y2))return undefined;var result,i,xRange;var overlappingEdges=this.shapeMarginEdgesThatOverlapYRange(y1,y2);if(overlappingEdges.length!==0){overlappingEdges.sort(compareEdgeMaxX);result=overlappingEdges[0].clippedEdgeXRange(y1,y2).x2;for(i=1;i0){var overlappingVertices=this.edgeVerticesThatOverlapYRange(y1-shapeMargin,y2+shapeMargin);overlappingVertices.sort(compareVertexXDecreasing);for(i=0;i=interval.endX;};function ShapeMarginIntervalGenerator(shapeMargin){this.shapeMargin=shapeMargin;this.xIntercepts=[];for(var y=0;y<=shapeMargin;y++){this.xIntercepts[y]=Math.sqrt(shapeMargin*shapeMargin-y*y);}}ShapeMarginIntervalGenerator.prototype.generateIntervalAt=function(atY,forInterval){var xInterceptsIndex=Math.abs(atY-forInterval.y);var dx=xInterceptsIndex>this.shapeMargin?0:this.xIntercepts[xInterceptsIndex];return new RasterInterval(atY,forInterval.startX-dx,forInterval.endX+dx);};RasterIntervals.prototype.computeMarginIntervals=function(shapeMargin,clip){var mig=new ShapeMarginIntervalGenerator(shapeMargin);var result=new RasterIntervals(this.yOffset,this.size);for(var y=this.minY;y=marginY0;--marginY){if(marginY>0&&this.intervalAtContains(marginY,intervalAtY))break;result.uniteIntervalAt(marginY,mig.generateIntervalAt(marginY,intervalAtY));}result.uniteIntervalAt(y,mig.generateIntervalAt(y,intervalAtY));for(marginY=y+1;marginY<=marginY1;++marginY){if(marginY0)raster.intervals=raster.intervals.computeMarginIntervals(raster.shapeMargin,raster.clip);}if(blob)URL.revokeObjectURL(blob);callback();};image.onerror=function(){error(raster.url); /* raster.intervals is undefined */callback();}; /* Try this approach for browsers that don't support * CORS-enabled images (ie IE). Ideally we'd skip this * for same-origin images, but we don't have a good test * for that. */if(!image.hasOwnProperty('crossOrigin')&&window.URL&&window.URL.createObjectURL){var xhr=new XMLHttpRequest();xhr.onreadystatechange=function(){if(xhr.readyState===4){if(xhr.status===200){blob=URL.createObjectURL(xhr.response);image.src=blob;}else {error(raster.url);callback();}}};xhr.open('GET',raster.url,true);xhr.responseType='blob';xhr.send();}else {image.crossOrigin="anonymous";image.src=raster.url;}};Raster.prototype.computeIntervals=function(image){var clip=this.clip,threshold=this.shapeImageThreshold,width=this.box.width,height=this.box.height,rasterImage=new RasterImage(image,width,height);if(!rasterImage.hasData())return undefined;var intervals=new RasterIntervals(-clip.y,clip.height),maxY=Math.min(clip.height,this.box.height);for(var y=0;ythreshold){startX=x;if(intervals.intervalAt(y)===RasterIntervals.none)intervals.setIntervalAt(y,new RasterInterval(y,startX,width));}else if(startX!=-1&&alpha<=threshold){intervals.intervalAt(y).endX=x;startX=-1;}}}return intervals;};Raster.prototype.rightExclusionEdge=function(y1,y2){ // y2 >= y1 var intervals=this.intervals;if(!intervals)return this.clip.width;var x; // = undefined; for(var y=Math.max(y1,this.clip.y);y<=y2&&yx)x=endX;}return x;};Raster.prototype.leftExclusionEdge=function(y1,y2){ // y2 >= y1 var intervals=this.intervals;if(!intervals)return 0;var x; // = undefined; for(var y=Math.max(y1,this.clip.y);y<=y2&&y=this.x&&x=this.y&&y=this.y&&minY=this.x&&minX0&&radius.height>0;}return isCornerRadiusNonZero(this.radii.topLeft)||isCornerRadiusNonZero(this.radii.topRight)||isCornerRadiusNonZero(this.radii.bottomLeft)||isCornerRadiusNonZero(this.radii.bottomRight);};RoundedRect.prototype.cornersInsetRect=function(){var topLeftCorner=this.topLeftCorner();var topRightCorner=this.topRightCorner();var bottomLeftCorner=this.bottomLeftCorner();var bottomRightCorner=this.bottomRightCorner();var x=Math.max(topLeftCorner.maxX,bottomLeftCorner.maxX);var y=Math.max(topLeftCorner.maxY,topRightCorner.maxY);return new Rect(x,y,Math.min(topRightCorner.x,bottomRightCorner.x)-x,Math.min(bottomLeftCorner.y,bottomRightCorner.y)-y);};RoundedRect.prototype.scaleRadii=function(factor){if(factor==1)return;var radii=this.radii;radii.topLeft.scale(factor);if(radii.topLeft.isEmpty())radii.topLeft=Size.zeroSize;radii.topRight.scale(factor);if(radii.topRight.isEmpty())radii.topRight=Size.zeroSize;radii.bottomLeft.scale(factor);if(radii.bottomLeft.isEmpty())radii.bottomLeft=Size.zeroSize;radii.bottomRight.scale(factor);if(radii.bottomRight.isEmpty())radii.bottomRight=Size.zeroSize;}; // See RoundedRect::isRenderable() in https://trac.webkit.org/browser/trunk/Source/WebCore/platform/graphics/RoundedRect.cpp // and http://www.w3.org/TR/css3-background/#corner-overlap RoundedRect.prototype.isRenderable=function(){var radii=this.radii;var rect=this.rect;return radii.topLeft.width+radii.topRight.width<=rect.width&&radii.bottomLeft.width+radii.bottomRight.width<=rect.width&&radii.topLeft.height+radii.bottomLeft.height<=rect.height&&radii.topRight.height+radii.bottomRight.height<=rect.height;}; // See RoundedRect::adjustRadii() in https://trac.webkit.org/browser/trunk/Source/WebCore/platform/graphics/RoundedRect.cpp // and http://www.w3.org/TR/css3-background/#corner-overlap RoundedRect.prototype.adjustRadii=function(){var radii=this.radii;var maxRadiusWidth=Math.max(radii.topLeft.width+radii.topRight.width,radii.bottomLeft.width+radii.bottomRight.width);var maxRadiusHeight=Math.max(radii.topLeft.height+radii.bottomLeft.height,radii.topRight.height+radii.bottomRight.height);if(maxRadiusWidth<=0||maxRadiusHeight<=0){this.radii={topLeft:Size.zeroSize,topRight:Size.zeroSize,bottomRight:Size.zeroSize,bottomLeft:Size.zeroSize};return;}var rect=this.rect;var widthRatio=rect.width/maxRadiusWidth;var heightRatio=rect.height/maxRadiusHeight;this.scaleRadii(widthRatio= y1 if(this.rect.isEmpty()||!this.rect.overlapsYRange(y1,y2))return undefined;if(!this.isRounded()||this.cornersInsetRect().overlapsYRange(y1,y2))return this.rect.maxX;return Math.max(this.maxXInterceptAt(y1,this.rect.x),this.maxXInterceptAt(y2,this.rect.x));};RoundedRect.prototype.leftExclusionEdge=function(y1,y2){ // y2 >= y1 if(this.rect.isEmpty()||!this.rect.overlapsYRange(y1,y2))return undefined;if(!this.isRounded()||this.cornersInsetRect().overlapsYRange(y1,y2))return this.rect.x;return Math.min(this.minXInterceptAt(y1,this.rect.maxX),this.minXInterceptAt(y2,this.rect.maxX));};function computeOffsetHeight(dx,dy,areaLimit){if(dy===0)return 1;if(dx===0||dx*dy/2= y1 if(!this.rect.overlapsYRange(y1,y2))return [{x:undefined,height:y2-y1}];var offsets=[];if(y1this.rect.maxY)offsets.push({x:undefined,height:y2-this.rect.maxY});return offsets;};}RoundedRect.prototype.rightExclusionOffsets=adaptiveOffsetFnGenerator(RoundedRect.prototype.topRightCorner,RoundedRect.prototype.bottomRightCorner,rightBoxOffset,rightCornerOffset);RoundedRect.prototype.leftExclusionOffsets=adaptiveOffsetFnGenerator(RoundedRect.prototype.topLeftCorner,RoundedRect.prototype.bottomLeftCorner,leftBoxOffset,leftCornerOffset);function createRoundedRectForCircle(circle,margin){var r=circle.r+margin;var c=new Size(r,r);return new RoundedRect(new Rect(circle.cx-r,circle.cy-r,r*2,r*2),c,c,c,c);}function createRoundedRectForEllipse(ellipse,margin){var c=new Size(ellipse.rx+margin,ellipse.ry+margin);return new RoundedRect(new Rect(ellipse.cx-c.width,ellipse.cy-c.height,c.width*2,c.height*2),c,c,c,c);}function createRoundedRectForInset(inset,margin){function toSize(r){return new Size(r[0]+margin,r[1]+margin);}var topLeft=toSize(inset.radii[0]);var topRight=toSize(inset.radii[1]);var bottomRight=toSize(inset.radii[2]);var bottomLeft=toSize(inset.radii[3]);var rect=new Rect(inset.x-margin,inset.y-margin,inset.width+2*margin,inset.height+2*margin);return new RoundedRect(rect,topLeft,topRight,bottomLeft,bottomRight);}function createRoundedRectForBox(box,margin){function toSize(r){return new Size(r[0]+margin,r[1]+margin);}var topLeft=toSize(box.radii[0]),topRight=toSize(box.radii[1]),bottomRight=toSize(box.radii[2]),bottomLeft=toSize(box.radii[3]); // This box is at 0,0 relative to its sizing box (itself) var rect=new Rect(-margin,-margin,box.width+2*margin,box.height+2*margin);return new RoundedRect(rect,topLeft,topRight,bottomLeft,bottomRight);}function createRaster(url,box,shapeImageThreshold,shapeMargin,clip,doLayout){var clipRect=new Rect(clip.x,clip.y,clip.width,clip.height);return new Raster(url,box,shapeImageThreshold,shapeMargin,clipRect,doLayout);}function createPolygon(polygon,shapeMargin){return new Polygon(polygon.points,polygon.fillRule,shapeMargin);}function createShapeGeometry(shapeValue,whenReady){var shapeMargin=shapeValue.shapeMargin===undefined?0:shapeValue.shapeMargin;var geometry;if(shapeValue.shape){switch(shapeValue.shape.type){case "circle":geometry=createRoundedRectForCircle(shapeValue.shape,shapeMargin);break;case "ellipse":geometry=createRoundedRectForEllipse(shapeValue.shape,shapeMargin);break;case "inset":geometry=createRoundedRectForInset(shapeValue.shape,shapeMargin);if(!geometry.isRenderable())geometry.adjustRadii();break;case "polygon":geometry=createPolygon(shapeValue.shape,shapeMargin);break;}whenReady();return geometry;}if(shapeValue.url)return createRaster(shapeValue.url,shapeValue.box,shapeValue.shapeImageThreshold,shapeMargin,shapeValue.clip,whenReady);if(shapeValue.box){geometry=createRoundedRectForBox(shapeValue.box,shapeMargin);whenReady();return geometry;}console.error("Unrecognized shape");}function ShapeInfo(element){this.metrics=new Metrics(element);var parserSettings={metrics:this.metrics,shapeOutside:element.getAttribute('data-shape-outside'),shapeMargin:element.getAttribute('data-shape-margin'),shapeImageThreshold:element.getAttribute('data-shape-image-threshold')};this.shapeValue=new ShapeValue(parserSettings);var self=this;this.geometry=createShapeGeometry(this.shapeValue,function(){self.ready=true;if(self.callback)self.callback();});}ShapeInfo.prototype.onReady=function(callback){if(this.ready)callback();else this.callback=callback;};ShapeInfo.prototype.leftExclusionEdge=function(line){ // { top, bottom, left, right } return this.geometry?this.geometry.leftExclusionEdge(line.top,line.bottom):line.left;};ShapeInfo.prototype.rightExclusionEdge=function(line){ // { top, bottom, left, right } return this.geometry?this.geometry.rightExclusionEdge(line.top,line.bottom):line.right;};function exclusionEdgeValue(x){return x===undefined?0:x;}ShapeInfo.prototype.computeStepOffsets=function(step){var offset,offsets=[];for(var i=0;i1?insets[1]:result.insets[0];result.insets[2]=insets.length>2?insets[2]:result.insets[0];result.insets[3]=insets.length>3?insets[3]:result.insets[1];result.insets[0]=metrics.toPixels(result.insets[0],box.height);result.insets[1]=metrics.toPixels(result.insets[1],box.width);result.insets[2]=metrics.toPixels(result.insets[2],box.height);result.insets[3]=metrics.toPixels(result.insets[3],box.width);}var radii;if(args&&args[2]){radii=args[2].trim();radii=radii.split(/\s+/);if(radii.length<2)radii.push(radii[0]);if(radii.length<3)radii.push(radii[0]);if(radii.length<4)radii.push(radii[1]);result.radii=radii.map(function(radius){radius=metrics.toPixels(radius,box.width);return [radius,radius];});}if(args&&args[3]){radii=args[3].trim();radii=radii.split(/\s+/);if(radii.length<2)radii.push(radii[0]);if(radii.length<3)radii.push(radii[0]);if(radii.length<4)radii.push(radii[1]);radii.forEach(function(radius,i){result.radii[i][1]=metrics.toPixels(radius,box.height);});}result.x=result.insets[3];result.y=result.insets[0];result.width=box.width-(result.insets[1]+result.insets[3]);result.height=box.height-(result.insets[0]+result.insets[2]);return result;};function positionOffsetToPixels(offset,extent,metrics){offset=offset.split(/\s+/);var direction='TopLeft';var length=0;switch(offset[0]){case 'top':case 'left':break;case 'bottom':case 'right':direction='BottomRight';break;case 'center':length=extent/2.0;break;default:length=metrics.toPixels(offset[0],extent);}if(offset.length>1)length=metrics.toPixels(offset[1],extent);return direction==='TopLeft'?length:extent-length;}function radiusToPixels(r,sides,extent,metrics){if(r==='closest-side')return Math.min.apply(null,sides);else if(r==='farthest-side')return Math.max.apply(null,sides);else return metrics.toPixels(r,extent);} // Parse but do not resolve yet (shared by circle and ellipse) ShapeValue.prototype.parseEllipsoid=function(args){ // use the 'a' in 'at' as the delimiter var re=/((?:[^a]|a(?!t))*)?\s*(?:at\s+(.*))?/;args=re.exec(args);var result={};if(args&&args[1]){var radii=args[1].trim();radii=radii.split(/\s+/);result.rx=radii[0];result.ry=radii.length>1?radii[1]:radii[0];}else {result.rx=result.ry='closest-side';}var resolvedPositions=[];if(args&&args[2]){var positions=args[2].trim();positions=positions.split(/\s+/);var canMergeBack=false;positions.forEach(function(position){ // if it is an offset if(/\d+/.test(position)&&canMergeBack)resolvedPositions[resolvedPositions.length-1]+=' '+position;else resolvedPositions.push(position); // it's a non-center keyword and there are more than two inputs canMergeBack=/top|bottom|left|right/.test(position)&&positions.length>2;});}while(resolvedPositions.length<2){resolvedPositions.push('center');}if(/top|bottom/.test(resolvedPositions[0])||/left|right/.test(resolvedPositions[1])){var swap=resolvedPositions[0];resolvedPositions[0]=resolvedPositions[1];resolvedPositions[1]=swap;}result.cx=resolvedPositions[0];result.cy=resolvedPositions[1];return result;};ShapeValue.prototype.parseCircle=function(args,box,metrics){var result=this.parseEllipsoid(args);result.type='circle';result.cx=positionOffsetToPixels(result.cx,box.width,metrics);result.cy=positionOffsetToPixels(result.cy,box.height,metrics);result.r=radiusToPixels(result.rx,[Math.abs(result.cx),Math.abs(box.width-result.cx),Math.abs(result.cy),Math.abs(box.height-result.cy)],Math.sqrt((box.width*box.width+box.height*box.height)/2),metrics);delete result.rx;delete result.ry;return result;};ShapeValue.prototype.parseEllipse=function(args,box,metrics){var result=this.parseEllipsoid(args);result.type='ellipse';result.cx=positionOffsetToPixels(result.cx,box.width,metrics);result.cy=positionOffsetToPixels(result.cy,box.height,metrics);result.rx=radiusToPixels(result.rx,[Math.abs(result.cx),Math.abs(box.width-result.cx)],box.width,metrics);result.ry=radiusToPixels(result.ry,[Math.abs(result.cy),Math.abs(box.height-result.cy)],box.height,metrics);return result;};ShapeValue.prototype.parsePolygon=function(args,box,metrics){args=args.split(/\s*,\s*/);var rule='nonzero';if(args.length>0&&/nonzero|evenodd/.test(args[0])){rule=args[0].trim();args=args.slice(1);}var points=args.map(function(point){var coords=point.split(/\s+/);return {x:metrics.toPixels(coords[0],box.width),y:metrics.toPixels(coords[1],box.height)};});return {type:'polygon','fillRule':rule,'points':points};};ShapeValue.prototype.computeClip=function(referenceBox,metrics){ // margins: [marginTop, marginRight, marginBottom, marginLeft] var marginLeft=metrics.margins[3];var marginTop=metrics.margins[0];var marginWidth=metrics.margins[3]+metrics.margins[1];var marginHeight=metrics.margins[0]+metrics.margins[2];return {x:-referenceBox.x-marginLeft,y:-referenceBox.y-marginTop,width:metrics.borderBox.width+marginWidth,height:metrics.borderBox.height+marginHeight};};ShapeValue.prototype.parseShapeMargin=function(margin,box,metrics){return parseInt(margin)?Math.max(0,metrics.toPixels(margin,box.width)):0;};ShapeValue.prototype.parseShapeImageThreshold=function(threshold){var value=parseFloat(threshold); // FIXME: disallow non-numerical values return value?Math.min(Math.max(0,value),1.0):0;};function getStyleSheetElements(){var doc=document,stylesheets=[],i,len;if(typeof doc.querySelectorAll=='function'){ // shiny new browsers stylesheets=doc.querySelectorAll('link[rel="stylesheet"], style'); // make it an array stylesheets=Array.prototype.slice.call(stylesheets,0);}else { // old and busted browsers // var tags=doc.getElementsByTagName("link");if(tags.length){for(i=0,len=tags.length;i tags=doc.getElementsByTagName("style");for(i=0,len=tags.length;i=0;},addClass:function addClass(element,className){element.className+=' '+className;},removeClass:function removeClass(element,className){var regex=new RegExp('\\b'+this.escapeRegExp(className)+'\\b');element.className=element.className.replace(regex,'');},interpolateString:function interpolateString(str,callback){var marker=/{{([a-z][a-z0-9\-_]*)}}/gi;return str.replace(marker,function(matches){return callback(arguments[1])||'';});},getCookie:function getCookie(name){var value='; '+document.cookie;var parts=value.split('; '+name+'=');return parts.length<2?undefined:parts.pop().split(';').shift();},setCookie:function setCookie(name,value,expiryDays,domain,path,secure){var exdate=new Date();exdate.setHours(exdate.getHours()+(expiryDays||365)*24);var cookie=[name+'='+value,'expires='+exdate.toUTCString(),'path='+(path||'/')];if(domain){cookie.push('domain='+domain);}if(secure){cookie.push('secure');}document.cookie=cookie.join(';');}, // only used for extending the initial options deepExtend:function deepExtend(target,source){for(var prop in source){if(source.hasOwnProperty(prop)){if(prop in target&&this.isPlainObject(target[prop])&&this.isPlainObject(source[prop])){this.deepExtend(target[prop],source[prop]);}else {target[prop]=source[prop];}}}return target;}, // only used for throttling the 'mousemove' event (used for animating the revoke button when `animateRevokable` is true) throttle:function throttle(callback,limit){var wait=false;return function(){if(!wait){callback.apply(this,arguments);wait=true;setTimeout(function(){wait=false;},limit);}};}, // only used for hashing json objects (used for hash mapping palette objects, used when custom colours are passed through JavaScript) hash:function hash(str){var hash=0,i,chr,len;if(str.length===0)return hash;for(i=0,len=str.length;i=128?'#000':'#fff';}, // used to change color on highlight getLuminance:function getLuminance(hex){var num=parseInt(this.normaliseHex(hex),16),amt=38,R=(num>>16)+amt,B=(num>>8&0x00ff)+amt,G=(num&0x0000ff)+amt;var newColour=(0x1000000+(R<255?R<1?0:R:255)*0x10000+(B<255?B<1?0:B:255)*0x100+(G<255?G<1?0:G:255)).toString(16).slice(1);return '#'+newColour;},isMobile:function isMobile(){return (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent));},isPlainObject:function isPlainObject(obj){ // The code "typeof obj === 'object' && obj !== null" allows Array objects return (typeof obj==='undefined'?'undefined':_typeof(obj))==='object'&&obj!==null&&obj.constructor==Object;},traverseDOMPath:function traverseDOMPath(elem,className){if(!elem||!elem.parentNode)return null;if(util.hasClass(elem,className))return elem;return this.traverseDOMPath(elem.parentNode,className);}}; // valid cookie values cc.status={deny:'deny',allow:'allow',dismiss:'dismiss'}; // detects the `transitionend` event name cc.transitionEnd=function(){var el=document.createElement('div');var trans={t:'transitionend',OT:'oTransitionEnd',msT:'MSTransitionEnd',MozT:'transitionend',WebkitT:'webkitTransitionEnd'};for(var prefix in trans){if(trans.hasOwnProperty(prefix)&&typeof el.style[prefix+'ransition']!='undefined'){return trans[prefix];}}return '';}();cc.hasTransition=!!cc.transitionEnd; // array of valid regexp escaped statuses var __allowedStatuses=Object.keys(cc.status).map(util.escapeRegExp); // contains references to the custom