@liquid-js/lyr-extras 0.0.0-stage → 22.0.0-alpha.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.
- package/LICENSE.txt +23 -0
- package/README.md +61 -2
- package/fesm2022/liquid-js-lyr-extras-chart.mjs +871 -0
- package/fesm2022/liquid-js-lyr-extras-chart.mjs.map +1 -0
- package/fesm2022/liquid-js-lyr-extras-color-picker.mjs +819 -0
- package/fesm2022/liquid-js-lyr-extras-color-picker.mjs.map +1 -0
- package/fesm2022/liquid-js-lyr-extras-markdown-editor.mjs +921 -0
- package/fesm2022/liquid-js-lyr-extras-markdown-editor.mjs.map +1 -0
- package/fesm2022/liquid-js-lyr-extras-markdown-viewer.mjs +369 -0
- package/fesm2022/liquid-js-lyr-extras-markdown-viewer.mjs.map +1 -0
- package/fesm2022/liquid-js-lyr-extras-mask.mjs +238 -0
- package/fesm2022/liquid-js-lyr-extras-mask.mjs.map +1 -0
- package/fesm2022/liquid-js-lyr-extras-media.mjs +1142 -0
- package/fesm2022/liquid-js-lyr-extras-media.mjs.map +1 -0
- package/fesm2022/liquid-js-lyr-extras-phone-input.mjs +862 -0
- package/fesm2022/liquid-js-lyr-extras-phone-input.mjs.map +1 -0
- package/fesm2022/liquid-js-lyr-extras-qr-code.mjs +236 -0
- package/fesm2022/liquid-js-lyr-extras-qr-code.mjs.map +1 -0
- package/fesm2022/liquid-js-lyr-extras.mjs +0 -0
- package/package.json +159 -3
- package/types/liquid-js-lyr-extras-chart.d.ts +294 -0
- package/types/liquid-js-lyr-extras-color-picker.d.ts +311 -0
- package/types/liquid-js-lyr-extras-markdown-editor.d.ts +367 -0
- package/types/liquid-js-lyr-extras-markdown-viewer.d.ts +174 -0
- package/types/liquid-js-lyr-extras-mask.d.ts +130 -0
- package/types/liquid-js-lyr-extras-media.d.ts +517 -0
- package/types/liquid-js-lyr-extras-phone-input.d.ts +428 -0
- package/types/liquid-js-lyr-extras-qr-code.d.ts +113 -0
- package/types/liquid-js-lyr-extras.d.ts +1 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"liquid-js-lyr-extras-markdown-viewer.mjs","names":["blockParents"],"sources":["../../../packages/extras/markdown-viewer/src/markdown-tree.ts","../../../packages/extras/markdown-viewer/src/texts.ts","../../../packages/extras/markdown-viewer/src/markdown-viewer.component.ts","../../../packages/extras/markdown-viewer/src/markdown-viewer.component.html"],"sourcesContent":["import type { Definition, FootnoteDefinition, Html, Node, Nodes, Parent, Root, RootContent } from 'mdast'\n\n/** An inline HTML element of the markdown, e.g. `<kbd>Ctrl</kbd>`, with the markdown between its tags. */\nexport interface NbMarkdownHtmlElement extends Parent {\n type: 'nbHtmlElement'\n tagName: string\n}\n\n/** A link from a footnote back to where the text refers to it, at the end of the footnote. */\nexport interface NbMarkdownFootnoteBack extends Node {\n type: 'nbFootnoteBack'\n identifier: string\n}\n\n/** The footnotes, at the end of the document. */\nexport interface NbMarkdownFootnotes extends Parent {\n type: 'nbFootnotes'\n children: FootnoteDefinition[]\n}\n\ndeclare module 'mdast' {\n interface PhrasingContentMap {\n nbHtmlElement: NbMarkdownHtmlElement\n nbFootnoteBack: NbMarkdownFootnoteBack\n }\n interface RootContentMap {\n nbHtmlElement: NbMarkdownHtmlElement\n nbFootnoteBack: NbMarkdownFootnoteBack\n nbFootnotes: NbMarkdownFootnotes\n }\n}\n\nconst voidElements = new Set(['br', 'wbr', 'img', 'hr'])\nconst openingTag = /^<([a-z][a-z0-9-]*)(?:\\s[^>]*)?>$/i\nconst selfClosingTag = /^<([a-z][a-z0-9-]*)(?:\\s[^>]*)?\\/>$/i\nconst closingTag = /^<\\/([a-z][a-z0-9-]*)\\s*>$/i\n/** Parents of block content, whose HTML is a block of its own rather than tags in a line of text. */\nconst blockParents = new Set(['root', 'blockquote', 'listItem', 'footnoteDefinition', 'nbFootnotes'])\n\nfunction tagName(node: RootContent, pattern: RegExp) {\n return node.type === 'html' ? pattern.exec(node.value)?.[1].toLowerCase() : undefined\n}\n\n/** Pairs the opening and closing tags of HTML in a line of text into elements, with the content between them. */\nfunction pairTags(children: RootContent[]): RootContent[] {\n const paired = new Array<RootContent>()\n for (let index = 0; index < children.length; index++) {\n const child = children[index]\n const name = tagName(child, openingTag)\n const selfClosing = tagName(child, selfClosingTag)\n if (selfClosing || (name && voidElements.has(name))) {\n paired.push({ type: 'nbHtmlElement', tagName: selfClosing ?? name ?? '', children: [] })\n continue\n }\n if (!name) {\n paired.push(child)\n continue\n }\n let depth = 0\n let end = index + 1\n for (; end < children.length; end++) {\n if (tagName(children[end], openingTag) === name) {\n depth++\n } else if (tagName(children[end], closingTag) === name && depth-- === 0) {\n break\n }\n }\n if (end === children.length) {\n paired.push(child)\n continue\n }\n const content = pairTags(children.slice(index + 1, end)) as NbMarkdownHtmlElement['children']\n paired.push({ type: 'nbHtmlElement', tagName: name, children: content })\n index = end\n }\n return paired\n}\n\n/** Whether a list's items hold their text without paragraphs, as in `mdast-util-to-hast`. */\nfunction isTight(node: Nodes) {\n if (node.type !== 'list' || node.spread) {\n return false\n }\n return node.children.every((item) => !(item.spread ?? item.children.length > 1))\n}\n\n/**\n * Prepares the markdown's syntax tree for its templates, as `remark-rehype` prepares it for HTML: references become\n * links and images, a tight list's items lose their paragraphs, footnotes move to the end, and the tags of HTML in a\n * line of text are paired into elements.\n */\nexport function prepareTree(tree: Root) {\n const definitions = new Map<string, Definition>()\n const footnotes = new Array<FootnoteDefinition>()\n const collect = (node: Nodes) => {\n if (node.type === 'definition') {\n definitions.set(node.identifier, node)\n }\n if ('children' in node) {\n node.children.forEach(collect)\n }\n }\n collect(tree)\n\n const transform = (node: Nodes) => {\n if (!('children' in node)) {\n return\n }\n const children = new Array<RootContent>()\n for (const child of node.children as RootContent[]) {\n if (child.type === 'definition') {\n continue\n }\n if (child.type === 'footnoteDefinition') {\n footnotes.push(child)\n transform(child)\n continue\n }\n if (child.type === 'linkReference') {\n const { url = '', title } = definitions.get(child.identifier) ?? {}\n const link = { type: 'link', url, title, children: child.children } as const\n transform(link)\n children.push(link)\n continue\n }\n if (child.type === 'imageReference') {\n const { url = '', title } = definitions.get(child.identifier) ?? {}\n children.push({ type: 'image', url, title, alt: child.alt })\n continue\n }\n transform(child)\n if (child.type === 'listItem' && isTight(node)) {\n child.children = child.children.flatMap((content) =>\n content.type === 'paragraph' ? (content.children as typeof child.children) : [content]\n )\n }\n children.push(child)\n }\n const hasHtml = children.some((child): child is Html => child.type === 'html')\n node.children = (hasHtml && !blockParents.has(node.type) ? pairTags(children) : children) as typeof node.children\n }\n transform(tree)\n\n if (footnotes.length) {\n // Each footnote ends with a link back to where the text refers to it, as GitHub's do.\n for (const footnote of footnotes) {\n const back: NbMarkdownFootnoteBack = { type: 'nbFootnoteBack', identifier: footnote.identifier }\n const last = footnote.children.at(-1)\n if (last?.type === 'paragraph') {\n last.children.push(back)\n } else {\n footnote.children.push({ type: 'paragraph', children: [back] })\n }\n }\n tree.children.push({ type: 'nbFootnotes', children: footnotes })\n }\n return tree\n}\n","import { injectNbTexts, NbLocalize } from '@liquid-js/lyr-core'\n\n/** @internal */\ndeclare const $localize: NbLocalize\n\n/**\n * The texts of the markdown viewer. `provideNbTexts({ markdownViewer: { ... } })` changes them, and they're translated\n * with Angular's i18n, as `$localize` messages with ids like `@@nb.markdownViewer.footnotes`.\n */\nexport interface NbMarkdownViewerTexts {\n /** Names the footnotes at the end of the text. */\n footnotes: string\n /** Names the link at the end of a footnote back to where the text refers to it. */\n backToText: string\n}\n\ndeclare module '@liquid-js/lyr-core' {\n interface NbTexts {\n markdownViewer: NbMarkdownViewerTexts\n }\n}\n\n/** @internal */\nexport function injectNbMarkdownViewerTexts() {\n return injectNbTexts('markdownViewer', () => ({\n footnotes: $localize`:@@nb.markdownViewer.footnotes:Footnotes`,\n backToText: $localize`:@@nb.markdownViewer.backToText:Back to the text`\n }))\n}\n","import {\n booleanAttribute,\n ChangeDetectionStrategy,\n Component,\n computed,\n contentChildren,\n ElementRef,\n inject,\n input,\n TemplateRef,\n viewChild,\n viewChildren,\n ViewEncapsulation\n} from '@angular/core'\nimport type { Node, Root } from 'mdast'\nimport { RemarkNodeComponent, RemarkTemplateDirective, RemarkTemplatesService } from 'ngx-remark'\nimport { HighlightDirective, NXT_HIGHLIGHT_OPTIONS } from 'nxt-highlightjs'\nimport { remark } from 'remark'\nimport remarkGfm from 'remark-gfm'\nimport remarkSmartypants from 'remark-smartypants'\n\nimport { prepareTree } from './markdown-tree'\nimport { injectNbMarkdownViewerTexts } from './texts'\n\n/** A unified processor that parses markdown, with its plugins, e.g. `remark().use(remarkGfm)`. */\nexport interface NbMarkdownProcessor {\n parse(markdown: string): Node\n runSync(tree: Node): Node\n}\n\n/** Typographic characters for the plain ones the markdown editor's Format button writes: `--` and `---` are dashes. */\nconst typography = { dashes: 'oldschool' } as const\n\nconst defaultProcessor: NbMarkdownProcessor = remark().use(remarkGfm).use(remarkSmartypants, typography).freeze()\n\n/** HTML elements the markdown can use in a line of text, without their attributes. */\nconst htmlElements = new Set([\n 'abbr',\n 'b',\n 'br',\n 'cite',\n 'code',\n 'del',\n 'em',\n 'i',\n 'ins',\n 'kbd',\n 'mark',\n 's',\n 'samp',\n 'small',\n 'span',\n 'strong',\n 'sub',\n 'sup',\n 'u',\n 'var',\n 'wbr'\n])\n\nconst blockParents = new Set(['root', 'blockquote', 'listItem', 'footnoteDefinition'])\n\nlet nextId = 0\n\n/**\n * Shows markdown, in the theme's text styles:\n *\n * ```html\n * <nb-markdown-viewer [markdown]=\"text\" />\n * ```\n *\n * @stacked-example(Showcase, markdown/markdown-viewer-showcase.component)\n *\n * ### Installation\n *\n * It renders the markdown with Angular's templates through [`ngx-remark`](https://www.npmjs.com/package/ngx-remark),\n * which parses it with [`remark`](https://remark.js.org), [`remark-gfm`](https://www.npmjs.com/package/remark-gfm) and\n * [`remark-smartypants`](https://www.npmjs.com/package/remark-smartypants), and highlights code with\n * [`nxt-highlightjs`](https://www.npmjs.com/package/nxt-highlightjs); install them and import\n * `NbMarkdownViewerComponent` from `@liquid-js/lyr-extras/markdown-viewer`.\n *\n * ```sh\n * npm install ngx-remark remark remark-gfm remark-smartypants nxt-highlightjs highlight.js\n * ```\n *\n * `remark` uses a CommonJS module, `extend`, which Angular's build warns about unless it's in\n * `allowedCommonJsDependencies` in `angular.json`.\n *\n * ### Usage\n *\n * The markdown is CommonMark with GitHub's extensions: tables, task lists, strikethrough, autolinks and footnotes. It\n * renders as the editor's preview shows it, on the server too, so a prerendered page has the text before scripts run.\n * The text's straight quotes, `--`, `---` and `...` show as typographic quotes, en and em dashes and ellipses, so the\n * markdown can keep the plain characters that the editor's Format button writes; code shows them as they are.\n *\n * HTML blocks in the markdown are sanitized by Angular. In a line of text, only formatting elements such as `<kbd>`,\n * `<sup>` or `<mark>` apply, without their attributes.\n *\n * Each element is rendered by an Angular template, which a template of your own can replace, e.g. to render links\n * with the router or code with a highlighter. Import `RemarkModule` from `ngx-remark`, and put the templates in the\n * viewer, named by the [type of node](https://github.com/syntax-tree/mdast#nodes) they render; `[remarkNode]` renders\n * the node's content in an element, or `<remark-node [remarkNode]=\"node\" />` in a component:\n *\n * ```html\n * <nb-markdown-viewer [markdown]=\"text\">\n * <a *remarkTemplate=\"'link'; let node\" [routerLink]=\"node.url\" [remarkNode]=\"node\"></a>\n * </nb-markdown-viewer>\n * ```\n * @stacked-example(Templates, markdown/markdown-viewer-templates.component)\n *\n * Text that mixes right-to-left and left-to-right languages, e.g. Arabic or Hebrew quoted in English, reads right\n * with `autoDirection`, as in the editor: each block of the document, i.e. a paragraph, heading, list, quote, table,\n * HTML block or the footnotes, takes the direction of its own text, as `dir=\"auto\"` does. Blocks in a quote or a list\n * share its direction, and code blocks read left to right. Templates of your own render their elements as they are, so\n * they need `dir=\"auto\"` themselves.\n *\n * `processor` replaces the parser, e.g. to add remark plugins, whose new types of nodes need templates of their own.\n *\n * ### Code highlighting\n *\n * Code blocks are highlighted in the theme's colours once the app loads highlight.js, with the languages it uses:\n *\n * ```ts\n * import { provideHighlightOptions } from 'nxt-highlightjs';\n *\n * provideHighlightOptions({\n * coreLibraryLoader: () => import('highlight.js/lib/core').then((m) => m.default),\n * languages: {\n * typescript: () => import('highlight.js/lib/languages/typescript').then((m) => m.default),\n * xml: () => import('highlight.js/lib/languages/xml').then((m) => m.default),\n * },\n * });\n * ```\n *\n * Code in other languages, or without one, shows as plain text. The server waits for highlight.js, so a prerendered\n * page has highlighted code. `nb-markdown-editor` highlights its preview and WYSIWYG code the same way.\n */\n@Component({\n selector: 'nb-markdown-viewer',\n templateUrl: './markdown-viewer.component.html',\n styleUrl: './markdown-viewer.component.scss',\n encapsulation: ViewEncapsulation.None,\n changeDetection: ChangeDetectionStrategy.OnPush,\n providers: [RemarkTemplatesService],\n imports: [RemarkNodeComponent, RemarkTemplateDirective, HighlightDirective],\n host: {\n class: 'nb-markdown'\n }\n})\nexport class NbMarkdownViewerComponent {\n /** The markdown to show. */\n readonly markdown = input('')\n /** Parses the markdown, `remark().use(remarkGfm).use(remarkSmartypants, { dashes: 'oldschool' })` by default. */\n readonly processor = input<NbMarkdownProcessor>()\n /**\n * Gives each block of the document, e.g. a paragraph or a list, the direction of its own text (`dir=\"auto\"`), for\n * text in more than one direction; `false` by default.\n */\n readonly autoDirection = input(false, { transform: booleanAttribute })\n\n /** The markdown's syntax tree, as its templates render it. */\n readonly tree = computed(() => {\n const processor = this.processor() ?? defaultProcessor\n return prepareTree(processor.runSync(processor.parse(this.markdown())) as Root)\n })\n\n protected readonly id = `nb-markdown-${nextId++}`\n protected readonly texts = injectNbMarkdownViewerTexts()\n protected readonly htmlElements = htmlElements\n protected readonly blockParents = blockParents\n protected readonly element = inject<ElementRef<HTMLElement>>(ElementRef)\n /** Whether the app loads highlight.js for code, the same on the server and in the browser. */\n protected readonly highlighting = !!inject(NXT_HIGHLIGHT_OPTIONS, { optional: true })\n protected readonly defaultTemplates = viewChildren(RemarkTemplateDirective)\n protected readonly customTemplates = contentChildren(RemarkTemplateDirective)\n protected readonly fallback = viewChild.required<TemplateRef<unknown>>('fallback')\n\n constructor() {\n // A node without a template, e.g. of a plugin, shows its content.\n inject(RemarkTemplatesService).templates = computed(() => {\n const templates: Record<string, TemplateRef<unknown> | undefined> = {}\n for (const template of [...this.defaultTemplates(), ...this.customTemplates()]) {\n templates[template.nodeType()] = template.template\n }\n const fallback = this.fallback()\n return new Proxy(templates, { get: (target, type: string) => target[type] ?? fallback })\n })\n }\n\n /** `auto` for a block of the document, with `autoDirection`, which a block in a quote or a list shares. */\n protected direction(parent: Node) {\n return this.autoDirection() && parent.type === 'root' ? 'auto' : null\n }\n\n protected footnoteId(identifier: string, reference = false) {\n return `${this.id}-${reference ? 'fnref' : 'fn'}-${identifier}`\n }\n\n /** Moves to a footnote in the page, whose address the document's base would otherwise change. */\n protected showFootnote(event: Event, id: string) {\n const target = this.element.nativeElement.querySelector<HTMLElement>(`#${CSS.escape(id)}`)\n if (target) {\n event.preventDefault()\n target.scrollIntoView()\n }\n }\n}\n","<div class=\"uf-contents\"\n [remarkNode]=\"tree()\"></div>\n\n<ng-template #fallback\n let-node>\n @if (node.children) {\n <remark-node [remarkNode]=\"node\" />\n }\n</ng-template>\n\n<!-- Blocks -->\n\n<p *remarkTemplate=\"'paragraph'; let node; let parent = parent\"\n [attr.dir]=\"direction(parent)\"\n [remarkNode]=\"node\"></p>\n\n<ng-template remarkTemplate=\"heading\"\n let-node\n let-parent=\"parent\">\n @let dir = direction(parent);\n @switch (node.depth) {\n @case (1) {\n <h1 [attr.dir]=\"dir\"\n [remarkNode]=\"node\"></h1>\n }\n @case (2) {\n <h2 [attr.dir]=\"dir\"\n [remarkNode]=\"node\"></h2>\n }\n @case (3) {\n <h3 [attr.dir]=\"dir\"\n [remarkNode]=\"node\"></h3>\n }\n @case (4) {\n <h4 [attr.dir]=\"dir\"\n [remarkNode]=\"node\"></h4>\n }\n @case (5) {\n <h5 [attr.dir]=\"dir\"\n [remarkNode]=\"node\"></h5>\n }\n @default {\n <h6 [attr.dir]=\"dir\"\n [remarkNode]=\"node\"></h6>\n }\n }\n</ng-template>\n\n<blockquote *remarkTemplate=\"'blockquote'; let node; let parent = parent\"\n [attr.dir]=\"direction(parent)\"\n [remarkNode]=\"node\"></blockquote>\n\n<ng-template remarkTemplate=\"list\"\n let-node\n let-parent=\"parent\">\n @if (node.ordered) {\n <ol [remarkNode]=\"node\"\n [attr.dir]=\"direction(parent)\"\n [attr.start]=\"node.start === 1 ? null : node.start\"></ol>\n } @else {\n <ul [attr.dir]=\"direction(parent)\"\n [remarkNode]=\"node\"></ul>\n }\n</ng-template>\n\n<ng-template remarkTemplate=\"listItem\"\n let-node>\n @if (node.checked === true || node.checked === false) {\n <li class=\"task-list-item\"\n [class.checked]=\"node.checked\">\n <!-- The state for assistive technology; the box is drawn in the item's styles. -->\n <input type=\"checkbox\"\n class=\"visually-hidden\"\n disabled\n [checked]=\"node.checked\" />\n <remark-node [remarkNode]=\"node\" />\n </li>\n } @else {\n <li [remarkNode]=\"node\"></li>\n }\n</ng-template>\n\n<ng-template remarkTemplate=\"code\"\n let-node>\n @if (highlighting) {\n <pre><code [nxtHighlight]=\"node.value\" [language]=\"node.lang ?? undefined\" [attr.data-language]=\"node.lang\"></code></pre>\n } @else {\n <pre><code [attr.data-language]=\"node.lang\">{{ node.value }}</code></pre>\n }\n</ng-template>\n\n<hr *remarkTemplate=\"'thematicBreak'\" />\n\n<ng-template remarkTemplate=\"html\"\n let-node\n let-parent=\"parent\">\n <!-- Tags in a line of text that aren't paired into an element are left out. -->\n @if (blockParents.has(parent.type)) {\n <div [attr.dir]=\"direction(parent)\"\n [innerHTML]=\"node.value\"></div>\n }\n</ng-template>\n\n<table *remarkTemplate=\"'table'; let node; let parent = parent\"\n [attr.dir]=\"direction(parent)\">\n <thead>\n @if (node.children[0]; as row) {\n <tr>\n @for (cell of row.children; track $index) {\n <th [remarkNode]=\"cell\"\n [style.text-align]=\"node.align?.[$index]\"></th>\n }\n </tr>\n }\n </thead>\n <tbody>\n @for (row of node.children.slice(1); track $index) {\n <tr>\n @for (cell of row.children; track $index) {\n <td [remarkNode]=\"cell\"\n [style.text-align]=\"node.align?.[$index]\"></td>\n }\n </tr>\n }\n </tbody>\n</table>\n\n<section *remarkTemplate=\"'nbFootnotes'; let node; let parent = parent\"\n class=\"nb-markdown-footnotes\"\n [attr.aria-label]=\"texts().footnotes\"\n [attr.dir]=\"direction(parent)\">\n <hr />\n <ol [remarkNode]=\"node\"></ol>\n</section>\n\n<!-- The way back from a footnote to its reference, after its text. -->\n<ng-template remarkTemplate=\"nbFootnoteBack\"\n let-node><a class=\"nb-markdown-footnote-back\"\n [href]=\"'#' + footnoteId(node.identifier, true)\"\n [attr.aria-label]=\"texts().backToText\"\n (click)=\"showFootnote($event, footnoteId(node.identifier, true))\">↩︎</a></ng-template>\n\n<li *remarkTemplate=\"'footnoteDefinition'; let node\"\n [id]=\"footnoteId(node.identifier)\"\n [remarkNode]=\"node\"></li>\n\n<!-- Text -->\n\n<ng-container *remarkTemplate=\"'text'; let node\">{{ node.value }}</ng-container>\n\n<em *remarkTemplate=\"'emphasis'; let node\"\n [remarkNode]=\"node\"></em>\n\n<strong *remarkTemplate=\"'strong'; let node\"\n [remarkNode]=\"node\"></strong>\n\n<del *remarkTemplate=\"'delete'; let node\"\n [remarkNode]=\"node\"></del>\n\n<code *remarkTemplate=\"'inlineCode'; let node\">{{ node.value }}</code>\n\n<br *remarkTemplate=\"'break'\" />\n\n<a *remarkTemplate=\"'link'; let node\"\n [href]=\"node.url\"\n [attr.title]=\"node.title\"\n [remarkNode]=\"node\"></a>\n\n<img *remarkTemplate=\"'image'; let node\"\n [src]=\"node.url\"\n [alt]=\"node.alt ?? ''\"\n [attr.title]=\"node.title\" />\n\n<sup *remarkTemplate=\"'footnoteReference'; let node\">\n <a [id]=\"footnoteId(node.identifier, true)\"\n [href]=\"'#' + footnoteId(node.identifier)\"\n (click)=\"showFootnote($event, footnoteId(node.identifier))\">{{ node.label }}</a>\n</sup>\n\n<ng-template remarkTemplate=\"nbHtmlElement\"\n let-node>\n @switch (htmlElements.has(node.tagName) ? node.tagName : '') {\n @case ('abbr') {\n <abbr [remarkNode]=\"node\"></abbr>\n }\n @case ('b') {\n <b [remarkNode]=\"node\"></b>\n }\n @case ('br') {\n <br />\n }\n @case ('cite') {\n <cite [remarkNode]=\"node\"></cite>\n }\n @case ('code') {\n <code [remarkNode]=\"node\"></code>\n }\n @case ('del') {\n <del [remarkNode]=\"node\"></del>\n }\n @case ('em') {\n <em [remarkNode]=\"node\"></em>\n }\n @case ('i') {\n <i [remarkNode]=\"node\"></i>\n }\n @case ('ins') {\n <ins [remarkNode]=\"node\"></ins>\n }\n @case ('kbd') {\n <kbd [remarkNode]=\"node\"></kbd>\n }\n @case ('mark') {\n <mark [remarkNode]=\"node\"></mark>\n }\n @case ('s') {\n <s [remarkNode]=\"node\"></s>\n }\n @case ('samp') {\n <samp [remarkNode]=\"node\"></samp>\n }\n @case ('small') {\n <small [remarkNode]=\"node\"></small>\n }\n @case ('span') {\n <span [remarkNode]=\"node\"></span>\n }\n @case ('strong') {\n <strong [remarkNode]=\"node\"></strong>\n }\n @case ('sub') {\n <sub [remarkNode]=\"node\"></sub>\n }\n @case ('sup') {\n <sup [remarkNode]=\"node\"></sup>\n }\n @case ('u') {\n <u [remarkNode]=\"node\"></u>\n }\n @case ('var') {\n <var [remarkNode]=\"node\"></var>\n }\n @case ('wbr') {\n <wbr />\n }\n @default {\n <remark-node [remarkNode]=\"node\" />\n }\n }\n</ng-template>\n"],"mappings":";;;;;;;;AAgCA,MAAM,+BAAe,IAAI,IAAI;CAAC;CAAM;CAAO;CAAO;AAAI,CAAC;AACvD,MAAM,aAAa;AACnB,MAAM,iBAAiB;AACvB,MAAM,aAAa;AAEnB,MAAMA,iCAAe,IAAI,IAAI;CAAC;CAAQ;CAAc;CAAY;CAAsB;AAAa,CAAC;AAEpG,SAAS,QAAQ,MAAmB,SAAe;CAC/C,OAAO,KAAK,SAAS,SAAS,QAAQ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AA,CAAA;EAZrC,MAAA;EACa,MAAA,CAAA;GAAA,UAAA;GAAoB,eAGf,kBAAkB;GAAI,iBACpB,wBAAwB;GAAM,WACpC,CAAC,sBAAsB;GAAC,SAC1B;IAAC;IAAqB;IAAyB;GAAkB;GAAC,MACrE,EACF,OAAO,cACV;GAAA,UAAA;GAAA,QAAA,CAAA,srcAAA;EAAA,CAAA;CA0BkD,CAAA;CAAA,sBAAA,CAAA;CAAA,gBAAA;EAAA,UAAA,CAAA;GAAA,MAAA,GAAA;GAAA,MAAA,CAAA;IAAA,UAAA;IAAA,OAAA;IAAA,UAAA;GAAA,CAAA;EAAA,CAAA;EAAA,WAAA,CAAA;GAAA,MAAA,GAAA;GAAA,MAAA,CAAA;IAAA,UAAA;IAAA,OAAA;IAAA,UAAA;GAAA,CAAA;EAAA,CAAA;EAAA,eAAA,CAAA;GAAA,MAAA,GAAA;GAAA,MAAA,CAAA;IAAA,UAAA;IAAA,OAAA;IAAA,UAAA;GAAA,CAAA;EAAA,CAAA;EAAA,kBAAA,CAAA;GAAA,MAAA,GAAA;GAAA,MAAA,CAAA,GAAA,iBAAA,uBAAuB,GAAA,EAAA,UAAA,KAAA,CAAA;EAAA,CAAA;EAAA,iBAAA,CAAA;GAAA,MAAA,GAAA;GAAA,MAAA,CAAA,GAAA,iBACrB,uBAAuB,GAAA,EAAA,UAAA,KAAA,CAAA;EAAA,CAAA;EAAA,UAAA,CAAA;GAAA,MAAA,GAAA;GAAA,MAAA,CACL,YAAU,EAAA,UAAA,KAAA,CAAA;EAAA,CAAA;CAAA;AAAA,CAAA"}
|
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
import * as i0 from "@angular/core";
|
|
2
|
+
import { DestroyRef, Directive, ElementRef, PLATFORM_ID, computed, effect, forwardRef, inject, input, signal, untracked } from "@angular/core";
|
|
3
|
+
import { isPlatformBrowser } from "@angular/common";
|
|
4
|
+
import { NG_VALIDATORS, NG_VALUE_ACCESSOR } from "@angular/forms";
|
|
5
|
+
import { injectNbTexts, injectNbValidationMessage } from "@liquid-js/lyr-core";
|
|
6
|
+
import { Mask, MaskInput } from "maska";
|
|
7
|
+
function injectNbMaskTexts() {
|
|
8
|
+
return injectNbTexts("mask", () => ({ incomplete: $localize`:@@nb.mask.incomplete:Complete the value` }));
|
|
9
|
+
}
|
|
10
|
+
const NB_MASK_ERROR = "nbMask";
|
|
11
|
+
var NbMaskDirective = class NbMaskDirective {
|
|
12
|
+
constructor() {
|
|
13
|
+
this.texts = injectNbMaskTexts();
|
|
14
|
+
this.message = injectNbValidationMessage();
|
|
15
|
+
this.element = inject(ElementRef).nativeElement;
|
|
16
|
+
this.mask = input.required({
|
|
17
|
+
...ngDevMode ? { debugName: "mask" } : /* istanbul ignore next */ {},
|
|
18
|
+
alias: "nbMask"
|
|
19
|
+
});
|
|
20
|
+
this.options = input({}, {
|
|
21
|
+
...ngDevMode ? { debugName: "options" } : /* istanbul ignore next */ {},
|
|
22
|
+
alias: "nbMaskOptions"
|
|
23
|
+
});
|
|
24
|
+
this.valueType = input("unmasked", {
|
|
25
|
+
...ngDevMode ? { debugName: "valueType" } : /* istanbul ignore next */ {},
|
|
26
|
+
alias: "nbMaskValue"
|
|
27
|
+
});
|
|
28
|
+
this.completed = signal(false, ...ngDevMode ? [{ debugName: "completed" }] : /* istanbul ignore next */ []);
|
|
29
|
+
this.parseError = signal(false, ...ngDevMode ? [{ debugName: "parseError" }] : /* istanbul ignore next */ []);
|
|
30
|
+
this.formatter = computed(() => {
|
|
31
|
+
const { preProcess, postProcess, ...options } = this.options();
|
|
32
|
+
const mask = new Mask({
|
|
33
|
+
...options,
|
|
34
|
+
mask: this.mask()
|
|
35
|
+
});
|
|
36
|
+
return {
|
|
37
|
+
mask,
|
|
38
|
+
masked: (value) => {
|
|
39
|
+
const text = mask.masked(preProcess ? preProcess(value) : value);
|
|
40
|
+
return postProcess ? postProcess(text) : text;
|
|
41
|
+
},
|
|
42
|
+
unmasked: (value) => mask.unmasked(preProcess ? preProcess(value) : value),
|
|
43
|
+
completed: (value) => options.number || this.mask() === null ? true : mask.completed(preProcess ? preProcess(value) : value)
|
|
44
|
+
};
|
|
45
|
+
}, ...ngDevMode ? [{ debugName: "formatter" }] : /* istanbul ignore next */ []);
|
|
46
|
+
this.value = "";
|
|
47
|
+
this.onChange = () => {};
|
|
48
|
+
this.onTouched = () => {};
|
|
49
|
+
this.onValidatorChange = () => {};
|
|
50
|
+
const browser = isPlatformBrowser(inject(PLATFORM_ID));
|
|
51
|
+
let started = false;
|
|
52
|
+
effect(() => {
|
|
53
|
+
const options = {
|
|
54
|
+
...this.options(),
|
|
55
|
+
mask: this.mask(),
|
|
56
|
+
onMaska: (detail) => this.changed(detail)
|
|
57
|
+
};
|
|
58
|
+
this.valueType();
|
|
59
|
+
untracked(() => {
|
|
60
|
+
if (browser) {
|
|
61
|
+
if (this.maskInput) this.maskInput.update(options);
|
|
62
|
+
else this.maskInput = new MaskInput(this.element, options);
|
|
63
|
+
}
|
|
64
|
+
this.show(this.value);
|
|
65
|
+
if (started) this.take(this.element.value);
|
|
66
|
+
started = true;
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
inject(DestroyRef).onDestroy(() => this.maskInput?.destroy());
|
|
70
|
+
}
|
|
71
|
+
writeValue(value) {
|
|
72
|
+
const text = String(value ?? "");
|
|
73
|
+
this.value = text;
|
|
74
|
+
this.show(text);
|
|
75
|
+
this.setParseError(false);
|
|
76
|
+
}
|
|
77
|
+
registerOnChange(fn) {
|
|
78
|
+
this.onChange = fn;
|
|
79
|
+
}
|
|
80
|
+
registerOnTouched(fn) {
|
|
81
|
+
this.onTouched = fn;
|
|
82
|
+
}
|
|
83
|
+
registerOnValidatorChange(fn) {
|
|
84
|
+
this.onValidatorChange = fn;
|
|
85
|
+
}
|
|
86
|
+
setDisabledState(disabled) {
|
|
87
|
+
this.element.disabled = disabled;
|
|
88
|
+
}
|
|
89
|
+
validate() {
|
|
90
|
+
if (!this.parseError()) return null;
|
|
91
|
+
const error = {
|
|
92
|
+
kind: NB_MASK_ERROR,
|
|
93
|
+
message: this.texts().incomplete
|
|
94
|
+
};
|
|
95
|
+
return { [NB_MASK_ERROR]: {
|
|
96
|
+
...error,
|
|
97
|
+
message: this.message({
|
|
98
|
+
kind: NB_MASK_ERROR,
|
|
99
|
+
params: error
|
|
100
|
+
})
|
|
101
|
+
} };
|
|
102
|
+
}
|
|
103
|
+
show(value) {
|
|
104
|
+
const formatter = this.formatter();
|
|
105
|
+
const masked = value ? formatter.masked(value) : "";
|
|
106
|
+
this.element.value = masked;
|
|
107
|
+
this.completed.set(!!masked && formatter.completed(masked));
|
|
108
|
+
}
|
|
109
|
+
changed(detail) {
|
|
110
|
+
this.take(detail.masked);
|
|
111
|
+
}
|
|
112
|
+
take(masked) {
|
|
113
|
+
const formatter = this.formatter();
|
|
114
|
+
const unmasked = formatter.unmasked(masked);
|
|
115
|
+
const completed = !!unmasked && formatter.completed(masked);
|
|
116
|
+
this.completed.set(completed);
|
|
117
|
+
this.setParseError(!!unmasked && !completed);
|
|
118
|
+
if (unmasked && !completed) return;
|
|
119
|
+
const value = !unmasked ? "" : this.valueType() === "masked" ? masked : unmasked;
|
|
120
|
+
if (value !== this.value) {
|
|
121
|
+
this.value = value;
|
|
122
|
+
this.onChange(value);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
setParseError(parseError) {
|
|
126
|
+
if (parseError !== this.parseError()) {
|
|
127
|
+
this.parseError.set(parseError);
|
|
128
|
+
this.onValidatorChange();
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
static {
|
|
132
|
+
this.ɵfac = i0.ɵɵngDeclareFactory({
|
|
133
|
+
minVersion: "12.0.0",
|
|
134
|
+
version: "22.3.0",
|
|
135
|
+
ngImport: i0,
|
|
136
|
+
type: NbMaskDirective,
|
|
137
|
+
deps: [],
|
|
138
|
+
target: i0.ɵɵFactoryTarget.Directive
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
static {
|
|
142
|
+
this.ɵdir = i0.ɵɵngDeclareDirective({
|
|
143
|
+
minVersion: "17.1.0",
|
|
144
|
+
version: "22.3.0",
|
|
145
|
+
type: NbMaskDirective,
|
|
146
|
+
isStandalone: true,
|
|
147
|
+
selector: "input[nbMask]",
|
|
148
|
+
inputs: {
|
|
149
|
+
mask: {
|
|
150
|
+
classPropertyName: "mask",
|
|
151
|
+
publicName: "nbMask",
|
|
152
|
+
isSignal: true,
|
|
153
|
+
isRequired: true,
|
|
154
|
+
transformFunction: null
|
|
155
|
+
},
|
|
156
|
+
options: {
|
|
157
|
+
classPropertyName: "options",
|
|
158
|
+
publicName: "nbMaskOptions",
|
|
159
|
+
isSignal: true,
|
|
160
|
+
isRequired: false,
|
|
161
|
+
transformFunction: null
|
|
162
|
+
},
|
|
163
|
+
valueType: {
|
|
164
|
+
classPropertyName: "valueType",
|
|
165
|
+
publicName: "nbMaskValue",
|
|
166
|
+
isSignal: true,
|
|
167
|
+
isRequired: false,
|
|
168
|
+
transformFunction: null
|
|
169
|
+
}
|
|
170
|
+
},
|
|
171
|
+
host: { listeners: { "blur": "onTouched()" } },
|
|
172
|
+
providers: [{
|
|
173
|
+
provide: NG_VALUE_ACCESSOR,
|
|
174
|
+
useExisting: forwardRef(() => NbMaskDirective),
|
|
175
|
+
multi: true
|
|
176
|
+
}, {
|
|
177
|
+
provide: NG_VALIDATORS,
|
|
178
|
+
useExisting: forwardRef(() => NbMaskDirective),
|
|
179
|
+
multi: true
|
|
180
|
+
}],
|
|
181
|
+
exportAs: ["nbMask"],
|
|
182
|
+
ngImport: i0
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
};
|
|
186
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
187
|
+
minVersion: "12.0.0",
|
|
188
|
+
version: "22.3.0",
|
|
189
|
+
ngImport: i0,
|
|
190
|
+
type: NbMaskDirective,
|
|
191
|
+
decorators: [{
|
|
192
|
+
type: Directive,
|
|
193
|
+
args: [{
|
|
194
|
+
selector: "input[nbMask]",
|
|
195
|
+
exportAs: "nbMask",
|
|
196
|
+
providers: [{
|
|
197
|
+
provide: NG_VALUE_ACCESSOR,
|
|
198
|
+
useExisting: forwardRef(() => NbMaskDirective),
|
|
199
|
+
multi: true
|
|
200
|
+
}, {
|
|
201
|
+
provide: NG_VALIDATORS,
|
|
202
|
+
useExisting: forwardRef(() => NbMaskDirective),
|
|
203
|
+
multi: true
|
|
204
|
+
}],
|
|
205
|
+
host: { "(blur)": "onTouched()" }
|
|
206
|
+
}]
|
|
207
|
+
}],
|
|
208
|
+
ctorParameters: () => [],
|
|
209
|
+
propDecorators: {
|
|
210
|
+
mask: [{
|
|
211
|
+
type: i0.Input,
|
|
212
|
+
args: [{
|
|
213
|
+
isSignal: true,
|
|
214
|
+
alias: "nbMask",
|
|
215
|
+
required: true
|
|
216
|
+
}]
|
|
217
|
+
}],
|
|
218
|
+
options: [{
|
|
219
|
+
type: i0.Input,
|
|
220
|
+
args: [{
|
|
221
|
+
isSignal: true,
|
|
222
|
+
alias: "nbMaskOptions",
|
|
223
|
+
required: false
|
|
224
|
+
}]
|
|
225
|
+
}],
|
|
226
|
+
valueType: [{
|
|
227
|
+
type: i0.Input,
|
|
228
|
+
args: [{
|
|
229
|
+
isSignal: true,
|
|
230
|
+
alias: "nbMaskValue",
|
|
231
|
+
required: false
|
|
232
|
+
}]
|
|
233
|
+
}]
|
|
234
|
+
}
|
|
235
|
+
});
|
|
236
|
+
export { NB_MASK_ERROR, NbMaskDirective };
|
|
237
|
+
|
|
238
|
+
//# sourceMappingURL=liquid-js-lyr-extras-mask.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"liquid-js-lyr-extras-mask.mjs","names":[],"sources":["../../../packages/extras/mask/src/texts.ts","../../../packages/extras/mask/src/mask.directive.ts"],"sourcesContent":["import { injectNbTexts, NbLocalize } from '@liquid-js/lyr-core'\n\n/** @internal */\ndeclare const $localize: NbLocalize\n\n/**\n * The texts of masked fields. `provideNbTexts({ mask: { ... } })` changes them, and they're translated with Angular's\n * i18n, as `$localize` messages with ids like `@@nb.mask.incomplete`.\n */\nexport interface NbMaskTexts {\n /** The message of the `nbMask` error for a value that doesn't fill the mask. */\n incomplete: string\n}\n\ndeclare module '@liquid-js/lyr-core' {\n interface NbTexts {\n mask: NbMaskTexts\n }\n}\n\n/** @internal */\nexport function injectNbMaskTexts() {\n return injectNbTexts('mask', () => ({\n incomplete: $localize`:@@nb.mask.incomplete:Complete the value`\n }))\n}\n","import {\n computed,\n DestroyRef,\n Directive,\n effect,\n ElementRef,\n forwardRef,\n inject,\n input,\n PLATFORM_ID,\n signal,\n untracked\n} from '@angular/core'\nimport { isPlatformBrowser } from '@angular/common'\nimport {\n ControlValueAccessor,\n NG_VALIDATORS,\n NG_VALUE_ACCESSOR,\n ValidationErrors,\n Validator\n} from '@angular/forms'\nimport { injectNbValidationMessage } from '@liquid-js/lyr-core'\nimport { Mask, MaskaDetail, MaskInput, MaskInputOptions, MaskType } from 'maska'\n\nimport { injectNbMaskTexts } from './texts'\n\n/** The form value of a masked field: the characters typed (`unmasked`, default), or the text as shown (`masked`). */\nexport type NbMaskValue = 'unmasked' | 'masked'\n\n/** The error kind of a value that doesn't fill the mask. */\nexport const NB_MASK_ERROR = 'nbMask' as const\n\n/** The `nbMask` error, as Angular gives parse errors: its kind and its message. */\nexport interface NbMaskError {\n kind: typeof NB_MASK_ERROR\n message: string\n}\n\n/** maska's options besides the mask: `tokens`, `eager`, `reversed`, `number`, `preProcess` and `postProcess`. */\nexport type NbMaskOptions = Omit<MaskInputOptions, 'mask' | 'onMaska'>\n\n/**\n * Formats what the user types in a field with a mask, e.g. a phone number or a card number:\n *\n * ```html\n * <input nbInput type=\"tel\" [nbMask]=\"'(###) ###-####'\" formControlName=\"phone\" />\n * ```\n *\n * @stacked-example(Showcase, mask/mask-showcase.component)\n *\n * ### Installation\n *\n * It formats with [`maska`](https://www.npmjs.com/package/maska); install it and import `NbMaskDirective` from\n * `@liquid-js/lyr-extras/mask`.\n *\n * ```sh\n * npm install maska\n * ```\n *\n * ### Usage\n *\n * In the mask, `#` is a digit, `@` a letter and `*` either; other characters are shown as they are. A list of masks\n * picks the one that fits the length of what's typed, e.g. `['#### ####', '#### #### ####']`, and a function gives\n * the mask for what's typed. `nbMaskOptions` takes maska's other options, e.g. `eager` to show the mask's next\n * characters before they're typed, `tokens` of your own, or `number` for numbers in the app's format.\n *\n * The form value is what the user typed, without the mask's characters, e.g. `2015550123`, or with\n * `nbMaskValue=\"masked\"`, the text as shown, `(201) 555-0123`. While the text doesn't fill the mask, the value stays\n * the last complete one, or empty, and the field has the `nbMask` parse error, `{ kind, message }`, as Angular's\n * controls report text they can't parse; an empty field passes. It works with `formControl`, `formControlName`,\n * `ngModel` and signal forms' `[formField]`.\n * @stacked-example(Validation, mask/mask-validation.component)\n *\n * It works on text, search, URL, phone and password inputs.\n */\n@Directive({\n selector: 'input[nbMask]',\n exportAs: 'nbMask',\n providers: [\n { provide: NG_VALUE_ACCESSOR, useExisting: forwardRef(() => NbMaskDirective), multi: true },\n { provide: NG_VALIDATORS, useExisting: forwardRef(() => NbMaskDirective), multi: true }\n ],\n host: {\n '(blur)': 'onTouched()'\n }\n})\nexport class NbMaskDirective implements ControlValueAccessor, Validator {\n protected readonly texts = injectNbMaskTexts()\n /** The message of an error, as `nb-validation-errors` shows it. */\n protected readonly message = injectNbValidationMessage()\n protected readonly element = inject<ElementRef<HTMLInputElement>>(ElementRef).nativeElement\n\n /** The mask, e.g. `(###) ###-####`, a list of masks, or a function that gives the mask for what's typed. */\n readonly mask = input.required<MaskType>({ alias: 'nbMask' })\n /** maska's other options, e.g. `{ eager: true }`. */\n readonly options = input<NbMaskOptions>({}, { alias: 'nbMaskOptions' })\n /** The form value: `unmasked` (default), what was typed, or `masked`, the text as shown. */\n readonly valueType = input<NbMaskValue>('unmasked', { alias: 'nbMaskValue' })\n\n /** Whether the text fills the mask. */\n readonly completed = signal(false)\n /** Whether the text doesn't fill the mask, which the form gets as a parse error. */\n protected readonly parseError = signal(false)\n\n /** Formats values the way the field does. */\n protected readonly formatter = computed(() => {\n const { preProcess, postProcess, ...options } = this.options()\n const mask = new Mask({ ...options, mask: this.mask() })\n return {\n mask,\n masked: (value: string) => {\n const text = mask.masked(preProcess ? preProcess(value) : value)\n return postProcess ? postProcess(text) : text\n },\n unmasked: (value: string) => mask.unmasked(preProcess ? preProcess(value) : value),\n // A number, or no mask, has no length to fill.\n completed: (value: string) =>\n options.number || this.mask() === null ? true : mask.completed(preProcess ? preProcess(value) : value)\n }\n })\n\n protected maskInput?: MaskInput\n /** The value last given to the form. */\n protected value = ''\n\n protected onChange: (value: string) => void = () => {}\n /** @internal */\n onTouched: () => void = () => {}\n protected onValidatorChange: () => void = () => {}\n\n constructor() {\n const browser = isPlatformBrowser(inject(PLATFORM_ID))\n let started = false\n effect(() => {\n const options: MaskInputOptions = {\n ...this.options(),\n mask: this.mask(),\n onMaska: (detail) => this.changed(detail)\n }\n // Read for the mask's options, which change what the value is.\n this.valueType()\n untracked(() => {\n if (browser) {\n if (this.maskInput) {\n this.maskInput.update(options)\n } else {\n this.maskInput = new MaskInput(this.element, options)\n }\n }\n this.show(this.value)\n // A new mask or kind of value changes the value, which the first run only shows.\n if (started) {\n this.take(this.element.value)\n }\n started = true\n })\n })\n inject(DestroyRef).onDestroy(() => this.maskInput?.destroy())\n }\n\n writeValue(value?: string | number | null) {\n const text = String(value ?? '')\n this.value = text\n this.show(text)\n this.setParseError(false)\n }\n\n registerOnChange(fn: (value: string) => void) {\n this.onChange = fn\n }\n\n registerOnTouched(fn: () => void) {\n this.onTouched = fn\n }\n\n registerOnValidatorChange(fn: () => void) {\n this.onValidatorChange = fn\n }\n\n setDisabledState(disabled: boolean) {\n this.element.disabled = disabled\n }\n\n /** The parse error of text that doesn't fill the mask. */\n validate(): ValidationErrors | null {\n if (!this.parseError()) {\n return null\n }\n // The app's message for the kind, or the mask's text.\n const error: NbMaskError = { kind: NB_MASK_ERROR, message: this.texts().incomplete }\n return { [NB_MASK_ERROR]: { ...error, message: this.message({ kind: NB_MASK_ERROR, params: error }) } }\n }\n\n /** Shows a form value in the field, formatted. */\n protected show(value: string) {\n const formatter = this.formatter()\n const masked = value ? formatter.masked(value) : ''\n this.element.value = masked\n this.completed.set(!!masked && formatter.completed(masked))\n }\n\n protected changed(detail: MaskaDetail) {\n this.take(detail.masked)\n }\n\n /**\n * Gives the form the value of the text in the field, when it's another; while the text doesn't fill the mask, the\n * value stays and the field has the parse error.\n */\n protected take(masked: string) {\n const formatter = this.formatter()\n const unmasked = formatter.unmasked(masked)\n const completed = !!unmasked && formatter.completed(masked)\n this.completed.set(completed)\n this.setParseError(!!unmasked && !completed)\n if (unmasked && !completed) {\n return\n }\n const value = !unmasked ? '' : this.valueType() === 'masked' ? masked : unmasked\n if (value !== this.value) {\n this.value = value\n this.onChange(value)\n }\n }\n\n protected setParseError(parseError: boolean) {\n if (parseError !== this.parseError()) {\n this.parseError.set(parseError)\n this.onValidatorChange()\n }\n }\n}\n"],"mappings":";;;;;;AAqBA,SAAgB,oBAAiB;CAC7B,OAAO,cAAc,eAAe,EAChC,YAAY,SAAS,2CACxB,EAAC;AACN;ACKA,MAAa,gBAAgB;AAwD7B,IAAa,kBAAb,MAAa,gBAAe;CA4CxB,cAAA;EA3CmB,KAAA,QAAQ,kBAAiB;EAEzB,KAAA,UAAU,0BAAyB;EACnC,KAAA,UAAU,OAAqC,UAAU,CAAC,CAAC;EAGrE,KAAA,OAAO,MAAM,SAAQ;GAAA,GAAA,YAAA,EAAA,WAAA,OAAA,+BAAA,CAAA;GAAa,OAAO;EAAQ,CAAA;EAEjD,KAAA,UAAU,MAAqB,CAAA,GAAE;GAAA,GAAA,YAAA,EAAA,WAAA,UAAA,+BAAA,CAAA;GAAI,OAAO;EAAe,CAAA;EAE3D,KAAA,YAAY,MAAmB,YAAU;GAAA,GAAA,YAAA,EAAA,WAAA,YAAA,+BAAA,CAAA;GAAI,OAAO;EAAa,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