react-ai-renderer 0.1.16 → 0.1.17

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/index.cjs CHANGED
@@ -10,7 +10,6 @@ var RemarkGfm = require('remark-gfm');
10
10
  var mdx = require('@mdx-js/mdx');
11
11
  var RehypeKatex = require('rehype-katex');
12
12
  var RehypeHighlight = require('rehype-highlight');
13
- var RehypeRaw = require('rehype-raw');
14
13
 
15
14
  function _interopNamespaceDefault(e) {
16
15
  var n = Object.create(null);
@@ -58359,13 +58358,13 @@ function renderText(textContent, scope, registeredComponents) {
58359
58358
  children: textContent,
58360
58359
  components: registeredComponents,
58361
58360
  remarkPlugins: [RemarkMath, RemarkGfm, RemarkBreaks],
58362
- rehypePlugins: [RehypeRaw, RehypeKatex, [RehypeHighlight, {
58361
+ rehypePlugins: [RehypeKatex, [RehypeHighlight, {
58363
58362
  detect: false,
58364
58363
  ignoreMissing: true,
58365
58364
  plainText: ['mermaid'] // 将mermaid作为纯文本处理,避免被错误高亮
58366
58365
  }]],
58367
58366
  remarkRehypeOptions: {
58368
- allowDangerousHtml: true // 允许处理 HTML 标签
58367
+ allowDangerousHtml: false // 允许处理 HTML 标签
58369
58368
  }
58370
58369
  })];
58371
58370
  });
@@ -58625,10 +58624,523 @@ function MdxLayout(_a) {
58625
58624
  });
58626
58625
  }
58627
58626
 
