@innovastudio/contentbuilder 1.4.93 → 1.4.95

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.93",
4
+ "version": "1.4.95",
5
5
  "description": "",
6
6
  "main": "public/contentbuilder/contentbuilder.esm.js",
7
7
  "files": [
@@ -2077,7 +2077,7 @@ button:focus-visible {
2077
2077
  .is-ui .is-modal.imageadjust2,
2078
2078
  .is-ui .is-modal.audioselect,
2079
2079
  .is-ui .is-modal.mediasource {
2080
- z-index: 10005 !important;
2080
+ z-index: 10006 !important;
2081
2081
  }
2082
2082
  #_cbhtml .is-modal.previewcontent,
2083
2083
  .is-ui .is-modal.previewcontent {
@@ -15886,10 +15886,6 @@ const prepareSvgIcons = builder => {
15886
15886
  <path d="M4 12h4"></path>
15887
15887
  <path d="M4 18h4"></path>
15888
15888
  </symbol>
15889
- <symbol id="icon-folder" viewBox="0 0 24 24" stroke-width="1" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
15890
- <path stroke="none" d="M0 0h24v24H0z" fill="none"></path>
15891
- <path d="M5 4h4l3 3h7a2 2 0 0 1 2 2v8a2 2 0 0 1 -2 2h-14a2 2 0 0 1 -2 -2v-11a2 2 0 0 1 2 -2"></path>
15892
- </symbol>
15893
15889
  <symbol id="icon-folder-media" viewBox="0 0 24 24" stroke-width="1" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
15894
15890
  <path stroke="none" d="M0 0h24v24H0z" fill="none"></path>
15895
15891
  <path d="M5 4h4l3 3h7a2 2 0 0 1 2 2v8a2 2 0 0 1 -2 2h-14a2 2 0 0 1 -2 -2v-11a2 2 0 0 1 2 -2"></path>
@@ -15958,6 +15954,23 @@ const prepareSvgIcons = builder => {
15958
15954
  <path d="M18 18m-3 0a3 3 0 1 0 6 0a3 3 0 1 0 -6 0"></path>
15959
15955
  <path d="M20.2 20.2l1.8 1.8"></path>
15960
15956
  </symbol>
15957
+
15958
+ <symbol id="icon-folder-old" viewBox="0 0 24 24" stroke-width="1" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
15959
+ <path stroke="none" d="M0 0h24v24H0z" fill="none"></path>
15960
+ <path d="M5 4h4l3 3h7a2 2 0 0 1 2 2v8a2 2 0 0 1 -2 2h-14a2 2 0 0 1 -2 -2v-11a2 2 0 0 1 2 -2"></path>
15961
+ </symbol>
15962
+ <symbol id="icon-folder" viewBox="0 0 24 24" stroke-width="1" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
15963
+ <path stroke="none" d="M0 0h24v24H0z" fill="none"></path>
15964
+ <path d="M11 19h-6a2 2 0 0 1 -2 -2v-11a2 2 0 0 1 2 -2h4l3 3h7a2 2 0 0 1 2 2v2.5"></path>
15965
+ <path d="M18 18m-3 0a3 3 0 1 0 6 0a3 3 0 1 0 -6 0"></path>
15966
+ <path d="M20.2 20.2l1.8 1.8"></path>
15967
+ </symbol>
15968
+ <symbol id="icon-folder2" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
15969
+ <path stroke="none" d="M0 0h24v24H0z" fill="none"></path>
15970
+ <path d="M11 19h-6a2 2 0 0 1 -2 -2v-11a2 2 0 0 1 2 -2h4l3 3h7a2 2 0 0 1 2 2v2.5"></path>
15971
+ <path d="M18 18m-3 0a3 3 0 1 0 6 0a3 3 0 1 0 -6 0"></path>
15972
+ <path d="M20.2 20.2l1.8 1.8"></path>
15973
+ </symbol>
15961
15974
 
15962
15975
  </defs>
15963
15976
  </svg>`;
@@ -49551,6 +49564,7 @@ class Image$1 {
49551
49564
  <input title="${util.out('Change Image')}" data-title="${util.out('Change Image')}" id="fileEmbedImage" type="file" accept="image/*" style="position:absolute;top:-20px;left:0;width:40px;height:60px;opacity: 0;cursor: pointer;"/>
49552
49565
  </div>
49553
49566
  <button tabindex="0" title="${util.out('Link')}" data-title="${util.out('Link')}" class="image-link" style="width:40px;height:40px;"><svg class="is-icon-flex" style="width:17px;height:17px;"><use xlink:href="#ion-link"></use></svg></button>
49567
+ <button tabindex="0" title="${util.out('Select')}" data-title="${util.out('Select')}" class="open-asset" style="display:none;width:40px;height:40px;"><svg class="is-icon-flex" style="width:17px;height:17px;color:#fff"><use xlink:href="#icon-folder2"></use></svg></button>
49554
49568
  <button tabindex="0" title="${util.out('Edit')}" data-title="${util.out('Edit')}" class="image-edit" style="width:40px;height:40px;"><svg class="is-icon-flex" style="width:14px;height:14px;"><use xlink:href="#ion-android-create"></use></svg></button>
49555
49569
  </div>
49556
49570
  <div id="divImageProgress">
@@ -50067,6 +50081,35 @@ class Image$1 {
50067
50081
  util.hideModal(modalImageLink);
50068
50082
  this.builder.elmTool.refresh();
50069
50083
  });
50084
+ const btnOpenAsset = imageTool.querySelector('.open-asset');
50085
+ if (this.builder.opts.onImageSelectClick || this.builder.opts.imageselect) {
50086
+ btnOpenAsset.style.display = 'block';
50087
+ dom.addEventListener(btnOpenAsset, 'click', () => {
50088
+ this.builder.openImageSelect(src => {
50089
+ this.builder.uo.saveForUndo();
50090
+ let img = this.builder.activeImage;
50091
+ img.setAttribute('src', src);
50092
+ setTimeout(() => {
50093
+ img.click();
50094
+ let divImageResizer = document.querySelector('#divImageResizer');
50095
+ if (divImageResizer) divImageResizer.click();
50096
+ setTimeout(() => {
50097
+ img.click();
50098
+ let divImageResizer = document.querySelector('#divImageResizer');
50099
+ if (divImageResizer) divImageResizer.click();
50100
+ }, 600);
50101
+ }, 10);
50102
+
50103
+ //Trigger Change event
50104
+ this.builder.opts.onChange();
50105
+
50106
+ //Trigger Render event
50107
+ this.builder.opts.onRender();
50108
+ });
50109
+ });
50110
+ } else {
50111
+ btnOpenAsset.style.display = 'none';
50112
+ }
50070
50113
 
50071
50114
  // Select image (opens Asset Manager plugin or custom dialog)
50072
50115
  let divImageSrc = modalImageLink.querySelector('.image-src');
@@ -77984,7 +78027,7 @@ class Dictation {
77984
78027
  let htmlList = '';
77985
78028
  const commandInfo = this.builder.commandInfo;
77986
78029
  let bImageGeneration = false;
77987
- if (this.builder.generateImageUrl && this.builder.uploadBase64Url) {
78030
+ if (this.builder.textToImageUrl) {
77988
78031
  bImageGeneration = true;
77989
78032
  }
77990
78033
  for (const key in commandInfo) {
@@ -78122,7 +78165,7 @@ class Dictation {
78122
78165
  const btnScopeOthers = this.modalCommand.querySelector('.scope-others');
78123
78166
  const btnScopeImage = this.modalCommand.querySelector('.scope-image');
78124
78167
  btnScopeBlock.disabled = true;
78125
- if (this.builder.generateImageUrl) btnScopeImage.style.display = ''; // show generate image button
78168
+ if (this.builder.textToImageUrl) btnScopeImage.style.display = ''; // show generate image button
78126
78169
 
78127
78170
  const assistModeBtns = modalCommand.querySelectorAll('.div-assistant-mode button');
78128
78171
  assistModeBtns.forEach(btn => {
@@ -80895,6 +80938,35 @@ class ContentBuilder {
80895
80938
  return this.targetAssetType; // not used yet
80896
80939
  }
80897
80940
 
80941
+ openImageSelect(callback) {
80942
+ const inpUrl = document.createElement('input');
80943
+
80944
+ // dummy button (for the openAsset() method, for the old Asset Manager. Not needed for the new.)
80945
+ const btn = document.createElement('button');
80946
+ this.openAsset(inpUrl, 'image', btn);
80947
+ let out = s => this.util.out(s);
80948
+ const desc = Object.getOwnPropertyDescriptor(HTMLInputElement.prototype, 'value');
80949
+ Object.defineProperty(inpUrl, 'value', {
80950
+ get: desc.get,
80951
+ set: function (s) {
80952
+ // Additional protection if normal selectAsset() is not used in asset dialog.
80953
+ // This is used if onImageSelectClick or onFileSelectClick are used.
80954
+ const filename = s.substring(s.lastIndexOf('/') + 1);
80955
+ let extension = filename.split('.').pop();
80956
+ extension = extension.toLowerCase();
80957
+ let ok = false;
80958
+ if (extension === 'jpg' || extension === 'jpeg' || extension === 'png' || extension === 'gif' || extension === 'webm' || extension === 'webp') {
80959
+ ok = true;
80960
+ } else {
80961
+ alert(out('Please select an image file.'));
80962
+ }
80963
+ if (ok) {
80964
+ if (callback) callback(s);
80965
+ }
80966
+ desc.set.call(this, s);
80967
+ }
80968
+ });
80969
+ }
80898
80970
  renderSelectAsset(btn, targetAssetType, callback) {
80899
80971
  const _id = 'inp_' + this.util.makeId();
80900
80972
  btn.insertAdjacentHTML('afterend', `<input type="hidden" id="${_id}">`);
@@ -81864,17 +81936,36 @@ class ContentBuilder {
81864
81936
  }
81865
81937
  }
81866
81938
  }
81867
- async generateImage(prompt, num, callback) {
81868
- if (!(this.generateImageUrl && this.uploadBase64Url)) return;
81939
+ async generateImage(prompt, callback) {
81869
81940
  this.controller = new AbortController(); // Create a new AbortController
81870
81941
  this.signal = this.controller.signal; // Get a new signal object
81871
81942
 
81943
+ let model = 'realistic-vision-v3';
81944
+ let negative_prompt = '';
81945
+ if (model.includes('realistic-vision')) {
81946
+ if (negative_prompt === '') negative_prompt = 'duplicate, (deformed iris, deformed pupils, semi-realistic, cgi, 3d, render, sketch, cartoon, drawing, anime:1.4), text, close up, cropped, out of frame, worst quality, low quality, jpeg artifacts, ugly, duplicate, morbid, mutilated, extra fingers, mutated hands, poorly drawn hands, poorly drawn face, mutation, deformed, blurry, dehydrated, bad anatomy, bad proportions, extra limbs, cloned face, disfigured, gross proportions, malformed limbs, missing arms, missing legs, extra arms, extra legs, fused fingers, too many fingers, long neck, bad_prompt_version2, bad-hands-5, badhandv4, bad anatomy, deformed, mutated, amputated, missing finger, extra finger, fused fingers, missing leg, extra leg, fused legs, missing digit, extra digit, fused digits, missing hand, extra hand, fused hands, missing arm, extra arm, fused arms, missing limb, extra limb, fused limbs, fused bodies, merged bodies, extra bodies, dual bodies, extra navel, elongated body, missing joint, extra joint, fused joints, deformed hip, twisted limbs, twisted legs, twisted arms, missing head, extra head, double head, twins, missing ear, extra ear, deformed ear, black and white, monochrome, multiple views, blurry, text, signature, head out of frame, paintings, sketches, (worst quality:2), (low quality:2), (normal quality:2), lowres, grayscale, glans, bad hands, error, extra digit, fewer digits, cropped, jpeg artifacts, watermark, username, bad feet, poorly drawn hands, poorly drawn face, mutation, too many fingers, long neck, long body, long arms, cross-eyed, mutated hands, polar lowres, bad body, bad proportions, gross proportions, cropped head , bad eyes, extra breast, missing breast, fused breasts, unnatural proportions, necklace';
81947
+ }
81948
+ let width = 1024;
81949
+ let height = 1024;
81950
+ let steps = 25;
81951
+ let guidance = 7.5;
81952
+ let scheduler = 'dpmsolver++';
81953
+ let output_format = 'jpeg';
81872
81954
  const messages = {
81873
- prompt,
81874
- num
81955
+ model: 'realistic-vision-v3',
81956
+ prompt: prompt,
81957
+ negative_prompt: negative_prompt,
81958
+ width: width,
81959
+ height: height,
81960
+ steps: steps,
81961
+ guidance: guidance,
81962
+ scheduler: scheduler,
81963
+ output_format: output_format,
81964
+ folder_path: ''
81875
81965
  };
81876
81966
  try {
81877
- const response = await fetch(this.generateImageUrl, {
81967
+ let url = this.textToImageUrl;
81968
+ const response = await fetch(url, {
81878
81969
  signal: this.signal,
81879
81970
  // Abort
81880
81971
  method: 'POST',
@@ -81888,41 +81979,8 @@ class ContentBuilder {
81888
81979
  console.log('Error:\n' + result.error);
81889
81980
  return;
81890
81981
  }
81891
- const filename = result.filename;
81892
- let images = [];
81893
- const base64 = result.data;
81894
- const src = `data:image/jpeg;base64,${base64}`;
81895
- var newWidth = 1024;
81896
- var newHeight = 1024;
81897
- var img = new Image();
81898
- img.src = src;
81899
- img.onload = () => {
81900
- var canvas = document.createElement('canvas');
81901
- canvas.width = newWidth;
81902
- canvas.height = newHeight;
81903
- var ctx = canvas.getContext('2d');
81904
- ctx.drawImage(img, 0, 0, newWidth, newHeight);
81905
- var resizedBase64 = canvas.toDataURL('image/jpeg');
81906
- let image = resizedBase64;
81907
- image = image.replace(/^data:image\/(png|jpeg);base64,/, '');
81908
- const reqBody = {
81909
- image: image,
81910
- filename: filename
81911
- };
81912
- fetch(this.uploadBase64Url, {
81913
- method: 'POST',
81914
- body: JSON.stringify(reqBody),
81915
- headers: {
81916
- 'Content-Type': 'application/json'
81917
- }
81918
- }).then(response => response.json()).then(response => {
81919
- if (!response.error) {
81920
- const uploadedImageUrl = response.url;
81921
- images.push(uploadedImageUrl);
81922
- callback(images);
81923
- }
81924
- });
81925
- };
81982
+ const imageUrl = result.url;
81983
+ callback([imageUrl]);
81926
81984
  } catch (error) {
81927
81985
  if (error.name === 'AbortError') ; else {
81928
81986
  // CORS or code errors goes here
@@ -81934,8 +81992,11 @@ class ContentBuilder {
81934
81992
  }
81935
81993
  }
81936
81994
 
81937
- /*
81938
- async generateImage(prompt, num, callback) {
81995
+ /* OpenAI
81996
+ // Requires:
81997
+ // generateImageUrl: '/generateimage',
81998
+ // uploadBase64Url:'/uploadbase64',
81999
+ async generateImage(prompt, num, callback) {
81939
82000
  if(!(this.generateImageUrl && this.uploadBase64Url)) return;
81940
82001
  this.controller = new AbortController(); // Create a new AbortController
81941
82002
  this.signal = this.controller.signal; // Get a new signal object