@doubao-dev/plugin-app-dev 0.0.0-stage → 0.0.40-canary-dea0ddc73-20261026073950

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.
Files changed (107) hide show
  1. package/README.md +10 -2
  2. package/dist/147.js +9 -0
  3. package/dist/assets.d.ts +5 -0
  4. package/dist/assets.js +4 -0
  5. package/dist/index.d.ts +43 -0
  6. package/dist/index.js +1378 -0
  7. package/dist/plugin.d.ts +102 -0
  8. package/dist/plugin.js +4995 -0
  9. package/dist/preview.js +16 -0
  10. package/dist/rslib-runtime.js +33 -0
  11. package/dist/skills/doubao-plugin-app/SKILL.md +21 -0
  12. package/dist/skills/doubao-plugin-app/references/app-development.md +85 -0
  13. package/dist/skills/doubao-plugin-app/references/frontend/components/container-overlay.md +131 -0
  14. package/dist/skills/doubao-plugin-app/references/frontend/components/form-controls.md +146 -0
  15. package/dist/skills/doubao-plugin-app/references/frontend/components/interactive-controls.md +120 -0
  16. package/dist/skills/doubao-plugin-app/references/frontend/components/map-canvas.md +107 -0
  17. package/dist/skills/doubao-plugin-app/references/frontend/components/overview.md +43 -0
  18. package/dist/skills/doubao-plugin-app/references/frontend/components/scroll-list.md +149 -0
  19. package/dist/skills/doubao-plugin-app/references/frontend/components/text-media.md +209 -0
  20. package/dist/skills/doubao-plugin-app/references/frontend/doubao-agentic-service-api/01-/345/237/272/347/241/200.md +1389 -0
  21. package/dist/skills/doubao-plugin-app/references/frontend/doubao-agentic-service-api/02-/347/263/273/347/273/237.md +1376 -0
  22. package/dist/skills/doubao-plugin-app/references/frontend/doubao-agentic-service-api/03-/350/207/252/345/256/232/344/271/211/351/200/232/344/277/241.md +127 -0
  23. package/dist/skills/doubao-plugin-app/references/frontend/doubao-agentic-service-api/04-/345/256/232/344/275/215.md +784 -0
  24. package/dist/skills/doubao-plugin-app/references/frontend/doubao-agentic-service-api/05-/345/255/230/345/202/250.md +1176 -0
  25. package/dist/skills/doubao-plugin-app/references/frontend/doubao-agentic-service-api/06-/350/267/257/347/224/261.md +839 -0
  26. package/dist/skills/doubao-plugin-app/references/frontend/doubao-agentic-service-api/07-/347/225/214/351/235/242.md +376 -0
  27. package/dist/skills/doubao-plugin-app/references/frontend/doubao-agentic-service-api/08-/344/272/244/344/272/222.md +1319 -0
  28. package/dist/skills/doubao-plugin-app/references/frontend/doubao-agentic-service-api/09-/350/276/223/345/205/245.md +192 -0
  29. package/dist/skills/doubao-plugin-app/references/frontend/doubao-agentic-service-api/10-/347/275/221/347/273/234.md +900 -0
  30. package/dist/skills/doubao-plugin-app/references/frontend/doubao-agentic-service-api/11-/345/252/222/344/275/223.md +1496 -0
  31. package/dist/skills/doubao-plugin-app/references/frontend/doubao-agentic-service-api/12-/344/270/232/345/212/241/350/203/275/345/212/233.md +1281 -0
  32. package/dist/skills/doubao-plugin-app/references/frontend/doubao-agentic-service-api/13-/347/231/273/345/275/225.md +511 -0
  33. package/dist/skills/doubao-plugin-app/references/frontend/doubao-agentic-service-api/14-/346/224/257/344/273/230.md +943 -0
  34. package/dist/skills/doubao-plugin-app/references/frontend/doubao-agentic-service-api/15-/346/225/260/346/215/256/345/210/206/346/236/220.md +124 -0
  35. package/dist/skills/doubao-plugin-app/references/frontend/doubao-agentic-service-api/16-/350/223/235/347/211/231.md +3364 -0
  36. package/dist/skills/doubao-plugin-app/references/frontend/doubao-agentic-service-api/17-wi-fi.md +1028 -0
  37. package/dist/skills/doubao-plugin-app/references/frontend/doubao-agentic-service-api/18-/345/212/240/351/200/237/345/272/246/350/256/241.md +354 -0
  38. package/dist/skills/doubao-plugin-app/references/frontend/doubao-agentic-service-api/19-ibeacon.md +508 -0
  39. package/dist/skills/doubao-plugin-app/references/frontend/doubao-agentic-service-api/20-/347/275/227/347/233/230.md +320 -0
  40. package/dist/skills/doubao-plugin-app/references/frontend/doubao-agentic-service-api/21-/350/256/276/345/244/207/346/226/271/345/220/221.md +351 -0
  41. package/dist/skills/doubao-plugin-app/references/frontend/doubao-agentic-service-api/22-/351/231/200/350/236/272/344/273/252.md +354 -0
  42. package/dist/skills/doubao-plugin-app/references/frontend/doubao-agentic-service-api/23-/345/252/222/344/275/223-/350/256/276/345/244/207-/347/275/221/347/273/234.md +264 -0
  43. package/dist/skills/doubao-plugin-app/references/frontend/doubao-agentic-service-api/24-/347/237/255/344/277/241.md +155 -0
  44. package/dist/skills/doubao-plugin-app/references/frontend/doubao-agentic-service-api/25-/346/227/240/351/232/234/347/242/215.md +144 -0
  45. package/dist/skills/doubao-plugin-app/references/frontend/doubao-agentic-service-api/26-/345/237/272/347/241/200/344/277/241/346/201/257.md +238 -0
  46. package/dist/skills/doubao-plugin-app/references/frontend/doubao-agentic-service-api/27-/347/224/265/346/261/240.md +235 -0
  47. package/dist/skills/doubao-plugin-app/references/frontend/doubao-agentic-service-api/28-/345/211/252/350/264/264/346/235/277.md +303 -0
  48. package/dist/skills/doubao-plugin-app/references/frontend/doubao-agentic-service-api/29-/345/212/240/345/257/206.md +126 -0
  49. package/dist/skills/doubao-plugin-app/references/frontend/doubao-agentic-service-api/30-/346/227/245/345/216/206.md +417 -0
  50. package/dist/skills/doubao-plugin-app/references/frontend/doubao-agentic-service-api/31-/347/224/265/350/257/235.md +144 -0
  51. package/dist/skills/doubao-plugin-app/references/frontend/doubao-agentic-service-api/32-/346/211/253/347/240/201.md +236 -0
  52. package/dist/skills/doubao-plugin-app/references/frontend/doubao-agentic-service-api/33-/345/261/217/345/271/225.md +747 -0
  53. package/dist/skills/doubao-plugin-app/references/frontend/doubao-agentic-service-api/34-/351/234/207/345/212/250.md +277 -0
  54. package/dist/skills/doubao-plugin-app/references/frontend/doubao-agentic-service-api/35-/346/226/207/344/273/266/347/263/273/347/273/237.md +431 -0
  55. package/dist/skills/doubao-plugin-app/references/frontend/doubao-agentic-service-api/common-errors.md +69 -0
  56. package/dist/skills/doubao-plugin-app/references/frontend/doubao-agentic-service-api/groups.md +43 -0
  57. package/dist/skills/doubao-plugin-app/references/frontend/doubao-agentic-service-api/quick-reference.md +436 -0
  58. package/dist/skills/doubao-plugin-app/references/frontend/examples/common-patterns.md +590 -0
  59. package/dist/skills/doubao-plugin-app/references/frontend/examples/doubao-agentic-service-api-recipes.md +209 -0
  60. package/dist/skills/doubao-plugin-app/references/frontend/examples/page-widget-basics.md +368 -0
  61. package/dist/skills/doubao-plugin-app/references/frontend/examples/page-widget-recipes.md +65 -0
  62. package/dist/skills/doubao-plugin-app/references/frontend/framework/core.md +283 -0
  63. package/dist/skills/doubao-plugin-app/references/frontend/guides/auth.md +277 -0
  64. package/dist/skills/doubao-plugin-app/references/frontend/guides/best-practices.md +574 -0
  65. package/dist/skills/doubao-plugin-app/references/frontend/guides/client-tools-and-events.md +209 -0
  66. package/dist/skills/doubao-plugin-app/references/frontend/guides/component-development.md +832 -0
  67. package/dist/skills/doubao-plugin-app/references/frontend/guides/debugger-mcp.md +537 -0
  68. package/dist/skills/doubao-plugin-app/references/frontend/guides/expired-widget.md +101 -0
  69. package/dist/skills/doubao-plugin-app/references/frontend/guides/performance-optimization.md +417 -0
  70. package/dist/skills/doubao-plugin-app/references/frontend/guides/troubleshooting.md +278 -0
  71. package/dist/skills/doubao-plugin-app/references/frontend/lynx/best-practices.md +720 -0
  72. package/dist/skills/doubao-plugin-app/references/frontend/lynx/css/pseudo-classes.md +149 -0
  73. package/dist/skills/doubao-plugin-app/references/frontend/lynx/css/selectors.md +224 -0
  74. package/dist/skills/doubao-plugin-app/references/frontend/lynx/css/supported-properties.md +269 -0
  75. package/dist/skills/doubao-plugin-app/references/frontend/lynx/css/values-and-units.md +314 -0
  76. package/dist/skills/doubao-plugin-app/references/frontend/lynx/layout/flex-layout.md +334 -0
  77. package/dist/skills/doubao-plugin-app/references/frontend/lynx/layout/grid-layout.md +408 -0
  78. package/dist/skills/doubao-plugin-app/references/frontend/lynx/layout/linear-layout.md +355 -0
  79. package/dist/skills/doubao-plugin-app/references/frontend/lynx/layout/relative-layout.md +189 -0
  80. package/dist/skills/doubao-plugin-app/references/frontend/lynx/lynx-vs-web/css-differences.md +737 -0
  81. package/dist/skills/doubao-plugin-app/references/frontend/lynx/lynx-vs-web/migration-guide.md +669 -0
  82. package/dist/skills/doubao-plugin-app/references/frontend/lynx/lynx-vs-web/unsupported-features.md +290 -0
  83. package/dist/skills/doubao-plugin-app/references/frontend/lynx/overview.md +60 -0
  84. package/dist/skills/doubao-plugin-app/references/frontend/lynx/patterns/animation.md +243 -0
  85. package/dist/skills/doubao-plugin-app/references/frontend/lynx/patterns/responsive.md +194 -0
  86. package/dist/skills/doubao-plugin-app/references/frontend/lynx/patterns/theming.md +143 -0
  87. package/dist/skills/doubao-plugin-app/references/frontend/lynx/quick-reference.md +229 -0
  88. package/dist/skills/doubao-plugin-app/references/frontend/rules/dos-and-donts.md +479 -0
  89. package/dist/skills/doubao-plugin-app/references/frontend/widget-templates/design-boundary.md +46 -0
  90. package/dist/skills/doubao-plugin-app/references/frontend/widget-templates/overview.md +118 -0
  91. package/dist/skills/doubao-plugin-app/references/frontend/widget-templates/props.md +301 -0
  92. package/dist/skills/doubao-plugin-app/references/mcp-and-cards.md +38 -0
  93. package/dist/templates/README.md.template +11 -0
  94. package/dist/templates/com.doubao/app/manifest.yaml +41 -0
  95. package/dist/templates/com.doubao/app/package.json.template +13 -0
  96. package/dist/templates/com.doubao/app/src/app.config.ts.template +5 -0
  97. package/dist/templates/com.doubao/app/src/app.ts.template +3 -0
  98. package/dist/templates/com.doubao/app/src/pages/home/index.css +14 -0
  99. package/dist/templates/com.doubao/app/src/pages/home/index.tsx.template +14 -0
  100. package/dist/templates/com.doubao/app/src/widgets/example/index.tsx.template +29 -0
  101. package/dist/templates/com.doubao/app/tsconfig.json +19 -0
  102. package/dist/templates/mcp.json +9 -0
  103. package/dist/templates/plugin.json.template +29 -0
  104. package/dist/templates/skills/example/SKILL.md.template +14 -0
  105. package/dist/upload.d.ts +44 -0
  106. package/dist/upload.js +38 -0
  107. package/package.json +60 -3
