tanstack-head-controller 0.0.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/LICENSE +201 -0
- package/README.md +27 -0
- package/dist/configs/index.d.ts +2 -0
- package/dist/configs/index.d.ts.map +1 -0
- package/dist/configs/index.js +3 -0
- package/dist/configs/index.js.map +1 -0
- package/dist/configs/type.d.ts +2 -0
- package/dist/configs/type.d.ts.map +1 -0
- package/dist/configs/type.js +3 -0
- package/dist/configs/type.js.map +1 -0
- package/dist/context/edit.d.ts +8 -0
- package/dist/context/edit.d.ts.map +1 -0
- package/dist/context/edit.js +22 -0
- package/dist/context/edit.js.map +1 -0
- package/dist/context/index.d.ts +2 -0
- package/dist/context/index.d.ts.map +1 -0
- package/dist/context/index.js +3 -0
- package/dist/context/index.js.map +1 -0
- package/dist/context/log.d.ts +2 -0
- package/dist/context/log.d.ts.map +1 -0
- package/dist/context/log.js +6 -0
- package/dist/context/log.js.map +1 -0
- package/dist/context/safe.d.ts +23 -0
- package/dist/context/safe.d.ts.map +1 -0
- package/dist/context/safe.js +46 -0
- package/dist/context/safe.js.map +1 -0
- package/dist/context/type.d.ts +7 -0
- package/dist/context/type.d.ts.map +1 -0
- package/dist/context/type.js +3 -0
- package/dist/context/type.js.map +1 -0
- package/dist/controller.d.ts +2 -0
- package/dist/controller.d.ts.map +1 -0
- package/dist/controller.js +47 -0
- package/dist/controller.js.map +1 -0
- package/dist/create.d.ts +8 -0
- package/dist/create.d.ts.map +1 -0
- package/dist/create.js +16 -0
- package/dist/create.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/logger.d.ts +3 -0
- package/dist/lib/logger.d.ts.map +1 -0
- package/dist/lib/logger.js +98 -0
- package/dist/lib/logger.js.map +1 -0
- package/dist/plugins/apply.d.ts +8 -0
- package/dist/plugins/apply.d.ts.map +1 -0
- package/dist/plugins/apply.js +11 -0
- package/dist/plugins/apply.js.map +1 -0
- package/dist/plugins/create.d.ts +3 -0
- package/dist/plugins/create.d.ts.map +1 -0
- package/dist/plugins/create.js +5 -0
- package/dist/plugins/create.js.map +1 -0
- package/dist/plugins/index.d.ts +3 -0
- package/dist/plugins/index.d.ts.map +1 -0
- package/dist/plugins/index.js +4 -0
- package/dist/plugins/index.js.map +1 -0
- package/dist/plugins/type.d.ts +7 -0
- package/dist/plugins/type.d.ts.map +1 -0
- package/dist/plugins/type.js +3 -0
- package/dist/plugins/type.js.map +1 -0
- package/dist/types/head.d.ts +20 -0
- package/dist/types/head.d.ts.map +1 -0
- package/dist/types/head.js +3 -0
- package/dist/types/head.js.map +1 -0
- package/dist/types/router.d.ts +5 -0
- package/dist/types/router.d.ts.map +1 -0
- package/dist/types/router.js +3 -0
- package/dist/types/router.js.map +1 -0
- package/dist/utils/data.d.ts +22 -0
- package/dist/utils/data.d.ts.map +1 -0
- package/dist/utils/data.js +36 -0
- package/dist/utils/data.js.map +1 -0
- package/dist/utils/render.d.ts +10 -0
- package/dist/utils/render.d.ts.map +1 -0
- package/dist/utils/render.js +42 -0
- package/dist/utils/render.js.map +1 -0
- package/package.json +82 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# tanstack-head-controller
|
|
2
|
+
|
|
3
|
+
Head management library for TanStack Router.
|
|
4
|
+
|
|
5
|
+
It collects route-level head data (`meta`, `links`, `styles`, `scripts`), applies plugin-based transforms, and renders the final tags in your root document.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
pnpm add tanstack-head-controller
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Quick Example
|
|
14
|
+
|
|
15
|
+
```tsx
|
|
16
|
+
import { createHeadController, HeadControllerRender } from 'tanstack-head-controller'
|
|
17
|
+
|
|
18
|
+
const headCtrlr = createHeadController()
|
|
19
|
+
|
|
20
|
+
// Put headCtrlr in router context,
|
|
21
|
+
// then render in your root document:
|
|
22
|
+
// <head><HeadControllerRender /></head>
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Documentation
|
|
26
|
+
|
|
27
|
+
- [Documentation Site](https://thc.tkcl.tv/en/)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/configs/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/configs/index.ts"],"sourcesContent":["export * from \"./type\";\n"],"names":[],"mappings":"AAAA,cAAc,SAAS"}
|
|
@@ -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 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/configs/type.ts"],"sourcesContent":["export type ThcConfigs = Record<string, any>;\n"],"names":[],"mappings":"AAAA,WAA6C"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { ThcConfigs } from "../configs/type";
|
|
2
|
+
import type { ThcPlugin } from "../plugins/type";
|
|
3
|
+
export interface ContextEditProps {
|
|
4
|
+
configs?: ThcConfigs;
|
|
5
|
+
plugins?: ThcPlugin[];
|
|
6
|
+
}
|
|
7
|
+
export declare const editContext: (ctx: any, props: ContextEditProps) => any;
|
|
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,iBAAiB,CAAC;AAClD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAKjD,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,QAa5D,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { rLogger } from "./log";
|
|
2
|
+
const logger = rLogger.getSubLogger({
|
|
3
|
+
name: "Edit"
|
|
4
|
+
});
|
|
5
|
+
export const editContext = (ctx, props)=>{
|
|
6
|
+
const result = {
|
|
7
|
+
...ctx,
|
|
8
|
+
...props,
|
|
9
|
+
configs: {
|
|
10
|
+
...ctx.configs,
|
|
11
|
+
...props.configs
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
logger.debug("Context edited", {
|
|
15
|
+
ctx,
|
|
16
|
+
props,
|
|
17
|
+
result
|
|
18
|
+
});
|
|
19
|
+
return result;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
//# sourceMappingURL=edit.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/context/edit.ts"],"sourcesContent":["import type { ThcConfigs } from \"../configs/type\";\nimport type { ThcPlugin } from \"../plugins/type\";\nimport { rLogger } from \"./log\";\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) => {\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,SAASA,OAAO,QAAQ,QAAQ;AAEhC,MAAMC,SAASD,QAAQE,YAAY,CAAC;IAAEC,MAAM;AAAO;AAMnD,OAAO,MAAMC,cAAc,CAACC,KAAUC;IACpC,MAAMC,SAAS;QACb,GAAGF,GAAG;QACN,GAAGC,KAAK;QACRE,SAAS;YACP,GAAGH,IAAIG,OAAO;YACd,GAAGF,MAAME,OAAO;QAClB;IACF;IAEAP,OAAOQ,KAAK,CAAC,kBAAkB;QAAEJ;QAAKC;QAAOC;IAAO;IAEpD,OAAOA;AACT,EAAE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/context/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/context/index.ts"],"sourcesContent":["export * from \"./edit\";\n"],"names":[],"mappings":"AAAA,cAAc,SAAS"}
|
|
@@ -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 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/context/log.ts"],"sourcesContent":["import { cLogger } from \"../lib/logger\";\n\nexport const rLogger = cLogger().getSubLogger({ name: \"Context\" });\n"],"names":["cLogger","rLogger","getSubLogger","name"],"mappings":"AAAA,SAASA,OAAO,QAAQ,gBAAgB;AAExC,OAAO,MAAMC,UAAUD,UAAUE,YAAY,CAAC;IAAEC,MAAM;AAAU,GAAG"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* このファイルは、`headCtrlrContext` を安全に使用するための機能を提供します。
|
|
3
|
+
*
|
|
4
|
+
* 1. 型が保証された状態でコンテキストを使用できるようにする。
|
|
5
|
+
* 2. コンテキストの構造が変更された場合に、型エラーを通じて問題を早期に発見できるようにする。
|
|
6
|
+
* 3. コンテキストの使用箇所で、必要なプロパティが存在することを保証する。
|
|
7
|
+
*/
|
|
8
|
+
import type { headCtrlrContext } from "./type";
|
|
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,QAAQ,CAAC;AAgB/C;;;;;;;;;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,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* このファイルは、`headCtrlrContext` を安全に使用するための機能を提供します。
|
|
3
|
+
*
|
|
4
|
+
* 1. 型が保証された状態でコンテキストを使用できるようにする。
|
|
5
|
+
* 2. コンテキストの構造が変更された場合に、型エラーを通じて問題を早期に発見できるようにする。
|
|
6
|
+
* 3. コンテキストの使用箇所で、必要なプロパティが存在することを保証する。
|
|
7
|
+
*/ import { rLogger } from "./log";
|
|
8
|
+
const logger = rLogger.getSubLogger({
|
|
9
|
+
name: "Safe"
|
|
10
|
+
});
|
|
11
|
+
function isRecord(value) {
|
|
12
|
+
return typeof value === "object" && value !== null;
|
|
13
|
+
}
|
|
14
|
+
function isHeadCtrlrContext(value) {
|
|
15
|
+
if (!isRecord(value)) {
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
return Array.isArray(value.plugins);
|
|
19
|
+
}
|
|
20
|
+
export function useSafeHeadCtrlrContext(ctx, options = {}) {
|
|
21
|
+
const { isThrow = true } = options;
|
|
22
|
+
if (!isRecord(ctx)) {
|
|
23
|
+
if (isThrow) {
|
|
24
|
+
throw logger.error("Invalid context: Context must be an object.", {
|
|
25
|
+
receivedType: typeof ctx
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
if (!("headCtrlr" in ctx)) {
|
|
31
|
+
if (isThrow) {
|
|
32
|
+
throw logger.error("Invalid context: Missing 'headCtrlr' property.");
|
|
33
|
+
}
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
const headCtrlr = ctx.headCtrlr;
|
|
37
|
+
if (!isHeadCtrlrContext(headCtrlr)) {
|
|
38
|
+
if (isThrow) {
|
|
39
|
+
throw logger.error("Invalid context: 'headCtrlr.plugins' must be an array.");
|
|
40
|
+
}
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
return headCtrlr;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
//# 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\";\nimport type { headCtrlrContext } from \"./type\";\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 (!(\"headCtrlr\" in ctx)) {\n if (isThrow) {\n throw logger.error(\"Invalid context: Missing 'headCtrlr' property.\");\n }\n return null;\n }\n\n const headCtrlr = ctx.headCtrlr;\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"],"mappings":"AAAA;;;;;;CAMC,GAED,SAASA,OAAO,QAAQ,QAAQ;AAGhC,MAAMC,SAASD,QAAQE,YAAY,CAAC;IAAEC,MAAM;AAAO;AAEnD,SAASC,SAASC,KAAc;IAC9B,OAAO,OAAOA,UAAU,YAAYA,UAAU;AAChD;AAEA,SAASC,mBAAmBD,KAAc;IACxC,IAAI,CAACD,SAASC,QAAQ;QACpB,OAAO;IACT;IAEA,OAAOE,MAAMC,OAAO,CAACH,MAAMI,OAAO;AACpC;AAgBA,OAAO,SAASC,wBACdC,GAAY,EACZC,UAA0C,CAAC,CAAC;IAE5C,MAAM,EAAEC,UAAU,IAAI,EAAE,GAAGD;IAE3B,IAAI,CAACR,SAASO,MAAM;QAClB,IAAIE,SAAS;YACX,MAAMZ,OAAOa,KAAK,CAAC,+CAA+C;gBAChEC,cAAc,OAAOJ;YACvB;QACF;QACA,OAAO;IACT;IAEA,IAAI,CAAE,CAAA,eAAeA,GAAE,GAAI;QACzB,IAAIE,SAAS;YACX,MAAMZ,OAAOa,KAAK,CAAC;QACrB;QACA,OAAO;IACT;IAEA,MAAME,YAAYL,IAAIK,SAAS;IAE/B,IAAI,CAACV,mBAAmBU,YAAY;QAClC,IAAIH,SAAS;YACX,MAAMZ,OAAOa,KAAK,CAAC;QACrB;QACA,OAAO;IACT;IAEA,OAAOE;AACT"}
|
|
@@ -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,iBAAiB,CAAC;AAClD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAEjD,MAAM,MAAM,gBAAgB,GAAG;IAC7B,OAAO,EAAE,UAAU,CAAC;IACpB,OAAO,EAAE,SAAS,EAAE,CAAC;CACtB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/context/type.ts"],"sourcesContent":["import type { ThcConfigs } from \"../configs/type\";\nimport type { ThcPlugin } from \"../plugins/type\";\n\nexport type headCtrlrContext = {\n configs: ThcConfigs;\n plugins: ThcPlugin[];\n};\n"],"names":[],"mappings":"AAGA,WAGE"}
|
|
@@ -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,47 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useRouterState } from "@tanstack/react-router";
|
|
3
|
+
import { useSafeHeadCtrlrContext } from "./context/safe";
|
|
4
|
+
import { cLogger } from "./lib/logger";
|
|
5
|
+
import { applyPlugins } from "./plugins/apply";
|
|
6
|
+
import { collectHeadDataFromRoutes } from "./utils/data";
|
|
7
|
+
import { HeadRender } from "./utils/render";
|
|
8
|
+
// Loggerの初期化
|
|
9
|
+
const logger = cLogger().getSubLogger({
|
|
10
|
+
name: "Controller"
|
|
11
|
+
});
|
|
12
|
+
export const HeadControllerRender = ()=>{
|
|
13
|
+
// ルーターの状態を取得
|
|
14
|
+
const routes = useRouterState({
|
|
15
|
+
select: (s)=>s.matches
|
|
16
|
+
});
|
|
17
|
+
// ルートからheadデータを収集
|
|
18
|
+
const resolvedHead = collectHeadDataFromRoutes(routes);
|
|
19
|
+
// 現在のルート情報
|
|
20
|
+
const currentRouteData = [
|
|
21
|
+
...routes
|
|
22
|
+
].reverse().find((d)=>d);
|
|
23
|
+
// logger.info("Resolved Head from Routes:", { resolvedHead, ctx: currentRouteData?.context });
|
|
24
|
+
// 現在のルートのコンテキストを安全に取得
|
|
25
|
+
const currentContext = useSafeHeadCtrlrContext(currentRouteData?.context);
|
|
26
|
+
// もしコンテキストが取得できない場合は、警告を出力して、HeadRenderを返す
|
|
27
|
+
if (!currentContext) {
|
|
28
|
+
logger.warn("No valid context found for the current route.");
|
|
29
|
+
return /*#__PURE__*/ _jsx(HeadRender, {
|
|
30
|
+
head: resolvedHead
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
// ログ出力
|
|
34
|
+
// logger.info("Current Route:", { pathname: currentRouteData?.pathname, resolvedHead });
|
|
35
|
+
// プラグインの適用
|
|
36
|
+
const finalHead = applyPlugins({
|
|
37
|
+
head: resolvedHead,
|
|
38
|
+
ctx: currentContext
|
|
39
|
+
});
|
|
40
|
+
// ログ出力
|
|
41
|
+
// logger.info("Final Head:", { finalHead });
|
|
42
|
+
return /*#__PURE__*/ _jsx(HeadRender, {
|
|
43
|
+
head: finalHead
|
|
44
|
+
});
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
//# 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\";\nimport { cLogger } from \"./lib/logger\";\nimport { applyPlugins } from \"./plugins/apply\";\nimport { collectHeadDataFromRoutes } from \"./utils/data\";\nimport { HeadRender } from \"./utils/render\";\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":";AAAA,SAASA,cAAc,QAAQ,yBAAyB;AACxD,SAASC,uBAAuB,QAAQ,iBAAiB;AACzD,SAASC,OAAO,QAAQ,eAAe;AACvC,SAASC,YAAY,QAAQ,kBAAkB;AAC/C,SAASC,yBAAyB,QAAQ,eAAe;AACzD,SAASC,UAAU,QAAQ,iBAAiB;AAE5C,aAAa;AACb,MAAMC,SAASJ,UAAUK,YAAY,CAAC;IAAEC,MAAM;AAAa;AAE3D,OAAO,MAAMC,uBAAuB;IAClC,aAAa;IACb,MAAMC,SAASV,eAAe;QAAEW,QAAQ,CAACC,IAAMA,EAAEC,OAAO;IAAC;IAEzD,mBAAmB;IACnB,MAAMC,eAAeV,0BAA0BM;IAE/C,WAAW;IACX,MAAMK,mBAAmB;WAAIL;KAAO,CAACM,OAAO,GAAGC,IAAI,CAAC,CAACC,IAAMA;IAE3D,+FAA+F;IAE/F,sBAAsB;IACtB,MAAMC,iBAAiBlB,wBAAwBc,kBAAkBK;IAEjE,2CAA2C;IAC3C,IAAI,CAACD,gBAAgB;QACnBb,OAAOe,IAAI,CAAC;QACZ,qBAAO,KAAChB;YAAWiB,MAAMR;;IAC3B;IAEA,OAAO;IACP,yFAAyF;IAEzF,WAAW;IACX,MAAMS,YAAYpB,aAAa;QAAEmB,MAAMR;QAAcU,KAAKL;IAAe;IAEzE,OAAO;IACP,6CAA6C;IAE7C,qBAAO,KAACd;QAAWiB,MAAMC;;AAC3B,EAAE"}
|
package/dist/create.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { ThcConfigs } from "./configs/type";
|
|
2
|
+
import type { ThcPlugin } from "./plugins/type";
|
|
3
|
+
export interface CreateHeadControllerOptions {
|
|
4
|
+
configs?: ThcConfigs;
|
|
5
|
+
plugins?: ThcPlugin[];
|
|
6
|
+
}
|
|
7
|
+
export declare const createHeadController: (options?: CreateHeadControllerOptions) => any;
|
|
8
|
+
//# 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,gBAAgB,CAAC;AAGjD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAEhD,MAAM,WAAW,2BAA2B;IAC1C,OAAO,CAAC,EAAE,UAAU,CAAC;IACrB,OAAO,CAAC,EAAE,SAAS,EAAE,CAAC;CACvB;AAID,eAAO,MAAM,oBAAoB,GAAI,UAAS,2BAAgC,QAO7E,CAAC"}
|
package/dist/create.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { editContext } from "./context/edit";
|
|
2
|
+
import { cLogger } from "./lib/logger";
|
|
3
|
+
const logger = cLogger().getSubLogger({
|
|
4
|
+
name: "Create"
|
|
5
|
+
});
|
|
6
|
+
export const createHeadController = (options = {})=>{
|
|
7
|
+
const { configs = {}, plugins = [] } = options;
|
|
8
|
+
// logger.info("Initializing head controller with options:", options);
|
|
9
|
+
// logger.info("Registered plugins:", plugins);
|
|
10
|
+
return editContext({}, {
|
|
11
|
+
configs,
|
|
12
|
+
plugins
|
|
13
|
+
});
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
//# sourceMappingURL=create.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/create.ts"],"sourcesContent":["import type { ThcConfigs } from \"./configs/type\";\nimport { editContext } from \"./context/edit\";\nimport { cLogger } from \"./lib/logger\";\nimport type { ThcPlugin } from \"./plugins/type\";\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 editContext({}, { configs, plugins });\n};\n"],"names":["editContext","cLogger","logger","getSubLogger","name","createHeadController","options","configs","plugins"],"mappings":"AACA,SAASA,WAAW,QAAQ,iBAAiB;AAC7C,SAASC,OAAO,QAAQ,eAAe;AAQvC,MAAMC,SAASD,UAAUE,YAAY,CAAC;IAAEC,MAAM;AAAS;AAEvD,OAAO,MAAMC,uBAAuB,CAACC,UAAuC,CAAC,CAAC;IAC5E,MAAM,EAAEC,UAAU,CAAC,CAAC,EAAEC,UAAU,EAAE,EAAE,GAAGF;IAEvC,sEAAsE;IACtE,+CAA+C;IAE/C,OAAON,YAAY,CAAC,GAAG;QAAEO;QAASC;IAAQ;AAC5C,EAAE"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,UAAU,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["export * from \"./controller\";\nexport * from \"./create\";\n"],"names":[],"mappings":"AAAA,cAAc,eAAe;AAC7B,cAAc,WAAW"}
|
|
@@ -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,98 @@
|
|
|
1
|
+
import { Logger } from "tslog";
|
|
2
|
+
export const cLogger = ()=>new Logger({
|
|
3
|
+
type: "pretty",
|
|
4
|
+
name: "THC",
|
|
5
|
+
prettyLogTemplate: "{{yyyy}}-{{mm}}-{{dd}} {{hh}}:{{MM}}:{{ss}}.{{ms}} {{logLevelName}} {{name}} ",
|
|
6
|
+
overwrite: {
|
|
7
|
+
transportFormatted: (logMetaMarkup, logArgs, logErrors)=>{
|
|
8
|
+
const output = `${logMetaMarkup}${logArgs.map(formatLogArg).join(" ")}${logErrors.length > 0 ? `\n${logErrors.join("\n")}` : ""}`;
|
|
9
|
+
console.log(output);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
});
|
|
13
|
+
const useAnsiColors = typeof process !== "undefined" && process?.versions?.node != null;
|
|
14
|
+
const ansi = {
|
|
15
|
+
reset: "\u001b[0m",
|
|
16
|
+
dim: "\u001b[2m",
|
|
17
|
+
cyan: "\u001b[36m",
|
|
18
|
+
green: "\u001b[32m",
|
|
19
|
+
magenta: "\u001b[35m",
|
|
20
|
+
yellow: "\u001b[33m",
|
|
21
|
+
red: "\u001b[31m"
|
|
22
|
+
};
|
|
23
|
+
const colorize = (value, color)=>{
|
|
24
|
+
if (!useAnsiColors) {
|
|
25
|
+
return value;
|
|
26
|
+
}
|
|
27
|
+
return `${ansi[color]}${value}${ansi.reset}`;
|
|
28
|
+
};
|
|
29
|
+
const formatLogArg = (value)=>{
|
|
30
|
+
if (typeof value === "string") {
|
|
31
|
+
return colorize(value, "green");
|
|
32
|
+
}
|
|
33
|
+
if (value instanceof Error) {
|
|
34
|
+
return value.stack ?? value.message;
|
|
35
|
+
}
|
|
36
|
+
if (value == null) {
|
|
37
|
+
return colorize(String(value), "yellow");
|
|
38
|
+
}
|
|
39
|
+
return formatPrettyValue(value);
|
|
40
|
+
};
|
|
41
|
+
const formatPrettyValue = (value)=>{
|
|
42
|
+
const seen = new WeakSet();
|
|
43
|
+
return formatValue(value, 0, seen);
|
|
44
|
+
};
|
|
45
|
+
const formatValue = (value, indentLevel, seen)=>{
|
|
46
|
+
if (value instanceof Error) {
|
|
47
|
+
return value.stack ?? value.message;
|
|
48
|
+
}
|
|
49
|
+
if (value instanceof Date) {
|
|
50
|
+
return colorize(`"${value.toISOString()}"`, "green");
|
|
51
|
+
}
|
|
52
|
+
if (typeof value === "string") {
|
|
53
|
+
return colorize(`"${escapeString(value)}"`, "green");
|
|
54
|
+
}
|
|
55
|
+
if (typeof value === "number" || typeof value === "boolean") {
|
|
56
|
+
return colorize(String(value), typeof value === "number" ? "cyan" : "magenta");
|
|
57
|
+
}
|
|
58
|
+
if (typeof value === "bigint") {
|
|
59
|
+
return colorize(`${value}n`, "cyan");
|
|
60
|
+
}
|
|
61
|
+
if (typeof value === "symbol") {
|
|
62
|
+
return colorize(value.toString(), "magenta");
|
|
63
|
+
}
|
|
64
|
+
if (typeof value === "function") {
|
|
65
|
+
return colorize(`[Function${value.name ? `: ${value.name}` : ""}]`, "red");
|
|
66
|
+
}
|
|
67
|
+
if (value == null) {
|
|
68
|
+
return colorize(String(value), "yellow");
|
|
69
|
+
}
|
|
70
|
+
if (typeof value !== "object") {
|
|
71
|
+
return String(value);
|
|
72
|
+
}
|
|
73
|
+
if (seen.has(value)) {
|
|
74
|
+
return colorize("[Circular]", "red");
|
|
75
|
+
}
|
|
76
|
+
seen.add(value);
|
|
77
|
+
if (Array.isArray(value)) {
|
|
78
|
+
if (value.length === 0) {
|
|
79
|
+
return colorize("[]", "dim");
|
|
80
|
+
}
|
|
81
|
+
const nextIndent = indentLevel + 2;
|
|
82
|
+
const items = value.map((item)=>`${indent(nextIndent)}${formatValue(item, nextIndent, seen)}`);
|
|
83
|
+
return `${colorize("[", "dim")}\n${items.join(colorize(",", "dim") + "\n")}
|
|
84
|
+
${indent(indentLevel)}${colorize("]", "dim")}`;
|
|
85
|
+
}
|
|
86
|
+
const entries = Object.entries(value);
|
|
87
|
+
if (entries.length === 0) {
|
|
88
|
+
return colorize("{}", "dim");
|
|
89
|
+
}
|
|
90
|
+
const nextIndent = indentLevel + 2;
|
|
91
|
+
const lines = entries.map(([key, entryValue])=>`${indent(nextIndent)}${colorize(key, "yellow")}: ${formatValue(entryValue, nextIndent, seen)}`);
|
|
92
|
+
return `${colorize("{", "dim")}\n${lines.join(colorize(",", "dim") + "\n")}
|
|
93
|
+
${indent(indentLevel)}${colorize("}", "dim")}`;
|
|
94
|
+
};
|
|
95
|
+
const indent = (size)=>" ".repeat(size);
|
|
96
|
+
const escapeString = (value)=>value.split("\\").join("\\\\").split('"').join('\\"');
|
|
97
|
+
|
|
98
|
+
//# 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";
|
|
2
|
+
import type { Head } from "../types/head";
|
|
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,iBAAiB,CAAC;AACxD,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AAE1C,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 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/plugins/apply.ts"],"sourcesContent":["import type { headCtrlrContext } from \"../context/type\";\nimport type { Head } from \"../types/head\";\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,EAAEC,IAAI,EAAEC,GAAG,EAAuB;IAC7D,IAAIC,SAASF;IAEb,KAAK,MAAMG,UAAUF,IAAIG,OAAO,CAAE;QAChC,IAAID,OAAOE,SAAS,EAAE;YACpBH,SAASC,OAAOE,SAAS,CAACH,QAAQD;QACpC;IACF;IAEA,OAAOC;AACT"}
|
|
@@ -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,QAAQ,CAAC;AAExC,wBAAgB,eAAe,CAAC,MAAM,EAAE,SAAS,GAAG,SAAS,CAE5D"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/plugins/create.ts"],"sourcesContent":["import type { ThcPlugin } from \"./type\";\n\nexport function createThcPlugin(plugin: ThcPlugin): ThcPlugin {\n return plugin;\n}\n"],"names":["createThcPlugin","plugin"],"mappings":"AAEA,OAAO,SAASA,gBAAgBC,MAAiB;IAC/C,OAAOA;AACT"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/plugins/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,QAAQ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/plugins/index.ts"],"sourcesContent":["export * from \"./create\";\nexport * from \"./type\";\n"],"names":[],"mappings":"AAAA,cAAc,WAAW;AACzB,cAAc,SAAS"}
|
|
@@ -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 @@
|
|
|
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,WAIE"}
|
|
@@ -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 @@
|
|
|
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,WAMC"}
|
|
@@ -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,iBAAiB,CAAC;AAExD,MAAM,MAAM,oBAAoB,CAAC,CAAC,IAAI,CAAC,GAAG;IACxC,SAAS,EAAE,gBAAgB,CAAC;CAC7B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/types/router.ts"],"sourcesContent":["import type { headCtrlrContext } from \"../context/type\";\n\nexport type THCcontextWithRouter<T> = T & {\n headCtrlr: headCtrlrContext;\n};\n"],"names":[],"mappings":"AAEA,WAEE"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { MakeRouteMatchUnion } from "@tanstack/react-router";
|
|
2
|
+
import type { Head } from "../types/head";
|
|
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,eAAe,CAAC;AAE1C;;;;;;;;;;;;;;;;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,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* route の生データから head 情報を収集するためのユーティリティ関数
|
|
3
|
+
*
|
|
4
|
+
* @param routeMatches
|
|
5
|
+
* @returns
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```ts
|
|
9
|
+
* import { useRouterState } from "@tanstack/react-router";
|
|
10
|
+
* import { collectHeadDataFromRoute } from "@/plugins/head-controller/data";
|
|
11
|
+
*
|
|
12
|
+
* const routeMatches = useRouterState({ select: (s) => s.matches });;
|
|
13
|
+
* const match = [...routeMatches].reverse().find((d) => d);
|
|
14
|
+
*
|
|
15
|
+
* const headData = collectHeadDataFromRoute(match);
|
|
16
|
+
* ```
|
|
17
|
+
*/ export function collectHeadDataFromRoute(route) {
|
|
18
|
+
const headData = {
|
|
19
|
+
meta: route?.meta,
|
|
20
|
+
links: route?.links,
|
|
21
|
+
styles: route?.styles,
|
|
22
|
+
scripts: route?.scripts
|
|
23
|
+
};
|
|
24
|
+
return headData;
|
|
25
|
+
}
|
|
26
|
+
export function collectHeadDataFromRoutes(routeMatches) {
|
|
27
|
+
const resolvedHead = {
|
|
28
|
+
meta: routeMatches.flatMap((m)=>m.meta ?? []),
|
|
29
|
+
links: routeMatches.flatMap((m)=>m.links ?? []),
|
|
30
|
+
styles: routeMatches.flatMap((m)=>m.styles ?? []),
|
|
31
|
+
scripts: routeMatches.flatMap((m)=>m.headScripts ?? [])
|
|
32
|
+
};
|
|
33
|
+
return resolvedHead;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
//# 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\";\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":"AAGA;;;;;;;;;;;;;;;;CAgBC,GACD,OAAO,SAASA,yBAAyBC,KAA2B;IAClE,MAAMC,WAAW;QACfC,MAAMF,OAAOE;QACbC,OAAOH,OAAOG;QACdC,QAAQJ,OAAOI;QACfC,SAASL,OAAOK;IAClB;IACA,OAAOJ;AACT;AAEA,OAAO,SAASK,0BAA0BC,YAAmC;IAC3E,MAAMC,eAAe;QACnBN,MAAMK,aAAaE,OAAO,CAAC,CAACC,IAAMA,EAAER,IAAI,IAAI,EAAE;QAC9CC,OAAOI,aAAaE,OAAO,CAAC,CAACC,IAAMA,EAAEP,KAAK,IAAI,EAAE;QAChDC,QAAQG,aAAaE,OAAO,CAAC,CAACC,IAAMA,EAAEN,MAAM,IAAI,EAAE;QAClDC,SAASE,aAAaE,OAAO,CAAC,CAACC,IAAMA,EAAEC,WAAW,IAAI,EAAE;IAC1D;IACA,OAAOH;AACT"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Head } from "../types/head";
|
|
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,eAAe,CAAC;AAE1C;;;;GAIG;AACH,eAAO,MAAM,UAAU,GAAI,UAAU;IAAE,IAAI,EAAE,IAAI,CAAC,KAAK,CAAA;CAAE,4CA4BxD,CAAC"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* ヘッダーのレンダリングコンポーネント
|
|
4
|
+
* @param param0
|
|
5
|
+
* @returns
|
|
6
|
+
*/ export const HeadRender = ({ head })=>{
|
|
7
|
+
const meta = head.meta?.map((meta, index)=>{
|
|
8
|
+
if (meta?.title) {
|
|
9
|
+
return /*#__PURE__*/ _jsx("title", {
|
|
10
|
+
children: meta.title
|
|
11
|
+
}, index);
|
|
12
|
+
}
|
|
13
|
+
return /*#__PURE__*/ _jsx("meta", {
|
|
14
|
+
...meta
|
|
15
|
+
}, index);
|
|
16
|
+
});
|
|
17
|
+
const links = head.links?.map((link, index)=>{
|
|
18
|
+
return /*#__PURE__*/ _jsx("link", {
|
|
19
|
+
...link
|
|
20
|
+
}, index);
|
|
21
|
+
});
|
|
22
|
+
const styles = head.styles?.map((style, index)=>{
|
|
23
|
+
return /*#__PURE__*/ _jsx("style", {
|
|
24
|
+
...style
|
|
25
|
+
}, index);
|
|
26
|
+
});
|
|
27
|
+
const scripts = head.scripts?.map((script, index)=>{
|
|
28
|
+
return /*#__PURE__*/ _jsx("script", {
|
|
29
|
+
...script
|
|
30
|
+
}, index);
|
|
31
|
+
});
|
|
32
|
+
return /*#__PURE__*/ _jsxs(_Fragment, {
|
|
33
|
+
children: [
|
|
34
|
+
meta,
|
|
35
|
+
links,
|
|
36
|
+
styles,
|
|
37
|
+
scripts
|
|
38
|
+
]
|
|
39
|
+
});
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
//# sourceMappingURL=render.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/utils/render.tsx"],"sourcesContent":["import type { Head } from \"../types/head\";\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":";AAEA;;;;CAIC,GACD,OAAO,MAAMA,aAAa,CAAC,EAAEC,IAAI,EAAwB;IACvD,MAAMC,OAAOD,KAAKC,IAAI,EAAEC,IAAI,CAACD,MAAME;QACjC,IAAIF,MAAMG,OAAO;YACf,qBAAO,KAACA;0BAAmBH,KAAKG,KAAK;eAAlBD;QACrB;QACA,qBAAO,KAACF;YAAkB,GAAGA,IAAI;WAAfE;IACpB;IAEA,MAAME,QAAQL,KAAKK,KAAK,EAAEH,IAAI,CAACI,MAAMH;QACnC,qBAAO,KAACG;YAAkB,GAAGA,IAAI;WAAfH;IACpB;IAEA,MAAMI,SAASP,KAAKO,MAAM,EAAEL,IAAI,CAACM,OAAOL;QACtC,qBAAO,KAACK;YAAmB,GAAGA,KAAK;WAAhBL;IACrB;IAEA,MAAMM,UAAUT,KAAKS,OAAO,EAAEP,IAAI,CAACQ,QAAQP;QACzC,qBAAO,KAACO;YAAoB,GAAGA,MAAM;WAAjBP;IACtB;IAEA,qBACE;;YACGF;YACAI;YACAE;YACAE;;;AAGP,EAAE"}
|
package/package.json
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "tanstack-head-controller",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "0.0.1",
|
|
5
|
+
"description": "Head management library for TanStack Router with plugin-based transforms.",
|
|
6
|
+
"homepage": "https://thc.tkcl.tv/",
|
|
7
|
+
"author": "toakiryu",
|
|
8
|
+
"license": "Apache-2.0",
|
|
9
|
+
"funding": "https://buymeacoffee.com/toakiryu",
|
|
10
|
+
"sideEffects": false,
|
|
11
|
+
"main": "./dist/index.js",
|
|
12
|
+
"module": "./dist/index.js",
|
|
13
|
+
"types": "./dist/index.d.ts",
|
|
14
|
+
"repository": {
|
|
15
|
+
"type": "git",
|
|
16
|
+
"url": "https://github.com/toaki-cltv/tanstack-head-controller.git",
|
|
17
|
+
"directory": "packages/tanstack-head-controller"
|
|
18
|
+
},
|
|
19
|
+
"bugs": "https://github.com/toaki-cltv/tanstack-head-controller/issues",
|
|
20
|
+
"keywords": [
|
|
21
|
+
"tanstack",
|
|
22
|
+
"tanstack-router",
|
|
23
|
+
"react",
|
|
24
|
+
"router",
|
|
25
|
+
"head",
|
|
26
|
+
"meta",
|
|
27
|
+
"seo",
|
|
28
|
+
"controller",
|
|
29
|
+
"ecosystem"
|
|
30
|
+
],
|
|
31
|
+
"files": [
|
|
32
|
+
"dist"
|
|
33
|
+
],
|
|
34
|
+
"exports": {
|
|
35
|
+
".": {
|
|
36
|
+
"types": "./dist/index.d.ts",
|
|
37
|
+
"import": "./dist/index.js"
|
|
38
|
+
},
|
|
39
|
+
"./context": {
|
|
40
|
+
"types": "./dist/context/index.d.ts",
|
|
41
|
+
"import": "./dist/context/index.js"
|
|
42
|
+
},
|
|
43
|
+
"./configs": {
|
|
44
|
+
"types": "./dist/configs/index.d.ts",
|
|
45
|
+
"import": "./dist/configs/index.js"
|
|
46
|
+
},
|
|
47
|
+
"./plugins": {
|
|
48
|
+
"types": "./dist/plugins/index.d.ts",
|
|
49
|
+
"import": "./dist/plugins/index.js"
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
"engines": {
|
|
53
|
+
"node": ">=22"
|
|
54
|
+
},
|
|
55
|
+
"peerDependencies": {
|
|
56
|
+
"@tanstack/react-router": ">=1",
|
|
57
|
+
"react": ">=19"
|
|
58
|
+
},
|
|
59
|
+
"dependencies": {
|
|
60
|
+
"tslog": "^4.10.2",
|
|
61
|
+
"zod": "^4.3.6"
|
|
62
|
+
},
|
|
63
|
+
"devDependencies": {
|
|
64
|
+
"@biomejs/biome": "2.4.0",
|
|
65
|
+
"@types/node": "^22.19.15",
|
|
66
|
+
"@types/react": "^19.2.0",
|
|
67
|
+
"@types/react-dom": "^19.2.0",
|
|
68
|
+
"typescript": "^5.9.3"
|
|
69
|
+
},
|
|
70
|
+
"peerDependenciesMeta": {
|
|
71
|
+
"@tanstack/react-router": {
|
|
72
|
+
"optional": false
|
|
73
|
+
},
|
|
74
|
+
"react": {
|
|
75
|
+
"optional": false
|
|
76
|
+
}
|
|
77
|
+
},
|
|
78
|
+
"scripts": {
|
|
79
|
+
"build": "node ../../scripts/build.ts tanstack-head-controller",
|
|
80
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
81
|
+
}
|
|
82
|
+
}
|