ember-repl 5.0.1 → 6.0.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.
- package/declarations/compile/formats/gjs/eval.d.ts.map +1 -1
- package/declarations/compile/formats/gjs/index.d.ts.map +1 -1
- package/declarations/compile/formats/gjs/known-modules.d.ts +3 -1
- package/declarations/compile/formats/gjs/known-modules.d.ts.map +1 -1
- package/declarations/compile/formats/hbs.d.ts.map +1 -1
- package/declarations/compile/formats/markdown.d.ts.map +1 -1
- package/declarations/compile/formats.d.ts +1 -2
- package/declarations/compile/formats.d.ts.map +1 -1
- package/declarations/compile/index.d.ts +1 -2
- package/declarations/compile/index.d.ts.map +1 -1
- package/dist/compile/formats/gjs/eval.js +1 -2
- package/dist/compile/formats/gjs/eval.js.map +1 -1
- package/dist/compile/formats/gjs/index.js +12 -10
- package/dist/compile/formats/gjs/index.js.map +1 -1
- package/dist/compile/formats/gjs/known-modules.js +3 -1
- package/dist/compile/formats/gjs/known-modules.js.map +1 -1
- package/dist/compile/formats/hbs.js +10 -11
- package/dist/compile/formats/hbs.js.map +1 -1
- package/dist/compile/formats/markdown.js +23 -21
- package/dist/compile/formats/markdown.js.map +1 -1
- package/dist/compile/formats.js +14 -14
- package/dist/compile/formats.js.map +1 -1
- package/dist/compile/index.js +10 -10
- package/dist/compile/index.js.map +1 -1
- package/dist/compile/utils.js +1 -1
- package/dist/compile/utils.js.map +1 -1
- package/package.json +42 -50
- package/src/compile/formats/gjs/eval.ts +1 -2
- package/src/compile/formats/gjs/index.ts +12 -10
- package/src/compile/formats/gjs/known-modules.ts +1 -1
- package/src/compile/formats/hbs.ts +10 -11
- package/src/compile/formats/markdown.ts +22 -21
- package/src/compile/formats.ts +15 -16
- package/src/compile/index.ts +12 -12
- package/src/compile/utils.ts +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"eval.d.ts","sourceRoot":"","sources":["../../../../src/compile/formats/gjs/eval.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"eval.d.ts","sourceRoot":"","sources":["../../../../src/compile/formats/gjs/eval.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,SAAS,MAAM,oBAAoB,CAAC;AAEhD,wBAAgB,WAAW,CACzB,QAAQ,EAAE,MAAM,EAChB,YAAY,GAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAA4B,GAC/D;IACD,OAAO,EAAE,SAAS,CAAC;IACnB,QAAQ,CAAC,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;KAAE,CAAC;CACvC,CAkBA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/compile/formats/gjs/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/compile/formats/gjs/index.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAGpD,MAAM,WAAW,IAAI;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;CACd;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAsB,SAAS,CAC7B,IAAI,EAAE,MAAM,EACZ,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GACrC,OAAO,CAAC,aAAa,CAAC,CAkBxB"}
|
|
@@ -25,7 +25,9 @@ export declare const modules: {
|
|
|
25
25
|
'@ember/array': typeof _array;
|
|
26
26
|
'@ember/component': typeof _EmberComponent;
|
|
27
27
|
'@ember/component/helper': typeof _EmberComponentHelper;
|
|
28
|
-
'@ember/component/template-only': <S>(moduleName?: string, name?: string) => import("@ember/component/template-only").TemplateOnlyComponent<S
|
|
28
|
+
'@ember/component/template-only': (<S>(moduleName?: string, name?: string) => import("@ember/component/template-only").TemplateOnlyComponent<S>) & {
|
|
29
|
+
default: <S>(moduleName?: string, name?: string) => import("@ember/component/template-only").TemplateOnlyComponent<S>;
|
|
30
|
+
};
|
|
29
31
|
'@ember/debug': typeof _debug;
|
|
30
32
|
'@ember/destroyable': typeof _destroyable;
|
|
31
33
|
'@ember/helper': typeof _helpers;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"known-modules.d.ts","sourceRoot":"","sources":["../../../../src/compile/formats/gjs/known-modules.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,iBAAiB,MAAM,oBAAoB,CAAC;AACnD,OAAO,KAAK,SAAS,MAAM,mBAAmB,CAAC;AAC/C,OAAO,KAAK,YAAY,MAAM,oBAAoB,CAAC;AACnD,OAAO,KAAK,MAAM,MAAM,cAAc,CAAC;AACvC,OAAO,KAAK,eAAe,MAAM,kBAAkB,CAAC;AACpD,OAAO,KAAK,qBAAqB,MAAM,yBAAyB,CAAC;AAEjE,OAAO,KAAK,MAAM,MAAM,cAAc,CAAC;AACvC,OAAO,KAAK,YAAY,MAAM,oBAAoB,CAAC;AACnD,OAAO,KAAK,QAAQ,MAAM,eAAe,CAAC;AAC1C,OAAO,KAAK,SAAS,MAAM,iBAAiB,CAAC;AAC7C,OAAO,KAAK,OAAO,MAAM,eAAe,CAAC;AACzC,OAAO,KAAK,MAAM,MAAM,cAAc,CAAC;AACvC,OAAO,KAAK,QAAQ,MAAM,gBAAgB,CAAC;AAC3C,OAAO,KAAK,QAAQ,MAAM,gBAAgB,CAAC;AAC3C,OAAO,KAAK,SAAS,MAAM,iBAAiB,CAAC;AAG7C,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAChE,OAAO,KAAK,MAAM,MAAM,cAAc,CAAC;AAEvC,OAAO,KAAK,kBAAkB,MAAM,8BAA8B,CAAC;AAEnE,eAAO,MAAM,OAAO
|
|
1
|
+
{"version":3,"file":"known-modules.d.ts","sourceRoot":"","sources":["../../../../src/compile/formats/gjs/known-modules.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,iBAAiB,MAAM,oBAAoB,CAAC;AACnD,OAAO,KAAK,SAAS,MAAM,mBAAmB,CAAC;AAC/C,OAAO,KAAK,YAAY,MAAM,oBAAoB,CAAC;AACnD,OAAO,KAAK,MAAM,MAAM,cAAc,CAAC;AACvC,OAAO,KAAK,eAAe,MAAM,kBAAkB,CAAC;AACpD,OAAO,KAAK,qBAAqB,MAAM,yBAAyB,CAAC;AAEjE,OAAO,KAAK,MAAM,MAAM,cAAc,CAAC;AACvC,OAAO,KAAK,YAAY,MAAM,oBAAoB,CAAC;AACnD,OAAO,KAAK,QAAQ,MAAM,eAAe,CAAC;AAC1C,OAAO,KAAK,SAAS,MAAM,iBAAiB,CAAC;AAC7C,OAAO,KAAK,OAAO,MAAM,eAAe,CAAC;AACzC,OAAO,KAAK,MAAM,MAAM,cAAc,CAAC;AACvC,OAAO,KAAK,QAAQ,MAAM,gBAAgB,CAAC;AAC3C,OAAO,KAAK,QAAQ,MAAM,gBAAgB,CAAC;AAC3C,OAAO,KAAK,SAAS,MAAM,iBAAiB,CAAC;AAG7C,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAChE,OAAO,KAAK,MAAM,MAAM,cAAc,CAAC;AAEvC,OAAO,KAAK,kBAAkB,MAAM,8BAA8B,CAAC;AAEnE,eAAO,MAAM,OAAO;;;;;;;;;;;;;;;;;;;;;;;;CAqBnB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hbs.d.ts","sourceRoot":"","sources":["../../../src/compile/formats/hbs.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"hbs.d.ts","sourceRoot":"","sources":["../../../src/compile/formats/hbs.ts"],"names":[],"mappings":"AAiBA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAGjD;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,GAAE,sBAA2B,GAAG,aAAa,CAehG;AAED,UAAU,sBAAsB;IAC9B;;OAEG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACjC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"markdown.d.ts","sourceRoot":"","sources":["../../../src/compile/formats/markdown.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAMjD,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,kBAAkB;IACjC,oBAAoB,EAAE,MAAM,CAAC;IAC7B,MAAM,EAAE,aAAa,EAAE,CAAC;CACzB;
|
|
1
|
+
{"version":3,"file":"markdown.d.ts","sourceRoot":"","sources":["../../../src/compile/formats/markdown.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAMjD,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,kBAAkB;IACjC,oBAAoB,EAAE,MAAM,CAAC;IAC7B,MAAM,EAAE,aAAa,EAAE,CAAC;CACzB;AA2SD,UAAU,oBAAoB;IAC5B,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,aAAa,CAAC,EAAE,aAAa,EAAE,CAAC;IAChC,aAAa,CAAC,EAAE,aAAa,EAAE,CAAC;CACjC;AAED;;GAEG;AACH,wBAAsB,aAAa,CACjC,KAAK,EAAE,MAAM,EACb,OAAO,GAAE,oBAAyB,GACjC,OAAO,CAAC,kBAAkB,CAAC,CAO7B"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import type { CompileResult, UnifiedPlugin } from './types.ts';
|
|
2
|
-
import type { EvalImportMap, ScopeMap } from './types.ts';
|
|
1
|
+
import type { CompileResult, EvalImportMap, ScopeMap, UnifiedPlugin } from './types.ts';
|
|
3
2
|
export declare function compileGJS(gjsInput: string, importMap?: EvalImportMap): Promise<CompileResult>;
|
|
4
3
|
export declare function compileHBS(hbsInput: string, options?: {
|
|
5
4
|
moduleName?: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"formats.d.ts","sourceRoot":"","sources":["../../src/compile/formats.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,aAAa,EAAE,aAAa,EAAE,
|
|
1
|
+
{"version":3,"file":"formats.d.ts","sourceRoot":"","sources":["../../src/compile/formats.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,aAAa,EAAE,aAAa,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAYxF,wBAAsB,UAAU,CAC9B,QAAQ,EAAE,MAAM,EAChB,SAAS,CAAC,EAAE,aAAa,GACxB,OAAO,CAAC,aAAa,CAAC,CAQxB;AAED,wBAAsB,UAAU,CAC9B,QAAQ,EAAE,MAAM,EAChB,OAAO,CAAC,EAAE;IACR,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACjC,GACA,OAAO,CAAC,aAAa,CAAC,CAQxB;AA2CD,wBAAsB,SAAS,CAC7B,aAAa,EAAE,MAAM,EACrB,OAAO,CAAC,EAAE;IACR,SAAS,CAAC,EAAE,aAAa,CAAC;IAC1B,aAAa,CAAC,EAAE,QAAQ,CAAC;IACzB,aAAa,CAAC,EAAE,aAAa,EAAE,CAAC;IAChC,aAAa,CAAC,EAAE,aAAa,EAAE,CAAC;IAChC,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B,GACA,OAAO,CAAC,aAAa,GAAG;IAAE,YAAY,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC,CAkFpD"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import type { UnifiedPlugin } from './types.ts';
|
|
2
|
-
import type { EvalImportMap, ScopeMap } from './types.ts';
|
|
1
|
+
import type { EvalImportMap, ScopeMap, UnifiedPlugin } from './types.ts';
|
|
3
2
|
import type { ComponentLike } from '@glint/template';
|
|
4
3
|
type Format = 'glimdown' | 'gjs' | 'hbs';
|
|
5
4
|
export declare const CACHE: Map<string, ComponentLike>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/compile/index.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAiB,aAAa,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/compile/index.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAiB,aAAa,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AACxF,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAErD,KAAK,MAAM,GAAG,UAAU,GAAG,KAAK,GAAG,KAAK,CAAC;AAEzC,eAAO,MAAM,KAAK,4BAAmC,CAAC;AAEtD,UAAU,MAAM;IACd,SAAS,EAAE,CAAC,SAAS,EAAE,aAAa,KAAK,OAAO,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC;IACpE,OAAO,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC;IACvD,cAAc,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC;CAClD;AAED,UAAU,KAAK;IACb,SAAS,CAAC,EAAE,aAAa,CAAC;CAC3B;AAID,UAAU,eAAgB,SAAQ,KAAK,EAAE,MAAM;IAC7C,MAAM,EAAE,UAAU,CAAC;IACnB,aA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,SAAS,CAAC,EAAE,aAAa,CAAC;IAC1B,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,aAAa,CAAC,EAAE,QAAQ,CAAC;CAC1B,GACD;IACE,MAAM,EAAE,KAAK,CAAC;IACd,aAAa,CAAC,EAAE,QAAQ,CAAC;CAC1B,GACD;IACE,MAAM,EAAE,KAAK,CAAC;IACd,SAAS,CAAC,EAAE,aAAa,CAAC;CAC3B,CAAC;AAEN;;GAEG;AACH,MAAM,WAAW,KAAK;IACpB,OAAO,EAAE,OAAO,CAAC;IACjB,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,SAAS,EAAE,aAAa,CAAC;CAC1B;AAED,wBAAgB,QAAQ,CAAC,YAAY,EAAE,KAAK,GAAG,CAAC,MAAM,KAAK,CAAC,GAAG,KAAK,CAAC;AACrE,wBAAgB,QAAQ,CAAC,YAAY,EAAE,KAAK,GAAG,CAAC,MAAM,KAAK,CAAC,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,KAAK,CAAC;AACvF,wBAAgB,QAAQ,CAAC,YAAY,EAAE,KAAK,GAAG,CAAC,MAAM,KAAK,CAAC,EAAE,OAAO,CAAC,EAAE,MAAM,MAAM,GAAG,KAAK,CAAC;AAC7F,wBAAgB,QAAQ,CAAC,YAAY,EAAE,KAAK,GAAG,CAAC,MAAM,KAAK,CAAC,EAAE,OAAO,CAAC,EAAE,YAAY,GAAG,KAAK,CAAC;AAC7F,wBAAgB,QAAQ,CAAC,YAAY,EAAE,KAAK,GAAG,CAAC,MAAM,KAAK,CAAC,EAAE,OAAO,CAAC,EAAE,MAAM,YAAY,GAAG,KAAK,CAAC"}
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { modules } from './known-modules.js';
|
|
2
2
|
|
|
3
|
-
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
4
3
|
function evalSnippet(compiled, extraModules = {}) {
|
|
5
4
|
const exports = {};
|
|
6
5
|
function require(moduleName) {
|
|
7
|
-
|
|
6
|
+
const preConfigured = modules[moduleName] || extraModules[moduleName];
|
|
8
7
|
|
|
9
8
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
10
9
|
// @ts-ignore
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"eval.js","sources":["../../../../src/compile/formats/gjs/eval.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"file":"eval.js","sources":["../../../../src/compile/formats/gjs/eval.ts"],"sourcesContent":["import { modules } from './known-modules.ts';\n\nimport type Component from '@glimmer/component';\n\nexport function evalSnippet(\n compiled: string,\n extraModules: Record<string, unknown /* imported module */> = {}\n): {\n default: Component;\n services?: { [key: string]: unknown };\n} {\n const exports = {};\n\n function require(moduleName: keyof typeof modules): unknown {\n const preConfigured = modules[moduleName] || extraModules[moduleName];\n\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n return preConfigured || window.require(moduleName);\n }\n\n eval(compiled);\n\n return Object.assign(exports, { require }) as {\n default: Component;\n services?: { [key: string]: unknown };\n require: unknown;\n };\n}\n"],"names":["evalSnippet","compiled","extraModules","exports","require","moduleName","preConfigured","modules","window","eval","Object","assign"],"mappings":";;AAIO,SAASA,WAAWA,CACzBC,QAAgB,EAChBC,YAA2D,GAAG,EAAE,EAIhE;EACA,MAAMC,OAAO,GAAG,EAAE;EAElB,SAASC,OAAOA,CAACC,UAAgC,EAAW;IAC1D,MAAMC,aAAa,GAAGC,OAAO,CAACF,UAAU,CAAC,IAAIH,YAAY,CAACG,UAAU,CAAC;;AAErE;AACA;AACA,IAAA,OAAOC,aAAa,IAAIE,MAAM,CAACJ,OAAO,CAACC,UAAU,CAAC;AACpD;EAEAI,IAAI,CAACR,QAAQ,CAAC;AAEd,EAAA,OAAOS,MAAM,CAACC,MAAM,CAACR,OAAO,EAAE;AAAEC,IAAAA;AAAQ,GAAC,CAAC;AAK5C;;;;"}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import * as compiler from 'ember-template-compiler';
|
|
1
|
+
import * as compiler from 'ember-source/dist/ember-template-compiler.js';
|
|
2
2
|
import { nameFor } from '../../utils.js';
|
|
3
3
|
import { evalSnippet } from './eval.js';
|
|
4
4
|
|
|
5
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
6
|
+
// @ts-ignore
|
|
5
7
|
/**
|
|
6
8
|
* @public
|
|
7
9
|
* Transpiles GlimmerJS (*.gjs) formatted text into and evaluates as a JS Module.
|
|
@@ -20,11 +22,11 @@ import { evalSnippet } from './eval.js';
|
|
|
20
22
|
* needs to be downloaded before running the `code` / invoking the component
|
|
21
23
|
*/
|
|
22
24
|
async function compileJS(code, extraModules) {
|
|
23
|
-
|
|
25
|
+
const name = nameFor(code);
|
|
24
26
|
let component;
|
|
25
27
|
let error;
|
|
26
28
|
try {
|
|
27
|
-
|
|
29
|
+
const compiled = await transpile({
|
|
28
30
|
code: code,
|
|
29
31
|
name
|
|
30
32
|
});
|
|
@@ -45,12 +47,12 @@ async function transpile({
|
|
|
45
47
|
code: input,
|
|
46
48
|
name
|
|
47
49
|
}) {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
+
const preprocessed = await preprocess(input, name);
|
|
51
|
+
const result = await transform(preprocessed, name);
|
|
50
52
|
if (!result) {
|
|
51
53
|
return;
|
|
52
54
|
}
|
|
53
|
-
|
|
55
|
+
const {
|
|
54
56
|
code
|
|
55
57
|
} = result;
|
|
56
58
|
return code;
|
|
@@ -62,12 +64,12 @@ async function preprocess(input, name) {
|
|
|
62
64
|
fetchingPromise = import('content-tag');
|
|
63
65
|
}
|
|
64
66
|
if (!processor) {
|
|
65
|
-
|
|
67
|
+
const {
|
|
66
68
|
Preprocessor
|
|
67
69
|
} = await fetchingPromise;
|
|
68
70
|
processor = new Preprocessor();
|
|
69
71
|
}
|
|
70
|
-
|
|
72
|
+
const {
|
|
71
73
|
code /* map */
|
|
72
74
|
} = processor.process(input, {
|
|
73
75
|
filename: `${name}.js`,
|
|
@@ -93,9 +95,9 @@ async function transform(intermediate, name) {
|
|
|
93
95
|
const emberTemplateCompilation = 'default' in _emberTemplateCompilation ? _emberTemplateCompilation.default : _emberTemplateCompilation;
|
|
94
96
|
|
|
95
97
|
// so we have to use the default export (which is all the exports)
|
|
96
|
-
|
|
98
|
+
const maybeBabel = await import('@babel/standalone');
|
|
97
99
|
// Handle difference between vite and webpack in consuming projects...
|
|
98
|
-
|
|
100
|
+
const babel = 'availablePlugins' in maybeBabel ? maybeBabel : maybeBabel.default;
|
|
99
101
|
return babel.transform(intermediate, {
|
|
100
102
|
filename: `${name}.js`,
|
|
101
103
|
plugins: [[emberTemplateCompilation, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../../../src/compile/formats/gjs/index.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../../src/compile/formats/gjs/index.ts"],"sourcesContent":["// eslint-disable-next-line @typescript-eslint/ban-ts-comment\n// @ts-ignore\nimport * as compiler from 'ember-source/dist/ember-template-compiler.js';\n\nimport { nameFor } from '../../utils.ts';\nimport { evalSnippet } from './eval.ts';\n\nimport type { CompileResult } from '../../types.ts';\nimport type { ComponentLike } from '@glint/template';\n\nexport interface Info {\n code: string;\n name: string;\n}\n\n/**\n * @public\n * Transpiles GlimmerJS (*.gjs) formatted text into and evaluates as a JS Module.\n * The returned component can be invoked explicitly in the consuming project.\n *\n * SEE: README for example usage\n *\n * @param {string} code: the code to be compiled\n * @param {Object} extraModules: map of import paths to modules. This isn't needed\n * for classic ember projects, but for strict static ember projects, extraModules\n * will need to be pasesd if compileJS is intended to be used in a styleguide or\n * if there are additional modules that could be imported in the passed `code`.\n *\n * Later on, imports that are not present by default (ember/glimmer) or that\n * are not provided by extraModules will be searched on npm to see if a package\n * needs to be downloaded before running the `code` / invoking the component\n */\nexport async function compileJS(\n code: string,\n extraModules?: Record<string, unknown>\n): Promise<CompileResult> {\n const name = nameFor(code);\n let component: undefined | ComponentLike;\n let error: undefined | Error;\n\n try {\n const compiled = await transpile({ code: code, name });\n\n if (!compiled) {\n throw new Error(`Compiled output is missing`);\n }\n\n component = evalSnippet(compiled, extraModules).default as unknown as ComponentLike;\n } catch (e) {\n error = e as Error | undefined;\n }\n\n return { name, component, error };\n}\n\nasync function transpile({ code: input, name }: Info) {\n const preprocessed = await preprocess(input, name);\n const result = await transform(preprocessed, name);\n\n if (!result) {\n return;\n }\n\n const { code } = result;\n\n return code;\n}\n\nimport type { Babel } from './babel.ts';\n\nlet processor: any;\nlet fetchingPromise: Promise<any>;\n\nasync function preprocess(input: string, name: string): Promise<string> {\n if (!fetchingPromise) {\n fetchingPromise = import('content-tag');\n }\n\n if (!processor) {\n const { Preprocessor } = await fetchingPromise;\n\n processor = new Preprocessor();\n }\n\n const { code /* map */ } = processor.process(input, {\n filename: `${name}.js`,\n inline_source_map: true,\n });\n\n return code;\n}\n\nasync function transform(\n intermediate: string,\n name: string\n): Promise<ReturnType<Babel['transform']>> {\n const [\n // _parser, _traverse, _generator,\n _decoratorTransforms,\n _emberTemplateCompilation,\n ] = await Promise.all([\n // @babel/* doesn't have the greatest ESM compat yet\n // https://github.com/babel/babel/issues/14314#issuecomment-1054505190\n //\n // babel-standalone is so easy...\n // import('@babel/parser'),\n // import('@babel/traverse'),\n // import('@babel/generator'),\n import('decorator-transforms'),\n import('babel-plugin-ember-template-compilation'),\n ]);\n\n // These libraries are compiled incorrectly for cjs<->ESM compat\n const decoratorTransforms =\n 'default' in _decoratorTransforms ? _decoratorTransforms.default : _decoratorTransforms;\n\n const emberTemplateCompilation =\n 'default' in _emberTemplateCompilation\n ? _emberTemplateCompilation.default\n : _emberTemplateCompilation;\n\n // so we have to use the default export (which is all the exports)\n const maybeBabel = (await import('@babel/standalone')) as any;\n // Handle difference between vite and webpack in consuming projects...\n const babel: Babel = 'availablePlugins' in maybeBabel ? maybeBabel : maybeBabel.default;\n\n return babel.transform(intermediate, {\n filename: `${name}.js`,\n plugins: [\n [\n emberTemplateCompilation,\n {\n compiler,\n },\n ],\n [\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore - we don't care about types here..\n decoratorTransforms,\n {\n runtime: {\n import: 'decorator-transforms/runtime',\n },\n },\n ],\n // Womp.\n // See this exploration into true ESM:\n // https://github.com/NullVoxPopuli/limber/pull/1805\n [babel.availablePlugins['transform-modules-commonjs']],\n ],\n presets: [],\n });\n}\n"],"names":["compileJS","code","extraModules","name","nameFor","component","error","compiled","transpile","Error","evalSnippet","default","e","input","preprocessed","preprocess","result","transform","processor","fetchingPromise","Preprocessor","process","filename","inline_source_map","intermediate","_decoratorTransforms","_emberTemplateCompilation","Promise","all","decoratorTransforms","emberTemplateCompilation","maybeBabel","babel","plugins","compiler","runtime","import","availablePlugins","presets"],"mappings":";;;;AAAA;AACA;AAcA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,eAAeA,SAASA,CAC7BC,IAAY,EACZC,YAAsC,EACd;AACxB,EAAA,MAAMC,IAAI,GAAGC,OAAO,CAACH,IAAI,CAAC;AAC1B,EAAA,IAAII,SAAoC;AACxC,EAAA,IAAIC,KAAwB;EAE5B,IAAI;AACF,IAAA,MAAMC,QAAQ,GAAG,MAAMC,SAAS,CAAC;AAAEP,MAAAA,IAAI,EAAEA,IAAI;AAAEE,MAAAA;AAAK,KAAC,CAAC;IAEtD,IAAI,CAACI,QAAQ,EAAE;AACb,MAAA,MAAM,IAAIE,KAAK,CAAC,CAAA,0BAAA,CAA4B,CAAC;AAC/C;IAEAJ,SAAS,GAAGK,WAAW,CAACH,QAAQ,EAAEL,YAAY,CAAC,CAACS,OAAmC;GACpF,CAAC,OAAOC,CAAC,EAAE;AACVN,IAAAA,KAAK,GAAGM,CAAsB;AAChC;EAEA,OAAO;IAAET,IAAI;IAAEE,SAAS;AAAEC,IAAAA;GAAO;AACnC;AAEA,eAA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oBAAoB;EAEzF,MAAMK,wBAAwB,GAC5B,SAAS,IAAIJ,yBAAyB,GAClCA,yBAAyB,CAACf,OAAO,GACjCe,yBAAyB;;AAE/B;AACA,EAAA,MAAMK,UAAU,GAAI,MAAM,OAAO,mBAAmB,CAAS;AAC7D;EACA,MAAMC,KAAY,GAAG,kBAAkB,IAAID,UAAU,GAAGA,UAAU,GAAGA,UAAU,CAACpB,OAAO;AAEvF,EAAA,OAAOqB,KAAK,CAACf,SAAS,CAACO,YAAY,EAAE;IACnCF,QAAQ,EAAE,CAAGnB,EAAAA,IAAI,CAAK,GAAA,CAAA;AACtB8B,IAAAA,OAAO,EAAE,CACP,CACEH,wBAAwB,EACxB;AACEI,MAAAA;AACF,KAAC,CACF,EACD;AACE;AACA;AACAL,IAAAA,mBAAmB,EACnB;AACEM,MAAAA,OAAO,EAAE;AACPC,QAAAA,MAAM,EAAE;AACV;AACF,KAAC,CACF;AACD;AACA;AACA;AACA,IAAA,CAACJ,KAAK,CAACK,gBAAgB,CAAC,4BAA4B,CAAC,CAAC,CACvD;AACDC,IAAAA,OAAO,EAAE;AACX,GAAC,CAAC;AACJ;;;;"}
|
|
@@ -27,7 +27,9 @@ const modules = {
|
|
|
27
27
|
'@ember/array': _array,
|
|
28
28
|
'@ember/component': _EmberComponent,
|
|
29
29
|
'@ember/component/helper': _EmberComponentHelper,
|
|
30
|
-
'@ember/component/template-only': _TO,
|
|
30
|
+
'@ember/component/template-only': Object.assign(_TO, {
|
|
31
|
+
default: _TO
|
|
32
|
+
}),
|
|
31
33
|
'@ember/debug': _debug,
|
|
32
34
|
'@ember/destroyable': _destroyable,
|
|
33
35
|
'@ember/helper': _helpers,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"known-modules.js","sources":["../../../../src/compile/formats/gjs/known-modules.ts"],"sourcesContent":["/**\n * We need to import and hang on to these references so that they\n * don't get optimized away during deploy\n */\nimport _GlimmerComponent from '@glimmer/component';\nimport * as _tracking from '@glimmer/tracking';\nimport * as _application from '@ember/application';\nimport * as _array from '@ember/array';\nimport * as _EmberComponent from '@ember/component';\nimport * as _EmberComponentHelper from '@ember/component/helper';\nimport _TO from '@ember/component/template-only';\nimport * as _debug from '@ember/debug';\nimport * as _destroyable from '@ember/destroyable';\nimport * as _helpers from '@ember/helper';\nimport * as _modifier from '@ember/modifier';\nimport * as _object from '@ember/object';\nimport * as _owner from '@ember/owner';\nimport * as _runloop from '@ember/runloop';\nimport * as _service from '@ember/service';\nimport * as _template from '@ember/template';\n// eslint-disable-next-line @typescript-eslint/ban-ts-comment\n// @ts-ignore\nimport { createTemplateFactory } from '@ember/template-factory';\nimport * as _utils from '@ember/utils';\n\nimport * as _decoratorsRuntime from 'decorator-transforms/runtime';\n\nexport const modules = {\n '@ember/application': _application,\n '@ember/array': _array,\n '@ember/component': _EmberComponent,\n '@ember/component/helper': _EmberComponentHelper,\n '@ember/component/template-only': _TO,\n '@ember/debug': _debug,\n '@ember/destroyable': _destroyable,\n '@ember/helper': _helpers,\n '@ember/modifier': _modifier,\n '@ember/object': _object,\n '@ember/runloop': _runloop,\n '@ember/service': _service,\n '@ember/template-factory': { createTemplateFactory },\n '@ember/utils': _utils,\n '@ember/template': _template,\n '@ember/owner': _owner,\n\n '@glimmer/component': _GlimmerComponent,\n '@glimmer/tracking': _tracking,\n 'decorator-transforms/runtime': _decoratorsRuntime,\n};\n"],"names":["modules","_application","_array","_EmberComponent","_EmberComponentHelper","_TO","_debug","_destroyable","_helpers","_modifier","_object","_runloop","_service","createTemplateFactory","_utils","_template","_owner","_GlimmerComponent","_tracking","_decoratorsRuntime"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AACA;AACA;AACA;AAwBO,MAAMA,OAAO,GAAG;AACrB,EAAA,oBAAoB,EAAEC,YAAY;AAClC,EAAA,cAAc,EAAEC,MAAM;AACtB,EAAA,kBAAkB,EAAEC,eAAe;AACnC,EAAA,yBAAyB,EAAEC,qBAAqB;AAChD,EAAA,gCAAgC,EAAEC,GAAG;
|
|
1
|
+
{"version":3,"file":"known-modules.js","sources":["../../../../src/compile/formats/gjs/known-modules.ts"],"sourcesContent":["/**\n * We need to import and hang on to these references so that they\n * don't get optimized away during deploy\n */\nimport _GlimmerComponent from '@glimmer/component';\nimport * as _tracking from '@glimmer/tracking';\nimport * as _application from '@ember/application';\nimport * as _array from '@ember/array';\nimport * as _EmberComponent from '@ember/component';\nimport * as _EmberComponentHelper from '@ember/component/helper';\nimport _TO from '@ember/component/template-only';\nimport * as _debug from '@ember/debug';\nimport * as _destroyable from '@ember/destroyable';\nimport * as _helpers from '@ember/helper';\nimport * as _modifier from '@ember/modifier';\nimport * as _object from '@ember/object';\nimport * as _owner from '@ember/owner';\nimport * as _runloop from '@ember/runloop';\nimport * as _service from '@ember/service';\nimport * as _template from '@ember/template';\n// eslint-disable-next-line @typescript-eslint/ban-ts-comment\n// @ts-ignore\nimport { createTemplateFactory } from '@ember/template-factory';\nimport * as _utils from '@ember/utils';\n\nimport * as _decoratorsRuntime from 'decorator-transforms/runtime';\n\nexport const modules = {\n '@ember/application': _application,\n '@ember/array': _array,\n '@ember/component': _EmberComponent,\n '@ember/component/helper': _EmberComponentHelper,\n '@ember/component/template-only': Object.assign(_TO, { default: _TO }),\n '@ember/debug': _debug,\n '@ember/destroyable': _destroyable,\n '@ember/helper': _helpers,\n '@ember/modifier': _modifier,\n '@ember/object': _object,\n '@ember/runloop': _runloop,\n '@ember/service': _service,\n '@ember/template-factory': { createTemplateFactory },\n '@ember/utils': _utils,\n '@ember/template': _template,\n '@ember/owner': _owner,\n\n '@glimmer/component': _GlimmerComponent,\n '@glimmer/tracking': _tracking,\n 'decorator-transforms/runtime': _decoratorsRuntime,\n};\n"],"names":["modules","_application","_array","_EmberComponent","_EmberComponentHelper","Object","assign","_TO","default","_debug","_destroyable","_helpers","_modifier","_object","_runloop","_service","createTemplateFactory","_utils","_template","_owner","_GlimmerComponent","_tracking","_decoratorsRuntime"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AACA;AACA;AACA;AAwBO,MAAMA,OAAO,GAAG;AACrB,EAAA,oBAAoB,EAAEC,YAAY;AAClC,EAAA,cAAc,EAAEC,MAAM;AACtB,EAAA,kBAAkB,EAAEC,eAAe;AACnC,EAAA,yBAAyB,EAAEC,qBAAqB;AAChD,EAAA,gCAAgC,EAAEC,MAAM,CAACC,MAAM,CAACC,GAAG,EAAE;AAAEC,IAAAA,OAAO,EAAED;AAAI,GAAC,CAAC;AACtE,EAAA,cAAc,EAAEE,MAAM;AACtB,EAAA,oBAAoB,EAAEC,YAAY;AAClC,EAAA,eAAe,EAAEC,QAAQ;AACzB,EAAA,iBAAiB,EAAEC,SAAS;AAC5B,EAAA,eAAe,EAAEC,OAAO;AACxB,EAAA,gBAAgB,EAAEC,QAAQ;AAC1B,EAAA,gBAAgB,EAAEC,QAAQ;AAC1B,EAAA,yBAAyB,EAAE;AAAEC,IAAAA;GAAuB;AACpD,EAAA,cAAc,EAAEC,MAAM;AACtB,EAAA,iBAAiB,EAAEC,SAAS;AAC5B,EAAA,cAAc,EAAEC,MAAM;AAEtB,EAAA,oBAAoB,EAAEC,iBAAiB;AACvC,EAAA,mBAAmB,EAAEC,SAAS;AAC9B,EAAA,8BAA8B,EAAEC;AAClC;;;;"}
|
|
@@ -7,7 +7,6 @@ import { on } from '@ember/modifier';
|
|
|
7
7
|
import { createTemplateFactory } from '@ember/template-factory';
|
|
8
8
|
import { nameFor } from '../utils.js';
|
|
9
9
|
|
|
10
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
11
10
|
// import { precompileJSON } from '@glimmer/compiler';
|
|
12
11
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
13
12
|
// @ts-ignore
|
|
@@ -20,7 +19,7 @@ import { nameFor } from '../utils.js';
|
|
|
20
19
|
* (templates alone do not have a way to import / define complex structures)
|
|
21
20
|
*/
|
|
22
21
|
function compileHBS(template, options = {}) {
|
|
23
|
-
|
|
22
|
+
const name = nameFor(template);
|
|
24
23
|
let component;
|
|
25
24
|
let error;
|
|
26
25
|
try {
|
|
@@ -49,7 +48,7 @@ function compileTemplate(source, {
|
|
|
49
48
|
moduleName,
|
|
50
49
|
scope = {}
|
|
51
50
|
}) {
|
|
52
|
-
|
|
51
|
+
const localScope = {
|
|
53
52
|
array,
|
|
54
53
|
concat,
|
|
55
54
|
fn,
|
|
@@ -58,8 +57,8 @@ function compileTemplate(source, {
|
|
|
58
57
|
on,
|
|
59
58
|
...scope
|
|
60
59
|
};
|
|
61
|
-
|
|
62
|
-
|
|
60
|
+
const locals = getTemplateLocals(source);
|
|
61
|
+
const options = {
|
|
63
62
|
strictMode: true,
|
|
64
63
|
moduleName,
|
|
65
64
|
locals,
|
|
@@ -70,23 +69,23 @@ function compileTemplate(source, {
|
|
|
70
69
|
};
|
|
71
70
|
|
|
72
71
|
// Copied from @glimmer/compiler/lib/compiler#precompile
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
72
|
+
const [block, usedLocals] = precompileJSON(source, options);
|
|
73
|
+
const usedScope = usedLocals.map(key => {
|
|
74
|
+
const value = localScope[key];
|
|
76
75
|
if (!value) {
|
|
77
76
|
throw new Error(`Attempt to use ${key} in compiled hbs, but it was not available in scope. ` + `Available scope includes: ${Object.keys(localScope)}`);
|
|
78
77
|
}
|
|
79
78
|
return value;
|
|
80
79
|
});
|
|
81
|
-
|
|
82
|
-
|
|
80
|
+
const blockJSON = JSON.stringify(block);
|
|
81
|
+
const templateJSONObject = {
|
|
83
82
|
id: moduleName,
|
|
84
83
|
block: blockJSON,
|
|
85
84
|
moduleName: moduleName ?? '(dynamically compiled component)',
|
|
86
85
|
scope: () => usedScope,
|
|
87
86
|
isStrictMode: true
|
|
88
87
|
};
|
|
89
|
-
|
|
88
|
+
const factory = createTemplateFactory(templateJSONObject);
|
|
90
89
|
return factory;
|
|
91
90
|
}
|
|
92
91
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hbs.js","sources":["../../../src/compile/formats/hbs.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"file":"hbs.js","sources":["../../../src/compile/formats/hbs.ts"],"sourcesContent":["// import { precompileJSON } from '@glimmer/compiler';\n// eslint-disable-next-line @typescript-eslint/ban-ts-comment\n// @ts-ignore\n// These things are pre-bundled in the old system.\n// ember-template-compiler defines them in AMD/requirejs\nimport { precompileJSON } from '@glimmer/compiler';\nimport { getTemplateLocals } from '@glimmer/syntax';\nimport { setComponentTemplate } from '@ember/component';\nimport templateOnlyComponent from '@ember/component/template-only';\nimport { array, concat, fn, get, hash } from '@ember/helper';\nimport { on } from '@ember/modifier';\n// eslint-disable-next-line @typescript-eslint/ban-ts-comment\n// @ts-ignore\nimport { createTemplateFactory } from '@ember/template-factory';\n\nimport { nameFor } from '../utils.ts';\n\nimport type { CompileResult } from '../types.ts';\nimport type { ComponentLike } from '@glint/template';\n\n/**\n * compile a template with an empty scope\n * to use components, helpers, etc, you will need to compile with JS\n *\n * (templates alone do not have a way to import / define complex structures)\n */\nexport function compileHBS(template: string, options: CompileTemplateOptions = {}): CompileResult {\n const name = nameFor(template);\n let component: undefined | ComponentLike;\n let error: undefined | Error;\n\n try {\n component = setComponentTemplate(\n compileTemplate(template, { moduleName: options.moduleName || name, ...options }),\n templateOnlyComponent(options.moduleName || name)\n ) as ComponentLike;\n } catch (e) {\n error = e as Error | undefined;\n }\n\n return { name, component, error };\n}\n\ninterface CompileTemplateOptions {\n /**\n * Used for debug viewing\n */\n moduleName?: string;\n scope?: Record<string, unknown>;\n}\n\n/**\n * The reason why we can't use precompile directly is because of this:\n * https://github.com/glimmerjs/glimmer-vm/blob/master/packages/%40glimmer/compiler/lib/compiler.ts#L132\n *\n * Support for dynamically compiling templates in strict mode doesn't seem to be fully their yet.\n * That JSON.stringify (and the lines after) prevent us from easily setting the scope function,\n * which means that *everything* is undefined.\n */\nfunction compileTemplate(source: string, { moduleName, scope = {} }: CompileTemplateOptions) {\n const localScope = { array, concat, fn, get, hash, on, ...scope } as any;\n const locals = getTemplateLocals(source);\n\n const options = {\n strictMode: true,\n moduleName,\n locals,\n isProduction: false,\n meta: { moduleName },\n };\n\n // Copied from @glimmer/compiler/lib/compiler#precompile\n const [block, usedLocals] = precompileJSON(source, options);\n\n const usedScope = usedLocals.map((key: string) => {\n const value = localScope[key];\n\n if (!value) {\n throw new Error(\n `Attempt to use ${key} in compiled hbs, but it was not available in scope. ` +\n `Available scope includes: ${Object.keys(localScope)}`\n );\n }\n\n return value;\n });\n\n const blockJSON = JSON.stringify(block);\n const templateJSONObject = {\n id: moduleName,\n block: blockJSON,\n moduleName: moduleName ?? '(dynamically compiled component)',\n scope: () => usedScope,\n isStrictMode: true,\n };\n\n const factory = createTemplateFactory(templateJSONObject);\n\n return factory;\n}\n"],"names":["compileHBS","template","options","name","nameFor","component","error","setComponentTemplate","compileTemplate","moduleName","templateOnlyComponent","e","source","scope","localScope","array","concat","fn","get","hash","on","locals","getTemplateLocals","strictMode","isProduction","meta","block","usedLocals","precompileJSON","usedScope","map","key","value","Error","Object","keys","blockJSON","JSON","stringify","templateJSONObject","id","isStrictMode","factory","createTemplateFactory"],"mappings":";;;;;;;;;AAAA;AACA;AACA;AACA;AACA;AAgBA;AACA;AACA;AACA;AACA;AACA;AACO,SAASA,UAAUA,CAACC,QAAgB,EAAEC,OAA+B,GAAG,EAAE,EAAiB;AAChG,EAAA,MAAMC,IAAI,GAAGC,OAAO,CAACH,QAAQ,CAAC;AAC9B,EAAA,IAAII,SAAoC;AACxC,EAAA,IAAIC,KAAwB;EAE5B,IAAI;AACFD,IAAAA,SAAS,GAAGE,oBAAoB,CAC9BC,eAAe,CAACP,QAAQ,EAAE;AAAEQ,MAAAA,UAAU,EAAEP,OAAO,CAACO,UAAU,IAAIN,IAAI;MAAE,GAAGD;KAAS,CAAC,EACjFQ,GAAqB,CAACR,OAAO,CAACO,UAAU,IAAIN,IAAI,CAClD,CAAkB;GACnB,CAAC,OAAOQ,CAAC,EAAE;AACVL,I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AAS;IAChB3B,UAAU,EAAEA,UAAU,IAAI,kCAAkC;IAC5DI,KAAK,EAAEA,MAAMgB,SAAS;AACtBY,IAAAA,YAAY,EAAE;GACf;AAED,EAAA,MAAMC,OAAO,GAAGC,qBAAqB,CAACJ,kBAAkB,CAAC;AAEzD,EAAA,OAAOG,OAAO;AAChB;;;;"}
|
|
@@ -22,7 +22,7 @@ function isBelow(meta) {
|
|
|
22
22
|
|
|
23
23
|
// TODO: extract and publish remark plugin
|
|
24
24
|
function liveCodeExtraction(options = {}) {
|
|
25
|
-
|
|
25
|
+
const {
|
|
26
26
|
copyComponent,
|
|
27
27
|
snippets,
|
|
28
28
|
demo
|
|
@@ -38,7 +38,9 @@ function liveCodeExtraction(options = {}) {
|
|
|
38
38
|
function isRelevantCode(node) {
|
|
39
39
|
if (node.type !== 'code') return false;
|
|
40
40
|
let {
|
|
41
|
-
meta
|
|
41
|
+
meta
|
|
42
|
+
} = node;
|
|
43
|
+
const {
|
|
42
44
|
lang
|
|
43
45
|
} = node;
|
|
44
46
|
meta = meta?.trim();
|
|
@@ -49,7 +51,7 @@ function liveCodeExtraction(options = {}) {
|
|
|
49
51
|
if (!ALLOWED_LANGUAGES.includes(lang)) return false;
|
|
50
52
|
return true;
|
|
51
53
|
}
|
|
52
|
-
|
|
54
|
+
const copyNode = {
|
|
53
55
|
type: 'html',
|
|
54
56
|
value: copyComponent
|
|
55
57
|
};
|
|
@@ -83,13 +85,13 @@ function liveCodeExtraction(options = {}) {
|
|
|
83
85
|
if (parent === null || parent === undefined) return;
|
|
84
86
|
if (index === null || index === undefined) return;
|
|
85
87
|
if (!isRelevantCode(node)) {
|
|
86
|
-
|
|
88
|
+
const enhanced = enhance(node);
|
|
87
89
|
parent.children[index] = enhanced;
|
|
88
90
|
return 'skip';
|
|
89
91
|
}
|
|
90
92
|
if (seen.has(node)) return 'skip';
|
|
91
93
|
seen.add(node);
|
|
92
|
-
|
|
94
|
+
const {
|
|
93
95
|
meta,
|
|
94
96
|
lang,
|
|
95
97
|
value
|
|
@@ -97,15 +99,15 @@ function liveCodeExtraction(options = {}) {
|
|
|
97
99
|
if (!meta) return 'skip';
|
|
98
100
|
if (!lang) return 'skip';
|
|
99
101
|
file.data.liveCode ??= [];
|
|
100
|
-
|
|
101
|
-
|
|
102
|
+
const code = value.trim();
|
|
103
|
+
const name = nameFor(code);
|
|
102
104
|
let invocation = invocationOf(name);
|
|
103
|
-
|
|
104
|
-
|
|
105
|
+
const shadow = options.shadowComponent;
|
|
106
|
+
const wrapInShadow = shadow && !meta?.includes('no-shadow');
|
|
105
107
|
if (wrapInShadow) {
|
|
106
108
|
invocation = `<${shadow}>${invocation}</${shadow}>`;
|
|
107
109
|
}
|
|
108
|
-
|
|
110
|
+
const invokeNode = {
|
|
109
111
|
type: 'html',
|
|
110
112
|
data: {
|
|
111
113
|
hProperties: {
|
|
@@ -114,15 +116,15 @@ function liveCodeExtraction(options = {}) {
|
|
|
114
116
|
},
|
|
115
117
|
value: `<div class="${demoClasses}">${invocation}</div>`
|
|
116
118
|
};
|
|
117
|
-
|
|
119
|
+
const wrapper = enhance(node);
|
|
118
120
|
file.data.liveCode.push({
|
|
119
121
|
lang,
|
|
120
122
|
name,
|
|
121
123
|
code
|
|
122
124
|
});
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
125
|
+
const live = isLive(meta);
|
|
126
|
+
const preview = isPreview(meta);
|
|
127
|
+
const below = isBelow(meta);
|
|
126
128
|
if (live && preview && below) {
|
|
127
129
|
flatReplaceAt(parent.children, index, [wrapper, invokeNode]);
|
|
128
130
|
return 'skip';
|
|
@@ -167,7 +169,7 @@ function buildCompiler(options) {
|
|
|
167
169
|
options.remarkPlugins.forEach(plugin => {
|
|
168
170
|
// Arrays are how plugins are passed options (for some reason?)
|
|
169
171
|
// why not just invoke the the function?
|
|
170
|
-
|
|
172
|
+
const p = Array.isArray(plugin) ? plugin : [plugin];
|
|
171
173
|
compiler = compiler.use(...p);
|
|
172
174
|
});
|
|
173
175
|
}
|
|
@@ -197,7 +199,7 @@ function buildCompiler(options) {
|
|
|
197
199
|
compiler = compiler.use(() => tree => {
|
|
198
200
|
visit(tree, function (node) {
|
|
199
201
|
// We rely on an implicit transformation of data.hProperties => properties
|
|
200
|
-
|
|
202
|
+
const properties = node.properties;
|
|
201
203
|
if (properties?.[GLIMDOWN_PREVIEW]) {
|
|
202
204
|
return 'skip';
|
|
203
205
|
}
|
|
@@ -223,7 +225,7 @@ function buildCompiler(options) {
|
|
|
223
225
|
options.rehypePlugins.forEach(plugin => {
|
|
224
226
|
// Arrays are how plugins are passed options (for some reason?)
|
|
225
227
|
// why not just invoke the the function?
|
|
226
|
-
|
|
228
|
+
const p = Array.isArray(plugin) ? plugin : [plugin];
|
|
227
229
|
compiler = compiler.use(...p);
|
|
228
230
|
});
|
|
229
231
|
}
|
|
@@ -250,10 +252,10 @@ function buildCompiler(options) {
|
|
|
250
252
|
* @internal not under semver
|
|
251
253
|
*/
|
|
252
254
|
async function parseMarkdown(input, options = {}) {
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
255
|
+
const markdownCompiler = buildCompiler(options);
|
|
256
|
+
const processed = await markdownCompiler.process(input);
|
|
257
|
+
const liveCode = processed.data.liveCode || [];
|
|
258
|
+
const templateOnly = processed.toString();
|
|
257
259
|
return {
|
|
258
260
|
templateOnlyGlimdown: templateOnly,
|
|
259
261
|
blocks: liveCode
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"markdown.js","sources":["../../../src/compile/formats/markdown.ts"],"sourcesContent":["import rehypeRaw from 'rehype-raw';\nimport rehypeStringify from 'rehype-stringify';\nimport remarkGfm from 'remark-gfm';\nimport remarkParse from 'remark-parse';\nimport remarkRehype from 'remark-rehype';\nimport { unified } from 'unified';\nimport { visit } from 'unist-util-visit';\n\nimport { invocationOf, nameFor } from '../utils.ts';\n\nimport type { UnifiedPlugin } from '../types.ts';\nimport type { Node } from 'hast';\nimport type { Code, Text } from 'mdast';\nimport type { Parent } from 'unist';\nimport type { VFile } from 'vfile';\n\nexport interface ExtractedCode {\n name: string;\n code: string;\n lang: string;\n}\n\nexport interface LiveCodeExtraction {\n templateOnlyGlimdown: string;\n blocks: ExtractedCode[];\n}\ntype LiveData = {\n liveCode?: ExtractedCode[];\n};\ntype VFileWithMeta = VFile & {\n data: LiveData;\n};\n\ninterface Options {\n snippets?: {\n classList?: string[];\n };\n demo?: {\n classList?: string[];\n };\n copyComponent?: string;\n shadowComponent?: string;\n}\n\nconst GLIMDOWN_PREVIEW = Symbol('__GLIMDOWN_PREVIEW__');\nconst GLIMDOWN_RENDER = Symbol('__GLIMDOWN_RENDER__');\nconst ALLOWED_LANGUAGES = ['gjs', 'hbs'] as const;\n\ntype AllowedLanguage = (typeof ALLOWED_LANGUAGES)[number];\ntype RelevantCode = Omit<Code, 'lang'> & { lang: AllowedLanguage };\n\nfunction isLive(meta: string) {\n return meta.includes('live');\n}\n\nfunction isPreview(meta: string) {\n return meta.includes('preview');\n}\n\nfunction isBelow(meta: string) {\n return meta.includes('below');\n}\n\n// TODO: extract and publish remark plugin\nfunction liveCodeExtraction(options: Options = {}) {\n let { copyComponent, snippets, demo } = options;\n let { classList: snippetClasses } = snippets || {};\n let { classList: demoClasses } = demo || {};\n\n snippetClasses ??= [];\n demoClasses ??= [];\n\n function isRelevantCode(node: Code): node is RelevantCode {\n if (node.type !== 'code') return false;\n\n let { meta, lang } = node;\n\n meta = meta?.trim();\n\n if (!meta || !lang) return false;\n\n if (!meta.includes('live')) {\n return false;\n }\n\n if (!(ALLOWED_LANGUAGES as unknown as string[]).includes(lang)) return false;\n\n return true;\n }\n\n let copyNode = {\n type: 'html',\n value: copyComponent,\n };\n\n function enhance(code: Code) {\n code.data ??= {};\n (code.data as any)['hProperties'] ??= {};\n // This is secret-to-us-only API, so we don't really care about the type\n (code.data as any)['hProperties'][GLIMDOWN_PREVIEW] = true;\n\n return {\n data: {\n hProperties: { className: snippetClasses },\n },\n type: 'div',\n hProperties: { className: snippetClasses },\n children: [code, copyNode],\n };\n }\n\n function flatReplaceAt<T>(array: T[], index: number, replacement: T[]) {\n array.splice(index, 1, ...replacement);\n }\n\n // because we mutate the tree as we iterate,\n // we need to make sure we don't loop forever\n const seen = new Set();\n\n return function transformer(tree: Parent, file: VFileWithMeta) {\n visit(tree, ['code'], function (node, index, parent) {\n if (parent === null || parent === undefined) return;\n if (index === null || index === undefined) return;\n\n if (!isRelevantCode(node as Code)) {\n let enhanced = enhance(node as Code);\n\n parent.children[index] = enhanced;\n\n return 'skip';\n }\n\n if (seen.has(node)) return 'skip';\n\n seen.add(node);\n\n let { meta, lang, value } = node as Code;\n\n if (!meta) return 'skip';\n if (!lang) return 'skip';\n\n file.data.liveCode ??= [];\n\n let code = value.trim();\n let name = nameFor(code);\n let invocation = invocationOf(name);\n\n let shadow = options.shadowComponent;\n\n let wrapInShadow = shadow && !meta?.includes('no-shadow');\n\n if (wrapInShadow) {\n invocation = `<${shadow}>${invocation}</${shadow}>`;\n }\n\n let invokeNode = {\n type: 'html',\n data: {\n hProperties: { [GLIMDOWN_RENDER]: true },\n },\n value: `<div class=\"${demoClasses}\">${invocation}</div>`,\n };\n\n let wrapper = enhance(node as Code);\n\n file.data.liveCode.push({\n lang,\n name,\n code,\n });\n\n let live = isLive(meta);\n let preview = isPreview(meta);\n let below = isBelow(meta);\n\n if (live && preview && below) {\n flatReplaceAt(parent.children, index, [wrapper, invokeNode]);\n\n return 'skip';\n }\n\n if (live && preview) {\n flatReplaceAt(parent.children, index, [invokeNode, wrapper]);\n\n return 'skip';\n }\n\n if (live) {\n parent.children[index] = invokeNode;\n\n return 'skip';\n }\n\n parent.children[index] = wrapper;\n\n return;\n });\n };\n}\n\nfunction sanitizeForGlimmer(/* options */) {\n return (tree: Parent) => {\n visit(tree, 'element', (node: Parent) => {\n if ('tagName' in node) {\n if (!['pre', 'code'].includes(node.tagName as string)) return;\n\n visit(node, 'text', (textNode: Text) => {\n if ('value' in textNode && textNode.value) {\n textNode.value = textNode.value.replace(/{{/g, '\\\\{{');\n }\n });\n\n return 'skip';\n }\n });\n };\n}\n\nfunction buildCompiler(options: ParseMarkdownOptions) {\n let compiler = unified().use(remarkParse).use(remarkGfm);\n\n /**\n * If this were \"use\"d after `remarkRehype`,\n * remark is gone, and folks would need to work with rehype trees\n */\n if (options.remarkPlugins) {\n options.remarkPlugins.forEach((plugin) => {\n // Arrays are how plugins are passed options (for some reason?)\n // why not just invoke the the function?\n let p = Array.isArray(plugin) ? plugin : [plugin];\n\n compiler = compiler.use(...(p as [any]));\n });\n }\n\n // TODO: we only want to do this when we have pre > code.\n // code can exist inline.\n compiler = compiler.use(liveCodeExtraction, {\n snippets: {\n classList: ['glimdown-snippet', 'relative'],\n },\n demo: {\n classList: ['glimdown-render'],\n },\n copyComponent: options?.CopyComponent,\n shadowComponent: options?.ShadowComponent,\n });\n\n // .use(() => (tree) => visit(tree, (node) => console.log('i', node)))\n // remark rehype is needed to convert markdown to HTML\n // However, it also changes all the nodes, so we need another pass\n // to make sure our Glimmer-aware nodes are in tact\n compiler = compiler.use(remarkRehype, { allowDangerousHtml: true });\n\n // Convert invocables to raw format, so Glimmer can invoke them\n compiler = compiler.use(() => (tree: Node) => {\n visit(tree, function (node) {\n // We rely on an implicit transformation of data.hProperties => properties\n let properties = (node as any).properties;\n\n if (properties?.[GLIMDOWN_PREVIEW]) {\n return 'skip';\n }\n\n if (node.type === 'element' || ('tagName' in node && node.tagName === 'code')) {\n if (properties?.[GLIMDOWN_RENDER]) {\n node.type = 'glimmer_raw';\n\n return;\n }\n\n return 'skip';\n }\n\n if (node.type === 'text' || node.type === 'raw') {\n // definitively not the better way, but this is supposed to detect \"glimmer\" nodes\n if (\n 'value' in node &&\n typeof node.value === 'string' &&\n node.value.match(/<\\/?[_A-Z:0-9].*>/g)\n ) {\n node.type = 'glimmer_raw';\n }\n\n node.type = 'glimmer_raw';\n\n return 'skip';\n }\n\n return;\n });\n });\n\n if (options.rehypePlugins) {\n options.rehypePlugins.forEach((plugin) => {\n // Arrays are how plugins are passed options (for some reason?)\n // why not just invoke the the function?\n let p = Array.isArray(plugin) ? plugin : [plugin];\n\n compiler = compiler.use(...(p as [any]));\n });\n }\n\n compiler = compiler.use(rehypeRaw, { passThrough: ['glimmer_raw', 'raw'] }).use(() => (tree) => {\n visit(tree, 'glimmer_raw', (node: Node) => {\n node.type = 'raw';\n });\n });\n\n compiler = compiler.use(sanitizeForGlimmer);\n\n // Finally convert to string! oofta!\n compiler = compiler.use(rehypeStringify, {\n collapseEmptyAttributes: true,\n closeSelfClosing: true,\n allowParseErrors: true,\n allowDangerousCharacters: true,\n allowDangerousHtml: true,\n }) as any;\n\n return compiler as ReturnType<typeof unified>;\n}\n\ninterface ParseMarkdownOptions {\n CopyComponent?: string;\n ShadowComponent?: string;\n remarkPlugins?: UnifiedPlugin[];\n rehypePlugins?: UnifiedPlugin[];\n}\n\n/**\n * @internal not under semver\n */\nexport async function parseMarkdown(\n input: string,\n options: ParseMarkdownOptions = {}\n): Promise<LiveCodeExtraction> {\n let markdownCompiler = buildCompiler(options);\n let processed = await markdownCompiler.process(input);\n let liveCode = (processed.data as LiveData).liveCode || [];\n let templateOnly = processed.toString();\n\n return { templateOnlyGlimdown: templateOnly, blocks: liveCode };\n}\n"],"names":["GLIMDOWN_PREVIEW","Symbol","GLIMDOWN_RENDER","ALLOWED_LANGUAGES","isLive","meta","includes","isPreview","isBelow","liveCodeExtraction","options","copyComponent","snippets","demo","classList","snippetClasses","demoClasses","isRelevantCode","node","type","lang","trim","copyNode","value","enhance","code","data","hProperties","className","children","flatReplaceAt","array","index","replacement","splice","seen","Set","transformer","tree","file","visit","parent","undefined","enhanced","has","add","liveCode","name","nameFor","invocation","invocationOf","shadow","shadowComponent","wrapInShadow","invokeNode","wrapper","push","live","preview","below","sanitizeForGlimmer","tagName","textNode","replace","buildCompiler","compiler","unified","use","remarkParse","remarkGfm","remarkPlugins","forEach","plugin","p","Array","isArray","CopyComponent","ShadowComponent","remarkRehype","allowDangerousHtml","properties","match","rehypePlugins","rehypeRaw","passThrough","rehypeStringify","collapseEmptyAttributes","closeSelfClosing","allowParseErrors","allowDangerousCharacters","parseMarkdown","input","markdownCompiler","processed","process","templateOnly","toString","templateOnlyGlimdown","blocks"],"mappings":";;;;;;;;;AA4CA,MAAMA,gBAAgB,GAAGC,MAAM,CAAC,sBAAsB,CAAC;AACvD,MAAMC,eAAe,GAAGD,MAAM,CAAC,qBAAqB,CAAC;AACrD,MAAME,iBAAiB,GAAG,CAAC,KAAK,EAAE,KAAK,CAAU;AAKjD,SAASC,MAAMA,CAACC,IAAY,EAAE;AAC5B,EAAA,OAAOA,IAAI,CAACC,QAAQ,CAAC,MAAM,CAAC;AAC9B;AAEA,SAASC,SAASA,CAACF,IAAY,EAAE;AAC/B,EAAA,OAAOA,IAAI,CAACC,QAAQ,CAAC,SAAS,CAAC;AACjC;AAEA,SAASE,OAAOA,CAACH,IAAY,EAAE;AAC7B,EAAA,OAAOA,IAAI,CAACC,QAAQ,CAAC,OAAO,CAAC;AAC/B;;AAEA;AACA,SAASG,kBAAkBA,CAACC,OAAgB,GAAG,EAAE,EAAE;EACjD,IAAI;IAAEC,aAAa;IAAEC,QAAQ;AAAEC,IAAAA;AAAK,GAAC,GAAGH,OAAO;EAC/C,IAAI;AAAEI,IAAAA,SAAS,EAAEC;AAAe,GAAC,GAAGH,QAAQ,IAAI,EAAE;EAClD,IAAI;AAAEE,IAAAA,SAAS,EAAEE;AAAY,GAAC,GAAGH,IAAI,IAAI,EAAE;AAE3CE,EAAAA,cAAc,KAAK,EAAE;AACrBC,EAAAA,WAAW,KAAK,EAAE;EAElB,SAASC,cAAcA,CAACC,IAAU,EAAwB;AACxD,IAAA,IAAIA,IAAI,CAACC,IAAI,KAAK,MAAM,EAAE,OAAO,KAAK;IAEtC,IAAI;MAAEd,IAAI;AAAEe,MAAAA;AAAK,KAAC,GAAGF,IAAI;AAEzBb,IAAAA,IAAI,GAAGA,IAAI,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K,CAAC;EACrD,IAAI7C,QAAQ,GAAI+C,SAAS,CAACnE,IAAI,CAAcoB,QAAQ,IAAI,EAAE;AAC1D,EAAA,IAAIiD,YAAY,GAAGF,SAAS,CAACG,QAAQ,EAAE;EAEvC,OAAO;AAAEC,IAAAA,oBAAoB,EAAEF,YAAY;AAAEG,IAAAA,MAAM,EAAEpD;GAAU;AACjE;;;;"}
|
|
1
|
+
{"version":3,"file":"markdown.js","sources":["../../../src/compile/formats/markdown.ts"],"sourcesContent":["import rehypeRaw from 'rehype-raw';\nimport rehypeStringify from 'rehype-stringify';\nimport remarkGfm from 'remark-gfm';\nimport remarkParse from 'remark-parse';\nimport remarkRehype from 'remark-rehype';\nimport { unified } from 'unified';\nimport { visit } from 'unist-util-visit';\n\nimport { invocationOf, nameFor } from '../utils.ts';\n\nimport type { UnifiedPlugin } from '../types.ts';\nimport type { Node } from 'hast';\nimport type { Code, Text } from 'mdast';\nimport type { Parent } from 'unist';\nimport type { VFile } from 'vfile';\n\nexport interface ExtractedCode {\n name: string;\n code: string;\n lang: string;\n}\n\nexport interface LiveCodeExtraction {\n templateOnlyGlimdown: string;\n blocks: ExtractedCode[];\n}\ntype LiveData = {\n liveCode?: ExtractedCode[];\n};\ntype VFileWithMeta = VFile & {\n data: LiveData;\n};\n\ninterface Options {\n snippets?: {\n classList?: string[];\n };\n demo?: {\n classList?: string[];\n };\n copyComponent?: string;\n shadowComponent?: string;\n}\n\nconst GLIMDOWN_PREVIEW = Symbol('__GLIMDOWN_PREVIEW__');\nconst GLIMDOWN_RENDER = Symbol('__GLIMDOWN_RENDER__');\nconst ALLOWED_LANGUAGES = ['gjs', 'hbs'] as const;\n\ntype AllowedLanguage = (typeof ALLOWED_LANGUAGES)[number];\ntype RelevantCode = Omit<Code, 'lang'> & { lang: AllowedLanguage };\n\nfunction isLive(meta: string) {\n return meta.includes('live');\n}\n\nfunction isPreview(meta: string) {\n return meta.includes('preview');\n}\n\nfunction isBelow(meta: string) {\n return meta.includes('below');\n}\n\n// TODO: extract and publish remark plugin\nfunction liveCodeExtraction(options: Options = {}) {\n const { copyComponent, snippets, demo } = options;\n let { classList: snippetClasses } = snippets || {};\n let { classList: demoClasses } = demo || {};\n\n snippetClasses ??= [];\n demoClasses ??= [];\n\n function isRelevantCode(node: Code): node is RelevantCode {\n if (node.type !== 'code') return false;\n\n let { meta } = node;\n const { lang } = node;\n\n meta = meta?.trim();\n\n if (!meta || !lang) return false;\n\n if (!meta.includes('live')) {\n return false;\n }\n\n if (!(ALLOWED_LANGUAGES as unknown as string[]).includes(lang)) return false;\n\n return true;\n }\n\n const copyNode = {\n type: 'html',\n value: copyComponent,\n };\n\n function enhance(code: Code) {\n code.data ??= {};\n (code.data as any)['hProperties'] ??= {};\n // This is secret-to-us-only API, so we don't really care about the type\n (code.data as any)['hProperties'][GLIMDOWN_PREVIEW] = true;\n\n return {\n data: {\n hProperties: { className: snippetClasses },\n },\n type: 'div',\n hProperties: { className: snippetClasses },\n children: [code, copyNode],\n };\n }\n\n function flatReplaceAt<T>(array: T[], index: number, replacement: T[]) {\n array.splice(index, 1, ...replacement);\n }\n\n // because we mutate the tree as we iterate,\n // we need to make sure we don't loop forever\n const seen = new Set();\n\n return function transformer(tree: Parent, file: VFileWithMeta) {\n visit(tree, ['code'], function (node, index, parent) {\n if (parent === null || parent === undefined) return;\n if (index === null || index === undefined) return;\n\n if (!isRelevantCode(node as Code)) {\n const enhanced = enhance(node as Code);\n\n parent.children[index] = enhanced;\n\n return 'skip';\n }\n\n if (seen.has(node)) return 'skip';\n\n seen.add(node);\n\n const { meta, lang, value } = node as Code;\n\n if (!meta) return 'skip';\n if (!lang) return 'skip';\n\n file.data.liveCode ??= [];\n\n const code = value.trim();\n const name = nameFor(code);\n let invocation = invocationOf(name);\n\n const shadow = options.shadowComponent;\n\n const wrapInShadow = shadow && !meta?.includes('no-shadow');\n\n if (wrapInShadow) {\n invocation = `<${shadow}>${invocation}</${shadow}>`;\n }\n\n const invokeNode = {\n type: 'html',\n data: {\n hProperties: { [GLIMDOWN_RENDER]: true },\n },\n value: `<div class=\"${demoClasses}\">${invocation}</div>`,\n };\n\n const wrapper = enhance(node as Code);\n\n file.data.liveCode.push({\n lang,\n name,\n code,\n });\n\n const live = isLive(meta);\n const preview = isPreview(meta);\n const below = isBelow(meta);\n\n if (live && preview && below) {\n flatReplaceAt(parent.children, index, [wrapper, invokeNode]);\n\n return 'skip';\n }\n\n if (live && preview) {\n flatReplaceAt(parent.children, index, [invokeNode, wrapper]);\n\n return 'skip';\n }\n\n if (live) {\n parent.children[index] = invokeNode;\n\n return 'skip';\n }\n\n parent.children[index] = wrapper;\n\n return;\n });\n };\n}\n\nfunction sanitizeForGlimmer(/* options */) {\n return (tree: Parent) => {\n visit(tree, 'element', (node: Parent) => {\n if ('tagName' in node) {\n if (!['pre', 'code'].includes(node.tagName as string)) return;\n\n visit(node, 'text', (textNode: Text) => {\n if ('value' in textNode && textNode.value) {\n textNode.value = textNode.value.replace(/{{/g, '\\\\{{');\n }\n });\n\n return 'skip';\n }\n });\n };\n}\n\nfunction buildCompiler(options: ParseMarkdownOptions) {\n let compiler = unified().use(remarkParse).use(remarkGfm);\n\n /**\n * If this were \"use\"d after `remarkRehype`,\n * remark is gone, and folks would need to work with rehype trees\n */\n if (options.remarkPlugins) {\n options.remarkPlugins.forEach((plugin) => {\n // Arrays are how plugins are passed options (for some reason?)\n // why not just invoke the the function?\n const p = Array.isArray(plugin) ? plugin : [plugin];\n\n compiler = compiler.use(...(p as [any]));\n });\n }\n\n // TODO: we only want to do this when we have pre > code.\n // code can exist inline.\n compiler = compiler.use(liveCodeExtraction, {\n snippets: {\n classList: ['glimdown-snippet', 'relative'],\n },\n demo: {\n classList: ['glimdown-render'],\n },\n copyComponent: options?.CopyComponent,\n shadowComponent: options?.ShadowComponent,\n });\n\n // .use(() => (tree) => visit(tree, (node) => console.log('i', node)))\n // remark rehype is needed to convert markdown to HTML\n // However, it also changes all the nodes, so we need another pass\n // to make sure our Glimmer-aware nodes are in tact\n compiler = compiler.use(remarkRehype, { allowDangerousHtml: true });\n\n // Convert invocables to raw format, so Glimmer can invoke them\n compiler = compiler.use(() => (tree: Node) => {\n visit(tree, function (node) {\n // We rely on an implicit transformation of data.hProperties => properties\n const properties = (node as any).properties;\n\n if (properties?.[GLIMDOWN_PREVIEW]) {\n return 'skip';\n }\n\n if (node.type === 'element' || ('tagName' in node && node.tagName === 'code')) {\n if (properties?.[GLIMDOWN_RENDER]) {\n node.type = 'glimmer_raw';\n\n return;\n }\n\n return 'skip';\n }\n\n if (node.type === 'text' || node.type === 'raw') {\n // definitively not the better way, but this is supposed to detect \"glimmer\" nodes\n if (\n 'value' in node &&\n typeof node.value === 'string' &&\n node.value.match(/<\\/?[_A-Z:0-9].*>/g)\n ) {\n node.type = 'glimmer_raw';\n }\n\n node.type = 'glimmer_raw';\n\n return 'skip';\n }\n\n return;\n });\n });\n\n if (options.rehypePlugins) {\n options.rehypePlugins.forEach((plugin) => {\n // Arrays are how plugins are passed options (for some reason?)\n // why not just invoke the the function?\n const p = Array.isArray(plugin) ? plugin : [plugin];\n\n compiler = compiler.use(...(p as [any]));\n });\n }\n\n compiler = compiler.use(rehypeRaw, { passThrough: ['glimmer_raw', 'raw'] }).use(() => (tree) => {\n visit(tree, 'glimmer_raw', (node: Node) => {\n node.type = 'raw';\n });\n });\n\n compiler = compiler.use(sanitizeForGlimmer);\n\n // Finally convert to string! oofta!\n compiler = compiler.use(rehypeStringify, {\n collapseEmptyAttributes: true,\n closeSelfClosing: true,\n allowParseErrors: true,\n allowDangerousCharacters: true,\n allowDangerousHtml: true,\n }) as any;\n\n return compiler as ReturnType<typeof unified>;\n}\n\ninterface ParseMarkdownOptions {\n CopyComponent?: string;\n ShadowComponent?: string;\n remarkPlugins?: UnifiedPlugin[];\n rehypePlugins?: UnifiedPlugin[];\n}\n\n/**\n * @internal not under semver\n */\nexport async function parseMarkdown(\n input: string,\n options: ParseMarkdownOptions = {}\n): Promise<LiveCodeExtraction> {\n const markdownCompiler = buildCompiler(options);\n const processed = await markdownCompiler.process(input);\n const liveCode = (processed.data as LiveData).liveCode || [];\n const templateOnly = processed.toString();\n\n return { templateOnlyGlimdown: templateOnly, blocks: liveCode };\n}\n"],"names":["GLIMDOWN_PREVIEW","Symbol","GLIMDOWN_RENDER","ALLOWED_LANGUAGES","isLive","meta","includes","isPreview","isBelow","liveCodeExtraction","options","copyComponent","snippets","demo","classList","snippetClasses","demoClasses","isRelevantCode","node","type","lang","trim","copyNode","value","enhance","code","data","hProperties","className","children","flatReplaceAt","array","index","replacement","splice","seen","Set","transformer","tree","file","visit","parent","undefined","enhanced","has","add","liveCode","name","nameFor","invocation","invocationOf","shadow","shadowComponent","wrapInShadow","invokeNode","wrapper","push","live","preview","below","sanitizeForGlimmer","tagName","textNode","replace","buildCompiler","compiler","unified","use","remarkParse","remarkGfm","remarkPlugins","forEach","plugin","p","Array","isArray","CopyComponent","ShadowComponent","remarkRehype","allowDangerousHtml","properties","match","rehypePlugins","rehypeRaw","passThrough","rehypeStringify","collapseEmptyAttributes","closeSelfClosing","allowParseErrors","allowDangerousCharacters","parseMarkdown","input","markdownCompiler","processed","process","templateOnly","toString","templateOnlyGlimdown","blocks"],"mappings":";;;;;;;;;AA4CA,MAAMA,gBAAgB,GAAGC,MAAM,CAAC,sBAAsB,CAAC;AACvD,MAAMC,eAAe,GAAGD,MAAM,CAAC,qBAAqB,CAAC;AACrD,MAAME,iBAAiB,GAAG,CAAC,KAAK,EAAE,KAAK,CAAU;AAKjD,SAASC,MAAMA,CAACC,IAAY,EAAE;AAC5B,EAAA,OAAOA,IAAI,CAACC,QAAQ,CAAC,MAAM,CAAC;AAC9B;AAEA,SAASC,SAASA,CAACF,IAAY,EAAE;AAC/B,EAAA,OAAOA,IAAI,CAACC,QAAQ,CAAC,SAAS,CAAC;AACjC;AAEA,SAASE,OAAOA,CAACH,IAAY,EAAE;AAC7B,EAAA,OAAOA,IAAI,CAACC,QAAQ,CAAC,OAAO,CAAC;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