[go: up one dir, main page]

CN109558553B - Method and device for determining style - Google Patents

Method and device for determining style Download PDF

Info

Publication number
CN109558553B
CN109558553B CN201811385666.8A CN201811385666A CN109558553B CN 109558553 B CN109558553 B CN 109558553B CN 201811385666 A CN201811385666 A CN 201811385666A CN 109558553 B CN109558553 B CN 109558553B
Authority
CN
China
Prior art keywords
style
css
target node
selector
descendant
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN201811385666.8A
Other languages
Chinese (zh)
Other versions
CN109558553A (en
Inventor
董永清
杨亮
余鹏
沈妮
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Beijing Xiaomi Mobile Software Co Ltd
Original Assignee
Beijing Xiaomi Mobile Software Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Beijing Xiaomi Mobile Software Co Ltd filed Critical Beijing Xiaomi Mobile Software Co Ltd
Priority to CN201811385666.8A priority Critical patent/CN109558553B/en
Publication of CN109558553A publication Critical patent/CN109558553A/en
Application granted granted Critical
Publication of CN109558553B publication Critical patent/CN109558553B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING OR CALCULATING; COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/20Software design

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • General Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)
  • Devices For Executing Special Programs (AREA)

Abstract

The present disclosure relates to a pattern determination method and apparatus. The method comprises the following steps: after a target node of a view model instance is created, determining a target style information object on which the target node depends; the target style information object includes: the CSS-based selector comprises a style rule corresponding to a CSS basic selector, a style rule corresponding to a CSS descendant selector, a priority score of the style rule and index information of each CSS descendant selector; determining a style rule matched with the target node according to the index information of each CSS descendant selector; and combining the various formula rules matched with the target node according to the priority scores of the various formula rules to determine the style of the target node. The method and the device can help developers to improve development efficiency by supporting the offspring selectors, are simple to implement, and low in development and maintenance cost, and can improve pattern rule matching efficiency, application performance and user experience by storing the index information of each CSS offspring selector in the pattern information object.

Description

样式确定方法及装置Style determination method and device

技术领域Technical Field

本公开涉及终端技术领域,尤其涉及样式确定方法及装置。The present disclosure relates to the field of terminal technology, and in particular to a style determination method and device.

背景技术Background Art

随着智能终端技术的发展,出现了众多基于移动端、个人计算机(PC,PersonalComputer)端的开发平台以及操作系统。而为了将同一款应用推广至不同平台和操作系统,开发者需要针对不同平台和操作系统分别开发不同的版本,造成开发成本过高,维护工作量过大。鉴于此,设备商推出了诸如快应用平台等能够提供应用秒开功能的统一平台,为用户提供无需下载安装就可以立即使用应用的服务;快应用是基于终端硬件平台的新型应用形态,是一套以前端开发技术栈为主进行应用开发的框架,采用流行的前端开发模式,同时大幅提升应用性能,提供大量前端环境无法使用的系统能力和很多第三方服务的对接能力;基于快应用平台,开发者仅需编写一套代码,快应用可以运行于Android、IOS、Webview等不同开发平台和操作系统,并且开发者可以通过以编写传统html类似的语言方式来编写快应用,能够降低开发者对代码的开发成本,减少维护工作量。With the development of smart terminal technology, many development platforms and operating systems based on mobile terminals and personal computers (PCs) have emerged. In order to promote the same application to different platforms and operating systems, developers need to develop different versions for different platforms and operating systems, resulting in high development costs and excessive maintenance workload. In view of this, equipment manufacturers have launched unified platforms such as the Quick Application Platform that can provide the function of opening applications in seconds, providing users with services that allow them to use applications immediately without downloading and installing; Quick Application is a new application form based on the terminal hardware platform. It is a framework for application development based on the front-end development technology stack. It adopts the popular front-end development model and greatly improves application performance. It provides a large number of system capabilities that cannot be used in the front-end environment and the ability to connect to many third-party services; based on the Quick Application Platform, developers only need to write a set of codes, and Quick Application can run on different development platforms and operating systems such as Android, IOS, Webview, etc., and developers can write Quick Applications in a language similar to traditional HTML, which can reduce developers' code development costs and maintenance workload.

相关技术中,当前主流浏览器都支持层叠样式表(CSS,Cascading Style Sheets)后代选择器,并且支持很多的选择器和功能,例如包括通配符、及样式继承等。In the related art, current mainstream browsers all support Cascading Style Sheets (CSS) descendant selectors, and support many selectors and functions, such as wildcards, style inheritance, and the like.

发明内容Summary of the invention

为克服相关技术中存在的问题,本公开实施例提供一种样式确定方法及装置。所述技术方案如下:In order to overcome the problems existing in the related art, the present disclosure provides a method and device for determining a style. The technical solution is as follows:

根据本公开实施例的第一方面,提供一种样式确定方法,方法包括:According to a first aspect of an embodiment of the present disclosure, a style determination method is provided, the method comprising:

在创建视图模型实例的目标节点之后,确定所述目标节点所依赖的目标样式信息对象;所述目标样式信息对象包括:层叠样式表CSS基础选择器对应的样式规则、CSS后代选择器对应的样式规则、各所述样式规则的优先级分数、及各所述CSS后代选择器的索引信息;各所述CSS后代选择器的索引信息,用于记录将各所述CSS后代选择器按照CSS后代选择器的名称中最后一个基础选择器的名称进行分类后得到的分类结果;After creating a target node of the view model instance, determining a target style information object on which the target node depends; the target style information object includes: style rules corresponding to a CSS base selector, style rules corresponding to a CSS descendant selector, priority scores of each of the style rules, and index information of each of the CSS descendant selectors; the index information of each of the CSS descendant selectors is used to record a classification result obtained by classifying each of the CSS descendant selectors according to the name of the last base selector in the name of the CSS descendant selector;

根据所述目标样式信息对象中各所述CSS后代选择器的索引信息,确定所述目标节点匹配的样式规则;Determining the style rule matched by the target node according to the index information of each of the CSS descendant selectors in the target style information object;

根据所述目标节点所匹配的各所述样式规则的优先级分数,将所述目标节点匹配的各所述样式规则进行合并,确定所述目标节点的样式。According to the priority scores of the style rules matched by the target node, the style rules matched by the target node are merged to determine the style of the target node.

本公开的实施例提供的技术方案可以包括以下有益效果:该技术方案通过支持后代选择器,能够帮助开发者提高开发效率,实现简单,开发和维护成本低,通过在样式信息对象中保存各CSS后代选择器的索引信息,能够提升样式规则匹配效率,提升应用性能,提高用户体验。The technical solution provided by the embodiments of the present disclosure may include the following beneficial effects: the technical solution can help developers improve development efficiency by supporting descendant selectors, is simple to implement, and has low development and maintenance costs; and can improve style rule matching efficiency, application performance, and user experience by saving index information of each CSS descendant selector in a style information object.

在一个实施例中,所述方法还包括:In one embodiment, the method further comprises:

当创建所述视图模型实例的根节点时,编译样式代码,生成待注册样式信息对象;When creating the root node of the view model instance, compile the style code and generate a style information object to be registered;

在页面的文档上注册所述待注册样式信息对象;Registering the style information object to be registered on the document of the page;

在所述视图模型实例的根节点上绑定所述待注册样式信息对象的标识。The identifier of the style information object to be registered is bound to the root node of the view model instance.

在一个实施例中,所述确定所述目标节点所依赖的目标样式信息对象,包括:In one embodiment, determining the target style information object on which the target node depends includes:

获取所述目标节点所属的文档上注册的样式信息对象的集合;Obtain a collection of style information objects registered on the document to which the target node belongs;

获取所述目标节点所属的视图模型实例的根节点上绑定的样式信息对象的标识;Obtaining the identifier of the style information object bound to the root node of the view model instance to which the target node belongs;

根据所获取的样式信息对象的集合、及所获取的样式信息对象的标识,确定所述目标节点所依赖的目标样式信息对象。The target style information object on which the target node depends is determined according to the acquired set of style information objects and the identifiers of the acquired style information objects.

在一个实施例中,所述根据所述目标样式信息对象中各所述CSS后代选择器的索引信息,确定所述目标节点匹配的样式规则,包括:In one embodiment, determining the style rule matched by the target node according to the index information of each CSS descendant selector in the target style information object includes:

在所述目标样式信息对象所包括的各CSS基础选择器对应的样式规则中,查找所述目标节点匹配的第一CSS基础选择器;Searching for a first CSS base selector matching the target node in the style rules corresponding to each CSS base selector included in the target style information object;

在所述目标样式信息对象所包括的各所述CSS后代选择器的索引信息中,查找所述目标节点匹配的第二CSS基础选择器、及以所述第二CSS基础选择器的名称为索引的第一CSS后代选择器;Searching for a second CSS base selector matching the target node and a first CSS descendant selector with the name of the second CSS base selector as an index in the index information of each CSS descendant selector included in the target style information object;

获取所述目标节点的所有父节点;Get all parent nodes of the target node;

分别根据各所述父节点查找各所述第一CSS后代选择器中与所述目标节点匹配的第二CSS后代选择器;Searching for a second CSS descendant selector matching the target node in each of the first CSS descendant selectors according to each of the parent nodes;

根据所述第一CSS基础选择器和所述第二CSS后代选择器,确定所述目标节点匹配的样式规则。A style rule that matches the target node is determined according to the first CSS base selector and the second CSS descendant selector.

在一个实施例中,所述方法还包括:In one embodiment, the method further comprises:

将所确定的所述目标节点匹配的样式规则,按照样式规则的不同类别分类缓存至所述目标节点中。The determined style rules matching the target node are cached in the target node according to different categories of style rules.

在一个实施例中,所述根据所述目标节点所匹配的各所述样式规则的优先级分数,将所述目标节点匹配的各所述样式规则进行合并,确定所述目标节点的样式,包括:In one embodiment, merging the style rules matched by the target node according to the priority scores of the style rules matched by the target node to determine the style of the target node includes:

按照所述目标节点所匹配的各所述样式规则的优先级分数由小到大的顺序,将各所述样式规则进行排序;Sort the style rules matched by the target node in ascending order of priority scores;

通过优先级分数大的样式规则覆盖优先级分数小的样式规则,将排序后各所述样式规则进行合并,得到所述目标节点的样式。The style rules with larger priority scores are used to cover the style rules with smaller priority scores, and the sorted style rules are merged to obtain the style of the target node.

根据本公开实施例的第二方面,提供一种样式确定装置,包括:According to a second aspect of an embodiment of the present disclosure, a pattern determination device is provided, including:

目标样式信息对象确定模块,用于在创建视图模型实例的目标节点之后,确定所述目标节点所依赖的目标样式信息对象;所述目标样式信息对象包括:层叠样式表CSS基础选择器对应的样式规则、CSS后代选择器对应的样式规则、各所述样式规则的优先级分数、及各所述CSS后代选择器的索引信息;各所述CSS后代选择器的索引信息,用于记录将各所述CSS后代选择器按照CSS后代选择器的名称中最后一个基础选择器的名称进行分类后得到的分类结果;A target style information object determination module is used to determine the target style information object that the target node depends on after creating the target node of the view model instance; the target style information object includes: style rules corresponding to the CSS base selector of the cascading style sheet, style rules corresponding to the CSS descendant selector, priority scores of each style rule, and index information of each CSS descendant selector; the index information of each CSS descendant selector is used to record the classification result obtained after classifying each CSS descendant selector according to the name of the last base selector in the name of the CSS descendant selector;

样式规则确定模块,用于根据所述目标样式信息对象中各所述CSS后代选择器的索引信息,确定所述目标节点匹配的样式规则;A style rule determination module, used to determine the style rule matched by the target node according to the index information of each CSS descendant selector in the target style information object;

