@sealcode/jdd 0.1.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.
Files changed (41) hide show
  1. package/.arclint +18 -0
  2. package/@types/component-arguments.d.ts +31 -0
  3. package/@types/component.d.ts +10 -0
  4. package/@types/components/markdown.d.ts +13 -0
  5. package/@types/index.d.ts +15 -0
  6. package/@types/pipeline.d.ts +0 -0
  7. package/@types/primitives/block.d.ts +18 -0
  8. package/@types/primitives/heading.d.ts +17 -0
  9. package/@types/primitives/image.d.ts +15 -0
  10. package/@types/primitives/parse_primitives.d.ts +2 -0
  11. package/@types/primitives/primitive.d.ts +11 -0
  12. package/@types/primitives/text.d.ts +14 -0
  13. package/@types/registry.d.ts +6 -0
  14. package/@types/utils/assert-throws.d.ts +1 -0
  15. package/lib/component-arguments.js +49 -0
  16. package/lib/component-arguments.js.map +1 -0
  17. package/lib/component.js +7 -0
  18. package/lib/component.js.map +1 -0
  19. package/lib/components/markdown.js +17 -0
  20. package/lib/components/markdown.js.map +1 -0
  21. package/lib/index.js +36 -0
  22. package/lib/index.js.map +1 -0
  23. package/lib/pipeline.js +16 -0
  24. package/lib/pipeline.js.map +1 -0
  25. package/lib/primitives/block.js +44 -0
  26. package/lib/primitives/block.js.map +1 -0
  27. package/lib/primitives/heading.js +28 -0
  28. package/lib/primitives/heading.js.map +1 -0
  29. package/lib/primitives/image.js +27 -0
  30. package/lib/primitives/image.js.map +1 -0
  31. package/lib/primitives/parse_primitives.js +28 -0
  32. package/lib/primitives/parse_primitives.js.map +1 -0
  33. package/lib/primitives/primitive.js +13 -0
  34. package/lib/primitives/primitive.js.map +1 -0
  35. package/lib/primitives/text.js +23 -0
  36. package/lib/primitives/text.js.map +1 -0
  37. package/lib/registry.js +17 -0
  38. package/lib/registry.js.map +1 -0
  39. package/lib/utils/assert-throws.js +35 -0
  40. package/lib/utils/assert-throws.js.map +1 -0
  41. package/package.json +40 -0
