@mokup/shared 1.0.2 → 1.1.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.
package/dist/chokidar.cjs CHANGED
@@ -1,7 +1,5 @@
1
1
  'use strict';
2
2
 
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
3
  const chokidar = require('chokidar');
6
4
 
7
5
  function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
@@ -10,14 +8,4 @@ const chokidar__default = /*#__PURE__*/_interopDefaultCompat(chokidar);
10
8
 
11
9
 
12
10
 
13
- exports.default = chokidar__default;
14
- Object.prototype.hasOwnProperty.call(chokidar, '__proto__') &&
15
- !Object.prototype.hasOwnProperty.call(exports, '__proto__') &&
16
- Object.defineProperty(exports, '__proto__', {
17
- enumerable: true,
18
- value: chokidar['__proto__']
19
- });
20
-
21
- Object.keys(chokidar).forEach(function (k) {
22
- if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) exports[k] = chokidar[k];
23
- });
11
+ module.exports = chokidar__default;
package/dist/chokidar.mjs CHANGED
@@ -1,2 +1 @@
1
- export * from 'chokidar';
2
1
  export { default } from 'chokidar';
package/dist/index.d.cts CHANGED
@@ -81,6 +81,12 @@ type PlaygroundOptionsInput = boolean | {
81
81
  * @default "/__mokup"
82
82
  */
83
83
  path?: string;
84
+ /**
85
+ * Emit playground assets during production builds.
86
+ *
87
+ * @default false
88
+ */
89
+ build?: boolean;
84
90
  /**
85
91
  * Enable or disable the playground routes.
86
92
  *
package/dist/index.d.mts CHANGED
@@ -81,6 +81,12 @@ type PlaygroundOptionsInput = boolean | {
81
81
  * @default "/__mokup"
82
82
  */
83
83
  path?: string;
84
+ /**
85
+ * Emit playground assets during production builds.
86
+ *
87
+ * @default false
88
+ */
89
+ build?: boolean;
84
90
  /**
85
91
  * Enable or disable the playground routes.
86
92
  *
package/dist/index.d.ts CHANGED
@@ -81,6 +81,12 @@ type PlaygroundOptionsInput = boolean | {
81
81
  * @default "/__mokup"
82
82
  */
83
83
  path?: string;
84
+ /**
85
+ * Emit playground assets during production builds.
86
+ *
87
+ * @default false
88
+ */
89
+ build?: boolean;
84
90
  /**
85
91
  * Enable or disable the playground routes.
86
92
  *
@@ -0,0 +1,57 @@
1
+ 'use strict';
2
+
3
+ const node_process = require('node:process');
4
+ const pathe = require('pathe');
5
+
6
+ function isWindowsLikePath(normalized) {
7
+ return node_process.platform === "win32" || /^[a-z]:\//i.test(normalized) || normalized.startsWith("//");
8
+ }
9
+ function toPosix(value) {
10
+ return value.replace(/\\/g, "/");
11
+ }
12
+ function normalizePath(value) {
13
+ return pathe.normalize(toPosix(value));
14
+ }
15
+ function normalizePathForComparison(value) {
16
+ const normalized = normalizePath(value);
17
+ return isWindowsLikePath(normalized) ? normalized.toLowerCase() : normalized;
18
+ }
19
+ function isInDirs(file, dirs) {
20
+ const normalized = normalizePathForComparison(file);
21
+ return dirs.some((dir) => {
22
+ const normalizedDir = normalizePathForComparison(dir).replace(/\/$/, "");
23
+ return normalized === normalizedDir || normalized.startsWith(`${normalizedDir}/`);
24
+ });
25
+ }
26
+ function testPatterns(patterns, value) {
27
+ const list = Array.isArray(patterns) ? patterns : [patterns];
28
+ return list.some((pattern) => pattern.test(value));
29
+ }
30
+ function matchesFilter(file, include, exclude) {
31
+ const normalized = normalizePathForComparison(file);
32
+ if (exclude && testPatterns(exclude, normalized)) {
33
+ return false;
34
+ }
35
+ if (include) {
36
+ return testPatterns(include, normalized);
37
+ }
38
+ return true;
39
+ }
40
+ function hasIgnoredPrefix(file, rootDir, prefixes) {
41
+ if (prefixes.length === 0) {
42
+ return false;
43
+ }
44
+ const normalizedRoot = normalizePathForComparison(rootDir);
45
+ const normalizedFile = normalizePathForComparison(file);
46
+ const relativePath = toPosix(pathe.relative(normalizedRoot, normalizedFile));
47
+ const segments = relativePath.split("/");
48
+ return segments.some(
49
+ (segment) => prefixes.some((prefix) => segment.startsWith(prefix))
50
+ );
51
+ }
52
+
53
+ exports.hasIgnoredPrefix = hasIgnoredPrefix;
54
+ exports.isInDirs = isInDirs;
55
+ exports.matchesFilter = matchesFilter;
56
+ exports.normalizePathForComparison = normalizePathForComparison;
57
+ exports.toPosix = toPosix;
@@ -0,0 +1,7 @@
1
+ declare function toPosix(value: string): string;
2
+ declare function normalizePathForComparison(value: string): string;
3
+ declare function isInDirs(file: string, dirs: string[]): boolean;
4
+ declare function matchesFilter(file: string, include?: RegExp | RegExp[], exclude?: RegExp | RegExp[]): boolean;
5
+ declare function hasIgnoredPrefix(file: string, rootDir: string, prefixes: string[]): boolean;
6
+
7
+ export { hasIgnoredPrefix, isInDirs, matchesFilter, normalizePathForComparison, toPosix };
@@ -0,0 +1,7 @@
1
+ declare function toPosix(value: string): string;
2
+ declare function normalizePathForComparison(value: string): string;
3
+ declare function isInDirs(file: string, dirs: string[]): boolean;
4
+ declare function matchesFilter(file: string, include?: RegExp | RegExp[], exclude?: RegExp | RegExp[]): boolean;
5
+ declare function hasIgnoredPrefix(file: string, rootDir: string, prefixes: string[]): boolean;
6
+
7
+ export { hasIgnoredPrefix, isInDirs, matchesFilter, normalizePathForComparison, toPosix };
@@ -0,0 +1,7 @@
1
+ declare function toPosix(value: string): string;
2
+ declare function normalizePathForComparison(value: string): string;
3
+ declare function isInDirs(file: string, dirs: string[]): boolean;
4
+ declare function matchesFilter(file: string, include?: RegExp | RegExp[], exclude?: RegExp | RegExp[]): boolean;
5
+ declare function hasIgnoredPrefix(file: string, rootDir: string, prefixes: string[]): boolean;
6
+
7
+ export { hasIgnoredPrefix, isInDirs, matchesFilter, normalizePathForComparison, toPosix };
@@ -0,0 +1,51 @@
1
+ import { platform } from 'node:process';
2
+ import { relative, normalize } from 'pathe';
3
+
4
+ function isWindowsLikePath(normalized) {
5
+ return platform === "win32" || /^[a-z]:\//i.test(normalized) || normalized.startsWith("//");
6
+ }
7
+ function toPosix(value) {
8
+ return value.replace(/\\/g, "/");
9
+ }
10
+ function normalizePath(value) {
11
+ return normalize(toPosix(value));
12
+ }
13
+ function normalizePathForComparison(value) {
14
+ const normalized = normalizePath(value);
15
+ return isWindowsLikePath(normalized) ? normalized.toLowerCase() : normalized;
16
+ }
17
+ function isInDirs(file, dirs) {
18
+ const normalized = normalizePathForComparison(file);
19
+ return dirs.some((dir) => {
20
+ const normalizedDir = normalizePathForComparison(dir).replace(/\/$/, "");
21
+ return normalized === normalizedDir || normalized.startsWith(`${normalizedDir}/`);
22
+ });
23
+ }
24
+ function testPatterns(patterns, value) {
25
+ const list = Array.isArray(patterns) ? patterns : [patterns];
26
+ return list.some((pattern) => pattern.test(value));
27
+ }
28
+ function matchesFilter(file, include, exclude) {
29
+ const normalized = normalizePathForComparison(file);
30
+ if (exclude && testPatterns(exclude, normalized)) {
31
+ return false;
32
+ }
33
+ if (include) {
34
+ return testPatterns(include, normalized);
35
+ }
36
+ return true;
37
+ }
38
+ function hasIgnoredPrefix(file, rootDir, prefixes) {
39
+ if (prefixes.length === 0) {
40
+ return false;
41
+ }
42
+ const normalizedRoot = normalizePathForComparison(rootDir);
43
+ const normalizedFile = normalizePathForComparison(file);
44
+ const relativePath = toPosix(relative(normalizedRoot, normalizedFile));
45
+ const segments = relativePath.split("/");
46
+ return segments.some(
47
+ (segment) => prefixes.some((prefix) => segment.startsWith(prefix))
48
+ );
49
+ }
50
+
51
+ export { hasIgnoredPrefix, isInDirs, matchesFilter, normalizePathForComparison, toPosix };
@@ -0,0 +1,95 @@
1
+ 'use strict';
2
+
3
+ const node_process = require('node:process');
4
+ const pathe = require('pathe');
5
+ const pathUtils = require('./path-utils.cjs');
6
+
7
+ function normalizePath(value) {
8
+ return pathe.normalize(pathUtils.toPosix(value));
9
+ }
10
+ function isAncestor(parent, child) {
11
+ const normalizedParent = pathUtils.normalizePathForComparison(parent).replace(/\/$/, "");
12
+ const normalizedChild = pathUtils.normalizePathForComparison(child);
13
+ return normalizedChild === normalizedParent || normalizedChild.startsWith(`${normalizedParent}/`);
14
+ }
15
+ function resolveGroupRoot(dirs, serverRoot) {
16
+ if (!dirs || dirs.length === 0) {
17
+ return serverRoot ?? node_process.cwd();
18
+ }
19
+ if (serverRoot) {
20
+ const normalizedRoot = normalizePath(serverRoot);
21
+ const canUseRoot = dirs.every((dir) => isAncestor(normalizedRoot, dir));
22
+ if (canUseRoot) {
23
+ return normalizedRoot;
24
+ }
25
+ }
26
+ if (dirs.length === 1) {
27
+ return normalizePath(pathe.dirname(dirs[0]));
28
+ }
29
+ let common = normalizePath(dirs[0]);
30
+ for (const dir of dirs.slice(1)) {
31
+ const normalizedDir = normalizePath(dir);
32
+ while (common && !isAncestor(common, normalizedDir)) {
33
+ const parent = normalizePath(pathe.dirname(common));
34
+ if (parent === common) {
35
+ break;
36
+ }
37
+ common = parent;
38
+ }
39
+ }
40
+ if (!common || common === "/") {
41
+ return serverRoot ?? node_process.cwd();
42
+ }
43
+ return common;
44
+ }
45
+ function resolveGroups(dirs, root) {
46
+ const groups = [];
47
+ const seen = /* @__PURE__ */ new Set();
48
+ for (const dir of dirs) {
49
+ const normalized = normalizePath(dir);
50
+ const compareKey = pathUtils.normalizePathForComparison(dir);
51
+ if (seen.has(compareKey)) {
52
+ continue;
53
+ }
54
+ seen.add(compareKey);
55
+ const rel = pathUtils.toPosix(pathe.relative(root, normalized));
56
+ const label = rel && !rel.startsWith("..") ? rel : normalized;
57
+ groups.push({
58
+ key: normalized,
59
+ label,
60
+ path: normalized
61
+ });
62
+ }
63
+ return groups;
64
+ }
65
+ function resolveRouteGroup(routeFile, groups) {
66
+ if (groups.length === 0) {
67
+ return void 0;
68
+ }
69
+ const normalizedFile = pathUtils.normalizePathForComparison(routeFile);
70
+ let matched;
71
+ for (const group of groups) {
72
+ const normalizedGroup = pathUtils.normalizePathForComparison(group.path);
73
+ if (normalizedFile === normalizedGroup || normalizedFile.startsWith(`${normalizedGroup}/`)) {
74
+ if (!matched || group.path.length > matched.path.length) {
75
+ matched = group;
76
+ }
77
+ }
78
+ }
79
+ return matched;
80
+ }
81
+ function formatRouteFile(file, root) {
82
+ if (!root) {
83
+ return pathUtils.toPosix(file);
84
+ }
85
+ const rel = pathUtils.toPosix(pathe.relative(root, file));
86
+ if (!rel || rel.startsWith("..")) {
87
+ return pathUtils.toPosix(file);
88
+ }
89
+ return rel;
90
+ }
91
+
92
+ exports.formatRouteFile = formatRouteFile;
93
+ exports.resolveGroupRoot = resolveGroupRoot;
94
+ exports.resolveGroups = resolveGroups;
95
+ exports.resolveRouteGroup = resolveRouteGroup;
@@ -0,0 +1,12 @@
1
+ interface PlaygroundGroup {
2
+ key: string;
3
+ label: string;
4
+ path: string;
5
+ }
6
+ declare function resolveGroupRoot(dirs: string[], serverRoot?: string): string;
7
+ declare function resolveGroups(dirs: string[], root: string): PlaygroundGroup[];
8
+ declare function resolveRouteGroup(routeFile: string, groups: PlaygroundGroup[]): PlaygroundGroup | undefined;
9
+ declare function formatRouteFile(file: string, root?: string): string;
10
+
11
+ export { formatRouteFile, resolveGroupRoot, resolveGroups, resolveRouteGroup };
12
+ export type { PlaygroundGroup };
@@ -0,0 +1,12 @@
1
+ interface PlaygroundGroup {
2
+ key: string;
3
+ label: string;
4
+ path: string;
5
+ }
6
+ declare function resolveGroupRoot(dirs: string[], serverRoot?: string): string;
7
+ declare function resolveGroups(dirs: string[], root: string): PlaygroundGroup[];
8
+ declare function resolveRouteGroup(routeFile: string, groups: PlaygroundGroup[]): PlaygroundGroup | undefined;
9
+ declare function formatRouteFile(file: string, root?: string): string;
10
+
11
+ export { formatRouteFile, resolveGroupRoot, resolveGroups, resolveRouteGroup };
12
+ export type { PlaygroundGroup };
@@ -0,0 +1,12 @@
1
+ interface PlaygroundGroup {
2
+ key: string;
3
+ label: string;
4
+ path: string;
5
+ }
6
+ declare function resolveGroupRoot(dirs: string[], serverRoot?: string): string;
7
+ declare function resolveGroups(dirs: string[], root: string): PlaygroundGroup[];
8
+ declare function resolveRouteGroup(routeFile: string, groups: PlaygroundGroup[]): PlaygroundGroup | undefined;
9
+ declare function formatRouteFile(file: string, root?: string): string;
10
+
11
+ export { formatRouteFile, resolveGroupRoot, resolveGroups, resolveRouteGroup };
12
+ export type { PlaygroundGroup };
@@ -0,0 +1,90 @@
1
+ import { cwd } from 'node:process';
2
+ import { relative, dirname, normalize } from 'pathe';
3
+ import { toPosix, normalizePathForComparison } from './path-utils.mjs';
4
+
5
+ function normalizePath(value) {
6
+ return normalize(toPosix(value));
7
+ }
8
+ function isAncestor(parent, child) {
9
+ const normalizedParent = normalizePathForComparison(parent).replace(/\/$/, "");
10
+ const normalizedChild = normalizePathForComparison(child);
11
+ return normalizedChild === normalizedParent || normalizedChild.startsWith(`${normalizedParent}/`);
12
+ }
13
+ function resolveGroupRoot(dirs, serverRoot) {
14
+ if (!dirs || dirs.length === 0) {
15
+ return serverRoot ?? cwd();
16
+ }
17
+ if (serverRoot) {
18
+ const normalizedRoot = normalizePath(serverRoot);
19
+ const canUseRoot = dirs.every((dir) => isAncestor(normalizedRoot, dir));
20
+ if (canUseRoot) {
21
+ return normalizedRoot;
22
+ }
23
+ }
24
+ if (dirs.length === 1) {
25
+ return normalizePath(dirname(dirs[0]));
26
+ }
27
+ let common = normalizePath(dirs[0]);
28
+ for (const dir of dirs.slice(1)) {
29
+ const normalizedDir = normalizePath(dir);
30
+ while (common && !isAncestor(common, normalizedDir)) {
31
+ const parent = normalizePath(dirname(common));
32
+ if (parent === common) {
33
+ break;
34
+ }
35
+ common = parent;
36
+ }
37
+ }
38
+ if (!common || common === "/") {
39
+ return serverRoot ?? cwd();
40
+ }
41
+ return common;
42
+ }
43
+ function resolveGroups(dirs, root) {
44
+ const groups = [];
45
+ const seen = /* @__PURE__ */ new Set();
46
+ for (const dir of dirs) {
47
+ const normalized = normalizePath(dir);
48
+ const compareKey = normalizePathForComparison(dir);
49
+ if (seen.has(compareKey)) {
50
+ continue;
51
+ }
52
+ seen.add(compareKey);
53
+ const rel = toPosix(relative(root, normalized));
54
+ const label = rel && !rel.startsWith("..") ? rel : normalized;
55
+ groups.push({
56
+ key: normalized,
57
+ label,
58
+ path: normalized
59
+ });
60
+ }
61
+ return groups;
62
+ }
63
+ function resolveRouteGroup(routeFile, groups) {
64
+ if (groups.length === 0) {
65
+ return void 0;
66
+ }
67
+ const normalizedFile = normalizePathForComparison(routeFile);
68
+ let matched;
69
+ for (const group of groups) {
70
+ const normalizedGroup = normalizePathForComparison(group.path);
71
+ if (normalizedFile === normalizedGroup || normalizedFile.startsWith(`${normalizedGroup}/`)) {
72
+ if (!matched || group.path.length > matched.path.length) {
73
+ matched = group;
74
+ }
75
+ }
76
+ }
77
+ return matched;
78
+ }
79
+ function formatRouteFile(file, root) {
80
+ if (!root) {
81
+ return toPosix(file);
82
+ }
83
+ const rel = toPosix(relative(root, file));
84
+ if (!rel || rel.startsWith("..")) {
85
+ return toPosix(file);
86
+ }
87
+ return rel;
88
+ }
89
+
90
+ export { formatRouteFile, resolveGroupRoot, resolveGroups, resolveRouteGroup };
@@ -0,0 +1,20 @@
1
+ 'use strict';
2
+
3
+ function createDebouncer(delayMs, fn) {
4
+ let timer = null;
5
+ return () => {
6
+ if (timer) {
7
+ clearTimeout(timer);
8
+ }
9
+ timer = setTimeout(() => {
10
+ timer = null;
11
+ fn();
12
+ }, delayMs);
13
+ };
14
+ }
15
+ function delay(ms) {
16
+ return new Promise((resolve) => setTimeout(resolve, ms));
17
+ }
18
+
19
+ exports.createDebouncer = createDebouncer;
20
+ exports.delay = delay;
@@ -0,0 +1,4 @@
1
+ declare function createDebouncer(delayMs: number, fn: () => void): () => void;
2
+ declare function delay(ms: number): Promise<void>;
3
+
4
+ export { createDebouncer, delay };
@@ -0,0 +1,4 @@
1
+ declare function createDebouncer(delayMs: number, fn: () => void): () => void;
2
+ declare function delay(ms: number): Promise<void>;
3
+
4
+ export { createDebouncer, delay };
@@ -0,0 +1,4 @@
1
+ declare function createDebouncer(delayMs: number, fn: () => void): () => void;
2
+ declare function delay(ms: number): Promise<void>;
3
+
4
+ export { createDebouncer, delay };
@@ -0,0 +1,17 @@
1
+ function createDebouncer(delayMs, fn) {
2
+ let timer = null;
3
+ return () => {
4
+ if (timer) {
5
+ clearTimeout(timer);
6
+ }
7
+ timer = setTimeout(() => {
8
+ timer = null;
9
+ fn();
10
+ }, delayMs);
11
+ };
12
+ }
13
+ function delay(ms) {
14
+ return new Promise((resolve) => setTimeout(resolve, ms));
15
+ }
16
+
17
+ export { createDebouncer, delay };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@mokup/shared",
3
3
  "type": "module",
4
- "version": "1.0.2",
4
+ "version": "1.1.1",
5
5
  "description": "Shared dependency exports for mokup.",
6
6
  "license": "MIT",
7
7
  "homepage": "https://mokup.icebreaker.top",
@@ -43,6 +43,21 @@
43
43
  "import": "./dist/pathe.mjs",
44
44
  "require": "./dist/pathe.cjs"
45
45
  },
46
+ "./path-utils": {
47
+ "types": "./dist/path-utils.d.ts",
48
+ "import": "./dist/path-utils.mjs",
49
+ "require": "./dist/path-utils.cjs"
50
+ },
51
+ "./playground-grouping": {
52
+ "types": "./dist/playground-grouping.d.ts",
53
+ "import": "./dist/playground-grouping.mjs",
54
+ "require": "./dist/playground-grouping.cjs"
55
+ },
56
+ "./timing": {
57
+ "types": "./dist/timing.d.ts",
58
+ "import": "./dist/timing.mjs",
59
+ "require": "./dist/timing.cjs"
60
+ },
46
61
  "./jsonc-parser": {
47
62
  "types": "./dist/jsonc-parser.d.ts",
48
63
  "import": "./dist/jsonc-parser.mjs",