@octane-xplat/bamboo 0.16.0 → 0.17.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/dist/config.js +105 -0
- package/dist/platform-output.js +161 -0
- package/dist/vite.js +92 -0
- package/package.json +10 -9
package/dist/config.js
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { preset as presetBase } from '@bamboocss/preset-base';
|
|
2
|
+
// Bamboo 1.56.2 has no flexWrap utility. Keep it outside this selected subset
|
|
3
|
+
// rather than promising a utility that cannot be generated.
|
|
4
|
+
const portableProperties = [
|
|
5
|
+
'alignItems',
|
|
6
|
+
'alignSelf',
|
|
7
|
+
'backgroundColor',
|
|
8
|
+
'borderColor',
|
|
9
|
+
'borderRadius',
|
|
10
|
+
'borderWidth',
|
|
11
|
+
'color',
|
|
12
|
+
'display',
|
|
13
|
+
'flexDirection',
|
|
14
|
+
'flexGrow',
|
|
15
|
+
'flexShrink',
|
|
16
|
+
'fontFamily',
|
|
17
|
+
'fontSize',
|
|
18
|
+
'fontWeight',
|
|
19
|
+
'gap',
|
|
20
|
+
'height',
|
|
21
|
+
'justifyContent',
|
|
22
|
+
'lineHeight',
|
|
23
|
+
'margin',
|
|
24
|
+
'marginBottom',
|
|
25
|
+
'marginLeft',
|
|
26
|
+
'marginRight',
|
|
27
|
+
'marginTop',
|
|
28
|
+
'maxHeight',
|
|
29
|
+
'maxWidth',
|
|
30
|
+
'minHeight',
|
|
31
|
+
'minWidth',
|
|
32
|
+
'padding',
|
|
33
|
+
'paddingBottom',
|
|
34
|
+
'paddingLeft',
|
|
35
|
+
'paddingRight',
|
|
36
|
+
'paddingTop',
|
|
37
|
+
'textAlign',
|
|
38
|
+
'width',
|
|
39
|
+
];
|
|
40
|
+
const colors = Object.fromEntries(['danger', 'onprimary', 'primary', 'surface', 'surface-secondary', 'text', 'text-secondary'].map((name) => [name, { value: `var(--color-${name})` }]));
|
|
41
|
+
const spacing = Object.fromEntries(['4'].map((name) => [name, { value: `var(--space-${name})` }]));
|
|
42
|
+
const radii = Object.fromEntries(['sm', 'md', 'lg', 'xl'].map((name) => [name, { value: `var(--radius-${name})` }]));
|
|
43
|
+
const portableUtilities = Object.fromEntries(portableProperties.map((property) => {
|
|
44
|
+
const config = presetBase.utilities[property];
|
|
45
|
+
if (!config) {
|
|
46
|
+
throw new Error(`@octane-xplat/bamboo: missing portable utility "${property}" in @bamboocss/preset-base`);
|
|
47
|
+
}
|
|
48
|
+
// Bamboo's default margin scale includes `auto`, which NativeScript
|
|
49
|
+
// ignores; expose token spacing only in the shared preset.
|
|
50
|
+
return [property, property.startsWith('margin') ? { ...config, values: 'spacing' } : config];
|
|
51
|
+
}));
|
|
52
|
+
const portableTheme = {
|
|
53
|
+
tokens: {
|
|
54
|
+
colors,
|
|
55
|
+
radii,
|
|
56
|
+
spacing,
|
|
57
|
+
},
|
|
58
|
+
};
|
|
59
|
+
// Compile through the framework CSS pipeline, rather than adding runtime
|
|
60
|
+
// ancestor selectors or selector specificity. These names also generate types.
|
|
61
|
+
const platformConditions = {
|
|
62
|
+
web: '@platform web',
|
|
63
|
+
mobile: '@platform mobile',
|
|
64
|
+
native: '@platform native',
|
|
65
|
+
ios: '@platform ios',
|
|
66
|
+
android: '@platform android',
|
|
67
|
+
visionos: '@platform visionos',
|
|
68
|
+
macos: '@platform macos',
|
|
69
|
+
windows: '@platform windows',
|
|
70
|
+
linux: '@platform linux',
|
|
71
|
+
gtk: '@platform gtk',
|
|
72
|
+
};
|
|
73
|
+
/**
|
|
74
|
+
* Utilities and tokens selected for the CSS subset shared by NativeScript and
|
|
75
|
+
* browsers. This intentionally omits Bamboo's full browser-oriented preset;
|
|
76
|
+
* apps can extend it when they have checked a property on their targets.
|
|
77
|
+
*/
|
|
78
|
+
export const xplatPortablePreset = {
|
|
79
|
+
name: '@octane-xplat/bamboo/portable',
|
|
80
|
+
conditions: platformConditions,
|
|
81
|
+
utilities: portableUtilities,
|
|
82
|
+
theme: portableTheme,
|
|
83
|
+
};
|
|
84
|
+
/**
|
|
85
|
+
* Bamboo defaults for apps using the shared Octane xplat stylesheet.
|
|
86
|
+
*
|
|
87
|
+
* Pass this object to `defineConfig` from `@bamboocss/dev`, then add the app's
|
|
88
|
+
* `include` and `outdir`. The shared UI stylesheet declares the matching layer
|
|
89
|
+
* order before `virtual:bamboo.css` is imported.
|
|
90
|
+
*/
|
|
91
|
+
export const xplatBambooConfig = {
|
|
92
|
+
preflight: false,
|
|
93
|
+
conditions: platformConditions,
|
|
94
|
+
cssVarRoot: ':root, .ns-root',
|
|
95
|
+
layers: {
|
|
96
|
+
reset: 'xplat.reset',
|
|
97
|
+
base: 'xplat.base',
|
|
98
|
+
tokens: 'xplat.tokens',
|
|
99
|
+
recipes: 'xplat.recipes',
|
|
100
|
+
utilities: 'xplat.utilities',
|
|
101
|
+
},
|
|
102
|
+
presets: [],
|
|
103
|
+
utilities: portableUtilities,
|
|
104
|
+
theme: portableTheme,
|
|
105
|
+
};
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import { posix } from 'node:path';
|
|
3
|
+
import MagicString from 'magic-string';
|
|
4
|
+
import remapping from '@ampproject/remapping';
|
|
5
|
+
/** Filter only after Bamboo's validation and restore content-addressed asset names. */
|
|
6
|
+
export function platformOutput() {
|
|
7
|
+
let compiler;
|
|
8
|
+
let ssr = false;
|
|
9
|
+
const adapted = new WeakSet();
|
|
10
|
+
return {
|
|
11
|
+
name: 'xplat-bamboo:platform-output',
|
|
12
|
+
enforce: 'post',
|
|
13
|
+
configResolved(config) {
|
|
14
|
+
ssr = Boolean(config.build.ssr);
|
|
15
|
+
compiler = config.plugins.find((plugin) => plugin.name === 'xplat-platform-css')?.api;
|
|
16
|
+
if (config.command === 'build') {
|
|
17
|
+
compiler?.defer('virtual:bamboo.css');
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
transform: {
|
|
21
|
+
order: 'pre',
|
|
22
|
+
handler(code, id) {
|
|
23
|
+
if (!id.split('?')[0].endsWith('virtual:bamboo.css') || !code.includes('@platform')) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
if (!compiler) {
|
|
27
|
+
this.error('@octane-xplat/bamboo: platform conditions require xplatCss(target) from @octane-xplat/cli/vite');
|
|
28
|
+
}
|
|
29
|
+
if (ssr || this.environment?.config.build.ssr) {
|
|
30
|
+
this.error('@octane-xplat/bamboo: platform conditions currently require a single renderer build; SSR generation is not supported');
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
options: {
|
|
35
|
+
order: 'post',
|
|
36
|
+
handler(input) {
|
|
37
|
+
const outputs = input.output;
|
|
38
|
+
for (const output of Array.isArray(outputs) ? outputs : outputs ? [outputs] : []) {
|
|
39
|
+
for (const plugin of (output.plugins ?? []).flat(Infinity)) {
|
|
40
|
+
if (!plugin?.name?.startsWith('bamboocss:output-finalizer:') || adapted.has(plugin)) {
|
|
41
|
+
continue;
|
|
42
|
+
}
|
|
43
|
+
const hook = plugin.generateBundle;
|
|
44
|
+
const handler = typeof hook === 'function' ? hook : hook?.handler;
|
|
45
|
+
if (!handler) {
|
|
46
|
+
throw new Error('@octane-xplat/bamboo: output finalizer has no generateBundle handler');
|
|
47
|
+
}
|
|
48
|
+
plugin.generateBundle = {
|
|
49
|
+
...(typeof hook === 'object' ? hook : {}),
|
|
50
|
+
async handler(options, bundle, isWrite) {
|
|
51
|
+
await handler.call(this, options, bundle, isWrite);
|
|
52
|
+
if (!compiler) {
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
const renamed = new Map();
|
|
56
|
+
for (const [key, asset] of Object.entries(bundle)) {
|
|
57
|
+
if (asset.type !== 'asset' || !asset.fileName.endsWith('.css')) {
|
|
58
|
+
continue;
|
|
59
|
+
}
|
|
60
|
+
const source = typeof asset.source === 'string'
|
|
61
|
+
? asset.source
|
|
62
|
+
: new TextDecoder().decode(asset.source);
|
|
63
|
+
const mapKey = `${asset.fileName}.map`;
|
|
64
|
+
const mapAsset = bundle[mapKey];
|
|
65
|
+
const previousMap = mapAsset?.type === 'asset' ? String(mapAsset.source) : undefined;
|
|
66
|
+
if (!source.includes('@platform')) {
|
|
67
|
+
continue;
|
|
68
|
+
}
|
|
69
|
+
const projected = compiler.project(source, asset.fileName, previousMap);
|
|
70
|
+
let filtered = projected.css;
|
|
71
|
+
if (filtered === source) {
|
|
72
|
+
continue;
|
|
73
|
+
}
|
|
74
|
+
const hash = createHash('sha256').update(filtered).digest('hex').slice(0, 16);
|
|
75
|
+
const next = asset.fileName.replace(/\.css$/, `.platform-${hash}.css`);
|
|
76
|
+
renamed.set(asset.fileName, next);
|
|
77
|
+
if (projected.map && previousMap) {
|
|
78
|
+
const nextMap = `${next}.map`;
|
|
79
|
+
const map = JSON.parse(projected.map);
|
|
80
|
+
map.file = posix.basename(next);
|
|
81
|
+
this.emitFile({ type: 'asset', fileName: nextMap, source: JSON.stringify(map) });
|
|
82
|
+
delete bundle[mapKey];
|
|
83
|
+
filtered += `
|
|
84
|
+
/*# sourceMappingURL=${posix.basename(nextMap)} */`;
|
|
85
|
+
}
|
|
86
|
+
this.emitFile({ type: 'asset', fileName: next, source: filtered });
|
|
87
|
+
delete bundle[key];
|
|
88
|
+
}
|
|
89
|
+
for (const file of Object.values(bundle)) {
|
|
90
|
+
const replace = (text) => {
|
|
91
|
+
for (const [old, next] of renamed) {
|
|
92
|
+
text = text.split(old).join(next);
|
|
93
|
+
const directory = posix.dirname(file.fileName);
|
|
94
|
+
text = text
|
|
95
|
+
.split(posix.relative(directory, old))
|
|
96
|
+
.join(posix.relative(directory, next));
|
|
97
|
+
}
|
|
98
|
+
return text;
|
|
99
|
+
};
|
|
100
|
+
if (file.type === 'chunk') {
|
|
101
|
+
const nextCode = replace(file.code);
|
|
102
|
+
if (nextCode !== file.code) {
|
|
103
|
+
const magic = new MagicString(file.code);
|
|
104
|
+
const replacements = new Map(renamed);
|
|
105
|
+
for (const [old, next] of renamed) {
|
|
106
|
+
replacements.set(posix.relative(posix.dirname(file.fileName), old), posix.relative(posix.dirname(file.fileName), next));
|
|
107
|
+
}
|
|
108
|
+
// Scan the original code once so overlapping full/relative names
|
|
109
|
+
// cannot apply two edits to the same source-map span.
|
|
110
|
+
for (let index = 0; index < file.code.length; index++) {
|
|
111
|
+
const found = [...replacements].find(([old]) => file.code.startsWith(old, index));
|
|
112
|
+
if (!found) {
|
|
113
|
+
continue;
|
|
114
|
+
}
|
|
115
|
+
magic.overwrite(index, index + found[0].length, found[1]);
|
|
116
|
+
index += found[0].length - 1;
|
|
117
|
+
}
|
|
118
|
+
file.code = magic.toString();
|
|
119
|
+
if (file.map) {
|
|
120
|
+
const combined = remapping([
|
|
121
|
+
magic.generateMap({ source: file.fileName, hires: 'boundary' }),
|
|
122
|
+
file.map,
|
|
123
|
+
], () => null);
|
|
124
|
+
const encoded = combined.toString();
|
|
125
|
+
file.map = Object.assign(combined, {
|
|
126
|
+
toUrl: () => `data:application/json;charset=utf-8;base64,${Buffer.from(encoded).toString('base64')}`,
|
|
127
|
+
});
|
|
128
|
+
const mapFile = bundle[`${file.fileName}.map`];
|
|
129
|
+
if (mapFile?.type === 'asset') {
|
|
130
|
+
mapFile.source = encoded;
|
|
131
|
+
}
|
|
132
|
+
if (file.code.includes('//# sourceMappingURL=data:')) {
|
|
133
|
+
file.code =
|
|
134
|
+
file.code.replace(/\n?\/\/# sourceMappingURL=data:application\/json[^\n]*$/, '') +
|
|
135
|
+
`
|
|
136
|
+
//# sourceMappingURL=${file.map.toUrl()}`;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
const refs = file;
|
|
141
|
+
if (refs.referencedFiles) {
|
|
142
|
+
refs.referencedFiles = refs.referencedFiles.map(replace);
|
|
143
|
+
}
|
|
144
|
+
const metadata = file.viteMetadata;
|
|
145
|
+
if (metadata?.importedCss) {
|
|
146
|
+
metadata.importedCss = new Set([...metadata.importedCss].map(replace));
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
else if (typeof file.source === 'string') {
|
|
150
|
+
file.source = replace(file.source);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
},
|
|
154
|
+
};
|
|
155
|
+
adapted.add(plugin);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
},
|
|
159
|
+
},
|
|
160
|
+
};
|
|
161
|
+
}
|
package/dist/vite.js
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { bamboocss } from '@bamboocss/vite';
|
|
2
|
+
import { platformOutput } from "./platform-output.js";
|
|
3
|
+
function runBeforeNativeCss(plugin, anchor) {
|
|
4
|
+
const hook = plugin?.generateBundle;
|
|
5
|
+
if (plugin && typeof hook === 'function') {
|
|
6
|
+
plugin.generateBundle = { order: 'pre', handler: hook };
|
|
7
|
+
}
|
|
8
|
+
else if (hook && typeof hook === 'object' && typeof hook.handler === 'function') {
|
|
9
|
+
hook.order = 'pre';
|
|
10
|
+
}
|
|
11
|
+
else {
|
|
12
|
+
throw new Error(`@octane-xplat/bamboo: native CSS adaptation requires ${anchor} with a generateBundle handler`);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Create Bamboo's Vite plugins for an Octane xplat app.
|
|
17
|
+
*
|
|
18
|
+
* Pass `cwd` and `configPath` when Bamboo's source/config root differs from
|
|
19
|
+
* Vite's app root, as it does in the shared harness.
|
|
20
|
+
*/
|
|
21
|
+
export function xplatBamboo({ native = false, ...options } = {}) {
|
|
22
|
+
const plugins = bamboocss(options);
|
|
23
|
+
if (native) {
|
|
24
|
+
// Let Bamboo prune and validate the emitted asset before NativeScript's
|
|
25
|
+
// main-entry hook serializes it into the native bootstrap and removes it.
|
|
26
|
+
const cssPlugin = plugins.find((plugin) => plugin.name === 'bamboocss:css');
|
|
27
|
+
runBeforeNativeCss(cssPlugin, 'bamboocss:css');
|
|
28
|
+
let isBuild = false;
|
|
29
|
+
plugins.push({
|
|
30
|
+
name: 'xplat-bamboo:nativescript-entry-graph',
|
|
31
|
+
enforce: 'post',
|
|
32
|
+
configResolved(config) {
|
|
33
|
+
isBuild = config.command === 'build';
|
|
34
|
+
},
|
|
35
|
+
buildEnd(error) {
|
|
36
|
+
if (!isBuild || error) {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
// Inspect the graph, including cached modules in watch builds. A
|
|
40
|
+
// custom entry that already imports the sheet needs no injection.
|
|
41
|
+
if (![...this.getModuleIds()].some((id) => id.split('?')[0] === '\0virtual:bamboo.css')) {
|
|
42
|
+
this.error('@octane-xplat/bamboo: native entry graph is missing virtual:bamboo.css; expected virtual:entry-with-polyfills or an explicit stylesheet import');
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
transform(code, id) {
|
|
46
|
+
// @nativescript/vite builds from a generated entry
|
|
47
|
+
// (`virtual:entry-with-polyfills`). Under HMR that entry boots
|
|
48
|
+
// the app over HTTP instead of statically importing the app's
|
|
49
|
+
// main module, so `import 'virtual:bamboo.css'` there never
|
|
50
|
+
// enters the bundle's module graph — while class values still
|
|
51
|
+
// compile, tripping bamboocss's entry-graph check at buildEnd.
|
|
52
|
+
// Import the stylesheet from the generated entry itself so it
|
|
53
|
+
// is in the graph in every mode; the emitted asset then flows
|
|
54
|
+
// through the same generateBundle path as every other .css.
|
|
55
|
+
if (id !== '\0virtual:entry-with-polyfills' || code.includes('virtual:bamboo.css')) {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
return { code: `${code}\nimport 'virtual:bamboo.css';\n`, map: null };
|
|
59
|
+
},
|
|
60
|
+
});
|
|
61
|
+
plugins.push({
|
|
62
|
+
name: 'xplat-bamboo:nativescript-output',
|
|
63
|
+
enforce: 'post',
|
|
64
|
+
options: {
|
|
65
|
+
order: 'post',
|
|
66
|
+
handler(inputOptions) {
|
|
67
|
+
const options = inputOptions;
|
|
68
|
+
const outputs = Array.isArray(options.output)
|
|
69
|
+
? options.output
|
|
70
|
+
: options.output
|
|
71
|
+
? [options.output]
|
|
72
|
+
: [];
|
|
73
|
+
// Upstream installs one finalizer per configured output. With no
|
|
74
|
+
// output configured its options hook deliberately installs none.
|
|
75
|
+
for (const output of outputs) {
|
|
76
|
+
const finalizers = (output.plugins ?? [])
|
|
77
|
+
.flat(Infinity)
|
|
78
|
+
.filter((plugin) => Boolean(plugin && plugin.name?.startsWith('bamboocss:output-finalizer:')));
|
|
79
|
+
if (!finalizers.length) {
|
|
80
|
+
throw new Error('@octane-xplat/bamboo: native CSS adaptation requires a bamboocss:output-finalizer:* plugin for each configured output');
|
|
81
|
+
}
|
|
82
|
+
for (const finalizer of finalizers) {
|
|
83
|
+
runBeforeNativeCss(finalizer, finalizer.name);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
},
|
|
87
|
+
},
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
plugins.push(platformOutput());
|
|
91
|
+
return plugins;
|
|
92
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@octane-xplat/bamboo",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.17.0",
|
|
4
4
|
"description": "Bamboo CSS integration defaults for Octane xplat apps",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"bamboo",
|
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
"directory": "packages/bamboo"
|
|
18
18
|
},
|
|
19
19
|
"files": [
|
|
20
|
+
"dist",
|
|
20
21
|
"src",
|
|
21
22
|
"types",
|
|
22
23
|
"!src/**/*.test.*",
|
|
@@ -26,38 +27,38 @@
|
|
|
26
27
|
"exports": {
|
|
27
28
|
".": {
|
|
28
29
|
"types": "./types/generated/config.d.ts",
|
|
29
|
-
"default": "./
|
|
30
|
+
"default": "./dist/config.js"
|
|
30
31
|
},
|
|
31
32
|
"./config": {
|
|
32
33
|
"types": "./types/generated/config.d.ts",
|
|
33
|
-
"default": "./
|
|
34
|
+
"default": "./dist/config.js"
|
|
34
35
|
},
|
|
35
36
|
"./vite": {
|
|
36
37
|
"types": "./types/generated/vite.d.ts",
|
|
37
|
-
"default": "./
|
|
38
|
+
"default": "./dist/vite.js"
|
|
38
39
|
}
|
|
39
40
|
},
|
|
40
41
|
"publishConfig": {
|
|
41
42
|
"access": "public"
|
|
42
43
|
},
|
|
43
44
|
"dependencies": {
|
|
45
|
+
"@ampproject/remapping": "2.3.0",
|
|
44
46
|
"@bamboocss/preset-base": "1.56.2",
|
|
45
47
|
"@bamboocss/types": "1.56.2",
|
|
46
48
|
"@bamboocss/vite": "1.56.2",
|
|
47
|
-
"magic-string": "0.30.21"
|
|
48
|
-
"@ampproject/remapping": "2.3.0"
|
|
49
|
+
"magic-string": "0.30.21"
|
|
49
50
|
},
|
|
50
51
|
"devDependencies": {
|
|
51
|
-
"typescript": "5.9.3",
|
|
52
52
|
"@bamboocss/dev": "1.56.2",
|
|
53
|
-
"@octane-xplat/cli": "0.
|
|
53
|
+
"@octane-xplat/cli": "0.17.0",
|
|
54
|
+
"typescript": "5.9.3"
|
|
54
55
|
},
|
|
55
56
|
"peerDependencies": {
|
|
56
57
|
"vite": ">=5"
|
|
57
58
|
},
|
|
58
59
|
"scripts": {
|
|
59
60
|
"test:packed": "node tests/packed-consumer.mjs",
|
|
60
|
-
"typegen": "tsc -p tsconfig.
|
|
61
|
+
"typegen": "tsc -p tsconfig.build.json",
|
|
61
62
|
"test": "node --test tests/platform.test.mjs"
|
|
62
63
|
}
|
|
63
64
|
}
|