@tarojs/runtime 3.6.34 → 3.6.35-alpha.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/dom-external/inner-html/parser.js +44 -3
- package/dist/dom-external/inner-html/parser.js.map +1 -1
- package/dist/dom-external/inner-html/tags.d.ts +6 -1
- package/dist/dom-external/inner-html/tags.js +18 -3
- package/dist/dom-external/inner-html/tags.js.map +1 -1
- package/dist/index.cjs.js +59 -3
- package/dist/index.cjs.js.map +1 -1
- package/dist/runtime.esm.js +59 -3
- package/dist/runtime.esm.js.map +1 -1
- package/package.json +3 -3
|
@@ -2,7 +2,7 @@ import { isFunction } from '@tarojs/shared';
|
|
|
2
2
|
import { options } from '../../options.js';
|
|
3
3
|
import { Scaner } from './scaner.js';
|
|
4
4
|
import StyleTagParser from './style.js';
|
|
5
|
-
import { specialMiniElements, isMiniElements, isBlockElements, isInlineElements } from './tags.js';
|
|
5
|
+
import { specialMiniElements, isMiniElements, isBlockElements, isInlineElements, isSpecialElements, getSpecialElementMapping } from './tags.js';
|
|
6
6
|
import { unquote } from './utils.js';
|
|
7
7
|
|
|
8
8
|
const closingTagAncestorBreakers = {
|
|
@@ -32,7 +32,21 @@ function hasTerminalParent(tagName, stack) {
|
|
|
32
32
|
}
|
|
33
33
|
return false;
|
|
34
34
|
}
|
|
35
|
-
|
|
35
|
+
/**
|
|
36
|
+
* 将属性数组转换为属性对象
|
|
37
|
+
* @param attributes 字符串数组,包含属性信息
|
|
38
|
+
* @returns 属性对象,键为属性名,值为属性值或true
|
|
39
|
+
*/
|
|
40
|
+
function attributesArray2Props(attributes) {
|
|
41
|
+
const props = {};
|
|
42
|
+
for (let i = 0; i < attributes.length; i++) {
|
|
43
|
+
const attr = attributes[i];
|
|
44
|
+
const [key, value] = splitEqual(attr);
|
|
45
|
+
props[key] = value == null ? true : unquote(value);
|
|
46
|
+
}
|
|
47
|
+
return props;
|
|
48
|
+
}
|
|
49
|
+
function getTagName(tag, attributes) {
|
|
36
50
|
if (options.html.renderHTMLTag) {
|
|
37
51
|
return tag;
|
|
38
52
|
}
|
|
@@ -48,6 +62,14 @@ function getTagName(tag) {
|
|
|
48
62
|
else if (isInlineElements(tag)) {
|
|
49
63
|
return 'text';
|
|
50
64
|
}
|
|
65
|
+
else if (isSpecialElements(tag)) {
|
|
66
|
+
// if it's special tag, the real tag is determined by the config mapping
|
|
67
|
+
const mapping = getSpecialElementMapping(tag);
|
|
68
|
+
const props = attributesArray2Props(attributes);
|
|
69
|
+
if (mapping) {
|
|
70
|
+
return mapping.mapName(props);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
51
73
|
return 'view';
|
|
52
74
|
}
|
|
53
75
|
function splitEqual(str) {
|
|
@@ -81,7 +103,26 @@ function format(children, document, styleOptions, parent) {
|
|
|
81
103
|
parent === null || parent === void 0 ? void 0 : parent.appendChild(text);
|
|
82
104
|
return text;
|
|
83
105
|
}
|
|
84
|
-
|
|
106
|
+
// img标签,把width和height写入style,删除原有的width、height和style属性
|
|
107
|
+
if (child.tagName === 'img') {
|
|
108
|
+
let styleText = '';
|
|
109
|
+
const toBeRemovedIndexs = [];
|
|
110
|
+
for (let i = 0; i < child.attributes.length; i++) {
|
|
111
|
+
const attr = child.attributes[i];
|
|
112
|
+
const [key, value] = splitEqual(attr);
|
|
113
|
+
if (key === 'width' || key === 'height') {
|
|
114
|
+
styleText += `${key}:${value};`;
|
|
115
|
+
toBeRemovedIndexs.push(i);
|
|
116
|
+
}
|
|
117
|
+
else if (key === 'style') {
|
|
118
|
+
styleText = `${styleText}${value};`;
|
|
119
|
+
toBeRemovedIndexs.push(i);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
child.attributes = child.attributes.filter((_, index) => !toBeRemovedIndexs.includes(index));
|
|
123
|
+
child.attributes.push(`style=${styleText.replace(/['"]/g, '')}`);
|
|
124
|
+
}
|
|
125
|
+
const el = document.createElement(getTagName(child.tagName, child.attributes));
|
|
85
126
|
el.h5tagName = child.tagName;
|
|
86
127
|
parent === null || parent === void 0 ? void 0 : parent.appendChild(el);
|
|
87
128
|
if (!options.html.renderHTMLTag) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parser.js","sources":["../../../src/dom-external/inner-html/parser.ts"],"sourcesContent":["import { isFunction } from '@tarojs/shared'\n\nimport { options } from '../../options'\nimport { Scaner, Token } from './scaner'\nimport StyleTagParser from './style'\nimport { isBlockElements, isInlineElements, isMiniElements, specialMiniElements } from './tags'\nimport { unquote } from './utils'\n\nimport type { TaroDocument } from '../../dom/document'\nimport type { TaroElement } from '../../dom/element'\n\ninterface State {\n tokens: Token[]\n cursor: number\n stack: Element[]\n}\n\nconst closingTagAncestorBreakers = {\n li: ['ul', 'ol', 'menu'],\n dt: ['dl'],\n dd: ['dl'],\n tbody: ['table'],\n thead: ['table'],\n tfoot: ['table'],\n tr: ['table'],\n td: ['table']\n}\n\ninterface Node {\n type: string\n}\n\ninterface Comment extends Node {\n type: 'comment'\n content: string\n}\n\nexport interface Text extends Node {\n type: 'text'\n content: string\n}\n\nexport interface Element extends Node {\n type: 'element'\n tagName: string\n children: ChildNode[]\n attributes: string[]\n}\n\nexport interface ParsedTaroElement extends TaroElement{\n h5tagName?: string\n}\n\ntype ChildNode = Comment | Text | Element\n\nfunction hasTerminalParent (tagName: string, stack: Element[]) {\n const tagParents: undefined | string[] = closingTagAncestorBreakers[tagName]\n if (tagParents) {\n let currentIndex = stack.length - 1\n while (currentIndex >= 0) {\n const parentTagName = stack[currentIndex].tagName\n if (parentTagName === tagName) {\n break\n }\n if (tagParents && tagParents.includes(parentTagName!)) {\n return true\n }\n currentIndex--\n }\n }\n return false\n}\n\nfunction getTagName (tag: string) {\n if (options.html!.renderHTMLTag) {\n return tag\n }\n\n if (specialMiniElements[tag]) {\n return specialMiniElements[tag]\n } else if (isMiniElements(tag)) {\n return tag\n } else if (isBlockElements(tag)) {\n return 'view'\n } else if (isInlineElements(tag)) {\n return 'text'\n }\n\n return 'view'\n}\n\nfunction splitEqual (str: string) {\n const sep = '='\n const idx = str.indexOf(sep)\n if (idx === -1) return [str]\n const key = str.slice(0, idx).trim()\n const value = str.slice(idx + sep.length).trim()\n return [key, value]\n}\n\nfunction format (\n children: ChildNode[],\n document: TaroDocument,\n styleOptions: {\n styleTagParser: StyleTagParser\n descendantList: number[]\n },\n parent?: TaroElement\n) {\n return children\n .filter(child => {\n // 过滤注释和空文本节点\n if (child.type === 'comment') {\n return false\n } else if (child.type === 'text') {\n return child.content !== ''\n }\n return true\n })\n .map((child: Text | Element) => {\n // 文本节点\n if (child.type === 'text') {\n let text = document.createTextNode(child.content)\n if (isFunction(options.html!.transformText)) {\n text = options.html!.transformText(text, child)\n }\n parent?.appendChild(text)\n return text\n }\n\n const el: ParsedTaroElement = document.createElement(getTagName(child.tagName))\n el.h5tagName = child.tagName\n\n parent?.appendChild(el)\n\n if (!options.html!.renderHTMLTag) {\n el.className = `h5-${child.tagName}`\n }\n\n for (let i = 0; i < child.attributes.length; i++) {\n const attr = child.attributes[i]\n const [key, value] = splitEqual(attr)\n if (key === 'class') {\n el.className += ' ' + unquote(value)\n } else if (key[0] === 'o' && key[1] === 'n') {\n continue\n } else {\n el.setAttribute(key, value == null ? true : unquote(value))\n }\n }\n\n const { styleTagParser, descendantList } = styleOptions\n const list = descendantList.slice()\n const style = styleTagParser.matchStyle(child.tagName, el, list)\n\n el.setAttribute('style', style + el.style.cssText)\n // console.log('style, ', style)\n\n format(child.children, document, {\n styleTagParser,\n descendantList: list\n }, el)\n\n if (isFunction(options.html!.transformElement)) {\n return options.html!.transformElement(el, child)\n }\n\n return el\n })\n}\n\nexport function parser (html: string, document: TaroDocument) {\n const styleTagParser = new StyleTagParser()\n html = styleTagParser.extractStyle(html)\n\n const tokens = new Scaner(html).scan()\n\n const root: Element = { tagName: '', children: [], type: 'element', attributes: [] }\n\n const state = { tokens, options, cursor: 0, stack: [root] }\n parse(state)\n\n return format(root.children, document, {\n styleTagParser,\n descendantList: Array(styleTagParser.styles.length).fill(0)\n })\n}\n\nfunction parse (state: State) {\n const { tokens, stack } = state\n let { cursor } = state\n\n const len = tokens.length\n\n let nodes = stack[stack.length - 1].children\n\n while (cursor < len) {\n const token = tokens[cursor]\n if (token.type !== 'tag-start') {\n // comment or text\n nodes.push(token as ChildNode)\n cursor++\n continue\n }\n\n const tagToken = tokens[++cursor]\n cursor++\n const tagName = tagToken.content!.toLowerCase()\n if (token.close) {\n let index = stack.length\n let shouldRewind = false\n while (--index > -1) {\n if (stack[index].tagName === tagName) {\n shouldRewind = true\n break\n }\n }\n while (cursor < len) {\n const endToken = tokens[cursor]\n if (endToken.type !== 'tag-end') break\n cursor++\n }\n if (shouldRewind) {\n stack.splice(index)\n break\n } else {\n continue\n }\n }\n\n const isClosingTag = options.html!.closingElements.has(tagName)\n let shouldRewindToAutoClose = isClosingTag\n if (shouldRewindToAutoClose) {\n shouldRewindToAutoClose = !hasTerminalParent(tagName, stack)\n }\n\n if (shouldRewindToAutoClose) {\n let currentIndex = stack.length - 1\n while (currentIndex > 0) {\n if (tagName === stack[currentIndex].tagName) {\n stack.splice(currentIndex)\n const previousIndex = currentIndex - 1\n nodes = stack[previousIndex].children\n break\n }\n currentIndex = currentIndex - 1\n }\n }\n\n const attributes: string[] = []\n let attrToken: Token\n while (cursor < len) {\n attrToken = tokens[cursor]\n if (attrToken.type === 'tag-end') break\n attributes.push(attrToken.content!)\n cursor++\n }\n\n cursor++\n const children: Element[] = []\n const element: Element = {\n type: 'element',\n tagName: tagToken.content!,\n attributes,\n children\n }\n nodes.push(element)\n\n const hasChildren = !(attrToken!.close || options.html!.voidElements.has(tagName))\n if (hasChildren) {\n stack.push({ tagName, children } as any)\n const innerState: State = { tokens, cursor, stack }\n parse(innerState)\n cursor = innerState.cursor\n }\n }\n\n state.cursor = cursor\n}\n"],"names":[],"mappings":";;;;;;;AAiBA,MAAM,0BAA0B,GAAG;AACjC,IAAA,EAAE,EAAE,CAAC,IAAI,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.js","sources":["../../../src/dom-external/inner-html/parser.ts"],"sourcesContent":["import { isFunction } from '@tarojs/shared'\n\nimport { options } from '../../options'\nimport { Scaner, Token } from './scaner'\nimport StyleTagParser from './style'\nimport { getSpecialElementMapping, isBlockElements, isInlineElements, isMiniElements, isSpecialElements, specialMiniElements } from './tags'\nimport { unquote } from './utils'\n\nimport type { TaroDocument } from '../../dom/document'\nimport type { TaroElement } from '../../dom/element'\n\ninterface State {\n tokens: Token[]\n cursor: number\n stack: Element[]\n}\n\nconst closingTagAncestorBreakers = {\n li: ['ul', 'ol', 'menu'],\n dt: ['dl'],\n dd: ['dl'],\n tbody: ['table'],\n thead: ['table'],\n tfoot: ['table'],\n tr: ['table'],\n td: ['table']\n}\n\ninterface Node {\n type: string\n}\n\ninterface Comment extends Node {\n type: 'comment'\n content: string\n}\n\nexport interface Text extends Node {\n type: 'text'\n content: string\n}\n\nexport interface Element extends Node {\n type: 'element'\n tagName: string\n children: ChildNode[]\n attributes: string[]\n}\n\nexport interface ParsedTaroElement extends TaroElement {\n h5tagName?: string\n}\n\ntype ChildNode = Comment | Text | Element\n\nfunction hasTerminalParent (tagName: string, stack: Element[]) {\n const tagParents: undefined | string[] = closingTagAncestorBreakers[tagName]\n if (tagParents) {\n let currentIndex = stack.length - 1\n while (currentIndex >= 0) {\n const parentTagName = stack[currentIndex].tagName\n if (parentTagName === tagName) {\n break\n }\n if (tagParents && tagParents.includes(parentTagName!)) {\n return true\n }\n currentIndex--\n }\n }\n return false\n}\n\n/**\n * 将属性数组转换为属性对象\n * @param attributes 字符串数组,包含属性信息\n * @returns 属性对象,键为属性名,值为属性值或true\n */\nfunction attributesArray2Props (attributes: string[]): Record<string, string | true> {\n const props: Record<string, string | true> = {}\n for (let i = 0; i < attributes.length; i++) {\n const attr = attributes[i]\n const [key, value] = splitEqual(attr)\n props[key] = value == null ? true : unquote(value)\n }\n\n return props\n}\n\nfunction getTagName (tag: string, attributes: string[]) {\n if (options.html!.renderHTMLTag) {\n return tag\n }\n\n if (specialMiniElements[tag]) {\n return specialMiniElements[tag]\n } else if (isMiniElements(tag)) {\n return tag\n } else if (isBlockElements(tag)) {\n return 'view'\n } else if (isInlineElements(tag)) {\n return 'text'\n } else if (isSpecialElements(tag)) {\n // if it's special tag, the real tag is determined by the config mapping\n const mapping = getSpecialElementMapping(tag)\n const props = attributesArray2Props(attributes)\n\n if (mapping) {\n return mapping.mapName(props)\n }\n }\n\n return 'view'\n}\n\nfunction splitEqual (str: string) {\n const sep = '='\n const idx = str.indexOf(sep)\n if (idx === -1) return [str]\n const key = str.slice(0, idx).trim()\n const value = str.slice(idx + sep.length).trim()\n return [key, value]\n}\n\nfunction format (\n children: ChildNode[],\n document: TaroDocument,\n styleOptions: {\n styleTagParser: StyleTagParser\n descendantList: number[]\n },\n parent?: TaroElement\n) {\n return children\n .filter(child => {\n // 过滤注释和空文本节点\n if (child.type === 'comment') {\n return false\n } else if (child.type === 'text') {\n return child.content !== ''\n }\n return true\n })\n .map((child: Text | Element) => {\n // 文本节点\n if (child.type === 'text') {\n let text = document.createTextNode(child.content)\n if (isFunction(options.html!.transformText)) {\n text = options.html!.transformText(text, child)\n }\n parent?.appendChild(text)\n return text\n }\n // img标签,把width和height写入style,删除原有的width、height和style属性\n if (child.tagName === 'img') {\n let styleText = ''\n const toBeRemovedIndexs: number[] = []\n for (let i = 0; i < child.attributes.length; i++) {\n const attr = child.attributes[i]\n const [key, value] = splitEqual(attr)\n if (key === 'width' || key === 'height') {\n styleText += `${key}:${value};`\n toBeRemovedIndexs.push(i)\n } else if (key === 'style') {\n styleText = `${styleText}${value};`\n toBeRemovedIndexs.push(i)\n }\n }\n child.attributes = child.attributes.filter((_, index) => !toBeRemovedIndexs.includes(index))\n child.attributes.push(`style=${styleText.replace(/['\"]/g, '')}`)\n }\n\n const el: ParsedTaroElement = document.createElement(getTagName(child.tagName, child.attributes))\n el.h5tagName = child.tagName\n\n parent?.appendChild(el)\n\n if (!options.html!.renderHTMLTag) {\n el.className = `h5-${child.tagName}`\n }\n\n for (let i = 0; i < child.attributes.length; i++) {\n const attr = child.attributes[i]\n const [key, value] = splitEqual(attr)\n if (key === 'class') {\n el.className += ' ' + unquote(value)\n } else if (key[0] === 'o' && key[1] === 'n') {\n continue\n } else {\n el.setAttribute(key, value == null ? true : unquote(value))\n }\n }\n\n const { styleTagParser, descendantList } = styleOptions\n const list = descendantList.slice()\n const style = styleTagParser.matchStyle(child.tagName, el, list)\n\n el.setAttribute('style', style + el.style.cssText)\n // console.log('style, ', style)\n\n format(child.children, document, {\n styleTagParser,\n descendantList: list\n }, el)\n\n if (isFunction(options.html!.transformElement)) {\n return options.html!.transformElement(el, child)\n }\n\n return el\n })\n}\n\nexport function parser (html: string, document: TaroDocument) {\n const styleTagParser = new StyleTagParser()\n html = styleTagParser.extractStyle(html)\n\n const tokens = new Scaner(html).scan()\n\n const root: Element = { tagName: '', children: [], type: 'element', attributes: [] }\n\n const state = { tokens, options, cursor: 0, stack: [root] }\n parse(state)\n\n return format(root.children, document, {\n styleTagParser,\n descendantList: Array(styleTagParser.styles.length).fill(0)\n })\n}\n\nfunction parse (state: State) {\n const { tokens, stack } = state\n let { cursor } = state\n\n const len = tokens.length\n\n let nodes = stack[stack.length - 1].children\n\n while (cursor < len) {\n const token = tokens[cursor]\n if (token.type !== 'tag-start') {\n // comment or text\n nodes.push(token as ChildNode)\n cursor++\n continue\n }\n\n const tagToken = tokens[++cursor]\n cursor++\n const tagName = tagToken.content!.toLowerCase()\n if (token.close) {\n let index = stack.length\n let shouldRewind = false\n while (--index > -1) {\n if (stack[index].tagName === tagName) {\n shouldRewind = true\n break\n }\n }\n while (cursor < len) {\n const endToken = tokens[cursor]\n if (endToken.type !== 'tag-end') break\n cursor++\n }\n if (shouldRewind) {\n stack.splice(index)\n break\n } else {\n continue\n }\n }\n\n const isClosingTag = options.html!.closingElements.has(tagName)\n let shouldRewindToAutoClose = isClosingTag\n if (shouldRewindToAutoClose) {\n shouldRewindToAutoClose = !hasTerminalParent(tagName, stack)\n }\n\n if (shouldRewindToAutoClose) {\n let currentIndex = stack.length - 1\n while (currentIndex > 0) {\n if (tagName === stack[currentIndex].tagName) {\n stack.splice(currentIndex)\n const previousIndex = currentIndex - 1\n nodes = stack[previousIndex].children\n break\n }\n currentIndex = currentIndex - 1\n }\n }\n\n const attributes: string[] = []\n let attrToken: Token\n while (cursor < len) {\n attrToken = tokens[cursor]\n if (attrToken.type === 'tag-end') break\n attributes.push(attrToken.content!)\n cursor++\n }\n\n cursor++\n const children: Element[] = []\n const element: Element = {\n type: 'element',\n tagName: tagToken.content!,\n attributes,\n children\n }\n nodes.push(element)\n\n const hasChildren = !(attrToken!.close || options.html!.voidElements.has(tagName))\n if (hasChildren) {\n stack.push({ tagName, children } as any)\n const innerState: State = { tokens, cursor, stack }\n parse(innerState)\n cursor = innerState.cursor\n }\n }\n\n state.cursor = cursor\n}\n"],"names":[],"mappings":";;;;;;;AAiBA,MAAM,0BAA0B,GAAG;AACjC,IAAA,EAAE,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,CAAC;IACxB,EAAE,EAAE,CAAC,IAAI,CAAC;IACV,EAAE,EAAE,CAAC,IAAI,CAAC;IACV,KAAK,EAAE,CAAC,OAAO,CAAC;IAChB,KAAK,EAAE,CAAC,OAAO,CAAC;IAChB,KAAK,EAAE,CAAC,OAAO,CAAC;IAChB,EAAE,EAAE,CAAC,OAAO,CAAC;IACb,EAAE,EAAE,CAAC,OAAO,CAAC;CACd,CAAA;AA6BD,SAAS,iBAAiB,CAAE,OAAe,EAAE,KAAgB,EAAA;AAC3D,IAAA,MAAM,UAAU,GAAyB,0BAA0B,CAAC,OAAO,CAAC,CAAA;AAC5E,IAAA,IAAI,UAAU,EAAE;AACd,QAAA,IAAI,YAAY,GAAG,KAAK,CAAC,MAAM,GAAG,CAAC,CAAA;QACnC,OAAO,YAAY,IAAI,CAAC,EAAE;YACxB,MAAM,aAAa,GAAG,KAAK,CAAC,YAAY,CAAC,CAAC,O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F,KAAA;AAED,IAAA,KAAK,CAAC,MAAM,GAAG,MAAM,CAAA;AACvB;;;;"}
|
|
@@ -3,7 +3,12 @@ declare const specialMiniElements: {
|
|
|
3
3
|
img: string;
|
|
4
4
|
iframe: string;
|
|
5
5
|
};
|
|
6
|
+
interface SpecialMap {
|
|
7
|
+
mapName: (props: Record<string, string | boolean>) => string;
|
|
8
|
+
}
|
|
9
|
+
declare const getSpecialElementMapping: (tag: string, expectsLowerCase?: boolean) => SpecialMap | undefined;
|
|
6
10
|
declare const isMiniElements: (key: string) => boolean;
|
|
7
11
|
declare const isInlineElements: (key: string) => boolean;
|
|
8
12
|
declare const isBlockElements: (key: string) => boolean;
|
|
9
|
-
|
|
13
|
+
declare const isSpecialElements: (key: string) => boolean;
|
|
14
|
+
export { makeMap, specialMiniElements, getSpecialElementMapping, isMiniElements, isInlineElements, isBlockElements, isSpecialElements };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { internalComponents } from '@tarojs/shared';
|
|
1
|
+
import { isString, internalComponents } from '@tarojs/shared';
|
|
2
2
|
|
|
3
3
|
function makeMap(str, expectsLowerCase) {
|
|
4
4
|
const map = Object.create(null);
|
|
@@ -12,15 +12,30 @@ const specialMiniElements = {
|
|
|
12
12
|
img: 'image',
|
|
13
13
|
iframe: 'web-view'
|
|
14
14
|
};
|
|
15
|
+
const specialElements = new Map([
|
|
16
|
+
['a', {
|
|
17
|
+
mapName(props) {
|
|
18
|
+
if (props.as && isString(props.as))
|
|
19
|
+
return props.as.toLowerCase();
|
|
20
|
+
return !props.href || isString(props.href) && (/^javascript/.test(props.href)) ? 'view' : 'navigator';
|
|
21
|
+
}
|
|
22
|
+
}],
|
|
23
|
+
]);
|
|
24
|
+
const getSpecialElementMapping = (tag, expectsLowerCase = true) => {
|
|
25
|
+
tag = expectsLowerCase ? tag.toLowerCase() : tag;
|
|
26
|
+
return specialElements.get(tag);
|
|
27
|
+
};
|
|
15
28
|
const internalCompsList = Object.keys(internalComponents)
|
|
16
29
|
.map(i => i.toLowerCase())
|
|
17
30
|
.join(',');
|
|
18
31
|
// https://developers.weixin.qq.com/miniprogram/dev/component
|
|
19
32
|
const isMiniElements = makeMap(internalCompsList, true);
|
|
20
33
|
// https://developer.mozilla.org/en-US/docs/Web/HTML/Inline_elements
|
|
21
|
-
const isInlineElements = makeMap('
|
|
34
|
+
const isInlineElements = makeMap('i,abbr,iframe,select,acronym,slot,small,span,bdi,kbd,strong,big,map,sub,sup,br,mark,mark,meter,template,canvas,textarea,cite,object,time,code,output,u,data,picture,tt,datalist,var,dfn,del,q,em,s,embed,samp,b', true);
|
|
22
35
|
// https://developer.mozilla.org/en-US/docs/Web/HTML/Block-level_elements
|
|
23
36
|
const isBlockElements = makeMap('address,fieldset,li,article,figcaption,main,aside,figure,nav,blockquote,footer,ol,details,form,p,dialog,h1,h2,h3,h4,h5,h6,pre,dd,header,section,div,hgroup,table,dl,hr,ul,dt', true);
|
|
37
|
+
// specialElements
|
|
38
|
+
const isSpecialElements = makeMap('a', true);
|
|
24
39
|
|
|
25
|
-
export { isBlockElements, isInlineElements, isMiniElements, makeMap, specialMiniElements };
|
|
40
|
+
export { getSpecialElementMapping, isBlockElements, isInlineElements, isMiniElements, isSpecialElements, makeMap, specialMiniElements };
|
|
26
41
|
//# sourceMappingURL=tags.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tags.js","sources":["../../../src/dom-external/inner-html/tags.ts"],"sourcesContent":["import { internalComponents } from '@tarojs/shared'\n\nexport function makeMap (\n str: string,\n expectsLowerCase?: boolean\n): (key: string) => boolean {\n const map: Record<string, boolean> = Object.create(null)\n const list: Array<string> = str.split(',')\n for (let i = 0; i < list.length; i++) {\n map[list[i]] = true\n }\n return expectsLowerCase ? val => !!map[val.toLowerCase()] : val => !!map[val]\n}\n\nexport const specialMiniElements = {\n img: 'image',\n iframe: 'web-view'\n}\n\nconst internalCompsList = Object.keys(internalComponents)\n .map(i => i.toLowerCase())\n .join(',')\n\n// https://developers.weixin.qq.com/miniprogram/dev/component\nexport const isMiniElements = makeMap(internalCompsList, true)\n\n// https://developer.mozilla.org/en-US/docs/Web/HTML/Inline_elements\nexport const isInlineElements = makeMap('
|
|
1
|
+
{"version":3,"file":"tags.js","sources":["../../../src/dom-external/inner-html/tags.ts"],"sourcesContent":["import { internalComponents, isString } from '@tarojs/shared'\n\nexport function makeMap (\n str: string,\n expectsLowerCase?: boolean\n): (key: string) => boolean {\n const map: Record<string, boolean> = Object.create(null)\n const list: Array<string> = str.split(',')\n for (let i = 0; i < list.length; i++) {\n map[list[i]] = true\n }\n return expectsLowerCase ? val => !!map[val.toLowerCase()] : val => !!map[val]\n}\n\nexport const specialMiniElements = {\n img: 'image',\n iframe: 'web-view'\n}\n\ninterface SpecialMap {\n mapName: (props: Record<string, string | boolean>) => string\n}\n\nconst specialElements = new Map<string, SpecialMap>([\n ['a', {\n mapName (props) {\n if (props.as && isString(props.as)) return props.as.toLowerCase()\n return !props.href || isString(props.href) && (/^javascript/.test(props.href)) ? 'view' : 'navigator'\n }\n }],\n])\n\nexport const getSpecialElementMapping = (tag: string, expectsLowerCase:boolean = true) => {\n tag = expectsLowerCase ? tag.toLowerCase() : tag\n return specialElements.get(tag)\n}\n\n\nconst internalCompsList = Object.keys(internalComponents)\n .map(i => i.toLowerCase())\n .join(',')\n\n// https://developers.weixin.qq.com/miniprogram/dev/component\nexport const isMiniElements = makeMap(internalCompsList, true)\n\n// https://developer.mozilla.org/en-US/docs/Web/HTML/Inline_elements\nexport const isInlineElements = makeMap('i,abbr,iframe,select,acronym,slot,small,span,bdi,kbd,strong,big,map,sub,sup,br,mark,mark,meter,template,canvas,textarea,cite,object,time,code,output,u,data,picture,tt,datalist,var,dfn,del,q,em,s,embed,samp,b', true)\n\n// https://developer.mozilla.org/en-US/docs/Web/HTML/Block-level_elements\nexport const isBlockElements = makeMap('address,fieldset,li,article,figcaption,main,aside,figure,nav,blockquote,footer,ol,details,form,p,dialog,h1,h2,h3,h4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W,EAAE,gBAAA,GAA2B,IAAI,KAAI;AACvF,IAAA,GAAG,GAAG,gBAAgB,GAAG,GAAG,CAAC,WAAW,EAAE,GAAG,GAAG,CAAA;AAChD,IAAA,OAAO,eAAe,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;AACjC,EAAC;AAGD,MAAM,iBAAiB,GAAG,MAAM,CAAC,IAAI,CAAC,kBAAkB,CAAC;KACtD,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,WAAW,EAAE,CAAC;KACzB,IAAI,CAAC,GAAG,CAAC,CAAA;AAEZ;AACa,MAAA,cAAc,GAAG,OAAO,CAAC,iBAAiB,EAAE,IAAI,EAAC;AAE9D;AACa,MAAA,gBAAgB,GAAG,OAAO,CAAC,iNAAiN,EAAE,IAAI,EAAC;AAEhQ;AACa,MAAA,eAAe,GAAG,OAAO,CAAC,8KAA8K,EAAE,IAAI,EAAC;AAE5N;AACa,MAAA,iBAAiB,GAAG,OAAO,CAAC,GAAG,EAAE,IAAI;;;;"}
|
package/dist/index.cjs.js
CHANGED
|
@@ -2105,15 +2105,30 @@ const specialMiniElements = {
|
|
|
2105
2105
|
img: 'image',
|
|
2106
2106
|
iframe: 'web-view'
|
|
2107
2107
|
};
|
|
2108
|
+
const specialElements = new Map([
|
|
2109
|
+
['a', {
|
|
2110
|
+
mapName(props) {
|
|
2111
|
+
if (props.as && shared.isString(props.as))
|
|
2112
|
+
return props.as.toLowerCase();
|
|
2113
|
+
return !props.href || shared.isString(props.href) && (/^javascript/.test(props.href)) ? 'view' : 'navigator';
|
|
2114
|
+
}
|
|
2115
|
+
}],
|
|
2116
|
+
]);
|
|
2117
|
+
const getSpecialElementMapping = (tag, expectsLowerCase = true) => {
|
|
2118
|
+
tag = expectsLowerCase ? tag.toLowerCase() : tag;
|
|
2119
|
+
return specialElements.get(tag);
|
|
2120
|
+
};
|
|
2108
2121
|
const internalCompsList = Object.keys(shared.internalComponents)
|
|
2109
2122
|
.map(i => i.toLowerCase())
|
|
2110
2123
|
.join(',');
|
|
2111
2124
|
// https://developers.weixin.qq.com/miniprogram/dev/component
|
|
2112
2125
|
const isMiniElements = makeMap(internalCompsList, true);
|
|
2113
2126
|
// https://developer.mozilla.org/en-US/docs/Web/HTML/Inline_elements
|
|
2114
|
-
const isInlineElements = makeMap('
|
|
2127
|
+
const isInlineElements = makeMap('i,abbr,iframe,select,acronym,slot,small,span,bdi,kbd,strong,big,map,sub,sup,br,mark,mark,meter,template,canvas,textarea,cite,object,time,code,output,u,data,picture,tt,datalist,var,dfn,del,q,em,s,embed,samp,b', true);
|
|
2115
2128
|
// https://developer.mozilla.org/en-US/docs/Web/HTML/Block-level_elements
|
|
2116
2129
|
const isBlockElements = makeMap('address,fieldset,li,article,figcaption,main,aside,figure,nav,blockquote,footer,ol,details,form,p,dialog,h1,h2,h3,h4,h5,h6,pre,dd,header,section,div,hgroup,table,dl,hr,ul,dt', true);
|
|
2130
|
+
// specialElements
|
|
2131
|
+
const isSpecialElements = makeMap('a', true);
|
|
2117
2132
|
|
|
2118
2133
|
const closingTagAncestorBreakers = {
|
|
2119
2134
|
li: ['ul', 'ol', 'menu'],
|
|
@@ -2142,7 +2157,21 @@ function hasTerminalParent(tagName, stack) {
|
|
|
2142
2157
|
}
|
|
2143
2158
|
return false;
|
|
2144
2159
|
}
|
|
2145
|
-
|
|
2160
|
+
/**
|
|
2161
|
+
* 将属性数组转换为属性对象
|
|
2162
|
+
* @param attributes 字符串数组,包含属性信息
|
|
2163
|
+
* @returns 属性对象,键为属性名,值为属性值或true
|
|
2164
|
+
*/
|
|
2165
|
+
function attributesArray2Props(attributes) {
|
|
2166
|
+
const props = {};
|
|
2167
|
+
for (let i = 0; i < attributes.length; i++) {
|
|
2168
|
+
const attr = attributes[i];
|
|
2169
|
+
const [key, value] = splitEqual(attr);
|
|
2170
|
+
props[key] = value == null ? true : unquote(value);
|
|
2171
|
+
}
|
|
2172
|
+
return props;
|
|
2173
|
+
}
|
|
2174
|
+
function getTagName(tag, attributes) {
|
|
2146
2175
|
if (options.html.renderHTMLTag) {
|
|
2147
2176
|
return tag;
|
|
2148
2177
|
}
|
|
@@ -2158,6 +2187,14 @@ function getTagName(tag) {
|
|
|
2158
2187
|
else if (isInlineElements(tag)) {
|
|
2159
2188
|
return 'text';
|
|
2160
2189
|
}
|
|
2190
|
+
else if (isSpecialElements(tag)) {
|
|
2191
|
+
// if it's special tag, the real tag is determined by the config mapping
|
|
2192
|
+
const mapping = getSpecialElementMapping(tag);
|
|
2193
|
+
const props = attributesArray2Props(attributes);
|
|
2194
|
+
if (mapping) {
|
|
2195
|
+
return mapping.mapName(props);
|
|
2196
|
+
}
|
|
2197
|
+
}
|
|
2161
2198
|
return 'view';
|
|
2162
2199
|
}
|
|
2163
2200
|
function splitEqual(str) {
|
|
@@ -2191,7 +2228,26 @@ function format(children, document, styleOptions, parent) {
|
|
|
2191
2228
|
parent === null || parent === void 0 ? void 0 : parent.appendChild(text);
|
|
2192
2229
|
return text;
|
|
2193
2230
|
}
|
|
2194
|
-
|
|
2231
|
+
// img标签,把width和height写入style,删除原有的width、height和style属性
|
|
2232
|
+
if (child.tagName === 'img') {
|
|
2233
|
+
let styleText = '';
|
|
2234
|
+
const toBeRemovedIndexs = [];
|
|
2235
|
+
for (let i = 0; i < child.attributes.length; i++) {
|
|
2236
|
+
const attr = child.attributes[i];
|
|
2237
|
+
const [key, value] = splitEqual(attr);
|
|
2238
|
+
if (key === 'width' || key === 'height') {
|
|
2239
|
+
styleText += `${key}:${value};`;
|
|
2240
|
+
toBeRemovedIndexs.push(i);
|
|
2241
|
+
}
|
|
2242
|
+
else if (key === 'style') {
|
|
2243
|
+
styleText = `${styleText}${value};`;
|
|
2244
|
+
toBeRemovedIndexs.push(i);
|
|
2245
|
+
}
|
|
2246
|
+
}
|
|
2247
|
+
child.attributes = child.attributes.filter((_, index) => !toBeRemovedIndexs.includes(index));
|
|
2248
|
+
child.attributes.push(`style=${styleText.replace(/['"]/g, '')}`);
|
|
2249
|
+
}
|
|
2250
|
+
const el = document.createElement(getTagName(child.tagName, child.attributes));
|
|
2195
2251
|
el.h5tagName = child.tagName;
|
|
2196
2252
|
parent === null || parent === void 0 ? void 0 : parent.appendChild(el);
|
|
2197
2253
|
if (!options.html.renderHTMLTag) {
|