@@ -0,0 +1,355 @@
1
+ # Linear 布局(默认布局)
2
+
3
+ Linear 是 Lynx 的默认布局系统,类似于 Android 的 LinearLayout。当你不设置 `display` 属性时,默认使用 Linear 布局。
4
+
5
+ ## 基本用法
6
+
7
+ ```jsx
8
+ // 默认情况下,子元素垂直排列
9
+ <view className="container">
10
+ <text>Item 1</text>
11
+ <text>Item 2</text>
12
+ <text>Item 3</text>
13
+ </view>
14
+ ```
15
+
16
+ ```css
17
+ .container {
18
+ /* 无需设置 display,默认就是 linear */
19
+ padding: 16px;
20
+ }
21
+ ```
22
+
23
+ ## 方向设置
24
+
25
+ ```css
26
+ .row {
27
+ display: linear;
28
+ linear-orientation: horizontal; /* 或 row */
29
+ }
30
+ ```
31
+
32
+ **linear-orientation 所有可选值**:
33
+
34
+ - `horizontal` / `row` - 水平排列
35
+ - `vertical` / `column` - 垂直排列(默认)
36
+ - `horizontal-reverse` / `row-reverse` - 水平反向排列
37
+ - `vertical-reverse` / `column-reverse` - 垂直反向排列
38
+
39
+ ```jsx
40
+ <view className="row">
41
+ <text>Left</text>
42
+ <text>Center</text>
43
+ <text>Right</text>
44
+ </view>
45
+ ```
46
+
47
+ ## 权重分配
48
+
49
+ 使用 `linear-weight` 分配剩余空间:
50
+
51
+ ```css
52
+ .container {
53
+ display: linear;
54
+ linear-orientation: horizontal;
55
+ }
56
+
57
+ .sidebar {
58
+ width: 200px; /* 固定宽度 */
59
+ }
60
+
61
+ .main {
62
+ linear-weight: 1; /* 占据剩余所有空间 */
63
+ }
64
+
65
+ .aside {
66
+ linear-weight: 0.5; /* 占据 1/3 剩余空间 */
67
+ }
68
+ ```
69
+
70
+ ```jsx
71
+ <view className="container">
72
+ <view className="sidebar">
73
+ <text>Sidebar</text>
74
+ </view>
75
+ <view className="main">
76
+ <text>Main Content</text>
77
+ </view>
78
+ <view className="aside">
79
+ <text>Aside</text>
80
+ </view>
81
+ </view>
82
+ ```
83
+
84
+ ## 对齐方式
85
+
86
+ ```css
87
+ /* 子元素整体居中 */
88
+ .center-container {
89
+ display: linear;
90
+ linear-gravity: center;
91
+ }
92
+
93
+ /* 水平居中 */
94
+ .horizontal-center {
95
+ display: linear;
96
+ linear-gravity: center-horizontal;
97
+ }
98
+
99
+ /* 垂直居中 */
100
+ .vertical-center {
101
+ display: linear;
102
+ linear-gravity: center-vertical;
103
+ }
104
+
105
+ /* 子元素拉伸填满 */
106
+ .stretch-container {
107
+ display: linear;
108
+ linear-orientation: horizontal;
109
+ }
110
+
111
+ .stretch-container .item {
112
+ linear-layout-gravity: stretch;
113
+ }
114
+ ```
115
+
116
+ ## 属性值参考
117
+
118
+ ### linear-orientation
119
+
120
+ 控制布局方向:
121
+
122
+ | 值 | 说明 |
123
+ | ------------------------------------- | ---------------- |
124
+ | `horizontal` / `row` | 水平排列 |
125
+ | `vertical` / `column` | 垂直排列(默认) |
126
+ | `horizontal-reverse` / `row-reverse` | 水平反向 |
127
+ | `vertical-reverse` / `column-reverse` | 垂直反向 |
128
+
129
+ ### linear-direction
130
+
131
+ **Lynx 2.2+** 替代 `linear-orientation` 的属性,语义更清晰:
132
+
133
+ | 值 | 说明 |
134
+ | ---------------- | ---------------- |
135
+ | `row` | 水平排列 |
136
+ | `column` | 垂直排列(默认) |
137
+ | `row-reverse` | 水平反向 |
138
+ | `column-reverse` | 垂直反向 |
139
+
140
+ ### linear-gravity(容器属性)
141
+
142
+ 控制子元素在主轴上的对齐:
143
+
144
+ | 值 | 说明 |
145
+ | ------------------- | ---------------------- |
146
+ | `none` | 无特殊对齐 |
147
+ | `top` | 顶部对齐(垂直布局时) |
148
+ | `bottom` | 底部对齐(垂直布局时) |
149
+ | `left` | 左侧对齐(水平布局时) |
150
+ | `right` | 右侧对齐(水平布局时) |
151
+ | `center-vertical` | 垂直居中 |
152
+ | `center-horizontal` | 水平居中 |
153
+ | `center` | 主轴居中 |
154
+ | `start` | 主轴起点对齐 |
155
+ | `end` | 主轴终点对齐 |
156
+ | `space-between` | 两端对齐,中间等分 |
157
+
158
+ > **注意**: `top`/`bottom`/`left`/`right` 是物理方向值,会根据 `linear-orientation` 自动映射到逻辑方向。
159
+
160
+ ### linear-layout-gravity(子元素属性)
161
+
162
+ 控制单个子元素在交叉轴上的对齐:
163
+
164
+ | 值 | 说明 |
165
+ | ------------------- | --------------------- |
166
+ | `none` | 无特殊对齐 |
167
+ | `top` | 顶部对齐 |
168
+ | `bottom` | 底部对齐 |
169
+ | `left` | 左侧对齐 |
170
+ | `right` | 右侧对齐 |
171
+ | `center-vertical` | 垂直居中 |
172
+ | `center-horizontal` | 水平居中 |
173
+ | `center` | 交叉轴居中 |
174
+ | `fill-vertical` | 垂直方向填充 |
175
+ | `fill-horizontal` | 水平方向填充 |
176
+ | `stretch` | 拉伸填满(Lynx 1.6+) |
177
+ | `start` | 起点对齐(Lynx 1.6+) |
178
+ | `end` | 终点对齐(Lynx 1.6+) |
179
+
180
+ > **注意**: `stretch`、`fill-vertical`、`fill-horizontal` 是不同的值。`stretch` 是逻辑方向填充,根据布局方向自动决定。
181
+
182
+ ### linear-cross-gravity(容器属性)
183
+
184
+ 控制所有子元素在交叉轴上的默认对齐(Lynx 1.6+):
185
+
186
+ | 值 | 说明 |
187
+ | --------- | ---------- |
188
+ | `none` | 无特殊对齐 |
189
+ | `start` | 起点对齐 |
190
+ | `end` | 终点对齐 |
191
+ | `center` | 居中对齐 |
192
+ | `stretch` | 拉伸填满 |
193
+
194
+ ### linear-weight
195
+
196
+ 数字类型,指定子元素占据剩余空间的比例。
197
+
198
+ ```css
199
+ .item {
200
+ linear-weight: 1; /* 占据一份剩余空间 */
201
+ }
202
+ ```
203
+
204
+ ### linear-weight-sum
205
+
206
+ **高级属性** 设置权重计算的总和。默认自动计算所有子元素 weight 之和。
207
+
208
+ ```css
209
+ .container {
210
+ linear-weight-sum: 100; /* 设置总权重为100 */
211
+ }
212
+
213
+ .item1 {
214
+ linear-weight: 30; /* 占据 30% */
215
+ }
216
+
217
+ .item2 {
218
+ linear-weight: 70; /* 占据 70% */
219
+ }
220
+ ```
221
+
222
+ ## Linear vs Flex 对比
223
+
224
+ | 特性 | Linear | Flex |
225
+ | ---------- | ---------------- | ------------------ |
226
+ | 性能 | 更快(简单场景) | 稍慢 |
227
+ | 换行 | 不支持 | 支持 wrap |
228
+ | 多行对齐 | 不支持 | 支持 align-content |
229
+ | 子元素排序 | 不支持 | 支持 order |
230
+ | 适用场景 | 简单列表 | 复杂弹性布局 |
231
+
232
+ **建议**: 简单列表用 Linear,复杂布局用 Flex。
233
+
234
+ ## 与 Web Block Layout 的差异(迁移要点)
235
+
236
+ **这是从 Web 迁移到 Lynx 时最常见的陷阱之一**。
237
+
238
+ ### 默认布局差异
239
+
240
+ | 特性 | Web Block Layout | Lynx Linear Layout(默认) |
241
+ | -------------------- | ------------------------------------------ | ---------------------------------------------- |
242
+ | 默认 display | `block`(flow layout) | `linear`(类似 flex column) |
243
+ | 子元素宽度 | 默认 `width: 100%`,自动填满父元素 | 默认由内容决定,**不会自动填满** |
244
+ | 子元素高度 | 由内容决定 | 由内容决定 |
245
+ | 嵌套元素尺寸 | 继承父元素尺寸(逐层填满) | **不会自动继承**,需要显式设置 |
246
+ | 空元素尺寸 | 可能为 0(取决于 overflow 和 min-height) | **通常为 0**(无内容且无显式宽高时) |
247
+
248
+ ### 子元素尺寸问题示例
249
+
250
+ ```css
251
+ /* Web: 子元素自动填满父元素 */
252
+ .parent { width: 200px; }
253
+ .child { /* 默认 width: 100%,实际 200px */ }
254
+
255
+ /* Lynx: 子元素不会自动填满 */
256
+ .parent { width: 200px; display: linear; }
257
+ .child { /* 默认宽度由内容决定,可能远小于 200px */ }
258
+
259
+ /* Lynx 修复方案 1:显式设置 width */
260
+ .child { width: 100%; }
261
+
262
+ /* Lynx 修复方案 2:使用 linear-layout-gravity */
263
+ .child { linear-layout-gravity: stretch; }
264
+
265
+ /* Lynx 修复方案 3:父元素设置 linear-cross-gravity */
266
+ .parent { linear-cross-gravity: stretch; }
267
+ ```
268
+
269
+ ### 嵌套元素尺寸问题示例
270
+
271
+ ```css
272
+ /* Web: 嵌套 div 自动填满 */
273
+ .grandparent { width: 100px; height: 100px; }
274
+ .parent { /* 自动 100x100 */ }
275
+ .child { /* 自动 100x100 */ }
276
+
277
+ /* Lynx: 需要每层都显式设置 */
278
+ .grandparent { width: 100px; height: 100px; display: linear; }
279
+ .parent { width: 100%; height: 100%; }
280
+ .child { width: 100%; height: 100%; }
281
+
282
+ /* 或者使用 stretch */
283
+ .grandparent {
284
+ width: 100px;
285
+ height: 100px;
286
+ display: linear;
287
+ linear-cross-gravity: stretch;
288
+ }
289
+ ```
290
+
291
+ ## 常见布局模式
292
+
293
+ ### 垂直列表
294
+
295
+ ```css
296
+ .list {
297
+ display: linear;
298
+ /* 默认就是垂直 */
299
+ gap: 12px;
300
+ padding: 16px;
301
+ }
302
+
303
+ .list-item {
304
+ padding: 12px;
305
+ background-color: #f5f5f5;
306
+ border-radius: 8px;
307
+ }
308
+ ```
309
+
310
+ ### 水平按钮组
311
+
312
+ ```css
313
+ .button-group {
314
+ display: linear;
315
+ linear-orientation: horizontal;
316
+ gap: 8px;
317
+ padding: 16px;
318
+ }
319
+
320
+ .button-group .button {
321
+ linear-weight: 1; /* 等分宽度 */
322
+ }
323
+ ```
324
+
325
+ ### 侧边栏 + 主内容
326
+
327
+ ```css
328
+ .layout {
329
+ display: linear;
330
+ linear-orientation: horizontal;
331
+ height: 100vh;
332
+ }
333
+
334
+ .sidebar {
335
+ width: 250px;
336
+ }
337
+
338
+ .main {
339
+ linear-weight: 1; /* 占据剩余空间 */
340
+ }
341
+ ```
342
+
343
+ ### 使用 linear-cross-gravity 的列表
344
+
345
+ ```css
346
+ .list {
347
+ display: linear;
348
+ linear-orientation: horizontal;
349
+ linear-cross-gravity: stretch; /* 所有子元素等高 */
350
+ }
351
+
352
+ .list-item {
353
+ /* 子元素会自动拉伸到容器高度 */
354
+ }
355
+ ```
@@ -0,0 +1,189 @@
1
+ # Relative 布局
2
+
3
+ Lynx 特有的布局系统,类似于 Android 的 RelativeLayout。适用于需要相对定位的复杂布局。
4
+
5
+ ## 核心概念
6
+
7
+ 每个元素通过 `relative-id` 标识,然后引用其他元素的 ID 进行定位。
8
+
9
+ ## 基本用法
10
+
11
+ ```css
12
+ .container {
13
+ display: relative;
14
+ width: 100%;
15
+ height: 400px;
16
+ }
17
+
18
+ /* 左上角头像 */
19
+ .avatar {
20
+ relative-id: 1;
21
+ relative-align-left: parent;
22
+ relative-align-top: parent;
23
+ width: 80px;
24
+ height: 80px;
25
+ }
26
+
27
+ /* 用户名在头像右边 */
28
+ .username {
29
+ relative-id: 2;
30
+ relative-right-of: 1; /* 在 ID 1 的右边 */
31
+ relative-align-top: 1; /* 顶部与 ID 1 对齐 */
32
+ }
33
+
34
+ /* 描述在用户名下方 */
35
+ .description {
36
+ relative-id: 3;
37
+ relative-right-of: 1;
38
+ relative-bottom-of: 2; /* 在 ID 2 的下方 */
39
+ }
40
+
41
+ /* 关闭按钮右上角 */
42
+ .close {
43
+ relative-id: 4;
44
+ relative-align-right: parent;
45
+ relative-align-top: parent;
46
+ }
47
+ ```
48
+
49
+ ```jsx
50
+ <view className="container">
51
+ <image className="avatar" src="avatar.png" />
52
+ <text className="username">Username</text>
53
+ <text className="description">Description here</text>
54
+ <text className="close">×</text>
55
+ </view>
56
+ ```
57
+
58
+ ## 对齐方式
59
+
60
+ ```css
61
+ /* 水平居中 */
62
+ .center-horizontal {
63
+ relative-id: 1;
64
+ relative-center: horizontal;
65
+ }
66
+
67
+ /* 垂直居中 */
68
+ .center-vertical {
69
+ relative-id: 1;
70
+ relative-center: vertical;
71
+ }
72
+
73
+ /* 完全居中 */
74
+ .center-both {
75
+ relative-id: 1;
76
+ relative-center: both;
77
+ }
78
+ ```
79
+
80
+ ## 相对定位属性
81
+
82
+ | 属性 | 说明 | 值 |
83
+ | ----------------------- | -------------- | -------------------------------- |
84
+ | `relative-id` | 元素唯一标识 | 数字 |
85
+ | `relative-align-top` | 顶部对齐 | parent 或 其他元素 ID |
86
+ | `relative-align-bottom` | 底部对齐 | parent 或 其他元素 ID |
87
+ | `relative-align-left` | 左对齐 | parent 或 其他元素 ID |
88
+ | `relative-align-right` | 右对齐 | parent 或 其他元素 ID |
89
+ | `relative-top-of` | 位于某元素上方 | 其他元素 ID |
90
+ | `relative-bottom-of` | 位于某元素下方 | 其他元素 ID |
91
+ | `relative-left-of` | 位于某元素左侧 | 其他元素 ID |
92
+ | `relative-right-of` | 位于某元素右侧 | 其他元素 ID |
93
+ | `relative-center` | 居中 | none, vertical, horizontal, both |
94
+
95
+ ### relative-center 可选值
96
+
97
+ | 值 | 说明 |
98
+ | ------------ | ---------------- |
99
+ | `none` | 不居中(默认) |
100
+ | `vertical` | 垂直居中 |
101
+ | `horizontal` | 水平居中 |
102
+ | `both` | 水平和垂直都居中 |
103
+
104
+ ## 适用场景
105
+
106
+ - 卡片式布局(头像+文字+按钮)
107
+ - 聊天界面
108
+ - 复杂的表单项
109
+ - 任何需要"相对某个元素定位"的场景
110
+
111
+ ## 注意事项
112
+
113
+ 1. 每个 `relative-id` 在同一父容器内必须唯一
114
+ 2. 循环引用会导致布局错误(A 依赖 B,B 又依赖 A)
115
+ 3. 如果不设置任何相对属性,元素会堆叠在左上角
116
+
117
+ ## 高级用法
118
+
119
+ ### RTL 支持(Lynx 2.0+)
120
+
121
+ 对于需要适配从右到左(RTL)语言(如阿拉伯语、希伯来语)的布局,可以使用逻辑方向属性:
122
+
123
+ | 物理方向 | 逻辑方向(推荐) |
124
+ | ---------------------- | ----------------------------- |
125
+ | `relative-align-left` | `relative-align-inline-start` |
126
+ | `relative-align-right` | `relative-align-inline-end` |
127
+ | `relative-left-of` | `relative-inline-start-of` |
128
+ | `relative-right-of` | `relative-inline-end-of` |
129
+
130
+ ```css
131
+ /* 推荐:使用逻辑方向,自动适配 RTL */
132
+ .card {
133
+ display: relative;
134
+ }
135
+
136
+ .avatar {
137
+ relative-id: 1;
138
+ relative-align-inline-start: parent; /* LTR时左对齐,RTL时右对齐 */
139
+ relative-align-top: parent;
140
+ }
141
+
142
+ .username {
143
+ relative-id: 2;
144
+ relative-inline-start-of: 1; /* LTR时在左边,RTL时在右边 */
145
+ relative-align-top: 1;
146
+ }
147
+ ```
148
+
149
+ ### relative-layout-once(内部属性)
150
+
151
+ ```css
152
+ .container {
153
+ relative-layout-once: true; /* 默认值,优化性能 */
154
+ }
155
+ ```
156
+
157
+ > **注意**: 这是内部优化属性,通常不需要手动设置。
158
+
159
+ ## 实际案例:聊天消息
160
+
161
+ ```css
162
+ .chat-message {
163
+ display: relative;
164
+ padding: 12px;
165
+ }
166
+
167
+ .avatar {
168
+ relative-id: 1;
169
+ relative-align-left: parent;
170
+ relative-align-top: parent;
171
+ width: 40px;
172
+ height: 40px;
173
+ }
174
+
175
+ .username {
176
+ relative-id: 2;
177
+ relative-right-of: 1;
178
+ relative-top-of: 3;
179
+ margin-left: 8px;
180
+ }
181
+
182
+ .message-bubble {
183
+ relative-id: 3;
184
+ relative-right-of: 1;
185
+ relative-bottom-of: 2;
186
+ margin-left: 8px;
187
+ margin-top: 4px;
188
+ }
189
+ ```