@visactor/vrender-kits
Version:
## Description
62 lines (53 loc) • 2.38 kB
JavaScript
var __rest = this && this.__rest || function(s, e) {
var t = {};
for (var p in s) Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0 && (t[p] = s[p]);
if (null != s && "function" == typeof Object.getOwnPropertySymbols) {
var i = 0;
for (p = Object.getOwnPropertySymbols(s); i < p.length; i++) e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]) && (t[p[i]] = s[p[i]]);
}
return t;
};
import { isArray, isString } from "@visactor/vutils";
import { Group, graphicCreator } from "@visactor/vrender-core";
import { REACT_TO_CANOPUS_EVENTS } from "./graphicType";
function flatten(list, out) {
if (isArray(list)) return list.forEach((i => flatten(i, out)));
out.push(list);
}
export function jsx(type, config, ...children) {
const _a = config || {}, {key: key, name: name, id: id, attribute: attribute, stateProxy: stateProxy, animation: animation, timeline: timeline} = _a, props = __rest(_a, [ "key", "name", "id", "attribute", "stateProxy", "animation", "timeline" ]);
let c = type;
isString(type) && (c = graphicCreator[type]);
const childrenList = [];
children.length && flatten(1 === children.length ? children[0] : children, childrenList);
const g = "Group" === c.name ? new c(attribute) : c(config);
if (parseToGraphic(g, childrenList, props), stateProxy && (g.stateProxy = stateProxy),
name && (g.name = name), isArray(animation)) {
const animate = g.animate();
timeline && animate.setTimeline(timeline), animation.forEach((item => {
animate[item[0]](...item.slice(1));
}));
}
return g;
}
function parseToGraphic(g, childrenList, props) {
let out, isGraphic = !1;
switch (g.type) {
case "richtext":
case "rich/image":
break;
case "rich/text":
out = g.attribute || {}, childrenList[0] && (out.text = childrenList[0]);
break;
default:
isGraphic = !0;
}
isGraphic ? (childrenList.forEach((c => {
c && g.add(c);
})), Object.keys(props).forEach((k => {
const en = REACT_TO_CANOPUS_EVENTS[k];
en && g.on(en, props[k]);
}))) : "richtext" === g.type && (g.attribute.textConfig = childrenList.map((item => item.attribute)).filter((item => item)));
}
export const Fragment = Group;
//# sourceMappingURL=jsx-classic.js.map