hyperbook 0.86.4 → 0.87.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.
@@ -0,0 +1,32 @@
1
+ /// <reference path="../hyperbook.types.js" />
2
+
3
+ /**
4
+ * Blockflow editor client script.
5
+ * Prepends window.origin to relative project URLs so that
6
+ * blockflow.openpatch.org can fetch them cross-origin.
7
+ */
8
+ (function () {
9
+ function fixIframes(root) {
10
+ var iframes = root.querySelectorAll
11
+ ? root.querySelectorAll(".directive-blockflow-editor iframe")
12
+ : [];
13
+ iframes.forEach(function (iframe) {
14
+ var src = iframe.getAttribute("src");
15
+ if (!src) return;
16
+ try {
17
+ var url = new URL(src);
18
+ var project = url.searchParams.get("project");
19
+ if (project && !project.match(/^https?:\/\//)) {
20
+ url.searchParams.set("project", window.origin + project);
21
+ iframe.setAttribute("src", url.toString());
22
+ }
23
+ } catch (e) {
24
+ // ignore malformed URLs
25
+ }
26
+ });
27
+ }
28
+
29
+ document.addEventListener("DOMContentLoaded", function () {
30
+ fixIframes(document);
31
+ });
32
+ })();
@@ -0,0 +1,20 @@
1
+ .directive-blockflow-editor {
2
+ width: 100%;
3
+ position: relative;
4
+ overflow: hidden;
5
+ border-radius: 8px;
6
+ border-style: solid;
7
+ border-width: 2px;
8
+ border-color: var(--color-brand);
9
+ }
10
+
11
+ .directive-blockflow-editor iframe {
12
+ width: 100%;
13
+ height: 100%;
14
+ border-width: 0;
15
+ bottom: 0;
16
+ top: 0;
17
+ left: 0;
18
+ right: 0;
19
+ position: absolute;
20
+ }
@@ -0,0 +1,32 @@
1
+ /// <reference path="../hyperbook.types.js" />
2
+
3
+ /**
4
+ * Blockflow player client script.
5
+ * Prepends window.origin to relative project URLs so that
6
+ * blockflow.openpatch.org can fetch them cross-origin.
7
+ */
8
+ (function () {
9
+ function fixIframes(root) {
10
+ var iframes = root.querySelectorAll
11
+ ? root.querySelectorAll(".directive-blockflow-player iframe")
12
+ : [];
13
+ iframes.forEach(function (iframe) {
14
+ var src = iframe.getAttribute("src");
15
+ if (!src) return;
16
+ try {
17
+ var url = new URL(src);
18
+ var project = url.searchParams.get("project");
19
+ if (project && !project.match(/^https?:\/\//)) {
20
+ url.searchParams.set("project", window.origin + project);
21
+ iframe.setAttribute("src", url.toString());
22
+ }
23
+ } catch (e) {
24
+ // ignore malformed URLs
25
+ }
26
+ });
27
+ }
28
+
29
+ document.addEventListener("DOMContentLoaded", function () {
30
+ fixIframes(document);
31
+ });
32
+ })();
@@ -0,0 +1,20 @@
1
+ .directive-blockflow-player {
2
+ width: 100%;
3
+ position: relative;
4
+ overflow: hidden;
5
+ border-radius: 8px;
6
+ border-style: solid;
7
+ border-width: 2px;
8
+ border-color: var(--color-brand);
9
+ }
10
+
11
+ .directive-blockflow-player iframe {
12
+ width: 100%;
13
+ height: 100%;
14
+ border-width: 0;
15
+ bottom: 0;
16
+ top: 0;
17
+ left: 0;
18
+ right: 0;
19
+ position: absolute;
20
+ }
package/dist/index.js CHANGED
@@ -55533,6 +55533,7 @@ async function runBuild(root, rootProject, basePath, prefix, out, filter) {
55533
55533
  if (out) {
55534
55534
  rootOut = path_1.default.join(out, ".hyperbook", "out", basePath || "");
55535
55535
  }
55536
+ const assetsOut = path_1.default.join(rootOut, exports.ASSETS_FOLDER);
55536
55537
  console.log(`${chalk_1.default.blue(`[${prefix}]`)} Cleaning output folder ${rootOut}.`);
55537
55538
  await (0, archive_1.runArchive)(root, rootOut, prefix);
55538
55539
  // Helper function to resolve relative paths
@@ -55636,6 +55637,17 @@ async function runBuild(root, rootProject, basePath, prefix, out, filter) {
55636
55637
  for (let directive of Object.keys(result.data.directives || {})) {
55637
55638
  directives.add(directive);
55638
55639
  }
55640
+ for (const generated of result.data.generatedFiles || []) {
55641
+ let genDir;
55642
+ if (generated.relativeTo === "page") {
55643
+ genDir = path_1.default.join(rootOut, file.path.directory);
55644
+ }
55645
+ else {
55646
+ genDir = path_1.default.join(assetsOut, `directive-${generated.directive}`);
55647
+ }
55648
+ await (0, make_dir_1.makeDir)(genDir, { recursive: true });
55649
+ await promises_1.default.writeFile(path_1.default.join(genDir, generated.filename), generated.content);
55650
+ }
55639
55651
  let directoryOut = path_1.default.join(rootOut, file.path.directory);
55640
55652
  let href;
55641
55653
  if (file.name === "index") {
@@ -55708,6 +55720,17 @@ async function runBuild(root, rootProject, basePath, prefix, out, filter) {
55708
55720
  for (let directive of Object.keys(result.data.directives || {})) {
55709
55721
  directives.add(directive);
55710
55722
  }
55723
+ for (const generated of result.data.generatedFiles || []) {
55724
+ let genDir;
55725
+ if (generated.relativeTo === "page") {
55726
+ genDir = path_1.default.join(rootOut, file.path.directory);
55727
+ }
55728
+ else {
55729
+ genDir = path_1.default.join(assetsOut, `directive-${generated.directive}`);
55730
+ }
55731
+ await (0, make_dir_1.makeDir)(genDir, { recursive: true });
55732
+ await promises_1.default.writeFile(path_1.default.join(genDir, generated.filename), generated.content);
55733
+ }
55711
55734
  let href = file.path.href + ".html";
55712
55735
  let fileOut = path_1.default.join(rootOut, href);
55713
55736
  if (hyperbookJson.trailingSlash) {
@@ -55734,7 +55757,6 @@ async function runBuild(root, rootProject, basePath, prefix, out, filter) {
55734
55757
  }
55735
55758
  process.stdout.write("\n");
55736
55759
  const assetsPath = path_1.default.join(__dirname, "assets");
55737
- const assetsOut = path_1.default.join(rootOut, exports.ASSETS_FOLDER);
55738
55760
  await (0, promises_1.mkdir)(assetsOut, {
55739
55761
  recursive: true,
55740
55762
  });
@@ -200864,6 +200886,142 @@ var remarkDirectiveStruktolab_default = (ctx) => () => {
200864
200886
  };
200865
200887
  };
200866
200888
 
200889
+ // src/remarkDirectiveBlockflowPlayer.ts
200890
+ var remarkDirectiveBlockflowPlayer_default = (ctx) => () => {
200891
+ const name = "blockflow-player";
200892
+ return (tree, file) => {
200893
+ visit(tree, function(node3) {
200894
+ if (isDirective(node3)) {
200895
+ if (node3.name !== name) return;
200896
+ const data = node3.data || (node3.data = {});
200897
+ expectLeafDirective(node3, file, name);
200898
+ registerDirective(file, name, ["client.js"], ["style.css"], []);
200899
+ const {
200900
+ src,
200901
+ width = "100%",
200902
+ height = "600px",
200903
+ aspectRatio = "4/3"
200904
+ } = node3.attributes || {};
200905
+ const iframeSrc = src ? `https://blockflow.openpatch.org/player.html?project=${encodeURIComponent(src)}` : void 0;
200906
+ data.hName = "div";
200907
+ data.hProperties = {
200908
+ class: "directive-blockflow-player",
200909
+ style: `aspect-ratio: ${aspectRatio}; height: ${height}; width: ${width}`
200910
+ };
200911
+ data.hChildren = [
200912
+ {
200913
+ type: "element",
200914
+ tagName: "iframe",
200915
+ properties: {
200916
+ src: iframeSrc,
200917
+ allowfullscreen: true
200918
+ },
200919
+ children: []
200920
+ }
200921
+ ];
200922
+ }
200923
+ });
200924
+ };
200925
+ };
200926
+
200927
+ // src/remarkDirectiveBlockflowEditor.ts
200928
+ var remarkDirectiveBlockflowEditor_default = (ctx) => () => {
200929
+ const name = "blockflow-editor";
200930
+ return (tree, file) => {
200931
+ visit(tree, function(node3) {
200932
+ if (isDirective(node3)) {
200933
+ if (node3.name !== name) return;
200934
+ const data = node3.data || (node3.data = {});
200935
+ expectContainerDirective(node3, file, name);
200936
+ registerDirective(file, name, ["client.js"], ["style.css"], ["step"]);
200937
+ const {
200938
+ title,
200939
+ src,
200940
+ project,
200941
+ width = "100%",
200942
+ height = "700px",
200943
+ aspectRatio,
200944
+ allowExtensions,
200945
+ showCostumesTab,
200946
+ showSoundsTab,
200947
+ categories,
200948
+ ...rest
200949
+ } = node3.attributes || {};
200950
+ let projectParam;
200951
+ if (project) {
200952
+ projectParam = encodeURIComponent(project);
200953
+ } else {
200954
+ const steps = [];
200955
+ for (const child of node3.children || []) {
200956
+ if (!isDirective(child) || child.name !== "step") continue;
200957
+ const stepAttrs = child.attributes || {};
200958
+ const text9 = toString3(child).trim() || void 0;
200959
+ steps.push({
200960
+ title: stepAttrs.title || void 0,
200961
+ text: text9,
200962
+ image: stepAttrs.image || void 0,
200963
+ video: stepAttrs.video || void 0
200964
+ });
200965
+ }
200966
+ const config2 = {};
200967
+ if (title) config2.title = title;
200968
+ if (src) config2.sb3 = src;
200969
+ const ui = {};
200970
+ if (allowExtensions !== void 0) {
200971
+ ui.allowExtensions = allowExtensions !== "false";
200972
+ }
200973
+ if (showCostumesTab !== void 0) {
200974
+ ui.showCostumesTab = showCostumesTab !== "false";
200975
+ }
200976
+ if (showSoundsTab !== void 0) {
200977
+ ui.showSoundsTab = showSoundsTab !== "false";
200978
+ }
200979
+ if (Object.keys(ui).length > 0) {
200980
+ config2.ui = ui;
200981
+ }
200982
+ if (categories || Object.keys(rest).some((k) => k.startsWith("blocks-"))) {
200983
+ config2.toolbox = {};
200984
+ if (categories) {
200985
+ config2.toolbox.categories = categories.split(",").map((c) => c.trim());
200986
+ }
200987
+ const blocks2 = {};
200988
+ for (const [key2, value] of Object.entries(rest)) {
200989
+ if (key2.startsWith("blocks-") && value) {
200990
+ const category = key2.slice("blocks-".length);
200991
+ blocks2[category] = value.split(",").map((b) => b.trim());
200992
+ }
200993
+ }
200994
+ if (Object.keys(blocks2).length > 0) {
200995
+ config2.toolbox.blocks = blocks2;
200996
+ }
200997
+ }
200998
+ if (steps.length > 0) config2.steps = steps;
200999
+ const configJson = JSON.stringify(config2);
201000
+ projectParam = Buffer.from(configJson).toString("base64");
201001
+ }
201002
+ const iframeSrc = `https://blockflow.openpatch.org?project=${projectParam}`;
201003
+ data.hName = "div";
201004
+ data.hProperties = {
201005
+ class: "directive-blockflow-editor",
201006
+ style: `aspect-ratio: ${aspectRatio}; height: ${height}; width: ${width}`
201007
+ };
201008
+ data.hChildren = [
201009
+ {
201010
+ type: "element",
201011
+ tagName: "iframe",
201012
+ properties: {
201013
+ src: iframeSrc,
201014
+ allowfullscreen: true
201015
+ },
201016
+ children: []
201017
+ }
201018
+ ];
201019
+ node3.children = [];
201020
+ }
201021
+ });
201022
+ };
201023
+ };
201024
+
200867
201025
  // src/process.ts
200868
201026
  var remark = (ctx) => {
200869
201027
  i18n.init(ctx.config.language || "en");
@@ -200902,6 +201060,8 @@ var remark = (ctx) => {
200902
201060
  remarkDirectiveExcalidraw_default(ctx),
200903
201061
  remarkDirectiveStruktog_default(ctx),
200904
201062
  remarkDirectiveStruktolab_default(ctx),
201063
+ remarkDirectiveBlockflowPlayer_default(ctx),
201064
+ remarkDirectiveBlockflowEditor_default(ctx),
200905
201065
  remarkDirectiveGeogebra_default(ctx),
200906
201066
  remarkDirectiveH5P_default(ctx),
200907
201067
  remarkDirectiveJSXGraph_default(ctx),
@@ -201024,7 +201184,7 @@ module.exports = /*#__PURE__*/JSON.parse('{"application/1d-interleaved-parityfec
201024
201184
  /***/ ((module) => {
201025
201185
 
201026
201186
  "use strict";
201027
- module.exports = /*#__PURE__*/JSON.parse('{"name":"hyperbook","version":"0.86.4","author":"Mike Barkmin","homepage":"https://github.com/openpatch/hyperbook#readme","license":"MIT","bin":{"hyperbook":"./dist/index.js"},"files":["dist"],"publishConfig":{"access":"public"},"repository":{"type":"git","url":"git+https://github.com/openpatch/hyperbook.git","directory":"packages/hyperbook"},"bugs":{"url":"https://github.com/openpatch/hyperbook/issues"},"engines":{"node":">=18"},"scripts":{"version":"pnpm build","lint":"tsc --noEmit","dev":"ncc build ./index.ts -w -o dist/","build":"rimraf dist && ncc build ./index.ts -o ./dist/ --no-cache --no-source-map-register --external favicons --external sharp && node postbuild.mjs"},"dependencies":{"favicons":"^7.2.0"},"devDependencies":{"create-hyperbook":"workspace:*","@hyperbook/fs":"workspace:*","@hyperbook/markdown":"workspace:*","@hyperbook/types":"workspace:*","@pnpm/exportable-manifest":"1000.0.6","@types/archiver":"6.0.3","@types/async-retry":"1.4.9","@types/cross-spawn":"6.0.6","@types/lunr":"^2.3.7","@types/prompts":"2.4.9","@types/tar":"6.1.13","@types/ws":"^8.5.14","@vercel/ncc":"0.38.3","archiver":"7.0.1","async-retry":"1.3.3","chalk":"5.4.1","chokidar":"4.0.3","commander":"12.1.0","cpy":"11.1.0","cross-spawn":"7.0.6","domutils":"^3.2.2","extract-zip":"^2.0.1","got":"12.6.0","htmlparser2":"^10.0.0","lunr":"^2.3.9","lunr-languages":"^1.14.0","mime":"^4.0.6","prompts":"2.4.2","rimraf":"6.0.1","tar":"7.4.3","update-check":"1.5.4","ws":"^8.18.0"}}');
201187
+ module.exports = /*#__PURE__*/JSON.parse('{"name":"hyperbook","version":"0.87.0","author":"Mike Barkmin","homepage":"https://github.com/openpatch/hyperbook#readme","license":"MIT","bin":{"hyperbook":"./dist/index.js"},"files":["dist"],"publishConfig":{"access":"public"},"repository":{"type":"git","url":"git+https://github.com/openpatch/hyperbook.git","directory":"packages/hyperbook"},"bugs":{"url":"https://github.com/openpatch/hyperbook/issues"},"engines":{"node":">=18"},"scripts":{"version":"pnpm build","lint":"tsc --noEmit","dev":"ncc build ./index.ts -w -o dist/","build":"rimraf dist && ncc build ./index.ts -o ./dist/ --no-cache --no-source-map-register --external favicons --external sharp && node postbuild.mjs"},"dependencies":{"favicons":"^7.2.0"},"devDependencies":{"create-hyperbook":"workspace:*","@hyperbook/fs":"workspace:*","@hyperbook/markdown":"workspace:*","@hyperbook/types":"workspace:*","@pnpm/exportable-manifest":"1000.0.6","@types/archiver":"6.0.3","@types/async-retry":"1.4.9","@types/cross-spawn":"6.0.6","@types/lunr":"^2.3.7","@types/prompts":"2.4.9","@types/tar":"6.1.13","@types/ws":"^8.5.14","@vercel/ncc":"0.38.3","archiver":"7.0.1","async-retry":"1.3.3","chalk":"5.4.1","chokidar":"4.0.3","commander":"12.1.0","cpy":"11.1.0","cross-spawn":"7.0.6","domutils":"^3.2.2","extract-zip":"^2.0.1","got":"12.6.0","htmlparser2":"^10.0.0","lunr":"^2.3.9","lunr-languages":"^1.14.0","mime":"^4.0.6","prompts":"2.4.2","rimraf":"6.0.1","tar":"7.4.3","update-check":"1.5.4","ws":"^8.18.0"}}');
201028
201188
 
201029
201189
  /***/ })
201030
201190
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hyperbook",
3
- "version": "0.86.4",
3
+ "version": "0.87.0",
4
4
  "author": "Mike Barkmin",
5
5
  "homepage": "https://github.com/openpatch/hyperbook#readme",
6
6
  "license": "MIT",
@@ -56,10 +56,10 @@
56
56
  "tar": "7.4.3",
57
57
  "update-check": "1.5.4",
58
58
  "ws": "^8.18.0",
59
- "@hyperbook/types": "0.22.1",
60
- "@hyperbook/markdown": "0.58.4",
61
- "@hyperbook/fs": "0.24.2",
62
- "create-hyperbook": "0.3.5"
59
+ "create-hyperbook": "0.3.5",
60
+ "@hyperbook/fs": "0.25.0",
61
+ "@hyperbook/markdown": "0.59.0",
62
+ "@hyperbook/types": "0.22.1"
63
63
  },
64
64
  "scripts": {
65
65
  "version": "pnpm build",