tanstack-head-controller 0.0.2 → 0.0.4

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.
Files changed (77) hide show
  1. package/dist/configs/index.d.ts +2 -0
  2. package/dist/configs/index.d.ts.map +1 -0
  3. package/dist/configs/index.js +2 -0
  4. package/dist/configs/index.js.map +1 -0
  5. package/dist/configs/type.d.ts +2 -0
  6. package/dist/configs/type.d.ts.map +1 -0
  7. package/dist/configs/type.js +2 -0
  8. package/dist/configs/type.js.map +1 -0
  9. package/dist/context/edit.d.ts +8 -0
  10. package/dist/context/edit.d.ts.map +1 -0
  11. package/dist/context/edit.js +2 -0
  12. package/dist/context/edit.js.map +1 -0
  13. package/dist/context/index.d.ts +2 -0
  14. package/dist/context/index.d.ts.map +1 -0
  15. package/dist/context/index.js +2 -0
  16. package/dist/context/index.js.map +1 -0
  17. package/dist/context/log.d.ts +2 -0
  18. package/dist/context/log.d.ts.map +1 -0
  19. package/dist/context/log.js +2 -0
  20. package/dist/context/log.js.map +1 -0
  21. package/dist/context/safe.d.ts +23 -0
  22. package/dist/context/safe.d.ts.map +1 -0
  23. package/dist/context/safe.js +2 -0
  24. package/dist/context/safe.js.map +1 -0
  25. package/dist/context/type.d.ts +7 -0
  26. package/dist/context/type.d.ts.map +1 -0
  27. package/dist/context/type.js +2 -0
  28. package/dist/context/type.js.map +1 -0
  29. package/dist/controller.d.ts +2 -0
  30. package/dist/controller.d.ts.map +1 -0
  31. package/dist/controller.js +2 -0
  32. package/dist/controller.js.map +1 -0
  33. package/dist/create.d.ts +10 -0
  34. package/dist/create.d.ts.map +1 -0
  35. package/dist/create.js +2 -0
  36. package/dist/create.js.map +1 -0
  37. package/dist/index.d.ts +3 -0
  38. package/dist/index.d.ts.map +1 -0
  39. package/dist/index.js +2 -0
  40. package/dist/index.js.map +1 -0
  41. package/dist/lib/logger.d.ts +3 -0
  42. package/dist/lib/logger.d.ts.map +1 -0
  43. package/dist/lib/logger.js +7 -0
  44. package/dist/lib/logger.js.map +1 -0
  45. package/dist/plugins/apply.d.ts +8 -0
  46. package/dist/plugins/apply.d.ts.map +1 -0
  47. package/dist/plugins/apply.js +2 -0
  48. package/dist/plugins/apply.js.map +1 -0
  49. package/dist/plugins/create.d.ts +3 -0
  50. package/dist/plugins/create.d.ts.map +1 -0
  51. package/dist/plugins/create.js +2 -0
  52. package/dist/plugins/create.js.map +1 -0
  53. package/dist/plugins/index.d.ts +3 -0
  54. package/dist/plugins/index.d.ts.map +1 -0
  55. package/dist/plugins/index.js +2 -0
  56. package/dist/plugins/index.js.map +1 -0
  57. package/dist/plugins/type.d.ts +7 -0
  58. package/dist/plugins/type.d.ts.map +1 -0
  59. package/dist/plugins/type.js +2 -0
  60. package/dist/plugins/type.js.map +1 -0
  61. package/dist/types/head.d.ts +20 -0
  62. package/dist/types/head.d.ts.map +1 -0
  63. package/dist/types/head.js +2 -0
  64. package/dist/types/head.js.map +1 -0
  65. package/dist/types/router.d.ts +5 -0
  66. package/dist/types/router.d.ts.map +1 -0
  67. package/dist/types/router.js +2 -0
  68. package/dist/types/router.js.map +1 -0
  69. package/dist/utils/data.d.ts +22 -0
  70. package/dist/utils/data.d.ts.map +1 -0
  71. package/dist/utils/data.js +2 -0
  72. package/dist/utils/data.js.map +1 -0
  73. package/dist/utils/render.d.ts +10 -0
  74. package/dist/utils/render.d.ts.map +1 -0
  75. package/dist/utils/render.js +2 -0
  76. package/dist/utils/render.js.map +1 -0
  77. package/package.json +1 -1
