draft-ole 0.9.0
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 +21 -0
- package/README.ja.md +134 -0
- package/README.md +128 -0
- package/dist/chunk-5BNNDTRT.js +95 -0
- package/dist/chunk-5BNNDTRT.js.map +1 -0
- package/dist/chunk-STLTIBMA.js +7658 -0
- package/dist/chunk-STLTIBMA.js.map +1 -0
- package/dist/chunk-YK4Y4ENL.js +389 -0
- package/dist/chunk-YK4Y4ENL.js.map +1 -0
- package/dist/entries/app.cjs +7337 -0
- package/dist/entries/app.cjs.map +1 -0
- package/dist/entries/app.d.cts +115 -0
- package/dist/entries/app.d.ts +115 -0
- package/dist/entries/app.js +10 -0
- package/dist/entries/app.js.map +1 -0
- package/dist/entries/page.cjs +7558 -0
- package/dist/entries/page.cjs.map +1 -0
- package/dist/entries/page.d.cts +2 -0
- package/dist/entries/page.d.ts +2 -0
- package/dist/entries/page.js +30 -0
- package/dist/entries/page.js.map +1 -0
- package/dist/index.cjs +10524 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +4700 -0
- package/dist/index.d.ts +4700 -0
- package/dist/index.js +2573 -0
- package/dist/index.js.map +1 -0
- package/dist/page-DylNkWXm.d.ts +366 -0
- package/dist/page-h3DPzs8l.d.cts +366 -0
- package/dist/transformer/call-detector.d.ts +38 -0
- package/dist/transformer/call-detector.d.ts.map +1 -0
- package/dist/transformer/call-detector.js +151 -0
- package/dist/transformer/call-detector.js.map +1 -0
- package/dist/transformer/command-injector.d.ts +27 -0
- package/dist/transformer/command-injector.d.ts.map +1 -0
- package/dist/transformer/command-injector.js +111 -0
- package/dist/transformer/command-injector.js.map +1 -0
- package/dist/transformer/diagnostic-reporter.d.ts +81 -0
- package/dist/transformer/diagnostic-reporter.d.ts.map +1 -0
- package/dist/transformer/diagnostic-reporter.js +330 -0
- package/dist/transformer/diagnostic-reporter.js.map +1 -0
- package/dist/transformer/each-scope-branch.d.ts +28 -0
- package/dist/transformer/each-scope-branch.d.ts.map +1 -0
- package/dist/transformer/each-scope-branch.js +95 -0
- package/dist/transformer/each-scope-branch.js.map +1 -0
- package/dist/transformer/each-state-rewriter.d.ts +117 -0
- package/dist/transformer/each-state-rewriter.d.ts.map +1 -0
- package/dist/transformer/each-state-rewriter.js +393 -0
- package/dist/transformer/each-state-rewriter.js.map +1 -0
- package/dist/transformer/format-diagnostics.d.ts +27 -0
- package/dist/transformer/format-diagnostics.d.ts.map +1 -0
- package/dist/transformer/format-diagnostics.js +50 -0
- package/dist/transformer/format-diagnostics.js.map +1 -0
- package/dist/transformer/handler-ir-extractor.d.ts +71 -0
- package/dist/transformer/handler-ir-extractor.d.ts.map +1 -0
- package/dist/transformer/handler-ir-extractor.js +171 -0
- package/dist/transformer/handler-ir-extractor.js.map +1 -0
- package/dist/transformer/handler-serializer.d.ts +56 -0
- package/dist/transformer/handler-serializer.d.ts.map +1 -0
- package/dist/transformer/handler-serializer.js +315 -0
- package/dist/transformer/handler-serializer.js.map +1 -0
- package/dist/transformer/helper-context-resolver.d.ts +180 -0
- package/dist/transformer/helper-context-resolver.d.ts.map +1 -0
- package/dist/transformer/helper-context-resolver.js +376 -0
- package/dist/transformer/helper-context-resolver.js.map +1 -0
- package/dist/transformer/helper-decl-utils.d.ts +28 -0
- package/dist/transformer/helper-decl-utils.d.ts.map +1 -0
- package/dist/transformer/helper-decl-utils.js +92 -0
- package/dist/transformer/helper-decl-utils.js.map +1 -0
- package/dist/transformer/identifier-collector.d.ts +28 -0
- package/dist/transformer/identifier-collector.d.ts.map +1 -0
- package/dist/transformer/identifier-collector.js +184 -0
- package/dist/transformer/identifier-collector.js.map +1 -0
- package/dist/transformer/index.d.ts +56 -0
- package/dist/transformer/index.d.ts.map +1 -0
- package/dist/transformer/index.js +333 -0
- package/dist/transformer/index.js.map +1 -0
- package/dist/transformer/inline-recovery.d.ts +109 -0
- package/dist/transformer/inline-recovery.d.ts.map +1 -0
- package/dist/transformer/inline-recovery.js +369 -0
- package/dist/transformer/inline-recovery.js.map +1 -0
- package/dist/transformer/label-injector.d.ts +105 -0
- package/dist/transformer/label-injector.d.ts.map +1 -0
- package/dist/transformer/label-injector.js +221 -0
- package/dist/transformer/label-injector.js.map +1 -0
- package/dist/transformer/package.json +3 -0
- package/dist/transformer/per-call-context.d.ts +95 -0
- package/dist/transformer/per-call-context.d.ts.map +1 -0
- package/dist/transformer/per-call-context.js +3 -0
- package/dist/transformer/per-call-context.js.map +1 -0
- package/dist/transformer/state-id-fallback.d.ts +85 -0
- package/dist/transformer/state-id-fallback.d.ts.map +1 -0
- package/dist/transformer/state-id-fallback.js +132 -0
- package/dist/transformer/state-id-fallback.js.map +1 -0
- package/dist/transformer/state-id-resolver.d.ts +104 -0
- package/dist/transformer/state-id-resolver.d.ts.map +1 -0
- package/dist/transformer/state-id-resolver.js +222 -0
- package/dist/transformer/state-id-resolver.js.map +1 -0
- package/dist/transformer/theme-class-detector.d.ts +47 -0
- package/dist/transformer/theme-class-detector.d.ts.map +1 -0
- package/dist/transformer/theme-class-detector.js +242 -0
- package/dist/transformer/theme-class-detector.js.map +1 -0
- package/dist/transformer/varname-resolver.d.ts +53 -0
- package/dist/transformer/varname-resolver.d.ts.map +1 -0
- package/dist/transformer/varname-resolver.js +231 -0
- package/dist/transformer/varname-resolver.js.map +1 -0
- package/dist/transformer/whitelist-registry.d.ts +68 -0
- package/dist/transformer/whitelist-registry.d.ts.map +1 -0
- package/dist/transformer/whitelist-registry.js +122 -0
- package/dist/transformer/whitelist-registry.js.map +1 -0
- package/dist/transformer/whitelist-validator.d.ts +59 -0
- package/dist/transformer/whitelist-validator.d.ts.map +1 -0
- package/dist/transformer/whitelist-validator.js +493 -0
- package/dist/transformer/whitelist-validator.js.map +1 -0
- package/dist/types-BXV3vhHS.d.cts +4590 -0
- package/dist/types-BXV3vhHS.d.ts +4590 -0
- package/package.json +121 -0
|
@@ -0,0 +1,4590 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Represents an object that can be rendered to a string representation.
|
|
3
|
+
*
|
|
4
|
+
* This interface corresponds to the Swift Renderable protocol and serves as
|
|
5
|
+
* the foundation for all elements that can produce string output (e.g., HTML, CSS).
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* class MyElement implements Renderable {
|
|
10
|
+
* render(): string {
|
|
11
|
+
* return '<div>Hello</div>';
|
|
12
|
+
* }
|
|
13
|
+
* }
|
|
14
|
+
*
|
|
15
|
+
* const element = new MyElement();
|
|
16
|
+
* console.log(element.render()); // '<div>Hello</div>'
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
interface Renderable {
|
|
20
|
+
/**
|
|
21
|
+
* Renders the object to its string representation.
|
|
22
|
+
*
|
|
23
|
+
* @returns The string representation of the object
|
|
24
|
+
*/
|
|
25
|
+
render(): string;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Represents an object that can be exported to a file.
|
|
29
|
+
*
|
|
30
|
+
* This interface is used by publishers and other components that need to
|
|
31
|
+
* write content to the filesystem. It provides both the content to export
|
|
32
|
+
* and the method to perform the export operation.
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* ```typescript
|
|
36
|
+
* class HtmlDocument implements Exportable {
|
|
37
|
+
* readonly content: string;
|
|
38
|
+
*
|
|
39
|
+
* constructor(html: string) {
|
|
40
|
+
* this.content = html;
|
|
41
|
+
* }
|
|
42
|
+
*
|
|
43
|
+
* exportTo(fileName: string, path?: string): void {
|
|
44
|
+
* // Export logic here
|
|
45
|
+
* }
|
|
46
|
+
* }
|
|
47
|
+
*
|
|
48
|
+
* const doc = new HtmlDocument('<html>...</html>');
|
|
49
|
+
* doc.exportTo('index.html', './dist');
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
52
|
+
interface Exportable {
|
|
53
|
+
/**
|
|
54
|
+
* The content to be exported.
|
|
55
|
+
*
|
|
56
|
+
* This property holds the string content that will be written to the file.
|
|
57
|
+
*/
|
|
58
|
+
readonly content: string;
|
|
59
|
+
/**
|
|
60
|
+
* Exports the content to a file.
|
|
61
|
+
*
|
|
62
|
+
* @param fileName - The name of the file to create
|
|
63
|
+
* @param path - Optional directory path where the file should be created.
|
|
64
|
+
* If not provided, the file is created in the current directory.
|
|
65
|
+
*
|
|
66
|
+
* @throws {ExportableError} When the export operation fails
|
|
67
|
+
*/
|
|
68
|
+
exportTo(fileName: string, path?: string): void;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* CSS単位型の定義と変換関数
|
|
73
|
+
*
|
|
74
|
+
* CSS値に使用する単位の型安全な表現と、
|
|
75
|
+
* HlUnit から CSS 文字列への変換を提供する。
|
|
76
|
+
*/
|
|
77
|
+
/**
|
|
78
|
+
* CSS values unit types.
|
|
79
|
+
*
|
|
80
|
+
* Represents the allowed unit types for CSS dimensional values.
|
|
81
|
+
* The 'none' value is used for unitless numbers (e.g., line-height, opacity).
|
|
82
|
+
*
|
|
83
|
+
* @example
|
|
84
|
+
* ```typescript
|
|
85
|
+
* const pixelUnit: UnitStyle = 'px';
|
|
86
|
+
* const percentUnit: UnitStyle = '%';
|
|
87
|
+
* const unitless: UnitStyle = 'none';
|
|
88
|
+
* ```
|
|
89
|
+
*/
|
|
90
|
+
type UnitStyle = 'px' | 'em' | 'rem' | '%' | 'vw' | 'vh' | 'fr' | 'none';
|
|
91
|
+
/**
|
|
92
|
+
* CSS position property values.
|
|
93
|
+
*
|
|
94
|
+
* Represents the allowed values for the CSS `position` property,
|
|
95
|
+
* defining how an element is positioned in the document.
|
|
96
|
+
*
|
|
97
|
+
* @example
|
|
98
|
+
* ```typescript
|
|
99
|
+
* const position: RelationShip = 'absolute';
|
|
100
|
+
* const stickyHeader: RelationShip = 'sticky';
|
|
101
|
+
* ```
|
|
102
|
+
*
|
|
103
|
+
* @see {@link https://developer.mozilla.org/en-US/docs/Web/CSS/position | MDN position}
|
|
104
|
+
*/
|
|
105
|
+
type RelationShip = 'relative' | 'absolute' | 'static' | 'fixed' | 'sticky';
|
|
106
|
+
/**
|
|
107
|
+
* Represents a numeric value with its associated CSS unit.
|
|
108
|
+
*
|
|
109
|
+
* This interface provides type-safe representation of CSS dimensional values
|
|
110
|
+
* by pairing a numeric value with its unit type.
|
|
111
|
+
*
|
|
112
|
+
* @example
|
|
113
|
+
* ```typescript
|
|
114
|
+
* const width: HlUnit = { value: 100, unit: 'px' };
|
|
115
|
+
* const height: HlUnit = { value: 50, unit: '%' };
|
|
116
|
+
* const opacity: HlUnit = { value: 0.5, unit: 'none' };
|
|
117
|
+
* ```
|
|
118
|
+
*/
|
|
119
|
+
interface HlUnit {
|
|
120
|
+
/**
|
|
121
|
+
* The numeric value.
|
|
122
|
+
*/
|
|
123
|
+
value: number;
|
|
124
|
+
/**
|
|
125
|
+
* The unit type for the value.
|
|
126
|
+
*/
|
|
127
|
+
unit: UnitStyle;
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Converts an HlUnit to a CSS-compatible string.
|
|
131
|
+
*
|
|
132
|
+
* This function transforms a structured unit value into its string representation
|
|
133
|
+
* for use in CSS. When the unit is 'none', only the numeric value is returned.
|
|
134
|
+
*
|
|
135
|
+
* @param hlUnit - The HlUnit to convert
|
|
136
|
+
* @returns A CSS-compatible string representation
|
|
137
|
+
*
|
|
138
|
+
* @example
|
|
139
|
+
* ```typescript
|
|
140
|
+
* hlUnitToCssString({ value: 16, unit: 'px' }) // '16px'
|
|
141
|
+
* hlUnitToCssString({ value: 50, unit: '%' }) // '50%'
|
|
142
|
+
* hlUnitToCssString({ value: 1.5, unit: 'rem' }) // '1.5rem'
|
|
143
|
+
* hlUnitToCssString({ value: 0, unit: 'none' }) // '0'
|
|
144
|
+
* hlUnitToCssString({ value: 2, unit: 'none' }) // '2' (for unitless values like line-height)
|
|
145
|
+
* ```
|
|
146
|
+
*/
|
|
147
|
+
declare function hlUnitToCssString(hlUnit: HlUnit): string;
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Tag structure classification.
|
|
151
|
+
*
|
|
152
|
+
* - **pair**: Elements with opening and closing tags (e.g., `<div>...</div>`)
|
|
153
|
+
* - **selfClosing**: Self-closing (void) elements (e.g., `<br>`)
|
|
154
|
+
*/
|
|
155
|
+
type TagStructure = 'pair' | 'selfClosing';
|
|
156
|
+
/**
|
|
157
|
+
* Constant object defining all 97 HTML tag types.
|
|
158
|
+
*
|
|
159
|
+
* This object uses HTML standard tag names as keys (unlike Swift version which used
|
|
160
|
+
* enum aliases like `paragraph="p"`, `bold="b"`). As a result, TypeScript version
|
|
161
|
+
* has 97 unique entries vs Swift's 66 cases (including aliases).
|
|
162
|
+
*
|
|
163
|
+
* **Categories:**
|
|
164
|
+
* - **Basic (10):** html, head, body, div, p, span, script, root, text, doctype
|
|
165
|
+
* - **Semantic (9):** header, footer, nav, main, section, article, aside, figure, figcaption
|
|
166
|
+
* - **Table (9):** table, thead, tbody, tfoot, tr, th, td, caption, colgroup
|
|
167
|
+
* - **List (6):** ul, ol, li, dl, dt, dd
|
|
168
|
+
* - **Form (11):** form, label, button, select, option, optgroup, textarea, fieldset, legend, datalist, output
|
|
169
|
+
* - **Text Decoration (20):** strong, em, b, i, u, s, mark, small, sub, sup, code, pre, blockquote, q, cite, abbr, address, time, kbd, samp
|
|
170
|
+
* - **Heading (6):** h1, h2, h3, h4, h5, h6
|
|
171
|
+
* - **Media (5):** video, audio, picture, canvas, svg
|
|
172
|
+
* - **Interactive (5):** details, summary, dialog, iframe, noscript
|
|
173
|
+
* - **Self-Closing (13):** br, hr, img, input, meta, link, source, track, area, col, base, embed, wbr
|
|
174
|
+
* - **Other (3):** a, title, var
|
|
175
|
+
*
|
|
176
|
+
* **Total:** 10 + 9 + 9 + 6 + 11 + 20 + 6 + 5 + 5 + 13 + 3 = 97
|
|
177
|
+
*
|
|
178
|
+
* @example
|
|
179
|
+
* ```typescript
|
|
180
|
+
* import { TAG_TYPES } from './tag-type.js';
|
|
181
|
+
*
|
|
182
|
+
* console.log(TAG_TYPES.div); // 'div'
|
|
183
|
+
* console.log(TAG_TYPES.p); // 'p'
|
|
184
|
+
* console.log(TAG_TYPES.br); // 'br'
|
|
185
|
+
* ```
|
|
186
|
+
*/
|
|
187
|
+
declare const TAG_TYPES: {
|
|
188
|
+
readonly html: "html";
|
|
189
|
+
readonly head: "head";
|
|
190
|
+
readonly body: "body";
|
|
191
|
+
readonly div: "div";
|
|
192
|
+
readonly p: "p";
|
|
193
|
+
readonly span: "span";
|
|
194
|
+
readonly script: "script";
|
|
195
|
+
readonly root: "root";
|
|
196
|
+
readonly text: "text";
|
|
197
|
+
readonly doctype: "doctype";
|
|
198
|
+
readonly header: "header";
|
|
199
|
+
readonly footer: "footer";
|
|
200
|
+
readonly nav: "nav";
|
|
201
|
+
readonly main: "main";
|
|
202
|
+
readonly section: "section";
|
|
203
|
+
readonly article: "article";
|
|
204
|
+
readonly aside: "aside";
|
|
205
|
+
readonly figure: "figure";
|
|
206
|
+
readonly figcaption: "figcaption";
|
|
207
|
+
readonly table: "table";
|
|
208
|
+
readonly thead: "thead";
|
|
209
|
+
readonly tbody: "tbody";
|
|
210
|
+
readonly tfoot: "tfoot";
|
|
211
|
+
readonly tr: "tr";
|
|
212
|
+
readonly th: "th";
|
|
213
|
+
readonly td: "td";
|
|
214
|
+
readonly caption: "caption";
|
|
215
|
+
readonly colgroup: "colgroup";
|
|
216
|
+
readonly ul: "ul";
|
|
217
|
+
readonly ol: "ol";
|
|
218
|
+
readonly li: "li";
|
|
219
|
+
readonly dl: "dl";
|
|
220
|
+
readonly dt: "dt";
|
|
221
|
+
readonly dd: "dd";
|
|
222
|
+
readonly form: "form";
|
|
223
|
+
readonly label: "label";
|
|
224
|
+
readonly button: "button";
|
|
225
|
+
readonly select: "select";
|
|
226
|
+
readonly option: "option";
|
|
227
|
+
readonly optgroup: "optgroup";
|
|
228
|
+
readonly textarea: "textarea";
|
|
229
|
+
readonly fieldset: "fieldset";
|
|
230
|
+
readonly legend: "legend";
|
|
231
|
+
readonly datalist: "datalist";
|
|
232
|
+
readonly output: "output";
|
|
233
|
+
readonly strong: "strong";
|
|
234
|
+
readonly em: "em";
|
|
235
|
+
readonly b: "b";
|
|
236
|
+
readonly i: "i";
|
|
237
|
+
readonly u: "u";
|
|
238
|
+
readonly s: "s";
|
|
239
|
+
readonly mark: "mark";
|
|
240
|
+
readonly small: "small";
|
|
241
|
+
readonly sub: "sub";
|
|
242
|
+
readonly sup: "sup";
|
|
243
|
+
readonly code: "code";
|
|
244
|
+
readonly pre: "pre";
|
|
245
|
+
readonly blockquote: "blockquote";
|
|
246
|
+
readonly q: "q";
|
|
247
|
+
readonly cite: "cite";
|
|
248
|
+
readonly abbr: "abbr";
|
|
249
|
+
readonly address: "address";
|
|
250
|
+
readonly time: "time";
|
|
251
|
+
readonly kbd: "kbd";
|
|
252
|
+
readonly samp: "samp";
|
|
253
|
+
readonly h1: "h1";
|
|
254
|
+
readonly h2: "h2";
|
|
255
|
+
readonly h3: "h3";
|
|
256
|
+
readonly h4: "h4";
|
|
257
|
+
readonly h5: "h5";
|
|
258
|
+
readonly h6: "h6";
|
|
259
|
+
readonly video: "video";
|
|
260
|
+
readonly audio: "audio";
|
|
261
|
+
readonly picture: "picture";
|
|
262
|
+
readonly canvas: "canvas";
|
|
263
|
+
readonly svg: "svg";
|
|
264
|
+
readonly details: "details";
|
|
265
|
+
readonly summary: "summary";
|
|
266
|
+
readonly dialog: "dialog";
|
|
267
|
+
readonly iframe: "iframe";
|
|
268
|
+
readonly noscript: "noscript";
|
|
269
|
+
readonly br: "br";
|
|
270
|
+
readonly hr: "hr";
|
|
271
|
+
readonly img: "img";
|
|
272
|
+
readonly input: "input";
|
|
273
|
+
readonly meta: "meta";
|
|
274
|
+
readonly link: "link";
|
|
275
|
+
readonly source: "source";
|
|
276
|
+
readonly track: "track";
|
|
277
|
+
readonly area: "area";
|
|
278
|
+
readonly col: "col";
|
|
279
|
+
readonly base: "base";
|
|
280
|
+
readonly embed: "embed";
|
|
281
|
+
readonly wbr: "wbr";
|
|
282
|
+
readonly a: "a";
|
|
283
|
+
readonly title: "title";
|
|
284
|
+
readonly var: "var";
|
|
285
|
+
};
|
|
286
|
+
/**
|
|
287
|
+
* Union type of all HTML tag types.
|
|
288
|
+
*
|
|
289
|
+
* Derived from the values of {@link TAG_TYPES} as a string literal union.
|
|
290
|
+
*
|
|
291
|
+
* @example
|
|
292
|
+
* ```typescript
|
|
293
|
+
* const tagName: TagType = 'div'; // Valid
|
|
294
|
+
* const invalid: TagType = 'foo'; // Type error
|
|
295
|
+
* ```
|
|
296
|
+
*/
|
|
297
|
+
type TagType = typeof TAG_TYPES[keyof typeof TAG_TYPES];
|
|
298
|
+
/**
|
|
299
|
+
* Set of all 13 standard HTML void (self-closing) elements.
|
|
300
|
+
*
|
|
301
|
+
* **Included Tags:**
|
|
302
|
+
* br, hr, img, input, meta, link, source, track, area, col, base, embed, wbr
|
|
303
|
+
*
|
|
304
|
+
* **Note:** `doctype` is not included (handled as a special case).
|
|
305
|
+
*
|
|
306
|
+
* @example
|
|
307
|
+
* ```typescript
|
|
308
|
+
* import { SELF_CLOSING_TAGS } from './tag-type.js';
|
|
309
|
+
*
|
|
310
|
+
* console.log(SELF_CLOSING_TAGS.has('br')); // true
|
|
311
|
+
* console.log(SELF_CLOSING_TAGS.has('div')); // false
|
|
312
|
+
* ```
|
|
313
|
+
*/
|
|
314
|
+
declare const SELF_CLOSING_TAGS: ReadonlySet<TagType>;
|
|
315
|
+
/**
|
|
316
|
+
* Determines the structure type of a given HTML tag.
|
|
317
|
+
*
|
|
318
|
+
* @param tag - The tag type to check
|
|
319
|
+
* @returns 'selfClosing' if the tag is a void element, 'pair' otherwise
|
|
320
|
+
*
|
|
321
|
+
* @example
|
|
322
|
+
* ```typescript
|
|
323
|
+
* import { getTagStructure, TAG_TYPES } from './tag-type.js';
|
|
324
|
+
*
|
|
325
|
+
* console.log(getTagStructure(TAG_TYPES.br)); // 'selfClosing'
|
|
326
|
+
* console.log(getTagStructure(TAG_TYPES.div)); // 'pair'
|
|
327
|
+
* console.log(getTagStructure(TAG_TYPES.img)); // 'selfClosing'
|
|
328
|
+
* console.log(getTagStructure(TAG_TYPES.p)); // 'pair'
|
|
329
|
+
* ```
|
|
330
|
+
*/
|
|
331
|
+
declare function getTagStructure(tag: TagType): TagStructure;
|
|
332
|
+
|
|
333
|
+
/**
|
|
334
|
+
* HTML属性値のdiscriminated union型と factory 関数
|
|
335
|
+
*
|
|
336
|
+
* Swift版 HtmlAttributeValue に対応する TypeScript 型定義と、
|
|
337
|
+
* 各 variant の安全な生成を支援する factory 関数群を提供する。
|
|
338
|
+
*/
|
|
339
|
+
/**
|
|
340
|
+
* Represents a boolean HTML attribute (e.g., disabled, checked, hidden).
|
|
341
|
+
*
|
|
342
|
+
* @remarks
|
|
343
|
+
* Boolean attributes render as just the attribute name without a value.
|
|
344
|
+
*
|
|
345
|
+
* @example
|
|
346
|
+
* ```typescript
|
|
347
|
+
* const value: BooleanAttributeValue = { type: 'boolean' };
|
|
348
|
+
* // Renders as: 'disabled' (not 'disabled="true"')
|
|
349
|
+
* ```
|
|
350
|
+
*/
|
|
351
|
+
interface BooleanAttributeValue {
|
|
352
|
+
readonly type: 'boolean';
|
|
353
|
+
}
|
|
354
|
+
/**
|
|
355
|
+
* Represents a key-value HTML attribute (e.g., id="main", class="container").
|
|
356
|
+
*
|
|
357
|
+
* @remarks
|
|
358
|
+
* Key-value attributes render as `key="value"` with the value automatically HTML-escaped.
|
|
359
|
+
*
|
|
360
|
+
* @example
|
|
361
|
+
* ```typescript
|
|
362
|
+
* const value: KeyValueAttributeValue = { type: 'keyValue', value: 'main-content' };
|
|
363
|
+
* // Renders as: 'id="main-content"'
|
|
364
|
+
* ```
|
|
365
|
+
*/
|
|
366
|
+
interface KeyValueAttributeValue {
|
|
367
|
+
readonly type: 'keyValue';
|
|
368
|
+
readonly value: string;
|
|
369
|
+
}
|
|
370
|
+
/**
|
|
371
|
+
* Represents a custom data-* HTML attribute (e.g., data-theme="dark").
|
|
372
|
+
*
|
|
373
|
+
* @remarks
|
|
374
|
+
* Custom attributes render as `data-{name}="{value}"` with the value automatically HTML-escaped.
|
|
375
|
+
*
|
|
376
|
+
* @example
|
|
377
|
+
* ```typescript
|
|
378
|
+
* const value: CustomAttributeValue = { type: 'custom', name: 'theme', value: 'dark' };
|
|
379
|
+
* // Renders as: 'data-theme="dark"'
|
|
380
|
+
* ```
|
|
381
|
+
*/
|
|
382
|
+
interface CustomAttributeValue {
|
|
383
|
+
readonly type: 'custom';
|
|
384
|
+
readonly name: string;
|
|
385
|
+
readonly value: string;
|
|
386
|
+
}
|
|
387
|
+
/**
|
|
388
|
+
* Discriminated union type for all HTML attribute value types.
|
|
389
|
+
*
|
|
390
|
+
* @remarks
|
|
391
|
+
* This type enables type-safe handling of different attribute value types
|
|
392
|
+
* using TypeScript's discriminated union pattern.
|
|
393
|
+
*
|
|
394
|
+
* @example
|
|
395
|
+
* ```typescript
|
|
396
|
+
* function renderValue(attrValue: HtmlAttributeValue): string {
|
|
397
|
+
* switch (attrValue.type) {
|
|
398
|
+
* case 'boolean':
|
|
399
|
+
* return 'attribute-name';
|
|
400
|
+
* case 'keyValue':
|
|
401
|
+
* return `attribute-name="${attrValue.value}"`;
|
|
402
|
+
* case 'custom':
|
|
403
|
+
* return `data-${attrValue.name}="${attrValue.value}"`;
|
|
404
|
+
* }
|
|
405
|
+
* }
|
|
406
|
+
* ```
|
|
407
|
+
*/
|
|
408
|
+
type HtmlAttributeValue = BooleanAttributeValue | KeyValueAttributeValue | CustomAttributeValue;
|
|
409
|
+
/**
|
|
410
|
+
* Creates a boolean attribute value.
|
|
411
|
+
*
|
|
412
|
+
* @returns A BooleanAttributeValue instance
|
|
413
|
+
*
|
|
414
|
+
* @example
|
|
415
|
+
* ```typescript
|
|
416
|
+
* const disabled = createBooleanValue();
|
|
417
|
+
* // Returns: { type: 'boolean' }
|
|
418
|
+
* ```
|
|
419
|
+
*/
|
|
420
|
+
declare function createBooleanValue(): BooleanAttributeValue;
|
|
421
|
+
/**
|
|
422
|
+
* Creates a key-value attribute value.
|
|
423
|
+
*
|
|
424
|
+
* @param value - The attribute value
|
|
425
|
+
* @returns A KeyValueAttributeValue instance
|
|
426
|
+
*
|
|
427
|
+
* @example
|
|
428
|
+
* ```typescript
|
|
429
|
+
* const id = createKeyValueValue('main-content');
|
|
430
|
+
* // Returns: { type: 'keyValue', value: 'main-content' }
|
|
431
|
+
* ```
|
|
432
|
+
*/
|
|
433
|
+
declare function createKeyValueValue(value: string): KeyValueAttributeValue;
|
|
434
|
+
/**
|
|
435
|
+
* Creates a custom data-* attribute value.
|
|
436
|
+
*
|
|
437
|
+
* @param name - The data attribute name (without 'data-' prefix)
|
|
438
|
+
* @param value - The attribute value
|
|
439
|
+
* @returns A CustomAttributeValue instance
|
|
440
|
+
*
|
|
441
|
+
* @example
|
|
442
|
+
* ```typescript
|
|
443
|
+
* const theme = createCustomValue('theme', 'dark');
|
|
444
|
+
* // Returns: { type: 'custom', name: 'theme', value: 'dark' }
|
|
445
|
+
* ```
|
|
446
|
+
*/
|
|
447
|
+
declare function createCustomValue(name: string, value: string): CustomAttributeValue;
|
|
448
|
+
|
|
449
|
+
/**
|
|
450
|
+
* ChildManageable: 子要素管理の責務インターフェース
|
|
451
|
+
*
|
|
452
|
+
* HTMLタグの子要素追加・管理に関する操作を定義する。
|
|
453
|
+
* HTMLTagProtocol はこのインターフェースを継承して子要素管理機能を提供する。
|
|
454
|
+
*
|
|
455
|
+
* Task 5.1: HTMLTagProtocol の責務明確化(Requirement 4.4)
|
|
456
|
+
*
|
|
457
|
+
* Preconditions: children は追加順に保持される
|
|
458
|
+
* Postconditions: addChild/addChildren は this を返却(メソッドチェーン可能)
|
|
459
|
+
* Invariants: 子要素の順序は変更されない
|
|
460
|
+
*/
|
|
461
|
+
|
|
462
|
+
/**
|
|
463
|
+
* 子要素管理の責務インターフェース
|
|
464
|
+
*
|
|
465
|
+
* @remarks
|
|
466
|
+
* このインターフェースは、HTMLタグの子要素を管理する責務を定義します。
|
|
467
|
+
* メソッドチェーンをサポートするため、すべてのメソッドは `this` を返します。
|
|
468
|
+
*
|
|
469
|
+
* @example
|
|
470
|
+
* ```typescript
|
|
471
|
+
* const div = new PairType('div');
|
|
472
|
+
* div.addChild(new TextType('Hello'))
|
|
473
|
+
* .addChild(new TextType('World'));
|
|
474
|
+
*
|
|
475
|
+
* console.log(div.children.length); // 2
|
|
476
|
+
* ```
|
|
477
|
+
*/
|
|
478
|
+
interface ChildManageable {
|
|
479
|
+
/**
|
|
480
|
+
* 子要素の読み取り専用配列
|
|
481
|
+
*
|
|
482
|
+
* @remarks
|
|
483
|
+
* 子要素は追加順に保持されます。
|
|
484
|
+
* 直接配列を変更することはできません。addChild/addChildren メソッドを使用してください。
|
|
485
|
+
*/
|
|
486
|
+
readonly children: ReadonlyArray<HTMLTagProtocol>;
|
|
487
|
+
/**
|
|
488
|
+
* 子要素を1つ追加
|
|
489
|
+
*
|
|
490
|
+
* @param child - 追加する子要素
|
|
491
|
+
* @returns メソッドチェーンのため、this を返す
|
|
492
|
+
*
|
|
493
|
+
* @remarks
|
|
494
|
+
* 子要素は配列の末尾に追加されます。
|
|
495
|
+
*
|
|
496
|
+
* @example
|
|
497
|
+
* ```typescript
|
|
498
|
+
* div.addChild(new TextType('Hello'));
|
|
499
|
+
* ```
|
|
500
|
+
*/
|
|
501
|
+
addChild(child: HTMLTagProtocol): this;
|
|
502
|
+
/**
|
|
503
|
+
* 子要素を複数追加
|
|
504
|
+
*
|
|
505
|
+
* @param children - 追加する子要素の配列
|
|
506
|
+
* @returns メソッドチェーンのため、this を返す
|
|
507
|
+
*
|
|
508
|
+
* @remarks
|
|
509
|
+
* 子要素は配列の順序通りに追加されます。
|
|
510
|
+
*
|
|
511
|
+
* @example
|
|
512
|
+
* ```typescript
|
|
513
|
+
* div.addChildren([
|
|
514
|
+
* new TextType('Hello'),
|
|
515
|
+
* new TextType('World')
|
|
516
|
+
* ]);
|
|
517
|
+
* ```
|
|
518
|
+
*/
|
|
519
|
+
addChildren(children: ReadonlyArray<HTMLTagProtocol>): this;
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
/**
|
|
523
|
+
* AttributeManageable: 属性管理の責務インターフェース
|
|
524
|
+
*
|
|
525
|
+
* HTMLタグの属性追加・管理に関する操作を定義する。
|
|
526
|
+
* HTMLTagProtocol はこのインターフェースを継承して属性管理機能を提供する。
|
|
527
|
+
*
|
|
528
|
+
* Task 5.1: HTMLTagProtocol の責務明確化(Requirement 4.4)
|
|
529
|
+
*
|
|
530
|
+
* Preconditions: attributes は追加順に保持される
|
|
531
|
+
* Postconditions: addHtmlAttribute は this を返却(メソッドチェーン可能)
|
|
532
|
+
* Invariants: 属性の順序は変更されない
|
|
533
|
+
*/
|
|
534
|
+
|
|
535
|
+
/**
|
|
536
|
+
* 属性管理の責務インターフェース
|
|
537
|
+
*
|
|
538
|
+
* @remarks
|
|
539
|
+
* このインターフェースは、HTMLタグの属性を管理する責務を定義します。
|
|
540
|
+
* メソッドチェーンをサポートするため、すべてのメソッドは `this` を返します。
|
|
541
|
+
*
|
|
542
|
+
* @example
|
|
543
|
+
* ```typescript
|
|
544
|
+
* const div = new PairType('div');
|
|
545
|
+
* div.addHtmlAttribute(new HtmlAttribute('id', 'test-id'))
|
|
546
|
+
* .addHtmlAttribute(new HtmlAttribute('class', 'test-class'));
|
|
547
|
+
*
|
|
548
|
+
* console.log(div.attributes.length); // 2
|
|
549
|
+
* ```
|
|
550
|
+
*/
|
|
551
|
+
interface AttributeManageable {
|
|
552
|
+
/**
|
|
553
|
+
* 属性の読み取り専用配列
|
|
554
|
+
*
|
|
555
|
+
* @remarks
|
|
556
|
+
* 属性は追加順に保持されます。
|
|
557
|
+
* 直接配列を変更することはできません。addHtmlAttribute メソッドを使用してください。
|
|
558
|
+
*/
|
|
559
|
+
readonly attributes: ReadonlyArray<HtmlAttributeShape>;
|
|
560
|
+
/**
|
|
561
|
+
* HTML属性を1つ追加
|
|
562
|
+
*
|
|
563
|
+
* @param attribute - 追加する属性オブジェクト
|
|
564
|
+
* @returns メソッドチェーンのため、this を返す
|
|
565
|
+
*
|
|
566
|
+
* @remarks
|
|
567
|
+
* 属性は配列の末尾に追加されます。
|
|
568
|
+
* 同じ key の属性を複数追加した場合、後の属性が優先されます(HTML仕様に従う)。
|
|
569
|
+
*
|
|
570
|
+
* @example
|
|
571
|
+
* ```typescript
|
|
572
|
+
* div.addHtmlAttribute(new HtmlAttribute('id', 'test-id'));
|
|
573
|
+
* ```
|
|
574
|
+
*/
|
|
575
|
+
addHtmlAttribute(attribute: HtmlAttributeShape): this;
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
/**
|
|
579
|
+
* IdRegistry の公開インターフェイス
|
|
580
|
+
*/
|
|
581
|
+
interface IdRegistryProtocol {
|
|
582
|
+
/**
|
|
583
|
+
* id を登録する。既に同じ id が登録されている場合は HtmlError をスローする。
|
|
584
|
+
*
|
|
585
|
+
* @param id - 登録対象の id 文字列
|
|
586
|
+
* @param tagPath - 当該 id を持つタグの構造パス(エラー時の特定用)
|
|
587
|
+
* @throws {HtmlError} 既に同じ id が登録済みの場合
|
|
588
|
+
*/
|
|
589
|
+
register(id: string, tagPath: string): void;
|
|
590
|
+
/**
|
|
591
|
+
* 指定 id が登録済みかを返す。
|
|
592
|
+
*/
|
|
593
|
+
has(id: string): boolean;
|
|
594
|
+
/**
|
|
595
|
+
* 登録済み id をすべて破棄する。
|
|
596
|
+
*/
|
|
597
|
+
reset(): void;
|
|
598
|
+
}
|
|
599
|
+
/**
|
|
600
|
+
* 内部 Map で id を管理する IdRegistry の標準実装。
|
|
601
|
+
*/
|
|
602
|
+
declare class IdRegistry implements IdRegistryProtocol {
|
|
603
|
+
/** id → 最初に登録された tagPath */
|
|
604
|
+
private readonly entries;
|
|
605
|
+
/**
|
|
606
|
+
* id を登録する。重複検出時は HtmlError をスローする。
|
|
607
|
+
*/
|
|
608
|
+
register(id: string, tagPath: string): void;
|
|
609
|
+
/**
|
|
610
|
+
* 登録済みかを返す。
|
|
611
|
+
*/
|
|
612
|
+
has(id: string): boolean;
|
|
613
|
+
/**
|
|
614
|
+
* 登録をすべて破棄する。
|
|
615
|
+
*/
|
|
616
|
+
reset(): void;
|
|
617
|
+
}
|
|
618
|
+
|
|
619
|
+
/**
|
|
620
|
+
* 識別子リゾルバ(IdentifierResolver)
|
|
621
|
+
*
|
|
622
|
+
* 構造パス(tagPath)から CSS クラス名と HTML id を決定的に生成する純関数群。
|
|
623
|
+
* 同じ入力に対して常に同じ出力を返し、副作用を持たない(ビルド間で安定)。
|
|
624
|
+
*
|
|
625
|
+
* ## 設計方針
|
|
626
|
+
*
|
|
627
|
+
* - **バイト等価(受動追従)**: `resolveClassName(tagPath)` の bodyHash 省略経路は
|
|
628
|
+
* `generateScopedClassName(tagPath)` の出力に **バイト等価** な値を返す。
|
|
629
|
+
* THEMECLASS-3 で `generateScopedClassName` が debuggable prefix 形式
|
|
630
|
+
* (例: `_body-div-header__a1b2c3d4`)に拡張された場合、本関数は委譲によって
|
|
631
|
+
* 受動的に新フォーマットへ追従する(自関数内で prefix 生成ロジックを持たない)。
|
|
632
|
+
* - **bodyHash 付き経路の据え置き**: `bodyHash` 指定時は現フォーマット
|
|
633
|
+
* `_<djb2(tagPath)>_<djb2(bodyHash)>` を維持する。本経路は THEMECLASS-3 の
|
|
634
|
+
* debuggable prefix 適用対象外(本 spec のスコープ外)であり、新 prefix は
|
|
635
|
+
* 付与しない。
|
|
636
|
+
* - **id 生成**: `resolveId(tagPath)` は `_id_<djb2(tagPath)>` 形式を返し、
|
|
637
|
+
* クラス名空間とは `_id_` プレフィックスで名前空間が分離される(要件 3.5)。
|
|
638
|
+
*
|
|
639
|
+
* 要件: 1.2, 1.3, 2.3, 3.1, 3.3, 3.4, 3.5, 3.6, 3.7, 5.1, 5.2
|
|
640
|
+
*
|
|
641
|
+
* @module identifier-resolver
|
|
642
|
+
*/
|
|
643
|
+
/**
|
|
644
|
+
* 識別子リゾルバのインターフェース
|
|
645
|
+
*
|
|
646
|
+
* tagPath からクラス名・ID を決定的に生成する責務を持つ。
|
|
647
|
+
* 純関数の集合体としてふるまい、状態を持たない。
|
|
648
|
+
*/
|
|
649
|
+
interface IdentifierResolver {
|
|
650
|
+
/**
|
|
651
|
+
* tagPath(と任意の bodyHash, varName)から CSS クラス名を解決する。
|
|
652
|
+
*
|
|
653
|
+
* @param tagPath - 要素の構造パス(例: `'html>body>div'`)
|
|
654
|
+
* @param bodyHash - スタイル本体の djb2 ハッシュ(省略可)
|
|
655
|
+
* @param varName - `theme.class()` 呼び出し由来の変数名(省略可)。
|
|
656
|
+
* `bodyHash === undefined && varName !== undefined && varName !== ''` の場合のみ
|
|
657
|
+
* `generateScopedClassNameWithVarName(tagPath, varName)` 経路に分岐する。
|
|
658
|
+
*/
|
|
659
|
+
resolveClassName(tagPath: string, bodyHash?: string, varName?: string): string;
|
|
660
|
+
/**
|
|
661
|
+
* tagPath から HTML id 文字列を解決する。
|
|
662
|
+
*
|
|
663
|
+
* @param tagPath - 要素の構造パス
|
|
664
|
+
*/
|
|
665
|
+
resolveId(tagPath: string): string;
|
|
666
|
+
}
|
|
667
|
+
|
|
668
|
+
/**
|
|
669
|
+
* CSS出力設定クラス
|
|
670
|
+
*
|
|
671
|
+
* CSS出力の振る舞いを制御する設定を管理する。
|
|
672
|
+
* スコープドCSSの有効/無効と出力モードを設定できる。
|
|
673
|
+
*
|
|
674
|
+
* ## 設定項目
|
|
675
|
+
*
|
|
676
|
+
* - **scopedCssEnabled**: スコープドCSSの有効/無効
|
|
677
|
+
* - `true`: タグパスからハッシュクラス名を生成してCSSをラップ
|
|
678
|
+
* - `false`: インラインスタイル形式で出力
|
|
679
|
+
* - **outputMode**: 出力モード
|
|
680
|
+
* - `'inline'`: インラインスタイルとして出力
|
|
681
|
+
* - `'external'`: 外部CSSファイル用の出力
|
|
682
|
+
*
|
|
683
|
+
* @example
|
|
684
|
+
* ```ts
|
|
685
|
+
* // デフォルト設定(スコープドCSS有効、インラインモード)
|
|
686
|
+
* const config1 = new CssConfig();
|
|
687
|
+
* console.log(config1.scopedCssEnabled); // → true
|
|
688
|
+
* console.log(config1.outputMode); // → 'inline'
|
|
689
|
+
*
|
|
690
|
+
* // カスタム設定
|
|
691
|
+
* const config2 = new CssConfig({
|
|
692
|
+
* scopedCssEnabled: false,
|
|
693
|
+
* outputMode: 'external'
|
|
694
|
+
* });
|
|
695
|
+
*
|
|
696
|
+
* const manager = new CssManager('html>body>div', config2);
|
|
697
|
+
* ```
|
|
698
|
+
*/
|
|
699
|
+
/**
|
|
700
|
+
* CSS出力モード
|
|
701
|
+
*
|
|
702
|
+
* - `'inline'`: インラインスタイルとして出力
|
|
703
|
+
* - `'external'`: 外部CSSファイル用の出力
|
|
704
|
+
*/
|
|
705
|
+
type CssConfigOutputMode = 'inline' | 'external';
|
|
706
|
+
/**
|
|
707
|
+
* CssConfig コンストラクタオプション
|
|
708
|
+
*/
|
|
709
|
+
interface CssConfigOptions {
|
|
710
|
+
/** スコープドCSSの有効/無効 */
|
|
711
|
+
scopedCssEnabled: boolean;
|
|
712
|
+
/** 出力モード */
|
|
713
|
+
outputMode: CssConfigOutputMode;
|
|
714
|
+
/**
|
|
715
|
+
* scoped CSS クラス名の minify モード
|
|
716
|
+
*
|
|
717
|
+
* - `true`: `_<8hex>` 形式(コンパクト、production 向け)
|
|
718
|
+
* - `false`: debuggable 形式(既定)
|
|
719
|
+
* - 省略時は `process.env.NODE_ENV === 'production'` を fallback として参照する
|
|
720
|
+
*/
|
|
721
|
+
minifyClassNames?: boolean;
|
|
722
|
+
}
|
|
723
|
+
/**
|
|
724
|
+
* CSS出力設定
|
|
725
|
+
*/
|
|
726
|
+
declare class CssConfig {
|
|
727
|
+
/**
|
|
728
|
+
* スコープドCSSの有効/無効
|
|
729
|
+
*
|
|
730
|
+
* `true` の場合、タグパスからハッシュクラス名を生成してCSSをラップする。
|
|
731
|
+
* `false` の場合、インラインスタイル形式で出力する。
|
|
732
|
+
*
|
|
733
|
+
* @default true
|
|
734
|
+
*/
|
|
735
|
+
scopedCssEnabled: boolean;
|
|
736
|
+
/**
|
|
737
|
+
* 出力モード
|
|
738
|
+
*
|
|
739
|
+
* - `'inline'`: インラインスタイルとして出力
|
|
740
|
+
* - `'external'`: 外部CSSファイル用の出力
|
|
741
|
+
*
|
|
742
|
+
* @default 'inline'
|
|
743
|
+
*/
|
|
744
|
+
outputMode: CssConfigOutputMode;
|
|
745
|
+
/**
|
|
746
|
+
* scoped CSS クラス名の minify モード(解決済み)
|
|
747
|
+
*
|
|
748
|
+
* コンストラクタで `options.minifyClassNames` と `process.env.NODE_ENV` から
|
|
749
|
+
* 一度だけ解決され、以後は不変。
|
|
750
|
+
*
|
|
751
|
+
* - `true`: `_<8hex>` 形式(コンパクト)
|
|
752
|
+
* - `false`: debuggable 形式
|
|
753
|
+
*
|
|
754
|
+
* @default false(NODE_ENV !== 'production' のとき)
|
|
755
|
+
*/
|
|
756
|
+
readonly minifyClassNames: boolean;
|
|
757
|
+
/**
|
|
758
|
+
* CssConfig を構築する
|
|
759
|
+
*
|
|
760
|
+
* @param options - 設定オプション(省略時はデフォルト値を使用)
|
|
761
|
+
*/
|
|
762
|
+
constructor(options?: Partial<CssConfigOptions>);
|
|
763
|
+
}
|
|
764
|
+
|
|
765
|
+
/**
|
|
766
|
+
* RenderContext — protoRender 系メソッドが共有する単一コンテキスト。
|
|
767
|
+
*
|
|
768
|
+
* Requirements: 3.1(id 自動生成)、3.4(id 重複検出)
|
|
769
|
+
*
|
|
770
|
+
* 設計メモ:
|
|
771
|
+
* - `IdRegistry` と `IdentifierResolver` をひとつのオブジェクトに束ねて
|
|
772
|
+
* レンダーツリー全体で同一インスタンスを伝搬させるための器。
|
|
773
|
+
* - 既存の `protoRender` シグネチャに **optional 引数** として追加できる
|
|
774
|
+
* 形にしてあり、ctx 省略時は呼び出し側が `createDefaultRenderContext()`
|
|
775
|
+
* などで自前生成して旧挙動互換を保つ運用を想定する。
|
|
776
|
+
* - サブクラス(Root / PairType / SelfClosingType / TextType)の override は、
|
|
777
|
+
* 受け取った ctx を子要素 `protoRender(ctx)` に **必ず伝搬する責務**を持つ。
|
|
778
|
+
* 伝搬漏れは Req 3.4 の不達につながる(design.md 参照)。
|
|
779
|
+
*
|
|
780
|
+
* このファイルは純粋な型定義 + 軽量ファクトリのみで、副作用や
|
|
781
|
+
* ランタイム依存を持たない。
|
|
782
|
+
*/
|
|
783
|
+
|
|
784
|
+
/**
|
|
785
|
+
* レンダーフェーズ全体で共有するコンテキスト。
|
|
786
|
+
*
|
|
787
|
+
* - `registry`: ツリー単位で id 重複を検出するためのレジストリ。
|
|
788
|
+
* Root.protoRender() の冒頭で `reset()` され、以降の子要素レンダーで
|
|
789
|
+
* 同一インスタンスを共有する。
|
|
790
|
+
* - `resolver`: tagPath からクラス名・id を決定的に生成する純関数群。
|
|
791
|
+
* ステートレスなので使い回し可能。
|
|
792
|
+
*/
|
|
793
|
+
interface RenderContext {
|
|
794
|
+
readonly registry: IdRegistry;
|
|
795
|
+
readonly resolver: IdentifierResolver;
|
|
796
|
+
/**
|
|
797
|
+
* ファクトリ抽出モードフラグ。
|
|
798
|
+
*
|
|
799
|
+
* `true` の場合、`each` などの factory 由来コンポーネントの
|
|
800
|
+
* 抽出経路を有効化する(後続タスクで実装)。
|
|
801
|
+
* 未設定または `false` の場合は従来挙動を維持する。
|
|
802
|
+
*
|
|
803
|
+
* Requirements: 1.1, 2.1
|
|
804
|
+
*/
|
|
805
|
+
readonly factoryExtraction?: boolean;
|
|
806
|
+
}
|
|
807
|
+
|
|
808
|
+
/**
|
|
809
|
+
* HTMLTagProtocol: HTMLタグの共通操作を定義する複合インターフェース
|
|
810
|
+
*
|
|
811
|
+
* Phase 1の Renderable を拡張し、HTMLタグ固有の操作を追加する。
|
|
812
|
+
* CSS/JS機能はスタブとして定義し、Phase 3/4で具象化する。
|
|
813
|
+
*
|
|
814
|
+
* Task 5.1: ChildManageable と AttributeManageable を継承して責務を明確化
|
|
815
|
+
*
|
|
816
|
+
* Requirements: 1.1, 1.7, 4.4
|
|
817
|
+
*/
|
|
818
|
+
|
|
819
|
+
/**
|
|
820
|
+
* HTML属性の構造を定義する型
|
|
821
|
+
*
|
|
822
|
+
* このインターフェースは、HTML属性の最小限の形状を定義します。
|
|
823
|
+
* 具象クラス(HtmlAttribute)は Task 2.1 で実装されます。
|
|
824
|
+
*
|
|
825
|
+
* @remarks
|
|
826
|
+
* HTMLTagProtocol が参照する属性の契約を定義し、
|
|
827
|
+
* 属性のキー、値、およびレンダリング機能を提供します。
|
|
828
|
+
*
|
|
829
|
+
* @example
|
|
830
|
+
* ```typescript
|
|
831
|
+
* class HtmlAttribute implements HtmlAttributeShape {
|
|
832
|
+
* constructor(
|
|
833
|
+
* readonly key: string,
|
|
834
|
+
* readonly attributeValue: HtmlAttributeValue
|
|
835
|
+
* ) {}
|
|
836
|
+
*
|
|
837
|
+
* renderAttribute(): string {
|
|
838
|
+
* return `${this.key}="${this.attributeValue}"`;
|
|
839
|
+
* }
|
|
840
|
+
* }
|
|
841
|
+
*
|
|
842
|
+
* const attr = new HtmlAttribute('id', 'test-id');
|
|
843
|
+
* console.log(attr.renderAttribute()); // 'id="test-id"'
|
|
844
|
+
* ```
|
|
845
|
+
*/
|
|
846
|
+
interface HtmlAttributeShape {
|
|
847
|
+
/**
|
|
848
|
+
* 属性のキー名(例: 'id', 'class', 'href')
|
|
849
|
+
*/
|
|
850
|
+
readonly key: string;
|
|
851
|
+
/**
|
|
852
|
+
* 属性の値(文字列、数値、ブール値など)
|
|
853
|
+
*/
|
|
854
|
+
readonly attributeValue: HtmlAttributeValue;
|
|
855
|
+
/**
|
|
856
|
+
* 属性をHTML文字列としてレンダリング
|
|
857
|
+
*
|
|
858
|
+
* @returns HTML形式の属性文字列(例: `id="test"`)
|
|
859
|
+
*
|
|
860
|
+
* @remarks
|
|
861
|
+
* 属性のキーと値を `key="value"` 形式の文字列に変換します。
|
|
862
|
+
* ブール属性(例: hidden, disabled)の場合は、値の有無に応じて処理されます。
|
|
863
|
+
*
|
|
864
|
+
* @example
|
|
865
|
+
* ```typescript
|
|
866
|
+
* const idAttr = new HtmlAttribute('id', 'my-id');
|
|
867
|
+
* console.log(idAttr.renderAttribute()); // 'id="my-id"'
|
|
868
|
+
*
|
|
869
|
+
* const classAttr = new HtmlAttribute('class', 'btn btn-primary');
|
|
870
|
+
* console.log(classAttr.renderAttribute()); // 'class="btn btn-primary"'
|
|
871
|
+
* ```
|
|
872
|
+
*/
|
|
873
|
+
renderAttribute(): string;
|
|
874
|
+
}
|
|
875
|
+
/**
|
|
876
|
+
* HTMLタグの共通操作インターフェース
|
|
877
|
+
*
|
|
878
|
+
* Renderable, ChildManageable, AttributeManageable を継承し、
|
|
879
|
+
* タグ種別とレンダリング機能を追加する。
|
|
880
|
+
*
|
|
881
|
+
* @remarks
|
|
882
|
+
* このインターフェースは、責務の明確化のため以下の3つのインターフェースを継承します:
|
|
883
|
+
* - Renderable: レンダリング基本機能
|
|
884
|
+
* - ChildManageable: 子要素管理
|
|
885
|
+
* - AttributeManageable: 属性管理
|
|
886
|
+
*
|
|
887
|
+
* Preconditions: tagType は有効な TagType 値
|
|
888
|
+
* Postconditions: render()/protoRender() は有効な HTML 文字列を返す
|
|
889
|
+
* Invariants: children の順序は追加順に保持
|
|
890
|
+
*/
|
|
891
|
+
interface HTMLTagProtocol extends Renderable, ChildManageable, AttributeManageable {
|
|
892
|
+
/**
|
|
893
|
+
* HTMLタグの種別(例: 'div', 'p', 'span')
|
|
894
|
+
*/
|
|
895
|
+
readonly tagType: TagType;
|
|
896
|
+
/**
|
|
897
|
+
* フォーマット済みHTML文字列を生成
|
|
898
|
+
*
|
|
899
|
+
* @returns インデント・改行を含む整形済みHTML
|
|
900
|
+
*
|
|
901
|
+
* @remarks
|
|
902
|
+
* protoRender() の出力を HTMLFormatter で整形して返します。
|
|
903
|
+
*/
|
|
904
|
+
render(): string;
|
|
905
|
+
/**
|
|
906
|
+
* ミニファイ(最小化)されたHTML文字列を生成
|
|
907
|
+
*
|
|
908
|
+
* @returns インデント・改行を含まないHTML
|
|
909
|
+
*
|
|
910
|
+
* @remarks
|
|
911
|
+
* タグ、属性、子要素を連結したHTML文字列を返します。
|
|
912
|
+
* render() メソッドはこの出力を整形して返します。
|
|
913
|
+
*/
|
|
914
|
+
protoRender(ctx?: RenderContext): string;
|
|
915
|
+
}
|
|
916
|
+
|
|
917
|
+
/**
|
|
918
|
+
* レイアウト配置方向型
|
|
919
|
+
*
|
|
920
|
+
* レイアウト配置の方向を表す文字列リテラルユニオン型。
|
|
921
|
+
* {@link LayoutRegisteredItem} の basePosition / targetPosition で使用され、
|
|
922
|
+
* 要素間の位置関係を定義する。
|
|
923
|
+
*
|
|
924
|
+
* ## 値
|
|
925
|
+
*
|
|
926
|
+
* - `'top'`: 上端
|
|
927
|
+
* - `'bottom'`: 下端
|
|
928
|
+
* - `'left'`: 左端
|
|
929
|
+
* - `'right'`: 右端
|
|
930
|
+
* - `'none'`: 方向なし(値のみ保持)
|
|
931
|
+
*
|
|
932
|
+
* @example
|
|
933
|
+
* ```ts
|
|
934
|
+
* const item: LayoutRegisteredItem = {
|
|
935
|
+
* relationShip: 'absolute',
|
|
936
|
+
* baseTagPath: 'html>body>div.a',
|
|
937
|
+
* basePosition: 'left', // Positioning型
|
|
938
|
+
* targetTagPath: 'html>body>div.b',
|
|
939
|
+
* targetPosition: 'right', // Positioning型
|
|
940
|
+
* value: { value: 10, unit: 'px' }
|
|
941
|
+
* };
|
|
942
|
+
* ```
|
|
943
|
+
*
|
|
944
|
+
* @see {@link LayoutRegisteredItem}
|
|
945
|
+
* @see {@link LazyLayoutManager}
|
|
946
|
+
*/
|
|
947
|
+
type Positioning = 'top' | 'bottom' | 'left' | 'right' | 'none';
|
|
948
|
+
|
|
949
|
+
/**
|
|
950
|
+
* Task 1.3: LayoutRegisteredItem & LazyLayoutRegister インターフェース
|
|
951
|
+
*
|
|
952
|
+
* 遅延レイアウト解決に必要なデータ構造とレジスタインターフェース。
|
|
953
|
+
* LayoutRegisteredItem は要素間の位置関係を記述し、
|
|
954
|
+
* LazyLayoutRegister はそれらを登録・解決・レンダリングする。
|
|
955
|
+
*/
|
|
956
|
+
|
|
957
|
+
/**
|
|
958
|
+
* レイアウト登録アイテム。
|
|
959
|
+
* 基準要素とターゲット要素の位置関係を記述する。
|
|
960
|
+
*/
|
|
961
|
+
interface LayoutRegisteredItem {
|
|
962
|
+
relationShip: RelationShip;
|
|
963
|
+
baseTagPath: string;
|
|
964
|
+
basePosition: Positioning;
|
|
965
|
+
targetTagPath?: string;
|
|
966
|
+
targetPosition: Positioning;
|
|
967
|
+
value?: HlUnit;
|
|
968
|
+
}
|
|
969
|
+
/**
|
|
970
|
+
* 遅延レイアウト登録・解決インターフェース。
|
|
971
|
+
* レイアウトアイテムの登録、検索、レンダリング、一括解決を提供する。
|
|
972
|
+
*/
|
|
973
|
+
interface LazyLayoutRegister {
|
|
974
|
+
registerItem(item: LayoutRegisteredItem): void;
|
|
975
|
+
getRelationShip(tagPath: string): RelationShip | undefined;
|
|
976
|
+
renderItemsBy(tagPath: string): string;
|
|
977
|
+
renderAllItems(): string;
|
|
978
|
+
resolveAllLayout(): void;
|
|
979
|
+
}
|
|
980
|
+
|
|
981
|
+
/**
|
|
982
|
+
* CSS配置記述インターフェース
|
|
983
|
+
*
|
|
984
|
+
* 要素の配置情報(top, left, width, height)を表現する。
|
|
985
|
+
* {@link CssPositionMaker.description} プロパティで現在の配置設定を取得する際に使用される。
|
|
986
|
+
*
|
|
987
|
+
* ## プロパティ
|
|
988
|
+
*
|
|
989
|
+
* すべてのプロパティはオプショナルで、設定された値のみが含まれる。
|
|
990
|
+
* 未設定のプロパティは `undefined` となる。
|
|
991
|
+
*
|
|
992
|
+
* @example
|
|
993
|
+
* ```ts
|
|
994
|
+
* const maker = new CssPositionMaker('html>body>div');
|
|
995
|
+
* maker.placeAbsoluteWith(b => {
|
|
996
|
+
* b.top(10, 'px').left(20, 'px');
|
|
997
|
+
* });
|
|
998
|
+
*
|
|
999
|
+
* const desc = maker.description;
|
|
1000
|
+
* console.log(desc.top); // → { value: 10, unit: 'px' }
|
|
1001
|
+
* console.log(desc.left); // → { value: 20, unit: 'px' }
|
|
1002
|
+
* console.log(desc.width); // → undefined
|
|
1003
|
+
* console.log(desc.height); // → undefined
|
|
1004
|
+
* ```
|
|
1005
|
+
*
|
|
1006
|
+
* @see {@link CssPositionMaker}
|
|
1007
|
+
* @see {@link HlUnit}
|
|
1008
|
+
*/
|
|
1009
|
+
|
|
1010
|
+
interface CssPlaceDescription {
|
|
1011
|
+
/** 上端からの位置 */
|
|
1012
|
+
top?: HlUnit;
|
|
1013
|
+
/** 左端からの位置 */
|
|
1014
|
+
left?: HlUnit;
|
|
1015
|
+
/** 幅 */
|
|
1016
|
+
width?: HlUnit;
|
|
1017
|
+
/** 高さ */
|
|
1018
|
+
height?: HlUnit;
|
|
1019
|
+
}
|
|
1020
|
+
|
|
1021
|
+
/**
|
|
1022
|
+
* CSSレイアウトビルダーインターフェース
|
|
1023
|
+
*
|
|
1024
|
+
* CSS レイアウトプロパティをメソッドチェーンで構築するビルダーパターン。
|
|
1025
|
+
* {@link CssPositionMaker} の placeXxxWith() メソッドで使用される。
|
|
1026
|
+
*
|
|
1027
|
+
* ## メソッドチェーン
|
|
1028
|
+
*
|
|
1029
|
+
* 各メソッドは自身を返すため、流暢なインターフェースで連続的に呼び出せる。
|
|
1030
|
+
*
|
|
1031
|
+
* @example
|
|
1032
|
+
* ```ts
|
|
1033
|
+
* maker.placeAbsoluteWith(builder => {
|
|
1034
|
+
* builder
|
|
1035
|
+
* .top(0, 'px')
|
|
1036
|
+
* .left(0, 'px')
|
|
1037
|
+
* .width(100, '%')
|
|
1038
|
+
* .height(100, 'vh');
|
|
1039
|
+
* });
|
|
1040
|
+
* ```
|
|
1041
|
+
*
|
|
1042
|
+
* @see {@link CssPositionMaker}
|
|
1043
|
+
*/
|
|
1044
|
+
|
|
1045
|
+
interface CssLayoutBuilder {
|
|
1046
|
+
/**
|
|
1047
|
+
* top プロパティを設定する
|
|
1048
|
+
* @param value - 数値
|
|
1049
|
+
* @param unit - CSS単位
|
|
1050
|
+
* @returns this(メソッドチェーン用)
|
|
1051
|
+
*/
|
|
1052
|
+
top(value: number, unit: UnitStyle): CssLayoutBuilder;
|
|
1053
|
+
/**
|
|
1054
|
+
* left プロパティを設定する
|
|
1055
|
+
* @param value - 数値
|
|
1056
|
+
* @param unit - CSS単位
|
|
1057
|
+
* @returns this(メソッドチェーン用)
|
|
1058
|
+
*/
|
|
1059
|
+
left(value: number, unit: UnitStyle): CssLayoutBuilder;
|
|
1060
|
+
/**
|
|
1061
|
+
* width プロパティを設定する
|
|
1062
|
+
* @param value - 数値
|
|
1063
|
+
* @param unit - CSS単位
|
|
1064
|
+
* @returns this(メソッドチェーン用)
|
|
1065
|
+
*/
|
|
1066
|
+
width(value: number, unit: UnitStyle): CssLayoutBuilder;
|
|
1067
|
+
/**
|
|
1068
|
+
* height プロパティを設定する
|
|
1069
|
+
* @param value - 数値
|
|
1070
|
+
* @param unit - CSS単位
|
|
1071
|
+
* @returns this(メソッドチェーン用)
|
|
1072
|
+
*/
|
|
1073
|
+
height(value: number, unit: UnitStyle): CssLayoutBuilder;
|
|
1074
|
+
/**
|
|
1075
|
+
* bottom プロパティを設定する
|
|
1076
|
+
* @param value - 数値
|
|
1077
|
+
* @param unit - CSS単位
|
|
1078
|
+
* @returns this(メソッドチェーン用)
|
|
1079
|
+
*/
|
|
1080
|
+
bottom(value: number, unit: UnitStyle): CssLayoutBuilder;
|
|
1081
|
+
/**
|
|
1082
|
+
* right プロパティを設定する
|
|
1083
|
+
* @param value - 数値
|
|
1084
|
+
* @param unit - CSS単位
|
|
1085
|
+
* @returns this(メソッドチェーン用)
|
|
1086
|
+
*/
|
|
1087
|
+
right(value: number, unit: UnitStyle): CssLayoutBuilder;
|
|
1088
|
+
}
|
|
1089
|
+
|
|
1090
|
+
/**
|
|
1091
|
+
* Task 1.3: CssPositionMakerType インターフェース
|
|
1092
|
+
*
|
|
1093
|
+
* CSS 配置管理の抽象インターフェース。
|
|
1094
|
+
* Renderable を拡張し、absolute/relative/static/fixed の配置と
|
|
1095
|
+
* 遅延レイアウト登録を管理する。
|
|
1096
|
+
*/
|
|
1097
|
+
|
|
1098
|
+
interface CssPositionMakerType extends Renderable {
|
|
1099
|
+
tagPath: string;
|
|
1100
|
+
readonly description: CssPlaceDescription;
|
|
1101
|
+
updateLLRegister(register: LazyLayoutRegister | undefined): void;
|
|
1102
|
+
getLLRegister(): LazyLayoutRegister | undefined;
|
|
1103
|
+
placeAbsoluteWith(closure: (builder: CssLayoutBuilder) => void): void;
|
|
1104
|
+
placeRelativeWith(closure: (builder: CssLayoutBuilder) => void): void;
|
|
1105
|
+
placeStaticWith(closure: (builder: CssLayoutBuilder) => void): void;
|
|
1106
|
+
placeFixedWith(closure: (builder: CssLayoutBuilder) => void): void;
|
|
1107
|
+
}
|
|
1108
|
+
|
|
1109
|
+
/**
|
|
1110
|
+
* Task 1.3: CssStyleManagerType インターフェース
|
|
1111
|
+
*
|
|
1112
|
+
* スタイル管理の抽象インターフェース。
|
|
1113
|
+
* Renderable を拡張し、フォントサイズ単位の取得機能を持つ。
|
|
1114
|
+
*/
|
|
1115
|
+
|
|
1116
|
+
/**
|
|
1117
|
+
* HtmlStyle の前方宣言型。
|
|
1118
|
+
* 後続タスク(6.1)で具象化される。
|
|
1119
|
+
* 現時点では Renderable のサブタイプとして定義する。
|
|
1120
|
+
*/
|
|
1121
|
+
type HtmlStyleType = Renderable;
|
|
1122
|
+
/**
|
|
1123
|
+
* CSS スタイル管理の抽象インターフェース。
|
|
1124
|
+
*
|
|
1125
|
+
* HtmlTag に紐づくスタイル情報を保持し、
|
|
1126
|
+
* CSS 文字列へのレンダリングとフォントサイズ単位の参照を提供する。
|
|
1127
|
+
*/
|
|
1128
|
+
interface CssStyleManagerType extends Renderable {
|
|
1129
|
+
readonly style: HtmlStyleType;
|
|
1130
|
+
getFontSizeUnit(): HlUnit | undefined;
|
|
1131
|
+
}
|
|
1132
|
+
|
|
1133
|
+
/**
|
|
1134
|
+
* CssManagerInstance インターフェース
|
|
1135
|
+
*
|
|
1136
|
+
* HtmlTag が保持する CSS マネージャーのコンポジション型。
|
|
1137
|
+
* Renderable を拡張し、CSS レンダリング機能を提供する。
|
|
1138
|
+
*
|
|
1139
|
+
* 依存方向: html/protocols/ が定義を所有し、css/manager/ が実装する。
|
|
1140
|
+
*/
|
|
1141
|
+
|
|
1142
|
+
interface CssManagerInstance extends Renderable {
|
|
1143
|
+
readonly layout: CssPositionMakerType;
|
|
1144
|
+
readonly styleManager: CssStyleManagerType;
|
|
1145
|
+
tagPath: string;
|
|
1146
|
+
updateTagPath(newPath: string): void;
|
|
1147
|
+
updateLazyLayoutRegister(register: LazyLayoutRegister | undefined): void;
|
|
1148
|
+
/**
|
|
1149
|
+
* スコープド CSS を出力する。
|
|
1150
|
+
*
|
|
1151
|
+
* `resolver` が指定された場合、wrapper class 名は resolver 経由で取得する
|
|
1152
|
+
* (minify モード等が反映される)。省略時は従来通り純関数 `generateScopedClassName`
|
|
1153
|
+
* を直接呼ぶ(バイト等価)。
|
|
1154
|
+
*/
|
|
1155
|
+
renderCss(resolver?: IdentifierResolver): string;
|
|
1156
|
+
addMediaRule(breakpointPx: number, props: Record<string, string>): void;
|
|
1157
|
+
}
|
|
1158
|
+
|
|
1159
|
+
/**
|
|
1160
|
+
* CssManagerType: CSS 管理インターフェース
|
|
1161
|
+
*
|
|
1162
|
+
* Task 0.2: CssManagerInstance をコンポジションで保持し、
|
|
1163
|
+
* collectCssStyleString() は css.render() に委譲する。
|
|
1164
|
+
*
|
|
1165
|
+
* Requirements: 1.4
|
|
1166
|
+
*/
|
|
1167
|
+
|
|
1168
|
+
/**
|
|
1169
|
+
* CSS管理機能を提供するインターフェース
|
|
1170
|
+
*
|
|
1171
|
+
* このインターフェースは、HTML要素のCSS管理を担当します。
|
|
1172
|
+
* CssManagerInstanceをコンポジションで保持し、CSS文字列の収集とレンダリングをサポートします。
|
|
1173
|
+
*
|
|
1174
|
+
* @remarks
|
|
1175
|
+
* - `collectCssStyleString()` は後方互換性のために提供されており、内部的には `css.render()` に委譲します
|
|
1176
|
+
* - `css` アクセサを通じて直接CssManagerInstanceにアクセスできます
|
|
1177
|
+
* - HTMLタグの要素ツリー全体からCSSスタイルを収集します
|
|
1178
|
+
*
|
|
1179
|
+
* @example
|
|
1180
|
+
* ```typescript
|
|
1181
|
+
* class MyElement implements CssManagerType {
|
|
1182
|
+
* readonly css: CssManagerInstance = new CssManagerInstance();
|
|
1183
|
+
*
|
|
1184
|
+
* collectCssStyleString(): string {
|
|
1185
|
+
* return this.css.render();
|
|
1186
|
+
* }
|
|
1187
|
+
* }
|
|
1188
|
+
*
|
|
1189
|
+
* const element = new MyElement();
|
|
1190
|
+
* element.css.setBackgroundColor('#fff');
|
|
1191
|
+
* console.log(element.collectCssStyleString()); // "background-color: #fff;"
|
|
1192
|
+
* ```
|
|
1193
|
+
*/
|
|
1194
|
+
interface CssManagerType {
|
|
1195
|
+
/**
|
|
1196
|
+
* この要素とその子孫から生成されたCSSスタイル文字列を収集
|
|
1197
|
+
*
|
|
1198
|
+
* @returns 統合されたCSSスタイル文字列
|
|
1199
|
+
*
|
|
1200
|
+
* @remarks
|
|
1201
|
+
* このメソッドは後方互換性のために提供されています。
|
|
1202
|
+
* 内部的には `css.render()` に委譲して、要素とその子孫すべてのCSSスタイルを収集します。
|
|
1203
|
+
* 新しいコードでは `css.render()` を直接使用することを推奨します。
|
|
1204
|
+
*
|
|
1205
|
+
* @example
|
|
1206
|
+
* ```typescript
|
|
1207
|
+
* const div = new PairType('div');
|
|
1208
|
+
* div.css.setWidth('100px');
|
|
1209
|
+
* div.css.setHeight('50px');
|
|
1210
|
+
* console.log(div.collectCssStyleString()); // "width: 100px; height: 50px;"
|
|
1211
|
+
* ```
|
|
1212
|
+
*/
|
|
1213
|
+
collectCssStyleString(): string;
|
|
1214
|
+
/**
|
|
1215
|
+
* CssManagerInstanceへの読み取り専用アクセサ
|
|
1216
|
+
*
|
|
1217
|
+
* @remarks
|
|
1218
|
+
* このアクセサを通じて、CSS管理インスタンスに直接アクセスできます。
|
|
1219
|
+
* スタイルの設定やレンダリングなど、CssManagerInstanceの全機能を利用できます。
|
|
1220
|
+
*
|
|
1221
|
+
* @example
|
|
1222
|
+
* ```typescript
|
|
1223
|
+
* const div = new PairType('div');
|
|
1224
|
+
* div.css.setBackgroundColor('#f0f0f0');
|
|
1225
|
+
* div.css.setPadding('10px');
|
|
1226
|
+
* console.log(div.css.render()); // "background-color: #f0f0f0; padding: 10px;"
|
|
1227
|
+
* ```
|
|
1228
|
+
*/
|
|
1229
|
+
readonly css: CssManagerInstance;
|
|
1230
|
+
}
|
|
1231
|
+
|
|
1232
|
+
/**
|
|
1233
|
+
* jQuery method types supported by DraftOle
|
|
1234
|
+
*
|
|
1235
|
+
* 依存方向: html/protocols/ が定義を所有し、js/ が実装する。
|
|
1236
|
+
*/
|
|
1237
|
+
type JQueryMethodType = 'css' | 'height' | 'on' | 'text' | 'html' | 'addClass' | 'removeClass' | 'toggleClass';
|
|
1238
|
+
declare const JQUERY_METHOD_TYPES: readonly JQueryMethodType[];
|
|
1239
|
+
|
|
1240
|
+
/**
|
|
1241
|
+
* JQueryManagerInstance インターフェース
|
|
1242
|
+
*
|
|
1243
|
+
* HtmlTag が保持する jQuery マネージャーのコンポジション型。
|
|
1244
|
+
* Renderable を拡張し、jQuery風DOM操作コードの蓄積・出力を提供する。
|
|
1245
|
+
*
|
|
1246
|
+
* 依存方向: html/protocols/ が定義を所有し、js/ が実装する。
|
|
1247
|
+
*/
|
|
1248
|
+
|
|
1249
|
+
interface JQueryManagerInstance extends Renderable {
|
|
1250
|
+
readonly path: string;
|
|
1251
|
+
readonly usedMethods: ReadonlySet<JQueryMethodType>;
|
|
1252
|
+
css(properties: Record<string, string>): string;
|
|
1253
|
+
height(value: number, unit?: string): string;
|
|
1254
|
+
on(eventType: string, handler: string): string;
|
|
1255
|
+
click(handler: string): string;
|
|
1256
|
+
keydown(handler: string): string;
|
|
1257
|
+
keyup(handler: string): string;
|
|
1258
|
+
text(value: string, isVariable?: boolean): string;
|
|
1259
|
+
html(value: string): string;
|
|
1260
|
+
addClass(className: string): string;
|
|
1261
|
+
removeClass(className: string): string;
|
|
1262
|
+
toggleClass(className: string, force?: boolean): string;
|
|
1263
|
+
needsHelper(): boolean;
|
|
1264
|
+
updatePath(newPath: string): void;
|
|
1265
|
+
render(): string;
|
|
1266
|
+
}
|
|
1267
|
+
|
|
1268
|
+
/**
|
|
1269
|
+
* JQueryManagerProtocol: jQuery管理インターフェース
|
|
1270
|
+
*
|
|
1271
|
+
* Task 3.1 で型安全化: Set<string> → Set<JQueryMethodType>
|
|
1272
|
+
* jqm アクセサを追加して JQueryManagerInstance への参照を提供
|
|
1273
|
+
*
|
|
1274
|
+
* Requirements: 1.5, 1.9, 6.1, 6.2
|
|
1275
|
+
*/
|
|
1276
|
+
|
|
1277
|
+
/**
|
|
1278
|
+
* jQuery管理機能を提供するインターフェース
|
|
1279
|
+
*
|
|
1280
|
+
* このインターフェースは、HTML要素のjQuery機能管理を担当します。
|
|
1281
|
+
* JQueryManagerInstanceをコンポジションで保持し、JavaScript生成とTree-shakingサポートを提供します。
|
|
1282
|
+
*
|
|
1283
|
+
* @remarks
|
|
1284
|
+
* - HTML要素ツリー全体からjQueryコードを収集します
|
|
1285
|
+
* - 使用されたjQueryメソッドを追跡してTree-shakingを可能にします
|
|
1286
|
+
* - `jqm` アクセサは `css` アクセサと対称的な設計です
|
|
1287
|
+
*
|
|
1288
|
+
* Preconditions: JQueryManagerInstanceが適切に初期化されていること
|
|
1289
|
+
* Postconditions: collectJsContent()は要素とその子孫すべてのjQueryコードを返す
|
|
1290
|
+
* Invariants: 収集されたメソッドセットは重複を含まない
|
|
1291
|
+
*
|
|
1292
|
+
* @example
|
|
1293
|
+
* ```typescript
|
|
1294
|
+
* const div = new PairType('div');
|
|
1295
|
+
* div.jqm.addClass('active');
|
|
1296
|
+
* div.jqm.onClick('alert("clicked")');
|
|
1297
|
+
*
|
|
1298
|
+
* console.log(div.collectJsContent());
|
|
1299
|
+
* // $('#element').addClass('active').on('click', function() { alert("clicked"); });
|
|
1300
|
+
*
|
|
1301
|
+
* const methods = div.collectUsedMethods();
|
|
1302
|
+
* console.log(methods); // Set { 'addClass', 'on' }
|
|
1303
|
+
* ```
|
|
1304
|
+
*/
|
|
1305
|
+
interface JQueryManagerProtocol {
|
|
1306
|
+
/**
|
|
1307
|
+
* この要素とその子孫から生成されたjQueryコードを収集
|
|
1308
|
+
*
|
|
1309
|
+
* @returns 統合されたJavaScript文字列(jQuery形式)
|
|
1310
|
+
*
|
|
1311
|
+
* @remarks
|
|
1312
|
+
* 要素ツリーを再帰的に走査し、各要素のjQueryコードを収集して統合します。
|
|
1313
|
+
* 生成されるコードは、DOMの準備完了後($(document).ready())に実行されることを前提としています。
|
|
1314
|
+
*
|
|
1315
|
+
* @example
|
|
1316
|
+
* ```typescript
|
|
1317
|
+
* const div = new PairType('div');
|
|
1318
|
+
* div.addHtmlAttribute(new HtmlAttribute('id', 'myDiv'));
|
|
1319
|
+
* div.jqm.addClass('container');
|
|
1320
|
+
* div.jqm.setCss('background-color', '#fff');
|
|
1321
|
+
*
|
|
1322
|
+
* console.log(div.collectJsContent());
|
|
1323
|
+
* // $('#myDiv').addClass('container').css('background-color', '#fff');
|
|
1324
|
+
* ```
|
|
1325
|
+
*/
|
|
1326
|
+
collectJsContent(): string;
|
|
1327
|
+
/**
|
|
1328
|
+
* この要素とその子孫で使用されたjQueryメソッド種別を収集
|
|
1329
|
+
*
|
|
1330
|
+
* @returns JQueryMethodTypeのSet(重複なし)
|
|
1331
|
+
*
|
|
1332
|
+
* @remarks
|
|
1333
|
+
* この情報はTree-shakingに使用され、実際に使用されたjQueryメソッドだけを
|
|
1334
|
+
* 最終的なバンドルに含めることができます。
|
|
1335
|
+
* 要素ツリー全体を走査し、すべての使用済みメソッドを収集します。
|
|
1336
|
+
*
|
|
1337
|
+
* @example
|
|
1338
|
+
* ```typescript
|
|
1339
|
+
* const div = new PairType('div');
|
|
1340
|
+
* div.jqm.addClass('container');
|
|
1341
|
+
* div.jqm.onClick('handleClick()');
|
|
1342
|
+
*
|
|
1343
|
+
* const methods = div.collectUsedMethods();
|
|
1344
|
+
* console.log(methods); // Set { 'addClass', 'on' }
|
|
1345
|
+
* ```
|
|
1346
|
+
*/
|
|
1347
|
+
collectUsedMethods(): Set<JQueryMethodType>;
|
|
1348
|
+
/**
|
|
1349
|
+
* JQueryManagerInstanceへの読み取り専用アクセサ
|
|
1350
|
+
*
|
|
1351
|
+
* @remarks
|
|
1352
|
+
* このアクセサを通じて、jQuery管理インスタンスに直接アクセスできます。
|
|
1353
|
+
* jQueryメソッドの設定や管理など、JQueryManagerInstanceの全機能を利用できます。
|
|
1354
|
+
* CssManagerTypeの `css` アクセサと対称的な設計になっています。
|
|
1355
|
+
*
|
|
1356
|
+
* @example
|
|
1357
|
+
* ```typescript
|
|
1358
|
+
* const div = new PairType('div');
|
|
1359
|
+
* div.jqm.addClass('active');
|
|
1360
|
+
* div.jqm.onClick('handleClick()');
|
|
1361
|
+
* div.jqm.setData('userId', '123');
|
|
1362
|
+
*
|
|
1363
|
+
* console.log(div.jqm.render());
|
|
1364
|
+
* // .addClass('active').on('click', function() { handleClick(); }).data('userId', '123')
|
|
1365
|
+
* ```
|
|
1366
|
+
*/
|
|
1367
|
+
readonly jqm: JQueryManagerInstance;
|
|
1368
|
+
}
|
|
1369
|
+
|
|
1370
|
+
/**
|
|
1371
|
+
* CSS スタイルクラスの共通基底クラス。
|
|
1372
|
+
*
|
|
1373
|
+
* プロパティ保存・重複検知ガード・レンダリングを提供する。
|
|
1374
|
+
* 全 CSS スタイルクラス(CSSFont, CSSText 等)はこのクラスを継承する。
|
|
1375
|
+
*
|
|
1376
|
+
* @remarks
|
|
1377
|
+
* - `_props` は `private readonly` のため、サブクラスは `setProp` / `getProp` 経由でのみアクセスする
|
|
1378
|
+
* - `setProp` は `guardDuplicateCssProperty` を必ず呼んでから Map に書き込む
|
|
1379
|
+
* - `render()` は `renderCssProperties` に委譲し、サニタイズ・ソートを引き継ぐ
|
|
1380
|
+
*/
|
|
1381
|
+
declare abstract class CSSPropertyGroup implements Renderable {
|
|
1382
|
+
private readonly _props;
|
|
1383
|
+
/**
|
|
1384
|
+
* CSS プロパティを保存する。重複設定は DEV モードで検知される。
|
|
1385
|
+
*
|
|
1386
|
+
* @param cssKey - CSS プロパティキー(例: 'font-size')
|
|
1387
|
+
* @param value - プロパティ値
|
|
1388
|
+
*/
|
|
1389
|
+
protected setProp(cssKey: string, value: string): this;
|
|
1390
|
+
/**
|
|
1391
|
+
* 保存済み CSS プロパティ値を取得する。
|
|
1392
|
+
* 公開 getter が必要なサブクラス(例: CSSFont.getFontSize())で使用する。
|
|
1393
|
+
*
|
|
1394
|
+
* @param cssKey - CSS プロパティキー
|
|
1395
|
+
* @returns 設定済みの値、または未設定の場合は undefined
|
|
1396
|
+
*/
|
|
1397
|
+
protected getProp(cssKey: string): string | undefined;
|
|
1398
|
+
/**
|
|
1399
|
+
* string | HlUnit を CSS 文字列に変換するヘルパー。
|
|
1400
|
+
*
|
|
1401
|
+
* @param value - CSS 値文字列または HlUnit
|
|
1402
|
+
* @returns CSS 値文字列
|
|
1403
|
+
*/
|
|
1404
|
+
protected resolveUnit(value: string | HlUnit): string;
|
|
1405
|
+
/**
|
|
1406
|
+
* string | HlUnit を受け取り、resolveUnit で変換した後に setProp で保存するヘルパー。
|
|
1407
|
+
*
|
|
1408
|
+
* @param cssKey - CSS プロパティキー(例: 'margin-top')
|
|
1409
|
+
* @param value - CSS 値文字列または HlUnit
|
|
1410
|
+
* @returns this(メソッドチェーン用)
|
|
1411
|
+
*/
|
|
1412
|
+
protected setUnitProp(cssKey: string, value: string | HlUnit): this;
|
|
1413
|
+
/**
|
|
1414
|
+
* 設定済みプロパティを CSS 文字列としてレンダリングする。
|
|
1415
|
+
* renderCssProperties に委譲: アルファベットソート・サニタイズ・フォーマット。
|
|
1416
|
+
*
|
|
1417
|
+
* @returns CSS プロパティ文字列(例: `color: red;\nfont-size: 16px;`)、未設定の場合は空文字列
|
|
1418
|
+
*/
|
|
1419
|
+
render(): string;
|
|
1420
|
+
}
|
|
1421
|
+
|
|
1422
|
+
/**
|
|
1423
|
+
* Task 4.1: CSSAnimation -- アニメーション・トランジションプロパティ
|
|
1424
|
+
*
|
|
1425
|
+
* CSSPropertyGroup を継承し、共通の setProp/render パターンを利用する。
|
|
1426
|
+
* 14のAnimation/Transition関連CSSプロパティを型安全に管理し、
|
|
1427
|
+
* 設定済みプロパティのみをアルファベット順でCSS文字列として出力する。
|
|
1428
|
+
*
|
|
1429
|
+
* Requirements: 6.2, 6.3, 6.5
|
|
1430
|
+
*/
|
|
1431
|
+
|
|
1432
|
+
/**
|
|
1433
|
+
* アニメーション・トランジションプロパティを管理するクラス
|
|
1434
|
+
*
|
|
1435
|
+
* アニメーション系: animation-name, animation-duration, animation-timing-function,
|
|
1436
|
+
* animation-delay, animation-iteration-count, animation-direction,
|
|
1437
|
+
* animation-fill-mode, animation-play-state, animation
|
|
1438
|
+
* トランジション系: transition-property, transition-duration,
|
|
1439
|
+
* transition-timing-function, transition-delay, transition
|
|
1440
|
+
*/
|
|
1441
|
+
declare class CSSAnimation extends CSSPropertyGroup {
|
|
1442
|
+
/** animation-name を設定する */
|
|
1443
|
+
setAnimationName(value: string): this;
|
|
1444
|
+
/** animation-duration を設定する */
|
|
1445
|
+
setAnimationDuration(value: string): this;
|
|
1446
|
+
/** animation-timing-function を設定する */
|
|
1447
|
+
setAnimationTimingFunction(value: string): this;
|
|
1448
|
+
/** animation-delay を設定する */
|
|
1449
|
+
setAnimationDelay(value: string): this;
|
|
1450
|
+
/** animation-iteration-count を設定する */
|
|
1451
|
+
setAnimationIterationCount(value: string): this;
|
|
1452
|
+
/** animation-direction を設定する */
|
|
1453
|
+
setAnimationDirection(value: string): this;
|
|
1454
|
+
/** animation-fill-mode を設定する */
|
|
1455
|
+
setAnimationFillMode(value: string): this;
|
|
1456
|
+
/** animation-play-state を設定する */
|
|
1457
|
+
setAnimationPlayState(value: string): this;
|
|
1458
|
+
/** animation ショートハンドを設定する */
|
|
1459
|
+
setAnimation(value: string): this;
|
|
1460
|
+
/** transition-property を設定する */
|
|
1461
|
+
setTransitionProperty(value: string): this;
|
|
1462
|
+
/** transition-duration を設定する */
|
|
1463
|
+
setTransitionDuration(value: string): this;
|
|
1464
|
+
/** transition-timing-function を設定する */
|
|
1465
|
+
setTransitionTimingFunction(value: string): this;
|
|
1466
|
+
/** transition-delay を設定する */
|
|
1467
|
+
setTransitionDelay(value: string): this;
|
|
1468
|
+
/** transition ショートハンドを設定する */
|
|
1469
|
+
setTransition(value: string): this;
|
|
1470
|
+
}
|
|
1471
|
+
|
|
1472
|
+
/**
|
|
1473
|
+
* CSS標準色名定数
|
|
1474
|
+
*
|
|
1475
|
+
* 主要なCSS色名とCSS特殊キーワードを型安全に定義する。
|
|
1476
|
+
* {@link CSSColor.named}() メソッドで使用される。
|
|
1477
|
+
*
|
|
1478
|
+
* ## カテゴリ
|
|
1479
|
+
*
|
|
1480
|
+
* - **基本色**: black, white, red, green, blue, yellow, cyan, magenta, orange, pink, purple, brown
|
|
1481
|
+
* - **グレー系**: gray, grey, darkGray, lightGray, dimGray, silver
|
|
1482
|
+
* - **拡張色**: navy, teal, maroon, olive, lime, aqua, fuchsia, coral, salmon, gold, indigo, violet, crimson, turquoise
|
|
1483
|
+
* - **CSS特殊キーワード**: transparent, currentColor
|
|
1484
|
+
*
|
|
1485
|
+
* @example
|
|
1486
|
+
* ```ts
|
|
1487
|
+
* // 基本的な使用
|
|
1488
|
+
* CSSColorName.red // → "red"
|
|
1489
|
+
* CSSColorName.transparent // → "transparent"
|
|
1490
|
+
*
|
|
1491
|
+
* // CSSColorと組み合わせて使用
|
|
1492
|
+
* const color = CSSColor.named(CSSColorName.blue);
|
|
1493
|
+
* console.log(color.toString()); // → "blue"
|
|
1494
|
+
*
|
|
1495
|
+
* // プロパティクラスでの使用
|
|
1496
|
+
* const font = new CSSFont();
|
|
1497
|
+
* font.setColorValue(CSSColor.named(CSSColorName.red));
|
|
1498
|
+
* ```
|
|
1499
|
+
*
|
|
1500
|
+
* @see {@link CSSColor}
|
|
1501
|
+
* @see {@link CSSColorNameValue}
|
|
1502
|
+
*/
|
|
1503
|
+
declare const CSSColorName: {
|
|
1504
|
+
readonly black: "black";
|
|
1505
|
+
readonly white: "white";
|
|
1506
|
+
readonly red: "red";
|
|
1507
|
+
readonly green: "green";
|
|
1508
|
+
readonly blue: "blue";
|
|
1509
|
+
readonly yellow: "yellow";
|
|
1510
|
+
readonly cyan: "cyan";
|
|
1511
|
+
readonly magenta: "magenta";
|
|
1512
|
+
readonly orange: "orange";
|
|
1513
|
+
readonly pink: "pink";
|
|
1514
|
+
readonly purple: "purple";
|
|
1515
|
+
readonly brown: "brown";
|
|
1516
|
+
readonly gray: "gray";
|
|
1517
|
+
readonly grey: "grey";
|
|
1518
|
+
readonly darkGray: "darkgray";
|
|
1519
|
+
readonly darkGrey: "darkgrey";
|
|
1520
|
+
readonly lightGray: "lightgray";
|
|
1521
|
+
readonly lightGrey: "lightgrey";
|
|
1522
|
+
readonly dimGray: "dimgray";
|
|
1523
|
+
readonly dimGrey: "dimgrey";
|
|
1524
|
+
readonly silver: "silver";
|
|
1525
|
+
readonly navy: "navy";
|
|
1526
|
+
readonly teal: "teal";
|
|
1527
|
+
readonly maroon: "maroon";
|
|
1528
|
+
readonly olive: "olive";
|
|
1529
|
+
readonly lime: "lime";
|
|
1530
|
+
readonly aqua: "aqua";
|
|
1531
|
+
readonly fuchsia: "fuchsia";
|
|
1532
|
+
readonly coral: "coral";
|
|
1533
|
+
readonly salmon: "salmon";
|
|
1534
|
+
readonly gold: "gold";
|
|
1535
|
+
readonly indigo: "indigo";
|
|
1536
|
+
readonly violet: "violet";
|
|
1537
|
+
readonly crimson: "crimson";
|
|
1538
|
+
readonly turquoise: "turquoise";
|
|
1539
|
+
readonly transparent: "transparent";
|
|
1540
|
+
readonly currentColor: "currentColor";
|
|
1541
|
+
readonly inherit: "inherit";
|
|
1542
|
+
};
|
|
1543
|
+
/**
|
|
1544
|
+
* CSSColorName の値の型(ユニオン型)
|
|
1545
|
+
*/
|
|
1546
|
+
type CSSColorNameValue = (typeof CSSColorName)[keyof typeof CSSColorName];
|
|
1547
|
+
|
|
1548
|
+
/**
|
|
1549
|
+
* CSS色値オブジェクト
|
|
1550
|
+
*
|
|
1551
|
+
* HEX、RGB、RGBA、CSS色名、任意のCSS色文字列を統一的に扱える
|
|
1552
|
+
* イミュータブルな値オブジェクト。型安全なファクトリメソッドと
|
|
1553
|
+
* 検証メソッドを提供する。
|
|
1554
|
+
*
|
|
1555
|
+
* ## サポートする色形式
|
|
1556
|
+
*
|
|
1557
|
+
* - **HEX**: `#RGB`, `#RRGGBB`, `#RRGGBBAA`
|
|
1558
|
+
* - **RGB**: `rgb(r, g, b)`
|
|
1559
|
+
* - **RGBA**: `rgba(r, g, b, a)`
|
|
1560
|
+
* - **色名**: CSS標準色名({@link CSSColorName})
|
|
1561
|
+
* - **その他**: `hsl()`, `var()`, `currentColor` など
|
|
1562
|
+
*
|
|
1563
|
+
* @example
|
|
1564
|
+
* ```ts
|
|
1565
|
+
* // HEX形式
|
|
1566
|
+
* const hex = CSSColor.hex('#ff0000');
|
|
1567
|
+
* console.log(hex.toString()); // → "#ff0000"
|
|
1568
|
+
* console.log(hex.isHex()); // → true
|
|
1569
|
+
*
|
|
1570
|
+
* // RGB形式
|
|
1571
|
+
* const rgb = CSSColor.rgb(255, 0, 0);
|
|
1572
|
+
* console.log(rgb.toString()); // → "rgb(255, 0, 0)"
|
|
1573
|
+
* console.log(rgb.isRgb()); // → true
|
|
1574
|
+
*
|
|
1575
|
+
* // RGBA形式
|
|
1576
|
+
* const rgba = CSSColor.rgba(255, 0, 0, 0.5);
|
|
1577
|
+
* console.log(rgba.toString()); // → "rgba(255, 0, 0, 0.5)"
|
|
1578
|
+
*
|
|
1579
|
+
* // CSS色名
|
|
1580
|
+
* const named = CSSColor.named('red');
|
|
1581
|
+
* console.log(named.toString()); // → "red"
|
|
1582
|
+
* console.log(named.isColorName()); // → true
|
|
1583
|
+
*
|
|
1584
|
+
* // 任意のCSS色文字列
|
|
1585
|
+
* const custom = CSSColor.raw('hsl(0, 100%, 50%)');
|
|
1586
|
+
* console.log(custom.toString()); // → "hsl(0, 100%, 50%)"
|
|
1587
|
+
*
|
|
1588
|
+
* // CSSプロパティクラスでの使用
|
|
1589
|
+
* const font = new CSSFont();
|
|
1590
|
+
* font.setColorValue(CSSColor.hex('#333'));
|
|
1591
|
+
* ```
|
|
1592
|
+
*
|
|
1593
|
+
* @see {@link CSSColorName}
|
|
1594
|
+
* @see {@link CSSColorNameValue}
|
|
1595
|
+
*/
|
|
1596
|
+
|
|
1597
|
+
declare class CSSColor {
|
|
1598
|
+
private readonly value;
|
|
1599
|
+
/**
|
|
1600
|
+
* @internal
|
|
1601
|
+
* コンストラクタはプライベート。ファクトリメソッドを使用すること。
|
|
1602
|
+
*/
|
|
1603
|
+
private constructor();
|
|
1604
|
+
/**
|
|
1605
|
+
* HEX値から CSSColor を生成する
|
|
1606
|
+
*
|
|
1607
|
+
* @param value - HEX色値('#RGB', '#RRGGBB', '#RRGGBBAA' 形式)
|
|
1608
|
+
* @returns CSSColor インスタンス
|
|
1609
|
+
*
|
|
1610
|
+
* @example
|
|
1611
|
+
* ```ts
|
|
1612
|
+
* CSSColor.hex('#f00'); // → "#f00" (短縮形)
|
|
1613
|
+
* CSSColor.hex('#ff0000'); // → "#ff0000"
|
|
1614
|
+
* CSSColor.hex('#ff0000ff'); // → "#ff0000ff" (アルファ付き)
|
|
1615
|
+
* ```
|
|
1616
|
+
*/
|
|
1617
|
+
static hex(value: string): CSSColor;
|
|
1618
|
+
/**
|
|
1619
|
+
* RGB値から CSSColor を生成する
|
|
1620
|
+
*
|
|
1621
|
+
* @param r - Red (0-255)
|
|
1622
|
+
* @param g - Green (0-255)
|
|
1623
|
+
* @param b - Blue (0-255)
|
|
1624
|
+
* @returns CSSColor インスタンス
|
|
1625
|
+
*
|
|
1626
|
+
* @example
|
|
1627
|
+
* ```ts
|
|
1628
|
+
* CSSColor.rgb(255, 0, 0); // → "rgb(255, 0, 0)"
|
|
1629
|
+
* ```
|
|
1630
|
+
*/
|
|
1631
|
+
static rgb(r: number, g: number, b: number): CSSColor;
|
|
1632
|
+
/**
|
|
1633
|
+
* RGBA値から CSSColor を生成する
|
|
1634
|
+
*
|
|
1635
|
+
* @param r - Red (0-255)
|
|
1636
|
+
* @param g - Green (0-255)
|
|
1637
|
+
* @param b - Blue (0-255)
|
|
1638
|
+
* @param a - Alpha (0-1)
|
|
1639
|
+
* @returns CSSColor インスタンス
|
|
1640
|
+
*
|
|
1641
|
+
* @example
|
|
1642
|
+
* ```ts
|
|
1643
|
+
* CSSColor.rgba(255, 0, 0, 0.5); // → "rgba(255, 0, 0, 0.5)"
|
|
1644
|
+
* ```
|
|
1645
|
+
*/
|
|
1646
|
+
static rgba(r: number, g: number, b: number, a: number): CSSColor;
|
|
1647
|
+
/**
|
|
1648
|
+
* CSS標準色名から CSSColor を生成する
|
|
1649
|
+
*
|
|
1650
|
+
* @param name - CSS標準色名({@link CSSColorNameValue})
|
|
1651
|
+
* @returns CSSColor インスタンス
|
|
1652
|
+
*
|
|
1653
|
+
* @example
|
|
1654
|
+
* ```ts
|
|
1655
|
+
* CSSColor.named('red');
|
|
1656
|
+
* CSSColor.named('transparent');
|
|
1657
|
+
* CSSColor.named('currentColor');
|
|
1658
|
+
* ```
|
|
1659
|
+
*/
|
|
1660
|
+
static named(name: CSSColorNameValue): CSSColor;
|
|
1661
|
+
/**
|
|
1662
|
+
* 任意のCSS色文字列から CSSColor を生成する
|
|
1663
|
+
*
|
|
1664
|
+
* hsl(), var(), カスタムプロパティなど、任意のCSS色表現に対応。
|
|
1665
|
+
*
|
|
1666
|
+
* @param value - 任意のCSS色文字列
|
|
1667
|
+
* @returns CSSColor インスタンス
|
|
1668
|
+
*
|
|
1669
|
+
* @example
|
|
1670
|
+
* ```ts
|
|
1671
|
+
* CSSColor.raw('hsl(0, 100%, 50%)');
|
|
1672
|
+
* CSSColor.raw('var(--primary-color)');
|
|
1673
|
+
* CSSColor.raw('currentColor');
|
|
1674
|
+
* ```
|
|
1675
|
+
*/
|
|
1676
|
+
static raw(value: string): CSSColor;
|
|
1677
|
+
/**
|
|
1678
|
+
* 値が HEX 形式かどうかを判定する
|
|
1679
|
+
*
|
|
1680
|
+
* @returns HEX形式の場合 true
|
|
1681
|
+
*/
|
|
1682
|
+
isHex(): boolean;
|
|
1683
|
+
/**
|
|
1684
|
+
* 値が rgb() 形式かどうかを判定する
|
|
1685
|
+
*
|
|
1686
|
+
* @returns rgb() 形式の場合 true
|
|
1687
|
+
*/
|
|
1688
|
+
isRgb(): boolean;
|
|
1689
|
+
/**
|
|
1690
|
+
* 値が rgba() 形式かどうかを判定する
|
|
1691
|
+
*
|
|
1692
|
+
* @returns rgba() 形式の場合 true
|
|
1693
|
+
*/
|
|
1694
|
+
isRgba(): boolean;
|
|
1695
|
+
/**
|
|
1696
|
+
* 値が CSS 標準色名かどうかを判定する
|
|
1697
|
+
*
|
|
1698
|
+
* @returns CSS標準色名の場合 true
|
|
1699
|
+
*/
|
|
1700
|
+
isColorName(): boolean;
|
|
1701
|
+
/**
|
|
1702
|
+
* CSS色値の文字列表現を返す
|
|
1703
|
+
*
|
|
1704
|
+
* @returns CSS色値文字列
|
|
1705
|
+
*/
|
|
1706
|
+
toString(): string;
|
|
1707
|
+
}
|
|
1708
|
+
|
|
1709
|
+
/**
|
|
1710
|
+
* CSSBackground -- 背景プロパティクラス
|
|
1711
|
+
*
|
|
1712
|
+
* background-color, background-image, background-size,
|
|
1713
|
+
* background-position, background-repeat を管理する。
|
|
1714
|
+
* 線形グラデーション(linear-gradient)のヘルパーメソッドを提供する。
|
|
1715
|
+
* CSSColor 連携による型安全な色指定をサポートする。
|
|
1716
|
+
*
|
|
1717
|
+
* CSSPropertyGroup を継承し、共通の setProp/render パターンを利用する。
|
|
1718
|
+
* Fluent setter(メソッドチェーン)対応。
|
|
1719
|
+
* 設定プロパティのみ出力し、未設定は出力しない。
|
|
1720
|
+
*
|
|
1721
|
+
* Requirements: 5.4, 5.5, 5.7
|
|
1722
|
+
*/
|
|
1723
|
+
|
|
1724
|
+
/** Options for setBackground() shorthand. */
|
|
1725
|
+
interface BackgroundOptions {
|
|
1726
|
+
color?: string;
|
|
1727
|
+
image?: string;
|
|
1728
|
+
size?: string;
|
|
1729
|
+
position?: string;
|
|
1730
|
+
repeat?: string;
|
|
1731
|
+
}
|
|
1732
|
+
declare class CSSBackground extends CSSPropertyGroup {
|
|
1733
|
+
setBackgroundColor(value: string): this;
|
|
1734
|
+
setBackgroundImage(value: string): this;
|
|
1735
|
+
setBackgroundSize(value: string): this;
|
|
1736
|
+
setBackgroundPosition(value: string): this;
|
|
1737
|
+
setBackgroundRepeat(value: string): this;
|
|
1738
|
+
/**
|
|
1739
|
+
* background ショートハンド設定。
|
|
1740
|
+
* - 文字列: CSS `background:` ショートハンドとして出力(例: `'#fff url(...) no-repeat center/cover'`, `'radial-gradient(...), #000'`)
|
|
1741
|
+
* - オブジェクト: 個別の background-* プロパティを一括設定
|
|
1742
|
+
*/
|
|
1743
|
+
setBackground(value: string | BackgroundOptions): this;
|
|
1744
|
+
setBackgroundColorValue(color: CSSColor): this;
|
|
1745
|
+
setLinearGradient(direction: string, ...stops: string[]): this;
|
|
1746
|
+
setRadialGradient(shape: string, ...stops: string[]): this;
|
|
1747
|
+
}
|
|
1748
|
+
|
|
1749
|
+
/**
|
|
1750
|
+
* CSSBorder -- 枠線プロパティクラス
|
|
1751
|
+
*
|
|
1752
|
+
* border-width, border-style, border-color(各方向個別対応)、
|
|
1753
|
+
* border-radius(各角個別対応)を管理する。
|
|
1754
|
+
*
|
|
1755
|
+
* CSSPropertyGroup を継承し、共通の setProp/render パターンを利用する。
|
|
1756
|
+
* Fluent setter(メソッドチェーン)対応。
|
|
1757
|
+
* 設定プロパティのみ出力し、未設定は出力しない。
|
|
1758
|
+
* CSSColor連携による型安全な色指定をサポート。
|
|
1759
|
+
*
|
|
1760
|
+
* Requirements: 5.6, 5.7
|
|
1761
|
+
*/
|
|
1762
|
+
|
|
1763
|
+
/** Options for setBorder() shorthand. */
|
|
1764
|
+
interface BorderOptions {
|
|
1765
|
+
width?: string;
|
|
1766
|
+
style?: string;
|
|
1767
|
+
color?: string;
|
|
1768
|
+
radius?: string;
|
|
1769
|
+
}
|
|
1770
|
+
declare class CSSBorder extends CSSPropertyGroup {
|
|
1771
|
+
/** 主要 border プロパティ(width/style/color/radius)を一括設定するショートハンド */
|
|
1772
|
+
setBorder(options?: BorderOptions): this;
|
|
1773
|
+
/** border-width を一括設定する */
|
|
1774
|
+
setBorderWidth(value: string): this;
|
|
1775
|
+
/** border-style を一括設定する */
|
|
1776
|
+
setBorderStyle(value: string): this;
|
|
1777
|
+
/** border-color を文字列で一括設定する */
|
|
1778
|
+
setBorderColor(value: string): this;
|
|
1779
|
+
/** border-radius を一括設定する */
|
|
1780
|
+
setBorderRadius(value: string): this;
|
|
1781
|
+
/** border-top-width を設定する */
|
|
1782
|
+
setBorderTopWidth(value: string): this;
|
|
1783
|
+
/** border-right-width を設定する */
|
|
1784
|
+
setBorderRightWidth(value: string): this;
|
|
1785
|
+
/** border-bottom-width を設定する */
|
|
1786
|
+
setBorderBottomWidth(value: string): this;
|
|
1787
|
+
/** border-left-width を設定する */
|
|
1788
|
+
setBorderLeftWidth(value: string): this;
|
|
1789
|
+
/** border-top-style を設定する */
|
|
1790
|
+
setBorderTopStyle(value: string): this;
|
|
1791
|
+
/** border-right-style を設定する */
|
|
1792
|
+
setBorderRightStyle(value: string): this;
|
|
1793
|
+
/** border-bottom-style を設定する */
|
|
1794
|
+
setBorderBottomStyle(value: string): this;
|
|
1795
|
+
/** border-left-style を設定する */
|
|
1796
|
+
setBorderLeftStyle(value: string): this;
|
|
1797
|
+
/** border-top-color を文字列で設定する */
|
|
1798
|
+
setBorderTopColor(value: string): this;
|
|
1799
|
+
/** border-right-color を文字列で設定する */
|
|
1800
|
+
setBorderRightColor(value: string): this;
|
|
1801
|
+
/** border-bottom-color を文字列で設定する */
|
|
1802
|
+
setBorderBottomColor(value: string): this;
|
|
1803
|
+
/** border-left-color を文字列で設定する */
|
|
1804
|
+
setBorderLeftColor(value: string): this;
|
|
1805
|
+
/** border-top-left-radius を設定する */
|
|
1806
|
+
setBorderTopLeftRadius(value: string): this;
|
|
1807
|
+
/** border-top-right-radius を設定する */
|
|
1808
|
+
setBorderTopRightRadius(value: string): this;
|
|
1809
|
+
/** border-bottom-right-radius を設定する */
|
|
1810
|
+
setBorderBottomRightRadius(value: string): this;
|
|
1811
|
+
/** border-bottom-left-radius を設定する */
|
|
1812
|
+
setBorderBottomLeftRadius(value: string): this;
|
|
1813
|
+
/** border-color を CSSColor で一括設定する */
|
|
1814
|
+
setBorderColorValue(color: CSSColor): this;
|
|
1815
|
+
/** border-top-color を CSSColor で設定する */
|
|
1816
|
+
setBorderTopColorValue(color: CSSColor): this;
|
|
1817
|
+
/** border-right-color を CSSColor で設定する */
|
|
1818
|
+
setBorderRightColorValue(color: CSSColor): this;
|
|
1819
|
+
/** border-bottom-color を CSSColor で設定する */
|
|
1820
|
+
setBorderBottomColorValue(color: CSSColor): this;
|
|
1821
|
+
/** border-left-color を CSSColor で設定する */
|
|
1822
|
+
setBorderLeftColorValue(color: CSSColor): this;
|
|
1823
|
+
}
|
|
1824
|
+
|
|
1825
|
+
/**
|
|
1826
|
+
* CSSFlex -- Flexboxレイアウトプロパティ
|
|
1827
|
+
*
|
|
1828
|
+
* CSSPropertyGroup を継承し、setProp/getProp 経由でプロパティを管理する。
|
|
1829
|
+
* Fluent setter(メソッドチェーン)対応。
|
|
1830
|
+
* 設定プロパティのみ出力し、未設定は出力しない。
|
|
1831
|
+
*
|
|
1832
|
+
* Requirements: 4.1, 4.2, 4.3, 4.4, 4.5
|
|
1833
|
+
*/
|
|
1834
|
+
|
|
1835
|
+
/**
|
|
1836
|
+
* Flexboxレイアウトプロパティを管理するクラス
|
|
1837
|
+
*
|
|
1838
|
+
* コンテナプロパティ: flex-direction, justify-content, align-items,
|
|
1839
|
+
* align-content, flex-wrap, gap
|
|
1840
|
+
* アイテムプロパティ: flex-grow, flex-shrink, flex-basis, align-self, order
|
|
1841
|
+
*/
|
|
1842
|
+
/** Options for setFlex() shorthand. */
|
|
1843
|
+
interface FlexOptions {
|
|
1844
|
+
direction?: string;
|
|
1845
|
+
justify?: string;
|
|
1846
|
+
align?: string;
|
|
1847
|
+
wrap?: string;
|
|
1848
|
+
gap?: string;
|
|
1849
|
+
}
|
|
1850
|
+
declare class CSSFlex extends CSSPropertyGroup {
|
|
1851
|
+
/** CSS flex ショートハンドプロパティを設定する(アイテム用: e.g. '1 1 auto') */
|
|
1852
|
+
setFlexValue(value: string): this;
|
|
1853
|
+
/** display:flex + 主要プロパティを一括設定するショートハンド */
|
|
1854
|
+
setFlex(options?: FlexOptions): this;
|
|
1855
|
+
/** flex-direction を設定する */
|
|
1856
|
+
setFlexDirection(value: string): this;
|
|
1857
|
+
/** justify-content を設定する */
|
|
1858
|
+
setJustifyContent(value: string): this;
|
|
1859
|
+
/** align-items を設定する */
|
|
1860
|
+
setAlignItems(value: string): this;
|
|
1861
|
+
/** align-content を設定する */
|
|
1862
|
+
setAlignContent(value: string): this;
|
|
1863
|
+
/** flex-wrap を設定する */
|
|
1864
|
+
setFlexWrap(value: string): this;
|
|
1865
|
+
/** gap を設定する */
|
|
1866
|
+
setGap(value: string): this;
|
|
1867
|
+
/** flex-grow を設定する */
|
|
1868
|
+
setFlexGrow(value: string): this;
|
|
1869
|
+
/** flex-shrink を設定する */
|
|
1870
|
+
setFlexShrink(value: string): this;
|
|
1871
|
+
/** flex-basis を設定する */
|
|
1872
|
+
setFlexBasis(value: string): this;
|
|
1873
|
+
/** align-self を設定する */
|
|
1874
|
+
setAlignSelf(value: string): this;
|
|
1875
|
+
/** order を設定する */
|
|
1876
|
+
setOrder(value: string): this;
|
|
1877
|
+
}
|
|
1878
|
+
|
|
1879
|
+
/**
|
|
1880
|
+
* CSSFont -- フォント・文字色プロパティクラス
|
|
1881
|
+
*
|
|
1882
|
+
* font-family, font-size, font-weight, font-style,
|
|
1883
|
+
* color, line-height, letter-spacing を管理する。
|
|
1884
|
+
*
|
|
1885
|
+
* CSSPropertyGroup を継承し、setProp/getProp 経由でプロパティを管理する。
|
|
1886
|
+
* Fluent setter(メソッドチェーン)対応。
|
|
1887
|
+
* 設定プロパティのみ出力し、未設定は出力しない。
|
|
1888
|
+
*
|
|
1889
|
+
* Requirements: 5.1, 5.2, 5.7
|
|
1890
|
+
*/
|
|
1891
|
+
|
|
1892
|
+
/** Options for setFont() shorthand. */
|
|
1893
|
+
interface FontOptions {
|
|
1894
|
+
size?: string;
|
|
1895
|
+
weight?: string;
|
|
1896
|
+
family?: string;
|
|
1897
|
+
lineHeight?: string;
|
|
1898
|
+
color?: string;
|
|
1899
|
+
}
|
|
1900
|
+
declare class CSSFont extends CSSPropertyGroup {
|
|
1901
|
+
/** 主要フォント・文字色プロパティを一括設定するショートハンド */
|
|
1902
|
+
setFont(options?: FontOptions): this;
|
|
1903
|
+
setFontFamily(value: string): this;
|
|
1904
|
+
setFontSize(value: string): this;
|
|
1905
|
+
setFontWeight(value: string): this;
|
|
1906
|
+
setFontStyle(value: string): this;
|
|
1907
|
+
setColor(value: string): this;
|
|
1908
|
+
setLineHeight(value: string): this;
|
|
1909
|
+
setLetterSpacing(value: string): this;
|
|
1910
|
+
getFontSize(): string | undefined;
|
|
1911
|
+
setColorValue(color: CSSColor): this;
|
|
1912
|
+
}
|
|
1913
|
+
|
|
1914
|
+
/**
|
|
1915
|
+
* CSSGrid -- グリッドレイアウトプロパティ
|
|
1916
|
+
*
|
|
1917
|
+
* CSSPropertyGroup を継承し、setProp/getProp 経由でプロパティを管理する。
|
|
1918
|
+
* Fluent setter(メソッドチェーン)対応。
|
|
1919
|
+
* 設定プロパティのみ出力し、未設定は出力しない。
|
|
1920
|
+
*
|
|
1921
|
+
* Requirements: 6.1, 6.5
|
|
1922
|
+
*/
|
|
1923
|
+
|
|
1924
|
+
/** Options for setGrid() shorthand. */
|
|
1925
|
+
interface GridOptions {
|
|
1926
|
+
columns?: number | string;
|
|
1927
|
+
rows?: number | string;
|
|
1928
|
+
gap?: string;
|
|
1929
|
+
areas?: string;
|
|
1930
|
+
autoFlow?: string;
|
|
1931
|
+
}
|
|
1932
|
+
/**
|
|
1933
|
+
* グリッドレイアウトプロパティを管理するクラス
|
|
1934
|
+
*
|
|
1935
|
+
* コンテナプロパティ: grid-template-columns, grid-template-rows, grid-gap,
|
|
1936
|
+
* grid-template-areas, grid-auto-flow, grid-auto-columns, grid-auto-rows
|
|
1937
|
+
* アイテムプロパティ: grid-column, grid-row, grid-column-start, grid-column-end,
|
|
1938
|
+
* grid-row-start, grid-row-end, grid-area
|
|
1939
|
+
*/
|
|
1940
|
+
declare class CSSGrid extends CSSPropertyGroup {
|
|
1941
|
+
/** display:grid + 主要プロパティを一括設定するショートハンド */
|
|
1942
|
+
setGrid(options?: GridOptions): this;
|
|
1943
|
+
/** grid-template-columns を設定する */
|
|
1944
|
+
setGridTemplateColumns(value: string): this;
|
|
1945
|
+
/** grid-template-rows を設定する */
|
|
1946
|
+
setGridTemplateRows(value: string): this;
|
|
1947
|
+
/** grid-gap を設定する */
|
|
1948
|
+
setGridGap(value: string): this;
|
|
1949
|
+
/** grid-column を設定する */
|
|
1950
|
+
setGridColumn(value: string): this;
|
|
1951
|
+
/** grid-row を設定する */
|
|
1952
|
+
setGridRow(value: string): this;
|
|
1953
|
+
/** grid-column-start を設定する */
|
|
1954
|
+
setGridColumnStart(value: string): this;
|
|
1955
|
+
/** grid-column-end を設定する */
|
|
1956
|
+
setGridColumnEnd(value: string): this;
|
|
1957
|
+
/** grid-row-start を設定する */
|
|
1958
|
+
setGridRowStart(value: string): this;
|
|
1959
|
+
/** grid-row-end を設定する */
|
|
1960
|
+
setGridRowEnd(value: string): this;
|
|
1961
|
+
/** grid-template-areas を設定する */
|
|
1962
|
+
setGridTemplateAreas(value: string): this;
|
|
1963
|
+
/** grid-area を設定する */
|
|
1964
|
+
setGridArea(value: string): this;
|
|
1965
|
+
/** grid-auto-flow を設定する */
|
|
1966
|
+
setGridAutoFlow(value: string): this;
|
|
1967
|
+
/** grid-auto-columns を設定する */
|
|
1968
|
+
setGridAutoColumns(value: string): this;
|
|
1969
|
+
/** grid-auto-rows を設定する */
|
|
1970
|
+
setGridAutoRows(value: string): this;
|
|
1971
|
+
}
|
|
1972
|
+
|
|
1973
|
+
/**
|
|
1974
|
+
* CSSList -- リストスタイルプロパティ
|
|
1975
|
+
*
|
|
1976
|
+
* CSSPropertyGroup を継承し、setProp/getProp 経由でプロパティを管理する。
|
|
1977
|
+
* Fluent setter(メソッドチェーン)対応。
|
|
1978
|
+
* 設定プロパティのみ出力し、未設定は出力しない。
|
|
1979
|
+
*
|
|
1980
|
+
* Requirements: 7.5, 7.7
|
|
1981
|
+
*/
|
|
1982
|
+
|
|
1983
|
+
/**
|
|
1984
|
+
* リストスタイルプロパティを管理するクラス
|
|
1985
|
+
*
|
|
1986
|
+
* プロパティ: list-style-type, list-style-position,
|
|
1987
|
+
* list-style-image, list-style (shorthand)
|
|
1988
|
+
*/
|
|
1989
|
+
declare class CSSList extends CSSPropertyGroup {
|
|
1990
|
+
/** list-style-type を設定する */
|
|
1991
|
+
setListStyleType(value: string): this;
|
|
1992
|
+
/** list-style-position を設定する */
|
|
1993
|
+
setListStylePosition(value: string): this;
|
|
1994
|
+
/** list-style-image を設定する */
|
|
1995
|
+
setListStyleImage(value: string): this;
|
|
1996
|
+
/** list-style (shorthand) を設定する */
|
|
1997
|
+
setListStyle(value: string): this;
|
|
1998
|
+
}
|
|
1999
|
+
|
|
2000
|
+
/**
|
|
2001
|
+
* 疑似クラス(:hover / :focus / :active)用 fluent スタイルビルダー。
|
|
2002
|
+
*
|
|
2003
|
+
* `Map<string, string>` に直接 CSS プロパティ(kebab-case)を書き込む。
|
|
2004
|
+
* `CSSPseudo.applyBuilder()` がこの Map を消費する。
|
|
2005
|
+
*
|
|
2006
|
+
* エスケープハッチ `.set(property, value)` により、メソッドに未定義の
|
|
2007
|
+
* CSS プロパティも任意に設定できる。
|
|
2008
|
+
*/
|
|
2009
|
+
declare class PseudoStyleBuilder {
|
|
2010
|
+
private readonly _props;
|
|
2011
|
+
color(v: string): this;
|
|
2012
|
+
background(v: string): this;
|
|
2013
|
+
backgroundColor(v: string): this;
|
|
2014
|
+
opacity(v: string): this;
|
|
2015
|
+
transform(v: string): this;
|
|
2016
|
+
boxShadow(v: string): this;
|
|
2017
|
+
border(v: string): this;
|
|
2018
|
+
borderColor(v: string): this;
|
|
2019
|
+
borderRadius(v: string): this;
|
|
2020
|
+
fontSize(v: string): this;
|
|
2021
|
+
fontWeight(v: string): this;
|
|
2022
|
+
textDecoration(v: string): this;
|
|
2023
|
+
padding(v: string | number): this;
|
|
2024
|
+
width(v: string): this;
|
|
2025
|
+
height(v: string): this;
|
|
2026
|
+
cursor(v: string): this;
|
|
2027
|
+
transition(v: string): this;
|
|
2028
|
+
/** 任意の CSS プロパティを kebab-case で直接設定するエスケープハッチ */
|
|
2029
|
+
set(property: string, value: string): this;
|
|
2030
|
+
/** @internal CSSPseudo が Map を取得するための内部 API */
|
|
2031
|
+
toMap(): ReadonlyMap<string, string>;
|
|
2032
|
+
}
|
|
2033
|
+
|
|
2034
|
+
declare class CSSPseudo {
|
|
2035
|
+
private _states;
|
|
2036
|
+
setHover(builder: PseudoStyleBuilder): this;
|
|
2037
|
+
setFocus(builder: PseudoStyleBuilder): this;
|
|
2038
|
+
setActive(builder: PseudoStyleBuilder): this;
|
|
2039
|
+
hasAny(): boolean;
|
|
2040
|
+
renderForScope(scopeClass: string): string[];
|
|
2041
|
+
private applyBuilder;
|
|
2042
|
+
}
|
|
2043
|
+
|
|
2044
|
+
/**
|
|
2045
|
+
* Task 3: CSSSpacing - HlUnit 統合と CSSPropertyGroup 移行
|
|
2046
|
+
*
|
|
2047
|
+
* CSSPropertyGroup を継承し、string | HlUnit の union 型セッターを提供する。
|
|
2048
|
+
* setXxxUnit メソッドは後方互換エイリアスとして維持する。
|
|
2049
|
+
*
|
|
2050
|
+
* Requirements: 1.1, 1.2, 1.3, 2.1, 2.4, 3.1, 5.1, 5.2, 5.3, 5.4, 6.1
|
|
2051
|
+
*/
|
|
2052
|
+
|
|
2053
|
+
/**
|
|
2054
|
+
* CSS 余白プロパティ(margin / padding)を管理するクラス。
|
|
2055
|
+
*
|
|
2056
|
+
* CSSPropertyGroup を継承し、プロパティ保存・重複検知・レンダリングを委譲する。
|
|
2057
|
+
* setXxx(value: string | HlUnit) の union 型セッターと、
|
|
2058
|
+
* 後方互換のための setXxxUnit(hlUnit: HlUnit) エイリアスを提供する。
|
|
2059
|
+
*
|
|
2060
|
+
* @example
|
|
2061
|
+
* ```ts
|
|
2062
|
+
* const spacing = new CSSSpacing();
|
|
2063
|
+
* spacing.setMarginTop('10px').setPaddingBottom('20px');
|
|
2064
|
+
* spacing.render();
|
|
2065
|
+
* // → 'margin-top: 10px;\npadding-bottom: 20px;'
|
|
2066
|
+
* ```
|
|
2067
|
+
*/
|
|
2068
|
+
declare class CSSSpacing extends CSSPropertyGroup {
|
|
2069
|
+
/** margin-top を設定する */
|
|
2070
|
+
setMarginTop(value: string | HlUnit): this;
|
|
2071
|
+
/** margin-right を設定する */
|
|
2072
|
+
setMarginRight(value: string | HlUnit): this;
|
|
2073
|
+
/** margin-bottom を設定する */
|
|
2074
|
+
setMarginBottom(value: string | HlUnit): this;
|
|
2075
|
+
/** margin-left を設定する */
|
|
2076
|
+
setMarginLeft(value: string | HlUnit): this;
|
|
2077
|
+
/** margin 一括指定を設定する */
|
|
2078
|
+
setMargin(value: string): this;
|
|
2079
|
+
/** padding-top を設定する */
|
|
2080
|
+
setPaddingTop(value: string | HlUnit): this;
|
|
2081
|
+
/** padding-right を設定する */
|
|
2082
|
+
setPaddingRight(value: string | HlUnit): this;
|
|
2083
|
+
/** padding-bottom を設定する */
|
|
2084
|
+
setPaddingBottom(value: string | HlUnit): this;
|
|
2085
|
+
/** padding-left を設定する */
|
|
2086
|
+
setPaddingLeft(value: string | HlUnit): this;
|
|
2087
|
+
/** padding 一括指定を設定する */
|
|
2088
|
+
setPadding(value: string): this;
|
|
2089
|
+
/** margin-top を HlUnit で設定する(後方互換エイリアス) */
|
|
2090
|
+
setMarginTopUnit(hlUnit: HlUnit): this;
|
|
2091
|
+
/** margin-right を HlUnit で設定する(後方互換エイリアス) */
|
|
2092
|
+
setMarginRightUnit(hlUnit: HlUnit): this;
|
|
2093
|
+
/** margin-bottom を HlUnit で設定する(後方互換エイリアス) */
|
|
2094
|
+
setMarginBottomUnit(hlUnit: HlUnit): this;
|
|
2095
|
+
/** margin-left を HlUnit で設定する(後方互換エイリアス) */
|
|
2096
|
+
setMarginLeftUnit(hlUnit: HlUnit): this;
|
|
2097
|
+
/** padding-top を HlUnit で設定する(後方互換エイリアス) */
|
|
2098
|
+
setPaddingTopUnit(hlUnit: HlUnit): this;
|
|
2099
|
+
/** padding-right を HlUnit で設定する(後方互換エイリアス) */
|
|
2100
|
+
setPaddingRightUnit(hlUnit: HlUnit): this;
|
|
2101
|
+
/** padding-bottom を HlUnit で設定する(後方互換エイリアス) */
|
|
2102
|
+
setPaddingBottomUnit(hlUnit: HlUnit): this;
|
|
2103
|
+
/** padding-left を HlUnit で設定する(後方互換エイリアス) */
|
|
2104
|
+
setPaddingLeftUnit(hlUnit: HlUnit): this;
|
|
2105
|
+
}
|
|
2106
|
+
|
|
2107
|
+
/**
|
|
2108
|
+
* Task 5.3: CSSTable -- テーブルレイアウトプロパティ
|
|
2109
|
+
*
|
|
2110
|
+
* CSSPropertyGroup を継承することで、collectProperties() と render() の
|
|
2111
|
+
* 重複実装を排除したリファクタリング済みクラス。
|
|
2112
|
+
* 5つのTable関連CSSプロパティを型安全に管理し、
|
|
2113
|
+
* 設定済みプロパティのみをアルファベット順でCSS文字列として出力する。
|
|
2114
|
+
*
|
|
2115
|
+
* Requirements: 7.4, 7.7
|
|
2116
|
+
*/
|
|
2117
|
+
|
|
2118
|
+
/**
|
|
2119
|
+
* テーブルレイアウトプロパティを管理するクラス
|
|
2120
|
+
*
|
|
2121
|
+
* プロパティ: border-collapse, border-spacing, table-layout,
|
|
2122
|
+
* caption-side, empty-cells
|
|
2123
|
+
*/
|
|
2124
|
+
declare class CSSTable extends CSSPropertyGroup {
|
|
2125
|
+
/** border-collapse を設定する */
|
|
2126
|
+
setBorderCollapse(value: string): this;
|
|
2127
|
+
/** border-spacing を設定する */
|
|
2128
|
+
setBorderSpacing(value: string): this;
|
|
2129
|
+
/** table-layout を設定する */
|
|
2130
|
+
setTableLayout(value: string): this;
|
|
2131
|
+
/** caption-side を設定する */
|
|
2132
|
+
setCaptionSide(value: string): this;
|
|
2133
|
+
/** empty-cells を設定する */
|
|
2134
|
+
setEmptyCells(value: string): this;
|
|
2135
|
+
}
|
|
2136
|
+
|
|
2137
|
+
/**
|
|
2138
|
+
* Task 4.3: CSSText -- テキスト装飾プロパティ
|
|
2139
|
+
*
|
|
2140
|
+
* CSSPropertyGroup を継承することで、collectProperties() と render() の
|
|
2141
|
+
* 重複実装を排除したリファクタリング済みクラス。
|
|
2142
|
+
* 13のText関連CSSプロパティを型安全に管理し、
|
|
2143
|
+
* 設定済みプロパティのみをアルファベット順でCSS文字列として出力する。
|
|
2144
|
+
*
|
|
2145
|
+
* Requirements: 6.4, 6.5
|
|
2146
|
+
*/
|
|
2147
|
+
|
|
2148
|
+
/**
|
|
2149
|
+
* テキスト装飾プロパティを管理するクラス
|
|
2150
|
+
*
|
|
2151
|
+
* 基本プロパティ: text-align, text-decoration, text-transform, text-indent,
|
|
2152
|
+
* word-spacing, white-space, text-overflow
|
|
2153
|
+
* 拡張プロパティ: text-decoration-color, text-decoration-style,
|
|
2154
|
+
* text-decoration-line, word-break, overflow-wrap, text-shadow
|
|
2155
|
+
*/
|
|
2156
|
+
declare class CSSText extends CSSPropertyGroup {
|
|
2157
|
+
/** text-align を設定する */
|
|
2158
|
+
setTextAlign(value: string): this;
|
|
2159
|
+
/** text-decoration を設定する */
|
|
2160
|
+
setTextDecoration(value: string): this;
|
|
2161
|
+
/** text-transform を設定する */
|
|
2162
|
+
setTextTransform(value: string): this;
|
|
2163
|
+
/** text-indent を設定する */
|
|
2164
|
+
setTextIndent(value: string): this;
|
|
2165
|
+
/** word-spacing を設定する */
|
|
2166
|
+
setWordSpacing(value: string): this;
|
|
2167
|
+
/** white-space を設定する */
|
|
2168
|
+
setWhiteSpace(value: string): this;
|
|
2169
|
+
/** text-overflow を設定する */
|
|
2170
|
+
setTextOverflow(value: string): this;
|
|
2171
|
+
/** text-decoration-color を設定する */
|
|
2172
|
+
setTextDecorationColor(value: string): this;
|
|
2173
|
+
/** text-decoration-style を設定する */
|
|
2174
|
+
setTextDecorationStyle(value: string): this;
|
|
2175
|
+
/** text-decoration-line を設定する */
|
|
2176
|
+
setTextDecorationLine(value: string): this;
|
|
2177
|
+
/** word-break を設定する */
|
|
2178
|
+
setWordBreak(value: string): this;
|
|
2179
|
+
/** overflow-wrap を設定する */
|
|
2180
|
+
setOverflowWrap(value: string): this;
|
|
2181
|
+
/** text-shadow を設定する */
|
|
2182
|
+
setTextShadow(value: string): this;
|
|
2183
|
+
}
|
|
2184
|
+
|
|
2185
|
+
/**
|
|
2186
|
+
* Task 5.1: CSSTransform -- 変形・フィルタプロパティ
|
|
2187
|
+
*
|
|
2188
|
+
* CSSPropertyGroup を継承することで、collectProperties() と render() の
|
|
2189
|
+
* 重複実装を排除したリファクタリング済みクラス。
|
|
2190
|
+
* 6つのTransform関連CSSプロパティを型安全に管理し、
|
|
2191
|
+
* 設定済みプロパティのみをアルファベット順でCSS文字列として出力する。
|
|
2192
|
+
*
|
|
2193
|
+
* Requirements: 7.1, 7.2, 7.7
|
|
2194
|
+
*/
|
|
2195
|
+
|
|
2196
|
+
/**
|
|
2197
|
+
* 変形・フィルタプロパティを管理するクラス
|
|
2198
|
+
*
|
|
2199
|
+
* 変形プロパティ: transform, transform-origin
|
|
2200
|
+
* フィルタプロパティ: filter, backdrop-filter
|
|
2201
|
+
* パースペクティブプロパティ: perspective, perspective-origin
|
|
2202
|
+
*/
|
|
2203
|
+
declare class CSSTransform extends CSSPropertyGroup {
|
|
2204
|
+
/** transform を設定する */
|
|
2205
|
+
setTransform(value: string): this;
|
|
2206
|
+
/** transform-origin を設定する */
|
|
2207
|
+
setTransformOrigin(value: string): this;
|
|
2208
|
+
/** filter を設定する */
|
|
2209
|
+
setFilter(value: string): this;
|
|
2210
|
+
/** backdrop-filter を設定する */
|
|
2211
|
+
setBackdropFilter(value: string): this;
|
|
2212
|
+
/** perspective を設定する */
|
|
2213
|
+
setPerspective(value: string): this;
|
|
2214
|
+
/** perspective-origin を設定する */
|
|
2215
|
+
setPerspectiveOrigin(value: string): this;
|
|
2216
|
+
}
|
|
2217
|
+
|
|
2218
|
+
/**
|
|
2219
|
+
* CSSVisibility -- 表示制御・サイズ・可視性プロパティクラス
|
|
2220
|
+
*
|
|
2221
|
+
* display, width/height/min/max, visibility, z-index,
|
|
2222
|
+
* overflow/overflowX/overflowY, float, clear を管理する。
|
|
2223
|
+
*
|
|
2224
|
+
* CSSPropertyGroup を継承し、setProp/getProp 経由でプロパティを管理する。
|
|
2225
|
+
* Fluent setter(メソッドチェーン)対応。
|
|
2226
|
+
* 設定プロパティのみ出力し、未設定は出力しない。
|
|
2227
|
+
*
|
|
2228
|
+
* Requirements: 3.1, 3.2, 3.5, 3.6, 7.6
|
|
2229
|
+
*/
|
|
2230
|
+
|
|
2231
|
+
declare class CSSVisibility extends CSSPropertyGroup {
|
|
2232
|
+
setDisplay(value: string): this;
|
|
2233
|
+
setWidth(value: string): this;
|
|
2234
|
+
setHeight(value: string): this;
|
|
2235
|
+
setMinWidth(value: string): this;
|
|
2236
|
+
setMaxWidth(value: string): this;
|
|
2237
|
+
setMinHeight(value: string): this;
|
|
2238
|
+
setMaxHeight(value: string): this;
|
|
2239
|
+
setVisibility(value: string): this;
|
|
2240
|
+
setZIndex(value: string): this;
|
|
2241
|
+
setFloat(value: string): this;
|
|
2242
|
+
setClear(value: string): this;
|
|
2243
|
+
}
|
|
2244
|
+
|
|
2245
|
+
/**
|
|
2246
|
+
* CSSVisual -- 視覚効果プロパティ
|
|
2247
|
+
*
|
|
2248
|
+
* CSSPropertyGroup を継承し、setProp/getProp 経由でプロパティを管理する。
|
|
2249
|
+
* 6のVisual関連CSSプロパティを型安全に管理し、
|
|
2250
|
+
* 設定済みプロパティのみをアルファベット順でCSS文字列として出力する。
|
|
2251
|
+
*
|
|
2252
|
+
* Requirements: 7.3, 7.7
|
|
2253
|
+
*/
|
|
2254
|
+
|
|
2255
|
+
/**
|
|
2256
|
+
* 視覚効果プロパティを管理するクラス
|
|
2257
|
+
*
|
|
2258
|
+
* プロパティ: box-shadow, opacity, cursor, overflow, overflow-x, overflow-y
|
|
2259
|
+
*/
|
|
2260
|
+
declare class CSSVisual extends CSSPropertyGroup {
|
|
2261
|
+
/** box-shadow を設定する */
|
|
2262
|
+
setBoxShadow(value: string): this;
|
|
2263
|
+
/** opacity を設定する */
|
|
2264
|
+
setOpacity(value: string): this;
|
|
2265
|
+
/** cursor を設定する */
|
|
2266
|
+
setCursor(value: string): this;
|
|
2267
|
+
/** overflow を設定する */
|
|
2268
|
+
setOverflow(value: string): this;
|
|
2269
|
+
/** overflow-x を設定する */
|
|
2270
|
+
setOverflowX(value: string): this;
|
|
2271
|
+
/** overflow-y を設定する */
|
|
2272
|
+
setOverflowY(value: string): this;
|
|
2273
|
+
}
|
|
2274
|
+
|
|
2275
|
+
/**
|
|
2276
|
+
* HTML要素のスタイル統合管理クラス
|
|
2277
|
+
*
|
|
2278
|
+
* 13種類のCSSプロパティクラスを統合的に保持し、一元的なCSS文字列出力を提供する。
|
|
2279
|
+
* 各プロパティクラスは独立してメソッドチェーン可能で、設定されたプロパティのみが出力される。
|
|
2280
|
+
*
|
|
2281
|
+
* ## プロパティクラス一覧
|
|
2282
|
+
*
|
|
2283
|
+
* | カテゴリ | クラス | 管理プロパティ数 |
|
|
2284
|
+
* |---------|--------|-----------------|
|
|
2285
|
+
* | フォント | {@link CSSFont} | 7 |
|
|
2286
|
+
* | 背景 | {@link CSSBackground} | 5 |
|
|
2287
|
+
* | テキスト | {@link CSSText} | 13 |
|
|
2288
|
+
* | 余白 | {@link CSSSpacing} | 10 |
|
|
2289
|
+
* | 枠線 | {@link CSSBorder} | 20 |
|
|
2290
|
+
* | 表示制御 | {@link CSSVisibility} | 31 |
|
|
2291
|
+
* | Flexbox | {@link CSSFlex} | 11 |
|
|
2292
|
+
* | Grid | {@link CSSGrid} | 14 |
|
|
2293
|
+
* | 視覚効果 | {@link CSSVisual} | 6 |
|
|
2294
|
+
* | 変形 | {@link CSSTransform} | 6 |
|
|
2295
|
+
* | アニメーション | {@link CSSAnimation} | 14 |
|
|
2296
|
+
* | テーブル | {@link CSSTable} | 5 |
|
|
2297
|
+
* | リスト | {@link CSSList} | 4 |
|
|
2298
|
+
*
|
|
2299
|
+
* ## 出力順序
|
|
2300
|
+
*
|
|
2301
|
+
* レンダリング時のプロパティ出力順序(Swift版と同一):
|
|
2302
|
+
*
|
|
2303
|
+
* 1. font → 2. backgroundColor → 3. text → 4. spacing → 5. border →
|
|
2304
|
+
* 6. position → 7. flex → 8. grid → 9. visual → 10. transform →
|
|
2305
|
+
* 11. animation → 12. table → 13. list
|
|
2306
|
+
*
|
|
2307
|
+
* @example
|
|
2308
|
+
* ```ts
|
|
2309
|
+
* const style = new HtmlStyle();
|
|
2310
|
+
*
|
|
2311
|
+
* // メソッドチェーンで複数プロパティを設定
|
|
2312
|
+
* style.font
|
|
2313
|
+
* .setFontSize('16px')
|
|
2314
|
+
* .setFontWeight('bold')
|
|
2315
|
+
* .setColor('#333');
|
|
2316
|
+
*
|
|
2317
|
+
* style.spacing
|
|
2318
|
+
* .setMarginTop('10px')
|
|
2319
|
+
* .setPaddingLeft('20px');
|
|
2320
|
+
*
|
|
2321
|
+
* style.flex
|
|
2322
|
+
* .setFlexDirection('column')
|
|
2323
|
+
* .setJustifyContent('center');
|
|
2324
|
+
*
|
|
2325
|
+
* // 設定されたプロパティのみを出力
|
|
2326
|
+
* console.log(style.render());
|
|
2327
|
+
* // → "color: #333;
|
|
2328
|
+
* // font-size: 16px;
|
|
2329
|
+
* // font-weight: bold;
|
|
2330
|
+
* // margin-top: 10px;
|
|
2331
|
+
* // padding-left: 20px;
|
|
2332
|
+
* // align-items: center;
|
|
2333
|
+
* // flex-direction: column;"
|
|
2334
|
+
* ```
|
|
2335
|
+
*
|
|
2336
|
+
* @see {@link HtmlStyleType}
|
|
2337
|
+
*/
|
|
2338
|
+
|
|
2339
|
+
declare class HtmlStyle implements HtmlStyleType {
|
|
2340
|
+
/** フォント・文字色プロパティ(7プロパティ) */
|
|
2341
|
+
readonly font: CSSFont;
|
|
2342
|
+
/** 背景プロパティ(5プロパティ) */
|
|
2343
|
+
readonly backgroundColor: CSSBackground;
|
|
2344
|
+
/** テキスト装飾プロパティ(13プロパティ) */
|
|
2345
|
+
readonly text: CSSText;
|
|
2346
|
+
/** 余白プロパティ(10プロパティ) */
|
|
2347
|
+
readonly spacing: CSSSpacing;
|
|
2348
|
+
/** 枠線プロパティ(20プロパティ) */
|
|
2349
|
+
readonly border: CSSBorder;
|
|
2350
|
+
/** 表示制御・可視性プロパティ(31プロパティ) */
|
|
2351
|
+
readonly position: CSSVisibility;
|
|
2352
|
+
/** Flexboxレイアウトプロパティ(11プロパティ) */
|
|
2353
|
+
readonly flex: CSSFlex;
|
|
2354
|
+
/** Gridレイアウトプロパティ(14プロパティ) */
|
|
2355
|
+
readonly grid: CSSGrid;
|
|
2356
|
+
/** 視覚効果プロパティ(6プロパティ) */
|
|
2357
|
+
readonly visual: CSSVisual;
|
|
2358
|
+
/** 変形・フィルタプロパティ(6プロパティ) */
|
|
2359
|
+
readonly transform: CSSTransform;
|
|
2360
|
+
/** アニメーション・トランジションプロパティ(14プロパティ) */
|
|
2361
|
+
readonly animation: CSSAnimation;
|
|
2362
|
+
/** テーブルレイアウトプロパティ(5プロパティ) */
|
|
2363
|
+
readonly table: CSSTable;
|
|
2364
|
+
/** リストスタイルプロパティ(4プロパティ) */
|
|
2365
|
+
readonly list: CSSList;
|
|
2366
|
+
/**
|
|
2367
|
+
* 擬似クラス(:hover / :focus / :active)スタイル。
|
|
2368
|
+
*
|
|
2369
|
+
* Anti-Invariant:
|
|
2370
|
+
* CSSPseudo は意図的に `Renderable` を実装せず、`render()` の outputs 配列にも
|
|
2371
|
+
* 含めない。擬似クラスは body-level プロパティ集約ではなく CSS ルールブロック
|
|
2372
|
+
* (セレクタ付き)であり、`CssManager.renderCss()` から `renderForScope(scopeClass)` を
|
|
2373
|
+
* 直接呼び出して出力する。
|
|
2374
|
+
*/
|
|
2375
|
+
readonly pseudo: CSSPseudo;
|
|
2376
|
+
/**
|
|
2377
|
+
* すべてのプロパティをCSS文字列としてレンダリングする
|
|
2378
|
+
*
|
|
2379
|
+
* 各プロパティクラスの出力を順序通りに結合し、空文字列のものは除外する。
|
|
2380
|
+
* 未設定のプロパティは出力されない。
|
|
2381
|
+
*
|
|
2382
|
+
* @returns CSS文字列(全プロパティ未設定の場合は空文字列)
|
|
2383
|
+
*/
|
|
2384
|
+
render(): string;
|
|
2385
|
+
}
|
|
2386
|
+
|
|
2387
|
+
type EdgeSet = 'horizontal' | 'vertical' | 'top' | 'right' | 'bottom' | 'left';
|
|
2388
|
+
|
|
2389
|
+
declare const Breakpoints: {
|
|
2390
|
+
readonly sm: 640;
|
|
2391
|
+
readonly md: 768;
|
|
2392
|
+
readonly lg: 1024;
|
|
2393
|
+
readonly xl: 1280;
|
|
2394
|
+
};
|
|
2395
|
+
type BreakpointKey = keyof typeof Breakpoints;
|
|
2396
|
+
interface BreakpointStyles {
|
|
2397
|
+
sm?: Partial<CSSStyleDeclaration>;
|
|
2398
|
+
md?: Partial<CSSStyleDeclaration>;
|
|
2399
|
+
lg?: Partial<CSSStyleDeclaration>;
|
|
2400
|
+
xl?: Partial<CSSStyleDeclaration>;
|
|
2401
|
+
[customPx: number]: Partial<CSSStyleDeclaration> | undefined;
|
|
2402
|
+
}
|
|
2403
|
+
|
|
2404
|
+
/**
|
|
2405
|
+
* `src/js/vanilla` モジュール全体で共有される型定義。
|
|
2406
|
+
*
|
|
2407
|
+
* - `JsExpr` / `JsBoolExpr`: JS 式を表す値オブジェクト型。
|
|
2408
|
+
* - `ElementEventName`: `HTMLElementEventMap` のキーに制約されたイベント名。
|
|
2409
|
+
* - `EventArgRef<K>`: `on()` ハンドラの第 2 引数として注入される型付きイベント参照。
|
|
2410
|
+
* - `StringKeysOf<T>`: 文字列/数値/真偽プロパティのキーのみを抽出する内部ユーティリティ型。
|
|
2411
|
+
* - `WritableStyleKey`: `CSSStyleDeclaration` の書き込み可能プロパティキーのみを抽出した型。
|
|
2412
|
+
*
|
|
2413
|
+
* 本ファイルは設計書 `design.md` の「types」セクションに対応する。
|
|
2414
|
+
*/
|
|
2415
|
+
/**
|
|
2416
|
+
* JS 式を表す値オブジェクト。`.code` で生文字列を、メソッドで合成式を得る。
|
|
2417
|
+
* 具体的なチェーンメソッド(`eq` / `ne` / `or` / `trim` / `isFalsy` / `isTruthy`)は
|
|
2418
|
+
* 後続タスクで実装する。
|
|
2419
|
+
*/
|
|
2420
|
+
interface JsExpr {
|
|
2421
|
+
readonly __jsExpr: true;
|
|
2422
|
+
readonly code: string;
|
|
2423
|
+
eq(other: string | number | JsExpr): JsBoolExpr;
|
|
2424
|
+
ne(other: string | number | JsExpr): JsBoolExpr;
|
|
2425
|
+
or(fallback: string | JsExpr): JsExpr;
|
|
2426
|
+
trim(): JsExpr;
|
|
2427
|
+
isFalsy(): JsBoolExpr;
|
|
2428
|
+
isTruthy(): JsBoolExpr;
|
|
2429
|
+
}
|
|
2430
|
+
/**
|
|
2431
|
+
* JS 真偽値式を表す値オブジェクト。`JsExpr` のサブタイプ。
|
|
2432
|
+
* `ifThen` / `toggleClass(force)` などで型レベルに真偽式のみを許容するための標識。
|
|
2433
|
+
*/
|
|
2434
|
+
interface JsBoolExpr extends JsExpr {
|
|
2435
|
+
readonly __jsBool: true;
|
|
2436
|
+
}
|
|
2437
|
+
/**
|
|
2438
|
+
* 入力系要素(`value` プロパティを持つ要素)を表す内部型。
|
|
2439
|
+
* `ElementRef.value` の条件付き公開のために使用する。
|
|
2440
|
+
*/
|
|
2441
|
+
type InputLikeElement = HTMLInputElement | HTMLTextAreaElement | HTMLSelectElement;
|
|
2442
|
+
/**
|
|
2443
|
+
* 要素参照を「変数参照 / セレクタ / 任意の JS 式」の 3 形態で統一表現する値オブジェクト。
|
|
2444
|
+
* 不透明型として扱い、`kind` と `code` のみを外部に露出する。
|
|
2445
|
+
*
|
|
2446
|
+
* - `kind: 'var'`: `jsName` 由来の変数参照。`code === varName`。
|
|
2447
|
+
* - `kind: 'selector'`: `document.querySelector(sel)` のインライン展開。
|
|
2448
|
+
* - `kind: 'expr'`: 任意の JS 式(内部用)。
|
|
2449
|
+
*
|
|
2450
|
+
* `textContent` / `value` は `JsExpr` として遅延的に露出する。
|
|
2451
|
+
* `value` は要素型 `E` が入力系要素のときのみ型レベルでアクセス可能。
|
|
2452
|
+
*/
|
|
2453
|
+
interface ElementRef<E extends Element = Element> {
|
|
2454
|
+
readonly __ref: true;
|
|
2455
|
+
readonly kind: 'var' | 'selector' | 'expr';
|
|
2456
|
+
readonly code: string;
|
|
2457
|
+
readonly textContent: JsExpr;
|
|
2458
|
+
readonly value: E extends InputLikeElement ? JsExpr : never;
|
|
2459
|
+
cache(name?: string): ElementRef<E>;
|
|
2460
|
+
/**
|
|
2461
|
+
* `element.classList.contains(name)` を `JsBoolExpr` として返す。
|
|
2462
|
+
* `ifThen` / `toggleClass(force)` / `filterNot` 等の真偽式引数に使用する。
|
|
2463
|
+
*/
|
|
2464
|
+
containsClass(name: string): JsBoolExpr;
|
|
2465
|
+
}
|
|
2466
|
+
|
|
2467
|
+
/**
|
|
2468
|
+
* `ElementTarget` 判別共用体の定義。
|
|
2469
|
+
*
|
|
2470
|
+
* 設計書 `design.md` の「Target 抽象」「ElementTarget union」に対応。
|
|
2471
|
+
* バインドコマンドが対象 DOM 要素を指す方法を 2 種類のバリアントで表現する:
|
|
2472
|
+
*
|
|
2473
|
+
* - `'sel'`: CSS セレクタ文字列で指定(既存挙動・後方互換)。
|
|
2474
|
+
* ランタイムでは `document.querySelector(selector)` で解決される。
|
|
2475
|
+
* - `'closure-ref'`: クロージャ内ローカル変数名で指定(each テンプレート等)。
|
|
2476
|
+
* ランタイムではコード生成時の裸の識別子(例: `_e0`)として埋め込まれる。
|
|
2477
|
+
* - `'deferred-self'`: 生成時点で対象要素が未確定。ランタイムに `this` として解決される。
|
|
2478
|
+
*
|
|
2479
|
+
* このモジュールは型のみを export する純粋な型定義ファイルであり、
|
|
2480
|
+
* 後続タスク(5.3 `_getTargetCode` リファクタ、5.4 `binding-emitter`
|
|
2481
|
+
* 各 emit 関数の引数型統一)から canonical な型として import される。
|
|
2482
|
+
*
|
|
2483
|
+
* NOTE: `commands.ts` の `ElementTarget`(`'var' | 'sel'`)とは別の union。
|
|
2484
|
+
* 5.3 / 5.4 のリファクタで両者を整合させる予定(本タスクでは触らない)。
|
|
2485
|
+
*
|
|
2486
|
+
* Requirements: 4.1, 4.2, 4.4, 4.5
|
|
2487
|
+
*/
|
|
2488
|
+
/**
|
|
2489
|
+
* CSS セレクタ文字列で対象要素を指すバリアント。
|
|
2490
|
+
*
|
|
2491
|
+
* 既存の `{ kind: 'sel', selector }` 構造をそのまま踏襲する(後方互換)。
|
|
2492
|
+
*/
|
|
2493
|
+
type SelectorTarget = {
|
|
2494
|
+
readonly kind: 'sel';
|
|
2495
|
+
readonly selector: string;
|
|
2496
|
+
};
|
|
2497
|
+
/**
|
|
2498
|
+
* クロージャ内ローカル変数名で対象要素を指すバリアント。
|
|
2499
|
+
*
|
|
2500
|
+
* `varName` は factory コード内のローカル変数名(`_e0`, `_e1` 等)。
|
|
2501
|
+
* ランタイムには裸の識別子としてそのまま埋め込まれる。
|
|
2502
|
+
*/
|
|
2503
|
+
type ClosureRefTarget = {
|
|
2504
|
+
readonly kind: 'closure-ref';
|
|
2505
|
+
readonly varName: string;
|
|
2506
|
+
};
|
|
2507
|
+
/**
|
|
2508
|
+
* 遅延解決バリアント。バインドコマンド生成時点では対象要素が未確定で、
|
|
2509
|
+
* ランタイムに `this`(自身の要素)として解決されることを示す。
|
|
2510
|
+
*
|
|
2511
|
+
* Requirements: 1.1, 1.2, 1.3, 4.1
|
|
2512
|
+
*/
|
|
2513
|
+
type DeferredSelfTarget = {
|
|
2514
|
+
readonly kind: 'deferred-self';
|
|
2515
|
+
};
|
|
2516
|
+
/**
|
|
2517
|
+
* 要素ターゲットの判別共用体。
|
|
2518
|
+
*
|
|
2519
|
+
* `kind` フィールドによる discriminated union として narrow できる。
|
|
2520
|
+
*/
|
|
2521
|
+
type ElementTarget = SelectorTarget | ClosureRefTarget | DeferredSelfTarget;
|
|
2522
|
+
|
|
2523
|
+
/**
|
|
2524
|
+
* 内部命令レコード `VanillaCommand` 判別共用体と JS 文字列化関数。
|
|
2525
|
+
*
|
|
2526
|
+
* 設計書 `design.md` の「commands: VanillaCommand」「renderCommand」「renderCommands」に対応。
|
|
2527
|
+
* 本モジュールは全 API が発行する命令の代数的データ型と、それらを JS 文字列へ
|
|
2528
|
+
* 変換する純関数を 1 箇所に集約する。`jQuery` / `$` を出力に含めない制約を
|
|
2529
|
+
* コードレビュー可能にする責務を負う(Req 1.5, 7.1)。
|
|
2530
|
+
*/
|
|
2531
|
+
|
|
2532
|
+
/**
|
|
2533
|
+
* each テンプレートの捕捉情報。
|
|
2534
|
+
* `each-template.ts` との循環 import を避けるためここで独立定義する。
|
|
2535
|
+
* (`each-template.ts` が `commands.ts` を import するため循環になる)
|
|
2536
|
+
*
|
|
2537
|
+
* - `itemStateIdPattern`: "{parent}.item{i}" パターン
|
|
2538
|
+
* - `templateCommands`: テンプレート HtmlTag の `_pending` から取り出した命令列
|
|
2539
|
+
*/
|
|
2540
|
+
interface EachTemplateSnapshot {
|
|
2541
|
+
/** スロット ID パターン。ランタイムが "{i}" を実際のインデックスに置換する */
|
|
2542
|
+
itemStateIdPattern: string;
|
|
2543
|
+
/** テンプレート内の VanillaCommand(_pending からスナップショット) */
|
|
2544
|
+
templateCommands: VanillaCommand[];
|
|
2545
|
+
/**
|
|
2546
|
+
* 6.1: closure 形式 factory 関数文字列。
|
|
2547
|
+
* `function(arrayId, idx, draftole) { ... return _e0; }` 形式。
|
|
2548
|
+
*/
|
|
2549
|
+
factoryCode?: string;
|
|
2550
|
+
/** factory コード生成方式。closure(新形)/ static-placeholder(旧形)。 */
|
|
2551
|
+
factoryKind?: 'closure' | 'static-placeholder';
|
|
2552
|
+
/**
|
|
2553
|
+
* each-closure-fix: closure 経路で build-phase 直後に保持する template HtmlTag。
|
|
2554
|
+
* emit-phase で tagPath 注入と factoryCode 生成のために再走査する。
|
|
2555
|
+
* factoryCode 確定後は不要となるため optional。
|
|
2556
|
+
*/
|
|
2557
|
+
_templateRoot?: HtmlTag;
|
|
2558
|
+
}
|
|
2559
|
+
/**
|
|
2560
|
+
* バニラ JS ビルダーが発行する内部命令の判別共用体。
|
|
2561
|
+
* 各バリアントは `type` で識別され、`renderCommand` により JS 文字列に変換される。
|
|
2562
|
+
*/
|
|
2563
|
+
type VanillaCommand = {
|
|
2564
|
+
type: 'addEventListener';
|
|
2565
|
+
target: ElementTarget;
|
|
2566
|
+
event: string;
|
|
2567
|
+
handlerCode: string;
|
|
2568
|
+
} | {
|
|
2569
|
+
type: 'domReady';
|
|
2570
|
+
bodyCode: string;
|
|
2571
|
+
} | {
|
|
2572
|
+
type: 'declareFunction';
|
|
2573
|
+
name: string;
|
|
2574
|
+
params: readonly string[];
|
|
2575
|
+
bodyCode: string;
|
|
2576
|
+
} | {
|
|
2577
|
+
type: 'declareConst';
|
|
2578
|
+
name: string;
|
|
2579
|
+
expr: string;
|
|
2580
|
+
} | {
|
|
2581
|
+
type: 'classListToggle';
|
|
2582
|
+
target: ElementTarget;
|
|
2583
|
+
name: string;
|
|
2584
|
+
force?: string;
|
|
2585
|
+
} | {
|
|
2586
|
+
type: 'classListAdd';
|
|
2587
|
+
target: ElementTarget;
|
|
2588
|
+
name: string;
|
|
2589
|
+
} | {
|
|
2590
|
+
type: 'classListRemove';
|
|
2591
|
+
target: ElementTarget;
|
|
2592
|
+
name: string;
|
|
2593
|
+
} | {
|
|
2594
|
+
type: 'setProp';
|
|
2595
|
+
target: ElementTarget;
|
|
2596
|
+
prop: 'textContent' | 'value';
|
|
2597
|
+
expr: string;
|
|
2598
|
+
} | {
|
|
2599
|
+
type: 'setStyle';
|
|
2600
|
+
target: ElementTarget;
|
|
2601
|
+
key: string;
|
|
2602
|
+
expr: string;
|
|
2603
|
+
} | {
|
|
2604
|
+
type: 'appendChild';
|
|
2605
|
+
parent: ElementTarget;
|
|
2606
|
+
child: ElementTarget;
|
|
2607
|
+
} | {
|
|
2608
|
+
type: 'remove';
|
|
2609
|
+
target: ElementTarget;
|
|
2610
|
+
} | {
|
|
2611
|
+
type: 'forEach';
|
|
2612
|
+
listExpr: string;
|
|
2613
|
+
itemVar: string;
|
|
2614
|
+
bodyCode: string;
|
|
2615
|
+
} | {
|
|
2616
|
+
type: 'if';
|
|
2617
|
+
condition: string;
|
|
2618
|
+
thenCode: string;
|
|
2619
|
+
elseCode?: string;
|
|
2620
|
+
} | {
|
|
2621
|
+
type: 'expr';
|
|
2622
|
+
code: string;
|
|
2623
|
+
} | {
|
|
2624
|
+
type: 'raw';
|
|
2625
|
+
code: string;
|
|
2626
|
+
} | {
|
|
2627
|
+
type: 'state-init';
|
|
2628
|
+
id: string;
|
|
2629
|
+
initial: JsExpr;
|
|
2630
|
+
} | {
|
|
2631
|
+
type: 'state-set';
|
|
2632
|
+
id: string;
|
|
2633
|
+
value: JsExpr;
|
|
2634
|
+
} | {
|
|
2635
|
+
type: 'state-update';
|
|
2636
|
+
id: string;
|
|
2637
|
+
body: JsExpr;
|
|
2638
|
+
} | {
|
|
2639
|
+
type: 'bind-text';
|
|
2640
|
+
target: ElementTarget;
|
|
2641
|
+
stateId: string;
|
|
2642
|
+
transform?: JsExpr;
|
|
2643
|
+
} | {
|
|
2644
|
+
type: 'bind-value';
|
|
2645
|
+
target: ElementTarget;
|
|
2646
|
+
stateId: string;
|
|
2647
|
+
transform?: JsExpr;
|
|
2648
|
+
} | {
|
|
2649
|
+
type: 'bind-checked';
|
|
2650
|
+
target: ElementTarget;
|
|
2651
|
+
stateId: string;
|
|
2652
|
+
transform?: JsExpr;
|
|
2653
|
+
} | {
|
|
2654
|
+
type: 'bind-class-all';
|
|
2655
|
+
target: ElementTarget;
|
|
2656
|
+
stateId: string;
|
|
2657
|
+
transform?: JsExpr;
|
|
2658
|
+
} | {
|
|
2659
|
+
type: 'bind-class-add';
|
|
2660
|
+
target: ElementTarget;
|
|
2661
|
+
stateId: string;
|
|
2662
|
+
transform?: JsExpr;
|
|
2663
|
+
} | {
|
|
2664
|
+
type: 'bind-style';
|
|
2665
|
+
target: ElementTarget;
|
|
2666
|
+
prop: string;
|
|
2667
|
+
stateId: string;
|
|
2668
|
+
transform?: JsExpr;
|
|
2669
|
+
} | {
|
|
2670
|
+
type: 'bind-attr';
|
|
2671
|
+
target: ElementTarget;
|
|
2672
|
+
attr: string;
|
|
2673
|
+
stateId: string;
|
|
2674
|
+
transform?: JsExpr;
|
|
2675
|
+
} | {
|
|
2676
|
+
type: 'bind-each';
|
|
2677
|
+
target: ElementTarget;
|
|
2678
|
+
stateId: string;
|
|
2679
|
+
template: EachTemplateSnapshot;
|
|
2680
|
+
} | {
|
|
2681
|
+
type: 'derive-state';
|
|
2682
|
+
sourceId: string;
|
|
2683
|
+
derivedId: string;
|
|
2684
|
+
transformBody: JsExpr;
|
|
2685
|
+
} | {
|
|
2686
|
+
type: 'handler-body';
|
|
2687
|
+
target: ElementTarget;
|
|
2688
|
+
event: string;
|
|
2689
|
+
code: string;
|
|
2690
|
+
params: readonly string[];
|
|
2691
|
+
};
|
|
2692
|
+
|
|
2693
|
+
/**
|
|
2694
|
+
* `VanillaScriptBuilder` クラス本体(命令蓄積器 + `render()`)。
|
|
2695
|
+
*
|
|
2696
|
+
* 設計書 `design.md` の「vanilla-script-builder」「VanillaScope」節に対応する。
|
|
2697
|
+
*
|
|
2698
|
+
* 責務:
|
|
2699
|
+
* - トップレベル命令キュー、`onDomReady` ブロック用の単一キュー、子 Builder を用いた
|
|
2700
|
+
* 関数本体 / `onDomReady` / `forEach` / `ifThen` / イベントハンドラ本体の組み立て。
|
|
2701
|
+
* - `render()` は冪等で副作用を持たず、`append` 順を保った JS 文字列を返す(Req 7.4)。
|
|
2702
|
+
* - `hasDomReady` は `onDomReady` が 1 度でも呼ばれたかを反映する(wrapDOMReady 併用判定に使用)。
|
|
2703
|
+
* - 出力に `jQuery` / `$` を含まない(Req 1.5, 7.1、`commands.ts` の語彙集約による担保)。
|
|
2704
|
+
*
|
|
2705
|
+
* 公開 API は `createVanillaScript()` ファクトリのみ。クラス本体は外部 import しない。
|
|
2706
|
+
*/
|
|
2707
|
+
|
|
2708
|
+
/**
|
|
2709
|
+
* `ifThen` の条件や `let` の値、`call` の引数に渡す最小インターフェース。
|
|
2710
|
+
* `.code` を備えた任意の値オブジェクト(`JsExpr` / `ElementRef` 等)が適合する。
|
|
2711
|
+
*/
|
|
2712
|
+
interface ScopeExpr {
|
|
2713
|
+
readonly code: string;
|
|
2714
|
+
}
|
|
2715
|
+
/**
|
|
2716
|
+
* スコープ内で利用できる制御・値組み立て API。
|
|
2717
|
+
*
|
|
2718
|
+
* Task 3.1 で提供する最小セット:`raw` / `let` / `call` / `return` / `ifThen`。
|
|
2719
|
+
* `query` / `on` / `classList.*` 等は後続タスクで別ファイルから拡張される想定。
|
|
2720
|
+
*/
|
|
2721
|
+
interface VanillaScope {
|
|
2722
|
+
/**
|
|
2723
|
+
* 内部 API:現在スコープのキューに任意の `VanillaCommand` を追加する。
|
|
2724
|
+
*
|
|
2725
|
+
* このフックは `event-api` / `query-api` / `dom-api` / `tree-api` などの
|
|
2726
|
+
* ユーザ向け関数が、Scope インターフェース自体を `on` / `query` / `classList.*`
|
|
2727
|
+
* 等で肥大化させずに命令を append できるようにするためのエスケープハッチ。
|
|
2728
|
+
* 利用者コードからの直接呼び出しは非推奨(命令種別は内部詳細)。
|
|
2729
|
+
*/
|
|
2730
|
+
_append(cmd: VanillaCommand): void;
|
|
2731
|
+
/**
|
|
2732
|
+
* 内部 API:現在スコープ用に子スコープを構築するためのフック。
|
|
2733
|
+
* `event-api` のハンドラ本体組み立てなど、子キューで命令を蓄積して
|
|
2734
|
+
* まとめて `renderCommands` に掛ける用途に利用する。
|
|
2735
|
+
*/
|
|
2736
|
+
_childScope(queue: VanillaCommand[]): VanillaScope;
|
|
2737
|
+
/** 任意 JS 式を式として埋め込む。副作用として命令は発行しない(`JsExpr` 相当を返す)。 */
|
|
2738
|
+
raw(code: string): ScopeExpr;
|
|
2739
|
+
/**
|
|
2740
|
+
* `const name = <value.code>;` 命令を現在スコープに append し、`name` を指す値オブジェクトを返す。
|
|
2741
|
+
* 設計では `const`/`let` の区別は内部詳細であり、常に `const` を出力する。
|
|
2742
|
+
*/
|
|
2743
|
+
let(name: string, value: ScopeExpr): ScopeExpr;
|
|
2744
|
+
/**
|
|
2745
|
+
* 関数呼び出し式 `name(args...)` を現在スコープに `expr` 命令として append する。
|
|
2746
|
+
* 戻り値は式として再利用可能なオブジェクト(呼び出し結果を別文脈で使いたい場合)。
|
|
2747
|
+
*/
|
|
2748
|
+
call(name: string, args?: readonly ScopeExpr[]): ScopeExpr;
|
|
2749
|
+
/** `return;` を発行する。 */
|
|
2750
|
+
return(): void;
|
|
2751
|
+
/** `if (cond) { then } else? { orElse }` を発行する。 */
|
|
2752
|
+
ifThen(condition: ScopeExpr, then: (s: VanillaScope) => void, orElse?: (s: VanillaScope) => void): void;
|
|
2753
|
+
}
|
|
2754
|
+
/**
|
|
2755
|
+
* `render()` で JS 文字列を得るアキュムレータの公開ビュー。
|
|
2756
|
+
*/
|
|
2757
|
+
interface VanillaScript {
|
|
2758
|
+
/** 生成される JS 文字列。末尾改行は含めない。 */
|
|
2759
|
+
render(): string;
|
|
2760
|
+
/**
|
|
2761
|
+
* `render()` 出力が最外層で `DOMContentLoaded` リスナーを含むか。
|
|
2762
|
+
* `wrapDOMReady` 併用の要否判定に利用する。
|
|
2763
|
+
*/
|
|
2764
|
+
readonly hasDomReady: boolean;
|
|
2765
|
+
}
|
|
2766
|
+
/**
|
|
2767
|
+
* `VanillaScript` に加えて命令 append と制御フロー API を公開する Builder 型。
|
|
2768
|
+
* 公開 API からは `createVanillaScript()` 経由でのみ取得できる。
|
|
2769
|
+
*/
|
|
2770
|
+
interface VanillaScriptBuilder extends VanillaScript {
|
|
2771
|
+
/** 内部 API:任意の `VanillaCommand` をトップレベルキューに追加する。 */
|
|
2772
|
+
append(cmd: VanillaCommand): void;
|
|
2773
|
+
/** `onDomReady` ブロックを開き、ハンドラ内で append された命令を DOMContentLoaded 内に合流する。 */
|
|
2774
|
+
onDomReady(body: (s: VanillaScope) => void): void;
|
|
2775
|
+
/** トップレベルに関数定義を追加する。 */
|
|
2776
|
+
declareFunction(name: string, params: readonly string[], body: (s: VanillaScope) => void): void;
|
|
2777
|
+
/** `declareFunction` の省略形。`fn(name, body)` なら params は空配列。 */
|
|
2778
|
+
fn(name: string, body: (s: VanillaScope) => void): void;
|
|
2779
|
+
fn(name: string, params: readonly string[], body: (s: VanillaScope) => void): void;
|
|
2780
|
+
}
|
|
2781
|
+
/**
|
|
2782
|
+
* `VanillaScriptBuilder` インスタンスを生成する公開ファクトリ。
|
|
2783
|
+
*
|
|
2784
|
+
* クラス実装は非公開であり、このファクトリ経由でのみ取得できる。
|
|
2785
|
+
* `Root` は内部でこのファクトリを使用して単一の builder を遅延生成する。
|
|
2786
|
+
* 直接利用する場合は `append` / `fn` / `onDomReady` / `render` を呼ぶ。
|
|
2787
|
+
*
|
|
2788
|
+
* @returns 新しい `VanillaScriptBuilder` インスタンス
|
|
2789
|
+
*
|
|
2790
|
+
* @example
|
|
2791
|
+
* ```typescript
|
|
2792
|
+
* const builder = createVanillaScript();
|
|
2793
|
+
* builder.onDomReady(s => s.call('init'));
|
|
2794
|
+
* console.log(builder.render());
|
|
2795
|
+
* ```
|
|
2796
|
+
*/
|
|
2797
|
+
declare function createVanillaScript(): VanillaScriptBuilder;
|
|
2798
|
+
|
|
2799
|
+
/**
|
|
2800
|
+
* StateRegistry — 状態エントリの管理と状態 ID 採番を担うクラス。
|
|
2801
|
+
*
|
|
2802
|
+
* 設計書 `design.md` の「Components and Interfaces: StateRegistry」に対応。
|
|
2803
|
+
* - 状態 ID → StateEntry のマッピングを管理する
|
|
2804
|
+
* - 状態 ID を "s0", "s1", ... の形式で一意に採番する
|
|
2805
|
+
* - state-init コマンド列を生成して FileExporter に提供する(Req 1.2, 1.3, 5.4)
|
|
2806
|
+
*
|
|
2807
|
+
* Note: StateInitCommand は tasks 3.1 で commands.ts に移動予定のため、
|
|
2808
|
+
* 現時点ではこのファイル内にローカル定義する。
|
|
2809
|
+
*/
|
|
2810
|
+
|
|
2811
|
+
/**
|
|
2812
|
+
* 状態エントリ(StateRegistry 内部)。
|
|
2813
|
+
* design.md の Data Models セクションに対応。
|
|
2814
|
+
*/
|
|
2815
|
+
interface StateEntry {
|
|
2816
|
+
/** ランタイム状態 ID(例: "s0", "s1")*/
|
|
2817
|
+
runtimeId: string;
|
|
2818
|
+
/** JSON.stringify された初期値を表す JS 式 */
|
|
2819
|
+
initialExpr: JsExpr;
|
|
2820
|
+
/** 型名(デバッグ用、optional)*/
|
|
2821
|
+
typeHint?: string;
|
|
2822
|
+
}
|
|
2823
|
+
/**
|
|
2824
|
+
* state-init コマンドを表すローカル型。
|
|
2825
|
+
* タスク 3.1 で VanillaCommand に統合予定。
|
|
2826
|
+
*/
|
|
2827
|
+
interface StateInitCommand {
|
|
2828
|
+
type: 'state-init';
|
|
2829
|
+
id: string;
|
|
2830
|
+
initial: JsExpr;
|
|
2831
|
+
}
|
|
2832
|
+
/**
|
|
2833
|
+
* Computed 派生状態のエントリ。
|
|
2834
|
+
* 方針 B: .map() で生成された Computed をランタイム状態として管理する。
|
|
2835
|
+
* sourceId の変化を購読して derivedId を更新するサブスクリプションを生成する。
|
|
2836
|
+
*/
|
|
2837
|
+
interface DerivedEntry {
|
|
2838
|
+
/** 派生状態の ID(allocateId() で採番済み)*/
|
|
2839
|
+
derivedId: string;
|
|
2840
|
+
/** 購読元の状態 ID(直接の親状態)*/
|
|
2841
|
+
sourceId: string;
|
|
2842
|
+
/** _v を入力変数とした変換式(例: `((_v).filter(...).length)`)*/
|
|
2843
|
+
transformBody: JsExpr;
|
|
2844
|
+
}
|
|
2845
|
+
/**
|
|
2846
|
+
* derive-state コマンドを表す型。
|
|
2847
|
+
* file-exporter が renderCommand に渡すために使用する。
|
|
2848
|
+
*/
|
|
2849
|
+
interface DeriveStateCommand {
|
|
2850
|
+
type: 'derive-state';
|
|
2851
|
+
sourceId: string;
|
|
2852
|
+
derivedId: string;
|
|
2853
|
+
transformBody: JsExpr;
|
|
2854
|
+
}
|
|
2855
|
+
/**
|
|
2856
|
+
* StateRegistry クラス。
|
|
2857
|
+
*
|
|
2858
|
+
* - `allocateId()`: "s0", "s1", ... の形式で一意な状態 ID を採番
|
|
2859
|
+
* - `register(entry)`: StateEntry を entries マップに登録
|
|
2860
|
+
* - `isEmpty()`: 状態が 1 つも宣言されていないか確認(Req 5.4)
|
|
2861
|
+
* - `listInitCommands()`: state-init コマンド列を返す(FileExporter が利用)
|
|
2862
|
+
*/
|
|
2863
|
+
declare class StateRegistry {
|
|
2864
|
+
private _nextId;
|
|
2865
|
+
readonly entries: Map<string, StateEntry>;
|
|
2866
|
+
private readonly _derivedEntries;
|
|
2867
|
+
/**
|
|
2868
|
+
* 次の一意な状態 ID を採番して返す("s0", "s1", ...)。
|
|
2869
|
+
* 採番のみ行い、エントリへの登録は行わない。
|
|
2870
|
+
* Req 1.3: 同一 Root から root.state(...) を複数回呼び出すと、呼び出しごとに異なる状態 ID を採番。
|
|
2871
|
+
*/
|
|
2872
|
+
allocateId(): string;
|
|
2873
|
+
/**
|
|
2874
|
+
* StateEntry を entries マップに追加する。
|
|
2875
|
+
* runtimeId をキーとして Map に格納する。
|
|
2876
|
+
*/
|
|
2877
|
+
register(entry: StateEntry): void;
|
|
2878
|
+
/**
|
|
2879
|
+
* Computed 派生エントリを登録する。
|
|
2880
|
+
* .map() で生成された Computed ごとに呼ばれる(方針 B)。
|
|
2881
|
+
*/
|
|
2882
|
+
registerDerived(entry: DerivedEntry): void;
|
|
2883
|
+
/**
|
|
2884
|
+
* derive-state コマンド列を返す。
|
|
2885
|
+
* file-exporter が state-init の直後に出力して親→派生のサブスクリプションを確立する。
|
|
2886
|
+
* 登録順で返すことで依存関係の解決順序を保証する。
|
|
2887
|
+
*/
|
|
2888
|
+
listDeriveCommands(): DeriveStateCommand[];
|
|
2889
|
+
/**
|
|
2890
|
+
* 状態が 1 つも宣言されていないか確認する。
|
|
2891
|
+
* Req 5.4: Root に状態が 1 つも宣言されていない場合、FileExporter はプレリュードを出力しない。
|
|
2892
|
+
*/
|
|
2893
|
+
isEmpty(): boolean;
|
|
2894
|
+
/**
|
|
2895
|
+
* state-init コマンド列を返す。
|
|
2896
|
+
* FileExporter が script.js に初期化コードを出力するために利用する(Req 1.2)。
|
|
2897
|
+
* エントリの登録順でコマンドを返す。
|
|
2898
|
+
*/
|
|
2899
|
+
listInitCommands(): StateInitCommand[];
|
|
2900
|
+
}
|
|
2901
|
+
|
|
2902
|
+
/**
|
|
2903
|
+
* StateJsAccessor — State 値を読み書きする JS 文字列アクセサ
|
|
2904
|
+
*
|
|
2905
|
+
* 設計書 `design.md` の「Component: StateJsAccessor (NEW)」に対応。
|
|
2906
|
+
*
|
|
2907
|
+
* - `get()` → `"__draftole__.state('<runtimeId>').get()"`
|
|
2908
|
+
* - `set(expr)` → `"__draftole__.state('<runtimeId>').set(<expr>)"`
|
|
2909
|
+
* - `update(body)` → `"__draftole__.state('<runtimeId>').set((__v) => { <body> })"`
|
|
2910
|
+
*
|
|
2911
|
+
* Requirements: 1.1, 1.2, 1.3, 1.4
|
|
2912
|
+
*/
|
|
2913
|
+
interface StateJsAccessor {
|
|
2914
|
+
/** `"__draftole__.state('<runtimeId>').get()"` を返す */
|
|
2915
|
+
get(): string;
|
|
2916
|
+
/** `"__draftole__.state('<runtimeId>').set(<expr>)"` を返す */
|
|
2917
|
+
set(expr: string): string;
|
|
2918
|
+
/** `"__draftole__.state('<runtimeId>').set((__v) => { <body> })"` を返す */
|
|
2919
|
+
update(body: string): string;
|
|
2920
|
+
}
|
|
2921
|
+
|
|
2922
|
+
/**
|
|
2923
|
+
* State<T> / Computed<T> の実装
|
|
2924
|
+
*
|
|
2925
|
+
* 設計書 `design.md` の「Components and Interfaces: State<T> / Computed<T>」に対応。
|
|
2926
|
+
*
|
|
2927
|
+
* - `State<T>`: 読み書き可能な観測可能値オブジェクト(ビルド時)
|
|
2928
|
+
* - `Computed<T>`: 読み取り専用の派生値オブジェクト(`.set` を持たない)
|
|
2929
|
+
* - `createStateExpr`: runtimeId から `__draftole__.state(id).get()` 形式の JsExpr を生成
|
|
2930
|
+
*
|
|
2931
|
+
* 設計上の決定事項:
|
|
2932
|
+
* - `.get()` は JsExpr を返す(ランタイム API 呼び出し式)
|
|
2933
|
+
* - `.set(v)` / `.update(body)` は ScriptScope 内で呼ばれることを前提としたコマンド生成 API
|
|
2934
|
+
* (このタスクでは no-op / stub として実装)
|
|
2935
|
+
* - `.map(fn)` は Computed<U> を返す(fn はビルド時に呼ばれる)
|
|
2936
|
+
* - `.field(key)` は State/Computed の派生を返す(_parent / _fieldKey チェーンを保持)
|
|
2937
|
+
* - `.each(fn)` は EachBinding<U> を返す(タスク 2.3 で詳細実装)
|
|
2938
|
+
*
|
|
2939
|
+
* Requirements: 1.4, 2.1, 2.2, 2.3, 3.1, 3.2, 3.4, 6.3
|
|
2940
|
+
*/
|
|
2941
|
+
|
|
2942
|
+
/**
|
|
2943
|
+
* ReadableState<T> を識別するための構造的マーカーシンボル。
|
|
2944
|
+
*
|
|
2945
|
+
* `declare const` なのでランタイムには存在しない(型レイヤのみ)。
|
|
2946
|
+
* transformer の TypeChecker から 1 回の getTypeAtLocation で
|
|
2947
|
+
* State / Computed / ScriptStateHandle を判別可能にする(Design D-7)。
|
|
2948
|
+
*/
|
|
2949
|
+
declare const DraftoleStateMarker: unique symbol;
|
|
2950
|
+
/** 配列要素型の抽出(design.md の ArrayItem<T>)*/
|
|
2951
|
+
type ArrayItem<T> = T extends readonly (infer U)[] ? U : never;
|
|
2952
|
+
/** each バインディングの戻り値型(design.md の EachBinding<U>)*/
|
|
2953
|
+
interface EachBinding<U> {
|
|
2954
|
+
readonly _kind: 'each';
|
|
2955
|
+
readonly _stateId: string;
|
|
2956
|
+
readonly _template: U;
|
|
2957
|
+
}
|
|
2958
|
+
/**
|
|
2959
|
+
* 読み取り専用の観測可能値インタフェース。
|
|
2960
|
+
* State<T> / Computed<T> 共通。
|
|
2961
|
+
*
|
|
2962
|
+
* design.md: ReadableState<T>
|
|
2963
|
+
*/
|
|
2964
|
+
interface ReadableState<T> {
|
|
2965
|
+
/** 構造的マーカー(Design D-7): transformer の TypeChecker が State 型を識別するために使用。
|
|
2966
|
+
* `declare const DraftoleStateMarker: unique symbol` なのでランタイムには存在しない。 */
|
|
2967
|
+
readonly [DraftoleStateMarker]: 'state';
|
|
2968
|
+
/**
|
|
2969
|
+
* build 時の状態 ID(handler-serialization から参照可、Req 6.3)
|
|
2970
|
+
* @deprecated Use state.js.get() / state.js.set() instead
|
|
2971
|
+
*/
|
|
2972
|
+
readonly _runtimeId: string;
|
|
2973
|
+
/** JS 文字列アクセサ(Req 1.1, 1.2, 1.5)*/
|
|
2974
|
+
readonly js: StateJsAccessor;
|
|
2975
|
+
/**
|
|
2976
|
+
* ハンドラ内で呼び出すと現在の状態値(T)を返す(state-handler-typing Req 1.1)。
|
|
2977
|
+
*
|
|
2978
|
+
* 注意: ハンドラ外(モジュールトップレベル等)で呼び出すと、
|
|
2979
|
+
* transformer の whitelist-validator により静的エラーになる。
|
|
2980
|
+
* ビルド時に JS コード片が必要な場合は `state.js.get()` を使う。
|
|
2981
|
+
*/
|
|
2982
|
+
get(): T;
|
|
2983
|
+
/** 派生値 Computed<U>(Req 3.1)*/
|
|
2984
|
+
map<U>(fn: (t: T) => U): Computed<U>;
|
|
2985
|
+
/** オブジェクトフィールドの読み取り専用派生(Computed として返す)*/
|
|
2986
|
+
field<K extends keyof T>(key: K): T extends object ? Computed<T[K]> : never;
|
|
2987
|
+
}
|
|
2988
|
+
/**
|
|
2989
|
+
* 読み書き可能な観測可能値インタフェース。
|
|
2990
|
+
*
|
|
2991
|
+
* design.md: State<T>
|
|
2992
|
+
*/
|
|
2993
|
+
interface State<T> extends ReadableState<T> {
|
|
2994
|
+
/** 書き込み: T の即値 または JsExpr(Req 2.2)*/
|
|
2995
|
+
set(value: T): void;
|
|
2996
|
+
set(value: JsExpr): void;
|
|
2997
|
+
/** 更新関数: 本仕様では JsExpr 形式のみ(Req 2.3, R-2)*/
|
|
2998
|
+
update(body: JsExpr): void;
|
|
2999
|
+
/** 書き戻し可能なフィールド派生(State として返す、R-1 決定)*/
|
|
3000
|
+
field<K extends keyof T>(key: K): T extends object ? State<T[K]> : never;
|
|
3001
|
+
/** 配列要素を State<Item> として受け取る要素ビルダテンプレート(Req 3.5)*/
|
|
3002
|
+
each<U extends HtmlTag | readonly HtmlTag[]>(fn: (item: State<ArrayItem<T>>) => U): EachBinding<U>;
|
|
3003
|
+
}
|
|
3004
|
+
/**
|
|
3005
|
+
* 読み取り専用の派生値インタフェース。
|
|
3006
|
+
*
|
|
3007
|
+
* design.md: Computed<T>
|
|
3008
|
+
* Req 3.2: set を持たない
|
|
3009
|
+
*/
|
|
3010
|
+
type Computed<T> = ReadableState<T>;
|
|
3011
|
+
|
|
3012
|
+
/**
|
|
3013
|
+
* `ScriptStateHandle<T>` の実装。
|
|
3014
|
+
*
|
|
3015
|
+
* 設計書 `design.md` の「ScriptScope.state / ScriptStateHandle<T>」に対応。
|
|
3016
|
+
* ScriptScope 内でハンドラが `s.state(ref).set(v)` / `.update(body)` / `.get()` / `.field(k)`
|
|
3017
|
+
* を呼び出すための軽量ファサード。
|
|
3018
|
+
*
|
|
3019
|
+
* - `.set(value)` → `state-set` コマンドを `VanillaScope._append` に積む
|
|
3020
|
+
* - `.update(body)` → `state-update` コマンドを `VanillaScope._append` に積む
|
|
3021
|
+
* - `.get()` → `State.get()` と等価な JsExpr を返す(_append しない)
|
|
3022
|
+
* - `.field(key)` → フィールドに対応する派生 ScriptStateHandle を返す
|
|
3023
|
+
*
|
|
3024
|
+
* R-4 決定: 実体は `{ ref: ReadableState<T>, scope: VanillaScope }` のみ。
|
|
3025
|
+
*
|
|
3026
|
+
* Requirements: 6.1, 6.2, 6.3
|
|
3027
|
+
*/
|
|
3028
|
+
|
|
3029
|
+
/**
|
|
3030
|
+
* ハンドラ内から状態を更新するための軽量ハンドルインタフェース。
|
|
3031
|
+
*
|
|
3032
|
+
* design.md: ScriptStateHandle<T>
|
|
3033
|
+
*/
|
|
3034
|
+
interface ScriptStateHandle<T> {
|
|
3035
|
+
/** 参照のみ(State.get と等価)。_append しない */
|
|
3036
|
+
get(): JsExpr;
|
|
3037
|
+
/** `state-set` コマンドを scope に _append する(Req 6.2)*/
|
|
3038
|
+
set(value: T | JsExpr): void;
|
|
3039
|
+
/** `state-update` コマンドを scope に _append する(Req 6.2)*/
|
|
3040
|
+
update(body: JsExpr): void;
|
|
3041
|
+
/** フィールドに対応する派生 ScriptStateHandle を返す(Req 6.1)*/
|
|
3042
|
+
field<K extends keyof T>(key: K): ScriptStateHandle<T[K]>;
|
|
3043
|
+
}
|
|
3044
|
+
|
|
3045
|
+
/**
|
|
3046
|
+
* `ScriptScope`: `root.script` および要素メソッド `on` ハンドラの `s` 引数として
|
|
3047
|
+
* 公開されるスクリプトスコープ API。
|
|
3048
|
+
*
|
|
3049
|
+
* 本ファイルは `unified-element-api` 仕様の Task 3.1 に対応する薄いアダプタであり、
|
|
3050
|
+
* 既存 `VanillaScriptBuilder` / `VanillaScope` の実装をパススルーで露出する。
|
|
3051
|
+
*
|
|
3052
|
+
* 対応 requirement: 3.1, 3.2, 3.3, 3.4, 3.5, 3.6
|
|
3053
|
+
* 対応 design.md セクション: 「ScriptScope」
|
|
3054
|
+
*
|
|
3055
|
+
* 方針:
|
|
3056
|
+
* - `ScriptScope` インターフェースは `VanillaScope` を拡張し、さらに
|
|
3057
|
+
* `VanillaScriptBuilder` のトップレベル API (`fn` / `onDomReady`) を表面化する。
|
|
3058
|
+
* - `.if` は内部 `VanillaScope.ifThen` へのエイリアスである(design の公開語彙に揃える)。
|
|
3059
|
+
* - 実装はクラスを作らず、既存オブジェクトに不足メソッドを合成する薄いラッパで与える。
|
|
3060
|
+
* - `VanillaCommand` / `VanillaScope` の既存コントラクトは一切変更しない。
|
|
3061
|
+
*/
|
|
3062
|
+
|
|
3063
|
+
/**
|
|
3064
|
+
* `root.script` 相当の API。`VanillaScope` の制御フロー API に、
|
|
3065
|
+
* トップレベル関数宣言 `fn` / DOMContentLoaded ブロック `onDomReady` と
|
|
3066
|
+
* `.if` エイリアスを加えたもの。
|
|
3067
|
+
*
|
|
3068
|
+
* design.md のサービスインターフェースが公開する語彙
|
|
3069
|
+
* (`fn` / `onDomReady` / `if` / `let` / `return` / `call` / `raw`)は
|
|
3070
|
+
* すべて本インターフェース上で型解決可能である。
|
|
3071
|
+
*/
|
|
3072
|
+
interface ScriptScope extends VanillaScope {
|
|
3073
|
+
/**
|
|
3074
|
+
* トップレベルに関数定義を追加する。
|
|
3075
|
+
* `VanillaScriptBuilder.fn` のパススルー。
|
|
3076
|
+
*/
|
|
3077
|
+
fn(name: string, body: (s: ScriptScope) => void): void;
|
|
3078
|
+
fn(name: string, params: readonly string[], body: (s: ScriptScope) => void): void;
|
|
3079
|
+
/**
|
|
3080
|
+
* `DOMContentLoaded` リスナー本体ブロックを登録する。
|
|
3081
|
+
* `VanillaScriptBuilder.onDomReady` のパススルー。
|
|
3082
|
+
*/
|
|
3083
|
+
onDomReady(body: (s: ScriptScope) => void): void;
|
|
3084
|
+
/**
|
|
3085
|
+
* `if (cond) { then } else? { orElse }` を現在スコープに発行する。
|
|
3086
|
+
* 内部実装は `VanillaScope.ifThen` と同一(design の公開語彙 `.if` に揃えたエイリアス)。
|
|
3087
|
+
*/
|
|
3088
|
+
if(condition: ScopeExpr, then: (s: ScriptScope) => void, orElse?: (s: ScriptScope) => void): void;
|
|
3089
|
+
/**
|
|
3090
|
+
* 状態参照から `ScriptStateHandle<T>` を取得する。
|
|
3091
|
+
* ハンドラ内で `s.state(ref).set(v)` / `.update(body)` の形で状態を更新する(Req 6.1)。
|
|
3092
|
+
*/
|
|
3093
|
+
state<T>(ref: ReadableState<T>): ScriptStateHandle<T>;
|
|
3094
|
+
/**
|
|
3095
|
+
* transformer が生成したシリアライズ済みハンドラ本体を `handler-body` コマンドとして発行する。
|
|
3096
|
+
*
|
|
3097
|
+
* transformer は `.on(event, arrowFn)` の第 2 引数を
|
|
3098
|
+
* `(s) => s._emitHandlerBody(serialized, params)` の形に書き換える。
|
|
3099
|
+
* `.on` 実装側の dispatcher がその関数を呼ぶとき `s` に本メソッドが存在する専用スコープが渡される。
|
|
3100
|
+
*
|
|
3101
|
+
* @param code - シリアライズ済みハンドラ本体の JS コード文字列
|
|
3102
|
+
* @param params - ハンドラ引数名の配列(例: `["e"]` または `[]`)
|
|
3103
|
+
*/
|
|
3104
|
+
_emitHandlerBody(code: string, params: readonly string[]): void;
|
|
3105
|
+
}
|
|
3106
|
+
|
|
3107
|
+
/**
|
|
3108
|
+
* `ElementMethods<Self>` 型と `ElementMixin` の実装。
|
|
3109
|
+
*
|
|
3110
|
+
* 本モジュールは `unified-element-api` 仕様の Task 3.3 に対応し、
|
|
3111
|
+
* `HtmlTag` サブクラスへの DOM 操作メソッドの mixin 差し込みを提供する。
|
|
3112
|
+
* Task 4.1 で reactive-state 仕様の状態受容オーバーロードを追加した。
|
|
3113
|
+
*
|
|
3114
|
+
* 設計方針:
|
|
3115
|
+
* - `ElementMethods<Self>` は `.on/.setText/.setValue/.setStyle/.addClass/.toggleClass
|
|
3116
|
+
* /.removeClass/.appendChild` を定義するジェネリックインターフェース。
|
|
3117
|
+
* - `applyElementMixin(proto)` は `HtmlTag` の prototype 上に各メソッドを直接差し込む
|
|
3118
|
+
* (module augmentation ではなく composition-root 側で呼び出す)。
|
|
3119
|
+
* - 各メソッドは `_scope === undefined` の間は `_pending` バッファに追加し、
|
|
3120
|
+
* `_scope` が設定済みの場合は即時 `_scope._append` を呼び出す(遅延解決モデル)。
|
|
3121
|
+
* - 文字列引数は `encodeLiteral`(= JSON.stringify)でリテラル化し、`JsExpr` は `.code` を素通し(Req 4.5)。
|
|
3122
|
+
* - `on` ハンドラは `ScriptScope` 型の子スコープを受け取り、本体を即時評価してから
|
|
3123
|
+
* 文字列化した `handlerCode` を `addEventListener` 命令に埋め込む。
|
|
3124
|
+
* - 状態受容経路: `ReadableState<T>` を受け取った場合は `binding-emitter` 経由で
|
|
3125
|
+
* `bind-*` コマンドを生成し、`appendCmd` で PendingBuffer に積む(Req 4.1–4.7)。
|
|
3126
|
+
*
|
|
3127
|
+
* 対応 requirement: 1.1, 1.2, 1.3, 1.4, 1.5, 4.1–4.7 (reactive-state)
|
|
3128
|
+
* 依存: Task 2.2 (PendingBuffer), Task 3.1 (ScriptScope), Task 3.2 (ExprFactory.encodeLiteral),
|
|
3129
|
+
* Task 3.3 (binding-emitter), Task 2.3 (each-template)
|
|
3130
|
+
*/
|
|
3131
|
+
|
|
3132
|
+
/** `on` ハンドラのコールバック型。ハンドラ内では ScriptScope の制御フロー API を利用できる。 */
|
|
3133
|
+
type HandlerCallback = (s: ScriptScope) => void;
|
|
3134
|
+
/**
|
|
3135
|
+
* アロー関数形式のイベントハンドラ型(handler-serialization Task 2.1)。
|
|
3136
|
+
*
|
|
3137
|
+
* イベント引数を受け取る形式(`(e: Ev) => void`)と
|
|
3138
|
+
* ゼロ引数形式(`() => void`)の両方を受け付ける。
|
|
3139
|
+
* `Ev` は `HTMLElementEventMap` のイベント型(例: `MouseEvent`, `InputEvent`)。
|
|
3140
|
+
*/
|
|
3141
|
+
type ArrowHandler<Ev extends Event = Event> = (() => void) | ((e: Ev) => void);
|
|
3142
|
+
/**
|
|
3143
|
+
* DOM 操作メソッド群を定義するジェネリックインターフェース。
|
|
3144
|
+
*
|
|
3145
|
+
* `Self` は戻り値型(メソッドチェーンのため)。HtmlTag サブクラスでは `Self = HtmlTag`、
|
|
3146
|
+
* `SelectorRef<E>` では `Self = SelectorRef<E>` を渡す。
|
|
3147
|
+
* 未定義メソッドはコンパイル時に型エラーとして検出可能(Req 1.4)。
|
|
3148
|
+
* 各メソッドは `Self`(= `this`)を返し、CSS チェーンと連結可能(Req 1.5)。
|
|
3149
|
+
*/
|
|
3150
|
+
interface ElementMethods<Self> {
|
|
3151
|
+
/**
|
|
3152
|
+
* 要素にイベントリスナを追加する JS 文を生成する(既存: HandlerCallback 形式)。
|
|
3153
|
+
*
|
|
3154
|
+
* @param event - `addEventListener` に渡すイベント名(例: `'click'`)
|
|
3155
|
+
* @param handler - ハンドラ本体を構築するコールバック。引数 `s` は `ScriptScope`
|
|
3156
|
+
*/
|
|
3157
|
+
on(event: string, handler: HandlerCallback): Self;
|
|
3158
|
+
/**
|
|
3159
|
+
* 要素にイベントリスナを追加する JS 文を生成する(ArrowHandler: keyof HTMLElementEventMap 形式)。
|
|
3160
|
+
*
|
|
3161
|
+
* イベント名 `K` が `HTMLElementEventMap` のキーのとき、ハンドラ引数 `e` が
|
|
3162
|
+
* `HTMLElementEventMap[K]`(例: `click` → `MouseEvent`)として推論される(Req 1.3)。
|
|
3163
|
+
*
|
|
3164
|
+
* @param event - `HTMLElementEventMap` のキー(例: `'click'`, `'input'`)
|
|
3165
|
+
* @param handler - アロー関数形式のハンドラ。`(e: MouseEvent) => void` または `() => void`
|
|
3166
|
+
*/
|
|
3167
|
+
on<K extends keyof HTMLElementEventMap>(event: K, handler: ArrowHandler<HTMLElementEventMap[K]>): Self;
|
|
3168
|
+
/**
|
|
3169
|
+
* 要素にイベントリスナを追加する JS 文を生成する(ArrowHandler: 任意イベント名フォールバック)。
|
|
3170
|
+
*
|
|
3171
|
+
* `HTMLElementEventMap` に存在しないカスタムイベント名向けのフォールバック。
|
|
3172
|
+
* ハンドラ引数型は `Event` になる。
|
|
3173
|
+
*
|
|
3174
|
+
* @param event - 任意のイベント名文字列
|
|
3175
|
+
* @param handler - アロー関数形式のハンドラ
|
|
3176
|
+
*/
|
|
3177
|
+
on(event: string, handler: ArrowHandler<Event>): Self;
|
|
3178
|
+
/**
|
|
3179
|
+
* `element.textContent = value` に対応する JS 文を生成する。
|
|
3180
|
+
* `ReadableState<string>` を渡すと bind-text コマンドを発行する(Req 4.1)。
|
|
3181
|
+
* 即値(string / JsExpr)の場合は setProp textContent を生成する(Req 4.6)。
|
|
3182
|
+
*/
|
|
3183
|
+
setText(value: string | JsExpr | ReadableState<string>): Self;
|
|
3184
|
+
/**
|
|
3185
|
+
* `setText` の便宜エイリアス(R-3 決定)。
|
|
3186
|
+
*/
|
|
3187
|
+
text(value: string | JsExpr | ReadableState<string>): Self;
|
|
3188
|
+
/**
|
|
3189
|
+
* `element.value = value` に対応する JS 文を生成する。
|
|
3190
|
+
* `ReadableState<string>` を渡すと bind-value コマンドを発行する(Req 4.2)。
|
|
3191
|
+
* 即値(string / JsExpr)の場合は setProp value を生成する(Req 4.6)。
|
|
3192
|
+
*/
|
|
3193
|
+
setValue(value: string | JsExpr | ReadableState<string>): Self;
|
|
3194
|
+
/**
|
|
3195
|
+
* `setValue` の便宜エイリアス(R-3 決定)。
|
|
3196
|
+
*/
|
|
3197
|
+
value(value: string | JsExpr | ReadableState<string>): Self;
|
|
3198
|
+
/**
|
|
3199
|
+
* `element.style[prop] = value` に対応する JS 文を生成する。
|
|
3200
|
+
* `ReadableState<string>` を渡すと bind-style コマンドを発行する(Req 4.4)。
|
|
3201
|
+
* 即値(string / JsExpr)の場合は setStyle コマンドを生成する(Req 4.6)。
|
|
3202
|
+
*/
|
|
3203
|
+
setStyle(prop: string, value: string | JsExpr | ReadableState<string>): Self;
|
|
3204
|
+
/**
|
|
3205
|
+
* `element.classList.add(name)` に対応する JS 文を生成する。
|
|
3206
|
+
* `ReadableState<string>` を渡すと bind-class-add コマンドを発行する(Req 4.3)。
|
|
3207
|
+
* 即値(string)の場合は classListAdd を生成する(Req 4.6)。
|
|
3208
|
+
*/
|
|
3209
|
+
addClass(name: string | ReadableState<string>): Self;
|
|
3210
|
+
/**
|
|
3211
|
+
* クラス名全体を状態値で置換する便宜エイリアス(Req 4.5, R-3 決定)。
|
|
3212
|
+
* `ReadableState<string>` は bind-class-all コマンドを発行する。
|
|
3213
|
+
*/
|
|
3214
|
+
class(name: string | JsExpr | ReadableState<string>): Self;
|
|
3215
|
+
/**
|
|
3216
|
+
* `input.checked` を状態値にバインドする(Req 4.x)。
|
|
3217
|
+
* `ReadableState<boolean>` を受け取り bind-attr(checked)コマンドを発行する。
|
|
3218
|
+
*/
|
|
3219
|
+
checked(value: ReadableState<boolean>): Self;
|
|
3220
|
+
/**
|
|
3221
|
+
* `element.classList.toggle(name, force?)` に対応する JS 文を生成する。
|
|
3222
|
+
*
|
|
3223
|
+
* @param name - トグル対象のクラス名
|
|
3224
|
+
* @param force - 省略時は無条件トグル。`JsBoolExpr` を渡すと force 引数として埋め込む
|
|
3225
|
+
*/
|
|
3226
|
+
toggleClass(name: string, force?: JsBoolExpr): Self;
|
|
3227
|
+
/**
|
|
3228
|
+
* `element.classList.remove(name)` に対応する JS 文を生成する。
|
|
3229
|
+
*
|
|
3230
|
+
* @param name - 削除するクラス名
|
|
3231
|
+
*/
|
|
3232
|
+
removeClass(name: string): Self;
|
|
3233
|
+
/**
|
|
3234
|
+
* `parent.appendChild(child)` に対応する JS 文を生成する。
|
|
3235
|
+
* `EachBinding<U>` を渡すと bind-each コマンドを発行する(Req 4.7)。
|
|
3236
|
+
* `HtmlTag` を渡すと通常の appendChild コマンドを生成する(Req 1.1)。
|
|
3237
|
+
*
|
|
3238
|
+
* @param child - 子として追加する `HtmlTag`(`id` 属性必須)または `EachBinding<U>`
|
|
3239
|
+
*/
|
|
3240
|
+
appendChild<U extends HtmlTag | readonly HtmlTag[]>(child: HtmlTag | EachBinding<U>): Self;
|
|
3241
|
+
}
|
|
3242
|
+
|
|
3243
|
+
/**
|
|
3244
|
+
* CSS共有スタイル定義
|
|
3245
|
+
*
|
|
3246
|
+
* createStyle() でクラスベースのCSSルールを定義し、
|
|
3247
|
+
* 複数要素に同じスタイルを適用する。
|
|
3248
|
+
* 疑似セレクタ(:hover, :focus, :active)もサポート。
|
|
3249
|
+
* SwiftUI の ViewModifier に相当。
|
|
3250
|
+
*
|
|
3251
|
+
* @example
|
|
3252
|
+
* ```typescript
|
|
3253
|
+
* import { Root } from '../html/elements/root.js';
|
|
3254
|
+
* const btn = createStyle('btn', {
|
|
3255
|
+
* padding: '10px 12px',
|
|
3256
|
+
* cursor: 'pointer',
|
|
3257
|
+
* }, {
|
|
3258
|
+
* hover: { background: 'rgba(255,255,255,0.10)' },
|
|
3259
|
+
* });
|
|
3260
|
+
*
|
|
3261
|
+
* const root = new Root({ css: [btn.css] });
|
|
3262
|
+
* // → .btn { padding: 10px 12px; cursor: pointer; }
|
|
3263
|
+
* // → .btn:hover { background: rgba(255,255,255,0.10); }
|
|
3264
|
+
* ```
|
|
3265
|
+
*/
|
|
3266
|
+
|
|
3267
|
+
/**
|
|
3268
|
+
* Style selector definitions.
|
|
3269
|
+
*
|
|
3270
|
+
* Key formats:
|
|
3271
|
+
* - `hover`, `focus`, etc. → pseudo selector (`.name:hover`)
|
|
3272
|
+
* - `&.modifier` → compound selector (`.name.modifier`)
|
|
3273
|
+
* - ` .child` → descendant selector (`.name .child`)
|
|
3274
|
+
* - `&.state .child` → compound + descendant (`.name.state .child`)
|
|
3275
|
+
*/
|
|
3276
|
+
type StyleSelectors = {
|
|
3277
|
+
[key: string]: Record<string, string>;
|
|
3278
|
+
};
|
|
3279
|
+
/**
|
|
3280
|
+
* Represents a shared CSS style that can be applied to multiple elements.
|
|
3281
|
+
*/
|
|
3282
|
+
interface SharedStyle {
|
|
3283
|
+
/** The CSS class name. */
|
|
3284
|
+
readonly className: string;
|
|
3285
|
+
/** The complete CSS rule block(s) including pseudo-selectors. */
|
|
3286
|
+
readonly css: string;
|
|
3287
|
+
/**
|
|
3288
|
+
* Internal `StyleTemplate` representation.
|
|
3289
|
+
*
|
|
3290
|
+
* Maintained for the new colocated-style pipeline (Req 2.1, 2.2, 2.4, 2.5).
|
|
3291
|
+
* 既存の `className` / `css` / `toString()` 経路は従来どおり機能するため、
|
|
3292
|
+
* 旧 API 利用者は `_template` を意識する必要はない。
|
|
3293
|
+
*
|
|
3294
|
+
* @internal
|
|
3295
|
+
*/
|
|
3296
|
+
readonly _template: StyleTemplate;
|
|
3297
|
+
/** Returns the class name (for template literal usage). */
|
|
3298
|
+
toString(): string;
|
|
3299
|
+
}
|
|
3300
|
+
|
|
3301
|
+
/**
|
|
3302
|
+
* StyleTemplate オブジェクト。
|
|
3303
|
+
*
|
|
3304
|
+
* 名前あり/なしの両 `createStyle` 戻り値を統一する中間表現。
|
|
3305
|
+
* 生成後は freeze され、外部からの変更は受け付けない。
|
|
3306
|
+
*
|
|
3307
|
+
* - `hasExplicitName === true` ⇔ `name !== undefined`
|
|
3308
|
+
* - `bodyHash` は `(properties, selectors)` の決定的ハッシュ
|
|
3309
|
+
*/
|
|
3310
|
+
interface StyleTemplate {
|
|
3311
|
+
readonly _kind: 'styleTemplate';
|
|
3312
|
+
readonly hasExplicitName: boolean;
|
|
3313
|
+
readonly name?: string;
|
|
3314
|
+
readonly properties: Readonly<Record<string, string>>;
|
|
3315
|
+
readonly selectors?: Readonly<StyleSelectors>;
|
|
3316
|
+
readonly bodyHash: string;
|
|
3317
|
+
readonly debugVarName?: string;
|
|
3318
|
+
}
|
|
3319
|
+
|
|
3320
|
+
/**
|
|
3321
|
+
* HtmlTag 抽象基底クラス
|
|
3322
|
+
*
|
|
3323
|
+
* 全タグ共通のレンダリングロジックと属性管理を集約する。
|
|
3324
|
+
* HTMLTagProtocol を実装し、サブクラス(Root, PairType, SelfClosingType, TextType)の
|
|
3325
|
+
* 共通動作を提供する。
|
|
3326
|
+
*
|
|
3327
|
+
* レンダリングフロー:
|
|
3328
|
+
* render() → protoRender() → HTMLFormatter.format()
|
|
3329
|
+
*
|
|
3330
|
+
* Task 0.2: CssManagerInstance をコンポジションで保持。
|
|
3331
|
+
* collectCssStyleString() は this._css.render() に委譲する。
|
|
3332
|
+
*
|
|
3333
|
+
* Requirements: 6.1, 6.2, 6.7
|
|
3334
|
+
*/
|
|
3335
|
+
|
|
3336
|
+
/**
|
|
3337
|
+
* HtmlTag コンストラクタのオプション引数。
|
|
3338
|
+
* テスト時に CssManager / JQueryManager をモック注入するために使用。
|
|
3339
|
+
*/
|
|
3340
|
+
interface HtmlTagOptions {
|
|
3341
|
+
css?: CssManagerInstance;
|
|
3342
|
+
jqm?: JQueryManagerInstance;
|
|
3343
|
+
}
|
|
3344
|
+
/**
|
|
3345
|
+
* `.frame()` 修飾子のオプション型。
|
|
3346
|
+
*
|
|
3347
|
+
* 各プロパティは省略可能。省略されたプロパティは既存の設定値を変更しない。
|
|
3348
|
+
*
|
|
3349
|
+
* 変換ルール:
|
|
3350
|
+
* - `number` → `{n}px`
|
|
3351
|
+
* - `Infinity` (maxWidth / maxHeight のみ) → `'100%'`
|
|
3352
|
+
* - `string` → そのまま CSS 値として使用
|
|
3353
|
+
*
|
|
3354
|
+
* Requirements: 6.1, 6.2, 6.3, 6.4, 6.5, 6.6
|
|
3355
|
+
*/
|
|
3356
|
+
interface FrameOptions {
|
|
3357
|
+
width?: number | string;
|
|
3358
|
+
height?: number | string;
|
|
3359
|
+
minWidth?: number | string;
|
|
3360
|
+
maxWidth?: number | string;
|
|
3361
|
+
minHeight?: number | string;
|
|
3362
|
+
maxHeight?: number | string;
|
|
3363
|
+
}
|
|
3364
|
+
/**
|
|
3365
|
+
* Abstract base class for all HTML elements.
|
|
3366
|
+
*
|
|
3367
|
+
* This class provides the common rendering logic and attribute/child management
|
|
3368
|
+
* for all HTML tag types. It implements {@link HTMLTagProtocol}, {@link CssManagerType},
|
|
3369
|
+
* and {@link JQueryManagerProtocol}.
|
|
3370
|
+
*
|
|
3371
|
+
* **Rendering Flow:**
|
|
3372
|
+
* - `render()` → `protoRender()` → `HTMLFormatter.format()`
|
|
3373
|
+
*
|
|
3374
|
+
* **Composition Pattern:**
|
|
3375
|
+
* - CSS management is delegated to {@link CssManagerInstance}
|
|
3376
|
+
* - JavaScript/jQuery management is delegated to {@link JQueryManagerInstance}
|
|
3377
|
+
*
|
|
3378
|
+
* **Subclasses:**
|
|
3379
|
+
* - {@link Root} - Document root element
|
|
3380
|
+
* - {@link PairType} - Elements with opening and closing tags (e.g., `<div>...</div>`)
|
|
3381
|
+
* - {@link SelfClosingType} - Self-closing elements (e.g., `<br>`)
|
|
3382
|
+
* - {@link TextType} - Text nodes
|
|
3383
|
+
*
|
|
3384
|
+
* @example
|
|
3385
|
+
* ```typescript
|
|
3386
|
+
* // Typically used through factory functions, not instantiated directly
|
|
3387
|
+
* const element = div(
|
|
3388
|
+
* p('Hello'),
|
|
3389
|
+
* span('World')
|
|
3390
|
+
* );
|
|
3391
|
+
* console.log(element.render());
|
|
3392
|
+
* ```
|
|
3393
|
+
*
|
|
3394
|
+
* @remarks
|
|
3395
|
+
* **Preconditions:** tagType must be a valid {@link TagType} value
|
|
3396
|
+
*
|
|
3397
|
+
* **Postconditions:** `render()`/`protoRender()` return valid HTML strings
|
|
3398
|
+
*
|
|
3399
|
+
* **Invariants:** Children order is preserved in insertion order
|
|
3400
|
+
*/
|
|
3401
|
+
declare abstract class HtmlTag implements HTMLTagProtocol, CssManagerType, JQueryManagerProtocol {
|
|
3402
|
+
/**
|
|
3403
|
+
* The HTML tag type (e.g., 'div', 'p', 'span').
|
|
3404
|
+
*/
|
|
3405
|
+
readonly tagType: TagType;
|
|
3406
|
+
/**
|
|
3407
|
+
* Child elements managed by this tag.
|
|
3408
|
+
* @internal
|
|
3409
|
+
*/
|
|
3410
|
+
protected _children: HTMLTagProtocol[];
|
|
3411
|
+
/**
|
|
3412
|
+
* HTML attributes managed by this tag.
|
|
3413
|
+
* @internal
|
|
3414
|
+
*/
|
|
3415
|
+
protected _attributes: HtmlAttributeShape[];
|
|
3416
|
+
/**
|
|
3417
|
+
* CSS manager instance (composition pattern).
|
|
3418
|
+
* @internal
|
|
3419
|
+
*/
|
|
3420
|
+
private _css;
|
|
3421
|
+
/**
|
|
3422
|
+
* jQuery manager instance (composition pattern).
|
|
3423
|
+
* @internal
|
|
3424
|
+
*/
|
|
3425
|
+
private _jqm;
|
|
3426
|
+
/**
|
|
3427
|
+
* 遅延解決モデル用の未フラッシュ DOM 操作コマンドバッファ。
|
|
3428
|
+
*
|
|
3429
|
+
* `Root.addChild(this)` 以前に要素ビルダメソッド(`on` / `setText` 等)から
|
|
3430
|
+
* 積まれた {@link VanillaCommand} を保持する。`FlushOrchestrator.flush()` が
|
|
3431
|
+
* 呼ばれた時点で `_scope._append` に転送し、本配列は空になる。
|
|
3432
|
+
*
|
|
3433
|
+
* Requirements: 1.6, 1.7, 1.8 (unified-element-api)
|
|
3434
|
+
* Design: 遅延解決モデル / PendingBuffer
|
|
3435
|
+
*
|
|
3436
|
+
* @internal
|
|
3437
|
+
*/
|
|
3438
|
+
_pending: VanillaCommand[];
|
|
3439
|
+
/**
|
|
3440
|
+
* each-modifier-css-extraction: bind-each コマンドの永続スナップショット。
|
|
3441
|
+
*
|
|
3442
|
+
* `_pending` 内 bind-each は protoRender 後に `_scope` へ転送されて `_pending`
|
|
3443
|
+
* から消えるため、CSS 収集 phase(`collectCssStyleString`)に到達した時点では
|
|
3444
|
+
* 参照不能になる。本配列は bind-each コマンドの参照を append-only で保持し、
|
|
3445
|
+
* 後段の CSS 収集が templateRoot を辿れるようにする。
|
|
3446
|
+
*
|
|
3447
|
+
* @internal
|
|
3448
|
+
*/
|
|
3449
|
+
_eachTemplateSnapshots: VanillaCommand[];
|
|
3450
|
+
/**
|
|
3451
|
+
* element-methods.ts の `appendChild` で追加された子 `HtmlTag` 群。
|
|
3452
|
+
*
|
|
3453
|
+
* `addChild` を経由しない `.appendChild(child)` 呼び出しは `_children` に
|
|
3454
|
+
* 追加されないが、each テンプレート factory コード生成時には子要素ツリーが
|
|
3455
|
+
* 必要になる。本配列はその目的(factory コード生成)専用の追跡バッファ。
|
|
3456
|
+
*
|
|
3457
|
+
* @internal
|
|
3458
|
+
*/
|
|
3459
|
+
_appendedChildren: HtmlTag[];
|
|
3460
|
+
/**
|
|
3461
|
+
* `css` 属性経由で受理した {@link StyleTemplate} 群の未フラッシュバッファ。
|
|
3462
|
+
*
|
|
3463
|
+
* `applyAttributeMap` 経路(あるいは `addStyleTemplates`)で push 順に保持され、
|
|
3464
|
+
* **この時点では `CssManager` には流さない**。tagPath が確定する render 時
|
|
3465
|
+
* (Task 3.4)に初めて `_css.registerTemplate(tpl, ...)` へ転送される。
|
|
3466
|
+
*
|
|
3467
|
+
* Requirements: 1.1, 1.4
|
|
3468
|
+
* Design: 遅延解決モデル / `_pendingStyleTemplates`
|
|
3469
|
+
*
|
|
3470
|
+
* @internal
|
|
3471
|
+
*/
|
|
3472
|
+
_pendingStyleTemplates: StyleTemplate[];
|
|
3473
|
+
/**
|
|
3474
|
+
* フラッシュ済み要素が保持する {@link VanillaScope} 参照。
|
|
3475
|
+
*
|
|
3476
|
+
* `undefined` の間は未登録(バッファ経路)、`VanillaScope` 値が入った後は
|
|
3477
|
+
* 以降の要素ビルダメソッド呼び出しが即時 `_append` される。
|
|
3478
|
+
*
|
|
3479
|
+
* Requirements: 1.6, 1.7 (unified-element-api)
|
|
3480
|
+
* Design: 遅延解決モデル / FlushOrchestrator
|
|
3481
|
+
*
|
|
3482
|
+
* @internal
|
|
3483
|
+
*/
|
|
3484
|
+
_scope: VanillaScope | undefined;
|
|
3485
|
+
/**
|
|
3486
|
+
* Creates a new HtmlTag instance.
|
|
3487
|
+
*
|
|
3488
|
+
* @param tagType - The HTML tag type
|
|
3489
|
+
* @param options - Optional DI options for injecting CssManager/JQueryManager (mainly for testing)
|
|
3490
|
+
*/
|
|
3491
|
+
constructor(tagType: TagType, options?: HtmlTagOptions);
|
|
3492
|
+
/**
|
|
3493
|
+
* Gets the CSS manager for this element.
|
|
3494
|
+
*
|
|
3495
|
+
* @returns The {@link CssManagerInstance} for managing CSS styles
|
|
3496
|
+
*
|
|
3497
|
+
* @example
|
|
3498
|
+
* ```typescript
|
|
3499
|
+
* const element = div();
|
|
3500
|
+
* element.css.addRule('.my-class', { color: 'red' });
|
|
3501
|
+
* ```
|
|
3502
|
+
*/
|
|
3503
|
+
get css(): CssManagerInstance;
|
|
3504
|
+
/**
|
|
3505
|
+
* Shortcut to HtmlStyle (3-level chain: element.style.font.setFontSize()).
|
|
3506
|
+
* Equivalent to element.css.styleManager.style.
|
|
3507
|
+
*/
|
|
3508
|
+
get style(): HtmlStyle;
|
|
3509
|
+
padding(v: string): this;
|
|
3510
|
+
padding(v: number): this;
|
|
3511
|
+
padding(edge: EdgeSet, v: number): this;
|
|
3512
|
+
paddingTop(v: string): this;
|
|
3513
|
+
paddingRight(v: string): this;
|
|
3514
|
+
paddingBottom(v: string): this;
|
|
3515
|
+
paddingLeft(v: string): this;
|
|
3516
|
+
margin(v: string): this;
|
|
3517
|
+
marginTop(v: string): this;
|
|
3518
|
+
marginRight(v: string): this;
|
|
3519
|
+
marginBottom(v: string): this;
|
|
3520
|
+
marginLeft(v: string): this;
|
|
3521
|
+
background(v: string | BackgroundOptions): this;
|
|
3522
|
+
backgroundColor(v: string): this;
|
|
3523
|
+
color(v: string): this;
|
|
3524
|
+
foregroundStyle(v: string): this;
|
|
3525
|
+
fontSize(v: string): this;
|
|
3526
|
+
fontWeight(v: string): this;
|
|
3527
|
+
fontFamily(v: string): this;
|
|
3528
|
+
lineHeight(v: string): this;
|
|
3529
|
+
cornerRadius(v: string): this;
|
|
3530
|
+
display(v: string): this;
|
|
3531
|
+
width(v: string): this;
|
|
3532
|
+
height(v: string): this;
|
|
3533
|
+
minWidth(v: string): this;
|
|
3534
|
+
minHeight(v: string): this;
|
|
3535
|
+
maxWidth(v: string): this;
|
|
3536
|
+
maxHeight(v: string): this;
|
|
3537
|
+
textAlign(v: string): this;
|
|
3538
|
+
textDecoration(v: string): this;
|
|
3539
|
+
overflow(v: string): this;
|
|
3540
|
+
opacity(v: string): this;
|
|
3541
|
+
boxShadow(v: string): this;
|
|
3542
|
+
gap(v: string): this;
|
|
3543
|
+
flexGrow(v: string): this;
|
|
3544
|
+
flex(v: string): this;
|
|
3545
|
+
flex(options?: FlexOptions): this;
|
|
3546
|
+
grid(options?: GridOptions): this;
|
|
3547
|
+
font(options?: FontOptions): this;
|
|
3548
|
+
border(options?: BorderOptions): this;
|
|
3549
|
+
hover(configure: (s: PseudoStyleBuilder) => void): this;
|
|
3550
|
+
focus(configure: (s: PseudoStyleBuilder) => void): this;
|
|
3551
|
+
active(configure: (s: PseudoStyleBuilder) => void): this;
|
|
3552
|
+
/**
|
|
3553
|
+
* ブレークポイントごとのスタイルをメディアクエリとして登録する。
|
|
3554
|
+
*
|
|
3555
|
+
* - 名前付きキー('sm' / 'md' / 'lg' / 'xl')は `Breakpoints` 定数で数値に解決する
|
|
3556
|
+
* - 数値キーはそのままブレークポイント(px 値)として使用する
|
|
3557
|
+
* - 各ブレークポイントの CSS プロパティを `this._css.addMediaRule(bp, props)` に渡す
|
|
3558
|
+
* - `renderCss()` 出力の末尾に `@media (min-width: {bp}px) { .{scopedClass} { ... } }` ブロックが追加される
|
|
3559
|
+
*
|
|
3560
|
+
* @example
|
|
3561
|
+
* ```typescript
|
|
3562
|
+
* div()
|
|
3563
|
+
* .responsive({ md: { padding: '16px' }, xl: { fontSize: '18px' } })
|
|
3564
|
+
* ```
|
|
3565
|
+
*
|
|
3566
|
+
* Requirements: 9.1, 9.2, 9.3, 9.4, 9.5
|
|
3567
|
+
*/
|
|
3568
|
+
responsive(options: BreakpointStyles): this;
|
|
3569
|
+
/**
|
|
3570
|
+
* 条件付き修飾子。`condition` が `true` のとき `modifier(this)` を呼び出し、
|
|
3571
|
+
* `false` のときは modifier を呼び出さず `this` をそのまま返す。
|
|
3572
|
+
*
|
|
3573
|
+
* modifier が `null` / `undefined` を返した場合は元の要素(`this`)を返す。
|
|
3574
|
+
*
|
|
3575
|
+
* @example
|
|
3576
|
+
* ```typescript
|
|
3577
|
+
* div()
|
|
3578
|
+
* .if(isActive, el => el.background('#f00'))
|
|
3579
|
+
* .padding('16px')
|
|
3580
|
+
* ```
|
|
3581
|
+
*
|
|
3582
|
+
* Requirements: 10.1, 10.2, 10.3, 10.4, 10.5
|
|
3583
|
+
*/
|
|
3584
|
+
if<T extends HtmlTag>(this: T, condition: boolean, modifier: (el: T) => T | null | undefined): T;
|
|
3585
|
+
/**
|
|
3586
|
+
* 幅・高さ・最小/最大サイズを1つのメソッド呼び出しで設定する。
|
|
3587
|
+
*
|
|
3588
|
+
* - `number` → `{n}px` に変換する
|
|
3589
|
+
* - `Infinity` → `'100%'` に変換する(maxWidth / maxHeight のみ)
|
|
3590
|
+
* - `string` → そのまま CSS 値として使用する
|
|
3591
|
+
* - 省略されたプロパティは既存の設定値を変更しない
|
|
3592
|
+
*
|
|
3593
|
+
* Requirements: 6.1, 6.2, 6.3, 6.4, 6.5, 6.6
|
|
3594
|
+
*
|
|
3595
|
+
* @param options - 設定するフレームオプション
|
|
3596
|
+
* @returns This instance for method chaining
|
|
3597
|
+
*
|
|
3598
|
+
* @example
|
|
3599
|
+
* ```typescript
|
|
3600
|
+
* div().frame({ width: 700, maxWidth: Infinity })
|
|
3601
|
+
* // → width:700px; max-width:100%
|
|
3602
|
+
* ```
|
|
3603
|
+
*/
|
|
3604
|
+
frame(options: FrameOptions): this;
|
|
3605
|
+
/**
|
|
3606
|
+
* Gets the jQuery manager for this element.
|
|
3607
|
+
*
|
|
3608
|
+
* @returns The {@link JQueryManagerInstance} for managing JavaScript/jQuery operations
|
|
3609
|
+
*
|
|
3610
|
+
* @example
|
|
3611
|
+
* ```typescript
|
|
3612
|
+
* const element = div();
|
|
3613
|
+
* element.jqm.on('click', () => console.log('Clicked!'));
|
|
3614
|
+
* ```
|
|
3615
|
+
*/
|
|
3616
|
+
get jqm(): JQueryManagerInstance;
|
|
3617
|
+
/**
|
|
3618
|
+
* Gets the child elements of this tag.
|
|
3619
|
+
*
|
|
3620
|
+
* @returns Read-only array of child elements
|
|
3621
|
+
*/
|
|
3622
|
+
get children(): ReadonlyArray<HTMLTagProtocol>;
|
|
3623
|
+
/**
|
|
3624
|
+
* Adds a child element to this tag.
|
|
3625
|
+
*
|
|
3626
|
+
* @param child - The child element to add
|
|
3627
|
+
* @returns This instance for method chaining
|
|
3628
|
+
*
|
|
3629
|
+
* @example
|
|
3630
|
+
* ```typescript
|
|
3631
|
+
* const container = div();
|
|
3632
|
+
* container.addChild(p('Hello'));
|
|
3633
|
+
* container.addChild(span('World'));
|
|
3634
|
+
* ```
|
|
3635
|
+
*/
|
|
3636
|
+
addChild(child: HTMLTagProtocol): this;
|
|
3637
|
+
/** @internal */
|
|
3638
|
+
_propagateTagPaths(): void;
|
|
3639
|
+
/**
|
|
3640
|
+
* Adds multiple child elements to this tag.
|
|
3641
|
+
*
|
|
3642
|
+
* @param children - Array of child elements to add
|
|
3643
|
+
* @returns This instance for method chaining
|
|
3644
|
+
*
|
|
3645
|
+
* @example
|
|
3646
|
+
* ```typescript
|
|
3647
|
+
* const container = div();
|
|
3648
|
+
* container.addChildren([
|
|
3649
|
+
* p('First paragraph'),
|
|
3650
|
+
* p('Second paragraph')
|
|
3651
|
+
* ]);
|
|
3652
|
+
* ```
|
|
3653
|
+
*/
|
|
3654
|
+
addChildren(children: ReadonlyArray<HTMLTagProtocol>): this;
|
|
3655
|
+
/**
|
|
3656
|
+
* Gets the HTML attributes of this tag.
|
|
3657
|
+
*
|
|
3658
|
+
* @returns Read-only array of HTML attributes
|
|
3659
|
+
*/
|
|
3660
|
+
get attributes(): ReadonlyArray<HtmlAttributeShape>;
|
|
3661
|
+
/**
|
|
3662
|
+
* Adds an HTML attribute to this tag.
|
|
3663
|
+
*
|
|
3664
|
+
* @param attribute - The attribute to add
|
|
3665
|
+
* @returns This instance for method chaining
|
|
3666
|
+
*
|
|
3667
|
+
* @example
|
|
3668
|
+
* ```typescript
|
|
3669
|
+
* const element = div();
|
|
3670
|
+
* element.addHtmlAttribute(HtmlAttribute.className('container'));
|
|
3671
|
+
* element.addHtmlAttribute(HtmlAttribute.keyValue('id', 'main'));
|
|
3672
|
+
* ```
|
|
3673
|
+
*/
|
|
3674
|
+
addHtmlAttribute(attribute: HtmlAttributeShape): this;
|
|
3675
|
+
/**
|
|
3676
|
+
* `css` 属性由来の {@link StyleTemplate} 群を `_pendingStyleTemplates` に
|
|
3677
|
+
* push 順を保持して追加する。
|
|
3678
|
+
*
|
|
3679
|
+
* **重要**:本メソッドは保持のみを行い、`CssManager` への登録は行わない。
|
|
3680
|
+
* tagPath が確定する render フェーズ(Task 3.4)で `_css.registerTemplate`
|
|
3681
|
+
* へ転送される。
|
|
3682
|
+
*
|
|
3683
|
+
* Requirements: 1.1, 1.4
|
|
3684
|
+
*
|
|
3685
|
+
* @param tpls - 追加する StyleTemplate の配列(順序保持)
|
|
3686
|
+
* @returns This instance for method chaining
|
|
3687
|
+
*/
|
|
3688
|
+
addStyleTemplates(tpls: StyleTemplate[]): this;
|
|
3689
|
+
/**
|
|
3690
|
+
* Renders all attributes as an HTML string.
|
|
3691
|
+
*
|
|
3692
|
+
* @returns A space-prefixed string of attributes, or empty string if no attributes
|
|
3693
|
+
*
|
|
3694
|
+
* @example
|
|
3695
|
+
* ```typescript
|
|
3696
|
+
* // Returns: ' class="btn" id="submit"'
|
|
3697
|
+
* const element = div({ class: 'btn', id: 'submit' });
|
|
3698
|
+
* console.log(element.renderAttributes());
|
|
3699
|
+
* ```
|
|
3700
|
+
*/
|
|
3701
|
+
renderAttributes(): string;
|
|
3702
|
+
/**
|
|
3703
|
+
* Renders the element as a minified HTML string (without formatting).
|
|
3704
|
+
*
|
|
3705
|
+
* This method generates the raw HTML output based on the tag type:
|
|
3706
|
+
* - **root**: Concatenates child elements (no tag wrapper)
|
|
3707
|
+
* - **text**: Returns content as-is (overridden in {@link TextType})
|
|
3708
|
+
* - **selfClosing**: Returns `<tag attrs>` format
|
|
3709
|
+
* - **pair**: Returns `<tag attrs>children</tag>` format
|
|
3710
|
+
*
|
|
3711
|
+
* @returns Minified HTML string
|
|
3712
|
+
*
|
|
3713
|
+
* @remarks
|
|
3714
|
+
* This method is typically called internally by {@link render}.
|
|
3715
|
+
* Use {@link render} for formatted output.
|
|
3716
|
+
*/
|
|
3717
|
+
protoRender(ctx?: RenderContext): string;
|
|
3718
|
+
/**
|
|
3719
|
+
* Renders the element as a formatted HTML string.
|
|
3720
|
+
*
|
|
3721
|
+
* This method applies HTML formatting (indentation, line breaks) to the
|
|
3722
|
+
* minified output from {@link protoRender}.
|
|
3723
|
+
*
|
|
3724
|
+
* @returns Formatted HTML string
|
|
3725
|
+
*
|
|
3726
|
+
* @example
|
|
3727
|
+
* ```typescript
|
|
3728
|
+
* const element = div(
|
|
3729
|
+
* p('Hello'),
|
|
3730
|
+
* p('World')
|
|
3731
|
+
* );
|
|
3732
|
+
* console.log(element.render());
|
|
3733
|
+
* // Output:
|
|
3734
|
+
* // <div>
|
|
3735
|
+
* // <p>Hello</p>
|
|
3736
|
+
* // <p>World</p>
|
|
3737
|
+
* // </div>
|
|
3738
|
+
* ```
|
|
3739
|
+
*/
|
|
3740
|
+
render(): string;
|
|
3741
|
+
/**
|
|
3742
|
+
* Recursively collects CSS style strings from this element and its descendants.
|
|
3743
|
+
*
|
|
3744
|
+
* 実装は `_internal/css-collector.ts` の {@link collectCss} 純関数に委譲する。
|
|
3745
|
+
*
|
|
3746
|
+
* @param resolver - optional minify-aware identifier resolver
|
|
3747
|
+
* @returns Concatenated CSS string from this element and all descendants
|
|
3748
|
+
*/
|
|
3749
|
+
collectCssStyleString(resolver?: IdentifierResolver): string;
|
|
3750
|
+
/**
|
|
3751
|
+
* Recursively collects JavaScript content from this element and its descendants.
|
|
3752
|
+
*
|
|
3753
|
+
* 実装は `_internal/js-collector.ts` の {@link collectJs} 純関数に委譲する。
|
|
3754
|
+
*
|
|
3755
|
+
* @returns Concatenated JavaScript string (separated by `;\n`)
|
|
3756
|
+
*
|
|
3757
|
+
* @example
|
|
3758
|
+
* ```typescript
|
|
3759
|
+
* const element = div();
|
|
3760
|
+
* element.jqm.on('click', () => console.log('Clicked'));
|
|
3761
|
+
* const js = element.collectJsContent();
|
|
3762
|
+
* ```
|
|
3763
|
+
*/
|
|
3764
|
+
collectJsContent(): string;
|
|
3765
|
+
/**
|
|
3766
|
+
* Recursively collects jQuery method types used by this element and its descendants.
|
|
3767
|
+
*
|
|
3768
|
+
* This is used for tree-shaking to include only the necessary jQuery helper functions.
|
|
3769
|
+
*
|
|
3770
|
+
* 実装は `_internal/used-methods-collector.ts` の {@link collectUsedMethodsHelper}
|
|
3771
|
+
* (helper export 名 `collectUsedMethods` を本メソッドとの衝突回避のため alias 化)
|
|
3772
|
+
* 純関数に委譲する。
|
|
3773
|
+
*
|
|
3774
|
+
* @returns Set of {@link JQueryMethodType} used in the element tree
|
|
3775
|
+
*
|
|
3776
|
+
* @example
|
|
3777
|
+
* ```typescript
|
|
3778
|
+
* const element = div();
|
|
3779
|
+
* element.jqm.on('click', handler);
|
|
3780
|
+
* const methods = element.collectUsedMethods();
|
|
3781
|
+
* // methods includes: Set(['on'])
|
|
3782
|
+
* ```
|
|
3783
|
+
*/
|
|
3784
|
+
collectUsedMethods(): Set<JQueryMethodType>;
|
|
3785
|
+
}
|
|
3786
|
+
interface HtmlTag extends ElementMethods<HtmlTag> {
|
|
3787
|
+
}
|
|
3788
|
+
|
|
3789
|
+
/**
|
|
3790
|
+
* GlobalCss branded type と内部ヘルパ
|
|
3791
|
+
*
|
|
3792
|
+
* `GlobalCss` は string の subtype として branded nominal 型を提供する。
|
|
3793
|
+
* 外部コードが生 string を `GlobalCss` として渡すことをコンパイル時に阻止する。
|
|
3794
|
+
*
|
|
3795
|
+
* 内部 `brand()` がこのモジュールにおける唯一のキャスト発生点。
|
|
3796
|
+
* DSL 関数群(global-dsl.ts)はこのモジュールの内部 API を通じてのみ GlobalCss を生成する。
|
|
3797
|
+
*/
|
|
3798
|
+
/**
|
|
3799
|
+
* GlobalCss branded type。
|
|
3800
|
+
* `string & { readonly __globalCss: unique symbol }` により、
|
|
3801
|
+
* 生 string との代入非互換性を型システムで保証する。
|
|
3802
|
+
*
|
|
3803
|
+
* @example
|
|
3804
|
+
* ```typescript
|
|
3805
|
+
* // コンパイルエラー(生 string は渡せない)
|
|
3806
|
+
* const css: GlobalCss = "body { color: red; }"; // Error!
|
|
3807
|
+
*
|
|
3808
|
+
* // 正しい使い方(DSL 経由)
|
|
3809
|
+
* import { rule } from './global-dsl.js';
|
|
3810
|
+
* const css: GlobalCss = rule("body", { color: "red" });
|
|
3811
|
+
* ```
|
|
3812
|
+
*/
|
|
3813
|
+
type GlobalCss = string & {
|
|
3814
|
+
readonly __globalCss: unique symbol;
|
|
3815
|
+
};
|
|
3816
|
+
|
|
3817
|
+
/**
|
|
3818
|
+
* Publisher が Root から受け取る read-only export snapshot。
|
|
3819
|
+
* FileExporter はこの型からすべての必要情報を取得し、Root._stateRegistry などの
|
|
3820
|
+
* 内部状態へ直接アクセスしない。
|
|
3821
|
+
*/
|
|
3822
|
+
interface ExportContext {
|
|
3823
|
+
/** レンダリング済み HTML 文字列 */
|
|
3824
|
+
readonly html: string;
|
|
3825
|
+
/** 収集済み CSS 文字列(グローバル + スコープド) */
|
|
3826
|
+
readonly css: string;
|
|
3827
|
+
/** ユーザー定義 Vanilla JS(VanillaScriptBuilder 出力) */
|
|
3828
|
+
readonly userJs: string;
|
|
3829
|
+
/** ランタイムプレリュード(状態あり時のみ存在) */
|
|
3830
|
+
readonly runtimePrelude?: string;
|
|
3831
|
+
/** 状態初期化 JS(state-init + derive コマンド列) */
|
|
3832
|
+
readonly runtimeInitJs?: string;
|
|
3833
|
+
}
|
|
3834
|
+
|
|
3835
|
+
/**
|
|
3836
|
+
* FileExporterのオプション
|
|
3837
|
+
*
|
|
3838
|
+
* {@link FileExporter}の動作をカスタマイズするためのオプション定義です。
|
|
3839
|
+
*
|
|
3840
|
+
* @remarks
|
|
3841
|
+
* 全てのプロパティはオプションで、デフォルト値が設定されています。
|
|
3842
|
+
*
|
|
3843
|
+
* @example カスタムファイル名
|
|
3844
|
+
* ```typescript
|
|
3845
|
+
* const options: FileExporterOptions = {
|
|
3846
|
+
* htmlFileName: 'page.html',
|
|
3847
|
+
* cssFileName: 'main.css',
|
|
3848
|
+
* jsFileName: 'app.js',
|
|
3849
|
+
* };
|
|
3850
|
+
* ```
|
|
3851
|
+
*
|
|
3852
|
+
* @example reset.cssを含める
|
|
3853
|
+
* ```typescript
|
|
3854
|
+
* const options: FileExporterOptions = {
|
|
3855
|
+
* includeResetCss: true, // Eric Meyer's Reset CSSを自動挿入
|
|
3856
|
+
* };
|
|
3857
|
+
* ```
|
|
3858
|
+
*
|
|
3859
|
+
* @public
|
|
3860
|
+
*/
|
|
3861
|
+
interface FileExporterOptions {
|
|
3862
|
+
/** HTMLファイル名(デフォルト: 'index.html') */
|
|
3863
|
+
readonly htmlFileName?: string;
|
|
3864
|
+
/** CSSファイル名(デフォルト: 'style.css') */
|
|
3865
|
+
readonly cssFileName?: string;
|
|
3866
|
+
/** JSファイル名(デフォルト: 'script.js') */
|
|
3867
|
+
readonly jsFileName?: string;
|
|
3868
|
+
/** reset.cssを含めるか(デフォルト: false) */
|
|
3869
|
+
readonly includeResetCss?: boolean;
|
|
3870
|
+
/** JSをDOMContentLoadedでラップするか(デフォルト: false) */
|
|
3871
|
+
readonly wrapDOMReady?: boolean;
|
|
3872
|
+
}
|
|
3873
|
+
/**
|
|
3874
|
+
* FileExporter
|
|
3875
|
+
*
|
|
3876
|
+
* HTML、CSS、JavaScriptの3ファイルを統合的に出力するエクスポーターです。
|
|
3877
|
+
*
|
|
3878
|
+
* @remarks
|
|
3879
|
+
* DraftOleで生成されたコンテンツを、実行可能なWebページとして出力します。
|
|
3880
|
+
* 以下の機能を提供します:
|
|
3881
|
+
*
|
|
3882
|
+
* ### 主要機能
|
|
3883
|
+
* - **自動リンク挿入**: HTMLに`<link>`と`<script>`タグを自動挿入
|
|
3884
|
+
* - **スマートスキップ**: 空のCSS/JSはファイル出力とタグ挿入をスキップ
|
|
3885
|
+
* - **reset.cssバンドル**: オプションでEric Meyer's Reset CSSを自動追加
|
|
3886
|
+
* - **ディレクトリ自動作成**: 出力先が存在しない場合は再帰的に作成
|
|
3887
|
+
* - **エラーハンドリング**: {@link ExportableError}による詳細なエラー報告
|
|
3888
|
+
*
|
|
3889
|
+
* ### ファイル出力パターン
|
|
3890
|
+
*
|
|
3891
|
+
* **通常出力** (全ファイル非空時):
|
|
3892
|
+
* ```
|
|
3893
|
+
* output/
|
|
3894
|
+
* ├── index.html (with <link> and <script> tags)
|
|
3895
|
+
* ├── style.css
|
|
3896
|
+
* └── script.js
|
|
3897
|
+
* ```
|
|
3898
|
+
*
|
|
3899
|
+
* **CSS/JS空の場合**:
|
|
3900
|
+
* ```
|
|
3901
|
+
* output/
|
|
3902
|
+
* └── index.html (タグなし)
|
|
3903
|
+
* ```
|
|
3904
|
+
*
|
|
3905
|
+
* @example 基本的な使用方法
|
|
3906
|
+
* ```typescript
|
|
3907
|
+
* const exporter = new FileExporter();
|
|
3908
|
+
* exporter.export(
|
|
3909
|
+
* '<html><head></head><body>Hello</body></html>',
|
|
3910
|
+
* 'body { color: red; }',
|
|
3911
|
+
* 'console.log("Hello");',
|
|
3912
|
+
* './output'
|
|
3913
|
+
* );
|
|
3914
|
+
* // → output/index.html, output/style.css, output/script.js が生成される
|
|
3915
|
+
* ```
|
|
3916
|
+
*
|
|
3917
|
+
* @example カスタムファイル名
|
|
3918
|
+
* ```typescript
|
|
3919
|
+
* const exporter = new FileExporter({
|
|
3920
|
+
* htmlFileName: 'page.html',
|
|
3921
|
+
* cssFileName: 'main.css',
|
|
3922
|
+
* jsFileName: 'app.js',
|
|
3923
|
+
* });
|
|
3924
|
+
* exporter.export(html, css, js, './dist');
|
|
3925
|
+
* // → dist/page.html, dist/main.css, dist/app.js
|
|
3926
|
+
* ```
|
|
3927
|
+
*
|
|
3928
|
+
* @example reset.cssを含める
|
|
3929
|
+
* ```typescript
|
|
3930
|
+
* const exporter = new FileExporter({
|
|
3931
|
+
* includeResetCss: true,
|
|
3932
|
+
* });
|
|
3933
|
+
* exporter.export(html, css, js, './output');
|
|
3934
|
+
* // → style.css の先頭にreset.cssが自動追加される
|
|
3935
|
+
* ```
|
|
3936
|
+
*
|
|
3937
|
+
* @example エラーハンドリング
|
|
3938
|
+
* ```typescript
|
|
3939
|
+
* const exporter = new FileExporter();
|
|
3940
|
+
* try {
|
|
3941
|
+
* exporter.export(html, css, js, '');
|
|
3942
|
+
* } catch (error) {
|
|
3943
|
+
* if (error instanceof ExportableError) {
|
|
3944
|
+
* console.error(`Error [${error.code}]: ${error.message}`);
|
|
3945
|
+
* console.error(`File path: ${error.filePath}`);
|
|
3946
|
+
* }
|
|
3947
|
+
* }
|
|
3948
|
+
* ```
|
|
3949
|
+
*
|
|
3950
|
+
* @example 空のCSS/JSをスキップ
|
|
3951
|
+
* ```typescript
|
|
3952
|
+
* const exporter = new FileExporter();
|
|
3953
|
+
* exporter.export(
|
|
3954
|
+
* '<html><head></head><body>Static page</body></html>',
|
|
3955
|
+
* '', // 空のCSS
|
|
3956
|
+
* '', // 空のJS
|
|
3957
|
+
* './output'
|
|
3958
|
+
* );
|
|
3959
|
+
* // → output/index.html のみ生成(<link>/<script>タグなし)
|
|
3960
|
+
* ```
|
|
3961
|
+
*
|
|
3962
|
+
* @public
|
|
3963
|
+
*/
|
|
3964
|
+
declare class FileExporter {
|
|
3965
|
+
private readonly htmlFileName;
|
|
3966
|
+
private readonly cssFileName;
|
|
3967
|
+
private readonly jsFileName;
|
|
3968
|
+
private readonly includeResetCss;
|
|
3969
|
+
private readonly _wrapDOMReady;
|
|
3970
|
+
constructor(options?: FileExporterOptions);
|
|
3971
|
+
/**
|
|
3972
|
+
* HTML、CSS、JSを統合出力する
|
|
3973
|
+
*
|
|
3974
|
+
* DraftOleで生成されたコンテンツを、実行可能なWebページとして出力します。
|
|
3975
|
+
*
|
|
3976
|
+
* @param htmlContent - HTML内容(完全なHTML文書)
|
|
3977
|
+
* @param cssContent - CSS内容(空文字列の場合はスキップ)
|
|
3978
|
+
* @param jsContent - JS内容(空文字列の場合はスキップ)
|
|
3979
|
+
* @param outputPath - 出力先ディレクトリパス(存在しない場合は自動作成)
|
|
3980
|
+
*
|
|
3981
|
+
* @throws {@link ExportableError}
|
|
3982
|
+
* - `invalidPath`: outputPathが空文字列または無効
|
|
3983
|
+
* - `writeFailed`: ディレクトリ作成またはファイル書き込み失敗
|
|
3984
|
+
*
|
|
3985
|
+
* @remarks
|
|
3986
|
+
* ### 処理フロー
|
|
3987
|
+
* 1. 出力パスの検証
|
|
3988
|
+
* 2. ディレクトリの作成(存在しない場合)
|
|
3989
|
+
* 3. CSS処理(reset.css挿入判定)
|
|
3990
|
+
* 4. HTMLにタグ挿入(CSS/JS非空時)
|
|
3991
|
+
* 5. ファイル書き込み
|
|
3992
|
+
*
|
|
3993
|
+
* ### タグ挿入位置
|
|
3994
|
+
* - `<link>`: `</head>`タグの直前
|
|
3995
|
+
* - `<script>`: `</body>`タグの直前
|
|
3996
|
+
*
|
|
3997
|
+
* ### ファイル出力条件
|
|
3998
|
+
* - **HTML**: 常に出力
|
|
3999
|
+
* - **CSS**: `cssContent.trim().length > 0` または `includeResetCss === true`
|
|
4000
|
+
* - **JS**: `jsContent.trim().length > 0`
|
|
4001
|
+
*
|
|
4002
|
+
* @example 完全な出力
|
|
4003
|
+
* ```typescript
|
|
4004
|
+
* const exporter = new FileExporter();
|
|
4005
|
+
* exporter.export(
|
|
4006
|
+
* '<!DOCTYPE html><html><head></head><body><h1>Hello</h1></body></html>',
|
|
4007
|
+
* 'h1 { color: blue; }',
|
|
4008
|
+
* 'console.log("Loaded");',
|
|
4009
|
+
* './output'
|
|
4010
|
+
* );
|
|
4011
|
+
* ```
|
|
4012
|
+
*
|
|
4013
|
+
* @example HTMLのみ(静的ページ)
|
|
4014
|
+
* ```typescript
|
|
4015
|
+
* const exporter = new FileExporter();
|
|
4016
|
+
* exporter.export(
|
|
4017
|
+
* '<!DOCTYPE html><html><head></head><body><h1>Static</h1></body></html>',
|
|
4018
|
+
* '', // CSS空
|
|
4019
|
+
* '', // JS空
|
|
4020
|
+
* './output'
|
|
4021
|
+
* );
|
|
4022
|
+
* // → index.htmlのみ生成、<link>/<script>タグなし
|
|
4023
|
+
* ```
|
|
4024
|
+
*
|
|
4025
|
+
* @example エラーハンドリング
|
|
4026
|
+
* ```typescript
|
|
4027
|
+
* const exporter = new FileExporter();
|
|
4028
|
+
* try {
|
|
4029
|
+
* exporter.export(html, css, js, '/invalid/readonly/path');
|
|
4030
|
+
* } catch (error) {
|
|
4031
|
+
* if (error instanceof ExportableError) {
|
|
4032
|
+
* if (error.code === 'writeFailed') {
|
|
4033
|
+
* console.error('Failed to write files:', error.message);
|
|
4034
|
+
* console.error('Path:', error.filePath);
|
|
4035
|
+
* }
|
|
4036
|
+
* }
|
|
4037
|
+
* }
|
|
4038
|
+
* ```
|
|
4039
|
+
*
|
|
4040
|
+
* @example ネストされたディレクトリ
|
|
4041
|
+
* ```typescript
|
|
4042
|
+
* const exporter = new FileExporter();
|
|
4043
|
+
* exporter.export(html, css, js, './output/nested/deep/directory');
|
|
4044
|
+
* // → ディレクトリが自動的に再帰作成される
|
|
4045
|
+
* ```
|
|
4046
|
+
*
|
|
4047
|
+
* @public
|
|
4048
|
+
*/
|
|
4049
|
+
/**
|
|
4050
|
+
* Root オブジェクトから ExportContext を取得し、ファイル出力する。
|
|
4051
|
+
*
|
|
4052
|
+
* @param root - DraftOle Root インスタンス
|
|
4053
|
+
* @param outputPath - 出力先ディレクトリパス
|
|
4054
|
+
*/
|
|
4055
|
+
exportFromRoot(root: Root, outputPath: string): void;
|
|
4056
|
+
/**
|
|
4057
|
+
* ExportContext からコンテンツを組み立ててファイル出力する。
|
|
4058
|
+
*
|
|
4059
|
+
* - `runtimePrelude` が存在する場合、JS の先頭にプレリュードと state-init JS を挿入する。
|
|
4060
|
+
* - `runtimePrelude` が存在しない場合、`userJs` をそのまま使用する。
|
|
4061
|
+
*
|
|
4062
|
+
* @param ctx - ExportContext スナップショット
|
|
4063
|
+
* @param outputPath - 出力先ディレクトリパス
|
|
4064
|
+
*/
|
|
4065
|
+
exportContext(ctx: ExportContext, outputPath: string): void;
|
|
4066
|
+
export(htmlContent: string, cssContent: string, jsContent: string, outputPath: string): void;
|
|
4067
|
+
}
|
|
4068
|
+
|
|
4069
|
+
/**
|
|
4070
|
+
* `ExprFactory` の実装。
|
|
4071
|
+
*
|
|
4072
|
+
* 設計書 `design.md` の「ExprFactory」節に対応し、以下の API を提供する:
|
|
4073
|
+
* - `createExprFactory()`: callable な関数オブジェクトに `.bool` プロパティを
|
|
4074
|
+
* 付与して返す。`root.expr(code)` / `root.expr.bool(code)` のエントリポイント。
|
|
4075
|
+
* - `encodeLiteral(value)`: 文字列/数値は `JSON.stringify` でリテラル化し、
|
|
4076
|
+
* `JsExpr` は `.code` を素通しする共通ヘルパ。要素メソッド側(`setText` 等)
|
|
4077
|
+
* からも再利用される想定(Req 4.5)。
|
|
4078
|
+
*
|
|
4079
|
+
* 対応 requirement:
|
|
4080
|
+
* - 4.1: `root.expr(code)` が `.code === code` の `JsExpr` を返す
|
|
4081
|
+
* - 4.2: 返された `JsExpr` は `eq`/`ne`/`or`/`trim`/`isFalsy`/`isTruthy` を提供
|
|
4082
|
+
* - 4.3: `.bool(code)` が `JsBoolExpr` を返す
|
|
4083
|
+
* - 4.5: 文字列リテラルを `JSON.stringify` でエンコードする共通経路を提供
|
|
4084
|
+
*
|
|
4085
|
+
* 実装方針: 既存の内部ファクトリ `_makeJsExpr` / `_makeJsBoolExpr`(`element-ref.ts`)
|
|
4086
|
+
* を再利用し、式オブジェクトの振る舞いを単一化する(R-6 決定)。
|
|
4087
|
+
*/
|
|
4088
|
+
|
|
4089
|
+
/**
|
|
4090
|
+
* `root.expr` の型。callable + `.bool` namespace 構造(design.md §ExprFactory)。
|
|
4091
|
+
*/
|
|
4092
|
+
interface ExprFactory {
|
|
4093
|
+
/** 任意の JS 式コードを `.code` としてそのまま保持する `JsExpr` を生成する。 */
|
|
4094
|
+
(code: string): JsExpr;
|
|
4095
|
+
/** 真偽式として扱う生コードを `JsBoolExpr` として生成する。 */
|
|
4096
|
+
bool(code: string): JsBoolExpr;
|
|
4097
|
+
}
|
|
4098
|
+
|
|
4099
|
+
/**
|
|
4100
|
+
* `SelectorRef<E>` / `CollectionRef<E>` の実装。
|
|
4101
|
+
*
|
|
4102
|
+
* 本モジュールは `unified-element-api` 仕様の Task 3.4 に対応し、
|
|
4103
|
+
* `root.$` / `root.$$` の戻り値として公開するセレクタ参照ノードを提供する。
|
|
4104
|
+
*
|
|
4105
|
+
* 設計方針:
|
|
4106
|
+
* - `SelectorRef<E>` は `ElementMethods<SelectorRef<E>>` を実装し、内部で
|
|
4107
|
+
* `VanillaScope` と `ElementRef<E>` を保持して DOM 操作メソッドを提供する。
|
|
4108
|
+
* - `CollectionRef<E>` は `VanillaScope` と `ElementListRef<E>` を保持し、
|
|
4109
|
+
* `filterNot` / `length` / `removeAll` / `forEach` を提供する。
|
|
4110
|
+
* - 内部実装は `internal/dom-api` / `internal/query-api` / `internal/tree-api` に委譲する。
|
|
4111
|
+
* - `on` ハンドラ / `forEach` 本体のスコープは `_makeHandlerScope` を再利用する。
|
|
4112
|
+
*
|
|
4113
|
+
* 対応 requirement: 2.1, 2.2, 2.3, 2.4, 2.5, 2.6 (unified-element-api)
|
|
4114
|
+
* 依存: Task 3.3 (ElementMethods, _makeHandlerScope, renderElementTarget, HasPending)
|
|
4115
|
+
* Task 1.2 (internal/query-api, dom-api, tree-api)
|
|
4116
|
+
*/
|
|
4117
|
+
|
|
4118
|
+
/**
|
|
4119
|
+
* `root.$<E>(selector)` の戻り値。
|
|
4120
|
+
*
|
|
4121
|
+
* `ElementMethods<SelectorRef<E>>` を実装し、セレクタ対象要素への
|
|
4122
|
+
* DOM 操作メソッドを提供する。加えて `containsClass` / `cache` を追加する。
|
|
4123
|
+
*
|
|
4124
|
+
* 設計: SelectorRef は常に scope に紐付いており、バッファを持たない
|
|
4125
|
+
*(Root への登録が前提のため、即時 scope._append する)。
|
|
4126
|
+
*/
|
|
4127
|
+
interface SelectorRef<E extends Element = HTMLElement> extends ElementMethods<SelectorRef<E>> {
|
|
4128
|
+
/** `element.classList.contains(name)` を `JsBoolExpr` として返す(Req 2.4)。 */
|
|
4129
|
+
containsClass(name: string): JsBoolExpr;
|
|
4130
|
+
/**
|
|
4131
|
+
* セレクタ結果をローカル変数にキャッシュし、新しい `SelectorRef` を返す(Req 2.5)。
|
|
4132
|
+
* 同一セレクタを複数回埋め込む副作用を避けたい場合に使用する。
|
|
4133
|
+
*/
|
|
4134
|
+
cache(name: string): SelectorRef<E>;
|
|
4135
|
+
}
|
|
4136
|
+
/**
|
|
4137
|
+
* `root.$$<E>(selector)` の戻り値。
|
|
4138
|
+
*
|
|
4139
|
+
* `filterNot` / `length` / `removeAll` / `forEach` を提供するコレクション参照。
|
|
4140
|
+
*/
|
|
4141
|
+
interface CollectionRef<E extends Element = HTMLElement> {
|
|
4142
|
+
/**
|
|
4143
|
+
* 述語に一致しない要素だけを残す新しい `CollectionRef` を返す(Req 2.3)。
|
|
4144
|
+
* 式の合成のみを行い、scope にコマンドを追加しない。
|
|
4145
|
+
*/
|
|
4146
|
+
filterNot(predicate: (ref: SelectorRef<E>) => JsBoolExpr): CollectionRef<E>;
|
|
4147
|
+
/** コレクション内の要素数を `JsExpr` として返す(Req 2.3)。 */
|
|
4148
|
+
readonly length: JsExpr;
|
|
4149
|
+
/** コレクション内の全要素を削除する命令を scope に追加する(Req 2.3)。 */
|
|
4150
|
+
removeAll(): void;
|
|
4151
|
+
/**
|
|
4152
|
+
* コレクションを反復する `forEach` 命令を scope に追加する(Req 2.3)。
|
|
4153
|
+
* コールバックは `SelectorRef<E>` と `ScriptScope` を受け取る。
|
|
4154
|
+
*/
|
|
4155
|
+
forEach(body: (ref: SelectorRef<E>, s: ScriptScope) => void): void;
|
|
4156
|
+
}
|
|
4157
|
+
|
|
4158
|
+
/**
|
|
4159
|
+
* Task 4.5: Root ドキュメントルート要素
|
|
4160
|
+
*
|
|
4161
|
+
* HTML文書のトップレベル要素。Root自身のタグは出力せず、
|
|
4162
|
+
* 子要素のレンダリング結果を連結して返す。
|
|
4163
|
+
*
|
|
4164
|
+
* CSS出力モード(default/inline/external)を管理し、
|
|
4165
|
+
* ツリー全体のCSS/JSコンテンツ収集スタブ(Phase 3/4接続点)を提供する。
|
|
4166
|
+
*
|
|
4167
|
+
* レンダリング:
|
|
4168
|
+
* protoRender() → 子要素の protoRender() を連結(Root自体のタグは出力しない)
|
|
4169
|
+
* render() → protoRender() → HTMLFormatter.format()
|
|
4170
|
+
*
|
|
4171
|
+
* Requirements: 3.1, 3.7, 3.8, 3.9, 6.6, 6.1, 6.2, 6.3, 6.4
|
|
4172
|
+
*/
|
|
4173
|
+
|
|
4174
|
+
/**
|
|
4175
|
+
* Constructor options for Root.
|
|
4176
|
+
*
|
|
4177
|
+
* Extends {@link HtmlTagOptions} with document-level settings.
|
|
4178
|
+
* Note: the `css` property from HtmlTagOptions is omitted and replaced
|
|
4179
|
+
* with `css?: readonly GlobalCss[]` for global CSS injection.
|
|
4180
|
+
*/
|
|
4181
|
+
interface RootOptions extends Omit<HtmlTagOptions, 'css'> {
|
|
4182
|
+
/** Global CSS rules to inject before scoped styles. */
|
|
4183
|
+
css?: readonly GlobalCss[];
|
|
4184
|
+
/**
|
|
4185
|
+
* Whether to inject a CSS reset before all other styles.
|
|
4186
|
+
* @defaultValue false
|
|
4187
|
+
*/
|
|
4188
|
+
reset?: boolean;
|
|
4189
|
+
/**
|
|
4190
|
+
* CSS 出力設定(minify モード等)。
|
|
4191
|
+
*
|
|
4192
|
+
* 省略時は `new CssConfig()` の default を使用する(`NODE_ENV` fallback 適用)。
|
|
4193
|
+
* Root constructor 時点で評価され、以後不変。
|
|
4194
|
+
*
|
|
4195
|
+
* @see CssConfig
|
|
4196
|
+
*/
|
|
4197
|
+
cssConfig?: CssConfig;
|
|
4198
|
+
}
|
|
4199
|
+
|
|
4200
|
+
/**
|
|
4201
|
+
* CSS output mode for the document.
|
|
4202
|
+
*
|
|
4203
|
+
* - **default**: Default behavior (defined in Phase 3)
|
|
4204
|
+
* - **inline**: Inline CSS output (styles in `<style>` tags)
|
|
4205
|
+
* - **external**: External CSS output (separate `.css` file)
|
|
4206
|
+
*/
|
|
4207
|
+
type CssOutputMode = 'default' | 'inline' | 'external';
|
|
4208
|
+
/**
|
|
4209
|
+
* Represents the root element of an HTML document.
|
|
4210
|
+
*
|
|
4211
|
+
* Root is a special element that doesn't render its own tag, but instead
|
|
4212
|
+
* concatenates the rendering output of its child elements. It serves as the
|
|
4213
|
+
* top-level container for the entire HTML document tree.
|
|
4214
|
+
*
|
|
4215
|
+
* **Key Features:**
|
|
4216
|
+
* - Manages CSS output mode (default/inline/external)
|
|
4217
|
+
* - Collects CSS and JavaScript from entire document tree
|
|
4218
|
+
* - Provides `renderJs()` for complete JavaScript output with tree-shaking
|
|
4219
|
+
*
|
|
4220
|
+
* **Rendering Format:**
|
|
4221
|
+
* ```html
|
|
4222
|
+
* <!-- No root tag is rendered, only children: -->
|
|
4223
|
+
* <child1>...</child1>
|
|
4224
|
+
* <child2>...</child2>
|
|
4225
|
+
* ```
|
|
4226
|
+
*
|
|
4227
|
+
* @example
|
|
4228
|
+
* Basic document structure:
|
|
4229
|
+
* ```typescript
|
|
4230
|
+
* const doc = new Root();
|
|
4231
|
+
* doc.addChild(html(
|
|
4232
|
+
* head(title('My Page')),
|
|
4233
|
+
* body(
|
|
4234
|
+
* h1('Hello World'),
|
|
4235
|
+
* p('Welcome to my page')
|
|
4236
|
+
* )
|
|
4237
|
+
* ));
|
|
4238
|
+
*
|
|
4239
|
+
* console.log(doc.render());
|
|
4240
|
+
* ```
|
|
4241
|
+
*
|
|
4242
|
+
* @example
|
|
4243
|
+
* With JavaScript tree-shaking:
|
|
4244
|
+
* ```typescript
|
|
4245
|
+
* const doc = new Root();
|
|
4246
|
+
* const button = div();
|
|
4247
|
+
* button.jqm.on('click', () => console.log('Clicked'));
|
|
4248
|
+
* doc.addChild(button);
|
|
4249
|
+
*
|
|
4250
|
+
* // Only includes helper for 'on' method
|
|
4251
|
+
* const js = doc.renderJs();
|
|
4252
|
+
* ```
|
|
4253
|
+
*
|
|
4254
|
+
* @remarks
|
|
4255
|
+
* **Preconditions:** None (no constructor arguments required)
|
|
4256
|
+
*
|
|
4257
|
+
* **Postconditions:** `protoRender()` returns concatenated child output (no root tag)
|
|
4258
|
+
*
|
|
4259
|
+
* **Invariants:** `cssOutputMode` is one of {@link CssOutputMode} values
|
|
4260
|
+
*/
|
|
4261
|
+
declare class Root extends HtmlTag {
|
|
4262
|
+
/**
|
|
4263
|
+
* CSS output mode for this document.
|
|
4264
|
+
*
|
|
4265
|
+
* @defaultValue 'default'
|
|
4266
|
+
*/
|
|
4267
|
+
cssOutputMode: CssOutputMode;
|
|
4268
|
+
/** Document-level policy: doctype flag, global CSS, reset baseline. */
|
|
4269
|
+
private _documentContext;
|
|
4270
|
+
/**
|
|
4271
|
+
* Root が保持する単一の JS スクリプトスコープ。
|
|
4272
|
+
*
|
|
4273
|
+
* 初回アクセス時に遅延生成され、以後は同一インスタンスを返す。
|
|
4274
|
+
* 実装は `RuntimeContext.getScope()` への委譲。
|
|
4275
|
+
*
|
|
4276
|
+
* @example
|
|
4277
|
+
* ```typescript
|
|
4278
|
+
* const root = new Root();
|
|
4279
|
+
* root.script.onDomReady(s => {
|
|
4280
|
+
* s.call('init');
|
|
4281
|
+
* });
|
|
4282
|
+
* ```
|
|
4283
|
+
*/
|
|
4284
|
+
get script(): ScriptScope;
|
|
4285
|
+
/**
|
|
4286
|
+
* JS 式 / 真偽式を生成するファクトリ。
|
|
4287
|
+
*
|
|
4288
|
+
* 初回アクセス時に遅延生成され、以後は同一インスタンスを返す。
|
|
4289
|
+
* 実装は `RuntimeContext.getExprFactory()` への委譲。
|
|
4290
|
+
*
|
|
4291
|
+
* @example
|
|
4292
|
+
* ```typescript
|
|
4293
|
+
* const root = new Root();
|
|
4294
|
+
* const isActive = root.expr.bool('el.classList.contains("active")');
|
|
4295
|
+
* ```
|
|
4296
|
+
*/
|
|
4297
|
+
get expr(): ExprFactory;
|
|
4298
|
+
/**
|
|
4299
|
+
* CSS セレクタで単一要素を参照する `SelectorRef` を返す。
|
|
4300
|
+
*
|
|
4301
|
+
* 実装は `RuntimeContext.querySelector()` への委譲。
|
|
4302
|
+
*
|
|
4303
|
+
* @param selector - `document.querySelector` に渡すセレクタ文字列
|
|
4304
|
+
* @returns `SelectorRef<E>` — セレクタ参照ノード
|
|
4305
|
+
*
|
|
4306
|
+
* @example
|
|
4307
|
+
* ```typescript
|
|
4308
|
+
* const root = new Root();
|
|
4309
|
+
* root.$('#my-btn').on('click', s => s.call('handleClick'));
|
|
4310
|
+
* ```
|
|
4311
|
+
*/
|
|
4312
|
+
$<E extends Element = HTMLElement>(selector: string): SelectorRef<E>;
|
|
4313
|
+
/**
|
|
4314
|
+
* CSS セレクタで複数要素を参照する `CollectionRef` を返す。
|
|
4315
|
+
*
|
|
4316
|
+
* 実装は `RuntimeContext.querySelectorAll()` への委譲。
|
|
4317
|
+
*
|
|
4318
|
+
* @param selector - `document.querySelectorAll` に渡すセレクタ文字列
|
|
4319
|
+
* @returns `CollectionRef<E>` — コレクション参照ノード
|
|
4320
|
+
*
|
|
4321
|
+
* @example
|
|
4322
|
+
* ```typescript
|
|
4323
|
+
* const root = new Root();
|
|
4324
|
+
* root.$$('.todo-item').removeAll();
|
|
4325
|
+
* ```
|
|
4326
|
+
*/
|
|
4327
|
+
$$<E extends Element = HTMLElement>(selector: string): CollectionRef<E>;
|
|
4328
|
+
/**
|
|
4329
|
+
* Creates a new Root element.
|
|
4330
|
+
*
|
|
4331
|
+
* @param options - Optional options including css rules and DI overrides (for testing)
|
|
4332
|
+
*
|
|
4333
|
+
* @example
|
|
4334
|
+
* ```typescript
|
|
4335
|
+
* import { rule } from '../../css/variables/global-css.js';
|
|
4336
|
+
* const root = new Root({ css: [rule('.foo', { color: 'red' })] });
|
|
4337
|
+
* ```
|
|
4338
|
+
*/
|
|
4339
|
+
/**
|
|
4340
|
+
* RuntimeContext — state registry / JS aggregation の受け皿(task 3.2 委譲)。
|
|
4341
|
+
* @internal
|
|
4342
|
+
*/
|
|
4343
|
+
private _runtimeContext;
|
|
4344
|
+
constructor(options?: RootOptions);
|
|
4345
|
+
/**
|
|
4346
|
+
* CSS 出力設定(解決済み)。Root constructor 時点で fix される。
|
|
4347
|
+
* @internal
|
|
4348
|
+
*/
|
|
4349
|
+
private readonly _cssConfig;
|
|
4350
|
+
/**
|
|
4351
|
+
* 子要素を追加し、要素のバッファ済み Vanilla JS コマンドを Root の script スコープへフラッシュする。
|
|
4352
|
+
*
|
|
4353
|
+
* `HtmlTag.addChild` の CSS tagPath 設定処理を維持しつつ、
|
|
4354
|
+
* `FlushOrchestrator.flush(el, scope)` を追加実行する(Req 1.6, 1.7)。
|
|
4355
|
+
*/
|
|
4356
|
+
addChild(child: HTMLTagProtocol): this;
|
|
4357
|
+
/**
|
|
4358
|
+
* Root ツリーに既に追加済みの子要素配下に後から追加された要素のコマンドをフラッシュする。
|
|
4359
|
+
* `app()` の `exportTo()` など、Root.addChild 経由でない addChild の後に呼ぶ。
|
|
4360
|
+
* @internal
|
|
4361
|
+
*/
|
|
4362
|
+
flushDescendants(child: HTMLTagProtocol): void;
|
|
4363
|
+
/**
|
|
4364
|
+
* StateRegistry への package-private アクセス(FileExporter が参照)。
|
|
4365
|
+
*
|
|
4366
|
+
* `state()` を一度も呼んでいない場合は `undefined` を返す(遅延初期化と整合)。
|
|
4367
|
+
* 実態は `_runtimeContext.stateRegistry` へ委譲する(task 3.2)。
|
|
4368
|
+
* @internal
|
|
4369
|
+
*/
|
|
4370
|
+
get _stateRegistry(): StateRegistry | undefined;
|
|
4371
|
+
/**
|
|
4372
|
+
* 一意な状態 ID を採番し、State<T> オブジェクトを返す。
|
|
4373
|
+
*
|
|
4374
|
+
* Req 1.1: root.state<T>(initial) を呼び出すと一意な状態 ID を採番した State<T> を返す。
|
|
4375
|
+
* Req 1.3: 同一 Root から複数回呼び出すと異なる状態 ID を採番。
|
|
4376
|
+
*
|
|
4377
|
+
* `_runtimeContext.state(initial)` へ委譲する(task 3.2)。
|
|
4378
|
+
*
|
|
4379
|
+
* @param initial - 状態の初期値
|
|
4380
|
+
* @returns State<T> — 一意な `_runtimeId` を持つ観測可能値オブジェクト
|
|
4381
|
+
*/
|
|
4382
|
+
state<T>(initial: T): State<T>;
|
|
4383
|
+
/**
|
|
4384
|
+
* Vanilla JS Builder の出力を文字列として返す。
|
|
4385
|
+
*
|
|
4386
|
+
* 実装は `RuntimeContext.renderUserJs()` への委譲。
|
|
4387
|
+
* `script` にアクセスしていない場合(Builder が未初期化)は空文字列を返す。
|
|
4388
|
+
*/
|
|
4389
|
+
renderVanillaScript(): string;
|
|
4390
|
+
/**
|
|
4391
|
+
* Enables or disables <!DOCTYPE html> output.
|
|
4392
|
+
* Default is false (backward compatible).
|
|
4393
|
+
*/
|
|
4394
|
+
setDoctype(enabled?: boolean): this;
|
|
4395
|
+
/**
|
|
4396
|
+
* Task 3.2: Root の protoRender override。
|
|
4397
|
+
*
|
|
4398
|
+
* 受け取った ctx を子要素の `protoRender(ctx)` に必ず伝搬する。
|
|
4399
|
+
* ctx 省略時はツリー全体で共有する RenderContext を 1 つだけ生成し、
|
|
4400
|
+
* 全子要素に同一インスタンスとして渡す(registry の共有を保証する)。
|
|
4401
|
+
*
|
|
4402
|
+
* 出力は子要素 protoRender の連結(Root 自身のタグは出力しない)。
|
|
4403
|
+
*
|
|
4404
|
+
* @remarks
|
|
4405
|
+
* Task 3.3: Root はレンダーツリー境界の所有者であり、`protoRender` 開始時に
|
|
4406
|
+
* `ctx.registry.reset()` を呼んで前回レンダーで蓄積された id 集合を破棄する。
|
|
4407
|
+
* これにより同一 Root インスタンスを複数回 protoRender しても結果が
|
|
4408
|
+
* バイト等価になり(Req 3.7 ビルド間安定性)、外部から渡された ctx に既存 id が
|
|
4409
|
+
* 登録されていても Root 配下のレンダーには影響しない(Req 3.4 id 重複検出を
|
|
4410
|
+
* Root 境界内に閉じる)。
|
|
4411
|
+
*/
|
|
4412
|
+
protoRender(ctx?: RenderContext): string;
|
|
4413
|
+
/**
|
|
4414
|
+
* Renders the document tree to formatted HTML.
|
|
4415
|
+
* Prepends <!DOCTYPE html> if enabled via setDoctype().
|
|
4416
|
+
*/
|
|
4417
|
+
render(): string;
|
|
4418
|
+
/**
|
|
4419
|
+
* Recursively collects CSS styles from the entire document tree.
|
|
4420
|
+
*
|
|
4421
|
+
* Traverses all child elements and concatenates their CSS output.
|
|
4422
|
+
*
|
|
4423
|
+
* @returns Concatenated CSS string from all elements
|
|
4424
|
+
*
|
|
4425
|
+
* @example
|
|
4426
|
+
* ```typescript
|
|
4427
|
+
* const doc = new Root();
|
|
4428
|
+
* const element = div();
|
|
4429
|
+
* element.css.addRule('.my-class', { color: 'red' });
|
|
4430
|
+
* doc.addChild(element);
|
|
4431
|
+
*
|
|
4432
|
+
* const css = doc.collectCssStyleString();
|
|
4433
|
+
* ```
|
|
4434
|
+
*/
|
|
4435
|
+
collectCssStyleString(): string;
|
|
4436
|
+
/**
|
|
4437
|
+
* Recursively collects JavaScript content from the entire document tree.
|
|
4438
|
+
*
|
|
4439
|
+
* Traverses all child elements and concatenates their JavaScript output.
|
|
4440
|
+
*
|
|
4441
|
+
* @returns Concatenated JavaScript string from all elements
|
|
4442
|
+
*
|
|
4443
|
+
* @example
|
|
4444
|
+
* ```typescript
|
|
4445
|
+
* const doc = new Root();
|
|
4446
|
+
* const button = div();
|
|
4447
|
+
* button.jqm.on('click', () => console.log('Clicked'));
|
|
4448
|
+
* doc.addChild(button);
|
|
4449
|
+
*
|
|
4450
|
+
* const js = doc.collectJsContent();
|
|
4451
|
+
* ```
|
|
4452
|
+
*/
|
|
4453
|
+
collectJsContent(): string;
|
|
4454
|
+
/**
|
|
4455
|
+
* Recursively collects jQuery method types used in the entire document tree.
|
|
4456
|
+
*
|
|
4457
|
+
* Aggregates all jQuery methods used by descendant elements for tree-shaking.
|
|
4458
|
+
*
|
|
4459
|
+
* @returns Set of {@link JQueryMethodType} used in the document
|
|
4460
|
+
*/
|
|
4461
|
+
collectUsedMethods(): Set<JQueryMethodType>;
|
|
4462
|
+
/**
|
|
4463
|
+
* Generates complete JavaScript output with tree-shaking.
|
|
4464
|
+
*
|
|
4465
|
+
* Combines jQuery helper functions (only for used methods) with the actual
|
|
4466
|
+
* JavaScript content from the document tree.
|
|
4467
|
+
*
|
|
4468
|
+
* **Output Format:**
|
|
4469
|
+
* - If no methods used: returns empty string
|
|
4470
|
+
* - If no content but methods used: returns helper only
|
|
4471
|
+
* - Otherwise: returns `helper + "\n\n" + jsContent`
|
|
4472
|
+
*
|
|
4473
|
+
* @returns Complete JavaScript string ready for embedding
|
|
4474
|
+
*
|
|
4475
|
+
* @example
|
|
4476
|
+
* ```typescript
|
|
4477
|
+
* const doc = new Root();
|
|
4478
|
+
* const button = div();
|
|
4479
|
+
* button.jqm.on('click', () => console.log('Clicked'));
|
|
4480
|
+
* button.jqm.addClass('active');
|
|
4481
|
+
* doc.addChild(button);
|
|
4482
|
+
*
|
|
4483
|
+
* const js = doc.renderJs();
|
|
4484
|
+
* // Output includes:
|
|
4485
|
+
* // - Helper functions for 'on' and 'addClass' only (tree-shaken)
|
|
4486
|
+
* // - Actual event handler and addClass call
|
|
4487
|
+
* ```
|
|
4488
|
+
*
|
|
4489
|
+
* @remarks
|
|
4490
|
+
* **Preconditions:** None
|
|
4491
|
+
*
|
|
4492
|
+
* **Postconditions:**
|
|
4493
|
+
* - Empty string if no methods used
|
|
4494
|
+
* - `helper + "\n\n" + jsContent` format if methods used
|
|
4495
|
+
*
|
|
4496
|
+
* **Invariants:** Helper and jsContent separator is always `"\n\n"`
|
|
4497
|
+
*/
|
|
4498
|
+
renderJs(): string;
|
|
4499
|
+
/**
|
|
4500
|
+
* Publisher 用の export snapshot を組み立てて返す。
|
|
4501
|
+
*
|
|
4502
|
+
* runtime registry の内部構造をここで吸収し、FileExporter には漏らさない。
|
|
4503
|
+
* FileExporter は `ExportContext` 経由でのみ必要情報を受け取る(Req 3.1, 3.2)。
|
|
4504
|
+
*
|
|
4505
|
+
* - `html`: `this.render()` の出力
|
|
4506
|
+
* - `css`: `this.collectCssStyleString()` の出力
|
|
4507
|
+
* - `userJs`: `this.renderVanillaScript()` の出力
|
|
4508
|
+
* - `runtimePrelude`: 状態あり時のみ `RUNTIME_PRELUDE` を設定
|
|
4509
|
+
* - `runtimeInitJs`: 状態あり時のみ state-init + derive コマンド列を設定
|
|
4510
|
+
*
|
|
4511
|
+
* @returns ExportContext — publisher が必要とする read-only snapshot
|
|
4512
|
+
*/
|
|
4513
|
+
buildExportContext(): ExportContext;
|
|
4514
|
+
/**
|
|
4515
|
+
* ドキュメントツリーを HTML / CSS / JS ファイルとして出力する。
|
|
4516
|
+
*
|
|
4517
|
+
* `new FileExporter(options).exportFromRoot(this, outputPath)` と等価なショートカットメソッド。
|
|
4518
|
+
* `FileExporter` はそのまま残し、高度な制御(カスタムファイル名・reset.css・DOMContentLoaded ラップ等)
|
|
4519
|
+
* が必要な場合の entry point として引き続き利用できる。
|
|
4520
|
+
*
|
|
4521
|
+
* @param outputPath - 出力先ディレクトリパス(存在しない場合は自動作成)
|
|
4522
|
+
* @param options - {@link FileExporterOptions} オプション(省略可)
|
|
4523
|
+
*
|
|
4524
|
+
* @throws {@link ExportableError}
|
|
4525
|
+
* - `invalidPath`: outputPath が空文字列または無効
|
|
4526
|
+
* - `writeFailed`: ディレクトリ作成またはファイル書き込み失敗
|
|
4527
|
+
*
|
|
4528
|
+
* @example 基本的な使用方法
|
|
4529
|
+
* ```typescript
|
|
4530
|
+
* const root = new Root();
|
|
4531
|
+
* root.addChild(html(head(title('My Page')), body(h1('Hello'))));
|
|
4532
|
+
* root.export('./output/demo');
|
|
4533
|
+
* // 上記は以下と等価:
|
|
4534
|
+
* // new FileExporter().exportFromRoot(root, './output/demo');
|
|
4535
|
+
* ```
|
|
4536
|
+
*
|
|
4537
|
+
* @example カスタムオプション付き
|
|
4538
|
+
* ```typescript
|
|
4539
|
+
* const root = new Root();
|
|
4540
|
+
* root.export('./output/demo', { htmlFileName: 'page.html', includeResetCss: true });
|
|
4541
|
+
* // 上記は以下と等価:
|
|
4542
|
+
* // new FileExporter({ htmlFileName: 'page.html', includeResetCss: true }).exportFromRoot(root, './output/demo');
|
|
4543
|
+
* ```
|
|
4544
|
+
*
|
|
4545
|
+
* @remarks
|
|
4546
|
+
* **Preconditions:** `outputPath` は出力先ディレクトリパス
|
|
4547
|
+
*
|
|
4548
|
+
* **Postconditions:** `FileExporter.exportFromRoot` と同一の副作用(HTML/CSS/JS ファイル出力)
|
|
4549
|
+
*
|
|
4550
|
+
* **Error:** `FileExporter` から伝播するエラーはそのまま再スローされる
|
|
4551
|
+
*/
|
|
4552
|
+
export(outputPath: string, options?: FileExporterOptions): void;
|
|
4553
|
+
}
|
|
4554
|
+
|
|
4555
|
+
type View = HtmlTag;
|
|
4556
|
+
/**
|
|
4557
|
+
* `page` 公開面で受け付ける静的ビューの narrow interface(design.md §6.1)。
|
|
4558
|
+
*
|
|
4559
|
+
* `HtmlTag` を直接 `View` として再エクスポートせず、静的レンダリングに必要な
|
|
4560
|
+
* 能力のみを露出する。`HtmlTag` は構造的部分型としてこの interface を満たすため
|
|
4561
|
+
* `VStack()` / `Page()` / `div()` 等の戻り値はそのまま `StaticView` に代入可能だが、
|
|
4562
|
+
* `StaticView` 経由で取り出せるシンボルは static 系メソッドのみとなり、
|
|
4563
|
+
* `jqm` / `state` / `script` / `$` / `$$` 等の runtime 面は型レベルで不可達となる。
|
|
4564
|
+
*
|
|
4565
|
+
* 対応 requirement: 1.1, 1.2, 6.1, 6.2 (page-runtime-separation-spec)
|
|
4566
|
+
*/
|
|
4567
|
+
interface StaticView {
|
|
4568
|
+
/** 内部実装が静的 HTML をレンダリングするための最小契約 */
|
|
4569
|
+
protoRender(ctx?: RenderContext): string;
|
|
4570
|
+
/** 静的 CSS の収集(runtime JS 収集系は意図的に含めない) */
|
|
4571
|
+
collectCssStyleString(): string;
|
|
4572
|
+
}
|
|
4573
|
+
interface PageOptions {
|
|
4574
|
+
lang?: string;
|
|
4575
|
+
title?: string;
|
|
4576
|
+
description?: string;
|
|
4577
|
+
viewport?: string;
|
|
4578
|
+
charset?: string;
|
|
4579
|
+
}
|
|
4580
|
+
type HeadingLevel = 1 | 2 | 3 | 4 | 5 | 6;
|
|
4581
|
+
interface LinkOptions {
|
|
4582
|
+
href: string;
|
|
4583
|
+
target?: '_blank' | '_self';
|
|
4584
|
+
rel?: string;
|
|
4585
|
+
}
|
|
4586
|
+
interface ButtonOptions {
|
|
4587
|
+
type?: 'button' | 'submit' | 'reset';
|
|
4588
|
+
}
|
|
4589
|
+
|
|
4590
|
+
export { type CssConfigOutputMode as $, type AttributeManageable as A, type BooleanAttributeValue as B, type CssPositionMakerType as C, CSSColorName as D, type ElementRef as E, CSSFlex as F, type GlobalCss as G, type HtmlAttributeShape as H, type IdentifierResolver as I, type JQueryManagerInstance as J, CSSFont as K, type LazyLayoutRegister as L, CSSGrid as M, CSSList as N, CSSSpacing as O, CSSTable as P, CSSText as Q, type RenderContext as R, type StyleTemplate as S, type TagType as T, CSSTransform as U, CSSVisibility as V, CSSVisual as W, type ChildManageable as X, type CollectionRef as Y, type Computed as Z, type CssConfigOptions as _, type HTMLTagProtocol as a, type CssManagerType as a0, type CssOutputMode as a1, type CustomAttributeValue as a2, type EachBinding as a3, type EdgeSet as a4, type Exportable as a5, type ExprFactory as a6, FileExporter as a7, type FileExporterOptions as a8, type FlexOptions as a9, createCustomValue as aA, createKeyValueValue as aB, createVanillaScript as aC, getTagStructure as aD, hlUnitToCssString as aE, Root as aF, type StaticView as aG, type FontOptions as aa, type FrameOptions as ab, type GridOptions as ac, type HeadingLevel as ad, type HtmlStyleType as ae, JQUERY_METHOD_TYPES as af, type JQueryManagerProtocol as ag, type JsBoolExpr as ah, type JsExpr as ai, type KeyValueAttributeValue as aj, type LinkOptions as ak, type PageOptions as al, type Positioning as am, PseudoStyleBuilder as an, type ReadableState as ao, type Renderable as ap, SELF_CLOSING_TAGS as aq, type ScriptStateHandle as ar, type SelectorRef as as, type State as at, type StateJsAccessor as au, TAG_TYPES as av, type TagStructure as aw, type UnitStyle as ax, type View as ay, createBooleanValue as az, HtmlTag as b, type HtmlAttributeValue as c, type SharedStyle as d, type HtmlTagOptions as e, type CssPlaceDescription as f, type CssLayoutBuilder as g, type CssStyleManagerType as h, HtmlStyle as i, type HlUnit as j, type CssManagerInstance as k, CssConfig as l, type LayoutRegisteredItem as m, type RelationShip as n, type StyleSelectors as o, type JQueryMethodType as p, type ScriptScope as q, type BorderOptions as r, type BreakpointKey as s, type BreakpointStyles as t, Breakpoints as u, type ButtonOptions as v, CSSAnimation as w, CSSBackground as x, CSSBorder as y, CSSColor as z };
|