1 | "use strict";
|
2 |
|
3 | var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
4 | if (kind === "m") throw new TypeError("Private method is not writable");
|
5 | if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
6 | if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
7 | return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
8 | };
|
9 | var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
10 | if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
11 | if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
12 | return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
13 | };
|
14 | var _HTML_strings, _HTML_args, _UnsafeHTML_value, _Fallback_content, _Fallback_fallback;
|
15 | Object.defineProperty(exports, "__esModule", { value: true });
|
16 | exports.unsafeHTML = exports.fallback = exports.js = exports.css = exports.html = exports.Fallback = exports.UnsafeHTML = exports.HTML = exports.AbstractHTML = void 0;
|
17 | const mod_js_1 = require("./deps/deno.land/x/escape_html@1.0.0/mod.js");
|
18 | const isIterable = (x) => typeof x === 'object' && x !== null && Symbol.iterator in x;
|
19 | const isAsyncIterable = (x) => typeof x === 'object' && x !== null && Symbol.asyncIterator in x;
|
20 | async function* unpackContent(content) {
|
21 | const x = await content;
|
22 | if (x == null || x === '' || x === false) {
|
23 | yield '';
|
24 | }
|
25 | else if (x instanceof AbstractHTML) {
|
26 | yield* x;
|
27 | }
|
28 | else if (isIterable(x)) {
|
29 | for (const xi of x) {
|
30 | yield* unpackContent(xi);
|
31 | }
|
32 | }
|
33 | else if (isAsyncIterable(x)) {
|
34 | for await (const xi of x) {
|
35 | yield* unpackContent(xi);
|
36 | }
|
37 | }
|
38 | else {
|
39 | yield (0, mod_js_1.escapeHtml)(x);
|
40 | }
|
41 | }
|
42 | async function* unpack(content) {
|
43 | try {
|
44 | yield* unpackContent(typeof content === 'function' ? content() : content);
|
45 | }
|
46 | catch (err) {
|
47 | if (err instanceof AbstractHTML)
|
48 | yield* err;
|
49 | else
|
50 | throw err;
|
51 | }
|
52 | }
|
53 | class AbstractHTML {
|
54 | }
|
55 | exports.AbstractHTML = AbstractHTML;
|
56 | class HTML extends AbstractHTML {
|
57 | constructor(strings, args) {
|
58 | super();
|
59 | _HTML_strings.set(this, void 0);
|
60 | _HTML_args.set(this, void 0);
|
61 | __classPrivateFieldSet(this, _HTML_strings, strings, "f");
|
62 | __classPrivateFieldSet(this, _HTML_args, args, "f");
|
63 | }
|
64 |
|
65 |
|
66 |
|
67 | async *[(_HTML_strings = new WeakMap(), _HTML_args = new WeakMap(), Symbol.asyncIterator)]() {
|
68 | const stringsIt = __classPrivateFieldGet(this, _HTML_strings, "f")[Symbol.iterator]();
|
69 | const argsIt = __classPrivateFieldGet(this, _HTML_args, "f")[Symbol.iterator]();
|
70 | while (true) {
|
71 | const { done: stringDone, value: string } = stringsIt.next();
|
72 | if (stringDone)
|
73 | break;
|
74 | else
|
75 | yield string;
|
76 | const { done: argDone, value: arg } = argsIt.next();
|
77 | if (argDone)
|
78 | break;
|
79 | else
|
80 | yield* unpack(arg);
|
81 | }
|
82 | const { done: stringDone, value: string } = stringsIt.next();
|
83 | if (stringDone)
|
84 | return;
|
85 | else
|
86 | yield string;
|
87 | }
|
88 | }
|
89 | exports.HTML = HTML;
|
90 | class UnsafeHTML extends AbstractHTML {
|
91 | constructor(value) {
|
92 | super();
|
93 | _UnsafeHTML_value.set(this, void 0);
|
94 | __classPrivateFieldSet(this, _UnsafeHTML_value, value || '', "f");
|
95 | }
|
96 | async *[(_UnsafeHTML_value = new WeakMap(), Symbol.asyncIterator)]() { yield __classPrivateFieldGet(this, _UnsafeHTML_value, "f"); }
|
97 | toString() { return __classPrivateFieldGet(this, _UnsafeHTML_value, "f"); }
|
98 | toJSON() { return __classPrivateFieldGet(this, _UnsafeHTML_value, "f"); }
|
99 | }
|
100 | exports.UnsafeHTML = UnsafeHTML;
|
101 | class Fallback extends AbstractHTML {
|
102 | constructor(content, fallback) {
|
103 | super();
|
104 | _Fallback_content.set(this, void 0);
|
105 | _Fallback_fallback.set(this, void 0);
|
106 | __classPrivateFieldSet(this, _Fallback_content, content, "f");
|
107 | __classPrivateFieldSet(this, _Fallback_fallback, fallback, "f");
|
108 | }
|
109 | async *[(_Fallback_content = new WeakMap(), _Fallback_fallback = new WeakMap(), Symbol.asyncIterator)]() {
|
110 | try {
|
111 | yield* unpack(__classPrivateFieldGet(this, _Fallback_content, "f"));
|
112 | }
|
113 | catch (e) {
|
114 | yield* typeof __classPrivateFieldGet(this, _Fallback_fallback, "f") === 'function'
|
115 | ? __classPrivateFieldGet(this, _Fallback_fallback, "f").call(this, e)
|
116 | : __classPrivateFieldGet(this, _Fallback_fallback, "f");
|
117 | }
|
118 | }
|
119 | }
|
120 | exports.Fallback = Fallback;
|
121 | function html(strings, ...args) {
|
122 | return new HTML(strings, args);
|
123 | }
|
124 | exports.html = html;
|
125 | exports.css = html;
|
126 | exports.js = html;
|
127 | function fallback(content, fallback) {
|
128 | return new Fallback(content, fallback);
|
129 | }
|
130 | exports.fallback = fallback;
|
131 | function unsafeHTML(content) {
|
132 | return new UnsafeHTML(content);
|
133 | }
|
134 | exports.unsafeHTML = unsafeHTML;
|
135 |
|
\ | No newline at end of file |