@pallasoft/ps-utilities 2.22.0 → 2.23.0

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 (80) hide show
  1. package/dist/common/constants/html-entity-names.d.ts +1 -0
  2. package/dist/common/constants/html-entity-names.js +34 -0
  3. package/dist/common/constants/html-heading-styles.d.ts +1 -0
  4. package/dist/common/constants/html-heading-styles.js +11 -0
  5. package/dist/common/constants/html-text-config.d.ts +76 -0
  6. package/dist/common/constants/html-text-config.js +136 -0
  7. package/dist/common/constants/html-token-kind.d.ts +5 -0
  8. package/dist/common/constants/html-token-kind.js +8 -0
  9. package/dist/common/constants/portable-text-config.d.ts +16 -0
  10. package/dist/common/constants/portable-text-config.js +15 -1
  11. package/dist/common/html-entity-service.d.ts +6 -0
  12. package/dist/common/html-entity-service.js +34 -0
  13. package/dist/common/html-style-service.d.ts +12 -0
  14. package/dist/common/html-style-service.js +92 -0
  15. package/dist/common/html-token-service.d.ts +8 -0
  16. package/dist/common/html-token-service.js +90 -0
  17. package/dist/common/index.d.ts +1 -0
  18. package/dist/common/index.js +1 -0
  19. package/dist/common/portable-text-html-service.d.ts +28 -0
  20. package/dist/common/portable-text-html-service.js +392 -0
  21. package/dist/common/portable-text-link-service.d.ts +7 -0
  22. package/dist/common/portable-text-link-service.js +42 -0
  23. package/dist/common/portable-text-service.d.ts +7 -4
  24. package/dist/common/portable-text-service.js +15 -10
  25. package/dist/common/portable-text-tracking-service.d.ts +7 -0
  26. package/dist/common/portable-text-tracking-service.js +45 -0
  27. package/dist/esm/common/constants/html-entity-names.js +31 -0
  28. package/dist/esm/common/constants/html-heading-styles.js +8 -0
  29. package/dist/esm/common/constants/html-text-config.js +133 -0
  30. package/dist/esm/common/constants/html-token-kind.js +5 -0
  31. package/dist/esm/common/constants/portable-text-config.js +15 -1
  32. package/dist/esm/common/html-entity-service.js +25 -0
  33. package/dist/esm/common/html-style-service.js +85 -0
  34. package/dist/esm/common/html-token-service.js +83 -0
  35. package/dist/esm/common/index.js +1 -0
  36. package/dist/esm/common/portable-text-html-service.js +375 -0
  37. package/dist/esm/common/portable-text-link-service.js +35 -0
  38. package/dist/esm/common/portable-text-service.js +14 -9
  39. package/dist/esm/common/portable-text-tracking-service.js +34 -0
  40. package/dist/esm/models/html-attributes-data.js +1 -0
  41. package/dist/esm/models/html-close-token-data.js +1 -0
  42. package/dist/esm/models/html-context-data.js +1 -0
  43. package/dist/esm/models/html-conversion-data.js +1 -0
  44. package/dist/esm/models/html-declarations-data.js +1 -0
  45. package/dist/esm/models/html-frame-data.js +1 -0
  46. package/dist/esm/models/html-open-token-data.js +1 -0
  47. package/dist/esm/models/html-run-data.js +1 -0
  48. package/dist/esm/models/html-text-token-data.js +1 -0
  49. package/dist/esm/models/html-token-data.js +1 -0
  50. package/dist/esm/models/portable-text-block-link.js +1 -0
  51. package/dist/esm/models/portable-text-content-data.js +1 -0
  52. package/dist/esm/models/portable-text-image-data.js +1 -0
  53. package/dist/index.d.ts +3 -0
  54. package/dist/models/html-attributes-data.d.ts +1 -0
  55. package/dist/models/html-attributes-data.js +2 -0
  56. package/dist/models/html-close-token-data.d.ts +5 -0
  57. package/dist/models/html-close-token-data.js +2 -0
  58. package/dist/models/html-context-data.d.ts +6 -0
  59. package/dist/models/html-context-data.js +2 -0
  60. package/dist/models/html-conversion-data.d.ts +12 -0
  61. package/dist/models/html-conversion-data.js +2 -0
  62. package/dist/models/html-declarations-data.d.ts +1 -0
  63. package/dist/models/html-declarations-data.js +2 -0
  64. package/dist/models/html-frame-data.d.ts +13 -0
  65. package/dist/models/html-frame-data.js +2 -0
  66. package/dist/models/html-open-token-data.d.ts +8 -0
  67. package/dist/models/html-open-token-data.js +2 -0
  68. package/dist/models/html-run-data.d.ts +9 -0
  69. package/dist/models/html-run-data.js +2 -0
  70. package/dist/models/html-text-token-data.d.ts +5 -0
  71. package/dist/models/html-text-token-data.js +2 -0
  72. package/dist/models/html-token-data.d.ts +4 -0
  73. package/dist/models/html-token-data.js +2 -0
  74. package/dist/models/portable-text-block-link.d.ts +7 -0
  75. package/dist/models/portable-text-block-link.js +2 -0
  76. package/dist/models/portable-text-content-data.d.ts +3 -0
  77. package/dist/models/portable-text-content-data.js +2 -0
  78. package/dist/models/portable-text-image-data.d.ts +7 -0
  79. package/dist/models/portable-text-image-data.js +2 -0
  80. package/package.json +2 -2
