This repository has been archived on 2024-07-22. You can view files and clone it, but cannot push or open issues or pull requests.
Doric/src/shader/DoricImageNode.ts

52 lines
1.5 KiB
TypeScript
Raw Normal View History

2019-12-21 16:37:55 +08:00
import { DoricViewNode, LEFT, RIGHT, CENTER_X, CENTER_Y, TOP, BOTTOM, toPixelString, toRGBAString } from "./DoricViewNode";
2019-12-21 18:48:37 +08:00
enum ScaleType {
ScaleToFill = 0,
ScaleAspectFit,
ScaleAspectFill,
}
2019-12-21 16:37:55 +08:00
export class DoricImageNode extends DoricViewNode {
2019-12-21 18:48:37 +08:00
2019-12-21 16:37:55 +08:00
build(): HTMLElement {
2019-12-21 18:48:37 +08:00
const ret = document.createElement('img')
ret.style.objectFit = "fill"
return ret
2019-12-21 16:37:55 +08:00
}
2019-12-21 18:13:46 +08:00
blendProps(v: HTMLImageElement, propName: string, prop: any) {
2019-12-21 16:37:55 +08:00
switch (propName) {
case 'imageUrl':
v.setAttribute('src', prop)
break
case 'imageBase64':
v.setAttribute('src', prop)
break
case 'loadCallback':
v.onload = () => {
2019-12-21 18:13:46 +08:00
this.callJSResponse(prop, {
width: v.width,
height: v.height
})
2019-12-21 16:37:55 +08:00
}
break
2019-12-21 18:48:37 +08:00
case 'scaleType':
switch (prop) {
case ScaleType.ScaleToFill:
v.style.objectFit = "fill"
break
case ScaleType.ScaleAspectFit:
v.style.objectFit = "contain"
break
case ScaleType.ScaleAspectFill:
v.style.objectFit = "cover"
break
}
break
2019-12-21 16:37:55 +08:00
default:
super.blendProps(v, propName, prop)
break
}
}
}