@innovastudio/contentbuilder 1.4.83 → 1.4.85

Sign up to get free protection for your applications and to get access to all the features.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@innovastudio/contentbuilder",
3
3
  "type": "module",
4
- "version": "1.4.83",
4
+ "version": "1.4.85",
5
5
  "description": "",
6
6
  "main": "public/contentbuilder/contentbuilder.esm.js",
7
7
  "files": [
@@ -55,10 +55,9 @@
55
55
  "cropperjs": "^1.5.12",
56
56
  "js-beautify": "^1.14.0",
57
57
  "moveable": "^0.30.0",
58
- "opus-recorder": "^8.0.5",
59
58
  "rangy": "^1.3.0",
60
59
  "socket.io-client": "^4.7.1",
61
60
  "sortablejs": "^1.14.0",
62
- "string-similarity": "^4.0.4"
61
+ "string-similarity-js": "^2.1.4"
63
62
  }
64
63
  }
@@ -1,9 +1,5 @@
1
1
  var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
2
2
 
3
- function getDefaultExportFromCjs (x) {
4
- return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
5
- }
6
-
7
3
  var rangyCore = {exports: {}};
8
4
 
9
5
  /**
@@ -8551,7 +8547,7 @@ class Dom {
8551
8547
 
8552
8548
  var js$1 = {exports: {}};
8553
8549
 
8554
- var src$1 = {};
8550
+ var src = {};
8555
8551
 
8556
8552
  var javascript = {exports: {}};
8557
8553
 
@@ -13690,9 +13686,9 @@ function style_html(html_source, options, js, css) {
13690
13686
  }
13691
13687
  style_html.defaultOptions = html_beautify.defaultOptions;
13692
13688
 
13693
- src$1.js = js_beautify;
13694
- src$1.css = css_beautify;
13695
- src$1.html = style_html;
13689
+ src.js = js_beautify;
13690
+ src.css = css_beautify;
13691
+ src.html = style_html;
13696
13692
 
13697
13693
  /*jshint node:true */
13698
13694
 
