# Copyright 2023 The Chromium Authors
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import("//tools/typescript/ts_library.gni")
import("//ui/webui/resources/tools/bundle_js.gni")
import("//ui/webui/resources/tools/generate_grd.gni")
import("//ui/webui/resources/tools/minify_js.gni")
import("//ui/webui/webui_features.gni")
ts_library("build_ts") {
visibility = [
":build_bundle",
# TODO(crbug.com/40943652): Currently limiting Lit usage to a small set of
# folders during the initial experimentation phase.
# - cr_elements/ and cr_components/
# - tests that need to refer to CrLitElement.
# - a few chrome/browser/resources/ folders that hold small UIs.
# Update when the migration enters its next phase.
"//chrome/browser/resources/about_sys:build_ts",
"//chrome/browser/resources/app_home:build_ts",
"//chrome/browser/resources/app_settings:build_ts",
"//chrome/browser/resources/browser_switch:build_ts",
"//chrome/browser/resources/commerce/product_specifications:build_ts",
"//chrome/browser/resources/downloads:build_ts",
"//chrome/browser/resources/feedback:build_ts",
"//chrome/browser/resources/internals/user_education:build_ts",
"//chrome/browser/resources/intro:build_ts",
"//chrome/browser/resources/key_value_pair_viewer_shared:build_ts",
"//chrome/browser/resources/management:build_ts",
"//chrome/browser/resources/media_router/cast_feedback:build_ts",
"//chrome/browser/resources/new_tab_page:build_ts",
"//chrome/browser/resources/on_device_internals:build_ts",
"//chrome/browser/resources/pdf:build_ts",
"//chrome/browser/resources/privacy_sandbox/internals/private_state_tokens:build_ts",
"//chrome/browser/resources/privacy_sandbox/internals/related_website_sets:build_ts",
"//chrome/browser/resources/profile_internals:build_ts",
"//chrome/browser/resources/side_panel/bookmarks:build_ts",
"//chrome/browser/resources/side_panel/customize_chrome:build_ts",
"//chrome/browser/resources/side_panel/history_clusters:build_ts",
"//chrome/browser/resources/side_panel/read_anything:build_ts",
"//chrome/browser/resources/side_panel/reading_list:build_ts",
"//chrome/browser/resources/side_panel/shared:build_ts",
"//chrome/browser/resources/signin:build_ts",
"//chrome/browser/resources/signin/profile_picker:build_ts",
"//chrome/browser/resources/tab_search:build_ts",
"//chrome/browser/resources/webui_gallery:build_ts",
"//chrome/browser/resources/welcome:build_ts",
"//chrome/browser/resources/whats_new:build_ts",
"//chrome/test/data/pdf:build_ts",
"//chrome/test/data/webui/app_home:build_ts",
"//chrome/test/data/webui/cr_components:build_ts",
"//chrome/test/data/webui/cr_components/help_bubble:build_ts",
"//chrome/test/data/webui/cr_components/history_clusters:build_ts",
"//chrome/test/data/webui/cr_elements:build_ts",
"//chrome/test/data/webui/extensions:build_ts",
"//chrome/test/data/webui/history:build_ts",
"//chrome/test/data/webui/privacy_sandbox/internals/private_state_tokens:build_ts",
"//chrome/test/data/webui/privacy_sandbox/internals/related_website_sets:build_ts",
"//chrome/test/data/webui/signin:build_ts",
"//chrome/test/data/webui/tab_search:build_ts",
"//chrome/test/data/webui/welcome:build_ts",
"//content/browser/resources/traces_internals:build_ts",
"//ui/webui/resources/cr_components/certificate_manager:build_ts",
"//ui/webui/resources/cr_components/customize_color_scheme_mode:build_ts",
"//ui/webui/resources/cr_components/help_bubble:build_ts",
"//ui/webui/resources/cr_components/history_clusters:build_ts",
"//ui/webui/resources/cr_components/localized_link:build_ts",
"//ui/webui/resources/cr_components/managed_dialog:build_ts",
"//ui/webui/resources/cr_components/managed_footnote:build_ts",
"//ui/webui/resources/cr_components/most_visited:build_ts",
"//ui/webui/resources/cr_components/theme_color_picker:build_ts",
"//ui/webui/resources/cr_elements:build_ts",
]
composite = true
in_files = [
"lit.ts",
"cr_lit_element.ts",
]
node_modules = "//third_party/node/node_modules"
definitions = [
"${node_modules}/lit-html/directives/repeat.d.ts",
"${node_modules}/lit-html/directives/when.d.ts",
"${node_modules}/lit-html/directives/ref.d.ts",
"${node_modules}/lit-html/directives/cache.d.ts",
"${node_modules}/lit-html/directives/choose.d.ts",
"${node_modules}/lit-html/directives/async-append.d.ts",
"${node_modules}/lit-html/directives/until.d.ts",
"${node_modules}/lit-html/directives/template-content.d.ts",
"${node_modules}/lit-html/directives/keyed.d.ts",
"${node_modules}/lit-html/directives/style-map.d.ts",
"${node_modules}/lit-html/directives/if-defined.d.ts",
"${node_modules}/lit-html/directives/join.d.ts",
"${node_modules}/lit-html/directives/unsafe-svg.d.ts",
"${node_modules}/lit-html/directives/live.d.ts",
"${node_modules}/lit-html/directives/guard.d.ts",
"${node_modules}/lit-html/directives/async-replace.d.ts",
"${node_modules}/lit-html/directives/unsafe-html.d.ts",
"${node_modules}/lit-html/directives/map.d.ts",
"${node_modules}/lit-html/directives/private-async-helpers.d.ts",
"${node_modules}/lit-html/directives/range.d.ts",
"${node_modules}/lit-html/directives/class-map.d.ts",
"${node_modules}/lit-html/static.d.ts",
"${node_modules}/lit-html/lit-html.d.ts",
"${node_modules}/lit-html/is-server.d.ts",
"${node_modules}/lit-html/async-directive.d.ts",
"${node_modules}/lit-html/directive.d.ts",
"${node_modules}/lit-html/directive-helpers.d.ts",
"${node_modules}/lit-element/lit-element.d.ts",
"${node_modules}/lit-element/index.d.ts",
"${node_modules}/lit/directives/repeat.d.ts",
"${node_modules}/lit/directives/when.d.ts",
"${node_modules}/lit/directives/ref.d.ts",
"${node_modules}/lit/directives/cache.d.ts",
"${node_modules}/lit/directives/choose.d.ts",
"${node_modules}/lit/directives/async-append.d.ts",
"${node_modules}/lit/directives/until.d.ts",
"${node_modules}/lit/directives/template-content.d.ts",
"${node_modules}/lit/directives/keyed.d.ts",
"${node_modules}/lit/directives/style-map.d.ts",
"${node_modules}/lit/directives/if-defined.d.ts",
"${node_modules}/lit/directives/join.d.ts",
"${node_modules}/lit/directives/unsafe-svg.d.ts",
"${node_modules}/lit/directives/live.d.ts",
"${node_modules}/lit/directives/guard.d.ts",
"${node_modules}/lit/directives/async-replace.d.ts",
"${node_modules}/lit/directives/unsafe-html.d.ts",
"${node_modules}/lit/directives/map.d.ts",
"${node_modules}/lit/directives/range.d.ts",
"${node_modules}/lit/directives/class-map.d.ts",
"${node_modules}/lit/static-html.d.ts",
"${node_modules}/lit/async-directive.d.ts",
"${node_modules}/lit/html.d.ts",
"${node_modules}/lit/directive.d.ts",
"${node_modules}/lit/directive-helpers.d.ts",
"${node_modules}/lit/index.d.ts",
"${node_modules}/@lit/reactive-element/reactive-controller.d.ts",
"${node_modules}/@lit/reactive-element/css-tag.d.ts",
"${node_modules}/@lit/reactive-element/reactive-element.d.ts",
]
path_mappings = [
"lit/index.js|" +
rebase_path("${node_modules}/lit/index.d.ts", target_gen_dir),
"lit-html|" +
rebase_path("${node_modules}/lit-html/lit-html.d.ts", target_gen_dir),
"@lit/reactive-element|" + rebase_path(
"${node_modules}/@lit/reactive-element/reactive-element.d.ts",
target_gen_dir),
]
}
bundle_js("build_bundle") {
# Using a dummy value for`host` which is ignored anyway since the code being
# bundled below is using a custom config and plugin.
host = "_ignored_"
input = rebase_path(target_gen_dir, root_build_dir)
js_module_in_files = [ "lit.js" ]
rollup_config = "rollup.config.mjs"
out_folder = "$target_gen_dir/bundled"
deps = [ ":build_ts" ]
}
minify_js("build_min_js") {
deps = [ ":build_bundle" ]
in_folder = "$target_gen_dir/bundled"
in_files = [ "lit.rollup.js" ]
out_folder = "$target_gen_dir/minified"
out_manifest = "${target_gen_dir}/build_min_js_manifest.json"
}
generate_grd("build_grdp") {
grd_prefix = "lit_v3_0"
out_grd = "$target_gen_dir/resources.grdp"
resource_path_prefix = "lit/v3_0"
manifest_files = [ "${target_gen_dir}/build_min_js_manifest.json" ]
deps = [ ":build_min_js" ]
}