Skip to content

Commit

Permalink
feat: pass through ImageProps
Browse files Browse the repository at this point in the history
  • Loading branch information
Miaonster committed Apr 1, 2022
1 parent 3cc55d4 commit 6e3afc4
Show file tree
Hide file tree
Showing 16 changed files with 2,407 additions and 2,442 deletions.
1 change: 1 addition & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"plugin:@typescript-eslint/recommended",
"plugin:@typescript-eslint/recommended-requiring-type-checking",
"standard-with-typescript",
"plugin:prettier/recommended",
"plugin:jest/recommended"
],
"parserOptions": {
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ lib/
.vscode/
*.tgz
coverage
lerna-debug.log
14 changes: 0 additions & 14 deletions lerna-debug.log

This file was deleted.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@
"devDependencies": {
"@typescript-eslint/eslint-plugin": "4",
"@typescript-eslint/parser": "^4.15.1",
"babel-preset-taro": "3.2.13",
"babel-preset-taro": "3.4.4",
"cross-env": "^7.0.2",
"cz-conventional-changelog": "^3.0.2",
"eslint": "7",
"eslint": "7.32.0",
"eslint-config-prettier": "^8.1.0",
"eslint-config-standard": "^16.0.2",
"eslint-config-standard-with-typescript": "^20.0.0",
"eslint-config-taro": "3.2.13",
"eslint-config-taro": "3.4.4",
"eslint-import-resolver-typescript": "^2.4.0",
"eslint-plugin-import": "2",
"eslint-plugin-jest": "^24.3.6",
Expand All @@ -52,7 +52,7 @@
"eslint-plugin-react": "^7.8.2",
"eslint-plugin-react-hooks": "^4.2.0",
"eslint-plugin-standard": "^5.0.0",
"eslint-plugin-taro": "3.2.13",
"eslint-plugin-taro": "3.3.20",
"husky": "^6.0.0",
"lerna": "^3.22.1",
"lint-staged": "^10.5.4",
Expand Down
11 changes: 3 additions & 8 deletions packages/taro-code-demo/babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,7 @@
// https://github.com/NervJS/taro/blob/next/packages/babel-preset-taro/README.md
module.exports = {
presets: [
[
'taro',
{
framework: 'react',
ts: true
}
]
]
['taro', { framework: 'react', ts: true }],
'@babel/preset-typescript',
],
}
16 changes: 8 additions & 8 deletions packages/taro-code-demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,23 +39,23 @@
],
"dependencies": {
"@babel/runtime": "^7.7.7",
"@tarojs/components": "3.2.13",
"@tarojs/react": "3.2.13",
"@tarojs/runtime": "3.2.13",
"@tarojs/taro": "3.2.13",
"@tarojs/components": "3.4.4",
"@tarojs/react": "3.4.4",
"@tarojs/runtime": "3.4.4",
"@tarojs/taro": "3.4.4",
"react": "^17.0.0",
"react-dom": "^17.0.0",
"react-test-renderer": "^16.13.1",
"taro-code": "file:../taro-code"
},
"devDependencies": {
"@babel/core": "^7.8.0",
"@tarojs/cli": "3.2.13",
"@tarojs/mini-runner": "3.2.13",
"@tarojs/webpack-runner": "3.2.13",
"@tarojs/cli": "3.4.4",
"@tarojs/mini-runner": "3.4.4",
"@tarojs/webpack-runner": "3.4.4",
"@types/jest": "^26.0.23",
"babel-plugin-istanbul": "^6.0.0",
"babel-preset-taro": "3.2.13",
"babel-preset-taro": "3.4.4",
"nervjs": "^1.5.7",
"rimraf": "^3.0.2",
"typescript": "4.3.2"
Expand Down
21 changes: 16 additions & 5 deletions packages/taro-code-demo/project.config.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"miniprogramRoot": "lib/",
"miniprogramRoot": "lib/weapp/",
"projectname": "taro-code",
"description": "Taro.js barcode & qrcode",
"appid": "touristappid",
"appid": "wxdb0595bd3394feb6",
"setting": {
"urlCheck": true,
"es6": false,
Expand All @@ -21,17 +21,28 @@
"checkSiteMap": true,
"uploadWithSourceMap": true,
"compileHotReLoad": false,
"lazyloadPlaceholderEnable": false,
"useMultiFrameRuntime": true,
"useApiHook": true,
"useApiHostProcess": true,
"babelSetting": {
"ignore": [],
"disablePlugins": [],
"outputPath": ""
},
"enableEngineNative": false,
"useIsolateContext": true,
"useCompilerModule": false,
"userConfirmedUseCompilerModuleSwitch": false
"userConfirmedBundleSwitch": false,
"packNpmManually": false,
"packNpmRelationList": [],
"minifyWXSS": true,
"disableUseStrict": false,
"minifyWXML": true,
"showES6CompileOption": false,
"useCompilerPlugins": false
},
"compileType": "miniprogram",
"simulatorType": "wechat",
"simulatorPluginLibVersion": {},
"condition": {}
}
}
2 changes: 1 addition & 1 deletion packages/taro-code-demo/src/app.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react'