@@ -13735,7 +13731,7 @@ function get_beautify(js_beautify, css_beautify, html_beautify) {
13735
13731
 
13736
13732
  {
13737
13733
  (function(mod) {
13738
- var beautifier = src$1;
13734
+ var beautifier = src;
13739
13735
  beautifier.js_beautify = beautifier.js;
13740
13736
  beautifier.css_beautify = beautifier.css;
13741
13737
  beautifier.html_beautify = beautifier.html;
@@ -77398,14 +77394,8 @@ class Lib {
77398
77394
  }
77399
77395
  }
77400
77396
 
77401
- var recorder_min = {exports: {}};
77402
-
77403
- (function (module, exports) {
77404
- !function(e,t){module.exports=t();}("undefined"!=typeof self?self:commonjsGlobal,(function(){return function(e){var t={};function o(n){if(t[n])return t[n].exports;var i=t[n]={i:n,l:!1,exports:{}};return e[n].call(i.exports,i,i.exports,o),i.l=!0,i.exports}return o.m=e,o.c=t,o.d=function(e,t,n){o.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n});},o.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0});},o.t=function(e,t){if(1&t&&(e=o(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(o.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var i in e)o.d(n,i,function(t){return e[t]}.bind(null,i));return n},o.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return o.d(t,"a",t),t},o.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},o.p="",o(o.s=0)}([function(e,t,o){(function(t){function o(e,t){if(null==e)return {};var o,n,i=function(e,t){if(null==e)return {};var o,n,i={},r=Object.keys(e);for(n=0;n<r.length;n++)o=r[n],t.indexOf(o)>=0||(i[o]=e[o]);return i}(e,t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);for(n=0;n<r.length;n++)o=r[n],t.indexOf(o)>=0||Object.prototype.propertyIsEnumerable.call(e,o)&&(i[o]=e[o]);}return i}var n=t.AudioContext||t.webkitAudioContext,i=function e(){var t=this,o=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};if(!e.isRecordingSupported())throw new Error("Recording is not supported in this browser");this.state="inactive",this.config=Object.assign({bufferLength:4096,encoderApplication:2049,encoderFrameSize:20,encoderPath:"encoderWorker.min.js",encoderSampleRate:48e3,maxFramesPerPage:40,mediaTrackConstraints:!0,monitorGain:0,numberOfChannels:1,recordingGain:1,resampleQuality:3,streamPages:!1,wavBitDepth:16,sourceNode:{context:null}},o),this.encodedSamplePosition=0,this.initAudioContext(),this.initialize=this.initWorklet().then((function(){return t.initEncoder()}));};i.isRecordingSupported=function(){var e=t.navigator&&t.navigator.mediaDevices&&t.navigator.mediaDevices.getUserMedia;return n&&e&&t.WebAssembly},i.version="8.0.5",i.prototype.clearStream=function(){this.stream&&(this.stream.getTracks?this.stream.getTracks().forEach((function(e){return e.stop()})):this.stream.stop());},i.prototype.close=function(){return this.monitorGainNode.disconnect(),this.recordingGainNode.disconnect(),this.sourceNode&&this.sourceNode.disconnect(),this.clearStream(),this.encoder&&(this.encoderNode.disconnect(),this.encoder.postMessage({command:"close"})),this.config.sourceNode.context?Promise.resolve():this.audioContext.close()},i.prototype.encodeBuffers=function(e){if("recording"===this.state){for(var t=[],o=0;o<e.numberOfChannels;o++)t[o]=e.getChannelData(o);this.encoder.postMessage({command:"encode",buffers:t});}},i.prototype.initAudioContext=function(){this.audioContext=this.config.sourceNode.context?this.config.sourceNode.context:new n,this.monitorGainNode=this.audioContext.createGain(),this.setMonitorGain(this.config.monitorGain),this.recordingGainNode=this.audioContext.createGain(),this.setRecordingGain(this.config.recordingGain);},i.prototype.initEncoder=function(){var e=this;this.audioContext.audioWorklet?(this.encoderNode=new AudioWorkletNode(this.audioContext,"encoder-worklet",{numberOfOutputs:0}),this.encoder=this.encoderNode.port):(console.log("audioWorklet support not detected. Falling back to scriptProcessor"),this.encodeBuffers=function(){return delete e.encodeBuffers},this.encoderNode=this.audioContext.createScriptProcessor(this.config.bufferLength,this.config.numberOfChannels,this.config.numberOfChannels),this.encoderNode.onaudioprocess=function(t){var o=t.inputBuffer;return e.encodeBuffers(o)},this.encoderNode.connect(this.audioContext.destination),this.encoder=new t.Worker(this.config.encoderPath));},i.prototype.initSourceNode=function(){var e=this;return this.config.sourceNode.context?(this.sourceNode=this.config.sourceNode,Promise.resolve()):t.navigator.mediaDevices.getUserMedia({audio:this.config.mediaTrackConstraints}).then((function(t){e.stream=t,e.sourceNode=e.audioContext.createMediaStreamSource(t);}))},i.prototype.initWorker=function(){var e=this,t=(this.config.streamPages?this.streamPage:this.storePage).bind(this);return this.recordedPages=[],this.totalLength=0,new Promise((function(n){e.encoder.addEventListener("message",(function o(i){var r=i.data;switch(r.message){case"ready":n();break;case"page":e.encodedSamplePosition=r.samplePosition,t(r.page);break;case"done":e.encoder.removeEventListener("message",o),e.finish();}})),e.encoder.start&&e.encoder.start();var i=e.config,r=(i.sourceNode,o(i,["sourceNode"]));e.encoder.postMessage(Object.assign({command:"init",originalSampleRate:e.audioContext.sampleRate,wavSampleRate:e.audioContext.sampleRate},r));}))},i.prototype.initWorklet=function(){return this.audioContext.audioWorklet?this.audioContext.audioWorklet.addModule(this.config.encoderPath):Promise.resolve()},i.prototype.pause=function(e){var t=this;if("recording"===this.state)return this.state="paused",this.recordingGainNode.disconnect(),e&&this.config.streamPages?new Promise((function(e){t.encoder.addEventListener("message",(function o(n){"flushed"===n.data.message&&(t.encoder.removeEventListener("message",o),t.onpause(),e());})),t.encoder.start&&t.encoder.start(),t.encoder.postMessage({command:"flush"});})):(this.onpause(),Promise.resolve())},i.prototype.resume=function(){"paused"===this.state&&(this.state="recording",this.recordingGainNode.connect(this.encoderNode),this.onresume());},i.prototype.setRecordingGain=function(e){this.config.recordingGain=e,this.recordingGainNode&&this.audioContext&&this.recordingGainNode.gain.setTargetAtTime(e,this.audioContext.currentTime,.01);},i.prototype.setMonitorGain=function(e){this.config.monitorGain=e,this.monitorGainNode&&this.audioContext&&this.monitorGainNode.gain.setTargetAtTime(e,this.audioContext.currentTime,.01);},i.prototype.start=function(){var e=this;return "inactive"===this.state?(this.state="loading",this.encodedSamplePosition=0,this.audioContext.resume().then((function(){return e.initialize})).then((function(){return Promise.all([e.initSourceNode(),e.initWorker()])})).then((function(){e.state="recording",e.encoder.postMessage({command:"getHeaderPages"}),e.sourceNode.connect(e.monitorGainNode),e.sourceNode.connect(e.recordingGainNode),e.monitorGainNode.connect(e.audioContext.destination),e.recordingGainNode.connect(e.encoderNode),e.onstart();})).catch((function(t){throw e.state="inactive",t}))):Promise.resolve()},i.prototype.stop=function(){var e=this;return "paused"===this.state||"recording"===this.state?(this.state="inactive",this.recordingGainNode.connect(this.encoderNode),this.monitorGainNode.disconnect(),this.clearStream(),new Promise((function(t){e.encoder.addEventListener("message",(function o(n){"done"===n.data.message&&(e.encoder.removeEventListener("message",o),t());})),e.encoder.start&&e.encoder.start(),e.encoder.postMessage({command:"done"});}))):Promise.resolve()},i.prototype.storePage=function(e){this.recordedPages.push(e),this.totalLength+=e.length;},i.prototype.streamPage=function(e){this.ondataavailable(e);},i.prototype.finish=function(){if(!this.config.streamPages){var e=new Uint8Array(this.totalLength);this.recordedPages.reduce((function(t,o){return e.set(o,t),t+o.length}),0),this.ondataavailable(e);}this.onstop();},i.prototype.ondataavailable=function(){},i.prototype.onpause=function(){},i.prototype.onresume=function(){},i.prototype.onstart=function(){},i.prototype.onstop=function(){},e.exports=i;}).call(this,o(1));},function(e,t){var o;o=function(){return this}();try{o=o||new Function("return this")();}catch(e){"object"==typeof window&&(o=window);}e.exports=o;}])}));
77405
- }(recorder_min));
77406
-
77407
- var Recorder = /*@__PURE__*/getDefaultExportFromCjs(recorder_min.exports);
77408
-
77397
+ // import RecordRTC from 'recordrtc';
77398
+ // import Recorder from 'opus-recorder'; // Using Recorder
77409
77399
  const dom = new Dom();
