From f14c6fce92f24065792e60bc0e5159bdbaa7fe6a Mon Sep 17 00:00:00 2001 From: Kingcean Tuan Date: Tue, 6 Apr 2021 15:16:08 +0800 Subject: [PATCH] Add SVG supports. --- dist/index.js | 2 +- package-lock.json | 208 +++++++++++++++++++++++++++++++++++----------- package.json | 4 +- src/render.ts | 29 ++++++- 4 files changed, 191 insertions(+), 52 deletions(-) diff --git a/dist/index.js b/dist/index.js index 14aea9f..5772bc8 100644 --- a/dist/index.js +++ b/dist/index.js @@ -1,2 +1,2 @@ // Hyper-JSON Engine -var Hje;!function(e){function i(e,o){if(!e)return 0;var i=[];e.forEach(function(e,t,n){e===o&&i.push(t)});for(var t=i.length,n=t-1;n--;)e.splice(i[n],1);return t}var r={};e.InternalInjectionPool={hittask:function(e){return function(e,t,n){if(e){var o=!1;return"function"==typeof n?n(t)&&(o=!0):void 0!==t&&(o=!0),o&&(r[e]=t),r[e]}}("hittask",e,function(e){return"function"==typeof e})}};var t=(n.prototype.push=function(){for(var t=this,e=[],n=0;n { initView(context: ViewGeneratingContextContract, tagName: string) { let ele = context.element(); let eleType = typeof ele; - if (!ele || eleType === "symbol" || ele as any === true) return document.createElement(tagName || "div"); + if (!ele || eleType === "symbol" || ele as any === true) { + let tagNs = (context.model() || {} as any).tagNamespace; + if (!tagNs && tagName && tagName.indexOf(":") >= 0) { + if (tagName.startsWith("svg:")) { + tagNs = "http://www.w3.org/2000/svg"; + tagName = tagName.substring(4); + if (!tagName) tagName = "svg"; + } else if (tagName.startsWith("mathml:")) { + tagNs = "http://www.w3.org/1998/Math/MathML"; + tagName = tagName.substring(7); + if (!tagName) tagName = "math"; + } else if (tagName.startsWith("math:")) { + tagNs = "http://www.w3.org/1998/Math/MathML"; + tagName = tagName.substring(5); + if (!tagName) tagName = "math"; + } else if (tagName.startsWith("html:")) { + tagNs = "http://www.w3.org/1999/xhtml"; + tagName = tagName.substring(5); + } else if (tagName.startsWith(":")) { + tagName = tagName.substring(6); + } + } + + return tagNs + ? document.createElementNS(tagNs, tagName || this.defaultTagName || "div") + : document.createElement(tagName || this.defaultTagName || "div"); + } + if (eleType === "string") ele = document.getElementById(ele as any); else if (eleType === "number") ele = document.body.children[ele as any] as HTMLElement; if (ele) ele.innerHTML = "";