@lipemat/js-boilerplate-shared 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,45 @@
1
+ import { resolve } from 'path';
2
+ import { readFileSync, realpathSync } from 'node:fs';
3
+ function readJsonFile(filePath) {
4
+ return JSON.parse(readFileSync(filePath, 'utf8'));
5
+ }
6
+ const workingDirectory = realpathSync(process.cwd());
7
+ const defaults = {
8
+ brotliFiles: true,
9
+ cssTsFiles: true,
10
+ jsPath: './js',
11
+ packageDirectory: workingDirectory,
12
+ shortCssClasses: true,
13
+ url: 'http://localhost',
14
+ };
15
+ let packageConfig = readJsonFile(resolve(workingDirectory, 'package.json'));
16
+ packageConfig = { ...defaults, ...packageConfig };
17
+ packageConfig.workingDirectory = packageConfig.jsPath !== '' ? resolve(packageConfig.jsPath) : workingDirectory;
18
+ try {
19
+ const localConfig = readJsonFile(resolve(workingDirectory, './local-config.json'));
20
+ packageConfig = { ...packageConfig, ...localConfig };
21
+ }
22
+ catch {
23
+ }
24
+ /**
25
+ * Helper function to get the results of `packageConfig`.
26
+ *
27
+ * - Allows mocking the results of `packageConfig` for testing.
28
+ * - Allows getting the config through a callback instead of an import.
29
+ */
30
+ export function getPackageConfig() {
31
+ return { ...packageConfig, ...modifications };
32
+ }
33
+ /**
34
+ * Modify the `packageConfig` object.
35
+ *
36
+ * - Here mainly for testing purposes.
37
+ */
38
+ let modifications = {};
39
+ export function modifyPackageConfig(additions) {
40
+ modifications = additions;
41
+ }
42
+ export function resetPackageConfig() {
43
+ modifications = {};
44
+ }
45
+ //# sourceMappingURL=package-config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"package-config.js","sourceRoot":"","sources":["package-config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,OAAO,EAAC,MAAM,MAAM,CAAC;AAC7B,OAAO,EAAC,YAAY,EAAE,YAAY,EAAC,MAAM,SAAS,CAAC;AAEnD,SAAS,YAAY,C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97 @@
1
+ import {resolve} from 'path';
2
+ import {readFileSync, realpathSync} from 'node:fs';
3
+
4
+ function readJsonFile<T>( filePath: string ): T {
5
+ return JSON.parse( readFileSync( filePath, 'utf8' ) ) as T;
6
+ }
7
+
8
+ export interface PackageConfig {
9
+ author?: string;
10
+ brotliFiles: boolean;
11
+ certificates?: Certificates;
12
+ combinedJson: boolean;
13
+ cssTsFiles: boolean;
14
+ css_folder: string;
15
+ default: PackageConfig;
16
+ dependencies: Dependencies;
17
+ description?: string;
18
+ devDependencies: Dependencies;
19
+ getPackageConfig: () => PackageConfig;
20
+ jsPath: string;
21
+ license?: string;
22
+ name?: string;
23
+ packageDirectory: string;
24
+ packageManager?: string;
25
+ resolutions?: Dependencies;
26
+ scripts: Partial<Scripts>;
27
+ shortCssClasses: boolean | {
28
+ js: boolean;
29
+ pcss: boolean;
30
+ };
31
+ url: string;
32
+ version?: string;
33
+ workingDirectory: string;
34
+ }
35
+
36
+ export interface Dependencies {
37
+ [ name: string ]: string;
38
+ }
39
+
40
+ export interface Certificates {
41
+ cert: string;
42
+ key: string;
43
+ }
44
+
45
+ export interface Scripts {
46
+ browserslist: string;
47
+ dist: string;
48
+ lint: string;
49
+ postinstall: string;
50
+ start: string;
51
+ test: string;
52
+ }
53
+
54
+
55
+ const workingDirectory = realpathSync( process.cwd() );
56
+ const defaults: Partial<PackageConfig> = {
57
+ brotliFiles: true,
58
+ cssTsFiles: true,
59
+ jsPath: './js',
60
+ packageDirectory: workingDirectory,
61
+ shortCssClasses: true,
62
+ url: 'http://localhost',
63
+ };
64
+
65
+ let packageConfig: PackageConfig = readJsonFile<PackageConfig>( resolve( workingDirectory, 'package.json' ) );
66
+ packageConfig = {...defaults, ...packageConfig};
67
+ packageConfig.workingDirectory = packageConfig.jsPath !== '' ? resolve( packageConfig.jsPath ) : workingDirectory;
68
+
69
+ try {
70
+ const localConfig = readJsonFile<Partial<PackageConfig>>( resolve( workingDirectory, './local-config.json' ) );
71
+ packageConfig = {...packageConfig, ...localConfig};
72
+ } catch {
73
+ }
74
+
75
+ /**
76
+ * Helper function to get the results of `packageConfig`.
77
+ *
78
+ * - Allows mocking the results of `packageConfig` for testing.
79
+ * - Allows getting the config through a callback instead of an import.
80
+ */
81
+ export function getPackageConfig(): PackageConfig {
82
+ return {...packageConfig, ...modifications};
83
+ }
84
+
85
+ /**
86
+ * Modify the `packageConfig` object.
87
+ *
88
+ * - Here mainly for testing purposes.
89
+ */
90
+ let modifications: Partial<PackageConfig> = {};
91
+
92
+ export function modifyPackageConfig( additions: Partial<PackageConfig> ): void {
93
+ modifications = additions;
94
+ }
95
+ export function resetPackageConfig(): void {
96
+ modifications = {};
97
+ }
@@ -0,0 +1,135 @@
1
+ import { resolve } from 'path';
2
+ import { existsSync } from 'fs';
3
+ import postcssPresetEnv, {} from 'postcss-preset-env';
4
+ import { getExtensionsConfig } from './config.js';
5
+ import PrettyPlugin from '../lib/postcss-pretty.js';
6
+ import cleanCSS from '../lib/postcss-clean.js';
7
+ import { createRequire } from 'node:module';
8
+ import { getPackageConfig } from './package-config.js';
9
+ import { getBrowsersList } from './browserslist.js';
10
+ const requireModule = createRequire(import.meta.url);
11
+ const packageConfig = getPackageConfig();
12
+ function isPluginsArray(value) {
13
+ return Array.isArray(value);
14
+ }
15
+ /**
16
+ * Provide CSS properties and media queries to all postcss plugins.
17
+ *
18
+ * If a media-queries files exist, automatically load them.
19
+ * If CSS variables exist, automatically load them.
20
+ *
21
+ * 1. pcss/globals/variables.pcss
22
+ * 2. js/src/pcss/variables.pcss
23
+ * 3. pcss/globals/media-queries.pcss
24
+ * 4. js/src/pcss/media-queries.pcss
25
+ */
26
+ const externalFiles = [];
27
+ [
28
+ resolve(packageConfig.packageDirectory, 'pcss/globals/media-queries.pcss'),
29
+ resolve(packageConfig.packageDirectory, 'pcss/globals/variables.pcss'),
30
+ resolve(packageConfig.workingDirectory, 'src/pcss/media-queries.pcss'),
31
+ resolve(packageConfig.workingDirectory, 'src/pcss/variables.pcss'),
32
+ ].forEach((possibleFile) => {
33
+ if (existsSync(possibleFile)) {
34
+ externalFiles.push(possibleFile);
35
+ }
36
+ });
37
+ function getPresetEnvConfig() {
38
+ const presetEnv = {
39
+ browsers: [...getBrowsersList()],
40
+ features: {},
41
+ };
42
+ // Get a list of included postcss plugins based on the browser list.
43
+ const processor = postcssPresetEnv(presetEnv);
44
+ const includedPlugins = processor.plugins.map((plugin) => {
45
+ return 'postcssPlugin' in plugin ? plugin.postcssPlugin : '';
46
+ });
47
+ if ('object' === typeof presetEnv.features && includedPlugins.includes('postcss-focus-visible')) {
48
+ presetEnv.features['focus-visible-pseudo-class'] = {
49
+ /**
50
+ * Fixes `focus-visible` feature for CSS modules.
51
+ *
52
+ * Only needed if our browser list includes non-supported browsers
53
+ * such as Safari 15.3 and below.
54
+ *
55
+ * Requires `focus-visible` polyfill to be loaded externally.
56
+ * Most will often need it site wide on pages, which do and don't use the JS app.
57
+ *
58
+ * @link https://unpkg.com/focus-visible@5.2.0/dist/focus-visible.min.js
59
+ */
60
+ replaceWith: ':global(.focus-visible)',
61
+ };
62
+ }
63
+ return presetEnv;
64
+ }
65
+ export function assemblePostCssConfig(env) {
66
+ /**
67
+ * Put the config together.
68
+ */
69
+ const config = {
70
+ plugins: [
71
+ requireModule('@csstools/postcss-global-data')({
72
+ files: externalFiles,
73
+ }),
74
+ requireModule('postcss-import')({
75
+ skipDuplicates: false,
76
+ }),
77
+ requireModule('postcss-custom-media'),
78
+ requireModule('postcss-nested'),
79
+ postcssPresetEnv(getPresetEnvConfig()),
80
+ requireModule('postcss-color-mod-function'),
81
+ requireModule('postcss-sort-media-queries')({
82
+ onlyTopLevel: true,
83
+ sort: 'mobile-first',
84
+ configuration: {
85
+ unitlessMqAlwaysFirst: true,
86
+ },
87
+ }),
88
+ ],
89
+ parser: 'postcss-scss',
90
+ };
91
+ if (isPluginsArray(config.plugins)) {
92
+ if ('production' === env) {
93
+ // For production, we minify it.
94
+ config.plugins.push(cleanCSS({
95
+ level: 2,
96
+ }));
97
+ }
98
+ else {
99
+ config.plugins.push(PrettyPlugin);
100
+ config.sourceMap = true;
101
+ }
102
+ }
103
+ return config;
104
+ }
105
+ /**
106
+ * Return the postcss config merged with any extensions
107
+ * or local config.
108
+ *
109
+ * @see getConfig from @lipemat/js-boilerplate
110
+ */
111
+ export function getPostCSSConfig(env) {
112
+ const postCssConfig = assemblePostCssConfig(env);
113
+ let mergedConfig = { ...postCssConfig, ...getExtensionsConfig('postcss.config', postCssConfig) };
114
+ try {
115
+ let localConfig = createRequire(import.meta.url)(resolve(getPackageConfig().packageDirectory, 'config', 'postcss.config'));
116
+ if ('default' in localConfig) {
117
+ localConfig = localConfig.default;
118
+ }
119
+ if ('function' === typeof localConfig) {
120
+ mergedConfig = { ...mergedConfig, ...localConfig(mergedConfig) };
121
+ }
122
+ else {
123
+ mergedConfig = { ...mergedConfig, ...localConfig };
124
+ }
125
+ }
126
+ catch (e) {
127
+ if (e instanceof Error) {
128
+ if (!('code' in e) || ('MODULE_NOT_FOUND' !== e.code && 'ERR_MODULE_NOT_FOUND' !== e.code)) {
129
+ console.error(e);
130
+ }
131
+ }
132
+ }
133
+ return mergedConfig;
134
+ }
135
+ //# sourceMappingURL=postcss-config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"postcss-config.js","sourceRoot":"","sources":["postcss-config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,OAAO,EAAC,MAAM,MAAM,CAAC;AAC7B,OAAO,EAAC,UAAU,EAAC,MAAM,IAAI,CAAC;AAC9B,OAAO,gBAAgB,EAAE,EAAoB,MAAM,oBAAoB,CAAC;AAExE,OAAO,EAAC,mBAAmB,EAAC,MAAM,aAAa,CAAC;AAChD,OAAO,YAAY,MAAM,0BAA0B,CAAC;AACpD,OAAO,QAAQ,MAAM,yBAAyB,CAAC;AAI/C,OAAO,EAAC,aAAa,EAAC,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAC,gBAAgB,EAAC,MAAM,qBAAqB,CAAC;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,GAAQ;IACzC,MAAM,aAAa,GAAG,qBAAqB,CAAE,GAAG,CAAE,CAAC;IACnD,IAAI,YAAY,GAAkB,EAAC,GAAG,aAAa,EAAE,GAAG,mBAAmB,CAAiB,gBAAgB,EAAE,aAAa,CAAE,EAAC,CAAC;IAE/H,IAAI,CAAC;QACJ,IAAI,WAAW,GAAG,aAAa,CAAE,MAAM,CAAC,IAAI,CAAC,GAAG,CAAE,CAAE,OAAO,CAAE,gBAAgB,EAAE,CAAC,gBAAgB,EAAE,QAAQ,EAAE,gBAAgB,CAAE,CAAE,CAAC;QACjI,IAAK,SAAS,IAAI,WAAW,EAAG,CAAC;YAChC,WAAW,GAAG,WAAW,CAAC,OAAO,CAAC;QACnC,CAAC;QAED,IAAK,UAAU,KAAK,OAAO,WAAW,EAAG,CAAC;YACzC,YAAY,GAAG,EAAC,GAAG,YAAY,EAAE,GAAG,WAAW,CAAE,YAAY,CAAE,EAAC,CAAC;QAClE,CAAC;aAAM,CAAC;YACP,YAAY,GAAG,EAAC,GAAG,YAAY,EAAE,GAAG,WAAW,EAAC,CAAC;QAClD,CAAC;IACF,CAAC;IAAC,OAAQ,CAAC,EAAG,CAAC;QACd,IAAK,CAAC,YAAY,KAAK,EAAG,CAAC;YAC1B,IAAK,CAAE,CAAE,MAAM,IAAI,CAAC,CAAE,IAAI,CAAE,kBAAkB,KAAK,CAAC,CAAC,IAAI,IAAI,sBAAsB,KAAK,CAAC,CAAC,IAAI,CAAE,EAAG,CAAC;gBACnG,OAAO,CAAC,KAAK,CAAE,CAAC,CAAE,CAAC;YACpB,CAAC;QACF,CAAC;IACF,CAAC;IACD,OAAO,YAAY,CAAC;AACrB,CAAC"}
@@ -0,0 +1,159 @@
1
+ import {resolve} from 'path';
2
+ import {existsSync} from 'fs';
3
+ import postcssPresetEnv, {type pluginOptions} from 'postcss-preset-env';
4
+ import type Processor from 'postcss/lib/processor';
5
+ import {getExtensionsConfig} from './config.js';
6
+ import PrettyPlugin from '../lib/postcss-pretty.js';
7
+ import cleanCSS from '../lib/postcss-clean.js';
8
+ import type {Config, ConfigPlugin} from 'postcss-load-config';
9
+ import type {LoaderContext} from 'webpack';
10
+ import type {Plugin} from 'postcss';
11
+ import {createRequire} from 'node:module';
12
+ import {getPackageConfig} from './package-config.js';
13
+ import {getBrowsersList} from './browserslist.js';
14
+
15
+
16
+ export type PostcssConfig = Config & Partial<LoaderContext<Config>> & {
17
+ plugins: Plugin[];
18
+ parser: string;
19
+ }
20
+
21
+ export type ENV = 'development' | 'test' | 'production';
22
+
23
+ const requireModule = createRequire( import.meta.url );
24
+ const packageConfig = getPackageConfig();
25
+
26
+ function isPluginsArray( value: ConfigPlugin[] | false ): value is ConfigPlugin[] {
27
+ return Array.isArray( value );
28
+ }
29
+
30
+
31
+ /**
32
+ * Provide CSS properties and media queries to all postcss plugins.
33
+ *
34
+ * If a media-queries files exist, automatically load them.
35
+ * If CSS variables exist, automatically load them.
36
+ *
37
+ * 1. pcss/globals/variables.pcss
38
+ * 2. js/src/pcss/variables.pcss
39
+ * 3. pcss/globals/media-queries.pcss
40
+ * 4. js/src/pcss/media-queries.pcss
41
+ */
42
+ const externalFiles: string[] = [];
43
+ [
44
+ resolve( packageConfig.packageDirectory, 'pcss/globals/media-queries.pcss' ),
45
+ resolve( packageConfig.packageDirectory, 'pcss/globals/variables.pcss' ),
46
+ resolve( packageConfig.workingDirectory, 'src/pcss/media-queries.pcss' ),
47
+ resolve( packageConfig.workingDirectory, 'src/pcss/variables.pcss' ),
48
+ ].forEach( ( possibleFile: string ) => {
49
+ if ( existsSync( possibleFile ) ) {
50
+ externalFiles.push( possibleFile );
51
+ }
52
+ } );
53
+
54
+
55
+ function getPresetEnvConfig(): pluginOptions {
56
+ const presetEnv: pluginOptions = {
57
+ browsers: [ ...getBrowsersList( ) ],
58
+ features: {},
59
+ };
60
+
61
+ // Get a list of included postcss plugins based on the browser list.
62
+ const processor = postcssPresetEnv( presetEnv ) as Processor;
63
+ const includedPlugins: string[] = processor.plugins.map( ( plugin: Processor['plugins'][number] ) => {
64
+ return 'postcssPlugin' in plugin ? plugin.postcssPlugin : '';
65
+ } );
66
+
67
+
68
+ if ( 'object' === typeof presetEnv.features && includedPlugins.includes( 'postcss-focus-visible' ) ) {
69
+ presetEnv.features[ 'focus-visible-pseudo-class' ] = {
70
+ /**
71
+ * Fixes `focus-visible` feature for CSS modules.
72
+ *
73
+ * Only needed if our browser list includes non-supported browsers
74
+ * such as Safari 15.3 and below.
75
+ *
76
+ * Requires `focus-visible` polyfill to be loaded externally.
77
+ * Most will often need it site wide on pages, which do and don't use the JS app.
78
+ *
79
+ * @link https://unpkg.com/focus-visible@5.2.0/dist/focus-visible.min.js
80
+ */
81
+ replaceWith: ':global(.focus-visible)',
82
+ };
83
+ }
84
+ return presetEnv;
85
+ }
86
+
87
+
88
+ export function assemblePostCssConfig( env: ENV ): PostcssConfig {
89
+ /**
90
+ * Put the config together.
91
+ */
92
+ const config: PostcssConfig = {
93
+ plugins: [
94
+ requireModule( '@csstools/postcss-global-data' )( {
95
+ files: externalFiles,
96
+ } ),
97
+ requireModule( 'postcss-import' )( {
98
+ skipDuplicates: false,
99
+ } ),
100
+ requireModule( 'postcss-custom-media' ),
101
+ requireModule( 'postcss-nested' ),
102
+ postcssPresetEnv( getPresetEnvConfig() ),
103
+ requireModule( 'postcss-color-mod-function' ),
104
+ requireModule( 'postcss-sort-media-queries' )( {
105
+ onlyTopLevel: true,
106
+ sort: 'mobile-first',
107
+ configuration: {
108
+ unitlessMqAlwaysFirst: true,
109
+ },
110
+ } ),
111
+ ],
112
+ parser: 'postcss-scss',
113
+ };
114
+
115
+
116
+ if ( isPluginsArray( config.plugins ) ) {
117
+ if ( 'production' === env ) {
118
+ // For production, we minify it.
119
+ config.plugins.push( cleanCSS( {
120
+ level: 2,
121
+ } ) );
122
+ } else {
123
+ config.plugins.push( PrettyPlugin );
124
+ config.sourceMap = true;
125
+ }
126
+ }
127
+ return config;
128
+ }
129
+
130
+ /**
131
+ * Return the postcss config merged with any extensions
132
+ * or local config.
133
+ *
134
+ * @see getConfig from @lipemat/js-boilerplate
135
+ */
136
+ export function getPostCSSConfig( env: ENV ): PostcssConfig {
137
+ const postCssConfig = assemblePostCssConfig( env );
138
+ let mergedConfig: PostcssConfig = {...postCssConfig, ...getExtensionsConfig<PostcssConfig>( 'postcss.config', postCssConfig )};
139
+
140
+ try {
141
+ let localConfig = createRequire( import.meta.url )( resolve( getPackageConfig().packageDirectory, 'config', 'postcss.config' ) );
142
+ if ( 'default' in localConfig ) {
143
+ localConfig = localConfig.default;
144
+ }
145
+
146
+ if ( 'function' === typeof localConfig ) {
147
+ mergedConfig = {...mergedConfig, ...localConfig( mergedConfig )};
148
+ } else {
149
+ mergedConfig = {...mergedConfig, ...localConfig};
150
+ }
151
+ } catch ( e ) {
152
+ if ( e instanceof Error ) {
153
+ if ( ! ( 'code' in e ) || ( 'MODULE_NOT_FOUND' !== e.code && 'ERR_MODULE_NOT_FOUND' !== e.code ) ) {
154
+ console.error( e );
155
+ }
156
+ }
157
+ }
158
+ return mergedConfig;
159
+ }
@@ -0,0 +1,83 @@
1
+ /**
2
+ * Given a string, returns a new string with dash separators converted to
3
+ * camel-case equivalent. This is not as aggressive as `_.camelCase`,
4
+ * which would also upper-case letters following numbers.
5
+ *
6
+ * @param {string} slug Input dash-delimited string.
7
+ *
8
+ * @return {string} Camel-cased string.
9
+ */
10
+ const camelCaseDash = (slug) => slug.replace(/-([a-z])/g, (match, letter) => letter.toUpperCase());
11
+ /**
12
+ * Convert all wp libraries to the global variable, which are
13
+ * available in WP core when the corresponding libraries are cued.
14
+ *
15
+ * @type {{wpExternals: *}}
16
+ */
17
+ const wpExports = [
18
+ 'a11y',
19
+ 'annotations',
20
+ 'api-fetch',
21
+ 'autop',
22
+ 'blob',
23
+ 'block-directory',
24
+ 'block-editor',
25
+ 'block-library',
26
+ 'block-serialization-default-parser',
27
+ 'blocks',
28
+ 'commands',
29
+ 'components',
30
+ 'compose',
31
+ 'core-data',
32
+ 'data',
33
+ 'data-controls',
34
+ 'date',
35
+ 'deprecated',
36
+ 'dom',
37
+ 'dom-ready',
38
+ 'edit-post',
39
+ 'edit-site',
40
+ 'editor',
41
+ 'element',
42
+ 'escape-html',
43
+ 'hooks',
44
+ 'html-entities',
45
+ 'i18n',
46
+ 'is-shallow-equal',
47
+ 'keyboard-shortcuts',
48
+ 'keycodes',
49
+ 'list-reusable-blocks',
50
+ 'media-utils',
51
+ 'notices',
52
+ 'nux',
53
+ 'plugins',
54
+ 'primitives',
55
+ 'priority-queue',
56
+ 'redux-routine',
57
+ 'reusable-blocks',
58
+ 'rich-text',
59
+ 'server-side-render',
60
+ 'shortcode',
61
+ 'token-list',
62
+ 'url',
63
+ 'utils',
64
+ 'viewport',
65
+ 'warning',
66
+ 'wordcount',
67
+ ].reduce((externals, name) => ({
68
+ ...externals,
69
+ [`@wordpress/${name}`]: `window.wp?.${camelCaseDash(name)}`,
70
+ }), {
71
+ lodash: 'lodash',
72
+ wp: 'wp',
73
+ react: 'React',
74
+ 'react-dom': 'ReactDOM',
75
+ 'react-refresh/runtime': 'ReactRefreshRuntime',
76
+ jquery: 'jQuery',
77
+ tinymce: 'tinymce',
78
+ moment: 'moment',
79
+ 'react/jsx-runtime': 'ReactJSXRuntime',
80
+ backbone: 'Backbone',
81
+ });
82
+ export default wpExports;
83
+ //# sourceMappingURL=wp-externals.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wp-externals.js","sourceRoot":"","sources":["wp-externals.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,MAAM,aAAa,GAAG,CAAE,IAAY,EAAW,EAAE,CAAC,IAAI,CAAC,OAAO,CAAE,WAAW,EAAE,CAAE,KAAK,EAAE,MAAM,EAAG,EAAE,CAAC,MAAM,CAAC,WAAW,EAAE,CAAE,CAAC;AAEzH;;;;;GAKG;AACH,MAAM,SAAS,GAAiC;IAC/C,MAAM;IACN,aAAa;IACb,WAAW;IACX,OAAO;IACP,MAAM;IACN,iBAAiB;IACjB,cAAc;IACd,eAAe;IACf,oCAAoC;IACpC,QAAQ;IACR,UAAU;IACV,YAAY;IACZ,SAAS;IACT,WAAW;IACX,MAAM;IACN,eAAe;IACf,MAAM;IACN,YAAY;IACZ,KAAK;IACL,WAAW;IACX,WAAW;IACX,WAAW;IACX,QAAQ;IACR,SAAS;IACT,aAAa;IACb,OAAO;IACP,eAAe;IACf,MAAM;IACN,kBAAkB;IAClB,oBAAoB;IACpB,UAAU;IACV,sBAAsB;IACtB,aAAa;IACb,SAAS;IACT,KAAK;IACL,SAAS;IACT,YAAY;IACZ,gBAAgB;IAChB,eAAe;IACf,iBAAiB;IACjB,WAAW;IACX,oBAAoB;IACpB,WAAW;IACX,YAAY;IACZ,KAAK;IACL,OAAO;IACP,UAAU;IACV,SAAS;IACT,WAAW;CACX,CAAC,MAAM,CACP,CAAE,SAAS,EAAE,IAAI,EAAG,EAAE,CAAC,CAAE;IACxB,GAAG,SAAS;IACZ,CAAE,cAAc,IAAI,EAAE,CAAE,EAAE,cAAc,aAAa,CAAE,IAAI,CAAE,EAAE;CAC/D,CAAE,EACH;IACC,MAAM,EAAE,QAAQ;IAChB,EAAE,EAAE,IAAI;IACR,KAAK,EAAE,OAAO;IACd,WAAW,EAAE,UAAU;IACvB,uBAAuB,EAAE,qBAAqB;IAC9C,MAAM,EAAE,QAAQ;IAChB,OAAO,EAAE,SAAS;IAClB,MAAM,EAAE,QAAQ;IAChB,mBAAmB,EAAE,iBAAiB;IACtC,QAAQ,EAAE,UAAU;CACpB,CACD,CAAC;AAEF,eAAe,SAAS,CAAC"}
@@ -0,0 +1,87 @@
1
+ /**
2
+ * Given a string, returns a new string with dash separators converted to
3
+ * camel-case equivalent. This is not as aggressive as `_.camelCase`,
4
+ * which would also upper-case letters following numbers.
5
+ *
6
+ * @param {string} slug Input dash-delimited string.
7
+ *
8
+ * @return {string} Camel-cased string.
9
+ */
10
+ const camelCaseDash = ( slug: string ): string => slug.replace( /-([a-z])/g, ( match, letter ) => letter.toUpperCase() );
11
+
12
+ /**
13
+ * Convert all wp libraries to the global variable, which are
14
+ * available in WP core when the corresponding libraries are cued.
15
+ *
16
+ * @type {{wpExternals: *}}
17
+ */
18
+ const wpExports: { [ name: string ]: string } = [
19
+ 'a11y',
20
+ 'annotations',
21
+ 'api-fetch',
22
+ 'autop',
23
+ 'blob',
24
+ 'block-directory',
25
+ 'block-editor',
26
+ 'block-library',
27
+ 'block-serialization-default-parser',
28
+ 'blocks',
29
+ 'commands',
30
+ 'components',
31
+ 'compose',
32
+ 'core-data',
33
+ 'data',
34
+ 'data-controls',
35
+ 'date',
36
+ 'deprecated',
37
+ 'dom',
38
+ 'dom-ready',
39
+ 'edit-post',
40
+ 'edit-site',
41
+ 'editor',
42
+ 'element',
43
+ 'escape-html',
44
+ 'hooks',
45
+ 'html-entities',
46
+ 'i18n',
47
+ 'is-shallow-equal',
48
+ 'keyboard-shortcuts',
49
+ 'keycodes',
50
+ 'list-reusable-blocks',
51
+ 'media-utils',
52
+ 'notices',
53
+ 'nux',
54
+ 'plugins',
55
+ 'primitives',
56
+ 'priority-queue',
57
+ 'redux-routine',
58
+ 'reusable-blocks',
59
+ 'rich-text',
60
+ 'server-side-render',
61
+ 'shortcode',
62
+ 'token-list',
63
+ 'url',
64
+ 'utils',
65
+ 'viewport',
66
+ 'warning',
67
+ 'wordcount',
68
+ ].reduce(
69
+ ( externals, name ) => ( {
70
+ ...externals,
71
+ [ `@wordpress/${name}` ]: `window.wp?.${camelCaseDash( name )}`,
72
+ } ),
73
+ {
74
+ lodash: 'lodash',
75
+ wp: 'wp',
76
+ react: 'React',
77
+ 'react-dom': 'ReactDOM',
78
+ 'react-refresh/runtime': 'ReactRefreshRuntime',
79
+ jquery: 'jQuery',
80
+ tinymce: 'tinymce',
81
+ moment: 'moment',
82
+ 'react/jsx-runtime': 'ReactJSXRuntime',
83
+ backbone: 'Backbone',
84
+ },
85
+ );
86
+
87
+ export default wpExports;