filestack-adaptive
Version:
HTML5 picture elements powered by Filestack
127 lines (104 loc) • 2.64 kB
text/typescript
import 'regenerator-runtime/runtime';
import { LitElement, property, html, customElement } from 'lit-element';
import { makePicture } from './adapters/DOM';
import {
TransformOptions,
EFitOptions,
EAlignFacesOptions,
ECropfacesType,
EShapeType,
EBlurMode,
ENoiseType,
EStyleType,
EColorspaceType,
EAlignOptions,
EVideoAccessMode,
EVideoTypes,
EVideoLocations,
EVideoAccess,
EUrlscreenshotAgent,
EUrlscreenshotMode,
EUrlscreenshotOrientation,
} from 'filestack-js';
import { makePictureTree, PictureOptions, FileHandle } from './tree';
/**
* Helper that composes makePictureTree with the DOM adapter for generating
* actual picture elements.
*/
const picture = (
handle: FileHandle,
opts?: PictureOptions
): any => {
return makePicture(makePictureTree(handle, opts));
};
export {
makePictureTree,
TransformOptions,
EStyleType,
EShapeType,
ENoiseType,
EFitOptions,
EColorspaceType,
EBlurMode,
EAlignOptions,
EAlignFacesOptions,
ECropfacesType,
EVideoAccessMode,
EVideoTypes,
EVideoLocations,
EVideoAccess,
EUrlscreenshotAgent,
EUrlscreenshotMode,
EUrlscreenshotOrientation,
};
export const fsAdaptive = { picture };
export class FsAdaptiveWebComponent extends LitElement {
src: string = '';
alt: string;
width: string;
cname: string;
signature: string;
policy: string;
resolutions: string[];
formats: string[];
sizes: any;
class: string;
id: string;
render() {
let security;
if (this.signature && this.policy) {
security = { signature: this.signature, policy: this.policy };
}
const options: any = {
security,
alt: this.alt,
width: this.width,
cname: this.cname,
sizes: this.sizes,
formats: this.formats,
};
if (this.resolutions) {
options.resolutions = this.resolutions;
}
const el = fsAdaptive.picture(this.src, options);
if (el && this.class) {
el.setAttribute('class', this.class);
}
if (el && this.id) {
el.setAttribute('id', this.id);
}
return html`${el}`;
}
}