@rogieking/figui3 1.6.4 → 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
@@ -664,10 +664,6 @@ select {
664
664
  padding-right: 1.5rem;
665
665
  }
666
666
 
667
- fig-dialog > *:not(dialog) {
668
- display: none !important;
669
- }
670
-
671
667
  /* Dropdown */
672
668
  fig-dropdown,
673
669
  .fig-dropdown {
@@ -1194,6 +1190,7 @@ fig-image {
1194
1190
  place-items: center;
1195
1191
  width: var(--image-size);
1196
1192
  height: var(--image-size);
1193
+ aspect-ratio: 1 / 1;
1197
1194
  > * {
1198
1195
  grid-area: 1/1;
1199
1196
  }
@@ -1215,6 +1212,16 @@ fig-image {
1215
1212
  &[size="large"] {
1216
1213
  --image-size: 8rem;
1217
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
+ }
1218
1225
  }
1219
1226
 
1220
1227
  /* Combo input */
@@ -1938,49 +1945,38 @@ dialog,
1938
1945
  }
1939
1946
  }
1940
1947
  }
1941
- fig-dialog,
1942
- .fig-dialog {
1943
- display: contents;
1948
+ dialog[is="fig-dialog"] {
1944
1949
  --offset: 1rem;
1945
1950
  --translate-x: -50%;
1946
1951
  --translate-y: -50%;
1952
+ --z-index: 999999;
1947
1953
 
1948
- dialog {
1949
- position: fixed;
1950
- top: 50%;
1951
- left: 50%;
1952
- margin: 0;
1953
- z-index: 999999;
1954
- transform: translate(var(--translate-x), var(--translate-y));
1955
- }
1954
+ position: fixed;
1955
+ top: 50%;
1956
+ left: 50%;
1957
+ margin: 0;
1958
+ z-index: var(--z-index);
1959
+ transform: translate(var(--translate-x), var(--translate-y));
1956
1960
 
1957
1961
  &[position*="bottom"] {
1958
- dialog {
1959
- bottom: var(--offset);
1960
- top: auto;
1961
- --translate-y: 0;
1962
- }
1962
+ bottom: var(--offset);
1963
+ top: auto;
1964
+ --translate-y: 0;
1963
1965
  }
1964
1966
  &[position*="top"] {
1965
- dialog {
1966
- top: var(--offset);
1967
- bottom: auto;
1968
- --translate-y: 0;
1969
- }
1967
+ top: var(--offset);
1968
+ bottom: auto;
1969
+ --translate-y: 0;
1970
1970
  }
1971
1971
  &[position*="right"] {
1972
- dialog {
1973
- right: var(--offset);
1974
- left: auto;
1975
- --translate-x: 0;
1976
- }
1972
+ right: var(--offset);
1973
+ left: auto;
1974
+ --translate-x: 0;
1977
1975
  }
1978
1976
  &[position*="left"] {
1979
- dialog {
1980
- left: var(--offset);
1981
- right: auto;
1982
- --translate-: 0;
1983
- }
1977
+ left: var(--offset);
1978
+ right: auto;
1979
+ --translate-x: 0;
1984
1980
  }
1985
1981
  }
1986
1982
 
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>
@@ -435,8 +444,9 @@
435
444
  </fig-tooltip>
436
445
  </fig-field>
437
446
 
438
- <fig-dialog open="true"
439
- position="bottom right">
447
+ <dialog open="true"
448
+ position="bottom right"
449
+ is="fig-dialog">
440
450
  <fig-header>
441
451
  <h3>Dialog</h3>
442
452
  <fig-button variant="ghost"
@@ -458,13 +468,25 @@
458
468
  </fig-header>
459
469
  <fig-content>
460
470
  <p>Some content here</p>
471
+ <fig-field direction="horizontal">
472
+ <label for="colorLevels">Color Levels</label>
473
+ <fig-slider id="colorLevels"
474
+ min="2"
475
+ max="16"
476
+ value="4"
477
+ variant="minimal"
478
+ step="1"
479
+ text="true"
480
+ style="flex: 1; max-width: 200px;">
481
+ </fig-slider>
482
+ </fig-field>
461
483
  </fig-content>
462
484
  <footer>
463
485
  <fig-button variant="secondary"
464
486
  close-dialog>Cancel</fig-button>
465
487
  <fig-button>Save</fig-button>
466
488
  </footer>
467
- </fig-dialog>
489
+ </dialog>
468
490
  <fig-header>
469
491
  <h2>Dropdown</h2>
470
492
  </fig-header>
package/fig.js CHANGED
@@ -432,20 +432,10 @@ customElements.define("fig-popover", FigPopover);
432
432
  * @attr {boolean} open - Whether the dialog is visible
433
433
  * @attr {boolean} modal - Whether the dialog should be modal
434
434
  */
435
- class FigDialog extends HTMLElement {
436
- constructor() {
437
- super();
438
- this.attachShadow({ mode: "open" });
439
- this.dialog = document.createElement("dialog");
440
- this.contentSlot = document.createElement("slot");
441
- }
442
-
435
+ class FigDialog extends HTMLDialogElement {
443
436
  connectedCallback() {
444
437
  this.modal =
445
438
  this.hasAttribute("modal") && this.getAttribute("modal") !== "false";
446
- this.appendChild(this.dialog);
447
- this.shadowRoot.appendChild(this.contentSlot);
448
- this.contentSlot.addEventListener("slotchange", this.slotChange.bind(this));
449
439
 
450
440
  requestAnimationFrame(() => {
451
441
  this.#addCloseListeners();
@@ -453,61 +443,13 @@ class FigDialog extends HTMLElement {
453
443
  }
454
444
 
455
445
  #addCloseListeners() {
456
- this.dialog
457
- .querySelectorAll("fig-button[close-dialog]")
458
- .forEach((button) => {
459
- button.removeEventListener("click", this.close);
460
- button.addEventListener("click", this.close.bind(this));
461
- });
462
- }
463
-
464
- disconnectedCallback() {
465
- this.contentSlot.removeEventListener("slotchange", this.slotChange);
466
- }
467
-
468
- slotChange() {
469
- while (this.dialog.firstChild) {
470
- this.dialog.firstChild.remove();
471
- }
472
- this.contentSlot.assignedNodes().forEach((node) => {
473
- if (node !== this.dialog) {
474
- this.dialog.appendChild(node.cloneNode(true));
475
- }
446
+ this.querySelectorAll("fig-button[close-dialog]").forEach((button) => {
447
+ button.removeEventListener("click", this.close);
448
+ button.addEventListener("click", this.close.bind(this));
476
449
  });
477
- this.#addCloseListeners();
478
- }
479
-
480
- static get observedAttributes() {
481
- return ["open", "modal"];
482
- }
483
-
484
- attributeChangedCallback(name, oldValue, newValue) {
485
- switch (name) {
486
- case "open":
487
- this.open = newValue === "true" && newValue !== "false";
488
- if (this?.show) {
489
- this[this.open ? "show" : "close"]();
490
- }
491
- break;
492
- case "modal":
493
- this.modal = newValue === "true" && newValue !== "false";
494
- break;
495
- }
496
- }
497
-
498
- /* Public methods */
499
- show() {
500
- if (this.modal) {
501
- this.dialog.showModal();
502
- } else {
503
- this.dialog.show();
504
- }
505
- }
506
- close() {
507
- this.dialog.close();
508
450
  }
509
451
  }
510
- customElements.define("fig-dialog", FigDialog);
452
+ customElements.define("fig-dialog", FigDialog, { extends: "dialog" });
511
453
 
512
454
  class FigPopover2 extends HTMLElement {
513
455
  #popover;
@@ -1863,6 +1805,12 @@ class FigImage extends HTMLElement {
1863
1805
  this.innerHTML = this.#getInnerHTML();
1864
1806
  this.#updateRefs();
1865
1807
  }
1808
+ disconnectedCallback() {
1809
+ this.fileInput.removeEventListener(
1810
+ "change",
1811
+ this.#handleFileInput.bind(this)
1812
+ );
1813
+ }
1866
1814
 
1867
1815
  #updateRefs() {
1868
1816
  requestAnimationFrame(() => {
@@ -1873,12 +1821,47 @@ class FigImage extends HTMLElement {
1873
1821
 
1874
1822
  this.fileInput.addEventListener(
1875
1823
  "change",
1876
- this.handleFileInput.bind(this)
1824
+ this.#handleFileInput.bind(this)
1877
1825
  );
1878
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;
1879
1862
  });
1880
1863
  }
1881
- async handleFileInput(e) {
1864
+ async #handleFileInput(e) {
1882
1865
  this.blob = URL.createObjectURL(e.target.files[0]);
1883
1866
  //set base64 url
1884
1867
  const reader = new FileReader();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rogieking/figui3",
3
- "version": "1.6.4",
3
+ "version": "1.6.6",
4
4
  "module": "index.ts",
5
5
  "type": "module",
6
6
  "devDependencies": {