diff --git a/doric-demo/package.json b/doric-demo/package.json index 0fa91002..700f1e7a 100644 --- a/doric-demo/package.json +++ b/doric-demo/package.json @@ -18,8 +18,9 @@ "typescript": "^3.7.4" }, "devDependencies": { + "@rollup/plugin-buble": "^0.21.0", "@rollup/plugin-commonjs": "^11.0.1", - "@rollup/plugin-node-resolve": "^7.0.0", - "@rollup/plugin-buble": "^0.21.0" + "@rollup/plugin-image": "^2.0.4", + "@rollup/plugin-node-resolve": "^7.0.0" } } diff --git a/doric-demo/rollup.config.js b/doric-demo/rollup.config.js index 86262251..de3bd801 100644 --- a/doric-demo/rollup.config.js +++ b/doric-demo/rollup.config.js @@ -3,8 +3,50 @@ import commonjs from '@rollup/plugin-commonjs' import bundles from './build/index' import fs from 'fs' import path from 'path' -import buble from '@rollup/plugin-buble'; +import buble from '@rollup/plugin-buble' import json from "@rollup/plugin-json" +import image from '@rollup/plugin-image' + +function searchImages(dir, images) { + const files = fs.readdirSync(dir) + files.forEach((item, index) => { + var fullPath = path.join(dir, item) + const stat = fs.statSync(fullPath) + if (stat.isDirectory()) { + searchImages(path.join(dir, item), images) + } else { + if(fullPath.endsWith('.png')) { + images.push(fullPath) + } + } + }) + return images +} + +const allImages = [] +searchImages('src', allImages) + +function mkdirsSync(dirname) { + if (fs.existsSync(dirname)) { + return true + } else { + if (mkdirsSync(path.dirname(dirname))) { + fs.mkdirSync(dirname) + return true + } + } +} + +allImages.forEach((value) => { + let path = __dirname + '/build/' + value + let index = path.lastIndexOf('/') + mkdirsSync(path.substring(0, index)) + + fs.copyFile(__dirname + '/' + value, __dirname + '/build/' + value, error => { + console.log(error) + }) +}) + function readDirs(dirPath, files) { if (fs.statSync(dirPath).isDirectory()) { @@ -51,11 +93,12 @@ export default resolve({ mainFields: ["jsnext"] }), commonjs(), json(), + image(), ], external: ['reflect-metadata', 'doric'], onwarn: function (warning) { - if (warning.code === 'THIS_IS_UNDEFINED') { return; } - console.warn(warning.message); + if (warning.code === 'THIS_IS_UNDEFINED') { return } + console.warn(warning.message) } } }).concat( @@ -76,11 +119,12 @@ export default buble({ transforms: { dangerousForOf: true } }), + image(), ], external: ['reflect-metadata', 'doric'], onwarn: function (warning) { - if (warning.code === 'THIS_IS_UNDEFINED') { return; } - console.warn(warning.message); + if (warning.code === 'THIS_IS_UNDEFINED') { return } + console.warn(warning.message) } } })) \ No newline at end of file diff --git a/doric-demo/src/ImageDemo.ts b/doric-demo/src/ImageDemo.ts index 8d6ae2b3..fdc24947 100644 --- a/doric-demo/src/ImageDemo.ts +++ b/doric-demo/src/ImageDemo.ts @@ -1,8 +1,11 @@ import { Group, Panel, coordinator, text, gravity, Color, LayoutSpec, log, vlayout, scroller, layoutConfig, image, ScaleType, Image } from "doric"; import { colors, label } from "./utils"; import { img_base64 } from "./image_base64"; + const imageUrl = 'https://img.zcool.cn/community/01e75b5da933daa801209e1ffa4649.jpg@1280w_1l_2o_100sh.jpg' +import logo from "./images/logo_w.png" + @Entry class ImageDemo extends Panel { build(rootView: Group): void { @@ -124,7 +127,16 @@ class ImageDemo extends Panel { right: 0.149, bottom: 0 } - }) + }), + label('Asset Image'), + image({ + imageBase64: logo, + width: 235, + height: 235, + backgroundColor: Color.BLACK, + scaleType: ScaleType.ScaleAspectFill, + layoutConfig: layoutConfig().just(), + }), ], { layoutConfig: layoutConfig().most().configHeight(LayoutSpec.FIT), diff --git a/doric-demo/src/image.d.ts b/doric-demo/src/image.d.ts new file mode 100644 index 00000000..64607709 --- /dev/null +++ b/doric-demo/src/image.d.ts @@ -0,0 +1,4 @@ +declare module '*.png' { + const value: any; + export default value; +} \ No newline at end of file diff --git a/doric-demo/src/images/logo_w.png b/doric-demo/src/images/logo_w.png new file mode 100644 index 00000000..57b1dd54 Binary files /dev/null and b/doric-demo/src/images/logo_w.png differ