@@ -0,0 +1,2 @@
1
+ export * from "./type.js";
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/configs/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC"}
@@ -0,0 +1,2 @@
1
+ export*from"./type.js";
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/configs/index.ts"],"sourcesContent":["export * from \"./type.js\";\n"],"names":[],"mappings":"AAAA,WAAc,WAAY"}
@@ -0,0 +1,2 @@
1
+ export type ThcConfigs = Record<string, any>;
2
+ //# sourceMappingURL=type.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"type.d.ts","sourceRoot":"","sources":["../../src/configs/type.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC"}
@@ -0,0 +1,2 @@
1
+ export{};
2
+ //# sourceMappingURL=type.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/configs/type.ts"],"sourcesContent":["export type ThcConfigs = Record<string, any>;\n"],"names":[],"mappings":"AAAA,QAA6C"}
@@ -0,0 +1,8 @@
1
+ import type { ThcConfigs } from "../configs/type.js";
2
+ import type { ThcPlugin } from "../plugins/type.js";
3
+ export interface ContextEditProps {
4
+ configs?: ThcConfigs;
5
+ plugins?: ThcPlugin[];
6
+ }
7
+ export declare const editContext: (ctx: any, props: ContextEditProps) => ContextEditProps;
8
+ //# sourceMappingURL=edit.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"edit.d.ts","sourceRoot":"","sources":["../../src/context/edit.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAKpD,MAAM,WAAW,gBAAgB;IAC/B,OAAO,CAAC,EAAE,UAAU,CAAC;IACrB,OAAO,CAAC,EAAE,SAAS,EAAE,CAAC;CACvB;AACD,eAAO,MAAM,WAAW,GAAI,KAAK,GAAG,EAAE,OAAO,gBAAgB,KAAG,gBAa/D,CAAC"}
@@ -0,0 +1,2 @@
1
+ import{rLogger}from"./log.js";const logger=rLogger.getSubLogger({name:"Edit"});export const editContext=(ctx,props)=>{const result={...ctx,...props,configs:{...ctx.configs,...props.configs}};logger.debug("Context edited",{ctx,props,result});return result};
2
+ //# sourceMappingURL=edit.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/context/edit.ts"],"sourcesContent":["import type { ThcConfigs } from \"../configs/type.js\";\nimport type { ThcPlugin } from \"../plugins/type.js\";\nimport { rLogger } from \"./log.js\";\n\nconst logger = rLogger.getSubLogger({ name: \"Edit\" });\n\nexport interface ContextEditProps {\n configs?: ThcConfigs;\n plugins?: ThcPlugin[];\n}\nexport const editContext = (ctx: any, props: ContextEditProps): ContextEditProps => {\n const result = {\n ...ctx,\n ...props,\n configs: {\n ...ctx.configs,\n ...props.configs,\n },\n };\n\n logger.debug(\"Context edited\", { ctx, props, result });\n\n return result;\n};\n"],"names":["rLogger","logger","getSubLogger","name","editContext","ctx","props","result","configs","debug"],"mappings":"AAEA,OAASA,OAAO,KAAQ,UAAW,CAEnC,MAAMC,OAASD,QAAQE,YAAY,CAAC,CAAEC,KAAM,MAAO,EAMnD,QAAO,MAAMC,YAAc,CAACC,IAAUC,SACpC,MAAMC,OAAS,CACb,GAAGF,GAAG,CACN,GAAGC,KAAK,CACRE,QAAS,CACP,GAAGH,IAAIG,OAAO,CACd,GAAGF,MAAME,OAAO,AAClB,CACF,EAEAP,OAAOQ,KAAK,CAAC,iBAAkB,CAAEJ,IAAKC,MAAOC,MAAO,GAEpD,OAAOA,MACT,CAAE"}
@@ -0,0 +1,2 @@
1
+ export * from "./edit.js";
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/context/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC"}
@@ -0,0 +1,2 @@
1
+ export*from"./edit.js";
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/context/index.ts"],"sourcesContent":["export * from \"./edit.js\";\n"],"names":[],"mappings":"AAAA,WAAc,WAAY"}
@@ -0,0 +1,2 @@
1
+ export declare const rLogger: import("tslog").Logger<unknown>;
2
+ //# sourceMappingURL=log.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"log.d.ts","sourceRoot":"","sources":["../../src/context/log.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,OAAO,iCAA8C,CAAC"}
@@ -0,0 +1,2 @@
1
+ import{cLogger}from"../lib/logger.js";export const rLogger=cLogger().getSubLogger({name:"Context"});
2
+ //# sourceMappingURL=log.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/context/log.ts"],"sourcesContent":["import { cLogger } from \"../lib/logger.js\";\n\nexport const rLogger = cLogger().getSubLogger({ name: \"Context\" });\n"],"names":["cLogger","rLogger","getSubLogger","name"],"mappings":"AAAA,OAASA,OAAO,KAAQ,kBAAmB,AAE3C,QAAO,MAAMC,QAAUD,UAAUE,YAAY,CAAC,CAAEC,KAAM,SAAU,EAAG"}
@@ -0,0 +1,23 @@
1
+ /**
2
+ * このファイルは、`headCtrlrContext` を安全に使用するための機能を提供します。
3
+ *
4
+ * 1. 型が保証された状態でコンテキストを使用できるようにする。
5
+ * 2. コンテキストの構造が変更された場合に、型エラーを通じて問題を早期に発見できるようにする。
6
+ * 3. コンテキストの使用箇所で、必要なプロパティが存在することを保証する。
7
+ */
8
+ import type { headCtrlrContext } from "./type.js";
9
+ /**
10
+ * `headCtrlrContext` を安全に使用するための関数。
11
+ * @param ctx - 使用するルーターコンテキスト
12
+ * @returns `headCtrlrContext` 型のコンテキスト
13
+ * @throws コンテキストが正しい構造を持っていない場合にエラーをスロー
14
+ * @example
15
+ * const safeCtx = useSafeHeadCtrlrContext(ctx)
16
+ * // safeCtx は headCtrlrContext 型であることが保証される
17
+ * console.log(safeCtx.plugins) // plugins プロパティが存在することが保証される
18
+ */
19
+ export interface UseSafeHeadCtrlrContextOptions {
20
+ isThrow?: boolean;
21
+ }
22
+ export declare function useSafeHeadCtrlrContext(ctx: unknown, options?: UseSafeHeadCtrlrContextOptions): headCtrlrContext | null;
23
+ //# sourceMappingURL=safe.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"safe.d.ts","sourceRoot":"","sources":["../../src/context/safe.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAgBlD;;;;;;;;;GASG;AACH,MAAM,WAAW,8BAA8B;IAC7C,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED,wBAAgB,uBAAuB,CACrC,GAAG,EAAE,OAAO,EACZ,OAAO,GAAE,8BAAmC,GAC3C,gBAAgB,GAAG,IAAI,CA6BzB"}
@@ -0,0 +1,2 @@
1
+ import{rLogger}from"./log.js";const logger=rLogger.getSubLogger({name:"Safe"});function isRecord(value){return typeof value==="object"&&value!==null}function isHeadCtrlrContext(value){if(!isRecord(value)){return false}return Array.isArray(value.plugins)}export function useSafeHeadCtrlrContext(ctx,options={}){const{isThrow=true}=options;if(!isRecord(ctx)){if(isThrow){throw logger.error("Invalid context: Context must be an object.",{receivedType:typeof ctx})}return null}if(!("thc"in ctx)){if(isThrow){throw logger.error("Invalid context: Missing 'thc' property.")}return null}const headCtrlr=ctx.thc;if(!isHeadCtrlrContext(headCtrlr)){if(isThrow){throw logger.error("Invalid context: 'headCtrlr.plugins' must be an array.")}return null}return headCtrlr}
2
+ //# sourceMappingURL=safe.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/context/safe.ts"],"sourcesContent":["/**\n * このファイルは、`headCtrlrContext` を安全に使用するための機能を提供します。\n *\n * 1. 型が保証された状態でコンテキストを使用できるようにする。\n * 2. コンテキストの構造が変更された場合に、型エラーを通じて問題を早期に発見できるようにする。\n * 3. コンテキストの使用箇所で、必要なプロパティが存在することを保証する。\n */\n\nimport { rLogger } from \"./log.js\";\nimport type { headCtrlrContext } from \"./type.js\";\n\nconst logger = rLogger.getSubLogger({ name: \"Safe\" });\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === \"object\" && value !== null;\n}\n\nfunction isHeadCtrlrContext(value: unknown): value is headCtrlrContext {\n if (!isRecord(value)) {\n return false;\n }\n\n return Array.isArray(value.plugins);\n}\n\n/**\n * `headCtrlrContext` を安全に使用するための関数。\n * @param ctx - 使用するルーターコンテキスト\n * @returns `headCtrlrContext` 型のコンテキスト\n * @throws コンテキストが正しい構造を持っていない場合にエラーをスロー\n * @example\n * const safeCtx = useSafeHeadCtrlrContext(ctx)\n * // safeCtx は headCtrlrContext 型であることが保証される\n * console.log(safeCtx.plugins) // plugins プロパティが存在することが保証される\n */\nexport interface UseSafeHeadCtrlrContextOptions {\n isThrow?: boolean; // エラーをスローするかどうかのオプション(デフォルトは true)\n}\n\nexport function useSafeHeadCtrlrContext(\n ctx: unknown,\n options: UseSafeHeadCtrlrContextOptions = {}\n): headCtrlrContext | null {\n const { isThrow = true } = options;\n\n if (!isRecord(ctx)) {\n if (isThrow) {\n throw logger.error(\"Invalid context: Context must be an object.\", {\n receivedType: typeof ctx,\n });\n }\n return null;\n }\n\n if (!(\"thc\" in ctx)) {\n if (isThrow) {\n throw logger.error(\"Invalid context: Missing 'thc' property.\");\n }\n return null;\n }\n\n const headCtrlr = ctx.thc;\n\n if (!isHeadCtrlrContext(headCtrlr)) {\n if (isThrow) {\n throw logger.error(\"Invalid context: 'headCtrlr.plugins' must be an array.\");\n }\n return null;\n }\n\n return headCtrlr;\n}\n"],"names":["rLogger","logger","getSubLogger","name","isRecord","value","isHeadCtrlrContext","Array","isArray","plugins","useSafeHeadCtrlrContext","ctx","options","isThrow","error","receivedType","headCtrlr","thc"],"mappings":"AAQA,OAASA,OAAO,KAAQ,UAAW,CAGnC,MAAMC,OAASD,QAAQE,YAAY,CAAC,CAAEC,KAAM,MAAO,GAEnD,SAASC,SAASC,KAAc,EAC9B,OAAO,OAAOA,QAAU,UAAYA,QAAU,IAChD,CAEA,SAASC,mBAAmBD,KAAc,EACxC,GAAI,CAACD,SAASC,OAAQ,CACpB,OAAO,KACT,CAEA,OAAOE,MAAMC,OAAO,CAACH,MAAMI,OAAO,CACpC,CAgBA,OAAO,SAASC,wBACdC,GAAY,CACZC,QAA0C,CAAC,CAAC,EAE5C,KAAM,CAAEC,QAAU,IAAI,CAAE,CAAGD,QAE3B,GAAI,CAACR,SAASO,KAAM,CAClB,GAAIE,QAAS,CACX,MAAMZ,OAAOa,KAAK,CAAC,8CAA+C,CAChEC,aAAc,OAAOJ,GACvB,EACF,CACA,OAAO,IACT,CAEA,GAAI,CAAE,CAAA,QAASA,GAAE,EAAI,CACnB,GAAIE,QAAS,CACX,MAAMZ,OAAOa,KAAK,CAAC,2CACrB,CACA,OAAO,IACT,CAEA,MAAME,UAAYL,IAAIM,GAAG,CAEzB,GAAI,CAACX,mBAAmBU,WAAY,CAClC,GAAIH,QAAS,CACX,MAAMZ,OAAOa,KAAK,CAAC,yDACrB,CACA,OAAO,IACT,CAEA,OAAOE,SACT"}
@@ -0,0 +1,7 @@
1
+ import type { ThcConfigs } from "../configs/type.js";
2
+ import type { ThcPlugin } from "../plugins/type.js";
3
+ export type headCtrlrContext = {
4
+ configs: ThcConfigs;
5
+ plugins: ThcPlugin[];
6
+ };
7
+ //# sourceMappingURL=type.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"type.d.ts","sourceRoot":"","sources":["../../src/context/type.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAEpD,MAAM,MAAM,gBAAgB,GAAG;IAC7B,OAAO,EAAE,UAAU,CAAC;IACpB,OAAO,EAAE,SAAS,EAAE,CAAC;CACtB,CAAC"}
@@ -0,0 +1,2 @@
1
+ export{};
2
+ //# sourceMappingURL=type.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/context/type.ts"],"sourcesContent":["import type { ThcConfigs } from \"../configs/type.js\";\nimport type { ThcPlugin } from \"../plugins/type.js\";\n\nexport type headCtrlrContext = {\n configs: ThcConfigs;\n plugins: ThcPlugin[];\n};\n"],"names":[],"mappings":"AAGA,QAGE"}
@@ -0,0 +1,2 @@
1
+ export declare const HeadControllerRender: () => import("react/jsx-runtime").JSX.Element;
2
+ //# sourceMappingURL=controller.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"controller.d.ts","sourceRoot":"","sources":["../src/controller.tsx"],"names":[],"mappings":"AAUA,eAAO,MAAM,oBAAoB,+CA+BhC,CAAC"}
@@ -0,0 +1,2 @@
1
+ import{jsx as _jsx}from"react/jsx-runtime";import{useRouterState}from"@tanstack/react-router";import{useSafeHeadCtrlrContext}from"./context/safe.js";import{cLogger}from"./lib/logger.js";import{applyPlugins}from"./plugins/apply.js";import{collectHeadDataFromRoutes}from"./utils/data.js";import{HeadRender}from"./utils/render.js";const logger=cLogger().getSubLogger({name:"Controller"});export const HeadControllerRender=()=>{const routes=useRouterState({select:s=>s.matches});const resolvedHead=collectHeadDataFromRoutes(routes);const currentRouteData=[...routes].reverse().find(d=>d);const currentContext=useSafeHeadCtrlrContext(currentRouteData?.context);if(!currentContext){logger.warn("No valid context found for the current route.");return _jsx(HeadRender,{head:resolvedHead})}const finalHead=applyPlugins({head:resolvedHead,ctx:currentContext});return _jsx(HeadRender,{head:finalHead})};
2
+ //# sourceMappingURL=controller.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/controller.tsx"],"sourcesContent":["import { useRouterState } from \"@tanstack/react-router\";\nimport { useSafeHeadCtrlrContext } from \"./context/safe.js\";\nimport { cLogger } from \"./lib/logger.js\";\nimport { applyPlugins } from \"./plugins/apply.js\";\nimport { collectHeadDataFromRoutes } from \"./utils/data.js\";\nimport { HeadRender } from \"./utils/render.js\";\n\n// Loggerの初期化\nconst logger = cLogger().getSubLogger({ name: \"Controller\" });\n\nexport const HeadControllerRender = () => {\n // ルーターの状態を取得\n const routes = useRouterState({ select: (s) => s.matches });\n\n // ルートからheadデータを収集\n const resolvedHead = collectHeadDataFromRoutes(routes);\n\n // 現在のルート情報\n const currentRouteData = [...routes].reverse().find((d) => d);\n\n // logger.info(\"Resolved Head from Routes:\", { resolvedHead, ctx: currentRouteData?.context });\n\n // 現在のルートのコンテキストを安全に取得\n const currentContext = useSafeHeadCtrlrContext(currentRouteData?.context);\n\n // もしコンテキストが取得できない場合は、警告を出力して、HeadRenderを返す\n if (!currentContext) {\n logger.warn(\"No valid context found for the current route.\");\n return <HeadRender head={resolvedHead} />;\n }\n\n // ログ出力\n // logger.info(\"Current Route:\", { pathname: currentRouteData?.pathname, resolvedHead });\n\n // プラグインの適用\n const finalHead = applyPlugins({ head: resolvedHead, ctx: currentContext });\n\n // ログ出力\n // logger.info(\"Final Head:\", { finalHead });\n\n return <HeadRender head={finalHead} />;\n};\n"],"names":["useRouterState","useSafeHeadCtrlrContext","cLogger","applyPlugins","collectHeadDataFromRoutes","HeadRender","logger","getSubLogger","name","HeadControllerRender","routes","select","s","matches","resolvedHead","currentRouteData","reverse","find","d","currentContext","context","warn","head","finalHead","ctx"],"mappings":"0CAAA,QAASA,cAAc,KAAQ,wBAAyB,AACxD,QAASC,uBAAuB,KAAQ,mBAAoB,AAC5D,QAASC,OAAO,KAAQ,iBAAkB,AAC1C,QAASC,YAAY,KAAQ,oBAAqB,AAClD,QAASC,yBAAyB,KAAQ,iBAAkB,AAC5D,QAASC,UAAU,KAAQ,mBAAoB,CAG/C,MAAMC,OAASJ,UAAUK,YAAY,CAAC,CAAEC,KAAM,YAAa,EAE3D,QAAO,MAAMC,qBAAuB,KAElC,MAAMC,OAASV,eAAe,CAAEW,OAAQ,AAACC,GAAMA,EAAEC,OAAO,AAAC,GAGzD,MAAMC,aAAeV,0BAA0BM,QAG/C,MAAMK,iBAAmB,IAAIL,OAAO,CAACM,OAAO,GAAGC,IAAI,CAAC,AAACC,GAAMA,GAK3D,MAAMC,eAAiBlB,wBAAwBc,kBAAkBK,SAGjE,GAAI,CAACD,eAAgB,CACnBb,OAAOe,IAAI,CAAC,iDACZ,OAAO,KAAChB,YAAWiB,KAAMR,cAC3B,CAMA,MAAMS,UAAYpB,aAAa,CAAEmB,KAAMR,aAAcU,IAAKL,cAAe,GAKzE,OAAO,KAACd,YAAWiB,KAAMC,WAC3B,CAAE"}
@@ -0,0 +1,10 @@
1
+ import type { ThcConfigs } from "./configs/type.js";
2
+ import type { ThcPlugin } from "./plugins/type.js";
3
+ export interface CreateHeadControllerOptions {
4
+ configs?: ThcConfigs;
5
+ plugins?: ThcPlugin[];
6
+ }
7
+ export declare const createHeadController: (options?: CreateHeadControllerOptions) => {
8
+ thc: import("./context/edit.js").ContextEditProps;
9
+ };
10
+ //# sourceMappingURL=create.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create.d.ts","sourceRoot":"","sources":["../src/create.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAGpD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAEnD,MAAM,WAAW,2BAA2B;IAC1C,OAAO,CAAC,EAAE,UAAU,CAAC;IACrB,OAAO,CAAC,EAAE,SAAS,EAAE,CAAC;CACvB;AAID,eAAO,MAAM,oBAAoB,GAAI,UAAS,2BAAgC;;CAS7E,CAAC"}
package/dist/create.js ADDED
@@ -0,0 +1,2 @@
1
+ import{editContext}from"./context/edit.js";import{cLogger}from"./lib/logger.js";const logger=cLogger().getSubLogger({name:"Create"});export const createHeadController=(options={})=>{const{configs={},plugins=[]}=options;return{thc:editContext({},{configs,plugins})}};
2
+ //# sourceMappingURL=create.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/create.ts"],"sourcesContent":["import type { ThcConfigs } from \"./configs/type.js\";\nimport { editContext } from \"./context/edit.js\";\nimport { cLogger } from \"./lib/logger.js\";\nimport type { ThcPlugin } from \"./plugins/type.js\";\n\nexport interface CreateHeadControllerOptions {\n configs?: ThcConfigs;\n plugins?: ThcPlugin[];\n}\n\nconst logger = cLogger().getSubLogger({ name: \"Create\" });\n\nexport const createHeadController = (options: CreateHeadControllerOptions = {}) => {\n const { configs = {}, plugins = [] } = options;\n\n // logger.info(\"Initializing head controller with options:\", options);\n // logger.info(\"Registered plugins:\", plugins);\n\n return {\n thc: editContext({}, { configs, plugins }),\n };\n};\n"],"names":["editContext","cLogger","logger","getSubLogger","name","createHeadController","options","configs","plugins","thc"],"mappings":"AACA,OAASA,WAAW,KAAQ,mBAAoB,AAChD,QAASC,OAAO,KAAQ,iBAAkB,CAQ1C,MAAMC,OAASD,UAAUE,YAAY,CAAC,CAAEC,KAAM,QAAS,EAEvD,QAAO,MAAMC,qBAAuB,CAACC,QAAuC,CAAC,CAAC,IAC5E,KAAM,CAAEC,QAAU,CAAC,CAAC,CAAEC,QAAU,EAAE,CAAE,CAAGF,QAKvC,MAAO,CACLG,IAAKT,YAAY,CAAC,EAAG,CAAEO,QAASC,OAAQ,EAC1C,CACF,CAAE"}
@@ -0,0 +1,3 @@
1
+ export * from "./controller.js";
2
+ export * from "./create.js";
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,aAAa,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,2 @@
1
+ export*from"./controller.js";export*from"./create.js";
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["export * from \"./controller.js\";\nexport * from \"./create.js\";\n"],"names":[],"mappings":"AAAA,WAAc,iBAAkB,AAChC,YAAc,aAAc"}
@@ -0,0 +1,3 @@
1
+ import { Logger } from "tslog";
2
+ export declare const cLogger: () => Logger<unknown>;
3
+ //# sourceMappingURL=logger.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../src/lib/logger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAE/B,eAAO,MAAM,OAAO,uBAahB,CAAC"}
@@ -0,0 +1,7 @@
1
+ import{Logger}from"tslog";export const cLogger=()=>new Logger({type:"pretty",name:"THC",prettyLogTemplate:"{{yyyy}}-{{mm}}-{{dd}} {{hh}}:{{MM}}:{{ss}}.{{ms}} {{logLevelName}} {{name}} ",overwrite:{transportFormatted:(logMetaMarkup,logArgs,logErrors)=>{const output=`${logMetaMarkup}${logArgs.map(formatLogArg).join(" ")}${logErrors.length>0?`
2
+ ${logErrors.join("\n")}`:""}`;console.log(output)}}});const useAnsiColors=typeof process!=="undefined"&&process?.versions?.node!=null;const ansi={reset:"\x1b[0m",dim:"\x1b[2m",cyan:"\x1b[36m",green:"\x1b[32m",magenta:"\x1b[35m",yellow:"\x1b[33m",red:"\x1b[31m"};const colorize=(value,color)=>{if(!useAnsiColors){return value}return`${ansi[color]}${value}${ansi.reset}`};const formatLogArg=value=>{if(typeof value==="string"){return colorize(value,"green")}if(value instanceof Error){return value.stack??value.message}if(value==null){return colorize(String(value),"yellow")}return formatPrettyValue(value)};const formatPrettyValue=value=>{const seen=new WeakSet;return formatValue(value,0,seen)};const formatValue=(value,indentLevel,seen)=>{if(value instanceof Error){return value.stack??value.message}if(value instanceof Date){return colorize(`"${value.toISOString()}"`,"green")}if(typeof value==="string"){return colorize(`"${escapeString(value)}"`,"green")}if(typeof value==="number"||typeof value==="boolean"){return colorize(String(value),typeof value==="number"?"cyan":"magenta")}if(typeof value==="bigint"){return colorize(`${value}n`,"cyan")}if(typeof value==="symbol"){return colorize(value.toString(),"magenta")}if(typeof value==="function"){return colorize(`[Function${value.name?`: ${value.name}`:""}]`,"red")}if(value==null){return colorize(String(value),"yellow")}if(typeof value!=="object"){return String(value)}if(seen.has(value)){return colorize("[Circular]","red")}seen.add(value);if(Array.isArray(value)){if(value.length===0){return colorize("[]","dim")}const nextIndent=indentLevel+2;const items=value.map(item=>`${indent(nextIndent)}${formatValue(item,nextIndent,seen)}`);return`${colorize("[","dim")}
3
+ ${items.join(colorize(",","dim")+"\n")}
4
+ ${indent(indentLevel)}${colorize("]","dim")}`}const entries=Object.entries(value);if(entries.length===0){return colorize("{}","dim")}const nextIndent=indentLevel+2;const lines=entries.map(([key,entryValue])=>`${indent(nextIndent)}${colorize(key,"yellow")}: ${formatValue(entryValue,nextIndent,seen)}`);return`${colorize("{","dim")}
5
+ ${lines.join(colorize(",","dim")+"\n")}
6
+ ${indent(indentLevel)}${colorize("}","dim")}`};const indent=size=>" ".repeat(size);const escapeString=value=>value.split("\\").join("\\\\").split('"').join('\\"');
7
+ //# sourceMappingURL=logger.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/lib/logger.ts"],"sourcesContent":["import { Logger } from \"tslog\";\n\nexport const cLogger = () =>\n new Logger({\n type: \"pretty\",\n name: \"THC\",\n prettyLogTemplate:\n \"{{yyyy}}-{{mm}}-{{dd}} {{hh}}:{{MM}}:{{ss}}.{{ms}} {{logLevelName}} {{name}} \",\n overwrite: {\n transportFormatted: (logMetaMarkup, logArgs, logErrors) => {\n const output = `${logMetaMarkup}${logArgs.map(formatLogArg).join(\" \")}${logErrors.length > 0 ? `\\n${logErrors.join(\"\\n\")}` : \"\"}`;\n\n console.log(output);\n },\n },\n });\n\nconst useAnsiColors = typeof process !== \"undefined\" && process?.versions?.node != null;\n\nconst ansi = {\n reset: \"\\u001b[0m\",\n dim: \"\\u001b[2m\",\n cyan: \"\\u001b[36m\",\n green: \"\\u001b[32m\",\n magenta: \"\\u001b[35m\",\n yellow: \"\\u001b[33m\",\n red: \"\\u001b[31m\",\n};\n\nconst colorize = (value: string, color: keyof typeof ansi) => {\n if (!useAnsiColors) {\n return value;\n }\n\n return `${ansi[color]}${value}${ansi.reset}`;\n};\n\nconst formatLogArg = (value: unknown) => {\n if (typeof value === \"string\") {\n return colorize(value, \"green\");\n }\n\n if (value instanceof Error) {\n return value.stack ?? value.message;\n }\n\n if (value == null) {\n return colorize(String(value), \"yellow\");\n }\n\n return formatPrettyValue(value);\n};\n\nconst formatPrettyValue = (value: unknown) => {\n const seen = new WeakSet<object>();\n\n return formatValue(value, 0, seen);\n};\n\nconst formatValue = (value: unknown, indentLevel: number, seen: WeakSet<object>): string => {\n if (value instanceof Error) {\n return value.stack ?? value.message;\n }\n\n if (value instanceof Date) {\n return colorize(`\"${value.toISOString()}\"`, \"green\");\n }\n\n if (typeof value === \"string\") {\n return colorize(`\"${escapeString(value)}\"`, \"green\");\n }\n\n if (typeof value === \"number\" || typeof value === \"boolean\") {\n return colorize(String(value), typeof value === \"number\" ? \"cyan\" : \"magenta\");\n }\n\n if (typeof value === \"bigint\") {\n return colorize(`${value}n`, \"cyan\");\n }\n\n if (typeof value === \"symbol\") {\n return colorize(value.toString(), \"magenta\");\n }\n\n if (typeof value === \"function\") {\n return colorize(`[Function${value.name ? `: ${value.name}` : \"\"}]`, \"red\");\n }\n\n if (value == null) {\n return colorize(String(value), \"yellow\");\n }\n\n if (typeof value !== \"object\") {\n return String(value);\n }\n\n if (seen.has(value)) {\n return colorize(\"[Circular]\", \"red\");\n }\n\n seen.add(value);\n\n if (Array.isArray(value)) {\n if (value.length === 0) {\n return colorize(\"[]\", \"dim\");\n }\n\n const nextIndent = indentLevel + 2;\n const items = value.map(\n (item) => `${indent(nextIndent)}${formatValue(item, nextIndent, seen)}`\n );\n return `${colorize(\"[\", \"dim\")}\\n${items.join(colorize(\",\", \"dim\") + \"\\n\")}\n${indent(indentLevel)}${colorize(\"]\", \"dim\")}`;\n }\n\n const entries = Object.entries(value);\n\n if (entries.length === 0) {\n return colorize(\"{}\", \"dim\");\n }\n\n const nextIndent = indentLevel + 2;\n const lines = entries.map(\n ([key, entryValue]) =>\n `${indent(nextIndent)}${colorize(key, \"yellow\")}: ${formatValue(entryValue, nextIndent, seen)}`\n );\n\n return `${colorize(\"{\", \"dim\")}\\n${lines.join(colorize(\",\", \"dim\") + \"\\n\")}\n${indent(indentLevel)}${colorize(\"}\", \"dim\")}`;\n};\n\nconst indent = (size: number) => \" \".repeat(size);\n\nconst escapeString = (value: string) => value.split(\"\\\\\").join(\"\\\\\\\\\").split('\"').join('\\\\\"');\n"],"names":["Logger","cLogger","type","name","prettyLogTemplate","overwrite","transportFormatted","logMetaMarkup","logArgs","logErrors","output","map","formatLogArg","join","length","console","log","useAnsiColors","process","versions","node","ansi","reset","dim","cyan","green","magenta","yellow","red","colorize","value","color","Error","stack","message","String","formatPrettyValue","seen","WeakSet","formatValue","indentLevel","Date","toISOString","escapeString","toString","has","add","Array","isArray","nextIndent","items","item","indent","entries","Object","lines","key","entryValue","size","repeat","split"],"mappings":"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"}
@@ -0,0 +1,8 @@
1
+ import type { headCtrlrContext } from "../context/type.js";
2
+ import type { Head } from "../types/head.js";
3
+ export interface ApplyPluginsOptions {
4
+ head: Head.index;
5
+ ctx: headCtrlrContext;
6
+ }
7
+ export declare function applyPlugins({ head, ctx }: ApplyPluginsOptions): Head.index;
8
+ //# sourceMappingURL=apply.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"apply.d.ts","sourceRoot":"","sources":["../../src/plugins/apply.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAC3D,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAE7C,MAAM,WAAW,mBAAmB;IAClC,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC;IACjB,GAAG,EAAE,gBAAgB,CAAC;CACvB;AAED,wBAAgB,YAAY,CAAC,EAAE,IAAI,EAAE,GAAG,EAAE,EAAE,mBAAmB,GAAG,IAAI,CAAC,KAAK,CAU3E"}
@@ -0,0 +1,2 @@
1
+ export function applyPlugins({head,ctx}){let result=head;for(const plugin of ctx.plugins){if(plugin.transform){result=plugin.transform(result,ctx)}}return result}
2
+ //# sourceMappingURL=apply.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/plugins/apply.ts"],"sourcesContent":["import type { headCtrlrContext } from \"../context/type.js\";\nimport type { Head } from \"../types/head.js\";\n\nexport interface ApplyPluginsOptions {\n head: Head.index;\n ctx: headCtrlrContext;\n}\n\nexport function applyPlugins({ head, ctx }: ApplyPluginsOptions): Head.index {\n let result = head;\n\n for (const plugin of ctx.plugins) {\n if (plugin.transform) {\n result = plugin.transform(result, ctx);\n }\n }\n\n return result;\n}\n"],"names":["applyPlugins","head","ctx","result","plugin","plugins","transform"],"mappings":"AAQA,OAAO,SAASA,aAAa,CAAEC,IAAI,CAAEC,GAAG,CAAuB,EAC7D,IAAIC,OAASF,KAEb,IAAK,MAAMG,UAAUF,IAAIG,OAAO,CAAE,CAChC,GAAID,OAAOE,SAAS,CAAE,CACpBH,OAASC,OAAOE,SAAS,CAACH,OAAQD,IACpC,CACF,CAEA,OAAOC,MACT"}
@@ -0,0 +1,3 @@
1
+ import type { ThcPlugin } from "./type.js";
2
+ export declare function createThcPlugin(plugin: ThcPlugin): ThcPlugin;
3
+ //# sourceMappingURL=create.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create.d.ts","sourceRoot":"","sources":["../../src/plugins/create.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAE3C,wBAAgB,eAAe,CAAC,MAAM,EAAE,SAAS,GAAG,SAAS,CAE5D"}
@@ -0,0 +1,2 @@
1
+ export function createThcPlugin(plugin){return plugin}
2
+ //# sourceMappingURL=create.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/plugins/create.ts"],"sourcesContent":["import type { ThcPlugin } from \"./type.js\";\n\nexport function createThcPlugin(plugin: ThcPlugin): ThcPlugin {\n return plugin;\n}\n"],"names":["createThcPlugin","plugin"],"mappings":"AAEA,OAAO,SAASA,gBAAgBC,MAAiB,EAC/C,OAAOA,MACT"}
@@ -0,0 +1,3 @@
1
+ export * from "./create.js";
2
+ export * from "./type.js";
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/plugins/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC"}
@@ -0,0 +1,2 @@
1
+ export*from"./create.js";export*from"./type.js";
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/plugins/index.ts"],"sourcesContent":["export * from \"./create.js\";\nexport * from \"./type.js\";\n"],"names":[],"mappings":"AAAA,WAAc,aAAc,AAC5B,YAAc,WAAY"}
@@ -0,0 +1,7 @@
1
+ import type { headCtrlrContext } from "../context/type";
2
+ import type { Head } from "../types/head";
3
+ export type ThcPlugin = {
4
+ name: string;
5
+ transform?: (head: Head.index, ctx: headCtrlrContext) => Head.index;
6
+ };
7
+ //# sourceMappingURL=type.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"type.d.ts","sourceRoot":"","sources":["../../src/plugins/type.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACxD,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AAE1C,MAAM,MAAM,SAAS,GAAG;IACtB,IAAI,EAAE,MAAM,CAAC;IAEb,SAAS,CAAC,EAAE,CAAC,IAAI,EAAE,IAAI,CAAC,KAAK,EAAE,GAAG,EAAE,gBAAgB,KAAK,IAAI,CAAC,KAAK,CAAC;CACrE,CAAC"}
@@ -0,0 +1,2 @@
1
+ export{};
2
+ //# sourceMappingURL=type.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/plugins/type.ts"],"sourcesContent":["import type { headCtrlrContext } from \"../context/type\";\nimport type { Head } from \"../types/head\";\n\nexport type ThcPlugin = {\n name: string;\n\n transform?: (head: Head.index, ctx: headCtrlrContext) => Head.index;\n};\n"],"names":[],"mappings":"AAGA,QAIE"}
@@ -0,0 +1,20 @@
1
+ import type { AnyRouteMatch } from "@tanstack/react-router";
2
+ type __Meta = AnyRouteMatch["meta"];
3
+ type __Links = AnyRouteMatch["links"];
4
+ type __Scripts = AnyRouteMatch["scripts"];
5
+ type __Styles = AnyRouteMatch["styles"];
6
+ type __Head = {
7
+ meta?: __Meta;
8
+ links?: __Links;
9
+ scripts?: __Scripts;
10
+ styles?: __Styles;
11
+ };
12
+ export declare namespace Head {
13
+ type index = __Head;
14
+ type Meta = __Meta;
15
+ type Links = __Links;
16
+ type Scripts = __Scripts;
17
+ type Styles = __Styles;
18
+ }
19
+ export {};
20
+ //# sourceMappingURL=head.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"head.d.ts","sourceRoot":"","sources":["../../src/types/head.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAE5D,KAAK,MAAM,GAAG,aAAa,CAAC,MAAM,CAAC,CAAC;AACpC,KAAK,OAAO,GAAG,aAAa,CAAC,OAAO,CAAC,CAAC;AACtC,KAAK,SAAS,GAAG,aAAa,CAAC,SAAS,CAAC,CAAC;AAC1C,KAAK,QAAQ,GAAG,aAAa,CAAC,QAAQ,CAAC,CAAC;AAExC,KAAK,MAAM,GAAG;IACZ,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,OAAO,CAAC,EAAE,SAAS,CAAC;IACpB,MAAM,CAAC,EAAE,QAAQ,CAAC;CACnB,CAAC;AAEF,yBAAiB,IAAI,CAAC;IACpB,KAAY,KAAK,GAAG,MAAM,CAAC;IAC3B,KAAY,IAAI,GAAG,MAAM,CAAC;IAC1B,KAAY,KAAK,GAAG,OAAO,CAAC;IAC5B,KAAY,OAAO,GAAG,SAAS,CAAC;IAChC,KAAY,MAAM,GAAG,QAAQ,CAAC;CAC/B"}
@@ -0,0 +1,2 @@
1
+ export{};
2
+ //# sourceMappingURL=head.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/types/head.ts"],"sourcesContent":["import type { AnyRouteMatch } from \"@tanstack/react-router\";\n\ntype __Meta = AnyRouteMatch[\"meta\"];\ntype __Links = AnyRouteMatch[\"links\"];\ntype __Scripts = AnyRouteMatch[\"scripts\"];\ntype __Styles = AnyRouteMatch[\"styles\"];\n\ntype __Head = {\n meta?: __Meta;\n links?: __Links;\n scripts?: __Scripts;\n styles?: __Styles;\n};\n\nexport namespace Head {\n export type index = __Head;\n export type Meta = __Meta;\n export type Links = __Links;\n export type Scripts = __Scripts;\n export type Styles = __Styles;\n}\n"],"names":[],"mappings":"AAcA,QAMC"}
@@ -0,0 +1,5 @@
1
+ import type { headCtrlrContext } from "../context/type.js";
2
+ export type THCcontextWithRouter<T> = T & {
3
+ headCtrlr: headCtrlrContext;
4
+ };
5
+ //# sourceMappingURL=router.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"router.d.ts","sourceRoot":"","sources":["../../src/types/router.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAE3D,MAAM,MAAM,oBAAoB,CAAC,CAAC,IAAI,CAAC,GAAG;IACxC,SAAS,EAAE,gBAAgB,CAAC;CAC7B,CAAC"}
@@ -0,0 +1,2 @@
1
+ export{};
2
+ //# sourceMappingURL=router.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/types/router.ts"],"sourcesContent":["import type { headCtrlrContext } from \"../context/type.js\";\n\nexport type THCcontextWithRouter<T> = T & {\n headCtrlr: headCtrlrContext;\n};\n"],"names":[],"mappings":"AAEA,QAEE"}
@@ -0,0 +1,22 @@
1
+ import type { MakeRouteMatchUnion } from "@tanstack/react-router";
2
+ import type { Head } from "../types/head.js";
3
+ /**
4
+ * route の生データから head 情報を収集するためのユーティリティ関数
5
+ *
6
+ * @param routeMatches
7
+ * @returns
8
+ *
9
+ * @example
10
+ * ```ts
11
+ * import { useRouterState } from "@tanstack/react-router";
12
+ * import { collectHeadDataFromRoute } from "@/plugins/head-controller/data";
13
+ *
14
+ * const routeMatches = useRouterState({ select: (s) => s.matches });;
15
+ * const match = [...routeMatches].reverse().find((d) => d);
16
+ *
17
+ * const headData = collectHeadDataFromRoute(match);
18
+ * ```
19
+ */
20
+ export declare function collectHeadDataFromRoute(route?: MakeRouteMatchUnion): Head.index;
21
+ export declare function collectHeadDataFromRoutes(routeMatches: MakeRouteMatchUnion[]): Head.index;
22
+ //# sourceMappingURL=data.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"data.d.ts","sourceRoot":"","sources":["../../src/utils/data.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAClE,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAE7C;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,wBAAwB,CAAC,KAAK,CAAC,EAAE,mBAAmB,GAAG,IAAI,CAAC,KAAK,CAQhF;AAED,wBAAgB,yBAAyB,CAAC,YAAY,EAAE,mBAAmB,EAAE,GAAG,IAAI,CAAC,KAAK,CAQzF"}
@@ -0,0 +1,2 @@
1
+ export function collectHeadDataFromRoute(route){const headData={meta:route?.meta,links:route?.links,styles:route?.styles,scripts:route?.scripts};return headData}export function collectHeadDataFromRoutes(routeMatches){const resolvedHead={meta:routeMatches.flatMap(m=>m.meta??[]),links:routeMatches.flatMap(m=>m.links??[]),styles:routeMatches.flatMap(m=>m.styles??[]),scripts:routeMatches.flatMap(m=>m.headScripts??[])};return resolvedHead}
2
+ //# sourceMappingURL=data.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/utils/data.ts"],"sourcesContent":["import type { MakeRouteMatchUnion } from \"@tanstack/react-router\";\nimport type { Head } from \"../types/head.js\";\n\n/**\n * route の生データから head 情報を収集するためのユーティリティ関数\n *\n * @param routeMatches\n * @returns\n *\n * @example\n * ```ts\n * import { useRouterState } from \"@tanstack/react-router\";\n * import { collectHeadDataFromRoute } from \"@/plugins/head-controller/data\";\n *\n * const routeMatches = useRouterState({ select: (s) => s.matches });;\n * const match = [...routeMatches].reverse().find((d) => d);\n *\n * const headData = collectHeadDataFromRoute(match);\n * ```\n */\nexport function collectHeadDataFromRoute(route?: MakeRouteMatchUnion): Head.index {\n const headData = {\n meta: route?.meta,\n links: route?.links,\n styles: route?.styles,\n scripts: route?.scripts,\n };\n return headData;\n}\n\nexport function collectHeadDataFromRoutes(routeMatches: MakeRouteMatchUnion[]): Head.index {\n const resolvedHead = {\n meta: routeMatches.flatMap((m) => m.meta ?? []),\n links: routeMatches.flatMap((m) => m.links ?? []),\n styles: routeMatches.flatMap((m) => m.styles ?? []),\n scripts: routeMatches.flatMap((m) => m.headScripts ?? []),\n };\n return resolvedHead;\n}\n"],"names":["collectHeadDataFromRoute","route","headData","meta","links","styles","scripts","collectHeadDataFromRoutes","routeMatches","resolvedHead","flatMap","m","headScripts"],"mappings":"AAoBA,OAAO,SAASA,yBAAyBC,KAA2B,EAClE,MAAMC,SAAW,CACfC,KAAMF,OAAOE,KACbC,MAAOH,OAAOG,MACdC,OAAQJ,OAAOI,OACfC,QAASL,OAAOK,OAClB,EACA,OAAOJ,QACT,CAEA,OAAO,SAASK,0BAA0BC,YAAmC,EAC3E,MAAMC,aAAe,CACnBN,KAAMK,aAAaE,OAAO,CAAC,AAACC,GAAMA,EAAER,IAAI,EAAI,EAAE,EAC9CC,MAAOI,aAAaE,OAAO,CAAC,AAACC,GAAMA,EAAEP,KAAK,EAAI,EAAE,EAChDC,OAAQG,aAAaE,OAAO,CAAC,AAACC,GAAMA,EAAEN,MAAM,EAAI,EAAE,EAClDC,QAASE,aAAaE,OAAO,CAAC,AAACC,GAAMA,EAAEC,WAAW,EAAI,EAAE,CAC1D,EACA,OAAOH,YACT"}
@@ -0,0 +1,10 @@
1
+ import type { Head } from "../types/head.js";
2
+ /**
3
+ * ヘッダーのレンダリングコンポーネント
4
+ * @param param0
5
+ * @returns
6
+ */
7
+ export declare const HeadRender: ({ head }: {
8
+ head: Head.index;
9
+ }) => import("react/jsx-runtime").JSX.Element;
10
+ //# sourceMappingURL=render.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"render.d.ts","sourceRoot":"","sources":["../../src/utils/render.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAE7C;;;;GAIG;AACH,eAAO,MAAM,UAAU,GAAI,UAAU;IAAE,IAAI,EAAE,IAAI,CAAC,KAAK,CAAA;CAAE,4CA4BxD,CAAC"}
@@ -0,0 +1,2 @@
1
+ import{jsx as _jsx,jsxs as _jsxs,Fragment as _Fragment}from"react/jsx-runtime";export const HeadRender=({head})=>{const meta=head.meta?.map((meta,index)=>{if(meta?.title){return _jsx("title",{children:meta.title},index)}return _jsx("meta",{...meta},index)});const links=head.links?.map((link,index)=>{return _jsx("link",{...link},index)});const styles=head.styles?.map((style,index)=>{return _jsx("style",{...style},index)});const scripts=head.scripts?.map((script,index)=>{return _jsx("script",{...script},index)});return _jsxs(_Fragment,{children:[meta,links,styles,scripts]})};
2
+ //# sourceMappingURL=render.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/utils/render.tsx"],"sourcesContent":["import type { Head } from \"../types/head.js\";\n\n/**\n * ヘッダーのレンダリングコンポーネント\n * @param param0\n * @returns\n */\nexport const HeadRender = ({ head }: { head: Head.index }) => {\n const meta = head.meta?.map((meta, index) => {\n if (meta?.title) {\n return <title key={index}>{meta.title}</title>;\n }\n return <meta key={index} {...meta} />;\n });\n\n const links = head.links?.map((link, index) => {\n return <link key={index} {...link} />;\n });\n\n const styles = head.styles?.map((style, index) => {\n return <style key={index} {...style} />;\n });\n\n const scripts = head.scripts?.map((script, index) => {\n return <script key={index} {...script} />;\n });\n\n return (\n <>\n {meta}\n {links}\n {styles}\n {scripts}\n </>\n );\n};\n"],"names":["HeadRender","head","meta","map","index","title","links","link","styles","style","scripts","script"],"mappings":"8EAOA,QAAO,MAAMA,WAAa,CAAC,CAAEC,IAAI,CAAwB,IACvD,MAAMC,KAAOD,KAAKC,IAAI,EAAEC,IAAI,CAACD,KAAME,SACjC,GAAIF,MAAMG,MAAO,CACf,OAAO,KAACA,kBAAmBH,KAAKG,KAAK,EAAlBD,MACrB,CACA,OAAO,KAACF,QAAkB,GAAGA,IAAI,EAAfE,MACpB,GAEA,MAAME,MAAQL,KAAKK,KAAK,EAAEH,IAAI,CAACI,KAAMH,SACnC,OAAO,KAACG,QAAkB,GAAGA,IAAI,EAAfH,MACpB,GAEA,MAAMI,OAASP,KAAKO,MAAM,EAAEL,IAAI,CAACM,MAAOL,SACtC,OAAO,KAACK,SAAmB,GAAGA,KAAK,EAAhBL,MACrB,GAEA,MAAMM,QAAUT,KAAKS,OAAO,EAAEP,IAAI,CAACQ,OAAQP,SACzC,OAAO,KAACO,UAAoB,GAAGA,MAAM,EAAjBP,MACtB,GAEA,OACE,2BACGF,KACAI,MACAE,OACAE,UAGP,CAAE"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "tanstack-head-controller",
3
3
  "type": "module",
4
- "version": "0.0.2",
4
+ "version": "0.0.4",
5
5
  "description": "Head management library for TanStack Router with plugin-based transforms.",
6
6
  "homepage": "https://thc.tkcl.tv",
7
7
  "author": "toakiryu",