<commit_before>// candle.svg.js
/* global Candle:false, _doc:false, _2PI:false */

(function(){

/* ------------------- */
/*   SVG描画可能条件   */
/* ------------------- */
if(!Candle.addTypeIf('svg', function(){
	return (typeof document!=='undefined' && typeof window!=='undefined' && !window.opera && !!document.createElementNS);
})){ return;}

var SVGNS   = Candle.SVGNS   = "http://www.w3.org/2000/svg",
	XLINKNS = Candle.XLINKNS = "http://www.w3.org/1999/xlink";

function newEL(tag){ return _doc.createElementNS(SVGNS, tag);}

/* ------------------------------------------- */
/*   VectorContext(SVG)クラス用const文字列集   */
/* ------------------------------------------- */
var S_PATH_MOVE   = 'M',
	S_PATH_LINE   = 'L',
	S_PATH_ARCTO  = 'A',
	S_PATH_CLOSE  = 'z',

//	S_ATT_ID          = 'id',
	S_ATT_PATH        = 'd',
	S_ATT_FILL        = 'fill',
	S_ATT_STROKE      = 'stroke',
	S_ATT_STROKEWIDTH = 'stroke-width',
	S_ATT_RENDERING   = 'shape-rendering',

	S_NONE = 'none',

	S_ANCHOR = { left:'start', center:'middle', right:'end'},
	S_HEIGHT;

function setheight(){
	var UA = (typeof navigator!=='undefined' ? (navigator.userAgent||'') : '');
	if(UA.match(/Chrome/)){
		S_HEIGHT = { 'candle-top':-0.72, top:-0.95, hanging:-0.72, middle:-0.35, alphabetic:0, bottom:0.25 };
	}
	else if(UA.match(/AppleWebKit/)){
		S_HEIGHT = { 'candle-top':-0.7,  top:-0.9,  hanging:-0.9,  middle:-0.35, alphabetic:0, bottom:0.25 };
	}
	else if(UA.match(/Trident/)){
		S_HEIGHT = { 'candle-top':-0.74, top:-1.02, hanging:-1.02, middle:-0.32, alphabetic:0, bottom:0.45 };
	}
	else /* if(UA.match(/Gecko/)) */{
		if(UA.match(/Win/)){
			S_HEIGHT = { 'candle-top':-0.7,  top:-0.85, hanging:-0.85, middle:-0.34, alphabetic:0, bottom:0.15 };
		}
		else{
			S_HEIGHT = { 'candle-top':-0.76, top:-0.9,  hanging:-0.9,  middle:-0.38, alphabetic:0, bottom:0.08 };
		}
	}
}

/* ----------------- */
/*   SVG用ラッパー   */
/* ----------------- */
Candle.addWrapper('svg:wrapperbase',{

	initialize : function(parent){
		this.use = new Candle.TypeList('svg');

		// define const
		if(!S_HEIGHT){ setheight();}

		// 外部から変更される追加プロパティ
		this.vid      = '';
		this.elements = {};
		this._textcache = {};

		// variables for internal
		this.zidx = 1;
		this.zidx_array = {};
		this.target = null;	// エレメントの追加対象となるオブジェクト

		// 描画中path
		this.cpath    = [];
		this.lastpath = '';
		this.freezepath = false;

		Candle.wrapper.wrapperbase.prototype.initialize.call(this, parent);
	},

	/* additional functions (for initialize) */
	initElement : function(){
		this.canvas.style.overflow = 'hidden';
		var rect = Candle.getRectSize(this.canvas);
		var root = this.child = _doc.createElementNS(SVGNS,'svg');
		root.setAttribute('xmlns', SVGNS);
		root.setAttribute('xmlns:xlink', XLINKNS);
		root.setAttribute('id', this.canvasid);
		root.setAttribute('font-size', "10px");
		root.setAttribute('font-family', "sans-serif");
		root.setAttribute('width', rect.width);
		root.setAttribute('height', rect.height);
		root.setAttribute('viewBox', [0,0,rect.width,rect.height].join(' '));
		this.canvas.appendChild(root);
	},
	initFunction : function(){
		var xmldeclare = '<?xml version="1.0" encoding="UTF-8"?>\n';
		function getOuterHTML(el){ return el.outerHTML || new XMLSerializer().serializeToString(el);}
		
		var root = this.child;
		this.canvas.toDataURL = function(type, quality){
			return "data:image/svg+xml;base64," + window.btoa(getOuterHTML(root));
		};
		this.canvas.toBlob = function(callback, type, quality){
			callback(new Blob([xmldeclare + getOuterHTML(root)], {type:'image/svg+xml'}));
		};
		this.canvas.toBuffer = function(type, quality){
			return xmldeclare + getOuterHTML(root);
		};
	},
	initLayer : function(){
		this.setLayer();

		var rect = Candle.getRectSize(this.canvas);
		this.rect(0,0,rect.width,rect.height);
		this.addVectorElement(false,false);
	},

	clear : function(){
		var root = this.canvas.firstChild, el = root.firstChild;
		while(!!el){ root.removeChild(el); el = root.firstChild;}

		/* resetElement */
		this.vid = '';
		this.elements = {};
		this.target = _doc.getElementById(this.canvasid);
		this.zidx = 1;
		this.zidx_array = {};
		this.setLayer();
		this._textcache = {};
	},

	/* layer functions */
	setLayer : function(layerid, option){
		option = option || {};
		this.vid = '';
		if(!!layerid){
			var lid = [this.canvasid,"layer",layerid].join('_');
			var layer = _doc.getElementById(lid);
			if(!layer){
				layer = newEL('g');
				layer.setAttribute('id', lid);
				this.child.appendChild(layer);
			}

			if(!this.zidx_array[layerid]){
				this.zidx++;
				this.zidx_array[layerid] = layer.style.zIndex = this.zidx;
			}
			this.target = layer;
		}
		else{
			this.target = this.child;
		}
		
		this.currentLayerId = (!!layerid ? layerid : '_empty');
		if(option.rendering){ this.setRendering(option.rendering);}
		
		this.freezepath = (!!option && option.freeze);
	},

	/* property functions */
	setRendering : function(render){
		this.target.setAttribute(S_ATT_RENDERING, render);
	},

	changeSize : function(width,height){
		this.canvas.style.width  = width + 'px';
		this.canvas.style.height = height + 'px';<commit_msg>svg: CSSのz-indexを使用しないようにします<commit_after>// candle.svg.js
/* global Candle:false, _doc:false, _2PI:false */

(function(){

/* ------------------- */
/*   SVG描画可能条件   */
/* ------------------- */
if(!Candle.addTypeIf('svg', function(){
	return (typeof document!=='undefined' && typeof window!=='undefined' && !window.opera && !!document.createElementNS);
})){ return;}

var SVGNS   = Candle.SVGNS   = "http://www.w3.org/2000/svg",
	XLINKNS = Candle.XLINKNS = "http://www.w3.org/1999/xlink";

function newEL(tag){ return _doc.createElementNS(SVGNS, tag);}

/* ------------------------------------------- */
/*   VectorContext(SVG)クラス用const文字列集   */
/* ------------------------------------------- */
var S_PATH_MOVE   = 'M',
	S_PATH_LINE   = 'L',
	S_PATH_ARCTO  = 'A',
	S_PATH_CLOSE  = 'z',

//	S_ATT_ID          = 'id',
	S_ATT_PATH        = 'd',
	S_ATT_FILL        = 'fill',
	S_ATT_STROKE      = 'stroke',
	S_ATT_STROKEWIDTH = 'stroke-width',
	S_ATT_RENDERING   = 'shape-rendering',

	S_NONE = 'none',

	S_ANCHOR = { left:'start', center:'middle', right:'end'},
	S_HEIGHT;

function setheight(){
	var UA = (typeof navigator!=='undefined' ? (navigator.userAgent||'') : '');
	if(UA.match(/Chrome/)){
		S_HEIGHT = { 'candle-top':-0.72, top:-0.95, hanging:-0.72, middle:-0.35, alphabetic:0, bottom:0.25 };
	}
	else if(UA.match(/AppleWebKit/)){
		S_HEIGHT = { 'candle-top':-0.7,  top:-0.9,  hanging:-0.9,  middle:-0.35, alphabetic:0, bottom:0.25 };
	}
	else if(UA.match(/Trident/)){
		S_HEIGHT = { 'candle-top':-0.74, top:-1.02, hanging:-1.02, middle:-0.32, alphabetic:0, bottom:0.45 };
	}
	else /* if(UA.match(/Gecko/)) */{
		if(UA.match(/Win/)){
			S_HEIGHT = { 'candle-top':-0.7,  top:-0.85, hanging:-0.85, middle:-0.34, alphabetic:0, bottom:0.15 };
		}
		else{
			S_HEIGHT = { 'candle-top':-0.76, top:-0.9,  hanging:-0.9,  middle:-0.38, alphabetic:0, bottom:0.08 };
		}
	}
}

/* ----------------- */
/*   SVG用ラッパー   */
/* ----------------- */
Candle.addWrapper('svg:wrapperbase',{

	initialize : function(parent){
		this.use = new Candle.TypeList('svg');

		// define const
		if(!S_HEIGHT){ setheight();}

		// 外部から変更される追加プロパティ
		this.vid      = '';
		this.elements = {};
		this._textcache = {};

		// variables for internal
		this.target = null;	// エレメントの追加対象となるオブジェクト

		// 描画中path
		this.cpath    = [];
		this.lastpath = '';
		this.freezepath = false;

		Candle.wrapper.wrapperbase.prototype.initialize.call(this, parent);
	},

	/* additional functions (for initialize) */
	initElement : function(){
		this.canvas.style.overflow = 'hidden';
		var rect = Candle.getRectSize(this.canvas);
		var root = this.child = _doc.createElementNS(SVGNS,'svg');
		root.setAttribute('xmlns', SVGNS);
		root.setAttribute('xmlns:xlink', XLINKNS);
		root.setAttribute('id', this.canvasid);
		root.setAttribute('font-size', "10px");
		root.setAttribute('font-family', "sans-serif");
		root.setAttribute('width', rect.width);
		root.setAttribute('height', rect.height);
		root.setAttribute('viewBox', [0,0,rect.width,rect.height].join(' '));
		this.canvas.appendChild(root);
	},
	initFunction : function(){
		var xmldeclare = '<?xml version="1.0" encoding="UTF-8"?>\n';
		function getOuterHTML(el){ return el.outerHTML || new XMLSerializer().serializeToString(el);}
		
		var root = this.child;
		this.canvas.toDataURL = function(type, quality){
			return "data:image/svg+xml;base64," + window.btoa(getOuterHTML(root));
		};
		this.canvas.toBlob = function(callback, type, quality){
			callback(new Blob([xmldeclare + getOuterHTML(root)], {type:'image/svg+xml'}));
		};
		this.canvas.toBuffer = function(type, quality){
			return xmldeclare + getOuterHTML(root);
		};
	},
	initLayer : function(){
		this.setLayer();

		var rect = Candle.getRectSize(this.canvas);
		this.rect(0,0,rect.width,rect.height);
		this.addVectorElement(false,false);
	},

	clear : function(){
		var root = this.canvas.firstChild, el = root.firstChild;
		while(!!el){ root.removeChild(el); el = root.firstChild;}

		/* resetElement */
		this.vid = '';
		this.elements = {};
		this.target = this.child;
		this.setLayer();
		this._textcache = {};
	},

	/* layer functions */
	setLayer : function(layerid, option){
		option = option || {};
		this.vid = '';
		if(!!layerid){
			var lid = [this.canvasid,"layer",layerid].join('_');
			var layer = _doc.getElementById(lid);
			if(!layer){
				layer = newEL('g');
				layer.setAttribute('id', lid);
				this.child.appendChild(layer);
			}
			this.target = layer;
		}
		else{
			this.target = this.child;
		}
		
		this.currentLayerId = (!!layerid ? layerid : '_empty');
		if(option.rendering){ this.setRendering(option.rendering);}
		
		this.freezepath = (!!option && option.freeze);
	},

	/* property functions */
	setRendering : function(render){
		this.target.setAttribute(S_ATT_RENDERING, render);
	},

	changeSize : function(width,height){
		this.canvas.style.width  = width + 'px';
		this.canvas.style.height = height + 'px';
{'fraction_non_alphanumeric': 0.2219572776949826, 'fraction_numerical': 0.01927471435668157, 'mean_word_length': 3.2670623145400595, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 2, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 16}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3052054', 'n_tokens_mistral': 4116, 'n_tokens_neox': 3793, 'n_words': 573}