inline-style-editor 1.3.2 → 1.3.4

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.
@@ -1984,18 +1984,66 @@ class ColorPicker extends SvelteComponent {
1984
1984
 
1985
1985
  var ColorPicker$1 = ColorPicker;
1986
1986
 
1987
- const detector = new FontDetector();
1987
+ // https://stackoverflow.com/a/3368855
1988
+ function getAvailableFonts() {
1989
+ const fontsToCheck = new Set([
1990
+ 'Arial', 'Arial Black', 'Bahnschrift', 'Calibri', 'Cambria', 'Cambria Math', 'Candara', 'Comic Sans MS', 'Consolas', 'Constantia', 'Corbel', 'Courier New', 'Ebrima', 'Franklin Gothic Medium', 'Gabriola', 'Gadugi', 'Georgia', 'HoloLens MDL2 Assets', 'Impact', 'Ink Free', 'Javanese Text', 'Leelawadee UI', 'Lucida Console', 'Lucida Sans Unicode', 'Malgun Gothic', 'Marlett', 'Microsoft Himalaya', 'Microsoft JhengHei', 'Microsoft New Tai Lue', 'Microsoft PhagsPa', 'Microsoft Sans Serif', 'Microsoft Tai Le', 'Microsoft YaHei', 'Microsoft Yi Baiti', 'MingLiU-ExtB', 'Mongolian Baiti', 'MS Gothic', 'MV Boli', 'Myanmar Text', 'Nirmala UI', 'Palatino Linotype', 'Segoe MDL2 Assets', 'Segoe Print', 'Segoe Script', 'Segoe UI', 'Segoe UI Historic', 'Segoe UI Emoji', 'Segoe UI Symbol', 'SimSun', 'Sitka', 'Sylfaen', 'Symbol', 'Tahoma', 'Times New Roman', 'Trebuchet MS', 'Verdana', 'Webdings', 'Wingdings', 'Yu Gothic',
1991
+ 'American Typewriter', 'Andale Mono', 'Arial', 'Arial Black', 'Arial Narrow', 'Arial Rounded MT Bold', 'Arial Unicode MS', 'Avenir', 'Avenir Next', 'Avenir Next Condensed', 'Baskerville', 'Big Caslon', 'Bodoni 72', 'Bodoni 72 Oldstyle', 'Bodoni 72 Smallcaps', 'Bradley Hand', 'Brush Script MT', 'Chalkboard', 'Chalkboard SE', 'Chalkduster', 'Charter', 'Cochin', 'Comic Sans MS', 'Copperplate', 'Courier', 'Courier New', 'Didot', 'DIN Alternate', 'DIN Condensed', 'Futura', 'Geneva', 'Georgia', 'Gill Sans', 'Helvetica', 'Helvetica Neue', 'Herculanum', 'Hoefler Text', 'Impact', 'Lucida Grande', 'Luminari', 'Marker Felt', 'Menlo', 'Microsoft Sans Serif', 'Monaco', 'Noteworthy', 'Optima', 'Palatino', 'Papyrus', 'Phosphate', 'Rockwell', 'Savoye LET', 'SignPainter', 'Skia', 'Snell Roundhand', 'Tahoma', 'Times', 'Times New Roman', 'Trattatello', 'Trebuchet MS', 'Verdana', 'Zapfino',
1992
+ 'Comic Sans MS', 'Comic Sans', 'Apple Chancery', 'Bradley Hand', 'Brush Script MT', 'Brush Script Std', 'Snell Roundhand', 'URW Chancery L'
1993
+ ].sort());
1994
+ const defaultWidth = {};
1995
+ const defaultHeight = {};
1996
+ // a font will be compared against all the three default fonts.
1997
+ // and if it doesn't match all 3 then that font is not available.
1998
+ const baseFonts = ['monospace', 'sans-serif', 'serif', 'cursive'];
1999
+
2000
+ // we use m or w because these two characters take up the maximum width.
2001
+ // And we use a LLi so that the same matching fonts can get separated
2002
+ const testString = "mmmmmmmmmmlli";
2003
+
2004
+ // we test using 72px font size, we may use any size. I guess larger the better.
2005
+ const testSize = '72px';
2006
+
2007
+ const container = document.getElementsByTagName("body")[0];
2008
+
2009
+ // create a SPAN in the document to get the width of the text we use to test
2010
+ const spanTester = document.createElement("span");
2011
+ spanTester.style.fontSize = testSize;
2012
+ spanTester.innerHTML = testString;
2013
+ baseFonts.forEach(font => {
2014
+ //get the default width for the three base fonts
2015
+ spanTester.style.fontFamily = font;
2016
+ container.appendChild(spanTester);
2017
+ defaultWidth[font] = spanTester.offsetWidth; // width for the default font
2018
+ defaultHeight[font] = spanTester.offsetHeight; // height for the default font
2019
+ container.removeChild(spanTester);
2020
+ });
1988
2021
 
1989
- function getFonts() {
1990
- // const availableFonts = new Set();
2022
+ const availableFonts = [];
2023
+
2024
+ const fontExists = (fontName) => {
2025
+ let detected = false;
2026
+ for (const font of baseFonts) {
2027
+ spanTester.style.fontFamily = fontName + ',' + font; // name of the font along with the base font for fallback.
2028
+ container.appendChild(spanTester);
2029
+ const matched = (spanTester.offsetWidth != defaultWidth[font] || spanTester.offsetHeight != defaultHeight[font]);
2030
+ container.removeChild(spanTester);
2031
+ detected = detected || matched;
2032
+ }
2033
+ return detected;
2034
+ };
2035
+ for (const font of fontsToCheck.values()) {
2036
+ if (fontExists(font)) {
2037
+ availableFonts.push(font);
2038
+ }
2039
+ }
2040
+ return availableFonts.sort();
1991
2041
 
1992
- // for (const font of fontCheck.values()) {
1993
- // if (document.fonts.check(`12px "${font}"`)) {
1994
- // availableFonts.add(font);
1995
- // }
1996
- // }
2042
+ }
1997
2043
 
1998
- return [...listFonts(), ...detector.availableFonts]
2044
+ const availableFonts = getAvailableFonts();
2045
+ function getFonts() {
2046
+ return [...listFonts(), ...availableFonts]
1999
2047
  }
2000
2048
 
2001
2049
  function listFonts() {
@@ -2018,72 +2066,6 @@ function listFonts() {
2018
2066
  return [...new Set(arr)];
2019
2067
  }
2020
2068
 
2021
- // https://stackoverflow.com/a/3368855
2022
- class FontDetector {
2023
- constructor() {
2024
- this.fontsToCheck = new Set([
2025
- 'Arial', 'Arial Black', 'Bahnschrift', 'Calibri', 'Cambria', 'Cambria Math', 'Candara', 'Comic Sans MS', 'Consolas', 'Constantia', 'Corbel', 'Courier New', 'Ebrima', 'Franklin Gothic Medium', 'Gabriola', 'Gadugi', 'Georgia', 'HoloLens MDL2 Assets', 'Impact', 'Ink Free', 'Javanese Text', 'Leelawadee UI', 'Lucida Console', 'Lucida Sans Unicode', 'Malgun Gothic', 'Marlett', 'Microsoft Himalaya', 'Microsoft JhengHei', 'Microsoft New Tai Lue', 'Microsoft PhagsPa', 'Microsoft Sans Serif', 'Microsoft Tai Le', 'Microsoft YaHei', 'Microsoft Yi Baiti', 'MingLiU-ExtB', 'Mongolian Baiti', 'MS Gothic', 'MV Boli', 'Myanmar Text', 'Nirmala UI', 'Palatino Linotype', 'Segoe MDL2 Assets', 'Segoe Print', 'Segoe Script', 'Segoe UI', 'Segoe UI Historic', 'Segoe UI Emoji', 'Segoe UI Symbol', 'SimSun', 'Sitka', 'Sylfaen', 'Symbol', 'Tahoma', 'Times New Roman', 'Trebuchet MS', 'Verdana', 'Webdings', 'Wingdings', 'Yu Gothic',
2026
- 'American Typewriter', 'Andale Mono', 'Arial', 'Arial Black', 'Arial Narrow', 'Arial Rounded MT Bold', 'Arial Unicode MS', 'Avenir', 'Avenir Next', 'Avenir Next Condensed', 'Baskerville', 'Big Caslon', 'Bodoni 72', 'Bodoni 72 Oldstyle', 'Bodoni 72 Smallcaps', 'Bradley Hand', 'Brush Script MT', 'Chalkboard', 'Chalkboard SE', 'Chalkduster', 'Charter', 'Cochin', 'Comic Sans MS', 'Copperplate', 'Courier', 'Courier New', 'Didot', 'DIN Alternate', 'DIN Condensed', 'Futura', 'Geneva', 'Georgia', 'Gill Sans', 'Helvetica', 'Helvetica Neue', 'Herculanum', 'Hoefler Text', 'Impact', 'Lucida Grande', 'Luminari', 'Marker Felt', 'Menlo', 'Microsoft Sans Serif', 'Monaco', 'Noteworthy', 'Optima', 'Palatino', 'Papyrus', 'Phosphate', 'Rockwell', 'Savoye LET', 'SignPainter', 'Skia', 'Snell Roundhand', 'Tahoma', 'Times', 'Times New Roman', 'Trattatello', 'Trebuchet MS', 'Verdana', 'Zapfino',
2027
- 'Comic Sans MS', 'Comic Sans', 'Apple Chancery', 'Bradley Hand', 'Brush Script MT', 'Brush Script Std', 'Snell Roundhand', 'URW Chancery L'
2028
- ].sort());
2029
- this.init();
2030
- }
2031
-
2032
- init() {
2033
- this.defaultWidth = {};
2034
- this.defaultHeight = {};
2035
- // a font will be compared against all the three default fonts.
2036
- // and if it doesn't match all 3 then that font is not available.
2037
- this.baseFonts = ['monospace', 'sans-serif', 'serif', 'cursive'];
2038
-
2039
- // we use m or w because these two characters take up the maximum width.
2040
- // And we use a LLi so that the same matching fonts can get separated
2041
- const testString = "mmmmmmmmmmlli";
2042
-
2043
- // we test using 72px font size, we may use any size. I guess larger the better.
2044
- const testSize = '72px';
2045
-
2046
- this.container = document.getElementsByTagName("body")[0];
2047
-
2048
- // create a SPAN in the document to get the width of the text we use to test
2049
- this.spanTester = document.createElement("span");
2050
- this.spanTester.style.fontSize = testSize;
2051
- this.spanTester.innerHTML = testString;
2052
- this.baseFonts.forEach(font => {
2053
- //get the default width for the three base fonts
2054
- this.spanTester.style.fontFamily = font;
2055
- this.container.appendChild(this.spanTester);
2056
- this.defaultWidth[font] = this.spanTester.offsetWidth; // width for the default font
2057
- this.defaultHeight[font] = this.spanTester.offsetHeight; // height for the default font
2058
- this.container.removeChild(this.spanTester);
2059
- });
2060
- this.detectFonts();
2061
- }
2062
-
2063
- fontExists(fontName) {
2064
- let detected = false;
2065
- for (const font of this.baseFonts) {
2066
- this.spanTester.style.fontFamily = fontName + ',' + font; // name of the font along with the base font for fallback.
2067
- this.container.appendChild(this.spanTester);
2068
- const matched = (this.spanTester.offsetWidth != this.defaultWidth[font] || this.spanTester.offsetHeight != this.defaultHeight[font]);
2069
- this.container.removeChild(this.spanTester);
2070
- detected = detected || matched;
2071
- }
2072
- return detected;
2073
- }
2074
-
2075
- detectFonts() {
2076
- this.availableFonts = [];
2077
- for (const font of this.fontsToCheck.values()) {
2078
- if (this.fontExists(font)) {
2079
- this.availableFonts.push(font);
2080
- }
2081
- }
2082
- this.availableFonts.sort();
2083
- }
2084
-
2085
- }
2086
-
2087
2069
  /* src/components/InlineStyleEditor.svelte generated by Svelte v3.49.0 */
2088
2070
 
2089
2071
  function get_each_context(ctx, list, i) {
@@ -2138,7 +2120,7 @@ function get_each_context_5(ctx, list, i) {
2138
2120
  return child_ctx;
2139
2121
  }
2140
2122
 
2141
- // (415:4) {#if targetsToSearch.length > 1}
2123
+ // (417:4) {#if targetsToSearch.length > 1}
2142
2124
  function create_if_block_9(ctx) {
2143
2125
  let div;
2144
2126
  let b;
@@ -2203,7 +2185,7 @@ function create_if_block_9(ctx) {
2203
2185
  };
2204
2186
  }
2205
2187
 
2206
- // (418:8) {#each targetsToSearch as [_, name], elemIndex}
2188
+ // (420:8) {#each targetsToSearch as [_, name], elemIndex}
2207
2189
  function create_each_block_5(ctx) {
2208
2190
  let span;
2209
2191
  let t0_value = /*name*/ ctx[82] + "";
@@ -2249,7 +2231,7 @@ function create_each_block_5(ctx) {
2249
2231
  };
2250
2232
  }
2251
2233
 
2252
- // (427:8) {#each getRuleNames(allRules[selectedElemIndex]) as ruleName, ruleIndex}
2234
+ // (429:8) {#each getRuleNames(allRules[selectedElemIndex]) as ruleName, ruleIndex}
2253
2235
  function create_each_block_4(ctx) {
2254
2236
  let span;
2255
2237
  let t_value = /*ruleName*/ ctx[78] + "";
@@ -2298,7 +2280,7 @@ function create_each_block_4(ctx) {
2298
2280
  };
2299
2281
  }
2300
2282
 
2301
- // (438:12) {#if type !== 'custom' || (currentRule === 'inline' && type === 'custom' && hasDisplayedCustom )}
2283
+ // (440:12) {#if type !== 'custom' || (currentRule === 'inline' && type === 'custom' && hasDisplayedCustom )}
2302
2284
  function create_if_block_8(ctx) {
2303
2285
  let span;
2304
2286
  let t0_value = /*type*/ ctx[75] + "";
@@ -2344,7 +2326,7 @@ function create_if_block_8(ctx) {
2344
2326
  };
2345
2327
  }
2346
2328
 
2347
- // (436:8) {#each allTypes[selectedElemIndex] || [] as type, typeIndex}
2329
+ // (438:8) {#each allTypes[selectedElemIndex] || [] as type, typeIndex}
2348
2330
  function create_each_block_3(ctx) {
2349
2331
  let if_block_anchor;
2350
2332
  let if_block = (/*type*/ ctx[75] !== 'custom' || /*currentRule*/ ctx[17] === 'inline' && /*type*/ ctx[75] === 'custom' && /*hasDisplayedCustom*/ ctx[16]) && create_if_block_8(ctx);
@@ -2379,7 +2361,7 @@ function create_each_block_3(ctx) {
2379
2361
  };
2380
2362
  }
2381
2363
 
2382
- // (443:4) {#if allTypes[selectedElemIndex]}
2364
+ // (445:4) {#if allTypes[selectedElemIndex]}
2383
2365
  function create_if_block(ctx) {
2384
2366
  let div;
2385
2367
  let t0;
@@ -2510,7 +2492,7 @@ function create_if_block(ctx) {
2510
2492
  };
2511
2493
  }
2512
2494
 
2513
- // (454:16) {:else}
2495
+ // (456:16) {:else}
2514
2496
  function create_else_block(ctx) {
2515
2497
  let span;
2516
2498
  let t_value = /*selectedName*/ ctx[66] + "";
@@ -2534,7 +2516,7 @@ function create_else_block(ctx) {
2534
2516
  };
2535
2517
  }
2536
2518
 
2537
- // (448:16) {#if choices.props.length > 1}
2519
+ // (450:16) {#if choices.props.length > 1}
2538
2520
  function create_if_block_7(ctx) {
2539
2521
  let div;
2540
2522
  let select;
@@ -2608,7 +2590,7 @@ function create_if_block_7(ctx) {
2608
2590
  };
2609
2591
  }
2610
2592
 
2611
- // (450:24) {#each choices.props as propName, i}
2593
+ // (452:24) {#each choices.props as propName, i}
2612
2594
  function create_each_block_2(ctx) {
2613
2595
  let option;
2614
2596
  let t0_value = /*propName*/ ctx[72] + "";
@@ -2643,7 +2625,7 @@ function create_each_block_2(ctx) {
2643
2625
  };
2644
2626
  }
2645
2627
 
2646
- // (477:50)
2628
+ // (479:50)
2647
2629
  function create_if_block_6(ctx) {
2648
2630
  let colorpicker;
2649
2631
  let current;
@@ -2689,7 +2671,7 @@ function create_if_block_6(ctx) {
2689
2671
  };
2690
2672
  }
2691
2673
 
2692
- // (467:51)
2674
+ // (469:51)
2693
2675
  function create_if_block_4(ctx) {
2694
2676
  let select;
2695
2677
  let show_if = !/*choices*/ ctx[65].includes(/*allCurrentPropDefs*/ ctx[14][/*selectedName*/ ctx[66]].value);
@@ -2782,7 +2764,7 @@ function create_if_block_4(ctx) {
2782
2764
  };
2783
2765
  }
2784
2766
 
2785
- // (458:16) {#if choices.type === 'slider'}
2767
+ // (460:16) {#if choices.type === 'slider'}
2786
2768
  function create_if_block_3(ctx) {
2787
2769
  let input;
2788
2770
  let input_min_value;
@@ -2857,7 +2839,7 @@ function create_if_block_3(ctx) {
2857
2839
  };
2858
2840
  }
2859
2841
 
2860
- // (470:24) {#if !choices.includes(allCurrentPropDefs[selectedName].value)}
2842
+ // (472:24) {#if !choices.includes(allCurrentPropDefs[selectedName].value)}
2861
2843
  function create_if_block_5(ctx) {
2862
2844
  let option;
2863
2845
 
@@ -2878,7 +2860,7 @@ function create_if_block_5(ctx) {
2878
2860
  };
2879
2861
  }
2880
2862
 
2881
- // (473:24) {#each choices as choice}
2863
+ // (475:24) {#each choices as choice}
2882
2864
  function create_each_block_1(ctx) {
2883
2865
  let option;
2884
2866
  let t_value = /*choice*/ ctx[69] + "";
@@ -2916,7 +2898,7 @@ function create_each_block_1(ctx) {
2916
2898
  };
2917
2899
  }
2918
2900
 
2919
- // (445:8) {#each propsByType as choices}
2901
+ // (447:8) {#each propsByType as choices}
2920
2902
  function create_each_block(ctx) {
2921
2903
  let div;
2922
2904
  let t0;
@@ -3062,7 +3044,7 @@ function create_each_block(ctx) {
3062
3044
  };
3063
3045
  }
3064
3046
 
3065
- // (485:8) {#if currentRule === 'inline' && bringableToFront[selectedElemIndex] !== null}
3047
+ // (487:8) {#if currentRule === 'inline' && bringableToFront[selectedElemIndex] !== null}
3066
3048
  function create_if_block_2(ctx) {
3067
3049
  let div;
3068
3050
  let mounted;
@@ -3096,7 +3078,7 @@ function create_if_block_2(ctx) {
3096
3078
  };
3097
3079
  }
3098
3080
 
3099
- // (490:8) {#if currentRule === 'inline' && inlineDeletable(currentElement)}
3081
+ // (492:8) {#if currentRule === 'inline' && inlineDeletable(currentElement)}
3100
3082
  function create_if_block_1(ctx) {
3101
3083
  let div;
3102
3084
  let mounted;
@@ -3531,10 +3513,7 @@ function instance($$self, $$props, $$invalidate) {
3531
3513
  "background-color": { type: "color" }
3532
3514
  };
3533
3515
 
3534
- let { getAdditionalElems = () => {
3535
- return [];
3536
- } } = $$props;
3537
-
3516
+ let { getElems = null } = $$props;
3538
3517
  let { listenOnClick = false } = $$props;
3539
3518
 
3540
3519
  let { onStyleChanged = () => {
@@ -3740,7 +3719,8 @@ function instance($$self, $$props, $$invalidate) {
3740
3719
  $$invalidate(15, bringableToFront = []);
3741
3720
  $$invalidate(4, allTypes = []);
3742
3721
  $$invalidate(3, allRules = []);
3743
- $$invalidate(2, targetsToSearch = [[el, 'Clicked'], ...getAdditionalElems(el)]);
3722
+ console.log(getElems, getElems(el));
3723
+ if (getElems) $$invalidate(2, targetsToSearch = getElems(el)); else $$invalidate(2, targetsToSearch = [[el, 'Clicked']]);
3744
3724
  $$invalidate(4, allTypes = getEditableTypes(targetsToSearch));
3745
3725
  $$invalidate(16, hasDisplayedCustom = false);
3746
3726
  $$invalidate(3, allRules = getMatchedCSSRules(targetsToSearch));
@@ -3935,7 +3915,7 @@ function instance($$self, $$props, $$invalidate) {
3935
3915
  }
3936
3916
 
3937
3917
  $$self.$$set = $$props => {
3938
- if ('getAdditionalElems' in $$props) $$invalidate(25, getAdditionalElems = $$props.getAdditionalElems);
3918
+ if ('getElems' in $$props) $$invalidate(25, getElems = $$props.getElems);
3939
3919
  if ('listenOnClick' in $$props) $$invalidate(26, listenOnClick = $$props.listenOnClick);
3940
3920
  if ('onStyleChanged' in $$props) $$invalidate(27, onStyleChanged = $$props.onStyleChanged);
3941
3921
  if ('customProps' in $$props) $$invalidate(28, customProps = $$props.customProps);
@@ -4003,7 +3983,7 @@ function instance($$self, $$props, $$invalidate) {
4003
3983
  deleteElem,
4004
3984
  deleteProp,
4005
3985
  selectRule,
4006
- getAdditionalElems,
3986
+ getElems,
4007
3987
  listenOnClick,
4008
3988
  onStyleChanged,
4009
3989
  customProps,
@@ -4037,7 +4017,7 @@ class InlineStyleEditor$1 extends SvelteComponent {
4037
4017
  create_fragment,
4038
4018
  safe_not_equal,
4039
4019
  {
4040
- getAdditionalElems: 25,
4020
+ getElems: 25,
4041
4021
  listenOnClick: 26,
4042
4022
  onStyleChanged: 27,
4043
4023
  customProps: 28,