Style file processing method and style updating method of shadow document object model
By replacing the native style update logic with the target style update logic in the front-end development framework, the updates of CSS and HTML are decoupled, solving the problems of long update time and difficulty in splitting Shadow DOM styles, and realizing real-time updates and efficient CSS splitting.
Patent Information
- Application Number
- CN202410947620.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-15
- Publication Date
- 2024-11-08
AI Technical Summary
The CSS updates of Shadow DOM are coupled with HTML files, resulting in long update times and difficulty in easily separating them. Existing tools are complex to configure and not suitable for widespread use.
By taking over the style update mechanism of the front-end development framework and replacing the native style update logic with the target style update logic, the update process of CSS and HTML is decoupled, enabling real-time updates of Shadow DOM styles and the splitting of CSS.
It enables rapid updates of Shadow DOM styles and independent CSS splitting, improving update efficiency and user experience, and simplifying the configuration process.
Smart Images

Figure CN118917280A_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to the field of computer network technology, and in particular to a style file processing method and a style update method of a Shadow Document Object Model (Shadow DOM). In addition, the present disclosure also relates to related devices, electronic devices and program products. Background Art
[0002] Currently, the Document Object Model (DOM) is a widely used document model in web development, usually represented by a tree structure. Shadow DOM, as an extension of DOM, is hidden from the programming language and Cascading Style Sheets (CSS) running in the web page.
[0003] In the development environment, Shadow DOM's CSS is usually highly coupled with Shadow DOM's Hypertext Markup Language (Html) processing flow. Therefore, Shadow DOM's Cascading Style Sheet (CSS) in web pages is often difficult to update or refresh in real time, that is, when Shadow DOM's CSS is updated, the CSS and the corresponding Html will be recompiled as a whole, which results in a long processing time for each CSS update.
[0004] In addition, because Shadow DOM's CSS is usually processed together with Shadow DOM's Html during compilation, it is often difficult to easily split different CSS when processing Shadow DOM's CSS.
[0005] The content of this background technology description is only for facilitating understanding of the relevant technology in this field and is not regarded as an admission of the prior art. Summary of the invention
[0006] In this regard, the embodiments of the present disclosure provide a solution for style file processing and style updating of Shadow Document Object Model (Shadow DOM), which can overcome or alleviate the technical problem that the style of Shadow DOM is difficult to update in real time and / or difficult to split.
[0007] In a first aspect, an embodiment of the present disclosure provides a method for processing a style file of a shadow document object model, which may include:
[0008] Acquire a target source style file according to a preset condition, wherein the target source style file includes a cascading style sheet to be processed in a shadow document object model;
[0009] For the cascading style sheet to be processed, using the target style update logic to replace the native style update logic corresponding to the cascading style sheet to be processed in the front-end development framework;
[0010] Based on the target style update logic that has been replaced in the front-end development framework, the cascading style sheet to be processed is extracted from the target source style file into a target style sheet file.
[0011] In some embodiments, the step of obtaining a target source style file according to a preset condition includes:
[0012] According to the filtering conditions in the preset conditions, a filtering operation is performed on the source style file in the front-end development framework to obtain the target source style file containing the cascading style sheet to be processed.
[0013] In some embodiments, for the cascading style sheet to be processed, replacing the native style update logic corresponding to the cascading style sheet to be processed in the front-end development framework with the target style update logic includes:
[0014] Obtaining a container identifier of the target source style file containing the cascading style sheet to be processed;
[0015] Obtaining a preset style update logic corresponding to the cascading style sheet to be processed;
[0016] Adding the container identifier to the preset style update logic to obtain the target style update logic for replacement;
[0017] The target style update logic is replaced with the style update logic corresponding to the cascading style sheet to be processed in the front-end development framework.
[0018] In some embodiments, extracting the to-be-processed cascading style sheet from the target source style file into a target style sheet file based on the target style update logic replaced in the front-end development framework includes:
[0019] Processing the target source style file according to the target style update logic to generate the cascading style sheet;
[0020] According to the target style update logic, the generated cascading style sheet is configured into at least one of the target style sheet files.
[0021] In a second aspect, an embodiment of the present disclosure provides a method for updating a style of a shadow document object model, which may include:
[0022] Acquire a target style file, wherein the target style file is obtained by processing a cascading style sheet of a shadow document object model using a style file processing method, and the style file processing method is the style file processing method according to any one of the embodiments of the present disclosure;
[0023] Get a style tag including the cascading style sheet style parameters to be updated;
[0024] Without reloading the hypertext markup language of the shadow document object model, the style tag is imported into the shadow document object model, and the corresponding style of the processed cascading style sheet in the target style file is updated according to the style parameter.
[0025] In some embodiments, updating the corresponding style of the cascading style sheet processed in the target style file according to the style parameter includes:
[0026] If the style tag carries an identifier of a shadow document object model, updating a corresponding style of a first cascading style sheet, wherein the first cascading style sheet is the cascading style sheet of the shadow document object model corresponding to the identifier; and / or
[0027] If the style tag does not carry an identifier of a shadow document object model or carries a wildcard, the corresponding style of a second cascading style sheet is updated, wherein the second cascading style sheet is the cascading style sheet of all shadow document object models in the front-end page.
[0028] In a third aspect, an embodiment of the present disclosure provides a style file processing device for a shadow document object model, which may include:
[0029] an acquisition unit, configured to acquire a target source style file according to a preset condition, wherein the target source style file includes a cascading style sheet to be processed in a shadow document object model;
[0030] a replacement unit configured to replace the native style update logic corresponding to the cascading style sheet to be processed in the front-end development framework with the target style update logic for the cascading style sheet to be processed; and
[0031] The extraction unit is configured to extract the cascading style sheet to be processed from the target source style file into a target style sheet file based on the target style update logic that has been replaced in the front-end development framework.
[0032] In a fourth aspect, an embodiment of the present disclosure provides a style updating device for a shadow document object model, which may include:
[0033] The style file processing device according to the embodiment of the present disclosure is configured to process the cascading style sheet of the shadow document object model to obtain the target style file;
[0034] an acquiring unit configured to acquire a style tag including a cascading style sheet style parameter to be updated; and
[0035] The updating unit is configured to import the style tag into the shadow document object model without reloading the hypertext markup language of the shadow document object model, and update the corresponding style of the processed cascading style sheet in the target style file according to the style parameter.
[0036] In a fifth aspect, in an embodiment of the present disclosure, an electronic device is provided, comprising: a processor and a memory storing a computer program, wherein the processor is configured to implement a method of any embodiment of the present disclosure when executing the computer program.
[0037] In a sixth aspect, in an embodiment of the present disclosure, a program product is provided, which includes a computer program, wherein the computer program implements any method of the embodiment of the present disclosure when executed by a processor.
[0038] The disclosed embodiment proposes a style file processing method of a shadow document object model (Shadow DOM), preferably a CSS processing method of Shadow DOM, the method obtains a target source style file according to preset conditions, the target source style file includes a cascading style sheet to be processed in the shadow document object model; for the cascading style sheet to be processed, the native style update logic corresponding to the cascading style sheet to be processed in the front-end development framework is replaced with a target style update logic; based on the target style update logic replaced in the front-end development framework, the cascading style sheet to be processed is extracted from the target source style file to the target style sheet file, thereby allowing the hot update of the style (such as CSS) of the shadow document object model (Shadow DOM) in the web page in a convenient and effective manner, and also facilitates the splitting of different CSS of Shadow DOM. Further, the disclosed embodiment also proposes a style update method of the shadow document object model, which realizes the instant update or real-time refresh of Shadow DOM.
[0039] Other optional features and technical effects of the embodiments of the present disclosure are partially described below, and partially can be understood by reading this document. BRIEF DESCRIPTION OF THE DRAWINGS
[0040] Hereinafter, embodiments of the present disclosure will be described in detail with reference to the accompanying drawings. The elements shown are not limited by the proportions shown in the accompanying drawings. The same or similar reference numerals in the accompanying drawings represent the same or similar elements, wherein:
[0041] Figure 1 A schematic diagram of a DOM tree with a shadow document object model is shown;
[0042] Figure 2 An exemplary flow chart of a method for processing a style file of a shadow document object model according to an embodiment of the present disclosure is shown;
[0043] Figure 3 An exemplary flow chart of a method for processing a style file of a shadow document object model according to an embodiment of the present disclosure is shown;
[0044] Figure 4 An exemplary flow chart of a method for processing a style file of a shadow document object model according to an embodiment of the present disclosure is shown;
[0045] Figure 5 An exemplary flow chart of a method for processing style update of a shadow document object model according to an embodiment of the present disclosure is shown;
[0046] Figure 6 An exemplary flow chart of a method for updating a style of a shadow document object model according to an embodiment of the present disclosure is shown;
[0047] Figure 7 An exemplary structural diagram of a style file processing device of a shadow document object model according to an embodiment of the present disclosure is shown;
[0048] Figure 8 An exemplary structural diagram showing a style updating device of a shadow document object model according to an embodiment of the present disclosure; and
[0049] Fig. 9 An exemplary structural diagram of an electronic device capable of implementing the method according to an embodiment of the present disclosure is shown. DETAILED DESCRIPTION
[0050] In order to make the purpose, technical solution and advantages of the present disclosure more clear, the present disclosure is further described below in conjunction with specific implementation methods and drawings. Here, the illustrative implementation methods and descriptions of the present disclosure are used to explain the present disclosure, but are not intended to limit the present disclosure.
[0051] Document Object Model (DOM) is a data representation of document structure and content objects in the web. Figure 1 The DOM may be a tree structure (also called a DOM tree). When the DOM tree represents the document structure and content, the root node of the tree represents the document object, and the remaining nodes represent the document elements.
[0052] Continue to refer Figure 1Shadow Document Object Model (Shadow DOM) is an extension of DOM that allows a hidden DOM tree (also called Shadow DOM tree or shadow tree) to be attached to a node of a regular DOM tree. The regular DOM tree node to which Shadow DOM is attached is called ShadowHost, which constitutes the root node of the shadow tree, namely Shadow Root. Document elements can be attached to other nodes of Shadow DOM in the same way as regular DOM.
[0053] Furthermore, Shadow DOM is hidden from JavaScript and Cascading Style Sheets (CSS) of regular DOM running on the web. Therefore, the style or style update of regular DOM will not affect Shadow DOM, and vice versa. In the disclosed embodiments, the CSS of Shadow DOM can be referred to as Shadow CSS to distinguish it from the CSS of regular DOM.
[0054] As mentioned above, Shadow DOM's styles, such as Shadow CSS, are usually coupled with Shadow DOM's Hypertext Markup Language (Html) update compilation logic. Therefore, in web development, when updating Shadow CSS, it must be recompiled together with the Html file, which requires a long processing time, resulting in the difficulty of updating or refreshing the style changes corresponding to the Shadow CSS update in the web page in real time. The web page must be manually refreshed and waited to observe the style changes. In addition, since Shadow CSS and Html need to be processed together in the compilation process, it is also difficult to separate different CSS into the required style files for reuse.
[0055] Currently, there are proposals to use different tools to compile Shadow CSS to achieve instant updates or real-time refreshes. However, these tools or solutions have complex configuration processes and require experienced users to manually manage a large number of complex configuration items, so the configuration efficiency is low and not suitable for widespread use.
[0056] In this regard, the embodiments of the present disclosure propose a style file processing method for a shadow document object model (Shadow DOM). In one example, the style file processing method is a CSS processing method for Shadow DOM. The style file processing method can be used to simply and quickly implement real-time refresh of Shadow CSS updates in web pages. In the embodiments of the present disclosure, the style file processing method for the shadow document object model can be implemented in a web front-end development environment. In a specific implementation, the method provided by the embodiments of the present disclosure can be implemented based on a web front-end development framework (such as Vue), and the subject that executes the above method includes a web front-end development framework plug-in (such as a Vite plug-in).
[0057] In the embodiments of the present disclosure, any suitable front-end development framework and construction tools may be used to build a user interface, including but not limited to React, Angular, Svelte, Preact, LitElement, etc., and the front-end construction tools include but are not limited to Vite, etc.
[0058] In the style file processing method of the embodiment of the present disclosure, specifically, the CSS processing method of Shadow DOM, the independent real-time update of the Shadow DOM style file can be achieved by taking over the style update mechanism of the front-end development framework. This is achieved, for example, through the style update method of Shadow DOM of a further embodiment of the present disclosure, more specifically, through the CSS update method of Shadow DOM.
[0059] See also Figure 2 , shows a style file processing method of the Shadow Document Object Model (Shadow DOM) according to an embodiment of the present disclosure, specifically, an exemplary flowchart of the CSS processing method of the Shadow DOM.
[0060] like Figure 2 As shown, the method may include steps S210 to S230:
[0061] S210: Acquire a target source style file according to a preset condition, where the target source style file includes a cascading style sheet to be processed in a shadow document object model.
[0062] In the disclosed embodiment, for example, in the above step 210, the source style file includes all cascading style files (CSS files) processed by the web development environment (e.g., web front-end framework), and the target source style file includes a cascading style file belonging to ShadowDOM (hereinafter referred to as Shadow DOM CSS file), wherein the cascading style file refers to a file storing a specific cascading style sheet. In a specific example, cascading style sheet A is a specific style definition rule for a .logo, and the cascading style file is a file storing the cascading style sheet A, such as a .shadow.css file.
[0063] In some embodiments of the present disclosure, the above step S210 may include the following steps:
[0064] According to the filtering conditions in the preset conditions, a filtering operation is performed on the source style files in the front-end development framework to obtain a target source style file containing the cascading style sheet to be processed. The preset conditions may include filtering conditions, and the filtering conditions may include file type, file path, etc. In a specific example, the source style files in the front-end framework can be identified and filtered based on the include parameter and exclude parameter in the filtering conditions, such as identifying objects / files with suffixes of '.shadow.css' and '.shadow.Less', and identifying objects / files stored in the 'shadow / ' directory, thereby filtering the source style files to obtain a target source style file, which contains the Shadow DOM CSS file to be processed.
[0065] In some embodiments of the present disclosure, the filtering can be implemented by existing plug-ins in the front-end development framework, including but not limited to Vite, Webpack, Parcel, etc. In a specific example, the Vite plug-in filters out the target source style file containing the Shadow DOM CSS to be processed according to the filtering rules in the 'vite.config.js' configuration file. In another specific example, the Webpack plug-in automatically filters out the target source style file containing the Shadow DOM CSS to be processed according to the filtering rules in the 'webpack.config.js' configuration file.
[0066] S220: For the cascading style sheet to be processed, the target style update logic is used to replace the native style update logic corresponding to the cascading style sheet to be processed in the front-end development framework.
[0067] In the embodiments of the present disclosure, the term “update” in “style update” or “real-time update” will be interpreted broadly, including addition, removal and change, covering the narrow sense of “update”.
[0068] In the disclosed embodiment, for the target source style file whose update logic is not replaced, the native style update logic provided by the web front-end development framework is still used. As mentioned above, the native style update logic usually couples the update of Shadow DOMCSS with the update of the corresponding Html.
[0069] In some embodiments of the present disclosure, for example, in the above step S220, the aforementioned native style update logic may be replaced with a target style update logic, which can decouple the update process of the pending CSS in the target source style file from the update of the Html corresponding to the CSS when the CSS is updated, thereby facilitating the timely update / refresh of the CSS. In addition, this is further conducive to the splitting and reuse of CSS files, which will be described in detail later.
[0070] In some embodiments of the present disclosure, for the cascading style sheet to be processed, the calling logic of the native style update logic corresponding to the cascading style sheet to be processed can be intercepted based on the relevant mechanism in the front-end development framework. In a specific embodiment of the present disclosure, for example, in the above step S220, the CSS update behavior of Shadow DOM can be intercepted based on the Vite plug-in of the web front-end development framework, specifically based on the hook function 'transform' of the Vite plug-in, so as to take over the native style update mechanism of the web front-end development framework to take over the style update process of Shadow DOM. However, it can be understood that for different front-end frameworks, a variety of front-end tools can be used to take over the CSS style update mechanism for Shadow DOM when the front-end framework is running, and these situations fall within the scope of the present disclosure.
[0071] In some embodiments of the present disclosure, for example, in the above step S220, the target source style file includes multiple Shadow DOM CSS files, and the developer can specify the style update logic to replace the multiple Shadow DOM CSS files, or can specify the style update logic to replace part of the Shadow DOM CSS files according to the needs. In a specific example, the Vite plug-in can create a filter 'createFilter' through the hook function 'transform', and the filter can filter and specify the native style update logic of the Shadow DOM CSS file named 'button.shadow.css' according to the filtering rules in the preset rules to be replaced.
[0072] In some embodiments of the present disclosure, Figure 3 As shown, the above step S220 may include the following steps S221 to S224:
[0073] S221: Obtain a container identifier of a target source style file containing a cascading style sheet to be processed.
[0074] In the disclosed embodiment, the container identifier is an identifier for identifying the target source style file. In the style processing logic, the specific style file can be managed and updated through the container identifier. In one example, the container identifier corresponding to the file can be obtained by parsing the configuration file or object. Through the container identifier, a large number of style files can be classified and identified. For example, the target source style file belonging to the identifier can be quickly found and managed through the container identifier containerA. In the disclosed embodiment, through the use of the container identifier, the developer and the system can manage the target source style file through the container identifier, and different container identifiers can correspond to different update logics, which allows the developer and the system to define a set of special update logic for a specific container identifier containerA and apply it to the target source style file related to containerA.
[0075] In a specific example, for example, in the above step S221, a parsing function may be used to parse the container identifier of the cascading style sheet file to be processed. In a specific embodiment of the present disclosure, for example, in the above step S221, the configuration information corresponding to the configuration object 'options.config' may be parsed according to the passed-in file identifier 'id' by the 'parseConfig' function, and the information includes the processing method of the file, parameter settings, and the container identifier 'container' of the file.
[0076] S222: Acquire a preset style update logic corresponding to the cascading style sheet to be processed.
[0077] In some embodiments of the present disclosure, the preset style update logic may include a style update function, such as an 'updateShadowStyle' (Shadow DOM style update) function and its code, and a 'removeShadowStyle' (Shadow DOM style removal) function and its code.
[0078] In some embodiments of the present disclosure, for example, in the above step S222, the corresponding plug-in in the front-end framework, such as a function in the plug-in, will check and obtain the preset style update logic corresponding to the Shadow DOM CSS to be processed according to the configuration rules in the preset rules. In the embodiments of the present disclosure, the configuration rules are a set of definable rules for specifying how to process and update a specific Shadow DOM CSS. These rules are usually stored in a configuration file, such as options.config, which contains various parameters and settings related to the style file.
[0079] In some embodiments of the present disclosure, the above step S222 may also include: determining the preset style update logic corresponding to the cascading style sheet to be processed according to the configuration rules in the preset rules. In one example, the configuration rules may include a file identifier (id), a container identifier (container), a style update logic (processing), and an output file name (output), etc. For the cascading style sheet file to be processed, the configuration rules may be queried according to the incoming file identifier to confirm the container identifier (container), style update logic (processing), etc. corresponding to the cascading style sheet. In some embodiments of the present disclosure, in order to provide convenient import and update of the preset style update logic, a virtual module may also be set to provide dynamically generated code or content, and may be defined and used in combination with a hook function.
[0080] In one example, a virtual module may be defined for processing and updating Shadow DOM CSS styles. Here, a virtual module is a logical entity used in the development process. A virtual module has no corresponding physical file in the file system. In other words, the virtual module is generated by a development tool or framework at runtime. Accordingly, the disclosed embodiments may also include the steps of parsing and / or loading virtual modules. In a specific embodiment, a virtual module 'virtual:shadow-dom-css' may be set, which is identified based on an identifier (such as prefix '\0') specified by a web front-end development framework plug-in, and is parsed and / or loaded through a parsing function resolveId(id) and / or a loading function load(id), thereby utilizing the virtual module to process and update Shadow DOM CSS styles.
[0081] In some embodiments of the present disclosure, developers can formulate specific rules for their style update logic for different CSS according to their own needs through the use of hook functions and virtual modules. For example, the CSS file finally obtained by setting the style update logic will be output / reused in a specific target style file, which will be described in detail below. In a specific example, the hook function in the development framework plug-in includes a parsing hook function (resolveId) and a loading hook function (load). The parsing hook function (resolveId) will identify the virtual module according to the configuration rules and return a unique identifier "\0virtual:shadow-dom-css". The development framework plug-in confirms that it is a virtual module and not other real files based on the identifier. Subsequently, the loading hook function (load) will generate and return the actual content of the virtual module, including the specific logic of processing the style, the specific logic. Finally, these specific logics will be applied to the specified ShadowDOM CSS style file by the virtual module and output to the specified output1.css file for storage and reuse.
[0082] S223: Add the container identifier to the preset style update logic to obtain the target style update logic for replacement.
[0083] In the embodiment of the present disclosure, for example, in the above step S223, the container identifier of the corresponding file to be processed may be added to the preset style update logic to obtain the target style update logic for replacement.
[0084] In a specific embodiment of the present disclosure, in the above step S223, the container identifier 'container' of the file to be processed is parsed and attached to the preset style update code to obtain the target style update code 'updateShadowStyle(_containner)' for the file to be processed.
[0085] S224: Replace the target style update logic with the style update logic corresponding to the cascading style sheet to be processed in the front-end development framework.
[0086] In the embodiment of the present disclosure, the target style update code can be used to replace the native style update code of the front-end framework / tool, for example, the target style update code can be used to replace 'vite_updateStyle' and / or 'vite removeStyle'.
[0087] In a specific embodiment of the present disclosure, the replacement of the update logic (code) in step S224 can be achieved by string replacement. First, the native function call in 'code' is modified for the first time through the '.replace()' method: the native style update function 'updateStyle()' is replaced with 'updateShadowStyle(containner' which specifically updates Shadow DOM CSS; then, the '.replace()' method is used again to replace the native style removal function 'removeStyle()' call with 'removeShadowStyle(containner' which specifically removes Shadow DOM CSS; finally, the modified code string is encapsulated in an object and returned through 'return{code:_code,}'. The 'code' attribute in this object contains the final target style update code after two replacement operations.
[0088] Through the above method disclosed in the present invention, the update process of the cascading style sheet is optimized, and the update of any cascading style sheet will no longer trigger the native style update logic, but will be intercepted at the beginning of the update process and taken over by the customizable target style update logic. The target style update logic does not need to process the corresponding Html file when updating the cascading style sheet, so that the processing of the cascading style sheet and the Html file can be decoupled, and the update efficiency can be improved, so that the style on a specific web page can be quickly or even in real time / instantly refreshed.
[0089] Step S230: extracting the cascading style sheet to be processed from the target source style file into the target style sheet file based on the target style update logic that has been replaced in the front-end development framework.
[0090] In this embodiment, the update of CSS in the target style sheet file will be decoupled from the update of Html. Based on the replaced target style update logic, the Shadow DOM CSS to be processed will be extracted and compiled independently of the Html of Shadow DOM.
[0091] The method in the embodiment of the present disclosure, such as the aforementioned step S230, can be implemented by the front-end plug-in in the compilation stage, so that the CSS content extracted in this step will be output through the plug-in. In a specific example, the Vite plug-in extracts the CSS content using the target style update code and outputs it using ExtractShadowCSS.
[0092] In some embodiments of the present disclosure, Figure 4 As shown, step S230 may specifically include the following steps S231 to S232.
[0093] S231: Process the target source style file according to the target style update logic to generate a cascading style sheet.
[0094] In the embodiment of the present disclosure, the target style update logic can be used to compile and generate an updated Shadow DOM CSS file without processing the Html.
[0095] In one embodiment of the present disclosure, the target source style file includes a precompiled file, such as a .Less file. In this case, the compilation of the precompiled file may be prioritized over the execution of other plug-ins.
[0096] In a specific embodiment of the present disclosure, the Less compiler can be used asynchronously to convert the Less code 'code' into CSS code: first, the Less code is compiled asynchronously through the 'Less.render()' function. After the compilation is completed, the 'Less.render()' function will return an object containing the compiled CSS content. By checking whether 'LessContent' exists, it can be determined whether the compilation process is successful. If the compilation is successful, the CSS content will be stored in 'LessContent.css' and assigned to the 'content' variable. The 'content' variable will contain the compiled CSS code and can be further used to apply to the web or write to other style files. Among them, the 'code' is, for example, the style update code for replacing the native style code described in step S220 above, and more specifically, the target style update code (logic) used for replacement in S224.
[0097] S232: configuring the generated cascading style sheet into at least one target style sheet file according to the target style update logic.
[0098] In the embodiment of the present disclosure, the compiled cascading style sheet can be output to a designated directory according to the corresponding target style update logic.
[0099] In the embodiment of the present disclosure, the above step S232 may include the step of extracting the generated cascading style sheet.
[0100] In some embodiments of the present disclosure, the CSS file extracted in step S232 may be stored in a given object. To this end, before step S232, a step of pre-defining a mapping object extractedCSS of CSS content may be included.
[0101] In one embodiment of the present disclosure, the storage of the extracted CSS content may be based on key values to distinguish different extracted CSS contents. Here, the method includes, for example, the steps of:
[0102] If there is an extracted cascading style sheet key value, set the new key value to replace the existing key value, and map the newly extracted cascading style sheet to the object extractedCSS; otherwise, directly use the new key value to map the newly extracted cascading style sheet to the object extractedCSS.
[0103] In a specific embodiment of the present disclosure, a mapping object 'extractedCSS' may be first created or predefined, which is responsible for storing all extracted CSS contents, wherein each CSS content is stored in the form of a key-value pair, the key 'key' being the unique identifier of each CSS content, and the value 'value' being the corresponding CSS code string. Then, by calling the 'parseConfig' function, and passing in the configuration object 'options.config' and the file identifier 'id' as parameters, a key value 'key' is generated to identify and distinguish different CSS contents, and then the mapping object 'extractedCSS' is checked and updated:
[0104] If the given key value 'key' already exists in the mapping object 'extractedCSS', it means that the corresponding CSS content has been extracted before. At this time, the newly extracted CSS content 'conetnt' is appended to the existing CSS content and separated by a newline character '\n' to ensure that different CSS blocks are clearly separated to allow multiple CSS contents to be aggregated under the same key value.
[0105] If the given key value 'key' does not exist in the mapping object 'extractedCSS', the CSS content is extracted and stored for the first time. At this time, the new key value and the corresponding CSS content 'conetnt' are directly added to the mapping object.
[0106] Finally the 'parseConfig' function returns an object containing an empty code string and an empty mapping information. This return value may be used to indicate that the process does not directly produce new executable code, but is instead focused on managing and storing the extracted CSS content.
[0107] In some embodiments of the present disclosure, after all CSS to be processed are extracted, as described above, the extracted CSS may be written into an independent CSS file according to the target style update logic.
[0108] In a specific embodiment of the present disclosure, a function 'generateBundle' for generating files may be defined in the target style update logic, which is used to check the previously extracted CSS content 'conetnt' and write it to the file system: first, the 'generateBundle' function checks whether the 'extractedCSS' mapping object is empty (i.e., whether there is extracted CSS content). If there is no extracted CSS content ('extractedCSS.size'=0), there is no need to generate the file, and the function will return directly; if there is extracted CSS content ('extractedCSS.size'=1), the 'extractedCSS' mapping object will be traversed, and the 'this.emitFile' method will be used to generate the actual CSS file for each item therein, i.e., the replacement style sheet file.
[0109] In a further embodiment of the present disclosure, after all the CSS to be processed are extracted, as described above, the CSS file may be split into a plurality of designated target style sheet files according to the target style update logic.
[0110] Continuing with the above example, in a specific embodiment of the present disclosure, the key of extractedCSS is changed to a complete file name including a specified directory path and the generateBundle function is adjusted to directly use the key of extractedCSS as the file name, thereby splitting the generated files into multiple specified directories.
[0111] In the disclosed embodiment, since the compilation and generation of CSS files are decoupled from the processing of corresponding Html files, different CSS files can be split independently and configured into different directories / files according to the configuration rules in the target style update logic to achieve reuse.
[0112] The disclosed embodiment proposes a style file processing method of a shadow document object model (Shadow DOM), preferably a CSS processing method of a Shadow DOM, wherein the method obtains a target source style file according to a preset condition, wherein the target source style file includes a cascading style sheet to be processed in the shadow document object model; for the cascading style sheet to be processed, a target style update logic is used to replace a native style update logic corresponding to the cascading style sheet to be processed in a front-end development framework; based on the target style update logic that has been replaced in the front-end development framework, the cascading style sheet to be processed is extracted from the target source style file into a target style sheet file, thereby enabling hot updates of styles (such as CSS) of a shadow document object model (Shadow DOM) in a web page to be implemented in a convenient and effective manner, and also facilitating the splitting of different CSSs of the Shadow DOM.
[0113] like Figure 5 As shown, the embodiment of the present disclosure also provides a style update method of a shadow document object model (Shadow DOM), which may include:
[0114] S510: Obtain a target style file.
[0115] In an embodiment of the present disclosure, the target style file is obtained by processing the cascading style sheet of the shadow document object model using a style file processing method. In one embodiment, the style file processing method is a style file processing method according to any of the aforementioned embodiments of the present disclosure, or the style file processing method can be combined with any feature, step or sub-step of the style file processing method according to the embodiment of the present disclosure in a non-contradictory manner.
[0116] S520: Obtain a style tag including the cascading style sheet style parameters to be updated.
[0117] In an embodiment of the present disclosure, a CSS style tag of Shadow DOM may be provided as needed, wherein the style tag includes cascading style sheet style parameters intended to be updated, wherein the cascading style sheet style parameters define specific style properties applied in Shadow DOM.
[0118] In a specific embodiment of the present disclosure, a style tag A (CSS tag A) for the .logo class may be provided, and by using <style scoped shadow>标签指定这些样式参数应用于Shadow DOM内部。所述标签A定义了Shadow DOM中关于.logo类的一组具体样式参数,包括其以下具体样式属性:高度height、内边距padding、过渡效果transition以及对过滤器的变化预设will-change。同时,还定义了hover伪类参数,使得当用户悬停在logo上时,会应用一个阴影效果,具体的阴影颜色和范围随着类的不同而有所变化。
[0119] 在本公开一实施例中,所述样式标签中还可包括Shadow DOM的标识符,该标识符用于标识需要应用该样式标签的Shadow DOM实例。
[0120] 接上例,在本公开又一具体实施例中,可提供针对.logo类的样式标签B(CSS标签B),其同样定义了针对.logo类的一组样式参数,包括.logo类的高度height、内边距padding、过渡效果transition以及对过滤器的变化预设will-change等,同时其通过<style scoped shadow='key'>标签使用了一个额外的参数shadow=‘key’,所述‘key’是一个标识符,用于更精确地指定或识别应用这些样式的Shadow DOM的实例。该实施例中样式(CSS)标签B和前述标签A存在差别,主要在于相比于样式(CSS)标签A通用于web页面的Shadow DOM,而样式(CSS)标签B适用于标识符为‘key’(key仅为示例,可以是不同类型、参数的标识符)的Shadow DOM。
[0121] S530:在不重新加载影子文档对象模型的超文本标记语言的情况下,导入样式标签至影子文档对象模型,根据样式参数更新目标样式文件中被处理的层叠样式表的对应样式。
[0122] 在本公开一些实施例中,如图6所示,步骤S530可以包括:
[0123] S531:若样式标签带有影子文档对象模型的标识符,更新第一层叠样式表的对应样式,其中,第一层叠样式表为对应标识符的影子文档对象模型的层叠样式表;
[0124] 在本公开一个具体实施例中,例如可以通过如url链接来导入如上文所述的样式标签B。在该实施例中,例如可以通过样式标签带有影子文档对象模型的标识符(如‘key’),能够只对给定的Shadow DOM的进行相应的CSS更新。
[0125] 在本公开一些实施例中,步骤S530可以包括:
[0126] S532:若样式标签不带影子文档对象模型的标识符或带有通配符,更新第二层叠样式表的对应样式,其中,第二层叠样式表为前端页面中所有影子文档对象模型的层叠样式表。
[0127] 在本公开一个具体实施例中,例如可以通过如下url链接来导入如上文所述的样式标签A。在该实施例中,导入的样式标签中的待更改样式将可以适用于所有Shadow DOM的CSS更新。
[0128] 通过本公开实施例的样式更新方法,在样式更新过程中Shadow DOM的CSS和HTML结构的更新完全解耦。因此,导入需更新的样式标签后,无需重载HTML即可更新CSS样式,由此减少了资源消耗,加快了页面中Shadow DOM CSS更新的响应速度,以简单、有效的方式实现了Shadow DOM的CSS的热更新,从而提升了用户体验。此外,通过在样式标签中设置Shadow DOM的标识符,使得同一套样式参数可以根据标识符应用于指定的一个或多个不同的Shadow DOM,从而提高了样式可复用性。
[0129] 如图7所示,本公开实施例还提供了影子文档对象模型(Shadow DOM)的样式文件处理装置700,更具体地,Shadow DOM的CSS文件处理装置。该样式文件处理装置700可包括获取单元710、替换单元720和提取单元730。
[0130] 在图7所示的实施例中,获取单元710配置成配置成根据预设条件获取目标源样式文件,所述目标源样式文件包括影子文档对象模型中的待处理的层叠样式表。
[0131] 在图7所示的实施例中,替换单元720配置成针对所述待处理的层叠样式表,使用目标样式更新逻辑替换前端开发框架中所述待处理的层叠样式表对应的原生样式更新逻辑;以及
[0132] 在图7所示的实施例中,提取单元730配置成成基于所述前端开发框架中已替换的所述目标样式更新逻辑从所述目标源样式文件提取所述待处理的层叠样式表到目标样式表文件中。
[0133] 如图8所示,本公开实施例还提供了影子文档对象模型(Shadow DOM)的样式更新装置800、更具体地,Shadow DOM的CSS(热)更新装置。该样式更新装置800可包括样式文件处理装置810、获取单元820和更新单元830。
[0134] 在该实施例中,样式文件处理装置810可以为图7所示实施例的样式文件处理装置700。在另外的实施例中,样式文件处理装置810还可以是用于实施根据本公开的样式文件处理方法的装置或者包括对应于本公开实施例的该样式文件处理方法的若干特征组合的单元,本公开对此不作限制。样式文件处理装置810可以用于处理影子文档对象模型的层叠样式表以获得经处理的样式文件(如CSS文件),例如上文其他实施例所述的目标式文件。
[0135] 在图8所示的实施例中,获取单元820可配置成获取包括待更新的层叠样式表样式参数的样式标签。
[0136] 在图8所示的实施例中,更新单元830可配置成成在不重新加载影子文档对象模型的超文本标记语言的情况下,导入所述样式标签至所述影子文档对象模型,根据所述样式参数更新所述目标样式文件中被处理的层叠样式表的对应样式。
[0137] 在进一步的实施例中,本公开实施例所述的装置可以以不矛盾的方式结合任一实施例的方法的特征,反之亦然,在此不赘述。
[0138] 在本公开实施例中,提供电子设备,包括:处理器和存储有计算机程序的存储器,所述处理器被配置为在运行计算机程序时执行任一本公开实施例的方法。
[0139] 图9示出了可以实施本公开实施例的方法或实现本公开实施例的电子设备900的示意图,在一些实施例中可以包括比图示更多或更少的电子设备。在一些实施例中,可以利用单个或多个电子设备实施。在一些实施例中,可以利用云端或分布式的电子设备实施。
[0140] 如图9所示,电子设备900包括处理器901,其可以根据存储在只读存储器(ROM)902中的程序和 / 或数据或者从存储部分908加载到随机访问存储器(RAM)903中的程序和 / 或数据而执行各种适当的操作和处理。处理器901可以是一个多核的处理器,也可以包含多个处理器。在一些实施例中,处理器901可以包含一个通用的主处理器,例如中央处理器(CPU),以及一个或多个特殊的协处理器,例如图形处理器(GPU)、神经网络处理器(NPU)、数字信号处理器(DSP)等等。在RAM 903中,还存储有电子设备900操作所需的各种程序和数据。处理器901、ROM 902以及RAM 903通过总线904彼此相连。输入 / 输出(I / O)接口905也连接至总线904。
[0141] 上述处理器与存储器共同用于执行存储在存储器中的程序,所述程序被计算机执行时能够实现上述各实施例描述的方法的步骤或功能。
[0142] 以下部件连接至I / O接口905:包括键盘、鼠标、触摸屏等的输入部分906;包括诸如阴极射线管(CRT)、液晶显示器(LCD)等以及扬声器等的输出部分907;包括硬盘等的存储部分908;以及包括诸如LAN卡、调制解调器等的网络接口卡的通信部分909。通信部分909经由诸如因特网的网络执行通信处理。驱动器910也根据需要连接至I / O接口905。可拆卸介质911,诸如磁盘、光盘、磁光盘、半导体存储器等等,根据需要安装在驱动器910上,以便于从其上读出的计算机程序根据需要被安装入存储部分908。图9中仅示意性示出部分组件,并不意味着计算机系统900只包括图9所示组件。
[0143] 在一些实施例中,所述电子设备900指代的是移动终端或者计算机,包括手机,车载终端,智能电视等,以手机为例,所述电子设备900中还包括带触摸功能的显示屏,外放音响,陀螺仪,摄像头,4G / 5G天线等装置模块。
[0144] 上述实施例阐明的系统、装置、模块或单元,可以由计算机或其关联部件实现。计算机例如可以为移动终端、智能电话、个人计算机、膝上型计算机、车载人机交互设备、个人数字助理、媒体播放器、导航设备、游戏控制台、平板电脑、可穿戴设备、智能电视、物联网系统、智能家居、工业计算机、服务器或者其组合
[0145] 尽管未示出,在本公开实施例中,提供存储介质,所述存储介质存储有计算机程序,所述计算机程序配置成被运行时执行任一本公开实施例的方法。
[0146] 尽管未示出,在本公开实施例中,提供程序产品,包括计算机程序,所述计算机程序被处理器执行时实现任一本公开实施例的方法。
[0147] 在本公开的实施例的存储介质包括永久性和非永久性、可移动和非可移动的可以由任何方法或技术来实现信息存储的物品。存储介质的例子包括,但不限于相变内存(PRAM)、静态随机存取存储器(SRAM)、动态随机存取存储器(DRAM)、其他类型的随机存取存储器(RAM)、只读存储器(ROM)、电可擦除可编程只读存储器(EEPROM)、快闪记忆体或其他内存技术、只读光盘只读存储器(CD-ROM)、数字多功能光盘(DVD)或其他光学存储、磁盒式磁带,磁带磁磁盘存储或其他磁性存储设备或任何其他非传输介质,可用于存储可以被计算设备访问的信息。
[0148] 在本公开的实施例的方法、程序、系统、装置等,可以在单个或多个连网的计算机中执行或实现,也可以在分布式计算环境中实践。在本说明书实施例中,在这些分布式计算环境中,可以由通过通信网络而被连接的远程处理设备来执行任务。
[0149] 本领域技术人员应明白,本说明书的实施例可提供为方法、系统或计算机程序产品。因此,本领域技术人员可想到,上述实施例阐明的功能模块 / 单元或控制器以及相关方法步骤的实现,可以用软件、硬件和软 / 硬件结合的方式实现。
[0150] 除非明确指出,根据本公开实施例记载的方法、程序的动作或步骤并不必须按照特定的顺序来执行并且仍然可以实现期望的结果。在某些实施方式中,多任务处理和并行处理也是可以的或者可能是有利的。
[0151] 在本文中,针对本公开的多个实施例进行了描述,但为简明起见,各实施例的描述并不是详尽的,各个实施例之间相同或相似的特征或部分可能会被省略。在本文中,"一个实施例”、"一些实施例”、"示例”、"具体示例”、或"一些示例”意指适用于根据本公开的至少一个实施例或示例中,而非所有实施例。上述术语并不必然意味着指代相同的实施例或示例。在不相互矛盾的情况下,本领域的技术人员可以将本说明书中描述的不同实施例或示例以及不同实施例或示例的特征进行结合和组合。
[0152] 已参考上述实施例具体示出并描述了本公开的示例性系统及方法,其仅为实施本系统及方法的最佳模式的示例。本领域的技术人员可以理解的是可以在实施本系统及 / 或方法时对这里描述的系统及方法的实施例做各种改变而不脱离界定在所附权利要求中的本公开的精神及范围。< / style>
Claims
1. A style file processing method for a shadow document object model, It is characterized in that include: Acquire a target source style file according to a preset condition, wherein the target source style file includes a cascading style sheet to be processed in a shadow document object model; For the cascading style sheet to be processed, using the target style update logic to replace the native style update logic corresponding to the cascading style sheet to be processed in the front-end development framework; Based on the target style update logic that has been replaced in the front-end development framework, the cascading style sheet to be processed is extracted from the target source style file into a target style sheet file.
2. The form file processing method according to claim 1, It is characterized in that The step of obtaining the target source style file according to the preset conditions includes: According to the filtering conditions in the preset conditions, a filtering operation is performed on the source style file in the front-end development framework to obtain the target source style file containing the cascading style sheet to be processed.
3. The form file processing method according to claim 1, It is characterized in that The method of replacing the native style update logic corresponding to the cascading style sheet to be processed in the front-end development framework with the target style update logic for the cascading style sheet to be processed includes: Obtaining a container identifier of the target source style file containing the cascading style sheet to be processed; Obtaining a preset style update logic corresponding to the cascading style sheet to be processed; Adding the container identifier to the preset style update logic to obtain the target style update logic for replacement; The target style update logic is replaced with the style update logic corresponding to the cascading style sheet to be processed in the front-end development framework.
4. The method for processing a style file according to any one of claims 1 to 3, It is characterized in that The extracting the to-be-processed cascading style sheet from the target source style file into the target style sheet file based on the target style update logic replaced in the front-end development framework includes: Processing the target source style file according to the target style update logic to generate the cascading style sheet; According to the target style update logic, the generated cascading style sheet is configured into at least one of the target style sheet files.
5. A method for updating the style of a shadow document object model, It is characterized in that include: Acquire a target style file, wherein the target style file is obtained by processing a cascading style sheet of a shadow document object model using a style file processing method, and the style file processing method is the style file processing method according to any one of claims 1 to 4; Get a style tag including the cascading style sheet style parameters to be updated; Without reloading the hypertext markup language of the shadow document object model, the style tag is imported into the shadow document object model, and the corresponding style of the processed cascading style sheet in the target style file is updated according to the style parameter.
6. The style updating method according to claim 5, It is characterized in that The updating of the corresponding style of the cascading style sheet processed in the target style file according to the style parameter includes: If the style tag carries an identifier of a shadow document object model, updating a corresponding style of a first cascading style sheet, wherein the first cascading style sheet is the cascading style sheet of the shadow document object model corresponding to the identifier; and / or If the style tag does not carry an identifier of a shadow document object model or carries a wildcard, the corresponding style of a second cascading style sheet is updated, wherein the second cascading style sheet is the cascading style sheet of all shadow document object models in the front-end page.
7. A style file processing device for a shadow document object model, It is characterized in that include: an acquisition unit, configured to acquire a target source style file according to a preset condition, wherein the target source style file includes a cascading style sheet to be processed in a shadow document object model; A replacement unit is configured to replace the native style update logic corresponding to the cascading style sheet to be processed in the front-end development framework with the target style update logic for the cascading style sheet to be processed; as well as The extraction unit is configured to extract the cascading style sheet to be processed from the target source style file into a target style sheet file based on the target style update logic that has been replaced in the front-end development framework.
8. A style updating device for a shadow document object model, It is characterized in that include: The style file processing device according to claim 7, configured to process the cascading style sheet of the shadow document object model to obtain the target style file; An acquisition unit configured to acquire a style tag including a cascading style sheet style parameter to be updated; as well as The updating unit is configured to import the style tag into the shadow document object model without reloading the hypertext markup language of the shadow document object model, and update the corresponding style of the processed cascading style sheet in the target style file according to the style parameter.
9. An electronic device, It is characterized in that include: A processor and a memory storing a computer program, wherein the processor is configured to implement the method according to any one of claims 1 to 6 when executing the computer program.
10. A program product comprising a computer program, in, When the computer program is executed by a processor, the method according to any one of claims 1 to 6 is implemented.
