@zipify/wysiwyg 1.0.0-dev.3 → 1.0.0-dev.30

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.
Files changed (151) hide show
  1. package/.eslintignore +1 -0
  2. package/.github/dependabot.yaml +1 -0
  3. package/.release-it.json +3 -1
  4. package/.stylelintignore +1 -0
  5. package/README.md +3 -1
  6. package/config/jest/setupTests.js +7 -1
  7. package/config/webpack/example.config.js +2 -0
  8. package/config/webpack/lib.config.js +47 -0
  9. package/config/webpack/loaders/style-loader.js +3 -1
  10. package/config/webpack/loaders/svg-loader.js +1 -1
  11. package/dist/wysiwyg.css +1118 -0
  12. package/dist/wysiwyg.js +43805 -0
  13. package/example/ExampleApp.vue +51 -32
  14. package/example/example.js +26 -0
  15. package/example/pageBlocks.js +31 -0
  16. package/example/presets.js +4 -2
  17. package/lib/Wysiwyg.vue +41 -21
  18. package/lib/assets/icons/alignment-center.svg +3 -0
  19. package/lib/assets/icons/alignment-justify.svg +3 -0
  20. package/lib/assets/icons/alignment-left.svg +3 -0
  21. package/lib/assets/icons/alignment-right.svg +3 -0
  22. package/lib/assets/icons/arrow.svg +3 -0
  23. package/lib/assets/icons/background-color.svg +3 -0
  24. package/lib/assets/icons/case-style.svg +3 -0
  25. package/lib/assets/icons/font-color.svg +5 -0
  26. package/lib/assets/icons/italic.svg +3 -0
  27. package/lib/assets/icons/line-height.svg +3 -0
  28. package/lib/assets/icons/link.svg +3 -0
  29. package/lib/assets/icons/list-circle.svg +3 -0
  30. package/lib/assets/icons/list-decimal.svg +3 -0
  31. package/lib/assets/icons/list-disc.svg +3 -0
  32. package/lib/assets/icons/list-latin.svg +3 -0
  33. package/lib/assets/icons/list-roman.svg +3 -0
  34. package/lib/assets/icons/list-square.svg +3 -0
  35. package/lib/assets/icons/remove-format.svg +3 -0
  36. package/lib/assets/icons/reset-styles.svg +3 -0
  37. package/lib/assets/icons/strike-through.svg +3 -0
  38. package/lib/assets/icons/superscript.svg +3 -0
  39. package/lib/assets/icons/underline.svg +3 -0
  40. package/lib/assets/icons/unlink.svg +3 -0
  41. package/lib/components/base/Button.vue +21 -1
  42. package/lib/components/base/Checkbox.vue +89 -0
  43. package/lib/components/base/FieldLabel.vue +2 -1
  44. package/lib/components/base/Icon.vue +18 -10
  45. package/lib/components/base/Modal.vue +0 -1
  46. package/lib/components/base/TextField.vue +106 -0
  47. package/lib/components/base/__tests__/Icon.test.js +6 -13
  48. package/lib/components/base/__tests__/TextField.test.js +57 -0
  49. package/lib/components/base/__tests__/__snapshots__/TextField.test.js.snap +9 -0
  50. package/lib/components/base/colorPicker/composables/usePickerHotkeys.js +2 -1
  51. package/lib/components/base/composables/index.js +1 -0
  52. package/lib/components/base/composables/useValidator.js +19 -0
  53. package/lib/components/base/dropdown/Dropdown.vue +15 -3
  54. package/lib/components/base/dropdown/DropdownActivator.vue +19 -3
  55. package/lib/components/base/index.js +3 -1
  56. package/lib/components/toolbar/Toolbar.vue +49 -9
  57. package/lib/components/toolbar/ToolbarFull.vue +10 -2
  58. package/lib/components/toolbar/__tests__/Toolbar.test.js +6 -0
  59. package/lib/components/toolbar/controls/FontSizeControl.vue +7 -0
  60. package/lib/components/toolbar/controls/ListControl.vue +1 -5
  61. package/lib/components/toolbar/controls/UnderlineControl.vue +2 -2
  62. package/lib/components/toolbar/controls/__tests__/UnderlineControl.test.js +4 -0
  63. package/lib/components/toolbar/controls/index.js +1 -0
  64. package/lib/components/toolbar/controls/link/LinkControl.vue +152 -0
  65. package/lib/components/toolbar/controls/link/LinkControlApply.vue +35 -0
  66. package/lib/components/toolbar/controls/link/LinkControlHeader.vue +67 -0
  67. package/lib/components/toolbar/controls/link/composables/index.js +1 -0
  68. package/lib/components/toolbar/controls/link/composables/useLink.js +61 -0
  69. package/lib/components/toolbar/controls/link/destination/LinkControlDestination.vue +103 -0
  70. package/lib/components/toolbar/controls/link/destination/LinkControlPageBlock.vue +54 -0
  71. package/lib/components/toolbar/controls/link/destination/LinkControlUrl.vue +52 -0
  72. package/lib/components/toolbar/controls/link/destination/index.js +1 -0
  73. package/lib/components/toolbar/controls/link/index.js +1 -0
  74. package/lib/composables/__tests__/useEditor.test.js +14 -5
  75. package/lib/composables/useEditor.js +13 -8
  76. package/lib/composables/useToolbar.js +14 -29
  77. package/lib/directives/outClick.js +20 -4
  78. package/lib/enums/LinkDestinations.js +4 -0
  79. package/lib/enums/LinkTargets.js +4 -0
  80. package/lib/enums/TextSettings.js +3 -1
  81. package/lib/enums/index.js +2 -0
  82. package/lib/extensions/Alignment.js +21 -3
  83. package/lib/extensions/BackgroundColor.js +16 -1
  84. package/lib/extensions/FontColor.js +16 -1
  85. package/lib/extensions/FontFamily.js +26 -2
  86. package/lib/extensions/FontSize.js +28 -3
  87. package/lib/extensions/FontStyle.js +23 -2
  88. package/lib/extensions/FontWeight.js +33 -1
  89. package/lib/extensions/LineHeight.js +29 -3
  90. package/lib/extensions/Link.js +101 -0
  91. package/lib/extensions/StylePreset.js +36 -6
  92. package/lib/extensions/TextDecoration.js +29 -3
  93. package/lib/extensions/__tests__/Alignment.test.js +30 -3
  94. package/lib/extensions/__tests__/BackgroundColor.test.js +38 -3
  95. package/lib/extensions/__tests__/CaseStyle.test.js +4 -3
  96. package/lib/extensions/__tests__/FontColor.test.js +38 -3
  97. package/lib/extensions/__tests__/FontFamily.test.js +59 -5
  98. package/lib/extensions/__tests__/FontSize.test.js +38 -3
  99. package/lib/extensions/__tests__/FontStyle.test.js +46 -3
  100. package/lib/extensions/__tests__/FontWeight.test.js +66 -3
  101. package/lib/extensions/__tests__/LineHeight.test.js +49 -3
  102. package/lib/extensions/__tests__/StylePreset.test.js +143 -4
  103. package/lib/extensions/__tests__/TextDecoration.test.js +87 -3
  104. package/lib/extensions/__tests__/__snapshots__/Alignment.test.js.snap +70 -2
  105. package/lib/extensions/__tests__/__snapshots__/BackgroundColor.test.js.snap +121 -1
  106. package/lib/extensions/__tests__/__snapshots__/FontColor.test.js.snap +109 -1
  107. package/lib/extensions/__tests__/__snapshots__/FontFamily.test.js.snap +179 -1
  108. package/lib/extensions/__tests__/__snapshots__/FontSize.test.js.snap +132 -2
  109. package/lib/extensions/__tests__/__snapshots__/FontStyle.test.js.snap +142 -1
  110. package/lib/extensions/__tests__/__snapshots__/FontWeight.test.js.snap +179 -1
  111. package/lib/extensions/__tests__/__snapshots__/LineHeight.test.js.snap +118 -2
  112. package/lib/extensions/__tests__/__snapshots__/StylePreset.test.js.snap +171 -2
  113. package/lib/extensions/__tests__/__snapshots__/TextDecoration.test.js.snap +300 -3
  114. package/lib/extensions/core/CopyPasteProcessor.js +10 -0
  115. package/lib/extensions/core/TextProcessor.js +10 -0
  116. package/lib/extensions/core/__tests__/NodeProcessor.test.js +4 -3
  117. package/lib/extensions/core/__tests__/SelectionProcessor.test.js +9 -6
  118. package/lib/extensions/core/__tests__/TextProcessor.test.js +139 -10
  119. package/lib/extensions/core/__tests__/__snapshots__/TextProcessor.test.js.snap +26 -0
  120. package/lib/extensions/core/index.js +11 -2
  121. package/lib/extensions/core/plugins/PastePlugin.js +48 -0
  122. package/lib/extensions/core/plugins/ProseMirrorPlugin.js +20 -0
  123. package/lib/extensions/core/plugins/index.js +1 -0
  124. package/lib/extensions/index.js +41 -33
  125. package/lib/extensions/list/List.js +34 -0
  126. package/lib/extensions/list/__tests__/List.test.js +115 -5
  127. package/lib/extensions/list/__tests__/__snapshots__/List.test.js.snap +481 -0
  128. package/lib/index.js +4 -1
  129. package/lib/injectionTokens.js +2 -1
  130. package/lib/services/ContentNormalizer.js +157 -0
  131. package/lib/services/ContextWidnow.js +23 -0
  132. package/lib/services/Storage.js +1 -13
  133. package/lib/services/__tests__/ContentNormalizer.test.js +74 -0
  134. package/lib/services/__tests__/FavoriteColors.test.js +20 -0
  135. package/lib/services/__tests__/JsonSerializer.test.js +23 -0
  136. package/lib/services/__tests__/Storage.test.js +79 -0
  137. package/lib/services/index.js +2 -0
  138. package/lib/styles/content.css +96 -9
  139. package/lib/styles/helpers/offsets.css +16 -0
  140. package/lib/styles/variables.css +6 -0
  141. package/lib/utils/__tests__/__snapshots__/renderInlineSetting.test.js.snap +4 -4
  142. package/lib/utils/__tests__/convertColor.test.js +19 -0
  143. package/lib/utils/__tests__/createKeyboardShortcut.test.js +25 -0
  144. package/lib/utils/__tests__/renderInlineSetting.test.js +26 -0
  145. package/lib/utils/convertColor.js +7 -0
  146. package/lib/utils/importIcon.js +12 -0
  147. package/lib/utils/index.js +2 -0
  148. package/lib/utils/renderInlineSetting.js +2 -2
  149. package/package.json +18 -14
  150. package/lib/assets/icons.svg +0 -69
  151. package/lib/composables/__tests__/useToolbar.test.js +0 -56