@@ -0,0 +1 @@
1
+ export declare const HtmlEntityNames: Record<string, string>;
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.HtmlEntityNames = void 0;
4
+ exports.HtmlEntityNames = {
5
+ amp: '&',
6
+ lt: '<',
7
+ gt: '>',
8
+ quot: '"',
9
+ apos: "'",
10
+ nbsp: ' ',
11
+ ndash: '\u2013',
12
+ mdash: '\u2014',
13
+ hellip: '\u2026',
14
+ rsquo: '\u2019',
15
+ lsquo: '\u2018',
16
+ rdquo: '\u201D',
17
+ ldquo: '\u201C',
18
+ copy: '\u00A9',
19
+ reg: '\u00AE',
20
+ trade: '\u2122',
21
+ bull: '\u2022',
22
+ middot: '\u00B7',
23
+ euro: '\u20AC',
24
+ pound: '\u00A3',
25
+ yen: '\u00A5',
26
+ cent: '\u00A2',
27
+ laquo: '\u00AB',
28
+ raquo: '\u00BB',
29
+ times: '\u00D7',
30
+ deg: '\u00B0',
31
+ zwnj: '',
32
+ zwj: '',
33
+ shy: '',
34
+ };
@@ -0,0 +1 @@
1
+ export declare const HtmlHeadingStyles: Record<string, string>;
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.HtmlHeadingStyles = void 0;
4
+ exports.HtmlHeadingStyles = {
5
+ h1: 'h1',
6
+ h2: 'h2',
7
+ h3: 'h3',
8
+ h4: 'h3',
9
+ h5: 'h3',
10
+ h6: 'h3',
11
+ };
@@ -0,0 +1,76 @@
1
+ export declare const HtmlTextConfig: {
2
+ readonly skipTags: readonly ["head", "script", "style", "title", "noscript", "template", "svg", "iframe", "object", "embed", "video", "audio", "canvas", "select", "textarea"];
3
+ readonly rawTextTags: readonly ["script", "style", "title", "textarea"];
4
+ readonly voidTags: readonly ["area", "base", "br", "col", "embed", "hr", "img", "input", "link", "meta", "param", "source", "track", "wbr"];
5
+ readonly blockTags: readonly ["address", "article", "aside", "body", "center", "dd", "details", "div", "dl", "dt", "fieldset", "figcaption", "figure", "footer", "form", "header", "html", "main", "nav", "p", "pre", "section", "summary", "table", "tbody", "td", "tfoot", "th", "thead", "tr"];
6
+ readonly strongTags: readonly ["b", "strong"];
7
+ readonly emTags: readonly ["i", "em", "cite", "dfn"];
8
+ readonly underlineTags: readonly ["u", "ins"];
9
+ readonly codeTags: readonly ["code", "kbd", "samp", "tt"];
10
+ readonly linkTag: "a";
11
+ readonly imageTag: "img";
12
+ readonly breakTag: "br";
13
+ readonly ruleTag: "hr";
14
+ readonly preTag: "pre";
15
+ readonly quoteTag: "blockquote";
16
+ readonly listItemTag: "li";
17
+ readonly orderedListTag: "ol";
18
+ readonly unorderedListTag: "ul";
19
+ readonly hiddenClassPattern: RegExp;
20
+ readonly hiddenDisplay: "none";
21
+ readonly hiddenVisibility: "hidden";
22
+ readonly hiddenMso: "all";
23
+ readonly hiddenAttribute: "hidden";
24
+ readonly hiddenAria: "true";
25
+ readonly tinyImageSize: 2;
26
+ readonly importantPattern: RegExp;
27
+ readonly zeroPattern: RegExp;
28
+ readonly pixelPattern: RegExp;
29
+ readonly boldWeight: 600;
30
+ readonly largeText: {
31
+ readonly heading3: 20;
32
+ readonly heading2: 24;
33
+ readonly heading1: 30;
34
+ readonly maxLength: 100;
35
+ };
36
+ readonly boldHeadingMaxLength: 80;
37
+ readonly headingEndPattern: RegExp;
38
+ readonly pixelsPerPoint: 1.333;
39
+ readonly pixelsPerEm: 16;
40
+ readonly fontSizePattern: RegExp;
41
+ readonly commentStart: "<!--";
42
+ readonly commentEnd: "-->";
43
+ readonly declarationSeparator: ";";
44
+ readonly propertySeparator: ":";
45
+ readonly tagSource: "<(\\/?)([a-zA-Z][a-zA-Z0-9:-]*)((?:\"[^\"]*\"|'[^']*'|[^'\">])*)>";
46
+ readonly tagFlags: "y";
47
+ readonly attributePattern: RegExp;
48
+ readonly selfClosingPattern: RegExp;
49
+ readonly whitespacePattern: RegExp;
50
+ readonly preLineBreakPattern: RegExp;
51
+ readonly invisiblePattern: RegExp;
52
+ readonly entityPattern: RegExp;
53
+ readonly maxCodePoint: 1114111;
54
+ readonly numericEntityPrefix: "#";
55
+ readonly hexEntityPrefix: "#x";
56
+ readonly rootName: "root";
57
+ readonly bodyListLevel: 1;
58
+ readonly trailingBreakPattern: RegExp;
59
+ readonly leadingBreakPattern: RegExp;
60
+ readonly trailingSpacePattern: RegExp;
61
+ readonly leadingSpacePattern: RegExp;
62
+ readonly nonBreakingPattern: RegExp;
63
+ readonly srcAttribute: "src";
64
+ readonly altAttribute: "alt";
65
+ readonly hrefAttribute: "href";
66
+ readonly styleAttribute: "style";
67
+ readonly classAttribute: "class";
68
+ readonly widthAttribute: "width";
69
+ readonly heightAttribute: "height";
70
+ readonly aria: "aria-hidden";
71
+ readonly space: " ";
72
+ readonly newline: "\n";
73
+ readonly trackingLinePattern: RegExp;
74
+ readonly trackingEllipsis: "...";
75
+ readonly trackingEllipsisCharacter: "…";
76
+ };
@@ -0,0 +1,136 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.HtmlTextConfig = void 0;
4
+ exports.HtmlTextConfig = {
5
+ skipTags: [
6
+ 'head',
7
+ 'script',
8
+ 'style',
9
+ 'title',
10
+ 'noscript',
11
+ 'template',
12
+ 'svg',
13
+ 'iframe',
14
+ 'object',
15
+ 'embed',
16
+ 'video',
17
+ 'audio',
18
+ 'canvas',
19
+ 'select',
20
+ 'textarea',
21
+ ],
22
+ rawTextTags: ['script', 'style', 'title', 'textarea'],
23
+ voidTags: [
24
+ 'area',
25
+ 'base',
26
+ 'br',
27
+ 'col',
28
+ 'embed',
29
+ 'hr',
30
+ 'img',
31
+ 'input',
32
+ 'link',
33
+ 'meta',
34
+ 'param',
35
+ 'source',
36
+ 'track',
37
+ 'wbr',
38
+ ],
39
+ blockTags: [
40
+ 'address',
41
+ 'article',
42
+ 'aside',
43
+ 'body',
44
+ 'center',
45
+ 'dd',
46
+ 'details',
47
+ 'div',
48
+ 'dl',
49
+ 'dt',
50
+ 'fieldset',
51
+ 'figcaption',
52
+ 'figure',
53
+ 'footer',
54
+ 'form',
55
+ 'header',
56
+ 'html',
57
+ 'main',
58
+ 'nav',
59
+ 'p',
60
+ 'pre',
61
+ 'section',
62
+ 'summary',
63
+ 'table',
64
+ 'tbody',
65
+ 'td',
66
+ 'tfoot',
67
+ 'th',
68
+ 'thead',
69
+ 'tr',
70
+ ],
71
+ strongTags: ['b', 'strong'],
72
+ emTags: ['i', 'em', 'cite', 'dfn'],
73
+ underlineTags: ['u', 'ins'],
74
+ codeTags: ['code', 'kbd', 'samp', 'tt'],
75
+ linkTag: 'a',
76
+ imageTag: 'img',
77
+ breakTag: 'br',
78
+ ruleTag: 'hr',
79
+ preTag: 'pre',
80
+ quoteTag: 'blockquote',
81
+ listItemTag: 'li',
82
+ orderedListTag: 'ol',
83
+ unorderedListTag: 'ul',
84
+ hiddenClassPattern: /(^|[\s_-])(preheader|pre-header|preview-text|previewtext)([\s_-]|$)/i,
85
+ hiddenDisplay: 'none',
86
+ hiddenVisibility: 'hidden',
87
+ hiddenMso: 'all',
88
+ hiddenAttribute: 'hidden',
89
+ hiddenAria: 'true',
90
+ tinyImageSize: 2,
91
+ importantPattern: /!important/i,
92
+ zeroPattern: /^0(\.0+)?(px|pt|em|rem|%)?$/,
93
+ pixelPattern: /^([0-9.]+)(px)?$/,
94
+ boldWeight: 600,
95
+ largeText: { heading3: 20, heading2: 24, heading1: 30, maxLength: 100 },
96
+ boldHeadingMaxLength: 80,
97
+ headingEndPattern: /[.,;:!?]$/,
98
+ pixelsPerPoint: 1.333,
99
+ pixelsPerEm: 16,
100
+ fontSizePattern: /^([0-9.]+)(px|pt|em|rem)$/,
101
+ commentStart: '<!--',
102
+ commentEnd: '-->',
103
+ declarationSeparator: ';',
104
+ propertySeparator: ':',
105
+ tagSource: '<(\\/?)([a-zA-Z][a-zA-Z0-9:-]*)((?:"[^"]*"|\'[^\']*\'|[^\'">])*)>',
106
+ tagFlags: 'y',
107
+ attributePattern: /([^\s"'<>/=]+)(?:\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s"'=<>`]+)))?/g,
108
+ selfClosingPattern: /\/\s*$/,
109
+ whitespacePattern: /[ \t\r\n\f\u00A0\u2007\u202F]+/g,
110
+ preLineBreakPattern: /\r\n?/g,
111
+ invisiblePattern: /\u00AD|\u034F|[\u200B-\u200F\u2028\u2029\u2060\uFEFF]/g,
112
+ entityPattern: /&(#x[0-9a-fA-F]+|#[0-9]+|[a-zA-Z][a-zA-Z0-9]*);/g,
113
+ maxCodePoint: 0x10ffff,
114
+ numericEntityPrefix: '#',
115
+ hexEntityPrefix: '#x',
116
+ rootName: 'root',
117
+ bodyListLevel: 1,
118
+ trailingBreakPattern: /[ \n]+$/,
119
+ leadingBreakPattern: /^[ \n]+/,
120
+ trailingSpacePattern: / +$/,
121
+ leadingSpacePattern: /^ +/,
122
+ nonBreakingPattern: /[\u00A0\u2007\u202F]/g,
123
+ srcAttribute: 'src',
124
+ altAttribute: 'alt',
125
+ hrefAttribute: 'href',
126
+ styleAttribute: 'style',
127
+ classAttribute: 'class',
128
+ widthAttribute: 'width',
129
+ heightAttribute: 'height',
130
+ aria: 'aria-hidden',
131
+ space: ' ',
132
+ newline: '\n',
133
+ trackingLinePattern: /^\[\s*(?:<)?(https?:\/\/[^\s\]>]+?)(?:>)?\s*\]$/i,
134
+ trackingEllipsis: '...',
135
+ trackingEllipsisCharacter: '\u2026',
136
+ };
@@ -0,0 +1,5 @@
1
+ export declare const HtmlTokenKind: {
2
+ readonly Text: "text";
3
+ readonly Open: "open";
4
+ readonly Close: "close";
5
+ };
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.HtmlTokenKind = void 0;
4
+ exports.HtmlTokenKind = {
5
+ Text: 'text',
6
+ Open: 'open',
7
+ Close: 'close',
8
+ };
@@ -11,7 +11,23 @@ export declare const PortableTextConfig: {
11
11
  readonly keyPrefix: {
12
12
  readonly block: "b";
13
13
  readonly span: "s";
14
+ readonly link: "l";
15
+ readonly image: "i";
14
16
  };
17
+ readonly blockType: "block";
18
+ readonly spanType: "span";
19
+ readonly linkType: "link";
20
+ readonly imageType: "image";
21
+ readonly decorators: readonly ["strong", "em", "underline", "code"];
22
+ readonly headingStyles: readonly ["h1", "h2", "h3"];
23
+ readonly messageStyles: readonly ["normal", "h1", "h2", "h3", "blockquote"];
24
+ readonly linkProtocols: readonly ["http:", "https:", "mailto:"];
25
+ readonly maxListLevel: 3;
26
+ readonly maxImageSrcLength: 2048;
27
+ readonly maxImageAltLength: 300;
28
+ readonly imageProtocolPattern: RegExp;
29
+ readonly maxControlCode: 31;
30
+ readonly deleteCode: 127;
15
31
  readonly normalStyle: "normal";
16
32
  readonly quoteStyle: "blockquote";
17
33
  readonly bulletItem: "bullet";
@@ -12,7 +12,21 @@ exports.PortableTextConfig = {
12
12
  bulletPrefix: '- ',
13
13
  quotePrefix: '> ',
14
14
  numberSuffix: '. ',
15
- keyPrefix: { block: 'b', span: 's' },
15
+ keyPrefix: { block: 'b', span: 's', link: 'l', image: 'i' },
16
+ blockType: ps_models_1.Common.PortableTextConfig.blockType,
17
+ spanType: ps_models_1.Common.PortableTextConfig.spanType,
18
+ linkType: ps_models_1.Common.PortableTextConfig.linkType,
19
+ imageType: ps_models_1.Common.PortableTextConfig.imageType,
20
+ decorators: ps_models_1.Common.PortableTextConfig.decorators,
21
+ headingStyles: ps_models_1.Common.PortableTextConfig.headingStyles,
22
+ messageStyles: ps_models_1.Common.PortableTextConfig.messageStyles,
23
+ linkProtocols: ps_models_1.Common.PortableTextConfig.linkProtocols,
24
+ maxListLevel: ps_models_1.Common.PortableTextConfig.maxListLevel,
25
+ maxImageSrcLength: ps_models_1.Common.PortableTextConfig.maxImageSrcLength,
26
+ maxImageAltLength: ps_models_1.Common.PortableTextConfig.maxImageAltLength,
27
+ imageProtocolPattern: ps_models_1.Common.PortableTextConfig.imageProtocolPattern,
28
+ maxControlCode: 31,
29
+ deleteCode: 127,
16
30
  normalStyle: ps_models_1.Common.PortableTextConfig.styles[0],
17
31
  quoteStyle: ps_models_1.Common.PortableTextConfig.styles[1],
18
32
  bulletItem: ps_models_1.Common.PortableTextConfig.listItems[0],
@@ -0,0 +1,6 @@
1
+ export declare class HtmlEntityService {
2
+ static decode(value: string): string;
3
+ private static resolve;
4
+ private static fromCode;
5
+ private static isNamed;
6
+ }
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.HtmlEntityService = void 0;
4
+ var html_entity_names_1 = require("./constants/html-entity-names");
5
+ var html_text_config_1 = require("./constants/html-text-config");
6
+ var HtmlEntityService = /** @class */ (function () {
7
+ function HtmlEntityService() {
8
+ }
9
+ HtmlEntityService.decode = function (value) {
10
+ return value.replace(html_text_config_1.HtmlTextConfig.entityPattern, function (match, body) {
11
+ return HtmlEntityService.resolve(match, body);
12
+ });
13
+ };
14
+ HtmlEntityService.resolve = function (match, body) {
15
+ if (body.startsWith(html_text_config_1.HtmlTextConfig.hexEntityPrefix))
16
+ return HtmlEntityService.fromCode(match, Number.parseInt(body.slice(2), 16));
17
+ if (body.startsWith(html_text_config_1.HtmlTextConfig.numericEntityPrefix))
18
+ return HtmlEntityService.fromCode(match, Number.parseInt(body.slice(1), 10));
19
+ if (HtmlEntityService.isNamed(body))
20
+ return html_entity_names_1.HtmlEntityNames[body];
21
+ var lower = body.toLowerCase();
22
+ return HtmlEntityService.isNamed(lower) ? html_entity_names_1.HtmlEntityNames[lower] : match;
23
+ };
24
+ HtmlEntityService.fromCode = function (match, code) {
25
+ return Number.isInteger(code) && code > 0 && code <= html_text_config_1.HtmlTextConfig.maxCodePoint
26
+ ? String.fromCodePoint(code)
27
+ : match;
28
+ };
29
+ HtmlEntityService.isNamed = function (name) {
30
+ return Object.prototype.hasOwnProperty.call(html_entity_names_1.HtmlEntityNames, name);
31
+ };
32
+ return HtmlEntityService;
33
+ }());
34
+ exports.HtmlEntityService = HtmlEntityService;
@@ -0,0 +1,12 @@
1
+ import type { HtmlDeclarationsData } from '../models/html-declarations-data';
2
+ export declare class HtmlStyleService {
3
+ static parse(style: string | undefined): HtmlDeclarationsData;
4
+ static isHidden(declarations: HtmlDeclarationsData): boolean;
5
+ static isTiny(declarations: HtmlDeclarationsData): boolean;
6
+ static fontSize(declarations: HtmlDeclarationsData): number | null;
7
+ static bold(declarations: HtmlDeclarationsData): boolean | null;
8
+ static italic(declarations: HtmlDeclarationsData): boolean | null;
9
+ static underline(declarations: HtmlDeclarationsData): boolean | null;
10
+ private static isZero;
11
+ private static pixels;
12
+ }
@@ -0,0 +1,92 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.HtmlStyleService = void 0;
4
+ var html_text_config_1 = require("./constants/html-text-config");
5
+ var HtmlStyleService = /** @class */ (function () {
6
+ function HtmlStyleService() {
7
+ }
8
+ HtmlStyleService.parse = function (style) {
9
+ var declarations = {};
10
+ if (typeof style !== 'string')
11
+ return declarations;
12
+ style.split(html_text_config_1.HtmlTextConfig.declarationSeparator).forEach(function (entry) {
13
+ var index = entry.indexOf(html_text_config_1.HtmlTextConfig.propertySeparator);
14
+ if (index === -1)
15
+ return;
16
+ var property = entry.slice(0, index).trim().toLowerCase();
17
+ var value = entry
18
+ .slice(index + 1)
19
+ .replace(html_text_config_1.HtmlTextConfig.importantPattern, '')
20
+ .trim()
21
+ .toLowerCase();
22
+ if (property !== '' && value !== '')
23
+ declarations[property] = value;
24
+ });
25
+ return declarations;
26
+ };
27
+ HtmlStyleService.isHidden = function (declarations) {
28
+ return (declarations['display'] === html_text_config_1.HtmlTextConfig.hiddenDisplay ||
29
+ declarations['visibility'] === html_text_config_1.HtmlTextConfig.hiddenVisibility ||
30
+ declarations['mso-hide'] === html_text_config_1.HtmlTextConfig.hiddenMso ||
31
+ HtmlStyleService.isZero(declarations['max-height']) ||
32
+ HtmlStyleService.isZero(declarations['max-width']) ||
33
+ HtmlStyleService.isZero(declarations['font-size']) ||
34
+ HtmlStyleService.isZero(declarations['opacity']));
35
+ };
36
+ HtmlStyleService.isTiny = function (declarations) {
37
+ return (HtmlStyleService.pixels(declarations['width']) <= html_text_config_1.HtmlTextConfig.tinyImageSize ||
38
+ HtmlStyleService.pixels(declarations['height']) <= html_text_config_1.HtmlTextConfig.tinyImageSize);
39
+ };
40
+ HtmlStyleService.fontSize = function (declarations) {
41
+ var value = declarations['font-size'];
42
+ if (typeof value !== 'string')
43
+ return null;
44
+ var match = html_text_config_1.HtmlTextConfig.fontSizePattern.exec(value);
45
+ if (match === null)
46
+ return null;
47
+ var amount = Number.parseFloat(match[1]);
48
+ if (match[2] === 'pt')
49
+ return amount * html_text_config_1.HtmlTextConfig.pixelsPerPoint;
50
+ if (match[2] === 'em' || match[2] === 'rem')
51
+ return amount * html_text_config_1.HtmlTextConfig.pixelsPerEm;
52
+ return amount;
53
+ };
54
+ HtmlStyleService.bold = function (declarations) {
55
+ var value = declarations['font-weight'];
56
+ if (typeof value !== 'string')
57
+ return null;
58
+ if (value === 'bold' || value === 'bolder')
59
+ return true;
60
+ if (value === 'normal' || value === 'lighter')
61
+ return false;
62
+ var weight = Number.parseInt(value, 10);
63
+ return Number.isNaN(weight) ? null : weight >= html_text_config_1.HtmlTextConfig.boldWeight;
64
+ };
65
+ HtmlStyleService.italic = function (declarations) {
66
+ var value = declarations['font-style'];
67
+ if (typeof value !== 'string')
68
+ return null;
69
+ if (value === 'italic' || value === 'oblique')
70
+ return true;
71
+ return value === 'normal' ? false : null;
72
+ };
73
+ HtmlStyleService.underline = function (declarations) {
74
+ var value = declarations['text-decoration'];
75
+ if (typeof value !== 'string')
76
+ return null;
77
+ if (value.includes('underline'))
78
+ return true;
79
+ return value.includes('none') ? false : null;
80
+ };
81
+ HtmlStyleService.isZero = function (value) {
82
+ return typeof value === 'string' && html_text_config_1.HtmlTextConfig.zeroPattern.test(value);
83
+ };
84
+ HtmlStyleService.pixels = function (value) {
85
+ if (typeof value !== 'string')
86
+ return Number.POSITIVE_INFINITY;
87
+ var match = html_text_config_1.HtmlTextConfig.pixelPattern.exec(value);
88
+ return match === null ? Number.POSITIVE_INFINITY : Number.parseFloat(match[1]);
89
+ };
90
+ return HtmlStyleService;
91
+ }());
92
+ exports.HtmlStyleService = HtmlStyleService;
@@ -0,0 +1,8 @@
1
+ import type { HtmlTokenData } from '../models/html-token-data';
2
+ export declare class HtmlTokenService {
3
+ static tokenize(html: string): HtmlTokenData[];
4
+ private static consume;
5
+ private static skipRawText;
6
+ private static attributes;
7
+ private static pushText;
8
+ }
@@ -0,0 +1,90 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.HtmlTokenService = void 0;
4
+ var html_text_config_1 = require("./constants/html-text-config");
5
+ var html_token_kind_1 = require("./constants/html-token-kind");
6
+ var html_entity_service_1 = require("./html-entity-service");
7
+ var HtmlTokenService = /** @class */ (function () {
8
+ function HtmlTokenService() {
9
+ }
10
+ HtmlTokenService.tokenize = function (html) {
11
+ var tokens = [];
12
+ var cursor = 0;
13
+ while (cursor < html.length) {
14
+ var start = html.indexOf('<', cursor);
15
+ if (start === -1) {
16
+ HtmlTokenService.pushText(tokens, html.slice(cursor));
17
+ break;
18
+ }
19
+ HtmlTokenService.pushText(tokens, html.slice(cursor, start));
20
+ cursor = HtmlTokenService.consume(html, start, tokens);
21
+ }
22
+ return tokens;
23
+ };
24
+ HtmlTokenService.consume = function (html, start, tokens) {
25
+ if (html.startsWith(html_text_config_1.HtmlTextConfig.commentStart, start)) {
26
+ var end_1 = html.indexOf(html_text_config_1.HtmlTextConfig.commentEnd, start + html_text_config_1.HtmlTextConfig.commentStart.length);
27
+ return end_1 === -1 ? html.length : end_1 + html_text_config_1.HtmlTextConfig.commentEnd.length;
28
+ }
29
+ var next = html.charAt(start + 1);
30
+ if (next === '!' || next === '?') {
31
+ var end_2 = html.indexOf('>', start);
32
+ return end_2 === -1 ? html.length : end_2 + 1;
33
+ }
34
+ var pattern = new RegExp(html_text_config_1.HtmlTextConfig.tagSource, html_text_config_1.HtmlTextConfig.tagFlags);
35
+ pattern.lastIndex = start;
36
+ var match = pattern.exec(html);
37
+ if (match === null) {
38
+ HtmlTokenService.pushText(tokens, '<');
39
+ return start + 1;
40
+ }
41
+ var name = match[2].toLowerCase();
42
+ var end = start + match[0].length;
43
+ if (match[1] === '/') {
44
+ tokens.push({ kind: html_token_kind_1.HtmlTokenKind.Close, name: name });
45
+ return end;
46
+ }
47
+ tokens.push({
48
+ attributes: HtmlTokenService.attributes(match[3]),
49
+ kind: html_token_kind_1.HtmlTokenKind.Open,
50
+ name: name,
51
+ selfClosing: html_text_config_1.HtmlTextConfig.selfClosingPattern.test(match[3]),
52
+ });
53
+ return html_text_config_1.HtmlTextConfig.rawTextTags.includes(name)
54
+ ? HtmlTokenService.skipRawText(html, name, end, tokens)
55
+ : end;
56
+ };
57
+ HtmlTokenService.skipRawText = function (html, name, from, tokens) {
58
+ var closing = new RegExp("</".concat(name, "\\s*>"), 'gi');
59
+ closing.lastIndex = from;
60
+ var match = closing.exec(html);
61
+ if (match === null)
62
+ return html.length;
63
+ tokens.push({ kind: html_token_kind_1.HtmlTokenKind.Close, name: name });
64
+ return match.index + match[0].length;
65
+ };
66
+ HtmlTokenService.attributes = function (source) {
67
+ var attributes = {};
68
+ var pattern = new RegExp(html_text_config_1.HtmlTextConfig.attributePattern.source, html_text_config_1.HtmlTextConfig.attributePattern.flags);
69
+ var match = pattern.exec(source);
70
+ while (match !== null) {
71
+ var raw = [match[2], match[3], match[4]].find(function (value) { return typeof value === 'string'; });
72
+ var key = match[1].toLowerCase();
73
+ if (!Object.prototype.hasOwnProperty.call(attributes, key))
74
+ attributes[key] = html_entity_service_1.HtmlEntityService.decode(typeof raw === 'string' ? raw : '');
75
+ match = pattern.exec(source);
76
+ }
77
+ return attributes;
78
+ };
79
+ HtmlTokenService.pushText = function (tokens, text) {
80
+ if (text === '')
81
+ return;
82
+ var last = tokens[tokens.length - 1];
83
+ if (last !== undefined && last.kind === html_token_kind_1.HtmlTokenKind.Text)
84
+ last.text += text;
85
+ else
86
+ tokens.push({ kind: html_token_kind_1.HtmlTokenKind.Text, text: text });
87
+ };
88
+ return HtmlTokenService;
89
+ }());
90
+ exports.HtmlTokenService = HtmlTokenService;
@@ -24,5 +24,6 @@ export * from './error-response-service';
24
24
  export * from './relative-time-service';
25
25
  export * from './request-client-service';
26
26
  export * from './json-service';
27
+ export * from './portable-text-link-service';
27
28
  export * from './portable-text-service';
28
29
  export * from './text-tidy-service';
@@ -40,5 +40,6 @@ __exportStar(require("./error-response-service"), exports);
40
40
  __exportStar(require("./relative-time-service"), exports);
41
41
  __exportStar(require("./request-client-service"), exports);
42
42
  __exportStar(require("./json-service"), exports);
43
+ __exportStar(require("./portable-text-link-service"), exports);
43
44
  __exportStar(require("./portable-text-service"), exports);
44
45
  __exportStar(require("./text-tidy-service"), exports);
@@ -0,0 +1,28 @@
1
+ import type { PortableTextContentData } from '../models/portable-text-content-data';
2
+ export declare class PortableTextHtmlService {
3
+ static fromHtml(html: string): PortableTextContentData[];
4
+ private static rootFrame;
5
+ private static consume;
6
+ private static isVoid;
7
+ private static isBlockTag;
8
+ private static isHidden;
9
+ private static attribute;
10
+ private static open;
11
+ private static closeOpenItem;
12
+ private static frame;
13
+ private static resolve;
14
+ private static close;
15
+ private static addText;
16
+ private static push;
17
+ private static lineBreak;
18
+ private static image;
19
+ private static isTiny;
20
+ private static key;
21
+ private static context;
22
+ private static trimmed;
23
+ private static flush;
24
+ private static styleOf;
25
+ private static headingOf;
26
+ private static merge;
27
+ private static marks;
28
+ }