样式确定模块,用于根据所述目标节点所匹配的各所述样式规则的优先级分数,将所述目标节点匹配的各所述样式规则进行合并,确定所述目标节点的样式。The style determination module is used to merge the style rules matched by the target node according to the priority scores of the style rules matched by the target node, so as to determine the style of the target node.

在一个实施例中,所述装置还包括:In one embodiment, the apparatus further comprises:

生成模块,用于当创建所述视图模型实例的根节点时,编译样式代码,生成待注册样式信息对象;A generation module, used for compiling the style code and generating a style information object to be registered when creating the root node of the view model instance;

注册模块,用于在页面的文档上注册所述待注册样式信息对象;A registration module, used to register the style information object to be registered on the document of the page;

绑定模块,用于在所述视图模型实例的根节点上绑定所述待注册样式信息对象的标识。A binding module is used to bind the identifier of the style information object to be registered to the root node of the view model instance.

在一个实施例中,所述目标样式信息对象确定模块,包括:In one embodiment, the target style information object determination module includes:

第一获取子模块,用于获取所述目标节点所属的文档上注册的样式信息对象的集合;A first acquisition submodule is used to acquire a set of style information objects registered on the document to which the target node belongs;

第二获取子模块,用于获取所述目标节点所属的视图模型实例的根节点上绑定的样式信息对象的标识;A second acquisition submodule is used to acquire the identifier of the style information object bound to the root node of the view model instance to which the target node belongs;

第一确定子模块,用于根据所获取的样式信息对象的集合、及所获取的样式信息对象的标识,确定所述目标节点所依赖的目标样式信息对象。The first determination submodule is used to determine the target style information object on which the target node depends according to the acquired set of style information objects and the acquired identifiers of the style information objects.

在一个实施例中,所述样式规则确定模块,包括:In one embodiment, the style rule determination module includes:

第一查找子模块,用于在所述目标样式信息对象所包括的各CSS基础选择器对应的样式规则中,查找所述目标节点匹配的第一CSS基础选择器;A first search submodule, configured to search for a first CSS basic selector matching the target node in style rules corresponding to each CSS basic selector included in the target style information object;

第二查找子模块,用于在所述目标样式信息对象所包括的各所述CSS后代选择器的索引信息中,查找所述目标节点匹配的第二CSS基础选择器、及以所述第二CSS基础选择器的名称为索引的第一CSS后代选择器;A second search submodule is configured to search, in the index information of each of the CSS descendant selectors included in the target style information object, a second CSS base selector matching the target node and a first CSS descendant selector with the name of the second CSS base selector as an index;

第三获取子模块,用于获取所述目标节点的所有父节点;A third acquisition submodule is used to acquire all parent nodes of the target node;

匹配子模块,用于分别根据各所述父节点查找各所述第一CSS后代选择器中与所述目标节点匹配的第二CSS后代选择器;A matching submodule, used for searching, according to each of the parent nodes, for a second CSS descendant selector in each of the first CSS descendant selectors that matches the target node;

第二确定子模块,用于根据所述第一CSS基础选择器和所述第二CSS后代选择器,确定所述目标节点匹配的样式规则。The second determination submodule is used to determine the style rule matched by the target node according to the first CSS base selector and the second CSS descendant selector.

在一个实施例中,所述装置还包括:In one embodiment, the apparatus further comprises:

缓存模块,用于将所确定的所述目标节点匹配的样式规则,按照样式规则的不同类别分类缓存至所述目标节点中。The cache module is used to cache the determined style rules matched by the target node into the target node according to different categories of style rules.

在一个实施例中,所述样式确定模块,包括:In one embodiment, the style determination module includes:

排序子模块,用于按照所述目标节点所匹配的各所述样式规则的优先级分数由小到大的顺序,将各所述样式规则进行排序;A sorting submodule, used to sort the style rules matched by the target node in ascending order of priority scores of the style rules;

合并子模块,用于通过优先级分数大的样式规则覆盖优先级分数小的样式规则,将排序后各所述样式规则进行合并,得到所述目标节点的样式。The merging submodule is used to cover the style rules with smaller priority scores with the style rules with larger priority scores, and merge the sorted style rules to obtain the style of the target node.

根据本公开实施例的第三方面,提供一种样式确定装置,包括:According to a third aspect of an embodiment of the present disclosure, a pattern determination device is provided, including:

处理器;processor;

用于存储处理器可执行指令的存储器;a memory for storing processor-executable instructions;

其中,所述处理器被配置为:Wherein, the processor is configured to:

在创建视图模型实例的目标节点之后,确定所述目标节点所依赖的目标样式信息对象;所述目标样式信息对象包括:层叠样式表CSS基础选择器对应的样式规则、CSS后代选择器对应的样式规则、各所述样式规则的优先级分数、及各所述CSS后代选择器的索引信息;各所述CSS后代选择器的索引信息,用于记录将各所述CSS后代选择器按照CSS后代选择器的名称中最后一个基础选择器的名称进行分类后得到的分类结果;After creating a target node of the view model instance, determining a target style information object on which the target node depends; the target style information object includes: style rules corresponding to a CSS base selector, style rules corresponding to a CSS descendant selector, priority scores of each of the style rules, and index information of each of the CSS descendant selectors; the index information of each of the CSS descendant selectors is used to record a classification result obtained by classifying each of the CSS descendant selectors according to the name of the last base selector in the name of the CSS descendant selector;

根据所述目标样式信息对象中各所述CSS后代选择器的索引信息,确定所述目标节点匹配的样式规则;Determining the style rule matched by the target node according to the index information of each of the CSS descendant selectors in the target style information object;

根据所述目标节点所匹配的各所述样式规则的优先级分数,将所述目标节点匹配的各所述样式规则进行合并,确定所述目标节点的样式。According to the priority scores of the style rules matched by the target node, the style rules matched by the target node are merged to determine the style of the target node.

根据本公开实施例的第四方面,提供一种计算机可读存储介质,其上存储有计算机指令,该指令被处理器执行时实现上述第一方面所述方法的步骤。According to a fourth aspect of an embodiment of the present disclosure, there is provided a computer-readable storage medium on which computer instructions are stored, and when the instructions are executed by a processor, the steps of the method described in the first aspect are implemented.

应当理解的是,以上的一般描述和后文的细节描述仅是示例性和解释性的,并不能限制本公开。It is to be understood that the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the present disclosure.

附图说明BRIEF DESCRIPTION OF THE DRAWINGS

此处的附图被并入说明书中并构成本说明书的一部分,示出了符合本公开的实施例,并与说明书一起用于解释本公开的原理。The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present disclosure and, together with the description, serve to explain the principles of the present disclosure.

图1是根据一示例性实施例示出的样式确定方法的流程图。Fig. 1 is a flowchart of a method for determining a style according to an exemplary embodiment.

图2是根据一示例性实施例示出的样式确定方法的流程图。Fig. 2 is a flowchart of a method for determining a style according to an exemplary embodiment.

图3是根据一示例性实施例示出的样式确定装置的框图。Fig. 3 is a block diagram of a pattern determination device according to an exemplary embodiment.

图4是根据一示例性实施例示出的样式确定装置的框图。Fig. 4 is a block diagram of a pattern determination device according to an exemplary embodiment.

图5是根据一示例性实施例示出的样式确定装置的框图。Fig. 5 is a block diagram of a pattern determination device according to an exemplary embodiment.

图6是根据一示例性实施例示出的样式确定装置的框图。Fig. 6 is a block diagram of a pattern determination device according to an exemplary embodiment.

图7是根据一示例性实施例示出的样式确定装置的框图。Fig. 7 is a block diagram of a pattern determination device according to an exemplary embodiment.

图8是根据一示例性实施例示出的样式确定装置的框图。Fig. 8 is a block diagram of a pattern determination device according to an exemplary embodiment.

图9是根据一示例性实施例示出的样式确定装置的框图。Fig. 9 is a block diagram of a pattern determination device according to an exemplary embodiment.

图10是根据一示例性实施例示出的样式确定装置的框图。Fig. 10 is a block diagram of a pattern determination device according to an exemplary embodiment.

图11是根据一示例性实施例示出的样式确定装置的框图。Fig. 11 is a block diagram of a pattern determination device according to an exemplary embodiment.

具体实施方式DETAILED DESCRIPTION

这里将详细地对示例性实施例进行说明,其示例表示在附图中。下面的描述涉及附图时,除非另有表示,不同附图中的相同数字表示相同或相似的要素。以下示例性实施例中所描述的实施方式并不代表与本公开相一致的所有实施方式。相反,它们仅是与如所附权利要求书中所详述的、本公开的一些方面相一致的装置和方法的例子。Exemplary embodiments will be described in detail herein, examples of which are shown in the accompanying drawings. When the following description refers to the drawings, the same numbers in different drawings represent the same or similar elements unless otherwise indicated. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with the present disclosure. Instead, they are merely examples of devices and methods consistent with some aspects of the present disclosure as detailed in the appended claims.

相关技术中,当前主流浏览器都支持CSS后代选择器,并且支持很多的选择器和功能,例如包括通配符、及样式继承等,但是,这也为开发者带来了挑战,若开发者没有性能优化意识,很可能导致性能问题,影响用户体验,并且由于浏览器的实现复杂,导致浏览器的开发和维护成本较高。In the related technology, current mainstream browsers all support CSS descendant selectors, and support many selectors and functions, such as wildcards and style inheritance. However, this also brings challenges to developers. If developers are not aware of performance optimization, it is likely to cause performance problems and affect user experience. In addition, due to the complexity of browser implementation, the development and maintenance costs of the browser are high.

为了解决上述问题,本公开实施例提供了一种样式确定方法,方法包括:在创建视图模型(VM,View Model)实例的目标节点之后,确定目标节点所依赖的目标样式信息对象;目标样式信息对象包括:CSS基础选择器对应的样式规则、CSS后代选择器对应的样式规则、各样式规则的优先级分数、及各CSS后代选择器的索引信息;各CSS后代选择器的索引信息,用于记录将各CSS后代选择器按照CSS后代选择器的名称中最后一个基础选择器的名称进行分类后得到的分类结果;根据目标样式信息对象中各CSS后代选择器的索引信息,确定目标节点匹配的样式规则;根据目标节点所匹配的各样式规则的优先级分数,将目标节点匹配的各样式规则进行合并,确定目标节点的样式。本公开实施例提供的样式确定方法,通过支持后代选择器,能够帮助开发者提高开发效率,实现简单,开发和维护成本低,通过在样式信息对象中保存各CSS后代选择器的索引信息,能够提升样式规则匹配效率,提升应用性能,提高用户体验。In order to solve the above problems, the embodiment of the present disclosure provides a style determination method, the method comprising: after creating a target node of a view model (VM, View Model) instance, determining a target style information object on which the target node depends; the target style information object comprises: style rules corresponding to CSS base selectors, style rules corresponding to CSS descendant selectors, priority scores of each style rule, and index information of each CSS descendant selector; the index information of each CSS descendant selector is used to record the classification result obtained after classifying each CSS descendant selector according to the name of the last base selector in the name of the CSS descendant selector; according to the index information of each CSS descendant selector in the target style information object, determining the style rule matched by the target node; according to the priority score of each style rule matched by the target node, merging each style rule matched by the target node to determine the style of the target node. The style determination method provided by the embodiment of the present disclosure can help developers improve development efficiency by supporting descendant selectors, is simple to implement, and has low development and maintenance costs. By saving the index information of each CSS descendant selector in the style information object, the style rule matching efficiency can be improved, the application performance can be improved, and the user experience can be improved.