58627
+ function generateSkeletonByComponentName(componentName, props, style) {
58628
+ var _a, _b;
58629
+ var baseStyle = __assign({
58630
+ borderRadius: '8px',
58631
+ backgroundColor: '#f3f4f6'
58632
+ }, style);
58633
+ // 根据组件名称模式匹配生成不同的骨架图
58634
+ var name = componentName.toLowerCase();
58635
+ // 图表类组件
58636
+ if (name.includes('chart') || name.includes('graph') || name.includes('plot')) {
58637
+ return /*#__PURE__*/runtime.jsxs("div", {
58638
+ style: __assign(__assign({}, baseStyle), {
58639
+ padding: '24px',
58640
+ minHeight: (props === null || props === void 0 ? void 0 : props.height) ? "".concat(props.height, "px") : '300px',
58641
+ display: 'flex',
58642
+ flexDirection: 'column',
58643
+ gap: '12px'
58644
+ }),
58645
+ children: [/*#__PURE__*/runtime.jsxs("div", {
58646
+ style: {
58647
+ display: 'flex',
58648
+ justifyContent: 'space-between',
58649
+ alignItems: 'center',
58650
+ marginBottom: '8px'
58651
+ },
58652
+ children: [/*#__PURE__*/runtime.jsx("div", {
58653
+ style: {
58654
+ width: '120px',
58655
+ height: '20px',
58656
+ backgroundColor: '#e5e7eb',
58657
+ borderRadius: '4px'
58658
+ }
58659
+ }), /*#__PURE__*/runtime.jsx("div", {
58660
+ style: {
58661
+ width: '80px',
58662
+ height: '16px',
58663
+ backgroundColor: '#e5e7eb',
58664
+ borderRadius: '4px'
58665
+ }
58666
+ })]
58667
+ }), /*#__PURE__*/runtime.jsx("div", {
58668
+ style: {
58669
+ flex: 1,
58670
+ display: 'flex',
58671
+ alignItems: 'flex-end',
58672
+ gap: '8px',
58673
+ height: '200px'
58674
+ },
58675
+ children: Array.from({
58676
+ length: 8
58677
+ }).map(function (_, i) {
58678
+ return /*#__PURE__*/runtime.jsx("div", {
58679
+ style: {
58680
+ flex: 1,
58681
+ height: "".concat(Math.random() * 60 + 40, "%"),
58682
+ backgroundColor: '#d1d5db',
58683
+ borderRadius: '4px 4px 0 0',
58684
+ animation: 'pulse 1.5s ease-in-out infinite',
58685
+ animationDelay: "".concat(i * 0.1, "s")
58686
+ }
58687
+ }, i);
58688
+ })
58689
+ }), /*#__PURE__*/runtime.jsx("div", {
58690
+ style: {
58691
+ display: 'flex',
58692
+ gap: '12px',
58693
+ marginTop: '8px'
58694
+ },
58695
+ children: Array.from({
58696
+ length: 3
58697
+ }).map(function (_, i) {
58698
+ return /*#__PURE__*/runtime.jsxs("div", {
58699
+ style: {
58700
+ display: 'flex',
58701
+ alignItems: 'center',
58702
+ gap: '6px'
58703
+ },
58704
+ children: [/*#__PURE__*/runtime.jsx("div", {
58705
+ style: {
58706
+ width: '12px',
58707
+ height: '12px',
58708
+ backgroundColor: '#d1d5db',
58709
+ borderRadius: '2px'
58710
+ }
58711
+ }), /*#__PURE__*/runtime.jsx("div", {
58712
+ style: {
58713
+ width: '60px',
58714
+ height: '12px',
58715
+ backgroundColor: '#e5e7eb',
58716
+ borderRadius: '2px'
58717
+ }
58718
+ })]
58719
+ }, i);
58720
+ })
58721
+ }), /*#__PURE__*/runtime.jsx("style", {
58722
+ children: "\n @keyframes pulse {\n 0%, 100% { opacity: 1; }\n 50% { opacity: 0.5; }\n }\n "
58723
+ })]
58724
+ });
58725
+ }
58726
+ // 表格类组件
58727
+ if (name.includes('table') || name.includes('grid')) {
58728
+ var rowCount_1 = (props === null || props === void 0 ? void 0 : props.rows) || 5;
58729
+ var colCount_1 = (props === null || props === void 0 ? void 0 : props.columns) || 4;
58730
+ return /*#__PURE__*/runtime.jsxs("div", {
58731
+ style: __assign(__assign({}, baseStyle), {
58732
+ padding: '16px',
58733
+ overflow: 'hidden'
58734
+ }),
58735
+ children: [/*#__PURE__*/runtime.jsxs("div", {
58736
+ style: {
58737
+ marginBottom: '12px'
58738
+ },
58739
+ children: [/*#__PURE__*/runtime.jsx("div", {
58740
+ style: {
58741
+ width: '150px',
58742
+ height: '20px',
58743
+ backgroundColor: '#e5e7eb',
58744
+ borderRadius: '4px',
58745
+ marginBottom: '8px'
58746
+ }
58747
+ }), /*#__PURE__*/runtime.jsx("div", {
58748
+ style: {
58749
+ width: '200px',
58750
+ height: '16px',
58751
+ backgroundColor: '#e5e7eb',
58752
+ borderRadius: '4px'
58753
+ }
58754
+ })]
58755
+ }), /*#__PURE__*/runtime.jsxs("div", {
58756
+ style: {
58757
+ border: '1px solid #e5e7eb',
58758
+ borderRadius: '4px',
58759
+ overflow: 'hidden'
58760
+ },
58761
+ children: [/*#__PURE__*/runtime.jsx("div", {
58762
+ style: {
58763
+ display: 'grid',
58764
+ gridTemplateColumns: "repeat(".concat(colCount_1, ", 1fr)"),
58765
+ backgroundColor: '#f9fafb',
58766
+ borderBottom: '1px solid #e5e7eb'
58767
+ },
58768
+ children: Array.from({
58769
+ length: colCount_1
58770
+ }).map(function (_, i) {
58771
+ return /*#__PURE__*/runtime.jsx("div", {
58772
+ style: {
58773
+ padding: '12px',
58774
+ borderRight: i < colCount_1 - 1 ? '1px solid #e5e7eb' : 'none'
58775
+ },
58776
+ children: /*#__PURE__*/runtime.jsx("div", {
58777
+ style: {
58778
+ width: '80%',
58779
+ height: '16px',
58780
+ backgroundColor: '#d1d5db',
58781
+ borderRadius: '2px'
58782
+ }
58783
+ })
58784
+ }, i);
58785
+ })
58786
+ }), Array.from({
58787
+ length: rowCount_1
58788
+ }).map(function (_, rowIndex) {
58789
+ return /*#__PURE__*/runtime.jsx("div", {
58790
+ style: {
58791
+ display: 'grid',
58792
+ gridTemplateColumns: "repeat(".concat(colCount_1, ", 1fr)"),
58793
+ borderBottom: rowIndex < rowCount_1 - 1 ? '1px solid #e5e7eb' : 'none'
58794
+ },
58795
+ children: Array.from({
58796
+ length: colCount_1
58797
+ }).map(function (_, colIndex) {
58798
+ return /*#__PURE__*/runtime.jsx("div", {
58799
+ style: {
58800
+ padding: '12px',
58801
+ borderRight: colIndex < colCount_1 - 1 ? '1px solid #e5e7eb' : 'none'
58802
+ },
58803
+ children: /*#__PURE__*/runtime.jsx("div", {
58804
+ style: {
58805
+ width: "".concat(Math.random() * 40 + 60, "%"),
58806
+ height: '14px',
58807
+ backgroundColor: '#e5e7eb',
58808
+ borderRadius: '2px'
58809
+ }
58810
+ })
58811
+ }, colIndex);
58812
+ })
58813
+ }, rowIndex);
58814
+ })]
58815
+ })]
58816
+ });
58817
+ }
58818
+ // 卡片类组件
58819
+ if (name.includes('card')) {
58820
+ return /*#__PURE__*/runtime.jsxs("div", {
58821
+ style: __assign(__assign({}, baseStyle), {
58822
+ padding: '20px',
58823
+ minHeight: '200px'
58824
+ }),
58825
+ children: [/*#__PURE__*/runtime.jsx("div", {
58826
+ style: {
58827
+ width: '60%',
58828
+ height: '24px',
58829
+ backgroundColor: '#e5e7eb',
58830
+ borderRadius: '4px',
58831
+ marginBottom: '16px'
58832
+ }
58833
+ }), /*#__PURE__*/runtime.jsx("div", {
58834
+ style: {
58835
+ width: '100%',
58836
+ height: '16px',
58837
+ backgroundColor: '#e5e7eb',
58838
+ borderRadius: '4px',
58839
+ marginBottom: '8px'
58840
+ }
58841
+ }), /*#__PURE__*/runtime.jsx("div", {
58842
+ style: {
58843
+ width: '90%',
58844
+ height: '16px',
58845
+ backgroundColor: '#e5e7eb',
58846
+ borderRadius: '4px',
58847
+ marginBottom: '8px'
58848
+ }
58849
+ }), /*#__PURE__*/runtime.jsx("div", {
58850
+ style: {
58851
+ width: '70%',
58852
+ height: '16px',
58853
+ backgroundColor: '#e5e7eb',
58854
+ borderRadius: '4px',
58855
+ marginBottom: '16px'
58856
+ }
58857
+ }), /*#__PURE__*/runtime.jsxs("div", {
58858
+ style: {
58859
+ display: 'flex',
58860
+ gap: '8px',
58861
+ marginTop: '16px'
58862
+ },
58863
+ children: [/*#__PURE__*/runtime.jsx("div", {
58864
+ style: {
58865
+ width: '80px',
58866
+ height: '32px',
58867
+ backgroundColor: '#d1d5db',
58868
+ borderRadius: '4px'
58869
+ }
58870
+ }), /*#__PURE__*/runtime.jsx("div", {
58871
+ style: {
58872
+ width: '80px',
58873
+ height: '32px',
58874
+ backgroundColor: '#d1d5db',
58875
+ borderRadius: '4px'
58876
+ }
58877
+ })]
58878
+ })]
58879
+ });
58880
+ }
58881
+ // 列表类组件
58882
+ if (name.includes('list') || name.includes('todo')) {
58883
+ var itemCount_1 = ((_a = props === null || props === void 0 ? void 0 : props.items) === null || _a === void 0 ? void 0 : _a.length) || (props === null || props === void 0 ? void 0 : props.count) || 3;
58884
+ return /*#__PURE__*/runtime.jsx("div", {
58885
+ style: __assign(__assign({}, baseStyle), {
58886
+ padding: '16px'
58887
+ }),
58888
+ children: Array.from({
58889
+ length: itemCount_1
58890
+ }).map(function (_, i) {
58891
+ return /*#__PURE__*/runtime.jsxs("div", {
58892
+ style: {
58893
+ display: 'flex',
58894
+ alignItems: 'center',
58895
+ gap: '12px',
58896
+ marginBottom: i < itemCount_1 - 1 ? '12px' : '0',
58897
+ paddingBottom: i < itemCount_1 - 1 ? '12px' : '0',
58898
+ borderBottom: i < itemCount_1 - 1 ? '1px solid #e5e7eb' : 'none'
58899
+ },
58900
+ children: [/*#__PURE__*/runtime.jsx("div", {
58901
+ style: {
58902
+ width: '20px',
58903
+ height: '20px',
58904
+ backgroundColor: '#d1d5db',
58905
+ borderRadius: '4px',
58906
+ flexShrink: 0
58907
+ }
58908
+ }), /*#__PURE__*/runtime.jsxs("div", {
58909
+ style: {
58910
+ flex: 1
58911
+ },
58912
+ children: [/*#__PURE__*/runtime.jsx("div", {
58913
+ style: {
58914
+ width: "".concat(Math.random() * 30 + 60, "%"),
58915
+ height: '16px',
58916
+ backgroundColor: '#e5e7eb',
58917
+ borderRadius: '4px',
58918
+ marginBottom: '6px'
58919
+ }
58920
+ }), /*#__PURE__*/runtime.jsx("div", {
58921
+ style: {
58922
+ width: "".concat(Math.random() * 40 + 40, "%"),
58923
+ height: '14px',
58924
+ backgroundColor: '#e5e7eb',
58925
+ borderRadius: '4px'
58926
+ }
58927
+ })]
58928
+ })]
58929
+ }, i);
58930
+ })
58931
+ });
58932
+ }
58933
+ // 表单类组件
58934
+ if (name.includes('form') || name.includes('input') || name.includes('select')) {
58935
+ var fieldCount_1 = ((_b = props === null || props === void 0 ? void 0 : props.fields) === null || _b === void 0 ? void 0 : _b.length) || 3;
58936
+ return /*#__PURE__*/runtime.jsxs("div", {
58937
+ style: __assign(__assign({}, baseStyle), {
58938
+ padding: '20px'
58939
+ }),
58940
+ children: [Array.from({
58941
+ length: fieldCount_1
58942
+ }).map(function (_, i) {
58943
+ return /*#__PURE__*/runtime.jsxs("div", {
58944
+ style: {
58945
+ marginBottom: i < fieldCount_1 - 1 ? '20px' : '0'
58946
+ },
58947
+ children: [/*#__PURE__*/runtime.jsx("div", {
58948
+ style: {
58949
+ width: '100px',
58950
+ height: '14px',
58951
+ backgroundColor: '#e5e7eb',
58952
+ borderRadius: '2px',
58953
+ marginBottom: '8px'
58954
+ }
58955
+ }), /*#__PURE__*/runtime.jsx("div", {
58956
+ style: {
58957
+ width: '100%',
58958
+ height: '40px',
58959
+ backgroundColor: '#f3f4f6',
58960
+ border: '1px solid #e5e7eb',
58961
+ borderRadius: '4px'
58962
+ }
58963
+ })]
58964
+ }, i);
58965
+ }), /*#__PURE__*/runtime.jsxs("div", {
58966
+ style: {
58967
+ display: 'flex',
58968
+ gap: '12px',
58969
+ marginTop: '20px'
58970
+ },
58971
+ children: [/*#__PURE__*/runtime.jsx("div", {
58972
+ style: {
58973
+ width: '100px',
58974
+ height: '36px',
58975
+ backgroundColor: '#d1d5db',
58976
+ borderRadius: '4px'
58977
+ }
58978
+ }), /*#__PURE__*/runtime.jsx("div", {
58979
+ style: {
58980
+ width: '100px',
58981
+ height: '36px',
58982
+ backgroundColor: '#e5e7eb',
58983
+ borderRadius: '4px'
58984
+ }
58985
+ })]
58986
+ })]
58987
+ });
58988
+ }
58989
+ // 图片/媒体类组件
58990
+ if (name.includes('image') || name.includes('img') || name.includes('video') || name.includes('media')) {
58991
+ return /*#__PURE__*/runtime.jsx("div", {
58992
+ style: __assign(__assign({}, baseStyle), {
58993
+ padding: '16px',
58994
+ display: 'flex',
58995
+ alignItems: 'center',
58996
+ justifyContent: 'center',
58997
+ minHeight: (props === null || props === void 0 ? void 0 : props.height) ? "".concat(props.height, "px") : '200px'
58998
+ }),
58999
+ children: /*#__PURE__*/runtime.jsx("div", {
59000
+ style: {
59001
+ width: '100%',
59002
+ height: '100%',
59003
+ backgroundColor: '#e5e7eb',
59004
+ borderRadius: '8px',
59005
+ display: 'flex',
59006
+ alignItems: 'center',
59007
+ justifyContent: 'center'
59008
+ },
59009
+ children: /*#__PURE__*/runtime.jsx("div", {
59010
+ style: {
59011
+ width: '48px',
59012
+ height: '48px',
59013
+ backgroundColor: '#d1d5db',
59014
+ borderRadius: '50%',
59015
+ display: 'flex',
59016
+ alignItems: 'center',
59017
+ justifyContent: 'center'
59018
+ },
59019
+ children: /*#__PURE__*/runtime.jsx("div", {
59020
+ style: {
59021
+ width: '24px',
59022
+ height: '24px',
59023
+ backgroundColor: '#9ca3af',
59024
+ borderRadius: '4px'
59025
+ }
59026
+ })
59027
+ })
59028
+ })
59029
+ });
59030
+ }
59031
+ // 默认骨架图
59032
+ return /*#__PURE__*/runtime.jsxs("div", {
59033
+ style: __assign(__assign({}, baseStyle), {
59034
+ padding: '24px',
59035
+ minHeight: '120px',
59036
+ display: 'flex',
59037
+ flexDirection: 'column',
59038
+ gap: '12px',
59039
+ alignItems: 'center',
59040
+ justifyContent: 'center'
59041
+ }),
59042
+ children: [/*#__PURE__*/runtime.jsxs("div", {
59043
+ style: {
59044
+ width: '100%',
59045
+ maxWidth: '400px'
59046
+ },
59047
+ children: [/*#__PURE__*/runtime.jsx("div", {
59048
+ style: {
59049
+ width: '60%',
59050
+ height: '20px',
59051
+ backgroundColor: '#e5e7eb',
59052
+ borderRadius: '4px',
59053
+ marginBottom: '12px'
59054
+ }
59055
+ }), /*#__PURE__*/runtime.jsx("div", {
59056
+ style: {
59057
+ width: '100%',
59058
+ height: '16px',
59059
+ backgroundColor: '#e5e7eb',
59060
+ borderRadius: '4px',
59061
+ marginBottom: '8px'
59062
+ }
59063
+ }), /*#__PURE__*/runtime.jsx("div", {
59064
+ style: {
59065
+ width: '90%',
59066
+ height: '16px',
59067
+ backgroundColor: '#e5e7eb',
59068
+ borderRadius: '4px',
59069
+ marginBottom: '8px'
59070
+ }
59071
+ }), /*#__PURE__*/runtime.jsx("div", {
59072
+ style: {
59073
+ width: '75%',
59074
+ height: '16px',
59075
+ backgroundColor: '#e5e7eb',
59076
+ borderRadius: '4px'
59077
+ }
59078
+ })]
59079
+ }), /*#__PURE__*/runtime.jsxs("div", {
59080
+ style: {
59081
+ display: 'flex',
59082
+ gap: '8px',
59083
+ marginTop: '12px'
59084
+ },
59085
+ children: [/*#__PURE__*/runtime.jsx("div", {
59086
+ style: {
59087
+ width: '60px',
59088
+ height: '32px',
59089
+ backgroundColor: '#d1d5db',
59090
+ borderRadius: '4px'
59091
+ }
59092
+ }), /*#__PURE__*/runtime.jsx("div", {
59093
+ style: {
59094
+ width: '60px',
59095
+ height: '32px',
59096
+ backgroundColor: '#d1d5db',
59097
+ borderRadius: '4px'
59098
+ }
59099
+ })]
59100
+ })]
59101
+ });
59102
+ }
59103
+ /**
59104
+ * 创建骨架图组件
59105
+ */
59106
+ function createSkeletonComponent(componentName, componentData, skeletonConfig, style) {
59107
+ // 如果提供了自定义骨架图组件
59108
+ if (skeletonConfig === null || skeletonConfig === void 0 ? void 0 : skeletonConfig.component) {
59109
+ var SkeletonComponent = skeletonConfig.component;
59110
+ return /*#__PURE__*/runtime.jsx(SkeletonComponent, {
59111
+ componentName: componentName,
59112
+ componentData: componentData,
59113
+ props: componentData === null || componentData === void 0 ? void 0 : componentData.props,
59114
+ style: style
59115
+ });
59116
+ }
59117
+ // 如果提供了自定义骨架图元素
59118
+ if (skeletonConfig === null || skeletonConfig === void 0 ? void 0 : skeletonConfig.element) {
59119
+ return skeletonConfig.element;
59120
+ }
59121
+ // 如果提供了自定义生成函数
59122
+ if (skeletonConfig === null || skeletonConfig === void 0 ? void 0 : skeletonConfig.generator) {
59123
+ return skeletonConfig.generator({
59124
+ componentName: componentName,
59125
+ componentData: componentData,
59126
+ props: componentData === null || componentData === void 0 ? void 0 : componentData.props,
59127
+ style: style
59128
+ });
59129
+ }
59130
+ // 如果启用了自动生成,或者没有提供任何配置
59131
+ if ((skeletonConfig === null || skeletonConfig === void 0 ? void 0 : skeletonConfig.autoGenerate) !== false) {
59132
+ return generateSkeletonByComponentName(componentName, componentData === null || componentData === void 0 ? void 0 : componentData.props, style);
59133
+ }
59134
+ // 默认返回空
59135
+ return /*#__PURE__*/runtime.jsx(React.Fragment, {});
59136
+ }
59137
+
58628
59138
  var ComponentPlaceholder = function (_a) {
58629
59139
  var componentName = _a.componentName,
58630
59140
  style = _a.style,
58631
- loader = _a.loader;
59141
+ loader = _a.loader,
59142
+ skeleton = _a.skeleton,
59143
+ componentData = _a.componentData;
58632
59144
  // 如果有自定义加载内容,优先使用
58633
59145
  if (loader) {
58634
59146
  // 如果是布尔值 true,使用默认样式
@@ -58680,6 +59192,19 @@ var ComponentPlaceholder = function (_a) {
58680
59192
  }
58681
59193
  }
58682
59194
  }
59195
+ // 如果没有 loader,尝试使用骨架图
59196
+ if (skeleton || !loader) {
59197
+ try {
59198
+ var skeletonElement = createSkeletonComponent(componentName, componentData, skeleton, style);
59199
+ // 如果骨架图生成成功且不是空元素,使用骨架图
59200
+ if (skeletonElement && /*#__PURE__*/React.isValidElement(skeletonElement)) {
59201
+ return skeletonElement;
59202
+ }
59203
+ } catch (e) {
59204
+ // 如果骨架图生成失败,继续使用默认占位内容
59205
+ console.warn('Failed to generate skeleton:', e);
59206
+ }
59207
+ }
58683
59208
  // 默认占位内容
58684
59209
  return /*#__PURE__*/runtime.jsxs("div", {
58685
59210
  style: __assign({