@onesy/ui-react 1.0.25 → 1.0.26

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.
@@ -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
- // works well on desktop
194
- // mobile has issues with fixing web audio
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
@@ -1,4 +1,4 @@
1
- /** @license UiReact v1.0.25
1
+ /** @license UiReact v1.0.26
2
2
  *
3
3
  * This source code is licensed under the MIT license found in the
4
4
  * LICENSE file in the root directory of this source tree.
package/esm/utils.js CHANGED
@@ -1,5 +1,3 @@
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
2
  if (isEnvironment('browser')) {
5
3
  window.Buffer = Buffer;
@@ -1259,41 +1257,44 @@ export const currencies = [{
1259
1257
  code: 'ZMK',
1260
1258
  name_plural: 'Zambian kwachas'
1261
1259
  }];
1262
- export const audioFix = async blob => {
1260
+ export const audioFix = async (blob, duration) => {
1263
1261
  try {
1264
- const readAsArrayBuffer = () => {
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;
1262
+ const arrayBuffer = await blob.arrayBuffer();
1277
1263
  const uint8Array = new Uint8Array(arrayBuffer);
1278
- const elements = decoder.decode(uint8Array);
1279
- elements.forEach(element => reader.read(element));
1280
- reader.stop();
1281
- const refinedMetadataBuf = ebml.tools.makeMetadataSeekable(reader.metadatas, reader.duration, reader.cues);
1282
- const body = arrayBuffer.slice(reader.metadataSize);
1283
- const result = new Blob([refinedMetadataBuf, body], {
1284
- type: blob.type
1264
+
1265
+ // Function to find an EBML element by its ID
1266
+ function findElement(idHex) {
1267
+ const idBytes = new Uint8Array(idHex.match(/.{1,2}/g).map(byte => parseInt(byte, 16)));
1268
+ for (let i = 0; i < uint8Array.length - idBytes.length; i++) {
1269
+ if (uint8Array.slice(i, i + idBytes.length).toString() === idBytes.toString()) return i + idBytes.length; // Return position after the ID
1270
+ }
1271
+ return -1;
1272
+ }
1273
+
1274
+ // WebM duration EBML ID: 0x4489 (Segment Information -> Duration)
1275
+ const durationPos = findElement("4489");
1276
+ if (durationPos === -1) {
1277
+ throw new Error("Duration element not found in the WebM file.");
1278
+ }
1279
+
1280
+ // Encode new duration in IEEE 754 Float64 (Big Endian, 8 bytes)
1281
+ const durationBytes = new Uint8Array(new Float64Array([duration]).buffer).reverse();
1282
+
1283
+ // Overwrite duration bytes in the WebM file
1284
+ uint8Array.set(durationBytes, durationPos);
1285
+
1286
+ // Convert back to Blob
1287
+ const blobUpdated = new Blob([uint8Array], {
1288
+ type: "video/webm"
1285
1289
  });
1286
1290
  return {
1287
- blob: result
1291
+ blob: blobUpdated,
1292
+ duration
1288
1293
  };
1289
1294
  } catch (error) {
1290
- console.log('audioFix error', error);
1291
-
1292
- // fallback
1293
- // return durationFallback(blob);
1294
-
1295
1295
  return {
1296
1296
  blob,
1297
+ duration,
1297
1298
  error
1298
1299
  };
1299
1300
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onesy/ui-react",
3
- "version": "1.0.25",
3
+ "version": "1.0.26",
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
@@ -46,4 +46,4 @@ export declare const currencies: {
46
46
  code: string;
47
47
  name_plural: string;
48
48
  }[];
49
- export declare const audioFix: (blob: Blob) => Promise<IAudioFix>;
49
+ export declare const audioFix: (blob: Blob, duration: number) => Promise<IAudioFix>;
package/utils.js CHANGED
@@ -1,34 +1,9 @@
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
5
  if ((0, utils_1.isEnvironment)('browser')) {
31
- window.Buffer = buffer_1.Buffer;
6
+ window.Buffer = Buffer;
32
7
  }
33
8
  function reflow(element) {
34
9
  element === null || element === void 0 ? void 0 : element.offsetHeight;
@@ -1448,36 +1423,39 @@ exports.currencies = [
1448
1423
  name_plural: 'Zambian kwachas'
1449
1424
  }
1450
1425
  ];
1451
- const audioFix = async (blob) => {
1426
+ const audioFix = async (blob, duration) => {
1452
1427
  try {
1453
- const readAsArrayBuffer = () => {
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;
1428
+ const arrayBuffer = await blob.arrayBuffer();
1466
1429
  const uint8Array = new Uint8Array(arrayBuffer);
1467
- const elements = decoder.decode(uint8Array);
1468
- elements.forEach((element) => reader.read(element));
1469
- reader.stop();
1470
- const refinedMetadataBuf = ebml.tools.makeMetadataSeekable(reader.metadatas, reader.duration, reader.cues);
1471
- const body = arrayBuffer.slice(reader.metadataSize);
1472
- const result = new Blob([refinedMetadataBuf, body], { type: blob.type });
1473
- return { blob: result };
1430
+ // Function to find an EBML element by its ID
1431
+ function findElement(idHex) {
1432
+ const idBytes = new Uint8Array(idHex.match(/.{1,2}/g).map(byte => parseInt(byte, 16)));
1433
+ for (let i = 0; i < uint8Array.length - idBytes.length; i++) {
1434
+ if (uint8Array.slice(i, i + idBytes.length).toString() === idBytes.toString())
1435
+ return i + idBytes.length; // Return position after the ID
1436
+ }
1437
+ return -1;
1438
+ }
1439
+ // WebM duration EBML ID: 0x4489 (Segment Information -> Duration)
1440
+ const durationPos = findElement("4489");
1441
+ if (durationPos === -1) {
1442
+ throw new Error("Duration element not found in the WebM file.");
1443
+ }
1444
+ // Encode new duration in IEEE 754 Float64 (Big Endian, 8 bytes)
1445
+ const durationBytes = new Uint8Array(new Float64Array([duration]).buffer).reverse();
1446
+ // Overwrite duration bytes in the WebM file
1447
+ uint8Array.set(durationBytes, durationPos);
1448
+ // Convert back to Blob
1449
+ const blobUpdated = new Blob([uint8Array], { type: "video/webm" });
1450
+ return {
1451
+ blob: blobUpdated,
1452
+ duration
1453
+ };
1474
1454
  }
1475
1455
  catch (error) {
1476
- console.log('audioFix error', error);
1477
- // fallback
1478
- // return durationFallback(blob);
1479
1456
  return {
1480
1457
  blob,
1458
+ duration,
1481
1459
  error
1482
1460
  };
1483
1461
  }