本公开实施例中涉及的应用(app),例如为混合应用(Hyvrid app),但本公开并不以此为限。为更好的说明本公开中的实施例,进行以下说明:应用通常可以包括:原生应用(Native app)、网页应用(Web app)和混合应用(Hyvrid app);其中,原生应用是针对不同智能手机操作系统单独开发的本地应用,如需使用需要先下载到终端并安装,下载Nativeapp的最常见方法是访问应用程序商店,如苹果的应用商店(App Store)、安卓市场、谷歌商店(Google Play)等。Web应用是一个触屏版的网站,Web应用完全用Html、加瓦脚本(JS,JavaScript)和CSS等Web技术开发,通过终端的浏览器来访问,缺点是这些基于浏览器的应用无法调用系统应用程序编程接口(API,Application Programming Interface)来实现一些高级功能,也不适合高性能要求的场合。混合应用是一种介于Native app与Web app之间的app,虽然混合应用看上去是一个Native app,但只是一个UI WebView,里面访问的是一个Web App;混合应用的实质是伪造一个浏览器的apk/ipa原生程序,并运行了一个Webapp;Hybrid app兼具“Native app良好用户交互体验的优势”和“Web app跨平台开发的优势”,它可以使web开发人员可以几乎零成本的转型成移动应用开发者,并且相同的代码只需进行编译就能实现在多平台的分发,相较于Web app,开发者可以通过包装好的接口,调用大部分常用的系统API;其中,应用平台为用户提供无需下载安装就可以立即使用混合应用的服务,基于应用平台,开发者仅需编写一套代码,混合应用可以运行于Android、IOS、Webview等不同开发平台和操作系统,能够降低开发者对代码的开发成本和维护工作量。The application (app) involved in the embodiments of the present disclosure is, for example, a hybrid application (Hyvrid app), but the present disclosure is not limited thereto. To better illustrate the embodiments of the present disclosure, the following description is made: Applications can generally include: native applications (Native app), web applications (Web app) and hybrid applications (Hyvrid app); wherein, native applications are local applications developed separately for different smartphone operating systems, which need to be downloaded to the terminal and installed before use. The most common way to download Native apps is to visit application stores, such as Apple's App Store, Android Market, Google Play, etc. A web application is a touch-screen website. Web applications are completely developed using Web technologies such as Html, JavaScript (JS) and CSS, and are accessed through the browser of the terminal. The disadvantage is that these browser-based applications cannot call the system application programming interface (API, Application Programming Interface) to implement some advanced functions, and are not suitable for occasions with high performance requirements. A hybrid app is an app between a Native app and a Web app. Although a hybrid app looks like a Native app, it is just a UI WebView that accesses a Web app. The essence of a hybrid app is to forge an apk/ipa native program of a browser and run a Web app. A Hybrid app has both the "advantages of a good user interaction experience of a Native app" and the "advantages of cross-platform development of a Web app". It allows web developers to transform into mobile application developers at almost zero cost, and the same code can be distributed on multiple platforms by simply compiling. Compared with a Web app, developers can call most of the commonly used system APIs through packaged interfaces. Among them, the application platform provides users with services that allow them to use hybrid applications immediately without downloading and installing. Based on the application platform, developers only need to write one set of code. Hybrid applications can run on different development platforms and operating systems such as Android, IOS, and Webview, which can reduce developers' code development costs and maintenance workload.

需要说明的是,本公开实施例提供的样式确定方法,可以应用于诸如快应用平台等能够提供应用秒开功能的统一平台。It should be noted that the style determination method provided in the embodiments of the present disclosure can be applied to a unified platform such as a quick application platform that can provide an application opening function in seconds.

基于上述分析,提出以下各具体实施例。Based on the above analysis, the following specific embodiments are proposed.

图1是根据一示例性实施例示出的一种样式确定方法的流程图,该方法的执行主体可以为终端,例如智能手机、笔记本、或智能穿戴设备等电子设备;如图1所示,该方法包括以下步骤101-103:FIG. 1 is a flow chart of a method for determining a style according to an exemplary embodiment. The method may be performed by a terminal, such as a smart phone, a notebook, or an electronic device such as a smart wearable device. As shown in FIG. 1 , the method includes the following steps 101-103:

在步骤101中,在创建视图模型实例的目标节点之后,确定目标节点所依赖的目标样式信息对象;目标样式信息对象包括:CSS基础选择器对应的样式规则、CSS后代选择器对应的样式规则、各样式规则的优先级分数、及各CSS后代选择器的索引信息;各CSS后代选择器的索引信息,用于记录将各CSS后代选择器按照CSS后代选择器的名称中最后一个基础选择器的名称进行分类后得到的分类结果。In step 101, after creating the target node of the view model instance, determine the target style information object that the target node depends on; the target style information object includes: style rules corresponding to the CSS base selector, style rules corresponding to the CSS descendant selector, priority scores of each style rule, and index information of each CSS descendant selector; the index information of each CSS descendant selector is used to record the classification result obtained after classifying each CSS descendant selector according to the name of the last base selector in the name of the CSS descendant selector.

示例的,创建视图模型实例时会编译创建DOM节点,当DOM节点创建成功后,要将DOM节点插入到DOM树中,在此过程中,需要先计算出节点实际匹配的多个样式规则(CSSRule)。目标节点即为目标DOM节点。For example, when creating a view model instance, a DOM node will be compiled and created. When the DOM node is successfully created, it is necessary to insert the DOM node into the DOM tree. During this process, it is necessary to first calculate the multiple style rules (CSSRule) that the node actually matches. The target node is the target DOM node.

示例的,在目标节点创建之后,获取目标节点所属的文档上注册的样式信息对象的集合;获取目标节点所属的视图模型实例的根节点上绑定的样式信息对象的标识;根据所获取的样式信息对象的集合、及所获取的样式信息对象的标识,确定目标节点所依赖的目标样式信息对象。For example, after the target node is created, obtain a collection of style information objects registered on the document to which the target node belongs; obtain the identifier of the style information object bound to the root node of the view model instance to which the target node belongs; and determine the target style information object on which the target node depends based on the obtained collection of style information objects and the obtained identifier of the style information object.

需要说明的是,样式信息对象是指处理样式时生成的一种中间数据,在样式信息对象中储存样式计算所需的信息。It should be noted that the style information object refers to a kind of intermediate data generated when processing a style, and the information required for style calculation is stored in the style information object.

示例的,当创建视图模型实例的根节点时,通过编译样式代码,生成待注册样式信息对象;在页面的文档(Document)上注册待注册样式信息对象;在视图模型实例的根节点上绑定待注册样式信息对象的标识。For example, when creating the root node of the view model instance, the style information object to be registered is generated by compiling the style code; the style information object to be registered is registered on the document of the page; and the identifier of the style information object to be registered is bound to the root node of the view model instance.

在步骤102中,根据目标样式信息对象中各CSS后代选择器的索引信息,确定目标节点匹配的样式规则。In step 102, the style rule matched by the target node is determined according to the index information of each CSS descendant selector in the target style information object.

示例的,可以将样式规则分为不同类别,例如类别为:行内样式(inline)、标签(tag)、类(class)、标识(id)。在计算目标点匹配的样式规则时,按照不同的样式规则类别分别计算,在tag、class、id中,又分为基础和后代两种样式规则类别分别计算。For example, style rules can be divided into different categories, such as inline, tag, class, and id. When calculating the style rules matched by the target point, they are calculated according to different style rule categories. Among tag, class, and id, they are divided into two style rule categories: base and descendant.

在目标样式信息对象所包括的各CSS基础选择器对应的样式规则中,查找目标节点匹配的第一CSS基础选择器;若在目标样式信息对象所包括的各CSS后代选择器的索引信息中,查找到目标节点匹配的第二CSS基础选择器、及以第二CSS基础选择器的名称为索引的第一CSS后代选择器,则获取目标节点的所有父节点,再分别根据各父节点查找各第一CSS后代选择器中与目标节点匹配的第二CSS后代选择器;根据第一CSS基础选择器和第二CSS后代选择器,确定目标节点匹配的样式规则。可见,通过使用目标样式信息对象所包括的各CSS后代选择器的索引信息,根据基础选择器就找到所有可能的后代选择器,缩小匹配范围,提升样式规则匹配的效率。In the style rules corresponding to each CSS base selector included in the target style information object, search for the first CSS base selector that matches the target node; if the second CSS base selector that matches the target node and the first CSS descendant selector indexed by the name of the second CSS base selector are found in the index information of each CSS descendant selector included in the target style information object, then obtain all parent nodes of the target node, and then search for the second CSS descendant selector that matches the target node in each first CSS descendant selector according to each parent node; determine the style rule that matches the target node according to the first CSS base selector and the second CSS descendant selector. It can be seen that by using the index information of each CSS descendant selector included in the target style information object, all possible descendant selectors can be found according to the base selector, narrowing the matching range and improving the efficiency of style rule matching.

示例的,在确定目标节点匹配的样式规则之后,将所确定的目标节点匹配的样式规则,按照样式规则的不同类别分类缓存至目标节点中;当后续更新部分类别时,仅需重新计算相应类别匹配的CSS Rule,其他类别不需要重新计算,直接使用缓存即可,能够提高样式规则匹配性能。For example, after determining the style rules that match the target node, the style rules that match the target node are cached in the target node according to different categories of style rules; when some categories are subsequently updated, only the CSS Rules that match the corresponding categories need to be recalculated, and other categories do not need to be recalculated and can be directly used with the cache, which can improve the style rule matching performance.

在步骤103中,根据目标节点所匹配的各样式规则的优先级分数,将目标节点匹配的各样式规则进行合并,确定目标节点的样式。In step 103, the style rules matched by the target node are merged according to the priority scores of the style rules matched by the target node to determine the style of the target node.

示例的,按照目标节点所匹配的各样式规则的优先级分数由小到大的顺序,将各样式规则进行排序;通过优先级分数大的样式规则覆盖优先级分数小的样式规则,将排序后各样式规则进行合并,得到目标节点的样式。For example, the style rules are sorted in ascending order according to the priority scores of the style rules matched by the target node; the style rules with large priority scores cover the style rules with small priority scores, and the sorted style rules are merged to obtain the style of the target node.

本公开的实施例提供的技术方案,通过支持后代选择器,能够帮助开发者提高开发效率,实现简单,开发和维护成本低,通过在样式信息对象中保存各CSS后代选择器的索引信息,能够提升样式规则匹配效率,提升应用性能,提高用户体验。The technical solution provided by the embodiments of the present disclosure can help developers improve development efficiency by supporting descendant selectors, and is simple to implement with low development and maintenance costs. By saving the index information of each CSS descendant selector in the style information object, the style rule matching efficiency can be improved, the application performance can be improved, and the user experience can be improved.

图2是根据一示例性实施例示出的一种样式确定方法的流程图。如图2所示,在图1所示实施例的基础上,本公开涉及的样式确定方法可以包括以下步骤201-208:FIG2 is a flow chart of a method for determining a style according to an exemplary embodiment. As shown in FIG2 , based on the embodiment shown in FIG1 , the method for determining a style involved in the present disclosure may include the following steps 201-208:

在步骤201中,当创建视图模型实例的根节点时,编译样式代码,生成待注册样式信息对象;在页面的文档上注册待注册样式信息对象;在视图模型实例的根节点上绑定待注册样式信息对象的标识。In step 201, when creating the root node of the view model instance, compile the style code to generate the style information object to be registered; register the style information object to be registered on the document of the page; and bind the identifier of the style information object to be registered on the root node of the view model instance.

在步骤202中,在创建视图模型实例的目标节点之后,获取目标节点所属的文档上注册的样式信息对象的集合;获取目标节点所属的视图模型实例的根节点上绑定的样式信息对象的标识。In step 202, after creating the target node of the view model instance, obtain the collection of style information objects registered on the document to which the target node belongs; obtain the identifier of the style information object bound to the root node of the view model instance to which the target node belongs.