77410
77400
  class Dictation {
77411
77401
  constructor(opts = {}, builder) {
@@ -77845,11 +77835,11 @@ class Dictation {
77845
77835
  this.mediaRecorder.stop();
77846
77836
  this.localStream.getTracks().forEach(track => track.stop()); // Stop the tracks to release the resources
77847
77837
  }
77848
- } else {
77849
- // Using Recorder
77850
- if (this.recorder) this.recorder.stop();
77851
- if (this.localStream) this.localStream.getTracks().forEach(track => track.stop()); // Stop the tracks to release the resources
77852
- }
77838
+ } /* else {
77839
+ // Using Recorder
77840
+ if(this.recorder) this.recorder.stop();
77841
+ if(this.localStream) this.localStream.getTracks().forEach(track => track.stop()); // Stop the tracks to release the resources
77842
+ } */
77853
77843
 
77854
77844
  if (this.websocket && this.websocket.readyState === WebSocket.OPEN) {
77855
77845
  this.websocket.close();
@@ -77922,22 +77912,23 @@ class Dictation {
77922
77912
  }).catch(error => {
77923
77913
  console.log(error);
77924
77914
  });
77925
- } else {
77926
- // Using Recorder
77927
- this.recorder = new Recorder({
77928
- encoderPath: 'https://cdnjs.cloudflare.com/ajax/libs/opus-recorder/8.0.5/encoderWorker.min.js',
77929
- leaveStreamOpen: true,
77930
- numberOfChannels: 1,
77931
- // OPUS options
77932
- encoderSampleRate: sampleRate,
77933
- streamPages: true,
77934
- maxBuffersPerPage: 1
77935
- });
77936
- this.recorder.ondataavailable = e => {
77937
- if (this.aborted) return;
77938
- this.websocket.send(e.buffer);
77939
- };
77940
- }
77915
+ } /* else {
77916
+ // Using Recorder
77917
+ this.recorder = new Recorder({
77918
+ encoderPath: this.builder.encoderPath||
77919
+ 'https://cdnjs.cloudflare.com/ajax/libs/opus-recorder/8.0.5/encoderWorker.min.js',
77920
+ leaveStreamOpen: true,
77921
+ numberOfChannels: 1,
77922
+ // OPUS options
77923
+ encoderSampleRate: sampleRate,
77924
+ streamPages: true,
77925
+ maxBuffersPerPage: 1,
77926
+ });
77927
+ this.recorder.ondataavailable = (e) => {
77928
+ if(this.aborted) return;
77929
+ this.websocket.send(e.buffer);
77930
+ };
77931
+ } */
77941
77932
 
