UNPKG

vue-files-preview-inno

Version:

A tool for previewing files such as doc, excel, pdf, image, markdown, txt, audio, and video and so on.

673 lines (672 loc) 20.1 kB
import { configureNesting as q, parser as R } from "../../../@lezer/html/dist/index.mjs"; import { cssLanguage as _, css as H } from "../../lang-css/dist/index.mjs"; import { typescriptLanguage as U, jsxLanguage as W, tsxLanguage as J, javascriptLanguage as E, javascript as K } from "../../lang-javascript/dist/index.mjs"; import { EditorView as Q } from "../../view/dist/index.mjs"; import { EditorSelection as X } from "../../state/dist/index.mjs"; import { LRLanguage as Y, LanguageSupport as Z, indentNodeProp as ee, foldNodeProp as te, bracketMatchingHandle as le, syntaxTree as z } from "../../language/dist/index.mjs"; const T = ["_blank", "_self", "_top", "_parent"], S = ["ascii", "utf-8", "utf-16", "latin1", "latin1"], N = ["get", "post", "put", "delete"], j = ["application/x-www-form-urlencoded", "multipart/form-data", "text/plain"], p = ["true", "false"], l = {}, ae = { a: { attrs: { href: null, ping: null, type: null, media: null, target: T, hreflang: null } }, abbr: l, address: l, area: { attrs: { alt: null, coords: null, href: null, target: null, ping: null, media: null, hreflang: null, type: null, shape: ["default", "rect", "circle", "poly"] } }, article: l, aside: l, audio: { attrs: { src: null, mediagroup: null, crossorigin: ["anonymous", "use-credentials"], preload: ["none", "metadata", "auto"], autoplay: ["autoplay"], loop: ["loop"], controls: ["controls"] } }, b: l, base: { attrs: { href: null, target: T } }, bdi: l, bdo: l, blockquote: { attrs: { cite: null } }, body: l, br: l, button: { attrs: { form: null, formaction: null, name: null, value: null, autofocus: ["autofocus"], disabled: ["autofocus"], formenctype: j, formmethod: N, formnovalidate: ["novalidate"], formtarget: T, type: ["submit", "reset", "button"] } }, canvas: { attrs: { width: null, height: null } }, caption: l, center: l, cite: l, code: l, col: { attrs: { span: null } }, colgroup: { attrs: { span: null } }, command: { attrs: { type: ["command", "checkbox", "radio"], label: null, icon: null, radiogroup: null, command: null, title: null, disabled: ["disabled"], checked: ["checked"] } }, data: { attrs: { value: null } }, datagrid: { attrs: { disabled: ["disabled"], multiple: ["multiple"] } }, datalist: { attrs: { data: null } }, dd: l, del: { attrs: { cite: null, datetime: null } }, details: { attrs: { open: ["open"] } }, dfn: l, div: l, dl: l, dt: l, em: l, embed: { attrs: { src: null, type: null, width: null, height: null } }, eventsource: { attrs: { src: null } }, fieldset: { attrs: { disabled: ["disabled"], form: null, name: null } }, figcaption: l, figure: l, footer: l, form: { attrs: { action: null, name: null, "accept-charset": S, autocomplete: ["on", "off"], enctype: j, method: N, novalidate: ["novalidate"], target: T } }, h1: l, h2: l, h3: l, h4: l, h5: l, h6: l, head: { children: ["title", "base", "link", "style", "meta", "script", "noscript", "command"] }, header: l, hgroup: l, hr: l, html: { attrs: { manifest: null } }, i: l, iframe: { attrs: { src: null, srcdoc: null, name: null, width: null, height: null, sandbox: ["allow-top-navigation", "allow-same-origin", "allow-forms", "allow-scripts"], seamless: ["seamless"] } }, img: { attrs: { alt: null, src: null, ismap: null, usemap: null, width: null, height: null, crossorigin: ["anonymous", "use-credentials"] } }, input: { attrs: { alt: null, dirname: null, form: null, formaction: null, height: null, list: null, max: null, maxlength: null, min: null, name: null, pattern: null, placeholder: null, size: null, src: null, step: null, value: null, width: null, accept: ["audio/*", "video/*", "image/*"], autocomplete: ["on", "off"], autofocus: ["autofocus"], checked: ["checked"], disabled: ["disabled"], formenctype: j, formmethod: N, formnovalidate: ["novalidate"], formtarget: T, multiple: ["multiple"], readonly: ["readonly"], required: ["required"], type: [ "hidden", "text", "search", "tel", "url", "email", "password", "datetime", "date", "month", "week", "time", "datetime-local", "number", "range", "color", "checkbox", "radio", "file", "submit", "image", "reset", "button" ] } }, ins: { attrs: { cite: null, datetime: null } }, kbd: l, keygen: { attrs: { challenge: null, form: null, name: null, autofocus: ["autofocus"], disabled: ["disabled"], keytype: ["RSA"] } }, label: { attrs: { for: null, form: null } }, legend: l, li: { attrs: { value: null } }, link: { attrs: { href: null, type: null, hreflang: null, media: null, sizes: ["all", "16x16", "16x16 32x32", "16x16 32x32 64x64"] } }, map: { attrs: { name: null } }, mark: l, menu: { attrs: { label: null, type: ["list", "context", "toolbar"] } }, meta: { attrs: { content: null, charset: S, name: ["viewport", "application-name", "author", "description", "generator", "keywords"], "http-equiv": ["content-language", "content-type", "default-style", "refresh"] } }, meter: { attrs: { value: null, min: null, low: null, high: null, max: null, optimum: null } }, nav: l, noscript: l, object: { attrs: { data: null, type: null, name: null, usemap: null, form: null, width: null, height: null, typemustmatch: ["typemustmatch"] } }, ol: { attrs: { reversed: ["reversed"], start: null, type: ["1", "a", "A", "i", "I"] }, children: ["li", "script", "template", "ul", "ol"] }, optgroup: { attrs: { disabled: ["disabled"], label: null } }, option: { attrs: { disabled: ["disabled"], label: null, selected: ["selected"], value: null } }, output: { attrs: { for: null, form: null, name: null } }, p: l, param: { attrs: { name: null, value: null } }, pre: l, progress: { attrs: { value: null, max: null } }, q: { attrs: { cite: null } }, rp: l, rt: l, ruby: l, samp: l, script: { attrs: { type: ["text/javascript"], src: null, async: ["async"], defer: ["defer"], charset: S } }, section: l, select: { attrs: { form: null, name: null, size: null, autofocus: ["autofocus"], disabled: ["disabled"], multiple: ["multiple"] } }, slot: { attrs: { name: null } }, small: l, source: { attrs: { src: null, type: null, media: null } }, span: l, strong: l, style: { attrs: { type: ["text/css"], media: null, scoped: null } }, sub: l, summary: l, sup: l, table: l, tbody: l, td: { attrs: { colspan: null, rowspan: null, headers: null } }, template: l, textarea: { attrs: { dirname: null, form: null, maxlength: null, name: null, placeholder: null, rows: null, cols: null, autofocus: ["autofocus"], disabled: ["disabled"], readonly: ["readonly"], required: ["required"], wrap: ["soft", "hard"] } }, tfoot: l, th: { attrs: { colspan: null, rowspan: null, headers: null, scope: ["row", "col", "rowgroup", "colgroup"] } }, thead: l, time: { attrs: { datetime: null } }, title: l, tr: l, track: { attrs: { src: null, label: null, default: null, kind: ["subtitles", "captions", "descriptions", "chapters", "metadata"], srclang: null } }, ul: { children: ["li", "script", "template", "ul", "ol"] }, var: l, video: { attrs: { src: null, poster: null, width: null, height: null, crossorigin: ["anonymous", "use-credentials"], preload: ["auto", "metadata", "none"], autoplay: ["autoplay"], mediagroup: ["movie"], muted: ["muted"], controls: ["controls"] } }, wbr: l }, D = { accesskey: null, class: null, contenteditable: p, contextmenu: null, dir: ["ltr", "rtl", "auto"], draggable: ["true", "false", "auto"], dropzone: ["copy", "move", "link", "string:", "file:"], hidden: ["hidden"], id: null, inert: ["inert"], itemid: null, itemprop: null, itemref: null, itemscope: ["itemscope"], itemtype: null, lang: ["ar", "bn", "de", "en-GB", "en-US", "es", "fr", "hi", "id", "ja", "pa", "pt", "ru", "tr", "zh"], spellcheck: p, autocorrect: p, autocapitalize: p, style: null, tabindex: null, title: null, translate: ["yes", "no"], rel: ["stylesheet", "alternate", "author", "bookmark", "help", "license", "next", "nofollow", "noreferrer", "prefetch", "prev", "search", "tag"], role: /* @__PURE__ */ "alert application article banner button cell checkbox complementary contentinfo dialog document feed figure form grid gridcell heading img list listbox listitem main navigation region row rowgroup search switch tab table tabpanel textbox timer".split(" "), "aria-activedescendant": null, "aria-atomic": p, "aria-autocomplete": ["inline", "list", "both", "none"], "aria-busy": p, "aria-checked": ["true", "false", "mixed", "undefined"], "aria-controls": null, "aria-describedby": null, "aria-disabled": p, "aria-dropeffect": null, "aria-expanded": ["true", "false", "undefined"], "aria-flowto": null, "aria-grabbed": ["true", "false", "undefined"], "aria-haspopup": p, "aria-hidden": p, "aria-invalid": ["true", "false", "grammar", "spelling"], "aria-label": null, "aria-labelledby": null, "aria-level": null, "aria-live": ["off", "polite", "assertive"], "aria-multiline": p, "aria-multiselectable": p, "aria-owns": null, "aria-posinset": null, "aria-pressed": ["true", "false", "mixed", "undefined"], "aria-readonly": p, "aria-relevant": null, "aria-required": p, "aria-selected": ["true", "false", "undefined"], "aria-setsize": null, "aria-sort": ["ascending", "descending", "none", "other"], "aria-valuemax": null, "aria-valuemin": null, "aria-valuenow": null, "aria-valuetext": null }, F = /* @__PURE__ */ "beforeunload copy cut dragstart dragover dragleave dragenter dragend drag paste focus blur change click load mousedown mouseenter mouseleave mouseup keydown keyup resize scroll unload".split(" ").map((e) => "on" + e); for (let e of F) D[e] = null; class x { constructor(n, r) { this.tags = Object.assign(Object.assign({}, ae), n), this.globalAttrs = Object.assign(Object.assign({}, D), r), this.allTags = Object.keys(this.tags), this.globalAttrNames = Object.keys(this.globalAttrs); } } x.default = /* @__PURE__ */ new x(); function y(e, n, r = e.length) { if (!n) return ""; let a = n.firstChild, t = a && a.getChild("TagName"); return t ? e.sliceString(t.from, Math.min(t.to, r)) : ""; } function v(e, n = !1) { for (; e; e = e.parent) if (e.name == "Element") if (n) n = !1; else return e; return null; } function P(e, n, r) { let a = r.tags[y(e, v(n))]; return (a == null ? void 0 : a.children) || r.allTags; } function $(e, n) { let r = []; for (let a = v(n); a && !a.type.isTop; a = v(a.parent)) { let t = y(e, a); if (t && a.lastChild.name == "CloseTag") break; t && r.indexOf(t) < 0 && (n.name == "EndTag" || n.from >= a.firstChild.to) && r.push(t); } return r; } const V = /^[:\-\.\w\u00b7-\uffff]*$/; function O(e, n, r, a, t) { let o = /\s*>/.test(e.sliceDoc(t, t + 5)) ? "" : ">", s = v(r, !0); return { from: a, to: t, options: P(e.doc, s, n).map((u) => ({ label: u, type: "type" })).concat($(e.doc, r).map((u, i) => ({ label: "/" + u, apply: "/" + u + o, type: "type", boost: 99 - i }))), validFor: /^\/?[:\-\.\w\u00b7-\uffff]*$/ }; } function L(e, n, r, a) { let t = /\s*>/.test(e.sliceDoc(a, a + 5)) ? "" : ">"; return { from: r, to: a, options: $(e.doc, n).map((o, s) => ({ label: o, apply: o + t, type: "type", boost: 99 - s })), validFor: V }; } function ne(e, n, r, a) { let t = [], o = 0; for (let s of P(e.doc, r, n)) t.push({ label: "<" + s, type: "type" }); for (let s of $(e.doc, r)) t.push({ label: "</" + s + ">", type: "type", boost: 99 - o++ }); return { from: a, to: a, options: t, validFor: /^<\/?[:\-\.\w\u00b7-\uffff]*$/ }; } function re(e, n, r, a, t) { let o = v(r), s = o ? n.tags[y(e.doc, o)] : null, u = s && s.attrs ? Object.keys(s.attrs) : [], i = s && s.globalAttrs === !1 ? u : u.length ? u.concat(n.globalAttrNames) : n.globalAttrNames; return { from: a, to: t, options: i.map((f) => ({ label: f, type: "property" })), validFor: V }; } function se(e, n, r, a, t) { var o; let s = (o = r.parent) === null || o === void 0 ? void 0 : o.getChild("AttributeName"), u = [], i; if (s) { let f = e.sliceDoc(s.from, s.to), g = n.globalAttrs[f]; if (!g) { let c = v(r), m = c ? n.tags[y(e.doc, c)] : null; g = (m == null ? void 0 : m.attrs) && m.attrs[f]; } if (g) { let c = e.sliceDoc(a, t).toLowerCase(), m = '"', d = '"'; /^['"]/.test(c) ? (i = c[0] == '"' ? /^[^"]*$/ : /^[^']*$/, m = "", d = e.sliceDoc(t, t + 1) == c[0] ? "" : c[0], c = c.slice(1), a++) : i = /^[^\s<>='"]*$/; for (let h of g) u.push({ label: h, apply: m + h + d, type: "constant" }); } } return { from: a, to: t, options: u, validFor: i }; } function oe(e, n) { let { state: r, pos: a } = n, t = z(r).resolveInner(a, -1), o = t.resolve(a); for (let s = a, u; o == t && (u = t.childBefore(s)); ) { let i = u.lastChild; if (!i || !i.type.isError || i.from < i.to) break; o = t = u, s = i.from; } return t.name == "TagName" ? t.parent && /CloseTag$/.test(t.parent.name) ? L(r, t, t.from, a) : O(r, e, t, t.from, a) : t.name == "StartTag" ? O(r, e, t, a, a) : t.name == "StartCloseTag" || t.name == "IncompleteCloseTag" ? L(r, t, a, a) : t.name == "OpenTag" || t.name == "SelfClosingTag" || t.name == "AttributeName" ? re(r, e, t, t.name == "AttributeName" ? t.from : a, a) : t.name == "Is" || t.name == "AttributeValue" || t.name == "UnquotedAttributeValue" ? se(r, e, t, t.name == "Is" ? a : t.from, a) : n.explicit && (o.name == "Element" || o.name == "Text" || o.name == "Document") ? ne(r, e, t, a) : null; } function ie(e) { let { extraTags: n, extraGlobalAttributes: r } = e, a = r || n ? new x(n, r) : x.default; return (t) => oe(a, t); } const ue = /* @__PURE__ */ E.parser.configure({ top: "SingleExpression" }), B = [ { tag: "script", attrs: (e) => e.type == "text/typescript" || e.lang == "ts", parser: U.parser }, { tag: "script", attrs: (e) => e.type == "text/babel" || e.type == "text/jsx", parser: W.parser }, { tag: "script", attrs: (e) => e.type == "text/typescript-jsx", parser: J.parser }, { tag: "script", attrs(e) { return /^(importmap|speculationrules|application\/(.+\+)?json)$/i.test(e.type); }, parser: ue }, { tag: "script", attrs(e) { return !e.type || /^(?:text|application)\/(?:x-)?(?:java|ecma)script$|^module$|^$/i.test(e.type); }, parser: E.parser }, { tag: "style", attrs(e) { return (!e.lang || e.lang == "css") && (!e.type || /^(text\/)?(x-)?(stylesheet|css)$/i.test(e.type)); }, parser: _.parser } ], M = /* @__PURE__ */ [ { name: "style", parser: /* @__PURE__ */ _.parser.configure({ top: "Styles" }) } ].concat(/* @__PURE__ */ F.map((e) => ({ name: e, parser: E.parser }))), G = /* @__PURE__ */ Y.define({ name: "html", parser: /* @__PURE__ */ R.configure({ props: [ /* @__PURE__ */ ee.add({ Element(e) { let n = /^(\s*)(<\/)?/.exec(e.textAfter); return e.node.to <= e.pos + n[0].length ? e.continue() : e.lineIndent(e.node.from) + (n[2] ? 0 : e.unit); }, "OpenTag CloseTag SelfClosingTag"(e) { return e.column(e.node.from) + e.unit; }, Document(e) { if (e.pos + /\s*/.exec(e.textAfter)[0].length < e.node.to) return e.continue(); let n = null, r; for (let a = e.node; ; ) { let t = a.lastChild; if (!t || t.name != "Element" || t.to != a.to) break; n = a = t; } return n && !((r = n.lastChild) && (r.name == "CloseTag" || r.name == "SelfClosingTag")) ? e.lineIndent(n.from) + e.unit : null; } }), /* @__PURE__ */ te.add({ Element(e) { let n = e.firstChild, r = e.lastChild; return !n || n.name != "OpenTag" ? null : { from: n.to, to: r.name == "CloseTag" ? r.from : e.to }; } }), /* @__PURE__ */ le.add({ "OpenTag CloseTag": (e) => e.getChild("TagName") }) ] }), languageData: { commentTokens: { block: { open: "<!--", close: "-->" } }, indentOnInput: /^\s*<\/\w+\W$/, wordChars: "-._" } }), C = /* @__PURE__ */ G.configure({ wrap: /* @__PURE__ */ q(B, M) }); function be(e = {}) { let n = "", r; e.matchClosingTags === !1 && (n = "noMatch"), e.selfClosingTags === !0 && (n = (n ? n + " " : "") + "selfClosing"), (e.nestedLanguages && e.nestedLanguages.length || e.nestedAttributes && e.nestedAttributes.length) && (r = q((e.nestedLanguages || []).concat(B), (e.nestedAttributes || []).concat(M))); let a = r ? G.configure({ wrap: r, dialect: n }) : n ? C.configure({ dialect: n }) : C; return new Z(a, [ C.data.of({ autocomplete: ie(e) }), e.autoCloseTags !== !1 ? de : [], K().support, H().support ]); } const I = /* @__PURE__ */ new Set(/* @__PURE__ */ "area base br col command embed frame hr img input keygen link meta param source track wbr menuitem".split(" ")), de = /* @__PURE__ */ Q.inputHandler.of((e, n, r, a, t) => { if (e.composing || e.state.readOnly || n != r || a != ">" && a != "/" || !C.isActiveAt(e.state, n, -1)) return !1; let o = t(), { state: s } = o, u = s.changeByRange((i) => { var f, g, c; let m = s.doc.sliceString(i.from - 1, i.to) == a, { head: d } = i, h = z(s).resolveInner(d, -1), b; if (m && a == ">" && h.name == "EndTag") { let w = h.parent; if (((g = (f = w.parent) === null || f === void 0 ? void 0 : f.lastChild) === null || g === void 0 ? void 0 : g.name) != "CloseTag" && (b = y(s.doc, w.parent, d)) && !I.has(b)) { let A = d + (s.doc.sliceString(d, d + 1) === ">" ? 1 : 0), k = `</${b}>`; return { range: i, changes: { from: d, to: A, insert: k } }; } } else if (m && a == "/" && h.name == "IncompleteCloseTag") { let w = h.parent; if (h.from == d - 2 && ((c = w.lastChild) === null || c === void 0 ? void 0 : c.name) != "CloseTag" && (b = y(s.doc, w, d)) && !I.has(b)) { let A = d + (s.doc.sliceString(d, d + 1) === ">" ? 1 : 0), k = `${b}>`; return { range: X.cursor(d + k.length, -1), changes: { from: d, to: A, insert: k } }; } } return { range: i }; }); return u.changes.empty ? !1 : (e.dispatch([ o, s.update(u, { userEvent: "input.complete", scrollIntoView: !0 }) ]), !0); }); export { de as autoCloseTags, be as html, ie as htmlCompletionSourceWith, C as htmlLanguage, G as htmlPlain }; //# sourceMappingURL=index.mjs.map