在步骤203中,根据所获取的样式信息对象的集合、及所获取的样式信息对象的标识,确定目标节点所依赖的目标样式信息对象;目标样式信息对象包括:CSS基础选择器对应的样式规则、CSS后代选择器对应的样式规则、各样式规则的优先级分数、及各CSS后代选择器的索引信息;各CSS后代选择器的索引信息,用于记录将各CSS后代选择器按照CSS后代选择器的名称中最后一个基础选择器的名称进行分类后得到的分类结果。In step 203, the target style information object on which the target node depends is determined according to the set of style information objects obtained and the identifiers of the style information objects obtained; the target style information object includes: style rules corresponding to the CSS base selector, style rules corresponding to the CSS descendant selector, priority scores of each style rule, and index information of each CSS descendant selector; the index information of each CSS descendant selector is used to record the classification result obtained after classifying each CSS descendant selector according to the name of the last base selector in the name of the CSS descendant selector.

在步骤204中,在目标样式信息对象所包括的各CSS基础选择器对应的样式规则中,查找目标节点匹配的第一CSS基础选择器。In step 204, the first CSS base selector matching the target node is searched in the style rules corresponding to the CSS base selectors included in the target style information object.

在步骤205中,在目标样式信息对象所包括的各CSS后代选择器的索引信息中,查找目标节点匹配的第二CSS基础选择器、及以第二CSS基础选择器的名称为索引的第一CSS后代选择器。In step 205, the second CSS base selector matching the target node and the first CSS descendant selector with the name of the second CSS base selector as the index are searched in the index information of each CSS descendant selector included in the target style information object.

在步骤206中,获取目标节点的所有父节点;分别根据目标节点的各父节点查找各第一CSS后代选择器中与目标节点匹配的第二CSS后代选择器;根据第一CSS基础选择器和第二CSS后代选择器,确定目标节点匹配的样式规则。In step 206, all parent nodes of the target node are obtained; the second CSS descendant selector that matches the target node in each first CSS descendant selector is searched according to each parent node of the target node; and the style rule that matches the target node is determined according to the first CSS base selector and the second CSS descendant selector.

在步骤207中,将所确定的目标节点匹配的样式规则,按照样式规则的不同类别分类缓存至目标节点中。In step 207, the style rules matched by the determined target node are classified and cached in the target node according to different categories of the style rules.

在步骤208中,按照目标节点所匹配的各样式规则的优先级分数由小到大的顺序,将各样式规则进行排序;通过优先级分数大的样式规则覆盖优先级分数小的样式规则,将排序后各样式规则进行合并,得到目标节点的样式。In step 208, the style rules matched by the target node are sorted in ascending order according to their priority scores; style rules with smaller priority scores are covered by style rules with larger priority scores, and the sorted style rules are merged to obtain the style of the target node.

本公开的实施例提供的技术方案,通过支持后代选择器,能够帮助开发者提高开发效率,通过使用目标样式信息对象所包括的各CSS后代选择器的索引信息,根据基础选择器就找到所有可能的后代选择器,缩小匹配范围,提升样式规则匹配的效率,通过将样式规则按照不同类别分类缓存至目标节点中,能够提高样式规则匹配性能。The technical solution provided by the embodiments of the present disclosure can help developers improve development efficiency by supporting descendant selectors. By using the index information of each CSS descendant selector included in the target style information object, all possible descendant selectors can be found according to the basic selector, thereby narrowing the matching range and improving the efficiency of style rule matching. By caching style rules into target nodes according to different categories, the style rule matching performance can be improved.

作为一种可能的实施例,这里提供一种支持后代选择器的样式确定方法,在快应用等以前端开发技术栈为主进行应用开发的框架中支持后代选择器;以如下源代码为例,阐述技术方案的完整内容:As a possible embodiment, a method for determining a style that supports a descendant selector is provided here, which supports descendant selectors in a framework such as a quick application that mainly uses a front-end development technology stack for application development; the complete content of the technical solution is described using the following source code as an example:

Figure BDA0001872888000000111
Figure BDA0001872888000000111

Figure BDA0001872888000000121
Figure BDA0001872888000000121

阶段一:生成及注册样式信息对象Phase 1: Generate and register style information objects

创建视图模型实例时,会编译创建DOM节点。编译创建DOM节点时,会检测当前VM实例上是否已经存在VM的根节点,若VM上还没有根节点,则生成及注册样式信息对象。When creating a view model instance, the DOM node will be compiled and created. When compiling and creating a DOM node, it will detect whether the root node of the VM already exists on the current VM instance. If there is no root node on the VM, a style information object will be generated and registered.

具体步骤和说明如下:The specific steps and instructions are as follows:

1>生成样式信息对象1>Generate style information object

编译style样式代码(即上面示例中的<style>与</style>标签内的代码),生成样式信息对象。这个样式信息对象保存了后面样式计算所需的所有信息;其中的两个重点属性是:1)CSS Rule的优先级分数;2)以某个基础选择器结束的后代选择器列表(即本公开中涉及的各CSS后代选择器的索引信息)。样式信息对象示例如下:Compile the style code (i.e. the code within the <style> and </style> tags in the above example) to generate a style information object. This style information object stores all the information required for subsequent style calculations; two key attributes are: 1) the priority score of the CSS Rule; 2) the list of descendant selectors ending with a certain base selector (i.e. the index information of each CSS descendant selector involved in this disclosure). An example of a style information object is as follows:

Figure BDA0001872888000000122
Figure BDA0001872888000000122

Figure BDA0001872888000000131
Figure BDA0001872888000000131

2>注册样式信息对象2>Register style information object

在页面的Document上注册上述样式信息对象;在VM的根节点上绑定样式信息对象的标识(Id),便于在后续计算DOM节点匹配的样式时,获取节点所依赖的样式信息对象。Register the above style information object on the Document of the page; bind the identifier (Id) of the style information object to the root node of the VM, so as to obtain the style information object that the node depends on when calculating the style matching the DOM node later.

阶段二:计算节点匹配的样式规则(CSS Rule)列表Phase 2: Calculate the list of CSS rules that match the node

DOM节点创建成功后,要将DOM节点插入到DOM树中,在此过程中,需要先计算出节点实际匹配的多个CSS Rule。具体步骤和说明如下:After the DOM node is created successfully, it needs to be inserted into the DOM tree. During this process, it is necessary to first calculate the multiple CSS Rules that the node actually matches. The specific steps and instructions are as follows:

1>获取DOM节点依赖的样式信息对象1>Get the style information object that the DOM node depends on

通过DOM节点中保存的信息,找到其对应的Document,获取Document上注册的样式信息对象的集合;再从这个DOM节点起,开始向父节点查找,一直找到DOM节点所属的VM的根节点,获取根节点上绑定的样式信息对象的Id。最终,结合样式信息对象的集合和特定的样式信息对象的Id,获取节点所依赖的样式信息对象。Through the information stored in the DOM node, find the corresponding Document and obtain the collection of style information objects registered on the Document; then start searching from this DOM node to the parent node, and continue to find the root node of the VM to which the DOM node belongs, and obtain the ID of the style information object bound to the root node. Finally, combine the collection of style information objects and the ID of a specific style information object to obtain the style information object that the node depends on.

2>计算DOM节点匹配的CSS Rule列表2> Calculate the CSS Rule list that matches the DOM node

DOM节点匹配的样式规则分为4类:inline、tag、class、id。在计算DOM节点匹配的CSS Rule列表时,按照这四类分别计算,在tag、class、id中,又分为基础和后代两种类别分别计算。若能在“nameHash”中找到对应的基础选择器,则加入DOM节点匹配的CSS Rule列表中;若能在“descLast”中找到对应的基础选择器,则获取当前DOM节点的父节点数组,再根据父节点数组判断CSS Selector是否匹配当前节点。最后,得到所有匹配的CSS Rule列表。The style rules matched by DOM nodes are divided into four categories: inline, tag, class, and id. When calculating the CSS Rule list matched by the DOM node, calculate according to these four categories. In tag, class, and id, they are divided into two categories: base and descendant. If the corresponding base selector can be found in "nameHash", add it to the CSS Rule list matched by the DOM node; if the corresponding base selector can be found in "descLast", get the parent node array of the current DOM node, and then determine whether the CSS Selector matches the current node based on the parent node array. Finally, get a list of all matching CSS Rules.

在分为四类分别计算时,会将计算的结果按照类别缓存到节点中;当后续更新部分类别时,仅需重新计算自己类别匹配CSS Rule,其他类别使用缓存即可,优化了性能。When the calculations are divided into four categories, the calculation results will be cached in the node according to the category; when some categories are updated later, only the matching CSS Rule of their own category needs to be recalculated, and the cache can be used for other categories, which optimizes performance.

阶段三:合并节点匹配的CSS Rule列表Phase 3: Merge the CSS Rule list that matches the node

在JS将节点转成消息发送给Native前,将DOM节点中匹配的CSS Rule进行合并。具体步骤及说明如下:Before JS converts the node into a message and sends it to Native, the matching CSS Rules in the DOM node are merged. The specific steps and instructions are as follows:

1>CSS Rule排序1>CSS Rule sorting

按照CSS Rule的优先级进行从小到大的排序。Sort CSS Rules in ascending order according to their priority.

2>CSS Rule合并2>CSS Rule Merge

按照后者覆盖前者的规则,合并DOM节点的样式。Merge the styles of DOM nodes according to the rule that the latter overrides the former.

至此成功计算出了包含CSS后代选择器的样式,支持了CSS后代选择器。So far, the style including CSS descendant selectors has been successfully calculated, and CSS descendant selectors are supported.

本公开的实施例提供的技术方案,通过样式信息对象加入descLast属性,通过保存以某个基础选择器结束后代选择器列表,提升后续计算的效率;按照inline、tag、class、id四类计算节点匹配的CSS Rule时,按照类别缓存;当仅更新部分类别时,其他类别不需要重新计算,只需使用缓存即可,提高了效率,能够支持CSS后代选择器,帮助开发者提高开发效率。The technical solution provided by the embodiments of the present disclosure adds a descLast attribute to the style information object, and improves the efficiency of subsequent calculations by saving a list of descendant selectors that end with a certain basic selector; when calculating the CSS Rule matching the nodes according to the four categories of inline, tag, class, and id, cache is performed according to category; when only some categories are updated, other categories do not need to be recalculated, and only the cache needs to be used, which improves efficiency, can support CSS descendant selectors, and help developers improve development efficiency.

下述为本公开装置实施例,可以用于执行本公开方法实施例。The following are embodiments of the apparatus of the present disclosure, which can be used to execute embodiments of the method of the present disclosure.

图3是根据一示例性实施例示出的一种样式确定装置的框图;该装置可以采用各种方式来实施,例如在终端中实施装置的全部组件,或者,在终端侧以耦合的方式实施装置中的组件;该装置可以通过软件、硬件或者两者的结合实现上述本公开涉及的方法,如图3所示,该样式确定装置包括:目标样式信息对象确定模块301、样式规则确定模块302及样式确定模块303,其中:FIG3 is a block diagram of a style determination device according to an exemplary embodiment; the device may be implemented in various ways, such as implementing all components of the device in a terminal, or implementing components in the device in a coupled manner on the terminal side; the device may implement the method involved in the present disclosure through software, hardware, or a combination of both. As shown in FIG3 , the style determination device includes: a target style information object determination module 301, a style rule determination module 302, and a style determination module 303, wherein:

目标样式信息对象确定模块301被配置为在创建视图模型实例的目标节点之后,确定目标节点所依赖的目标样式信息对象;目标样式信息对象包括:CSS基础选择器对应的样式规则、CSS后代选择器对应的样式规则、各样式规则的优先级分数、及各CSS后代选择器的索引信息;各CSS后代选择器的索引信息,用于记录将各CSS后代选择器按照CSS后代选择器的名称中最后一个基础选择器的名称进行分类后得到的分类结果;The target style information object determination module 301 is configured to determine the target style information object that the target node depends on after creating the target node of the view model instance; the target style information object includes: style rules corresponding to the CSS base selector, style rules corresponding to the CSS descendant selector, priority scores of each style rule, and index information of each CSS descendant selector; the index information of each CSS descendant selector is used to record the classification result obtained after classifying each CSS descendant selector according to the name of the last base selector in the name of the CSS descendant selector;

