create-yoya-ui 0.2.0 → 0.2.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-yoya-ui",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "description": "Scaffold a new yoya-ui project with Vite: basic template (SPA) or SSR template (renderPage + hydrateOrMount).",
5
5
  "type": "module",
6
6
  "bin": {
@@ -1,6 +1,4 @@
1
- import { svg, vCard, vChart } from '@yoyaflow/yoya-ui';
2
-
3
- /* global document */
1
+ import { div, svg, vCard, vChart } from '@yoyaflow/yoya-ui';
4
2
 
5
3
  const VIEW_BOX = { height: 260, width: 640 };
6
4
  const PAD = { bottom: 34, left: 44, right: 16, top: 14 };
@@ -52,28 +50,37 @@ function createSvgAdapter() {
52
50
  function renderChart(instance, context) {
53
51
  const root = buildChartSvg(context.data, context.options);
54
52
  const legend = buildLegend(context.data?.series ?? []);
55
- instance.host.replaceChildren(legend, root.renderDom());
53
+ instance.host.replaceChildren(legend.renderDom(), root.renderDom());
56
54
  }
57
55
 
58
56
  function buildLegend(series) {
59
- const legend = document.createElement('div');
60
- legend.style.cssText =
61
- 'display:flex;flex-wrap:wrap;gap:14px;margin-bottom:8px;' +
62
- 'font-size:12px;color:var(--yoya-color-text-muted,#64748b);';
63
- series.forEach((entry, index) => {
64
- const color = entry.color ?? SERIES_COLORS[index % SERIES_COLORS.length];
65
- const dot = document.createElement('span');
66
- dot.style.cssText =
67
- `background:${color};border-radius:2px;display:inline-block;` +
68
- 'height:8px;margin-right:5px;width:8px;';
69
- const text = document.createElement('span');
70
- text.textContent = entry.name ?? `系列 ${index + 1}`;
71
- const item = document.createElement('span');
72
- item.style.cssText = 'align-items:center;display:inline-flex;';
73
- item.append(dot, text);
74
- legend.appendChild(item);
57
+ return div((legend) => {
58
+ legend.style({
59
+ color: 'var(--yoya-color-text-muted, #64748b)',
60
+ display: 'flex',
61
+ flexWrap: 'wrap',
62
+ fontSize: '12px',
63
+ gap: '14px',
64
+ marginBottom: '8px'
65
+ });
66
+ series.forEach((entry, index) => {
67
+ const color = entry.color ?? SERIES_COLORS[index % SERIES_COLORS.length];
68
+ legend.span((item) => {
69
+ item.style({ alignItems: 'center', display: 'inline-flex' });
70
+ item.span((dot) => {
71
+ dot.style({
72
+ background: color,
73
+ borderRadius: '2px',
74
+ display: 'inline-block',
75
+ height: '8px',
76
+ marginRight: '5px',
77
+ width: '8px'
78
+ });
79
+ });
80
+ item.span((text) => text.child(entry.name ?? `系列 ${index + 1}`));
81
+ });
82
+ });
75
83
  });
76
- return legend;
77
84
  }
78
85
 
79
86
  function buildChartSvg(data, options) {