package/.arclint ADDED
@@ -0,0 +1,18 @@
1
+ {
2
+ "linters": {
3
+ "prettier": {
4
+ "type": "prettier",
5
+ "bin": "./node_modules/.bin/prettier",
6
+ "include": [
7
+ "(src/.*\\.[tj]s$)"
8
+ ]
9
+ },
10
+ "eslint": {
11
+ "type": "eslint",
12
+ "include": [
13
+ "(src/.*\\.ts$)",
14
+ "(src/.*\\.js$)"
15
+ ]
16
+ }
17
+ }
18
+ }
@@ -0,0 +1,31 @@
1
+ export type ExtractComponentArgumentValue<C> = C extends ComponentArgument<infer T> ? T : never;
2
+ export type ExtractStructuredComponentArgumentsValues<C> = {
3
+ [property in keyof C]: ExtractComponentArgumentValue<C[property]>;
4
+ };
5
+ export declare abstract class ComponentArgument<ARG extends any> {
6
+ ARG: ARG;
7
+ abstract getTypeName(): string;
8
+ }
9
+ export declare class ShortText extends ComponentArgument<string> {
10
+ getTypeName(): string;
11
+ }
12
+ export declare class MarkdownArgument extends ComponentArgument<string> {
13
+ getTypeName(): string;
14
+ }
15
+ export declare class List<T extends ComponentArgument<unknown>> extends ComponentArgument<Array<ExtractComponentArgumentValue<T>>> {
16
+ item_type: T;
17
+ constructor(item_type: T);
18
+ getTypeName(): string;
19
+ }
20
+ export declare class Structured<T extends Record<string, ComponentArgument<unknown>>> extends ComponentArgument<{
21
+ [property in keyof T]: ExtractComponentArgumentValue<T[property]>;
22
+ }> {
23
+ structure: T;
24
+ constructor(structure: T);
25
+ getTypeName(): string;
26
+ }
27
+ export declare class Image extends ComponentArgument<string> {
28
+ path_to_image_on_fs: string;
29
+ constructor(path_to_image_on_fs: string);
30
+ getTypeName(): string;
31
+ }
@@ -0,0 +1,10 @@
1
+ import { FlatTemplatable } from "tempstream";
2
+ import { ComponentArgument, ExtractStructuredComponentArgumentsValues } from "./component-arguments";
3
+ import { JDDContext } from ".";
4
+ export interface ComponentConstructor<A extends Record<string, ComponentArgument<unknown>> = Record<string, ComponentArgument<unknown>>> {
5
+ new (): Component<A>;
6
+ }
7
+ export declare abstract class Component<ArgumentsT extends Record<string, ComponentArgument<unknown>> = Record<string, ComponentArgument<unknown>>> {
8
+ abstract getArguments(): ArgumentsT;
9
+ abstract toHTML(args: ExtractStructuredComponentArgumentsValues<ArgumentsT>, context: JDDContext): FlatTemplatable;
10
+ }
@@ -0,0 +1,13 @@
1
+ import { FlatTemplatable } from "tempstream";
2
+ import { Component } from "../component";
3
+ import { ExtractStructuredComponentArgumentsValues, MarkdownArgument } from "../component-arguments";
4
+ declare const component_arguments: {
5
+ readonly markdown: MarkdownArgument;
6
+ };
7
+ export declare class Markdown extends Component<typeof component_arguments> {
8
+ getArguments(): {
9
+ readonly markdown: MarkdownArgument;
10
+ };
11
+ toHTML({ markdown, }: ExtractStructuredComponentArgumentsValues<typeof component_arguments>): FlatTemplatable;
12
+ }
13
+ export {};
@@ -0,0 +1,15 @@
1
+ /// <reference types="node" />
2
+ import { FlatTemplatable } from "tempstream";
3
+ import { Registry } from "./registry";
4
+ export * from "./component-arguments";
5
+ export * from "./component";
6
+ export * from "./registry";
7
+ export type JDDocument = Array<{
8
+ component_name: string;
9
+ args: Record<string, unknown>;
10
+ }>;
11
+ export interface JDDContext {
12
+ render_image: (path_to_image: string) => FlatTemplatable;
13
+ }
14
+ export declare const simpleJDDContext: JDDContext;
15
+ export declare function render(registry: Registry, document: JDDocument, context: JDDContext): import("stream").Readable;
File without changes
@@ -0,0 +1,18 @@
1
+ import { ShapeToType } from "@sealcode/ts-predicates";
2
+ import { ConstPredicate } from "@sealcode/ts-predicates/@types/predicates/const";
3
+ import { LazyPredicate } from "@sealcode/ts-predicates/@types/predicates/lazy";
4
+ import { HeadingPrimitive } from "./heading";
5
+ import { Primitive, PrimitiveJSON } from "./primitive";
6
+ export declare const BlockShape: {
7
+ readonly type: ConstPredicate<"block">;
8
+ readonly content: LazyPredicate<PrimitiveJSON[]>;
9
+ };
10
+ export type BlockJSON = ShapeToType<typeof BlockShape>;
11
+ export declare class BlockPrimitive extends Primitive {
12
+ content: Primitive[];
13
+ id: string | null;
14
+ constructor(json: Record<string, unknown>);
15
+ to_html(): string;
16
+ extract_headings(): HeadingPrimitive[];
17
+ extract_images(): string[];
18
+ }
@@ -0,0 +1,17 @@
1
+ import { ShapeToType } from "@sealcode/ts-predicates";
2
+ import { Primitive } from "./primitive";
3
+ export declare const HeadingShape: {
4
+ type: import("@sealcode/ts-predicates/@types/predicates/const").ConstPredicate<"heading">;
5
+ content: import("@sealcode/ts-predicates/@types/predicates/string").StringPredicate;
6
+ level: import("@sealcode/ts-predicates/@types/predicates/number").NumberPredicate;
7
+ id: import("@sealcode/ts-predicates/@types/predicates/predicate").Predicate<string | undefined>;
8
+ };
9
+ export type HeadingJSON = ShapeToType<typeof HeadingShape>;
10
+ export declare class HeadingPrimitive extends Primitive {
11
+ content: string;
12
+ level: number;
13
+ id: string | null;
14
+ constructor(json: Record<string, unknown>);
15
+ to_html(): string;
16
+ extract_headings(): HeadingPrimitive[];
17
+ }
@@ -0,0 +1,15 @@
1
+ import { Primitive } from "./primitive";
2
+ import { ShapeToType } from "@sealcode/ts-predicates";
3
+ export declare const ImageShape: {
4
+ type: import("@sealcode/ts-predicates/@types/predicates/const").ConstPredicate<"image">;
5
+ content: import("@sealcode/ts-predicates/@types/predicates/string").StringPredicate;
6
+ id: import("@sealcode/ts-predicates/@types/predicates/predicate").Predicate<string | undefined>;
7
+ };
8
+ export type ImageJSON = ShapeToType<typeof ImageShape>;
9
+ export declare class ImagePrimitive extends Primitive {
10
+ content: string;
11
+ id: string | null;
12
+ constructor(json: Record<string, unknown>);
13
+ to_html(): string;
14
+ extract_images(): string[];
15
+ }
@@ -0,0 +1,2 @@
1
+ import { Primitive } from "./primitive";
2
+ export declare function parse_primitives(primitive_json: Record<string, unknown>[]): Primitive[];
@@ -0,0 +1,11 @@
1
+ import { BlockJSON } from "./block";
2
+ import { HeadingJSON, HeadingPrimitive } from "./heading";
3
+ import { ImageJSON } from "./image";
4
+ import { TextJSON } from "./text";
5
+ export type PrimitiveJSON = BlockJSON | HeadingJSON | ImageJSON | TextJSON;
6
+ export declare abstract class Primitive {
7
+ id: string | null;
8
+ abstract to_html(): string;
9
+ extract_headings(): HeadingPrimitive[];
10
+ extract_images(): string[];
11
+ }
@@ -0,0 +1,14 @@
1
+ import { ShapeToType } from "@sealcode/ts-predicates";
2
+ import { Primitive } from "./primitive";
3
+ export declare const TextShape: {
4
+ type: import("@sealcode/ts-predicates/@types/predicates/const").ConstPredicate<"text">;
5
+ content: import("@sealcode/ts-predicates/@types/predicates/string").StringPredicate;
6
+ id: import("@sealcode/ts-predicates/@types/predicates/predicate").Predicate<string | undefined>;
7
+ };
8
+ export type TextJSON = ShapeToType<typeof TextShape>;
9
+ export declare class TextPrimitive extends Primitive {
10
+ content: string;
11
+ id: string | null;
12
+ constructor(json: Record<string, unknown>);
13
+ to_html(): string;
14
+ }
@@ -0,0 +1,6 @@
1
+ import { Component, ComponentConstructor } from "./component";
2
+ export declare class Registry {
3
+ map: Map<string, Component>;
4
+ add(type: string, component: ComponentConstructor<any>): void;
5
+ get(type: string): Component | null;
6
+ }
@@ -0,0 +1 @@
1
+ export declare function assertThrowsAsync(fn: () => Promise<unknown>, error_handler?: (e: unknown) => Promise<void> | void): Promise<void>;
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Image = exports.Structured = exports.List = exports.MarkdownArgument = exports.ShortText = exports.ComponentArgument = void 0;
4
+ class ComponentArgument {
5
+ }
6
+ exports.ComponentArgument = ComponentArgument;
7
+ class ShortText extends ComponentArgument {
8
+ getTypeName() {
9
+ return "short-text";
10
+ }
11
+ }
12
+ exports.ShortText = ShortText;
13
+ class MarkdownArgument extends ComponentArgument {
14
+ getTypeName() {
15
+ return "markdown";
16
+ }
17
+ }
18
+ exports.MarkdownArgument = MarkdownArgument;
19
+ class List extends ComponentArgument {
20
+ constructor(item_type) {
21
+ super();
22
+ this.item_type = item_type;
23
+ }
24
+ getTypeName() {
25
+ return "list";
26
+ }
27
+ }
28
+ exports.List = List;
29
+ class Structured extends ComponentArgument {
30
+ constructor(structure) {
31
+ super();
32
+ this.structure = structure;
33
+ }
34
+ getTypeName() {
35
+ return "structured";
36
+ }
37
+ }
38
+ exports.Structured = Structured;
39
+ class Image extends ComponentArgument {
40
+ constructor(path_to_image_on_fs) {
41
+ super();
42
+ this.path_to_image_on_fs = path_to_image_on_fs;
43
+ }
44
+ getTypeName() {
45
+ return "image";
46
+ }
47
+ }
48
+ exports.Image = Image;
49
+ //# sourceMappingURL=component-arguments.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"component-arguments.js","sourceRoot":"","sources":["../src/component-arguments.ts"],"names":[],"mappings":";;;AAUA,MAAsB,iBAAiB;CAGtC;AAHD,8CAGC;AAED,MAAa,SAAU,SAAQ,iBAAyB;IACvD,WAAW;QACV,OAAO,YAAY,CAAC;IACrB,CAAC;CACD;AAJD,8BAIC;AAED,MAAa,gBAAiB,SAAQ,iBAAyB;IAC9D,WAAW;QACV,OAAO,UAAU,CAAC;IACnB,CAAC;CACD;AAJD,4CAIC;AAED,MAAa,IAEX,SAAQ,iBAA0D;IACnE,YAAmB,SAAY;QAC9B,KAAK,EAAE,CAAC;QADU,cAAS,GAAT,SAAS,CAAG;IAE/B,CAAC;IAED,WAAW;QACV,OAAO,MAAM,CAAC;IACf,CAAC;CACD;AAVD,oBAUC;AAED,MAAa,UAEX,SAAQ,iBAER;IACD,YAAmB,SAAY;QAC9B,KAAK,EAAE,CAAC;QADU,cAAS,GAAT,SAAS,CAAG;IAE/B,CAAC;IAED,WAAW;QACV,OAAO,YAAY,CAAC;IACrB,CAAC;CACD;AAZD,gCAYC;AAED,MAAa,KAAM,SAAQ,iBAAyB;IACnD,YAAmB,mBAA2B;QAC7C,KAAK,EAAE,CAAC;QADU,wBAAmB,GAAnB,mBAAmB,CAAQ;IAE9C,CAAC;IAED,WAAW;QACV,OAAO,OAAO,CAAC;IAChB,CAAC;CACD;AARD,sBAQC"}
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Component = void 0;
4
+ class Component {
5
+ }
6
+ exports.Component = Component;
7
+ //# sourceMappingURL=component.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"component.js","sourceRoot":"","sources":["../src/component.ts"],"names":[],"mappings":";;;AAgBA,MAAsB,SAAS;CAW9B;AAXD,8BAWC"}
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Markdown = void 0;
4
+ const component_1 = require("../component");
5
+ const component_arguments_1 = require("../component-arguments");
6
+ const marked_1 = require("marked");
7
+ const component_arguments = { markdown: new component_arguments_1.MarkdownArgument() };
8
+ class Markdown extends component_1.Component {
9
+ getArguments() {
10
+ return component_arguments;
11
+ }
12
+ toHTML({ markdown, }) {
13
+ return marked_1.marked.parse(markdown);
14
+ }
15
+ }
16
+ exports.Markdown = Markdown;
17
+ //# sourceMappingURL=markdown.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"markdown.js","sourceRoot":"","sources":["../../src/components/markdown.ts"],"names":[],"mappings":";;;AACA,4CAAyC;AACzC,gEAGgC;AAChC,mCAAgC;AAEhC,MAAM,mBAAmB,GAAU,EAAE,QAAQ,EAAE,IAAI,sCAAgB,EAAE,EAAE,CAAC;AAGxE,MAAa,QAAS,SAAQ,qBAAqC;IAClE,YAAY;QACX,OAAO,mBAAmB,CAAC;IAC5B,CAAC;IAED,MAAM,CAAC,EACN,QAAQ,GAGR;QACA,OAAO,eAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;IAC/B,CAAC;CACD;AAZD,4BAYC"}
package/lib/index.js ADDED
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.render = exports.simpleJDDContext = void 0;
18
+ const tempstream_1 = require("tempstream");
19
+ __exportStar(require("./component-arguments"), exports);
20
+ __exportStar(require("./component"), exports);
21
+ __exportStar(require("./registry"), exports);
22
+ exports.simpleJDDContext = {
23
+ render_image: (path) => /* HTML */ `<img src="file://path" />`,
24
+ };
25
+ function render(registry, document, context) {
26
+ return (0, tempstream_1.tempstream) `${document.map(({ component_name, args }) => {
27
+ const component = registry.get(component_name);
28
+ if (!component) {
29
+ console.warn("Component not found in the registry: " + component_name);
30
+ return "";
31
+ }
32
+ return component.toHTML(args, context);
33
+ })}`;
34
+ }
35
+ exports.render = render;
36
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,2CAAyD;AAEzD,wDAAsC;AACtC,8CAA4B;AAC5B,6CAA2B;AAWd,QAAA,gBAAgB,GAAe;IAC3C,YAAY,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,UAAU,CAAC,2BAA2B;CAC9D,CAAC;AAEF,SAAgB,MAAM,CACrB,QAAkB,EAClB,QAAoB,EACpB,OAAmB;IAEnB,OAAO,IAAA,uBAAU,EAAA,GAAG,QAAQ,CAAC,GAAG,CAAC,CAAC,EAAE,cAAc,EAAE,IAAI,EAAE,EAAE,EAAE;QAC7D,MAAM,SAAS,GAAG,QAAQ,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC;QAC/C,IAAI,CAAC,SAAS,EAAE;YACf,OAAO,CAAC,IAAI,CACX,uCAAuC,GAAG,cAAc,CACxD,CAAC;YACF,OAAO,EAAE,CAAC;SACV;QACD,OAAO,SAAS,CAAC,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IACxC,CAAC,CAAC,EAAE,CAAC;AACN,CAAC;AAfD,wBAeC"}
@@ -0,0 +1,16 @@
1
+ //commented out. We'll be doing the pandoc-style primitives+pipeline stuff in v2.
2
+ // import { PrimitiveJSON } from "./primitives/primitive";
3
+ // import { Registry } from "./registry";
4
+ // export function resolve_component(
5
+ // reg: Registry,
6
+ // type: string,
7
+ // component: Record<string, unknown>
8
+ // ): PrimitiveJSON {
9
+ // const func = reg.get_component(type);
10
+ // if (!func)
11
+ // throw new Error(
12
+ // `Component of type ${type} was not registered before trying to resolve it`
13
+ // );
14
+ // return func(component);
15
+ // }
16
+ //# sourceMappingURL=pipeline.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pipeline.js","sourceRoot":"","sources":["../src/pipeline.ts"],"names":[],"mappings":"AAAA,iFAAiF;AAEjF,0DAA0D;AAC1D,yCAAyC;AAEzC,qCAAqC;AACrC,kBAAkB;AAClB,iBAAiB;AACjB,sCAAsC;AACtC,qBAAqB;AACrB,yCAAyC;AACzC,cAAc;AACd,qBAAqB;AACrB,gFAAgF;AAChF,OAAO;AACP,2BAA2B;AAC3B,IAAI"}
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BlockPrimitive = exports.BlockShape = void 0;
4
+ const ts_predicates_1 = require("@sealcode/ts-predicates");
5
+ const heading_1 = require("./heading");
6
+ const image_1 = require("./image");
7
+ const parse_primitives_1 = require("./parse_primitives");
8
+ const primitive_1 = require("./primitive");
9
+ const text_1 = require("./text");
10
+ exports.BlockShape = {
11
+ type: ts_predicates_1.predicates.const("block"),
12
+ content: ts_predicates_1.predicates.lazy(() => ts_predicates_1.predicates.array(ts_predicates_1.predicates.or(ts_predicates_1.predicates.shape(exports.BlockShape), ts_predicates_1.predicates.shape(heading_1.HeadingShape), ts_predicates_1.predicates.shape(image_1.ImageShape), ts_predicates_1.predicates.shape(text_1.TextShape)))),
13
+ };
14
+ class BlockPrimitive extends primitive_1.Primitive {
15
+ constructor(json) {
16
+ super();
17
+ this.id = null;
18
+ this.content = (0, parse_primitives_1.parse_primitives)(json["content"]);
19
+ this.id = json["id"];
20
+ }
21
+ to_html() {
22
+ let html = `<div>`;
23
+ for (const comp of this.content) {
24
+ html += comp.to_html();
25
+ }
26
+ return `${html}</div>`;
27
+ }
28
+ extract_headings() {
29
+ const headings = [];
30
+ for (const primitive of this.content) {
31
+ headings.push(...primitive.extract_headings());
32
+ }
33
+ return headings;
34
+ }
35
+ extract_images() {
36
+ const ret = [];
37
+ for (const comp of this.content) {
38
+ ret.push(...comp.extract_images());
39
+ }
40
+ return ret;
41
+ }
42
+ }
43
+ exports.BlockPrimitive = BlockPrimitive;
44
+ //# sourceMappingURL=block.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"block.js","sourceRoot":"","sources":["../../src/primitives/block.ts"],"names":[],"mappings":";;;AAAA,2DAAkE;AAGlE,uCAA2D;AAC3D,mCAAqC;AACrC,yDAAsD;AACtD,2CAAuD;AACvD,iCAAmC;AAEtB,QAAA,UAAU,GAGZ;IACV,IAAI,EAAE,0BAAU,CAAC,KAAK,CAAQ,OAAO,CAAC;IACtC,OAAO,EAAE,0BAAU,CAAC,IAAI,CAAC,GAAG,EAAE,CAC7B,0BAAU,CAAC,KAAK,CACf,0BAAU,CAAC,EAAE,CACZ,0BAAU,CAAC,KAAK,CAAC,kBAAU,CAAC,EAC5B,0BAAU,CAAC,KAAK,CAAC,sBAAY,CAAC,EAC9B,0BAAU,CAAC,KAAK,CAAC,kBAAU,CAAC,EAC5B,0BAAU,CAAC,KAAK,CAAC,gBAAS,CAAC,CAC3B,CACD,CACD;CACD,CAAC;AAIF,MAAa,cAAe,SAAQ,qBAAS;IAI5C,YAAY,IAA6B;QACxC,KAAK,EAAE,CAAC;QAHT,OAAE,GAAkB,IAAI,CAAC;QAIxB,IAAI,CAAC,OAAO,GAAG,IAAA,mCAAgB,EAC9B,IAAI,CAAC,SAAS,CAA8B,CAC5C,CAAC;QACF,IAAI,CAAC,EAAE,GAAG,IAAI,CAAC,IAAI,CAAkB,CAAC;IACvC,CAAC;IAED,OAAO;QACN,IAAI,IAAI,GAAG,OAAO,CAAC;QAEnB,KAAK,MAAM,IAAI,IAAI,IAAI,CAAC,OAAO,EAAE;YAChC,IAAI,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;SACvB;QAED,OAAO,GAAG,IAAI,QAAQ,CAAC;IACxB,CAAC;IAED,gBAAgB;QACf,MAAM,QAAQ,GAAuB,EAAE,CAAC;QAExC,KAAK,MAAM,SAAS,IAAI,IAAI,CAAC,OAAO,EAAE;YACrC,QAAQ,CAAC,IAAI,CAAC,GAAG,SAAS,CAAC,gBAAgB,EAAE,CAAC,CAAC;SAC/C;QACD,OAAO,QAAQ,CAAC;IACjB,CAAC;IAED,cAAc;QACb,MAAM,GAAG,GAAa,EAAE,CAAC;QAEzB,KAAK,MAAM,IAAI,IAAI,IAAI,CAAC,OAAO,EAAE;YAChC,GAAG,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,cAAc,EAAE,CAAC,CAAC;SACnC;QACD,OAAO,GAAG,CAAC;IACZ,CAAC;CACD;AAvCD,wCAuCC"}
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.HeadingPrimitive = exports.HeadingShape = void 0;
4
+ const ts_predicates_1 = require("@sealcode/ts-predicates");
5
+ const primitive_1 = require("./primitive");
6
+ exports.HeadingShape = {
7
+ type: ts_predicates_1.predicates.const("heading"),
8
+ content: ts_predicates_1.predicates.string,
9
+ level: ts_predicates_1.predicates.number,
10
+ id: ts_predicates_1.predicates.maybe(ts_predicates_1.predicates.string),
11
+ };
12
+ class HeadingPrimitive extends primitive_1.Primitive {
13
+ constructor(json) {
14
+ super();
15
+ this.id = null;
16
+ this.content = json["content"];
17
+ this.level = json["level"];
18
+ this.id = json["id"];
19
+ }
20
+ to_html() {
21
+ return /* HTML */ `<h1>${this.content}</h1>`;
22
+ }
23
+ extract_headings() {
24
+ return [this];
25
+ }
26
+ }
27
+ exports.HeadingPrimitive = HeadingPrimitive;
28
+ //# sourceMappingURL=heading.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"heading.js","sourceRoot":"","sources":["../../src/primitives/heading.ts"],"names":[],"mappings":";;;AAAA,2DAAkE;AAClE,2CAAwC;AAE3B,QAAA,YAAY,GAAG;IAC3B,IAAI,EAAE,0BAAU,CAAC,KAAK,CAAQ,SAAS,CAAC;IACxC,OAAO,EAAE,0BAAU,CAAC,MAAM;IAC1B,KAAK,EAAE,0BAAU,CAAC,MAAM;IACxB,EAAE,EAAE,0BAAU,CAAC,KAAK,CAAC,0BAAU,CAAC,MAAM,CAAC;CACvC,CAAC;AAIF,MAAa,gBAAiB,SAAQ,qBAAS;IAK9C,YAAY,IAA6B;QACxC,KAAK,EAAE,CAAC;QAHT,OAAE,GAAkB,IAAI,CAAC;QAIxB,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,SAAS,CAAW,CAAC;QACzC,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,OAAO,CAAW,CAAC;QACrC,IAAI,CAAC,EAAE,GAAG,IAAI,CAAC,IAAI,CAAkB,CAAC;IACvC,CAAC;IAED,OAAO;QACN,OAAO,UAAU,CAAC,OAAO,IAAI,CAAC,OAAO,OAAO,CAAC;IAC9C,CAAC;IAED,gBAAgB;QACf,OAAO,CAAC,IAAI,CAAC,CAAC;IACf,CAAC;CACD;AAnBD,4CAmBC"}
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ImagePrimitive = exports.ImageShape = void 0;
4
+ const primitive_1 = require("./primitive");
5
+ const ts_predicates_1 = require("@sealcode/ts-predicates");
6
+ exports.ImageShape = {
7
+ type: ts_predicates_1.predicates.const("image"),
8
+ content: ts_predicates_1.predicates.string,
9
+ id: ts_predicates_1.predicates.maybe(ts_predicates_1.predicates.string),
10
+ };
11
+ // content here is the image url
12
+ class ImagePrimitive extends primitive_1.Primitive {
13
+ constructor(json) {
14
+ super();
15
+ this.id = null;
16
+ this.content = json["content"];
17
+ this.id = json["id"];
18
+ }
19
+ to_html() {
20
+ return `<img src="${this.content}"`;
21
+ }
22
+ extract_images() {
23
+ return [this.content];
24
+ }
25
+ }
26
+ exports.ImagePrimitive = ImagePrimitive;
27
+ //# sourceMappingURL=image.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"image.js","sourceRoot":"","sources":["../../src/primitives/image.ts"],"names":[],"mappings":";;;AAAA,2CAAwC;AAExC,2DAAkE;AAErD,QAAA,UAAU,GAAG;IACzB,IAAI,EAAE,0BAAU,CAAC,KAAK,CAAQ,OAAO,CAAC;IACtC,OAAO,EAAE,0BAAU,CAAC,MAAM;IAC1B,EAAE,EAAE,0BAAU,CAAC,KAAK,CAAC,0BAAU,CAAC,MAAM,CAAC;CACvC,CAAC;AAIF,gCAAgC;AAChC,MAAa,cAAe,SAAQ,qBAAS;IAI5C,YAAY,IAA6B;QACxC,KAAK,EAAE,CAAC;QAHT,OAAE,GAAkB,IAAI,CAAC;QAIxB,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,SAAS,CAAW,CAAC;QACzC,IAAI,CAAC,EAAE,GAAG,IAAI,CAAC,IAAI,CAAkB,CAAC;IACvC,CAAC;IAED,OAAO;QACN,OAAO,aAAa,IAAI,CAAC,OAAO,GAAG,CAAC;IACrC,CAAC;IAED,cAAc;QACb,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IACvB,CAAC;CACD;AAjBD,wCAiBC"}
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parse_primitives = void 0;
4
+ const block_1 = require("./block");
5
+ const heading_1 = require("./heading");
6
+ const image_1 = require("./image");
7
+ const text_1 = require("./text");
8
+ // parses primitive json into classes
9
+ function parse_primitives(primitive_json) {
10
+ const ret = [];
11
+ for (const p of primitive_json) {
12
+ if (p["type"] === "text") {
13
+ ret.push(new text_1.TextPrimitive(p));
14
+ }
15
+ else if (p["type"] === "heading") {
16
+ ret.push(new heading_1.HeadingPrimitive(p));
17
+ }
18
+ else if (p["type"] === "image") {
19
+ ret.push(new image_1.ImagePrimitive(p));
20
+ }
21
+ else if (p["type"] === "block") {
22
+ ret.push(new block_1.BlockPrimitive(p));
23
+ }
24
+ }
25
+ return ret;
26
+ }
27
+ exports.parse_primitives = parse_primitives;
28
+ //# sourceMappingURL=parse_primitives.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parse_primitives.js","sourceRoot":"","sources":["../../src/primitives/parse_primitives.ts"],"names":[],"mappings":";;;AAAA,mCAAyC;AACzC,uCAA6C;AAC7C,mCAAyC;AAEzC,iCAAuC;AAEvC,qCAAqC;AACrC,SAAgB,gBAAgB,CAC/B,cAAyC;IAEzC,MAAM,GAAG,GAAgB,EAAE,CAAC;IAE5B,KAAK,MAAM,CAAC,IAAI,cAAc,EAAE;QAC/B,IAAI,CAAC,CAAC,MAAM,CAAC,KAAK,MAAM,EAAE;YACzB,GAAG,CAAC,IAAI,CAAC,IAAI,oBAAa,CAAC,CAAC,CAAC,CAAC,CAAC;SAC/B;aAAM,IAAI,CAAC,CAAC,MAAM,CAAC,KAAK,SAAS,EAAE;YACnC,GAAG,CAAC,IAAI,CAAC,IAAI,0BAAgB,CAAC,CAAC,CAAC,CAAC,CAAC;SAClC;aAAM,IAAI,CAAC,CAAC,MAAM,CAAC,KAAK,OAAO,EAAE;YACjC,GAAG,CAAC,IAAI,CAAC,IAAI,sBAAc,CAAC,CAAC,CAAC,CAAC,CAAC;SAChC;aAAM,IAAI,CAAC,CAAC,MAAM,CAAC,KAAK,OAAO,EAAE;YACjC,GAAG,CAAC,IAAI,CAAC,IAAI,sBAAc,CAAC,CAAC,CAAC,CAAC,CAAC;SAChC;KACD;IACD,OAAO,GAAG,CAAC;AACZ,CAAC;AAjBD,4CAiBC"}
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Primitive = void 0;
4
+ class Primitive {
5
+ extract_headings() {
6
+ return [];
7
+ }
8
+ extract_images() {
9
+ return [];
10
+ }
11
+ }
12
+ exports.Primitive = Primitive;
13
+ //# sourceMappingURL=primitive.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"primitive.js","sourceRoot":"","sources":["../../src/primitives/primitive.ts"],"names":[],"mappings":";;;AAOA,MAAsB,SAAS;IAK9B,gBAAgB;QACf,OAAO,EAAE,CAAC;IACX,CAAC;IAED,cAAc;QACb,OAAO,EAAE,CAAC;IACX,CAAC;CAGD;AAdD,8BAcC"}
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TextPrimitive = exports.TextShape = void 0;
4
+ const ts_predicates_1 = require("@sealcode/ts-predicates");
5
+ const primitive_1 = require("./primitive");
6
+ exports.TextShape = {
7
+ type: ts_predicates_1.predicates.const("text"),
8
+ content: ts_predicates_1.predicates.string,
9
+ id: ts_predicates_1.predicates.maybe(ts_predicates_1.predicates.string),
10
+ };
11
+ class TextPrimitive extends primitive_1.Primitive {
12
+ constructor(json) {
13
+ super();
14
+ this.id = null;
15
+ this.content = json["content"];
16
+ this.id = json["id"];
17
+ }
18
+ to_html() {
19
+ return /* HTML */ `<p>${this.content}</p>`;
20
+ }
21
+ }
22
+ exports.TextPrimitive = TextPrimitive;
23
+ //# sourceMappingURL=text.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"text.js","sourceRoot":"","sources":["../../src/primitives/text.ts"],"names":[],"mappings":";;;AAAA,2DAAkE;AAClE,2CAAwC;AAE3B,QAAA,SAAS,GAAG;IACxB,IAAI,EAAE,0BAAU,CAAC,KAAK,CAAQ,MAAM,CAAC;IACrC,OAAO,EAAE,0BAAU,CAAC,MAAM;IAC1B,EAAE,EAAE,0BAAU,CAAC,KAAK,CAAC,0BAAU,CAAC,MAAM,CAAC;CACvC,CAAC;AAIF,MAAa,aAAc,SAAQ,qBAAS;IAI3C,YAAY,IAA6B;QACxC,KAAK,EAAE,CAAC;QAHF,OAAE,GAAkB,IAAI,CAAC;QAI/B,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,SAAS,CAAW,CAAC;QACzC,IAAI,CAAC,EAAE,GAAG,IAAI,CAAC,IAAI,CAAkB,CAAC;IACvC,CAAC;IAED,OAAO;QACN,OAAO,UAAU,CAAC,MAAM,IAAI,CAAC,OAAO,MAAM,CAAC;IAC5C,CAAC;CACD;AAbD,sCAaC"}
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Registry = void 0;
4
+ class Registry {
5
+ constructor() {
6
+ this.map = new Map();
7
+ }
8
+ add(type, component) {
9
+ this.map.set(type, new component());
10
+ }
11
+ get(type) {
12
+ const ret = this.map.get(type);
13
+ return ret ? ret : null;
14
+ }
15
+ }
16
+ exports.Registry = Registry;
17
+ //# sourceMappingURL=registry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"registry.js","sourceRoot":"","sources":["../src/registry.ts"],"names":[],"mappings":";;;AAEA,MAAa,QAAQ;IAArB;QACC,QAAG,GAA2B,IAAI,GAAG,EAAE,CAAC;IAUzC,CAAC;IARA,GAAG,CAAC,IAAY,EAAE,SAAoC;QACrD,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,EAAE,IAAI,SAAS,EAAE,CAAC,CAAC;IACrC,CAAC;IAED,GAAG,CAAC,IAAY;QACf,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QAC/B,OAAO,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC;IACzB,CAAC;CACD;AAXD,4BAWC"}
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.assertThrowsAsync = void 0;
16
+ const assert_1 = __importDefault(require("assert"));
17
+ function assertThrowsAsync(fn, error_handler) {
18
+ return __awaiter(this, void 0, void 0, function* () {
19
+ let error = null;
20
+ try {
21
+ yield fn();
22
+ }
23
+ catch (e) {
24
+ error = e;
25
+ }
26
+ finally {
27
+ assert_1.default.notStrictEqual(error, null, "It didn't throw");
28
+ if (error_handler) {
29
+ yield error_handler(error);
30
+ }
31
+ }
32
+ });
33
+ }
34
+ exports.assertThrowsAsync = assertThrowsAsync;
35
+ //# sourceMappingURL=assert-throws.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"assert-throws.js","sourceRoot":"","sources":["../../src/utils/assert-throws.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,oDAA4B;AAE5B,SAAsB,iBAAiB,CACtC,EAA0B,EAC1B,aAAoD;;QAEpD,IAAI,KAAK,GAAY,IAAI,CAAC;QAC1B,IAAI;YACH,MAAM,EAAE,EAAE,CAAC;SACX;QAAC,OAAO,CAAU,EAAE;YACpB,KAAK,GAAG,CAAC,CAAC;SACV;gBAAS;YACT,gBAAM,CAAC,cAAc,CAAC,KAAK,EAAE,IAAI,EAAE,iBAAiB,CAAC,CAAC;YACtD,IAAI,aAAa,EAAE;gBAClB,MAAM,aAAa,CAAC,KAAK,CAAC,CAAC;aAC3B;SACD;IACF,CAAC;CAAA;AAfD,8CAeC"}
package/package.json ADDED
@@ -0,0 +1,40 @@
1
+ {
2
+ "name": "@sealcode/jdd",
3
+ "version": "0.1.0",
4
+ "description": "JSON-Driven Documents",
5
+ "main": "lib/index.js",
6
+ "scripts": {
7
+ "test": "mocha",
8
+ "build": "tsc",
9
+ "prepare": "npm run build",
10
+ "clean-coverage": "rm -rf coverage .nyc_output .xunit",
11
+ "coverage": "npm run clean-coverage && nyc mocha",
12
+ "test-reports": "npm run clean-coverage && nyc --reporter clover mocha --reporter xunit --reporter-option output=.xunit",
13
+ "coverage-html": "npm run test-reports && nyc report --reporter lcov && xdg-open coverage/lcov-report/index.html"
14
+ },
15
+ "author": "",
16
+ "license": "ISC",
17
+ "devDependencies": {
18
+ "@istanbuljs/nyc-config-typescript": "^1.0.2",
19
+ "@types/mocha": "^10.0.1",
20
+ "@typescript-eslint/eslint-plugin": "^5.58.0",
21
+ "@typescript-eslint/parser": "^5.58.0",
22
+ "assert": "^2.0.0",
23
+ "eslint": "^8.38.0",
24
+ "eslint-config-prettier": "^8.8.0",
25
+ "eslint-plugin-prettier": "^4.2.1",
26
+ "eslint-plugin-with-tsc-error": "^0.0.8",
27
+ "mocha": "^10.2.0",
28
+ "nyc": "^15.1.0",
29
+ "prettier": "^2.8.7",
30
+ "source-map-support": "^0.5.21",
31
+ "ts-node": "^10.9.1",
32
+ "typescript": "^5.0.4"
33
+ },
34
+ "types": "./@types/index.d.ts",
35
+ "dependencies": {
36
+ "@sealcode/ts-predicates": "^0.5.3",
37
+ "marked": "^12.0.0",
38
+ "tempstream": "^0.3.0"
39
+ }
40
+ }