样式规则确定模块302被配置为根据目标样式信息对象中各CSS后代选择器的索引信息,确定目标节点匹配的样式规则;The style rule determination module 302 is configured to determine the style rule matched by the target node according to the index information of each CSS descendant selector in the target style information object;

样式确定模块303被配置为根据目标节点所匹配的各样式规则的优先级分数,将目标节点匹配的各样式规则进行合并,确定目标节点的样式。The style determination module 303 is configured to merge the style rules matched by the target node according to the priority scores of the style rules matched by the target node, and determine the style of the target node.

本公开实施例提供的装置能够用于执行图1所示实施例的技术方案,其执行方式和有益效果类似,此处不再赘述。The device provided in the embodiment of the present disclosure can be used to execute the technical solution of the embodiment shown in Figure 1, and its execution method and beneficial effects are similar, which will not be repeated here.

在一种可能的实施方式中,如图4所示,图3示出的样式确定装置还可以包括:生成模块401、注册模块402及绑定模块403,其中:In a possible implementation, as shown in FIG. 4 , the style determination device shown in FIG. 3 may further include: a generation module 401 , a registration module 402 and a binding module 403 , wherein:

生成模块401被配置为当创建视图模型实例的根节点时,编译样式代码,生成待注册样式信息对象;The generation module 401 is configured to compile the style code and generate a style information object to be registered when creating the root node of the view model instance;

注册模块402被配置为在页面的文档上注册待注册样式信息对象;The registration module 402 is configured to register the style information object to be registered on the document of the page;

绑定模块403被配置为在视图模型实例的根节点上绑定待注册样式信息对象的标识。The binding module 403 is configured to bind the identifier of the style information object to be registered to the root node of the view model instance.

在一种可能的实施方式中,如图5所示,图3示出的样式确定装置还可以包括把目标样式信息对象确定模块301配置成包括:第一获取子模块501、第二获取子模块502及第一确定子模块503,其中:In a possible implementation, as shown in FIG. 5 , the style determination apparatus shown in FIG. 3 may further include configuring the target style information object determination module 301 to include: a first acquisition submodule 501, a second acquisition submodule 502, and a first determination submodule 503, wherein:

第一获取子模块501被配置为获取目标节点所属的文档上注册的样式信息对象的集合;The first acquisition submodule 501 is configured to acquire a set of style information objects registered on the document to which the target node belongs;

第二获取子模块502被配置为获取目标节点所属的视图模型实例的根节点上绑定的样式信息对象的标识;The second acquisition submodule 502 is configured to acquire the identifier of the style information object bound to the root node of the view model instance to which the target node belongs;

第一确定子模块503被配置为根据所获取的样式信息对象的集合、及所获取的样式信息对象的标识,确定目标节点所依赖的目标样式信息对象。The first determining submodule 503 is configured to determine the target style information object on which the target node depends according to the acquired set of style information objects and the acquired identifiers of the style information objects.

在一种可能的实施方式中,如图6所示,图3示出的样式确定装置还可以包括把样式规则确定模块302配置成包括:第一查找子模块601、第二查找子模块602、第三获取子模块603、匹配子模块604及第二确定子模块605,其中:In a possible implementation, as shown in FIG. 6 , the style determination apparatus shown in FIG. 3 may further include configuring the style rule determination module 302 to include: a first search submodule 601, a second search submodule 602, a third acquisition submodule 603, a matching submodule 604, and a second determination submodule 605, wherein:

第一查找子模块601被配置为在目标样式信息对象所包括的各CSS基础选择器对应的样式规则中,查找目标节点匹配的第一CSS基础选择器;The first search submodule 601 is configured to search for a first CSS basic selector matching the target node in the style rules corresponding to each CSS basic selector included in the target style information object;

第二查找子模块602被配置为在目标样式信息对象所包括的各CSS后代选择器的索引信息中,查找目标节点匹配的第二CSS基础选择器、及以第二CSS基础选择器的名称为索引的第一CSS后代选择器;The second search submodule 602 is configured to search for the second CSS base selector that matches the target node and the first CSS descendant selector that uses the name of the second CSS base selector as an index in the index information of each CSS descendant selector included in the target style information object;

第三获取子模块603被配置为获取目标节点的所有父节点;The third acquisition submodule 603 is configured to acquire all parent nodes of the target node;

匹配子模块604被配置为分别根据各父节点查找各第一CSS后代选择器中与目标节点匹配的第二CSS后代选择器;The matching submodule 604 is configured to search for a second CSS descendant selector matching the target node in each first CSS descendant selector according to each parent node;

第二确定子模块605被配置为根据第一CSS基础选择器和第二CSS后代选择器,确定目标节点匹配的样式规则。The second determination submodule 605 is configured to determine the style rule matched by the target node according to the first CSS base selector and the second CSS descendant selector.

在一种可能的实施方式中,如图7所示,图3示出的样式确定装置还可以包括缓存模块701,被配置为将所确定的目标节点匹配的样式规则,按照样式规则的不同类别分类缓存至目标节点中。In a possible implementation, as shown in FIG. 7 , the style determination apparatus shown in FIG. 3 may further include a cache module 701 configured to cache the style rules matched by the determined target node into the target node according to different categories of the style rules.

在一种可能的实施方式中,如图8所示,图3示出的样式确定装置还可以包括把样式确定模块303配置成包括:排序子模块801及合并子模块802,其中:In a possible implementation, as shown in FIG8 , the style determination apparatus shown in FIG3 may further include configuring the style determination module 303 to include: a sorting submodule 801 and a merging submodule 802, wherein:

排序子模块801被配置为按照目标节点所匹配的各样式规则的优先级分数由小到大的顺序,将各样式规则进行排序;The sorting submodule 801 is configured to sort the style rules matched by the target node in ascending order of priority scores of the style rules;

合并子模块802被配置为通过优先级分数大的样式规则覆盖优先级分数小的样式规则,将排序后各样式规则进行合并,得到目标节点的样式。The merging submodule 802 is configured to cover the style rules with smaller priority scores with the style rules with larger priority scores, merge the sorted style rules, and obtain the style of the target node.

图9是根据一示例性实施例示出的一种样式确定装置900的框图,样式确定装置900包括:FIG9 is a block diagram of a style determination device 900 according to an exemplary embodiment. The style determination device 900 includes:

处理器901;Processor 901;

用于存储处理器可执行指令的存储器902;Memory 902 for storing processor executable instructions;

其中,处理器901被配置为:The processor 901 is configured as follows:

在创建视图模型实例的目标节点之后,确定目标节点所依赖的目标样式信息对象;目标样式信息对象包括:CSS基础选择器对应的样式规则、CSS后代选择器对应的样式规则、各样式规则的优先级分数、及各CSS后代选择器的索引信息;各CSS后代选择器的索引信息,用于记录将各CSS后代选择器按照CSS后代选择器的名称中最后一个基础选择器的名称进行分类后得到的分类结果;After creating the target node of the view model instance, determining the target style information object that the target node depends on; the target style information object includes: style rules corresponding to the CSS base selector, style rules corresponding to the CSS descendant selector, priority scores of each style rule, and index information of each CSS descendant selector; the index information of each CSS descendant selector is used to record the classification result obtained by classifying each CSS descendant selector according to the name of the last base selector in the name of the CSS descendant selector;

根据目标样式信息对象中各CSS后代选择器的索引信息,确定目标节点匹配的样式规则;Determine the style rule that the target node matches according to the index information of each CSS descendant selector in the target style information object;

根据目标节点所匹配的各样式规则的优先级分数,将目标节点匹配的各样式规则进行合并,确定目标节点的样式。According to the priority scores of the style rules matched by the target node, the style rules matched by the target node are merged to determine the style of the target node.

在一个实施例中,上述处理器901还可被配置为:In one embodiment, the processor 901 may also be configured to:

当创建视图模型实例的根节点时,编译样式代码,生成待注册样式信息对象;When creating the root node of the view model instance, compile the style code and generate the style information object to be registered;

在页面的文档上注册待注册样式信息对象;Register the style information object to be registered on the document of the page;

在视图模型实例的根节点上绑定待注册样式信息对象的标识。Bind the identifier of the style information object to be registered to the root node of the view model instance.

在一个实施例中,上述处理器901还可被配置为:In one embodiment, the processor 901 may also be configured to:

获取目标节点所属的文档上注册的样式信息对象的集合;Get the collection of style information objects registered on the document to which the target node belongs;

获取目标节点所属的视图模型实例的根节点上绑定的样式信息对象的标识;Get the ID of the style information object bound to the root node of the view model instance to which the target node belongs;

根据所获取的样式信息对象的集合、及所获取的样式信息对象的标识,确定目标节点所依赖的目标样式信息对象。The target style information object on which the target node depends is determined according to the acquired set of style information objects and the identifiers of the acquired style information objects.

在一个实施例中,上述处理器901还可被配置为:In one embodiment, the processor 901 may also be configured to:

在目标样式信息对象所包括的各CSS基础选择器对应的样式规则中,查找目标节点匹配的第一CSS基础选择器;Searching for the first CSS base selector that matches the target node in the style rules corresponding to the CSS base selectors included in the target style information object;

在目标样式信息对象所包括的各CSS后代选择器的索引信息中,查找目标节点匹配的第二CSS基础选择器、及以第二CSS基础选择器的名称为索引的第一CSS后代选择器;In the index information of each CSS descendant selector included in the target style information object, search for the second CSS base selector that matches the target node and the first CSS descendant selector with the name of the second CSS base selector as the index;

获取目标节点的所有父节点;Get all parent nodes of the target node;

分别根据各父节点查找各第一CSS后代选择器中与目标节点匹配的第二CSS后代选择器;Search each first CSS descendant selector for a second CSS descendant selector that matches the target node according to each parent node;

根据第一CSS基础选择器和第二CSS后代选择器,确定目标节点匹配的样式规则。Determine the style rule that matches the target node according to the first CSS base selector and the second CSS descendant selector.

在一个实施例中,上述处理器901还可被配置为:将所确定的目标节点匹配的样式规则,按照样式规则的不同类别分类缓存至目标节点中。In one embodiment, the processor 901 may be further configured to: cache the determined style rules matching the target node into the target node according to different categories of style rules.

在一个实施例中,上述处理器901还可被配置为:In one embodiment, the processor 901 may also be configured to:

按照目标节点所匹配的各样式规则的优先级分数由小到大的顺序,将各样式规则进行排序;Sort the style rules matched by the target node in ascending order of priority scores;

通过优先级分数大的样式规则覆盖优先级分数小的样式规则,将排序后各样式规则进行合并,得到目标节点的样式。The style rules with larger priority scores are used to overwrite the style rules with smaller priority scores, and the sorted style rules are merged to obtain the style of the target node.

关于上述实施例中的装置,其中各个模块执行操作的具体方式已经在有关该方法的实施例中进行了详细描述,此处将不做详细阐述说明。Regarding the device in the above embodiment, the specific manner in which each module performs operations has been described in detail in the embodiment of the method, and will not be elaborated here.

图10是根据一示例性实施例示出的一种样式确定装置的框图;样式确定装置1000适用于终端;样式确定装置1000可以包括以下一个或多个组件:处理组件1002,存储器1004,电源组件1006,多媒体组件1008,音频组件1010,输入/输出(I/O)的接口1012,传感器组件1014,以及通信组件1016。Figure 10 is a block diagram of a style determination device according to an exemplary embodiment; the style determination device 1000 is suitable for a terminal; the style determination device 1000 may include one or more of the following components: a processing component 1002, a memory 1004, a power supply component 1006, a multimedia component 1008, an audio component 1010, an input/output (I/O) interface 1012, a sensor component 1014, and a communication component 1016.

