@onesy/ui-react 1.0.25 → 1.0.27
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/AudioRecorder/AudioRecorder.js +2 -7
- package/esm/AudioRecorder/AudioRecorder.js +2 -9
- package/esm/index.js +1 -1
- package/esm/utils.js +30 -32
- package/package.json +2 -4
- package/utils.d.ts +1 -1
- package/utils.js +27 -52
@@ -190,14 +190,9 @@ const AudioRecorder = react_1.default.forwardRef((props_, ref) => {
|
|
190
190
|
// duration in seconds
|
191
191
|
duration: refs.duration.current / 1e3
|
192
192
|
};
|
193
|
-
|
194
|
-
|
195
|
-
const { blob: blobAudioFix, duration: durationAudioFix, error } = await (0, utils_2.audioFix)(blob);
|
196
|
-
if (!error) {
|
193
|
+
const { blob: blobAudioFix, error } = await (0, utils_2.audioFix)(blob, meta.duration);
|
194
|
+
if (!error)
|
197
195
|
blob = blobAudioFix;
|
198
|
-
if (durationAudioFix !== undefined)
|
199
|
-
meta.duration = durationAudioFix;
|
200
|
-
}
|
201
196
|
if ((0, utils_1.is)('function', onConfirm_))
|
202
197
|
onConfirm_(blob, meta);
|
203
198
|
}, [onStop, onConfirm_]);
|
@@ -215,18 +215,11 @@ const AudioRecorder = /*#__PURE__*/React.forwardRef((props_, ref) => {
|
|
215
215
|
// duration in seconds
|
216
216
|
duration: refs.duration.current / 1e3
|
217
217
|
};
|
218
|
-
|
219
|
-
// works well on desktop
|
220
|
-
// mobile has issues with fixing web audio
|
221
218
|
const {
|
222
219
|
blob: blobAudioFix,
|
223
|
-
duration: durationAudioFix,
|
224
220
|
error
|
225
|
-
} = await audioFix(blob);
|
226
|
-
if (!error)
|
227
|
-
blob = blobAudioFix;
|
228
|
-
if (durationAudioFix !== undefined) meta.duration = durationAudioFix;
|
229
|
-
}
|
221
|
+
} = await audioFix(blob, meta.duration);
|
222
|
+
if (!error) blob = blobAudioFix;
|
230
223
|
if (is('function', onConfirm_)) onConfirm_(blob, meta);
|
231
224
|
}, [onStop, onConfirm_]);
|
232
225
|
const onResume = React.useCallback(event => {
|
package/esm/index.js
CHANGED
package/esm/utils.js
CHANGED
@@ -1,9 +1,4 @@
|
|
1
|
-
import * as ebml from 'ts-ebml';
|
2
|
-
import { Buffer } from 'buffer';
|
3
1
|
import { is, canvasFilterBrightness, canvasFilterContrast, canvasFilterSaturation, canvasFilterFade, canvasFilterInvert, canvasFilterOldPhoto, download, clamp, isEnvironment } from '@onesy/utils';
|
4
|
-
if (isEnvironment('browser')) {
|
5
|
-
window.Buffer = Buffer;
|
6
|
-
}
|
7
2
|
export function reflow(element) {
|
8
3
|
element?.offsetHeight;
|
9
4
|
}
|
@@ -1259,41 +1254,44 @@ export const currencies = [{
|
|
1259
1254
|
code: 'ZMK',
|
1260
1255
|
name_plural: 'Zambian kwachas'
|
1261
1256
|
}];
|
1262
|
-
export const audioFix = async blob => {
|
1257
|
+
export const audioFix = async (blob, duration) => {
|
1263
1258
|
try {
|
1264
|
-
const
|
1265
|
-
return new Promise((resolve, reject) => {
|
1266
|
-
const fileReader = new FileReader();
|
1267
|
-
fileReader.readAsArrayBuffer(blob);
|
1268
|
-
fileReader.onloadend = () => resolve(fileReader.result);
|
1269
|
-
fileReader.onerror = event => reject(event.error);
|
1270
|
-
});
|
1271
|
-
};
|
1272
|
-
const arrayBuffer = await readAsArrayBuffer();
|
1273
|
-
const decoder = new ebml.Decoder();
|
1274
|
-
const reader = new ebml.Reader();
|
1275
|
-
reader.logging = false;
|
1276
|
-
reader.drop_default_duration = false;
|
1259
|
+
const arrayBuffer = await blob.arrayBuffer();
|
1277
1260
|
const uint8Array = new Uint8Array(arrayBuffer);
|
1278
|
-
|
1279
|
-
|
1280
|
-
|
1281
|
-
|
1282
|
-
|
1283
|
-
|
1284
|
-
|
1261
|
+
|
1262
|
+
// Function to find an EBML element by its ID
|
1263
|
+
function findElement(idHex) {
|
1264
|
+
const idBytes = new Uint8Array(idHex.match(/.{1,2}/g).map(byte => parseInt(byte, 16)));
|
1265
|
+
for (let i = 0; i < uint8Array.length - idBytes.length; i++) {
|
1266
|
+
if (uint8Array.slice(i, i + idBytes.length).toString() === idBytes.toString()) return i + idBytes.length; // Return position after the ID
|
1267
|
+
}
|
1268
|
+
return -1;
|
1269
|
+
}
|
1270
|
+
|
1271
|
+
// WebM duration EBML ID: 0x4489 (Segment Information -> Duration)
|
1272
|
+
const durationPos = findElement("4489");
|
1273
|
+
if (durationPos === -1) {
|
1274
|
+
throw new Error("Duration element not found in the WebM file.");
|
1275
|
+
}
|
1276
|
+
|
1277
|
+
// Encode new duration in IEEE 754 Float64 (Big Endian, 8 bytes)
|
1278
|
+
const durationBytes = new Uint8Array(new Float64Array([duration]).buffer).reverse();
|
1279
|
+
|
1280
|
+
// Overwrite duration bytes in the WebM file
|
1281
|
+
uint8Array.set(durationBytes, durationPos);
|
1282
|
+
|
1283
|
+
// Convert back to Blob
|
1284
|
+
const blobUpdated = new Blob([uint8Array], {
|
1285
|
+
type: "video/webm"
|
1285
1286
|
});
|
1286
1287
|
return {
|
1287
|
-
blob:
|
1288
|
+
blob: blobUpdated,
|
1289
|
+
duration
|
1288
1290
|
};
|
1289
1291
|
} catch (error) {
|
1290
|
-
console.log('audioFix error', error);
|
1291
|
-
|
1292
|
-
// fallback
|
1293
|
-
// return durationFallback(blob);
|
1294
|
-
|
1295
1292
|
return {
|
1296
1293
|
blob,
|
1294
|
+
duration,
|
1297
1295
|
error
|
1298
1296
|
};
|
1299
1297
|
}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@onesy/ui-react",
|
3
|
-
"version": "1.0.
|
3
|
+
"version": "1.0.27",
|
4
4
|
"description": "UI for React",
|
5
5
|
"repository": "https://github.com/onesy-me/onesy.git",
|
6
6
|
"author": "Lazar <lazareric2@gmail.com>",
|
@@ -41,9 +41,7 @@
|
|
41
41
|
"@onesy/icons-material-rounded-react": "^1.0.2",
|
42
42
|
"@onesy/log": "^1.0.0",
|
43
43
|
"@onesy/subscription": "^1.0.0",
|
44
|
-
"@onesy/utils": "^1.0.2"
|
45
|
-
"buffer": "^6.0.3",
|
46
|
-
"ts-ebml": "^3.0.1"
|
44
|
+
"@onesy/utils": "^1.0.2"
|
47
45
|
},
|
48
46
|
"publishConfig": {
|
49
47
|
"access": "public",
|
package/utils.d.ts
CHANGED
package/utils.js
CHANGED
@@ -1,35 +1,7 @@
|
|
1
1
|
"use strict";
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
3
|
-
if (k2 === undefined) k2 = k;
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
7
|
-
}
|
8
|
-
Object.defineProperty(o, k2, desc);
|
9
|
-
}) : (function(o, m, k, k2) {
|
10
|
-
if (k2 === undefined) k2 = k;
|
11
|
-
o[k2] = m[k];
|
12
|
-
}));
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
15
|
-
}) : function(o, v) {
|
16
|
-
o["default"] = v;
|
17
|
-
});
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
19
|
-
if (mod && mod.__esModule) return mod;
|
20
|
-
var result = {};
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
22
|
-
__setModuleDefault(result, mod);
|
23
|
-
return result;
|
24
|
-
};
|
25
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
26
3
|
exports.audioFix = exports.currencies = exports.iconFontSize = exports.formats = exports.toNumber = exports.caret = exports.keyboardStyleCommands = exports.keyboardStandardCommands = exports.getOverflowParent = exports.importIframeStyles = exports.replace = exports.sanitize = exports.minMaxBetweenNumbers = exports.controlPoint = exports.line = exports.angleToCoordinates = exports.matches = exports.save = exports.print = exports.canvasOldPhoto = exports.canvasInvert = exports.canvasFade = exports.canvasSaturation = exports.canvasContrast = exports.canvasBrightness = exports.image = exports.valueBreakpoints = exports.iconSizeToFontSize = exports.staticClassName = exports.reflow = void 0;
|
27
|
-
const ebml = __importStar(require("ts-ebml"));
|
28
|
-
const buffer_1 = require("buffer");
|
29
4
|
const utils_1 = require("@onesy/utils");
|
30
|
-
if ((0, utils_1.isEnvironment)('browser')) {
|
31
|
-
window.Buffer = buffer_1.Buffer;
|
32
|
-
}
|
33
5
|
function reflow(element) {
|
34
6
|
element === null || element === void 0 ? void 0 : element.offsetHeight;
|
35
7
|
}
|
@@ -1448,36 +1420,39 @@ exports.currencies = [
|
|
1448
1420
|
name_plural: 'Zambian kwachas'
|
1449
1421
|
}
|
1450
1422
|
];
|
1451
|
-
const audioFix = async (blob) => {
|
1423
|
+
const audioFix = async (blob, duration) => {
|
1452
1424
|
try {
|
1453
|
-
const
|
1454
|
-
return new Promise((resolve, reject) => {
|
1455
|
-
const fileReader = new FileReader();
|
1456
|
-
fileReader.readAsArrayBuffer(blob);
|
1457
|
-
fileReader.onloadend = () => resolve(fileReader.result);
|
1458
|
-
fileReader.onerror = (event) => reject(event.error);
|
1459
|
-
});
|
1460
|
-
};
|
1461
|
-
const arrayBuffer = await readAsArrayBuffer();
|
1462
|
-
const decoder = new ebml.Decoder();
|
1463
|
-
const reader = new ebml.Reader();
|
1464
|
-
reader.logging = false;
|
1465
|
-
reader.drop_default_duration = false;
|
1425
|
+
const arrayBuffer = await blob.arrayBuffer();
|
1466
1426
|
const uint8Array = new Uint8Array(arrayBuffer);
|
1467
|
-
|
1468
|
-
|
1469
|
-
|
1470
|
-
|
1471
|
-
|
1472
|
-
|
1473
|
-
|
1427
|
+
// Function to find an EBML element by its ID
|
1428
|
+
function findElement(idHex) {
|
1429
|
+
const idBytes = new Uint8Array(idHex.match(/.{1,2}/g).map(byte => parseInt(byte, 16)));
|
1430
|
+
for (let i = 0; i < uint8Array.length - idBytes.length; i++) {
|
1431
|
+
if (uint8Array.slice(i, i + idBytes.length).toString() === idBytes.toString())
|
1432
|
+
return i + idBytes.length; // Return position after the ID
|
1433
|
+
}
|
1434
|
+
return -1;
|
1435
|
+
}
|
1436
|
+
// WebM duration EBML ID: 0x4489 (Segment Information -> Duration)
|
1437
|
+
const durationPos = findElement("4489");
|
1438
|
+
if (durationPos === -1) {
|
1439
|
+
throw new Error("Duration element not found in the WebM file.");
|
1440
|
+
}
|
1441
|
+
// Encode new duration in IEEE 754 Float64 (Big Endian, 8 bytes)
|
1442
|
+
const durationBytes = new Uint8Array(new Float64Array([duration]).buffer).reverse();
|
1443
|
+
// Overwrite duration bytes in the WebM file
|
1444
|
+
uint8Array.set(durationBytes, durationPos);
|
1445
|
+
// Convert back to Blob
|
1446
|
+
const blobUpdated = new Blob([uint8Array], { type: "video/webm" });
|
1447
|
+
return {
|
1448
|
+
blob: blobUpdated,
|
1449
|
+
duration
|
1450
|
+
};
|
1474
1451
|
}
|
1475
1452
|
catch (error) {
|
1476
|
-
console.log('audioFix error', error);
|
1477
|
-
// fallback
|
1478
|
-
// return durationFallback(blob);
|
1479
1453
|
return {
|
1480
1454
|
blob,
|
1455
|
+
duration,
|
1481
1456
|
error
|
1482
1457
|
};
|
1483
1458
|
}
|