@zipify/wysiwyg 2.5.2 → 2.5.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.
@@ -1,14 +1,15 @@
1
1
  import { ref } from 'vue';
2
2
  import { getSchema } from '@tiptap/core';
3
3
  import { DOMParser } from 'prosemirror-model';
4
- import { JSDOM } from 'jsdom';
5
4
  import { buildExtensions } from '../extensions';
6
5
  import { Devices } from '../enums';
7
- import { ContentNormalizer } from '../services';
6
+ import { ContentNormalizer, ContextWindow } from '../services';
8
7
  import { NodeDomParser } from './NodeDomParser';
9
8
 
10
9
  export class ContentSerializer {
11
10
  static build(options) {
11
+ ContextWindow.use(NodeDomParser.createWindow());
12
+
12
13
  const extensions = buildExtensions({
13
14
  fonts: options.fonts,
14
15
  minFontSize: 0,
@@ -21,7 +22,7 @@ export class ContentSerializer {
21
22
  baseListClass: options.baseListClass,
22
23
  deviceRef: ref(Devices.DESKTOP),
23
24
  pageBlocksRef: ref([]),
24
- wrapperRef: JSDOM.fragment('<p></p>').firstElementChild
25
+ wrapperRef: ContextWindow.document.createElement('p')
25
26
  });
26
27
  const schema = getSchema(extensions);
27
28
 
@@ -1,6 +1,10 @@
1
1
  import { JSDOM } from 'jsdom';
2
2
 
3
3
  export class NodeDomParser {
4
+ static createWindow() {
5
+ return new JSDOM().window;
6
+ }
7
+
4
8
  types;
5
9
 
6
10
  parse(html) {
@@ -36,7 +36,7 @@ export const LineHeight = Extension.create({
36
36
  const wrapperEl = unref(this.options.wrapperRef);
37
37
  const converted = convertLineHeight(value, element, wrapperEl);
38
38
 
39
- return { desktop: converted, tablet: converted, mobile: null };
39
+ return converted ? { desktop: converted, tablet: converted, mobile: null } : null;
40
40
  },
41
41
 
42
42
  renderHTML(attrs) {
@@ -1,7 +1,9 @@
1
+ import { ContextWindow } from '../services';
2
+
1
3
  export function convertFontSize(value, wrapperEl) {
2
4
  if (!value.includes('em')) return parseInt(value);
3
5
 
4
- const containerValue = window.getComputedStyle(wrapperEl).fontSize;
6
+ const containerValue = ContextWindow.getComputedStyle(wrapperEl).fontSize;
5
7
  const size = parseFloat(value) * parseFloat(containerValue);
6
8
 
7
9
  return Math.round(size);
@@ -1,10 +1,11 @@
1
+ import { ContextWindow } from '../services';
1
2
  import { convertFontSize } from './convertFontSize';
2
3
 
3
4
  function getFontSize(sourceEl, wrapperEl) {
4
5
  const source = sourceEl.firstElementChild || sourceEl;
5
6
  const fontSize = source.style.fontSize;
6
7
 
7
- return fontSize || window.getComputedStyle(wrapperEl).fontSize;
8
+ return fontSize || ContextWindow.getComputedStyle(wrapperEl).fontSize;
8
9
  }
9
10
 
10
11
  export function convertLineHeight(value, sourceEl, wrapperEl) {
@@ -13,5 +14,5 @@ export function convertLineHeight(value, sourceEl, wrapperEl) {
13
14
  const rawFontSize = getFontSize(sourceEl, wrapperEl);
14
15
  const fontSize = convertFontSize(rawFontSize, wrapperEl);
15
16
 
16
- return (parseInt(value) / fontSize).toFixed(2);
17
+ return fontSize ? (parseInt(value) / fontSize).toFixed(2) : null;
17
18
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zipify/wysiwyg",
3
- "version": "2.5.2",
3
+ "version": "2.5.3",
4
4
  "description": "Zipify modification of TipTap text editor",
5
5
  "main": "dist/wysiwyg.mjs",
6
6
  "bin": {