@gilav21/shadcn-angular-rte 0.2.0 → 0.2.1

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 (19) hide show
  1. package/fesm2022/{gilav21-shadcn-angular-rte-docx-parser-CdxuIlVT.mjs → gilav21-shadcn-angular-rte-docx-parser-DiBPweI4.mjs} +63 -38
  2. package/fesm2022/gilav21-shadcn-angular-rte-docx-parser-DiBPweI4.mjs.map +1 -0
  3. package/fesm2022/{gilav21-shadcn-angular-rte-docx-to-editor-html-Cl9eIhkC.mjs → gilav21-shadcn-angular-rte-docx-to-editor-html-BreagmS_.mjs} +43 -33
  4. package/fesm2022/gilav21-shadcn-angular-rte-docx-to-editor-html-BreagmS_.mjs.map +1 -0
  5. package/fesm2022/{gilav21-shadcn-angular-rte-gilav21-shadcn-angular-rte-BFcfCqW4.mjs → gilav21-shadcn-angular-rte-gilav21-shadcn-angular-rte-BnEAQOuU.mjs} +3492 -1899
  6. package/fesm2022/gilav21-shadcn-angular-rte-gilav21-shadcn-angular-rte-BnEAQOuU.mjs.map +1 -0
  7. package/fesm2022/gilav21-shadcn-angular-rte-markup-safety-qJk8EoPk.mjs +69 -0
  8. package/fesm2022/gilav21-shadcn-angular-rte-markup-safety-qJk8EoPk.mjs.map +1 -0
  9. package/fesm2022/{gilav21-shadcn-angular-rte-pdf-readable-DmE-CIxv.mjs → gilav21-shadcn-angular-rte-pdf-readable-JvCpuNQH.mjs} +445 -124
  10. package/fesm2022/gilav21-shadcn-angular-rte-pdf-readable-JvCpuNQH.mjs.map +1 -0
  11. package/fesm2022/gilav21-shadcn-angular-rte.mjs +1 -1
  12. package/package.json +1 -1
  13. package/styles.css +1 -1
  14. package/types/gilav21-shadcn-angular-rte.d.ts +359 -113
  15. package/types/gilav21-shadcn-angular-rte.d.ts.map +1 -1
  16. package/fesm2022/gilav21-shadcn-angular-rte-docx-parser-CdxuIlVT.mjs.map +0 -1
  17. package/fesm2022/gilav21-shadcn-angular-rte-docx-to-editor-html-Cl9eIhkC.mjs.map +0 -1
  18. package/fesm2022/gilav21-shadcn-angular-rte-gilav21-shadcn-angular-rte-BFcfCqW4.mjs.map +0 -1
  19. package/fesm2022/gilav21-shadcn-angular-rte-pdf-readable-DmE-CIxv.mjs.map +0 -1
@@ -0,0 +1,69 @@
1
+ /*
2
+ * Importers (DOCX, DOC, PPTX, PDF) build markup from values read out of a
3
+ * document the user did not write. Each helper here makes one kind of such value
4
+ * safe for the slot it lands in, so a caller either gets a value of the right
5
+ * grammar or `undefined` and leaves the declaration, attribute or link out.
6
+ *
7
+ * "Escaped" is not enough for a CSS value: an escaped `red;background:url(…)` is
8
+ * still two declarations. A value has to MATCH the grammar of its property.
9
+ */
10
+ /** Hex, functional `rgb()/rgba()/hsl()/hsla()` with numeric arguments, or a bare keyword. */
11
+ const CSS_COLOR = /^(?:#[\da-f]{3,8}|(?:rgba?|hsla?)\([\d\s.,%/+-]*\)|[a-z]+)$/i;
12
+ const IMAGE_DATA_URL = /^data:image\/[\w.+-]+;base64,[\w+/=]*$/;
13
+ const SAFE_LINK_PROTOCOLS = new Set(['http:', 'https:', 'mailto:']);
14
+ /**
15
+ * A document colour when it is plain colour syntax, else `undefined`. The syntax
16
+ * admits no `;`, quote or `url(`, so the value cannot add a declaration or fetch.
17
+ */
18
+ function cssColor(value) {
19
+ return value && CSS_COLOR.test(value) ? value : undefined;
20
+ }
21
+ /**
22
+ * A document font name as one quoted CSS string, without a generic fallback (the
23
+ * caller appends the fallback its context wants). Quotes and backslashes are
24
+ * escaped and control characters dropped, because any of them could end the
25
+ * string and let the name write further declarations.
26
+ */
27
+ function cssFontFamily(name) {
28
+ let quoted = '';
29
+ for (const ch of name) {
30
+ const code = ch.codePointAt(0) ?? 0;
31
+ if (code < 0x20 || code === 0x7f)
32
+ continue;
33
+ quoted += ch === '\\' || ch === "'" ? `\\${ch}` : ch;
34
+ }
35
+ return `'${quoted}'`;
36
+ }
37
+ /** The value when it is a base64 image data URL — the only image source the parsers produce — else `undefined`. */
38
+ function imageDataUrl(value) {
39
+ return value && IMAGE_DATA_URL.test(value) ? value : undefined;
40
+ }
41
+ /**
42
+ * A link target an importer may render: an in-document `#fragment`, or an absolute
43
+ * http, https or mailto URL (returned as the browser will parse it, so the scheme
44
+ * checked is the scheme followed). Anything else — `javascript:`, `data:`, relative
45
+ * paths — yields `undefined` and the text renders unlinked.
46
+ */
47
+ function safeLinkHref(href) {
48
+ if (href.startsWith('#'))
49
+ return href;
50
+ try {
51
+ const url = new URL(href);
52
+ return SAFE_LINK_PROTOCOLS.has(url.protocol) ? url.href : undefined;
53
+ }
54
+ catch {
55
+ // Not an absolute URL; relative targets are not rendered as links.
56
+ return undefined;
57
+ }
58
+ }
59
+ /** A value for a double-quoted HTML attribute: nothing in it can end the attribute or open a tag. */
60
+ function escapeAttribute(value) {
61
+ return value
62
+ .replaceAll('&', '&amp;')
63
+ .replaceAll('"', '&quot;')
64
+ .replaceAll('<', '&lt;')
65
+ .replaceAll('>', '&gt;');
66
+ }
67
+
68
+ export { cssFontFamily as a, cssColor as c, escapeAttribute as e, imageDataUrl as i, safeLinkHref as s };
69
+ //# sourceMappingURL=gilav21-shadcn-angular-rte-markup-safety-qJk8EoPk.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gilav21-shadcn-angular-rte-markup-safety-qJk8EoPk.mjs","sources":["../../../packages/rte-package/src/lib/parsers/markup-safety.ts"],"sourcesContent":["/*\n * Importers (DOCX, DOC, PPTX, PDF) build markup from values read out of a\n * document the user did not write. Each helper here makes one kind of such value\n * safe for the slot it lands in, so a caller either gets a value of the right\n * grammar or `undefined` and leaves the declaration, attribute or link out.\n *\n * \"Escaped\" is not enough for a CSS value: an escaped `red;background:url(…)` is\n * still two declarations. A value has to MATCH the grammar of its property.\n */\n\n/** Hex, functional `rgb()/rgba()/hsl()/hsla()` with numeric arguments, or a bare keyword. */\nconst CSS_COLOR = /^(?:#[\\da-f]{3,8}|(?:rgba?|hsla?)\\([\\d\\s.,%/+-]*\\)|[a-z]+)$/i;\nconst IMAGE_DATA_URL = /^data:image\\/[\\w.+-]+;base64,[\\w+/=]*$/;\nconst SAFE_LINK_PROTOCOLS: ReadonlySet<string> = new Set(['http:', 'https:', 'mailto:']);\n\n/**\n * A document colour when it is plain colour syntax, else `undefined`. The syntax\n * admits no `;`, quote or `url(`, so the value cannot add a declaration or fetch.\n */\nexport function cssColor(value: string | undefined): string | undefined {\n return value && CSS_COLOR.test(value) ? value : undefined;\n}\n\n/**\n * A document font name as one quoted CSS string, without a generic fallback (the\n * caller appends the fallback its context wants). Quotes and backslashes are\n * escaped and control characters dropped, because any of them could end the\n * string and let the name write further declarations.\n */\nexport function cssFontFamily(name: string): string {\n let quoted = '';\n for (const ch of name) {\n const code = ch.codePointAt(0) ?? 0;\n if (code < 0x20 || code === 0x7f) continue;\n quoted += ch === '\\\\' || ch === \"'\" ? `\\\\${ch}` : ch;\n }\n return `'${quoted}'`;\n}\n\n/** The value when it is a base64 image data URL — the only image source the parsers produce — else `undefined`. */\nexport function imageDataUrl(value: string | undefined): string | undefined {\n return value && IMAGE_DATA_URL.test(value) ? value : undefined;\n}\n\n/**\n * A link target an importer may render: an in-document `#fragment`, or an absolute\n * http, https or mailto URL (returned as the browser will parse it, so the scheme\n * checked is the scheme followed). Anything else — `javascript:`, `data:`, relative\n * paths — yields `undefined` and the text renders unlinked.\n */\nexport function safeLinkHref(href: string): string | undefined {\n if (href.startsWith('#')) return href;\n try {\n const url = new URL(href);\n return SAFE_LINK_PROTOCOLS.has(url.protocol) ? url.href : undefined;\n } catch {\n // Not an absolute URL; relative targets are not rendered as links.\n return undefined;\n }\n}\n\n/** A value for a double-quoted HTML attribute: nothing in it can end the attribute or open a tag. */\nexport function escapeAttribute(value: string): string {\n return value\n .replaceAll('&', '&amp;')\n .replaceAll('\"', '&quot;')\n .replaceAll('<', '&lt;')\n .replaceAll('>', '&gt;');\n}\n"],"names":[],"mappings":"AAAA;;;;;;;;A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