@@ -210,3 +210,484 @@ Object {
210
210
  "type": "doc",
211
211
  }
212
212
  `;
213
+
214
+ exports[`parsing html should parse circle type by class 1`] = `
215
+ Object {
216
+ "content": Array [
217
+ Object {
218
+ "attrs": Object {
219
+ "bullet": Object {
220
+ "type": "circle",
221
+ },
222
+ },
223
+ "content": Array [
224
+ Object {
225
+ "content": Array [
226
+ Object {
227
+ "attrs": Object {
228
+ "preset": Object {
229
+ "id": "regular-1",
230
+ },
231
+ },
232
+ "content": Array [
233
+ Object {
234
+ "text": "lorem ipsum",
235
+ "type": "text",
236
+ },
237
+ ],
238
+ "type": "paragraph",
239
+ },
240
+ ],
241
+ "type": "listItem",
242
+ },
243
+ ],
244
+ "type": "list",
245
+ },
246
+ ],
247
+ "type": "doc",
248
+ }
249
+ `;
250
+
251
+ exports[`parsing html should parse decimal as default 1`] = `
252
+ Object {
253
+ "content": Array [
254
+ Object {
255
+ "attrs": Object {
256
+ "bullet": Object {
257
+ "type": "decimal",
258
+ },
259
+ },
260
+ "content": Array [
261
+ Object {
262
+ "content": Array [
263
+ Object {
264
+ "attrs": Object {
265
+ "preset": Object {
266
+ "id": "regular-1",
267
+ },
268
+ },
269
+ "content": Array [
270
+ Object {
271
+ "text": "lorem ipsum",
272
+ "type": "text",
273
+ },
274
+ ],
275
+ "type": "paragraph",
276
+ },
277
+ ],
278
+ "type": "listItem",
279
+ },
280
+ ],
281
+ "type": "list",
282
+ },
283
+ ],
284
+ "type": "doc",
285
+ }
286
+ `;
287
+
288
+ exports[`parsing html should parse decimal type by attribute 1`] = `
289
+ Object {
290
+ "content": Array [
291
+ Object {
292
+ "attrs": Object {
293
+ "bullet": Object {
294
+ "type": "decimal",
295
+ },
296
+ },
297
+ "content": Array [
298
+ Object {
299
+ "content": Array [
300
+ Object {
301
+ "attrs": Object {
302
+ "preset": Object {
303
+ "id": "regular-1",
304
+ },
305
+ },
306
+ "content": Array [
307
+ Object {
308
+ "text": "lorem ipsum",
309
+ "type": "text",
310
+ },
311
+ ],
312
+ "type": "paragraph",
313
+ },
314
+ ],
315
+ "type": "listItem",
316
+ },
317
+ ],
318
+ "type": "list",
319
+ },
320
+ ],
321
+ "type": "doc",
322
+ }
323
+ `;
324
+
325
+ exports[`parsing html should parse decimal type by class 1`] = `
326
+ Object {
327
+ "content": Array [
328
+ Object {
329
+ "attrs": Object {
330
+ "bullet": Object {
331
+ "type": "decimal",
332
+ },
333
+ },
334
+ "content": Array [
335
+ Object {
336
+ "content": Array [
337
+ Object {
338
+ "attrs": Object {
339
+ "preset": Object {
340
+ "id": "regular-1",
341
+ },
342
+ },
343
+ "content": Array [
344
+ Object {
345
+ "text": "lorem ipsum",
346
+ "type": "text",
347
+ },
348
+ ],
349
+ "type": "paragraph",
350
+ },
351
+ ],
352
+ "type": "listItem",
353
+ },
354
+ ],
355
+ "type": "list",
356
+ },
357
+ ],
358
+ "type": "doc",
359
+ }
360
+ `;
361
+
362
+ exports[`parsing html should parse disc as default 1`] = `
363
+ Object {
364
+ "content": Array [
365
+ Object {
366
+ "attrs": Object {
367
+ "bullet": Object {
368
+ "type": "disc",
369
+ },
370
+ },
371
+ "content": Array [
372
+ Object {
373
+ "content": Array [
374
+ Object {
375
+ "attrs": Object {
376
+ "preset": Object {
377
+ "id": "regular-1",
378
+ },
379
+ },
380
+ "content": Array [
381
+ Object {
382
+ "text": "lorem ipsum",
383
+ "type": "text",
384
+ },
385
+ ],
386
+ "type": "paragraph",
387
+ },
388
+ ],
389
+ "type": "listItem",
390
+ },
391
+ ],
392
+ "type": "list",
393
+ },
394
+ ],
395
+ "type": "doc",
396
+ }
397
+ `;
398
+
399
+ exports[`parsing html should parse disc type by class 1`] = `
400
+ Object {
401
+ "content": Array [
402
+ Object {
403
+ "attrs": Object {
404
+ "bullet": Object {
405
+ "type": "disc",
406
+ },
407
+ },
408
+ "content": Array [
409
+ Object {
410
+ "content": Array [
411
+ Object {
412
+ "attrs": Object {
413
+ "preset": Object {
414
+ "id": "regular-1",
415
+ },
416
+ },
417
+ "content": Array [
418
+ Object {
419
+ "text": "lorem ipsum",
420
+ "type": "text",
421
+ },
422
+ ],
423
+ "type": "paragraph",
424
+ },
425
+ ],
426
+ "type": "listItem",
427
+ },
428
+ ],
429
+ "type": "list",
430
+ },
431
+ ],
432
+ "type": "doc",
433
+ }
434
+ `;
435
+
436
+ exports[`parsing html should parse latin type by class 1`] = `
437
+ Object {
438
+ "content": Array [
439
+ Object {
440
+ "attrs": Object {
441
+ "bullet": Object {
442
+ "type": "latin",
443
+ },
444
+ },
445
+ "content": Array [
446
+ Object {
447
+ "content": Array [
448
+ Object {
449
+ "attrs": Object {
450
+ "preset": Object {
451
+ "id": "regular-1",
452
+ },
453
+ },
454
+ "content": Array [
455
+ Object {
456
+ "text": "lorem ipsum",
457
+ "type": "text",
458
+ },
459
+ ],
460
+ "type": "paragraph",
461
+ },
462
+ ],
463
+ "type": "listItem",
464
+ },
465
+ ],
466
+ "type": "list",
467
+ },
468
+ ],
469
+ "type": "doc",
470
+ }
471
+ `;
472
+
473
+ exports[`parsing html should parse latin type by lower attribute 1`] = `
474
+ Object {
475
+ "content": Array [
476
+ Object {
477
+ "attrs": Object {
478
+ "bullet": Object {
479
+ "type": "latin",
480
+ },
481
+ },
482
+ "content": Array [
483
+ Object {
484
+ "content": Array [
485
+ Object {
486
+ "attrs": Object {
487
+ "preset": Object {
488
+ "id": "regular-1",
489
+ },
490
+ },
491
+ "content": Array [
492
+ Object {
493
+ "text": "lorem ipsum",
494
+ "type": "text",
495
+ },
496
+ ],
497
+ "type": "paragraph",
498
+ },
499
+ ],
500
+ "type": "listItem",
501
+ },
502
+ ],
503
+ "type": "list",
504
+ },
505
+ ],
506
+ "type": "doc",
507
+ }
508
+ `;
509
+
510
+ exports[`parsing html should parse latin type by upper attribute 1`] = `
511
+ Object {
512
+ "content": Array [
513
+ Object {
514
+ "attrs": Object {
515
+ "bullet": Object {
516
+ "type": "latin",
517
+ },
518
+ },
519
+ "content": Array [
520
+ Object {
521
+ "content": Array [
522
+ Object {
523
+ "attrs": Object {
524
+ "preset": Object {
525
+ "id": "regular-1",
526
+ },
527
+ },
528
+ "content": Array [
529
+ Object {
530
+ "text": "lorem ipsum",
531
+ "type": "text",
532
+ },
533
+ ],
534
+ "type": "paragraph",
535
+ },
536
+ ],
537
+ "type": "listItem",
538
+ },
539
+ ],
540
+ "type": "list",
541
+ },
542
+ ],
543
+ "type": "doc",
544
+ }
545
+ `;
546
+
547
+ exports[`parsing html should parse roman type by class 1`] = `
548
+ Object {
549
+ "content": Array [
550
+ Object {
551
+ "attrs": Object {
552
+ "bullet": Object {
553
+ "type": "roman",
554
+ },
555
+ },
556
+ "content": Array [
557
+ Object {
558
+ "content": Array [
559
+ Object {
560
+ "attrs": Object {
561
+ "preset": Object {
562
+ "id": "regular-1",
563
+ },
564
+ },
565
+ "content": Array [
566
+ Object {
567
+ "text": "lorem ipsum",
568
+ "type": "text",
569
+ },
570
+ ],
571
+ "type": "paragraph",
572
+ },
573
+ ],
574
+ "type": "listItem",
575
+ },
576
+ ],
577
+ "type": "list",
578
+ },
579
+ ],
580
+ "type": "doc",
581
+ }
582
+ `;
583
+
584
+ exports[`parsing html should parse roman type by lower attribute 1`] = `
585
+ Object {
586
+ "content": Array [
587
+ Object {
588
+ "attrs": Object {
589
+ "bullet": Object {
590
+ "type": "roman",
591
+ },
592
+ },
593
+ "content": Array [
594
+ Object {
595
+ "content": Array [
596
+ Object {
597
+ "attrs": Object {
598
+ "preset": Object {
599
+ "id": "regular-1",
600
+ },
601
+ },
602
+ "content": Array [
603
+ Object {
604
+ "text": "lorem ipsum",
605
+ "type": "text",
606
+ },
607
+ ],
608
+ "type": "paragraph",
609
+ },
610
+ ],
611
+ "type": "listItem",
612
+ },
613
+ ],
614
+ "type": "list",
615
+ },
616
+ ],
617
+ "type": "doc",
618
+ }
619
+ `;
620
+
621
+ exports[`parsing html should parse roman type by upper attribute 1`] = `
622
+ Object {
623
+ "content": Array [
624
+ Object {
625
+ "attrs": Object {
626
+ "bullet": Object {
627
+ "type": "roman",
628
+ },
629
+ },
630
+ "content": Array [
631
+ Object {
632
+ "content": Array [
633
+ Object {
634
+ "attrs": Object {
635
+ "preset": Object {
636
+ "id": "regular-1",
637
+ },
638
+ },
639
+ "content": Array [
640
+ Object {
641
+ "text": "lorem ipsum",
642
+ "type": "text",
643
+ },
644
+ ],
645
+ "type": "paragraph",
646
+ },
647
+ ],
648
+ "type": "listItem",
649
+ },
650
+ ],
651
+ "type": "list",
652
+ },
653
+ ],
654
+ "type": "doc",
655
+ }
656
+ `;
657
+
658
+ exports[`parsing html should parse square type by class 1`] = `
659
+ Object {
660
+ "content": Array [
661
+ Object {
662
+ "attrs": Object {
663
+ "bullet": Object {
664
+ "type": "square",
665
+ },
666
+ },
667
+ "content": Array [
668
+ Object {
669
+ "content": Array [
670
+ Object {
671
+ "attrs": Object {
672
+ "preset": Object {
673
+ "id": "regular-1",
674
+ },
675
+ },
676
+ "content": Array [
677
+ Object {
678
+ "text": "lorem ipsum",
679
+ "type": "text",
680
+ },
681
+ ],
682
+ "type": "paragraph",
683
+ },
684
+ ],
685
+ "type": "listItem",
686
+ },
687
+ ],
688
+ "type": "list",
689
+ },
690
+ ],
691
+ "type": "doc",
692
+ }
693
+ `;
package/lib/index.js CHANGED
@@ -1 +1,4 @@
1
- export { default as Wysiwyg } from './Wysiwyg';
1
+ import Wysiwyg from './Wysiwyg';
2
+
3
+ export default Wysiwyg;
4
+ export { Wysiwyg };
@@ -3,5 +3,6 @@ export const InjectionTokens = Object.freeze({
3
3
  FONT_SIZES: Symbol('fontSizes'),
4
4
  EDITOR: Symbol('editor'),
5
5
  LOCAL_STORAGE: Symbol('localStorage'),
6
- FAVORITE_COLORS: Symbol('favoriteColors')
6
+ FAVORITE_COLORS: Symbol('favoriteColors'),
7
+ PAGE_BLOCKS: Symbol('pageBlocks')
7
8
  });
@@ -0,0 +1,157 @@
1
+ import { ContextWindow } from './ContextWidnow';
2
+
3
+ export class ContentNormalizer {
4
+ static BLOCK_STYLES = ['text-align', 'line-height'];
5
+
6
+ static normalize(content) {
7
+ return new ContentNormalizer(content).normalize();
8
+ }
9
+
10
+ constructor(content) {
11
+ this._content = content;
12
+ this._dom = null;
13
+ }
14
+
15
+ normalize() {
16
+ if (typeof this._content !== 'string') {
17
+ return this._content;
18
+ }
19
+ return this._normalizeTextContent();
20
+ }
21
+
22
+ _normalizeTextContent() {
23
+ this._dom = new DOMParser().parseFromString(this._content, 'text/html');
24
+
25
+ this._iterateNodes(this._normalizeListItems.bind(this), (node) => node.tagName === 'LI');
26
+ this._iterateNodes(this._normalizeSettingsStructure.bind(this), (node) => node.tagName === 'SPAN');
27
+ this._iterateNodes(this._normalizeStyles.bind(this), (node) => node.tagName !== 'SPAN');
28
+
29
+ return this._dom.body.innerHTML;
30
+ }
31
+
32
+ _iterateNodes(handler, condition) {
33
+ const iterator = this._dom.createNodeIterator(this._dom.body, NodeFilter.SHOW_ELEMENT, {
34
+ acceptNode: (node) => condition(node) ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_REJECT
35
+ });
36
+ let currentNode = iterator.nextNode();
37
+
38
+ while (currentNode) {
39
+ handler(currentNode);
40
+ currentNode = iterator.nextNode();
41
+ }
42
+ }
43
+
44
+ _normalizeListItems(itemEl) {
45
+ const fragment = new DocumentFragment();
46
+ const children = Array.from(itemEl.childNodes);
47
+ let capturingParagraph;
48
+
49
+ const append = (node) => {
50
+ this._assignElementProperties(node, itemEl, ContentNormalizer.BLOCK_STYLES);
51
+ fragment.append(node);
52
+ };
53
+
54
+ for (const node of children) {
55
+ if (node.tagName === 'P') {
56
+ append(node);
57
+ capturingParagraph = null;
58
+ continue;
59
+ }
60
+
61
+ if (!capturingParagraph) {
62
+ capturingParagraph = document.createElement('p');
63
+ append(capturingParagraph);
64
+ }
65
+
66
+ capturingParagraph.append(node);
67
+ }
68
+
69
+ itemEl.append(fragment);
70
+ this._removeStyleProperties(itemEl, ContentNormalizer.BLOCK_STYLES);
71
+ }
72
+
73
+ _normalizeSettingsStructure(element) {
74
+ const isTextChildren = Array.from(element.childNodes)
75
+ .every((node) => node.nodeType === Node.TEXT_NODE);
76
+
77
+ if (isTextChildren) return;
78
+
79
+ const cloned = element.cloneNode(true);
80
+ const migratingStyles = this._getMigratingStyles(element, { customProperties: true });
81
+ const content = [];
82
+
83
+ for (const node of cloned.childNodes) {
84
+ let child = node;
85
+
86
+ if (migratingStyles.length) {
87
+ child = this._wrapTextNode(cloned, node);
88
+ this._assignElementProperties(child, cloned, migratingStyles);
89
+ }
90
+
91
+ content.push(child);
92
+ }
93
+
94
+ element.replaceWith(...content);
95
+ }
96
+
97
+ _normalizeStyles(element) {
98
+ const properties = this._getMigratingStyles(element);
99
+
100
+ for (const node of element.childNodes) {
101
+ const child = this._wrapTextNode(element, node);
102
+
103
+ this._assignElementProperties(child, element, properties);
104
+ }
105
+
106
+ this._removeStyleProperties(element, properties);
107
+ }
108
+
109
+ _getMigratingStyles(element, { customProperties } = {}) {
110
+ const blacklist = ContentNormalizer.BLOCK_STYLES;
111
+ const properties = [];
112
+
113
+ for (let index = 0; index < element.style.length; index++) {
114
+ const property = element.style.item(index);
115
+
116
+ if (blacklist.includes(property)) continue;
117
+ if (!customProperties && property.startsWith('--')) continue;
118
+
119
+ properties.push(property);
120
+ }
121
+
122
+ return properties;
123
+ }
124
+
125
+ _wrapTextNode(parent, node) {
126
+ if (node.nodeType !== Node.TEXT_NODE) return node;
127
+
128
+ const span = ContextWindow.document.createElement('span');
129
+
130
+ span.append(node.cloneNode());
131
+ parent.replaceChild(span, node);
132
+
133
+ return span;
134
+ }
135
+
136
+ _assignElementProperties(target, source, properties) {
137
+ for (const property of properties) {
138
+ if (target.style.getPropertyValue(property)) {
139
+ continue;
140
+ }
141
+
142
+ const value = source.style.getPropertyValue(property);
143
+
144
+ if (value) target.style.setProperty(property, value);
145
+ }
146
+ }
147
+
148
+ _removeStyleProperties(element, properties) {
149
+ for (const property of properties) {
150
+ element.style.removeProperty(property);
151
+ }
152
+
153
+ if (element.style.length === 0) {
154
+ element.removeAttribute('style');
155
+ }
156
+ }
157
+ }
@@ -0,0 +1,23 @@
1
+ export class ContextWindow {
2
+ static window = window;
3
+
4
+ static use(window) {
5
+ this.window = window;
6
+ }
7
+
8
+ static get document() {
9
+ return this.window.document;
10
+ }
11
+
12
+ static get body() {
13
+ return this.document.body;
14
+ }
15
+
16
+ static get head() {
17
+ return this.document.head;
18
+ }
19
+
20
+ static getComputedStyle(element) {
21
+ return this.window.getComputedStyle(element);
22
+ }
23
+ }
@@ -17,19 +17,11 @@ export class Storage {
17
17
  }
18
18
 
19
19
  getItem(key) {
20
- const json = this._getItemFromStorage(key);
20
+ const json = this.accessToStorage((storage) => storage.getItem(this.makeKey(key)));
21
21
 
22
22
  return JsonSerializer.decode(json);
23
23
  }
24
24
 
25
- removeItem(key) {
26
- this.accessToStorage((storage) => storage.removeItem(this.makeKey(key)));
27
- }
28
-
29
- hasItem(key) {
30
- return !!this._getItemFromStorage(key);
31
- }
32
-
33
25
  accessToStorage(action) {
34
26
  try {
35
27
  return action(this.nativeStorage);
@@ -38,10 +30,6 @@ export class Storage {
38
30
  }
39
31
  }
40
32
 
41
- _getItemFromStorage(key) {
42
- return this.accessToStorage((storage) => storage.getItem(this.makeKey(key)));
43
- }
44
-
45
33
  onPrivateModeEnabled(error) {
46
34
  // eslint-disable-next-line no-console
47
35
  console.error(error);