@hpcc-js/observablehq-compiler 3.3.9 → 3.5.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/dist/dot-DK4iDc2-.js +40 -0
- package/dist/dot-DK4iDc2-.js.map +1 -0
- package/dist/duckdb-DkM9_nXT.js +298 -0
- package/dist/duckdb-DkM9_nXT.js.map +1 -0
- package/dist/highlight-Bv8PkwN-.js +2402 -0
- package/dist/highlight-Bv8PkwN-.js.map +1 -0
- package/dist/index-B7vRtYlU.js +1807 -0
- package/dist/index-B7vRtYlU.js.map +1 -0
- package/dist/index-COHaJzee.js +260 -0
- package/dist/index-COHaJzee.js.map +1 -0
- package/dist/index-CP3HrqN0.js +1815 -0
- package/dist/index-CP3HrqN0.js.map +1 -0
- package/dist/index-D3TL70UM.js +163 -0
- package/dist/index-D3TL70UM.js.map +1 -0
- package/dist/index-DNwLE6Kk.js +198 -0
- package/dist/index-DNwLE6Kk.js.map +1 -0
- package/dist/index.js +1716 -302
- package/dist/index.js.map +1 -1
- package/dist/inputs-CsCXZHQ8.js +3 -0
- package/dist/inputs-CsCXZHQ8.js.map +1 -0
- package/dist/leaflet-CkvVhxBL.js +9 -0
- package/dist/leaflet-CkvVhxBL.js.map +1 -0
- package/dist/mapboxgl-C0i2HzjJ.js +9 -0
- package/dist/mapboxgl-C0i2HzjJ.js.map +1 -0
- package/dist/md-Bxvu6Hld.js +7603 -0
- package/dist/md-Bxvu6Hld.js.map +1 -0
- package/dist/mermaid-CFg6sgdO.js +17 -0
- package/dist/mermaid-CFg6sgdO.js.map +1 -0
- package/dist/node/index.cjs +32 -0
- package/dist/node/index.cjs.map +7 -0
- package/dist/node/index.js +32 -0
- package/dist/node/index.js.map +7 -0
- package/dist/runtime.js +2501 -0
- package/dist/runtime.js.map +1 -0
- package/dist/tex-ayRXOMLZ.js +24 -0
- package/dist/tex-ayRXOMLZ.js.map +1 -0
- package/dist/vega-lite-CESXoehe.js +8 -0
- package/dist/vega-lite-CESXoehe.js.map +1 -0
- package/package.json +18 -10
- package/src/__package__.ts +2 -2
- package/src/compiler.ts +23 -6
- package/src/cst.ts +1 -2
- package/src/index.node.ts +7 -0
- package/src/index.ts +2 -3
- package/src/kit/compiler.ts +41 -0
- package/src/kit/index.ts +3 -0
- package/src/kit/runtime.ts +57 -0
- package/src/kit/util.ts +157 -0
- package/src/util.ts +36 -60
- package/types/compiler.d.ts +8 -36
- package/types/index.d.ts +2 -2
- package/types/kit/compiler.d.ts +6 -0
- package/types/kit/index.d.ts +3 -0
- package/types/kit/runtime.d.ts +13 -0
- package/types/kit/util.d.ts +52 -0
- package/types/util.d.ts +3 -14
- package/dist/index.umd.cjs +0 -5
- package/dist/index.umd.cjs.map +0 -1
- package/src/index.css +0 -460
package/dist/index.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
var __defProp = Object.defineProperty;
|
|
2
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
2
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
4
|
-
var
|
|
3
|
+
var _a;
|
|
5
4
|
var astralIdentifierCodes = [509, 0, 227, 0, 150, 4, 294, 9, 1368, 2, 2, 1, 6, 3, 41, 2, 5, 0, 166, 1, 574, 3, 9, 9, 7, 9, 32, 4, 318, 1, 80, 3, 71, 10, 50, 3, 123, 2, 54, 14, 32, 10, 3, 1, 11, 3, 46, 10, 8, 0, 46, 9, 7, 2, 37, 13, 2, 9, 6, 1, 45, 0, 13, 2, 49, 13, 9, 3, 2, 11, 83, 11, 7, 0, 3, 0, 158, 11, 6, 9, 7, 3, 56, 1, 2, 6, 3, 1, 3, 2, 10, 0, 11, 1, 3, 6, 4, 4, 68, 8, 2, 0, 3, 0, 2, 3, 2, 4, 2, 0, 15, 1, 83, 17, 10, 9, 5, 0, 82, 19, 13, 9, 214, 6, 3, 8, 28, 1, 83, 16, 16, 9, 82, 12, 9, 9, 7, 19, 58, 14, 5, 9, 243, 14, 166, 9, 71, 5, 2, 1, 3, 3, 2, 0, 2, 1, 13, 9, 120, 6, 3, 6, 4, 0, 29, 9, 41, 6, 2, 3, 9, 0, 10, 10, 47, 15, 343, 9, 54, 7, 2, 7, 17, 9, 57, 21, 2, 13, 123, 5, 4, 0, 2, 1, 2, 6, 2, 0, 9, 9, 49, 4, 2, 1, 2, 4, 9, 9, 330, 3, 10, 1, 2, 0, 49, 6, 4, 4, 14, 10, 5350, 0, 7, 14, 11465, 27, 2343, 9, 87, 9, 39, 4, 60, 6, 26, 9, 535, 9, 470, 0, 2, 54, 8, 3, 82, 0, 12, 1, 19628, 1, 4178, 9, 519, 45, 3, 22, 543, 4, 4, 5, 9, 7, 3, 6, 31, 3, 149, 2, 1418, 49, 513, 54, 5, 49, 9, 0, 15, 0, 23, 4, 2, 14, 1361, 6, 2, 16, 3, 6, 2, 1, 2, 4, 101, 0, 161, 6, 10, 9, 357, 0, 62, 13, 499, 13, 245, 1, 2, 9, 726, 6, 110, 6, 6, 9, 4759, 9, 787719, 239];
|
|
6
5
|
var astralIdentifierStartCodes = [0, 11, 2, 25, 2, 18, 2, 1, 2, 14, 3, 13, 35, 122, 70, 52, 268, 28, 4, 48, 48, 31, 14, 29, 6, 37, 11, 29, 3, 35, 5, 7, 2, 4, 43, 157, 19, 35, 5, 35, 5, 39, 9, 51, 13, 10, 2, 14, 2, 6, 2, 1, 2, 10, 2, 14, 2, 6, 2, 1, 4, 51, 13, 310, 10, 21, 11, 7, 25, 5, 2, 41, 2, 8, 70, 5, 3, 0, 2, 43, 2, 1, 4, 0, 3, 22, 11, 22, 10, 30, 66, 18, 2, 1, 11, 21, 11, 25, 71, 55, 7, 1, 65, 0, 16, 3, 2, 2, 2, 28, 43, 28, 4, 28, 36, 7, 2, 27, 28, 53, 11, 21, 11, 18, 14, 17, 111, 72, 56, 50, 14, 50, 14, 35, 39, 27, 10, 22, 251, 41, 7, 1, 17, 2, 60, 28, 11, 0, 9, 21, 43, 17, 47, 20, 28, 22, 13, 52, 58, 1, 3, 0, 14, 44, 33, 24, 27, 35, 30, 0, 3, 0, 9, 34, 4, 0, 13, 47, 15, 3, 22, 0, 2, 0, 36, 17, 2, 24, 20, 1, 64, 6, 2, 0, 2, 3, 2, 14, 2, 9, 8, 46, 39, 7, 3, 1, 3, 21, 2, 6, 2, 1, 2, 4, 4, 0, 19, 0, 13, 4, 31, 9, 2, 0, 3, 0, 2, 37, 2, 0, 26, 0, 2, 0, 45, 52, 19, 3, 21, 2, 31, 47, 21, 1, 2, 0, 185, 46, 42, 3, 37, 47, 21, 0, 60, 42, 14, 0, 72, 26, 38, 6, 186, 43, 117, 63, 32, 7, 3, 0, 3, 7, 2, 1, 2, 23, 16, 0, 2, 0, 95, 7, 3, 38, 17, 0, 2, 0, 29, 0, 11, 39, 8, 0, 22, 0, 12, 45, 20, 0, 19, 72, 200, 32, 32, 8, 2, 36, 18, 0, 50, 29, 113, 6, 2, 1, 2, 37, 22, 0, 26, 5, 2, 1, 2, 31, 15, 0, 328, 18, 16, 0, 2, 12, 2, 33, 125, 0, 80, 921, 103, 110, 18, 195, 2637, 96, 16, 1071, 18, 5, 26, 3994, 6, 582, 6842, 29, 1763, 568, 8, 30, 18, 78, 18, 29, 19, 47, 17, 3, 32, 20, 6, 18, 433, 44, 212, 63, 129, 74, 6, 0, 67, 12, 65, 1, 2, 0, 29, 6135, 9, 1237, 42, 9, 8936, 3, 2, 6, 2, 1, 2, 290, 16, 0, 30, 2, 3, 0, 15, 3, 9, 395, 2309, 106, 6, 12, 4, 8, 8, 9, 5991, 84, 2, 70, 2, 1, 3, 0, 3, 1, 3, 3, 2, 11, 2, 0, 2, 6, 2, 64, 2, 3, 3, 7, 2, 6, 2, 27, 2, 3, 2, 4, 2, 0, 4, 6, 2, 339, 3, 24, 2, 24, 2, 30, 2, 24, 2, 30, 2, 24, 2, 30, 2, 24, 2, 30, 2, 24, 2, 7, 1845, 30, 7, 5, 262, 61, 147, 44, 11, 6, 17, 0, 322, 29, 19, 43, 485, 27, 229, 29, 3, 0, 496, 6, 2, 3, 2, 1, 2, 14, 2, 196, 60, 67, 8, 0, 1205, 3, 2, 26, 2, 1, 2, 0, 3, 0, 2, 9, 2, 3, 2, 0, 2, 0, 7, 0, 5, 0, 2, 0, 2, 0, 2, 2, 2, 1, 2, 0, 3, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 1, 2, 0, 3, 3, 2, 6, 2, 3, 2, 3, 2, 0, 2, 9, 2, 16, 6, 2, 2, 4, 2, 16, 4421, 42719, 33, 4153, 7, 221, 3, 5761, 15, 7472, 16, 621, 2467, 541, 1507, 4938, 6, 4191];
|
|
7
6
|
var nonASCIIidentifierChars = "·̀-ͯ·҃-֑҇-ׇֽֿׁׂׅׄؐ-ًؚ-٩ٰۖ-ۜ۟-۪ۤۧۨ-ۭ۰-۹ܑܰ-݊ަ-ް߀-߉߫-߽߳ࠖ-࠙ࠛ-ࠣࠥ-ࠧࠩ-࡙࠭-࡛-࢟࣊-ࣣ࣡-ःऺ-़ा-ॏ॑-ॗॢॣ०-९ঁ-ঃ়া-ৄেৈো-্ৗৢৣ০-৯৾ਁ-ਃ਼ਾ-ੂੇੈੋ-੍ੑ੦-ੱੵઁ-ઃ઼ા-ૅે-ૉો-્ૢૣ૦-૯ૺ-૿ଁ-ଃ଼ା-ୄେୈୋ-୍୕-ୗୢୣ୦-୯ஂா-ூெ-ைொ-்ௗ௦-௯ఀ-ఄ఼ా-ౄె-ైొ-్ౕౖౢౣ౦-౯ಁ-ಃ಼ಾ-ೄೆ-ೈೊ-್ೕೖೢೣ೦-೯ೳഀ-ഃ഻഼ാ-ൄെ-ൈൊ-്ൗൢൣ൦-൯ඁ-ඃ්ා-ුූෘ-ෟ෦-෯ෲෳัิ-ฺ็-๎๐-๙ັິ-ຼ່-໎໐-໙༘༙༠-༩༹༵༷༾༿ཱ-྄྆྇ྍ-ྗྙ-ྼ࿆ါ-ှ၀-၉ၖ-ၙၞ-ၠၢ-ၤၧ-ၭၱ-ၴႂ-ႍႏ-ႝ፝-፟፩-፱ᜒ-᜕ᜲ-᜴ᝒᝓᝲᝳ឴-៓៝០-៩᠋-᠍᠏-᠙ᢩᤠ-ᤫᤰ-᤻᥆-᥏᧐-᧚ᨗ-ᨛᩕ-ᩞ᩠-᩿᩼-᪉᪐-᪙᪰-᪽ᪿ-ᫎᬀ-ᬄ᬴-᭄᭐-᭙᭫-᭳ᮀ-ᮂᮡ-ᮭ᮰-᮹᯦-᯳ᰤ-᰷᱀-᱉᱐-᱙᳐-᳔᳒-᳨᳭᳴᳷-᳹᷀-᷿‿⁀⁔⃐-⃥⃜⃡-⃰⳯-⵿⳱ⷠ-〪ⷿ-゙゚〯・꘠-꘩꙯ꙴ-꙽ꚞꚟ꛰꛱ꠂ꠆ꠋꠣ-ꠧ꠬ꢀꢁꢴ-ꣅ꣐-꣙꣠-꣱ꣿ-꤉ꤦ-꤭ꥇ-꥓ꦀ-ꦃ꦳-꧀꧐-꧙ꧥ꧰-꧹ꨩ-ꨶꩃꩌꩍ꩐-꩙ꩻ-ꩽꪰꪲ-ꪴꪷꪸꪾ꪿꫁ꫫ-ꫯꫵ꫶ꯣ-ꯪ꯬꯭꯰-꯹ﬞ︀-️︠-︯︳︴﹍-﹏0-9_・";
|
|
@@ -228,12 +227,12 @@ var skipWhiteSpace = /(?:\s|\/\/.*|\/\*[^]*?\*\/)*/g;
|
|
|
228
227
|
var ref = Object.prototype;
|
|
229
228
|
var hasOwnProperty = ref.hasOwnProperty;
|
|
230
229
|
var toString = ref.toString;
|
|
231
|
-
var hasOwn = Object.hasOwn || function(obj, propName) {
|
|
230
|
+
var hasOwn = Object.hasOwn || (function(obj, propName) {
|
|
232
231
|
return hasOwnProperty.call(obj, propName);
|
|
233
|
-
};
|
|
234
|
-
var isArray = Array.isArray || function(obj) {
|
|
232
|
+
});
|
|
233
|
+
var isArray = Array.isArray || (function(obj) {
|
|
235
234
|
return toString.call(obj) === "[object Array]";
|
|
236
|
-
};
|
|
235
|
+
});
|
|
237
236
|
var regexpCache = /* @__PURE__ */ Object.create(null);
|
|
238
237
|
function wordsRegexp(words) {
|
|
239
238
|
return regexpCache[words] || (regexpCache[words] = new RegExp("^(?:" + words.replace(/ /g, "|") + ")$"));
|
|
@@ -848,6 +847,11 @@ pp$8.parseStatement = function(context, topLevel, exports) {
|
|
|
848
847
|
}
|
|
849
848
|
}
|
|
850
849
|
return starttype === types$1._import ? this.parseImport(node) : this.parseExport(node, exports);
|
|
850
|
+
// If the statement does not start with a statement keyword or a
|
|
851
|
+
// brace, it's an ExpressionStatement or LabeledStatement. We
|
|
852
|
+
// simply start parsing an expression, and afterwards, if the
|
|
853
|
+
// next token is a colon and the expression was a simple
|
|
854
|
+
// Identifier node, we switch to interpreting it as a label.
|
|
851
855
|
default:
|
|
852
856
|
if (this.isAsyncFunction()) {
|
|
853
857
|
if (context) {
|
|
@@ -5065,8 +5069,11 @@ pp.readToken_numberSign = function() {
|
|
|
5065
5069
|
};
|
|
5066
5070
|
pp.getTokenFromCode = function(code) {
|
|
5067
5071
|
switch (code) {
|
|
5072
|
+
// The interpretation of a dot depends on whether it is followed
|
|
5073
|
+
// by a digit or another two dots.
|
|
5068
5074
|
case 46:
|
|
5069
5075
|
return this.readToken_dot();
|
|
5076
|
+
// Punctuation tokens.
|
|
5070
5077
|
case 40:
|
|
5071
5078
|
++this.pos;
|
|
5072
5079
|
return this.finishToken(types$1.parenL);
|
|
@@ -5113,6 +5120,8 @@ pp.getTokenFromCode = function(code) {
|
|
|
5113
5120
|
return this.readRadixNumber(2);
|
|
5114
5121
|
}
|
|
5115
5122
|
}
|
|
5123
|
+
// Anything else beginning with a digit is an integer, octal
|
|
5124
|
+
// number, or float.
|
|
5116
5125
|
case 49:
|
|
5117
5126
|
case 50:
|
|
5118
5127
|
case 51:
|
|
@@ -5123,9 +5132,14 @@ pp.getTokenFromCode = function(code) {
|
|
|
5123
5132
|
case 56:
|
|
5124
5133
|
case 57:
|
|
5125
5134
|
return this.readNumber(false);
|
|
5135
|
+
// Quotes produce strings.
|
|
5126
5136
|
case 34:
|
|
5127
5137
|
case 39:
|
|
5128
5138
|
return this.readString(code);
|
|
5139
|
+
// Operators are parsed inline in tiny state machines. '=' (61) is
|
|
5140
|
+
// often referred to. `finishOp` simply skips the amount of
|
|
5141
|
+
// characters it is given as second argument, and returns a token
|
|
5142
|
+
// of the type given by its first argument.
|
|
5129
5143
|
case 47:
|
|
5130
5144
|
return this.readToken_slash();
|
|
5131
5145
|
case 37:
|
|
@@ -5443,12 +5457,14 @@ pp.readInvalidTemplateToken = function() {
|
|
|
5443
5457
|
if (this.input[this.pos + 1] !== "{") {
|
|
5444
5458
|
break;
|
|
5445
5459
|
}
|
|
5460
|
+
// fall through
|
|
5446
5461
|
case "`":
|
|
5447
5462
|
return this.finishToken(types$1.invalidTemplate, this.input.slice(this.start, this.pos));
|
|
5448
5463
|
case "\r":
|
|
5449
5464
|
if (this.input[this.pos + 1] === "\n") {
|
|
5450
5465
|
++this.pos;
|
|
5451
5466
|
}
|
|
5467
|
+
// fall through
|
|
5452
5468
|
case "\n":
|
|
5453
5469
|
case "\u2028":
|
|
5454
5470
|
case "\u2029":
|
|
@@ -5465,24 +5481,33 @@ pp.readEscapedChar = function(inTemplate) {
|
|
|
5465
5481
|
switch (ch) {
|
|
5466
5482
|
case 110:
|
|
5467
5483
|
return "\n";
|
|
5484
|
+
// 'n' -> '\n'
|
|
5468
5485
|
case 114:
|
|
5469
5486
|
return "\r";
|
|
5487
|
+
// 'r' -> '\r'
|
|
5470
5488
|
case 120:
|
|
5471
5489
|
return String.fromCharCode(this.readHexChar(2));
|
|
5490
|
+
// 'x'
|
|
5472
5491
|
case 117:
|
|
5473
5492
|
return codePointToString(this.readCodePoint());
|
|
5493
|
+
// 'u'
|
|
5474
5494
|
case 116:
|
|
5475
5495
|
return " ";
|
|
5496
|
+
// 't' -> '\t'
|
|
5476
5497
|
case 98:
|
|
5477
5498
|
return "\b";
|
|
5499
|
+
// 'b' -> '\b'
|
|
5478
5500
|
case 118:
|
|
5479
5501
|
return "\v";
|
|
5502
|
+
// 'v' -> '\u000b'
|
|
5480
5503
|
case 102:
|
|
5481
5504
|
return "\f";
|
|
5505
|
+
// 'f' -> '\f'
|
|
5482
5506
|
case 13:
|
|
5483
5507
|
if (this.input.charCodeAt(this.pos) === 10) {
|
|
5484
5508
|
++this.pos;
|
|
5485
5509
|
}
|
|
5510
|
+
// '\r\n'
|
|
5486
5511
|
case 10:
|
|
5487
5512
|
if (this.options.locations) {
|
|
5488
5513
|
this.lineStart = this.pos;
|
|
@@ -5599,25 +5624,268 @@ Parser.acorn = {
|
|
|
5599
5624
|
lineBreakG,
|
|
5600
5625
|
nonASCIIwhitespace
|
|
5601
5626
|
};
|
|
5602
|
-
function
|
|
5627
|
+
function resolveJsrImport(specifier) {
|
|
5628
|
+
if (!specifier.startsWith("jsr:"))
|
|
5629
|
+
return specifier;
|
|
5630
|
+
return `https://esm.sh/jsr/${specifier.slice(4)}`;
|
|
5631
|
+
}
|
|
5632
|
+
__name(resolveJsrImport, "resolveJsrImport");
|
|
5633
|
+
function parseNpmSpecifier(specifier) {
|
|
5634
|
+
const parts = specifier.split("/");
|
|
5635
|
+
const namerange = specifier.startsWith("@") ? [parts.shift(), parts.shift()].join("/") : parts.shift();
|
|
5636
|
+
const ranged = namerange.indexOf("@", 1);
|
|
5637
|
+
const name = ranged > 0 ? namerange.slice(0, ranged) : namerange;
|
|
5638
|
+
const range = ranged > 0 ? namerange.slice(ranged) : "";
|
|
5639
|
+
const path = parts.length > 0 ? `/${parts.join("/")}` : "";
|
|
5640
|
+
return { name, range, path };
|
|
5641
|
+
}
|
|
5642
|
+
__name(parseNpmSpecifier, "parseNpmSpecifier");
|
|
5643
|
+
function resolveNpmImport(specifier) {
|
|
5644
|
+
if (!specifier.startsWith("npm:"))
|
|
5645
|
+
return specifier;
|
|
5646
|
+
const { name, range, path } = parseNpmSpecifier(specifier.slice(4));
|
|
5647
|
+
return `https://cdn.jsdelivr.net/npm/${name}${range || getDefaultRange(name)}${path ? !/(\.\w+|\/|\/\+esm)$/.test(path) ? `${path}/+esm` : path : getDefaultPath(name)}`;
|
|
5648
|
+
}
|
|
5649
|
+
__name(resolveNpmImport, "resolveNpmImport");
|
|
5650
|
+
function getDefaultRange(name) {
|
|
5651
|
+
switch (name) {
|
|
5652
|
+
case "@duckdb/duckdb-wasm":
|
|
5653
|
+
return "@1.29.0";
|
|
5654
|
+
// https://github.com/duckdb/duckdb-wasm/issues/1994
|
|
5655
|
+
case "apache-arrow":
|
|
5656
|
+
return "@17.0.0";
|
|
5657
|
+
// to match @duckdb/duckdb-wasm 1.29.0
|
|
5658
|
+
default:
|
|
5659
|
+
return "";
|
|
5660
|
+
}
|
|
5661
|
+
}
|
|
5662
|
+
__name(getDefaultRange, "getDefaultRange");
|
|
5663
|
+
function getDefaultPath(name) {
|
|
5664
|
+
switch (name) {
|
|
5665
|
+
case "mermaid":
|
|
5666
|
+
return "/dist/mermaid.esm.min.mjs/+esm";
|
|
5667
|
+
case "echarts":
|
|
5668
|
+
return "/dist/echarts.esm.min.js/+esm";
|
|
5669
|
+
case "jquery-ui":
|
|
5670
|
+
return "/dist/jquery-ui.js/+esm";
|
|
5671
|
+
case "deck.gl":
|
|
5672
|
+
return "/dist.min.js/+esm";
|
|
5673
|
+
case "react-dom":
|
|
5674
|
+
return "/client/+esm";
|
|
5675
|
+
default:
|
|
5676
|
+
return "/+esm";
|
|
5677
|
+
}
|
|
5678
|
+
}
|
|
5679
|
+
__name(getDefaultPath, "getDefaultPath");
|
|
5680
|
+
const CODE_DOLLAR$1 = 36;
|
|
5681
|
+
function resolveObservableImport(specifier) {
|
|
5682
|
+
if (!specifier.startsWith("observable:"))
|
|
5683
|
+
return specifier;
|
|
5684
|
+
return `https://api.observablehq.com/${specifier.slice("observable:".length)}.js?v=4`;
|
|
5685
|
+
}
|
|
5686
|
+
__name(resolveObservableImport, "resolveObservableImport");
|
|
5687
|
+
function isObservableImport(node, specifier) {
|
|
5688
|
+
const type = node.attributes?.find((a) => getImportAttributeKey(a) === "type")?.value;
|
|
5689
|
+
return type ? type.value === "observable" : specifier.startsWith("observable:");
|
|
5690
|
+
}
|
|
5691
|
+
__name(isObservableImport, "isObservableImport");
|
|
5692
|
+
function getImportAttributeKey(node) {
|
|
5693
|
+
return node.key.type === "Identifier" ? node.key.name : String(node.key.value);
|
|
5694
|
+
}
|
|
5695
|
+
__name(getImportAttributeKey, "getImportAttributeKey");
|
|
5696
|
+
function renderObservableImport(source, node, inputs) {
|
|
5697
|
+
if (!inputs.includes("__ojs_runtime"))
|
|
5698
|
+
inputs.push("__ojs_runtime");
|
|
5699
|
+
if (!inputs.includes("__ojs_observer"))
|
|
5700
|
+
inputs.push("__ojs_observer");
|
|
5701
|
+
return `(import(${JSON.stringify(source)}).then((_) => {
|
|
5702
|
+
const observers = {};
|
|
5703
|
+
const module = __ojs_runtime.module(_.default);
|
|
5704
|
+
const main = __ojs_runtime.module();${node.specifiers.map((specifier) => {
|
|
5705
|
+
if (specifier.type === "ImportNamespaceSpecifier")
|
|
5706
|
+
throw new SyntaxError("observable namespace imports are not supported");
|
|
5707
|
+
const iname = getImportedName(specifier);
|
|
5708
|
+
const vname = dedollar(iname);
|
|
5709
|
+
return `
|
|
5710
|
+
if (!module.defines("${vname}")) throw new SyntaxError(\`export '${vname}' not found\`);
|
|
5711
|
+
main.variable(observers.${iname} = __ojs_observer()).import("${vname}", module);`;
|
|
5712
|
+
}).join("")}
|
|
5713
|
+
return observers;
|
|
5714
|
+
}))`;
|
|
5715
|
+
}
|
|
5716
|
+
__name(renderObservableImport, "renderObservableImport");
|
|
5717
|
+
function dedollar(input) {
|
|
5718
|
+
const start = 0;
|
|
5719
|
+
const end = input.length;
|
|
5720
|
+
let dollars = 0;
|
|
5721
|
+
for (let i = start; i < end; ++i) {
|
|
5722
|
+
switch (input.charCodeAt(i)) {
|
|
5723
|
+
case CODE_DOLLAR$1: {
|
|
5724
|
+
++dollars;
|
|
5725
|
+
break;
|
|
5726
|
+
}
|
|
5727
|
+
default: {
|
|
5728
|
+
if (dollars > 0) {
|
|
5729
|
+
input = `${input.slice(0, i - 1)}${dollars === 1 ? " " : ""}${input.slice(i)}`;
|
|
5730
|
+
dollars = 0;
|
|
5731
|
+
}
|
|
5732
|
+
break;
|
|
5733
|
+
}
|
|
5734
|
+
}
|
|
5735
|
+
}
|
|
5736
|
+
if (dollars > 0) {
|
|
5737
|
+
input = `${input.slice(0, end - 1)}${dollars === 1 ? " " : ""}`;
|
|
5738
|
+
dollars = 0;
|
|
5739
|
+
}
|
|
5740
|
+
return input;
|
|
5741
|
+
}
|
|
5742
|
+
__name(dedollar, "dedollar");
|
|
5743
|
+
function isLiteral(node) {
|
|
5744
|
+
return node.type === "Literal";
|
|
5745
|
+
}
|
|
5746
|
+
__name(isLiteral, "isLiteral");
|
|
5747
|
+
function isTemplateLiteral(node) {
|
|
5748
|
+
return node.type === "TemplateLiteral";
|
|
5749
|
+
}
|
|
5750
|
+
__name(isTemplateLiteral, "isTemplateLiteral");
|
|
5751
|
+
function isStringLiteral(node) {
|
|
5752
|
+
return isLiteral(node) ? /^['"]/.test(node.raw) : isTemplateLiteral(node) ? node.expressions.every(isStringLiteral) : isBinaryExpression(node) ? node.operator === "+" && isStringLiteral(node.left) && isStringLiteral(node.right) : isMemberExpression(node) ? "value" in node : false;
|
|
5753
|
+
}
|
|
5754
|
+
__name(isStringLiteral, "isStringLiteral");
|
|
5755
|
+
function getStringLiteralValue(node) {
|
|
5756
|
+
return node.type === "TemplateLiteral" ? getTemplateLiteralValue(node) : node.type === "BinaryExpression" ? getBinaryExpressionValue(node) : node.value;
|
|
5757
|
+
}
|
|
5758
|
+
__name(getStringLiteralValue, "getStringLiteralValue");
|
|
5759
|
+
function getTemplateLiteralValue(node) {
|
|
5760
|
+
let value = node.quasis[0].value.cooked;
|
|
5761
|
+
for (let i = 0; i < node.expressions.length; ++i) {
|
|
5762
|
+
value += getStringLiteralValue(node.expressions[i]);
|
|
5763
|
+
value += node.quasis[i + 1].value.cooked;
|
|
5764
|
+
}
|
|
5765
|
+
return value;
|
|
5766
|
+
}
|
|
5767
|
+
__name(getTemplateLiteralValue, "getTemplateLiteralValue");
|
|
5768
|
+
function getBinaryExpressionValue(node) {
|
|
5769
|
+
return getStringLiteralValue(node.left) + getStringLiteralValue(node.right);
|
|
5770
|
+
}
|
|
5771
|
+
__name(getBinaryExpressionValue, "getBinaryExpressionValue");
|
|
5772
|
+
function isMemberExpression(node) {
|
|
5773
|
+
return node.type === "MemberExpression";
|
|
5774
|
+
}
|
|
5775
|
+
__name(isMemberExpression, "isMemberExpression");
|
|
5776
|
+
function isBinaryExpression(node) {
|
|
5777
|
+
return node.type === "BinaryExpression";
|
|
5778
|
+
}
|
|
5779
|
+
__name(isBinaryExpression, "isBinaryExpression");
|
|
5780
|
+
function syntaxError(message, node, input) {
|
|
5781
|
+
const { line, column } = getLineInfo(input, node.start);
|
|
5782
|
+
return new SyntaxError(`${message} (${line}:${column})`);
|
|
5783
|
+
}
|
|
5784
|
+
__name(syntaxError, "syntaxError");
|
|
5785
|
+
const defaultGlobals$1 = /* @__PURE__ */ new Set([
|
|
5786
|
+
"Array",
|
|
5787
|
+
"ArrayBuffer",
|
|
5788
|
+
"atob",
|
|
5789
|
+
"AudioContext",
|
|
5790
|
+
"Blob",
|
|
5791
|
+
"Boolean",
|
|
5792
|
+
"BigInt",
|
|
5793
|
+
"btoa",
|
|
5794
|
+
"clearInterval",
|
|
5795
|
+
"clearTimeout",
|
|
5796
|
+
"console",
|
|
5797
|
+
"crypto",
|
|
5798
|
+
"CustomEvent",
|
|
5799
|
+
"DataView",
|
|
5800
|
+
"Date",
|
|
5801
|
+
"decodeURI",
|
|
5802
|
+
"decodeURIComponent",
|
|
5803
|
+
"devicePixelRatio",
|
|
5804
|
+
"document",
|
|
5805
|
+
"encodeURI",
|
|
5806
|
+
"encodeURIComponent",
|
|
5807
|
+
"Error",
|
|
5808
|
+
"escape",
|
|
5809
|
+
"eval",
|
|
5810
|
+
"fetch",
|
|
5811
|
+
"File",
|
|
5812
|
+
"FileList",
|
|
5813
|
+
"FileReader",
|
|
5814
|
+
"Float32Array",
|
|
5815
|
+
"Float64Array",
|
|
5816
|
+
"Function",
|
|
5817
|
+
"Headers",
|
|
5818
|
+
"Image",
|
|
5819
|
+
"ImageData",
|
|
5820
|
+
"Infinity",
|
|
5821
|
+
"Int16Array",
|
|
5822
|
+
"Int32Array",
|
|
5823
|
+
"Int8Array",
|
|
5824
|
+
"Intl",
|
|
5825
|
+
"isFinite",
|
|
5826
|
+
"isNaN",
|
|
5827
|
+
"JSON",
|
|
5828
|
+
"Map",
|
|
5829
|
+
"Math",
|
|
5830
|
+
"NaN",
|
|
5831
|
+
"Number",
|
|
5832
|
+
"navigator",
|
|
5833
|
+
"Object",
|
|
5834
|
+
"parseFloat",
|
|
5835
|
+
"parseInt",
|
|
5836
|
+
"performance",
|
|
5837
|
+
"Path2D",
|
|
5838
|
+
"Promise",
|
|
5839
|
+
"Proxy",
|
|
5840
|
+
"RangeError",
|
|
5841
|
+
"ReferenceError",
|
|
5842
|
+
"Reflect",
|
|
5843
|
+
"RegExp",
|
|
5844
|
+
"cancelAnimationFrame",
|
|
5845
|
+
"requestAnimationFrame",
|
|
5846
|
+
"Set",
|
|
5847
|
+
"setInterval",
|
|
5848
|
+
"setTimeout",
|
|
5849
|
+
"String",
|
|
5850
|
+
"Symbol",
|
|
5851
|
+
"SyntaxError",
|
|
5852
|
+
"TextDecoder",
|
|
5853
|
+
"TextEncoder",
|
|
5854
|
+
"this",
|
|
5855
|
+
"TypeError",
|
|
5856
|
+
"Uint16Array",
|
|
5857
|
+
"Uint32Array",
|
|
5858
|
+
"Uint8Array",
|
|
5859
|
+
"Uint8ClampedArray",
|
|
5860
|
+
"undefined",
|
|
5861
|
+
"unescape",
|
|
5862
|
+
"URIError",
|
|
5863
|
+
"URL",
|
|
5864
|
+
"WeakMap",
|
|
5865
|
+
"WeakSet",
|
|
5866
|
+
"WebSocket",
|
|
5867
|
+
"Worker",
|
|
5868
|
+
"window"
|
|
5869
|
+
]);
|
|
5870
|
+
function simple$1(node, visitors, baseVisitor, state, override) {
|
|
5603
5871
|
if (!baseVisitor) {
|
|
5604
5872
|
baseVisitor = base;
|
|
5605
5873
|
}
|
|
5606
|
-
(/* @__PURE__ */ __name(function c(node2, st, override2) {
|
|
5874
|
+
(/* @__PURE__ */ __name((function c(node2, st, override2) {
|
|
5607
5875
|
var type = override2 || node2.type;
|
|
5608
5876
|
baseVisitor[type](node2, st, c);
|
|
5609
5877
|
if (visitors[type]) {
|
|
5610
5878
|
visitors[type](node2, st);
|
|
5611
5879
|
}
|
|
5612
|
-
}, "c"))(node, state, override);
|
|
5880
|
+
}), "c"))(node, state, override);
|
|
5613
5881
|
}
|
|
5614
|
-
__name(simple, "simple");
|
|
5615
|
-
function ancestor(node, visitors, baseVisitor, state, override) {
|
|
5882
|
+
__name(simple$1, "simple$1");
|
|
5883
|
+
function ancestor$1(node, visitors, baseVisitor, state, override) {
|
|
5616
5884
|
var ancestors = [];
|
|
5617
5885
|
if (!baseVisitor) {
|
|
5618
5886
|
baseVisitor = base;
|
|
5619
5887
|
}
|
|
5620
|
-
(/* @__PURE__ */ __name(function c(node2, st, override2) {
|
|
5888
|
+
(/* @__PURE__ */ __name((function c(node2, st, override2) {
|
|
5621
5889
|
var type = override2 || node2.type;
|
|
5622
5890
|
var isNew = node2 !== ancestors[ancestors.length - 1];
|
|
5623
5891
|
if (isNew) {
|
|
@@ -5630,11 +5898,18 @@ function ancestor(node, visitors, baseVisitor, state, override) {
|
|
|
5630
5898
|
if (isNew) {
|
|
5631
5899
|
ancestors.pop();
|
|
5632
5900
|
}
|
|
5633
|
-
}, "c"))(node, state, override);
|
|
5901
|
+
}), "c"))(node, state, override);
|
|
5634
5902
|
}
|
|
5635
|
-
__name(ancestor, "ancestor");
|
|
5903
|
+
__name(ancestor$1, "ancestor$1");
|
|
5904
|
+
function recursive$1(node, state, funcs, baseVisitor, override) {
|
|
5905
|
+
var visitor = funcs ? make(funcs, baseVisitor || void 0) : baseVisitor;
|
|
5906
|
+
(/* @__PURE__ */ __name((function c(node2, st, override2) {
|
|
5907
|
+
visitor[override2 || node2.type](node2, st, c);
|
|
5908
|
+
}), "c"))(node, state, override);
|
|
5909
|
+
}
|
|
5910
|
+
__name(recursive$1, "recursive$1");
|
|
5636
5911
|
function make(funcs, baseVisitor) {
|
|
5637
|
-
var visitor = Object.create(base);
|
|
5912
|
+
var visitor = Object.create(baseVisitor || base);
|
|
5638
5913
|
for (var type in funcs) {
|
|
5639
5914
|
visitor[type] = funcs[type];
|
|
5640
5915
|
}
|
|
@@ -5923,91 +6198,6 @@ base.MethodDefinition = base.PropertyDefinition = base.Property = function(node,
|
|
|
5923
6198
|
c(node.value, st, "Expression");
|
|
5924
6199
|
}
|
|
5925
6200
|
};
|
|
5926
|
-
const defaultGlobals = /* @__PURE__ */ new Set([
|
|
5927
|
-
"Array",
|
|
5928
|
-
"ArrayBuffer",
|
|
5929
|
-
"atob",
|
|
5930
|
-
"AudioContext",
|
|
5931
|
-
"Blob",
|
|
5932
|
-
"Boolean",
|
|
5933
|
-
"BigInt",
|
|
5934
|
-
"btoa",
|
|
5935
|
-
"clearInterval",
|
|
5936
|
-
"clearTimeout",
|
|
5937
|
-
"console",
|
|
5938
|
-
"crypto",
|
|
5939
|
-
"CustomEvent",
|
|
5940
|
-
"DataView",
|
|
5941
|
-
"Date",
|
|
5942
|
-
"decodeURI",
|
|
5943
|
-
"decodeURIComponent",
|
|
5944
|
-
"devicePixelRatio",
|
|
5945
|
-
"document",
|
|
5946
|
-
"encodeURI",
|
|
5947
|
-
"encodeURIComponent",
|
|
5948
|
-
"Error",
|
|
5949
|
-
"escape",
|
|
5950
|
-
"eval",
|
|
5951
|
-
"fetch",
|
|
5952
|
-
"File",
|
|
5953
|
-
"FileList",
|
|
5954
|
-
"FileReader",
|
|
5955
|
-
"Float32Array",
|
|
5956
|
-
"Float64Array",
|
|
5957
|
-
"Function",
|
|
5958
|
-
"Headers",
|
|
5959
|
-
"Image",
|
|
5960
|
-
"ImageData",
|
|
5961
|
-
"Infinity",
|
|
5962
|
-
"Int16Array",
|
|
5963
|
-
"Int32Array",
|
|
5964
|
-
"Int8Array",
|
|
5965
|
-
"Intl",
|
|
5966
|
-
"isFinite",
|
|
5967
|
-
"isNaN",
|
|
5968
|
-
"JSON",
|
|
5969
|
-
"Map",
|
|
5970
|
-
"Math",
|
|
5971
|
-
"NaN",
|
|
5972
|
-
"Number",
|
|
5973
|
-
"navigator",
|
|
5974
|
-
"Object",
|
|
5975
|
-
"parseFloat",
|
|
5976
|
-
"parseInt",
|
|
5977
|
-
"performance",
|
|
5978
|
-
"Path2D",
|
|
5979
|
-
"Promise",
|
|
5980
|
-
"Proxy",
|
|
5981
|
-
"RangeError",
|
|
5982
|
-
"ReferenceError",
|
|
5983
|
-
"Reflect",
|
|
5984
|
-
"RegExp",
|
|
5985
|
-
"cancelAnimationFrame",
|
|
5986
|
-
"requestAnimationFrame",
|
|
5987
|
-
"Set",
|
|
5988
|
-
"setInterval",
|
|
5989
|
-
"setTimeout",
|
|
5990
|
-
"String",
|
|
5991
|
-
"Symbol",
|
|
5992
|
-
"SyntaxError",
|
|
5993
|
-
"TextDecoder",
|
|
5994
|
-
"TextEncoder",
|
|
5995
|
-
"this",
|
|
5996
|
-
"TypeError",
|
|
5997
|
-
"Uint16Array",
|
|
5998
|
-
"Uint32Array",
|
|
5999
|
-
"Uint8Array",
|
|
6000
|
-
"Uint8ClampedArray",
|
|
6001
|
-
"undefined",
|
|
6002
|
-
"unescape",
|
|
6003
|
-
"URIError",
|
|
6004
|
-
"URL",
|
|
6005
|
-
"WeakMap",
|
|
6006
|
-
"WeakSet",
|
|
6007
|
-
"WebSocket",
|
|
6008
|
-
"Worker",
|
|
6009
|
-
"window"
|
|
6010
|
-
]);
|
|
6011
6201
|
const ohqWalk = make({
|
|
6012
6202
|
Import() {
|
|
6013
6203
|
},
|
|
@@ -6018,19 +6208,19 @@ const ohqWalk = make({
|
|
|
6018
6208
|
c(node.id, st, "Identifier");
|
|
6019
6209
|
}
|
|
6020
6210
|
});
|
|
6021
|
-
function isScope(node) {
|
|
6211
|
+
function isScope$1(node) {
|
|
6022
6212
|
return node.type === "FunctionExpression" || node.type === "FunctionDeclaration" || node.type === "ArrowFunctionExpression" || node.type === "Program";
|
|
6023
6213
|
}
|
|
6024
|
-
__name(isScope, "isScope");
|
|
6025
|
-
function isBlockScope(node) {
|
|
6026
|
-
return node.type === "BlockStatement" || node.type === "ForInStatement" || node.type === "ForOfStatement" || node.type === "ForStatement" || isScope(node);
|
|
6214
|
+
__name(isScope$1, "isScope$1");
|
|
6215
|
+
function isBlockScope$1(node) {
|
|
6216
|
+
return node.type === "BlockStatement" || node.type === "ForInStatement" || node.type === "ForOfStatement" || node.type === "ForStatement" || isScope$1(node);
|
|
6027
6217
|
}
|
|
6028
|
-
__name(isBlockScope, "isBlockScope");
|
|
6218
|
+
__name(isBlockScope$1, "isBlockScope$1");
|
|
6029
6219
|
function declaresArguments(node) {
|
|
6030
6220
|
return node.type === "FunctionExpression" || node.type === "FunctionDeclaration";
|
|
6031
6221
|
}
|
|
6032
6222
|
__name(declaresArguments, "declaresArguments");
|
|
6033
|
-
function findReferences(cell, globals) {
|
|
6223
|
+
function findReferences$1(cell, globals) {
|
|
6034
6224
|
const ast = { type: "Program", body: [cell.body] };
|
|
6035
6225
|
const locals = /* @__PURE__ */ new Map();
|
|
6036
6226
|
const globalSet = new Set(globals);
|
|
@@ -6088,13 +6278,13 @@ function findReferences(cell, globals) {
|
|
|
6088
6278
|
declareLocal(ast, node.local);
|
|
6089
6279
|
}
|
|
6090
6280
|
__name(declareModuleSpecifier, "declareModuleSpecifier");
|
|
6091
|
-
ancestor(
|
|
6281
|
+
ancestor$1(
|
|
6092
6282
|
ast,
|
|
6093
6283
|
{
|
|
6094
6284
|
VariableDeclaration: /* @__PURE__ */ __name((node, parents) => {
|
|
6095
6285
|
let parent = null;
|
|
6096
6286
|
for (let i = parents.length - 1; i >= 0 && parent === null; --i) {
|
|
6097
|
-
if (node.kind === "var" ? isScope(parents[i]) : isBlockScope(parents[i])) {
|
|
6287
|
+
if (node.kind === "var" ? isScope$1(parents[i]) : isBlockScope$1(parents[i])) {
|
|
6098
6288
|
parent = parents[i];
|
|
6099
6289
|
}
|
|
6100
6290
|
}
|
|
@@ -6103,7 +6293,7 @@ function findReferences(cell, globals) {
|
|
|
6103
6293
|
FunctionDeclaration: /* @__PURE__ */ __name((node, parents) => {
|
|
6104
6294
|
let parent = null;
|
|
6105
6295
|
for (let i = parents.length - 2; i >= 0 && parent === null; --i) {
|
|
6106
|
-
if (isScope(parents[i])) {
|
|
6296
|
+
if (isScope$1(parents[i])) {
|
|
6107
6297
|
parent = parents[i];
|
|
6108
6298
|
}
|
|
6109
6299
|
}
|
|
@@ -6114,7 +6304,7 @@ function findReferences(cell, globals) {
|
|
|
6114
6304
|
ClassDeclaration: /* @__PURE__ */ __name((node, parents) => {
|
|
6115
6305
|
let parent = null;
|
|
6116
6306
|
for (let i = parents.length - 2; i >= 0 && parent === null; i--) {
|
|
6117
|
-
if (isScope(parents[i])) {
|
|
6307
|
+
if (isScope$1(parents[i])) {
|
|
6118
6308
|
parent = parents[i];
|
|
6119
6309
|
}
|
|
6120
6310
|
}
|
|
@@ -6157,7 +6347,7 @@ function findReferences(cell, globals) {
|
|
|
6157
6347
|
}
|
|
6158
6348
|
}
|
|
6159
6349
|
__name(identifier, "identifier");
|
|
6160
|
-
ancestor(
|
|
6350
|
+
ancestor$1(
|
|
6161
6351
|
ast,
|
|
6162
6352
|
{
|
|
6163
6353
|
VariablePattern: identifier,
|
|
@@ -6211,7 +6401,7 @@ function findReferences(cell, globals) {
|
|
|
6211
6401
|
checkConst(node.left, parents);
|
|
6212
6402
|
}
|
|
6213
6403
|
__name(checkConstLeft, "checkConstLeft");
|
|
6214
|
-
ancestor(
|
|
6404
|
+
ancestor$1(
|
|
6215
6405
|
ast,
|
|
6216
6406
|
{
|
|
6217
6407
|
AssignmentExpression: checkConstLeft,
|
|
@@ -6224,12 +6414,12 @@ function findReferences(cell, globals) {
|
|
|
6224
6414
|
);
|
|
6225
6415
|
return references;
|
|
6226
6416
|
}
|
|
6227
|
-
__name(findReferences, "findReferences");
|
|
6417
|
+
__name(findReferences$1, "findReferences$1");
|
|
6228
6418
|
function findFeatures(cell, featureName) {
|
|
6229
6419
|
const ast = { type: "Program", body: [cell.body] };
|
|
6230
6420
|
const features = /* @__PURE__ */ new Map();
|
|
6231
6421
|
const { references } = cell;
|
|
6232
|
-
simple(
|
|
6422
|
+
simple$1(
|
|
6233
6423
|
ast,
|
|
6234
6424
|
{
|
|
6235
6425
|
CallExpression: /* @__PURE__ */ __name((node) => {
|
|
@@ -6256,7 +6446,7 @@ const SCOPE_GENERATOR = 8;
|
|
|
6256
6446
|
function parseCell$2(input, { tag, raw, globals, ...options } = {}) {
|
|
6257
6447
|
let cell;
|
|
6258
6448
|
if (tag != null && input) {
|
|
6259
|
-
cell = TemplateCellParser.parse(input, options);
|
|
6449
|
+
cell = TemplateCellParser$1.parse(input, options);
|
|
6260
6450
|
const parsedTag = CellTagParser.parse(tag, options);
|
|
6261
6451
|
parseReferences(parsedTag, tag, globals);
|
|
6262
6452
|
parseFeatures(parsedTag, tag);
|
|
@@ -6402,7 +6592,7 @@ const _CellParser = class _CellParser extends Parser {
|
|
|
6402
6592
|
}
|
|
6403
6593
|
checkLocal(id) {
|
|
6404
6594
|
const node = id.id || id;
|
|
6405
|
-
if (defaultGlobals.has(node.name) || node.name === "arguments") {
|
|
6595
|
+
if (defaultGlobals$1.has(node.name) || node.name === "arguments") {
|
|
6406
6596
|
this.raise(node.start, `Identifier '${node.name}' is reserved`);
|
|
6407
6597
|
}
|
|
6408
6598
|
}
|
|
@@ -6436,7 +6626,7 @@ const _CellParser = class _CellParser extends Parser {
|
|
|
6436
6626
|
};
|
|
6437
6627
|
__name(_CellParser, "CellParser");
|
|
6438
6628
|
let CellParser = _CellParser;
|
|
6439
|
-
const o_tmpl = new TokContext(
|
|
6629
|
+
const o_tmpl$1 = new TokContext(
|
|
6440
6630
|
"`",
|
|
6441
6631
|
// token
|
|
6442
6632
|
true,
|
|
@@ -6446,14 +6636,14 @@ const o_tmpl = new TokContext(
|
|
|
6446
6636
|
(parser) => readTemplateToken.call(parser)
|
|
6447
6637
|
// override
|
|
6448
6638
|
);
|
|
6449
|
-
|
|
6639
|
+
let TemplateCellParser$1 = (_a = class extends CellParser {
|
|
6450
6640
|
constructor(...args) {
|
|
6451
6641
|
super(...args);
|
|
6452
6642
|
this.type = types$1.backQuote;
|
|
6453
6643
|
this.exprAllowed = false;
|
|
6454
6644
|
}
|
|
6455
6645
|
initialContext() {
|
|
6456
|
-
return [o_tmpl];
|
|
6646
|
+
return [o_tmpl$1];
|
|
6457
6647
|
}
|
|
6458
6648
|
parseCell(node) {
|
|
6459
6649
|
this.startCell();
|
|
@@ -6475,9 +6665,7 @@ const _TemplateCellParser = class _TemplateCellParser extends CellParser {
|
|
|
6475
6665
|
this.expect(types$1.eof);
|
|
6476
6666
|
return this.finishCell(node, body, null);
|
|
6477
6667
|
}
|
|
6478
|
-
};
|
|
6479
|
-
__name(_TemplateCellParser, "TemplateCellParser");
|
|
6480
|
-
let TemplateCellParser = _TemplateCellParser;
|
|
6668
|
+
}, __name(_a, "TemplateCellParser"), _a);
|
|
6481
6669
|
function readTemplateToken() {
|
|
6482
6670
|
out: for (; this.pos < this.input.length; this.pos++) {
|
|
6483
6671
|
switch (this.input.charCodeAt(this.pos)) {
|
|
@@ -6540,14 +6728,14 @@ const _CellTagParser = class _CellTagParser extends Parser {
|
|
|
6540
6728
|
};
|
|
6541
6729
|
__name(_CellTagParser, "CellTagParser");
|
|
6542
6730
|
let CellTagParser = _CellTagParser;
|
|
6543
|
-
function parseReferences(cell, input, globals = defaultGlobals) {
|
|
6731
|
+
function parseReferences(cell, input, globals = defaultGlobals$1) {
|
|
6544
6732
|
if (!cell.body) {
|
|
6545
6733
|
cell.references = [];
|
|
6546
6734
|
} else if (cell.body.type === "ImportDeclaration") {
|
|
6547
6735
|
cell.references = cell.body.injections ? cell.body.injections.map((i) => i.imported) : [];
|
|
6548
6736
|
} else {
|
|
6549
6737
|
try {
|
|
6550
|
-
cell.references = findReferences(cell, globals);
|
|
6738
|
+
cell.references = findReferences$1(cell, globals);
|
|
6551
6739
|
} catch (error) {
|
|
6552
6740
|
if (error.node) {
|
|
6553
6741
|
const loc = getLineInfo(input, error.node.start);
|
|
@@ -6588,55 +6776,1137 @@ function parseFeatures(cell, input) {
|
|
|
6588
6776
|
return cell;
|
|
6589
6777
|
}
|
|
6590
6778
|
__name(parseFeatures, "parseFeatures");
|
|
6591
|
-
|
|
6592
|
-
|
|
6593
|
-
if (!node.cells) node.cells = [];
|
|
6594
|
-
while (this.type !== types$1.eof) {
|
|
6595
|
-
const cell = this.parseCell(this.startNode());
|
|
6596
|
-
cell.input = this.input;
|
|
6597
|
-
node.cells.push(cell);
|
|
6598
|
-
}
|
|
6599
|
-
this.next();
|
|
6600
|
-
return this.finishNode(node, "Program");
|
|
6601
|
-
}
|
|
6602
|
-
};
|
|
6603
|
-
__name(_ModuleParser, "ModuleParser");
|
|
6604
|
-
let ModuleParser = _ModuleParser;
|
|
6605
|
-
function splitModule(input) {
|
|
6606
|
-
return ModuleParser.parse(input, { ecmaVersion: "latest" }).cells.map((cell) => ({
|
|
6607
|
-
type: "Cell",
|
|
6608
|
-
text: input.substring(cell.start, cell.end),
|
|
6609
|
-
start: cell.start,
|
|
6610
|
-
end: cell.end
|
|
6611
|
-
}));
|
|
6779
|
+
function ancestor(node, visitors) {
|
|
6780
|
+
return ancestor$1(node, visitors, ohqWalk);
|
|
6612
6781
|
}
|
|
6613
|
-
__name(
|
|
6614
|
-
function
|
|
6615
|
-
return
|
|
6782
|
+
__name(ancestor, "ancestor");
|
|
6783
|
+
function recursive(node, state, functions) {
|
|
6784
|
+
return recursive$1(node, state, functions, ohqWalk);
|
|
6616
6785
|
}
|
|
6617
|
-
__name(
|
|
6618
|
-
|
|
6619
|
-
|
|
6620
|
-
functionType: Object.getPrototypeOf(function() {
|
|
6621
|
-
}).constructor,
|
|
6622
|
-
asyncFunctionType: Object.getPrototypeOf(async function() {
|
|
6623
|
-
}).constructor,
|
|
6624
|
-
generatorFunctionType: Object.getPrototypeOf(function* () {
|
|
6625
|
-
}).constructor,
|
|
6626
|
-
asyncGeneratorFunctionType: Object.getPrototypeOf(async function* () {
|
|
6627
|
-
}).constructor
|
|
6628
|
-
};
|
|
6629
|
-
function funcType(async = false, generator = false) {
|
|
6630
|
-
if (!async && !generator) return FuncTypes.functionType;
|
|
6631
|
-
if (async && !generator) return FuncTypes.asyncFunctionType;
|
|
6632
|
-
if (!async && generator) return FuncTypes.generatorFunctionType;
|
|
6633
|
-
return FuncTypes.asyncGeneratorFunctionType;
|
|
6786
|
+
__name(recursive, "recursive");
|
|
6787
|
+
function simple(node, visitors) {
|
|
6788
|
+
return simple$1(node, visitors, ohqWalk);
|
|
6634
6789
|
}
|
|
6635
|
-
__name(
|
|
6636
|
-
function
|
|
6637
|
-
|
|
6638
|
-
|
|
6639
|
-
}
|
|
6790
|
+
__name(simple, "simple");
|
|
6791
|
+
function checkExports(body, input) {
|
|
6792
|
+
function checkExport(child) {
|
|
6793
|
+
throw syntaxError("Unexpected token 'export'", child, input);
|
|
6794
|
+
}
|
|
6795
|
+
__name(checkExport, "checkExport");
|
|
6796
|
+
simple(body, {
|
|
6797
|
+
ExportAllDeclaration: checkExport,
|
|
6798
|
+
ExportNamedDeclaration: checkExport
|
|
6799
|
+
});
|
|
6800
|
+
}
|
|
6801
|
+
__name(checkExports, "checkExports");
|
|
6802
|
+
function hasImportDeclaration(body) {
|
|
6803
|
+
let has = false;
|
|
6804
|
+
simple(body, {
|
|
6805
|
+
ImportDeclaration() {
|
|
6806
|
+
has = true;
|
|
6807
|
+
}
|
|
6808
|
+
});
|
|
6809
|
+
return has;
|
|
6810
|
+
}
|
|
6811
|
+
__name(hasImportDeclaration, "hasImportDeclaration");
|
|
6812
|
+
function isImportMetaResolve(node) {
|
|
6813
|
+
return node.callee.type === "MemberExpression" && node.callee.object.type === "MetaProperty" && node.callee.object.meta.name === "import" && node.callee.object.property.name === "meta" && node.callee.property.type === "Identifier" && node.callee.property.name === "resolve" && node.arguments.length > 0;
|
|
6814
|
+
}
|
|
6815
|
+
__name(isImportMetaResolve, "isImportMetaResolve");
|
|
6816
|
+
function isImportMetaUrl(node) {
|
|
6817
|
+
return node.object.type === "MetaProperty" && node.object.meta.name === "import" && node.object.property.name === "meta" && node.property.type === "Identifier" && node.property.name === "url";
|
|
6818
|
+
}
|
|
6819
|
+
__name(isImportMetaUrl, "isImportMetaUrl");
|
|
6820
|
+
function resolveImport(specifier) {
|
|
6821
|
+
return resolveObservableImport(resolveJsrImport(resolveNpmImport(specifier)));
|
|
6822
|
+
}
|
|
6823
|
+
__name(resolveImport, "resolveImport");
|
|
6824
|
+
function rewriteImportExpressions(output, body, { resolveLocalImports } = {}) {
|
|
6825
|
+
function rewriteImportSource2(source, node = source) {
|
|
6826
|
+
const value = getStringLiteralValue(source);
|
|
6827
|
+
const resolution = resolveImport(value);
|
|
6828
|
+
output.replaceLeft(node.start, node.end, resolveLocalImports && isLocalImport(resolution) ? `new URL(${JSON.stringify(resolution)}, document.baseURI).href` : JSON.stringify(resolution));
|
|
6829
|
+
}
|
|
6830
|
+
__name(rewriteImportSource2, "rewriteImportSource");
|
|
6831
|
+
simple(body, {
|
|
6832
|
+
ImportExpression(node) {
|
|
6833
|
+
const source = node.source;
|
|
6834
|
+
if (isStringLiteral(source)) {
|
|
6835
|
+
rewriteImportSource2(source);
|
|
6836
|
+
}
|
|
6837
|
+
},
|
|
6838
|
+
MemberExpression(node) {
|
|
6839
|
+
if (resolveLocalImports && isImportMetaUrl(node)) {
|
|
6840
|
+
output.replaceLeft(node.start, node.end, "document.baseURI");
|
|
6841
|
+
}
|
|
6842
|
+
},
|
|
6843
|
+
CallExpression(node) {
|
|
6844
|
+
const source = node.arguments[0];
|
|
6845
|
+
if (isImportMetaResolve(node) && isStringLiteral(source)) {
|
|
6846
|
+
rewriteImportSource2(source, node);
|
|
6847
|
+
}
|
|
6848
|
+
}
|
|
6849
|
+
});
|
|
6850
|
+
}
|
|
6851
|
+
__name(rewriteImportExpressions, "rewriteImportExpressions");
|
|
6852
|
+
function rewriteImportDeclarations(output, body, inputs, { resolveLocalImports } = {}) {
|
|
6853
|
+
const declarations = [];
|
|
6854
|
+
simple(body, {
|
|
6855
|
+
ImportDeclaration(node) {
|
|
6856
|
+
if (isStringLiteral(node.source)) {
|
|
6857
|
+
declarations.push([node, node.source]);
|
|
6858
|
+
}
|
|
6859
|
+
}
|
|
6860
|
+
});
|
|
6861
|
+
const specifiers = [];
|
|
6862
|
+
const imports = [];
|
|
6863
|
+
for (const [node, source] of declarations) {
|
|
6864
|
+
output.delete(node.start, node.end + +(output.input[node.end] === "\n"));
|
|
6865
|
+
specifiers.push(rewriteImportSpecifiers(node));
|
|
6866
|
+
const value = getStringLiteralValue(source);
|
|
6867
|
+
const resolution = resolveImport(value);
|
|
6868
|
+
imports.push(isObservableImport(node, value) ? renderObservableImport(resolution, node, inputs) : renderImport(resolveLocalImports && isLocalImport(resolution) ? `new URL(${JSON.stringify(resolution)}, document.baseURI)` : JSON.stringify(resolution), node, output.input));
|
|
6869
|
+
}
|
|
6870
|
+
if (declarations.length > 1) {
|
|
6871
|
+
output.insertLeft(0, `const [${specifiers.join(", ")}] = await Promise.all([${imports.join(", ")}]);
|
|
6872
|
+
`);
|
|
6873
|
+
} else if (declarations.length === 1) {
|
|
6874
|
+
output.insertLeft(0, `const ${specifiers[0]} = await ${imports[0]};
|
|
6875
|
+
`);
|
|
6876
|
+
}
|
|
6877
|
+
}
|
|
6878
|
+
__name(rewriteImportDeclarations, "rewriteImportDeclarations");
|
|
6879
|
+
function renderImport(source, node, input) {
|
|
6880
|
+
const names = node.specifiers.filter(isNamedSpecifier).map(getImportedName);
|
|
6881
|
+
return `import(${source}${node.attributes.length > 0 ? `, {with: {${input.slice(node.attributes[0].start, node.attributes[node.attributes.length - 1].end)}}}` : ""})${names.length > 0 ? `.then((module) => {${names.map((name) => `
|
|
6882
|
+
if (!("${name}" in module)) throw new SyntaxError(\`export '${name}' not found\`);`).join("")}
|
|
6883
|
+
return module;
|
|
6884
|
+
})` : ""}`;
|
|
6885
|
+
}
|
|
6886
|
+
__name(renderImport, "renderImport");
|
|
6887
|
+
function getLocalName(node) {
|
|
6888
|
+
return node.local.name;
|
|
6889
|
+
}
|
|
6890
|
+
__name(getLocalName, "getLocalName");
|
|
6891
|
+
function getImportedName(node) {
|
|
6892
|
+
return node.type === "ImportDefaultSpecifier" ? "default" : node.imported.type === "Identifier" ? node.imported.name : node.imported.raw;
|
|
6893
|
+
}
|
|
6894
|
+
__name(getImportedName, "getImportedName");
|
|
6895
|
+
function isLocalImport(source) {
|
|
6896
|
+
return ["./", "../", "/"].some((prefix) => source.startsWith(prefix));
|
|
6897
|
+
}
|
|
6898
|
+
__name(isLocalImport, "isLocalImport");
|
|
6899
|
+
function isNamespaceSpecifier(node) {
|
|
6900
|
+
return node.type === "ImportNamespaceSpecifier";
|
|
6901
|
+
}
|
|
6902
|
+
__name(isNamespaceSpecifier, "isNamespaceSpecifier");
|
|
6903
|
+
function isNamedSpecifier(node) {
|
|
6904
|
+
return node.type !== "ImportNamespaceSpecifier";
|
|
6905
|
+
}
|
|
6906
|
+
__name(isNamedSpecifier, "isNamedSpecifier");
|
|
6907
|
+
function rewriteImportSpecifiers(node) {
|
|
6908
|
+
return node.specifiers.some(isNamedSpecifier) ? `{${node.specifiers.filter(isNamedSpecifier).map(rewriteImportSpecifier).join(", ")}}` : node.specifiers.find(isNamespaceSpecifier)?.local.name ?? "{}";
|
|
6909
|
+
}
|
|
6910
|
+
__name(rewriteImportSpecifiers, "rewriteImportSpecifiers");
|
|
6911
|
+
function rewriteImportSpecifier(node) {
|
|
6912
|
+
return getImportedName(node) === getLocalName(node) ? getLocalName(node) : `${getImportedName(node)}: ${getLocalName(node)}`;
|
|
6913
|
+
}
|
|
6914
|
+
__name(rewriteImportSpecifier, "rewriteImportSpecifier");
|
|
6915
|
+
const defaultGlobals = /* @__PURE__ */ new Set([
|
|
6916
|
+
"Array",
|
|
6917
|
+
"ArrayBuffer",
|
|
6918
|
+
"atob",
|
|
6919
|
+
"AudioContext",
|
|
6920
|
+
"Blob",
|
|
6921
|
+
"Boolean",
|
|
6922
|
+
"BigInt",
|
|
6923
|
+
"btoa",
|
|
6924
|
+
"clearInterval",
|
|
6925
|
+
"clearTimeout",
|
|
6926
|
+
"console",
|
|
6927
|
+
"crypto",
|
|
6928
|
+
"CustomEvent",
|
|
6929
|
+
"DataView",
|
|
6930
|
+
"Date",
|
|
6931
|
+
"decodeURI",
|
|
6932
|
+
"decodeURIComponent",
|
|
6933
|
+
"devicePixelRatio",
|
|
6934
|
+
"document",
|
|
6935
|
+
"encodeURI",
|
|
6936
|
+
"encodeURIComponent",
|
|
6937
|
+
"Error",
|
|
6938
|
+
"escape",
|
|
6939
|
+
"eval",
|
|
6940
|
+
"fetch",
|
|
6941
|
+
"File",
|
|
6942
|
+
"FileList",
|
|
6943
|
+
"FileReader",
|
|
6944
|
+
"Float32Array",
|
|
6945
|
+
"Float64Array",
|
|
6946
|
+
"Function",
|
|
6947
|
+
"Headers",
|
|
6948
|
+
"Image",
|
|
6949
|
+
"ImageData",
|
|
6950
|
+
"Infinity",
|
|
6951
|
+
"Int16Array",
|
|
6952
|
+
"Int32Array",
|
|
6953
|
+
"Int8Array",
|
|
6954
|
+
"Intl",
|
|
6955
|
+
"isFinite",
|
|
6956
|
+
"isNaN",
|
|
6957
|
+
"JSON",
|
|
6958
|
+
"Map",
|
|
6959
|
+
"Math",
|
|
6960
|
+
"NaN",
|
|
6961
|
+
"Number",
|
|
6962
|
+
"navigator",
|
|
6963
|
+
"Object",
|
|
6964
|
+
"observable",
|
|
6965
|
+
// for observable.params.foo
|
|
6966
|
+
"parseFloat",
|
|
6967
|
+
"parseInt",
|
|
6968
|
+
"performance",
|
|
6969
|
+
"Path2D",
|
|
6970
|
+
"Promise",
|
|
6971
|
+
"Proxy",
|
|
6972
|
+
"RangeError",
|
|
6973
|
+
"ReferenceError",
|
|
6974
|
+
"Reflect",
|
|
6975
|
+
"RegExp",
|
|
6976
|
+
"cancelAnimationFrame",
|
|
6977
|
+
"requestAnimationFrame",
|
|
6978
|
+
"Set",
|
|
6979
|
+
"setInterval",
|
|
6980
|
+
"setTimeout",
|
|
6981
|
+
"String",
|
|
6982
|
+
"Symbol",
|
|
6983
|
+
"SyntaxError",
|
|
6984
|
+
"TextDecoder",
|
|
6985
|
+
"TextEncoder",
|
|
6986
|
+
"this",
|
|
6987
|
+
"TypeError",
|
|
6988
|
+
"Uint16Array",
|
|
6989
|
+
"Uint32Array",
|
|
6990
|
+
"Uint8Array",
|
|
6991
|
+
"Uint8ClampedArray",
|
|
6992
|
+
"undefined",
|
|
6993
|
+
"unescape",
|
|
6994
|
+
"URIError",
|
|
6995
|
+
"URL",
|
|
6996
|
+
"WeakMap",
|
|
6997
|
+
"WeakSet",
|
|
6998
|
+
"WebSocket",
|
|
6999
|
+
"Worker",
|
|
7000
|
+
"window"
|
|
7001
|
+
]);
|
|
7002
|
+
function isScope(node) {
|
|
7003
|
+
return node.type === "FunctionExpression" || node.type === "FunctionDeclaration" || node.type === "ArrowFunctionExpression" || node.type === "Program";
|
|
7004
|
+
}
|
|
7005
|
+
__name(isScope, "isScope");
|
|
7006
|
+
function isBlockScope(node) {
|
|
7007
|
+
return node.type === "BlockStatement" || node.type === "SwitchStatement" || node.type === "ForInStatement" || node.type === "ForOfStatement" || node.type === "ForStatement" || isScope(node);
|
|
7008
|
+
}
|
|
7009
|
+
__name(isBlockScope, "isBlockScope");
|
|
7010
|
+
function findReferences(node, { globals = defaultGlobals, filterReference = /* @__PURE__ */ __name((identifier) => !globals.has(identifier.name), "filterReference"), filterDeclaration = /* @__PURE__ */ __name(() => true, "filterDeclaration") } = {}) {
|
|
7011
|
+
const locals = /* @__PURE__ */ new Map();
|
|
7012
|
+
const references = [];
|
|
7013
|
+
function hasLocal(node2, name) {
|
|
7014
|
+
const l = locals.get(node2);
|
|
7015
|
+
return l ? l.has(name) : false;
|
|
7016
|
+
}
|
|
7017
|
+
__name(hasLocal, "hasLocal");
|
|
7018
|
+
function declareLocal(node2, id) {
|
|
7019
|
+
if (!filterDeclaration(id))
|
|
7020
|
+
return;
|
|
7021
|
+
const l = locals.get(node2);
|
|
7022
|
+
if (l)
|
|
7023
|
+
l.add(id.name);
|
|
7024
|
+
else
|
|
7025
|
+
locals.set(node2, /* @__PURE__ */ new Set([id.name]));
|
|
7026
|
+
}
|
|
7027
|
+
__name(declareLocal, "declareLocal");
|
|
7028
|
+
function declareClass(node2) {
|
|
7029
|
+
if (node2.id)
|
|
7030
|
+
declareLocal(node2, node2.id);
|
|
7031
|
+
}
|
|
7032
|
+
__name(declareClass, "declareClass");
|
|
7033
|
+
function declareFunction(node2) {
|
|
7034
|
+
node2.params.forEach((param) => declarePattern(param, node2));
|
|
7035
|
+
if (node2.id)
|
|
7036
|
+
declareLocal(node2, node2.id);
|
|
7037
|
+
if (node2.type !== "ArrowFunctionExpression")
|
|
7038
|
+
declareLocal(node2, { name: "arguments" });
|
|
7039
|
+
}
|
|
7040
|
+
__name(declareFunction, "declareFunction");
|
|
7041
|
+
function declareCatchClause(node2) {
|
|
7042
|
+
if (node2.param)
|
|
7043
|
+
declarePattern(node2.param, node2);
|
|
7044
|
+
}
|
|
7045
|
+
__name(declareCatchClause, "declareCatchClause");
|
|
7046
|
+
function declarePattern(node2, parent) {
|
|
7047
|
+
switch (node2.type) {
|
|
7048
|
+
case "Identifier":
|
|
7049
|
+
declareLocal(parent, node2);
|
|
7050
|
+
break;
|
|
7051
|
+
case "ObjectPattern":
|
|
7052
|
+
node2.properties.forEach((node3) => declarePattern(node3.type === "Property" ? node3.value : node3, parent));
|
|
7053
|
+
break;
|
|
7054
|
+
case "ArrayPattern":
|
|
7055
|
+
node2.elements.forEach((node3) => node3 && declarePattern(node3, parent));
|
|
7056
|
+
break;
|
|
7057
|
+
case "RestElement":
|
|
7058
|
+
declarePattern(node2.argument, parent);
|
|
7059
|
+
break;
|
|
7060
|
+
case "AssignmentPattern":
|
|
7061
|
+
declarePattern(node2.left, parent);
|
|
7062
|
+
break;
|
|
7063
|
+
}
|
|
7064
|
+
}
|
|
7065
|
+
__name(declarePattern, "declarePattern");
|
|
7066
|
+
ancestor(node, {
|
|
7067
|
+
VariableDeclaration(node2, _state, parents) {
|
|
7068
|
+
let parent = null;
|
|
7069
|
+
for (let i = parents.length - 1; i >= 0 && parent === null; --i) {
|
|
7070
|
+
if (node2.kind === "var" ? isScope(parents[i]) : isBlockScope(parents[i])) {
|
|
7071
|
+
parent = parents[i];
|
|
7072
|
+
}
|
|
7073
|
+
}
|
|
7074
|
+
node2.declarations.forEach((declaration) => declarePattern(declaration.id, parent));
|
|
7075
|
+
},
|
|
7076
|
+
FunctionDeclaration(node2, _state, parents) {
|
|
7077
|
+
let parent = null;
|
|
7078
|
+
for (let i = parents.length - 2; i >= 0 && parent === null; --i) {
|
|
7079
|
+
if (isScope(parents[i])) {
|
|
7080
|
+
parent = parents[i];
|
|
7081
|
+
}
|
|
7082
|
+
}
|
|
7083
|
+
if (node2.id)
|
|
7084
|
+
declareLocal(parent, node2.id);
|
|
7085
|
+
declareFunction(node2);
|
|
7086
|
+
},
|
|
7087
|
+
FunctionExpression: declareFunction,
|
|
7088
|
+
ArrowFunctionExpression: declareFunction,
|
|
7089
|
+
ClassDeclaration(node2, _state, parents) {
|
|
7090
|
+
let parent = null;
|
|
7091
|
+
for (let i = parents.length - 2; i >= 0 && parent === null; --i) {
|
|
7092
|
+
if (isScope(parents[i])) {
|
|
7093
|
+
parent = parents[i];
|
|
7094
|
+
}
|
|
7095
|
+
}
|
|
7096
|
+
if (node2.id)
|
|
7097
|
+
declareLocal(parent, node2.id);
|
|
7098
|
+
},
|
|
7099
|
+
ClassExpression: declareClass,
|
|
7100
|
+
CatchClause: declareCatchClause,
|
|
7101
|
+
ImportDeclaration(node2, _state, [root]) {
|
|
7102
|
+
node2.specifiers.forEach((specifier) => declareLocal(root, specifier.local));
|
|
7103
|
+
}
|
|
7104
|
+
});
|
|
7105
|
+
function identifier(node2, _state, parents) {
|
|
7106
|
+
const name = node2.name;
|
|
7107
|
+
if (name === "undefined")
|
|
7108
|
+
return;
|
|
7109
|
+
for (let i = parents.length - 2; i >= 0; --i) {
|
|
7110
|
+
if (hasLocal(parents[i], name)) {
|
|
7111
|
+
return;
|
|
7112
|
+
}
|
|
7113
|
+
}
|
|
7114
|
+
if (filterReference(node2)) {
|
|
7115
|
+
references.push(node2);
|
|
7116
|
+
}
|
|
7117
|
+
}
|
|
7118
|
+
__name(identifier, "identifier");
|
|
7119
|
+
ancestor(node, {
|
|
7120
|
+
Pattern(node2, _state, parents) {
|
|
7121
|
+
if (node2.type === "Identifier") {
|
|
7122
|
+
identifier(node2, _state, parents);
|
|
7123
|
+
}
|
|
7124
|
+
},
|
|
7125
|
+
Identifier: identifier
|
|
7126
|
+
});
|
|
7127
|
+
return references;
|
|
7128
|
+
}
|
|
7129
|
+
__name(findReferences, "findReferences");
|
|
7130
|
+
function checkAssignments(node, references, input) {
|
|
7131
|
+
function checkConst(node2) {
|
|
7132
|
+
switch (node2.type) {
|
|
7133
|
+
case "Identifier":
|
|
7134
|
+
if (references.includes(node2))
|
|
7135
|
+
throw syntaxError(`Assignment to external variable '${node2.name}'`, node2, input);
|
|
7136
|
+
if (defaultGlobals.has(node2.name))
|
|
7137
|
+
throw syntaxError(`Assignment to global '${node2.name}'`, node2, input);
|
|
7138
|
+
break;
|
|
7139
|
+
case "ObjectPattern":
|
|
7140
|
+
node2.properties.forEach((node3) => checkConst(node3.type === "Property" ? node3.value : node3));
|
|
7141
|
+
break;
|
|
7142
|
+
case "ArrayPattern":
|
|
7143
|
+
node2.elements.forEach((node3) => node3 && checkConst(node3));
|
|
7144
|
+
break;
|
|
7145
|
+
case "RestElement":
|
|
7146
|
+
checkConst(node2.argument);
|
|
7147
|
+
break;
|
|
7148
|
+
}
|
|
7149
|
+
}
|
|
7150
|
+
__name(checkConst, "checkConst");
|
|
7151
|
+
function checkConstLeft({ left }) {
|
|
7152
|
+
checkConst(left);
|
|
7153
|
+
}
|
|
7154
|
+
__name(checkConstLeft, "checkConstLeft");
|
|
7155
|
+
function checkConstArgument({ argument }) {
|
|
7156
|
+
checkConst(argument);
|
|
7157
|
+
}
|
|
7158
|
+
__name(checkConstArgument, "checkConstArgument");
|
|
7159
|
+
simple(node, {
|
|
7160
|
+
AssignmentExpression: checkConstLeft,
|
|
7161
|
+
AssignmentPattern: checkConstLeft,
|
|
7162
|
+
UpdateExpression: checkConstArgument,
|
|
7163
|
+
ForOfStatement: checkConstLeft,
|
|
7164
|
+
ForInStatement: checkConstLeft
|
|
7165
|
+
});
|
|
7166
|
+
}
|
|
7167
|
+
__name(checkAssignments, "checkAssignments");
|
|
7168
|
+
function findDeclarations(node, input) {
|
|
7169
|
+
const declarations = [];
|
|
7170
|
+
function declareLocal(node2) {
|
|
7171
|
+
if (defaultGlobals.has(node2.name) || node2.name === "arguments") {
|
|
7172
|
+
throw syntaxError(`Global '${node2.name}' cannot be redefined`, node2, input);
|
|
7173
|
+
}
|
|
7174
|
+
declarations.push(node2);
|
|
7175
|
+
}
|
|
7176
|
+
__name(declareLocal, "declareLocal");
|
|
7177
|
+
function declarePattern(node2) {
|
|
7178
|
+
switch (node2.type) {
|
|
7179
|
+
case "Identifier":
|
|
7180
|
+
declareLocal(node2);
|
|
7181
|
+
break;
|
|
7182
|
+
case "ObjectPattern":
|
|
7183
|
+
node2.properties.forEach((node3) => declarePattern(node3.type === "Property" ? node3.value : node3));
|
|
7184
|
+
break;
|
|
7185
|
+
case "ArrayPattern":
|
|
7186
|
+
node2.elements.forEach((node3) => node3 && declarePattern(node3));
|
|
7187
|
+
break;
|
|
7188
|
+
case "RestElement":
|
|
7189
|
+
declarePattern(node2.argument);
|
|
7190
|
+
break;
|
|
7191
|
+
case "AssignmentPattern":
|
|
7192
|
+
declarePattern(node2.left);
|
|
7193
|
+
break;
|
|
7194
|
+
}
|
|
7195
|
+
}
|
|
7196
|
+
__name(declarePattern, "declarePattern");
|
|
7197
|
+
for (const child of node.body) {
|
|
7198
|
+
switch (child.type) {
|
|
7199
|
+
case "VariableDeclaration":
|
|
7200
|
+
child.declarations.forEach((node2) => declarePattern(node2.id));
|
|
7201
|
+
break;
|
|
7202
|
+
case "ClassDeclaration":
|
|
7203
|
+
case "FunctionDeclaration":
|
|
7204
|
+
declareLocal(child.id);
|
|
7205
|
+
break;
|
|
7206
|
+
case "ImportDeclaration":
|
|
7207
|
+
child.specifiers.forEach((node2) => declareLocal(node2.local));
|
|
7208
|
+
break;
|
|
7209
|
+
}
|
|
7210
|
+
}
|
|
7211
|
+
return declarations;
|
|
7212
|
+
}
|
|
7213
|
+
__name(findDeclarations, "findDeclarations");
|
|
7214
|
+
function findAwaits(node) {
|
|
7215
|
+
const nodes = [];
|
|
7216
|
+
recursive(node, null, {
|
|
7217
|
+
FunctionDeclaration() {
|
|
7218
|
+
},
|
|
7219
|
+
FunctionExpression() {
|
|
7220
|
+
},
|
|
7221
|
+
ArrowFunctionExpression() {
|
|
7222
|
+
},
|
|
7223
|
+
ForOfStatement(node2, state, callback) {
|
|
7224
|
+
if (node2.await)
|
|
7225
|
+
nodes.push(node2);
|
|
7226
|
+
if (node2.left)
|
|
7227
|
+
callback(node2.left, state);
|
|
7228
|
+
if (node2.right)
|
|
7229
|
+
callback(node2.right, state);
|
|
7230
|
+
if (node2.body)
|
|
7231
|
+
callback(node2.body, state);
|
|
7232
|
+
},
|
|
7233
|
+
AwaitExpression(node2) {
|
|
7234
|
+
nodes.push(node2);
|
|
7235
|
+
}
|
|
7236
|
+
});
|
|
7237
|
+
return nodes;
|
|
7238
|
+
}
|
|
7239
|
+
__name(findAwaits, "findAwaits");
|
|
7240
|
+
const acornOptions = {
|
|
7241
|
+
ecmaVersion: "latest",
|
|
7242
|
+
sourceType: "module"
|
|
7243
|
+
};
|
|
7244
|
+
function parseJavaScript(input) {
|
|
7245
|
+
let expression = maybeParseExpression(input);
|
|
7246
|
+
if (expression?.type === "ClassExpression" && expression.id)
|
|
7247
|
+
expression = null;
|
|
7248
|
+
if (expression?.type === "FunctionExpression" && expression.id)
|
|
7249
|
+
expression = null;
|
|
7250
|
+
const body = expression ?? parseProgram(input);
|
|
7251
|
+
checkExports(body, input);
|
|
7252
|
+
const references = findReferences(body);
|
|
7253
|
+
checkAssignments(body, references, input);
|
|
7254
|
+
return {
|
|
7255
|
+
body,
|
|
7256
|
+
declarations: expression ? null : findDeclarations(body, input),
|
|
7257
|
+
references,
|
|
7258
|
+
expression: !!expression,
|
|
7259
|
+
async: findAwaits(body).length > 0
|
|
7260
|
+
};
|
|
7261
|
+
}
|
|
7262
|
+
__name(parseJavaScript, "parseJavaScript");
|
|
7263
|
+
function parseProgram(input) {
|
|
7264
|
+
return Parser.parse(input, acornOptions);
|
|
7265
|
+
}
|
|
7266
|
+
__name(parseProgram, "parseProgram");
|
|
7267
|
+
function maybeParseExpression(input) {
|
|
7268
|
+
const parser = new Parser(acornOptions, input, 0);
|
|
7269
|
+
parser.nextToken();
|
|
7270
|
+
try {
|
|
7271
|
+
const node = parser.parseExpression();
|
|
7272
|
+
return parser.type === types$1.eof ? node : null;
|
|
7273
|
+
} catch {
|
|
7274
|
+
return null;
|
|
7275
|
+
}
|
|
7276
|
+
}
|
|
7277
|
+
__name(maybeParseExpression, "maybeParseExpression");
|
|
7278
|
+
const _Sourcemap = class _Sourcemap {
|
|
7279
|
+
constructor(input) {
|
|
7280
|
+
Object.defineProperty(this, "input", {
|
|
7281
|
+
enumerable: true,
|
|
7282
|
+
configurable: true,
|
|
7283
|
+
writable: true,
|
|
7284
|
+
value: void 0
|
|
7285
|
+
});
|
|
7286
|
+
Object.defineProperty(this, "_edits", {
|
|
7287
|
+
enumerable: true,
|
|
7288
|
+
configurable: true,
|
|
7289
|
+
writable: true,
|
|
7290
|
+
value: void 0
|
|
7291
|
+
});
|
|
7292
|
+
this.input = input;
|
|
7293
|
+
this._edits = [];
|
|
7294
|
+
}
|
|
7295
|
+
_bisectLeft(index) {
|
|
7296
|
+
let lo = 0;
|
|
7297
|
+
let hi = this._edits.length;
|
|
7298
|
+
while (lo < hi) {
|
|
7299
|
+
const mid = lo + hi >>> 1;
|
|
7300
|
+
if (this._edits[mid].start < index)
|
|
7301
|
+
lo = mid + 1;
|
|
7302
|
+
else
|
|
7303
|
+
hi = mid;
|
|
7304
|
+
}
|
|
7305
|
+
return lo;
|
|
7306
|
+
}
|
|
7307
|
+
_bisectRight(index) {
|
|
7308
|
+
let lo = 0;
|
|
7309
|
+
let hi = this._edits.length;
|
|
7310
|
+
while (lo < hi) {
|
|
7311
|
+
const mid = lo + hi >>> 1;
|
|
7312
|
+
if (this._edits[mid].start > index)
|
|
7313
|
+
hi = mid;
|
|
7314
|
+
else
|
|
7315
|
+
lo = mid + 1;
|
|
7316
|
+
}
|
|
7317
|
+
return lo;
|
|
7318
|
+
}
|
|
7319
|
+
_subsume(start, end) {
|
|
7320
|
+
let n = 0;
|
|
7321
|
+
for (let i = 0; i < this._edits.length; ++i) {
|
|
7322
|
+
const e = this._edits[i];
|
|
7323
|
+
if (start <= e.start && e.end < end)
|
|
7324
|
+
continue;
|
|
7325
|
+
this._edits[n++] = e;
|
|
7326
|
+
}
|
|
7327
|
+
this._edits.length = n;
|
|
7328
|
+
}
|
|
7329
|
+
insertLeft(index, value) {
|
|
7330
|
+
return this.replaceLeft(index, index, value);
|
|
7331
|
+
}
|
|
7332
|
+
insertRight(index, value) {
|
|
7333
|
+
return this.replaceRight(index, index, value);
|
|
7334
|
+
}
|
|
7335
|
+
delete(start, end) {
|
|
7336
|
+
return this.replaceRight(start, end, "");
|
|
7337
|
+
}
|
|
7338
|
+
replaceLeft(start, end, value) {
|
|
7339
|
+
this._subsume(start, end);
|
|
7340
|
+
this._edits.splice(this._bisectLeft(start), 0, { start, end, value });
|
|
7341
|
+
return this;
|
|
7342
|
+
}
|
|
7343
|
+
replaceRight(start, end, value) {
|
|
7344
|
+
this._subsume(start, end);
|
|
7345
|
+
this._edits.splice(this._bisectRight(start), 0, { start, end, value });
|
|
7346
|
+
return this;
|
|
7347
|
+
}
|
|
7348
|
+
translate(position) {
|
|
7349
|
+
let index = 0;
|
|
7350
|
+
let ci = { line: 1, column: 0 };
|
|
7351
|
+
let co = { line: 1, column: 0 };
|
|
7352
|
+
for (const { start, end, value } of this._edits) {
|
|
7353
|
+
if (start > index) {
|
|
7354
|
+
const l2 = positionLength(this.input, index, start);
|
|
7355
|
+
const ci22 = positionAdd(ci, l2);
|
|
7356
|
+
const co22 = positionAdd(co, l2);
|
|
7357
|
+
if (positionCompare(co22, position) > 0)
|
|
7358
|
+
break;
|
|
7359
|
+
ci = ci22;
|
|
7360
|
+
co = co22;
|
|
7361
|
+
}
|
|
7362
|
+
const il = positionLength(this.input, start, end);
|
|
7363
|
+
const ol = positionLength(value);
|
|
7364
|
+
const ci2 = positionAdd(ci, il);
|
|
7365
|
+
const co2 = positionAdd(co, ol);
|
|
7366
|
+
if (positionCompare(co2, position) > 0)
|
|
7367
|
+
return ci;
|
|
7368
|
+
ci = ci2;
|
|
7369
|
+
co = co2;
|
|
7370
|
+
index = end;
|
|
7371
|
+
}
|
|
7372
|
+
const l = positionSubtract(position, co);
|
|
7373
|
+
return positionAdd(ci, l);
|
|
7374
|
+
}
|
|
7375
|
+
trim() {
|
|
7376
|
+
const input = this.input;
|
|
7377
|
+
if (input.startsWith("\n"))
|
|
7378
|
+
this.delete(0, 1);
|
|
7379
|
+
if (input.endsWith("\n"))
|
|
7380
|
+
this.delete(input.length - 1, input.length);
|
|
7381
|
+
return this;
|
|
7382
|
+
}
|
|
7383
|
+
toString() {
|
|
7384
|
+
let output = "";
|
|
7385
|
+
let index = 0;
|
|
7386
|
+
for (const { start, end, value } of this._edits) {
|
|
7387
|
+
if (start > index)
|
|
7388
|
+
output += this.input.slice(index, start);
|
|
7389
|
+
output += value;
|
|
7390
|
+
index = end;
|
|
7391
|
+
}
|
|
7392
|
+
output += this.input.slice(index);
|
|
7393
|
+
return output;
|
|
7394
|
+
}
|
|
7395
|
+
};
|
|
7396
|
+
__name(_Sourcemap, "Sourcemap");
|
|
7397
|
+
let Sourcemap = _Sourcemap;
|
|
7398
|
+
function positionCompare(a, b) {
|
|
7399
|
+
return a.line - b.line || a.column - b.column;
|
|
7400
|
+
}
|
|
7401
|
+
__name(positionCompare, "positionCompare");
|
|
7402
|
+
function positionLength(input, start = 0, end = input.length) {
|
|
7403
|
+
let match;
|
|
7404
|
+
let line = 0;
|
|
7405
|
+
lineBreakG.lastIndex = start;
|
|
7406
|
+
while ((match = lineBreakG.exec(input)) && match.index < end) {
|
|
7407
|
+
++line;
|
|
7408
|
+
start = match.index + match[0].length;
|
|
7409
|
+
}
|
|
7410
|
+
return { line, column: end - start };
|
|
7411
|
+
}
|
|
7412
|
+
__name(positionLength, "positionLength");
|
|
7413
|
+
function positionSubtract(b, a) {
|
|
7414
|
+
return b.line === a.line ? { line: 0, column: b.column - a.column } : { line: b.line - a.line, column: b.column };
|
|
7415
|
+
}
|
|
7416
|
+
__name(positionSubtract, "positionSubtract");
|
|
7417
|
+
function positionAdd(p, l) {
|
|
7418
|
+
return l.line === 0 ? { line: p.line, column: p.column + l.column } : { line: p.line + l.line, column: l.column };
|
|
7419
|
+
}
|
|
7420
|
+
__name(positionAdd, "positionAdd");
|
|
7421
|
+
const CODE_DOLLAR = 36;
|
|
7422
|
+
const CODE_BACKSLASH = 92;
|
|
7423
|
+
const CODE_BACKTICK = 96;
|
|
7424
|
+
const CODE_BRACEL = 123;
|
|
7425
|
+
const o_tmpl = new TokContext(
|
|
7426
|
+
"`",
|
|
7427
|
+
// token
|
|
7428
|
+
true,
|
|
7429
|
+
// isExpr
|
|
7430
|
+
true,
|
|
7431
|
+
// preserveSpace
|
|
7432
|
+
(parser) => parser.readTemplateToken()
|
|
7433
|
+
// override
|
|
7434
|
+
);
|
|
7435
|
+
const _TemplateCellParser = class _TemplateCellParser extends Parser {
|
|
7436
|
+
constructor(options, input, startPos) {
|
|
7437
|
+
super(options, input, startPos);
|
|
7438
|
+
this.type = types$1.backQuote;
|
|
7439
|
+
this.exprAllowed = false;
|
|
7440
|
+
}
|
|
7441
|
+
initialContext() {
|
|
7442
|
+
return [o_tmpl];
|
|
7443
|
+
}
|
|
7444
|
+
parseTopLevel(node) {
|
|
7445
|
+
if (this.type === types$1.eof)
|
|
7446
|
+
this.value = "";
|
|
7447
|
+
const isTagged = true;
|
|
7448
|
+
const template = node;
|
|
7449
|
+
template.expressions = [];
|
|
7450
|
+
let curElt = this.parseTemplateElement({ isTagged });
|
|
7451
|
+
template.quasis = [curElt];
|
|
7452
|
+
while (this.type !== types$1.eof) {
|
|
7453
|
+
this.expect(types$1.dollarBraceL);
|
|
7454
|
+
template.expressions.push(this.parseExpression());
|
|
7455
|
+
this.expect(types$1.braceR);
|
|
7456
|
+
template.quasis.push(curElt = this.parseTemplateElement({ isTagged }));
|
|
7457
|
+
}
|
|
7458
|
+
curElt.tail = true;
|
|
7459
|
+
this.next();
|
|
7460
|
+
this.finishNode(template, "TemplateLiteral");
|
|
7461
|
+
this.expect(types$1.eof);
|
|
7462
|
+
return template;
|
|
7463
|
+
}
|
|
7464
|
+
readTemplateToken() {
|
|
7465
|
+
out: for (; this.pos < this.input.length; this.pos++) {
|
|
7466
|
+
switch (this.input.charCodeAt(this.pos)) {
|
|
7467
|
+
case CODE_BACKSLASH: {
|
|
7468
|
+
if (this.pos < this.input.length - 1)
|
|
7469
|
+
++this.pos;
|
|
7470
|
+
break;
|
|
7471
|
+
}
|
|
7472
|
+
case CODE_DOLLAR: {
|
|
7473
|
+
if (this.input.charCodeAt(this.pos + 1) === CODE_BRACEL) {
|
|
7474
|
+
if (this.pos === this.start && this.type === types$1.invalidTemplate) {
|
|
7475
|
+
this.pos += 2;
|
|
7476
|
+
return this.finishToken(types$1.dollarBraceL);
|
|
7477
|
+
}
|
|
7478
|
+
break out;
|
|
7479
|
+
}
|
|
7480
|
+
break;
|
|
7481
|
+
}
|
|
7482
|
+
}
|
|
7483
|
+
}
|
|
7484
|
+
return this.finishToken(types$1.invalidTemplate, this.input.slice(this.start, this.pos));
|
|
7485
|
+
}
|
|
7486
|
+
};
|
|
7487
|
+
__name(_TemplateCellParser, "TemplateCellParser");
|
|
7488
|
+
let TemplateCellParser = _TemplateCellParser;
|
|
7489
|
+
function parseTemplate(input) {
|
|
7490
|
+
return TemplateCellParser.parse(input, acornOptions);
|
|
7491
|
+
}
|
|
7492
|
+
__name(parseTemplate, "parseTemplate");
|
|
7493
|
+
function transpileTemplate(input, tag = "", raw = false) {
|
|
7494
|
+
let cell;
|
|
7495
|
+
if (typeof input !== "string") {
|
|
7496
|
+
cell = input;
|
|
7497
|
+
input = cell.value;
|
|
7498
|
+
tag = cell.mode === "tex" ? "tex.block" : cell.mode === "sql" ? getSqlTag(cell) : cell.mode;
|
|
7499
|
+
raw = cell.mode !== "md";
|
|
7500
|
+
}
|
|
7501
|
+
if (!input)
|
|
7502
|
+
return input;
|
|
7503
|
+
const source = new Sourcemap(input);
|
|
7504
|
+
const node = parseTemplate(input);
|
|
7505
|
+
(raw ? escapeRawTemplateElements : escapeTemplateElements)(source, node);
|
|
7506
|
+
source.insertLeft(node.start, "`");
|
|
7507
|
+
source.insertRight(node.end, "`");
|
|
7508
|
+
source.insertLeft(node.start, tag);
|
|
7509
|
+
let output = String(source);
|
|
7510
|
+
if (cell?.mode === "sql" && !cell.hidden)
|
|
7511
|
+
output += ".then(Inputs.table)";
|
|
7512
|
+
return output;
|
|
7513
|
+
}
|
|
7514
|
+
__name(transpileTemplate, "transpileTemplate");
|
|
7515
|
+
function getSqlTag(cell) {
|
|
7516
|
+
const { id, database = "var:db", since } = cell;
|
|
7517
|
+
return database.startsWith("var:") ? `${database.slice("var:".length)}.sql` : `DatabaseClient(${JSON.stringify(database)}, {id: ${id}${since === void 0 ? "" : `, since: ${JSON.stringify(since)}`}}).sql`;
|
|
7518
|
+
}
|
|
7519
|
+
__name(getSqlTag, "getSqlTag");
|
|
7520
|
+
function escapeTemplateElements(source, node) {
|
|
7521
|
+
for (const quasi of node.quasis) {
|
|
7522
|
+
escapeBacktick(source, quasi);
|
|
7523
|
+
escapeBackslash(source, quasi);
|
|
7524
|
+
}
|
|
7525
|
+
}
|
|
7526
|
+
__name(escapeTemplateElements, "escapeTemplateElements");
|
|
7527
|
+
function escapeRawTemplateElements(source, node) {
|
|
7528
|
+
for (const quasi of node.quasis) {
|
|
7529
|
+
escapeBacktick(source, quasi);
|
|
7530
|
+
}
|
|
7531
|
+
interpolateTerminalBackslash(source);
|
|
7532
|
+
}
|
|
7533
|
+
__name(escapeRawTemplateElements, "escapeRawTemplateElements");
|
|
7534
|
+
function escapeBacktick(source, { start, end }) {
|
|
7535
|
+
const { input } = source;
|
|
7536
|
+
for (let i = start; i < end; ++i) {
|
|
7537
|
+
if (input.charCodeAt(i) === CODE_BACKTICK) {
|
|
7538
|
+
source.insertRight(i, "\\");
|
|
7539
|
+
}
|
|
7540
|
+
}
|
|
7541
|
+
}
|
|
7542
|
+
__name(escapeBacktick, "escapeBacktick");
|
|
7543
|
+
function escapeBackslash(source, { start, end }) {
|
|
7544
|
+
const { input } = source;
|
|
7545
|
+
let afterDollar = false;
|
|
7546
|
+
let oddBackslashes = false;
|
|
7547
|
+
for (let i = start; i < end; ++i) {
|
|
7548
|
+
switch (input.charCodeAt(i)) {
|
|
7549
|
+
case CODE_DOLLAR: {
|
|
7550
|
+
afterDollar = true;
|
|
7551
|
+
oddBackslashes = false;
|
|
7552
|
+
break;
|
|
7553
|
+
}
|
|
7554
|
+
case CODE_BACKSLASH: {
|
|
7555
|
+
oddBackslashes = !oddBackslashes;
|
|
7556
|
+
if (afterDollar && input.charCodeAt(i + 1) === CODE_BRACEL)
|
|
7557
|
+
continue;
|
|
7558
|
+
if (oddBackslashes && input.charCodeAt(i + 1) === CODE_DOLLAR && input.charCodeAt(i + 2) === CODE_BRACEL)
|
|
7559
|
+
continue;
|
|
7560
|
+
source.insertRight(i, "\\");
|
|
7561
|
+
break;
|
|
7562
|
+
}
|
|
7563
|
+
default: {
|
|
7564
|
+
afterDollar = false;
|
|
7565
|
+
oddBackslashes = false;
|
|
7566
|
+
break;
|
|
7567
|
+
}
|
|
7568
|
+
}
|
|
7569
|
+
}
|
|
7570
|
+
}
|
|
7571
|
+
__name(escapeBackslash, "escapeBackslash");
|
|
7572
|
+
function interpolateTerminalBackslash(source) {
|
|
7573
|
+
const { input } = source;
|
|
7574
|
+
let oddBackslashes = false;
|
|
7575
|
+
for (let i = input.length - 1; i >= 0; i--) {
|
|
7576
|
+
if (input.charCodeAt(i) !== CODE_BACKSLASH)
|
|
7577
|
+
break;
|
|
7578
|
+
oddBackslashes = !oddBackslashes;
|
|
7579
|
+
}
|
|
7580
|
+
if (oddBackslashes)
|
|
7581
|
+
source.replaceRight(input.length - 1, input.length, "${'\\\\'}");
|
|
7582
|
+
}
|
|
7583
|
+
__name(interpolateTerminalBackslash, "interpolateTerminalBackslash");
|
|
7584
|
+
function toNotebook({ cells = [], title = "Untitled", theme = "air", readOnly = false }) {
|
|
7585
|
+
return {
|
|
7586
|
+
cells: cells.map(toCell),
|
|
7587
|
+
title,
|
|
7588
|
+
theme,
|
|
7589
|
+
readOnly
|
|
7590
|
+
};
|
|
7591
|
+
}
|
|
7592
|
+
__name(toNotebook, "toNotebook");
|
|
7593
|
+
function toCell({ id, value = "", mode = "js", pinned = defaultPinned(mode), hidden = false, output, database = mode === "sql" ? "var:db" : void 0, since }) {
|
|
7594
|
+
return {
|
|
7595
|
+
id,
|
|
7596
|
+
value,
|
|
7597
|
+
mode,
|
|
7598
|
+
pinned,
|
|
7599
|
+
hidden,
|
|
7600
|
+
output,
|
|
7601
|
+
database: mode === "sql" ? database : void 0,
|
|
7602
|
+
since: since !== void 0 ? asDate(since) : void 0
|
|
7603
|
+
};
|
|
7604
|
+
}
|
|
7605
|
+
__name(toCell, "toCell");
|
|
7606
|
+
function asDate(date) {
|
|
7607
|
+
return date instanceof Date ? date : new Date(date);
|
|
7608
|
+
}
|
|
7609
|
+
__name(asDate, "asDate");
|
|
7610
|
+
function defaultPinned(mode) {
|
|
7611
|
+
return mode === "js" || mode === "sql" || mode === "ojs";
|
|
7612
|
+
}
|
|
7613
|
+
__name(defaultPinned, "defaultPinned");
|
|
7614
|
+
function rewriteFileExpressions(output, body) {
|
|
7615
|
+
const files = new Set(findReferences(body, { filterReference: /* @__PURE__ */ __name(({ name }) => name === "FileAttachment", "filterReference") }));
|
|
7616
|
+
simple(body, {
|
|
7617
|
+
CallExpression(node) {
|
|
7618
|
+
const { callee } = node;
|
|
7619
|
+
if (callee.type !== "Identifier" || !files.has(callee))
|
|
7620
|
+
return;
|
|
7621
|
+
const args = node.arguments;
|
|
7622
|
+
if (args.length === 0)
|
|
7623
|
+
return;
|
|
7624
|
+
const [arg] = args;
|
|
7625
|
+
output.insertLeft(arg.start, "new URL(");
|
|
7626
|
+
output.insertRight(arg.end, ", import.meta.url).href");
|
|
7627
|
+
}
|
|
7628
|
+
});
|
|
7629
|
+
}
|
|
7630
|
+
__name(rewriteFileExpressions, "rewriteFileExpressions");
|
|
7631
|
+
function transpileObservable(input, options) {
|
|
7632
|
+
const cell = parseCell$2(input);
|
|
7633
|
+
if (!cell.body)
|
|
7634
|
+
return transpileJavaScript(input);
|
|
7635
|
+
if (cell.tag)
|
|
7636
|
+
throw new Error("tagged ojs cells are not supported");
|
|
7637
|
+
const output = new Sourcemap(input).trim();
|
|
7638
|
+
rewriteSpecialReferences(output, cell.body);
|
|
7639
|
+
if (cell.body.type === "ImportDeclaration") {
|
|
7640
|
+
rewriteImportSource(output, cell.body);
|
|
7641
|
+
return transpileJavaScript(String(output));
|
|
7642
|
+
}
|
|
7643
|
+
if (options?.resolveFiles)
|
|
7644
|
+
rewriteFileExpressions(output, cell.body);
|
|
7645
|
+
const inputs = Array.from(new Set(cell.references.map(asReference)));
|
|
7646
|
+
let start = "";
|
|
7647
|
+
let end = "";
|
|
7648
|
+
start += `${cell.async ? "async " : ""}function${cell.generator ? "*" : ""}`;
|
|
7649
|
+
if (cell.id)
|
|
7650
|
+
start += ` ${asReference(cell.id)}`;
|
|
7651
|
+
start += `(${inputs})`;
|
|
7652
|
+
if (cell.body.type !== "BlockStatement") {
|
|
7653
|
+
start += "{return(";
|
|
7654
|
+
end += ")}";
|
|
7655
|
+
}
|
|
7656
|
+
output.replaceLeft(0, cell.body.start, `${start}
|
|
7657
|
+
`);
|
|
7658
|
+
output.replaceRight(cell.body.end, input.length, `
|
|
7659
|
+
${end}`);
|
|
7660
|
+
return {
|
|
7661
|
+
body: String(output),
|
|
7662
|
+
inputs,
|
|
7663
|
+
output: cell.id ? asDeclaration(cell.id) : void 0,
|
|
7664
|
+
autodisplay: true,
|
|
7665
|
+
automutable: cell.id?.type === "MutableExpression",
|
|
7666
|
+
autoview: cell.id?.type === "ViewExpression"
|
|
7667
|
+
};
|
|
7668
|
+
}
|
|
7669
|
+
__name(transpileObservable, "transpileObservable");
|
|
7670
|
+
function rewriteImportSource(output, body) {
|
|
7671
|
+
const specifier = body.source.value;
|
|
7672
|
+
if (typeof specifier === "string" && !/^\w+:/.test(specifier)) {
|
|
7673
|
+
output.insertLeft(body.source.start + 1, "observable:");
|
|
7674
|
+
}
|
|
7675
|
+
output.insertRight(body.end, ";");
|
|
7676
|
+
}
|
|
7677
|
+
__name(rewriteImportSource, "rewriteImportSource");
|
|
7678
|
+
function rewriteSpecialReferences(output, body) {
|
|
7679
|
+
simple(body, {
|
|
7680
|
+
MutableExpression(node) {
|
|
7681
|
+
output.replaceLeft(node.start, node.end, `${asReference(node)}.value`);
|
|
7682
|
+
},
|
|
7683
|
+
ViewExpression(node) {
|
|
7684
|
+
output.replaceLeft(node.start, node.end, asReference(node));
|
|
7685
|
+
},
|
|
7686
|
+
ImportSpecifier(node) {
|
|
7687
|
+
const inode = node;
|
|
7688
|
+
const prefix = inode.view ? "viewof$" : inode.mutable ? "mutable$" : null;
|
|
7689
|
+
if (prefix) {
|
|
7690
|
+
const imported = asImportName(node.imported);
|
|
7691
|
+
output.replaceLeft(node.start, node.imported.start, prefix);
|
|
7692
|
+
if (node.imported === node.local) {
|
|
7693
|
+
output.insertLeft(node.start, `${imported},`);
|
|
7694
|
+
} else {
|
|
7695
|
+
const local = asImportName(node.local);
|
|
7696
|
+
output.insertLeft(node.start, `${imported} as ${local},`);
|
|
7697
|
+
output.insertLeft(node.local.start, prefix);
|
|
7698
|
+
}
|
|
7699
|
+
}
|
|
7700
|
+
}
|
|
7701
|
+
});
|
|
7702
|
+
}
|
|
7703
|
+
__name(rewriteSpecialReferences, "rewriteSpecialReferences");
|
|
7704
|
+
function asImportName(ref2) {
|
|
7705
|
+
return ref2.type === "Identifier" ? ref2.name : ref2.raw;
|
|
7706
|
+
}
|
|
7707
|
+
__name(asImportName, "asImportName");
|
|
7708
|
+
function asReference(ref2) {
|
|
7709
|
+
return ref2.type === "ViewExpression" ? `viewof$${ref2.id.name}` : ref2.type === "MutableExpression" ? `mutable$${ref2.id.name}` : ref2.name;
|
|
7710
|
+
}
|
|
7711
|
+
__name(asReference, "asReference");
|
|
7712
|
+
function asDeclaration(ref2) {
|
|
7713
|
+
return ref2.type === "ViewExpression" ? `viewof$${ref2.id.name}` : ref2.type === "MutableExpression" ? `mutable ${ref2.id.name}` : ref2.name;
|
|
7714
|
+
}
|
|
7715
|
+
__name(asDeclaration, "asDeclaration");
|
|
7716
|
+
function transpile(input, mode, options) {
|
|
7717
|
+
let cell;
|
|
7718
|
+
if (typeof input === "string") {
|
|
7719
|
+
mode = mode;
|
|
7720
|
+
cell = toCell({ id: -1, value: input, mode });
|
|
7721
|
+
} else {
|
|
7722
|
+
options = mode;
|
|
7723
|
+
mode = input.mode;
|
|
7724
|
+
cell = input;
|
|
7725
|
+
input = cell.value;
|
|
7726
|
+
}
|
|
7727
|
+
const transpiled = mode === "ojs" ? transpileObservable(input, options) : mode !== "js" ? transpileJavaScript(transpileTemplate(cell), options) : transpileJavaScript(input, options);
|
|
7728
|
+
if (transpiled.output === void 0)
|
|
7729
|
+
transpiled.output = cell.output;
|
|
7730
|
+
if (cell.hidden)
|
|
7731
|
+
transpiled.autodisplay = false;
|
|
7732
|
+
else if (mode !== "js" && mode !== "ojs") {
|
|
7733
|
+
transpiled.autodisplay = !!input;
|
|
7734
|
+
transpiled.autoview = mode === "sql" && transpiled.autodisplay && !!transpiled.output;
|
|
7735
|
+
if (transpiled.autoview)
|
|
7736
|
+
transpiled.output = `viewof$${transpiled.output}`;
|
|
7737
|
+
}
|
|
7738
|
+
return transpiled;
|
|
7739
|
+
}
|
|
7740
|
+
__name(transpile, "transpile");
|
|
7741
|
+
function transpileJavaScript(input, options) {
|
|
7742
|
+
const cell = parseJavaScript(input);
|
|
7743
|
+
let async = cell.async;
|
|
7744
|
+
const inputs = Array.from(new Set(cell.references.map((r) => r.name)));
|
|
7745
|
+
if (hasImportDeclaration(cell.body))
|
|
7746
|
+
async = true;
|
|
7747
|
+
const outputs = Array.from(new Set(cell.declarations?.map((r) => r.name)));
|
|
7748
|
+
const output = new Sourcemap(input).trim();
|
|
7749
|
+
rewriteImportDeclarations(output, cell.body, inputs, options);
|
|
7750
|
+
rewriteImportExpressions(output, cell.body, options);
|
|
7751
|
+
if (options?.resolveFiles)
|
|
7752
|
+
rewriteFileExpressions(output, cell.body);
|
|
7753
|
+
if (cell.expression)
|
|
7754
|
+
output.insertLeft(0, `return (
|
|
7755
|
+
`);
|
|
7756
|
+
output.insertLeft(0, `${async ? "async " : ""}(${inputs}) => {
|
|
7757
|
+
`);
|
|
7758
|
+
if (outputs.length > 0)
|
|
7759
|
+
output.insertRight(input.length, `
|
|
7760
|
+
return {${outputs}};`);
|
|
7761
|
+
if (cell.expression)
|
|
7762
|
+
output.insertRight(input.length, `
|
|
7763
|
+
)`);
|
|
7764
|
+
output.insertRight(input.length, "\n}");
|
|
7765
|
+
const body = String(output);
|
|
7766
|
+
const autodisplay = cell.expression && !(inputs.includes("display") || inputs.includes("view"));
|
|
7767
|
+
return { body, inputs, outputs, autodisplay };
|
|
7768
|
+
}
|
|
7769
|
+
__name(transpileJavaScript, "transpileJavaScript");
|
|
7770
|
+
function isEmpty(text) {
|
|
7771
|
+
return /^\s*$/.test(text);
|
|
7772
|
+
}
|
|
7773
|
+
__name(isEmpty, "isEmpty");
|
|
7774
|
+
function serialize(notebook2, { document = globalThis.document } = {}) {
|
|
7775
|
+
const _notebook = document.createElement("notebook");
|
|
7776
|
+
_notebook.setAttribute("theme", notebook2.theme);
|
|
7777
|
+
if (notebook2.readOnly)
|
|
7778
|
+
_notebook.setAttribute("readonly", "");
|
|
7779
|
+
_notebook.appendChild(document.createTextNode("\n "));
|
|
7780
|
+
const _title = document.createElement("title");
|
|
7781
|
+
_title.textContent = notebook2.title;
|
|
7782
|
+
_notebook.appendChild(_title);
|
|
7783
|
+
for (const cell of notebook2.cells) {
|
|
7784
|
+
_notebook.appendChild(document.createTextNode("\n "));
|
|
7785
|
+
const _cell = document.createElement("script");
|
|
7786
|
+
_cell.id = String(cell.id);
|
|
7787
|
+
_cell.type = serializeMode(cell.mode);
|
|
7788
|
+
_cell.textContent = indent(cell.value.replace(/<(?=\\*\/script(\s|>))/gi, "<\\"));
|
|
7789
|
+
if (cell.pinned)
|
|
7790
|
+
_cell.setAttribute("pinned", "");
|
|
7791
|
+
if (cell.hidden)
|
|
7792
|
+
_cell.setAttribute("hidden", "");
|
|
7793
|
+
if (cell.database)
|
|
7794
|
+
_cell.setAttribute("database", cell.database);
|
|
7795
|
+
if (cell.output)
|
|
7796
|
+
_cell.setAttribute("output", cell.output);
|
|
7797
|
+
_notebook.appendChild(_cell);
|
|
7798
|
+
}
|
|
7799
|
+
_notebook.appendChild(document.createTextNode("\n"));
|
|
7800
|
+
return `<!doctype html>
|
|
7801
|
+
${_notebook.outerHTML}
|
|
7802
|
+
`;
|
|
7803
|
+
}
|
|
7804
|
+
__name(serialize, "serialize");
|
|
7805
|
+
function deserialize(data2, { parser = new DOMParser() } = {}) {
|
|
7806
|
+
const document = parser.parseFromString(data2, "text/html");
|
|
7807
|
+
const _notebook = document.querySelector("notebook");
|
|
7808
|
+
const theme = deserializeTheme(_notebook?.getAttribute("theme"));
|
|
7809
|
+
const readOnly = _notebook?.hasAttribute("readonly");
|
|
7810
|
+
const title = document.querySelector("title")?.textContent ?? void 0;
|
|
7811
|
+
let maxCellId = 0;
|
|
7812
|
+
const cellIds = /* @__PURE__ */ new Set();
|
|
7813
|
+
const cells = Array.from(document.querySelectorAll("notebook script"), (cell) => {
|
|
7814
|
+
let id = Math.floor(Number(cell.id));
|
|
7815
|
+
if (!isFinite(id) || !(id > 0) || cellIds.has(id))
|
|
7816
|
+
id = ++maxCellId;
|
|
7817
|
+
else if (id > maxCellId)
|
|
7818
|
+
maxCellId = id;
|
|
7819
|
+
cellIds.add(id);
|
|
7820
|
+
const mode = deserializeMode(cell.getAttribute("type"));
|
|
7821
|
+
const value = dedent(cell.textContent?.replace(/<\\(?=\\*\/script(\s|>))/gi, "<") ?? "");
|
|
7822
|
+
const pinned = cell.hasAttribute("pinned");
|
|
7823
|
+
const hidden = cell.hasAttribute("hidden");
|
|
7824
|
+
const output = cell.getAttribute("output") ?? void 0;
|
|
7825
|
+
const database = cell.getAttribute("database") ?? void 0;
|
|
7826
|
+
return { id, mode, value, pinned, hidden, output, database };
|
|
7827
|
+
});
|
|
7828
|
+
return toNotebook({ title, theme, readOnly, cells });
|
|
7829
|
+
}
|
|
7830
|
+
__name(deserialize, "deserialize");
|
|
7831
|
+
function serializeMode(mode) {
|
|
7832
|
+
switch (mode) {
|
|
7833
|
+
case "md":
|
|
7834
|
+
return "text/markdown";
|
|
7835
|
+
case "html":
|
|
7836
|
+
return "text/html";
|
|
7837
|
+
case "tex":
|
|
7838
|
+
return "application/x-tex";
|
|
7839
|
+
case "sql":
|
|
7840
|
+
return "application/sql";
|
|
7841
|
+
case "dot":
|
|
7842
|
+
return "text/vnd.graphviz";
|
|
7843
|
+
case "ojs":
|
|
7844
|
+
return "application/vnd.observable.javascript";
|
|
7845
|
+
default:
|
|
7846
|
+
return "module";
|
|
7847
|
+
}
|
|
7848
|
+
}
|
|
7849
|
+
__name(serializeMode, "serializeMode");
|
|
7850
|
+
function deserializeMode(mode) {
|
|
7851
|
+
switch (mode) {
|
|
7852
|
+
case "text/markdown":
|
|
7853
|
+
return "md";
|
|
7854
|
+
case "text/html":
|
|
7855
|
+
return "html";
|
|
7856
|
+
case "application/x-tex":
|
|
7857
|
+
return "tex";
|
|
7858
|
+
case "application/sql":
|
|
7859
|
+
return "sql";
|
|
7860
|
+
case "text/vnd.graphviz":
|
|
7861
|
+
return "dot";
|
|
7862
|
+
case "application/vnd.observable.javascript":
|
|
7863
|
+
return "ojs";
|
|
7864
|
+
default:
|
|
7865
|
+
return "js";
|
|
7866
|
+
}
|
|
7867
|
+
}
|
|
7868
|
+
__name(deserializeMode, "deserializeMode");
|
|
7869
|
+
function deserializeTheme(theme) {
|
|
7870
|
+
return theme ?? "air";
|
|
7871
|
+
}
|
|
7872
|
+
__name(deserializeTheme, "deserializeTheme");
|
|
7873
|
+
function dedent(text) {
|
|
7874
|
+
const lines = text.split(/\r\n?|\n/);
|
|
7875
|
+
if (isEmpty(lines[lines.length - 1]))
|
|
7876
|
+
lines.pop();
|
|
7877
|
+
if (isEmpty(lines[0]))
|
|
7878
|
+
lines.shift();
|
|
7879
|
+
return lines.map((l) => l.replace(/^ {4}/, "")).join("\n");
|
|
7880
|
+
}
|
|
7881
|
+
__name(dedent, "dedent");
|
|
7882
|
+
function indent(text) {
|
|
7883
|
+
const lines = text.split(/\r\n?|\n/);
|
|
7884
|
+
return `
|
|
7885
|
+
${lines.map((l) => l.trim() ? ` ${l}` : "").join("\n")}
|
|
7886
|
+
`;
|
|
7887
|
+
}
|
|
7888
|
+
__name(indent, "indent");
|
|
7889
|
+
const FunctionConstructors = {
|
|
7890
|
+
regular: Object.getPrototypeOf(function() {
|
|
7891
|
+
}).constructor,
|
|
7892
|
+
async: Object.getPrototypeOf(async function() {
|
|
7893
|
+
}).constructor,
|
|
7894
|
+
generator: Object.getPrototypeOf(function* () {
|
|
7895
|
+
}).constructor,
|
|
7896
|
+
asyncGenerator: Object.getPrototypeOf(async function* () {
|
|
7897
|
+
}).constructor
|
|
7898
|
+
};
|
|
7899
|
+
function funcType(async = false, generator = false) {
|
|
7900
|
+
if (!async && !generator) return FunctionConstructors.regular;
|
|
7901
|
+
if (async && !generator) return FunctionConstructors.async;
|
|
7902
|
+
if (!async && generator) return FunctionConstructors.generator;
|
|
7903
|
+
return FunctionConstructors.asyncGenerator;
|
|
7904
|
+
}
|
|
7905
|
+
__name(funcType, "funcType");
|
|
7906
|
+
function createFunction(refs, async = false, generator = false, blockStatement = false, body) {
|
|
7907
|
+
if (body === void 0) {
|
|
7908
|
+
return void 0;
|
|
7909
|
+
}
|
|
6640
7910
|
refs.patches.sort((l, r) => r.start - l.start);
|
|
6641
7911
|
refs.patches.forEach((r) => {
|
|
6642
7912
|
body = body.substring(0, r.start) + r.newText + body.substring(r.end);
|
|
@@ -6657,108 +7927,116 @@ const fixRelativeUrl = /* @__PURE__ */ __name((path, basePath) => {
|
|
|
6657
7927
|
}
|
|
6658
7928
|
return path;
|
|
6659
7929
|
}, "fixRelativeUrl");
|
|
7930
|
+
const obfuscatedImportFunction = new FunctionConstructors.async("url", "return import(url)");
|
|
6660
7931
|
async function obfuscatedImport(url) {
|
|
6661
|
-
return
|
|
7932
|
+
return obfuscatedImportFunction(url);
|
|
6662
7933
|
}
|
|
6663
7934
|
__name(obfuscatedImport, "obfuscatedImport");
|
|
6664
|
-
function
|
|
6665
|
-
|
|
7935
|
+
function _constructFunction(body, bodyStr, name) {
|
|
7936
|
+
if (body.type !== "FunctionExpression" && body.type !== "FunctionDeclaration" && body.type !== "ArrowFunctionExpression") {
|
|
7937
|
+
throw new Error(`Unsupported function type: ${body.type}`);
|
|
7938
|
+
}
|
|
7939
|
+
const func = body.async && body.generator ? FunctionConstructors.asyncGenerator : body.async ? FunctionConstructors.async : body.generator ? FunctionConstructors.generator : FunctionConstructors.regular;
|
|
7940
|
+
const params = body.params?.map((param) => bodyStr.slice(param.start, param.end)).join(", ") ?? "";
|
|
7941
|
+
const isBlock = body.body.type === "BlockStatement";
|
|
7942
|
+
const { start, end } = body.body;
|
|
7943
|
+
const inner = isBlock ? bodyStr.slice(start + 1, end - 1) : `return ${bodyStr.slice(start, end)}`;
|
|
7944
|
+
if (name) {
|
|
7945
|
+
const sanitize = /* @__PURE__ */ __name((n) => {
|
|
7946
|
+
let s = n.replace(/[^A-Za-z0-9_$]/g, "_");
|
|
7947
|
+
if (!/^[A-Za-z_$]/.test(s)) s = "_" + s;
|
|
7948
|
+
return s;
|
|
7949
|
+
}, "sanitize");
|
|
7950
|
+
const id = sanitize(name);
|
|
7951
|
+
const asyncKw = body.async ? "async " : "";
|
|
7952
|
+
const genMark = body.generator ? "*" : "";
|
|
7953
|
+
const src = `return ${asyncKw}function${genMark} ${id}(${params}) {
|
|
7954
|
+
${inner}
|
|
7955
|
+
}`;
|
|
7956
|
+
const builtNamed = new Function(src)();
|
|
7957
|
+
try {
|
|
7958
|
+
builtNamed.displayName = name;
|
|
7959
|
+
} catch {
|
|
7960
|
+
}
|
|
7961
|
+
return builtNamed;
|
|
7962
|
+
}
|
|
7963
|
+
const built = func(params, inner);
|
|
7964
|
+
return built;
|
|
6666
7965
|
}
|
|
6667
|
-
__name(
|
|
6668
|
-
function
|
|
6669
|
-
|
|
6670
|
-
|
|
6671
|
-
|
|
6672
|
-
|
|
6673
|
-
|
|
6674
|
-
|
|
7966
|
+
__name(_constructFunction, "_constructFunction");
|
|
7967
|
+
function constructFunction(bodyStr, name) {
|
|
7968
|
+
const { body } = parseJavaScript(bodyStr);
|
|
7969
|
+
if (body.type === "Program") {
|
|
7970
|
+
if (body.body.length !== 1) {
|
|
7971
|
+
throw new Error(`Expected a single function, but found ${body.body.length} statements`);
|
|
7972
|
+
}
|
|
7973
|
+
return _constructFunction(body.body[0], bodyStr, name);
|
|
6675
7974
|
}
|
|
6676
|
-
return
|
|
6677
|
-
ojs,
|
|
6678
|
-
offset: offset2,
|
|
6679
|
-
inlineMD,
|
|
6680
|
-
cell,
|
|
6681
|
-
error
|
|
6682
|
-
};
|
|
7975
|
+
return _constructFunction(body, bodyStr, name);
|
|
6683
7976
|
}
|
|
6684
|
-
__name(
|
|
6685
|
-
|
|
7977
|
+
__name(constructFunction, "constructFunction");
|
|
7978
|
+
const html2notebook = /* @__PURE__ */ __name((html) => deserialize(html), "html2notebook");
|
|
7979
|
+
const notebook2html = /* @__PURE__ */ __name((notebook2) => serialize(notebook2), "notebook2html");
|
|
7980
|
+
function compile$1(notebook2, options = { inline: true }) {
|
|
6686
7981
|
const retVal = [];
|
|
6687
|
-
|
|
6688
|
-
|
|
6689
|
-
|
|
6690
|
-
|
|
6691
|
-
|
|
6692
|
-
|
|
6693
|
-
|
|
6694
|
-
|
|
6695
|
-
|
|
6696
|
-
|
|
6697
|
-
|
|
6698
|
-
|
|
6699
|
-
|
|
6700
|
-
|
|
7982
|
+
let id = 1;
|
|
7983
|
+
for (const cell of notebook2.cells) {
|
|
7984
|
+
try {
|
|
7985
|
+
const compiled = transpile(cell);
|
|
7986
|
+
retVal.push({
|
|
7987
|
+
id: id++,
|
|
7988
|
+
...compiled,
|
|
7989
|
+
body: options.inline ? constructFunction(compiled.body, `cell_${id}`) : compiled.body
|
|
7990
|
+
});
|
|
7991
|
+
if (cell.pinned) {
|
|
7992
|
+
const compiled2 = transpile({
|
|
7993
|
+
...cell,
|
|
7994
|
+
mode: "md",
|
|
7995
|
+
value: `\`\`\`${cell.mode}
|
|
7996
|
+
${cell.value}
|
|
7997
|
+
\`\`\``
|
|
7998
|
+
});
|
|
7999
|
+
retVal.push({
|
|
8000
|
+
id: id++,
|
|
8001
|
+
...compiled2,
|
|
8002
|
+
body: options.inline ? constructFunction(compiled2.body, `cell_${id}`) : compiled2.body
|
|
8003
|
+
});
|
|
8004
|
+
}
|
|
8005
|
+
} catch (error) {
|
|
8006
|
+
console.error(`Error compiling cell ${id}:`, error);
|
|
6701
8007
|
}
|
|
6702
|
-
prevOffset = match.index + match[0].length;
|
|
6703
|
-
match = re.exec(_);
|
|
6704
|
-
}
|
|
6705
|
-
if (_.length > prevOffset) {
|
|
6706
|
-
retVal.push(createParsedOJS(_.substring(prevOffset, _.length), prevOffset, true));
|
|
6707
8008
|
}
|
|
6708
8009
|
return retVal;
|
|
6709
8010
|
}
|
|
6710
|
-
__name(
|
|
6711
|
-
|
|
6712
|
-
|
|
6713
|
-
|
|
6714
|
-
|
|
6715
|
-
|
|
6716
|
-
|
|
6717
|
-
|
|
6718
|
-
|
|
6719
|
-
|
|
6720
|
-
|
|
6721
|
-
end: cell.end
|
|
6722
|
-
};
|
|
6723
|
-
})
|
|
6724
|
-
};
|
|
6725
|
-
}
|
|
6726
|
-
__name(ojs2notebook, "ojs2notebook");
|
|
6727
|
-
function omd2notebook(omd) {
|
|
6728
|
-
const cells = splitOmd(omd);
|
|
6729
|
-
return {
|
|
6730
|
-
files: [],
|
|
6731
|
-
nodes: cells.map((cell, idx) => {
|
|
6732
|
-
return {
|
|
6733
|
-
id: idx,
|
|
6734
|
-
mode: cell.inlineMD ? "md" : "js",
|
|
6735
|
-
value: cell.ojs,
|
|
6736
|
-
start: cell.offset,
|
|
6737
|
-
end: cell.offset + cell.ojs.length
|
|
6738
|
-
};
|
|
6739
|
-
})
|
|
6740
|
-
};
|
|
6741
|
-
}
|
|
6742
|
-
__name(omd2notebook, "omd2notebook");
|
|
6743
|
-
function fetchEx(url, proxyPrefix = "https://api.codetabs.com/v1/proxy/?quest=", proxyPostfix = "") {
|
|
6744
|
-
const matches = url.match(/^(?:https?:\/\/)?(?:[^@\n]+@)?(?:www\.)?([^:\/\n?]+)/img);
|
|
6745
|
-
if (!matches || matches.length === 0) {
|
|
6746
|
-
throw new Error(`Invalid URL: ${url}`);
|
|
8011
|
+
__name(compile$1, "compile$1");
|
|
8012
|
+
const _ModuleParser = class _ModuleParser extends CellParser {
|
|
8013
|
+
parseTopLevel(node) {
|
|
8014
|
+
if (!node.cells) node.cells = [];
|
|
8015
|
+
while (this.type !== types$1.eof) {
|
|
8016
|
+
const cell = this.parseCell(this.startNode());
|
|
8017
|
+
cell.input = this.input;
|
|
8018
|
+
node.cells.push(cell);
|
|
8019
|
+
}
|
|
8020
|
+
this.next();
|
|
8021
|
+
return this.finishNode(node, "Program");
|
|
6747
8022
|
}
|
|
6748
|
-
|
|
6749
|
-
|
|
6750
|
-
|
|
6751
|
-
|
|
6752
|
-
|
|
6753
|
-
|
|
6754
|
-
|
|
8023
|
+
};
|
|
8024
|
+
__name(_ModuleParser, "ModuleParser");
|
|
8025
|
+
let ModuleParser = _ModuleParser;
|
|
8026
|
+
function splitModule(input) {
|
|
8027
|
+
return ModuleParser.parse(input, { ecmaVersion: "latest" }).cells.map((cell) => ({
|
|
8028
|
+
type: "Cell",
|
|
8029
|
+
text: input.substring(cell.start, cell.end),
|
|
8030
|
+
start: cell.start,
|
|
8031
|
+
end: cell.end
|
|
8032
|
+
}));
|
|
6755
8033
|
}
|
|
6756
|
-
__name(
|
|
6757
|
-
function
|
|
6758
|
-
|
|
6759
|
-
return fetchEx(impUrl.replace(`https://observablehq.com/${isShared ? "d/" : ""}`, "https://api.observablehq.com/document/"), proxyPrefix, proxyPostfix).then((r) => r.json());
|
|
8034
|
+
__name(splitModule, "splitModule");
|
|
8035
|
+
function parseCell$1(input) {
|
|
8036
|
+
return parseCell$2(input);
|
|
6760
8037
|
}
|
|
6761
|
-
__name(
|
|
8038
|
+
__name(parseCell$1, "parseCell$1");
|
|
8039
|
+
const walk = ohqWalk;
|
|
6762
8040
|
function calcRefs(cellAst, cellStr) {
|
|
6763
8041
|
if (cellAst.references === void 0) return { inputs: [], args: [], patches: [] };
|
|
6764
8042
|
const dedup = {};
|
|
@@ -6768,12 +8046,9 @@ function calcRefs(cellAst, cellStr) {
|
|
|
6768
8046
|
args: Object.keys(dedup).map((r) => r.split(" ").join("_")),
|
|
6769
8047
|
patches: []
|
|
6770
8048
|
};
|
|
6771
|
-
const pushPatch = /* @__PURE__ */ __name((node, newText) => {
|
|
6772
|
-
var _a, _b;
|
|
6773
|
-
return retVal.patches.push({ start: node.start - (((_a = cellAst.body) == null ? void 0 : _a.start) ?? 0), end: node.end - (((_b = cellAst.body) == null ? void 0 : _b.start) ?? 0), newText });
|
|
6774
|
-
}, "pushPatch");
|
|
8049
|
+
const pushPatch = /* @__PURE__ */ __name((node, newText) => retVal.patches.push({ start: node.start - (cellAst.body?.start ?? 0), end: node.end - (cellAst.body?.start ?? 0), newText }), "pushPatch");
|
|
6775
8050
|
if (cellAst.body) {
|
|
6776
|
-
ancestor(cellAst.body, {
|
|
8051
|
+
ancestor$1(cellAst.body, {
|
|
6777
8052
|
Identifier(node) {
|
|
6778
8053
|
cellStr.substring(node.start, node.end);
|
|
6779
8054
|
},
|
|
@@ -6799,30 +8074,26 @@ function calcRefs(cellAst, cellStr) {
|
|
|
6799
8074
|
}
|
|
6800
8075
|
__name(calcRefs, "calcRefs");
|
|
6801
8076
|
function parseImportDeclaration(cellAst) {
|
|
6802
|
-
var _a, _b;
|
|
6803
8077
|
return {
|
|
6804
8078
|
type: "import",
|
|
6805
8079
|
src: cellAst.body.source.value,
|
|
6806
|
-
specifiers:
|
|
6807
|
-
var _a2;
|
|
8080
|
+
specifiers: cellAst.body.specifiers?.map((spec) => {
|
|
6808
8081
|
return {
|
|
6809
8082
|
view: spec.view,
|
|
6810
8083
|
name: spec.imported.name,
|
|
6811
|
-
alias:
|
|
8084
|
+
alias: spec.local?.name && spec.imported.name !== spec.local.name ? spec.local.name : spec.imported.name
|
|
6812
8085
|
};
|
|
6813
|
-
})
|
|
6814
|
-
injections:
|
|
6815
|
-
var _a2;
|
|
8086
|
+
}) ?? [],
|
|
8087
|
+
injections: cellAst.body.injections?.map((inj) => {
|
|
6816
8088
|
return {
|
|
6817
8089
|
name: inj.imported.name,
|
|
6818
|
-
alias:
|
|
8090
|
+
alias: inj.local?.name ?? inj.imported.name
|
|
6819
8091
|
};
|
|
6820
|
-
})
|
|
8092
|
+
}) ?? []
|
|
6821
8093
|
};
|
|
6822
8094
|
}
|
|
6823
8095
|
__name(parseImportDeclaration, "parseImportDeclaration");
|
|
6824
8096
|
function parseViewExpression(cellStr, cellAst, refs, bodyStr) {
|
|
6825
|
-
var _a, _b;
|
|
6826
8097
|
const id = cellAst.id && cellStr.substring(cellAst.id.start, cellAst.id.end);
|
|
6827
8098
|
return {
|
|
6828
8099
|
type: "viewof",
|
|
@@ -6834,7 +8105,7 @@ function parseViewExpression(cellStr, cellAst, refs, bodyStr) {
|
|
|
6834
8105
|
},
|
|
6835
8106
|
variableValue: {
|
|
6836
8107
|
type: "variable",
|
|
6837
|
-
id:
|
|
8108
|
+
id: cellAst?.id?.id?.name,
|
|
6838
8109
|
inputs: ["Generators", id],
|
|
6839
8110
|
func: /* @__PURE__ */ __name((G, _) => G.input(_), "func")
|
|
6840
8111
|
}
|
|
@@ -6842,9 +8113,8 @@ function parseViewExpression(cellStr, cellAst, refs, bodyStr) {
|
|
|
6842
8113
|
}
|
|
6843
8114
|
__name(parseViewExpression, "parseViewExpression");
|
|
6844
8115
|
function parseMutableExpression(cellStr, cellAst, refs, bodyStr) {
|
|
6845
|
-
var _a, _b;
|
|
6846
8116
|
const id = cellAst.id && cellStr.substring(cellAst.id.start, cellAst.id.end);
|
|
6847
|
-
const initialValueId =
|
|
8117
|
+
const initialValueId = cellAst?.id?.id?.name;
|
|
6848
8118
|
const initialId = `initial ${initialValueId}`;
|
|
6849
8119
|
return {
|
|
6850
8120
|
type: "mutable",
|
|
@@ -6870,20 +8140,18 @@ function parseMutableExpression(cellStr, cellAst, refs, bodyStr) {
|
|
|
6870
8140
|
}
|
|
6871
8141
|
__name(parseMutableExpression, "parseMutableExpression");
|
|
6872
8142
|
function parseVariableExpression(cellStr, cellAst, refs, bodyStr) {
|
|
6873
|
-
var _a, _b;
|
|
6874
8143
|
return {
|
|
6875
8144
|
type: "variable",
|
|
6876
|
-
id: cellAst.id && cellStr.substring(
|
|
8145
|
+
id: cellAst.id && cellStr.substring(cellAst.id?.start, cellAst.id?.end),
|
|
6877
8146
|
inputs: refs.inputs,
|
|
6878
8147
|
func: createFunction(refs, cellAst.async, cellAst.generator, cellAst.body.type === "BlockStatement", bodyStr)
|
|
6879
8148
|
};
|
|
6880
8149
|
}
|
|
6881
8150
|
__name(parseVariableExpression, "parseVariableExpression");
|
|
6882
8151
|
function parseCell(cellStr, baseUrl) {
|
|
6883
|
-
var _a, _b;
|
|
6884
8152
|
const cellAst = parseCell$1(cellStr);
|
|
6885
8153
|
let bodyStr = cellAst.body && cellStr.substring(cellAst.body.start, cellAst.body.end);
|
|
6886
|
-
switch (
|
|
8154
|
+
switch (cellAst.body?.type) {
|
|
6887
8155
|
case "ImportDeclaration":
|
|
6888
8156
|
return parseImportDeclaration(cellAst);
|
|
6889
8157
|
case "ImportExpression":
|
|
@@ -6896,7 +8164,7 @@ function parseCell(cellStr, baseUrl) {
|
|
|
6896
8164
|
}
|
|
6897
8165
|
}
|
|
6898
8166
|
const refs = calcRefs(cellAst, cellStr);
|
|
6899
|
-
switch (
|
|
8167
|
+
switch (cellAst.id?.type) {
|
|
6900
8168
|
case "ViewExpression":
|
|
6901
8169
|
return parseViewExpression(cellStr, cellAst, refs, bodyStr);
|
|
6902
8170
|
case "MutableExpression":
|
|
@@ -6907,13 +8175,13 @@ function parseCell(cellStr, baseUrl) {
|
|
|
6907
8175
|
}
|
|
6908
8176
|
__name(parseCell, "parseCell");
|
|
6909
8177
|
const _Writer = class _Writer {
|
|
8178
|
+
_files = [];
|
|
8179
|
+
_imports = [];
|
|
8180
|
+
_functions = [];
|
|
8181
|
+
_defines = [];
|
|
8182
|
+
_defineUid = 0;
|
|
8183
|
+
_functionUid = 0;
|
|
6910
8184
|
constructor() {
|
|
6911
|
-
__publicField(this, "_files", []);
|
|
6912
|
-
__publicField(this, "_imports", []);
|
|
6913
|
-
__publicField(this, "_functions", []);
|
|
6914
|
-
__publicField(this, "_defines", []);
|
|
6915
|
-
__publicField(this, "_defineUid", 0);
|
|
6916
|
-
__publicField(this, "_functionUid", 0);
|
|
6917
8185
|
}
|
|
6918
8186
|
toString() {
|
|
6919
8187
|
return `${this._imports.join("\n")}
|
|
@@ -6954,21 +8222,19 @@ export default function define(runtime, observer) {
|
|
|
6954
8222
|
});
|
|
6955
8223
|
}
|
|
6956
8224
|
function(variable) {
|
|
6957
|
-
var _a, _b;
|
|
6958
8225
|
let id = variable.id ?? `${++this._functionUid}`;
|
|
6959
8226
|
const idParts = id.split(" ");
|
|
6960
8227
|
id = `_${idParts[idParts.length - 1]}`;
|
|
6961
|
-
this._functions.push(`${
|
|
8228
|
+
this._functions.push(`${variable.func?.toString()?.replace("anonymous", `${id}`)}`);
|
|
6962
8229
|
return id;
|
|
6963
8230
|
}
|
|
6964
8231
|
define(variable, observable = true, inlineFunc = false, funcId) {
|
|
6965
|
-
var _a;
|
|
6966
8232
|
funcId = funcId ?? variable.id;
|
|
6967
8233
|
const observe = observable ? `.variable(observer(${variable.id ? JSON.stringify(variable.id) : ""}))` : "";
|
|
6968
8234
|
const id = variable.id ? `${JSON.stringify(variable.id)}, ` : "";
|
|
6969
8235
|
const variableInputs = variable.inputs ?? [];
|
|
6970
8236
|
const inputs = variableInputs.length ? `[${variableInputs.map((i) => JSON.stringify(i)).join(", ")}], ` : "";
|
|
6971
|
-
const func = inlineFunc ?
|
|
8237
|
+
const func = inlineFunc ? variable.func?.toString() : funcId;
|
|
6972
8238
|
this._defines.push(`main${observe}.define(${id}${inputs}${func});`);
|
|
6973
8239
|
}
|
|
6974
8240
|
error(msg) {
|
|
@@ -6976,6 +8242,137 @@ export default function define(runtime, observer) {
|
|
|
6976
8242
|
};
|
|
6977
8243
|
__name(_Writer, "Writer");
|
|
6978
8244
|
let Writer = _Writer;
|
|
8245
|
+
function encodeBacktick(str) {
|
|
8246
|
+
return str.split("`").join("\\`");
|
|
8247
|
+
}
|
|
8248
|
+
__name(encodeBacktick, "encodeBacktick");
|
|
8249
|
+
function createParsedOJS(ojs, offset2, inlineMD) {
|
|
8250
|
+
let cell;
|
|
8251
|
+
let error;
|
|
8252
|
+
try {
|
|
8253
|
+
cell = parseCell$1(ojs);
|
|
8254
|
+
} catch (e) {
|
|
8255
|
+
error = e;
|
|
8256
|
+
}
|
|
8257
|
+
return {
|
|
8258
|
+
ojs,
|
|
8259
|
+
offset: offset2,
|
|
8260
|
+
inlineMD,
|
|
8261
|
+
cell,
|
|
8262
|
+
error
|
|
8263
|
+
};
|
|
8264
|
+
}
|
|
8265
|
+
__name(createParsedOJS, "createParsedOJS");
|
|
8266
|
+
function splitOmd(_) {
|
|
8267
|
+
const retVal = [];
|
|
8268
|
+
const re = /(```(?:\s|\S)[\s\S]*?```)/g;
|
|
8269
|
+
let prevOffset = 0;
|
|
8270
|
+
let match = re.exec(_);
|
|
8271
|
+
while (match !== null) {
|
|
8272
|
+
if (match.index > prevOffset) {
|
|
8273
|
+
retVal.push(createParsedOJS(_.substring(prevOffset, match.index), prevOffset, true));
|
|
8274
|
+
}
|
|
8275
|
+
const outer = match[0];
|
|
8276
|
+
if (outer.indexOf("``` ") === 0 || outer.indexOf("```\n") === 0 || outer.indexOf("```\r\n") === 0) {
|
|
8277
|
+
const prefixLen = 3;
|
|
8278
|
+
const inner = outer.substring(prefixLen, outer.length - prefixLen);
|
|
8279
|
+
retVal.push(createParsedOJS(inner, match.index + prefixLen, false));
|
|
8280
|
+
} else {
|
|
8281
|
+
retVal.push(createParsedOJS(outer, match.index, true));
|
|
8282
|
+
}
|
|
8283
|
+
prevOffset = match.index + match[0].length;
|
|
8284
|
+
match = re.exec(_);
|
|
8285
|
+
}
|
|
8286
|
+
if (_.length > prevOffset) {
|
|
8287
|
+
retVal.push(createParsedOJS(_.substring(prevOffset, _.length), prevOffset, true));
|
|
8288
|
+
}
|
|
8289
|
+
return retVal;
|
|
8290
|
+
}
|
|
8291
|
+
__name(splitOmd, "splitOmd");
|
|
8292
|
+
function ojs2notebook(ojs) {
|
|
8293
|
+
const cells = splitModule(ojs);
|
|
8294
|
+
return {
|
|
8295
|
+
files: [],
|
|
8296
|
+
nodes: cells.map((cell, idx) => {
|
|
8297
|
+
return {
|
|
8298
|
+
id: idx,
|
|
8299
|
+
mode: "js",
|
|
8300
|
+
value: cell.text,
|
|
8301
|
+
start: cell.start,
|
|
8302
|
+
end: cell.end
|
|
8303
|
+
};
|
|
8304
|
+
})
|
|
8305
|
+
};
|
|
8306
|
+
}
|
|
8307
|
+
__name(ojs2notebook, "ojs2notebook");
|
|
8308
|
+
function ojs2notebookKit(ojs) {
|
|
8309
|
+
const cells = splitModule(ojs).map((cell, idx) => {
|
|
8310
|
+
return toCell({
|
|
8311
|
+
id: idx,
|
|
8312
|
+
mode: "ojs",
|
|
8313
|
+
value: cell.text
|
|
8314
|
+
});
|
|
8315
|
+
});
|
|
8316
|
+
return toNotebook({ cells });
|
|
8317
|
+
}
|
|
8318
|
+
__name(ojs2notebookKit, "ojs2notebookKit");
|
|
8319
|
+
function omd2notebook(omd) {
|
|
8320
|
+
const cells = splitOmd(omd);
|
|
8321
|
+
return {
|
|
8322
|
+
files: [],
|
|
8323
|
+
nodes: cells.map((cell, idx) => {
|
|
8324
|
+
return {
|
|
8325
|
+
id: idx,
|
|
8326
|
+
mode: cell.inlineMD ? "md" : "js",
|
|
8327
|
+
value: cell.ojs,
|
|
8328
|
+
start: cell.offset,
|
|
8329
|
+
end: cell.offset + cell.ojs.length
|
|
8330
|
+
};
|
|
8331
|
+
})
|
|
8332
|
+
};
|
|
8333
|
+
}
|
|
8334
|
+
__name(omd2notebook, "omd2notebook");
|
|
8335
|
+
function omd2notebookKit(omd) {
|
|
8336
|
+
const cells = [];
|
|
8337
|
+
splitOmd(omd).forEach((cell) => {
|
|
8338
|
+
if (!cell.inlineMD) {
|
|
8339
|
+
splitModule(cell.ojs).forEach((subCell) => {
|
|
8340
|
+
cells.push(toCell({
|
|
8341
|
+
id: cells.length + 1,
|
|
8342
|
+
mode: "ojs",
|
|
8343
|
+
value: subCell.text
|
|
8344
|
+
}));
|
|
8345
|
+
});
|
|
8346
|
+
} else {
|
|
8347
|
+
cells.push(toCell({
|
|
8348
|
+
id: cells.length + 1,
|
|
8349
|
+
mode: "md",
|
|
8350
|
+
value: cell.ojs
|
|
8351
|
+
}));
|
|
8352
|
+
}
|
|
8353
|
+
});
|
|
8354
|
+
return toNotebook({ cells });
|
|
8355
|
+
}
|
|
8356
|
+
__name(omd2notebookKit, "omd2notebookKit");
|
|
8357
|
+
function fetchEx(url, proxyPrefix = "https://api.codetabs.com/v1/proxy/?quest=", proxyPostfix = "") {
|
|
8358
|
+
const matches = url.match(/^(?:https?:\/\/)?(?:[^@\n]+@)?(?:www\.)?([^:\/\n?]+)/img);
|
|
8359
|
+
if (!matches || matches.length === 0) {
|
|
8360
|
+
throw new Error(`Invalid URL: ${url}`);
|
|
8361
|
+
}
|
|
8362
|
+
return fetch(url, { headers: { origin: matches[0], referer: url } }).then((response) => {
|
|
8363
|
+
if (response.ok) return response;
|
|
8364
|
+
throw new Error("CORS?");
|
|
8365
|
+
}).catch((e) => {
|
|
8366
|
+
url = `${proxyPrefix}${url}${proxyPostfix}`;
|
|
8367
|
+
return fetch(url, { headers: { origin: matches[0], referer: url } });
|
|
8368
|
+
});
|
|
8369
|
+
}
|
|
8370
|
+
__name(fetchEx, "fetchEx");
|
|
8371
|
+
function download(impUrl, proxyPrefix, proxyPostfix) {
|
|
8372
|
+
const isShared = impUrl.indexOf("https://observablehq.com/d") === 0;
|
|
8373
|
+
return fetchEx(impUrl.replace(`https://observablehq.com/${isShared ? "d/" : ""}`, "https://api.observablehq.com/document/"), proxyPrefix, proxyPostfix).then((r) => r.json());
|
|
8374
|
+
}
|
|
8375
|
+
__name(download, "download");
|
|
6979
8376
|
async function importFile(relativePath, baseUrl) {
|
|
6980
8377
|
const path = fixRelativeUrl(relativePath, baseUrl);
|
|
6981
8378
|
const content = await fetchEx(path).then((r) => r.text());
|
|
@@ -7082,7 +8479,7 @@ function createVariable(node, inspect, name, inputs, definition, inline = false)
|
|
|
7082
8479
|
try {
|
|
7083
8480
|
v.define(name, inputs, definition);
|
|
7084
8481
|
} catch (e) {
|
|
7085
|
-
console.error(e
|
|
8482
|
+
console.error(e?.message);
|
|
7086
8483
|
}
|
|
7087
8484
|
}
|
|
7088
8485
|
if (node.pinned) {
|
|
@@ -7094,20 +8491,19 @@ ${node.value}
|
|
|
7094
8491
|
\`\`\``;
|
|
7095
8492
|
});
|
|
7096
8493
|
} catch (e) {
|
|
7097
|
-
console.error(e
|
|
8494
|
+
console.error(e?.message);
|
|
7098
8495
|
}
|
|
7099
8496
|
}
|
|
7100
8497
|
return v;
|
|
7101
8498
|
}, "retVal");
|
|
7102
8499
|
retVal.delete = () => {
|
|
7103
|
-
var _a;
|
|
7104
8500
|
try {
|
|
7105
|
-
|
|
8501
|
+
i?._node?.remove();
|
|
7106
8502
|
} catch (e) {
|
|
7107
8503
|
}
|
|
7108
8504
|
i = void 0;
|
|
7109
8505
|
try {
|
|
7110
|
-
v
|
|
8506
|
+
v?.delete();
|
|
7111
8507
|
} catch (e) {
|
|
7112
8508
|
}
|
|
7113
8509
|
v = void 0;
|
|
@@ -7134,7 +8530,7 @@ function createImportVariable(name, alias) {
|
|
|
7134
8530
|
}
|
|
7135
8531
|
}, "retVal");
|
|
7136
8532
|
retVal.delete = () => {
|
|
7137
|
-
v
|
|
8533
|
+
v?.delete();
|
|
7138
8534
|
};
|
|
7139
8535
|
return retVal;
|
|
7140
8536
|
}
|
|
@@ -7243,19 +8639,37 @@ function notebook(_files = [], _cells = [], { baseUrl = ".", importMode = "preco
|
|
|
7243
8639
|
return retVal;
|
|
7244
8640
|
}
|
|
7245
8641
|
__name(notebook, "notebook");
|
|
8642
|
+
function isNotebookKit(value) {
|
|
8643
|
+
return !!value && Array.isArray(value.cells);
|
|
8644
|
+
}
|
|
8645
|
+
__name(isNotebookKit, "isNotebookKit");
|
|
8646
|
+
function isOhqNotebook(value) {
|
|
8647
|
+
return !!value && Array.isArray(value.nodes);
|
|
8648
|
+
}
|
|
8649
|
+
__name(isOhqNotebook, "isOhqNotebook");
|
|
7246
8650
|
async function compile(notebookOrOjs, { baseUrl = ".", importMode = "precompiled" } = {}) {
|
|
7247
|
-
|
|
7248
|
-
|
|
7249
|
-
|
|
8651
|
+
if (isNotebookKit(notebookOrOjs)) {
|
|
8652
|
+
return compile$1(notebookOrOjs);
|
|
8653
|
+
} else if (typeof notebookOrOjs === "string") {
|
|
8654
|
+
notebookOrOjs = ojs2notebook(notebookOrOjs);
|
|
8655
|
+
}
|
|
8656
|
+
const _cells = await Promise.all(notebookOrOjs.nodes.map((n) => createCell(n, { baseUrl, importMode })));
|
|
8657
|
+
return notebook(notebookOrOjs.files, _cells, { baseUrl, importMode });
|
|
7250
8658
|
}
|
|
7251
8659
|
__name(compile, "compile");
|
|
7252
8660
|
export {
|
|
7253
8661
|
Writer,
|
|
7254
8662
|
compile,
|
|
8663
|
+
compile$1 as compileKit,
|
|
7255
8664
|
download,
|
|
8665
|
+
html2notebook,
|
|
8666
|
+
isNotebookKit,
|
|
8667
|
+
isOhqNotebook,
|
|
7256
8668
|
notebook,
|
|
8669
|
+
notebook2html,
|
|
7257
8670
|
ojs2notebook,
|
|
7258
|
-
|
|
8671
|
+
ojs2notebookKit,
|
|
8672
|
+
omd2notebook,
|
|
8673
|
+
omd2notebookKit
|
|
7259
8674
|
};
|
|
7260
8675
|
//# sourceMappingURL=index.js.map
|
|
7261
|
-
!function(){"use strict";try{if("undefined"!=typeof document){var e=document.createElement("style");e.appendChild(document.createTextNode('@import"https://fonts.googleapis.com/css2?family=Source+Serif+Pro:ital,wght@0,400;0,600;0,700;1,400;1,600;1,700&display=swap";:root{--syntax-normal: #1b1e23;--syntax-comment: #828282;--syntax-number: #20a5ba;--syntax-keyword: #c30771;--syntax-atom: #10a778;--syntax-string: #008ec4;--syntax-error: #ffbedc;--syntax-unknown-variable: #838383;--syntax-known-variable: #005f87;--syntax-matchbracket: #20bbfc;--syntax-key: #6636b4;--mono-fonts: 82%/1.5 Menlo, Consolas, monospace}.observablehq--expanded,.observablehq--collapsed,.observablehq--function,.observablehq--import,.observablehq--string:before,.observablehq--string:after,.observablehq--gray{color:var(--syntax-normal)}.observablehq--collapsed,.observablehq--expanded.observablehq--inspect a{cursor:pointer}.observablehq--field{text-indent:-1em;margin-left:1em}.observablehq--empty{color:var(--syntax_comment)}a[href],.observablehq--keyword,.observablehq--blue{color:#3182bd}.hljs-deletion,.hljs-variable,.observablehq--forbidden,.observablehq--pink{color:#e377c2}.observablehq--orange{color:#e6550d}.observablehq--null,.observablehq--undefined,.observablehq--boolean,.hljs-literal{color:var(--syntax-atom)}.hljs-number,.hljs-regexp,.hljs-bullet,.hljs-link,.observablehq--bigint,.observablehq--number,.observablehq--date,.observablehq--regexp,.observablehq--symbol,.observablehq--green{color:var(--syntax-number)}.observablehq--index,.observablehq--key{color:var(--syntax-key)}.observablehq--prototype-key{color:#aaa}.observablehq--empty{font-style:oblique}.hljs-string,.hljs-meta,.hljs-symbol,.hljs-template-tag,.hljs-template-variable,.hljs-addition,.observablehq--string,.observablehq--purple{color:var(--syntax-string)}.observablehq--error,.observablehq--red{color:#e7040f}.observablehq:empty:after,.observablehq>link:only-child,.observablehq>style:only-child,.observablehq--inspect{font:var(--monospace-font);overflow-x:auto;display:block;padding:4px 0;white-space:pre}.observablehq--error .observablehq--inspect{word-break:break-all;white-space:pre-wrap}:root{--syntax-diff: #24292e;--syntax-diff-bg: #ffffff;--hr: rgba(0, 0, 0, .05);--monospace: Menlo, Consolas, monospace;--monospace-font: 14px/1.5 var(--monospace);--serif: "Source Serif Pro", "Iowan Old Style", "Apple Garamond", "Palatino Linotype", "Times New Roman", "Droid Serif", Times, serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";--sans-serif: -apple-system, BlinkMacSystemFont, "avenir next", avenir, helvetica, "helvetica neue", ubuntu, roboto, noto, "segoe ui", arial, sans-serif}html{font:17px/1.5 var(--serif);-webkit-text-size-adjust:100%;-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale;color:#1b1e23}body{margin:0 14px}body.fullscreen{margin:0}h1,h2,h3,h4,h5,h6{color:#333;font-weight:700;line-height:1.15;margin-top:0;margin-bottom:.25rem}h2~p,h3~p,h4~p,h2~table,h3~table,h4~table{margin-top:0}.observablehq:first-of-type h1+h2{font-size:20px;font-style:italic;font-weight:400;margin-bottom:1rem}a[href]{text-decoration:none}a[href]:hover{text-decoration:underline}h1 code,h2 code,h3 code,h4 code,h5 code,h6 code{font-size:90%}pre,code,tt{font-family:var(--monospace);font-size:14px;line-height:1.5}img{max-width:calc(100vw - 28px)}p,table,figure,figcaption,h1,h2,h3,h4,h5,h6,.katex-display{max-width:640px}blockquote,ol,ul{max-width:600px}blockquote{margin:1rem 1.5rem}ul,ol{padding-left:28px}hr{height:1px;margin:1rem 0;padding:1rem 0;border:none;background:no-repeat center/100% 1px linear-gradient(to right,var(--hr),var(--hr))}pre{padding:2px 0}.observablehq--md-pre{overflow-x:auto}input:not([type]),input[type=email],input[type=number],input[type=password],input[type=range],input[type=search],input[type=tel],input[type=text],input[type=url]{width:240px}input,canvas,button{vertical-align:middle}button,input,textarea{accent-color:#3b5fc0}table{width:100%;border-collapse:collapse;font:13px/1.2 var(--sans-serif)}table pre,table code,table tt{font-size:inherit;line-height:inherit}th>pre:only-child,td>pre:only-child{margin:0;padding:0}th{color:#111;text-align:left;vertical-align:bottom}td{color:#444;vertical-align:top}th,td{padding:3px 6.5px 3px 0}th:last-child,td:last-child{padding-right:0}tr:not(:last-child){border-bottom:solid 1px #eee}thead tr{border-bottom:solid 1px #ccc}figure,table{margin:1rem 0}figure img{max-width:100%}figcaption{font:small var(--sans-serif);color:var(--syntax-unknown-variable)}.observablehq--caret{margin-right:4px;vertical-align:baseline}.observablehq--field{text-indent:-1rem;margin-left:1rem}.observablehq--prototype-key,.observablehq--empty,.hljs-comment{color:var(--syntax-comment)}.hljs-built_in{color:var(--syntax-known-variable)}.observablehq--unknown{color:var(--syntax-unknown-variable)}.hljs-keyword,.hljs-selector-tag,.hljs-section,.hljs-doctag,.hljs-type,.hljs-tag,.hljs-name,.hljs-selector-id,.hljs-selector-class,.hljs-strong{color:var(--syntax-keyword)}.observablehq{position:relative;margin:17px 0;min-height:1.5rem}.observablehq:before{content:"";position:absolute;left:-14px;top:0;bottom:1px;width:4px;transition:background-color .25s linear}.observablehq--running:before,.observablehq--changed:before{background-color:#a9b0bc;transition:none}.observablehq--error:before{background-color:#e7040f}.observablehq:not(.observablehq--running):empty:after{content:"<detached>";color:var(--syntax-comment);font-style:oblique}.observablehq>link:only-child,.observablehq>style:only-child{visibility:hidden;white-space:nowrap;color:var(--syntax-keyword)}.observablehq>link:only-child:before{content:"<link>";visibility:visible;text-decoration:none;pointer-events:none}.observablehq>style:only-child:before{content:"<style>";visibility:visible}.observablehq--inspect.observablehq--import{white-space:normal}.observablehq--inspect::-webkit-scrollbar{display:none}.observablehq--string-expand{margin-left:6px;padding:2px 6px;border-radius:2px;font-size:80%;background:#eee;color:var(--syntax-normal);cursor:pointer;vertical-align:middle;position:sticky;right:0}.observablehq--string-expand:hover,.observablehq--string-expand:active{background:#ddd}')),document.head.appendChild(e)}}catch(o){console.error("vite-plugin-css-injected-by-js",o)}}();
|