@dirwell/theme-ledger 0.0.2 → 0.0.3

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/index.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { a as ThemeAction, c as ThemeLabels, i as ThemePage, o as ThemeColumn, s as ThemeCustomization, t as FrameworkRenderer } from "./model-BgCmoksr.mjs";
1
+ import { a as ThemeAction, c as ThemeLabels, i as ThemePage, o as ThemeColumn, s as ThemeCustomization, t as FrameworkRenderer } from "./model-CeW-leLg.mjs";
2
2
  import { ExplorerTheme } from "@dirwell/core";
3
3
  //#region src/index.d.ts
4
4
  export interface LedgerThemeOptions extends ThemeCustomization {
package/dist/index.mjs CHANGED
@@ -1,7 +1,6 @@
1
1
  import { readFile } from "node:fs/promises";
2
2
  import { createHash } from "node:crypto";
3
3
  import { copyJsonObject, escapeHtml, projectListingEntry } from "@dirwell/core";
4
- import path from "node:path";
5
4
  import { render } from "svelte/server";
6
5
  import * as $ from "svelte/internal/server";
7
6
  import { onMount, tick, untrack } from "svelte";
@@ -10,20 +9,9 @@ import { ListingDataError, loadListing, parseListingEntries } from "@dirwell/cor
10
9
  const pageAsset = (theme, directory, page = 1) => `${theme}-page-${createHash("sha256").update(directory).digest("hex").slice(0, 24)}-${page}.json`;
11
10
  function folderDataHref(entry, context, theme) {
12
11
  if (entry.exitsExplorer || entry.href === null || !(entry.kind === "directory" || entry.link?.targetKind === "directory")) return null;
13
- const fake = "https://dirwell.invalid/";
14
- const base = new URL(context.documentBaseHref ?? `${context.directoryPath ? context.directoryPath + "/" : ""}`, fake);
15
- const root = new URL(context.hrefForDirectory(""), base);
16
- const target = new URL(entry.href, base);
17
- const rootPath = root.pathname.endsWith("/") ? root.pathname : root.pathname.slice(0, root.pathname.lastIndexOf("/") + 1);
18
- const directoryPath = target.pathname.endsWith("/") ? target.pathname : target.pathname.slice(0, target.pathname.lastIndexOf("/") + 1);
19
- const logical = directoryPath.slice(rootPath.length).split("/").filter(Boolean).map(decodeURIComponent).join("/");
20
- const filename = pageAsset(theme, logical);
21
- if (context.pageDataHref !== void 0) return context.pageDataHref(theme, logical, 1);
22
- if (context.mode === "mpa") return context.assetHref(filename);
23
- const href = new URL(filename, new URL(directoryPath, target));
24
- if (href.origin !== new URL(fake).origin) return href.href;
25
- if (context.documentBaseHref === null && !entry.href.startsWith("/")) return path.posix.relative(context.directoryPath || ".", path.posix.join(logical, filename)).split("/").map((segment) => segment === ".." || segment === "." ? segment : encodeURIComponent(segment)).join("/");
26
- return href.pathname;
12
+ const logical = context.directoryPathForEntry(entry.id);
13
+ if (logical === null) return null;
14
+ return context.pageDataHref?.(theme, logical, 1) ?? context.assetHrefForDirectory(logical, pageAsset(theme, logical));
27
15
  }
28
16
  function createThemePage(context, theme, title) {
29
17
  const directoryPath = context.directory.current.relativePath;
@@ -32,20 +20,13 @@ function createThemePage(context, theme, title) {
32
20
  mode: context.mode,
33
21
  outputName: context.outputName,
34
22
  assetHref: context.assetHref,
23
+ assetHrefForDirectory: context.assetHrefForDirectory,
24
+ directoryPathForEntry: context.directoryPathForEntry,
35
25
  hrefForDirectory: context.hrefForDirectory,
36
26
  documentBaseHref: context.documentBaseHref,
37
27
  directoryPath
38
28
  };
39
- const dataForDirectory = (logicalPath) => context.hasPageForDirectory?.(logicalPath) === false ? null : folderDataHref({
40
- id: logicalPath,
41
- name: logicalPath,
42
- kind: "directory",
43
- href: context.hrefForDirectory(logicalPath),
44
- exitsExplorer: false,
45
- size: 0,
46
- modifiedAt: "",
47
- link: null
48
- }, safeContext, theme.name);
29
+ const dataForDirectory = (logicalPath) => context.hasPageForDirectory?.(logicalPath) === false ? null : context.pageDataHref?.(theme.name, logicalPath, 1) ?? context.assetHrefForDirectory(logicalPath, pageAsset(theme.name, logicalPath));
49
30
  const entries = context.directory.entries.map((entry) => {
50
31
  const record = projectListingEntry(entry, context);
51
32
  return theme.entryData === void 0 ? record : {
@@ -762,10 +743,6 @@ function Ledger($$renderer, $$props) {
762
743
  }, viewDefaults(model));
763
744
  }
764
745
  const isDirectory = directoryLike;
765
- function safeHref(record) {
766
- if (typeof location !== "undefined" && location.protocol === "file:" && isDirectory(record) && !record.exitsExplorer && record.href?.endsWith("/")) return record.href + "index.html";
767
- return record.href;
768
- }
769
746
  async function hydrateData() {
770
747
  if (complete() || !model.manifestHref || location.protocol === "file:") return;
771
748
  const local = abort, token = navigation;
@@ -1005,7 +982,7 @@ function Ledger($$renderer, $$props) {
1005
982
  if (column === "name") {
1006
983
  $$renderer.push(`<!--[0--><span class="identity">`);
1007
984
  if (entry.href) {
1008
- $$renderer.push(`<!--[0--><a class="name"${$.attr("href", safeHref(entry))}${$.attr("target", entry.exitsExplorer ? "_blank" : void 0)}${$.attr("rel", entry.exitsExplorer ? "noopener" : void 0)}>`);
985
+ $$renderer.push(`<!--[0--><a class="name"${$.attr("href", entry.href)}${$.attr("target", entry.exitsExplorer ? "_blank" : void 0)}${$.attr("rel", entry.exitsExplorer ? "noopener" : void 0)}>`);
1009
986
  if (row) {
1010
987
  $$renderer.push("<!--[0-->");
1011
988
  row($$renderer, {
@@ -1054,7 +1031,7 @@ function Ledger($$renderer, $$props) {
1054
1031
  const each_array_5 = $.ensure_array_like(ui().actions);
1055
1032
  for (let $$index_4 = 0, $$length = each_array_5.length; $$index_4 < $$length; $$index_4++) {
1056
1033
  let action = each_array_5[$$index_4];
1057
- if (action === "download" && entry.href && !isDirectory(entry) && !entry.link?.unavailable) $$renderer.push(`<!--[0--><a${$.attr("href", safeHref(entry))} download="">${$.escape(ui().labels.download)}</a>`);
1034
+ if (action === "download" && entry.href && !isDirectory(entry) && !entry.link?.unavailable) $$renderer.push(`<!--[0--><a${$.attr("href", entry.href)} download="">${$.escape(ui().labels.download)}</a>`);
1058
1035
  else if (action !== "download") $$renderer.push(`<!--[1--><button${$.attr("disabled", !ready || action === "copy-link" && !entry.href, true)}${$.attr("aria-label", (action === "copy-link" ? ui().labels.copyLink : ui().labels.copyPath) + ": " + entry.name)}>${$.escape(action === "copy-link" ? ui().labels.copyLink : ui().labels.copyPath)}</button>`);
1059
1036
  else $$renderer.push("<!--[-1-->");
1060
1037
  $$renderer.push(`<!--]-->`);