class App extends React.Component {
render (): React.ReactNode {
render(): React.ReactNode {
return this.props.children
}
}
Expand Down
9 changes: 8 additions & 1 deletion packages/taro-code-demo/src/pages/index/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useEffect, useState } from 'react'
import React, { useEffect, useRef, useState } from 'react'
import { View } from '@tarojs/components'
import { Barcode, QRCode } from '../../../../taro-code/lib'
import './index.css'
Expand All @@ -19,23 +19,30 @@ const Index: React.FC = () => {
}
}, [])

const barcodeRef = useRef(null)
const qrcodeRef = useRef(null)

return (
<View className='index'>
<View className='barcode'>
<Barcode
ref={barcodeRef}
text={text}
width={size}
height={60}
foregroundColor={foregroundColor}
backgroundColor={backgroundColor}
showMenuByLongpress
/>
</View>
<View className='qrcode'>
<QRCode
ref={qrcodeRef}
text={text}
size={size}
foregroundColor={foregroundColor}
backgroundColor={backgroundColor}
showMenuByLongpress
/>
</View>
</View>
Expand Down
17 changes: 0 additions & 17 deletions packages/taro-code/oldjest.config.js

This file was deleted.

24 changes: 11 additions & 13 deletions packages/taro-code/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"source": "src/index.ts",
"scripts": {
"dev": "yarn run dev:lib",
"dev:lib": "tsc --project ./tsconfig.build.json --watch --incremental",
"dev:lib": "tsc --project ./tsconfig.build.json --watch --incremental --declaration",
"build": "yarn run build:rollup && yarn run build:lib",
"build:lib": "tsc --project ./tsconfig.build.json --declaration",
"build:rollup": "rollup --config ./config/rollup.config.js",
Expand Down Expand Up @@ -48,13 +48,13 @@
"@rollup/plugin-commonjs": "^15.0.0",
"@rollup/plugin-json": "^4.1.0",
"@rollup/plugin-node-resolve": "^9.0.0",
"@tarojs/cli": "3.2.13",
"@tarojs/components": "3.2.13",
"@tarojs/mini-runner": "3.2.13",
"@tarojs/react": "3.2.13",
"@tarojs/runtime": "3.2.13",
"@tarojs/taro": "3.2.13",
"@tarojs/webpack-runner": "3.2.13",
"@tarojs/cli": "3.4.4",
"@tarojs/components": "3.4.4",
"@tarojs/mini-runner": "3.4.4",
"@tarojs/react": "3.4.4",
"@tarojs/runtime": "3.4.4",
"@tarojs/taro": "3.4.4",
"@tarojs/webpack-runner": "3.4.4",
"@testing-library/react": "^11.2.7",
"@types/classnames": "^2.2.10",
"@types/enzyme": "^3.10.8",
Expand All @@ -70,15 +70,13 @@
"@types/wechat-miniprogram": "^3.3.0",
"babel-jest": "^27.0.2",
"babel-plugin-istanbul": "^6.0.0",
"babel-preset-taro": "3.2.13",
"babel-preset-taro": "3.4.4",
"cross-env": "^7.0.2",
"enzyme": "^3.11.0",
"enzyme-adapter-react-16": "^1.15.6",
"enzyme-to-json": "^3.6.2",
"jest": "^26.4.1",
"nervjs": "^1.5.7",
"react": "^16.13.1",
"react-dom": "^16.13.1",
"rimraf": "^3.0.2",
"rollup": "^2.26.4",
"rollup-plugin-copy": "^3.3.0",
Expand All @@ -91,8 +89,8 @@
},
"peerDependencies": {
"@tarojs/react": ">=3",
"react": ">=16.13.0",
"react-dom": ">=16.13.0"
"react": ">=17.0.0",
"react-dom": ">=17.0.0"
},
"dependencies": {
"react-test-renderer": "^17.0.2"
Expand Down
64 changes: 31 additions & 33 deletions packages/taro-code/src/common/barcode/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,38 +77,36 @@ function getBuffer ({ pieces, width, extraBytes, scale = 1, whiteColor = '', bla
.join('')
}

export default function barcode ({ text, scale = 4, blackColor, whiteColor }) {
if (text) {
const pieces = code128(text)
const width = pieces.length * scale
const height = 1
const extraBytes = width % 4
const colorSize = height * (3 * width + extraBytes)
const offset = 54
const fileSize = colorSize + offset
const fileSizeBytes = getLittleEndianHex(fileSize)
const numFileBytes = getLittleEndianHex(colorSize)
const w = getLittleEndianHex(width)
const h = getLittleEndianHex(height)
const imgdata = getBuffer({ pieces, width, extraBytes, scale, blackColor, whiteColor })
export default function barcode ({ text = '', scale = 4, blackColor, whiteColor }) {
const pieces = code128(text)
const width = pieces.length * scale
const height = 1
const extraBytes = width % 4
const colorSize = height * (3 * width + extraBytes)
const offset = 54
const fileSize = colorSize + offset
const fileSizeBytes = getLittleEndianHex(fileSize)
const numFileBytes = getLittleEndianHex(colorSize)
const w = getLittleEndianHex(width)
const h = getLittleEndianHex(height)
const imgdata = getBuffer({ pieces, width, extraBytes, scale, blackColor, whiteColor })

const header =
'BM' + // Signature
fileSizeBytes + // size of the file (bytes)
'\x00\x00' + // reserved
'\x00\x00' + // reserved
'\x36\x00\x00\x00' + // offset of where BMP data lives (54 bytes)
'\x28\x00\x00\x00' + // number of remaining bytes in header from here (40 bytes)
w + // the width of the bitmap in pixels*
h + // the height of the bitmap in pixels*
'\x01\x00' + // the number of color planes (1)
'\x18\x00' + // 24 bits / pixel
'\x00\x00\x00\x00' + // No compression (0)
numFileBytes + // size of the BMP data (bytes)*
'\x13\x0B\x00\x00' + // 2835 pixels/meter - horizontal resolution
'\x13\x0B\x00\x00' + // 2835 pixels/meter - the vertical resolution
'\x00\x00\x00\x00' + // Number of colors in the palette (keep 0 for 32-bit)
'\x00\x00\x00\x00' // 0 important colors (means all colors are important)
return 'data:image/bmp;base64,' + btoa(header + imgdata)
}
const header =
'BM' + // Signature
fileSizeBytes + // size of the file (bytes)
'\x00\x00' + // reserved
'\x00\x00' + // reserved
'\x36\x00\x00\x00' + // offset of where BMP data lives (54 bytes)
'\x28\x00\x00\x00' + // number of remaining bytes in header from here (40 bytes)
w + // the width of the bitmap in pixels*
h + // the height of the bitmap in pixels*
'\x01\x00' + // the number of color planes (1)
'\x18\x00' + // 24 bits / pixel
'\x00\x00\x00\x00' + // No compression (0)
numFileBytes + // size of the BMP data (bytes)*
'\x13\x0B\x00\x00' + // 2835 pixels/meter - horizontal resolution
'\x13\x0B\x00\x00' + // 2835 pixels/meter - the vertical resolution
'\x00\x00\x00\x00' + // Number of colors in the palette (keep 0 for 32-bit)
'\x00\x00\x00\x00' // 0 important colors (means all colors are important)
return 'data:image/bmp;base64,' + btoa(header + imgdata)
}
Loading

0 comments on commit 6e3afc4

Please sign in to comment.