marko 6.0.0-3.11 → 6.0.0-3.12

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 (3) hide show
  1. package/index.d.ts +144 -0
  2. package/package.json +19 -10
  3. package/tags-html.d.ts +3935 -0
package/index.d.ts ADDED
@@ -0,0 +1,144 @@
1
+ import "./tags-html";
2
+
3
+ declare module "*.marko" {
4
+ const template: Marko.Template;
5
+ export default template;
6
+ }
7
+
8
+ declare global {
9
+ namespace NodeJS {
10
+ interface ReadableStream {}
11
+ }
12
+
13
+ namespace Marko {
14
+ /** A mutable global object for the current render. */
15
+ export interface Global {
16
+ [x: PropertyKey]: unknown;
17
+ /** An AbortSignal instance that, when aborted, stops further streamed content. */
18
+ signal?: AbortSignal;
19
+ /** A CSP Nonce to add to each script output from Marko. */
20
+ cspNonce?: string;
21
+ /** Used for rendering multiple Marko templates in a single hydrated page. */
22
+ renderId?: string;
23
+ /** Used to uniquely identify a instance of a Marko runtime. */
24
+ runtimeId?: string;
25
+ /** A list of globals that should be serialized to the browser. */
26
+ serializedGlobals?:
27
+ | (string | number)[]
28
+ | Record<string | number, boolean>;
29
+ }
30
+
31
+ export type TemplateInput<Input> = Input & {
32
+ /** Data available within all rendered templates as `$global`. */
33
+ $global?: Global;
34
+ };
35
+
36
+ /** Body content created from by a component, typically held in an object with a renderBody property. */
37
+ export interface Body<
38
+ in Params extends readonly any[] = [],
39
+ out Return = void,
40
+ > {}
41
+
42
+ /** Valid data types which can be passed in as a <${dynamic}/> tag name. */
43
+ export type Renderable =
44
+ | { renderBody: Body<any, any> | Template | string }
45
+ | Body<any, any>
46
+ | Template
47
+ | string;
48
+
49
+ /** Extract the return tag type from a renderBody. */
50
+ export type BodyReturnType<B> =
51
+ B extends Body<any, infer Return> ? Return : never;
52
+
53
+ /** Extract the tag parameter types received by a renderBody. */
54
+ export type BodyParameters<B> =
55
+ B extends Body<infer Params, any> ? Params : never;
56
+
57
+ /** The top level api for a Marko Template. */
58
+ export abstract class Template<Input = unknown, Return = unknown> {
59
+ /**
60
+ * The folowing types are processed up by the @marko/language-tools
61
+ * and inlined into the compiled template.
62
+ *
63
+ * This is done to support generics on each of these methods
64
+ * until TypeScript supports higher kinded types.
65
+ *
66
+ * https://github.com/microsoft/TypeScript/issues/1213
67
+ */
68
+
69
+ /** @marko-overload-start */
70
+ /** Render the template to a string. */
71
+ abstract render(input: Marko.TemplateInput<Input>): Promise<string> &
72
+ AsyncIterable<string> & {
73
+ toReadable(): ReadableStream;
74
+ pipe(stream: {
75
+ write(chunk: string): unknown;
76
+ end(): unknown;
77
+ flush?(): void;
78
+ }): void;
79
+ toString(): string;
80
+ };
81
+
82
+ /** Render and attach the template to a DOM node. */
83
+ abstract mount(
84
+ input: Marko.TemplateInput<Input>,
85
+ reference: ParentNode & Node,
86
+ position?: "afterbegin" | "afterend" | "beforebegin" | "beforeend",
87
+ ): {
88
+ update(input: Marko.TemplateInput<Input>): void;
89
+ destroy(): void;
90
+ };
91
+ /** @marko-overload-end */
92
+ }
93
+
94
+ export type AttrTag<T> = T & {
95
+ [Symbol.iterator](): Iterator<T>;
96
+ };
97
+
98
+ export interface NativeTag<
99
+ Input extends Record<string, any>,
100
+ Return extends Element,
101
+ > {
102
+ input: Input;
103
+ return: { value: () => Return };
104
+ }
105
+ export interface NativeTags {
106
+ [name: string]: NativeTag<Record<string, any>, Element>;
107
+ }
108
+
109
+ export type Input<Name> = 0 extends 1 & Name
110
+ ? any
111
+ : Name extends string
112
+ ? Name extends keyof NativeTags
113
+ ? NativeTags[Name]["input"]
114
+ : Record<string, unknown>
115
+ : Name extends
116
+ | Template<infer Input, any>
117
+ | { _(): () => (input: infer Input) => any }
118
+ ? Input
119
+ : Name extends Body<infer Args, any>
120
+ ? Args extends {
121
+ length: infer Length;
122
+ }
123
+ ? number extends Length
124
+ ? Args[0] | undefined
125
+ : 0 extends Length
126
+ ? undefined
127
+ : Args[0]
128
+ : never
129
+ : never;
130
+
131
+ export type Return<Name> = 0 extends 1 & Name
132
+ ? any
133
+ : Name extends string
134
+ ? Name extends keyof NativeTags
135
+ ? NativeTags[Name]["return"]
136
+ : () => Element
137
+ : Name extends
138
+ | { _(): () => (input: any) => { return: infer Return } }
139
+ | Template<any, infer Return>
140
+ | Body<any, infer Return>
141
+ ? Return
142
+ : never;
143
+ }
144
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "marko",
3
- "version": "6.0.0-3.11",
3
+ "version": "6.0.0-3.12",
4
4
  "description": "Optimized runtime for Marko templates.",
5
5
  "keywords": [
6
6
  "api",
@@ -17,23 +17,29 @@
17
17
  },
18
18
  "license": "MIT",
19
19
  "exports": {
20
- "./*.d.marko": "./tag-types/*",
20
+ ".": {
21
+ "types": "./index.d.ts"
22
+ },
21
23
  "./package.json": "./package.json",
22
24
  "./translator": "./dist/translator/index.js",
23
- "./*": {
24
- "types": "./dist/*.d.ts",
25
- "import": "./dist/*.mjs",
26
- "default": "./dist/*.js"
27
- },
25
+ "./tag-types/*": "./tag-types/*",
28
26
  "./debug/*": {
29
27
  "types": "./dist/*.d.ts",
30
28
  "import": "./dist/debug/*.mjs",
31
29
  "default": "./dist/debug/*.js"
30
+ },
31
+ "./*": {
32
+ "types": "./dist/*.d.ts",
33
+ "import": "./dist/*.mjs",
34
+ "default": "./dist/*.js"
32
35
  }
33
36
  },
37
+ "types": "index.d.ts",
34
38
  "files": [
35
39
  "dist",
36
40
  "tag-types",
41
+ "index.d.ts",
42
+ "tags-html.d.ts",
37
43
  "!**/meta.*.json",
38
44
  "!**/__tests__",
39
45
  "!**/*.tsbuildinfo"
@@ -47,9 +53,12 @@
47
53
  "magic-string": "^0.30.17"
48
54
  },
49
55
  "exports:override": {
50
- "./*.d.marko": "./tag-types/*",
56
+ ".": {
57
+ "types": "./index.d.ts"
58
+ },
51
59
  "./translator": "./src/translator/index.ts",
52
- "./*": "./src/*.ts",
53
- "./debug/*": "./src/*.ts"
60
+ "./tag-types/*": "./tag-types/*",
61
+ "./debug/*": "./src/*.ts",
62
+ "./*": "./src/*.ts"
54
63
  }
55
64
  }