mancha 0.5.0 → 0.5.2

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.
@@ -0,0 +1,44 @@
1
+ {
2
+ // Use IntelliSense to learn about possible attributes.
3
+ // Hover to view descriptions of existing attributes.
4
+ // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5
+ "version": "0.2.0",
6
+ "configurations": [
7
+ {
8
+ "name": "Mocha All",
9
+ "type": "node",
10
+ "request": "launch",
11
+ "program": "${workspaceFolder}/node_modules/mocha/bin/_mocha",
12
+ "args": [
13
+ "-r",
14
+ "ts-node/register",
15
+ "--no-timeouts",
16
+ "--colors",
17
+ "${workspaceFolder}/dist/**/*.test.ts"
18
+ ],
19
+ "console": "integratedTerminal",
20
+ "internalConsoleOptions": "neverOpen",
21
+ "skipFiles": [
22
+ "<node_internals>/**/*.js"
23
+ ]
24
+ },
25
+ {
26
+ "name": "Mocha Current File",
27
+ "type": "node",
28
+ "request": "launch",
29
+ "program": "${workspaceFolder}/node_modules/mocha/bin/_mocha",
30
+ "args": [
31
+ "-r",
32
+ "ts-node/register",
33
+ "--no-timeouts",
34
+ "--colors",
35
+ "${file}"
36
+ ],
37
+ "console": "integratedTerminal",
38
+ "internalConsoleOptions": "neverOpen",
39
+ "skipFiles": [
40
+ "<node_internals>/**/*.js"
41
+ ]
42
+ }
43
+ ]
44
+ }
@@ -1,10 +1,3 @@
1
- /**
2
- * Helper function used to escape HTML attribute values.
3
- * See: https://stackoverflow.com/a/9756789
4
- */
5
- export declare function encodeHtmlAttrib(value?: string): string;
6
- /** Inverse the operation of [encodeHtmlAttrib] */
7
- export declare function decodeHtmlAttrib(value?: string): string;
8
1
  /**
9
2
  * Converts from an attribute name to camelCase, e.g. `foo-bar` becomes `fooBar`.
10
3
  * @param name attribute name
@@ -1,21 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.attributeNameToCamelCase = exports.decodeHtmlAttrib = exports.encodeHtmlAttrib = void 0;
4
- /**
5
- * Helper function used to escape HTML attribute values.
6
- * See: https://stackoverflow.com/a/9756789
7
- */
8
- function encodeHtmlAttrib(value) {
9
- var _a, _b, _c, _d, _e, _f, _g;
10
- return ((_g = (_f = (_e = (_d = (_c = (_b = (_a = value === null || value === void 0 ? void 0 : value.replace(/&/g, "&amp;")) === null || _a === void 0 ? void 0 : _a.replace(/'/g, "&apos;")) === null || _b === void 0 ? void 0 : _b.replace(/"/g, "&quot;")) === null || _c === void 0 ? void 0 : _c.replace(/</g, "&lt;")) === null || _d === void 0 ? void 0 : _d.replace(/>/g, "&gt;")) === null || _e === void 0 ? void 0 : _e.replace(/\r\n/g, "&#13;")) === null || _f === void 0 ? void 0 : _f.replace(/[\r\n]/g, "&#13;")) !== null && _g !== void 0 ? _g : "");
11
- }
12
- exports.encodeHtmlAttrib = encodeHtmlAttrib;
13
- /** Inverse the operation of [encodeHtmlAttrib] */
14
- function decodeHtmlAttrib(value) {
15
- var _a, _b, _c, _d, _e, _f;
16
- return ((_f = (_e = (_d = (_c = (_b = (_a = value === null || value === void 0 ? void 0 : value.replace(/&amp;/g, "&")) === null || _a === void 0 ? void 0 : _a.replace(/&apos;/g, "'")) === null || _b === void 0 ? void 0 : _b.replace(/&quot;/g, '"')) === null || _c === void 0 ? void 0 : _c.replace(/&lt;/g, "<")) === null || _d === void 0 ? void 0 : _d.replace(/&gt;/g, ">")) === null || _e === void 0 ? void 0 : _e.replace(/&#13;/g, "\n")) !== null && _f !== void 0 ? _f : "");
17
- }
18
- exports.decodeHtmlAttrib = decodeHtmlAttrib;
3
+ exports.attributeNameToCamelCase = void 0;
19
4
  /**
20
5
  * Converts from an attribute name to camelCase, e.g. `foo-bar` becomes `fooBar`.
21
6
  * @param name attribute name
package/dist/browser.d.ts CHANGED
@@ -1,9 +1,10 @@
1
- import { IRenderer, ParserParams, RendererParams } from "./core";
1
+ import { IRenderer } from "./core";
2
+ import { ParserParams, RenderParams } from "./interfaces";
2
3
  declare class RendererImpl extends IRenderer {
3
- protected readonly fsroot: string;
4
+ protected readonly dirpath: string;
4
5
  parseHTML(content: string, params?: ParserParams): DocumentFragment;
5
6
  serializeHTML(root: Node | DocumentFragment): string;
6
- renderLocalPath(fpath: string, params?: RendererParams & ParserParams): Promise<DocumentFragment>;
7
+ preprocessLocal(fpath: string, params?: RenderParams & ParserParams): Promise<DocumentFragment>;
7
8
  }
8
9
  declare const Mancha: RendererImpl;
9
10
  export default Mancha;
package/dist/browser.js CHANGED
@@ -14,10 +14,10 @@ const core_1 = require("./core");
14
14
  class RendererImpl extends core_1.IRenderer {
15
15
  constructor() {
16
16
  super(...arguments);
17
- this.fsroot = (0, core_1.folderPath)(self.location.href);
17
+ this.dirpath = (0, core_1.dirname)(self.location.href);
18
18
  }
19
- parseHTML(content, params = { isRoot: false }) {
20
- if (params.isRoot) {
19
+ parseHTML(content, params = { root: false }) {
20
+ if (params.root) {
21
21
  return new DOMParser().parseFromString(content, "text/html");
22
22
  }
23
23
  else {
@@ -29,8 +29,9 @@ class RendererImpl extends core_1.IRenderer {
29
29
  serializeHTML(root) {
30
30
  return new XMLSerializer().serializeToString(root).replace(/\s?xmlns="[^"]+"/gm, "");
31
31
  }
32
- renderLocalPath(fpath, params) {
33
- throw new Error("Not implemented.");
32
+ preprocessLocal(fpath, params) {
33
+ // In the browser, "local" paths (i.e., relative) can still be fetched.
34
+ return this.preprocessRemote(fpath, params);
34
35
  }
35
36
  }
36
37
  const Mancha = new RendererImpl();
@@ -41,12 +42,9 @@ if ((_c = (_b = self.document) === null || _b === void 0 ? void 0 : _b.currentSc
41
42
  const debug = currentScript === null || currentScript === void 0 ? void 0 : currentScript.hasAttribute("debug");
42
43
  const cachePolicy = currentScript === null || currentScript === void 0 ? void 0 : currentScript.getAttribute("cache");
43
44
  const targets = ((_d = currentScript === null || currentScript === void 0 ? void 0 : currentScript.getAttribute("target")) === null || _d === void 0 ? void 0 : _d.split(",")) || ["body"];
44
- const renderings = targets.map((target) => __awaiter(void 0, void 0, void 0, function* () {
45
+ targets.map((target) => __awaiter(void 0, void 0, void 0, function* () {
45
46
  const fragment = self.document.querySelector(target);
46
47
  yield Mancha.mount(fragment, { cache: cachePolicy, debug });
47
48
  }));
48
- Promise.all(renderings).then(() => {
49
- dispatchEvent(new Event("mancha-render", { bubbles: true }));
50
- });
51
49
  }
52
50
  exports.default = Mancha;
package/dist/cli.js CHANGED
@@ -11,7 +11,7 @@ const args = (0, yargs_1.default)((0, helpers_1.hideBin)(process.argv))
11
11
  .describe("vars", "JSON-formatted variables")
12
12
  .demand(["input"])
13
13
  .parse();
14
- index_1.Mancha.renderLocalPath(args["input"], JSON.parse(args.vars || "{}")).then((result) => {
14
+ index_1.Mancha.preprocessLocal(args["input"], JSON.parse(args.vars || "{}")).then((result) => {
15
15
  if (!args.output || args.output === "-") {
16
16
  console.log(result + "\n");
17
17
  }
package/dist/core.d.ts CHANGED
@@ -1,44 +1,27 @@
1
- /// <reference types="node" />
2
- import { ReactiveProxy, ReactiveProxyStore } from "./reactive";
1
+ import { ReactiveProxyStore } from "./reactive";
2
+ import { ParserParams, RenderParams } from "./interfaces";
3
3
  export declare function traverse(root: Node | DocumentFragment | Document, skip?: Set<Node>): Generator<ChildNode>;
4
- export declare function folderPath(fpath: string): string;
5
- export declare function resolvePath(fpath: string): string;
6
- export declare function extractTextNodeKeys(content: string): [string, string, string[]][];
4
+ export declare function dirname(fpath: string): string;
5
+ export declare function isRelativePath(fpath: string): boolean;
7
6
  export declare function safeEval(code: string, context: any, args?: {
8
7
  [key: string]: any;
9
8
  }): Promise<any>;
10
- export interface ParserParams {
11
- isRoot?: boolean;
12
- encoding?: BufferEncoding;
13
- }
14
- export interface RendererParams {
15
- fsroot?: string;
16
- maxdepth?: number;
17
- cache?: RequestCache | null;
18
- debug?: boolean;
19
- }
20
9
  export declare abstract class IRenderer extends ReactiveProxyStore {
21
- protected readonly fsroot: string;
22
- protected readonly skipNodes: Set<Node>;
10
+ protected readonly dirpath: string;
11
+ readonly skipNodes: Set<Node>;
23
12
  abstract parseHTML(content: string, params?: ParserParams): DocumentFragment;
24
13
  abstract serializeHTML(root: DocumentFragment | Node): string;
25
- abstract renderLocalPath(fpath: string, params?: RendererParams & ParserParams): Promise<DocumentFragment>;
14
+ fetchRemote(fpath: string, params?: RenderParams): Promise<string>;
15
+ fetchLocal(fpath: string, params?: RenderParams): Promise<string>;
16
+ preprocessString(content: string, params?: RenderParams & ParserParams): Promise<DocumentFragment>;
17
+ preprocessLocal(fpath: string, params?: RenderParams & ParserParams): Promise<DocumentFragment>;
18
+ preprocessRemote(fpath: string, params?: RenderParams & ParserParams): Promise<DocumentFragment>;
26
19
  clone(): IRenderer;
27
- log(params?: RendererParams, ...args: any[]): void;
20
+ log(params?: RenderParams, ...args: any[]): void;
28
21
  eval(expr: string, args?: {
29
22
  [key: string]: any;
30
- }, params?: RendererParams): Promise<any>;
31
- resolveIncludes(root: Document | DocumentFragment | Node, params?: RendererParams): Promise<IRenderer>;
32
- resolveTextNode(node: ChildNode, params?: RendererParams): ReactiveProxy<any>[];
33
- resolveDataAttribute(node: ChildNode, params?: RendererParams): Promise<void>;
34
- resolveWatchAttribute(node: ChildNode, params?: RendererParams): Promise<void>;
35
- resolvePropAttributes(node: ChildNode, params?: RendererParams): Promise<void>;
36
- resolveAttrAttributes(node: ChildNode, params?: RendererParams): Promise<void>;
37
- resolveEventAttributes(node: ChildNode, params?: RendererParams): Promise<void>;
38
- resolveForAttribute(node: ChildNode, params?: RendererParams): Promise<void>;
39
- resolveBindAttribute(node: ChildNode, params?: RendererParams): Promise<void>;
40
- resolveShowAttribute(node: ChildNode, params?: RendererParams): Promise<void>;
41
- mount(root: Document | DocumentFragment | Node, params?: RendererParams): Promise<IRenderer>;
42
- renderString(content: string, params?: RendererParams & ParserParams): Promise<DocumentFragment>;
43
- renderRemotePath(fpath: string, params?: RendererParams & ParserParams): Promise<DocumentFragment>;
23
+ }, params?: RenderParams): Promise<any>;
24
+ preprocessNode(root: Document | DocumentFragment | Node, params?: RenderParams): Promise<void>;
25
+ renderNode(root: Document | DocumentFragment | Node, params?: RenderParams): Promise<void>;
26
+ mount(root: Document | DocumentFragment | Node, params?: RenderParams): Promise<void>;
44
27
  }