@reidelsaltres/pureper 0.1.67 → 0.1.68
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/out/foundation/PHTMLParser.d.ts +9 -0
- package/out/foundation/PHTMLParser.d.ts.map +1 -0
- package/out/foundation/PHTMLParser.js +80 -0
- package/out/foundation/PHTMLParser.js.map +1 -0
- package/out/foundation/Triplet.d.ts +4 -4
- package/out/foundation/Triplet.d.ts.map +1 -1
- package/out/foundation/Triplet.js +22 -13
- package/out/foundation/Triplet.js.map +1 -1
- package/out/foundation/TripletDecorator.d.ts +4 -0
- package/out/foundation/TripletDecorator.d.ts.map +1 -0
- package/out/foundation/TripletDecorator.js +23 -0
- package/out/foundation/TripletDecorator.js.map +1 -0
- package/package.json +1 -1
- package/src/foundation/PHTMLParser.ts +90 -0
- package/src/foundation/Triplet.ts +21 -13
- package/src/foundation/TripletDecorator.ts +26 -0
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export default class PHTMLParser {
|
|
2
|
+
private static rules;
|
|
3
|
+
variables: Record<string, unknown>;
|
|
4
|
+
addVariable(name: string, value: unknown): this;
|
|
5
|
+
resolveExpression(expr: string, scope?: Record<string, any>): any;
|
|
6
|
+
private stringifyValue;
|
|
7
|
+
parse(content: string, scope?: Record<string, any>): string;
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=PHTMLParser.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PHTMLParser.d.ts","sourceRoot":"","sources":["../../src/foundation/PHTMLParser.ts"],"names":[],"mappings":"AAWA,MAAM,CAAC,OAAO,OAAO,WAAW;IAC5B,OAAO,CAAC,MAAM,CAAC,KAAK,CAyClB;IACK,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAM;IAExC,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,GAAG,IAAI;IAQ/C,iBAAiB,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,GAAG;IAWxE,OAAO,CAAC,cAAc;IAMf,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,MAAM;CAQrE"}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
class PHTMLParserRule {
|
|
2
|
+
pattern;
|
|
3
|
+
replacer;
|
|
4
|
+
constructor(pattern, replacer) {
|
|
5
|
+
this.pattern = pattern;
|
|
6
|
+
this.replacer = replacer;
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
export default class PHTMLParser {
|
|
10
|
+
static rules = [
|
|
11
|
+
// Rule: for-loops like @for (item in items) { ... }
|
|
12
|
+
new PHTMLParserRule(/@for\s*\(([A-Za-z0-9_$]+)\s+in\s+([A-Za-z0-9_$.]+)\s*\)\s*\{([\s\S]*?)\}/g, (parser, m, scope) => {
|
|
13
|
+
// m[1] = iteration variable name, m[2] = iterable expression, m[3] = inner block
|
|
14
|
+
const iterVar = m[1];
|
|
15
|
+
const iterableExpr = m[2];
|
|
16
|
+
const inner = m[3];
|
|
17
|
+
const resolved = parser.resolveExpression(iterableExpr, scope);
|
|
18
|
+
const arr = Array.isArray(resolved) ? resolved : [];
|
|
19
|
+
const resultParts = [];
|
|
20
|
+
let i = 0;
|
|
21
|
+
for (const item of arr) {
|
|
22
|
+
const fullScope = Object.assign({}, scope, { [iterVar]: item });
|
|
23
|
+
// parse inner block for this item
|
|
24
|
+
let t = parser.parse(inner, fullScope);
|
|
25
|
+
// normalize whitespace: remove leading/trailing whitespace lines and
|
|
26
|
+
if (i === 0) {
|
|
27
|
+
t = t.trim();
|
|
28
|
+
t = " " + t;
|
|
29
|
+
}
|
|
30
|
+
t = t.split(/\n/)
|
|
31
|
+
//.map(line => line.trim())
|
|
32
|
+
.filter(line => line.length > 0)
|
|
33
|
+
.toString();
|
|
34
|
+
//.join('\n');
|
|
35
|
+
resultParts.push(t);
|
|
36
|
+
i++;
|
|
37
|
+
}
|
|
38
|
+
// join each item's rendered chunk with a single newline so output is compact
|
|
39
|
+
return resultParts.join('\n');
|
|
40
|
+
// Parse inner block for each element in the iterable using a local scope
|
|
41
|
+
//return arr.map((el) => parser.parse(inner, Object.assign({}, scope, { [iterVar]: el }))).join('');
|
|
42
|
+
}),
|
|
43
|
+
new PHTMLParserRule(/@\(\(([\s\S]+?)\)\)/g, (parser, m, scope) => parser.stringifyValue(parser.resolveExpression(m[1], scope))),
|
|
44
|
+
new PHTMLParserRule(/@\(([\s\S]+?)\)/g, (parser, m, scope) => parser.stringifyValue(parser.resolveExpression(m[1], scope))),
|
|
45
|
+
];
|
|
46
|
+
variables = {};
|
|
47
|
+
addVariable(name, value) {
|
|
48
|
+
this.variables[name] = value;
|
|
49
|
+
return this;
|
|
50
|
+
}
|
|
51
|
+
// Resolve a dotted expression against the parser variables and optional local scope.
|
|
52
|
+
// Examples: "subjectChips" -> this.variables.subjectChips
|
|
53
|
+
// "chip.Color" -> scope.chip.Color (if chip exists in scope) or this.variables.chip.Color
|
|
54
|
+
resolveExpression(expr, scope) {
|
|
55
|
+
const combined = Object.assign({}, this.variables, scope || {});
|
|
56
|
+
const parts = expr.split('.').map(p => p.trim()).filter(Boolean);
|
|
57
|
+
let cur = combined;
|
|
58
|
+
for (const part of parts) {
|
|
59
|
+
if (cur == null)
|
|
60
|
+
return undefined;
|
|
61
|
+
cur = cur[part];
|
|
62
|
+
}
|
|
63
|
+
return cur;
|
|
64
|
+
}
|
|
65
|
+
stringifyValue(val) {
|
|
66
|
+
if (val == null)
|
|
67
|
+
return '';
|
|
68
|
+
if (typeof val === 'string')
|
|
69
|
+
return val;
|
|
70
|
+
return String(val);
|
|
71
|
+
}
|
|
72
|
+
parse(content, scope) {
|
|
73
|
+
let working = content;
|
|
74
|
+
for (const rule of PHTMLParser.rules) {
|
|
75
|
+
working = working.replace(rule.pattern, (...args) => rule.replacer(this, args, scope));
|
|
76
|
+
}
|
|
77
|
+
return working;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
//# sourceMappingURL=PHTMLParser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PHTMLParser.js","sourceRoot":"","sources":["../../src/foundation/PHTMLParser.ts"],"names":[],"mappings":"AAAA,MAAM,eAAe;IACV,OAAO,CAAS;IAEhB,QAAQ,CAAkF;IAEjG,YAAY,OAAe,EAAE,QAAyF;QAClH,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC7B,CAAC;CACJ;AAED,MAAM,CAAC,OAAO,OAAO,WAAW;IACpB,MAAM,CAAC,KAAK,GAAsB;QACtC,oDAAoD;QACpD,IAAI,eAAe,CAAC,2EAA2E,EAC3F,CAAC,MAAM,EAAE,CAAC,EAAE,KAAK,EAAE,EAAE;YACjB,iFAAiF;YACjF,MAAM,OAAO,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;YACrB,MAAM,YAAY,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;YAC1B,MAAM,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;YAEnB,MAAM,QAAQ,GAAG,MAAM,CAAC,iBAAiB,CAAC,YAAY,EAAE,KAAK,CAAC,CAAC;YAC/D,MAAM,GAAG,GAAG,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC;YAEpD,MAAM,WAAW,GAAa,EAAE,CAAC;YACjC,IAAI,CAAC,GAAG,CAAC,CAAC;YACV,KAAK,MAAM,IAAI,IAAI,GAAG,EAAE,CAAC;gBACrB,MAAM,SAAS,GAAG,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,KAAK,EAAE,EAAE,CAAC,OAAO,CAAC,EAAE,IAAI,EAAE,C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|
export default class Triplet<T extends UniHtml> implements ITriplet {
|
|
4
4
|
private uni?;
|
|
5
5
|
private readonly access;
|
|
6
|
-
readonly
|
|
6
|
+
readonly markup?: string;
|
|
7
7
|
readonly css?: string;
|
|
8
8
|
readonly js?: string;
|
|
9
9
|
readonly additionalFiles: Map<string, string>;
|
|
@@ -15,7 +15,7 @@ export default class Triplet<T extends UniHtml> implements ITriplet {
|
|
|
15
15
|
private createInjectedClass;
|
|
16
16
|
}
|
|
17
17
|
interface ITriplet {
|
|
18
|
-
readonly
|
|
18
|
+
readonly markup?: string;
|
|
19
19
|
readonly css?: string;
|
|
20
20
|
readonly js?: string;
|
|
21
21
|
}
|
|
@@ -26,14 +26,14 @@ export declare enum AccessType {
|
|
|
26
26
|
BOTH = 3
|
|
27
27
|
}
|
|
28
28
|
export declare class TripletBuilder<T extends UniHtml> implements ITriplet {
|
|
29
|
-
readonly
|
|
29
|
+
readonly markup?: string;
|
|
30
30
|
readonly css?: string;
|
|
31
31
|
readonly js?: string;
|
|
32
32
|
uni?: AnyConstructor<UniHtml>;
|
|
33
33
|
access: AccessType;
|
|
34
34
|
readonly additionalFiles: Map<string, string>;
|
|
35
35
|
private constructor();
|
|
36
|
-
static create<T extends UniHtml>(
|
|
36
|
+
static create<T extends UniHtml>(markup?: string, css?: string, js?: string): TripletBuilder<T>;
|
|
37
37
|
withUni(cls: AnyConstructor<UniHtml>): TripletBuilder<T>;
|
|
38
38
|
withAccess(access: AccessType): TripletBuilder<T>;
|
|
39
39
|
withLightDOMCss(css: string): TripletBuilder<T>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Triplet.d.ts","sourceRoot":"","sources":["../../src/foundation/Triplet.ts"],"names":[],"mappings":"AACA,OAAO,OAAO,MAAM,4BAA4B,CAAC;AAKjD,OAAO,EAAE,cAAc,EAAe,MAAM,gCAAgC,CAAC;
|
|
1
|
+
{"version":3,"file":"Triplet.d.ts","sourceRoot":"","sources":["../../src/foundation/Triplet.ts"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,CAAC;IAC9B,MAAM,EAAE,UAAU,CAAmB;IAE5C,SAAgB,eAAe,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAa;IAEjE,OAAO;WAMO,MAAM,CAAC,CAAC,SAAS,OAAO,EAAE,MAAM,CAAC,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,EAAE,EAAE,CAAC,EAAE,MAAM,GAAG,cAAc,CAAC,CAAC,CAAC;IAQ/F,OAAO,CAAC,GAAG,EAAE,cAAc,CAAC,OAAO,CAAC,GAAG,cAAc,CAAC,CAAC,CAAC;IAIxD,UAAU,CAAC,MAAM,EAAE,UAAU,GAAG,cAAc,CAAC,CAAC,CAAC;IAIjD,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,cAAc,CAAC,CAAC,CAAC;IAM/C,KAAK,IAAI,OAAO,CAAC,CAAC,CAAC;CAG7B"}
|
|
@@ -3,15 +3,16 @@ import { Router } from "./worker/Router.js";
|
|
|
3
3
|
import ServiceWorker from "./worker/ServiceWorker.js";
|
|
4
4
|
import Page from "./component_api/Page.js";
|
|
5
5
|
import Component from "./component_api/Component.js";
|
|
6
|
+
import PHTMLParser from "./PHTMLParser.js";
|
|
6
7
|
export default class Triplet {
|
|
7
8
|
uni;
|
|
8
9
|
access;
|
|
9
|
-
|
|
10
|
+
markup;
|
|
10
11
|
css;
|
|
11
12
|
js;
|
|
12
13
|
additionalFiles = new Map();
|
|
13
14
|
constructor(builder) {
|
|
14
|
-
this.
|
|
15
|
+
this.markup = builder.markup;
|
|
15
16
|
this.css = builder.css;
|
|
16
17
|
this.js = builder.js;
|
|
17
18
|
this.additionalFiles = builder.additionalFiles;
|
|
@@ -35,8 +36,8 @@ export default class Triplet {
|
|
|
35
36
|
return true;
|
|
36
37
|
}
|
|
37
38
|
async cache() {
|
|
38
|
-
if (this.
|
|
39
|
-
await ServiceWorker.addToCache(this.
|
|
39
|
+
if (this.markup)
|
|
40
|
+
await ServiceWorker.addToCache(this.markup);
|
|
40
41
|
if (this.css)
|
|
41
42
|
await ServiceWorker.addToCache(this.css);
|
|
42
43
|
if (this.js)
|
|
@@ -77,7 +78,7 @@ export default class Triplet {
|
|
|
77
78
|
}
|
|
78
79
|
let ori = this.createInjectedClass(this.uni);
|
|
79
80
|
if (type === "router") {
|
|
80
|
-
var reg = Router.registerRoute(this.
|
|
81
|
+
var reg = Router.registerRoute(this.markup, name, (search) => {
|
|
81
82
|
const paramNames = (() => {
|
|
82
83
|
const ctor = this.uni.prototype.constructor;
|
|
83
84
|
const fnStr = ctor.toString();
|
|
@@ -93,7 +94,7 @@ export default class Triplet {
|
|
|
93
94
|
const unn = new ori(...args);
|
|
94
95
|
return unn;
|
|
95
96
|
});
|
|
96
|
-
console.info(`[Triplet]` + `: Router route '${name}' registered for path '${this.
|
|
97
|
+
console.info(`[Triplet]` + `: Router route '${name}' registered for path '${this.markup}' by class ${ori}.`);
|
|
97
98
|
return reg.then(() => true).catch(() => false);
|
|
98
99
|
}
|
|
99
100
|
else if (type === "markup") {
|
|
@@ -115,9 +116,17 @@ export default class Triplet {
|
|
|
115
116
|
let proto = ori.prototype;
|
|
116
117
|
proto._init = async function () {
|
|
117
118
|
///
|
|
118
|
-
const fullPath = that.
|
|
119
|
+
const fullPath = that.markup;
|
|
120
|
+
var markup = "";
|
|
121
|
+
if (fullPath.endsWith(".phtml")) {
|
|
122
|
+
const parser = new PHTMLParser();
|
|
123
|
+
markup = parser.parse(await Fetcher.fetchText(fullPath), this);
|
|
124
|
+
}
|
|
125
|
+
else {
|
|
126
|
+
markup = await Fetcher.fetchText(fullPath);
|
|
127
|
+
}
|
|
119
128
|
///
|
|
120
|
-
return
|
|
129
|
+
return markup;
|
|
121
130
|
};
|
|
122
131
|
proto._postInit = async function (preHtml) {
|
|
123
132
|
if (that.css) {
|
|
@@ -145,19 +154,19 @@ export var AccessType;
|
|
|
145
154
|
AccessType[AccessType["BOTH"] = 3] = "BOTH";
|
|
146
155
|
})(AccessType || (AccessType = {}));
|
|
147
156
|
export class TripletBuilder {
|
|
148
|
-
|
|
157
|
+
markup;
|
|
149
158
|
css;
|
|
150
159
|
js;
|
|
151
160
|
uni;
|
|
152
161
|
access = AccessType.BOTH;
|
|
153
162
|
additionalFiles = new Map();
|
|
154
|
-
constructor(
|
|
155
|
-
this.
|
|
163
|
+
constructor(markup, css, js) {
|
|
164
|
+
this.markup = markup;
|
|
156
165
|
this.css = css;
|
|
157
166
|
this.js = js;
|
|
158
167
|
}
|
|
159
|
-
static create(
|
|
160
|
-
let urlHtml =
|
|
168
|
+
static create(markup, css, js) {
|
|
169
|
+
let urlHtml = markup ? new URL(markup, window.location.origin) : null;
|
|
161
170
|
let urlCss = css ? new URL(css, window.location.origin) : null;
|
|
162
171
|
let urlJs = js ? new URL(js, window.location.origin) : null;
|
|
163
172
|
return new TripletBuilder(urlHtml?.href, urlCss?.href, urlJs?.href);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Triplet.js","sourceRoot":"","sources":["../../src/foundation/Triplet.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,cAAc,CAAC;AAEnC,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAC5C,OAAO,aAAa,MAAM,2BAA2B,CAAC;AACtD,OAAO,IAAI,MAAM,yBAAyB,CAAC;AAC3C,OAAO,SAAS,MAAM,8BAA8B,CAAC;
|
|
1
|
+
{"version":3,"file":"Triplet.js","sourceRoot":"","sources":["../../src/foundation/Triplet.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,cAAc,CAAC;AAEnC,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAC5C,OAAO,aAAa,MAAM,2BAA2B,CAAC;AACtD,OAAO,IAAI,MAAM,yBAAyB,CAAC;AAC3C,OAAO,SAAS,MAAM,8BAA8B,CAAC;AAErD,OAAO,WAAW,MAAM,kBAAkB,CAAC;AAE3C,MAAM,CAAC,OAAO,OAAO,OAAO;IAChB,GAA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IAChC,CAAC;CACJ"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { AccessType } from "./Triplet.js";
|
|
2
|
+
export declare function Component(html?: string, css?: string, js?: string, access?: AccessType, name?: string): (ctor: Function) => void;
|
|
3
|
+
export declare function Page(html?: string, css?: string, js?: string, access?: AccessType, path?: string): (ctor: Function) => void;
|
|
4
|
+
//# sourceMappingURL=TripletDecorator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TripletDecorator.d.ts","sourceRoot":"","sources":["../../src/foundation/TripletDecorator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAkB,MAAM,cAAc,CAAA;AAEzD,wBAAgB,SAAS,CAAC,IAAI,CAAC,EAAG,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,EAAE,EAAE,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,UAAU,EAAE,IAAI,CAAC,EAAE,MAAM,IAC3F,MAAM,QAAQ,UAQzB;AACD,wBAAgB,IAAI,CAAC,IAAI,CAAC,EAAG,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,EAAE,EAAE,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,UAAU,EAAE,IAAI,CAAC,EAAE,MAAM,IACtF,MAAM,QAAQ,UAQzB"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { AccessType, TripletBuilder } from "./Triplet.js";
|
|
2
|
+
export function Component(html, css, js, access, name) {
|
|
3
|
+
return (ctor) => {
|
|
4
|
+
const triplet = TripletBuilder.create(html, css, js)
|
|
5
|
+
.withUni(ctor)
|
|
6
|
+
.withAccess(access ?? AccessType.BOTH)
|
|
7
|
+
.build();
|
|
8
|
+
triplet.register("markup", name);
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
export function Page(html, css, js, access, path) {
|
|
12
|
+
return (ctor) => {
|
|
13
|
+
const triplet = TripletBuilder.create(html, css, js)
|
|
14
|
+
.withUni(ctor)
|
|
15
|
+
.withAccess(access ?? AccessType.BOTH)
|
|
16
|
+
.build();
|
|
17
|
+
triplet.register("router", path);
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
@Page()
|
|
21
|
+
class myFirstPlugin {
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=TripletDecorator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TripletDecorator.js","sourceRoot":"","sources":["../../src/foundation/TripletDecorator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,cAAc,CAAA;AAEzD,MAAM,UAAU,SAAS,CAAC,IAAc,EAAE,GAAY,EAAE,EAAW,EAAE,MAAmB,EAAE,IAAa;IACnG,OAAO,CAAC,IAAc,EAAE,EAAE;QACtB,MAAM,OAAO,GAAG,cAAc,CAAC,MAAM,CAAC,IAAI,EAAE,GAAG,EAAE,EAAE,CAAC;aACnD,OAAO,CAAC,IAAW,CAAC;aACpB,UAAU,CAAC,MAAM,IAAI,UAAU,CAAC,IAAI,CAAC;aACrC,KAAK,EAAE,CAAC;QAET,OAAO,CAAC,QAAQ,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAA;IACpC,CAAC,CAAA;AACL,CAAC;AACD,MAAM,UAAU,IAAI,CAAC,IAAc,EAAE,GAAY,EAAE,EAAW,EAAE,MAAmB,EAAE,IAAa;IAC9F,OAAO,CAAC,IAAc,EAAE,EAAE;QACtB,MAAM,OAAO,GAAG,cAAc,CAAC,MAAM,CAAC,IAAI,EAAE,GAAG,EAAE,EAAE,CAAC;aACnD,OAAO,CAAC,IAAW,CAAC;aACpB,UAAU,CAAC,MAAM,IAAI,UAAU,CAAC,IAAI,CAAC;aACrC,KAAK,EAAE,CAAC;QAET,OAAO,CAAC,QAAQ,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAA;IACpC,CAAC,CAAA;AACL,CAAC;AAGD,CAAC,IAAI,EAAE;MACD,aAAa;CAAG"}
|
package/package.json
CHANGED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
class PHTMLParserRule {
|
|
2
|
+
public pattern: RegExp;
|
|
3
|
+
|
|
4
|
+
public replacer: (parser: PHTMLParser, match: IArguments, scope?: Record<string, any>) => string;
|
|
5
|
+
|
|
6
|
+
constructor(pattern: RegExp, replacer: (parser: PHTMLParser, match: IArguments, scope?: Record<string, any>) => string) {
|
|
7
|
+
this.pattern = pattern;
|
|
8
|
+
this.replacer = replacer;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export default class PHTMLParser {
|
|
13
|
+
private static rules: PHTMLParserRule[] = [
|
|
14
|
+
// Rule: for-loops like @for (item in items) { ... }
|
|
15
|
+
new PHTMLParserRule(/@for\s*\(([A-Za-z0-9_$]+)\s+in\s+([A-Za-z0-9_$.]+)\s*\)\s*\{([\s\S]*?)\}/g,
|
|
16
|
+
(parser, m, scope) => {
|
|
17
|
+
// m[1] = iteration variable name, m[2] = iterable expression, m[3] = inner block
|
|
18
|
+
const iterVar = m[1];
|
|
19
|
+
const iterableExpr = m[2];
|
|
20
|
+
const inner = m[3];
|
|
21
|
+
|
|
22
|
+
const resolved = parser.resolveExpression(iterableExpr, scope);
|
|
23
|
+
const arr = Array.isArray(resolved) ? resolved : [];
|
|
24
|
+
|
|
25
|
+
const resultParts: string[] = [];
|
|
26
|
+
let i = 0;
|
|
27
|
+
for (const item of arr) {
|
|
28
|
+
const fullScope = Object.assign({}, scope, { [iterVar]: item });
|
|
29
|
+
// parse inner block for this item
|
|
30
|
+
let t = parser.parse(inner, fullScope);
|
|
31
|
+
// normalize whitespace: remove leading/trailing whitespace lines and
|
|
32
|
+
if (i === 0) {
|
|
33
|
+
t = t.trim();
|
|
34
|
+
t = " " + t;
|
|
35
|
+
}
|
|
36
|
+
t = t.split(/\n/)
|
|
37
|
+
//.map(line => line.trim())
|
|
38
|
+
.filter(line => line.length > 0)
|
|
39
|
+
.toString();
|
|
40
|
+
//.join('\n');
|
|
41
|
+
resultParts.push(t);
|
|
42
|
+
i++;
|
|
43
|
+
}
|
|
44
|
+
// join each item's rendered chunk with a single newline so output is compact
|
|
45
|
+
return resultParts.join('\n');
|
|
46
|
+
|
|
47
|
+
// Parse inner block for each element in the iterable using a local scope
|
|
48
|
+
//return arr.map((el) => parser.parse(inner, Object.assign({}, scope, { [iterVar]: el }))).join('');
|
|
49
|
+
}),
|
|
50
|
+
new PHTMLParserRule(/@\(\(([\s\S]+?)\)\)/g, (parser, m, scope) =>
|
|
51
|
+
parser.stringifyValue(parser.resolveExpression(m[1], scope))),
|
|
52
|
+
new PHTMLParserRule(/@\(([\s\S]+?)\)/g, (parser, m, scope) =>
|
|
53
|
+
parser.stringifyValue(parser.resolveExpression(m[1], scope))),
|
|
54
|
+
];
|
|
55
|
+
public variables: Record<string, unknown> = {};
|
|
56
|
+
|
|
57
|
+
public addVariable(name: string, value: unknown): this {
|
|
58
|
+
this.variables[name] = value;
|
|
59
|
+
return this;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// Resolve a dotted expression against the parser variables and optional local scope.
|
|
63
|
+
// Examples: "subjectChips" -> this.variables.subjectChips
|
|
64
|
+
// "chip.Color" -> scope.chip.Color (if chip exists in scope) or this.variables.chip.Color
|
|
65
|
+
public resolveExpression(expr: string, scope?: Record<string, any>): any {
|
|
66
|
+
const combined = Object.assign({}, this.variables, scope || {});
|
|
67
|
+
const parts = expr.split('.').map(p => p.trim()).filter(Boolean);
|
|
68
|
+
let cur: any = combined;
|
|
69
|
+
for (const part of parts) {
|
|
70
|
+
if (cur == null) return undefined;
|
|
71
|
+
cur = cur[part];
|
|
72
|
+
}
|
|
73
|
+
return cur;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
private stringifyValue(val: any): string {
|
|
77
|
+
if (val == null) return '';
|
|
78
|
+
if (typeof val === 'string') return val;
|
|
79
|
+
return String(val);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
public parse(content: string, scope?: Record<string, any>): string {
|
|
83
|
+
let working = content;
|
|
84
|
+
for (const rule of PHTMLParser.rules) {
|
|
85
|
+
working = working.replace(rule.pattern,
|
|
86
|
+
(...args) => rule.replacer(this, args as any, scope));
|
|
87
|
+
}
|
|
88
|
+
return working;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
@@ -5,19 +5,20 @@ import ServiceWorker from "./worker/ServiceWorker.js";
|
|
|
5
5
|
import Page from "./component_api/Page.js";
|
|
6
6
|
import Component from "./component_api/Component.js";
|
|
7
7
|
import { AnyConstructor, Constructor } from "./component_api/mixin/Proto.js";
|
|
8
|
+
import PHTMLParser from "./PHTMLParser.js";
|
|
8
9
|
|
|
9
10
|
export default class Triplet<T extends UniHtml> implements ITriplet {
|
|
10
11
|
private uni?: AnyConstructor<UniHtml>;
|
|
11
12
|
private readonly access: AccessType;
|
|
12
13
|
|
|
13
|
-
public readonly
|
|
14
|
+
public readonly markup?: string;
|
|
14
15
|
public readonly css?: string;
|
|
15
16
|
public readonly js?: string;
|
|
16
17
|
|
|
17
18
|
public readonly additionalFiles: Map<string, string> = new Map();
|
|
18
19
|
|
|
19
20
|
public constructor(builder: TripletBuilder<T>) {
|
|
20
|
-
this.
|
|
21
|
+
this.markup = builder.markup;
|
|
21
22
|
this.css = builder.css;
|
|
22
23
|
this.js = builder.js;
|
|
23
24
|
|
|
@@ -42,8 +43,8 @@ export default class Triplet<T extends UniHtml> implements ITriplet {
|
|
|
42
43
|
}
|
|
43
44
|
|
|
44
45
|
public async cache(): Promise<void> {
|
|
45
|
-
if (this.
|
|
46
|
-
await ServiceWorker.addToCache(this.
|
|
46
|
+
if (this.markup)
|
|
47
|
+
await ServiceWorker.addToCache(this.markup);
|
|
47
48
|
if (this.css)
|
|
48
49
|
await ServiceWorker.addToCache(this.css);
|
|
49
50
|
if (this.js)
|
|
@@ -90,7 +91,7 @@ export default class Triplet<T extends UniHtml> implements ITriplet {
|
|
|
90
91
|
let ori = this.createInjectedClass(this.uni);
|
|
91
92
|
|
|
92
93
|
if (type === "router") {
|
|
93
|
-
var reg = Router.registerRoute(this.
|
|
94
|
+
var reg = Router.registerRoute(this.markup!, name, (search) => {
|
|
94
95
|
const paramNames = (() => {
|
|
95
96
|
const ctor = this.uni.prototype.constructor;
|
|
96
97
|
const fnStr = ctor.toString();
|
|
@@ -110,7 +111,7 @@ export default class Triplet<T extends UniHtml> implements ITriplet {
|
|
|
110
111
|
return unn;
|
|
111
112
|
});
|
|
112
113
|
|
|
113
|
-
console.info(`[Triplet]` + `: Router route '${name}' registered for path '${this.
|
|
114
|
+
console.info(`[Triplet]` + `: Router route '${name}' registered for path '${this.markup}' by class ${ori}.`);
|
|
114
115
|
return reg.then(() => true).catch(() => false);
|
|
115
116
|
} else if (type === "markup") {
|
|
116
117
|
if (customElements.get(name)) throw new Error(`Custom element '${name}' is already defined.`);
|
|
@@ -131,9 +132,16 @@ export default class Triplet<T extends UniHtml> implements ITriplet {
|
|
|
131
132
|
let proto = ori.prototype as any;
|
|
132
133
|
proto._init = async function () {
|
|
133
134
|
///
|
|
134
|
-
const fullPath = that.
|
|
135
|
+
const fullPath = that.markup!;
|
|
136
|
+
var markup = "";
|
|
137
|
+
if (fullPath.endsWith(".phtml")) {
|
|
138
|
+
const parser = new PHTMLParser();
|
|
139
|
+
markup = parser.parse(await Fetcher.fetchText(fullPath), this);
|
|
140
|
+
} else {
|
|
141
|
+
markup = await Fetcher.fetchText(fullPath);
|
|
142
|
+
}
|
|
135
143
|
///
|
|
136
|
-
return
|
|
144
|
+
return markup;
|
|
137
145
|
}
|
|
138
146
|
proto._postInit = async function (preHtml: string): Promise<string> {
|
|
139
147
|
if (that.css) {
|
|
@@ -155,7 +163,7 @@ export default class Triplet<T extends UniHtml> implements ITriplet {
|
|
|
155
163
|
}
|
|
156
164
|
|
|
157
165
|
interface ITriplet {
|
|
158
|
-
readonly
|
|
166
|
+
readonly markup?: string;
|
|
159
167
|
readonly css?: string;
|
|
160
168
|
readonly js?: string;
|
|
161
169
|
}
|
|
@@ -174,19 +182,19 @@ export class TripletBuilder<T extends UniHtml> implements ITriplet {
|
|
|
174
182
|
public readonly additionalFiles: Map<string, string> = new Map();
|
|
175
183
|
|
|
176
184
|
private constructor(
|
|
177
|
-
public readonly
|
|
185
|
+
public readonly markup?: string,
|
|
178
186
|
public readonly css?: string,
|
|
179
187
|
public readonly js?: string
|
|
180
188
|
) { }
|
|
181
189
|
|
|
182
|
-
public static create<T extends UniHtml>(
|
|
183
|
-
let urlHtml: URL =
|
|
190
|
+
public static create<T extends UniHtml>(markup?: string, css?: string, js?: string): TripletBuilder<T> {
|
|
191
|
+
let urlHtml: URL = markup ? new URL(markup, window.location.origin) : null;
|
|
184
192
|
let urlCss: URL = css ? new URL(css, window.location.origin) : null;
|
|
185
193
|
let urlJs: URL = js ? new URL(js, window.location.origin) : null;
|
|
186
194
|
|
|
187
195
|
return new TripletBuilder(urlHtml?.href, urlCss?.href, urlJs?.href);
|
|
188
196
|
}
|
|
189
|
-
|
|
197
|
+
|
|
190
198
|
public withUni(cls: AnyConstructor<UniHtml>): TripletBuilder<T> {
|
|
191
199
|
this.uni = cls;
|
|
192
200
|
return this;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { AccessType, TripletBuilder } from "./Triplet.js"
|
|
2
|
+
|
|
3
|
+
export function Component(html? : string, css?: string, js?: string, access?: AccessType, name?: string) {
|
|
4
|
+
return (ctor: Function) => {
|
|
5
|
+
const triplet = TripletBuilder.create(html, css, js)
|
|
6
|
+
.withUni(ctor as any)
|
|
7
|
+
.withAccess(access ?? AccessType.BOTH)
|
|
8
|
+
.build();
|
|
9
|
+
|
|
10
|
+
triplet.register("markup", name)
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
export function Page(html? : string, css?: string, js?: string, access?: AccessType, path?: string) {
|
|
14
|
+
return (ctor: Function) => {
|
|
15
|
+
const triplet = TripletBuilder.create(html, css, js)
|
|
16
|
+
.withUni(ctor as any)
|
|
17
|
+
.withAccess(access ?? AccessType.BOTH)
|
|
18
|
+
.build();
|
|
19
|
+
|
|
20
|
+
triplet.register("router", path)
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
@Page()
|
|
26
|
+
class myFirstPlugin {}
|