处理组件1002通常控制样式确定装置1000的整体操作,诸如与显示,电话呼叫,数据通信,相机操作和记录操作相关联的操作。处理组件1002可以包括一个或多个处理器1020来执行指令,以完成上述的方法的全部或部分步骤。此外,处理组件1002可以包括一个或多个模块,便于处理组件1002和其他组件之间的交互。例如,处理组件1002可以包括多媒体模块,以方便多媒体组件1008和处理组件1002之间的交互。The processing component 1002 generally controls the overall operation of the style determination device 1000, such as operations associated with display, phone calls, data communications, camera operations, and recording operations. The processing component 1002 may include one or more processors 1020 to execute instructions to complete all or part of the steps of the above-mentioned method. In addition, the processing component 1002 may include one or more modules to facilitate the interaction between the processing component 1002 and other components. For example, the processing component 1002 may include a multimedia module to facilitate the interaction between the multimedia component 1008 and the processing component 1002.

存储器1004被配置为存储各种类型的数据以支持在样式确定装置1000的操作。这些数据的示例包括用于在样式确定装置1000上操作的任何应用程序或方法的指令,联系人数据,电话簿数据,消息,图片,视频等。存储器1004可以由任何类型的易失性或非易失性存储设备或者它们的组合实现,如静态随机存取存储器(SRAM),电可擦除可编程只读存储器(EEPROM),可擦除可编程只读存储器(EPROM),可编程只读存储器(PROM),只读存储器(ROM),磁存储器,快闪存储器,磁盘或光盘。The memory 1004 is configured to store various types of data to support the operation of the style determination device 1000. Examples of such data include instructions for any application or method operating on the style determination device 1000, contact data, phone book data, messages, pictures, videos, etc. The memory 1004 can be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as static random access memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic memory, flash memory, magnetic disk or optical disk.

电源组件1006为样式确定装置1000的各种组件提供电力。电源组件1006可以包括电源管理系统,一个或多个电源,及其他与为样式确定装置1000生成、管理和分配电力相关联的组件。The power supply component 1006 provides power to various components of the style determination device 1000. The power supply component 1006 may include a power management system, one or more power supplies, and other components associated with generating, managing, and distributing power for the style determination device 1000.

多媒体组件1008包括在样式确定装置1000和用户之间的提供一个输出接口的屏幕。在一些实施例中,屏幕可以包括液晶显示器(LCD)和触摸面板(TP)。如果屏幕包括触摸面板,屏幕可以被实现为触摸屏,以接收来自用户的输入信号。触摸面板包括一个或多个触摸传感器以感测触摸、滑动和触摸面板上的手势。触摸传感器可以不仅感测触摸或滑动动作的边界,而且还检测与触摸或滑动操作相关的持续时间和压力。在一些实施例中,多媒体组件1008包括一个前置摄像头和/或后置摄像头。当样式确定装置1000处于操作模式,如拍摄模式或视频模式时,前置摄像头和/或后置摄像头可以接收外部的多媒体数据。每个前置摄像头和后置摄像头可以是一个固定的光学透镜系统或具有焦距和光学变焦能力。The multimedia component 1008 includes a screen that provides an output interface between the style determination device 1000 and the user. In some embodiments, the screen may include a liquid crystal display (LCD) and a touch panel (TP). If the screen includes a touch panel, the screen may be implemented as a touch screen to receive input signals from the user. The touch panel includes one or more touch sensors to sense touch, slide, and gestures on the touch panel. The touch sensor may not only sense the boundaries of the touch or slide action, but also detect the duration and pressure associated with the touch or slide operation. In some embodiments, the multimedia component 1008 includes a front camera and/or a rear camera. When the style determination device 1000 is in an operating mode, such as a shooting mode or a video mode, the front camera and/or the rear camera may receive external multimedia data. Each front camera and the rear camera may be a fixed optical lens system or have a focal length and optical zoom capability.

音频组件1010被配置为输出和/或输入音频信号。例如,音频组件1010包括一个麦克风(MIC),当样式确定装置1000处于操作模式,如呼叫模式、记录模式和语音识别模式时,麦克风被配置为接收外部音频信号。所接收的音频信号可以被进一步存储在存储器1004或经由通信组件1016发送。在一些实施例中,音频组件1010还包括一个扬声器,用于输出音频信号。The audio component 1010 is configured to output and/or input audio signals. For example, the audio component 1010 includes a microphone (MIC), and when the style determination device 1000 is in an operation mode, such as a call mode, a recording mode, and a speech recognition mode, the microphone is configured to receive an external audio signal. The received audio signal can be further stored in the memory 1004 or sent via the communication component 1016. In some embodiments, the audio component 1010 also includes a speaker for outputting audio signals.

I/O接口1012为处理组件1002和外围接口模块之间提供接口,上述外围接口模块可以是键盘,点击轮,按钮等。这些按钮可包括但不限于:主页按钮、音量按钮、启动按钮和锁定按钮。I/O interface 1012 provides an interface between processing component 1002 and peripheral interface modules, such as keyboards, click wheels, buttons, etc. These buttons may include but are not limited to: a home button, a volume button, a start button, and a lock button.

传感器组件1014包括一个或多个传感器,用于为样式确定装置1000提供各个方面的状态评估。例如,传感器组件1014可以检测到样式确定装置1000的打开/关闭状态,组件的相对定位,例如组件为样式确定装置1000的显示器和小键盘,传感器组件1014还可以检测样式确定装置1000或样式确定装置1000一个组件的位置改变,用户与样式确定装置1000接触的存在或不存在,样式确定装置1000方位或加速/减速和样式确定装置1000的温度变化。传感器组件1014可以包括接近传感器,被配置用来在没有任何的物理接触时检测附近物体的存在。传感器组件1014还可以包括光传感器,如CMOS或CCD图像传感器,用于在成像应用中使用。在一些实施例中,该传感器组件1014还可以包括加速度传感器,陀螺仪传感器,磁传感器,压力传感器或温度传感器。The sensor assembly 1014 includes one or more sensors for providing various aspects of status assessment for the style determination device 1000. For example, the sensor assembly 1014 can detect the open/closed state of the style determination device 1000, the relative positioning of components, such as the display and keypad of the style determination device 1000, the sensor assembly 1014 can also detect the position change of the style determination device 1000 or a component of the style determination device 1000, the presence or absence of user contact with the style determination device 1000, the orientation or acceleration/deceleration of the style determination device 1000, and the temperature change of the style determination device 1000. The sensor assembly 1014 can include a proximity sensor configured to detect the presence of a nearby object without any physical contact. The sensor assembly 1014 can also include an optical sensor, such as a CMOS or CCD image sensor, for use in imaging applications. In some embodiments, the sensor assembly 1014 can also include an acceleration sensor, a gyroscope sensor, a magnetic sensor, a pressure sensor, or a temperature sensor.

通信组件1016被配置为便于样式确定装置1000和其他设备之间有线或无线方式的通信。样式确定装置1000可以接入基于通信标准的无线网络,如WiFi、2G、3G、4G、5G或它们的组合、或对讲网络。在一个示例性实施例中,通信组件1016经由广播信道接收来自外部广播管理系统的广播信号或广播相关信息。在一个示例性实施例中,通信组件1016还包括近场通信(NFC)模块,以促进短程通信。例如,在NFC模块可基于射频识别(RFID)技术,红外数据协会(IrDA)技术,超宽带(UWB)技术,蓝牙(BT)技术和其他技术来实现。Communication component 1016 is configured to facilitate wired or wireless communication between style determination device 1000 and other devices. Style determination device 1000 can access a wireless network based on a communication standard, such as WiFi, 2G, 3G, 4G, 5G or a combination thereof, or an intercom network. In an exemplary embodiment, communication component 1016 receives a broadcast signal or broadcast-related information from an external broadcast management system via a broadcast channel. In an exemplary embodiment, communication component 1016 also includes a near field communication (NFC) module to facilitate short-range communication. For example, the NFC module can be implemented based on radio frequency identification (RFID) technology, infrared data association (IrDA) technology, ultra-wideband (UWB) technology, Bluetooth (BT) technology and other technologies.

在示例性实施例中,样式确定装置1000可以被一个或多个应用专用集成电路(ASIC)、数字信号处理器(DSP)、数字信号处理设备(DSPD)、可编程逻辑器件(PLD)、现场可编程门阵列(FPGA)、控制器、微控制器、微处理器或其他电子组件实现,用于执行上述方法。In an exemplary embodiment, the style determination device 1000 can be implemented by one or more application-specific integrated circuits (ASICs), digital signal processors (DSPs), digital signal processing devices (DSPDs), programmable logic devices (PLDs), field programmable gate arrays (FPGAs), controllers, microcontrollers, microprocessors or other electronic components to perform the above method.

在示例性实施例中,还提供了一种包括指令的非临时性计算机可读存储介质,例如包括指令的存储器1004,上述指令可由样式确定装置1000的处理器1020执行以完成上述方法。例如,非临时性计算机可读存储介质可以是ROM、随机存取存储器(RAM)、CD-ROM、磁带、软盘和光数据存储设备等。In an exemplary embodiment, a non-transitory computer-readable storage medium including instructions is also provided, such as a memory 1004 including instructions, and the instructions can be executed by the processor 1020 of the pattern determination device 1000 to complete the above method. For example, the non-transitory computer-readable storage medium can be a ROM, a random access memory (RAM), a CD-ROM, a magnetic tape, a floppy disk, an optical data storage device, etc.

图11是根据一示例性实施例示出的一种样式确定装置的框图。例如,样式确定装置1100可以被提供为一服务器。样式确定装置1100包括处理组件1102,其进一步包括一个或多个处理器,以及由存储器1103所代表的存储器资源,用于存储可由处理组件1102的执行的指令,例如应用程序。存储器1103中存储的应用程序可以包括一个或一个以上的每一个对应于一组指令的模块。此外,处理组件1102被配置为执行指令,以执行上述方法。FIG11 is a block diagram of a style determination device according to an exemplary embodiment. For example, the style determination device 1100 can be provided as a server. The style determination device 1100 includes a processing component 1102, which further includes one or more processors, and a memory resource represented by a memory 1103, which is used to store instructions that can be executed by the processing component 1102, such as an application. The application stored in the memory 1103 can include one or more modules, each of which corresponds to a set of instructions. In addition, the processing component 1102 is configured to execute instructions to perform the above method.

样式确定装置1100还可以包括一个电源组件1106被配置为执行样式确定装置1100的电源管理,一个有线或无线网络接口1105被配置为将样式确定装置1100连接到网络,和一个输入输出(I/O)接口1108。样式确定装置1100可以操作基于存储在存储器1103的操作系统,例如Windows ServerTM,Mac OS XTM,UnixTM,LinuxTM,FreeBSDTM或类似。The style determination device 1100 may also include a power supply component 1106 configured to perform power management of the style determination device 1100, a wired or wireless network interface 1105 configured to connect the style determination device 1100 to a network, and an input/output (I/O) interface 1108. The style determination device 1100 may operate based on an operating system stored in the memory 1103, such as Windows Server™, Mac OS X™, Unix™, Linux™, FreeBSD™, or the like.

一种非临时性计算机可读存储介质,当存储介质中的指令由样式确定装置1000或样式确定装置1100的处理器执行时,使得样式确定装置1000或样式确定装置1100能够执行如下方法:A non-transitory computer-readable storage medium, when instructions in the storage medium are executed by a processor of a style determination apparatus 1000 or a style determination apparatus 1100, enables the style determination apparatus 1000 or the style determination apparatus 1100 to perform the following method:

在创建视图模型实例的目标节点之后,确定目标节点所依赖的目标样式信息对象;目标样式信息对象包括:CSS基础选择器对应的样式规则、CSS后代选择器对应的样式规则、各样式规则的优先级分数、及各CSS后代选择器的索引信息;各CSS后代选择器的索引信息,用于记录将各CSS后代选择器按照CSS后代选择器的名称中最后一个基础选择器的名称进行分类后得到的分类结果;After creating the target node of the view model instance, determining the target style information object that the target node depends on; the target style information object includes: style rules corresponding to the CSS base selector, style rules corresponding to the CSS descendant selector, priority scores of each style rule, and index information of each CSS descendant selector; the index information of each CSS descendant selector is used to record the classification result obtained by classifying each CSS descendant selector according to the name of the last base selector in the name of the CSS descendant selector;

根据目标样式信息对象中各CSS后代选择器的索引信息,确定目标节点匹配的样式规则;Determine the style rule that the target node matches according to the index information of each CSS descendant selector in the target style information object;

根据目标节点所匹配的各样式规则的优先级分数,将目标节点匹配的各样式规则进行合并,确定目标节点的样式。According to the priority scores of the style rules matched by the target node, the style rules matched by the target node are merged to determine the style of the target node.

在一个实施例中,方法还包括:In one embodiment, the method further comprises:

当创建视图模型实例的根节点时,编译样式代码,生成待注册样式信息对象;When creating the root node of the view model instance, compile the style code and generate the style information object to be registered;

在页面的文档上注册待注册样式信息对象;Register the style information object to be registered on the document of the page;

在视图模型实例的根节点上绑定待注册样式信息对象的标识。Bind the identifier of the style information object to be registered to the root node of the view model instance.

在一个实施例中,确定目标节点所依赖的目标样式信息对象,包括:In one embodiment, determining the target style information object that the target node depends on includes:

获取目标节点所属的文档上注册的样式信息对象的集合;Get the collection of style information objects registered on the document to which the target node belongs;

获取目标节点所属的视图模型实例的根节点上绑定的样式信息对象的标识;Get the ID of the style information object bound to the root node of the view model instance to which the target node belongs;

根据所获取的样式信息对象的集合、及所获取的样式信息对象的标识,确定目标节点所依赖的目标样式信息对象。The target style information object on which the target node depends is determined according to the acquired set of style information objects and the identifiers of the acquired style information objects.

在一个实施例中,根据目标样式信息对象中各CSS后代选择器的索引信息,确定目标节点匹配的样式规则,包括:In one embodiment, determining the style rule matched by the target node according to the index information of each CSS descendant selector in the target style information object includes:

在目标样式信息对象所包括的各CSS基础选择器对应的样式规则中,查找目标节点匹配的第一CSS基础选择器;Searching for the first CSS base selector that matches the target node in the style rules corresponding to the CSS base selectors included in the target style information object;

在目标样式信息对象所包括的各CSS后代选择器的索引信息中,查找目标节点匹配的第二CSS基础选择器、及以第二CSS基础选择器的名称为索引的第一CSS后代选择器;In the index information of each CSS descendant selector included in the target style information object, search for the second CSS base selector that matches the target node and the first CSS descendant selector with the name of the second CSS base selector as the index;

获取目标节点的所有父节点;Get all parent nodes of the target node;

分别根据各父节点查找各第一CSS后代选择器中与目标节点匹配的第二CSS后代选择器;Search each first CSS descendant selector for a second CSS descendant selector that matches the target node according to each parent node;

根据第一CSS基础选择器和第二CSS后代选择器,确定目标节点匹配的样式规则。Determine the style rule that matches the target node according to the first CSS base selector and the second CSS descendant selector.

在一个实施例中,方法还包括:In one embodiment, the method further comprises:

将所确定的目标节点匹配的样式规则,按照样式规则的不同类别分类缓存至目标节点中。The style rules that match the determined target node are classified and cached in the target node according to different categories of the style rules.

在一个实施例中,根据目标节点所匹配的各样式规则的优先级分数,将目标节点匹配的各样式规则进行合并,确定目标节点的样式,包括:In one embodiment, according to the priority scores of the style rules matched by the target node, the style rules matched by the target node are merged to determine the style of the target node, including:

按照目标节点所匹配的各样式规则的优先级分数由小到大的顺序,将各样式规则进行排序;Sort the style rules matched by the target node in ascending order of priority scores;

通过优先级分数大的样式规则覆盖优先级分数小的样式规则,将排序后各样式规则进行合并,得到目标节点的样式。The style rules with larger priority scores are used to overwrite the style rules with smaller priority scores, and the sorted style rules are merged to obtain the style of the target node.

本领域技术人员在考虑说明书及实践这里公开的公开后,将容易想到本公开的其它实施方案。本申请旨在涵盖本公开的任何变型、用途或者适应性变化,这些变型、用途或者适应性变化遵循本公开的一般性原理并包括本公开未公开的本技术领域中的公知常识或惯用技术手段。说明书和实施例仅被视为示例性的,本公开的真正范围和精神由下面的权利要求指出。Those skilled in the art will readily appreciate other embodiments of the present disclosure after considering the specification and practicing the disclosure disclosed herein. This application is intended to cover any variations, uses, or adaptations of the present disclosure that follow the general principles of the present disclosure and include common knowledge or customary techniques in the art that are not disclosed in the present disclosure. The specification and examples are intended to be exemplary only, and the true scope and spirit of the present disclosure are indicated by the following claims.

应当理解的是,本公开并不局限于上面已经描述并在附图中示出的精确结构,并且可以在不脱离其范围进行各种修改和改变。本公开的范围仅由所附的权利要求来限制。It should be understood that the present disclosure is not limited to the exact structures that have been described above and shown in the drawings, and that various modifications and changes may be made without departing from the scope thereof. The scope of the present disclosure is limited only by the appended claims.

Claims (10)

