inline-style-editor 1.3.1 → 1.3.3

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,23 +1984,66 @@ class ColorPicker extends SvelteComponent {
1984
1984
 
1985
1985
  var ColorPicker$1 = ColorPicker;
1986
1986
 
1987
- const fontCheck = new Set([
1988
- // Windows 10
1989
- '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',
1990
- // macOS
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
- ].sort());
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
+ });
1993
2021
 
1994
- function getFonts() {
1995
- const availableFonts = new Set();
2022
+ const availableFonts = [];
1996
2023
 
1997
- for (const font of fontCheck.values()) {
1998
- if (document.fonts.check(`12px "${font}"`)) {
1999
- availableFonts.add(font);
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);
2000
2038
  }
2001
2039
  }
2040
+ return availableFonts.sort();
2002
2041
 
2003
- return [...listFonts(), ...availableFonts.values()]
2042
+ }
2043
+
2044
+ const availableFonts = getAvailableFonts();
2045
+ function getFonts() {
2046
+ return [...listFonts(), ...availableFonts]
2004
2047
  }
2005
2048
 
2006
2049
  function listFonts() {
@@ -2077,7 +2120,7 @@ function get_each_context_5(ctx, list, i) {
2077
2120
  return child_ctx;
2078
2121
  }
2079
2122
 
2080
- // (416:4) {#if targetsToSearch.length > 1}
2123
+ // (415:4) {#if targetsToSearch.length > 1}
2081
2124
  function create_if_block_9(ctx) {
2082
2125
  let div;
2083
2126
  let b;
@@ -2142,7 +2185,7 @@ function create_if_block_9(ctx) {
2142
2185
  };
2143
2186
  }
2144
2187
 
2145
- // (419:8) {#each targetsToSearch as [_, name], elemIndex}
2188
+ // (418:8) {#each targetsToSearch as [_, name], elemIndex}
2146
2189
  function create_each_block_5(ctx) {
2147
2190
  let span;
2148
2191
  let t0_value = /*name*/ ctx[82] + "";
@@ -2188,7 +2231,7 @@ function create_each_block_5(ctx) {
2188
2231
  };
2189
2232
  }
2190
2233
 
2191
- // (428:8) {#each getRuleNames(allRules[selectedElemIndex]) as ruleName, ruleIndex}
2234
+ // (427:8) {#each getRuleNames(allRules[selectedElemIndex]) as ruleName, ruleIndex}
2192
2235
  function create_each_block_4(ctx) {
2193
2236
  let span;
2194
2237
  let t_value = /*ruleName*/ ctx[78] + "";
@@ -2237,7 +2280,7 @@ function create_each_block_4(ctx) {
2237
2280
  };
2238
2281
  }
2239
2282
 
2240
- // (439:12) {#if type !== 'custom' || (currentRule === 'inline' && type === 'custom' && hasDisplayedCustom )}
2283
+ // (438:12) {#if type !== 'custom' || (currentRule === 'inline' && type === 'custom' && hasDisplayedCustom )}
2241
2284
  function create_if_block_8(ctx) {
2242
2285
  let span;
2243
2286
  let t0_value = /*type*/ ctx[75] + "";
@@ -2283,7 +2326,7 @@ function create_if_block_8(ctx) {
2283
2326
  };
2284
2327
  }
2285
2328
 
2286
- // (437:8) {#each allTypes[selectedElemIndex] || [] as type, typeIndex}
2329
+ // (436:8) {#each allTypes[selectedElemIndex] || [] as type, typeIndex}
2287
2330
  function create_each_block_3(ctx) {
2288
2331
  let if_block_anchor;
2289
2332
  let if_block = (/*type*/ ctx[75] !== 'custom' || /*currentRule*/ ctx[17] === 'inline' && /*type*/ ctx[75] === 'custom' && /*hasDisplayedCustom*/ ctx[16]) && create_if_block_8(ctx);
@@ -2318,7 +2361,7 @@ function create_each_block_3(ctx) {
2318
2361
  };
2319
2362
  }
2320
2363
 
2321
- // (444:4) {#if allTypes[selectedElemIndex]}
2364
+ // (443:4) {#if allTypes[selectedElemIndex]}
2322
2365
  function create_if_block(ctx) {
2323
2366
  let div;
2324
2367
  let t0;
@@ -2449,7 +2492,7 @@ function create_if_block(ctx) {
2449
2492
  };
2450
2493
  }
2451
2494
 
2452
- // (455:16) {:else}
2495
+ // (454:16) {:else}
2453
2496
  function create_else_block(ctx) {
2454
2497
  let span;
2455
2498
  let t_value = /*selectedName*/ ctx[66] + "";
@@ -2473,7 +2516,7 @@ function create_else_block(ctx) {
2473
2516
  };
2474
2517
  }
2475
2518
 
2476
- // (449:16) {#if choices.props.length > 1}
2519
+ // (448:16) {#if choices.props.length > 1}
2477
2520
  function create_if_block_7(ctx) {
2478
2521
  let div;
2479
2522
  let select;
@@ -2547,7 +2590,7 @@ function create_if_block_7(ctx) {
2547
2590
  };
2548
2591
  }
2549
2592
 
2550
- // (451:24) {#each choices.props as propName, i}
2593
+ // (450:24) {#each choices.props as propName, i}
2551
2594
  function create_each_block_2(ctx) {
2552
2595
  let option;
2553
2596
  let t0_value = /*propName*/ ctx[72] + "";
@@ -2582,7 +2625,7 @@ function create_each_block_2(ctx) {
2582
2625
  };
2583
2626
  }
2584
2627
 
2585
- // (478:50)
2628
+ // (477:50)
2586
2629
  function create_if_block_6(ctx) {
2587
2630
  let colorpicker;
2588
2631
  let current;
@@ -2628,7 +2671,7 @@ function create_if_block_6(ctx) {
2628
2671
  };
2629
2672
  }
2630
2673
 
2631
- // (468:51)
2674
+ // (467:51)
2632
2675
  function create_if_block_4(ctx) {
2633
2676
  let select;
2634
2677
  let show_if = !/*choices*/ ctx[65].includes(/*allCurrentPropDefs*/ ctx[14][/*selectedName*/ ctx[66]].value);
@@ -2721,7 +2764,7 @@ function create_if_block_4(ctx) {
2721
2764
  };
2722
2765
  }
2723
2766
 
2724
- // (459:16) {#if choices.type === 'slider'}
2767
+ // (458:16) {#if choices.type === 'slider'}
2725
2768
  function create_if_block_3(ctx) {
2726
2769
  let input;
2727
2770
  let input_min_value;
@@ -2796,7 +2839,7 @@ function create_if_block_3(ctx) {
2796
2839
  };
2797
2840
  }
2798
2841
 
2799
- // (471:24) {#if !choices.includes(allCurrentPropDefs[selectedName].value)}
2842
+ // (470:24) {#if !choices.includes(allCurrentPropDefs[selectedName].value)}
2800
2843
  function create_if_block_5(ctx) {
2801
2844
  let option;
2802
2845
 
@@ -2817,7 +2860,7 @@ function create_if_block_5(ctx) {
2817
2860
  };
2818
2861
  }
2819
2862
 
2820
- // (474:24) {#each choices as choice}
2863
+ // (473:24) {#each choices as choice}
2821
2864
  function create_each_block_1(ctx) {
2822
2865
  let option;
2823
2866
  let t_value = /*choice*/ ctx[69] + "";
@@ -2855,7 +2898,7 @@ function create_each_block_1(ctx) {
2855
2898
  };
2856
2899
  }
2857
2900
 
2858
- // (446:8) {#each propsByType as choices}
2901
+ // (445:8) {#each propsByType as choices}
2859
2902
  function create_each_block(ctx) {
2860
2903
  let div;
2861
2904
  let t0;
@@ -3001,7 +3044,7 @@ function create_each_block(ctx) {
3001
3044
  };
3002
3045
  }
3003
3046
 
3004
- // (486:8) {#if currentRule === 'inline' && bringableToFront[selectedElemIndex] !== null}
3047
+ // (485:8) {#if currentRule === 'inline' && bringableToFront[selectedElemIndex] !== null}
3005
3048
  function create_if_block_2(ctx) {
3006
3049
  let div;
3007
3050
  let mounted;
@@ -3035,7 +3078,7 @@ function create_if_block_2(ctx) {
3035
3078
  };
3036
3079
  }
3037
3080
 
3038
- // (491:8) {#if currentRule === 'inline' && inlineDeletable(currentElement)}
3081
+ // (490:8) {#if currentRule === 'inline' && inlineDeletable(currentElement)}
3039
3082
  function create_if_block_1(ctx) {
3040
3083
  let div;
3041
3084
  let mounted;
@@ -3615,7 +3658,7 @@ function instance($$self, $$props, $$invalidate) {
3615
3658
  }
3616
3659
  } catch(err) {
3617
3660
  if (!warningDisplayed.has(i)) {
3618
- console.log('Style editor: Not able to access', sheets[i].ownerNode, 'sheet. Try CORS loading the sheet if you want to edit it.');
3661
+ console.warn('Style editor: Not able to access', sheets[i].ownerNode, 'sheet. Try CORS loading the sheet if you want to edit it.');
3619
3662
  warningDisplayed.add(i);
3620
3663
  }
3621
3664
  }
@@ -3654,7 +3697,6 @@ function instance($$self, $$props, $$invalidate) {
3654
3697
  types.push(typeBackground);
3655
3698
  }
3656
3699
 
3657
- console.log(types);
3658
3700
  if (bringable) bringableToFront.push(true); else bringableToFront.push(null);
3659
3701
  typesByElem.push(types);
3660
3702
  return typesByElem;