hyperbook 0.86.4 → 0.87.1

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,144 @@ 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 siteSrc = ctx.makeUrl(src || "", "public", ctx.navigation.current || void 0);
200906
+ const iframeSrc = src ? `https://blockflow.openpatch.org/player.html?project=${encodeURIComponent(siteSrc)}` : void 0;
200907
+ data.hName = "div";
200908
+ data.hProperties = {
200909
+ class: "directive-blockflow-player",
200910
+ style: `aspect-ratio: ${aspectRatio}; height: ${height}; width: ${width}`
200911
+ };
200912
+ data.hChildren = [
200913
+ {
200914
+ type: "element",
200915
+ tagName: "iframe",
200916
+ properties: {
200917
+ src: iframeSrc,
200918
+ allowfullscreen: true
200919
+ },
200920
+ children: []
200921
+ }
200922
+ ];
200923
+ }
200924
+ });
200925
+ };
200926
+ };
200927
+
200928
+ // src/remarkDirectiveBlockflowEditor.ts
200929
+ var remarkDirectiveBlockflowEditor_default = (ctx) => () => {
200930
+ const name = "blockflow-editor";
200931
+ return (tree, file) => {
200932
+ visit(tree, function(node3) {
200933
+ if (isDirective(node3)) {
200934
+ if (node3.name !== name) return;
200935
+ const data = node3.data || (node3.data = {});
200936
+ expectContainerDirective(node3, file, name);
200937
+ registerDirective(file, name, ["client.js"], ["style.css"], ["step"]);
200938
+ const {
200939
+ title,
200940
+ src,
200941
+ project,
200942
+ width = "100%",
200943
+ height = "700px",
200944
+ aspectRatio,
200945
+ allowExtensions,
200946
+ showCostumesTab,
200947
+ showSoundsTab,
200948
+ categories,
200949
+ ...rest
200950
+ } = node3.attributes || {};
200951
+ let projectParam;
200952
+ if (project) {
200953
+ const projectSrc = ctx.makeUrl(project, "public", ctx.navigation.current || void 0);
200954
+ projectParam = encodeURIComponent(projectSrc);
200955
+ } else {
200956
+ const steps = [];
200957
+ for (const child of node3.children || []) {
200958
+ if (!isDirective(child) || child.name !== "step") continue;
200959
+ const stepAttrs = child.attributes || {};
200960
+ const text9 = toString3(child).trim() || void 0;
200961
+ steps.push({
200962
+ title: stepAttrs.title || void 0,
200963
+ text: text9,
200964
+ image: stepAttrs.image ? ctx.makeUrl(stepAttrs.image, "public", ctx.navigation.current || void 0) : void 0,
200965
+ video: stepAttrs.video ? ctx.makeUrl(stepAttrs.video, "public", ctx.navigation.current || void 0) : void 0
200966
+ });
200967
+ }
200968
+ const config2 = {};
200969
+ if (title) config2.title = title;
200970
+ if (src) config2.sb3 = ctx.makeUrl(src, "public", ctx.navigation.current || void 0);
200971
+ const ui = {};
200972
+ if (allowExtensions !== void 0) {
200973
+ ui.allowExtensions = allowExtensions !== "false";
200974
+ }
200975
+ if (showCostumesTab !== void 0) {
200976
+ ui.showCostumesTab = showCostumesTab !== "false";
200977
+ }
200978
+ if (showSoundsTab !== void 0) {
200979
+ ui.showSoundsTab = showSoundsTab !== "false";
200980
+ }
200981
+ if (Object.keys(ui).length > 0) {
200982
+ config2.ui = ui;
200983
+ }
200984
+ if (categories || Object.keys(rest).some((k) => k.startsWith("blocks-"))) {
200985
+ config2.toolbox = {};
200986
+ if (categories) {
200987
+ config2.toolbox.categories = categories.split(",").map((c) => c.trim());
200988
+ }
200989
+ const blocks2 = {};
200990
+ for (const [key2, value] of Object.entries(rest)) {
200991
+ if (key2.startsWith("blocks-") && value) {
200992
+ const category = key2.slice("blocks-".length);
200993
+ blocks2[category] = value.split(",").map((b) => b.trim());
200994
+ }
200995
+ }
200996
+ if (Object.keys(blocks2).length > 0) {
200997
+ config2.toolbox.blocks = blocks2;
200998
+ }
200999
+ }
201000
+ if (steps.length > 0) config2.steps = steps;
201001
+ const configJson = JSON.stringify(config2);
201002
+ projectParam = Buffer.from(configJson).toString("base64");
201003
+ }
201004
+ const iframeSrc = `https://blockflow.openpatch.org?project=${projectParam}`;
201005
+ data.hName = "div";
201006
+ data.hProperties = {
201007
+ class: "directive-blockflow-editor",
201008
+ style: `aspect-ratio: ${aspectRatio}; height: ${height}; width: ${width}`
201009
+ };
201010
+ data.hChildren = [
201011
+ {
201012
+ type: "element",
201013
+ tagName: "iframe",
201014
+ properties: {
201015
+ src: iframeSrc,
201016
+ allowfullscreen: true
201017
+ },
201018
+ children: []
201019
+ }
201020
+ ];
201021
+ node3.children = [];
201022
+ }
201023
+ });
201024
+ };
201025
+ };
201026
+
200867
201027
  // src/process.ts
200868
201028
  var remark = (ctx) => {
200869
201029
  i18n.init(ctx.config.language || "en");
@@ -200902,6 +201062,8 @@ var remark = (ctx) => {
200902
201062
  remarkDirectiveExcalidraw_default(ctx),
200903
201063
  remarkDirectiveStruktog_default(ctx),
200904
201064
  remarkDirectiveStruktolab_default(ctx),
201065
+ remarkDirectiveBlockflowPlayer_default(ctx),
201066
+ remarkDirectiveBlockflowEditor_default(ctx),
200905
201067
  remarkDirectiveGeogebra_default(ctx),
200906
201068
  remarkDirectiveH5P_default(ctx),
200907
201069
  remarkDirectiveJSXGraph_default(ctx),
@@ -201024,7 +201186,7 @@ module.exports = /*#__PURE__*/JSON.parse('{"application/1d-interleaved-parityfec
201024
201186
  /***/ ((module) => {
201025
201187
 
201026
201188
  "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"}}');
201189
+ module.exports = /*#__PURE__*/JSON.parse('{"name":"hyperbook","version":"0.87.1","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
201190
 
201029
201191
  /***/ })
201030
201192
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hyperbook",
3
- "version": "0.86.4",
3
+ "version": "0.87.1",
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.1",
62
+ "@hyperbook/types": "0.22.1"
63
63
  },
64
64
  "scripts": {
65
65
  "version": "pnpm build",