@rogieking/figui3 1.6.5 → 1.6.6

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/charli.jpeg ADDED
Binary file
package/components.css CHANGED
@@ -1190,6 +1190,7 @@ fig-image {
1190
1190
  place-items: center;
1191
1191
  width: var(--image-size);
1192
1192
  height: var(--image-size);
1193
+ aspect-ratio: 1 / 1;
1193
1194
  > * {
1194
1195
  grid-area: 1/1;
1195
1196
  }
@@ -1211,6 +1212,16 @@ fig-image {
1211
1212
  &[size="large"] {
1212
1213
  --image-size: 8rem;
1213
1214
  }
1215
+ &[aspect-ratio="auto"] {
1216
+ aspect-ratio: var(--aspect-ratio);
1217
+ height: auto;
1218
+ fig-chit,
1219
+ fig-chit::after,
1220
+ input {
1221
+ height: auto !important;
1222
+ aspect-ratio: var(--aspect-ratio) !important;
1223
+ }
1224
+ }
1214
1225
  }
1215
1226
 
1216
1227
  /* Combo input */
package/example.html CHANGED
@@ -233,6 +233,15 @@
233
233
  size="large"></fig-image>
234
234
  </fig-field>
235
235
  <br /><br />
236
+ <fig-field>
237
+ <label>Large (with upload)</label>
238
+ <fig-image upload="true"
239
+ label="Change image"
240
+ aspect-ratio="auto"
241
+ src="charli.jpeg"
242
+ size="large"></fig-image>
243
+ </fig-field>
244
+ <br /><br />
236
245
  <fig-header>
237
246
  <h2>Button</h2>
238
247
  </fig-header>
package/fig.js CHANGED
@@ -1805,6 +1805,12 @@ class FigImage extends HTMLElement {
1805
1805
  this.innerHTML = this.#getInnerHTML();
1806
1806
  this.#updateRefs();
1807
1807
  }
1808
+ disconnectedCallback() {
1809
+ this.fileInput.removeEventListener(
1810
+ "change",
1811
+ this.#handleFileInput.bind(this)
1812
+ );
1813
+ }
1808
1814
 
1809
1815
  #updateRefs() {
1810
1816
  requestAnimationFrame(() => {
@@ -1815,12 +1821,47 @@ class FigImage extends HTMLElement {
1815
1821
 
1816
1822
  this.fileInput.addEventListener(
1817
1823
  "change",
1818
- this.handleFileInput.bind(this)
1824
+ this.#handleFileInput.bind(this)
1819
1825
  );
1820
1826
  }
1827
+ if (this.src) {
1828
+ this.#loadImage(this.src);
1829
+ }
1830
+ });
1831
+ }
1832
+ async #loadImage(src) {
1833
+ // Get blob from canvas
1834
+ await new Promise((resolve) => {
1835
+ this.image = new Image();
1836
+ this.image.crossOrigin = "Anonymous";
1837
+
1838
+ this.image.onload = async () => {
1839
+ this.aspectRatio = this.image.width / this.image.height;
1840
+ this.style.setProperty(
1841
+ "--aspect-ratio",
1842
+ `${this.image.width}/${this.image.height}`
1843
+ );
1844
+ resolve();
1845
+
1846
+ // Create canvas to extract blob and base64 from image
1847
+ const canvas = document.createElement("canvas");
1848
+ const ctx = canvas.getContext("2d");
1849
+ canvas.width = this.image.width;
1850
+ canvas.height = this.image.height;
1851
+ ctx.drawImage(this.image, 0, 0);
1852
+
1853
+ // Get base64 from canvas
1854
+ this.base64 = canvas.toDataURL();
1855
+
1856
+ // Get blob from canvas
1857
+ canvas.toBlob((blob) => {
1858
+ this.blob = URL.createObjectURL(blob);
1859
+ });
1860
+ };
1861
+ this.image.src = src;
1821
1862
  });
1822
1863
  }
1823
- async handleFileInput(e) {
1864
+ async #handleFileInput(e) {
1824
1865
  this.blob = URL.createObjectURL(e.target.files[0]);
1825
1866
  //set base64 url
1826
1867
  const reader = new FileReader();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rogieking/figui3",
3
- "version": "1.6.5",
3
+ "version": "1.6.6",
4
4
  "module": "index.ts",
5
5
  "type": "module",
6
6
  "devDependencies": {