Node-Red configuration
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

compiler-dom.esm-bundler.js 16KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505
  1. /**
  2. * @vue/compiler-dom v3.4.38
  3. * (c) 2018-present Yuxi (Evan) You and Vue contributors
  4. * @license MIT
  5. **/
  6. import { registerRuntimeHelpers, createSimpleExpression, createCompilerError, createObjectProperty, getConstantType, createCallExpression, TO_DISPLAY_STRING, transformModel as transformModel$1, findProp, hasDynamicKeyVBind, findDir, isStaticArgOf, transformOn as transformOn$1, isStaticExp, createCompoundExpression, checkCompatEnabled, noopDirectiveTransform, baseCompile, baseParse } from '@vue/compiler-core';
  7. export * from '@vue/compiler-core';
  8. import { isVoidTag, isHTMLTag, isSVGTag, isMathMLTag, parseStringStyle, capitalize, makeMap, extend } from '@vue/shared';
  9. const V_MODEL_RADIO = Symbol(!!(process.env.NODE_ENV !== "production") ? `vModelRadio` : ``);
  10. const V_MODEL_CHECKBOX = Symbol(!!(process.env.NODE_ENV !== "production") ? `vModelCheckbox` : ``);
  11. const V_MODEL_TEXT = Symbol(!!(process.env.NODE_ENV !== "production") ? `vModelText` : ``);
  12. const V_MODEL_SELECT = Symbol(!!(process.env.NODE_ENV !== "production") ? `vModelSelect` : ``);
  13. const V_MODEL_DYNAMIC = Symbol(!!(process.env.NODE_ENV !== "production") ? `vModelDynamic` : ``);
  14. const V_ON_WITH_MODIFIERS = Symbol(!!(process.env.NODE_ENV !== "production") ? `vOnModifiersGuard` : ``);
  15. const V_ON_WITH_KEYS = Symbol(!!(process.env.NODE_ENV !== "production") ? `vOnKeysGuard` : ``);
  16. const V_SHOW = Symbol(!!(process.env.NODE_ENV !== "production") ? `vShow` : ``);
  17. const TRANSITION = Symbol(!!(process.env.NODE_ENV !== "production") ? `Transition` : ``);
  18. const TRANSITION_GROUP = Symbol(!!(process.env.NODE_ENV !== "production") ? `TransitionGroup` : ``);
  19. registerRuntimeHelpers({
  20. [V_MODEL_RADIO]: `vModelRadio`,
  21. [V_MODEL_CHECKBOX]: `vModelCheckbox`,
  22. [V_MODEL_TEXT]: `vModelText`,
  23. [V_MODEL_SELECT]: `vModelSelect`,
  24. [V_MODEL_DYNAMIC]: `vModelDynamic`,
  25. [V_ON_WITH_MODIFIERS]: `withModifiers`,
  26. [V_ON_WITH_KEYS]: `withKeys`,
  27. [V_SHOW]: `vShow`,
  28. [TRANSITION]: `Transition`,
  29. [TRANSITION_GROUP]: `TransitionGroup`
  30. });
  31. let decoder;
  32. function decodeHtmlBrowser(raw, asAttr = false) {
  33. if (!decoder) {
  34. decoder = document.createElement("div");
  35. }
  36. if (asAttr) {
  37. decoder.innerHTML = `<div foo="${raw.replace(/"/g, "&quot;")}">`;
  38. return decoder.children[0].getAttribute("foo");
  39. } else {
  40. decoder.innerHTML = raw;
  41. return decoder.textContent;
  42. }
  43. }
  44. const parserOptions = {
  45. parseMode: "html",
  46. isVoidTag,
  47. isNativeTag: (tag) => isHTMLTag(tag) || isSVGTag(tag) || isMathMLTag(tag),
  48. isPreTag: (tag) => tag === "pre",
  49. decodeEntities: decodeHtmlBrowser ,
  50. isBuiltInComponent: (tag) => {
  51. if (tag === "Transition" || tag === "transition") {
  52. return TRANSITION;
  53. } else if (tag === "TransitionGroup" || tag === "transition-group") {
  54. return TRANSITION_GROUP;
  55. }
  56. },
  57. // https://html.spec.whatwg.org/multipage/parsing.html#tree-construction-dispatcher
  58. getNamespace(tag, parent, rootNamespace) {
  59. let ns = parent ? parent.ns : rootNamespace;
  60. if (parent && ns === 2) {
  61. if (parent.tag === "annotation-xml") {
  62. if (tag === "svg") {
  63. return 1;
  64. }
  65. if (parent.props.some(
  66. (a) => a.type === 6 && a.name === "encoding" && a.value != null && (a.value.content === "text/html" || a.value.content === "application/xhtml+xml")
  67. )) {
  68. ns = 0;
  69. }
  70. } else if (/^m(?:[ions]|text)$/.test(parent.tag) && tag !== "mglyph" && tag !== "malignmark") {
  71. ns = 0;
  72. }
  73. } else if (parent && ns === 1) {
  74. if (parent.tag === "foreignObject" || parent.tag === "desc" || parent.tag === "title") {
  75. ns = 0;
  76. }
  77. }
  78. if (ns === 0) {
  79. if (tag === "svg") {
  80. return 1;
  81. }
  82. if (tag === "math") {
  83. return 2;
  84. }
  85. }
  86. return ns;
  87. }
  88. };
  89. const transformStyle = (node) => {
  90. if (node.type === 1) {
  91. node.props.forEach((p, i) => {
  92. if (p.type === 6 && p.name === "style" && p.value) {
  93. node.props[i] = {
  94. type: 7,
  95. name: `bind`,
  96. arg: createSimpleExpression(`style`, true, p.loc),
  97. exp: parseInlineCSS(p.value.content, p.loc),
  98. modifiers: [],
  99. loc: p.loc
  100. };
  101. }
  102. });
  103. }
  104. };
  105. const parseInlineCSS = (cssText, loc) => {
  106. const normalized = parseStringStyle(cssText);
  107. return createSimpleExpression(
  108. JSON.stringify(normalized),
  109. false,
  110. loc,
  111. 3
  112. );
  113. };
  114. function createDOMCompilerError(code, loc) {
  115. return createCompilerError(
  116. code,
  117. loc,
  118. !!(process.env.NODE_ENV !== "production") || false ? DOMErrorMessages : void 0
  119. );
  120. }
  121. const DOMErrorCodes = {
  122. "X_V_HTML_NO_EXPRESSION": 53,
  123. "53": "X_V_HTML_NO_EXPRESSION",
  124. "X_V_HTML_WITH_CHILDREN": 54,
  125. "54": "X_V_HTML_WITH_CHILDREN",
  126. "X_V_TEXT_NO_EXPRESSION": 55,
  127. "55": "X_V_TEXT_NO_EXPRESSION",
  128. "X_V_TEXT_WITH_CHILDREN": 56,
  129. "56": "X_V_TEXT_WITH_CHILDREN",
  130. "X_V_MODEL_ON_INVALID_ELEMENT": 57,
  131. "57": "X_V_MODEL_ON_INVALID_ELEMENT",
  132. "X_V_MODEL_ARG_ON_ELEMENT": 58,
  133. "58": "X_V_MODEL_ARG_ON_ELEMENT",
  134. "X_V_MODEL_ON_FILE_INPUT_ELEMENT": 59,
  135. "59": "X_V_MODEL_ON_FILE_INPUT_ELEMENT",
  136. "X_V_MODEL_UNNECESSARY_VALUE": 60,
  137. "60": "X_V_MODEL_UNNECESSARY_VALUE",
  138. "X_V_SHOW_NO_EXPRESSION": 61,
  139. "61": "X_V_SHOW_NO_EXPRESSION",
  140. "X_TRANSITION_INVALID_CHILDREN": 62,
  141. "62": "X_TRANSITION_INVALID_CHILDREN",
  142. "X_IGNORED_SIDE_EFFECT_TAG": 63,
  143. "63": "X_IGNORED_SIDE_EFFECT_TAG",
  144. "__EXTEND_POINT__": 64,
  145. "64": "__EXTEND_POINT__"
  146. };
  147. const DOMErrorMessages = {
  148. [53]: `v-html is missing expression.`,
  149. [54]: `v-html will override element children.`,
  150. [55]: `v-text is missing expression.`,
  151. [56]: `v-text will override element children.`,
  152. [57]: `v-model can only be used on <input>, <textarea> and <select> elements.`,
  153. [58]: `v-model argument is not supported on plain elements.`,
  154. [59]: `v-model cannot be used on file inputs since they are read-only. Use a v-on:change listener instead.`,
  155. [60]: `Unnecessary value binding used alongside v-model. It will interfere with v-model's behavior.`,
  156. [61]: `v-show is missing expression.`,
  157. [62]: `<Transition> expects exactly one child element or component.`,
  158. [63]: `Tags with side effect (<script> and <style>) are ignored in client component templates.`
  159. };
  160. const transformVHtml = (dir, node, context) => {
  161. const { exp, loc } = dir;
  162. if (!exp) {
  163. context.onError(
  164. createDOMCompilerError(53, loc)
  165. );
  166. }
  167. if (node.children.length) {
  168. context.onError(
  169. createDOMCompilerError(54, loc)
  170. );
  171. node.children.length = 0;
  172. }
  173. return {
  174. props: [
  175. createObjectProperty(
  176. createSimpleExpression(`innerHTML`, true, loc),
  177. exp || createSimpleExpression("", true)
  178. )
  179. ]
  180. };
  181. };
  182. const transformVText = (dir, node, context) => {
  183. const { exp, loc } = dir;
  184. if (!exp) {
  185. context.onError(
  186. createDOMCompilerError(55, loc)
  187. );
  188. }
  189. if (node.children.length) {
  190. context.onError(
  191. createDOMCompilerError(56, loc)
  192. );
  193. node.children.length = 0;
  194. }
  195. return {
  196. props: [
  197. createObjectProperty(
  198. createSimpleExpression(`textContent`, true),
  199. exp ? getConstantType(exp, context) > 0 ? exp : createCallExpression(
  200. context.helperString(TO_DISPLAY_STRING),
  201. [exp],
  202. loc
  203. ) : createSimpleExpression("", true)
  204. )
  205. ]
  206. };
  207. };
  208. const transformModel = (dir, node, context) => {
  209. const baseResult = transformModel$1(dir, node, context);
  210. if (!baseResult.props.length || node.tagType === 1) {
  211. return baseResult;
  212. }
  213. if (dir.arg) {
  214. context.onError(
  215. createDOMCompilerError(
  216. 58,
  217. dir.arg.loc
  218. )
  219. );
  220. }
  221. function checkDuplicatedValue() {
  222. const value = findDir(node, "bind");
  223. if (value && isStaticArgOf(value.arg, "value")) {
  224. context.onError(
  225. createDOMCompilerError(
  226. 60,
  227. value.loc
  228. )
  229. );
  230. }
  231. }
  232. const { tag } = node;
  233. const isCustomElement = context.isCustomElement(tag);
  234. if (tag === "input" || tag === "textarea" || tag === "select" || isCustomElement) {
  235. let directiveToUse = V_MODEL_TEXT;
  236. let isInvalidType = false;
  237. if (tag === "input" || isCustomElement) {
  238. const type = findProp(node, `type`);
  239. if (type) {
  240. if (type.type === 7) {
  241. directiveToUse = V_MODEL_DYNAMIC;
  242. } else if (type.value) {
  243. switch (type.value.content) {
  244. case "radio":
  245. directiveToUse = V_MODEL_RADIO;
  246. break;
  247. case "checkbox":
  248. directiveToUse = V_MODEL_CHECKBOX;
  249. break;
  250. case "file":
  251. isInvalidType = true;
  252. context.onError(
  253. createDOMCompilerError(
  254. 59,
  255. dir.loc
  256. )
  257. );
  258. break;
  259. default:
  260. !!(process.env.NODE_ENV !== "production") && checkDuplicatedValue();
  261. break;
  262. }
  263. }
  264. } else if (hasDynamicKeyVBind(node)) {
  265. directiveToUse = V_MODEL_DYNAMIC;
  266. } else {
  267. !!(process.env.NODE_ENV !== "production") && checkDuplicatedValue();
  268. }
  269. } else if (tag === "select") {
  270. directiveToUse = V_MODEL_SELECT;
  271. } else {
  272. !!(process.env.NODE_ENV !== "production") && checkDuplicatedValue();
  273. }
  274. if (!isInvalidType) {
  275. baseResult.needRuntime = context.helper(directiveToUse);
  276. }
  277. } else {
  278. context.onError(
  279. createDOMCompilerError(
  280. 57,
  281. dir.loc
  282. )
  283. );
  284. }
  285. baseResult.props = baseResult.props.filter(
  286. (p) => !(p.key.type === 4 && p.key.content === "modelValue")
  287. );
  288. return baseResult;
  289. };
  290. const isEventOptionModifier = /* @__PURE__ */ makeMap(`passive,once,capture`);
  291. const isNonKeyModifier = /* @__PURE__ */ makeMap(
  292. // event propagation management
  293. `stop,prevent,self,ctrl,shift,alt,meta,exact,middle`
  294. );
  295. const maybeKeyModifier = /* @__PURE__ */ makeMap("left,right");
  296. const isKeyboardEvent = /* @__PURE__ */ makeMap(
  297. `onkeyup,onkeydown,onkeypress`,
  298. true
  299. );
  300. const resolveModifiers = (key, modifiers, context, loc) => {
  301. const keyModifiers = [];
  302. const nonKeyModifiers = [];
  303. const eventOptionModifiers = [];
  304. for (let i = 0; i < modifiers.length; i++) {
  305. const modifier = modifiers[i];
  306. if (modifier === "native" && checkCompatEnabled(
  307. "COMPILER_V_ON_NATIVE",
  308. context,
  309. loc
  310. )) {
  311. eventOptionModifiers.push(modifier);
  312. } else if (isEventOptionModifier(modifier)) {
  313. eventOptionModifiers.push(modifier);
  314. } else {
  315. if (maybeKeyModifier(modifier)) {
  316. if (isStaticExp(key)) {
  317. if (isKeyboardEvent(key.content)) {
  318. keyModifiers.push(modifier);
  319. } else {
  320. nonKeyModifiers.push(modifier);
  321. }
  322. } else {
  323. keyModifiers.push(modifier);
  324. nonKeyModifiers.push(modifier);
  325. }
  326. } else {
  327. if (isNonKeyModifier(modifier)) {
  328. nonKeyModifiers.push(modifier);
  329. } else {
  330. keyModifiers.push(modifier);
  331. }
  332. }
  333. }
  334. }
  335. return {
  336. keyModifiers,
  337. nonKeyModifiers,
  338. eventOptionModifiers
  339. };
  340. };
  341. const transformClick = (key, event) => {
  342. const isStaticClick = isStaticExp(key) && key.content.toLowerCase() === "onclick";
  343. return isStaticClick ? createSimpleExpression(event, true) : key.type !== 4 ? createCompoundExpression([
  344. `(`,
  345. key,
  346. `) === "onClick" ? "${event}" : (`,
  347. key,
  348. `)`
  349. ]) : key;
  350. };
  351. const transformOn = (dir, node, context) => {
  352. return transformOn$1(dir, node, context, (baseResult) => {
  353. const { modifiers } = dir;
  354. if (!modifiers.length) return baseResult;
  355. let { key, value: handlerExp } = baseResult.props[0];
  356. const { keyModifiers, nonKeyModifiers, eventOptionModifiers } = resolveModifiers(key, modifiers, context, dir.loc);
  357. if (nonKeyModifiers.includes("right")) {
  358. key = transformClick(key, `onContextmenu`);
  359. }
  360. if (nonKeyModifiers.includes("middle")) {
  361. key = transformClick(key, `onMouseup`);
  362. }
  363. if (nonKeyModifiers.length) {
  364. handlerExp = createCallExpression(context.helper(V_ON_WITH_MODIFIERS), [
  365. handlerExp,
  366. JSON.stringify(nonKeyModifiers)
  367. ]);
  368. }
  369. if (keyModifiers.length && // if event name is dynamic, always wrap with keys guard
  370. (!isStaticExp(key) || isKeyboardEvent(key.content))) {
  371. handlerExp = createCallExpression(context.helper(V_ON_WITH_KEYS), [
  372. handlerExp,
  373. JSON.stringify(keyModifiers)
  374. ]);
  375. }
  376. if (eventOptionModifiers.length) {
  377. const modifierPostfix = eventOptionModifiers.map(capitalize).join("");
  378. key = isStaticExp(key) ? createSimpleExpression(`${key.content}${modifierPostfix}`, true) : createCompoundExpression([`(`, key, `) + "${modifierPostfix}"`]);
  379. }
  380. return {
  381. props: [createObjectProperty(key, handlerExp)]
  382. };
  383. });
  384. };
  385. const transformShow = (dir, node, context) => {
  386. const { exp, loc } = dir;
  387. if (!exp) {
  388. context.onError(
  389. createDOMCompilerError(61, loc)
  390. );
  391. }
  392. return {
  393. props: [],
  394. needRuntime: context.helper(V_SHOW)
  395. };
  396. };
  397. const transformTransition = (node, context) => {
  398. if (node.type === 1 && node.tagType === 1) {
  399. const component = context.isBuiltInComponent(node.tag);
  400. if (component === TRANSITION) {
  401. return () => {
  402. if (!node.children.length) {
  403. return;
  404. }
  405. if (hasMultipleChildren(node)) {
  406. context.onError(
  407. createDOMCompilerError(
  408. 62,
  409. {
  410. start: node.children[0].loc.start,
  411. end: node.children[node.children.length - 1].loc.end,
  412. source: ""
  413. }
  414. )
  415. );
  416. }
  417. const child = node.children[0];
  418. if (child.type === 1) {
  419. for (const p of child.props) {
  420. if (p.type === 7 && p.name === "show") {
  421. node.props.push({
  422. type: 6,
  423. name: "persisted",
  424. nameLoc: node.loc,
  425. value: void 0,
  426. loc: node.loc
  427. });
  428. }
  429. }
  430. }
  431. };
  432. }
  433. }
  434. };
  435. function hasMultipleChildren(node) {
  436. const children = node.children = node.children.filter(
  437. (c) => c.type !== 3 && !(c.type === 2 && !c.content.trim())
  438. );
  439. const child = children[0];
  440. return children.length !== 1 || child.type === 11 || child.type === 9 && child.branches.some(hasMultipleChildren);
  441. }
  442. const ignoreSideEffectTags = (node, context) => {
  443. if (node.type === 1 && node.tagType === 0 && (node.tag === "script" || node.tag === "style")) {
  444. !!(process.env.NODE_ENV !== "production") && context.onError(
  445. createDOMCompilerError(
  446. 63,
  447. node.loc
  448. )
  449. );
  450. context.removeNode();
  451. }
  452. };
  453. const DOMNodeTransforms = [
  454. transformStyle,
  455. ...!!(process.env.NODE_ENV !== "production") ? [transformTransition] : []
  456. ];
  457. const DOMDirectiveTransforms = {
  458. cloak: noopDirectiveTransform,
  459. html: transformVHtml,
  460. text: transformVText,
  461. model: transformModel,
  462. // override compiler-core
  463. on: transformOn,
  464. // override compiler-core
  465. show: transformShow
  466. };
  467. function compile(src, options = {}) {
  468. return baseCompile(
  469. src,
  470. extend({}, parserOptions, options, {
  471. nodeTransforms: [
  472. // ignore <script> and <tag>
  473. // this is not put inside DOMNodeTransforms because that list is used
  474. // by compiler-ssr to generate vnode fallback branches
  475. ignoreSideEffectTags,
  476. ...DOMNodeTransforms,
  477. ...options.nodeTransforms || []
  478. ],
  479. directiveTransforms: extend(
  480. {},
  481. DOMDirectiveTransforms,
  482. options.directiveTransforms || {}
  483. ),
  484. transformHoist: null
  485. })
  486. );
  487. }
  488. function parse(template, options = {}) {
  489. return baseParse(template, extend({}, parserOptions, options));
  490. }
  491. export { DOMDirectiveTransforms, DOMErrorCodes, DOMErrorMessages, DOMNodeTransforms, TRANSITION, TRANSITION_GROUP, V_MODEL_CHECKBOX, V_MODEL_DYNAMIC, V_MODEL_RADIO, V_MODEL_SELECT, V_MODEL_TEXT, V_ON_WITH_KEYS, V_ON_WITH_MODIFIERS, V_SHOW, compile, createDOMCompilerError, parse, parserOptions, transformStyle };