refactor: 调整视图剪裁行为

pull/1/head
zestack 1 year ago
parent 3a5c29fe0d
commit 4c91f0f4f7
  1. 9
      src/engineer/render.ts
  2. 6
      src/engineer/types.ts
  3. 21
      src/engineer/utils/clip.ts
  4. 1
      src/engineer/utils/index.ts

@ -8,7 +8,8 @@ import { defineComponent, h } from 'vue'
import type {
Axis,
Block,
DataRefer, Theme,
DataRefer,
Theme,
View,
ViewChildren,
Widget,
@ -17,7 +18,7 @@ import { provideBlockId } from './context'
import {
align,
background,
bordering,
bordering, clip,
gap,
insets,
radii,
@ -55,7 +56,7 @@ function isRefer(s: any): s is DataRefer {
&& typeof s.key === 'string'
}
export const isFlexible = (theme: Theme) => {
export function isFlexible(theme: Theme) {
return theme.axis != null
|| theme.mainAlign != null
|| theme.crossAlign != null
@ -136,7 +137,7 @@ export function render(view?: ViewChildren, axis?: Axis): VNodeChild {
textAlign: theme?.textAlign,
lineHeight: theme?.lineHeight,
// clip
overflow: theme?.clip,
...clip(theme?.clip),
}
// note: 在前面初始化 css 时使用了参数 axis,

@ -252,11 +252,15 @@ export interface Widget {
slots?: Omit<Slots, 'default'>
}
/**
*
*/
export type ClipBehavior =
| 'hidden'
| 'visible'
| 'scroll'
| 'auto'
| 'autoX' // overflow-x: auto; overflow-y: hidden
| 'autoY' // overflow-x: hidden; overflow-y: auto
/**
*

@ -0,0 +1,21 @@
import type { CSSProperties } from 'vue'
import type { ClipBehavior } from '../types'
export function clip(clip: ClipBehavior | undefined): CSSProperties | undefined {
switch (clip) {
case 'autoX':
return {
overflowX: 'auto',
overflowY: 'hidden',
}
case 'autoY':
return {
overflowX: 'hidden',
overflowY: 'auto',
}
default:
return {
overflow: clip,
}
}
}

@ -1,6 +1,7 @@
export * from './align'
export * from './background'
export * from './border'
export * from './clip'
export * from './gap'
export * from './hash'
export * from './insets'

Loading…
Cancel
Save