1.一种样式确定方法,其特征在于,包括:1. A method for determining a style, comprising: 在创建视图模型实例的目标节点之后,确定所述目标节点所依赖的目标样式信息对象;所述目标样式信息对象包括:层叠样式表CSS基础选择器对应的样式规则、CSS后代选择器对应的样式规则、各所述样式规则的优先级分数、及各所述CSS后代选择器的索引信息;各所述CSS后代选择器的索引信息,用于记录将各所述CSS后代选择器按照CSS后代选择器的名称中最后一个基础选择器的名称进行分类后得到的分类结果;After creating a target node of the view model instance, determining a target style information object on which the target node depends; the target style information object includes: style rules corresponding to a CSS base selector, style rules corresponding to a CSS descendant selector, priority scores of each of the style rules, and index information of each of the CSS descendant selectors; the index information of each of the CSS descendant selectors is used to record a classification result obtained by classifying each of the CSS descendant selectors according to the name of the last base selector in the name of the CSS descendant selector; 根据所述目标样式信息对象中各所述CSS后代选择器的索引信息,确定所述目标节点匹配的样式规则;Determining the style rule matched by the target node according to the index information of each of the CSS descendant selectors in the target style information object; 根据所述目标节点所匹配的各所述样式规则的优先级分数,将所述目标节点匹配的各所述样式规则进行合并,确定所述目标节点的样式;According to the priority scores of the style rules matched by the target node, the style rules matched by the target node are merged to determine the style of the target node; 所述根据所述目标样式信息对象中各所述CSS后代选择器的索引信息,确定所述目标节点匹配的样式规则,包括:The step of determining the style rule matched by the target node according to the index information of each of the CSS descendant selectors in the target style information object includes: 在所述目标样式信息对象所包括的各CSS基础选择器对应的样式规则中,查找所述目标节点匹配的第一CSS基础选择器;Searching for a first CSS base selector matching the target node in the style rules corresponding to each CSS base selector included in the target style information object; 在所述目标样式信息对象所包括的各所述CSS后代选择器的索引信息中,查找所述目标节点匹配的第二CSS基础选择器、及以所述第二CSS基础选择器的名称为索引的第一CSS后代选择器;Searching for a second CSS base selector matching the target node and a first CSS descendant selector with the name of the second CSS base selector as an index in the index information of each CSS descendant selector included in the target style information object; 获取所述目标节点的所有父节点;Get all parent nodes of the target node; 分别根据各所述父节点查找各所述第一CSS后代选择器中与所述目标节点匹配的第二CSS后代选择器;Searching for a second CSS descendant selector matching the target node in each of the first CSS descendant selectors according to each of the parent nodes; 根据所述第一CSS基础选择器和所述第二CSS后代选择器,确定所述目标节点匹配的样式规则;Determine, according to the first CSS base selector and the second CSS descendant selector, a style rule matched by the target node; 所述根据所述目标节点所匹配的各所述样式规则的优先级分数,将所述目标节点匹配的各所述样式规则进行合并,确定所述目标节点的样式,包括:The step of merging the style rules matched by the target node according to the priority scores of the style rules matched by the target node to determine the style of the target node includes: 按照所述目标节点所匹配的各所述样式规则的优先级分数由小到大的顺序,将各所述样式规则进行排序;Sort the style rules matched by the target node in ascending order of priority scores; 通过优先级分数大的样式规则覆盖优先级分数小的样式规则,将排序后各所述样式规则进行合并,得到所述目标节点的样式。The style rules with larger priority scores are used to cover the style rules with smaller priority scores, and the sorted style rules are merged to obtain the style of the target node. 2.根据权利要求1所述的方法,其特征在于,所述方法还包括:2. The method according to claim 1, characterized in that the method further comprises: 当创建所述视图模型实例的根节点时,编译样式代码,生成待注册样式信息对象;When creating the root node of the view model instance, compile the style code and generate a style information object to be registered; 在页面的文档上注册所述待注册样式信息对象;Registering the style information object to be registered on the document of the page; 在所述视图模型实例的根节点上绑定所述待注册样式信息对象的标识。The identifier of the style information object to be registered is bound to the root node of the view model instance. 3.根据权利要求1所述的方法,其特征在于,所述确定所述目标节点所依赖的目标样式信息对象,包括:3. The method according to claim 1, characterized in that the step of determining the target style information object on which the target node depends comprises: 获取所述目标节点所属的文档上注册的样式信息对象的集合;Obtain a collection of style information objects registered on the document to which the target node belongs; 获取所述目标节点所属的视图模型实例的根节点上绑定的样式信息对象的标识;Obtaining the identifier of the style information object bound to the root node of the view model instance to which the target node belongs; 根据所获取的样式信息对象的集合、及所获取的样式信息对象的标识,确定所述目标节点所依赖的目标样式信息对象。The target style information object on which the target node depends is determined according to the acquired set of style information objects and the identifiers of the acquired style information objects. 4.根据权利要求1所述的方法,其特征在于,所述方法还包括:4. The method according to claim 1, characterized in that the method further comprises: 将所确定的所述目标节点匹配的样式规则,按照样式规则的不同类别分类缓存至所述目标节点中。The determined style rules matching the target node are cached in the target node according to different categories of style rules. 5.一种样式确定装置,其特征在于,包括:5. A pattern determination device, comprising: 目标样式信息对象确定模块,用于在创建视图模型实例的目标节点之后,确定所述目标节点所依赖的目标样式信息对象;所述目标样式信息对象包括:层叠样式表CSS基础选择器对应的样式规则、CSS后代选择器对应的样式规则、各所述样式规则的优先级分数、及各所述CSS后代选择器的索引信息;各所述CSS后代选择器的索引信息,用于记录将各所述CSS后代选择器按照CSS后代选择器的名称中最后一个基础选择器的名称进行分类后得到的分类结果;A target style information object determination module is used to determine the target style information object that the target node depends on after creating the target node of the view model instance; the target style information object includes: style rules corresponding to the CSS base selector of the cascading style sheet, style rules corresponding to the CSS descendant selector, priority scores of each style rule, and index information of each CSS descendant selector; the index information of each CSS descendant selector is used to record the classification result obtained after classifying each CSS descendant selector according to the name of the last base selector in the name of the CSS descendant selector; 样式规则确定模块,用于根据所述目标样式信息对象中各所述CSS后代选择器的索引信息,确定所述目标节点匹配的样式规则;A style rule determination module, used to determine the style rule matched by the target node according to the index information of each CSS descendant selector in the target style information object; 样式确定模块,用于根据所述目标节点所匹配的各所述样式规则的优先级分数,将所述目标节点匹配的各所述样式规则进行合并,确定所述目标节点的样式;A style determination module, configured to combine the style rules matched by the target node according to the priority scores of the style rules matched by the target node, and determine the style of the target node; 所述样式规则确定模块,包括:The style rule determination module includes: 第一查找子模块,用于在所述目标样式信息对象所包括的各CSS基础选择器对应的样式规则中,查找所述目标节点匹配的第一CSS基础选择器;A first search submodule, configured to search for a first CSS basic selector matching the target node in style rules corresponding to each CSS basic selector included in the target style information object; 第二查找子模块,用于在所述目标样式信息对象所包括的各所述CSS后代选择器的索引信息中,查找所述目标节点匹配的第二CSS基础选择器、及以所述第二CSS基础选择器的名称为索引的第一CSS后代选择器;A second search submodule is configured to search, in the index information of each of the CSS descendant selectors included in the target style information object, a second CSS base selector matching the target node and a first CSS descendant selector with the name of the second CSS base selector as an index; 第三获取子模块,用于获取所述目标节点的所有父节点;A third acquisition submodule is used to acquire all parent nodes of the target node; 匹配子模块,用于分别根据各所述父节点查找各所述第一CSS后代选择器中与所述目标节点匹配的第二CSS后代选择器;A matching submodule, used for searching, according to each of the parent nodes, for a second CSS descendant selector in each of the first CSS descendant selectors that matches the target node; 第二确定子模块,用于根据所述第一CSS基础选择器和所述第二CSS后代选择器,确定所述目标节点匹配的样式规则;A second determination submodule, configured to determine a style rule matched by the target node according to the first CSS base selector and the second CSS descendant selector; 所述样式确定模块,包括:The style determination module includes: 排序子模块,用于按照所述目标节点所匹配的各所述样式规则的优先级分数由小到大的顺序,将各所述样式规则进行排序;A sorting submodule, used to sort the style rules matched by the target node in ascending order of priority scores of the style rules; 合并子模块,用于通过优先级分数大的样式规则覆盖优先级分数小的样式规则,将排序后各所述样式规则进行合并,得到所述目标节点的样式。The merging submodule is used to cover the style rules with smaller priority scores with the style rules with larger priority scores, and merge the sorted style rules to obtain the style of the target node. 6.根据权利要求5所述的装置,其特征在于,所述装置还包括:6. The device according to claim 5, characterized in that the device further comprises: 生成模块,用于当创建所述视图模型实例的根节点时,编译样式代码,生成待注册样式信息对象;A generation module, used for compiling the style code and generating a style information object to be registered when creating the root node of the view model instance; 注册模块,用于在页面的文档上注册所述待注册样式信息对象;A registration module, used to register the style information object to be registered on the document of the page; 绑定模块,用于在所述视图模型实例的根节点上绑定所述待注册样式信息对象的标识。A binding module is used to bind the identifier of the style information object to be registered to the root node of the view model instance. 7.根据权利要求5所述的装置,其特征在于,所述目标样式信息对象确定模块,包括:7. The device according to claim 5, characterized in that the target style information object determination module comprises: 第一获取子模块,用于获取所述目标节点所属的文档上注册的样式信息对象的集合;A first acquisition submodule is used to acquire a set of style information objects registered on the document to which the target node belongs; 第二获取子模块,用于获取所述目标节点所属的视图模型实例的根节点上绑定的样式信息对象的标识;A second acquisition submodule is used to acquire the identifier of the style information object bound to the root node of the view model instance to which the target node belongs; 第一确定子模块,用于根据所获取的样式信息对象的集合、及所获取的样式信息对象的标识,确定所述目标节点所依赖的目标样式信息对象。The first determination submodule is used to determine the target style information object on which the target node depends according to the acquired set of style information objects and the acquired identifiers of the style information objects. 8.根据权利要求5所述的装置,其特征在于,所述装置还包括:8. The device according to claim 5, characterized in that the device further comprises: 缓存模块,用于将所确定的所述目标节点匹配的样式规则,按照样式规则的不同类别分类缓存至所述目标节点中。The cache module is used to cache the determined style rules matched by the target node into the target node according to different categories of style rules. 9.一种样式确定装置,其特征在于,包括:9. A pattern determination device, comprising: 处理器;processor; 用于存储处理器可执行指令的存储器;a memory for storing processor-executable instructions; 其中,所述处理器被配置为:Wherein, the processor is configured to: 在创建视图模型实例的目标节点之后,确定所述目标节点所依赖的目标样式信息对象;所述目标样式信息对象包括:层叠样式表CSS基础选择器对应的样式规则、CSS后代选择器对应的样式规则、各所述样式规则的优先级分数、及各所述CSS后代选择器的索引信息;各所述CSS后代选择器的索引信息,用于记录将各所述CSS后代选择器按照CSS后代选择器的名称中最后一个基础选择器的名称进行分类后得到的分类结果;After creating a target node of the view model instance, determining a target style information object on which the target node depends; the target style information object includes: style rules corresponding to a CSS base selector, style rules corresponding to a CSS descendant selector, priority scores of each of the style rules, and index information of each of the CSS descendant selectors; the index information of each of the CSS descendant selectors is used to record a classification result obtained by classifying each of the CSS descendant selectors according to the name of the last base selector in the name of the CSS descendant selector; 根据所述目标样式信息对象中各所述CSS后代选择器的索引信息,确定所述目标节点匹配的样式规则;Determining the style rule matched by the target node according to the index information of each of the CSS descendant selectors in the target style information object; 根据所述目标节点所匹配的各所述样式规则的优先级分数,将所述目标节点匹配的各所述样式规则进行合并,确定所述目标节点的样式;According to the priority scores of the style rules matched by the target node, the style rules matched by the target node are merged to determine the style of the target node; 所述根据所述目标样式信息对象中各所述CSS后代选择器的索引信息,确定所述目标节点匹配的样式规则,包括:The step of determining the style rule matched by the target node according to the index information of each of the CSS descendant selectors in the target style information object includes: 在所述目标样式信息对象所包括的各CSS基础选择器对应的样式规则中,查找所述目标节点匹配的第一CSS基础选择器;Searching for a first CSS base selector matching the target node in the style rules corresponding to each CSS base selector included in the target style information object; 在所述目标样式信息对象所包括的各所述CSS后代选择器的索引信息中,查找所述目标节点匹配的第二CSS基础选择器、及以所述第二CSS基础选择器的名称为索引的第一CSS后代选择器;Searching for a second CSS base selector matching the target node and a first CSS descendant selector with the name of the second CSS base selector as an index in the index information of each CSS descendant selector included in the target style information object; 获取所述目标节点的所有父节点;Get all parent nodes of the target node; 分别根据各所述父节点查找各所述第一CSS后代选择器中与所述目标节点匹配的第二CSS后代选择器;Searching for a second CSS descendant selector matching the target node in each of the first CSS descendant selectors according to each of the parent nodes; 根据所述第一CSS基础选择器和所述第二CSS后代选择器,确定所述目标节点匹配的样式规则;Determine, according to the first CSS base selector and the second CSS descendant selector, a style rule matched by the target node; 所述根据所述目标节点所匹配的各所述样式规则的优先级分数,将所述目标节点匹配的各所述样式规则进行合并,确定所述目标节点的样式,包括:The step of merging the style rules matched by the target node according to the priority scores of the style rules matched by the target node to determine the style of the target node includes: 按照所述目标节点所匹配的各所述样式规则的优先级分数由小到大的顺序,将各所述样式规则进行排序;Sort the style rules matched by the target node in ascending order of priority scores; 通过优先级分数大的样式规则覆盖优先级分数小的样式规则,将排序后各所述样式规则进行合并,得到所述目标节点的样式。The style rules with larger priority scores are used to cover the style rules with smaller priority scores, and the sorted style rules are merged to obtain the style of the target node. 10.一种计算机可读存储介质,其上存储有计算机指令,其特征在于,该指令被处理器执行时实现权利要求1-4中任一项所述方法的步骤。10. A computer-readable storage medium having computer instructions stored thereon, characterized in that when the instructions are executed by a processor, the steps of the method described in any one of claims 1 to 4 are implemented.
CN201811385666.8A 2018-11-20 2018-11-20 Method and device for determining style Active CN109558553B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201811385666.8A CN109558553B (en) 2018-11-20 2018-11-20 Method and device for determining style

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201811385666.8A CN109558553B (en) 2018-11-20 2018-11-20 Method and device for determining style

Publications (2)

Publication Number Publication Date
CN109558553A CN109558553A (en) 2019-04-02
CN109558553B true CN109558553B (en) 2023-04-04

Family

ID=65866910

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201811385666.8A Active CN109558553B (en) 2018-11-20 2018-11-20 Method and device for determining style

Country Status (1)

Country Link
CN (1) CN109558553B (en)

Families Citing this family (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN110865863B (en) * 2019-11-18 2022-09-30 北京小米移动软件有限公司 Interface display method and device for fast application and storage medium
CN111258696A (en) * 2020-01-15 2020-06-09 上海擎感智能科技有限公司 Fast application display method and device
CN111523067A (en) * 2020-03-19 2020-08-11 北京辰森世纪科技股份有限公司 Page style processing method and device, storage medium and computer equipment
CN117150167A (en) * 2023-08-30 2023-12-01 北京自如信息科技有限公司 A page rendering method, device, computer equipment and storage medium

Citations (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN104965866A (en) * 2015-06-05 2015-10-07 小米科技有限责任公司 Method and apparatus for establishing label and style rule binding relation

Family Cites Families (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20120110437A1 (en) * 2010-10-28 2012-05-03 Microsoft Corporation Style and layout caching of web content

Patent Citations (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN104965866A (en) * 2015-06-05 2015-10-07 小米科技有限责任公司 Method and apparatus for establishing label and style rule binding relation

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
嵌入式浏览器CSS引擎的研究与改进;刘剑等;《计算机工程》;20110505(第09期);全文 *

Also Published As

Publication number Publication date
CN109558553A (en) 2019-04-02

Similar Documents

Publication Publication Date Title
CN111026396B (en) Page rendering method and device, electronic equipment and storage medium
US20210019575A1 (en) Prioritized device actions triggered by device scan data
CN109558553B (en) Method and device for determining style
US10074365B2 (en) Voice control method, mobile terminal device, and voice control system
CN110308908B (en) Method, device, and storage medium for generating application configuration files and displaying application pages
CN107329743A (en) Methods of exhibiting, device and the storage medium of five application page
CN108319489A (en) Application page starting method and device, storage medium and electronic equipment
WO2019149026A1 (en) Method and device for generating link for application page, storage medium, and electronic apparatus
CN105930536B (en) Index establishing method, page jumping method and device
CN111931102A (en) Method, device and system for constructing page
CN109710259B (en) Data processing method, device and storage medium
WO2022127743A1 (en) Content display method and terminal device
CN110851108A (en) Electronic equipment operation method and device, electronic equipment and storage medium
CN110992937B (en) Language offline identification method, terminal and readable storage medium
CN106095455A (en) A kind of application update method and device
WO2018145574A1 (en) Information processing method and device, terminal, server and storage medium
US12222994B2 (en) Quick application startup method and related apparatus
CN107220371A (en) Page display method, device and storage medium
CN116361242A (en) File acquisition method, device, electronic device and readable storage medium
CN107911482A (en) Intended application deployment method and device
CN107450912A (en) Layout method, device and the terminal of the page
CN107402756A (en) For drawing the method, apparatus and terminal of the page
CN112130839A (en) Method for constructing database, method for voice programming and related device
CN112860625B (en) Data acquisition method, data storage method, device, equipment and storage medium
CN114281822B (en) Data processing method, device, electronic equipment and storage medium

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant