@react-native-ohos/react-native-blurhash 2.0.4-rc.4 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/harmony/blurhash/BuildProfile.ets +17 -0
- package/harmony/blurhash/index.ets +0 -2
- package/harmony/blurhash/oh-package.json5 +1 -1
- package/harmony/blurhash/src/main/cpp/Blurhash.cpp +78 -172
- package/harmony/blurhash/src/main/cpp/{Blurhash.h → Blurhash.hpp} +3 -6
- package/harmony/blurhash/src/main/cpp/BlurhashNode.cpp +12 -18
- package/harmony/blurhash/src/main/cpp/BlurhashNode.h +2 -3
- package/harmony/blurhash/src/main/cpp/BlurhashPackage.h +12 -23
- package/harmony/blurhash/src/main/cpp/BlurhashViewComponentInstance.cpp +82 -56
- package/harmony/blurhash/src/main/cpp/BlurhashViewComponentInstance.h +5 -8
- package/harmony/blurhash/src/main/cpp/BlurhashViewJSIBinder.h +7 -11
- package/harmony/blurhash/src/main/cpp/ComponentDescriptors.h +2 -4
- package/harmony/blurhash/src/main/cpp/EventEmitters.cpp +8 -9
- package/harmony/blurhash/src/main/cpp/EventEmitters.h +4 -4
- package/harmony/blurhash/src/main/cpp/Props.cpp +10 -11
- package/harmony/blurhash/src/main/cpp/Props.h +13 -19
- package/harmony/blurhash/src/main/cpp/RNBlurhashTurboModule.cpp +10 -16
- package/harmony/blurhash/src/main/cpp/RNBlurhashTurboModule.h +3 -3
- package/harmony/blurhash/src/main/cpp/ShadowNodes.cpp +2 -1
- package/harmony/blurhash/src/main/cpp/ShadowNodes.h +5 -5
- package/harmony/blurhash/src/main/cpp/SparseArray.cpp +4 -7
- package/harmony/blurhash/src/main/cpp/SparseArray.h +2 -2
- package/harmony/blurhash/src/main/cpp/napi_init.cpp +6 -5
- package/harmony/blurhash/src/main/cpp/types/libblurhash/Index.d.ts +1 -1
- package/harmony/blurhash/src/main/ets/{BlurhashPackage.ets → BlurhashPackage.ts} +2 -3
- package/harmony/blurhash/src/main/ets/BlurhashTurboModule.ts +2 -1
- package/{lib/commonjs/blurhash/ts.ets → harmony/blurhash/ts.ts} +1 -1
- package/harmony/blurhash.har +0 -0
- package/lib/commonjs/index.js +95 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/commonjs/specs/NativeBlurhashModule.js +9 -0
- package/lib/commonjs/specs/NativeBlurhashModule.js.map +1 -0
- package/lib/commonjs/specs/NativeBlurhashView.js +10 -0
- package/lib/commonjs/specs/NativeBlurhashView.js.map +1 -0
- package/lib/commonjs/utils.js +56 -0
- package/lib/commonjs/utils.js.map +1 -0
- package/lib/module/index.js +85 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/specs/NativeBlurhashModule.js +3 -0
- package/lib/module/specs/NativeBlurhashModule.js.map +1 -0
- package/lib/module/specs/NativeBlurhashView.js +3 -0
- package/lib/module/specs/NativeBlurhashView.js.map +1 -0
- package/lib/module/utils.js +48 -0
- package/lib/module/utils.js.map +1 -0
- package/lib/typescript/index.d.ts +90 -0
- package/lib/typescript/specs/NativeBlurhashModule.d.ts +9 -0
- package/lib/typescript/specs/NativeBlurhashView.d.ts +19 -0
- package/lib/typescript/utils.d.ts +22 -0
- package/package.json +5 -12
- package/harmony/blurhash/ts.ets +0 -26
- package/lib/commonjs/blurhash/hvigorfile.js +0 -13
- package/lib/commonjs/blurhash/hvigorfile.js.map +0 -1
- package/lib/commonjs/blurhash/oh-package.json5 +0 -13
- package/lib/commonjs/blurhash/src/main/ets/BlurhashTurboModule.js +0 -49
- package/lib/commonjs/blurhash/src/main/ets/BlurhashTurboModule.js.map +0 -1
- package/lib/commonjs/blurhash/src/main/ets/Logger.js +0 -66
- package/lib/commonjs/blurhash/src/main/ets/Logger.js.map +0 -1
- package/lib/commonjs/blurhash/src/main/ets/RNCBlurhashView.js +0 -111
- package/lib/commonjs/blurhash/src/main/ets/RNCBlurhashView.js.map +0 -1
- package/lib/commonjs/blurhash/src/main/ets/RNCSpecs.js +0 -117
- package/lib/commonjs/blurhash/src/main/ets/RNCSpecs.js.map +0 -1
- package/lib/commonjs/blurhash/src/main/ets/TMSpecs.js +0 -34
- package/lib/commonjs/blurhash/src/main/ets/TMSpecs.js.map +0 -1
- package/lib/commonjs/blurhash.har +0 -0
package/harmony/blurhash.har
CHANGED
|
Binary file
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.Blurhash = void 0;
|
|
7
|
+
var React = _interopRequireWildcard(require("react"));
|
|
8
|
+
var _reactNative = require("react-native");
|
|
9
|
+
var _NativeBlurhashModule = _interopRequireDefault(require("./specs/NativeBlurhashModule"));
|
|
10
|
+
var _NativeBlurhashView = _interopRequireDefault(require("./specs/NativeBlurhashView"));
|
|
11
|
+
var _utils = require("./utils");
|
|
12
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
14
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
15
|
+
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
16
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
17
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : String(i); }
|
|
18
|
+
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
19
|
+
class Blurhash extends React.PureComponent {
|
|
20
|
+
constructor(props) {
|
|
21
|
+
super(props);
|
|
22
|
+
this._onLoadStart = this._onLoadStart.bind(this);
|
|
23
|
+
this._onLoadEnd = this._onLoadEnd.bind(this);
|
|
24
|
+
this._onLoadError = this._onLoadError.bind(this);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Encodes the given image URI to a blurhash string
|
|
29
|
+
* @param imageUri An URI to an Image parseable by the react native image loader
|
|
30
|
+
* @param componentsX The number of X components
|
|
31
|
+
* @param componentsY The number of Y components
|
|
32
|
+
* @example
|
|
33
|
+
* const blurhash = await Blurhash.encode('https://blurha.sh/assets/images/img2.jpg')
|
|
34
|
+
*/
|
|
35
|
+
static encode(imageUri, componentsX, componentsY) {
|
|
36
|
+
if (typeof imageUri !== 'string') throw new Error('imageUri must be a non-empty string!');
|
|
37
|
+
if (typeof componentsX !== 'number') throw new Error('componentsX must be a valid positive number!');
|
|
38
|
+
if (typeof componentsY !== 'number') throw new Error('componentsY must be a valid positive number!');
|
|
39
|
+
return _NativeBlurhashModule.default.createBlurhashFromImage(imageUri, componentsX, componentsY);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Gets the average color in a given blurhash string.
|
|
44
|
+
*
|
|
45
|
+
* This uses the JS blurhash decoder, so it might be slow.
|
|
46
|
+
* @param blurhash The blurhash string
|
|
47
|
+
* @example
|
|
48
|
+
* const averageColor = Blurhash.getAverageColor(`LGFFaXYk^6#M@-5c,1J5@[or[Q6.`)
|
|
49
|
+
*/
|
|
50
|
+
static getAverageColor(blurhash) {
|
|
51
|
+
if (blurhash == null || blurhash.length < 7) return undefined;
|
|
52
|
+
const value = (0, _utils.decode83)(blurhash.substring(2, 6));
|
|
53
|
+
return (0, _utils.decodeDC)(value);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Clears the cosine cache and frees up memory.
|
|
58
|
+
*
|
|
59
|
+
* @platform Android
|
|
60
|
+
* @see https://github.com/mrousavy/react-native-blurhash#cosine-operations
|
|
61
|
+
*/
|
|
62
|
+
static clearCosineCache() {
|
|
63
|
+
if (_reactNative.Platform.OS === 'android' || _reactNative.Platform.OS === 'harmony') _NativeBlurhashModule.default.clearCosineCache();else console.warn('Blurhash.clearCosineCache is only available on Android.');
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Verifies if the given blurhash is valid by checking it's type, length and size flag.
|
|
68
|
+
*
|
|
69
|
+
* This uses the JS blurhash decoder, so it might be slow.
|
|
70
|
+
* @param blurhash The given blurhash string
|
|
71
|
+
*/
|
|
72
|
+
static isBlurhashValid(blurhash) {
|
|
73
|
+
return (0, _utils.isBlurhashValid)(blurhash);
|
|
74
|
+
}
|
|
75
|
+
_onLoadStart() {
|
|
76
|
+
if (this.props.onLoadStart != null) this.props.onLoadStart();
|
|
77
|
+
}
|
|
78
|
+
_onLoadEnd() {
|
|
79
|
+
if (this.props.onLoadEnd != null) this.props.onLoadEnd();
|
|
80
|
+
}
|
|
81
|
+
_onLoadError(event) {
|
|
82
|
+
var _event$nativeEvent;
|
|
83
|
+
if (this.props.onLoadError != null) this.props.onLoadError(event === null || event === void 0 || (_event$nativeEvent = event.nativeEvent) === null || _event$nativeEvent === void 0 ? void 0 : _event$nativeEvent.message);
|
|
84
|
+
}
|
|
85
|
+
render() {
|
|
86
|
+
return /*#__PURE__*/React.createElement(_NativeBlurhashView.default, _extends({}, this.props, {
|
|
87
|
+
onLoadStart: this._onLoadStart,
|
|
88
|
+
onLoadEnd: this._onLoadEnd,
|
|
89
|
+
onLoadError: this._onLoadError
|
|
90
|
+
}));
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
exports.Blurhash = Blurhash;
|
|
94
|
+
_defineProperty(Blurhash, "displayName", 'Blurhash');
|
|
95
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["React","_interopRequireWildcard","require","_reactNative","_NativeBlurhashModule","_interopRequireDefault","_NativeBlurhashView","_utils","obj","__esModule","default","_getRequireWildcardCache","e","WeakMap","r","t","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","prototype","hasOwnProperty","call","i","set","_extends","assign","bind","target","arguments","length","source","key","apply","_defineProperty","value","_toPropertyKey","enumerable","configurable","writable","_toPrimitive","String","Symbol","toPrimitive","TypeError","Number","Blurhash","PureComponent","constructor","props","_onLoadStart","_onLoadEnd","_onLoadError","encode","imageUri","componentsX","componentsY","Error","NativeBlurhashModule","createBlurhashFromImage","getAverageColor","blurhash","undefined","decode83","substring","decodeDC","clearCosineCache","Platform","OS","console","warn","isBlurhashValid","onLoadStart","onLoadEnd","event","_event$nativeEvent","onLoadError","nativeEvent","message","render","createElement","exports"],"sources":["index.tsx"],"sourcesContent":["import * as React from 'react';\nimport { Platform, type NativeSyntheticEvent, type ViewProps } from 'react-native';\nimport NativeBlurhashModule from './specs/NativeBlurhashModule';\nimport NativeBlurhashView from './specs/NativeBlurhashView';\nimport { decode83, decodeDC, isBlurhashValid, type RGB } from './utils';\n\nexport interface BlurhashProps extends Omit<ViewProps, 'children'> {\n\t/**\n\t * The blurhash string to use. Example: `LGFFaXYk^6#M@-5c,1J5@[or[Q6`.\n\t */\n\tblurhash: string;\n\t/**\n\t * The width (resolution) to decode to. Higher values decrease performance, use `16` for large lists, otherwise you can increase it to `32`.\n\t * @default 32\n\t */\n\tdecodeWidth?: number;\n\t/**\n\t * The height (resolution) to decode to. Higher values decrease performance, use `16` for large lists, otherwise you can increase it to `32`.\n\t * @default 32\n\t */\n\tdecodeHeight?: number;\n\t/**\n\t * Adjusts the contrast of the output image. Tweak it if you want a different look for your placeholders.\n\t * @default 1.0\n\t */\n\tdecodePunch?: number;\n\t/**\n\t * Asynchronously decode the Blurhash on a background Thread instead of the UI-Thread.\n\t * Read the [performance documentation](https://github.com/mrousavy/react-native-blurhash#performance)\n\t * before enabling this.\n\t * @default false\n\t */\n\tdecodeAsync?: boolean;\n\t/**\n\t * Adjusts the resize mode of the image.\n\t * @default 'cover'\n\t */\n\tresizeMode?: 'cover' | 'contain' | 'stretch' | 'center';\n\n\t/**\n\t * Emitted when the Blurhash received new parameters and started to decode the given `blurhash` string.\n\t */\n\tonLoadStart?: () => void;\n\n\t/**\n\t * Emitted when the Blurhash successfully decoded the given `blurhash` string and rendered the image to the `<Blurhash>` view.\n\t */\n\tonLoadEnd?: () => void;\n\n\t/**\n\t * Emitted when the Blurhash failed to decode/load.\n\t */\n\tonLoadError?: (message?: string) => void;\n}\n\nexport class Blurhash extends React.PureComponent<BlurhashProps> {\n\tstatic displayName = 'Blurhash';\n\n\tconstructor(props: BlurhashProps) {\n\t\tsuper(props);\n\t\tthis._onLoadStart = this._onLoadStart.bind(this);\n\t\tthis._onLoadEnd = this._onLoadEnd.bind(this);\n\t\tthis._onLoadError = this._onLoadError.bind(this);\n\t}\n\n\t/**\n\t * Encodes the given image URI to a blurhash string\n\t * @param imageUri An URI to an Image parseable by the react native image loader\n\t * @param componentsX The number of X components\n\t * @param componentsY The number of Y components\n\t * @example\n\t * const blurhash = await Blurhash.encode('https://blurha.sh/assets/images/img2.jpg')\n\t */\n\tstatic encode(imageUri: string, componentsX: number, componentsY: number): Promise<string> {\n\t\tif (typeof imageUri !== 'string') throw new Error('imageUri must be a non-empty string!');\n\t\tif (typeof componentsX !== 'number') throw new Error('componentsX must be a valid positive number!');\n\t\tif (typeof componentsY !== 'number') throw new Error('componentsY must be a valid positive number!');\n\n\t\treturn NativeBlurhashModule.createBlurhashFromImage(imageUri, componentsX, componentsY);\n\t}\n\n\t/**\n\t * Gets the average color in a given blurhash string.\n\t *\n\t * This uses the JS blurhash decoder, so it might be slow.\n\t * @param blurhash The blurhash string\n\t * @example\n\t * const averageColor = Blurhash.getAverageColor(`LGFFaXYk^6#M@-5c,1J5@[or[Q6.`)\n\t */\n\tstatic getAverageColor(blurhash: string): RGB | undefined {\n\t\tif (blurhash == null || blurhash.length < 7) return undefined;\n\n\t\tconst value = decode83(blurhash.substring(2, 6));\n\t\treturn decodeDC(value);\n\t}\n\n\t/**\n\t * Clears the cosine cache and frees up memory.\n\t *\n\t * @platform Android\n\t * @see https://github.com/mrousavy/react-native-blurhash#cosine-operations\n\t */\n\tstatic clearCosineCache(): void {\n\t\tif (Platform.OS === 'android') NativeBlurhashModule.clearCosineCache();\n\t\telse console.warn('Blurhash.clearCosineCache is only available on Android.');\n\t}\n\n\t/**\n\t * Verifies if the given blurhash is valid by checking it's type, length and size flag.\n\t *\n\t * This uses the JS blurhash decoder, so it might be slow.\n\t * @param blurhash The given blurhash string\n\t */\n\tstatic isBlurhashValid(blurhash: string): ReturnType<typeof isBlurhashValid> {\n\t\treturn isBlurhashValid(blurhash);\n\t}\n\n\t_onLoadStart() {\n\t\tif (this.props.onLoadStart != null) this.props.onLoadStart();\n\t}\n\t_onLoadEnd() {\n\t\tif (this.props.onLoadEnd != null) this.props.onLoadEnd();\n\t}\n\t_onLoadError(event?: NativeSyntheticEvent<{ message?: string }>) {\n\t\tif (this.props.onLoadError != null) this.props.onLoadError(event?.nativeEvent?.message);\n\t}\n\n\trender() {\n\t\treturn <NativeBlurhashView {...this.props} onLoadStart={this._onLoadStart} onLoadEnd={this._onLoadEnd} onLoadError={this._onLoadError} />;\n\t}\n}\n"],"mappings":";;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C6B,OAAA,CAAAnC,QAAA,GAAAA,QAAA;AAAAZ,eAAA,CA3EYY,QAAQ,iBACC,UAAU"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _reactNative = require("react-native");
|
|
8
|
+
var _default = exports.default = _reactNative.TurboModuleRegistry.getEnforcing('BlurhashModule');
|
|
9
|
+
//# sourceMappingURL=NativeBlurhashModule.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_reactNative","require","_default","exports","default","TurboModuleRegistry","getEnforcing"],"sources":["NativeBlurhashModule.ts"],"sourcesContent":["import { type TurboModule, TurboModuleRegistry } from 'react-native';\nimport type { Int32 } from 'react-native/Libraries/Types/CodegenTypes';\n\nexport interface Spec extends TurboModule {\n\tcreateBlurhashFromImage: (imageUri: string, componentsX: Int32, componentsY: Int32) => Promise<string>;\n\tclearCosineCache: () => void;\n}\n\nexport default TurboModuleRegistry.getEnforcing<Spec>('BlurhashModule');\n"],"mappings":";;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AAAqE,IAAAC,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAQtDC,gCAAmB,CAACC,YAAY,CAAO,gBAAgB,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _codegenNativeComponent = _interopRequireDefault(require("react-native/Libraries/Utilities/codegenNativeComponent"));
|
|
8
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
9
|
+
var _default = exports.default = (0, _codegenNativeComponent.default)('BlurhashView');
|
|
10
|
+
//# sourceMappingURL=NativeBlurhashView.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_codegenNativeComponent","_interopRequireDefault","require","obj","__esModule","default","_default","exports","codegenNativeComponent"],"sources":["NativeBlurhashView.ts"],"sourcesContent":["import codegenNativeComponent from 'react-native/Libraries/Utilities/codegenNativeComponent';\nimport type { DirectEventHandler, Double, Int32, WithDefault } from 'react-native/Libraries/Types/CodegenTypes';\nimport type { ViewProps } from 'react-native';\n\ntype OnLoadErrorEvent = { message?: string };\n\ninterface NativeProps extends ViewProps {\n\tblurhash: string;\n\tdecodeWidth?: WithDefault<Int32, 32>;\n\tdecodeHeight?: WithDefault<Int32, 32>;\n\tdecodePunch?: WithDefault<Double, 1>;\n\tdecodeAsync?: WithDefault<boolean, false>;\n\tresizeMode?: WithDefault<'cover' | 'contain' | 'stretch' | 'center', 'cover'>;\n\tonLoadStart?: DirectEventHandler<null>;\n\tonLoadEnd?: DirectEventHandler<null>;\n\tonLoadError?: DirectEventHandler<OnLoadErrorEvent>;\n}\n\nexport default codegenNativeComponent<NativeProps>('BlurhashView');\n"],"mappings":";;;;;;AAAA,IAAAA,uBAAA,GAAAC,sBAAA,CAAAC,OAAA;AAA6F,SAAAD,uBAAAE,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAAA,IAAAG,QAAA,GAAAC,OAAA,CAAAF,OAAA,GAkB9E,IAAAG,+BAAsB,EAAc,cAAc,CAAC"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.decode83 = decode83;
|
|
7
|
+
exports.decodeDC = decodeDC;
|
|
8
|
+
exports.isBlurhashValid = isBlurhashValid;
|
|
9
|
+
// Some functions from the Blurhash JS implementation that are used for light tasks (such as getting the average color or validating if a blurhash string is valid)
|
|
10
|
+
|
|
11
|
+
function sRGBToLinear(value) {
|
|
12
|
+
const v = value / 255;
|
|
13
|
+
if (v <= 0.04045) return v / 12.92;else return Math.pow((v + 0.055) / 1.055, 2.4);
|
|
14
|
+
}
|
|
15
|
+
function decodeDC(value) {
|
|
16
|
+
const intR = value >> 16;
|
|
17
|
+
const intG = value >> 8 & 255;
|
|
18
|
+
const intB = value & 255;
|
|
19
|
+
return {
|
|
20
|
+
r: sRGBToLinear(intR) * 255,
|
|
21
|
+
g: sRGBToLinear(intG) * 255,
|
|
22
|
+
b: sRGBToLinear(intB) * 255
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
function decode83(str) {
|
|
26
|
+
let value = 0;
|
|
27
|
+
for (let i = 0; i < str.length; i++) {
|
|
28
|
+
const c = str[i];
|
|
29
|
+
const digit = digitCharacters.indexOf(c);
|
|
30
|
+
value = value * 83 + digit;
|
|
31
|
+
}
|
|
32
|
+
return value;
|
|
33
|
+
}
|
|
34
|
+
function validateBlurhash(blurhash) {
|
|
35
|
+
if (!blurhash || blurhash.length < 6) throw new Error('The blurhash string must be at least 6 characters');
|
|
36
|
+
const sizeFlag = decode83(blurhash[0]);
|
|
37
|
+
const numY = Math.floor(sizeFlag / 9) + 1;
|
|
38
|
+
const numX = sizeFlag % 9 + 1;
|
|
39
|
+
if (blurhash.length !== 4 + 2 * numX * numY) throw new Error(`blurhash length mismatch: length is ${blurhash.length} but it should be ${4 + 2 * numX * numY}`);
|
|
40
|
+
}
|
|
41
|
+
function isBlurhashValid(blurhash) {
|
|
42
|
+
try {
|
|
43
|
+
validateBlurhash(blurhash);
|
|
44
|
+
} catch (error) {
|
|
45
|
+
const message = error instanceof Error ? error.message : JSON.stringify(error);
|
|
46
|
+
return {
|
|
47
|
+
isValid: false,
|
|
48
|
+
errorReason: message
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
return {
|
|
52
|
+
isValid: true
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
const digitCharacters = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '#', '$', '%', '*', '+', ',', '-', '.', ':', ';', '=', '?', '@', '[', ']', '^', '_', '{', '|', '}', '~'];
|
|
56
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["sRGBToLinear","value","v","Math","pow","decodeDC","intR","intG","intB","r","g","b","decode83","str","i","length","c","digit","digitCharacters","indexOf","validateBlurhash","blurhash","Error","sizeFlag","numY","floor","numX","isBlurhashValid","error","message","JSON","stringify","isValid","errorReason"],"sources":["utils.ts"],"sourcesContent":["// Some functions from the Blurhash JS implementation that are used for light tasks (such as getting the average color or validating if a blurhash string is valid)\n\nexport interface RGB {\n\t/**\n\t * The Red value component of this RGB instance. Ranges from 0 to 255.\n\t */\n\tr: number;\n\t/**\n\t * The Green value component of this RGB instance. Ranges from 0 to 255.\n\t */\n\tg: number;\n\t/**\n\t * The Blue value component of this RGB instance. Ranges from 0 to 255.\n\t */\n\tb: number;\n}\n\nfunction sRGBToLinear(value: number): number {\n\tconst v = value / 255;\n\tif (v <= 0.04045) return v / 12.92;\n\telse return Math.pow((v + 0.055) / 1.055, 2.4);\n}\n\nexport function decodeDC(value: number): RGB {\n\tconst intR = value >> 16;\n\tconst intG = (value >> 8) & 255;\n\tconst intB = value & 255;\n\treturn { r: sRGBToLinear(intR) * 255, g: sRGBToLinear(intG) * 255, b: sRGBToLinear(intB) * 255 };\n}\n\nexport function decode83(str: string): number {\n\tlet value = 0;\n\tfor (let i = 0; i < str.length; i++) {\n\t\tconst c = str[i];\n\t\tconst digit = digitCharacters.indexOf(c);\n\t\tvalue = value * 83 + digit;\n\t}\n\treturn value;\n}\n\nfunction validateBlurhash(blurhash: string): void {\n\tif (!blurhash || blurhash.length < 6) throw new Error('The blurhash string must be at least 6 characters');\n\n\tconst sizeFlag = decode83(blurhash[0]);\n\tconst numY = Math.floor(sizeFlag / 9) + 1;\n\tconst numX = (sizeFlag % 9) + 1;\n\n\tif (blurhash.length !== 4 + 2 * numX * numY)\n\t\tthrow new Error(`blurhash length mismatch: length is ${blurhash.length} but it should be ${4 + 2 * numX * numY}`);\n}\n\nexport function isBlurhashValid(blurhash: string): { isValid: true } | { isValid: false; errorReason: string } {\n\ttry {\n\t\tvalidateBlurhash(blurhash);\n\t} catch (error) {\n\t\tconst message = error instanceof Error ? error.message : JSON.stringify(error);\n\t\treturn { isValid: false, errorReason: message };\n\t}\n\n\treturn { isValid: true };\n}\n\nconst digitCharacters = [\n\t'0',\n\t'1',\n\t'2',\n\t'3',\n\t'4',\n\t'5',\n\t'6',\n\t'7',\n\t'8',\n\t'9',\n\t'A',\n\t'B',\n\t'C',\n\t'D',\n\t'E',\n\t'F',\n\t'G',\n\t'H',\n\t'I',\n\t'J',\n\t'K',\n\t'L',\n\t'M',\n\t'N',\n\t'O',\n\t'P',\n\t'Q',\n\t'R',\n\t'S',\n\t'T',\n\t'U',\n\t'V',\n\t'W',\n\t'X',\n\t'Y',\n\t'Z',\n\t'a',\n\t'b',\n\t'c',\n\t'd',\n\t'e',\n\t'f',\n\t'g',\n\t'h',\n\t'i',\n\t'j',\n\t'k',\n\t'l',\n\t'm',\n\t'n',\n\t'o',\n\t'p',\n\t'q',\n\t'r',\n\t's',\n\t't',\n\t'u',\n\t'v',\n\t'w',\n\t'x',\n\t'y',\n\t'z',\n\t'#',\n\t'$',\n\t'%',\n\t'*',\n\t'+',\n\t',',\n\t'-',\n\t'.',\n\t':',\n\t';',\n\t'=',\n\t'?',\n\t'@',\n\t'[',\n\t']',\n\t'^',\n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G,EACH,GAAG,EACH,GAAG,EACH,GAAG,EACH,GAAG,EACH,GAAG,EACH,GAAG,EACH,GAAG,EACH,GAAG,EACH,GAAG,EACH,GAAG,EACH,GAAG,EACH,GAAG,EACH,GAAG,EACH,GAAG,EACH,GAAG,EACH,GAAG,EACH,GAAG,EACH,GAAG,EACH,GAAG,EACH,GAAG,EACH,GAAG,EACH,GAAG,EACH,GAAG,EACH,GAAG,EACH,GAAG,EACH,GAAG,EACH,GAAG,EACH,GAAG,EACH,GAAG,EACH,GAAG,EACH,GAAG,EACH,GAAG,EACH,GAAG,EACH,GAAG,EACH,GAAG,EACH,GAAG,EACH,GAAG,EACH,GAAG,EACH,GAAG,EACH,GAAG,EACH,GAAG,EACH,GAAG,EACH,GAAG,EACH,GAAG,EACH,GAAG,CACH"}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
2
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
3
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : String(i); }
|
|
4
|
+
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
5
|
+
import * as React from 'react';
|
|
6
|
+
import { Platform } from 'react-native';
|
|
7
|
+
import NativeBlurhashModule from './specs/NativeBlurhashModule';
|
|
8
|
+
import NativeBlurhashView from './specs/NativeBlurhashView';
|
|
9
|
+
import { decode83, decodeDC, isBlurhashValid } from './utils';
|
|
10
|
+
export class Blurhash extends React.PureComponent {
|
|
11
|
+
constructor(props) {
|
|
12
|
+
super(props);
|
|
13
|
+
this._onLoadStart = this._onLoadStart.bind(this);
|
|
14
|
+
this._onLoadEnd = this._onLoadEnd.bind(this);
|
|
15
|
+
this._onLoadError = this._onLoadError.bind(this);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Encodes the given image URI to a blurhash string
|
|
20
|
+
* @param imageUri An URI to an Image parseable by the react native image loader
|
|
21
|
+
* @param componentsX The number of X components
|
|
22
|
+
* @param componentsY The number of Y components
|
|
23
|
+
* @example
|
|
24
|
+
* const blurhash = await Blurhash.encode('https://blurha.sh/assets/images/img2.jpg')
|
|
25
|
+
*/
|
|
26
|
+
static encode(imageUri, componentsX, componentsY) {
|
|
27
|
+
if (typeof imageUri !== 'string') throw new Error('imageUri must be a non-empty string!');
|
|
28
|
+
if (typeof componentsX !== 'number') throw new Error('componentsX must be a valid positive number!');
|
|
29
|
+
if (typeof componentsY !== 'number') throw new Error('componentsY must be a valid positive number!');
|
|
30
|
+
return NativeBlurhashModule.createBlurhashFromImage(imageUri, componentsX, componentsY);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Gets the average color in a given blurhash string.
|
|
35
|
+
*
|
|
36
|
+
* This uses the JS blurhash decoder, so it might be slow.
|
|
37
|
+
* @param blurhash The blurhash string
|
|
38
|
+
* @example
|
|
39
|
+
* const averageColor = Blurhash.getAverageColor(`LGFFaXYk^6#M@-5c,1J5@[or[Q6.`)
|
|
40
|
+
*/
|
|
41
|
+
static getAverageColor(blurhash) {
|
|
42
|
+
if (blurhash == null || blurhash.length < 7) return undefined;
|
|
43
|
+
const value = decode83(blurhash.substring(2, 6));
|
|
44
|
+
return decodeDC(value);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Clears the cosine cache and frees up memory.
|
|
49
|
+
*
|
|
50
|
+
* @platform Android
|
|
51
|
+
* @see https://github.com/mrousavy/react-native-blurhash#cosine-operations
|
|
52
|
+
*/
|
|
53
|
+
static clearCosineCache() {
|
|
54
|
+
if (Platform.OS === 'android' || _reactNative.Platform.OS === 'harmony') NativeBlurhashModule.clearCosineCache(); else console.warn('Blurhash.clearCosineCache is only available on Android.');
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Verifies if the given blurhash is valid by checking it's type, length and size flag.
|
|
59
|
+
*
|
|
60
|
+
* This uses the JS blurhash decoder, so it might be slow.
|
|
61
|
+
* @param blurhash The given blurhash string
|
|
62
|
+
*/
|
|
63
|
+
static isBlurhashValid(blurhash) {
|
|
64
|
+
return isBlurhashValid(blurhash);
|
|
65
|
+
}
|
|
66
|
+
_onLoadStart() {
|
|
67
|
+
if (this.props.onLoadStart != null) this.props.onLoadStart();
|
|
68
|
+
}
|
|
69
|
+
_onLoadEnd() {
|
|
70
|
+
if (this.props.onLoadEnd != null) this.props.onLoadEnd();
|
|
71
|
+
}
|
|
72
|
+
_onLoadError(event) {
|
|
73
|
+
var _event$nativeEvent;
|
|
74
|
+
if (this.props.onLoadError != null) this.props.onLoadError(event === null || event === void 0 || (_event$nativeEvent = event.nativeEvent) === null || _event$nativeEvent === void 0 ? void 0 : _event$nativeEvent.message);
|
|
75
|
+
}
|
|
76
|
+
render() {
|
|
77
|
+
return /*#__PURE__*/React.createElement(NativeBlurhashView, _extends({}, this.props, {
|
|
78
|
+
onLoadStart: this._onLoadStart,
|
|
79
|
+
onLoadEnd: this._onLoadEnd,
|
|
80
|
+
onLoadError: this._onLoadError
|
|
81
|
+
}));
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
_defineProperty(Blurhash, "displayName", 'Blurhash');
|
|
85
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["React","Platform","NativeBlurhashModule","NativeBlurhashView","decode83","decodeDC","isBlurhashValid","Blurhash","PureComponent","constructor","props","_onLoadStart","bind","_onLoadEnd","_onLoadError","encode","imageUri","componentsX","componentsY","Error","createBlurhashFromImage","getAverageColor","blurhash","length","undefined","value","substring","clearCosineCache","OS","console","warn","onLoadStart","onLoadEnd","event","_event$nativeEvent","onLoadError","nativeEvent","message","render","createElement","_extends","_defineProperty"],"sources":["index.tsx"],"sourcesContent":["import * as React from 'react';\nimport { Platform, type NativeSyntheticEvent, type ViewProps } from 'react-native';\nimport NativeBlurhashModule from './specs/NativeBlurhashModule';\nimport NativeBlurhashView from './specs/NativeBlurhashView';\nimport { decode83, decodeDC, isBlurhashValid, type RGB } from './utils';\n\nexport interface BlurhashProps extends Omit<ViewProps, 'children'> {\n\t/**\n\t * The blurhash string to use. Example: `LGFFaXYk^6#M@-5c,1J5@[or[Q6`.\n\t */\n\tblurhash: string;\n\t/**\n\t * The width (resolution) to decode to. Higher values decrease performance, use `16` for large lists, otherwise you can increase it to `32`.\n\t * @default 32\n\t */\n\tdecodeWidth?: number;\n\t/**\n\t * The height (resolution) to decode to. Higher values decrease performance, use `16` for large lists, otherwise you can increase it to `32`.\n\t * @default 32\n\t */\n\tdecodeHeight?: number;\n\t/**\n\t * Adjusts the contrast of the output image. Tweak it if you want a different look for your placeholders.\n\t * @default 1.0\n\t */\n\tdecodePunch?: number;\n\t/**\n\t * Asynchronously decode the Blurhash on a background Thread instead of the UI-Thread.\n\t * Read the [performance documentation](https://github.com/mrousavy/react-native-blurhash#performance)\n\t * before enabling this.\n\t * @default false\n\t */\n\tdecodeAsync?: boolean;\n\t/**\n\t * Adjusts the resize mode of the image.\n\t * @default 'cover'\n\t */\n\tresizeMode?: 'cover' | 'contain' | 'stretch' | 'center';\n\n\t/**\n\t * Emitted when the Blurhash received new parameters and started to decode the given `blurhash` string.\n\t */\n\tonLoadStart?: () => void;\n\n\t/**\n\t * Emitted when the Blurhash successfully decoded the given `blurhash` string and rendered the image to the `<Blurhash>` view.\n\t */\n\tonLoadEnd?: () => void;\n\n\t/**\n\t * Emitted when the Blurhash failed to decode/load.\n\t */\n\tonLoadError?: (message?: string) => void;\n}\n\nexport class Blurhash extends React.PureComponent<BlurhashProps> {\n\tstatic displayName = 'Blurhash';\n\n\tconstructor(props: BlurhashProps) {\n\t\tsuper(props);\n\t\tthis._onLoadStart = this._onLoadStart.bind(this);\n\t\tthis._onLoadEnd = this._onLoadEnd.bind(this);\n\t\tthis._onLoadError = this._onLoadError.bind(this);\n\t}\n\n\t/**\n\t * Encodes the given image URI to a blurhash string\n\t * @param imageUri An URI to an Image parseable by the react native image loader\n\t * @param componentsX The number of X components\n\t * @param componentsY The number of Y components\n\t * @example\n\t * const blurhash = await Blurhash.encode('https://blurha.sh/assets/images/img2.jpg')\n\t */\n\tstatic encode(imageUri: string, componentsX: number, componentsY: number): Promise<string> {\n\t\tif (typeof imageUri !== 'string') throw new Error('imageUri must be a non-empty string!');\n\t\tif (typeof componentsX !== 'number') throw new Error('componentsX must be a valid positive number!');\n\t\tif (typeof componentsY !== 'number') throw new Error('componentsY must be a valid positive number!');\n\n\t\treturn NativeBlurhashModule.createBlurhashFromImage(imageUri, componentsX, componentsY);\n\t}\n\n\t/**\n\t * Gets the average color in a given blurhash string.\n\t *\n\t * This uses the JS blurhash decoder, so it might be slow.\n\t * @param blurhash The blurhash string\n\t * @example\n\t * const averageColor = Blurhash.getAverageColor(`LGFFaXYk^6#M@-5c,1J5@[or[Q6.`)\n\t */\n\tstatic getAverageColor(blurhash: string): RGB | undefined {\n\t\tif (blurhash == null || blurhash.length < 7) return undefined;\n\n\t\tconst value = decode83(blurhash.substring(2, 6));\n\t\treturn decodeDC(value);\n\t}\n\n\t/**\n\t * Clears the cosine cache and frees up memory.\n\t *\n\t * @platform Android\n\t * @see https://github.com/mrousavy/react-native-blurhash#cosine-operations\n\t */\n\tstatic clearCosineCache(): void {\n\t\tif (Platform.OS === 'android') NativeBlurhashModule.clearCosineCache();\n\t\telse console.warn('Blurhash.clearCosineCache is only available on Android.');\n\t}\n\n\t/**\n\t * Verifies if the given blurhash is valid by checking it's type, length and size flag.\n\t *\n\t * This uses the JS blurhash decoder, so it might be slow.\n\t * @param blurhash The given blurhash string\n\t */\n\tstatic isBlurhashValid(blurhash: string): ReturnType<typeof isBlurhashValid> {\n\t\treturn isBlurhashValid(blurhash);\n\t}\n\n\t_onLoadStart() {\n\t\tif (this.props.onLoadStart != null) this.props.onLoadStart();\n\t}\n\t_onLoadEnd() {\n\t\tif (this.props.onLoadEnd != null) this.props.onLoadEnd();\n\t}\n\t_onLoadError(event?: NativeSyntheticEvent<{ message?: string }>) {\n\t\tif (this.props.onLoadError != null) this.props.onLoadError(event?.nativeEvent?.message);\n\t}\n\n\trender() {\n\t\treturn <NativeBlurhashView {...this.props} onLoadStart={this._onLoadStart} onLoadEnd={this._onLoadEnd} onLoadError={this._onLoadError} />;\n\t}\n}\n"],"mappings":";;;;AAAA,OAAO,KAAKA,KAAK,MAAM,OAAO;AAC9B,SAASC,QAAQ,QAAmD,cAAc;AAClF,OAAOC,oBAAoB,MAAM,8BAA8B;AAC/D,OAAOC,kBAAkB,MAAM,4BAA4B;AAC3D,SAASC,QAAQ,EAAEC,QAAQ,EAAEC,eAAe,QAAkB,SAAS;AAmDvE,OAAO,MAAMC,QAAQ,SAASP,KAAK,CAACQ,aAAa,CAAgB;EAGhEC,WAAWA,CAACC,KAAoB,EAAE;IACjC,KAAK,CAACA,KAAK,CAAC;IACZ,IAAI,CAACC,YAAY,GAAG,IAAI,CAACA,YAAY,CAACC,IAAI,CAAC,IAAI,CAAC;IAChD,IAAI,CAACC,UAAU,GAAG,IAAI,CAACA,UAAU,CAACD,IAAI,CAAC,IAAI,CAAC;IAC5C,IAAI,CAACE,YAAY,GAAG,IAAI,CAACA,YAAY,CAACF,IAAI,CAAC,IAAI,CAAC;EACjD;;EAEA;AACD;AACA;AACA;AACA;AACA;AACA;AACA;EACC,OAAOG,MAAMA,CAACC,QAAgB,EAAEC,WAAmB,EAAEC,WAAmB,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AAE,IAAI,CAACtB,KAAK,CAACsB,SAAS,CAAC,CAAC;EACzD;EACAlB,YAAYA,CAACmB,KAAkD,EAAE;IAAA,IAAAC,kBAAA;IAChE,IAAI,IAAI,CAACxB,KAAK,CAACyB,WAAW,IAAI,IAAI,EAAE,IAAI,CAACzB,KAAK,CAACyB,WAAW,CAACF,KAAK,aAALA,KAAK,gBAAAC,kBAAA,GAALD,KAAK,CAAEG,WAAW,cAAAF,kBAAA,uBAAlBA,kBAAA,CAAoBG,OAAO,CAAC;EACxF;EAEAC,MAAMA,CAAA,EAAG;IACR,oBAAOtC,KAAA,CAAAuC,aAAA,CAACpC,kBAAkB,EAAAqC,QAAA,KAAK,IAAI,CAAC9B,KAAK;MAAEqB,WAAW,EAAE,IAAI,CAACpB,YAAa;MAACqB,SAAS,EAAE,IAAI,CAACnB,UAAW;MAACsB,WAAW,EAAE,IAAI,CAACrB;IAAa,EAAE,CAAC;EAC1I;AACD;AAAC2B,eAAA,CA3EYlC,QAAQ,iBACC,UAAU"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["TurboModuleRegistry","getEnforcing"],"sources":["NativeBlurhashModule.ts"],"sourcesContent":["import { type TurboModule, TurboModuleRegistry } from 'react-native';\nimport type { Int32 } from 'react-native/Libraries/Types/CodegenTypes';\n\nexport interface Spec extends TurboModule {\n\tcreateBlurhashFromImage: (imageUri: string, componentsX: Int32, componentsY: Int32) => Promise<string>;\n\tclearCosineCache: () => void;\n}\n\nexport default TurboModuleRegistry.getEnforcing<Spec>('BlurhashModule');\n"],"mappings":"AAAA,SAA2BA,mBAAmB,QAAQ,cAAc;AAQpE,eAAeA,mBAAmB,CAACC,YAAY,CAAO,gBAAgB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["codegenNativeComponent"],"sources":["NativeBlurhashView.ts"],"sourcesContent":["import codegenNativeComponent from 'react-native/Libraries/Utilities/codegenNativeComponent';\nimport type { DirectEventHandler, Double, Int32, WithDefault } from 'react-native/Libraries/Types/CodegenTypes';\nimport type { ViewProps } from 'react-native';\n\ntype OnLoadErrorEvent = { message?: string };\n\ninterface NativeProps extends ViewProps {\n\tblurhash: string;\n\tdecodeWidth?: WithDefault<Int32, 32>;\n\tdecodeHeight?: WithDefault<Int32, 32>;\n\tdecodePunch?: WithDefault<Double, 1>;\n\tdecodeAsync?: WithDefault<boolean, false>;\n\tresizeMode?: WithDefault<'cover' | 'contain' | 'stretch' | 'center', 'cover'>;\n\tonLoadStart?: DirectEventHandler<null>;\n\tonLoadEnd?: DirectEventHandler<null>;\n\tonLoadError?: DirectEventHandler<OnLoadErrorEvent>;\n}\n\nexport default codegenNativeComponent<NativeProps>('BlurhashView');\n"],"mappings":"AAAA,OAAOA,sBAAsB,MAAM,yDAAyD;AAkB5F,eAAeA,sBAAsB,CAAc,cAAc,CAAC"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
// Some functions from the Blurhash JS implementation that are used for light tasks (such as getting the average color or validating if a blurhash string is valid)
|
|
2
|
+
|
|
3
|
+
function sRGBToLinear(value) {
|
|
4
|
+
const v = value / 255;
|
|
5
|
+
if (v <= 0.04045) return v / 12.92;else return Math.pow((v + 0.055) / 1.055, 2.4);
|
|
6
|
+
}
|
|
7
|
+
export function decodeDC(value) {
|
|
8
|
+
const intR = value >> 16;
|
|
9
|
+
const intG = value >> 8 & 255;
|
|
10
|
+
const intB = value & 255;
|
|
11
|
+
return {
|
|
12
|
+
r: sRGBToLinear(intR) * 255,
|
|
13
|
+
g: sRGBToLinear(intG) * 255,
|
|
14
|
+
b: sRGBToLinear(intB) * 255
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
export function decode83(str) {
|
|
18
|
+
let value = 0;
|
|
19
|
+
for (let i = 0; i < str.length; i++) {
|
|
20
|
+
const c = str[i];
|
|
21
|
+
const digit = digitCharacters.indexOf(c);
|
|
22
|
+
value = value * 83 + digit;
|
|
23
|
+
}
|
|
24
|
+
return value;
|
|
25
|
+
}
|
|
26
|
+
function validateBlurhash(blurhash) {
|
|
27
|
+
if (!blurhash || blurhash.length < 6) throw new Error('The blurhash string must be at least 6 characters');
|
|
28
|
+
const sizeFlag = decode83(blurhash[0]);
|
|
29
|
+
const numY = Math.floor(sizeFlag / 9) + 1;
|
|
30
|
+
const numX = sizeFlag % 9 + 1;
|
|
31
|
+
if (blurhash.length !== 4 + 2 * numX * numY) throw new Error(`blurhash length mismatch: length is ${blurhash.length} but it should be ${4 + 2 * numX * numY}`);
|
|
32
|
+
}
|
|
33
|
+
export function isBlurhashValid(blurhash) {
|
|
34
|
+
try {
|
|
35
|
+
validateBlurhash(blurhash);
|
|
36
|
+
} catch (error) {
|
|
37
|
+
const message = error instanceof Error ? error.message : JSON.stringify(error);
|
|
38
|
+
return {
|
|
39
|
+
isValid: false,
|
|
40
|
+
errorReason: message
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
return {
|
|
44
|
+
isValid: true
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
const digitCharacters = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '#', '$', '%', '*', '+', ',', '-', '.', ':', ';', '=', '?', '@', '[', ']', '^', '_', '{', '|', '}', '~'];
|
|
48
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["sRGBToLinear","value","v","Math","pow","decodeDC","intR","intG","intB","r","g","b","decode83","str","i","length","c","digit","digitCharacters","indexOf","validateBlurhash","blurhash","Error","sizeFlag","numY","floor","numX","isBlurhashValid","error","message","JSON","stringify","isValid","errorReason"],"sources":["utils.ts"],"sourcesContent":["// Some functions from the Blurhash JS implementation that are used for light tasks (such as getting the average color or validating if a blurhash string is valid)\n\nexport interface RGB {\n\t/**\n\t * The Red value component of this RGB instance. Ranges from 0 to 255.\n\t */\n\tr: number;\n\t/**\n\t * The Green value component of this RGB instance. Ranges from 0 to 255.\n\t */\n\tg: number;\n\t/**\n\t * The Blue value component of this RGB instance. Ranges from 0 to 255.\n\t */\n\tb: number;\n}\n\nfunction sRGBToLinear(value: number): number {\n\tconst v = value / 255;\n\tif (v <= 0.04045) return v / 12.92;\n\telse return Math.pow((v + 0.055) / 1.055, 2.4);\n}\n\nexport function decodeDC(value: number): RGB {\n\tconst intR = value >> 16;\n\tconst intG = (value >> 8) & 255;\n\tconst intB = value & 255;\n\treturn { r: sRGBToLinear(intR) * 255, g: sRGBToLinear(intG) * 255, b: sRGBToLinear(intB) * 255 };\n}\n\nexport function decode83(str: string): number {\n\tlet value = 0;\n\tfor (let i = 0; i < str.length; i++) {\n\t\tconst c = str[i];\n\t\tconst digit = digitCharacters.indexOf(c);\n\t\tvalue = value * 83 + digit;\n\t}\n\treturn value;\n}\n\nfunction validateBlurhash(blurhash: string): void {\n\tif (!blurhash || blurhash.length < 6) throw new Error('The blurhash string must be at least 6 characters');\n\n\tconst sizeFlag = decode83(blurhash[0]);\n\tconst numY = Math.floor(sizeFlag / 9) + 1;\n\tconst numX = (sizeFlag % 9) + 1;\n\n\tif (blurhash.length !== 4 + 2 * numX * numY)\n\t\tthrow new Error(`blurhash length mismatch: length is ${blurhash.length} but it should be ${4 + 2 * numX * numY}`);\n}\n\nexport function isBlurhashValid(blurhash: string): { isValid: true } | { isValid: false; errorReason: string } {\n\ttry {\n\t\tvalidateBlurhash(blurhash);\n\t} catch (error) {\n\t\tconst message = error instanceof Error ? error.message : JSON.stringify(error);\n\t\treturn { isValid: false, errorReason: message };\n\t}\n\n\treturn { isValid: true };\n}\n\nconst digitCharacters = [\n\t'0',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AGD,KAAK,YAAYN,KAAK,GAAGM,KAAK,CAACC,OAAO,GAAGC,IAAI,CAACC,SAAS,CAACH,KAAK,CAAC;IAC9E,OAAO;MAAEI,OAAO,EAAE,KAAK;MAAEC,WAAW,EAAEJ;IAAQ,CAAC;EAChD;EAEA,OAAO;IAAEG,OAAO,EAAE;EAAK,CAAC;AACzB;AAEA,MAAMd,eAAe,GAAG,CACvB,GAAG,EACH,GAAG,EACH,GAAG,EACH,GAAG,EACH,GAAG,EACH,GAAG,EACH,GAAG,EACH,GAAG,EACH,GAAG,EACH,GAAG,EACH,GAAG,EACH,GAAG,EACH,GAAG,EACH,GAAG,EACH,GAAG,EACH,GAAG,EACH,GAAG,EACH,GAAG,EACH,GAAG,EACH,GAAG,EACH,GAAG,EACH,GAAG,EACH,GAAG,EACH,GAAG,EACH,GAAG,EACH,GAAG,EACH,GAAG,EACH,GAAG,EACH,GAAG,EACH,GAAG,EACH,GAAG,EACH,GAAG,EACH,GAAG,EACH,GAAG,EACH,GAAG,EACH,GAAG,EACH,GAAG,EACH,GAAG,EACH,GAAG,EACH,GAAG,EACH,GAAG,EACH,GAAG,EACH,GAAG,EACH,GAAG,EACH,GAAG,EACH,GAAG,EACH,GAAG,EACH,GAAG,EACH,GAAG,EACH,GAAG,EACH,GAAG,EACH,GAAG,EACH,GAAG,EACH,GAAG,EACH,GAAG,EACH,GAAG,EACH,GAAG,EACH,GAAG,EACH,GAAG,EACH,GAAG,EACH,GAAG,EACH,GAAG,EACH,GAAG,EACH,GAAG,EACH,GAAG,EACH,GAAG,EACH,GAAG,EACH,GAAG,EACH,GAAG,EACH,GAAG,EACH,GAAG,EACH,GAAG,EACH,GAAG,EACH,GAAG,EACH,GAAG,EACH,GAAG,EACH,GAAG,EACH,GAAG,EACH,GAAG,EACH,GAAG,EACH,GAAG,EACH,GAAG,EACH,GAAG,CACH"}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { type NativeSyntheticEvent, type ViewProps } from 'react-native';
|
|
3
|
+
import { isBlurhashValid, type RGB } from './utils';
|
|
4
|
+
export interface BlurhashProps extends Omit<ViewProps, 'children'> {
|
|
5
|
+
/**
|
|
6
|
+
* The blurhash string to use. Example: `LGFFaXYk^6#M@-5c,1J5@[or[Q6`.
|
|
7
|
+
*/
|
|
8
|
+
blurhash: string;
|
|
9
|
+
/**
|
|
10
|
+
* The width (resolution) to decode to. Higher values decrease performance, use `16` for large lists, otherwise you can increase it to `32`.
|
|
11
|
+
* @default 32
|
|
12
|
+
*/
|
|
13
|
+
decodeWidth?: number;
|
|
14
|
+
/**
|
|
15
|
+
* The height (resolution) to decode to. Higher values decrease performance, use `16` for large lists, otherwise you can increase it to `32`.
|
|
16
|
+
* @default 32
|
|
17
|
+
*/
|
|
18
|
+
decodeHeight?: number;
|
|
19
|
+
/**
|
|
20
|
+
* Adjusts the contrast of the output image. Tweak it if you want a different look for your placeholders.
|
|
21
|
+
* @default 1.0
|
|
22
|
+
*/
|
|
23
|
+
decodePunch?: number;
|
|
24
|
+
/**
|
|
25
|
+
* Asynchronously decode the Blurhash on a background Thread instead of the UI-Thread.
|
|
26
|
+
* Read the [performance documentation](https://github.com/mrousavy/react-native-blurhash#performance)
|
|
27
|
+
* before enabling this.
|
|
28
|
+
* @default false
|
|
29
|
+
*/
|
|
30
|
+
decodeAsync?: boolean;
|
|
31
|
+
/**
|
|
32
|
+
* Adjusts the resize mode of the image.
|
|
33
|
+
* @default 'cover'
|
|
34
|
+
*/
|
|
35
|
+
resizeMode?: 'cover' | 'contain' | 'stretch' | 'center';
|
|
36
|
+
/**
|
|
37
|
+
* Emitted when the Blurhash received new parameters and started to decode the given `blurhash` string.
|
|
38
|
+
*/
|
|
39
|
+
onLoadStart?: () => void;
|
|
40
|
+
/**
|
|
41
|
+
* Emitted when the Blurhash successfully decoded the given `blurhash` string and rendered the image to the `<Blurhash>` view.
|
|
42
|
+
*/
|
|
43
|
+
onLoadEnd?: () => void;
|
|
44
|
+
/**
|
|
45
|
+
* Emitted when the Blurhash failed to decode/load.
|
|
46
|
+
*/
|
|
47
|
+
onLoadError?: (message?: string) => void;
|
|
48
|
+
}
|
|
49
|
+
export declare class Blurhash extends React.PureComponent<BlurhashProps> {
|
|
50
|
+
static displayName: string;
|
|
51
|
+
constructor(props: BlurhashProps);
|
|
52
|
+
/**
|
|
53
|
+
* Encodes the given image URI to a blurhash string
|
|
54
|
+
* @param imageUri An URI to an Image parseable by the react native image loader
|
|
55
|
+
* @param componentsX The number of X components
|
|
56
|
+
* @param componentsY The number of Y components
|
|
57
|
+
* @example
|
|
58
|
+
* const blurhash = await Blurhash.encode('https://blurha.sh/assets/images/img2.jpg')
|
|
59
|
+
*/
|
|
60
|
+
static encode(imageUri: string, componentsX: number, componentsY: number): Promise<string>;
|
|
61
|
+
/**
|
|
62
|
+
* Gets the average color in a given blurhash string.
|
|
63
|
+
*
|
|
64
|
+
* This uses the JS blurhash decoder, so it might be slow.
|
|
65
|
+
* @param blurhash The blurhash string
|
|
66
|
+
* @example
|
|
67
|
+
* const averageColor = Blurhash.getAverageColor(`LGFFaXYk^6#M@-5c,1J5@[or[Q6.`)
|
|
68
|
+
*/
|
|
69
|
+
static getAverageColor(blurhash: string): RGB | undefined;
|
|
70
|
+
/**
|
|
71
|
+
* Clears the cosine cache and frees up memory.
|
|
72
|
+
*
|
|
73
|
+
* @platform Android
|
|
74
|
+
* @see https://github.com/mrousavy/react-native-blurhash#cosine-operations
|
|
75
|
+
*/
|
|
76
|
+
static clearCosineCache(): void;
|
|
77
|
+
/**
|
|
78
|
+
* Verifies if the given blurhash is valid by checking it's type, length and size flag.
|
|
79
|
+
*
|
|
80
|
+
* This uses the JS blurhash decoder, so it might be slow.
|
|
81
|
+
* @param blurhash The given blurhash string
|
|
82
|
+
*/
|
|
83
|
+
static isBlurhashValid(blurhash: string): ReturnType<typeof isBlurhashValid>;
|
|
84
|
+
_onLoadStart(): void;
|
|
85
|
+
_onLoadEnd(): void;
|
|
86
|
+
_onLoadError(event?: NativeSyntheticEvent<{
|
|
87
|
+
message?: string;
|
|
88
|
+
}>): void;
|
|
89
|
+
render(): React.JSX.Element;
|
|
90
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/// <reference types="react-native/types/modules/codegen" />
|
|
2
|
+
import { type TurboModule } from 'react-native';
|
|
3
|
+
import type { Int32 } from 'react-native/Libraries/Types/CodegenTypes';
|
|
4
|
+
export interface Spec extends TurboModule {
|
|
5
|
+
createBlurhashFromImage: (imageUri: string, componentsX: Int32, componentsY: Int32) => Promise<string>;
|
|
6
|
+
clearCosineCache: () => void;
|
|
7
|
+
}
|
|
8
|
+
declare const _default: Spec;
|
|
9
|
+
export default _default;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/// <reference types="react-native/types/modules/codegen" />
|
|
2
|
+
import type { DirectEventHandler, Double, Int32, WithDefault } from 'react-native/Libraries/Types/CodegenTypes';
|
|
3
|
+
import type { ViewProps } from 'react-native';
|
|
4
|
+
type OnLoadErrorEvent = {
|
|
5
|
+
message?: string;
|
|
6
|
+
};
|
|
7
|
+
interface NativeProps extends ViewProps {
|
|
8
|
+
blurhash: string;
|
|
9
|
+
decodeWidth?: WithDefault<Int32, 32>;
|
|
10
|
+
decodeHeight?: WithDefault<Int32, 32>;
|
|
11
|
+
decodePunch?: WithDefault<Double, 1>;
|
|
12
|
+
decodeAsync?: WithDefault<boolean, false>;
|
|
13
|
+
resizeMode?: WithDefault<'cover' | 'contain' | 'stretch' | 'center', 'cover'>;
|
|
14
|
+
onLoadStart?: DirectEventHandler<null>;
|
|
15
|
+
onLoadEnd?: DirectEventHandler<null>;
|
|
16
|
+
onLoadError?: DirectEventHandler<OnLoadErrorEvent>;
|
|
17
|
+
}
|
|
18
|
+
declare const _default: import("react-native/Libraries/Utilities/codegenNativeComponent").NativeComponentType<NativeProps>;
|
|
19
|
+
export default _default;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export interface RGB {
|
|
2
|
+
/**
|
|
3
|
+
* The Red value component of this RGB instance. Ranges from 0 to 255.
|
|
4
|
+
*/
|
|
5
|
+
r: number;
|
|
6
|
+
/**
|
|
7
|
+
* The Green value component of this RGB instance. Ranges from 0 to 255.
|
|
8
|
+
*/
|
|
9
|
+
g: number;
|
|
10
|
+
/**
|
|
11
|
+
* The Blue value component of this RGB instance. Ranges from 0 to 255.
|
|
12
|
+
*/
|
|
13
|
+
b: number;
|
|
14
|
+
}
|
|
15
|
+
export declare function decodeDC(value: number): RGB;
|
|
16
|
+
export declare function decode83(str: string): number;
|
|
17
|
+
export declare function isBlurhashValid(blurhash: string): {
|
|
18
|
+
isValid: true;
|
|
19
|
+
} | {
|
|
20
|
+
isValid: false;
|
|
21
|
+
errorReason: string;
|
|
22
|
+
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-native-ohos/react-native-blurhash",
|
|
3
3
|
"title": "React Native Blurhash",
|
|
4
|
-
"version": "2.0
|
|
4
|
+
"version": "2.1.0",
|
|
5
5
|
"description": "🖼 Blurhash is a compact representation of a placeholder for an image. This is a Native UI Module for React Native to asynchronously wrap the Blurhash implementations and make them usable in React Native. Also supports encoding!",
|
|
6
6
|
"main": "lib/commonjs/index.js",
|
|
7
7
|
"types": "lib/typescript/index.d.ts",
|
|
@@ -21,10 +21,9 @@
|
|
|
21
21
|
"build": "bob build",
|
|
22
22
|
"release": "release-it"
|
|
23
23
|
},
|
|
24
|
-
"repository": "https://
|
|
24
|
+
"repository": "https://github.com/mrousavy/react-native-blurhash",
|
|
25
25
|
"publishConfig": {
|
|
26
|
-
"registry": "https://registry.npmjs.org/"
|
|
27
|
-
"access": "public"
|
|
26
|
+
"registry": "https://registry.npmjs.org/"
|
|
28
27
|
},
|
|
29
28
|
"keywords": [
|
|
30
29
|
"react-native",
|
|
@@ -107,14 +106,8 @@
|
|
|
107
106
|
"javaPackageName": "com.mrousavy.blurhash"
|
|
108
107
|
}
|
|
109
108
|
},
|
|
110
|
-
"harmony":
|
|
111
|
-
"alias": "react-native-blurhash"
|
|
112
|
-
"autolinking": {
|
|
113
|
-
"etsPackageClassName": "BlurhashPackage",
|
|
114
|
-
"cppPackageClassName": "BlurhashPackage",
|
|
115
|
-
"cmakeLibraryTargetName": "rnoh_blurhash",
|
|
116
|
-
"ohPackageName": "@react-native-ohos/react-native-blurhash"
|
|
117
|
-
}
|
|
109
|
+
"harmony":{
|
|
110
|
+
"alias": "react-native-blurhash"
|
|
118
111
|
},
|
|
119
112
|
"packageManager": "yarn@1.22.19+sha1.4ba7fc5c6e704fce2066ecbfb0b0d8976fe62447"
|
|
120
113
|
}
|