77942
77933
  /*
77943
77934
  // Using RecordRTC
@@ -77966,6 +77957,7 @@ class Dictation {
77966
77957
  }, 2000);
77967
77958
  }
77968
77959
  let finalTranscripts = '';
77960
+ let speechTimeout;
77969
77961
  this.websocket.onmessage = event => {
77970
77962
  const message = JSON.parse(event.data);
77971
77963
  if (message.event === 'can-open-mic') {
@@ -77973,22 +77965,29 @@ class Dictation {
77973
77965
 
77974
77966
  if (this.builder.useMediaRecorder) {
77975
77967
  this.mediaRecorder.start(1000); // Using mediaRecorder
77976
- } else {
77977
- this.recorder.start(); // Using Recorder
77978
- }
77968
+ } /* else {
77969
+ this.recorder.start(); // Using Recorder
77970
+ } */
77979
77971
 
77980
77972
  // console.log('Start Dictation');
77981
77973
  this.aborted = false;
77982
77974
  }
77983
77975
  if (message.event === 'transcript-result') {
77984
- const transcripts = message.data;
77985
77976
  if (this.builder.isInProgress || this.aborted) {
77986
77977
  return;
77987
77978
  }
77988
- finalTranscripts += ' ' + transcripts;
77979
+ const transcript = message.data.channel.alternatives[0].transcript;
77980
+ if (transcript && message.data.is_final) {
77981
+ finalTranscripts += ' ' + transcript;
77982
+ }
77989
77983
  inpCommand.value = finalTranscripts;
77990
- clearTimeout(this.speechTimeout);
77991
- this.speechTimeout = setTimeout(() => {
77984
+ clearTimeout(speechTimeout);
77985
+
77986
+ // console.log('Writing..');
77987
+
77988
+ speechTimeout = setTimeout(() => {
77989
+ // console.log('Clear');
77990
+
77992
77991
  this.builder.commandText = '';
77993
77992
  finalTranscripts = '';
77994
77993
  if (this.builder.autoSendCommand) {
@@ -78089,72 +78088,51 @@ class Dictation {
78089
78088
  }
78090
78089
  }
78091
78090
 
78092
- var src = {
78093
- compareTwoStrings:compareTwoStrings,
78094
- findBestMatch:findBestMatch
78091
+ var stringSimilarity = {};
78092
+
78093
+ (function (exports) {
78094
+ Object.defineProperty(exports, "__esModule", { value: true });
78095
+ exports.stringSimilarity = void 0;
78096
+ /* global exports, Map */
78097
+ /**
78098
+ * Calculate similarity between two strings
78099
+ * @param {string} str1 First string to match
78100
+ * @param {string} str2 Second string to match
78101
+ * @param {number} [substringLength=2] Optional. Length of substring to be used in calculating similarity. Default 2.
78102
+ * @param {boolean} [caseSensitive=false] Optional. Whether you want to consider case in string matching. Default false;
78103
+ * @returns Number between 0 and 1, with 0 being a low match score.
78104
+ */
78105
+ var stringSimilarity = function (str1, str2, substringLength, caseSensitive) {
78106
+ if (substringLength === void 0) { substringLength = 2; }
78107
+ if (caseSensitive === void 0) { caseSensitive = false; }
78108
+ if (!caseSensitive) {
78109
+ str1 = str1.toLowerCase();
78110
+ str2 = str2.toLowerCase();
78111
+ }
78112
+ if (str1.length < substringLength || str2.length < substringLength)
78113
+ return 0;
78114
+ var map = new Map();
78115
+ for (var i = 0; i < str1.length - (substringLength - 1); i++) {
78116
+ var substr1 = str1.substr(i, substringLength);
78117
+ map.set(substr1, map.has(substr1) ? map.get(substr1) + 1 : 1);
78118
+ }
78119
+ var match = 0;
78120
+ for (var j = 0; j < str2.length - (substringLength - 1); j++) {
78121
+ var substr2 = str2.substr(j, substringLength);
78122
+ var count = map.has(substr2) ? map.get(substr2) : 0;
78123
+ if (count > 0) {
78124
+ map.set(substr2, count - 1);
78125
+ match++;
78126
+ }
78127
+ }
78128
+ return (match * 2) / (str1.length + str2.length - ((substringLength - 1) * 2));
78095
78129
  };
78130
+ exports.stringSimilarity = stringSimilarity;
78131
+ exports.default = exports.stringSimilarity;
78096
78132
 
78097
- function compareTwoStrings(first, second) {
78098
- first = first.replace(/\s+/g, '');
78099
- second = second.replace(/\s+/g, '');
78100
-
78101
- if (first === second) return 1; // identical or empty
78102
- if (first.length < 2 || second.length < 2) return 0; // if either is a 0-letter or 1-letter string
78103
-
78104
- let firstBigrams = new Map();
78105
- for (let i = 0; i < first.length - 1; i++) {
78106
- const bigram = first.substring(i, i + 2);
78107
- const count = firstBigrams.has(bigram)
78108
- ? firstBigrams.get(bigram) + 1
78109
- : 1;
78110
-
78111
- firstBigrams.set(bigram, count);
78112
- }
78113
- let intersectionSize = 0;
78114
- for (let i = 0; i < second.length - 1; i++) {
78115
- const bigram = second.substring(i, i + 2);
78116
- const count = firstBigrams.has(bigram)
78117
- ? firstBigrams.get(bigram)
78118
- : 0;
78119
-
78120
- if (count > 0) {
78121
- firstBigrams.set(bigram, count - 1);
78122
- intersectionSize++;
78123
- }
78124
- }
78125
-
78126
- return (2.0 * intersectionSize) / (first.length + second.length - 2);
78127
- }
78128
-
78129
- function findBestMatch(mainString, targetStrings) {
78130
- if (!areArgsValid(mainString, targetStrings)) throw new Error('Bad arguments: First argument should be a string, second should be an array of strings');
78131
-
78132
- const ratings = [];
78133
- let bestMatchIndex = 0;
78134
-
78135
- for (let i = 0; i < targetStrings.length; i++) {
78136
- const currentTargetString = targetStrings[i];
78137
- const currentRating = compareTwoStrings(mainString, currentTargetString);
78138
- ratings.push({target: currentTargetString, rating: currentRating});
78139
- if (currentRating > ratings[bestMatchIndex].rating) {
78140
- bestMatchIndex = i;
78141
- }
78142
- }
78143
-
78144
-
78145
- const bestMatch = ratings[bestMatchIndex];
78146
-
78147
- return { ratings: ratings, bestMatch: bestMatch, bestMatchIndex: bestMatchIndex };
78148
- }
78149
-
78150
- function areArgsValid(mainString, targetStrings) {
78151
- if (typeof mainString !== 'string') return false;
78152
- if (!Array.isArray(targetStrings)) return false;
78153
- if (!targetStrings.length) return false;
78154
- if (targetStrings.find( function (s) { return typeof s !== 'string'})) return false;
78155
- return true;
78156
- }
78133
+ }(stringSimilarity));
78157
78134
 
78135
+ // import stringSimilarity from 'string-similarity';
78158
78136
  class Similarity {
78159
78137
  constructor(builder) {
78160
78138
  this.builder = builder;
@@ -78184,7 +78162,7 @@ class Similarity {
78184
78162
  const normalizedCommand = command.toLowerCase();
78185
78163
  let maxSimilarity = 0;
78186
78164
  for (const cmd of list) {
78187
- const similarity = src.compareTwoStrings(normalizedCommand, cmd);
78165
+ const similarity = stringSimilarity.stringSimilarity(normalizedCommand, cmd);
78188
78166
  if (similarity > maxSimilarity) {
78189
78167
  // console.log(list)
78190
78168
  // console.log(similarity)
@@ -78809,16 +78787,18 @@ class ContentBuilder {
78809
78787
  enableDragResize: true,
78810
78788
  simpleTextSettings: false,
78811
78789
  enableColumnsPerLine: true,
78812
- /* Prompt/Command Stuff */
78790
+ /* Prompt/Command Stuff for AI Assistant */
78813
78791
  isContentBox: false,
78814
78792
  sendCommandUrl: 'http://localhost:8081/answer',
78815
78793
  // speechTranscribeUrl: 'http://192.168.1.7:8081',
78816
78794
  onlineDemo: false,
78817
- autoSendDelay: 3000,
78795
+ autoSendDelay: 4000,
78818
78796
  commandPlaceholderText: '',
78819
78797
  enableShortCommands: true,
78820
78798
  speechRecognitionLang: 'en-US',
78821
- useMediaRecorder: false,
78799
+ useMediaRecorder: true,
78800
+ // do not change
78801
+ encoderPath: '',
78822
78802
  headlineList: ['We create simple and effective designs.', 'Ultimate Experiences With Story, Emotion, And Purpose.', 'Build Anything Beautifully', 'With Less Stuff and More Compassion', 'We\'re [CompanyName]. Full stack development with a spark of creativity.', 'Transforming your digital experience with [CompanyName]. Achieve your online goals with our customized solutions.', 'Revolutionizing web development with [CompanyName]. Unleash your digital potential with our high-performance solutions.', 'Creative and Inspiring'],
78823
78803
  shortCommandList: {
78824
78804
  undo: ['undo'],